Ctrl K

Robot Back on Old Ground

Easy
A robot vacuum starts at (0, 0) on a grid floor and follows route, a string of commands. Each command moves it one cell: 'N' north, 'S' south, 'E' east, 'W' west. Return True if at some moment the robot stands on a cell it has already visited (the starting cell counts), and False if every cell on the route is new.
Example 1
route="NNEESW" → False

The robot visits (0,1), (0,2), (1,2), (2,2), (2,1), (1,1) — all different.

Example 2
route="ENWS" → True

Four steps around a square bring the robot back to its start (0,0).

Example 3
route="WE" → True
Constraints
  • 1 ≤ len(route) ≤ 10⁵
  • route contains only 'N', 'S', 'E' and 'W'
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsValue of a Roman Numeral EasySame Letter Cipher EasySame Letters, Reshuffled EasySame When Flipped EasyShuffle Into a Palindrome Easy
loading Python…
Input
route="NNEESW"
Expected
False

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