6365. Minimum Operations to Reduce an Integer to 0 | LeetCode Weekly 333 | C++

Problem Link- leetcode.com/contest/weekly-c...
Solution Link- github.com/preetu391/LeetCode...

Пікірлер: 12

  • @adarsh7171
    @adarsh7171 Жыл бұрын

    Thanks I hustled a lot into this problem finally get to know why it is so easy.

  • @esseclues2873
    @esseclues287310 ай бұрын

    The flow of explanation was so good. Work is inspiring and appreciable ❤

  • @preetu391

    @preetu391

    10 ай бұрын

    Thank you so much. Means a lot! 🙏

  • @Kumarb694
    @Kumarb694 Жыл бұрын

    Simple and beginner friendly. Thank You

  • @preetu391

    @preetu391

    Жыл бұрын

    You are welcome!

  • @depressed-undergrad5548
    @depressed-undergrad5548 Жыл бұрын

    So nice ❤,please don’t stop posting videos , I'm highly using ur videos,its so helpful

  • @abhinavchakravarty5147
    @abhinavchakravarty5147 Жыл бұрын

    Nice explanation Priyanshi, I was wondering can we actually prove that the greedy approach will always give us the minimum number of operations. For example it might be possible that if we add some value to n in such a way that the new number becomes exactly divisible by a power of 2 but by following greedy approach, the number of steps are more

  • @preetu391

    @preetu391

    Жыл бұрын

    Well actually this greedy approach gives us the minimum answer, you may try out using some examples and work them out to see why it works, then you'll find out. If you see we are constantly trying to reduce the number by powers of two and you know a number can be formed by summing up powers of two and those powers that you need to add are unique, thus we know that this gives us the minimum operation.

  • @aaryannaugaraiya1118
    @aaryannaugaraiya1118 Жыл бұрын

    awesome explanation! You got a new subscriber today .. 😁

  • @preetu391

    @preetu391

    Жыл бұрын

    Awesome, thank you!

  • @devanshpurwar
    @devanshpurwar Жыл бұрын

    i have one question , if we are adding power 2 in n then why n becomes (power of 2 ) - n

  • @preetu391

    @preetu391

    Жыл бұрын

    If you observe a little closely, we are doing the exact same thing given in the question for example if you consider (64-54) which is 10 you are just trying to make the number 64 only, so you're counting how much you need to do that which is 10 and the same you are doing for 10. And that's the reason we are considering the minimum difference because the lesser the difference the less powers of 2 you require. And we are able to do it comfortably as every number can be represented as the sum of powers of 2.