Amazon Interview Question for Quality Assurance Engineers


Country: India




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

def solve(arr):
	left=0
	right=len(arr)-1
	while left<right:
		while left<right and arr[left]==0:
			left+=1
		while left<right and arr[right]==1:
			right-=1
		arr[left],arr[right]=arr[right],arr[left]
		left+=1
		right-=1
	return arr

- Anonymous October 24, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Let me give you an O(2n) algorithm (pseudocode).

sum = 0;
binaryArray = [0, 1, 1, 0, 0, 1, 0, 0, 1];

for i in binaryArray:
    sum = sum + i;

length = len(binaryArray)
result = zeros(length)

for i, value in enumerate(result):
    if sum > 0:
        result[length - i] = 1
        sum = sum - 1

- Prasad N R October 21, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static int[] zerosToLeft(int[] arr) {
		int j = arr.length-1;
		int[] rez = new int[arr.length];
		for(int i = 0; i < arr.length; i++){
			if(arr[i] == 1) {
				rez[j] = arr[i];
				j--;
			}
		}
		return rez;

}

- Ahmet October 27, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

let a = [1,0,1,0,0,1,0,1,0,0,0,0,0]

func zeroFollowedByOne(a: [Int]) -> [Int] {
var a = a
var l = 0
var h = a.count - 1

while l < h {
if a[l] == 1 && a[h] == 0 {
let temp = a[h]
a[h] = a[l]
a[l] = temp
l+=1
h-=1
} else if a[l] == 0 && a[h] == 1 {
l+=1
h-=1
} else if a[l] == 0 && a[h] == 0 {
l+=1
}
}

return a
}

- trycoding October 30, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

let a = [1,0,1,0,0,1,0,1,0,0,0,0,0]

func zeroFollowedByOne(a: [Int]) -> [Int] {
    var a = a
    var l = 0
    var h = a.count - 1
    
    while l < h {
        if a[l] == 1 && a[h] == 0 {
            let temp = a[h]
            a[h] = a[l]
            a[l] = temp
            l+=1
            h-=1
        } else if a[l] == 0 && a[h] == 1 {
            l+=1
            h-=1
        } else if a[l] == 0 && a[h] == 0 {
            l+=1
        }
    }
    
    return a
}

- trycoding October 30, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

let a = [1,0,1,0,0,1,0,1,0,0,0,0,0]

func zeroFollowedByOne(a: [Int]) -> [Int] {
    var a = a
    var l = 0
    var h = a.count - 1
    
    while l < h {
        if a[l] == 1 && a[h] == 0 {
            let temp = a[h]
            a[h] = a[l]
            a[l] = temp
            l+=1
            h-=1
        } else if a[l] == 0 && a[h] == 1 {
            l+=1
            h-=1
        } else if a[l] == 0 && a[h] == 0 {
            l+=1
        }
    }
    
    return a

}

- trycoding October 30, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

O(n) where in is the length of bin_array
In python:

def sort(bin_array):
    length = len(bin_array)
    ones = sum(bin_array)
    zeros = length - ones
    return [0 for _ in range(zeros)] + [1 for _ in range(ones)]

- Anonymous November 02, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String[] args) {

int array[]= {0,1,1,0,0,1,0,0,1};
int lastIndexValue=array.length-1;
int newArray[]= new int[array.length];

for(int i=0;i<array.length;i++) {

if(array[i]==1) {
newArray[lastIndexValue]=1;
lastIndexValue--;
}
}

System.out.println(Arrays.toString(newArray));
}

- Amir Luitel November 10, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String[] args) {
		
		int array[]= {0,1,1,0,0,1,0,0,1};
		int lastIndexValue=array.length-1;
		int newArray[]= new int[array.length];
		
		for(int i=0;i<array.length;i++) {
			
			if(array[i]==1) {
				newArray[lastIndexValue]=1;
				lastIndexValue--;
			}
		}
		
		System.out.println(Arrays.toString(newArray));
	}

- Amir Luitel November 10, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def sortbits(il):

    for i in range(len(il)):
        if il[i] == 1:
            for j in range(len(il) - 1, i + 1, -1):
                if il[j] == 0:
                    il[i], il[j] = il[j], il[i]
                    break

    return il

driver = [0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0]
print(sortbits(driver))

- Anonymous November 10, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def sortbits(il):
    for i in range(len(il)):
        if il[i] == 1:
            for j in range(len(il) - 1, i + 1, -1):
                if il[j] == 0:
                    il[i], il[j] = il[j], il[i]
                    break
    return il

driver = [0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0]
print(sortbits(driver))

- Anonymous November 10, 2019 | 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