Trapping Rain Water Problem ( LeetCode #42 ) Part-1 | FREE DSA Course in JAVA | Lecture 72

Поділитися
Вставка
  • Опубліковано 8 лют 2023
  • This is a popular Leetcode question asked in many product-based companies like Google, Facebook, and Salesforce.
    The question reads out:-
    Given n non negative integers representing an elevation map where the width of each bar is 1. Calculate how much water it can trap after raining.
    So basically we have to find out how many units of water will be stored with the given arrangement of bars in form of an array.
    There are certain observations you can make some base conditions
    1. There should be minimum of three bars
    2. Increasing bars will not store any water
    3. Decreasing water will not store any water
    4. 1st and last bar will not store any water
    So you can use them to directly return 0 as the answer.
    Check out the complete lecture to know the complete solution to the program to find the trapped rain water.
    For more information, fill this form: forms.gle/8eiUmM92Fx563Aen9
    or call us at 8884881203
    Facebook: / thetapacademy
    Instagram: / tapacademy_online
    Linkedin: / 73820805
    Website: www.thetapacademy.com​
    #java #javaarray #array #arrayjava #javaprogramming #programming #programmer

КОМЕНТАРІ • 23

  • @pallavisharma8169
    @pallavisharma8169 Рік тому +7

    Seriously, i have learnt from many youtube channels but the way you explain concepts, i gurauntee no one can. Even this DSA series is far better than the paid courses.
    You are doing extremely well. Thank you so much, you are a great teacher.👍

  • @Niftymatics
    @Niftymatics 2 місяці тому +1

    Bayya, You are the only teacher who is dedicating more than paid teachers.

  • @sandeepamarnath3295
    @sandeepamarnath3295 Рік тому +2

    Oh my god! So nicely explained. Best way to teach coding I think. Subscribed to your channel and shared to my friends bro!

  • @great.Indian.culture
    @great.Indian.culture Рік тому +3

    Incredible explanation wow 🎉🎉🎉

  • @Lakshya_Agrahari
    @Lakshya_Agrahari 6 місяців тому +1

    Best explanation

  • @PrashantKumar-fk8le
    @PrashantKumar-fk8le 10 місяців тому +1

    Amazing Explaination 👑👑

  • @Welcomereddy
    @Welcomereddy 4 місяці тому

    best explanation ever

  • @sayanroy3159
    @sayanroy3159 9 місяців тому

    Excellent explanation sir ❤
    Best explanation ever .. after kunal kushwaha this is the best course

    • @fredmhiche3614
      @fredmhiche3614 4 місяці тому

      I find Rohit is far ahead of Kunal Kushwaha

  • @user-yu1og4hs7h
    @user-yu1og4hs7h 8 місяців тому

    🥰🥰

  • @sharanya_sr
    @sharanya_sr 9 місяців тому +2

    In the animation code, Result variable should be out of the forloop. It is getting overridden in every iteration.

  • @himanshushaw5689
    @himanshushaw5689 11 місяців тому +1

    Sir what is the midddle bar is greater than the left as well as the right bar, when there will be total number of 3 bars.

  • @vijik3959
    @vijik3959 7 місяців тому

    Sorry for asking this. Are you anirudh ravichandar's brother? Your voice and appearance same as him. Kudos to you and your team. Vera level teaching ♥️. Soon you will teach 1M I'm one of them.

  • @amanruhela3199
    @amanruhela3199 Рік тому +2

    Sir, some issues with the recorded voice.

  • @Maqsood1005
    @Maqsood1005 Рік тому +3

    Sir,
    your code run this my pc to execute output written 7

    • @ShivKumar-py4oe
      @ShivKumar-py4oe Рік тому

      what r u saying?
      explain properly

    • @Maqsood1005
      @Maqsood1005 Рік тому

      @@ShivKumar-py4oe my output written by 7

    • @technicaroabhi8442
      @technicaroabhi8442 11 місяців тому

      @@ShivKumar-py4oe answer from your code gives output 7 whereas required output is 9 on leetcode

  • @abhimanisangam79
    @abhimanisangam79 Рік тому +1

    What happened

  • @jackfrost8969
    @jackfrost8969 10 місяців тому

    time complexity is O(n2) as there is a loop inside a loop.
    This is more optimal and is in O(n).
    Using JavaScript:
    const input = [3, 1, 2, 4, 0, 1, 3, 2];
    const input2 = [4, 2, 0, 3, 2, 5];
    const input3 = [4];
    const getTrappedWater = (input) => {
    let leftGreatestValue = input[0];
    let rightGreatestValue = input[input.length - 1];
    let leftArray = [];
    let rightArray = [];
    input.map((e) => {
    leftGreatestValue = Math.max(e, leftGreatestValue);
    leftArray.push(leftGreatestValue);
    });
    for (let i = input.length - 1; i >= 0; i--) {
    rightGreatestValue = Math.max(input[i], rightGreatestValue);
    rightArray.unshift(rightGreatestValue);
    }
    let trappedWater = 0;
    leftArray.map((value, index) => {
    trappedWater +=
    Math.min(leftArray[index], rightArray[index]) - input[index];
    });
    return trappedWater;
    };
    console.log(getTrappedWater(input));
    console.log(getTrappedWater(input2));
    console.log(getTrappedWater(input3));

  • @sumitpatil5516
    @sumitpatil5516 3 місяці тому

    Bro takes 36 minutes and ended after finding brute force solution 🤡