smallest number greater than N following a property. HELP
Anonymous User
1254

question: You are given a number N. a number is called beautiful if for every digit x in the number there are x occurrences of it in the number.

  • 1 is beautiful because 1 has 1 occurrence
  • 3133 is beautiful becasue 1 has 1 occurence and 3 has 3 occurences
  • 224 is not beautiful

determine the samllest beautiful number which is greater than N.

eg. N=1 ans: 22 is the smallest beautiful number greater than 1
N=250 ans: 333

how to solve this without travelling through every next element to determine the correct output??

Comments (0)