Count Rightward Grid Paths
Updated
Problem statement
A board has rows rows and columns columns. Start at [startRow,0] and reach [endRow,columns-1].
Each move advances one column right and changes the row by -1, 0, or +1. The row must stay inside the board.
Return the number of distinct paths modulo 1,000,000,007.
Function
countRightwardPaths(rows: int, columns: int, startRow: int, endRow: int) → intExamples
Example 1
rows = 3columns = 3startRow = 2endRow = 2return = 2The row sequences are 2-1-2 and 2-2-2.
Example 2
rows = 1columns = 4startRow = 0endRow = 0return = 1Only straight-right moves stay in the one-row board.
Example 3
rows = 2columns = 2startRow = 0endRow = 1return = 1One down-right move reaches the target.
Constraints
1 <= rows, columns <= 100000.0 <= startRow, endRow < rows.rows * columns <= 2,000,000.
More Google Onsite Interview questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Assign Escalations to TeamsAmazon · ONSITE INTERVIEW
- Knight Probability in ChessboardGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
- Maximum All-Ones Square Side LengthOmnissa · ONSITE INTERVIEWOmnissa interview questions
- Enumerate Right-and-Down Matrix PathsOracle · ONSITE INTERVIEWOracle interview questions
- Maximal Square AreaUber · ONSITE INTERVIEWUber interview questions
- Minimum Path SumMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Maximum Grid Path ScoreDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
- Minimum Path SumBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Bomb Enemy Best CoordinatesSambaNova Systems · ONSITE INTERVIEWSambaNova Systems interview questions
- Maximum Falling Path Sum in a RectanglePeopleStrong · ONSITE INTERVIEWPeopleStrong interview questions