Answer: BAE SYSTEMS Hiring | On-Campus OA (2022) | Path Crossing
Answer · Posted Jun 2026
Approach Start at coordinate (0,0). Store every visited position in a HashSet. Process each movement: N → y++ S → y-- E → x++ W → x-- If a position has already been visited, return true. If all moves are processed without revisiting a position, return false. Strategy Use a HashSet to store visited coordinates. Every move updates the current position. Checking whether a coordinate has already been visited takes O(1) time on average. Java Code import java.util.HashSet; import java.util.Set; ...
The full answer & interview discussion are available to premium members.
Log in Create a free account