How would you solve the following problems? Can you think of an O(n^2), O(n log n), and O(n) solution to each problem? If you have time, code one of the functions you thought of to solve the problem.
Examples:
[1,4,5,4,2,2,4]returns4
Write a function that takes an array of numbers and returns the greatest difference you can get by subtracting any two of those numbers.
Examples:
[1, 5, 3, 1, 15]returns14
Examples:
[3,5,3,4,6,6,4]returns5
Examples:
([1,3,2,5], [3,9,8,1])returns[1, 3]
Examples:
("cat", "act")returnstrue("at", "tat")returnsfalse("cat", "dog")returnsfalse
Examples:
"banana"returnsfalse"bacon"returnstrue
Sources: