Count Bounded Diagonal Grid Paths
Updated
Problem statement
Start at cell (0, 0) in a grid with width columns and height rows. Every move advances to the next column and changes the row by -1, 0, or 1; moves outside rows 0 through height - 1 are invalid. Return two counts: all paths that end at (width - 1, 0), and the paths among them that pass through (passX, passY).
Function
countBoundedGridPaths(width: int, height: int, passX: int, passY: int) → long[]Examples
Example 1
width = 4height = 3passX = 1passY = 1return = [4,2]There are four bounded paths to the destination, and two of them pass through row one in column one.
Example 2
width = 1height = 1passX = 0passY = 0return = [1,1]The empty path is the only route and passes through the single cell.
Constraints
1 <= width <= 301 <= height <= 300 <= passX < width0 <= passY < heightboth returned counts fit signed 64-bit integers
More Google Phone Screen questions
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
- Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
- Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Logger Rate Limiter with Every-Arrival HistoryPHONE SCREEN · Seen Nov 2026
Similar questions at other companies
- Unique Grid PathsMorgan Stanley · PHONE SCREENMorgan Stanley interview questions
- Count Starts Reaching a Grid MaximumDuolingo · PHONE SCREENDuolingo interview questions
- Find Robots by Blocker DistancesUber · PHONE SCREENUber interview questions
- Factory Cost — Minimum Cost Across StagesStripe · PHONE SCREENStripe interview questions
- Path Through an O/X Grid Using Only Right and DownAmazon · PHONE SCREEN
- 3D Grid Diagonal Walk ProbabilityApple · PHONE SCREENApple interview questions
- Maximum Rocks on a North-or-East Grid PathGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
- Maximal SquareAirwallex · PHONE SCREENAirwallex interview questions
- Maximal SquareSalesforce · PHONE SCREENSalesforce interview questions
- Maximum Grid Path ScoreDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions