🥇 PYTHON  ||  EXPLAINED  ||  ; ]
UPVOTE IF HELPFuuL\n\nHERE I HAVE CREATED TWO SEPRATE FUNCTION , ONE FUNCTION COULD BE MADE , THIS IS JUST DONE FOR CLARITY.\n\nWe need to count the number of c
**UPVOTE IF HELPFuuL**\n\n**HERE I HAVE CREATED TWO SEPRATE FUNCTION , ONE FUNCTION COULD BE MADE , THIS IS JUST DONE FOR CLARITY.**\n\nWe need to count the number of cells from which waer could flow to both the oceans.\nWater can go to **left,top** for pacific and to **right,down** for atlantic.\n\n**APPROACH**\n\nWe just do what is asked for.\n\nWhen at cell ```ht[i][j]``` :\n* we check that water can flow to **left,top** and also to **right,down**.\n* It is similar to finding a path with non-increasing values.\n* To prevent repeation, we use memoization to store the result for certain ```ht[i][j]```.\n\n*How memoization helps :*\n* Let water can flow to both oceans from cell ```ht[i][j]```, so while checking for its adjacent cells, we need not find the complete path to oceans, **we just find a path that leads to a cell that reaches both oceans.**\n\n**Finding water can reach both oceans :**\n* As we going for memoization, we create two ```2-D array  for atlantic and pacific``` that stores that whether water can flow to ocean for each ocean respectively.\n* For pacific, we created ```pac``` and water initially water can flow for top and left cells.\n* For atlanic, we created ```atl``` and water initially water can flow for bottom and right cells.\n* Then for each cell, we check whether water flows off :\n* * For cell ```ht[i][j]``` we recurcively call for its adjacent cells, if neightbouring height is less or equal to current cell.\n* * Water can flow off if we reach a cell for which we already have solution.\n* * * For pacific we already made top,left cells ```true``` and same for atlantic.\n\n* Whenever water reaches, make all cells in that path ```true``` so they need not to be calculated in future.\n\n\n\n**UPVOTE IF HELPFuuL**\n\n*Here i created and pdated the memoization table first and calculated number of cells afterwards, can be combined to single step.*\n\n**PYTHOON**\n```\nclass Solution:\n    def pacificAtlantic(self, ht: List[List[int]]) -> List[List[int]]:\n        \n        def pac(i,j):\n            if rp[i][j]:\n                return True\n            k=False\n            h=ht[i][j]\n            ht[i][j]=100001\n            if ht[i-1][j]<=h:\n                k=k or pac(i-1,j)\n                \n            if ht[i][j-1]<=h:\n                k=k or pac(i,j-1)\n                \n            if i<m-1 and ht[i+1][j]<=h:\n                k=k or pac(i+1,j)\n                \n            if j<n-1 and ht[i][j+1]<=h:\n                k=k or pac(i,j+1)\n                \n            ht[i][j]=h\n            rp[i][j]=k\n            return k\n        \n        def ant(i,j):\n            if ra[i][j]:\n                return True\n            k=False\n            h=ht[i][j]\n            ht[i][j]=100001\n            if i>0 and ht[i-1][j]<=h:\n                k=k or ant(i-1,j)\n                \n            if j>0 and ht[i][j-1]<=h:\n                k=k or ant(i,j-1)\n                \n            if ht[i+1][j]<=h:\n                k=k or ant(i+1,j)\n                \n            if ht[i][j+1]<=h:\n                k=k or ant(i,j+1)\n                \n            ht[i][j]=h\n            ra[i][j]=k\n            return k\n        \n        m=len(ht)\n        n=len(ht[0])\n        rp=[[False for i in range(n)] for j in range(m)]\n        ra=[[False for i in range(n)] for j in range(m)]\n        \n        for i in range(m):\n            rp[i][0]=True\n            ra[i][-1]=True\n        for i in range(n):\n            rp[0][i]=True\n            ra[-1][i]=True\n        \n        for i in range(m):\n            for j in range(n):\n                pac(i,j)\n                ant(i,j)\n        res=[]\n        for i in range(m):\n            for j in range(n):\n                if rp[i][j] and ra[i][j]:\n                    res.append([i,j])\n        return res\n```\n\n![image](https://assets.leetcode.com/users/images/8cd20a0a-9ab1-456e-a5f3-69f05e67e3ed_1661908619.3639503.jpeg)\n
['Recursion', 'Python', 'Python3']