Each letter, a-z, is assigned values in the following way: a: 1, b: 2, …, z: 26. You are given string, S, consisting of lowercase English letters and an integer, K. Find the lexicographically minimal string, whose sum is equal to K
# | User | Rating |
---|---|---|
1 | tourist | 3690 |
2 | jiangly | 3647 |
3 | Benq | 3581 |
4 | orzdevinwang | 3570 |
5 | Geothermal | 3569 |
5 | cnnfls_csy | 3569 |
7 | Radewoosh | 3509 |
8 | ecnerwala | 3486 |
9 | jqdai0815 | 3474 |
10 | gyh20 | 3447 |
# | User | Contrib. |
---|---|---|
1 | maomao90 | 174 |
2 | awoo | 165 |
3 | adamant | 161 |
4 | TheScrasse | 160 |
5 | nor | 158 |
6 | maroonrk | 156 |
7 | -is-this-fft- | 152 |
8 | orz | 146 |
8 | SecondThread | 146 |
10 | pajenegod | 145 |
Each letter, a-z, is assigned values in the following way: a: 1, b: 2, …, z: 26. You are given string, S, consisting of lowercase English letters and an integer, K. Find the lexicographically minimal string, whose sum is equal to K
Name |
---|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
But if the string is given....dont we have to find lexicographically minimal string starting from that string.....???
i think i may have interpret this problem in a wrong way !!! can you explain ??!!
i mean that you need to write letter "a" k times
Answer is 'a' repeated k times.
The answer would simply be 'a' k times... but since it's super obvious I suppose you meant (maybe) the lexicographically minimal string out of the ones with minimal length.
If that is the case, then the minimal amount of letters you will need is ceil(K / 26). Then: if K is divisible by 26, then it is the letter 'z' (K / 26) times.
else, then the first letter is (K mod 26), and after it's 'z' (K / 26) times.
Buuuuuuut according to how you worded your question, the answer is K times 'a'.