Pergunta de entrevista da empresa Booking.com

Given a integer , return corresponding ASCII char representation without using language building in feature. ex. input interger 1234, return "1234" in string or characters

Respostas da entrevista

Sigiloso

10 de out. de 2017

function numberToString(n){ if(n/10 < 1) return "" + n //edge case return numberToString(Math.round(n/10)) + "" + n%10 //I concatenate with the empty string just to convert the number to a string without using built-in toString() }

1

Sigiloso

19 de out. de 2017

def itoa(num): array = [] while num > 0: rem = num % 10 array.append(chr(rem + 48)) num = num // 10 array.reverse() return ''.join(array)

1

Sigiloso

19 de dez. de 2017

num = 1234 result='' while (num > 0): rem = num % 10 result = str(rem) + result num = int(num / 10) print(result)

Sigiloso

4 de jul. de 2019

def int2str(num: Int): String = { if (num > 0) int2str(num / 10) + (num % 10).toString else "" }

Sigiloso

4 de jul. de 2019

def int2str(num: Int): String = { if (num > 0) int2str(num / 10) + (num % 10 + 48).toChar else "" }

Sigiloso

8 de out. de 2016

num_to_convert = 10 # or any INT number converted_str = '' while True: remainder = num_to_convert % 10 converted_str += str(remainder) if (num_to_convert // 10) <= 0: break else: num_to_convert //= 10 print(converted_str[::-1])

Sigiloso

15 de jun. de 2016

while (num > 0) { int rem = num % 10; result += rem; num = num / 10; } string x = Reverse(result); return x;

3