Applied through LinkedIn got a call from recruiter within a week and scheduled the interview rounds.
Experience:
Round - 1
Interview taken by a senior engineer.
1203. Sort Items by Groups Respecting Dependencies
: Similar to this problem but it was twisted with some other criteria. => Discussed the approach and code it but all the cases weren't passed
19. Remove Nth Node From End of List : Here also not only the removeNthFromEnd function but you have to write the whole code from scratch like main function and construct a LinkedList then add a method to the given problem. => Wrote everything from scratch. Interviewer was satisfied.
503. Next Greater Element II : For this problem also interviewer changed a bit,
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 -1Solution:
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...