## Amazon Interview Question for Software Engineer in Tests

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

``````int reversedNumber = 0;

while (n > 0) {
reversedNumber = 10 * reversedNumber + n % 10;
n /= 10;``````

}

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

This is most correct and concise solution. It takes care of negative integer as well.

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

``````#include<stdio.h>

int revDigits(int no) {
int negFlag=0;
int rev=0;
if(no<0) {
negFlag=1;
no=-no;
}
while(no>0) {
rev*=10;
rev+=(no%10);
no=no/10;
}
if(negFlag) {
rev=-rev;
}
return rev;
}

int main() {
printf("%d : %d\n",764,revDigits(764));
printf("%d : %d\n",-764,revDigits(-764));
printf("%d : %d\n",0,revDigits(0));
printf("%d : %d",4,revDigits(4));
}``````

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

int reverseInt(int numero)
{
int residuo = 0;
while(numero != 0)
{
residuo = numero%10;
numero -= residuo;
numero= numero/10;
}

}

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

here we go again:

``````int reverseInt(int numero)
{
int residuo = 0;
while(numero != 0)
{
residuo = numero%10;
numero -= residuo;
numero= numero/10;
}

}``````

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

int n;
char a[11];//as 2^32 = 4294967296
sprintf(a,"%d",n);
if(n<0)sprintf(a,"-");
strrev(a);
n=atoi(a);
hence reversed........

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

void ReverseDigit(int number){
//cout<<"number"<<number<<endl;
if (number==0){
return;
}
cout<<number%10;
ReverseDigit(number/10);

return;
}

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.