Water collected between towers

后端 未结 26 1193
无人共我
无人共我 2020-12-22 16:51

I recently came across an interview question asked by Amazon and I am not able to find an optimized algorithm to solve this question:

You are given an input array wh

26条回答
  •  难免孤独
    2020-12-22 17:26

    /*** Theta(n) Time COmplexity ***/
            static int trappingRainWater(int ar[],int n)
            {
                int res=0;
                int lmaxArray[]=new int[n];
                int rmaxArray[]=new int[n];
                lmaxArray[0]=ar[0];
                for(int j=1;j=0;j--)
                {
                    rmaxArray[j]=Math.max(rmaxArray[j+1], ar[j]);
                }
                for(int i=1;i

提交回复
热议问题