Question: Data : -3, 4, 5, -2, -1, 2, 6, -4 The first k elements is read to an array and sorted (in decreasing order). Each
Data : -3, 4, 5, -2, -1, 2, 6, -4
The first k elements is read to an array and sorted (in decreasing order). Each remaining element is read one by one. As a new element arrives, it is ignored if it is smaller than the kth element in the array. Otherwise, it is placed in its correct spot in the array, bumping one element out of the array. When the algorithm ends, the element in the 4th position is returned as the answer
c++
k I believe is 0 or is from the created array
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
