Problem · Array

Stable Robot Configurations

Learn this problem
MediumAmazonINTERNNEW GRADOA
See Amazon hiring insights

Problem statement

In Amazon's warehouse robotics system, multiple robots operate simultaneously to transport packages efficiently. Each robot can be in one of two states: Standby or Operating.

For smooth coordination, each robot i has a predefined coordination threshold, coordinationThreshold[i]. This threshold determines the conditions under which a robot malfunctions:

  • A robot i malfunctions if it is in the Operating state but the total number of other robots in the Operating state is less than coordinationThreshold[i].
  • A robot i malfunctions if it is in the Standby state but the total number of robots in the Operating state is greater than or equal to coordinationThreshold[i].

If any robot malfunctions, the system is considered unstable. Return the total number of distinct valid configurations where no robot malfunctions.

A configuration is an assignment of each of the n robots to either Operating or Standby. A configuration is considered valid if no robot malfunctions under that arrangement. Two configurations are distinct if at least one robot is in a different state.

Function

countStableConfigurations(coordinationThreshold: int[]) → int

Examples

Example 1

coordinationThreshold = [6, 0, 3, 3, 6, 7, 2, 7]return = 3

There are three valid ways to select robots to be in the Operating state. The source explanation shows these two:

  1. Only the robot at index 1 is Operating. Its threshold is 0, so it has at least 0 other operating robots. All other robots remain in Standby, and their thresholds exceed the one operating robot.
  2. Robots at indices 1, 2, 3, and 6 are Operating, with threshold values 0, 3, 3, and 2. Each operating robot has at least its threshold number of other operating robots, and every standby robot has fewer operating robots than its threshold.

So the total number of valid configurations is 3.

More Amazon problems

drafts saved locally
public int countStableConfigurations(int[] coordinationThreshold) {
  // write your code here
}
coordinationThreshold[6, 0, 3, 3, 6, 7, 2, 7]
expected3
checking account