Sorted subsequence of size 3

PHOTO EMBED

Tue Oct 18 2022 17:23:48 GMT+0000 (Coordinated Universal Time)

Saved by @Ranjan_kumar #c++

class Solution{
  public:
    vector<int> find3Numbers(vector<int> arr, int N) {
        // Your code here
        vector<int>v;
        int left=INT_MAX;
        int mn=left;
        int mid=INT_MAX;
        if(N<3) 
        {
            return {};
        }
        for(int i=0;i<N;i++)
        {
            if(arr[i]<left) 
            {
                left=arr[i];
            }
            else if(arr[i]>left&&arr[i]<mid)
            {
                mid=arr[i];
                mn=left;
            }
            else if(arr[i]>mid) 
            {
                v.push_back(mn);
                v.push_back(mid);
                v.push_back(arr[i]);
                return v;
            }
        }
        return {};
    
    }
};
content_copyCOPY

https://practice.geeksforgeeks.org/problems/sorted-subsequence-of-size-3/1?utm_source=gfg&utm_medium=article&utm_campaign=bottom_sticky_on_article