Back
Close

Stem and leaf diagram

Statement

 Goal

Stem-and-leaf diagrams are useful for visualizing the distribution of data, whether continuous or discrete. In a stem-and-leaf diagram, each data value is split into two, where:
* The stem contains every digit but the last
* The leaf contains only the last digit

Stems and leaves should be sorted in ascending order. One stem can have multiple leaves, which is the case when multiple values share the same stem. For example, the stem-and-leaf plot for the set 24, 27, 24 looks like:
2 | 4 4 7

Given n integers, output a stem-and-leaf diagram.
Input
Line 1: An integer n representing the number of integers to plot
Line 2: n space-separated integers
Output
A stem and leaf diagram, where the stems and leaves are separated by a "|"
Constraints
0<n<1000
Example
Input
2
1 10
Output
  | 1
1 | 0

Tags
SortingArraysLoops

Difficulty
Hard

Test cases
Test 1 Test
Input
2 1 10
Output
| 1 1 | 0

Validator 1 Validator
Input
4 11 23 44 58
Output
1 | 1 2 | 3 4 | 4 5 | 8

Test 2 Test
Input
6 1 9 2 5 4 7
Output
| 1 2 4 5 7 9

Validator 2 Validator
Input
6 0 12 34 56 78 9
Output
| 0 9 1 | 2 3 | 4 5 | 6 7 | 8

Test 3 Test
Input
0
Output
NOTHING

Validator 3 Validator
Input
1 0
Output
| 0

Test 4 Test
Input
50 699377 170465 837076 324136 981072 691683 372004 318411 646052 466432 231027 99021 681383 475369 804377 886486 214388 8275 243880 883371 163966 382671 833651 771104 879201 847539 444576 916797 472937 808976 428988 175181 307073 643284 940941 245777 27926 735942 616772 277626 237961 931252 198002 826623 7946 923746 552722 793752 28461 745387
Output
794 | 6 827 | 5 2792 | 6 2846 | 1 9902 | 1 16396 | 6 17046 | 5 17518 | 1 19800 | 2 21438 | 8 23102 | 7 23796 | 1 24388 | 0 24577 | 7 27762 | 6 30707 | 3 31841 | 1 32413 | 6 37200 | 4 38267 | 1 42898 | 8 44457 | 6 46643 | 2 47293 | 7 47536 | 9 55272 | 2 61677 | 2 64328 | 4 64605 | 2 68138 | 3 69168 | 3 69937 | 7 73594 | 2 74538 | 7 77110 | 4 79375 | 2 80437 | 7 80897 | 6 82662 | 3 83365 | 1 83707 | 6 84753 | 9 87920 | 1 88337 | 1 88648 | 6 91679 | 7 92374 | 6 93125 | 2 94094 | 1 98107 | 2

Validator 4 Validator
Input
19 6942096 48265 4851299 13265498 34168511 546846 214596 418574 524 546 876815 687435 8756651 68745 657654 76541 654654465 654657 6345
Output
52 | 4 54 | 6 634 | 5 4826 | 5 6874 | 5 7654 | 1 21459 | 6 41857 | 4 54684 | 6 65465 | 7 65765 | 4 68743 | 5 87681 | 5 485129 | 9 694209 | 6 875665 | 1 1326549 | 8 3416851 | 1 65465446 | 5

Solution language

Solution

Stub generator input