Update appNew update is available. Click here to update.
About
hi there! currently i am pursuing Btech from BVCOE, Delhi
Bharati Vidyapeeth College Of Engineering 2024
C++ - Default language
My Stats
EXP gained
yellow-spark
17747
Level
7 (Expert)
Community stats
Discussions
0
Upvotes
0
Know more
235
Total problems solved
159
Easy
56
Moderate
16
Hard
4
Ninja
Jan Jan Feb Feb Mar Mar Apr Apr May May Jun Jun Jul Jul Aug Aug Sep Sep Oct Oct Nov Nov Dec Dec

Current streak:

0 days

Longest streak:

7 days

Less

More

Achievements
4
Ronin
Topics
Binary Search
Strings
+ 2 more
2
Samurai
Topics
Arrays
Sorting
1
Sensei
Topics
Linked List
Discussions
easy c++ approach
Interview problems

#include<vector>

 

void mergeTwoSortedArraysWithoutExtraSpace(vector<long long> &nums1, vector<long long> &nums2){

    // Write your code here.

 

    

 

        int i=nums1.size()-1;

        int j=0;

 

        while(i>=0 && j<nums2.size()){

            if(nums1[i]>nums2[j]){

                swap(nums1[i], nums2[j]);

                i--;

                j++;

            }

            else{

                break;

            }

 

        }

 

        sort(nums1.begin(), nums1.end());

        sort(nums2.begin(), nums2.end());

        // j=nums2.size();

         

 

        

}

        

 

profile
HARSHIT2001
Published On 03-Sep-2023
135 views
0 replies
2 upvotes
nlogn approach for c++
Interview problems

#include <bits/stdio.h>

#include <bits/stdc++.h>

bool isAnagram(string str1, string str2)

{

    //Write your code here

 

   sort(str1.begin(), str1.end());

   sort(str2.begin(), str2.end());

 

   if(str1!=str2){

       return 0;

   }

   return 1;

}

profile
HARSHIT2001
Published On 09-Aug-2023
69 views
0 replies
0 upvotes
easy approach using recursion
Interview problems

int lowestCommonAncestor(TreeNode<int> *root, int x, int y)

{

    //    Write your code here

    if(root==NULL){

        return -1;

    }

 

    if(root->data==x || root->data==y){

        return root->data;

    }

 

    int leftchild=lowestCommonAncestor(root->left, x,  y);

    int rightchild=lowestCommonAncestor(root->right, x,  y);

 

    if(leftchild==-1 && rightchild==-1){

        return -1;

    }

 

    if(leftchild!=-1 && rightchild==-1){

        return leftchild;

    }

 

    if(leftchild==-1 && rightchild!=-1){

        return rightchild;

    }

    if(leftchild!=-1 && rightchild!=-1){

        return root->data;

    }

}

profile
HARSHIT2001
Published On 09-Aug-2023
16 views
0 replies
0 upvotes
easy approach using recursion
Interview problems

int lowestCommonAncestor(TreeNode<int> *root, int x, int y)

{

    //    Write your code here

    if(root==NULL){

        return -1;

    }

 

    if(root->data==x || root->data==y){

        return root->data;

    }

 

    int leftchild=lowestCommonAncestor(root->left, x,  y);

    int rightchild=lowestCommonAncestor(root->right, x,  y);

 

    if(leftchild==-1 && rightchild==-1){

        return -1;

    }

 

    if(leftchild!=-1 && rightchild==-1){

        return leftchild;

    }

 

    if(leftchild==-1 && rightchild!=-1){

        return rightchild;

    }

    if(leftchild!=-1 && rightchild!=-1){

        return root->data;

    }

}

profile
HARSHIT2001
Published On 09-Aug-2023
16 views
0 replies
0 upvotes
easy approach
Interview problems

#include <bits/stdc++.h> 

int largestElement(vector<int> &arr, int n) {

    // Write your code here.

 

    sort(arr.begin(),arr.end());

    

    int ans=arr[n-1];

    return ans;

}

 

profile
HARSHIT2001
Published On 30-Jul-2023
130 views
0 replies
0 upvotes