Teleporter Board: Squares After One Roll
Updated
Problem statement
Given a board game with teleporters, return every square a player can end on after exactly one turn, starting from square start.
The board has squares numbered 0 to lastSquare. Each string in teleporters has the form "from,to": a player whose move ends on square from is sent to square to, which may be ahead or behind.
One turn works like this:
- Roll a die that shows a number from
1todieSides. - Move forward that many squares. If that would pass
lastSquare, stop onlastSquare. - If you stop on a square with a teleporter, follow it. At most one teleporter is used per turn, even if the teleporter sends you to another teleporter square.
Return the distinct squares in ascending order.
Function
destinations(teleporters: String[], dieSides: int, start: int, lastSquare: int) → List<Integer>Examples
Example 1
teleporters = ["3,1","4,2","5,10"]dieSides = 6start = 0lastSquare = 20return = [1,2,6,10]Rolls of 1, 2 and 6 land on plain squares. A roll of 3 lands on 3 and goes to 1, 4 goes to 2, and 5 goes to 10. The distinct squares are 1, 2, 6 and 10.
Example 2
teleporters = ["5,10","6,22","39,40","40,49","47,29"]dieSides = 6start = 46lastSquare = 100return = [29,48,49,50,51,52]Example 3
teleporters = ["5,10","6,22","39,40","40,49","47,29"]dieSides = 10start = 0lastSquare = 50return = [1,2,3,4,7,8,9,10,22]Example 4
teleporters = ["6,18","36,26","41,21","49,55","54,52","71,58","74,77","78,76","80,73","92,85"]dieSides = 10start = 95lastSquare = 100return = [96,97,98,99,100]A roll of 5 lands on 100, and every larger roll would pass it, so it also stops on 100.
Example 5
teleporters = ["6,18","36,26","41,21","49,55","54,52","71,58","74,77","78,76","80,73","92,85"]dieSides = 10start = 70lastSquare = 100return = [58,72,73,75,76,77,79]Example 6
teleporters = ["97,93","99,81","36,33","92,59","17,3","82,75","4,1","84,79","54,4","88,53","91,37","60,57","61,7","62,51","31,19"]dieSides = 6start = 0lastSquare = 100return = [1,2,3,5,6]Example 7
teleporters = ["3,8","8,9","9,3"]dieSides = 6start = 0lastSquare = 20return = [1,2,4,5,6,8]A roll of 3 lands on the teleporter at 3 and goes to 8. Square 8 also has a teleporter, but only one teleporter is used per turn.
Constraints
1 <= lastSquare <= 10001 <= dieSides <= lastSquare0 <= start < lastSquare0 <= teleporters.length <= lastSquare- Each
teleporters[i]is"from,to"with1 <= from < lastSquare,0 <= to <= lastSquareandfrom != to. - No two teleporters start on the same square.
More WhatNot Phone Screen questions
- Adjacent Pair and Run RemovalPHONE SCREEN · Seen Nov 2026
- Merge Sorted Squares of Two ArraysPHONE SCREEN · Seen Nov 2026
- User Journey PathsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Knight Dialer SequencesPHONE SCREEN · Seen Oct 2026
- Reachable Exits in an Obstacle GridPHONE SCREEN · Seen Oct 2026
- Palindrome with One DeletionPHONE SCREEN · Seen Oct 2026
- Search a 2D MatrixPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Attraction Route Without Reusing TrailsPHONE SCREEN · Seen Sep 2026
- Earliest Car for Each PassengerPHONE SCREEN · Seen Sep 2026
- Minimum Stores for a Shopping ListPHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- Count Distinct Underwriting PII ValuesAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
- Bounded IPv4 FilterAmazon · PHONE SCREEN
- SimpleRDD Multiset IntersectionDatologyAI · PHONE SCREEN
- Vehicle Maintenance Event ReadinessWaymo · PHONE SCREENWaymo interview questions
- Summarize the Latest Event for Each DeviceOneTrust · PHONE SCREEN
- Project JSON Fields into a Target FormatBooking.com · PHONE SCREEN
- Employee Training StatusVanta · PHONE SCREEN
- Select Object by Key ExtremeBridge · PHONE SCREENBridge interview questions
- Group Names by DepartmentMastercard · PHONE SCREENMastercard interview questions
- AI Role: Collection with Add and Remove OperationsApple · PHONE SCREENApple interview questions