Amazon Interview Question for Software Engineer / Developers






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

int main()
{
	int i = 0, n=2;
	int temp1 = 0, temp2 =0 ;	
	int A[100] ;
	
	A[0] = A[1]=1;
	
    printf("\t %d \t %d \n", A[0],A[1] );
	
	// print 100 pascal traingle rows 	
	while( n < 10 )
	{
		temp2 = 0,temp1=0 ;		
		 i = 0;
		while( i < n )
		{
	 		temp2 = A[i] ;
		 	A[i] = temp1 + temp2;			
			printf("\t %d ", A[i] );
		 	temp1 = temp2 ;
		 	i++;		 	
		 }
		 n++;
		 A[i] = temp1;
 	 	printf("\t %d ", A[i] );		 
 	 	printf("\n");
	}
}

- siva.sai.2020 March 11, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <iostream>
using namespace std;

int main() {

	int n , x, k;
	cout << "Enter pascal triangle rows needed : " ;
	cin >> n;

	for (int i= 0; i< n; i++)
	{
		for (k =0; k< n-i; k++)
		{
			cout << " ";
		}
		x = 1;
		for (k =0; k<=i; k++)
		{
			cout << x << " ";
			x = (x*(i-k))/(k+1);
		}
		cout << endl;
	}
	return 0;
}

- chandra March 04, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int[,] a = new int[6,6];
           
            for (int i = 0; i < 6; i++)
            {
                for (int j = 0; j <= i; j++)
                {
                    if (j == 0 || j == i)
                    {
                        (a[i, j]) = 1;
                        Console.Write(a[i, j]);
                    }
                    else
                    {
                        a[i, j] = a[i - 1, j - 1] + a[i - 1, j];
                        Console.Write(a[i, j]);
                    }
                    
                }
                Console.WriteLine();

                
            }

- vidya March 05, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>
#include <stdlib.h>
#include <vector>

std::vector<unsigned int>pascal(unsigned int i)
{
  if (i == 1) {
    std::vector<unsigned int>v;
    v.push_back(1);
    return v;
  }
  if (i == 2) {
    std::vector<unsigned int>v;
    v.push_back(1);
    v.push_back(1);
    return v;
  }
  std::vector<unsigned int>p = pascal(i - 1);
  std::vector<unsigned int>r;
  r.push_back(1);
  for (unsigned int j = 1; j < i - 1; j++) {
    r.push_back(p[j - 1] + p[j]);
  }
  r.push_back(1);
  return r;
}
int main(int argc, char **argv)
{
  if (argc != 2) {
    printf("usage: %s n\n", argv[0]);
    exit(1);
  }
  unsigned int n = atoi(argv[1]);
  for(unsigned int i = 1; i <= n; i++) {
    std::vector<unsigned int>v = pascal(i);
    for (unsigned int j = 0; j < i; j++) {
      printf("%d ", v[j]);
    }
    printf("\n");
  }
}

$ ./pascal-triangle 6
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1

- leeym March 07, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

c# recursive solution:
private static void printPascal(int[] a, int level, int n)
{
int n1 = a.Length + 1;
int[] result = new int[n1];
if (level < n)
{
result[0] = 0;
result[n1 - 1] = 0;
for (int i = 1; i < (n1 - 2); i++)
{
result[i] = a[i - 1] + a[i];
}
level++;
Console.WriteLine();
for (int i = 1; i < result.Length - 2; i++)
{
Console.Write("\t"+result[i]);
}
printPascal(result, level, n);

}
}

here i took a[] = {0,1,0}
and level = -1

- Anonymous March 07, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Node {
	public Node next;
	public int value;
		
	public Node(int value) {
		this.value = value;
	}
}

public void pascalTriangle(int howManyLines) {
		Node n = new Node(1);
		Node start = n;
		int count  = 0;
		while(count < howManyLines) {
			count++;
			n = start;
			int prev = 0;
			for(; n != null; n = n.next) {
				System.out.print(String.format("%5s", n.value));
				if (prev == 0) {
					prev = n.value;
				}
				else {
					int tmp = n.value;
					n.value += prev;
					prev = tmp;
				}
				if (n.next == null) { 
					n.next = new Node(1); break; 
				}
			}
			System.out.println();
		}
	}

- Claudio March 11, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Am i missing something here, why can we not just print out the powers of 11?

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

exactly... 11^5 = 161051 but here we should print 1,6,15,20,15,6,1

- swathi June 29, 2011 | Flag


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