L9. Divide Two Integers without using Multiplication and Division Operators | Bit Manipulation

Поделиться
HTML-код
  • Опубликовано: 27 окт 2024

Комментарии • 139

  • @NaveenBeniwal-c7z
    @NaveenBeniwal-c7z 3 месяца назад +13

    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.❤❤❤

  • @thoughtsofkrishna8963
    @thoughtsofkrishna8963 7 месяцев назад +144

    Waiting for strings playlist

  • @bhagyashreeaher7429
    @bhagyashreeaher7429 7 месяцев назад +30

    Hello Striver
    Thank you for Bit manipulation Series
    Please make String Problems Solving series soon :)

    • @md_seraj786_
      @md_seraj786_ 4 месяца назад

      yes, please make String problem series 🙏

  • @udayshankar-e6v
    @udayshankar-e6v 6 месяцев назад +16

    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

  • @sujalgupta6100
    @sujalgupta6100 7 месяцев назад +20

    string matching algorithms would also help. Please make a playlist on that too.

  • @ayushmamgain9040
    @ayushmamgain9040 Месяц назад +4

    The question requires not to use multiplication operator, but it is used in the last line:
    n = n - (d * (1

  • @areeb6703
    @areeb6703 5 месяцев назад +1

    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.

  • @shwetanshu13
    @shwetanshu13 7 месяцев назад +4

    Thank you so so much.... I was eagerly waiting for the bit manipulation series.

  • @shrutikumbhare2009
    @shrutikumbhare2009 7 месяцев назад +2

    amazing playlist..
    its a humble request to bring a new stack & queue playlist as well

  • @balajisadhu8510
    @balajisadhu8510 6 месяцев назад +4

    i didnt expect i wound complete this bit manipulation tipic in 4 hts in one sitting .. thank you sooo muchhh

  • @viratlover6206
    @viratlover6206 7 месяцев назад +4

    Thank you so much Striver you are motivating us to learn new topics by your videos. You are really doing great work!!

  • @utube4026
    @utube4026 7 месяцев назад +9

    LGTA HAI RAJ BHAI AAJ HI BIT MANUPULATION KHATAM KR DENGE 😂😂😂😂😂😂😂😂. BUT SIR I HAVE MAD RESPECT FOR YOU 😊😊🫡🫡

  • @Codebond7
    @Codebond7 7 месяцев назад +5

    Thanks I will complete till here by tomorrow

  • @akashpurbia4390
    @akashpurbia4390 7 месяцев назад +1

    Thanks for this amazing playlist!

  • @HitheshB-m8w
    @HitheshB-m8w 7 месяцев назад +11

    bro CAN U START STRING SERIES AS WELL PLZZZZZZZZZZZZZZZZZZZZZZZZZ

  • @krityranjanpanda6259
    @krityranjanpanda6259 7 месяцев назад +1

    Great content 😁💯 waiting for string matching algorithms

  • @knowthrvdo
    @knowthrvdo 7 месяцев назад

    add this link to a to z dsa sheet so that students can easily get it and thanks for uploading lectures

  • @RiddhiMS-l5g
    @RiddhiMS-l5g 7 месяцев назад

    Heyy striver,
    I have been learning from your videos and they are very nice.
    I would request you to start string series please.

  • @foziezzz1250
    @foziezzz1250 5 месяцев назад +4

    small doubt
    why did we checked that quotient == 1

  • @NiveditaKar-xj6ew
    @NiveditaKar-xj6ew 7 месяцев назад

    Amazing explaination Striver

  • @kushagrasahay
    @kushagrasahay 7 месяцев назад +1

    thanks for such amazing playlist

  • @stith_pragya
    @stith_pragya 6 месяцев назад +1

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

  • @riteshbisht94
    @riteshbisht94 6 месяцев назад +1

    Please continue the bit manipulation series 🙏

  • @shashankgsharma0901
    @shashankgsharma0901 3 месяца назад

    Understood, btw, innner while loop was O(1) as max is 32 only and it doesn't increase with size.

  • @limitless6189
    @limitless6189 7 месяцев назад +6

    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

  • @017_indrasen9
    @017_indrasen9 7 месяцев назад

    Thank you @Striver respect++

  • @shreyxnsh.14
    @shreyxnsh.14 6 месяцев назад +4

    we were not supposed to use multiplication, then how is this solution valid?

  • @sarder681
    @sarder681 3 месяца назад

    Thank you striver from bangladesh.

  • @mounikap4492
    @mounikap4492 5 месяцев назад

    Please include 1915. Number of Wonderful Substrings, and it would be nice to cover the concept of masking in bit_manipulation series. Thanks.

  • @shreyxnsh.14
    @shreyxnsh.14 6 месяцев назад +11

    this question is so bad, what does this even test? your mugging up skills?

  • @Yogamindmastery
    @Yogamindmastery 3 месяца назад

    Very good explaination thanks a lot Sir

  • @AfzalAsar
    @AfzalAsar 7 месяцев назад +2

    Bhaiyaa please upload stack queue asap as well please 🥺

  • @riteshbisht94
    @riteshbisht94 7 месяцев назад +1

    Great video 🔥

  • @UECAshutoshKumar
    @UECAshutoshKumar 7 месяцев назад +1

    Thank you 😊

  • @sumitsharma-ss2xr
    @sumitsharma-ss2xr 7 месяцев назад

    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

  • @harshith1424
    @harshith1424 7 месяцев назад

    Most wanted topic❤

  • @himanshukaushik9223
    @himanshukaushik9223 7 месяцев назад +2

    Bhaiya a2z sheet pa code and article ka link upload kar do binary search tree pa bhi kuch questions pa nahi hai ??

  • @SuvradipDasPhotographyOfficial
    @SuvradipDasPhotographyOfficial 3 месяца назад

    Striver bhai bit manipulation over, please do strings. It's very important, many questions are getting stuck in string. Please bhai🙏🙏

  • @AdityaKumar-be7hx
    @AdityaKumar-be7hx 4 месяца назад

    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

  • @kunal5077
    @kunal5077 3 месяца назад

    Please start with string playlist sir
    HUMBLE REQUEST TO YOU

  • @shreyxnsh.14
    @shreyxnsh.14 6 месяцев назад +5

    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

  • @ss_shruti10
    @ss_shruti10 Месяц назад

    Please upload String Playlist also :)

  • @sashibhushanarajput1194
    @sashibhushanarajput1194 Месяц назад

    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

  • @Algorithmswithsubham
    @Algorithmswithsubham 7 месяцев назад +2

    sir how to write good quality code uspe ak video banaya

  • @U2011-n7w
    @U2011-n7w 3 месяца назад +1

    best video

  • @AkashKumar-qb6sc
    @AkashKumar-qb6sc 2 месяца назад +1

    Awsm

  • @shaikkhizar8133
    @shaikkhizar8133 7 месяцев назад +1

    Thankyou sir

  • @vaibhavagarwal1479
    @vaibhavagarwal1479 7 месяцев назад

    is this the end of the playlist??
    as there are some advance maths questions there in bit manipulation

  • @karthik-varma-1579
    @karthik-varma-1579 20 дней назад

    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

  • @nisanduathsara5242
    @nisanduathsara5242 7 месяцев назад

    hey striver need a full combinatorics playlist...

  • @SibiRanganathL
    @SibiRanganathL 2 месяца назад +1

    Understood

  • @the_ved11
    @the_ved11 7 месяцев назад

    On the 2nd while condition, why does it not as n>= (d*(1

    • @ckrakle
      @ckrakle 7 месяцев назад

      same as n >= (d

    • @akworld2739
      @akworld2739 6 месяцев назад +1

      check his first video of bit manipulation in left shift

  • @khalasianiket816
    @khalasianiket816 3 месяца назад

    understood ❤

  • @karthik-varma-1579
    @karthik-varma-1579 20 дней назад

    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

  • @Learnprogramming-q7f
    @Learnprogramming-q7f 6 месяцев назад

    Thank you Bhaiya

  • @rishijen7363
    @rishijen7363 7 месяцев назад +1

    Pls string playlist ❤❤❤

  • @rushidesai2836
    @rushidesai2836 7 месяцев назад

    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

  • @udaychaudhary3636
    @udaychaudhary3636 7 месяцев назад +1

    waiting for the string playlist

  • @jaydabhi5539
    @jaydabhi5539 6 месяцев назад

    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.

  • @Rahul-rp5hk
    @Rahul-rp5hk 7 месяцев назад

    Can be easily done in O(logn) too

  • @thanuja.07
    @thanuja.07 7 месяцев назад

    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

  • @abhimanyuthapliyal5823
    @abhimanyuthapliyal5823 3 месяца назад

    isnt TC better for appr 1 , then why is appr 2 reqd ?

  • @ayushraj5672
    @ayushraj5672 7 месяцев назад

    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:⁠-⁠)

  • @akashkumaryadav1827
    @akashkumaryadav1827 2 месяца назад +1

    🔥

  • @govindlohar6816
    @govindlohar6816 5 месяцев назад

    very nice

  • @shaiksoofi3741
    @shaiksoofi3741 4 месяца назад +1

    understood

  • @mohitsingh7793
    @mohitsingh7793 6 месяцев назад

    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

    • @TheHariPutraOfficially
      @TheHariPutraOfficially 2 месяца назад

      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

  • @deepakkumar13204
    @deepakkumar13204 7 месяцев назад

    First view from my sids 😊

  • @sword013
    @sword013 20 дней назад

    the overflow part is still not that clear

  • @ankitpradhan2499
    @ankitpradhan2499 4 месяца назад +1

    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

  • @Chhooso
    @Chhooso 5 месяцев назад

    striver please drop the strings playlist

  • @ritesh_kr
    @ritesh_kr 7 месяцев назад

    what if our d is INT_MIN ?
    ps : i didnt watch the whole lecture 😅

  • @mimansatripathi
    @mimansatripathi 7 месяцев назад

    please start string series 🥺🥺🥺🥺🥺🥺

  • @257divyanshu
    @257divyanshu 6 месяцев назад +1

    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

    • @HaamroNotes
      @HaamroNotes 5 месяцев назад

      // 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

    • @pBERA0_0
      @pBERA0_0 Месяц назад

      same doubt :/
      @257divyanshu

  • @tanishjain1643
    @tanishjain1643 5 месяцев назад

    These code is working in cpp but not in java
    Greeting tle

  • @prajwalrai2596
    @prajwalrai2596 7 месяцев назад

    Waiting for string

  • @ketonesgaming1121
    @ketonesgaming1121 7 месяцев назад

    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

  • @SudhirKumar-ge5nv
    @SudhirKumar-ge5nv 7 месяцев назад

    I just want to believe if the shift operators are used anywhere... 😢😢😢

    • @akworld2739
      @akworld2739 6 месяцев назад

      yes it is too confuesing😅

  • @VisibleNasir
    @VisibleNasir 7 месяцев назад

  • @ayushojha4607
    @ayushojha4607 7 месяцев назад

    start heap playlist

  • @paarthkumar3787
    @paarthkumar3787 3 месяца назад

    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

  • @AbhishekKumar-lh2pt
    @AbhishekKumar-lh2pt 6 месяцев назад

    🙇🙇🙌

  • @abdealimuneem4968
    @abdealimuneem4968 4 месяца назад

    could have also used binary search, amirite//

  • @akshatgoel149
    @akshatgoel149 4 месяца назад +1

    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

  • @sanjaykatta6499
    @sanjaykatta6499 4 месяца назад

    we didn't completely get away from using multiplication even with this code.

  • @MohitKumar-uw1pz
    @MohitKumar-uw1pz Месяц назад

    MAIN HOON MOHIT

  • @zaffarzeshan1308
    @zaffarzeshan1308 5 месяцев назад

    2nd test case failed

  • @slayer-x2f
    @slayer-x2f 2 месяца назад +2

    could have been better

  • @Lucifer0872
    @Lucifer0872 7 месяцев назад

    hail mary

  • @sanjanareddy2696
    @sanjanareddy2696 7 месяцев назад

    Please stop wearing red and try other colors. Its boring now

    • @tousifjaved3485
      @tousifjaved3485 7 месяцев назад

      Red increases attention and engagement of audience
      Maybe that's why he always wears red for video making

  • @ckrakle
    @ckrakle 7 месяцев назад

    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

  • @amitdahiya7425
    @amitdahiya7425 7 месяцев назад +2

    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

    • @the_ved11
      @the_ved11 7 месяцев назад

      On the 2nd while condition, why does it not as n>= (d*(1

    • @takeUforward
      @takeUforward  7 месяцев назад

      it is not possible, did not see any solution working with using int, you can use signed int, but that is violation as well

  • @animeshkumar2683
    @animeshkumar2683 2 месяца назад +1

    Understood

  • @rohanagarwal4290
    @rohanagarwal4290 7 месяцев назад +1

    waiting for strings playlist

  • @Rahulyadav-sd3oj
    @Rahulyadav-sd3oj 7 месяцев назад

    Thank u sir

  • @shashankvashishtha4454
    @shashankvashishtha4454 3 месяца назад

    understood

  • @Sumanth_Siddareddy
    @Sumanth_Siddareddy 3 месяца назад

    Understood

  • @hardikpatel352
    @hardikpatel352 3 месяца назад

    understood