Back
Close

The lost child.Episode-1

Statement

 Goal

The 12 year old child has lost his mother and now he wants to meet his mother. He can move horizontally or vertically but not diagonally. In order to help him you have to tell him the exact shortest distance. Each block = 10km.
Input
10 lines: A string row for one row of the map, which consists of the following characters only:
. means a road where the child can move.
# means a wall that the child cannot pass through.
M is the position of the mother.
C is the position of the child.
Output
Line 1: An integer for the shortest distance which the child has to travel in order to reach his mother, followed by km.
Constraints
There will always be a solution.
Example
Input
..........
M....C....
..........
..........
..........
..........
..........
..........
..........
..........
Output
50km

Tags
Pathfinding2D arrayBFS

Difficulty
Medium

Test cases
Lost in playground Test
Input
.......... M....C.... .......... .......... .......... .......... .......... .......... .......... ..........
Output
50km

Validator 1 Validator
Input
.......... M......... .C........ .......... .......... .......... .......... .......... .......... ..........
Output
20km

Lost in paris Test
Input
.......... M#........ #C##...... .......... .......... .......... .......... .......... .......... ..........
Output
120km

Validator 2 Validator
Input
.......... .#M....... #C##...... .......... .......... .......... .......... .......... .......... ..........
Output
80km

Lost in jungle Test
Input
########## #...#C...# #...##...# ###.#..### #.##M#...# #.....#..# #.....#..# #.....#..# #........# ##########
Output
160km

Validator 3 Validator
Input
########## #...#C...# #...##...# ###....### #M##.#...# #.....#..# #.....#..# #.....#..# #........# ##########
Output
110km

Lost in Maze Runner Test
Input
########## #..M#C...# #...##...# ###..#.### #.##.#...# #.....#..# #.....#..# #.....#..# #........# ##########
Output
200km

Validator 4 Validator
Input
########## #..M#C...# #...##...# #.#..#.### #.####...# #.....#..# #.....#..# #.....#..# #........# ##########
Output
240km

Lost in Space Test
Input
########## #...#....# #.C.#.#..# ###.#..### #M#......# #.###.#..# #.#....#.# #..#.##..# #........# ##########
Output
170km

Validator 5 Validator
Input
########## #...#....# #.C...#..# ###.#..### #M##.#...# #...#.#..# #.....#..# #.....#..# #........# ##########
Output
210km

Solution language

Solution

Stub generator input