Shellhead96's blog

By Shellhead96, history, 7 years ago, In English

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

  • Vote: I like it
  • -9
  • Vote: I do not like it

| Write comment?
»
7 years ago, # |
  Vote: I like it +35 Vote: I do not like it

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

  • »
    »
    7 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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 ??!!

»
7 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Answer is 'a' repeated k times.

»
7 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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'.