Below question I got as part in Microsoft Codility Interview, which is the first round here now.
Please do share the interview questions you got & please suggest their answers so that others can get the help.
Write a function:
class Solution { public int solution(int[] A); }
that, given an array A of N integers, returns the smallest positive integer (greater than 0) that does not occur in A.
For example, given A = [1, 3, 6, 4, 1, 2], the function should return 5.
Given A = [1, 2, 3], the function should return 4.
Given A = [−1, −3], the function should return 1.
Write an efficient algorithm for the following assumptions:
This demo question had 30 mins limit but it took me 90 minutes to make this task pass for both correctness & performance, so surely I am not the kind of efficient coders such companies hire.
Below is the code which worked 100% for both correctness & performance -
Please do share the interview questions you got & please suggest their answers so that others can get the help.
Write a function:
class Solution { public int solution(int[] A); }
that, given an array A of N integers, returns the smallest positive integer (greater than 0) that does not occur in A.
For example, given A = [1, 3, 6, 4, 1, 2], the function should return 5.
Given A = [1, 2, 3], the function should return 4.
Given A = [−1, −3], the function should return 1.
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..100,000];
- each element of array A is an integer within the range [−1,000,000..1,000,000].
This demo question had 30 mins limit but it took me 90 minutes to make this task pass for both correctness & performance, so surely I am not the kind of efficient coders such companies hire.
Below is the code which worked 100% for both correctness & performance -
MSDemo
Actual Codility Test questions you may not be getting that difficult questions & depending on the difficult of the questions, you can expect the number of questions with time 30 min - 120 mins to solve those questions.
I got 2 questions to solve in 90 mins, one was on numbers & second was I think to look how you design your class & methods to solve the problem.
Question 1 was checking correctness & performance & my solution got 40% only for the performance &
Question 2 was analyzed for the correctness by the system. May be some person from MS would have checked the design also.
My suggestion while solving such questions -
First target to solve those all questions without worrying about the performance, just try to make sure that your solutions give correct results.
If have time then can work on performance improvements as right performance is not achieved with a clock on your head.
Can check various problems about numbers patterns like Pronic numbers.
Plus in case of processing text on codility where new line comes then try to use "\\\\n"
"\n" or "\\n" didn't work for me on codility.
Rest I had a good 2 rounds of discussions where
1 round was to code for one problem which was like to find how many buildings you can cross by using the given resources like Ladders & Bricks. I was not able to code for that.
& second round was about designing the system like DropBox, like give the classes structure.
Suggestion: During these in-person interviews don't say any extra word & try to bring the interviewer to the interview questions, as these people have limited time about 1 hour & then you will be getting less time to work on the given problem.
So Go Ahead & try...ALL THE BEST
I got 2 questions to solve in 90 mins, one was on numbers & second was I think to look how you design your class & methods to solve the problem.
Question 1 was checking correctness & performance & my solution got 40% only for the performance &
Question 2 was analyzed for the correctness by the system. May be some person from MS would have checked the design also.
My suggestion while solving such questions -
First target to solve those all questions without worrying about the performance, just try to make sure that your solutions give correct results.
If have time then can work on performance improvements as right performance is not achieved with a clock on your head.
Can check various problems about numbers patterns like Pronic numbers.
Plus in case of processing text on codility where new line comes then try to use "\\\\n"
"\n" or "\\n" didn't work for me on codility.
Rest I had a good 2 rounds of discussions where
1 round was to code for one problem which was like to find how many buildings you can cross by using the given resources like Ladders & Bricks. I was not able to code for that.
& second round was about designing the system like DropBox, like give the classes structure.
Suggestion: During these in-person interviews don't say any extra word & try to bring the interviewer to the interview questions, as these people have limited time about 1 hour & then you will be getting less time to work on the given problem.
So Go Ahead & try...ALL THE BEST