Sherlock and numbers - HackerEarth Problem Solution :
Watson gives to sherlock a bag of numbers [1,2,3,....N] and he removes k numbers A1, A2,....,Ak from the bag. He now asks sherlock to find the pth smallest number in the bag.
Input:
2
4 1 2
1
5 2 4
1 3
Output:
3
-1
Test case 1:
Remaining Numbers are [2,3,4]. 3 is the 2nd smallest remaining numbers
Remaining Numbers are [2,4,5]. 4th smallest number doesn't exist.
PHP Implementation:
Watson gives to sherlock a bag of numbers [1,2,3,....N] and he removes k numbers A1, A2,....,Ak from the bag. He now asks sherlock to find the pth smallest number in the bag.
Input:
2
4 1 2
1
5 2 4
1 3
Output:
3
-1
Test case 1:
Remaining Numbers are [2,3,4]. 3 is the 2nd smallest remaining numbers
Remaining Numbers are [2,4,5]. 4th smallest number doesn't exist.
PHP Implementation: