Web appOpen in Telegram

PostTrapRainWater Code time complexibilty O(n)

4 July 2025
<
</> ᴍᴜᴋᴇsʜ </>
TrapRainWater Code time complexibilty O(n) public class traprainwat { public static int trapwater(int height[]) { // left max int n = height.length; int leftMax[] = new int[n]; leftMax[0] = height[0]; for (int i = 1; i < n; i++) { leftMax[i] = Math.max(height[i], leftMax[i - 1]); } // for (int i = 0; i < n; i++) { // System.out.print(leftMax[i]); // } // right max int rightMax[] = new int[n]; rightMax[n - 1] = height[n - 1]; for (int i = n - 2; i >= 0; i--) { rightMax[i] = Math.max(rightMax[i + 1], height[i]); } // for (int i = 0; i < rightMax.length; i++) { // System.out.print(rightMax[i]); // } // loop int traprainw = 0; for (int i = 0; i < n; i++) { // waterlevel=min(leftmax,rightmax) int waterlevel = Math.min(leftMax[i], rightMax[i]); // traprainwater=waterlevel-height[i] traprainw += waterlevel - height[i]; } return traprainw; } public static void main(String[] args) { int height[] = { 4, 2, 0, 6, 3, 2, 5 }; System.out.println(trapwater(height)); } } Output: 11
5 · 2.7K ·

Nearby in the feed

<</> ᴍᴜᴋᴇsʜ </>Maximum Subarray sum using Kadane's Algorithm. import java.util.*; public class Kadane { public static void kaddanelgoSum(int numbers[]) { int currsum = 0; int रराम सियाराम सियाराम जय जय राम 🙏 तुम साथ हो जो मेरे, किस चीज की कमी है ।Poll
this message
<</> ᴍᴜᴋᴇsʜ </>Best time to buy /sell any stock public class buysell { public static int buySellStock(int prices[]) { int MaxProfit = 0; int buyPrice = Integer.MAX_VALUE; for रराम सियाराम सियाराम जय जय राम 🙏 तुम साथ हो जो मेरे, किस चीज की कमी है ।Join @LogicBots For Getting Updates of our bots Sujjestion for new bot Sujjestion for new features https://t.me/logicBots
JJava Codes Basic to AdvanceJava Codes Basic to Advance@Java_Codes_Pro · channel · Tech
1 988subscribers213posts in the index
Venue feed Open in Telegram

An open public feed from the search index ChatCrawler — “Google for public Telegram”; refreshed as the venue is crawled. Times are UTC.

Public content only, official Telegram API. About · FAQ · What we do not do · Remove a page · Catalog · Search · How we count