Distinct Positions After One Teleporter Board Roll
Updated
Problem statement
A board has squares numbered from 0 through lastNumber. You stand on startPosition and roll a die exactly once. The roll can be any integer from 1 through maxValue.
The roll moves you forward by its value. If that would take you past lastNumber, you stop on lastNumber instead.
Each string in teleporters has the form source,destination. If you land on a teleporter's source square, it moves you to its destination exactly once. The destination never sends you on through another teleporter. The square you start on does not teleport you before the roll. No two teleporters share a source, every square they name is on the board, and the final square is never a source.
Return every different square you can end on after this one roll, in increasing order. List each square once, even when several rolls end there, such as several rolls that stop on the final square. Do not modify the input.
Function
oneRollLandings(teleporters: String[], maxValue: int, startPosition: int, lastNumber: int) → int[]Examples
Example 1
teleporters = ["3,1","5,10","8,2"]maxValue = 6startPosition = 0lastNumber = 10return = [1,2,4,6,10]Rolls 1 through 6 finish at 1, 2, 1, 4, 10, and 6.
Example 2
teleporters = []maxValue = 6startPosition = 8lastNumber = 10return = [9,10]Roll 1 reaches 9. Roll 2 reaches 10 exactly. Larger rolls would go past the last square, so they stop on 10 too.
Example 3
teleporters = ["1,4","4,2"]maxValue = 1startPosition = 0lastNumber = 5return = [4]The landing at 1 moves to 4 once. The teleporter at 4 is not followed during this turn.
Constraints
1 <= lastNumber <= 1000,0 <= startPosition <= lastNumber, and1 <= maxValue <= lastNumber + 1.0 <= teleporters.length <= lastNumber.- Each string holds two nonnegative integers written in decimal digits, separated by one comma. It has no spaces, no signs, and no leading zeros, though
0itself is allowed. Each source is unique and lies in[0,lastNumber-1]. Each destination lies in[0,lastNumber].
More Atlassian Phone Screen questions
- Merge Overlapping IntervalsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Tennis Court SchedulingPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Implement a Rate LimiterPHONE SCREEN · Seen Oct 2026
- Longest Consistent Activity StreakPHONE SCREEN · Seen Sep 2026
- Music Player Operation SequencePHONE SCREEN · Seen Sep 2026
- Underline Shortest Unique SubstringsPHONE SCREEN · Seen Aug 2026
- Can a Dictionary Word Be Formed from Note Letters?PHONE SCREEN · Seen Feb 2026
- Word Path Moving Only Right or DownPHONE SCREEN · Seen Feb 2026
- Ordered Badge Entry and Exit ViolationsPHONE SCREEN · Seen Aug 2025
- Two Sum with an Ordered Index PairPHONE SCREEN · Seen Aug 2025
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
- Badge Records Without a MatchWhatNot · PHONE SCREENWhatNot interview questions