Комментарии:
The 2's compliment explaination is OP. Like no one ever explained y this happened. Hats off man.
ОтветитьI was scared of DSA but after watching his videos I just love to learn DSA and addicted to solve problems, really thankful,God bless u ❤❤❤❤❤
Ответитьthis guy is this good : (10)^256<<16^256
Ответитьi believe setReset would work a lot better if we do it using XOR, since XOR of 1 with something gives you the complement of it and we can use leftshift to not update the original number!
Ответитьplease anyone tell me in last question what was the purpose of second loop and what does it do?
ОтветитьCan i watch this if i only know C++ not java ?? pls tell
Ответитьquestion 11 mai 1<<n-1 kyu hua? please explain
ОтветитьHey Kunal! In Question 5 doing the "or operation" might change the bits present before the "set bit"? Why aren't we worried about that? And in Question 6 we are careful about having the other bits other than the bit to be reset is "1" @Kunal
ОтветитьKunal! I wanna know how do you get so deeply into a Subject? What is your go to resources? Like I'm really eager to know How did you learn the negative number stuff so deeply to it's base? 🎉
Ответитьfirst math class watched with interest
Ответитьyou are so intelligent ⭐
ОтветитьBhaiya mujhe kabhi kabhi bahut depression hota hai 😭
Ответитьi am unable to comprehend question 8 if anyone understood please comment your explanation here
ОтветитьQuestion - 08 Solution - Although not optimal I coded this. Please comment on how I can improve it.
import java.util.Arrays;
public class FindUniqueInThriceOccurrence {
public static void main(String[] args) {
int[] arr = {2, 2, 3, 2, 7,7, 8,7,8,8};
// sorting the array
Arrays.sort(arr);
// find the length of maximum value in binary.
int maxLength = (int) (Math.log(arr[arr.length-1])/Math.log(2))+ 1;
String sumOfNums = "";
// find the bit at an index and sum of all the 1s in that particular index.
for(int index=maxLength; index>=1; index--) {
int sumOfIndex = 0;
for (int i : arr) {
sumOfIndex += findithBit(i, index);
}
sumOfNums+=sumOfIndex;
}
String ans ="";
// take modulous of each index by 3 and append it to a string.
for(int i=0; i<sumOfNums.length();i++){
ans+=Integer.parseInt(String.valueOf(sumOfNums.charAt(i)))%3;
}
// convert binary to Integer.
System.out.println(Integer.parseInt(ans, 2));
}
static int findithBit(int num, int index){
int nums = (num & (1<<(index-1))) >> (index-1);
return nums;
}
}
For question no 7 - N & (-N) would give the value rather than the index of the right most set bit. We would have to do the right shift to get the position of the set index.
ОтветитьN&(-N) is giving 4 as output for 100 ( Integer 4), it should be 3 right not 4?
ОтветитьHey Kunal, in question 7 you said the rightmost set bit is equal to n & n-1.
But if we take an eg. 8, i.e. 1000 in binary, 8 & -8 is equal to 8 itself.
The answer should have been 4, please clear my doubt, Thanks
No one can give deep content in the free of cost like Kunal Kushwaha, Hats off to this man.👌👌👌
Ответитьnoice 👌
ОтветитьCan anyone help me by providing question no 8 solution???
ОтветитьHow can -N & N give the position of the rightmost set bit? It will not give.. it is a wrong solution
ОтветитьBro please create video on dynamic programming
Ответитьpublic static int findSingleNumber(int[] nums) {
int result = 0; // This variable will store the single occurring number.
// We iterate through each bit position in a number (assuming 32-bit integers).
for (int i = 0; i < 32; i++) {
int sum = 0; // This will store the sum of bits at position i across all numbers.
// We go through each number in the array and count the bits at position i.
for (int num : nums) {
sum += (num >> i) & 1;
// (num >> i) shifts the bits of num to the right by i positions.
// The "& 1" operation isolates the bit at position i.
// We add the isolated bit to the sum.
}
sum %= 3; // Taking the sum modulo 3 eliminates bits appearing in triplets.
// Now, we set the corresponding bit in the 'result' using bitwise OR operation.
// We shift the calculated sum by i positions and then set the bit in 'result'.
result |= (sum << i);
}
return result; // The 'result' now holds the single occurring number.
}
After learning how to create mask all my concepts were clear. I previously didn't know how to access any bit of an integer. Now I know how and rest of the logics are basic stuff.
Ответить👍
Ответитьncie video
ОтветитьOP Video
ОтветитьFor those who are getting doubts in any bit manipulation solution explained in the video, just dry run 2 or 3 testcases and observe the changes to the bits. You will get the answer.
ОтветитьMan!!!!!! the Q8 what a pain, but when you understand the rightshift and leftshift will be crystal clear to you
ОтветитьQ8 answer ----
public class Question8 {
public static void main(String[] args) {
int[]arr = {1,1,1,3,3,3,10,10,10,7};
System.out.println(detect(arr,3));
}
public static int detect(int[]arr,int repeatationTime){
int[] setBitArray = new int[32];
for (int i : arr) {
int index = 0;
while(i > 0){
setBitArray[index] += i & 1;
i = i >> 1;
index++;
}
}
for (int i= 0; i < setBitArray.length; i++) {
setBitArray[i] %= repeatationTime;
}
int ans = 0;
for (int i = 0; i < setBitArray.length; i++) {
ans += setBitArray[i] * (int)Math.pow(2, i);
}
return ans;
}
}
Video 25 Completed! For me it took quite a long time to understand.
Ответитьfor question 12, will finding the right most set bit on n => (n&-n) say x and xoring it with n if it gives 0 , then they are same , (the rightmost set bit and the number) => its a power of two.
i mean,
int rightMostSetBit=n&-n;
if(rightMostSetBit^n==0) sout(power of two)
else sout(not power of two)
will this work.?
For finding the i'th bit the answer should be ((n & (1 << (targetBit - 1))) >> (targetBit - 1))
ОтветитьThanks for the video . Small point here. Left shift and right shift are not really bitwise operations. They are more like arithmetic operations which basically multiply or divide by 2
ОтветитьPlease enable the subtitles for the videos.
Ответить