Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
What is the minimum number of knight moves needed to go from square (0, 0) to (3, 3) on an 8 by 8 board (coordinates 0 to 7)?
- A. 3
- B. 4
- C. 2
- D. 6
Correct answer: C. 2
A breadth-first search over knight moves gives the minimum. The two-move route is (0,0) to (1,2) to (3,3), and no single move reaches it.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- Two sorted linked lists are [1, 5, 9, 12] and [2, 3, 8]. They are merged into one sorted list. What is the 5th value of the merged list…
- In the array [2, 8, 5, 5, 3, 7, 5], how many index pairs i < j have a[i] + a[j] = 10?
- How many distinct sums are obtained by contiguous non-empty subarrays of [1, -1, 2, -2]?
- What is the length of the longest substring of aabbcaabcc in which every character occurs at least twice?
- How many palindromic substrings of length at least 2 does abcbaccab contain (counted by position)?
- How many distinct substrings of length 3 of abcabcabc occur at least twice in the string?