Data Structures & AlgorithmsHardTCS NQT · Accenture
In a 3 by 3 grid with no walls, how many cells are exactly 2 moves (up, down, left or right) away from the top-left corner?
- A. 4
- B. 5
- C. 3
- D. 7
Correct answer: C. 3
The cells at Manhattan distance 2 are (0,2), (1,1) and (2,0), so the count is 3.
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
- How many index pairs i < j in [3, 4, 4, 5, 7, 6] have values that differ by exactly 1?
- What is the length of the longest contiguous subarray of [1, 2, 1, 2, 3] that contains at most two distinct values?
- How many adjacent position pairs in the string abbaabab are equal to ab or ba (overlapping adjacent pairs counted)?
- What is the lexicographically smallest rotation of the string bca?
- What is the sum of all integers x in [1, 50] that are divisible by 4 or by 6?
- How many positive divisors of 360 are odd?