Amazon Interview Question for Quality Assurance Engineers

Country: India
Interview Type: In-Person

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

Just keep a count of the number of zeros and the number of ones, since they can't be intermingled. No data structure even required.

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

``````public void addElements(int k) {
DoubleSidedLnkedList node = new DoubleSidedLnkedList(k);
temp = node;
} else if (k == 0) {
while (temp.previous != null) {
temp=temp.previous;
}
node.next = temp;
temp.previous=node;
}
else{
while (temp.next != null) {
temp=temp.next;
}
node.previous = temp;
temp.next=node;
}
}``````

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

You can try and solve this using linked list implementation. If input is one you add it at the end of the linked list, if the input is zero you add it at the start. Each time user inputs something, just print the whole linked list.

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

Linked List or any other Data Structure cannot be used.

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

``````public Node buildList(int input, Node head) {
Node temp = new Node();
if (input == null || head == null)
return null;

if (head.value == null){ // first element
}
if (input == 1) // add to the end of the list
while(tempHead.next != null) // iterate to the end of the list
temp.value = input;
else if (input == 0){ // add to beginning
temp.value = input;
}

}

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

Undoubtedly not perfect, but basic algorithm

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

{
{
{#include<stdio.h>
#include<conio.h>
int a[50],b[50],count=0;
void zero(int ,int );
void display();
void zero(int p,int q)
{
int i;
for(i=q;i>=0;i--)
{
b[i+1]=b[i];
}
b[0]=p;
}
void display(int i)
{
int j;
for(j=0;j<=i;j++)
printf("%d",b[j]);
}
void main()
{
int i,j;
clrscr();
i=0;
while(i<50)
{
scanf("%d",&a[i]);

if(a[i]==0)
{ zero(a[i],i);
count++;
}
else if(a[i]==1)
{ b[count]=a[i];
count++;
}
else
break;

printf("\t");
display(i);
printf("\n");
i++;

}
getch();
exit (1);
}
}
}
}

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

Here i am using array of 50. It can be changed as require.
And this code giving output in next line. Is this correct?

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

``````#include <iostream>

using namespace std;

int main() {
int c1=0, c0=0;
char in;
while(1){
cin>>in;
if(in=='1') c1++;
else if(in=='0') c0++;
else break;
for(int i=c0; i>0; i--)
cout<<0;
for(int i=c1; i>0; i--)
cout<<1;
cout<<endl;
}
return 0;
}``````

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

did without datastructure

``````while (true) {

num = scanner.nextInt();

if (num == 1) {
count1++;
}
if (num == 0) {

count0++;
}

for (int i = 0; i < count0; i++)
System.out.print(""+0);

for (int i = 0; i < count1; i++)
System.out.print(""+1);
System.out.println("");
}``````

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

static String s ="";

public static void main(String args[])
{
Scanner in = new Scanner(System.in);
while (in.hasNext())
{
String str = in.nextLine();
if(str.equals("1") || str.equals("0"))
{
String s1 = testmethod(str);
System.out.println("s= "+s1);
}
else
return; // break; can also be used here.

}
}

public static String testmethod(String args)
{

if(args.equals("0"))
{
s = args+s;

}
else if(args.equals("1"))
{
s = s+args;
}

return s;
}

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

What is scanner class in this program? I did not find this in java.

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

``````#!/usr/bin/python

import os
import sys

numString = ''

while True:

num = int(raw_input())

if num == 1:
numString += '1'

elif num == 0:
numString = '0' + numString

print str(num)+' '+numString``````

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

In python:

``````while True:
x=(input("Enter the numbers to append:"))
if x=='q':
break
result=""
for i in x:
if i is '1':
out.append(i)
elif i is '0':
out.insert(-len(out),i)
result=(''.join(out))
print (result)``````

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.

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.

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.

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.