Блог пользователя Shellhead96

Автор Shellhead96, история, 7 лет назад, По-английски

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

  • Проголосовать: нравится
  • -9
  • Проголосовать: не нравится

»
7 лет назад, # |
  Проголосовать: нравится +35 Проголосовать: не нравится

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    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 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

Answer is 'a' repeated k times.

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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