I am doing past interviews and a question states the following: students are asked to stand in non-decreasing order. Find out the number of students not standing in the right place.
Seems quite simple, yet the expected output is totally different, a few example outputs:
[5,1,1,3,4,1] -> 3
[4,1,2,3,4] -> 0
[4,4,3,2,1] -> 4
What am I not seeing right?
This question is poorly worded, and all of these answers are going to be opinion based.. That said, my only thought to make this work in any reasonable way is if the first number indicated the size of the array.
[5,1,1,3,4,1] -> 3
5 students in order [1,1,3,4,1]
unsorted [1,1,3,4,1]
sorted [1,1,1,3,4]
non-matching [ x,x,x]
-> 3
Same for the others
4 students in order [1,2,3,4]
unsorted [1,2,3,4]
sorted [1,2,3,4]
non-matching [ ]
-> 0
4 students in order [4,3,2,1]
unsorted [4,3,2,1]
sorted [1,2,3,4]
non-matching [x,x,x,x]
-> 4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With