Problem

Count Picked Items Less Than Queries

Learn this problem
AmazonFULLTIMEOA
See Amazon hiring insights

Problem statement

A warehouse has items represented by an array items, where items[i] is the value of the i-th item.

There are several orders. The i-th order picks every item in the inclusive index range startIndex[i] through endIndex[i]. Across all orders, this creates one combined multiset of picked item values.

For each value query[i], return how many picked items have value strictly less than query[i].

Function

countPickedItemsLessThan(items: int[], startIndex: int[], endIndex: int[], query: int[]) → int[]

Examples

Example 1

items = [1,2,5,4,5]startIndex = [0,0,1]endIndex = [1,2,2]query = [2,4]return = [2,5]

The orders pick values [1,2], [1,2,5], and [2,5]. Two picked values are less than 2, and five are less than 4.

Constraints

  • 1 <= items.length
  • startIndex.length == endIndex.length
  • 0 <= startIndex[i] <= endIndex[i] < items.length

More Amazon problems

drafts saved locally
public int[] countPickedItemsLessThan(int[] items, int[] startIndex, int[] endIndex, int[] query) {
  // write your code here
}
items[1,2,5,4,5]
startIndex[0,0,1]
endIndex[1,2,2]
query[2,4]
expected[2,5]
checking account