Robot Return to Origin
Real-world version: Shuttle Back On The DockThe statement here is our own: the same inputs, outputs and technique.
A floor shuttle in a parts warehouse begins parked on its charging dock and then plays back a tape of single-letter steps, moves, one step per letter, each step covering one tile:
'U'moves it one tile up the aisle,'D'moves it one tile down the aisle,'L'moves it one tile to the left,'R'moves it one tile to the right.
The floor is unobstructed, so every step is carried out exactly as written and the shuttle may pass over the dock tile as often as it likes mid-tape.
Return true when the shuttle is sitting on the dock tile once the whole tape has been played back, and false when it stops anywhere else.
Examples
Example 1
- Input
- moves = "RRLL"
- Output
- true
Two steps right then two steps left leave the shuttle on the dock tile, so the answer is true.
Example 2
- Input
- moves = "RRUL"
- Output
- false
The shuttle finishes one tile to the right of the dock and one tile up the aisle from it, so it is not parked.
Example 3
- Input
- moves = "ULDR"
- Output
- true
The shuttle walks a small loop, passing three other tiles, and its last step puts it back on the dock.
Example 4
- Input
- moves = "D"
- Output
- false
A single step down the aisle leaves the shuttle one tile away from the dock.
Constraints
- 1 <= moves.length <= 2 * 10^4
- moves only contains the characters 'U', 'D', 'L' and 'R'.
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def ends_on_dock(tape: str) -> bool:public boolean endsOnDock(String tape)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 9 test cases: 9 passed
- Passed: 4 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's