Amazon Interview Question 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;

}

- intrepid_interviewee on October 14, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

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

- Gajanan on November 14, 2009 | Flag
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));
}

- wolverine on October 17, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

return resultado;
}

- Axel David Velazquez Huerta. on October 18, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

here we go again:

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

- Axel David Velazquez Huerta. on October 18, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

how about
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........

- utscool on March 02, 2010 | Flag Reply
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;
}

- ad on November 24, 2010 | Flag Reply


Add a Comment
Name:

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

Books

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

Learn More

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.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More