Given an array of stock prices and their respective growth rates, determine the optimal investment portfolio by selecting at most one stock that will yield the highest returns, assuming the goal is to maximize returns without considering the budget or other constraints.
Explanation: Step-by-step: with input [[100, 3], [50, 2], [30, 3], [20, 1]], we first sort the array based on the growth rate in descending order. Then we select the first element which has the highest growth rate, giving output [1].
Explanation: Step-by-step: with input [[20, 1], [30, 3], [50, 2], [100, 3]], we first sort the array based on the growth rate in descending order. Then we select the first element which has the highest growth rate, giving output [2].
Arrays
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak