Rain Water Trapped
Problem Given an array arr[] of N non-negative integers representing height of blocks at index i as A i where the width of each block is 1. Compute how much water can be trapped in between blocks after raining. Problem Constraints 1 <= |arr| <= 100000 Example Input Input 1: A = [0, 1, 0, 2] Input 2: A = [1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1] Example Output Output 1: 1 Output 2: 6 Question Link https://leetcode.com/problems/trapping-rain-water/ https://practice.geeksforgeeks.org/problems/trapping-rain-water/0 Solution We have to calculate the amount of water to be stored in between the blocks. Solution 1: Brute Force In Brute force approach, We do what it says in the question. For each element in the array, we find the maximum amount of water it can trap. we calculate the minimum of the maximum of left side and right side of the element. Algorithm Initialize res = 0 ; Iterate the array from left to right : Initialize left_max = Integer.MIN_VAL...