Amazon Interview Question for Software Engineers


Country: United States




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

int parity(int x) {
    return (x == 0) ? 0 : parity(x >>> 1) + (x & 0x1);
}

- Dave H March 18, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

In other words,

int parity(int x) {
    return (x == 0) ? 0 : parity(x / 2) + (x % 2);
 }

- harshan87 April 07, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static boolean evenParity(Integer value){
        int i =0;
        boolean result = false;

        do{
           if ((value&1) == 1){
                i++;
           }
            value = value>>1;
        }while(value == 0);

        if(i % 2 == 0){
            result = true;
        }
        return result;
    }

- GT March 16, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

I didn't see the optimization part. So I would say something like that :

public static int evenRecursiveParity(Integer value){
        return value !=0 ? ((value&1) + evenRecursiveParity(value>>1))%2 : 0;
    }

Return 1 if odd and 0 if even.

- GT March 16, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int parity(int n, int bits, int p) {
  return (bits == 0) ?  p : parity(n, bits - 1, (n & (1 << (bits-1))) ? ((p + 1) % 2) : p);
}

int main(int argc, char**argv) {
  int n = 0;
  sscanf(argv[1], "%d", &n);
  int bits = floor(log(n)/log(2)) + 1;
  int p = parity(n, bits, 0);
  printf("%d", p);
  return 0;
}

- babesh March 17, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I am a newbe, I have a basic question here. We need to count the number of ones and if they are odd, then its odd or even parity bit. Now, when we look at the code, the code keeps right shifting the number until it reaches '0'. So, we are counting bits from different number than the one passed.My, understanding was we should count the one bits of a given number without chaining the number. Even though this code is working correctly I'm not able to understand how this is working.

- chandram.CM26 March 23, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

static Boolean GetParity(int num, Boolean checkEven){
		return (num == 0) ? checkEven : GetParity((num-1)& num, !checkEven);
	}

- Kshitiz Agarwal March 29, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

static Boolean GetParity(int num, Boolean checkEven){
	return (num == 0) ? checkEven : GetParity((num-1)& num, !checkEven);
}

- Kshitiz Agarwal March 29, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

static Boolean GetParity(int num, Boolean checkEven){
	return (num == 0) ? checkEven : GetParity((num-1)& num, !checkEven);
}

- havefun March 29, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class ParityCheck {
	
	public static boolean parityCheck(int in)
	{
		int count = 0;
		while(in >0)
		{
			count = count+in%2;
			 in =in >> 1;
		}
		
		return (count%2 == 0)?true:false;
	}

- pbhat June 19, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class ParityCheck {
	
	public static boolean parityCheck(int in)
	{
		int count = 0;
		while(in >0)
		{
			count = count+in%2;
			 in =in >> 1;
		}
		
		return (count%2 == 0)?true:false;
	}

- pbhat June 19, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class ParityCheck {
	
	public static boolean parityCheck(int in)
	{
		int count = 0;
		while(in >0)
		{
			count = count+in%2;
			 in =in >> 1;
		}
		
		return (count%2 == 0)?true:false;
	}

- pbhat June 19, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote
public class ParityCheck {{{ public static boolean parityCheck(int in) {{{ int count = 0; while(in >0) {{{ count = count+in%2; in =in >> 1; }}} return (count%2 == 0)?true:false; }}} - pbhat June 19, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class ParityCheck {
	
	public static boolean parityCheck(int in)
	{
		int count = 0;
		while(in >0)
		{
			count = count+in%2;
			 in =in >> 1;
		}
		
		return (count%2 == 0)?true:false;
	}

- pbhat June 19, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

{public class ParityCheck {

public static boolean parityCheck(int in)
{
int count = 0;
while(in >0)
{
count = count+in%2;
in =in >> 1;
}

return (count%2 == 0)?true:false;
}}

- pbhat June 19, 2015 | 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