Ctrl K

Drone Back on the Pad

Easy
A drone takes off from a landing pad at (0, 0) and flies over a grid. Its route is the string path, where each letter is one step to a neighbouring cell: - U means up, - D means down, - L means left, - R means right. The way the drone is facing does not matter: a letter always moves it exactly one cell in that direction. Return True if the drone is back over the pad once the whole route is flown, and False otherwise.
Example 1
path="URDL" → True

The drone flies around a square (up, right, down, left) and ends where it took off.

Example 2
path="UUD" → False

Two steps up and only one down leave the drone one cell above the pad.

Example 3
path="RRLLDU" → True
Constraints
  • 1 ≤ len(path) ≤ 2·10⁴
  • path contains only the letters U, D, L, R
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsSum of Binary Strings EasyCounting Off by Threes and Fives EasyAdding Long Numbers in Strings EasySame Text After Erasing EasyAlphabet Code Digit Rounds Easy
loading Python…
Input
path="URDL"
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 115 tests on the server, hidden ones included.