Get best answers to any doubt/query/question related to programming , jobs, gate, internships and tech-companies. Feel free to ask a question and you will receive the best advice/suggestion related to anything you ask about software-engineering , development and programming problems .

0 like 0 dislike
1,172 views
in Online Assessments by Expert (44,360 points)

2 Answers

0 like 0 dislike
 
Best answer

 

 

Microsoft OA | SDE 2 | April 2022

 

2 Questions on Codility -

 

by Expert (44,360 points)
0 like 0 dislike

JavaScript Solution

 

const kLargest = (a) => {
  a.sort((a,b) => a-b);
  let left = 0, right = a.length;
  while(left<right){
    if(-a[left] === a[right]){
      return a[right];
    }
    if(Math.abs(a[left]) > a[right]){
      left++;
    }
    else{
      right--;
    }
  }
  return -1;
};
by Expert (44,360 points)
...