In this challenge, we practice calculating quartiles. Check out the Tutorial tab for learning materials and an instructional video!
Given an array, , of integers, calculate the respective first quartile (), second quartile (), and third quartile (). It is guaranteed that , , and are integers.
The sorted array is which has an odd number of elements. The lower half consists of , and its median is . The middle element is and represents the second quartile. The upper half is and its median is . Return .
The array is already sorted. The lower half is with a median = . The median of the entire array is , and of the upper half is . Return .
Complete the quartiles function in the editor below.
quartiles has the following parameters:
int arr[n]: the values to segregate
int: the medians of the left half of , in total, and the right half of .
The first line contains an integer, , the number of elements in .
The second line contains space-separated integers, each an .