Adobe Amazon Interview Question for Development Support Engineers






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

public void permutation(char[] a, int n) {
		if(n == 1){
			System.out.println(a);
			return;
		}
		
		for(int i = 0; i < n; i++){
			swap(a, i, n-1);
			permutation(a, n-1);
			swap(a, i, n-1);
		}
		
	}


	private void swap(char[] a, int i, int j) {
		char c;
		c = a[i]; a[i] = a[j]; a[j] = c;
		
	}

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

This is a really good solution but I have no idea how it works, it doesn't seem intuitive to me at all. Can somebody try to explain this in pseudo code or words?

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

void permute(char s[],int k)
{
if(i==strlen(s))
cout<<s<<endl;
else
for(int j=0;j<strlen(s);++j)
{
swap(s[k],s[j]);
permute(s,k+1);
swap(s[k],s[j]);
}
}
int main()
{
char s1[5]="hello";
permute(s1,0);
return 0;
}

- tomek May 20, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

You didn't declare "i" in permute function and your char array s1 is too short for string "hello".

- Oki May 20, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

This code does not take into consideration the second condition.

If the input string is "aaaaa" this program will give "aaaaa" 5 factorial times but actually it shoud give only once.

- Praveen May 21, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

This code does not take into consideration the second condition.

If the input string is "aaaaa" this program will give "aaaaa" 5 factorial times but actually it shoud give only once.

- Praveen May 21, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

@Tomek..The for loop should be like this .

for(int j=k;j<strlen(s);++j)

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

haha, be careful with writing strlen(s) in the for-loop's condition statement.
Some interviewers may end the interview when they see this :)

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

Hi ,

Can any one post the correct solution for given constraint in the string like in case of "aaa" it should repeat only once .once way is to check if the string contains duplicates initially , what can be another way ... please some one suggest

- Nishant July 03, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void Anagram(string in, string out)
{
int len = in.length();

if (len == 0)
std::cout<< out <<"\t";
for (int i =0; i< len; i++)
{
if ( len > (i+1) && in.at(i) == in.at(i+1) )
continue; //for dupilcate alphabet
Anagram(in.substr(0,i) + in.substr(i+1,len), out+ in.at(i) );
}
}

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

Here is what I wrote for integers -- basically same thing.

To calculate the permutation of an array of objects, foreach object in the array, add the object to the permutations of the reminder of the group recursively.

public ArrayList<ArrayList<Integer>> findPermutations(ArrayList<Integer> integers)
    {
        ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>();
        if (integers == null || integers.size() == 0)
        {
            return result;
        }
        for (int i = 0; i < integers.size(); i++)
        {
            ArrayList<Integer> subArray = new ArrayList<Integer>();
            for (int j = 0; j < integers.size(); j++)
            {
                if (!integers.get(j).equals(integers.get(i)))
                {
                    subArray.add(integers.get(j));
                }
            }
            ArrayList<ArrayList<Integer>> subResult = this.findPermutations(subArray);
            for (ArrayList<Integer> subPerm : subResult)
            {
                subPerm.add(integers.get(i));
                result.add(subPerm);
            }
            ArrayList<Integer> selfResult = new ArrayList<Integer>();
            selfResult.add(integers.get(i));
            result.add(selfResult);
        }
        return result;
    }

So for [1, 2, 3, 4] you'll get

[4, 3, 2, 1]
[3, 2, 1]
[3, 4, 2, 1]
[4, 2, 1]
[2, 1]
[4, 2, 3, 1]
[2, 3, 1]
[2, 4, 3, 1]
[4, 3, 1]
[3, 1]
[3, 2, 4, 1]
[2, 4, 1]
[2, 3, 4, 1]
[3, 4, 1]
[4, 1]
[1]
[4, 3, 1, 2]
[3, 1, 2]
[3, 4, 1, 2]
[4, 1, 2]
[1, 2]
[4, 1, 3, 2]
[1, 3, 2]
[1, 4, 3, 2]
[4, 3, 2]
[3, 2]
[3, 1, 4, 2]
[1, 4, 2]
[1, 3, 4, 2]
[3, 4, 2]
[4, 2]
[2]
[4, 2, 1, 3]
[2, 1, 3]
[2, 4, 1, 3]
[4, 1, 3]
[1, 3]
[4, 1, 2, 3]
[1, 2, 3]
[1, 4, 2, 3]
[4, 2, 3]
[2, 3]
[2, 1, 4, 3]
[1, 4, 3]
[1, 2, 4, 3]
[2, 4, 3]
[4, 3]
[3]
[3, 2, 1, 4]
[2, 1, 4]
[2, 3, 1, 4]
[3, 1, 4]
[1, 4]
[3, 1, 2, 4]
[1, 2, 4]
[1, 3, 2, 4]
[3, 2, 4]
[2, 4]
[2, 1, 3, 4]
[1, 3, 4]
[1, 2, 3, 4]
[2, 3, 4]
[3, 4]
[4]

- Ozan Eren Bilgen October 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Permutation2 {
public static void main(String[] args)
{

	char[] a = "aa".toCharArray();
	Permutation2 p = new Permutation2();
	p.permutation(a,a.length);
	
	
}
public void permutation(char[] a, int n) {
	if(n == 1){
		System.out.println(a);
		return;
	}
	boolean[] b = new boolean[256];
	for(int i = 0; i < n; i++){
		if(b[(int)a[i]])continue;
		b[(int)a[i]]=true;
		swap(a, i, n-1);
		permutation(a, n-1);
		swap(a, i, n-1);
	}
	
}
private void swap(char[] a, int i, int j) {
		char c;
		c = a[i]; a[i] = a[j]; a[j] = c;
		
	}
	
}

- vinod February 22, 2013 | 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