A histogram is the quickest summary of an image's tone: count how many pixels fall into each brightness band and you can see at a glance whether a photo is underexposed, blown out, or sitting comfortably in the middle.
Task: write histogram(pixels, bins) returning a list of bins counts.
pixels is a 2D grid of integers from 0 to 255.0–255 into bins equal-width bands and count how many pixels land in each.In Python that's p * bins // 256 — integer division, no floats needed.
bins entries, including zeros for empty bands, and they sum to the total pixel count.The 256 matters. There are 256 possible values (0 through 255), so dividing by 256 — rather than 255 — puts the largest possible pixel in the last band and nothing beyond it. Divide by 255 instead and a pixel of exactly 255 lands at index bins, one past the end of your list, for an IndexError that only ever appears on images containing pure white.
Multiply before dividing, too: p * bins // 256 is exact integer arithmetic, while p // (256 // bins) breaks as soon as bins isn't a power of two.
Visualize binning frequency, check distribution shapes, and inspect skewness effects on center measures.
We group values using [left-inclusive, right-exclusive) intervals. For example, in the Medium setting, a value of exactly 8 belongs to interval [8, 12) and is not counted in [4, 8). The final interval [20, 24] includes both endpoints to capture the maximum value.
Notice how changing the bin setting from Few to More changes the visual resolution of the dataset, revealing local clusters or smoothing them out, while the underlying observations remain identical.
Once your code passes every test, a reference solution shows up here so you can compare it with yours.