employer cover photo
employer logo
employer logo

Walt Disney Company

Is this your company?

Walt Disney Company interview question

Write code to reverse the digits in an integer.

Interview Answers

Anonymous

1 Mar 2013

int reverse(int a) { int b = 0; while (a>0) { b *= 10; b += a%10; a /= 10; } return b; }

10

Anonymous

1 July 2015

To Robert: Remember integer division will truncate the value, so 93/10 = 9, not 9.3.

1

Anonymous

31 July 2016

function reverseNum(num) { let result = 0, isNeg = num 0) { result = result * 10 + num % 10; num = Math.floor(num / 10); } return isNeg ? -1 * result : result; }

Anonymous

31 July 2016

The above formatted incorrectly. function reverseNum(num) { let result = 0, isNeg = num 0) { result = result * 10 + num % 10; num = Math.floor(num / 10); } return isNeg ? -1 * result : result; }

Anonymous

12 June 2015

I am not sure this solution would work because if a was 93, your program would produce the answer 39.3, but I am not really a software guy so idk. my logic is that a=93 93%10 = 3 b=3 a=9.3 *next iteration* b=30 9.3%10 = 9.3 b = 39.3 is this correct? just as a disclaimer, I am not trying be an jerk, I am just practicing interview questions lol

1