Amazon Interview Question for Software Engineer / Developers






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

boolean isBitPalindrome(int num) {
		int store = num;
		int reversedNum = 0;
		while ( num != 0) {
			if ( (num & 1) == 1) {
				reversedNum += 1;
			}
			num = num >> 1;
			if ( num != 0)
				reversedNum = reversedNum << 1;
		}
		return (store == reversedNum);
	}

- Anonymous February 26, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

What questions were you asked in Multithreading?

- Satya April 16, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

lets take an example
0xabcddcba
Byte0 is Reverse of Byte3 (ba .. ab)
Byte1 is Reverse of Byte2 (dc ..cd)

Logic is simple, just compare B3 with reverse of B0 && B1 with reverse of B2. if both evaulates to TRUE, given bit pattern of an integer is a palindrome.

I assume there exists a lookup table which already stores the reverse of numbers from 0-256.

if((lookupTable[n&0xff]) == (n>>24 & 0xff)
&& (lookupTable[n>>8 & 0xff]) == (n>>16 & 0xff)
)
{
printf("Bit pattern of <%d> is a palindrome\n", n);
}

- Jack of All October 08, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

one issue with this approach is that you are assuming
size of the int type,which is quite platform dependent.

- acoader November 09, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

// copy the bit pattern backwards & xor with original.
// if result is 0 then its palindrome,return true
// else false
bool isPalindrome( int x )
{
size_t t = sizeof(int)*CHAR_BIT; // num of bits in the int
int x_rev = 0; // to store the reverse pattern
const int mask = 1;

for ( int i = 0; i < t; ++i ) {

// the bit at position t-i must
// be the bit at position i for a
// palindrome! 0 bits are already there
// in x_rev. Only 1s need to be
// determined
if ( x & (mask << i) ) {
x_rev |= mask << t - i;
}
}
return !(x^x_rev);
}

- acoader@gmail.com November 09, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote
{{{ bool Ispalin(int b1){ int b2; while(b1){ b2 + = (b1 & 1); B1>>1; B2<<1; } return ((b1==b2)? 1:0) } - cray_aksday December 20, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

bool Ispalin(int b1){
	int b2;
	while(b1){
		b2 + = (b1 & 1);
		B1>>1;
		B2<<1;
	}
return ((b1==b2)? 1:0)

}

- cray_aksday December 20, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

this wont work because in the last shift when b1 becomes 0, u r unnecessarily adding a 0 to b2

- translator February 26, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

int check_palindrome(unsigned int n)
{
  unsigned int t = 0;

  for(unsigned int bit = 1; bit && bit <= n; bit <<= 1)
    t = (t << 1) | !!(n & bit);

  return t == n;
}

- sraj October 17, 2012 | 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