Amazon Interview Question for Quality Assurance Engineers


Team: QAE 1
Country: India
Interview Type: In-Person




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

package com.amazon.techinterview;

public class OddStar {

public static void main (String args[]){
int n = 7;
for (int i=1; i<=n; i=i+2){
for (int j=1; j<=i; j++){
System.out.print("*");
}
System.out.print("\n");
}
for (int i=n-2; i>=1; i=i-2){
for (int j=1; j<=i; j++){
System.out.print("*");
}
System.out.print("\n");
}
}
}

- Nilanjan Sil February 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

package com.dev;

public class Recursion_dots {

/**
* @param args
*/
public static void design(int num) {
for (int i = 0; i < num; i++) {
System.out.print("*");
}
System.out.println("");
}

public static void main(String[] args) {
// TODO Auto-generated method stub
int num = 7;
for (int j = 0; j < num; j++) {
if (j % 2 != 0) {
design(j);
}
}
for (int k = num; k > 0; k--) {
if (k % 2 != 0) {
design(k);
}
}

}

}

- Mayur Patel January 02, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I don't see it following any pattern. First there are 1 3 1 stars then 1 2 4 2 1 stars. Is that the correct output?

- Satya Vijay February 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int _tmain(int argc, _TCHAR* argv[])
{
  int n=7;
  Print_Odd_Numbers(1, n);
  return 0;
}
void Print_Odd_Numbers(int start, int n)
{
  if(start < 1 || start > n)
    return;
  for(int i=1; i<=start; i++)
    cout << "*";
  cout << endl;
  Print_Odd_Numbers(start+2, n);
  if(start == n)
    return;
  for(int i=1; i<=start; i++)
    cout << "*";
  cout << endl;
}

- Anonymous February 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Try this one :

public static void printOddNumberPattern (int x){
       if(x%2 != 0){
           for(int i=0;i<x;i++){
               for(int j=0;j<x;j++){
               if((i<x/2 && i>=j) || (i>=x/2 && i<=j) ) 
                   System.out.print("*");
               }
               if(i == x/2){
                 System.out.print("*");
               }
             System.out.print("\n");
           }
       }
   
   }

- Anonymous February 13, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can you explain me the pattern you used to write this logic?

- puja July 14, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

This will give the exact solution:

public class Starprint{


public void printOddNumberPattern (int x){
    
    int d=(x+1)/2;
    
       if(x%2 != 0){
           for(int i=1;i<=x;i++){
               for(int j=1;j<=x;j++){
            if((i<d && i>=j) || (i>d && i<=j) ) 
                   System.out.print("*");
               }
               if(i == (x+1)/2){
                for (int k=0;k<x;k++)  
                 System.out.print("*");
               }
             System.out.print("\n");
           }
       }
       
   
   }

     public static void main(String []args){
             Starprint sp= new Starprint();
            sp.printOddNumberPattern(7);
     }
}

- gsksandy April 24, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void display(int count){
		int mid = (count + 1)/2;
		for(int i=0;i<mid;i++){
			double currLevel = Math.pow(2, i);
			for(int j=0;j<currLevel;j++){
				System.out.print('*');
			}
			System.out.println();
		}
		for(int i=mid-2;i>=0;i--){
			double currLevel = Math.pow(2, i);
			for(int j=0;j<currLevel;j++){
				System.out.print('*');
			}
			System.out.println();
		}
	}

- Mihir Patel February 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void display(int count){
		int mid = (count + 1)/2;
		for(int i=0;i<mid;i++){
			double currLevel = Math.pow(2, i);
			for(int j=0;j<currLevel;j++){
				System.out.print('*');
			}
			System.out.println();
		}
		for(int i=mid-2;i>=0;i--){
			double currLevel = Math.pow(2, i);
			for(int j=0;j<currLevel;j++){
				System.out.print('*');
			}
			System.out.println();
		}
	}

- Mihir Patel February 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote
{{{ public static void display(int count){ int mid = (count + 1)/2; for(int i=0;i<mid;i++){ double currLevel = Math.pow(2, i); for(int j=0;j<currLevel;j++){ System.out.print('*'); } System.out.println(); } for(int i=mid-2;i>=0;i--){ double currLevel = Math.pow(2, i); for(int j=0;j<currLevel;j++){ System.out.print('*'); } System.out.println(); } } - Mihir Patel February 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void shiningStar(int n, int mx)
{
	cout << setw(n) << setfill('*') << "" << endl;
	if ( n == mx ) return;
	shiningStar(n+2,mx);
	cout << setw(n) << setfill('*') << "" << endl;

}

- SuYo February 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def printStars(n):
  if n % 2 == 1:
    s = 1
    for i in range(n):
      sb = ""
      for _ in range(s): sb+="*" 
      print sb
      if i < (n / 2):
        s += 1
      else: s-=1
  else:
    print "Supply an odd number!"

- amshali February 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void printStars(int n) {
		if (n % 2 == 0) {
			System.out.println("Odd number only");
			return;
		} else {
			int i;
			for (i = 0; i < n; i++) {
				if (i > n / 2) {
					printStar((n - i) * 2 - 1);
				} else {
					printStar(i * 2 + 1);
				}
			}
		}
	}

	public static void printStar(int n) {
		int i = 0;
		while (i < n) {
			System.out.print("* ");
			i++;
		}
		System.out.println();
	}

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

Simple code here

int a=3,i=1,j=1,k=1;
String ans="";

while(i<=a)
{
while(k<=j)
{
ans=ans+"* ";
k++;
}
ans=ans+"\n";

if(i<((a+1)/2))
{
j=j+2;
}
else j=j-2;

k=1;
i++;
}

System.out.println(ans);

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

#include <stdio.h>
#include <conio.h>

int main()
{

int num, i,j,k,m;

printf("Enter the number : ");
scanf("%d",&num);

if(num%2!=0)
{
	for (m=0;m<2;m++)
	{
		if(m==0)
		{
			for(i=0;i<num;)
			{
				for(j=0;j<=i;j++)
				{
					printf("*");
				}
				printf("\n");

				i=i+2;
			}
		}else if(m==1){
			for(i=num-3;i>=0;)
			{
				for(j=0;j<=i;j++)
					printf("*");
			       printf("\n");
			       i=i-2;

			}

		}


	}
}else
	printf("\nEntered number is not odd\n");

getch();
clrscr();
return 0;
}

- abhi.20dec September 26, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This is one of the solution:

public class Starprint{


public void printOddNumberPattern (int x){
    
    int d=(x+1)/2;
    
       if(x%2 != 0){
           for(int i=1;i<=x;i++){
               for(int j=1;j<=x;j++){
            if((i<d && i>=j) || (i>d && i<=j) ) 
                   System.out.print("*");
               }
               if(i == (x+1)/2){
                for (int k=0;k<x;k++)  
                 System.out.print("*");
               }
             System.out.print("\n");
           }
       }
       
   
   }

     public static void main(String []args){
             Starprint sp= new Starprint();
            sp.printOddNumberPattern(7);
     }
}

- gsksandy April 24, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

n=7
middle = Round(n/2,0)


pstr = ""
For i = 0 to middle
 str = ""
 For j = 1 to i 
  str = str & "*"
  If j = middle then
    str = str & "*"	
  End If	
 Next
 pstr = pstr & str & Chr(10)
Next

For i = middle-1 to 0 step -1
 str = ""
 For j = i to 1 step -1
  str = str & "*"
 Next
 pstr = pstr & str & Chr(10)
Next

msgbox pstr

- swapnil July 24, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

n=7
middle = Round(n/2,0)


pstr = ""
For i = 0 to middle
 str = ""
 For j = 1 to i 
  str = str & "*"
  If j = middle then
    str = str & "*"	
  End If	
 Next
 pstr = pstr & str & Chr(10)
Next

For i = middle-1 to 0 step -1
 str = ""
 For j = i to 1 step -1
  str = str & "*"
 Next
 pstr = pstr & str & Chr(10)
Next

msgbox pstr

- swapnil July 24, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

n=7
middle = Round(n/2,0)


pstr = ""
For i = 0 to middle
 str = ""
 For j = 1 to i 
  str = str & "*"
  If j = middle then
    str = str & "*"	
  End If	
 Next
 pstr = pstr & str & Chr(10)
Next

For i = middle-1 to 0 step -1
 str = ""
 For j = i to 1 step -1
  str = str & "*"
 Next
 pstr = pstr & str & Chr(10)
Next

msgbox pstr

- swapnil July 24, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class PrintAstriek {

public static void printAst(int i) {

for(int j=1;j<=i;j=j+2){
for(int k=1;k<=j;k++) System.out.print("*");
System.out.println();
}
for(int x=i-2;x>=1;x=x-2){
for(int y=1;y<=x;y++) System.out.print("*");
System.out.println();
}

}

public static void main(String[] args) {

for (int i=1;i<=7;i=i+2) {
printAst(i);
}
}

}

- vivek.sit September 01, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>
#include <string.h>

void main()
{
int n[10] ={ 0,0,0,0,0,0,0,0,0,1};
int i,temp=0,index=0;

for( i=0;i<10;i++)
{
if(n[i]==0 && n[i+1]!=0 && (i+1<10))
{

if(index==0 && n[0]==0)
{
index =0;
}
else if(index==0)
{
index =i;
}

temp= n[index];
n[index]=n[i+1];
n[i+1]=temp;
index++;



}

}


for( i=0;i<10;i++)
{
printf("%d",n[i]);
}
getch();
}

- Sanjeev October 22, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.Scanner;
public class StarPattern {

    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        for(int i=0;i<n;i++)
        {
            if(i<=n/2)
            {
            for(int j=i;j>=0;j--)
            {
                System.out.print("*");
            }
            }
            else
            {
             for(int j=n-i;j>0;j--)
            {
                System.out.print("*");
            }   
            }
            System.out.println();
        }
    }
}

- Keshav November 16, 2015 | 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