Update appNew update is available. Click here to update.
About
heyloooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
TIET - Thapar Institute of Engineering And Technology 2024
My Stats
EXP gained
yellow-spark
53364
Level
8 (Master)
Community stats
Discussions
0
Upvotes
0
Know more
541
Total problems solved
241
Easy
249
Moderate
50
Hard
1
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:

25 days

Less

More

Achievements
7
Ronin
Topics
Bit Manipulation
Heap
Trees
+ 4 more
9
Samurai
Topics
Dynamic Programming
Strings
+ 7 more
1
Sensei
Topics
Arrays
Discussions
easy c++ code for happy String
Interview problems

 

bool check(string &str,string tocheck){

    int n=str.size();

    if(n<2){

        return false;

    }

    if(str.substr(n-2)==tocheck){

        return true;

    }else{

        return false;

    }

}

 

string happyString(int x, int y, int z)

{

    // Write your code here.

   int maxlen=x+y+z;

   string result="";

    for(int i=0;i<maxlen;i++){

 

        if((x>=y && x>=z && check(result,"aa")==false)

        ||(x>0 && (check(result,"bb") || check(result,"cc"))==true)){

            result.push_back('a');

            x--;

        }

        else if((y>=x && y>=z && check(result,"bb")==false)||(y>0 && (check(result,"aa") || check(result,"cc"))==true)){

            result.push_back('b');

            y--;

        }else if((z>=y && z>=x && check(result,"cc")==false)||(z>0 && (check(result,"bb") || check(result,"aa"))==true)){

            result.push_back('c');

            z--;

        }

    }

    return result;

}

profile
rohitknanda
Published On 08-Oct-2023
22 views
0 replies
0 upvotes
super easy c++ dp soln of longest duplicate substring
Interview problems

#include <bits/stdc++.h> 

int longestduplicateSubstring(string s)

{

    // Write your code here.

    int n=s.length();

    vector<vector<int>>dp(n+1,vector<int>(n+1,0));

    int ans=0;

    for(int i=1;i<=n;i++){

        for(int j=1;j<=n;j++){

            if(s[i-1]==s[j-1] && i!=j){

                dp[i][j]=1+dp[i-1][j-1];

            }else{

                dp[i][j]=0;

            }

            ans=max(ans,dp[i][j]);

        }

    }

    return ans;

}

profile
rohitknanda
Published On 08-Oct-2023
14 views
0 replies
0 upvotes
Making trees easy c++
Interview problems

void helper(BinaryTreeNode<int>* root,long long&oddl,long long&evenl,int level){

    if(root==NULL){

        return;

    }

    if(level%2==0){

        evenl+=root->data;

    }else{

        oddl+=root->data;

    }

    helper(root->left,oddl,evenl,level+1);

    helper(root->right,oddl,evenl,level+1);

}

 

void evenOddLevelDifference(BinaryTreeNode<int>* root){

    // Write your code here. 

    if(root==NULL){

        cout<<0<<endl;

        return ;

    }    

    long long oddl=0;

    long long evenl=0;

    helper(root,oddl,evenl,1);

    long long ans=abs(oddl-evenl);

    cout<<ans<<endl;

    

}

 

profile
rohitknanda
Published On 22-Sep-2023
41 views
0 replies
0 upvotes
Making trees easy c++
Interview problems

void helper(BinaryTreeNode<int>* root,long long&oddl,long long&evenl,int level){

    if(root==NULL){

        return;

    }

    if(level%2==0){

        evenl+=root->data;

    }else{

        oddl+=root->data;

    }

    helper(root->left,oddl,evenl,level+1);

    helper(root->right,oddl,evenl,level+1);

}

 

void evenOddLevelDifference(BinaryTreeNode<int>* root){

    // Write your code here. 

    if(root==NULL){

        cout<<0<<endl;

        return ;

    }    

    long long oddl=0;

    long long evenl=0;

    helper(root,oddl,evenl,1);

    long long ans=abs(oddl-evenl);

    cout<<ans<<endl;

    

}

 

profile
rohitknanda
Published On 22-Sep-2023
41 views
0 replies
0 upvotes
easy c++ code
Interview problems

int missingK(vector < int > arr, int n, int k) {

    // Write your code here.

    int start=0;

    int end=n-1;

    int missednum=arr[n-1]-n;

    while(start<=end){

        int mid=(start+end)/2;

        missednum=arr[mid]-(mid+1);

        if(missednum>=k){

            end=mid-1;

        }else{

            start=mid+1;

        }

 

    }

    if(end==-1){

        return k;

    }else{

        return arr[end]+k-(arr[end]-(end+1));

    }

}

 

profile
rohitknanda
Published On 12-Sep-2023
57 views
0 replies
0 upvotes
easy c++ code
Interview problems

int missingK(vector < int > arr, int n, int k) {

    // Write your code here.

    int start=0;

    int end=n-1;

    int missednum=arr[n-1]-n;

    while(start<=end){

        int mid=(start+end)/2;

        missednum=arr[mid]-(mid+1);

        if(missednum>=k){

            end=mid-1;

        }else{

            start=mid+1;

        }

 

    }

    if(end==-1){

        return k;

    }else{

        return arr[end]+k-(arr[end]-(end+1));

    }

}

 

profile
rohitknanda
Published On 12-Sep-2023
57 views
0 replies
0 upvotes
super easy c++ code
Interview problems

int smallestDivisor(vector<int>& arr, int limit)

{

    // Write your code here.

    int start=0;

    int end=*max_element(arr.begin(),arr.end());

    int ans=0;

    while(start<=end){

        int mid=(start+end)/2;

        long long sum=0;

        for(int i=0;i<arr.size();i++){

            if(arr[i]%mid==0){

                sum+=(arr[i]/mid);

            }else{

                sum+=(arr[i]/mid)+1;

            }

        }

        if(sum>limit){

            start=mid+1;

        }else{

            ans=mid;

            end=mid-1;

        }

    }

    return ans;

}

profile
rohitknanda
Published On 12-Sep-2023
20 views
0 replies
0 upvotes
super easy c++ code
Interview problems

int smallestDivisor(vector<int>& arr, int limit)

{

    // Write your code here.

    int start=0;

    int end=*max_element(arr.begin(),arr.end());

    int ans=0;

    while(start<=end){

        int mid=(start+end)/2;

        long long sum=0;

        for(int i=0;i<arr.size();i++){

            if(arr[i]%mid==0){

                sum+=(arr[i]/mid);

            }else{

                sum+=(arr[i]/mid)+1;

            }

        }

        if(sum>limit){

            start=mid+1;

        }else{

            ans=mid;

            end=mid-1;

        }

    }

    return ans;

}

profile
rohitknanda
Published On 12-Sep-2023
20 views
0 replies
0 upvotes