Better time as well space complexity class Solution { public: long long minEnd(int n, int m) { if(n==1) return m; int bit = ceil(log2(n)); long long ans = 0; int i = 0; int k = n - 1; int j=64; while (j--) { if ((m & 1)) { ans += pow(2, i); } else { if (bit--) { ans += (k & 1) * (pow(2, i)); k = k >> 1; } } m = m >> 1; i++; } return ans; } };
This week is a bit manipulation hell but all thanks to you we can understand the logic and begin our code! Amazing work sir!
Happy to help :)
😁 thank you for helping us out
Happy to help 😄
Awesome :)
Consistent :)
nice example!
Thanks 😊
thankyou sir but im not good in math can you have any playlist for bit manipulation and math
I am making playlist for all chapters.
The daily videos will get sorted and you will see by December and prepare from scratch for free :)
How binary (n-1) works like how it's come in your mind I am not understanding
As I said, generating combinations starts from 0 while the N count starts from 1.
If you write on your notebook it will be clear.
I did the same :)
Better time as well space complexity
class Solution {
public:
long long minEnd(int n, int m) {
if(n==1) return m;
int bit = ceil(log2(n));
long long ans = 0;
int i = 0;
int k = n - 1;
int j=64;
while (j--) {
if ((m & 1)) {
ans += pow(2, i);
} else {
if (bit--) {
ans += (k & 1) * (pow(2, i));
k = k >> 1;
}
}
m = m >> 1;
i++;
}
return ans;
}
};
nice
some one lose way
yes zoro :P