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)?

  1. A. 7
  2. B. 10
  3. C. 3
  4. 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.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic