You are given two lists:
price[]: A list of integers representing the prices of different stocks.futurePrice[]: A list of integers representing the future prices of those stocks.principle: An integer representing the amount of money you have available to invest.You can buy as many stocks as you want, but the total cost of the stocks you buy must not exceed your principle.
Task:
Write a function that calculates the maximum profit you can make by buying stocks, where:
futurePrice[i] - price[i]).Constraints:)
You can buy any number of stocks, as long as the total price of the selected stocks is less than or equal to principle. If you can't buy any stock (because all stock prices exceed the principle), the maximum profit is 0.
🚗 The 1010th thank you is being carried by USPS to spike! 📬
Examples
01 · Example 1
price = [10, 50, 30, 40, 70] futurePrice = [100, 40, 50, 30, 90] principle = 100 return = 110
🍓🍓
Constraints
See above 👆More Amazon problems
- Count Promotional PeriodsOA · Seen Jun 2026
- Find Maximum Total Amount (SDE I, Fungible :)Seen Jun 2026
- Get Minimum AmountOA · Seen Jun 2026
- Find Minimum CostOA · Seen Jun 2026
- Get Smallest Base SegmentOA · Seen Jun 2026
- Select Least Resource TasksOA · Seen Jun 2026
- Product Category Group SizesPHONE SCREEN · Seen May 2026
- Count Connected ComponentsPHONE SCREEN · Seen May 2026
public int calculateMaxProfit(int[] price, int[] futurePrice, int principle) {
// write your code here
}
price[10, 50, 30, 40, 70]
futurePrice[100, 40, 50, 30, 90]
principle100
expected110
sign in to submit