Company: ION

Difficulty: medium

Problem Statement

You start on a 2D grid at (startX, startY) and want to reach (endX, endY) . You are given a string directions of length n , where each character specifies the allowed movement direction at that second: 'E' : move to (x + 1, y) 'W' : move to (x - 1, y) 'N' : move to (x, y + 1) 'S' : move to (x, y - 1) At the i th second, you may choose one of the following: Move one unit in the direction given by directions[i] Stay at your current position Determine the earliest time (in seconds) at which you can reach (endX, endY) . If it is not possible to reach the target within the n seconds covered by directions , return -1 . If you already start at the target, the answer is 0 . Input Format The first line contains the string directions . The second line contains the integer startX . The third line contains the integer startY . The fourth line contains the integer endX . The fifth line contains the integer endY . Output Format Print a single integer — the earliest second at which (endX, endY) can b

More ION OA questionsInterview experiences