Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

smallest string with a given numeric value

def solve(n, k):
   string = ""
   while n > 0:
      letter = min(26, k-n+1)
      string += chr(letter + ord('a') - 1)
      k -= letter
      n -= 1
   return string[::-1]

n = 4
k = 16
print(solve(n, k))
Source by www.tutorialspoint.com #
 
PREVIOUS NEXT
Tagged: #smallest #string #numeric
ADD COMMENT
Topic
Name
1+6 =