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
/*** 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