Code Room
CodingMediumcod-g184
Subject Combinatorial countingLevel Mid–Senior~20 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

On a grid with (rows+1) by (cols+1) intersection points, you start at the top-left corner and may step only right or down by one unit at a time until you reach the bottom-right corner. Return the number of distinct monotonic lattice paths, modulo mod. For example, a 2-by-2 grid of moves (2 rights, 2 downs) has 6 paths. Assume 0 <= rows, cols <= 30 and mod >= 2.

Implement
lattice_paths_mod(rows: int, cols: int, mod: int) → int
Examples
in[2,2,1000000007]out6
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.