You are given a grid of size n*n, a starting point, and an ending point. There are some cells in the grid which are permanently blocked. There are two other types of cells - key and lock. You cannot go into a lock cell until you have found its key in the grid. It is guaranteed that there is a unique key for each lock. All other cells are open. Find the shortest path from starting to ending position.