Dcoder

Happy String @ Dcoder

By Lochard | As a newbie programmer | 15 Mar 2023


Problem: A happy string is a string in which each character is lexicographically greater than its next character. You are given a positive integer N as an input. You need to print the smallest lexicographical string possible of length N.
NOTE: All characters in a happy string are in lowercase.
Input: A single integer N.
Output: Print the lexicographically smallest string of length N.
Constraints: 1 ≤ N ≤ 26
Sample Input: 2
Sample Output:
ba

n = int(input()) + 96
for i in range(n, 96, -1):
  print(chr(i), end ='')

How do you rate this article?

4


Lochard
Lochard

20240228 Arrived in the UK for about 2 week. All my fears persist. Some are even getting worse. https://github.com/locharp/asylum_diary/


As a newbie programmer
As a newbie programmer

Sharing entry level codes. My snippets on GitHub https://github.com/locharp/code-snippets

Publish0x

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.