Amazon Interview Question for Quality Assurance Engineers


Country: India
Interview Type: Written Test




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

Make hash table of S1. Iterate S1 if all elements are present and iterate S3 if any one element is missing by checking with hash table of S1.

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

import java.util.HashMap;
import java.util.Map;

public class SubSetQuestion {

	public static void main(String[] args) {
		int[] S1 = {1,5,4,6,8,2};
		int[] S2 = {5,8,2};
		int[] S3 = {5,8,2,7};
		
		Map<Integer, Integer> map = new HashMap();
		for(int i=0;i<S1.length;i++)
		{
			map.put(S1[i], 1);
		}
		
		for(int i=0;i<S2.length;i++)
		{
			if(!map.containsKey(S2[i]))
				System.out.println("S2 is not subset");
		}
		
		for(int i=0;i<S3.length;i++)
		{
			if(!map.containsKey(S3[i]))
				System.out.println("S3 is not subset");
		}


	}

}

- Kamna May 12, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void findSubset(){
    int s1[]={1,5,4,6,8,2};
   int s2[]={5,8,2};
    //int s2[]={5,8,2,7};
    
    if(s2.length > s1.length || s2.length == 0)
        System.out.println(s2+" is not a subset of "+s1);
    
    int k=0;
    boolean isSubset=false;
    for(int i=0;i<s1.length;i++){
        if(s1[i] == s2[k]){
            if(k+1 == s2.length){
              System.out.println(s2+" is a subset of "+s1);
              isSubset=true;
            }
            k++;
        }
    }
    if(!isSubset)
      System.out.println(s2+" is not a subset of "+s1);
    
}

- Amod Kumar May 13, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void findSubset(){
    int s1[]={1,5,4,6,8,2};
   int s2[]={5,8,2};
    //int s2[]={5,8,2,7};
    
    if(s2.length > s1.length || s2.length == 0)
        System.out.println(s2+" is not a subset of "+s1);
    
    int k=0;
    boolean isSubset=false;
    for(int i=0;i<s1.length;i++){
        if(s1[i] == s2[k]){
            if(k+1 == s2.length){
              System.out.println(s2+" is a subset of "+s1);
              isSubset=true;
            }
            k++;
        }
    }
    if(!isSubset)
      System.out.println(s2+" is not a subset of "+s1);
    
}

- Amod Kumar May 13, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void findSubset(){
    int s1[]={1,5,4,6,8,2};
   int s2[]={5,8,2};
    //int s2[]={5,8,2,7};
    
    if(s2.length > s1.length || s2.length == 0)
        System.out.println(s2+" is not a subset of "+s1);
    
    int k=0;
    boolean isSubset=false;
    for(int i=0;i<s1.length;i++){
        if(s1[i] == s2[k]){
            if(k+1 == s2.length){
              System.out.println(s2+" is a subset of "+s1);
              isSubset=true;
            }
            k++;
        }
    }
    if(!isSubset)
      System.out.println(s2+" is not a subset of "+s1);

- Amod Kumar May 13, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void findSubset(){
    int s1[]={1,5,4,6,8,2};
   int s2[]={5,8,2};
    //int s2[]={5,8,2,7};
    
    if(s2.length > s1.length || s2.length == 0)
        System.out.println(s2+" is not a subset of "+s1);
    
    int k=0;
    boolean isSubset=false;
    for(int i=0;i<s1.length;i++){
        if(s1[i] == s2[k]){
            if(k+1 == s2.length){
              System.out.println(s2+" is a subset of "+s1);
              isSubset=true;
            }
            k++;
        }
    }
    if(!isSubset)
      System.out.println(s2+" is not a subset of "+s1);
    
}

- Amod Kumar May 13, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

For this above problem, one may use unordered set in c++ and insert all the elements of s1 to the set and then keep traversing both the other arrays and check that for the s2 array if all the elements are present and for the s3 array all the elements are not present then return true else return false.

Implementation:

#include<bits/stdc++.h>
using namespace std;
bool findsubsets(int s1[], int n1, int s2[], int n2, int s3[], int n3){
int flag = 0;
int temp = 0;
unordered_set<int> s;
for(int i = 0; i < n1; i++)
s.insert(s1[i]);
for(int j = 0; j < n2; j++){
if(s.find(s2[j]) == s.end()){
flag = -1;
break;
}
}
if(flag != -1)
flag = 1;
for(int j = 0; j < n3; j++){
if(s.find(s3[j]) == s.end()){
temp = 1;
break;
}
}
if(temp != 1)
temp = -1;
if(flag == 1 && temp == 1)
return true;
else
return false;
}
int main()
{
int s1[] = {1, 5, 4, 6, 8, 2};
int s2[] = {5, 8, 2};
int s3[] = {5, 8, 2, 7};
int n1 = sizeof(s1) / sizeof(s1[0]);
int n2 = sizeof(s2) / sizeof(s2[0]);
int n3 = sizeof(s3) / sizeof(s3[0]);
cout<<findsubsets(s1, n1, s2, n2, s3, n3)<<endl;

return 0;
}

- swapnilkant11 May 29, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Subset {

public static void main(String args[]) {

int[] s2 = {5, 8, 2};
int[] s1 = {1, 5, 4, 6, 8, 2};
int[] s3 = {5, 8, 2, 7};

Set<Integer> s = new HashSet<Integer>();
for (Integer i : s1) {
s.add(i);
}
System.out.println(isContains(s2, s));
System.out.println(isContains(s3, s));
}


private static boolean isContains(int[] array, Set s) {
for (int i : array) {
if (s.add(i)) {
return false;
}
}
return true;
}
}

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

package carrercup;

import java.util.*;

public class Subset {

public static void main(String args[]) {
int[] s2 = {5, 8, 2};
int[] s1 = {1, 5, 4, 6, 8, 2};
int[] s3 = {5, 8, 2, 7};

Set<Integer> s = new HashSet<Integer>();
for (Integer i : s1) {
s.add(i);
}
System.out.println(isContains(s2, s));
System.out.println(isContains(s3, s));
}

private static boolean isContains(int[] array, Set s) {
for (int i : array) {
if (s.add(i)) {
return false;
}
}
return true;
}


}

- Vinaya June 05, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void checkSubset() {
    	int[] S1 = {1,5,4,6,8,2};
		int[] S2 = {5,8,2};
		int[] S3 = {5,8,2,7};
		
		List<Integer> s1List = new ArrayList<Integer>();
		for(int s: S1) {
			s1List.add(s);
		}
		
		List<Integer> s2List = new ArrayList<Integer>();
		for(int s: S2) {
			s2List.add(s);
		}
		
		List<Integer> s3List = new ArrayList<Integer>();
		for(int s: S3) {
			s3List.add(s);
		}
		
		// Finding if S2 is a subset of S1
		boolean isSubset = false;
		for(int s: s2List) {
			
			if (s1List.contains(s)) {
				isSubset = true;
			}
			else {
				isSubset = false;
				break;
			}
		}
		System.out.println("Is S2 Subset of S1: "+isSubset);
		
		// Finding if S2 is a subset of S1
		isSubset = false;
		for(int s: s3List) {
			
			if (s1List.contains(s)) {
				isSubset = true;
			}
			else {
				isSubset = false;
				break;
			}
		}
		System.out.println("Is S3 Subset of S1: "+isSubset);

}

- Gayathri June 25, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void checkSubset() {
    	int[] S1 = {1,5,4,6,8,2};
		int[] S2 = {5,8,2};
		int[] S3 = {5,8,2,7};
		
		List<Integer> s1List = new ArrayList<Integer>();
		for(int s: S1) {
			s1List.add(s);
		}
		
		List<Integer> s2List = new ArrayList<Integer>();
		for(int s: S2) {
			s2List.add(s);
		}
		
		List<Integer> s3List = new ArrayList<Integer>();
		for(int s: S3) {
			s3List.add(s);
		}
		
		// Finding if S2 is a subset of S1
		boolean isSubset = false;
		for(int s: s2List) {
			
			if (s1List.contains(s)) {
				isSubset = true;
			}
			else {
				isSubset = false;
				break;
			}
		}
		System.out.println("Is S2 Subset of S1: "+isSubset);
		
		// Finding if S2 is a subset of S1
		isSubset = false;
		for(int s: s3List) {
			
			if (s1List.contains(s)) {
				isSubset = true;
			}
			else {
				isSubset = false;
				break;
			}
		}
		System.out.println("Is S3 Subset of S1: "+isSubset);
    }

- Gayathri June 25, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void checkSubset() {
int[] S1 = {1,5,4,6,8,2};
int[] S2 = {5,8,2};
int[] S3 = {5,8,2,7};

List<Integer> s1List = new ArrayList<Integer>();
for(int s: S1) {
s1List.add(s);
}

List<Integer> s2List = new ArrayList<Integer>();
for(int s: S2) {
s2List.add(s);
}

List<Integer> s3List = new ArrayList<Integer>();
for(int s: S3) {
s3List.add(s);
}

// Finding if S2 is a subset of S1
boolean isSubset = false;
for(int s: s2List) {

if (s1List.contains(s)) {
isSubset = true;
}
else {
isSubset = false;
break;
}
}
System.out.println("Is S2 Subset of S1: "+isSubset);

// Finding if S2 is a subset of S1
isSubset = false;
for(int s: s3List) {

if (s1List.contains(s)) {
isSubset = true;
}
else {
isSubset = false;
break;
}
}
System.out.println("Is S3 Subset of S1: "+isSubset);
}

- Gayathri June 25, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void checkSubset() {
    	int[] S1 = {1,5,4,6,8,2};
		int[] S2 = {5,8,2};
		int[] S3 = {5,8,2,7};
		
		List<Integer> s1List = new ArrayList<Integer>();
		for(int s: S1) {
			s1List.add(s);
		}
		
		List<Integer> s2List = new ArrayList<Integer>();
		for(int s: S2) {
			s2List.add(s);
		}
		
		List<Integer> s3List = new ArrayList<Integer>();
		for(int s: S3) {
			s3List.add(s);
		}
		
		// Finding if S2 is a subset of S1
		boolean isSubset = false;
		for(int s: s2List) {
			
			if (s1List.contains(s)) {
				isSubset = true;
			}
			else {
				isSubset = false;
				break;
			}
		}
		System.out.println("Is S2 Subset of S1: "+isSubset);
		
		// Finding if S2 is a subset of S1
		isSubset = false;
		for(int s: s3List) {
			
			if (s1List.contains(s)) {
				isSubset = true;
			}
			else {
				isSubset = false;
				break;
			}
		}
		System.out.println("Is S3 Subset of S1: "+isSubset);
    }

- Gayathri June 25, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void checkSubset() {
    	int[] S1 = {1,5,4,6,8,2};
		int[] S2 = {5,8,2};
		int[] S3 = {5,8,2,7};
		
		List<Integer> s1List = new ArrayList<Integer>();
		for(int s: S1) {
			s1List.add(s);
		}
		
		List<Integer> s2List = new ArrayList<Integer>();
		for(int s: S2) {
			s2List.add(s);
		}
		
		List<Integer> s3List = new ArrayList<Integer>();
		for(int s: S3) {
			s3List.add(s);
		}
		
		// Finding if S2 is a subset of S1
		boolean isSubset = false;
		for(int s: s2List) {
			
			if (s1List.contains(s)) {
				isSubset = true;
			}
			else {
				isSubset = false;
				break;
			}
		}
		System.out.println("Is S2 Subset of S1: "+isSubset);
		
		// Finding if S2 is a subset of S1
		isSubset = false;
		for(int s: s3List) {
			
			if (s1List.contains(s)) {
				isSubset = true;
			}
			else {
				isSubset = false;
				break;
			}
		}
		System.out.println("Is S3 Subset of S1: "+isSubset);
    }

- Gayathri June 25, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void checkSubset() {
int[] S1 = {1,5,4,6,8,2};
int[] S2 = {5,8,2};
int[] S3 = {5,8,2,7};

List<Integer> s1List = new ArrayList<Integer>();
for(int s: S1) {
s1List.add(s);
}

List<Integer> s2List = new ArrayList<Integer>();
for(int s: S2) {
s2List.add(s);
}

List<Integer> s3List = new ArrayList<Integer>();
for(int s: S3) {
s3List.add(s);
}

// Finding if S2 is a subset of S1
boolean isSubset = false;
for(int s: s2List) {

if (s1List.contains(s)) {
isSubset = true;
}
else {
isSubset = false;
break;
}
}
System.out.println("Is S2 Subset of S1: "+isSubset);

// Finding if S2 is a subset of S1
isSubset = false;
for(int s: s3List) {

if (s1List.contains(s)) {
isSubset = true;
}
else {
isSubset = false;
break;
}
}
System.out.println("Is S3 Subset of S1: "+isSubset);
}

- Gayathri June 25, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void checkSubset() {
int[] S1 = {1,5,4,6,8,2};
int[] S2 = {5,8,2};
int[] S3 = {5,8,2,7};

List<Integer> s1List = new ArrayList<Integer>();
for(int s: S1) {
s1List.add(s);
}

List<Integer> s2List = new ArrayList<Integer>();
for(int s: S2) {
s2List.add(s);
}

List<Integer> s3List = new ArrayList<Integer>();
for(int s: S3) {
s3List.add(s);
}

// Finding if S2 is a subset of S1
boolean isSubset = false;
for(int s: s2List) {

if (s1List.contains(s)) {
isSubset = true;
}
else {
isSubset = false;
break;
}
}
System.out.println("Is S2 Subset of S1: "+isSubset);

// Finding if S2 is a subset of S1
isSubset = false;
for(int s: s3List) {

if (s1List.contains(s)) {
isSubset = true;
}
else {
isSubset = false;
break;
}
}
System.out.println("Is S3 Subset of S1: "+isSubset);
}

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

public static void checkSubset() {
int[] S1 = {1,5,4,6,8,2};
int[] S2 = {5,8,2};
int[] S3 = {5,8,2,7};

List<Integer> s1List = new ArrayList<Integer>();
for(int s: S1) {
s1List.add(s);
}

List<Integer> s2List = new ArrayList<Integer>();
for(int s: S2) {
s2List.add(s);
}

List<Integer> s3List = new ArrayList<Integer>();
for(int s: S3) {
s3List.add(s);
}

// Finding if S2 is a subset of S1
boolean isSubset = false;
for(int s: s2List) {

if (s1List.contains(s)) {
isSubset = true;
}
else {
isSubset = false;
break;
}
}
System.out.println("Is S2 Subset of S1: "+isSubset);

// Finding if S2 is a subset of S1
isSubset = false;
for(int s: s3List) {

if (s1List.contains(s)) {
isSubset = true;
}
else {
isSubset = false;
break;
}
}
System.out.println("Is S3 Subset of S1: "+isSubset);
}

- Gayathri June 25, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void checkSubset() {
int[] S1 = {1,5,4,6,8,2};
int[] S2 = {5,8,2};
int[] S3 = {5,8,2,7};

List<Integer> s1List = new ArrayList<Integer>();
for(int s: S1) {
s1List.add(s);
}

List<Integer> s2List = new ArrayList<Integer>();
for(int s: S2) {
s2List.add(s);
}

List<Integer> s3List = new ArrayList<Integer>();
for(int s: S3) {
s3List.add(s);
}

// Finding if S2 is a subset of S1
boolean isSubset = false;
for(int s: s2List) {

if (s1List.contains(s)) {
isSubset = true;
}
else {
isSubset = false;
break;
}
}
System.out.println("Is S2 Subset of S1: "+isSubset);

// Finding if S2 is a subset of S1
isSubset = false;
for(int s: s3List) {

if (s1List.contains(s)) {
isSubset = true;
}
else {
isSubset = false;
break;
}
}
System.out.println("Is S3 Subset of S1: "+isSubset);
}

- Gayathri June 25, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void checkSubset() {
int[] S1 = {1,5,4,6,8,2};
int[] S2 = {5,8,2};
int[] S3 = {5,8,2,7};

List<Integer> s1List = new ArrayList<Integer>();
for(int s: S1) {
s1List.add(s);
}

List<Integer> s2List = new ArrayList<Integer>();
for(int s: S2) {
s2List.add(s);
}

List<Integer> s3List = new ArrayList<Integer>();
for(int s: S3) {
s3List.add(s);
}

// Finding if S2 is a subset of S1
boolean isSubset = false;
for(int s: s2List) {

if (s1List.contains(s)) {
isSubset = true;
}
else {
isSubset = false;
break;
}
}
System.out.println("Is S2 Subset of S1: "+isSubset);

// Finding if S2 is a subset of S1
isSubset = false;
for(int s: s3List) {

if (s1List.contains(s)) {
isSubset = true;
}
else {
isSubset = false;
break;
}
}
System.out.println("Is S3 Subset of S1: "+isSubset);
}

- Gayathri June 25, 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