Copy Set Bits in a Range | Toggle Bits in a Range | Bit Manipulation Interview Questions

Sdílet
Vložit
  • čas přidán 6. 09. 2020
  • Please consume this content on nados.pepcoding.com for a richer experience. It is necessary to solve the questions while watching videos, nados.pepcoding.com enables that.
    NADOS also enables doubt support, career opportunities and contests besides free of charge content for learning. In this video, we discuss the Copy Set Bits in a Range problem using bit manipulation algorithms. In this problem,
    1. You are given two numbers A and B.
    2. You are given two more numbers left and right, representing a range [left,right].
    3. You have to set bits in B which are set in A lying in the above mentioned range.
    4. Print the updated number B.
    To submit the question, click here: www.pepcoding.com/resources/d...
    For a better experience and more exercises, VISIT: www.pepcoding.com/resources/o...
    #bitmanipulation #bits
    Have a look at our result: www.pepcoding.com/placements
    Follow us on our FB page: / pepcoding
    Follow us on Instagram: / pepcoding
    Follow us on LinkedIn: / pepcoding-education

Komentáře • 55

  • @akasht5184
    @akasht5184 Před rokem +7

    I don't understand why the likes and views on your channel are low. You deserve more. The way you teach is exceptional and needs a lot of appreciation and attention.

  • @blizzardstorm9715
    @blizzardstorm9715 Před 3 lety +4

    My reaction at 7:32 is like wow. i mean i know this thing right, i know this pattern, i have observed that, bit i never thought it will come handy in this way. Thanks man! Great work!

  • @mananagrawal4114
    @mananagrawal4114 Před 3 lety +9

    You deserve much more views than this! Great Explaination man!!

    • @Pepcoding
      @Pepcoding  Před 3 lety +1

      Thankyou beta,
      I am glad you liked it. I also hope that you are watching till end.
      If you like our efforts, will you like to write a few words about us here (www.quora.com/How-do-I-start-learning-or-strengthen-my-knowledge-of-data-structures-and-algorithms )

  • @partharora5309
    @partharora5309 Před rokem +1

    Next Level ;) sumeet sir please More videos on LeetCode hard problems on DP , Bitmask, Graph etc.

  • @AnkitBhatt-we3ml
    @AnkitBhatt-we3ml Před rokem

    Simple and Amazing explanation!

  • @aryaraj1898
    @aryaraj1898 Před rokem +1

    Thank you so much sir your effort is priceless i watch your all videos thankyou so much it s very helpfull for me 🥰

  • @Rajatkumar-tg3es
    @Rajatkumar-tg3es Před 2 lety

    simple and wonderful explanation

  • @ananyasingh1141
    @ananyasingh1141 Před 3 lety +2

    AND All my doubts are solved by watching this! Thank you so much sir!

    • @Pepcoding
      @Pepcoding  Před 3 lety +1

      Thankyou beta!
      I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem.
      If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

  • @babbarutkarsh7770
    @babbarutkarsh7770 Před 2 lety

    utter perfection!

  • @mjj2745
    @mjj2745 Před 2 lety

    very good explanation for finding the mask, gfg was very confusing, thanks

  • @akatsuki1363
    @akatsuki1363 Před 3 lety

    Awesome expression👌👌🔥

  • @siddheshb.kukade4685
    @siddheshb.kukade4685 Před rokem

    Thanks

  • @aakansha7256
    @aakansha7256 Před rokem

    thanks

  • @ashishm8850
    @ashishm8850 Před 3 lety

    Thank you!

    • @Pepcoding
      @Pepcoding  Před 3 lety

      You're welcome! and If you like our efforts, please upvote the comments written by the students about Pepcoding here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

  • @NehaKumari-cx6un
    @NehaKumari-cx6un Před 3 lety

    Thanku soo much sir for all these contents😀

    • @Pepcoding
      @Pepcoding  Před 3 lety

      If you like our efforts, we request a review
      g.page/Pepcoding/review?rc
      You can subscribe to our channel here
      czcams.com/users/Pepcodingabout?view_as=subscriber
      For clearing your doubts, you can join our community on telegram
      t.me/pepcoding

  • @tarunmehta8448
    @tarunmehta8448 Před 3 lety +5

    No coding Platform is gonna beat you in future.
    1. Wrote reviews on quora
    2. subscribed
    3. If i find a question is explained by Pepcoding on youtube, i can't even think of going to another channel.
    🙏🙏🙏
    You guys are killing it

    • @Pepcoding
      @Pepcoding  Před 3 lety +1

      Thank you so much. Keep learning, Keep growing and keep loving Pepcoding!😊

    • @prayagpatel9136
      @prayagpatel9136 Před 2 lety

      completely agreed man

  • @amitkumargupta6722
    @amitkumargupta6722 Před 3 lety

    thank u so much...

  • @sasta_rancho
    @sasta_rancho Před 3 lety +3

    you should be a professor in IIT...great job bro

    • @Pepcoding
      @Pepcoding  Před 3 lety +2

      Glad to know that you liked the content and thank you for appreciating.
      The love and respect which I get from you people keep me highly motivated and the same I am able to forward It to you people through my videos.
      So, keep motivating, keep learning and keep loving Pepcoding😊

    • @nitinkumar5974
      @nitinkumar5974 Před 3 lety

      @@Pepcoding Sir video ke end mai Time complexity bhi ek baar jaldi se discuss kardiya kare code ki👍👍
      Video poori achhe se samjh aa gayi , agle ek saal tak nahi bhulunga

  • @shivammehta9661
    @shivammehta9661 Před 3 lety

    Very Nice Explanation.....Keep making videos

  • @LegitGamer2345
    @LegitGamer2345 Před 3 lety +9

    Guys this logic will fail if right is greater than number of bits in binary representation of A , so to handle that make right as minimum of (right,length of binary string of A ) which can be done as follows :
    right = Math.min(right,len(A)); // call to len function
    len function code :
    static int len(int num){
    int len = ((int)(Math.log(num)/Math.log(2))) +1;
    return len;
    }

  • @suyashgupta1741
    @suyashgupta1741 Před 3 lety +1

    Amazing content!

    • @Pepcoding
      @Pepcoding  Před 3 lety +1

      Thankyou beta!
      I am glad you liked it. I also hope that you are watching till end and trying to understand the what, how and especially why of the problem.
      If you like our efforts, we request a review - g.page/Pepcoding/review?rc

    • @suyashgupta1741
      @suyashgupta1741 Před 3 lety

      @@Pepcoding Absolutely sir. I understood the concept really well and was able to code it on my own as well.
      Thank you!

  • @sukritakhauri65
    @sukritakhauri65 Před 2 lety

    Nice explanation sir

    • @Pepcoding
      @Pepcoding  Před 2 lety

      Keep learning.
      And for better experience and well organised content visit nados.pepcoding.com

  • @rahulbhatia3075
    @rahulbhatia3075 Před 3 lety

    Awesome explanation 😀😀

    • @Pepcoding
      @Pepcoding  Před 3 lety +2

      Seekhte rahie. Bhot khushi ho rahi hai ki aap sare questions dekh rhe hain

    • @rahulbhatia3075
      @rahulbhatia3075 Před 3 lety +1

      @@Pepcoding sir content is really good l. I never get bored while watching videos

  • @anishkumargiri9490
    @anishkumargiri9490 Před 2 lety

    sir use 1l literal it will help and it will be more efficient for a larger problem

  • @surendrapokala5533
    @surendrapokala5533 Před 4 měsíci

    simple approach
    for (int i=left-1; i

  • @aadityabedi3140
    @aadityabedi3140 Před 3 lety

    sir ap toh bade aggresively padha rhe but explaination was good

  • @palakgupta4104
    @palakgupta4104 Před 3 lety

    time complexity would be o(1) na??

    • @Pepcoding
      @Pepcoding  Před 3 lety

      Beta, I regret to inform you that, I won't be able to answer/solve the personal doubts of each and every student over here. For clearing your doubts, you can join our community on telegram - t.me/pepcoding.

    • @fresh-avocado
      @fresh-avocado Před 3 lety

      yes it's O(1)

  • @harshitsharma4063
    @harshitsharma4063 Před 3 lety

    agr sir isme esa case aaya ki carry aa rha ho toh yeh algo fail ho jaega na?

    • @Pepcoding
      @Pepcoding  Před 3 lety

      Beta, I regret to inform you that, I won't be able to answer/solve the personal doubts of each and every student over here. For clearing your doubts, you can join our community on telegram - t.me/pepcoding.

  • @aman6561
    @aman6561 Před 3 lety

    sr approach to same hi sochi thi bs mask code ni hua khud se

    • @Pepcoding
      @Pepcoding  Před 3 lety +1

      shabaash!!

    • @aman6561
      @aman6561 Před 3 lety

      @@Pepcoding sr aap almost sbhi comments ka reply krte ho aisa lgra hai ekdm offline pdhra hu

  • @sparshtaneja
    @sparshtaneja Před rokem +2

    anyone submitting on gfg take 1ll instead of 1
    can use the code
    if(x == y) return x;
    if(l 32) return x;
    int mask = 1ll

  • @loserfruit9663
    @loserfruit9663 Před 3 lety

    Easy tha kaafi phir b na ho paya

    • @Pepcoding
      @Pepcoding  Před 3 lety +8

      Beta, agr questions banne lge to ghamand nh krna aur agr naa ho to haar nh maan ni.
      Aur aise h apna pyaar bnaye rkhe aur pdte rhe😊

    • @rohank1411
      @rohank1411 Před rokem

      @@Pepcoding great thoughts sir... learnt a lot😊