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

public class Prob1 {
    public static void main(String[] args) {
        int[] s= {1,1,0,0,1,3,4};
//     /**/   int[] s = {/*1,1,1,*/0,0,3,4};
        int i=0;
        boolean isOneStart = false;
        boolean isOneEnd = false;
        boolean isConsec = true;
        while(i<s.length){

            if(isOneStart==false && s[i]==1){
                isOneStart = true;
            }

            else if(isOneStart==true && isOneEnd==false && s[i]!=1){
                isOneEnd = true;
            }

            else if(isOneEnd== true && s[i]==1){
                isConsec = false;
                break;
            }

            i++;
        }

        if(isOneStart==false){
            System.out.println("Array doesnt have any Ones");
        } else {
            if (isConsec) {
                System.out.println("It is consecutive");
            } else {
                System.out.println("It is not consecutive");
            }
        }
    }
}

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

public class Prob1 {
    public static void main(String[] args) {
        int[] s= {1,1,0,0,1,3,4};
        int i=0;
        boolean isOneStart = false;
        boolean isOneEnd = false;
        boolean isConsec = true;
        while(i<s.length){

            if(isOneStart==false && s[i]==1){
                isOneStart = true;
            }

            else if(isOneStart==true && isOneEnd==false && s[i]!=1){
                isOneEnd = true;
            }

            else if(isOneEnd== true && s[i]==1){
                isConsec = false;
                break;
            }

            i++;
        }

        if(isOneStart==false){
            System.out.println("Array doesnt have any Ones");
        } else {
            if (isConsec) {
                System.out.println("It is consecutive");
            } else {
                System.out.println("It is not consecutive");
            }
        }
    }
}

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

bool ChecKConsecutive(int[] a, int key )
{
int len = a.Length;
if(len ==0)
return false;
if(len==1)
return true;
int lastIndex = -1;
for(int i=0;i<len;i++)
{
if(a[i] == key)
{
if(lastIndex != -1 && lastIndex +1 !=i)
{
return false;
}
lastIndex = i;
}
continue;
}
return true;

}

- Raj Mandaala May 30, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

private bool CheckConsecutive(int[] a, int key)
	{
		int len  = a.Length;
		if(len ==0)
		return false;
		if(len == 1 && a[0] == key)
		return true;

		int lastIndex =-1;
		
		for (int i =0 ;i < len;i++)
		{
			if(a[i] == k)
			{
				if(lastIndex  != -1 &&  lastIndex  +1 == i)
				{
					return false;
				}
				lastIndex = i;
			}
			continue;
		}	
	}

- Raj Mandaala May 30, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

One of the clear implementations of the above problem is that you must count the total number of given key elements in the array and then count the number of the key elements which is present consecutively in the array, if the next element is not the key element then, simply make a counter variable 0, and at last if the value of the counter variable equals the total count then, return true else return false.

Implementation of the above code:

#include<bits/stdc++.h>
using namespace std;
bool checknumbers(int arr[], int key, int n){
int count = 0;
for(int i = 0; i < n; i++){
if(arr[i] == key)
count++;
}
int temp = 1;
for(int i = 0; (i + 1) < n; i++){
if(arr[i] == key && arr[i + 1] == key){
temp++;
if(temp == count)
return true;
}
else
temp = 1;
}
return false;
}
int main(){
int arr[] = {1, 1, 0, 1, 1, 1, 1};
cout<<checknumbers(arr, 1, 7)<<endl;
}

For example, the above code will return false because there are a total of 6 one's but all are not consecutive.

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

public static boolean checkConsecutive(int[] array, int key) {

if (array.length == 0) {
return false;
}
if (array.length == 1 && array[0] == key)
return true;
if (array.length > 1 && array[0] == key && array[1] != key)
return false;
for (int i = 1; i < array.length; i++ ){
if (array[i] == key) {
if (i + 1 >= array.length && array[i - 1] != key) {
return false;
}
if (array[i + 1] != key && array[i - 1] != key)
return false;
}
}
return true;
}

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

public static boolean checkConsecutive(int[] array, int key) {

        if (array.length == 0) {
            return false;
        }
        if (array.length == 1 && array[0] == key)
            return true;
        if (array.length > 1 && array[0] == key && array[1] != key)
            return false;
        for (int i = 1; i < array.length; i++ ){
            if (array[i] == key) {
                if (i + 1 >= array.length && array[i - 1] != key) {
                    return false;
                }
                if (array[i + 1] != key && array[i - 1] != key)
                    return false;
            }
        }
        return true;

}

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

public static boolean checkConsecutive(int[] array, int key) {
if (array.length == 0) {
return false;
}
if (array.length == 1 && array[0] == key)
return true;
if (array.length > 1 && array[0] == key && array[1] != key)
return false;
for (int i = 1; i < array.length; i++ ){
if (array[i] == key) {
if (i + 1 >= array.length && array[i - 1] != key) {
return false;
}
if (array[i + 1] != key && array[i - 1] != key)
return false;
}
}
return true;
}

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

#include<stdio.h>


int ConsecutiveNumberInArray(int arr[10])
{
	int i,j,k;
	int count = 0;
	int trac = 0;
	int num;
	int arr_val;
	int index_chk = 0;
	
	printf("Enter the array elements: ");
	for(i=0; i<7; i++)
	{
		scanf("%d", &arr_val);
		arr[i] = arr_val;
	}
	
	printf("The array is: ");
	for(j=0; j<7; j++)
	{
		printf("%d  ", arr[j]);
	}
	
	printf("\n\nEnter the number to searched for consecutively: ");
	scanf("%d", &num);
	
	for(k=0; k<7; k++)
	{
		if((num == arr[k]) && (k == trac))
		{
			count++;
			++trac;
			printf("count = %d and trac = %d\n", count , trac);
			if(count ==3)
				break;
		}
		else
		{
			count = 0;
			trac++;
		}
	}
	if(count == 3)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}
int main()
{
	int result;
	int array[10];
	
	result = ConsecutiveNumberInArray(array);
	
	if(result == 1)
	{
		printf("Searched number appeared consecutively\n");
	}
	else
	{
		if(result == 0)
		{
			printf("Searched number does not appeared consucutively\n");
		}
	}
}

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

#include<stdio.h>


int ConsecutiveNumberInArray(int arr[10])
{
	int i,j,k;
	int count = 0;
	int trac = 0;
	int num;
	int arr_val;
	int index_chk = 0;
	
	printf("Enter the array elements: ");
	for(i=0; i<7; i++)
	{
		scanf("%d", &arr_val);
		arr[i] = arr_val;
	}
	
	printf("The array is: ");
	for(j=0; j<7; j++)
	{
		printf("%d  ", arr[j]);
	}
	
	printf("\n\nEnter the number to searched for consecutively: ");
	scanf("%d", &num);
	
	for(k=0; k<7; k++)
	{
		if((num == arr[k]) && (k == trac))
		{
			count++;
			++trac;
			printf("count = %d and trac = %d\n", count , trac);
			if(count ==3)
				break;
		}
		else
		{
			count = 0;
			trac++;
		}
	}
	if(count == 3)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}
int main()
{
	int result;
	int array[10];
	
	result = ConsecutiveNumberInArray(array);
	
	if(result == 1)
	{
		printf("Searched number appeared consecutively\n");
	}
	else
	{
		if(result == 0)
		{
			printf("Searched number does not appeared consucutively\n");
		}
	}

}

- Anonymous June 13, 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