Question: Write a function that receives a StaticArray that is sorted in order, either non-descending or non-ascending. The function will return (in this order) the mode

 Write a function that receives a StaticArray that is sorted in

Write a function that receives a StaticArray that is sorted in order, either non-descending or non-ascending. The function will return (in this order) the mode (most-occurring value) of the array, and its frequency (how many times it appears). If there is more than one value that has the highest frequency, select the one that occurs first in the array. You may assume that the input array will contain at least one element and that values stored in the array are all of the same type (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 being created. Example 1: test cases =( [1, 20, 30, 40, 500, 500, 500), [2, 2, 2, 2, 1, 1, 1, 1), ["zebra", "sloth", "otter", "otter", "moose", "koala"], ["Albania", "Belgium", "Chile", "Denmark", "Egypt", "Fiji" for case in test_cases

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!