Amazon Interview Question for SDE-3s


Country: United States
Interview Type: In-Person




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

package main

import "fmt"

func Sum(a, b int) int {
	res := a ^ b
	y := a & b << 1
	for y > 0 {
		a = res
		res = res ^ y
		y = a & y << 1
	}
	return res
}

func main() {
	fmt.Println(Sum(10, 20)) // Output: 30
}

- dmitry.labutin March 09, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I would just write the simple logic here :

int Add(int x, int y){
    while(y!=0){
        int carry = (x&y)<<1;
        x=x^y;
        y=carry;
    }
    return x;
}

- Joe March 10, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

handles all cases easy ans simple

#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
while(b!=0)
{
int carry= a&b;
a = a ^ b;
b = carry<<1;
}
cout<< a<<endl;;
}

- rahul_kumar March 18, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>

int Add(int x, int y)
{
// Iterate till there is no carry
while (y != 0)
{
// carry now contains common set bits of x and y
int carry = x & y;

// Sum of bits of x and y where at least one of the bits is not set
x = x ^ y;

// Carry is shifted by one so that adding it to x gives the required sum
y = carry << 1;
}
return x;
}

- ajkool111 March 21, 2017 | 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