Amazon Interview Question for Developer Program Engineers


Country: India
Interview Type: Phone Interview




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

Its really irritating how people just paste code without explaining what they are doing

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

public static boolean nextArrangementWithRepeatsChars(char[] chars,
			char[] charsOriginal, char letter) {
		for (int i = 0; i < chars.length; i++) {
			if (chars[i] != letter
					&& !(i < chars.length - 1 && chars[i + 1] == letter)) {
				chars[i] = letter;
				while (--i >= 0) {
					chars[i] = charsOriginal[i];
				}
				return true;
			}
		}
		return false;
	}

	public static void main(String[] args) {
		int number = 12345;
		String numberStr = String.valueOf(number);
		char[] charsOriginal = numberStr.toCharArray();
		char[] chars = numberStr.toCharArray();
		do {
			System.out.println(new String(chars));
		} while (nextArrangementWithRepeatsChars(chars, charsOriginal, 'a'));
	}

- Oleg G June 14, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

String replace(String txt, int pos, char chr){
StringBuffer strBuffer = new StringBuffer();
for(int i=0; i<txt.length(); i++){
if (i != pos){
strBuffer.append(txt.charAt(i));
}else{
strBuffer.append(chr);
}
}
return strBuffer.toString();
}

List<String> all = new ArrayList<String>();
void combinations(String text, int startPos, char chr){
// base case
if(startPos >= text.length()) return;

for(int i=startPos; i<text.length(); i+=1){
// build a new string by copying the text
String newText = replace(text, i, chr);
all.add(newText);
combinations(newText, i+2, chr);
}
}

- NaN June 15, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>
#include<sstream>
#include<string>
using namespace std;
void convertNumToString(int num,string & s)
{
ostringstream strstream;
strstream<<num;
s = strstream.str();
}
void replaceAndPrint(string &str,char ch,int strLen)
{
string backUp(str);
for(int i=0;i<strLen;i++)
{
str = backUp;
for(int j = i;j<strLen;j=j +2)
{
str[j] = ch;
cout<<str<<"\t";
}
}
}
void printString(int num,char ch)
{
string str;
convertNumToString(num,str);
int strLen = str.size();
replaceAndPrint(str,ch,strLen);

}
int main()
{
printString(12345,'a');
return 0;
}

- Dexter June 18, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#!/usr/local/bin/python2.7

print "Hello World!\n";
list1=[1,2,3,4]
list2=[1,2,3,4]
i=0
j=len(list1)
def swap(i):
if list1[i]=='a':
list1[i]=list2[i]
else:
list1[i]='a'
def func(i,j):
if i==j:
return
func(i+1,j)
list3=[]
for i in range(i,j):
if list1[i-1]!='a':
swap(i)
list3.append(i)
print list1
for k in list3:
swap(k)
func(i,j)

- Aalekh Neema June 21, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String[] args)
{
char arr[] = "12345".toCharArray();
replace(arr);
}
public static void replace(char arr[])
{
for(int i=0; i< arr.length; i++)
{
rep(arr,i);
}
}

private static void rep(char arr[], int pos)
{
char t = arr[pos];
arr[pos] = 'a';
System.out.println(Arrays.toString(arr));
for(int i = pos+2 ; i< arr.length ; i++)
{
rep(arr,i);
}
arr[pos] = t;
}

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

Backtracking version.

public static void replace(char[] no, int i) {
	if(i >= no.length) {
		System.out.println(Arrays.toString(no));
		return;
	}
	
	for(int k=i; k<no.length; ++k) {
		char c = no[k];
		no[k] = 'a';
		replace(no, k+2);
		no[k] = c;
	}
}

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

code without recursion.Hope it helps

public static void main(String args[]) {
		int num =12345;
		
		SortLinkedList.replace(num);
	}
    
	public static void replace(int number) {
		int z=0;
		String s = ((Integer)number).toString();
		char [] arr = s.toCharArray();
		
		for(int i = 0; i < arr.length;  i++) {
			z=i;
			System.out.println("outer");
		    
			while(  z <= arr.length - 1){
			char c = arr[z]; 
			arr[z] = 'a';
			System.out.print(Arrays.toString(arr));
			System.out.println();
			System.out.println("heya");
			z=z+2;
			
				
			}
			arr =s.toCharArray();
		}
			
		}

- crazyMe June 24, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Sorry,SortedLinkedList is the class name.Also ignore the comments such as heya and outer......

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

#include <stdio.h>
void printa (char* a, int i, int len)
{
                char n = a [i];
                a [i] = 'a';
                printf ("%s\n",a);
                for (int j=i+2;j<len; j++)
                {
                        printa (a,j, len);
                }
                a [i] = n;

}

int main ()
{
char  arr [] = {'1', '2', '3', '4', '5', '6'};
int len = 6;
for (int i=0; i<len; i++)
printa (arr, i, 6);
return 0;
}

- Abhay June 27, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Of course the number first has to be converted to a character array are (which i have skipped).

- Abhay June 27, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <iostream>
#include <string>

using namespace std;

void generate(int index,  string& str , char aChar, char aReplaceChar)
{
    if(index < str.length())
    {
        if(str[index] == aChar && (index == 0 || str[index-1] != aReplaceChar))
        {
            str[index] = aReplaceChar;            
            generate(index + 1 , str, aChar , aReplaceChar);
            cout<<"\n"<<str;
            
            str[index] = aChar;
            generate(index + 1 , str, aChar , aReplaceChar);            
        }
        else
        {
            generate(index + 1 , str , aChar , aReplaceChar);
        }
    }
}

void generate(string& str , char aChar, char aReplaceChar)
{
    generate(0 , str , aChar , aReplaceChar);
}


int main()
{
    string str = "1211151";
    generate(str , '1' , 'A');
    
    cout<<"\n---------------------------";    
    string str1 = "123451";    
    generate(str1 , '1' , 'A');
    
    
    cout<<"\n---------------------------";
    string str2 = "121451";    
    generate(str2 , '1' , 'A');
   
    return 0;
}

- MIG July 21, 2014 | 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