FastPrepMaximum Number of Products You Can Pick
Problems/Maximum Number of Products You Can Pick

Maximum Number of Products You Can Pick

Amazon logoAmazon● HardOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

You are given an array products. The value products[i] is how many items of product i are in stock.

Choose a subarray of products. A subarray is a stretch of products that sit next to each other. Go through it from left to right and pick some items from every product in it.

  • From each product, pick at least 1 item and at most its stock.
  • The number you pick from a product must be bigger than the number you picked from the product before it.

Return the largest total number of items you can pick.

For example, take products = [7, 5, 3]. If you use the whole array, you must pick 1, 2 and 3 items, which gives 6. If you use only [7, 5], you can pick 4 and 5 items, which gives 9. So the answer for this array is 9.

Another example is products = [2, 9, 4, 7, 5, 3]. Use the subarray [2, 9, 4, 7] and pick 2, 3, 4 and 7 items. The total is 16, and no other choice gives more.

Function

maximumProductsPicked(products: int[]) → long

Complete the function maximumProductsPicked in the editor.

maximumProductsPicked has the following parameter:

  • int[] products: the stock of each product

Returns long: the largest total number of items you can pick

Examples

Example 1

products = [2, 9, 4, 7, 5, 3]return = 16

Use the subarray [2, 9, 4, 7]. Pick 2 items from the first product, 3 from the second, 4 from the third and 7 from the fourth. Each number is bigger than the one before, and none is above its stock. The total is 2 + 3 + 4 + 7 = 16. No other subarray gives more, so the answer is 16.

Constraints

  • 1 <= n <= 5000, where n is the length of products
  • 1 <= products[i] <= 10^9

More Amazon interview questions

  • LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Maximal SquareONSITE INTERVIEW · Seen Nov 2026
  • Serialize and Deserialize a Binary TreeONSITE INTERVIEW · Seen Nov 2026
  • Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Diagonal Traversal of a Binary TreeONSITE 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
  • Maximize K-Element AND with an Increment BudgetOA · Seen Nov 2026

Similar questions at other companies

  • Split Array to Minimize the Largest SumInfosys · OAInfosys interview questions
  • Largest Consistent Visiting GroupAuxoAI · OA
  • Delete K Subsets for Maximum ScoreRubrik · OARubrik interview questions
  • Optimize Discount Selection Under a Point BudgetPalantir · OAPalantir interview questions
  • Maximum Index-Weighted Sum with Disjoint SwapsVisa · OAVisa interview questions
  • Maximum Sum of HeightsVirtu Financial · OAVirtu Financial interview questions
  • Pressure-Isolation Shutdown OrderIntuit · OAIntuit interview questions
  • Get Minimum IncrementIBM · OAIBM interview questions
  • Jump Game with Prime-3 StepsUber · OAUber interview questions
  • Maximum Payout with Context SwitchesPhonePe · OAPhonePe interview questions

Interview reports that mention this question

  • Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)

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, Recent Reports (Part 4 of 5)
  • Amazon New Grad OA Problems: Every Task We Have (Part 3 of 5)
See Amazon hiring insights
Saved
class Solution {
    public long maximumProductsPicked(int[] products) {
        // write your code here
    }

}
Checking account…