Hello there, budding programmer! I hope you're ready because today, we're going to dive deep into high-level data manipulation and increase our understanding of heaps. Heaps are fundamental data structures commonly used in algorithms. We're going to leverage their potential today in an interesting algorithmic problem. Are you ready for the challenge? Let's get started!
We have a task at hand related to array manipulation and the use of heaps. The task is as follows: Given a vector of unique integers with elements ranging from to and length between to , we need to create a C++ function prefixMedian(). This function will take the vector as input and return a corresponding vector, which consists of the medians of all the prefixes of the input vector.
Remember that a prefix of a vector is a contiguous subsequence that starts from the first element. The median of a sequence of numbers is the middle number when the sequence is sorted. If the length of the sequence is even, the median is the element in the position length / 2 - 1.
For example, consider an input vector {1, 9, 2, 8, 3}. The output of your function should be {1, 1, 2, 2, 3}.
