how to find next highest number for the given number which should contains only the digits 2 and 7. ex:i/p 2 o/p 7,i/p 22 o/p 27 | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 2

how to find next highest number for the given number which should contains only the digits 2 and 7. ex:i/p 2 o/p 7,i/p 22 o/p 27

what is the way to find 2nd highest value in Ruby's

7th Feb 2018, 7:09 PM
Gopi Krishna
Gopi Krishna - avatar
1 Respuesta
+ 1
I'd create a class that translates your number to binary (replace 2 by 0 and 7 by 1), then increase your number and convert back to 2's and 7's. Example: i/p: 7727 is translated to binary 1101, which is 13. Add 1 makes 14, which is 1110. Translated this makes 7772 :)
9th Feb 2018, 3:44 PM
Freddy