Booking.com interview question

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

Interview Answers

Anonymous

10 Oct 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

Anonymous

19 Oct 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

Anonymous

19 Dec 2017

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

Anonymous

4 July 2019

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

Anonymous

4 July 2019

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

Anonymous

8 Oct 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])

Anonymous

15 June 2016

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

3