Teleporter Board: Can You Finish?
Updated
Problem statement
Given a board game with teleporters, return true if a player starting on square start can reach square lastSquare in some number of turns, and false otherwise.
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.
You may choose any die roll on every turn. Teleporters can send you backward, so some squares may lead only to loops.
Function
finishable(teleporters: String[], dieSides: int, start: int, lastSquare: int) → booleanExamples
Example 1
teleporters = ["10,8","11,5","12,7","13,9"]dieSides = 4start = 0lastSquare = 20return = falseWith a 4-sided die you cannot jump past squares 10 to 13, and each of them sends you back. You never get past square 13.
Example 2
teleporters = ["10,8","11,5","12,7","13,9","2,15"]dieSides = 4start = 0lastSquare = 20return = trueRoll 2 from square 0 to land on 2 and teleport to 15. From there you can walk to 20.
Example 3
teleporters = ["10,8","11,5","12,7","13,9","2,15"]dieSides = 4start = 9lastSquare = 20return = falseFrom square 9 every path still runs into the teleporters at 10 to 13, and you cannot get back to square 2.
Example 4
teleporters = ["10,8","11,5","12,1","13,9","2,15"]dieSides = 4start = 9lastSquare = 20return = trueExample 5
teleporters = ["2,4","9,8","11,7","12,6","18,14","19,16","20,9","21,14","22,6","23,26","25,10","28,19","29,27","31,29","38,33","39,17","41,30","42,28","45,44","46,36"]dieSides = 4start = 0lastSquare = 50return = falseExample 6
teleporters = ["2,4","9,8","11,7","12,6","18,14","19,16","20,9","21,14","22,6","23,26","25,10","28,19","29,27","31,29","38,33","39,17","41,30","42,28","45,44","46,36"]dieSides = 6start = 0lastSquare = 50return = trueExample 7
teleporters = ["4,21","11,18","13,17","16,17","18,21","22,11","26,25","27,9","31,38","32,43","34,19","35,19","36,39","38,25","41,31"]dieSides = 4start = 0lastSquare = 50return = trueExample 8
teleporters = ["4,21","11,18","13,17","16,17","18,21","22,11","26,25","27,9","31,38","32,43","34,19","35,19","36,39","38,25","41,31"]dieSides = 2start = 0lastSquare = 50return = falseConstraints
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
- Shortest Pin Path Through TopicsPinterest · PHONE SCREENPinterest interview questions
- Word Chain Jumps in a GridGoogle · PHONE SCREENGoogle interview questions
- Linked Merchants Within Two HopsStripe · PHONE SCREENStripe interview questions
- Currency Conversion RateAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Route Graph Reachability with a Broken LinkFigma · PHONE SCREENFigma interview questions
- Minimum Currency ConversionsEPAM · PHONE SCREENEPAM interview questions
- Finite Web CrawlerMongoDB · PHONE SCREEN · ONSITE INTERVIEWMongoDB interview questions
- Currency Conversion RateBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Clone a Connected GraphAbridge · PHONE SCREENAbridge interview questions
- Rule References: Validity and EligibilityPlaid · PHONE SCREENPlaid interview questions