Back to Browse

Arrays Series #14- Trapping Rainwater Problem- Intuition + Dry run + Live code - (Java)

2.0K views
Sep 19, 2022
11:18

Given an array arr[] of N non-negative integers representing the height of blocks. If width of each block is 1, compute how much water can be trapped between the blocks during the rainy season. Example 1: Input: N = 6 arr[] = {3,0,0,2,0,4} Output: 10 Explanation: Example 2: Input: N = 4 arr[] = {7,4,0,9} Output: 10 Explanation: Water trapped by above block of height 4 is 3 units and above block of height 0 is 7 units. So, the total unit of water trapped is 10 units. Example 3: Input: N = 3 arr[] = {6,9,9} Output: 0 Explanation: No water will be trapped. 👉👉Practice here - https://practice.geeksforgeeks.org/problems/trapping-rain-water-1587115621/1 https://leetcode.com/problems/trapping-rain-water/ ============================================================ Other playlists in the channel that you can follow: ➡️ Recursion Primer Series - https://www.youtube.com/playlist?list=PLBBK9G6O8MPApTdumRhSjPexLiml_Kb-e ➡️ String coding interview questions - https://www.youtube.com/playlist?list=PLBBK9G6O8MPA56acesslU-5l9zc3S9ctq ➡️ Arrays Series - https://www.youtube.com/playlist?list=PLBBK9G6O8MPDr9LdgV5HDmn9KGcTnOC9r ➡️Linked List Series - https://www.youtube.com/playlist?list=PLBBK9G6O8MPArEF-_qMwt_cmyxeSpNUv3 ➡️ Sorting Primer Series - https://www.youtube.com/playlist?list=PLBBK9G6O8MPDU-njw8UMtAx_fBwTpF20G ➡️ Binary Search Series - https://www.youtube.com/playlist?list=PLBBK9G6O8MPAFQ202maphKSugeWTRacsd ======================================================= Please click the LIKE button so that this kind of content can be seen by as many as possible aspiring engineers and professionals. Doing so gives me even more motivation to post such content in the future. Please comment below and let me know if you have any questions or concerns. Additionally, don't forget to click the bell symbol to receive notifications and subscribe to the channel. Follow us on: ➡️Twitter - https://twitter.com/CodeEase ---------------------------------------------------------- Created and Instructed by: Varsha Das Mid-senior Software Engineer, Content Curator of @Code With Ease ➡️ LinkedIn - https://www.linkedin.com/in/varsha-das-se/ ➡️ Quora - https://www.quora.com/profile/Varsha-Das-11 ➡️ Hashnode - https://varsha-das.hashnode.dev/ ➡️ Medium - https://medium.com/@varshadas21 Code With Ease is meant to make problem-solving in programming easier. For DSA preparation, we post topic-specific videos pertaining to Coding Interview topics so that everyone may approach such questions with a clear thought process and achieve the best outcomes. In addition, we make an effort to include different "Primer Series" that teach particular concepts or algorithms. We want to be the one-stop solution for everything pertaining to DSA preparation and programming foundations in general, saving candidates from having to visit many sources in order to receive structured content. Additionally, we believe that learning to code entails much more than only "cracking the coding interview." The long-term goal of this channel is to create more proficient problem-solvers in this field so that, in the end, we can create fantastic products and be able to resolve challenging issues in our environment to improve the quality of life for everyone. #trappingrainwater #rainwatertrappingproblem #codinginterviewquestions #coding #leetcodehard #arraysinjava trapping rain water problem in java trapping rain water problem trapping rain water a gallery with plants is divided into n parts, numbered 0, 1, 2, 3, ..., n-1. there are provisions for attaching water sprinklers in every division. a sprinkler with range x at division i can water all divisions from i-x to i+x. given an array gallery[] consisting of n integers, where gallery[i] is the range of the sprinkler at partition i (a power of -1 indicates no sprinkler attached), return the minimum number of sprinklers that need to be turned on to water the entire gallery. if there is no possible way to water the full length using the given sprinklers, print -1. rainwater trapping problem

Download

0 formats

No download links available.

Arrays Series #14- Trapping Rainwater Problem- Intuition + Dry run + Live code - (Java) | NatokHD