Digit Frequency Histogram - Problem
Given a positive integer, count the frequency of each digit (0-9) and display a horizontal histogram using '*' characters.
For each digit that appears in the number, print the digit followed by a colon, then print '*' characters equal to the frequency of that digit.
Rules:
- Only display digits that actually appear in the number
- Display digits in ascending order (0, 1, 2, ..., 9)
- Each histogram bar should be on a separate line
- Format:
digit: ****(digit, colon, space, then stars)
Input & Output
Example 1 — Basic Case
$
Input:
number = 1223
›
Output:
1: *
2: **
3: *
💡 Note:
Digit 1 appears 1 time, digit 2 appears 2 times, digit 3 appears 1 time. Display in ascending order with histogram bars.
Example 2 — Repeated Digits
$
Input:
number = 112233
›
Output:
1: **
2: **
3: **
💡 Note:
Each digit 1, 2, and 3 appears exactly 2 times, so each gets a 2-star histogram bar.
Example 3 — Single Digit
$
Input:
number = 7
›
Output:
7: *
💡 Note:
Only digit 7 appears once, so output shows just '7: *'
Constraints
- 1 ≤ number ≤ 1018
- Number is always positive
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code