Back to Practice
#0208
Direction Sense: Final Position
EasyAptitude15 min10 XP
Problem
A person walks 4 km south, then 3 km east, then 1 km north. How far and in which direction is he from the starting point?
Why This Matters
Direction questions become simple coordinate problems when every move updates x or y.
Examples
Example 1
InputSouth 4, East 3, North 1
Output3 * sqrt(2) km southeast
Net movement is 3 km east and 3 km south, so distance is sqrt(3^2 + 3^2).
Constraints
- Return the exact requested result.
- Handle common edge cases.
- Keep the solution readable before optimizing.
CodeReasoning
A person walks 4 km south, then 3 km east, then 1 km north. How far and in which direction is he from the starting point?
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core example
InputSouth 4, East 3, North 1
Expected3 * sqrt(2) km southeast
Net movement is 3 km east and 3 km south, so distance is sqrt(3^2 + 3^2).
Hidden Test Categories
empty or minimal inputrepeated valueslarger realistic input