Problem

Count Unstable Processes

Learn this problem
IBM logoIBMINTERNOA
See IBM hiring insights

Problem statement

You are given three arrays of equal length: process, timestamp, and limit. Entry i records that process process[i] had limit limit[i] at time timestamp[i].

For each process, order its records by increasing timestamp. A process is unstable if its ordered limit sequence has at least one increase and at least one decrease between consecutive records.

Return the number of unstable processes.

Function

countUnstableProcesses(process: String[], timestamp: int[], limit: int[]) → int

Examples

Example 1

process = ["A", "B", "A", "C", "D", "A"]timestamp = [10, 25, 30, 35, 15, 20]limit = [20, 18, 10, 8, 30, 27]return = 1

Process A has records ordered by time 20 -> 27 -> 10, which includes both an increase and a decrease. The other processes are not unstable.

Example 2

process = ["A", "A", "B", "B", "B"]timestamp = [1, 2, 1, 2, 3]limit = [5, 7, 3, 2, 1]return = 0

Process A only increases, and process B only decreases, so neither is unstable.

Constraints

  • 1 <= process.length == timestamp.length == limit.length <= 2 * 10^5
  • process[i] is a non-empty string.
  • 0 <= timestamp[i] <= 10^9
  • -10^9 <= limit[i] <= 10^9
  • No process has two records with the same timestamp.

More IBM problems

drafts saved locally
public int countUnstableProcesses(String[] process, int[] timestamp, int[] limit) {
  // write your code here
}
process["A", "B", "A", "C", "D", "A"]
timestamp[10, 25, 30, 35, 15, 20]
limit[20, 18, 10, 8, 30, 27]
expected1
checking account