Data Structures & AlgorithmsVery hardICPC regional · GATE CS
Problem: A lattice path goes from (0,0) to (3,3) using steps right (1,0) and up (0,1), and it must never go above the diagonal (that is, at every point the x-coordinate is at least the y-coordinate). How many such paths exist?
- A. 5
- B. 6
- C. 4
- D. 7
Correct answer: A. 5
These are ballot-type paths counted by Catalan numbers; the DP that forbids points with y > x gives the count. Counting all C(6,3) = 20 monotone paths ignores the diagonal restriction.
More Coding Interview Problems questions
- Problem: The array [1, 2, 4, 8, 16, 32] stores powers of two. For how many pairs (i < j) is a[i] + a[j] a power of two?
- Problem: A queue of 5 customers arrives with service times 4, 2, 6, 1, 3. A single server processes them in order (first come first…
- Problem: Starting with the list [3, 8, 2, 5], repeatedly take the last two elements, replace them by their difference (larger minus…
- Problem: How many 3-digit numbers (100–999) have digits that form a strictly increasing sequence when read left to right?
- Problem: In a list of the first 30 positive integers, how many numbers are multiples of 2 or 3 but not of 6?
- Problem: For the array [6, 1, 8, 3, 7], find the minimum number of adjacent swaps needed to sort it in increasing order (adjacent swaps…