Best playlist over bit manipulation on entire youtube , I have completed it in just 1 day and its still 5 pm and i started on 9 am. The content was very enjoyable and gave me new ways to think using xor and many others . Thank you a lot for providing such a amazing content for FREE.❤❤❤
little modification requires for java : then it will pass all use case; long n = Math.abs((long)dividend); // Convert to long to handle Integer.MIN_VALUE long d = Math.abs((long)divisor); // Convert to long to handle Integer.MIN_VALUE
We can start our cnt from 32 (declared outside) and that way we won't have to increment it uptill 32, 31, 30... in order to find the point where ((d n) each time as the outer while loop iterates. This way we can simply keep decrementing cnt it until 0. Time complexity: O(32) which is as good as constant.
Complete CPP Code: class Solution { public: int divide(int dividend, int divisor) { if(dividend==divisor) return 1; bool sign = true; if((dividend0) || (divisor=0)) sign = false; unsigned int n = abs(dividend); unsigned int d = abs(divisor); unsigned int ans = 0; while(n>=d){ short count=0; while(n > (d
Bro though this is good but the main gist of the problem is implemenation as well within the rules after knowing the logic, and by using long that rule has been broken
This one works with 32 bit integers and is similar to Strivers solution: class Solution { public: int divide(int dividend, int divisor) { if(dividend == divisor) return 1; if (dividend == INT_MIN && divisor == -1) return INT_MAX; int sign = 1; if(dividend>=0 and divisor=d){ int cnt=0; while(n>d
bro y did u delete the old string , heap, and other videos untill u upload new videos pls let the old one be there a kind ly request from ur student community pls understand us
Bhaiya sliding window v jldi lana i know apki schedule busy h but fir v wait kr rha hu 😅 Koi or playlist se pdh rha tha but waiting for yours sliding window playlist
Below one slightly modified. public int divide(int dividend, int divisor) { // Check for edge cases if (dividend == 0) return 0; if (divisor == 0) throw new ArithmeticException("Division by zero"); if (divisor == -1 && dividend == Integer.MIN_VALUE) return Integer.MAX_VALUE; // Determine the sign of the result boolean isNegative = (dividend < 0) ^ (divisor < 0); // Convert dividend and divisor to positive values long absDividend = Math.abs((long) dividend); long absDivisor = Math.abs((long) divisor); long quotient = 0; while (absDividend >= absDivisor) { long temp = absDivisor; long shift = 1; // Shift the divisor left until it becomes greater than the dividend while ((temp
More efficient than Striver's code : T.C: O(1) S.C : O(1) int divideTwoInteger(int dividend, int divisor) { long q=0,sign=-1; if((dividend0)) sign=1; long d1=abs(dividend), d2=abs(divisor),temp=0; for(int i=31;i>=0;i--) { if((temp+(d2
Bhai mujhe English samajne me dikkat ho rahi ..and striver fails to say what he wants to do..like..in this..start ne bolte .. multiplication means continuous subtraction I give up with DSA..kitna rough hai... Best development haiii
Thanks striver. I understand the solution but i just want to ask will it help in any other problems if i know this solution?Anyone? Your reply is appreciated.
C++ Solution - #include using namespace std; class Solution { public: int divide(int dividend, int divisor) { if (dividend == divisor) return 1; if (dividend == INT_MIN && divisor == -1) return INT_MAX; int sign = 1; if ((dividend >= 0 && divisor < 0) || (dividend 0)) { sign = -1; } long n = labs(dividend); // Use labs for long absolute value long d = labs(divisor); // Use labs for long absolute value long ans = 0; while (n >= d) { int cnt = 0; while (n >= (d
can anyone plzz tell why this code is not working --> int division(int given, int divisor){ bool sign = true; // sign is positive if(given < 0 && divisor > 0) sign = false; // sign is negative if(given > 0 && divisor < 0) sign = false; // sign is negaitve long given1 = abs(given); long divisor1 = abs(divisor); long ans = 0; int cnt = 0; while( given1 - ( divisor1
Bhaiya, actually i want to start this DSA playlist but don't know from which video should i start as you have made playlists topicwise. It would really be helpful if you would create a new playlist and add all videos in order, else you can upload a seperate video regarding roadmap for this particular playlist, like from where one should start then what, then what, then next what.... --Thank you Please reply asap:-)
There is no need for nested loops TC - O(log2N) class Solution { public: int divide(int dividend, int divisor) { long c = 0; int sign = 0; if(dividend0) sign = 1; if(dividend>0 && divisor
I have a question, why are the we removing the largest possible first I mean why are we removing 12 first and then 6 and then 3...... we could have removed 3 and then 6 and then 12 (doing so will reduce the need to find what's the maximum that can be returned)............ after removing 3 (3 * 2^0) our n will 19, then we see that 6 (3 * 2^1) can be removed so we will remove 6, after removing 6 n becomes 13.... then we see that 12 (3 * 2^2) can be removed so we remove 12, then our n becomes 1, now the next thing that should be removed is 24 (3 * 2^3) .... but this cannot so we will return the sum of 1, 2 and 4 which is 7..... I tried this approach on the leetcode question 29, but it's giving TLE...... can someone please explain why..... I just reversed the order, right? this shouldn't cause TLE
So I wrote the code same as yours , got runtime error due to corner cases , Checked the solution 99% of solution have used long long which is violation of the question rules and then checked the LEE215 solution but it was working well in past not now , so can anyone provide me the solution which works well and follows the question rules too Edit : Got the solution here it is 👇👇 class Solution { public: int divide(int dividend, int divisor) { if (dividend == INT_MIN && divisor==-1) return INT_MAX; if(dividend==divisor)return 1; unsigned int n=abs(dividend),d=abs(divisor); bool neg=false; if(dividend =0)neg=true; else if(dividend >=0 && divisor=d){ short count=0; while(n > (d
Waiting for strings playlist
same! @Striver bhai please yaar
Yes we want string playlist
waiting for string playlist
Yep can't wait for string playlist
pls pls
Best playlist over bit manipulation on entire youtube , I have completed it in just 1 day and its still 5 pm and i started on 9 am. The content was very enjoyable and gave me new ways to think using xor and many others . Thank you a lot for providing such a amazing content for FREE.❤❤❤
W
Hello Striver
Thank you for Bit manipulation Series
Please make String Problems Solving series soon :)
yes, please make String problem series 🙏
string matching algorithms would also help. Please make a playlist on that too.
little modification requires for java : then it will pass all use case;
long n = Math.abs((long)dividend); // Convert to long to handle Integer.MIN_VALUE
long d = Math.abs((long)divisor); // Convert to long to handle Integer.MIN_VALUE
thanks brother
Thanks
@@shatabdipanda9818 its giving me TLE. How did you handled it?
The question requires not to use multiplication operator, but it is used in the last line:
n = n - (d * (1
Thank you so so much.... I was eagerly waiting for the bit manipulation series.
We can start our cnt from 32 (declared outside) and that way we won't have to increment it uptill 32, 31, 30... in order to find the point where ((d n) each time as the outer while loop iterates.
This way we can simply keep decrementing cnt it until 0. Time complexity: O(32) which is as good as constant.
Exactly 💯
LGTA HAI RAJ BHAI AAJ HI BIT MANUPULATION KHATAM KR DENGE 😂😂😂😂😂😂😂😂. BUT SIR I HAVE MAD RESPECT FOR YOU 😊😊🫡🫡
amazing playlist..
its a humble request to bring a new stack & queue playlist as well
Thank you so much Striver you are motivating us to learn new topics by your videos. You are really doing great work!!
i didnt expect i wound complete this bit manipulation tipic in 4 hts in one sitting .. thank you sooo muchhh
Which college and which semester bro....
Thanks I will complete till here by tomorrow
Thanks for this amazing playlist!
bro CAN U START STRING SERIES AS WELL PLZZZZZZZZZZZZZZZZZZZZZZZZZ
Complete CPP Code:
class Solution {
public:
int divide(int dividend, int divisor) {
if(dividend==divisor)
return 1;
bool sign = true;
if((dividend0) || (divisor=0))
sign = false;
unsigned int n = abs(dividend);
unsigned int d = abs(divisor);
unsigned int ans = 0;
while(n>=d){
short count=0;
while(n > (d
Why unsigned int???
@@adityasrivastava3540 read the problem carefullly on LC
Thanks a lot 🙌
Best ever explanation ,Thank you Bhaiya .
Heyy striver,
I have been learning from your videos and they are very nice.
I would request you to start string series please.
Great content 😁💯 waiting for string matching algorithms
add this link to a to z dsa sheet so that students can easily get it and thanks for uploading lectures
this question is so bad, what does this even test? your mugging up skills?
Amazing explaination Striver
Bro though this is good but the main gist of the problem is implemenation as well within the rules after knowing the logic, and by using long that rule has been broken
Understood, btw, innner while loop was O(1) as max is 32 only and it doesn't increase with size.
This one works with 32 bit integers and is similar to Strivers solution:
class Solution {
public:
int divide(int dividend, int divisor) {
if(dividend == divisor)
return 1;
if (dividend == INT_MIN && divisor == -1) return INT_MAX;
int sign = 1;
if(dividend>=0 and divisor=d){
int cnt=0;
while(n>d
Thank you striver from bangladesh.
Thank You So Much for this wonderful video.....🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
bro y did u delete the old string , heap, and other videos untill u upload new videos pls let the old one be there a kind ly request from ur student community pls understand us
class Solution {
public int divide(int dividend, int divisor) {
if(dividend == divisor) return 1;
boolean sign = true;
if(dividend0) sign = false;
if(dividend>0 && divisor=d){
int count = 0;
while(n>=(d
Thank you @Striver respect++
Please continue the bit manipulation series 🙏
thanks for such amazing playlist
Please include 1915. Number of Wonderful Substrings, and it would be nice to cover the concept of masking in bit_manipulation series. Thanks.
we were not supposed to use multiplication, then how is this solution valid?
Bhaiyaa please upload stack queue asap as well please 🥺
There is another Math solution you can use. TC : LogN
Use binary serach in range [1,N/2], pick mid and keep checking -> if mid*division
Java Solution:
class Solution {
public int divide(int dividend, int divisor) {
if(dividend == divisor) return 1;
boolean sign = true;
if(dividend0) sign = false;
if(dividend>0 && divisor=d){
int count = 0;
while(n>=(d
Very good explaination thanks a lot Sir
Most wanted topic❤
Bhaiya sliding window v jldi lana i know apki schedule busy h but fir v wait kr rha hu 😅 Koi or playlist se pdh rha tha but waiting for yours sliding window playlist
Striver bhai bit manipulation over, please do strings. It's very important, many questions are getting stuck in string. Please bhai🙏🙏
Great video 🔥
Thank you 😊
Bhaiya a2z sheet pa code and article ka link upload kar do binary search tree pa bhi kuch questions pa nahi hai ??
sir how to write good quality code uspe ak video banaya
small doubt
why did we checked that quotient == 1
same doubt
Have any answer or not please tell I am also stuck here
Please start with string playlist sir
HUMBLE REQUEST TO YOU
Below one slightly modified.
public int divide(int dividend, int divisor) {
// Check for edge cases
if (dividend == 0) return 0;
if (divisor == 0) throw new ArithmeticException("Division by zero");
if (divisor == -1 && dividend == Integer.MIN_VALUE) return Integer.MAX_VALUE;
// Determine the sign of the result
boolean isNegative = (dividend < 0) ^ (divisor < 0);
// Convert dividend and divisor to positive values
long absDividend = Math.abs((long) dividend);
long absDivisor = Math.abs((long) divisor);
long quotient = 0;
while (absDividend >= absDivisor) {
long temp = absDivisor;
long shift = 1;
// Shift the divisor left until it becomes greater than the dividend
while ((temp
best video
More efficient than Striver's code :
T.C: O(1)
S.C : O(1)
int divideTwoInteger(int dividend, int divisor) {
long q=0,sign=-1;
if((dividend0))
sign=1;
long d1=abs(dividend), d2=abs(divisor),temp=0;
for(int i=31;i>=0;i--)
{
if((temp+(d2
Bhai mujhe English samajne me dikkat ho rahi ..and striver fails to say what he wants to do..like..in this..start ne bolte .. multiplication means continuous subtraction
I give up with DSA..kitna rough hai...
Best development haiii
Please upload String Playlist also :)
Can be easily done in O(logn) too
hey striver need a full combinatorics playlist...
is this the end of the playlist??
as there are some advance maths questions there in bit manipulation
waiting for the string playlist
Pls string playlist ❤❤❤
Thankyou sir
Awsm
Which college bro and which semester
understood ❤
Thanks striver.
I understand the solution but i just want to ask will it help in any other problems if i know this solution?Anyone? Your reply is appreciated.
🔥
Which college and which semester bro....
Java Solution : public class Solution {
public static int divideTwoInteger(int dividend, int divisor) {
if (dividend == divisor)
return 1;
boolean sign = true;
if (dividend > 0 && divisor < 0)
sign = false;
if (dividend < 0 && divisor > 0)
sign = false;
int n = Math.abs(dividend);
int d = Math.abs(divisor);
int ans = 0;
while (n >= d) {
int count = 0;
while (n >= (d
ans += (1
Can anyone tell me, where is the link to the problem and notes, as i couldn't figure out where is day8 in the link given in description
On the 2nd while condition, why does it not as n>= (d*(1
same as n >= (d
check his first video of bit manipulation in left shift
understood
Which college and which semester bro....
Thank you Bhaiya
isnt TC better for appr 1 , then why is appr 2 reqd ?
striver please drop the strings playlist
First view from my sids 😊
very nice
Understood
we didn't completely get away from using multiplication even with this code.
please start string series 🥺🥺🥺🥺🥺🥺
C++ Solution -
#include
using namespace std;
class Solution {
public:
int divide(int dividend, int divisor) {
if (dividend == divisor) return 1;
if (dividend == INT_MIN && divisor == -1) return INT_MAX;
int sign = 1;
if ((dividend >= 0 && divisor < 0) || (dividend 0)) {
sign = -1;
}
long n = labs(dividend); // Use labs for long absolute value
long d = labs(divisor); // Use labs for long absolute value
long ans = 0;
while (n >= d) {
int cnt = 0;
while (n >= (d
I give up.... Developement isse acha haii
can anyone plzz tell why this code is not working -->
int division(int given, int divisor){
bool sign = true; // sign is positive
if(given < 0 && divisor > 0) sign = false; // sign is negative
if(given > 0 && divisor < 0) sign = false; // sign is negaitve
long given1 = abs(given);
long divisor1 = abs(divisor);
long ans = 0;
int cnt = 0;
while( given1 - ( divisor1
the overflow part is still not that clear
Bhaiya, actually i want to start this DSA playlist but don't know from which video should i start as you have made playlists topicwise. It would really be helpful if you would create a new playlist and add all videos in order, else you can upload a seperate video regarding roadmap for this particular playlist, like from where one should start then what, then what, then next what....
--Thank you
Please reply asap:-)
what if our d is INT_MIN ?
ps : i didnt watch the whole lecture 😅
There is no need for nested loops
TC - O(log2N)
class Solution {
public:
int divide(int dividend, int divisor) {
long c = 0;
int sign = 0;
if(dividend0) sign = 1;
if(dividend>0 && divisor
when i run this code it gives tle
These code is working in cpp but not in java
Greeting tle
I have a question, why are the we removing the largest possible first I mean why are we removing 12 first and then 6 and then 3...... we could have removed 3 and then 6 and then 12 (doing so will reduce the need to find what's the maximum that can be returned)............ after removing 3 (3 * 2^0) our n will 19, then we see that 6 (3 * 2^1) can be removed so we will remove 6, after removing 6 n becomes 13.... then we see that 12 (3 * 2^2) can be removed so we remove 12, then our n becomes 1, now the next thing that should be removed is 24 (3 * 2^3) .... but this cannot so we will return the sum of 1, 2 and 4 which is 7..... I tried this approach on the leetcode question 29, but it's giving TLE...... can someone please explain why..... I just reversed the order, right? this shouldn't cause TLE
// Online C compiler to run C program online
#include
int main() {
int n;
int d;
scanf("%d %d",&n,&d);
int sum=0;
int count=0;
int ans=0;
while(sum
same doubt :/
@257divyanshu
I just want to believe if the shift operators are used anywhere... 😢😢😢
yes it is too confuesing😅
start heap playlist
Waiting for string
MAIN HOON MOHIT
❤
🙇🙇🙌
could have also used binary search, amirite//
could have been better
Which college and which semester bro....
2nd test case failed
Which college and which semester bro....
taking long long 1LL menas ans += (1LL passed
if(ans > INT_MAX && sign == 0) return INT_MAX;
if(ans > INT_MAX && sign == 1) return INT_MIN;
code 2 => not passed
if(ans >= INT_MAX && sign == 0) return INT_MAX;
if(ans >= INT_MAX && sign == 1) return INT_MIN;
code 3 => not passed
if(ans >= (1 (1
hail mary
Please stop wearing red and try other colors. Its boring now
Red increases attention and engagement of audience
Maybe that's why he always wears red for video making
So I wrote the code same as yours , got runtime error due to corner cases , Checked the solution 99% of solution have used long long which is violation of the question rules
and then checked the LEE215 solution but it was working well in past not now , so can anyone provide me the solution which works well and follows the question rules too
Edit : Got the solution here it is 👇👇
class Solution {
public:
int divide(int dividend, int divisor) {
if (dividend == INT_MIN && divisor==-1) return INT_MAX;
if(dividend==divisor)return 1;
unsigned int n=abs(dividend),d=abs(divisor);
bool neg=false;
if(dividend =0)neg=true;
else if(dividend >=0 && divisor=d){
short count=0;
while(n > (d
On the 2nd while condition, why does it not as n>= (d*(1
it is not possible, did not see any solution working with using int, you can use signed int, but that is violation as well
The question requires not to use multiplication operator, but it is used in the last line:
n = n - (d * (1
Understood
Which college and which semester bro....
@@mdfaizanmdfaizan6041 i'm 12th bro
waiting for strings playlist
Thank u sir
understood