Amazon Interview Question for Software Engineer / Developers


Country: India
Interview Type: In-Person




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

Common Question on Combination.

Write recursive function which will limit the maximum call upto depth 3 and manipulate the string content.

- hprem991 October 28, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can you please give the code?

- Anonymous October 28, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

if there are just two letters and the length 'n', I suppose you just need to enumerate all numbers from 0 to 2^n, i.e.:
000 - ppp
001 - ppo
010 - pop
...
111 - ppp

if there more than two letter, say k, probably one needs to consider all numbers 0..k^n in radix-k system

- Anonymous October 28, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

str is the string combination, k is start from 0, n is the string length
void findComp(char* str, int k, int n){
if(k == n-1){
str[k] = 'p';
str[n] = '\0';
printf("str=%s\n", str);
str[k] = 'o';
str[n] = '\0';
printf("str=%s\n", str);
}else{
str[k] = 'p';
findComp(str, k+1, n);
str[k] = 'o';
findComp(str, k+1, n);
}
}

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

public class Main {
public static void main(String[] args) {
combinations("hello", "", 3);
}

private static void combinations(String sourceString, String accum,
int limit) {
if (sourceString == null || sourceString.length() == 0
|| "".equals(sourceString) || limit == 0) {
System.out.println(accum);
} else {
for (char ch : sourceString.toCharArray()) {
combinations(sourceString, accum + ch, limit - 1);
}
}
}
}

- pablo.barrientos October 28, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public void printString(List chars, int reqLength, int currentLength, StringBuilder stbd){

if(reqLength == currentLength)
{
	System.out.println(stbd);
	return;
}

	Iterator itr = chars.iterator();
	 while(itr.hasNext()){
		stbd.append(((Character)itr.next()).charValue());
		printString(chars, reqLength, currentLength+1, stbd);
		stbd.delete(stbd.length()-1);
	}
}

- ishantagarwal1986 October 29, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This one will be a little better than the earlier solns. because here we are not using "String" instead we are using "StringBuffer" which is mutable, hence lesser number of objects will get created, so little improvement in terms of time complexity as well as space complexity.

- ishantagarwal1986 October 29, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

void permute_chars(std::string letters, int length, std::string permutaion="")
{
	if( length == 0 )
	{
		std::cout<<permutaion<<std::endl;
		return;
	}

	for(size_t i=0; i<letters.size(); i++)
		permute_chars(letters, length-1, permutaion+letters.at(i));
	
}

- Sani October 29, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This can be done without recursion...

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

if number of letters is <=10, n<=10

char a[n],int len,int b[len]={0,0...0}
int p=n^len,i=0,cntr=0,j,iterate;
for i=0 to p-1
j=i
while j>0
b[cntr]=j%n
cntr++
j/=n
cntr=0
for iterate=0 to len
print a[b[iterate]]
print newline

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

my bad lost indentation
if number of letters is <=10, n<=10

char a[n],int len,int b[len]={0,0...0}
int p=n^len,i=0,cntr=0,j,iterate;
for i=0 to p-1
 j=i
 while j>0
  b[cntr]=j%n
  cntr++
  j/=n
 cntr=0
 for iterate=0 to len
  print a[b[iterate]]
 print newline

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

<pre lang="" line="1" title="CodeMonkey35868" class="run-this">private static void GetAllPermutations(char[] tokens, int len, ref HashSet<string> words)
{
if (len == 0)
{
return;
}

words = new HashSet<string>();
for (int i = 0; i < tokens.Length; i++)
{
words.Add("" + tokens[i].ToString());
}

HashSet<string> lastSet = words;

for(int size = 2; size <= len; size++)
{
HashSet<string> currentSet = new HashSet<string>();
foreach (var word in lastSet)
{
for (int i = 0; i < tokens.Length; i++)
{
char currentChar = tokens[i];
for (int k = 0; k <= word.Length; k++)
{
currentSet.Add(word.Insert(k, currentChar.ToString()));
}
}
}

lastSet = currentSet;
words = currentSet;
}
}</pre><pre title="CodeMonkey35868" input="yes">
</pre>

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

// 'letters' is an array of letters
List<string> GetWords(char[] letters, int length)
{
List<string> currentSet = new List<string>();
List<string> nextSet = new List<string>();
List<string> tempSet;

for (int l = 0; l < letterCount; l++)
{
currentSet.Add(string.Empty);
}

for (int x = 0; x < length; x++)
{
foreach(string item in currentSet)
{
for (int l = 0; l < letterCount; l++)
{
nextSet.Add(item + letters[l]);
}
}

currentSet.Clear();
tempSet = currentSet;
currentSet = nextSet;
nextSet = tempSet;
}

return currentSet;
}

- Laxmi Narsimha Rao Oruganti November 02, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void fun(char str[],int n,char cur[],int index)
{
  if(index==n)
  {
    cur[index]='\0';
    printf("\n%s",cur);
    return;
  }
  for(int i=0;i<strlen(str);i++)
  {
   cur[index]=str[i];
   fun(str,n,cur,index+1);

  }
}

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

#include <stdio.h>
#include <math.h>
#define LENGTH 3
#define CHARACTERS 2
void convert_to_binary(int a[],int i) {

int j = LENGTH - 1;

for (j = LENGTH - 1; j >= 0; --j) {
a[j] = i%2;
i = i/2;
if (i == 0) break;
}
}
int main() {
int last_no = (int)(pow(CHARACTERS,LENGTH)) - 1;
int i = 0, j = 0;
int a[LENGTH] = {0,};
char p[CHARACTERS] = "po";

for (i = 0; i <= last_no; ++i) {
convert_to_binary(a,i);
for (j = 0; j < LENGTH; ++j)
printf("%c",p[a[j]]);
printf(" ");
memset(a,0,sizeof(a));
}
printf("\b\n");
getchar();
}

- Chola Bhatura November 05, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <string>
#include <iostream>

using namespace std;

void allp(const string& s, int lth, string& out)
{
if (out.size() == lth)
{
cout << out << endl;
return;
}

for (int i = 0; i < s.size(); ++i)
{
out.append(1, s.at(i));
allp(s, lth, out);
out = out.substr(0, out.size() - 1);
}
}
int main()
{
string out;
allp("op", 3, out);
}

- Anonymous November 21, 2011 | 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