✅ ✅93.94% faster || Most Optimal || w/ Complete Explanation ||✅ ✅ C++ || Easy to Understand
Where Will the Ball Fall - MOST OPTIMAL SOLUTION w/ COMPLETE EXPLANATION ||  \u2705[ C++ ] \u2705|| EASY TO UNDERSTAND || \n\nPlease upvote if you like it. Upvo
## Where Will the Ball Fall - MOST OPTIMAL SOLUTION w/ COMPLETE EXPLANATION ||  \u2705[ C++ ] \u2705|| EASY TO UNDERSTAND || \n\n*Please upvote if you like it. Upvote costs nothing* \uD83D\uDE0E\n\n### EXPLANATION:\n![image](https://assets.leetcode.com/users/images/ddfc46ea-3bbd-4be6-ba50-bd0262f59757_1667280623.9965203.png)\n![image](https://assets.leetcode.com/users/images/7af20529-bcc2-4ebd-9a9c-57a0c1bc33f9_1667280663.5865903.png)\n![image](https://assets.leetcode.com/users/images/c3d092cb-d072-4f61-be8d-833ef7b0bfb8_1667280700.6527362.png)\n![image](https://assets.leetcode.com/users/images/fe196afa-8301-4ad5-8aeb-33dd92a179f2_1667280716.0740366.png)\n\n##### **Time Complexity : O(M X N)**-----> For each ball traversing array\n##### **Space Complexity : O(N)**  ---->Costant space\n##\n### **</>CODE :**\n### \n```\nclass Solution\n{\npublic:\n    vector<int> findBall(vector<vector<int>> &grid)\n    {\n        int row = grid.size();\n        int col = grid[0].size();\n        vector<int> ans(col, -1);\n        for (int j = 0; j < col; j++)\n        {\n            int ballPosition = j;\n            int i = 0;\n            while (i < row)\n            {\n                if (grid[i][ballPosition] == 1)\n                {\n                    if (ballPosition + 1 == col) // WALL BLOCK CONDITION  Case IV\n                    {\n                        break;\n                    }\n                    else if (grid[i][ballPosition + 1] == -1) // ADJACENT COLUMN CONDITION  Case I\n                    {\n                        break;\n                    }\n                    ballPosition++; // ball moves to right\n                }\n                else\n                {\n                    if (ballPosition - 1 < 0) // WALL BLOCK CONDITION  Case III\n                    {\n                        break;\n                    }\n                    else if (grid[i][ballPosition - 1] == 1) // ADJACENT COLUMN CONDITION  Case II\n                    {\n                        break;\n                    }\n                    ballPosition--; // ball moves to left\n                }\n                i++;\n            }\n            if (i == row)\n            {\n                ans[j] = ballPosition;\n            }\n        }\n        return ans;\n    }\n};\n```\n![image](https://assets.leetcode.com/users/images/18869958-84a2-4749-8598-62fd1fe15366_1667281221.5670905.png)\n\n\n\n\n\n\n\n\n\n\n\n
['C', 'Simulation']