# Interview Questions

This category contains few tricky questions asked in interviews..

## Preserve indices while sorting array

Introduction This is a request from one of the readers. This is mostly useful in competitive programming where you want to sort an array by the values, but at the same time the requirement is to preserve the index of each element. If I have to explain using an example, then consider the array below. The array is zero indexed. The first two rows represent the input array and indices of each element in the array. The next two rows represent the sorted array, but the moment you sort it, the index for each element changes. Earlier A was at index 4 but in the sorted array it is at index ...

## Print all paths of robot through the grid

Introduction This is a supplement to the previous post where we were interested in just one path of a robot from top left corner to the bottom right corner. In this post we will print all paths of robot moving through a given grid containing few blocked cells. The algorithm for this solution remains the same, we just need few tricks to get that right. Here, I will explain the idea behind printing all paths of robot through the grid. Approach Here, let us discuss what different we need to do to print all the paths. As we can recall from the previous post, the moment we reached the destina...

## Find Path through grid – constrained motion

Introduction This is another addition to the backtracking series of problems. The problem is asked in many interviews in many different forms. Here are few of them: Given a grid where few of the cells are blocked. You have a robot placed at the top left corner of the grid. Find path through grid such that the robot starts from the top left corner and moves to the bottom right corner. Another form just asks for all possible paths from one cell to another into a grid. Of course there are constraints on the movement of the robot, else you would end up going in circles and the paths wo...