Minimum Operations to Reduce X to Zero | Dynamic Programming | Leetcode

แชร์
ฝัง
  • เผยแพร่เมื่อ 8 ม.ค. 2025

ความคิดเห็น • 54

  • @ankitsagar255
    @ankitsagar255 2 ปีที่แล้ว +12

    Anyone wondering if it's still giving TLE, please watch the complete video.. (y) 21:35

  • @IUKB
    @IUKB 4 ปีที่แล้ว +17

    I have been following your channel since leetcode monthly challenge started but never fully explored your channel. I was just watching videos whenever I had doubts about solving some problems. Today I explored all the playlists and checked the content. It's wonderful how you are contributing to the community. In the future, your channel will be one of the best resources for Interview preparation and particularly learning DS and algorithms(it still is but need more impact and viewers). Now I am going to suggest all my juniors to learn from this channel instead of buying any course. Best of luck and thanks for sharing such great content.

    • @techdose4u
      @techdose4u  4 ปีที่แล้ว

      Thanks for your motivation 🙂

    • @fffooccc9801
      @fffooccc9801 ปีที่แล้ว

      @@techdose4u can you tell me why it doesn't work
      int solve(int l,int r,vector &nums,int x){
      if(x

  • @hymnish_you
    @hymnish_you 4 ปีที่แล้ว +7

    I was wondering about the solution as I was getting TLE and here you are, I am so lucky to have you over youtube.

  • @sumitkeshari1461
    @sumitkeshari1461 4 ปีที่แล้ว +2

    When i saw this problem first time i approached it using recursion which is intuitive for this problem.. then i came here.. thank for this video....

    • @techdose4u
      @techdose4u  4 ปีที่แล้ว

      Nice. Welcome bro :)

  • @dhanashreegodase4445
    @dhanashreegodase4445 3 ปีที่แล้ว

    one of the best tutorial for Dp

  • @MaxCarliChannel
    @MaxCarliChannel 4 ปีที่แล้ว +5

    Not sure the x has a meaning in the calculation of the key for the memoization. If you have left and right indexes the x should always be the same.

  • @utkarshgupta2909
    @utkarshgupta2909 4 ปีที่แล้ว +10

    next video of playlist : th-cam.com/video/7nzwrX4N_A0/w-d-xo.html

  • @kruthikhm6379
    @kruthikhm6379 4 ปีที่แล้ว +3

    Sir for this I think we can take left pointer and right pointer and traverse array completely making hashmap of element and count if we find complementary elements we can find minimum count

    • @techdose4u
      @techdose4u  4 ปีที่แล้ว +1

      Yes that's the optimal approach

  • @kaushik.aryan04
    @kaushik.aryan04 ปีที่แล้ว

    is there a way to apply bottom up in this as memoization is giving tle

  • @ArifulIslam-im7wr
    @ArifulIslam-im7wr 4 ปีที่แล้ว +2

    Nice Explanation ❤❤❤

  • @abhinavbindra9274
    @abhinavbindra9274 2 ปีที่แล้ว

    recursion is intiuative in this questions ,but the memoization part can be thought only if you have already seen solution

  • @MahirHasancse21
    @MahirHasancse21 4 ปีที่แล้ว +3

    Can i use dp[left][right]=count in this manner to store minimum count?

  • @brennanfradelis9267
    @brennanfradelis9267 4 ปีที่แล้ว +2

    Nice explanation!

  • @duraik7602
    @duraik7602 4 ปีที่แล้ว +3

    This approach is giving TLE if we convert the approach to Java based. Any suggestion to resolve TLE?

    • @jaybisht8502
      @jaybisht8502 3 ปีที่แล้ว +3

      Watch the complete video

  • @surajitroy_roll-5023
    @surajitroy_roll-5023 3 ปีที่แล้ว +3

    Leetcode mein TLE a raha hain

  • @ankita1464
    @ankita1464 4 ปีที่แล้ว +1

    It would be great if you can upload leetcode weekly contest solutions

    • @techdose4u
      @techdose4u  4 ปีที่แล้ว

      I would love to, but I don't get time 😅

    • @ankita1464
      @ankita1464 4 ปีที่แล้ว

      Ok

  • @vidhyahariharan4035
    @vidhyahariharan4035 3 ปีที่แล้ว

    Can we use dp tabulatio method for this problem?

  • @vedantmondkar9963
    @vedantmondkar9963 4 ปีที่แล้ว +1

    @TECH DOSE Can't this problem be solved by making two dimensional table as u have made in your previous videos of DP??

    • @minhdang5132
      @minhdang5132 4 ปีที่แล้ว

      Is there any follow up?

  • @rishurana9655
    @rishurana9655 3 ปีที่แล้ว

    can greedy approch be used in this question?

  • @E__ShameemAhamedS
    @E__ShameemAhamedS 4 ปีที่แล้ว +1

    amazing sir!!

  • @arjunmallick4901
    @arjunmallick4901 3 ปีที่แล้ว

    Did not get as to why we need the count in making a unique key...could we form a unique state only using left+"*" +right (each are string) ??

    • @ganeshkamath89
      @ganeshkamath89 2 ปีที่แล้ว

      Hi Arjun, I think he has concatenated x, so that if user passes the same x multiple times, it will straight away hit memoization value. So successive calls of x will take very little time.
      If you take the solution for just one x value, it will not make sense. If this problem was a very small part of a large solution where this block is called multiple times with repeating x values, it will show the true usefulness of concatenating x.

  • @anushkathakur6531
    @anushkathakur6531 ปีที่แล้ว

    bhaiya yeh jo 2 base cases hain unko ooper neeche karne se toh test cases ke galat answer aa rhe hain...par aisa kyon ho rha hai line number 8 ki condition pehle aur line number 6 ki baad mein likhne se wrong output aa rha hai..

  • @pleasesirmorevideos4684
    @pleasesirmorevideos4684 4 ปีที่แล้ว

    it is better to use pair for memorization

  • @amitavamozumder73
    @amitavamozumder73 3 ปีที่แล้ว +1

    I did exactly this but still getting heap out of memory exception.

    • @techdose4u
      @techdose4u  3 ปีที่แล้ว

      Maybe out of bounds

  • @priyanshusingh8971
    @priyanshusingh8971 3 ปีที่แล้ว +1

    this is giving tle error although explanation is awesome

  • @akhilgaddam5128
    @akhilgaddam5128 2 ปีที่แล้ว

    it is similar to coin change problem 1

  • @harish_raghucollege8995
    @harish_raghucollege8995 ปีที่แล้ว

    can i get this code in python

  • @sagarjangra5274
    @sagarjangra5274 4 ปีที่แล้ว +1

    I submitted this question using greedy algorithm

    • @techdose4u
      @techdose4u  4 ปีที่แล้ว

      Nice :)

    • @sagarjangra5274
      @sagarjangra5274 4 ปีที่แล้ว

      @@techdose4u we can use sliding window technique such a minimum window that sums to target will be our ans.
      leetcode.com/problems/minimum-operations-to-reduce-x-to-zero/discuss/939891/Sliding-Window-C%2B%2B

  • @prashanttiwari1252
    @prashanttiwari1252 4 ปีที่แล้ว +1

    class Solution {
    HashMap dp;
    int min;
    int solve(int [] nums,int l,int r,int x ,int count){
    if(x==0)
    {
    return count;
    }
    if( l>r || x

    • @prashanttiwari1252
      @prashanttiwari1252 4 ปีที่แล้ว

      You have commented on top MEMOIZATION->TLE ..?

  • @swagatpatra2139
    @swagatpatra2139 4 ปีที่แล้ว +1

    public int minOperations(int[] nums, int x) {
    int[] dp = new int[nums.length];
    int count = helper(x, nums, 0, nums.length-1, 0, dp);
    return count == Integer.MAX_VALUE?-1:count;
    }

    int helper(int x, int[] arr, int i, int j, int count, int[] dp){
    if(xj) return Integer.MAX_VALUE;
    if(dp[i]!=0) return dp[i];
    return
    dp [i] = Math.min( helper(x - arr[i], arr, i+1, j, count+1, dp),
    helper (x - arr[j], arr, i, j-1, count+1, dp) );
    }
    I tried using 2 player stone game technique, but got TLE.

  • @ShubhamSharma-sn8rq
    @ShubhamSharma-sn8rq 3 ปีที่แล้ว

    giving tle