Update appNew update is available. Click here to update.
About
Aspiring Software Developer with expertise in Web Development, DSA, Data Science, & Cloud Deployment. Ranked number 1 in BTech CSE, have a strong academic background in Computer Science and Engineerin...
Major League Hacking - SDE - Intern
Vellore Institute of Technology 2024
C++ - Default language
My Stats
EXP gained
yellow-spark
34968
Level
7 (Expert)
Community stats
Discussions
0
Upvotes
1
Know more
Weekend contest rating
Contest attended
Problems solved
2021 2023
Better than %
Weekend contest rating
Contest attended
Problems solved
2021 2023
Better than %
598
Total problems solved
464
Easy
96
Moderate
16
Hard
22
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:

10 days

Less

More

Achievements
Contest Ranks
7
Ronin
Topics
Linked List
Strings
Heap
+ 4 more
5
Samurai
Topics
Arrays
Tries
Sorting
+ 2 more
1
Sensei
Topics
SQL
1
Ronin
Guided path
Basics of java
1
Sensei
Guided path
Oops in C++
Discussions
Optimal Solution | Pair Sum
Interview problems
#include <bits/stdc++.h>
vector<vector<int>> pairSum(vector<int> &arr, int s){
   sort(arr.begin(), arr.end());
   vector<vector<int>>ans;
   for(int i=0;i<arr.size()-1;i++){
      vector<int>temp;
      for(int j=i+1;j<arr.size();j++){
         if(arr[i]+arr[j]==s){
            temp.push_back(arr[i]);
            temp.push_back(arr[j]);
            ans.push_back(temp);
         }
         if(arr[i]+arr[j]>s){
            break;
         }
      }
      
   }
   return ans;
}
profile
hariketsheth
Published On 09-Jul-2023
422 views
0 replies
4 upvotes
LCA of Three Nodes
Interview problems
BinaryTreeNode<int>* lcaOfTwoNodes(BinaryTreeNode<int>* root, int node1, int node2) {
    if (root == NULL) {
        return NULL;
    }

    if (root->data == node1 || root->data == node2) {
        return root;
    }

    BinaryTreeNode<int>* leftLCA = lcaOfTwoNodes(root->left, node1, node2);
    BinaryTreeNode<int>* rightLCA = lcaOfTwoNodes(root->right, node1, node2);

    if (leftLCA != NULL && rightLCA != NULL) {
        return root;
    }

    if (leftLCA != NULL) {
        return leftLCA;
    }

    return rightLCA;
}

BinaryTreeNode<int>* lcaOfThreeNodes(BinaryTreeNode<int>* root, int node1, int node2, int node3) {
    if (root == NULL) {
        return NULL;
    }

    BinaryTreeNode<int>* lca12 = lcaOfTwoNodes(root, node1, node2);
    BinaryTreeNode<int>* lca = lcaOfTwoNodes(root, lca12->data, node3);

    return lca;
}
profile
hariketsheth
Published On 09-Jul-2023
489 views
0 replies
4 upvotes
Find Unique
Interview problems

We are basically taking a variable with initial value 0 and then performing XOR Operation. When a same number is XORed, it results in 0, otherwise the number is retained as per truth table of XOR.

Since all other elements appear twice, they cancel out and at the end, only the variable appearing once retains.

 

int findUnique(int *arr, int size){
    int ans = 0;
    for ( int i = 0 ; i < size ; i++ )
        ans = ans ^ arr[i];
    return  ans;
}
profile
hariketsheth
Published On 09-Jul-2023
46 views
0 replies
2 upvotes
Kth Special Number in Range
Interview problems
#include <iostream> 
#include <string> 
using namespace std;

bool isSpecialNumber(int num) {
    string binary = bitset<32>(num).to_string();
    size_t pos = binary.find("101");
    return (pos != string::npos);
}

int kthSpecialNumber(int l, int r, int k) { 
    int count = 0; for (int num = l; num <= r; num++) { 
        if (isSpecialNumber(num)) { 
            count++; 
            if (count == k) return num;
        } 
    }
    return -1; 
}
profile
hariketsheth
Published On 09-Jul-2023
602 views
0 replies
4 upvotes