Given an array of integers, delete the max and min numbers (both could appear more than once) in place. Do it in O(n) without shifting.
Respuestas de entrevistas
Anónimo
10 feb 2016
You could do in one loop, with two cursors :)
1
Anónimo
15 ene 2016
Go through the array twice. In the first run save the min and max, in the second run remove them.
Both steps are O(N), so the entire algo is also O(N), it does not matter that the array is walked twice.
1
Anónimo
10 feb 2016
1. find max and min in first loop
2. In second loop following if element is min/max = simply increment a counter else a[i-counter] = a[i].
2
Anónimo
10 feb 2016
1. find max and min in first loop.
2. In second loop if a[i] is min/max then simply increment a counter else a[i-counter] = a[i].