Count Points in Each Boundary Interval
Updated
Problem statement
You are given a list of points on a number line, in any order, and a strictly increasing list of boundaries with m values.
Each pair of neighboring boundaries makes an interval, so there are m - 1 intervals. Interval j holds every value x with boundaries[j] <= x < boundaries[j + 1]: it includes its left end but not its right end. So a point that sits exactly on a boundary between two intervals belongs to the interval on its right.
Return an array counts of length m - 1, where counts[j] is the number of points inside interval j. Points below the first boundary, or at or above the last boundary, are not counted. Equal points are counted separately.
Function
countPointsPerInterval(points: double[], boundaries: double[]) → int[]Examples
Example 1
points = [2.3,4.5,7.8]boundaries = [0,5,10]return = [2,1]The boundaries make two intervals: from 0 up to 5, and from 5 up to 10.
Points 2.3 and 4.5 are in the first interval and 7.8 is in the second, so the answer is [2, 1].
Example 2
points = [5,0,10,-1,9.99]boundaries = [0,5,10]return = [1,2]Point 0 sits on the left end of the first interval, so it counts there. Point 5 sits on the boundary between the intervals, so it counts in the second one, which starts at 5.
Point 9.99 is also in the second interval. Point 10 is the right end of the last interval and point -1 is below the first boundary, so neither counts. The answer is [1, 2].
Example 3
points = [7.5,1.25,3,3,12.5,6]boundaries = [1,2.5,6,8,12]return = [1,2,2,0]The points come in any order. Point 1.25 is in the interval from 1 to 2.5. Both copies of 3 are in the interval from 2.5 to 6. Points 6 and 7.5 are in the interval from 6 to 8.
No point is between 8 and 12, and 12.5 is past the last boundary. The answer is [1, 2, 2, 0].
Example 4
points = [-3.5,-0.5,0.5]boundaries = [-2,0]return = [1]There is one interval, from -2 up to 0. Only -0.5 is inside it: -3.5 is below -2, and 0.5 is past 0. The answer is [1].
Constraints
1 <= points.length <= 10^42 <= boundaries.length <= 10^4-10^6 <= points[i], boundaries[j] <= 10^6boundariesis strictly increasing.
More Bloomberg LP Onsite Interview questions
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent WordsONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Decode StringPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Minimum Replacements to Make Two Strings AnagramsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Currency Conversion RatePHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Find Unmet Users With Shared InterestsPalantir · ONSITE INTERVIEWPalantir interview questions
- 3Sum SmallerSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Russian Doll EnvelopesGoogle · ONSITE INTERVIEWGoogle interview questions
- Minimum Operations to Make an Array ContinuousAmazon · ONSITE INTERVIEW
- Russian Doll EnvelopesInMobi · ONSITE INTERVIEWInMobi interview questions
- Room Occupancy at Query TimesWhatNot · ONSITE INTERVIEWWhatNot interview questions
- Count Later Lower ReadingsRippling · ONSITE INTERVIEWRippling interview questions
- HTTP Log QueriesDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
- Smallest Common Integer in Sorted ListsMotive · ONSITE INTERVIEWMotive interview questions
- Sliding Window MedianAuxoAI · OA
Bloomberg LP interview experiences
- Bloomberg SWE Phone Screen and Onsite: 1 Experience
- Bloomberg SWE Phone Screens with Two Teams: 1 Experience
- Bloomberg AI Interview, Hiring Level Not Reported: 2 Experiences
- Bloomberg Experienced SWE AI Coding Interviews: 2 Experiences
- Bloomberg New Grad AI-Assisted Coding Rounds: 3 Experiences
- Bloomberg New Grad SWE AI-Assisted Coding Rounds: 1 Experience