## Booking.com Interview Question for Software Developers

Country: United States
Interview Type: Phone Interview

Comment hidden because of low score. Click to expand.
2
of 2 vote

Java:

``````public class IntegerToString {

public static void main(String[] args) {
System.out.println(itoa(4973));
System.out.println(itoa(-59385));
System.out.println(itoa(0));
}

private static String itoa(int num) {
if(num == 0){
return "0";
}
boolean negative = num < 0;
String result = "";
while(num != 0) {
result = Math.abs(num%10) + result;
num /= 10;
}
return negative ? "-" + result : result;
}

}``````

Outputs:

``````4973
-59385
0``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

It's actually quite simple. Use mod and div.

Comment hidden because of low score. Click to expand.
0
of 0 vote

Use recursion

``````char result [50]={'0'};
int i=0;

itoa(int a){
if(!a) return;
else{
itoa(a/10);
result[i++]=a%10+'0';
}
}``````

Do checks on negative numbers before and increment i by 1 storing '-' at 0th position of result

Comment hidden because of low score. Click to expand.
0
of 0 vote

Use recursion

``````char result [50];
int i=0;

void itoa(int a){
if(!a) return;
else
itoa(a/10);
result [i++]= a%10+'0';
}``````

Check for negative and zero before calling recursion and make changes in the result array accordingly.

Comment hidden because of low score. Click to expand.
0
of 0 vote

``System.out.println("an itoa");``

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````public class Solution1 {
public static void main (String args[]) {
Solution1 s = new Solution1();
System.out.println(s.solve(-333));
}
public String solve(int number) {
if (number == 0)
return "0";
String results = "";
boolean negative = false;
if (number < 0){
results = "-";
negative = true;
}
if (negative)
number = number * (-1);
int remain = number % 10;
number = number / 10;
if (number != 0)
return results+""+solve(number)+remain;
return results+""+remain;
}
}``````

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.