CoinSwitch Kuber | SDE - II | Bangalore | May 2022
Anonymous User
470

Applied through LinkedIn got a call from recruiter within a week and scheduled the interview rounds.

Experience:

  • 2.9 YoE product based startup

Round - 1
Interview taken by a senior engineer.

In the linked problem test cases are:
Input: nums = [1,2,3,4,3]
Output: [2,3,4,-1,4]

But interviewer expected:
Input: nums = [1,2,3,4,3]
Output: [2,3,4,-1,-1]
Explanation: Last element 3, there's not grater to its next(right) so it'll show -1

Solution:

vector<int> nextGraterEle(vector<int> &vec){
    int size = vec.size();
    vector<int> res(size, -1);

    stack<int>s;

    for(int i=size-1; i>=0; i--){
        while(!s.empty()){
            if(s.top() <= vec[i])
                s.pop();
            else{
                res[i] = s.top();
                brak;
            }
        }
        s.push(vec[i]);
    }
    return res;
}

If you want to know about anything else related to this interview left a comment I'll reply back. Wants to connect then leave your LinkedIn profile link in the comment section, will send an invitation request. Please upvote if it helps!

Happy coding...

Comments (3)