Company: Snowflake
Difficulty: medium
Selecting Stocks Problem Description An investor with limited funds wants to invest in the stock market. They can buy at most one share of each company and cannot exceed their available funds. The future values of the stocks after one year have been predicted. Your task is to determine the maximum profit the investor can earn by selecting the optimal combination of stocks to buy. Complete the function selectStock in the editor with the following parameter(s): int saving : amount available for investment int currentValue[n] : the current stock values int futureValue[n] : the values of the stocks after one year Returns: int : the maximum profit after one year Examples Example 1: Input: saving = 250 currentValue = [175, 133, 109, 210, 97] futureValue = [200, 126, 128, 228, 133] Output: 55 Explanation: Optimal investment strategy is to buy stocks at indices 2 and 4, with current values 109 and 97. Total investment: 109 + 97 = 206. Future value of these stocks: 128 + 133 = 261. Profit: 261