route one by one: N moves one cell up, S down, E right and W left.
Before it starts, you may replace at most edits characters of the route with any of these four commands.
Return the largest Manhattan distance from the origin that the robot can reach at any moment of the walk, not necessarily at the end. The Manhattan distance to (x, y) is |x| + |y|.route="NENSW", edits=1 → 4
Change the S to N to get NENNW. After the fourth step we are at (1, 3), distance 4.
route="EWEW", edits=0 → 1
With no edits we just swing between (0, 0) and (1, 0), so the best is 1.
route="SNSNWE", edits=2 → 5
route consists only of N, S, E, Wroute="NENSW", edits=1
4
Run checks the first 3 tests in your browser. Submit checks all 109 tests on the server, hidden ones included.