Python | Two Pointers
Algorithm\n1. Create a skeleton matrix with the number of rows and columns interchanged.\n2. Rotate the box -> matrix\n3. Iterate through each column and use tw
# Algorithm\n1. Create a skeleton matrix with the number of rows and columns interchanged.\n2. Rotate the box -> matrix\n3. Iterate through each column and use two pointers in bottom-up fashion to seach for stone and blanks.\n4. Throughout the entire iteration the points to be kept in mind are:\n\t* \tThe index for stone must be lesser than the index of the blank\n\t* \tSearch for stone and blanks independently\n\t* \tIf while searching for the stone, an obstacle is found make the search for blanks from that index\n\n**NOTE**: The variables **\'stone\'** and **\'blank\'** are keeping track of the **indices** for stone and blank respectively.\n\n# Code\n```\n        matrix = []\n        rows, cols = len(box), len(box[0])\n        \n\t\t# Creation of the new matrix skeleton\n        for col in range(cols):\n            temp = []\n            for row in range(rows):\n                temp.append(" ")\n            matrix.append(temp)\n        \n\t\t# Rotating the box\n        for row in range(cols):\n            for col in range(rows):\n                matrix[row][col] = box[rows - col - 1][row]\n        \n        rows, cols = cols, rows\n        \n\t\t# Main logic\n        for col in range(cols):\n            blank, stone = rows - 1, rows - 1\n\t\t\t# Iterating till all the rows are iterated over\n            while stone >= 0:\n\t\t\t\t# Iterating the column bottom-up till a stone is found\n                while stone >= 0 and matrix[stone][col] != \'#\':\n\t\t\t\t\t# If an obstacle is found make its previous index the starting point for the search for blanks\n                    if matrix[stone][col] == \'*\':\n                        blank = stone - 1\n                    stone -= 1\n\t\t\t\t# Iterating the column bottom-up till a blank is found\n                while blank >= 0 and matrix[blank][col] != \'.\':\n                    blank -= 1\n\t\t\t\t# Check for the index values for out of bounds and mainly if the index for stone is lesser than the index for blank\n                if blank >= 0 and stone >= 0 and stone < blank:\n                    matrix[blank][col], matrix[stone][col]  = matrix[stone][col], matrix[blank][col]\n                stone -= 1\n        return matrix\n```
['Two Pointers', 'Python', 'Python3']