Calculate Maximum Profit
Updated
Problem statement
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:
- The profit for each stock is calculated as the difference between its futurePrice and price (i.e.,
futurePrice[i] - price[i]). - You can buy a stock only if its price is less than or equal to the available principle.
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! 📬
Function
calculateMaxProfit(price: int[], futurePrice: int[], principle: int) → intExamples
Example 1
price = [10, 50, 30, 40, 70]futurePrice = [100, 40, 50, 30, 90]principle = 100return = 110🍓🍓
Constraints
See above 👆
More Amazon Phone Screen questions
- LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Spread Through a GridPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Consistent-Hash Packet RouterPHONE SCREEN · Seen Nov 2026
- Count Connected ComponentsPHONE SCREEN · Seen Nov 2026
- Second Largest Distinct ElementPHONE SCREEN · Seen Nov 2026
- Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent ElementsOA · PHONE SCREEN · Seen Nov 2026
- Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Choose the Front Football TeamAnduril · PHONE SCREENAnduril interview questions
- Assign CookiesExpedia · PHONE SCREEN · ONSITE INTERVIEWExpedia interview questions
- Tennis Court SchedulingAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
- Apartment Housemate PreferencesGoogle · PHONE SCREENGoogle interview questions
- IPOThe D.E. Shaw Group · PHONE SCREENThe D.E. Shaw Group interview questions
- Maximum Number of Events That Can Be AttendedByteDance · PHONE SCREENByteDance interview questions
- Minimize Range After Three ChangesDRW · PHONE SCREENDRW interview questions
- Minimum Bus Fleet Across StationsSnowflake · PHONE SCREENSnowflake interview questions
- Maximize Workday EarningsCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
- IPOTekion · PHONE SCREENTekion interview questions
Amazon interview experiences
- Amazon Experienced SDE Onsite Questions: 1 Experience
- Amazon SDE Onsite Interview Questions: 9 Experiences
- Amazon SDE II and L5 FDE Interview Questions: 4 Experiences
- Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)
- Amazon Full-Time OA Problems, Recent Reports (Part 4 of 5)
- Amazon New Grad OA Problems: Every Task We Have (Part 3 of 5)