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.
Antworten zu Vorstellungsgespräch
Anonym
10. Feb. 2016
You could do in one loop, with two cursors :)
1
Anonym
15. Jan. 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
Anonym
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
Anonym
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].