Amazon Interview Question for Software Engineer in Tests






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

Nice que.

What about following logic:

reverse the bits of number for example number is 01100110
int dig = 1;
int rev = 0;
for(i=0;i<8;++i)
{
if(number & (dig<<i))
rev = pow(2,(7-i)) + rev;
}

if(! rev ^ number)
{
print palindrom
}
else
{
print bye-bye :)
}

- Rahul D July 22, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

hey dude why the fuck u people post the code???
Just write the logic how to do.

- Anonymous July 23, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

didnt get the question
suppose how 0110 be a palindrome????
wy are u taking the leading zero if i take like this 0110= 0000110 then????
i think we should take till 1 means 6=110 is it or please elaborate what to do ??

- geeks July 22, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Same problem here..how we are defining
4= 0100 but we can write 4 as 00100 and its also palindrome .

- ashish July 29, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I concur, it's a poorly structured and very ambiguous question. Also, it's obvious from the attempted solutions that the intent of the question is not clear to any one else either.

- Developer August 22, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Rahul is right. Although I would've preferred using scanf() to create two strings nd using strcmp()

- Jay July 22, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

bool isPalindrome(int num)
{
	int revNum=0;
	int temp=num;
	while(temp)
	{
		revNum = (revNum<<1)|(temp&1);
		temp=temp>>1;
	}
	temp=num;
	while((temp&1)==0)
	{
		revNum = revNum<<1;
		temp=temp>>1;
	}
	return ((num&revNum)==num)?true:false;
}

- Anonymous July 22, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>
using namespace std;
#include<stdlib.h>
#include<string.h>

char *convert(int num)
{
char *str=new char(20);
char *st="0123456789";
int x,i=0;;
while(num)
{
x=num%2;
str[i++]=st[x];
num=num>>1;
}
str[i]='\0';
return str;
}

bool check(char *str)
{
int flag=1;
for(int i=0,j=strlen(str)-1;i<=j;i++,j--)
{
if(str[i]==str[j])
flag=1;
else
{
flag=0;
break;
}
}
if(flag)
return true;
else
return false;
}

int main()
{
int num;
cout<<"entr num\n";
cin>>num;
char *str=new char(20);
strcpy(str,convert(num));
if(check(str))
cout<<"is palin\n";
else
cout<<"not a palindrom\n";
return 0;
}

- ashu July 24, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I'm considering all the bits of the given number. So let N is the original number. Now initially nLeft = N and nRight = N. nLeft & nRight represent result of the number N when its left & right shifted by 1 respectively. Algo is as follows:

while (nLeft != 0 && nRight != 0)
{
 if (first bit of nRight != last bit of nLeft)
 {
    number is not palindrom
    break;
 }
  nRight = nRight >> 1;
  nLeft = nLeft << 1;
}

if (nLeft == nRight)
{
  number is palindrom
}

Hope I'm clear enough. Plz comment on the approach.

- Aqui July 28, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

// Since Character is unsigned short :) - Check with any 16 bit palindrome
	private boolean CheckBits(Character val,int n)
	{
		if(n > Character.SIZE-n-1)
			return true;
		if(((val >> n)&1) == ((val >> Character.SIZE-n-1)&1))
			{
			return CheckBits(val, n+1);
			}
		return false;
	}

- RiTZ August 11, 2011 | Flag Reply


Add a Comment
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.

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