FastPrepWarehouse Robots with Threshold
Problems/Warehouse Robots with Threshold

Warehouse Robots with Threshold

Amazon logoAmazon● MediumINTERNOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

You are given an integer array arr of size n, where arr[i] represents the threshold of the i-th robot. Each robot can be assigned one of two states: Running or Waiting.

A configuration is valid if all robots satisfy the following conditions:

  • If a robot is Running, then the total number of running robots must be ≥ arr[i].
  • If a robot is Waiting, then the total number of waiting robots must be < arr[i].

Each robot must be assigned exactly one state. A configuration is valid only if no robot violates its condition.

Return the total number of valid configurations.

Function

countValidConfigurations(arr: int[]) → int

Examples

Example 1

arr = [1,2]return = 2

n=2. Config 1: robot-0 Running, robot-1 Waiting. Running count=1 >= arr[0]=1 ✓. Waiting count=1 < arr[1]=2 ✓. Valid. Config 2: both Running. Running count=2 >= arr[0]=1 ✓, 2 >= arr[1]=2 ✓. No waiting robots to check. Valid. Config "both Waiting": waiting count=2, robot-0 needs 2 < arr[0]=1 ✗. Invalid. Config "robot-1 Running only": running count=1 >= arr[1]=2? 1 >= 2 ✗. Invalid. Total = 2.

Example 2

arr = [2,2]return = 1

n=2. Both Running: running count=2 >= arr[0]=2 ✓, 2 >= arr[1]=2 ✓. Valid. All other configs fail: running count 0 or 1 cannot satisfy arr[i]=2 for a Running robot, and waiting count 1 or 2 cannot satisfy < arr[i]=2 for a Waiting robot (1 < 2 ✓ but a single Running robot fails its own condition). Total = 1.

Constraints

  • 1 <= n <= 10^5
  • 1 <= arr[i] <= n

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

  • Maximum Easy Tasks After RearrangingIBM · OAIBM interview questions
  • Minimum Cost K-Capable ModelsMicrosoft · OAMicrosoft interview questions
  • Maximum Distinct Values After Unit AdjustmentsBirla Pivot · OA
  • Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
  • Minimum Distinct Prefix CostGoldman Sachs · OAGoldman Sachs interview questions
  • Maximize Minimum Deployment DifficultyJP Morgan Chase · OAJP Morgan Chase interview questions
  • Latest Arrival to Catch a BusAutodesk · OAAutodesk interview questions
  • EV Charging Cost OptimizationTata Consultancy Services · OATata Consultancy Services interview questions
  • Maximize Workday EarningsCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
  • Minimum Removals to Balance ArraySalesforce · OASalesforce interview questions

Interview reports that mention this question

  • Amazon Intern OA Problems: Every Task We Have (Part 2 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, Earlier Reports (Part 5 of 5)
  • Amazon Full-Time OA Problems, Recent Reports (Part 4 of 5)
See Amazon hiring insights
Saved
class Solution {
    public int countValidConfigurations(int[] arr) {
      // write your code here
    }

}
Checking account…