Discover the best answers to your questions with the help of IDNLearn.com. Get the information you need from our community of experts who provide accurate and thorough answers to all your questions.
You need to get to the mall to buy some new shoes, but you're not sure how to get there. Your city is a n×m rectangular grid of blocks, where your home is located at the coordinates (x1,y1) and the mall's location is (xz,y2). Since you're not sure exactly how to get to the mall, you follow a movement strategy based on these rules: - Move diagonally on each move, starting in the direction (+1,+1). It means that standing at a cell with coordinates ( x, y ) , you'll move to the cell with coordinates (x+1,y+1) unless the new cell is outside the city grid, - If the current move would take you outside the city grid, come back and reverse the direction that was leading outside the grid (eg: if the x coordinate is outside the grid, reverse the x movement direction), - If the current move would escape the city grid outside of a corner, reverse both directions. Your task is to determine how many steps it will take to reach the mall at (x2,y2). Return −1 if it's not possible to reach the mall using this strategy.
Sagot :
Thank you for participating in our discussion. We value every contribution. Keep sharing knowledge and helping others find the answers they need. Let's create a dynamic and informative learning environment together. Your questions deserve reliable answers. Thanks for visiting IDNLearn.com, and see you again soon for more helpful information.