hi there! currently i am pursuing Btech from BVCOE, Delhi
Bharati Vidyapeeth College Of Engineering 2024
C++ - Default language
My Stats
EXP gained
17747
Level
7 (Expert)
Community stats
Discussions
0
0
Know more
235
Total problems solved
159
Easy
56
Moderate
16
Hard
4
Ninja

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
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();

}

HARSHIT2001
Published On 03-Sep-2023
135 views
0 replies
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;

}

HARSHIT2001
Published On 09-Aug-2023
69 views
0 replies
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;

}

}

HARSHIT2001
Published On 09-Aug-2023
16 views
0 replies
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;

}

}

HARSHIT2001
Published On 09-Aug-2023
16 views
0 replies
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;

}

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