Exercises
The following exercises provide you with the opportunity to practice with fast sorting. The solutions to these exercises are found in the section Chapter 13.
-
Given an array of positive numbers, write a function that returns the greatest product of any three numbers. The approach of using three nested loops would clock in at O(N3), which is very slow. Use sorting to implement the function in a way that it computes at O(N log N) speed. (Some other implementations are even faster, but we’re focusing on using sorting as a technique to make code faster.)
-
The following function finds the missing number from an array of integers; that is, the array is expected to have all integers from 0 up to the array’s length, but one is missing. As ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access