Count grayscale pixel intensities and return a compact sparse histogram. Scan every pixel, count each intensity, then return only intensities that appear. Each output entry is a two-element list containing the intensity followed by its count. Sort entries by increasing intensity.
Input: image = [[0, 1], [1, 2]]
Output: [[0, 1], [1, 2], [2, 1]]
Explanation: Intensities zero and two occur once, while intensity one occurs twice.
Input: image = [[128, 128], [128, 128]]
Output: [[128, 4]]
Use a 256-element count list or a dictionary while scanning the pixels.
Build the result in increasing intensity order and skip zero counts.
Sign in to take notes on this problem
Accepts: array
Count grayscale pixel intensities and return a compact sparse histogram. Scan every pixel, count each intensity, then return only intensities that appear. Each output entry is a two-element list containing the intensity followed by its count. Sort entries by increasing intensity.
Input: image = [[0, 1], [1, 2]]
Output: [[0, 1], [1, 2], [2, 1]]
Explanation: Intensities zero and two occur once, while intensity one occurs twice.
Input: image = [[128, 128], [128, 128]]
Output: [[128, 4]]
Use a 256-element count list or a dictionary while scanning the pixels.
Build the result in increasing intensity order and skip zero counts.
Sign in to take notes on this problem
Accepts: array