Data Structures & AlgorithmsModerateTCS NQT · Infosys
Problem: Find the number of distinct strings obtained by reading the grid of letters ab cd moving right or down from the top-left, where each step appends the letter of the cell entered (the start letter counts). How many different strings can be produced?
- A. 3
- B. 1
- C. 2
- D. 4
Correct answer: C. 2
There are only two monotone paths in a 2×2 grid, and each spells a different string. Counting cells in the grid overstates the answer because paths are what matter.
More Coding Interview Problems questions
- Problem: The string "ababa" has how many distinct substrings of length 2 and 3 combined?
- Problem: Count the palindromic substrings of "abcbaabc" that start at index 0 (each prefix that is a palindrome counts once).
- Problem: Maximum sum of a subarray with length exactly 3 in [4, −2, 5, 1, 0, 2, −3, 6]. Report the maximum window sum.
- Problem: The longest subarray with sum divisible by 4 in [5, 3, 7, 2, 2, 6, 1, 1]: what is its length?
- Problem: In the array [9, 3, 7, 3, 9, 1, 7], how many elements are equal to the maximum of the elements to their right (the last element…
- Problem: Start with the empty stack. Process the string "7 3 2 + 5 -" as postfix tokens (numbers are pushed, operators pop two values…