Reverse Bits using Bit Manipulation | Leetcode 190 Solution

Sdílet
Vložit
  • čas přidán 10. 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 Reverse Bits problem using Bit Manipulation. In this problem,
    1. You are given a number.
    2. You have to print its binary representation.
    3. You also have to reverse the bits of n and print the number obtained after reversing the bits.
    To submit the problem, click here: www.pepcoding.com/resources/d...
    For a better experience and more exercises, VISIT: www.pepcoding.com/resources/o...
    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 • 34

  • @dhara2814
    @dhara2814 Před 2 lety +1

    Very clear explanation. Thankyou!

  • @mansisaxena815
    @mansisaxena815 Před 3 lety

    your explanation is great

  • @stith_pragya
    @stith_pragya Před 5 měsíci

    Thank You So Much for this wonderful video............🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻

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

    A very good explanation

  • @therawcoconut9279
    @therawcoconut9279 Před rokem

    Excellent Explanation.....

  • @bhaveshverma8629
    @bhaveshverma8629 Před 2 měsíci

    That's awesome ❤

  • @cenacr007
    @cenacr007 Před rokem

    great explanation.

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

    sir i am in final year in tear 3 government college , i have recently started competitive programming in this lockdown i am very worried about my career i want to be place in product based company but i am confuse what to do should i continue cp or i should focus on ds algo. I m worried that without cp i wont be getting refral. i really like the way sumit sir teaches if you can help me or suggest me it will be a great help for me.

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

      pepcoding ka level1, level2 aur web dev kar lijie. level1 freely available hai. baaki do freely aa rhe hain. itna kar lenge to sahi job mil jaegi. worry not.

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

      sir thank you but itna krne se koi refral dega? mjhe lgta tha cp codeforces me rating acha hona chaiye refral milne ke liye.

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

      @@shivabansfore7510 kya hua Bhai job mili?

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

    Sir Level 2 (complete) and Web Dev ka kab tak available hoga protal me? BTW, you are great

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

      Beta jaldi he hoga, company main financial crisis chl rh h to abhi funds arrange karne me he lage h taaki in videos ko bna sake aur company run ho sake. And bro trust me, I am more than committed to bring videos to all of you.
      Hope you can understand🙏🏼

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

      @@Pepcoding Sir sab theek ho jayega. Corona ne bura hi kra hua hai. Hope 2021 will be a good start.

    • @mickyman753
      @mickyman753 Před 2 lety +1

      bhai level 1 and level2 revise kaise krte ho ,aur level 2 ke baad kya krte ho aur dsa practice ke liye?

  • @girikgarg8
    @girikgarg8 Před rokem

    Done!

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

    Sir tier 3 ke student ko CP Krna jaruri hai offcampus ke liya ya DS Algo or subjective strong krke v ho sakta hai

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

      I think CP is a cherry on top of the cake

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

      CP is beneficial but not necessary

  • @b.sainathreddy4567
    @b.sainathreddy4567 Před 3 lety

    sir we can take the xor of (nbr and 1111) we will get the reverse of the nbr . it will work or not ?

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

      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.

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

      Toggle nahi reverse karna ha

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

    import java.io.*;
    import java.util.*;
    public class Main {
    public static void main(String[] args){
    Scanner scn = new Scanner(System.in);
    int n = scn.nextInt();
    String binary = Integer.toBinaryString(n);
    System.out.println(binary);
    int ans = 0;
    int mask =0;
    for(int i=binary.length()-1;i>=0;i--){
    mask = binary.charAt(i)-'0';
    mask

  • @girikgarg8
    @girikgarg8 Před rokem

    class Solution {
    public:
    uint32_t reverseBits(uint32_t n) {
    int i=0; //the rightmost bit
    int j=31; //the leftmost bit
    uint32_t answer=n;
    while (i

  • @pratyakshamaheshwari8269

    I have written this solution in leetcode but it is failing can someone telle me the error
    public class Solution {
    // you need treat n as an unsigned value
    public int reverseBits(int n) {

    boolean flag = false;
    int rev = 0;
    int j = 0;
    for(int i = 31; i >= 0; i--){
    int mask = (1

  • @mickyman753
    @mickyman753 Před 2 lety

    sir ye solution is case ke liye fail ho rha hai interviewbit pr
    00000000000000000000000000000011
    => 11000000000000000000000000000000
    //ham rev aise calc kr lenge and Long.toBinaryString se isko string mai convert kr sakte hai
    public long reverse(long n) {
    long rev=0;
    int j=0;
    for(int i=31;i>=0;i--)
    {
    long mask=(1L

  • @mailtobasit74
    @mailtobasit74 Před 3 lety

    thanks, Sumeet sir, your content is really helpful 👌👌👌
    my solutions
    public int reverseBits(int n) {
    int sum = 0;
    int mask = 1;
    for (int pow = 31; pow >= 0; pow--) {
    sum = sum + ((n & mask) >= 1;
    }
    return sum;
    }

  • @ritikmishra5210
    @ritikmishra5210 Před 2 lety

    Leetcode solution:
    uint32_t reverseBits(uint32_t n) {
    uint32_t res = 0;
    for (int i = 0; i < 31; i++) {
    res = (n&1) + res >= 1;
    }
    return res + n % 2;
    }

    • @Pepcoding
      @Pepcoding  Před 2 lety

      For better experience and well-organised content visit on nados.pepcoding.com. Also you can post your query on Community tab.
      Don't forget to follow us on Instagram instagram.com/pepcoding/

  • @dhanyaabharadwaj1376
    @dhanyaabharadwaj1376 Před 3 lety

    C++ solution anyone?