Reverse Bits using Bit Manipulation | Leetcode 190 Solution
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
Very clear explanation. Thankyou!
your explanation is great
Thank You So Much for this wonderful video............🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
A very good explanation
Excellent Explanation.....
That's awesome ❤
great explanation.
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 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.
sir thank you but itna krne se koi refral dega? mjhe lgta tha cp codeforces me rating acha hona chaiye refral milne ke liye.
@@shivabansfore7510 kya hua Bhai job mili?
Sir Level 2 (complete) and Web Dev ka kab tak available hoga protal me? BTW, you are great
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🙏🏼
@@Pepcoding Sir sab theek ho jayega. Corona ne bura hi kra hua hai. Hope 2021 will be a good start.
bhai level 1 and level2 revise kaise krte ho ,aur level 2 ke baad kya krte ho aur dsa practice ke liye?
Done!
Sir tier 3 ke student ko CP Krna jaruri hai offcampus ke liya ya DS Algo or subjective strong krke v ho sakta hai
I think CP is a cherry on top of the cake
CP is beneficial but not necessary
sir we can take the xor of (nbr and 1111) we will get the reverse of the nbr . it will work or not ?
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.
Toggle nahi reverse karna ha
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
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
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
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
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;
}
Wrong solution...
Value overflow ho jayegi 2^32 tak to
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;
}
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/
C++ solution anyone?
Can we code together?