Bucket Counts
DatadogEasy
You are given a sorted list of non-negative integers data that you want to summarize as a histogram with num_buckets buckets, each bucket_width wide.
Part 1: Count values per bucket
Bucket i covers the values from i * bucket_width up to (i + 1) * bucket_width - 1, except for the last bucket, which takes every value that is at least (num_buckets - 1) * bucket_width.
Return a list of length num_buckets where entry i is how many values of data fall in bucket i.
- Example 1
- data
[0,1,2,3,4,5,6,7,8,20]- num_buckets
4- bucket_width
5- Output
[5,4,0,1]
Why: Bucket 0 covers 0 to 4 and holds five values, bucket 1 covers 5 to 9 and holds four, bucket 2 covers 10 to 14 and is empty, and the last bucket takes
20and anything larger.
Constraints
0 <= len(data) <= 10^50 <= data[i] <= 10^9datais sorted in non-decreasing order1 <= bucket_width <= 10^91 <= num_buckets <= 1000
Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.