Bucketize

MediumData EngineeringArrayMathSortingGraph

Description

Given an array of values and an array of sorted ascending bin edges, return the bin index for each value: the number of edges that the value meets or exceeds. A value below the first edge falls in bin 0.

Examples

Input:[5,15,25,10], [10,20]
Output:[0,1,2,1]
Explanation:

Each value is placed by counting how many of the ascending edges it reaches, so larger values land in higher bins.

Input:[1,2,3], [5]
Output:[0,0,0]
Explanation:

Each value is placed by counting how many of the ascending edges it reaches, so larger values land in higher bins.

Input:[5,10,15], [10]
Output:[0,1,1]
Explanation:

Each value is placed by counting how many of the ascending edges it reaches, so larger values land in higher bins.

Constraints

  • 1 ≤ values ≤ 10⁴
  • edges sorted ascending

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.