Hyundai Mobis Autonomous Driving System
InterviewTime limit1sMemory limit512 MB
Find the shortest path from the top-left to the bottom-right of a grid that visits at least one waypoint, using up to K uses of a 5x5 jump pattern.
- Level
Medium5 of 10
- Topics
- BFS, Shortest path, Graph
- Solved
- No attempts yet
Problem

At the Seosan test track of Hyundai Mobis, a mobility fitted with parts from the company's new autonomous driving system is undergoing driving tests. The system uses satellite imagery to recognize the area around the mobility and computes the shortest distance from its current position to the destination. The old system moved the mobility only up, down, left, and right. The new system moves it in those four directions and also with additional movement patterns. The system cannot keep communicating with the satellite, so the additional patterns cannot be used without limit.
Seungjun is testing this system to find the shortest distance from a fixed start at the top-left corner to a fixed final destination at the bottom-right corner, passing through at least one of the waypoints. The destination may itself be a waypoint, in which case visiting the waypoint counts as arriving at the destination. Given the map, the additional movement patterns, and the number of times each pattern may be used, write a program that finds the shortest distance from the start, through at least one waypoint, to the final destination.
A pattern is given as a array. The mobility is at row , column of the array. If the value at row , column is , the system can use a pattern that moves the mobility from row , column to row , column .
Input
The first line contains the height , the width , and the number of pattern uses .
The map has rows and columns. 0 is an empty cell, 1 is a wall, and 2 is a waypoint. The mobility cannot move onto a wall or outside the map. The start at the top-left cell is guaranteed to be 0.
The next 5 lines give the pattern array, with values 0 or 1.
Output
Print the shortest distance from the start, passing through at least one waypoint, to the destination. If the destination cannot be reached through at least one waypoint in any case, print -1.