Count Routes Through a City Grid
Updated
Problem statement
A city is represented by a rectangular grid with rows rows and columns columns. Start at the top-left cell and reach the bottom-right cell.
For this exercise, assume each step moves exactly one cell right or one cell down, every cell is open, and there is no wrapping. Count distinct step sequences that reach the destination. For this exercise, assume the grid dimensions are supplied as parameters and the result is an exact signed 64-bit count with no modulus.
A one-cell grid has one route: the empty sequence. Complete countCityGridRoutes(rows, columns).
Function
countCityGridRoutes(rows: int, columns: int) → longExamples
Example 1
rows = 3columns = 3return = 6Each route has two right moves and two down moves. Choosing their order gives 6 routes.
Example 2
rows = 1columns = 1return = 1The start is already the destination, so the empty sequence is the single route.
Example 3
rows = 1columns = 5return = 1Every step must go right, giving exactly one route.
Example 4
rows = 25columns = 40return = 156655690918541325Choose positions of the 24 down moves among 63 steps: C(63,24)=156655690918541325. This odd integer exceeds the exact-integer range of an IEEE 754 double, so keep the count in signed 64-bit arithmetic.
Constraints
- For this exercise, assume
1 <= rows <= 25and1 <= columns <= 40. - The largest result is
156655690918541325, which fits a signed64-bit integer. - Do not use floating-point rounding to count routes.
More IMC Trading Phone Screen questions
- Election District Budget Allocation AnalysisPHONE SCREEN · Seen Aug 2026
- Uniform Variables: Smaller Below Larger SquaredPHONE SCREEN · Seen Mar 2026
- Combination Sum with Unlimited ReusePHONE SCREEN · Seen Dec 2025
- Valid Range of a Three-Outcome Probability ParameterPHONE SCREEN · Seen Dec 2025
- Expected Fishing CatchPHONE SCREEN · Seen Dec 2025
- Expected City Arrival and Return DaysPHONE SCREEN · Seen Nov 2024
- Stationary City Population SharesPHONE SCREEN · Seen Nov 2024
- Maximum Falling Path SumPHONE SCREEN · Seen Nov 2024
- Trading Profit Percentage ChangePHONE SCREEN · Seen Feb 2024
- Poker Suit Expected ProfitPHONE SCREEN · Seen Sep 2023
Similar questions at other companies
- Biased Coin: Probability of Exactly h HeadsAkuna Capital · PHONE SCREENAkuna Capital interview questions
- Probability of Consecutive HeadsSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
- Heads in Fair Coin FlipsJane Street · PHONE SCREENJane Street interview questions
- Strictly More Heads with Fewer CoinsSusquehanna International Group (SIG) · PHONE SCREENSusquehanna International Group (SIG) interview questions
- Count Clean Attendance LogsRippling · PHONE SCREENRippling interview questions
- Count Array DerangementsInMobi · PHONE SCREENInMobi interview questions
- Count Staircases with Strictly Increasing StepseBay · ONSITE INTERVIEWeBay interview questions
- Count Nondecreasing Digit-Sum ArraysMicrosoft · OAMicrosoft interview questions
- Stable Workload Redistribution TreesTower Research Capital · OA
- Count Valid A-B-C Sequences Under a Modulo-Four RuleInfosys · OAInfosys interview questions