Lecture21: Solving LeetCode/CodeStudio Questions [Arrays]

Поділитися
Вставка
  • Опубліковано 1 гру 2024

КОМЕНТАРІ • 638

  • @CodeHelp
    @CodeHelp  3 роки тому +54

    Do Visit Relevel: relvl.co/2smk

    • @ShouryaPant
      @ShouryaPant 3 роки тому +5

      Bhaiyaa notes ki link galt dal gyi

    • @Góne-y2s
      @Góne-y2s 3 роки тому +1

      reach++

    • @CodeHelp
      @CodeHelp  3 роки тому +7

      @@ShouryaPant corrected

    • @ShouryaPant
      @ShouryaPant 3 роки тому +6

      @@CodeHelp thanx Bhaiyya You are Doing An Amazing Job. 👏 This Course Is Fantastic And awesome. KEEP it Up The Good Work🙂🙂

    • @siddharth7261
      @siddharth7261 3 роки тому +1

      @@CodeHelp Sir, I can create an interactive blog that will help students to get topic wise notes along with code for this DSA course.

  • @shreyanshthakur5405
    @shreyanshthakur5405 2 роки тому +72

    "Programming pe kam focus karo, engineering pe zyada focus karo" (Before bursting out to code, first break the problem into subparts or conditons). Awesome lecture bhaiya

  • @deeppatel0586
    @deeppatel0586 2 роки тому +212

    if you hate the subject, its because of the teacher.
    if you love the subject, its because of the teacher.
    tremendous thanks babbar sir.

  • @saignaneswarsutrave1171
    @saignaneswarsutrave1171 2 роки тому +61

    My approach for Rotate Array problem:
    1. Reverse the whole vector
    2. Reverse the first k elements of the vector
    3. Reverse the remaining elements of the vector
    code:
    void rotate(vector &nums, int k){
    k = k % nums.size();
    reverse(nums.begin(), nums.end());
    reverse(nums.begin(), nums.begin() + k);
    reverse(nums.begin() + k, nums.end());
    }
    Dry run:
    arr = {1, 2, 3, 4}
    k = 2
    step 1: {4, 3, 2, 1}
    step 2: Reverse first two elements -> {3, 4, 2, 1} (k = 2 -> reverse elements present at 0th and 1st index)
    step 3: Reverse the remaining elements -> {3, 4, 1 , 2}

    • @ashish7604
      @ashish7604 5 місяців тому

      hey did you get somewhere or this was your organic thinking if it was what was your approach

    • @_PRANAYMATE
      @_PRANAYMATE 4 місяці тому

      @@ashish7604 Nice bro

  • @yatharthahuja1635
    @yatharthahuja1635 2 роки тому +11

    Question 3) Add 2 arrays can also be done in the following way.
    vector reverse(vectorv){
    int s = 0;
    int e = v.size()-1;
    while(s=0;i--){
    res1 = res1 + (a[i]*mul);
    mul=mul*10;// this was the changing step
    }
    mul=1;
    for(int i=m-1;i>=0;i--){
    res2 = res2 + (b[i]*mul);
    mul=mul*10;
    }
    int total = res1+res2;
    while(total > 0){
    int ele = total % 10;
    ans.push_back(ele);
    total = total / 10;
    }
    return reverse(ans);
    }

  • @nischalgupta8050
    @nischalgupta8050 3 роки тому +24

    I found your playlist on dsa few days ago and I loved this playlist

  • @er.preetiyadav1688
    @er.preetiyadav1688 3 роки тому +14

    "why I started...?"
    This line motivates me a lot...
    Thnks bhaiya..❣️❣️

  • @cr7motive720
    @cr7motive720 3 роки тому +19

    Blessings of many students are with you
    Keep going bhaiya 🙏🙏(respect)

  • @sounaksaha1455
    @sounaksaha1455 3 роки тому +6

    Present Bhaiyaji,
    Aap sirf video dalte rahiye .. humare taraf se full support aur mehenat hum darshaate rahenge...
    Aur ye course duniya ka best course hai.

  • @zhrrBro
    @zhrrBro 2 роки тому +21

    Homework | Time Complexities |
    1> TC = O(n)
    SC = O(n)
    2> TC = O(n)
    SC = O(1)
    3> TC = O(n+m)
    SC = O (n+m)
    Awesome Lecture !!

    • @amitprakhar4802
      @amitprakhar4802 Рік тому

      Why it is showing time limit exceeded the find sum question

    • @amitprakhar4802
      @amitprakhar4802 Рік тому

      In gfg ide

    • @OmPrakash-vk4ko
      @OmPrakash-vk4ko Рік тому

      ig both time and space should be ----> O(min(M,N) + {max(M,N)-min(M,N)} + 1)
      becz 1st loop will run till one of the array ends
      2nd will run till other part and carry could not be of more than one digit
      Am I thinking right🤔

  • @amitshukla2268
    @amitshukla2268 3 роки тому +49

    My approach for 3rd question :-
    vector findArraySum(vector&a, int n, vector&b, int m) {
    int x=a[0],y=b[0];
    for(int i=1;i

    • @anuragraut5101
      @anuragraut5101 2 роки тому +1

      this was the first approach that came to my mind after seeing the question

    • @bishalchatterjee745
      @bishalchatterjee745 2 роки тому +2

      I did a similar code but was facing issue with the carry part.. Thanks for the help buddy>>!!

    • @amitshukla2268
      @amitshukla2268 2 роки тому +3

      @@bishalchatterjee745 welcome bro :)

    • @taranjotsingh2374
      @taranjotsingh2374 2 роки тому

      Thanks for the solution. @Amit Shukla but what would be the time complexity of this solution?

    • @bishalchatterjee745
      @bishalchatterjee745 2 роки тому +1

      @@taranjotsingh2374 O(n)

  • @bcs_Jaskaran
    @bcs_Jaskaran Рік тому +1

    Check sorted and rotated :
    {
    int n = given.size();
    vector temp(n);
    temp = given;
    sort(given.begin(), given.end());
    vector check(n);
    for (int k = 0; k < n; k++)
    {
    for (int i = 0; i < n; i++)
    {
    int pos = (i + k) % n;
    check[i] = given[pos];
    }
    if (check == temp)
    {
    return 1;
    }
    }
    return 0;
    }

  • @valendradangi1822
    @valendradangi1822 11 місяців тому +1

    We can also do the 3rd question as follows:
    vector findArraySum(vector &a, int n, vector &b, int m)
    {
    int num1 = 0, num2 = 0, num3r = 0, num3;
    for (int i = 0; i < n; i++)
    {
    num1 = num1 * 10 + a[i];
    }
    for (int i = 0; i < m; i++)
    {
    num2 = num2 * 10 + b[i];
    }
    num3 = num1 + num2;
    cout

  • @avijeetpaul1378
    @avijeetpaul1378 Рік тому +2

    love your channel sir, hats of to you.
    i have a small add-on to the last question, as i tried to solve the last question before hand of watching the solution, so i came up with my solution as:
    I would first convert the arrays into an integer, and the sum the both converted integer to get the final answer and then mod the answer with 10 to get the remainders and push that remainder into a vector and later reverse it to get the final answer.
    Code:
    #include
    vector findArraySum(vector&a, int n, vector&b, int m) {
    int sum1=0, sum2=0;
    int sig=0;
    for(int i=n-1;i>=0;i--){
    sum1=sum1+(a[i]*pow(10,sig));
    sig++;
    }
    sig=0;
    for(int i=m-1;i>=0;i--){
    sum2=sum2+(b[i]*pow(10,sig));
    sig++;
    }
    int sum=sum1+sum2;
    vector arr;
    while(sum!=0){
    int temp=sum%10;
    arr.push_back(temp);
    sum/=10;
    }
    reverse(arr.begin(),arr.end());
    return arr;
    }
    And thank you so much for your incredible persistence sir.

  • @pratyush2331raj
    @pratyush2331raj 2 роки тому +4

    Time Complexities
    Q1- TC = O(n)
    SC = O(n)
    OR
    // For recursive approach
    TC = O(n)
    SC = O(1)
    Q2- TC = O(n)
    SC = O(1)
    Q3- TC = O(max(n, m))
    SC = O(max(n, m))

  • @sumitshetty295
    @sumitshetty295 3 роки тому +14

    Another solution for Array rotation : (Using Reversal Algorithm)
    void rotate(vector& nums, int k)
    {

    int pos = nums.size()-(k%nums.size());

    //reversing last k elements
    reverse(nums.begin()+pos,nums.end());

    //reversing remaining nums.size()-k elements
    reverse(nums.begin(),nums.begin()+pos);

    //reversing whole vector
    reverse(nums.begin(),nums.end());
    }
    Time Complexity : O(N)
    Space Complexity: O(1)

  • @shifteditz06
    @shifteditz06 2 місяці тому +1

    Question 3 : easiest and shortest solution
    string s1, s2;
    for(int i=0;i integer to string
    vector arr;

    for(int i=0;i

  • @rishabhtyagi7369
    @rishabhtyagi7369 2 роки тому +5

    Another solution for finding if the array is rotated or sorted or both:
    #include
    using namespace std;
    void check(int arr[], int n){
    int count = 0;
    for(int i = 0; iarr[i+1]){
    count++;
    }
    }
    if(count==1 && arr[0]>arr[n-1]){
    cout

  • @akshayjain1332
    @akshayjain1332 2 роки тому +6

    (my approach to q3: using some old tricks taught by luv bhaiya ❤️)
    vector findArraySum(vector&a, int n, vector&b, int m) {
    int num1 = 0 ;
    int num2 = 0 ;
    int sum = 0;
    vector ans;
    for(int i = 0;i

    • @taranjotsingh2374
      @taranjotsingh2374 2 роки тому +1

      Can you help in explaining the time complexity of this solution

    • @AkshayKumar-gm7mx
      @AkshayKumar-gm7mx 2 роки тому

      your solution is good enough. but don't repeat the step to calculate num1 and num2. Just define a function to do that for u.

  • @ritikchaudhary1232
    @ritikchaudhary1232 3 роки тому +7

    Rotate ques : Time complexity -> O(n)
    space complexity -> O(n) , n is size of nums vector.
    Sorted and Rotated : Time Complexity-> O(n)
    space complexity -> O(1)
    Add array : Time complexity -> O(m+n)
    Space Complexity -> O(m) or O(n).
    if I am wrong anywhere please correct me.

    • @KushalChandar.
      @KushalChandar. 2 роки тому

      I think
      Time Complexity-> O(max(m, n)); //only one of 2 while loops will execute //i,e i >= 0 or j >= 0
      Space Complexity-> O(max(m, n));
      //carry while loop does can actually be made into a if statement, i think carry can only be 0 or 1,
      correct me if i am wrong

  • @jayant-baid
    @jayant-baid 2 роки тому +3

    Another Approach for Sum of Two Arrays
    vector findArraySum(vector&a, int n, vector&b, int m) {
    int sum1=0,sum2=0;
    for(int i=0;i

    • @avibirla9863
      @avibirla9863 2 роки тому

      Nice approach 👍

    • @jayant-baid
      @jayant-baid 2 роки тому

      @@avibirla9863Thankyou

    • @xeroday342
      @xeroday342 2 місяці тому

      bhai ye hi mene socha tha ,kya ye cases waki bakchodi karni😅

  • @abhaysingh1665
    @abhaysingh1665 2 роки тому +2

    This line "Hello jii this is love babbar" gives us a peace and motivation that i can do 🙏🙏🙏

  • @youtubeshortz20
    @youtubeshortz20 2 роки тому +3

    rotated arrray without using extra space :-
    k =k%nums.size();
    reverse(nums.begin(),nums.end());
    reverse(nums.begin(),nums.begin()+k);
    reverse(nums.begin()+k,nums.end());

  • @vishaljoshi-v5i
    @vishaljoshi-v5i 11 місяців тому

    My Approach for the first question is -->
    void rotate(vector arr, int key)
    vector::iterator it = arr.begin() + key - 1;
    reverse(arr.begin(), arr.end());
    reverse(it+1, arr.end());
    it = arr.begin() + key;
    reverse(arr.begin(),it);

  • @aniket_k720
    @aniket_k720 3 роки тому +2

    Love bhaiyaa 🌹❤️
    Watching your videos since i was in class 11th .....now i am in college and feel.glad that am following ur videos since then.....helpsss too much........🌹

  • @kunalkamthe8039
    @kunalkamthe8039 Рік тому +3

    This placement series is awesome bhaiya and best ever series on dsa ever...

  • @akashthoriya
    @akashthoriya 3 роки тому +1

    me Saturday-sunday pura din beth ke, video dekhta hu aur practice bhi karta hu,
    Thank you bhai💛🤗

  • @sunnykakrani7830
    @sunnykakrani7830 2 роки тому

    Simple Approach in array sum : we can avoid the usage of carry as well .
    vector findArraySum(vector&a, int n, vector&b, int m) {

    int num1=0;
    int num2=0;

    int j=n-1;
    // create the first number
    for(int i=0;i

  • @dbgaming7722
    @dbgaming7722 2 місяці тому +1

    another approach to solve rotate an array
    class Solution {
    public:
    void reverse(vector& arr, int s, int e){
    while(s

  • @jiyasharma9225
    @jiyasharma9225 Рік тому +1

    second ques using modulus
    class Solution {
    public:
    bool check(vector& nums) {
    int n=nums.size();
    int count = 0;
    for(int i=0;inums[(i+1)%n]){
    count++;
    }
    }

    return count

  • @nainaryan
    @nainaryan 2 роки тому +4

    we have to use ans.pop_back(sum);
    in 3rd question to avoid reverse function

  • @RaniKumari-io1rr
    @RaniKumari-io1rr 2 роки тому +4

    this could be also a solution of sum of two arrays.
    please consider this code also
    vector reverse(vectorv) {
    int s=0;
    int e=v.size()-1;
    while(s

  • @goldiison9663
    @goldiison9663 2 роки тому +1

    First
    By the review of your course in UA-cam i don't visit your channel but now from this video i recommend my friend your channel.

  • @princejacker321
    @princejacker321 3 роки тому +30

    Time Complexities
    Q1- Time=O(n)
    Space=O(n)
    Q2- Time=O(n)
    Space=O(1)
    Q3- Time=O(n+m)
    Space=O(n+m)

    • @backbencher304
      @backbencher304 2 роки тому

      n+n kaise hoga bro ak bar explain kr de.....m confuse ho rha hu is question m

  • @Mb-nr5nz
    @Mb-nr5nz Рік тому +1

    for 3rd question we can also use this , i tried this code by myself
    #include
    vector findArraySum(vector&a, int n, vector&b, int m) {
    // Write your code here.
    int sum1 = 0;
    for (int i= 0 ; i < n ; i++ )
    {
    sum1 = sum1 * 10 ;
    sum1 = sum1 + a[i];
    }
    int sum2 = 0;
    for (int i= 0 ; i < m ; i++ )
    {
    sum2 = sum2 * 10 ;
    sum2 = sum2 + b[i];
    }
    int sum = sum1 + sum2 ;
    vector c ;
    while (sum != 0)
    {
    c.push_back(sum % 10) ;
    sum = sum / 10;
    }
    reverse (c.begin() , c.end());
    return c;
    }

  • @awais_ansarii
    @awais_ansarii 2 роки тому +6

    Thank you for this placement series Bhaiya
    We're learning and enjoying a lot.

  • @rahulstudies1178
    @rahulstudies1178 2 роки тому +2

    q1) time complexity- O(n)
    q2) O(n);
    q3) O(n+m);

  • @iconliving9076
    @iconliving9076 2 роки тому +1

    Best way of teaching. Quick and quirky. Please keep on making such videos.

  • @LootCrack
    @LootCrack Рік тому +1

    "check if array is sorted and rotated" Sir is question me loop i=1 se i

  • @ayushanand4938
    @ayushanand4938 3 роки тому +2

    //Add 2 arrays(Without extra array/vector)
    vector findArraySum(vector&a, int n, vector&b, int m) {
    //setting the large array in a and small in b
    if(n=0){
    int sum=a[j]+b[i]+carry;
    carry=sum/10;
    sum=sum%10;
    a[j]=sum;
    i--;
    j--;
    }
    while(j>=0){
    long sum=a[j]+b[i]+carry;
    carry=sum/10;
    sum=sum%10;
    a[j]=sum;
    if(carry==0)
    break;
    j--;
    }
    if(carry!=0)
    a.insert(a.begin(),carry);
    return a;
    }

  • @Shivamkumar-xu6hu
    @Shivamkumar-xu6hu 3 роки тому +2

    #consistency op
    Both your and mine let's see who will break first 😂

  • @vigneshv7632
    @vigneshv7632 3 роки тому +3

    I sticked until last minute. I am liking it. Let's keep the josh high🔥

  • @arungujjar7328
    @arungujjar7328 3 роки тому +1

    Bhaiya, i just saw a comment in telegram channel which u shared... ignore that type of people they themselves are chu****...u are doing a great job... thanks a lot bhai for this type of content for free❣️🙌

  • @29-rohitkatare3
    @29-rohitkatare3 3 роки тому +2

    problem 1: TC O(n), SC O(n)
    problem 2: TC O(n), SC O(1)
    problem 3: TC O(max(n,m)+(n)), SC O(n)

  • @MOTO-SP
    @MOTO-SP Рік тому +2

    my apporach for q3
    eg
    first we take a[ ] = { 4,5,1} and b[ ] = { 3,4,5}
    we add a as 451 by (ans x 10) + digit ( i.e here 4) == 4
    now ( 4 x 10 ) + 5= 45
    (45 x 10) +1 = 451
    similarly we get 345
    now we add them to get 796
    now
    Get the last digit of the number
    Insert the digit at the beginning of the vector
    number /= 10; // Remove the last digit from the number
    to get c[ ] ={7,9,6}
    open for suggestions

  • @ankushladani496
    @ankushladani496 3 роки тому +1

    Abhi aaya hu dekhne ke pehle hi bol diya done..👍👍

  • @discoverComputerprogramming7
    @discoverComputerprogramming7 4 місяці тому

    bool check(vector &arr){
    int count =0;
    for(int i=1; iarr[i] % arr.size())
    count++;
    }
    return count

  • @piyushborkar6803
    @piyushborkar6803 3 роки тому +1

    Love bhaiya content bohot tagde level ka aa raha hai 🔥🔥😍 Aise hi banate raho

  • @abhirajvarshney7394
    @abhirajvarshney7394 2 роки тому

    (Diff approach) Sum of two arrays :
    vector findArraySum(vector&a, int n, vector&b, int m) {
    int ans1 = 0, ans2 =0,ans3=0,ans,i;
    vector c;
    i=0;
    while(i

  • @amandeshpande8981
    @amandeshpande8981 3 роки тому +1

    This is way better than uploading a 4 hr video In a day and taking break for weeks

  • @rishabhjha2356
    @rishabhjha2356 3 роки тому +1

    rotate by k(without using extra space)
    void rotateFull(vector& num,int s,int e){
    int n=num.size();

    while(s

  • @patelrajkumarnareshkumar8156
    @patelrajkumarnareshkumar8156 2 роки тому +1

    easy way to solve sum of two array wala problem
    vector findArraySum(vector&a, int n, vector&b, int m) {
    // Write your code here.
    int A = 0 , B = 0 ;
    for(int i = 0 ; i < n ; i++){
    A = A*10 + a[i];
    }
    for(int i = 0 ; i < m ; i++){
    B = B*10 + b[i];
    }
    A= A + B;
    vector sum;
    while(A > 0){
    int mod = A % 10;
    sum.push_back(mod);
    A = A / 10 ;
    }
    reverse(sum.begin() , sum.end());
    return sum;
    }

  • @hyderali1520
    @hyderali1520 3 роки тому

    bhaiya apka solutions ka approach ko 100 topoo ki salamii.maja araha hai dsa karna ma ab pahla stress ata tha rona ata tha.

  • @bharatchudasama8853
    @bharatchudasama8853 Рік тому +1

    Q1- Time=O(n)
    Space=O(n)
    Q2- Time=O(n)
    Space=O(1)
    Q3- Time=O(n+m)
    Space=O(n+m)

  • @mitesh3579
    @mitesh3579 3 роки тому +1

    *My approach for "check if array is sorted and rotated..."*
    class Solution {
    public:
    bool check(vector& nums) {
    int n = nums.size();
    int ans =0;
    for(int i=0; i nums[(i+1)%n]){
    ans++;
    }
    }
    if (ans

    • @bellalmahtab8220
      @bellalmahtab8220 2 роки тому

      Bhaii yhaa num se pehle ampersand kyu lgaya haii btayee ga Kya

    • @blackfox3586
      @blackfox3586 10 місяців тому

      In sorted and rotated how nums[i-1]>nums[i] if it's sorted

  • @mahimanbansal1709
    @mahimanbansal1709 5 місяців тому

    heres another approach for sum of array
    vector c;
    int s1=0;
    int s2=0;
    for(int i=n-1;i>=0;i--){
    s1=a[i]*pow(10,i)+s1;
    }
    for(int i=0;i

  • @programmer545
    @programmer545 2 роки тому +2

    ques 1 :
    time complexity : o(n)
    space complexity : o(n)
    ques 2:
    time complexity : o(n)
    space complexity : o(1)
    ques 3:
    time complexity : o(n+m)
    space complexity : o(n+m)
    please correct if wrong anywhere?

  • @a_28_mayekarprathameshmang88

    1)Rotate array
    Time Complexity - O(n)
    Space Complexity - O(n)
    2)check sorted and rotated
    Time Complexity - O(n)
    Space Complexity - O(1)
    3)sum of two arrays
    Time Complexity - O[max(m,n)]
    Space Complexity - O[max(m,n)]

  • @usersb685
    @usersb685 Рік тому

    bhaiya apne ye kaisa logic soch liya mujhe ye dekh ke differentiation yaad aaa gya

  • @AkhilBharti-k5t
    @AkhilBharti-k5t 9 місяців тому

    For third question you can use this approach too :
    vector findArraySum(vector&a, int n, vector&b, int m) {

    vector ans;
    int temp1 = 0, temp2 = 0;
    for(int i = 0; i < n; i++){
    temp1 = (temp1 * 10) + a[i];
    }
    for(int j = 0; j < m; j++){
    temp2 = (temp2 * 10) + b[j];
    }
    int sum = temp1 + temp2;
    while(sum != 0){
    ans.insert(ans.begin(), sum % 10);
    sum /= 10;
    }
    return ans;
    }

  • @divyanshrathore8878
    @divyanshrathore8878 2 роки тому

    My approach for Q2.
    int count=0;
    for(int i=0;i

  • @shobhitkatiyar9224
    @shobhitkatiyar9224 2 роки тому

    Rotate ques :
    Time complexity -> O(n)
    space complexity -> O(n)
    Sorted and Rotated :
    Time Complexity-> O(n)
    space complexity -> O(1)
    sum of two array :
    Time complexity -> O(n+m)
    Space Complexity -> O(n).

  • @kunalhole6911
    @kunalhole6911 3 роки тому +4

    Bhaiyaa Time Complexity bhii Code kii discuss karna video may.
    After coding discuss the complexity of solution so Practise hoti rahagiii dono kiii code kii bhii aur complexity ki bhii.

    • @CodeHelp
      @CodeHelp  3 роки тому +1

      will make it as a practice from next video

  • @patelrajkumarnareshkumar8156
    @patelrajkumarnareshkumar8156 2 роки тому +1

    we can solve rotate array without using extra space
    class Solution {
    public:
    void rotate(vector& nums, int k) {
    k %=nums.size();
    reverse(nums.begin(), nums.end());
    reverse(nums.begin(), nums.begin()+k);
    reverse(nums.begin()+k, nums.end());
    }
    };

  • @Avi058
    @Avi058 4 місяці тому

    my approach of 2nd ques derived from rotated array ques
    class Solution {
    public:
    bool check(vector& nums) {
    int n = nums.size();
    int i = 0 , j = 0 , k=0;
    vectortemp(n);
    for(int i = 0 ; i < n-1 ; i++)
    {
    if(nums[i] > nums[i+1])
    {
    k = i+1;
    break;

    }
    }
    while(i < n)
    {
    j = (i + (n-k) )%n;
    temp[j] = nums[i];
    i++;
    }
    sort(nums.begin(),nums.end());
    if(nums == temp)
    {return true;}
    else
    {return false; }

    }
    };

  • @varun-qm3xj
    @varun-qm3xj 2 роки тому

    bhaiya aj 3no question khud se lagaye maza he aagya. confidence next level hai ab

  • @rishabhrajdhiman3005
    @rishabhrajdhiman3005 2 роки тому +1

    I did the last one like this :
    vector findArraySum(vector&a, int n, vector&b, int m) {
    // Write your code here.
    int numa = 0;
    int numb = 0;
    for(int i=0 ; i

  • @I_Anupam_Pandey
    @I_Anupam_Pandey 3 роки тому +2

    attendance lecture 21
    thank you bhaiya for this amazing video
    aur notes ma lagta ha apke raw video file upload ho gaye haan

  • @karanmehra3305
    @karanmehra3305 2 роки тому

    in question 3 we can use stack for the (sum of two arrays) resultant array . we don't need to write the reverse function .
    because the stack works on LIFO principal.
    thank you love bhai

  • @sadaf_r
    @sadaf_r 2 роки тому

    Question bahot sahi le rahe ho bhaiya...ekdum kadak level k🔥maja aagya

  • @dwivedi6037
    @dwivedi6037 2 роки тому

    Rotate arrays: time complexity ==> O(n)
    space complexity ==> O(n) , n is size of nums vector.
    Rotated and sorted array: time complexity ==> O(n)
    space complexity ==> O(1)
    Add array : Time complexity ==> O(m+n)
    space complexity ==> O(m) or O(n).

  • @RohitKumar-oo8lo
    @RohitKumar-oo8lo 2 роки тому +1

    Going great, bhaiya!
    Keep it up! We are with you!

  • @jagmohanrai2714
    @jagmohanrai2714 Рік тому

    Explanation of sum of array is awesome bhaiya best explanation I did not see anywhere,explanation like yours thanx

  • @RohitRana-tz2lr
    @RohitRana-tz2lr 2 роки тому +1

    Thanks, bhaiya, I am continuously watching your DSA series. I am loving it so much

  • @AakashShah-y3s
    @AakashShah-y3s Рік тому

    Ek he to dil hai , kitne bar jitoge babbar bhai

  • @OmPrakash-vk4ko
    @OmPrakash-vk4ko Рік тому

    for third question this could also be one of the solution : -
    class Solution{
    public:
    vector findSum(vector &a, vector &b) {
    // T.C & space complexity ----> O(M+N)
    // finding integers
    vector ans;
    int num1=0, num2=0;
    // 1st number
    int j=0;
    for(int i=a.size()-1; i>=0; i--){
    int last_D1 = a[i];
    num1 += pow(10,j++)*last_D1;
    }
    // 2nd number
    int k=0;
    for(int i=b.size()-1;i>=0;i--){
    int last_D2 = b[i];
    num2 += pow(10,k++)*last_D2;
    }

    // new num = sum
    int sum = num1 + num2;
    while(sum!=0){
    int lastD = sum%10;
    ans.insert(ans.begin(),lastD);
    sum /=10;
    }
    return ans;
    }
    };

  • @anmol3
    @anmol3 Рік тому

    Runtime 16 ms < 175 ms
    Solution 3
    //Sum of two arrays
    vector findArraySum(vector&arr1, int size1, vector&arr2, int size2) {
    int size1=arr1.size(), size2=arr2.size();
    vector ans(max(size1, size2)+1,0);
    int size3=ans.size();
    int i=size1-1, j=size2-1, k=size3-1;
    int carry=0;
    while(i>=0 && j>=0){
    ans[k]=(arr1[i]+arr2[j]+carry)%10;
    carry=(arr1[i]+arr2[j]+carry)/10;
    if (carry==1) ans[k-1]=1;
    i--, j--, k--;
    }
    while(i>=0){
    ans[k]+=arr1[i];
    i--; k--;
    }
    while(j>=0){
    ans[k]+=arr2[j];
    j--; k--;
    }
    if(ans[0]==0){
    for(int i=0; i

  • @poojayadav695
    @poojayadav695 3 роки тому

    Ques1-Time complexity-O(n)
    space complexity-O(n)
    Ques2-Time complexity-O(n)
    space complexity-O(1)
    Ques3-Time complexity-O(n+m)
    space complexity-O(max(n,m))

  • @anuragpandey8165
    @anuragpandey8165 2 роки тому +1

    Check if rotated and sorted array - Without extra space ( temp ) --- > O(n) | O(1) solution:
    class Solution {
    public:
    void rotate(vector& nums, int k)
    {
    k = k%nums.size();
    int s1 = 0, e1 = nums.size()-k-1;
    int s2 = nums.size()-k, e2 = nums.size()-1;
    while(s1

  • @sandipdegloore3494
    @sandipdegloore3494 2 роки тому

    Time complexities :
    1} time = O(n)
    space complexities = O(n)
    2}
    time complexities = O(n) and
    space complexities = O(1)
    3}
    time complexities = O(n) or O(m) and
    space complexities = O(n)

  • @shashinibhat8989
    @shashinibhat8989 3 роки тому +2

    Top level consistency🔥🔥🔥

  • @priyanshubari9685
    @priyanshubari9685 6 місяців тому

    on leetcode, the first question states that you have to solve it using constant space complexity. the solution provided has linear space complexity.

  • @siftainejaz4772
    @siftainejaz4772 Рік тому

    Bhaiya.. Sum of two arrays ka aur tareeka hai. I thought it might be helpful for a lot of peaple. So, I am posting this.
    vector c;
    int sum=0;
    int sum1=0;
    for(int i=0;i

    • @devanshraghuwanshi710
      @devanshraghuwanshi710 Рік тому

      bhai while loop kese kaam kar rha hai yaha pe aap har total ki last digit ko vector ek beginning me dalte jaa rhe ho isse to vector me total ka reverse aaa jayega

  • @coder9760
    @coder9760 2 роки тому

    ADD ARRAY another Aproach :-
    vector findArraySum(vector&a, int n, vector&b, int m) {
    int num1=0,num2=0,ans;
    vector temp;
    for(int i=0;i

  • @pranav_1056
    @pranav_1056 3 роки тому +1

    Commenting for reach
    Babbar bhai great job ! ❤️

  • @AdityaKumar-dz1pf
    @AdityaKumar-dz1pf 2 роки тому

    Before looking to solution for 3rd ques I tried this one and successfully run.
    vector findArraySum(vector&a, int n, vector&b, int m) {
    // Write your code here.
    int sum_a=0,sum_b=0;
    vector ans;
    for(int i=0;i

  • @aditya_jainn
    @aditya_jainn 2 роки тому

    1) time complexity- O(n)
    2) O(n);
    3) O(n+m);

  • @sanskargour6673
    @sanskargour6673 2 роки тому +4

    22:16 Question 3 (alternate code) -
    #include
    using namespace std;
    int digit (int arr[],int n) {
    int digit = 0;
    for (int i = 0 ; i < n ; i++ ) {
    digit = digit* 10 + arr[i];
    }
    return digit;
    }
    int main() {
    int arr1[3] = {1,2,3} , arr2[2] = {9,9};
    int n = 3 , m = 2 ;
    cout

  • @kaushikmandal8061
    @kaushikmandal8061 2 роки тому

    1st question -> TC = O(n), SC = O(n)
    2nd question -> TC = O(n), SC = O(1)
    3rd question -> TC = O(n+m), SC = O(temp)

  • @erenyeager6092
    @erenyeager6092 2 роки тому

    easier approch for Q1.
    class Solution {
    public:
    void rotate(vector& nums, int k) {
    int n=nums.size();
    k%=n;
    reverse(nums.begin(),nums.end());
    reverse(nums.begin(),nums.begin()+k);
    reverse(nums.begin()+k,nums.end());

    }
    };

  • @gurpreetSingh-ir3ho
    @gurpreetSingh-ir3ho 2 роки тому

    rotate an array---->
    class Solution {
    public:
    void rotate(vector& nums, int k) {
    k %=nums.size();
    reverse(nums.begin(), nums.end());
    reverse(nums.begin(), nums.begin()+k);
    reverse(nums.begin()+k, nums.end());
    }
    };

  • @harshk8609
    @harshk8609 3 роки тому +87

    Request: web dev ka course kb tk aayega because dsa itna achaa h to pta nhi dev fir Kitna khaas hoga

    • @harshk8609
      @harshk8609 3 роки тому +4

      @@shubham5934 bro jitna jldi hoga utna shi rhega

    • @siddheshabnave2101
      @siddheshabnave2101 3 роки тому

      Tu 4th year mai hai?

    • @sjcreations2490
      @sjcreations2490 3 роки тому +10

      @@shubham5934 bhia web development itna important nahi jitna dsa he. Aur waise bhi web d samajh sakte ho apne ap se par dsa samajhne ke liye teacher. So let bhaiya teach dsa first

    • @priyamtiwari391
      @priyamtiwari391 2 роки тому

      Ruko jara sabar karo

    • @rameshmalhotra9525
      @rameshmalhotra9525 2 роки тому

      ua-cam.com/video/tAQIKe0UGH4/v-deo.html

  • @crazy_stanle
    @crazy_stanle 3 роки тому

    Semester chalrahe hai
    Semester khatam hote hi Sare vedios dekhlungaa
    APP DAREHAATE RAHOO
    BABBAR BRO

  • @bansalshivam
    @bansalshivam Рік тому

    Reverse array algo to rotate the array is better than modulo algo as in-place solution is require and it has better space complexity O(1).

  • @Risingstar-k6w
    @Risingstar-k6w 23 дні тому

    we can solve 3rd question using one more method by if we create a number by accessing the elements from vector and in initital lecture you taught one formula of ans=ans*10+digit it will create a number then simply add them

  • @sujalsharma5181
    @sujalsharma5181 3 місяці тому

    its good that you were able to solve this rotated and sorted question but i don't think anyone should approach a question like you did which was depending on the test it worked this time but won't work every time and plus it was very clear that you have already been to this question many times, like the way you approached tells that there was literally no concept used

    • @sujalsharma5181
      @sujalsharma5181 3 місяці тому

      go and watch NeetCode's solution, the way that guy solved the question is exactly how you should approach and analyze a question

    • @sujalsharma5181
      @sujalsharma5181 3 місяці тому

      And want to know why he was able to solve this ? because he is very good at this but remember not everyone can teach others

  • @_IT_RajnishKrYadav
    @_IT_RajnishKrYadav 2 роки тому

    Add 2 array wala ko aise bhi solve kr skte h n - carry ka jhamela hi nai esme 😅😅
    int s1=0, s2=0; //s1 = digit of Array1 & s2 = digit of array2
    vector ans;
    for(int i=0; i

  • @SACHINKUMAR-ye8dc
    @SACHINKUMAR-ye8dc 2 роки тому

    add 2 arrays : diffrent approach
    solution :
    vector findArraySum(vector&a, int n, vector&b, int m) {

    int digit1=0;
    for(int i=0;i

  • @geekyprogrammer4831
    @geekyprogrammer4831 2 роки тому

    I like your course more than MIT Data Structures and Algorithms!

  • @9852963775aaa
    @9852963775aaa 3 роки тому

    bhaiya teeno questions solve hogaye thankyou so much bhaiya>>>>>>