Meesho Coding Question – Solved

3 Live
The city of Hackerland can be represented using a grid with n rows and m columns containing an empty cell represented by a '*' and a blocked cell represented by a #. Traveling is allowed only through empty cells. The people of Hackerland are required to travel from a starting cell defined by the character 'S' to an ending cell represented by a character 'E'. The people can jump a length of any integer k in all four directions from a given cell i.e. up, down, left, and right. However, if the jump length kis greater than 1, the next jump must be made in the same direction, For example, a hacker is allowed to jump 3 units towards the right, followed by 1 unit towards the right, and then 3 units towards the left. They however cannot jump 3 units towards the right followed by 1 unit towards the left as direction change is not allowed if the previous jump was of length greater than 1. Note that the last jump in any jump sequence is always of length 1. The jump can be made over a blocked cell as well as long as both starting and ending cells are empty. Given the map of Hackerland as a 2g matrix grid, that contains exactly one 'S' and 'E' each, find the minimum number of jumps required to travel from Sto E. Report -1 if it is not possible to reach E from S. Example Suppose n = 5, m = 6 and grid = ["S **** #". ******** ******* ******** " ***** E")

Asked in: Meesho

Image of the Question

Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| Given an n x m grid, where rows are numbered from 7 to n and columns from 1 to … |
| There are 'N' coders standing in a line, where i denotes the ith position of a … |
| A birthday party was attended by N number of kids, and each kid was given a uni… |
| Given a matrix of size m * n, where m denotes the number of rows (starting with… |
| A traveler is traveling from the city of Zeta to Omega. He starts with X amount… |
| As an operations engineer at Amazon, you are responsible for organizing the dis… |