Question: find _ mode ( arr: DynamicArray ) - > tuple [ DynamicArray , int ] : Write a standalone function outside of the DynamicArray class

find_mode(arr: DynamicArray)-> tuple[DynamicArray, int]:
Write a standalone function outside of the DynamicArray class that receives a dynamic array
already in sorted order, either non-descending or non-ascending. The function will return a
tuple containing (in this order) a dynamic array comprising the mode (most-occurring)
value/s of the array, and an integer that represents the highest frequency (how many times
they appear).
If there is more than one value that has the highest frequency, all values at that frequency
should be included in the array being returned in the order in which they appear in the input
array. If there is only one mode, only that value should be included.
You may assume that the input array will contain one or more homogeneous
elements(either all numbers, or strings, or custom objects, but never a mix of these). You
do not need to write checks for these conditions.
For full credit, the function must be implemented with O(N) complexity with no additional
data structures (beyond the array you return) being created. (Note: You can
replace the return array as needed)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!