Update appNew update is available. Click here to update.
About
Madan Mohan Malaviya University Of Technology 2024
C++ - Default language
My Stats
EXP gained
yellow-spark
10707
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 %
343
Total problems solved
304
Easy
38
Moderate
1
Hard
0
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:

22 days

Less

More

Achievements
4
Ronin
Topics
Arrays
Stacks & Queues
+ 2 more
Discussions
All three possible solution
Interview problems

#include <bits/stdc++.h>

string read(int n, vector<int> book, int target)

{

    //brute force approach  T.C-->O(N)  S.C-->O(1)

 

    // for(int i=0;i<book.size();i++)

    // {

    //     for(int j=1;j<book.size();j++)

    //     {

    //         if(book[i]+book[j] == target) return "YES";

    //     }

    // }

    // return "NO";

 

    // first approach   T.C-->O(N)  S.C-->O(1)

 

    // sort(book.begin(),book.end());//O(nlogn)

    // int i=0,j=book.size()-1;

    // while(i<=j)//O(N)

    // {

    //     if(book[i]+book[j] == target)

    //         return "YES";

    //     else if(book[i]+book[j]<target)

    //     {

    //         i++;

    //     }

    //     else

    //     {

    //         j--;

    //     }

    // }

    // return "NO";

 

    //second approach  T.C-->O(N)  S.C-->O(N)

    //can use map too but why bother to use and make key pair if asked to find the target only

    unordered_set<int> s;

    int val;

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

    {

        val=target-book[i];

        if(s.find(val)!= s.end())

        {

            return "YES";

        }

        else

        {

            s.insert(book[i]);

        }

    }

    return "NO";

}

 

profile
Uchiha_Obito
Published On 09-Jul-2023
99 views
0 replies
0 upvotes
Sliding window Technique
Interview problems

#include <bits/stdc++.h> 

int minSubarraySum(int arr[], int n, int k) 

{

    // Write your code here 

    int i=0,j=0,sum=0,ans=INT_MAX;

    while(j<=n-1)

    {

        sum+=arr[j];

        if((j-i+1)<k)

        {

            j++;

        }

        else

        {

            ans=min(ans,sum);

            // cout<<ans<<endl;

            sum-=arr[i];

            i++;

            j++;

        }

    }

    return ans;

}

profile
Uchiha_Obito
Published On 30-Apr-2023
246 views
0 replies
3 upvotes
100% percent better perform|| Optimal code
Interview problems

int search(vector<int>& nums, int target) {

    // Write Your Code Here

    int i=0,j=nums.size()-1;

    while(i<=j)

    {

        int mid=i+(j-i)/2;

        if(nums[mid]==target)

            return mid;

        else if(nums[mid]>target)

        {

            j=mid-1;

        }

        else

        {

            i=mid+1;

        }

    }

    return -1;

}

profile
Uchiha_Obito
Published On 29-Apr-2023
149 views
0 replies
1 upvotes