BackmediumArrays Oracle Amazon

Optimal Investment Portfolio Solution

Problem Statement

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.

Example 1
Input
[[100, 3], [50, 2], [30, 3], [20, 1]]
Output
[1]

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].

Example 2
Input
[[20, 1], [30, 3], [50, 2], [100, 3]]
Output
[2]

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].

Constraints

  • The input array will contain at least 1 and at most 20 stock-price pairs.
  • Each stock price will be a positive integer between 1 and 1000.
  • Each growth rate will be a decimal value between 0.01 and 0.1.
  • The output should be an array of at most one index corresponding to the selected stock.
  • The budget for investment can be considered unlimited for simplicity.
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free