Data Structures & AlgorithmsHardGATE CS · Codeforces Div2 D
A robot walks from the top-left corner of a 3 × 4 grid of cells to the bottom-right corner, moving only right or down. How many such paths make EXACTLY two turns (a turn is a change of direction between consecutive moves)?
- A. 7
- B. 10
- C. 3
- D. 0
Correct answer: C. 3
A path with exactly two turns is a run of one direction, then the other, then the first again. Count the ways to split the R−1 down moves and C−1 right moves into alternating blocks. The total number of monotone paths, C(5, 2) = 10, overcounts the paths with other turn counts.
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 lists a = [4, 9, 1, 7] and b = [3, 8, 2, 10] are paired one-to-one (any bijection). What is the minimum possible value of the sum of…
- In the sequence [1, 3, 5, 2, 4, 6], how many strictly increasing subsequences have the maximum possible length (count by index positions)?
- Consider the routine that computes the length of the longest STRICTLY increasing subsequence of [2, 2, 3, 3, 4, 4, 5] using the tails…
- How many unordered pairs of positions of the same letter are there in "abracadabra" (i < j with s[i] = s[j])?
- A Java program computes d[0] = d[1] = 1 and d[i] = d[i−1] + d[i−2] using int (32-bit two's complement, wrapping on overflow) with no…
- What is the largest sum of any contiguous window of exactly 4 elements of [2, 7, 1, 8, 2, 8, 1, 8, 2, 8]?