Adobe Interview Question for Java Developers


Country: United States
Interview Type: In-Person




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

I'm guessing 'avoiding pallindrome' means the combinations like "ab" "ba" is not sllowed, right??

- TS July 12, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

What do you mean by 'avoiding pallindrome'? Some people post questions with the most confusing descriptions.

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

This is a typical backtracking problem. Basically to all the permutation of 5 characters.

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

If my assumption is correct, then I would handle the problem with recursive approach like

pseudo code:

public void ShowAllCombinations(string inputString, string carry, int point)
{
   if (point >= inputString.Length) return;

   for (int i = point; i < inputString.Length; i++)
   {
       string newString = carry == null or empty ? inputString[i] : carry +  inputString[i];
       // Conversion method from char to string is needed here....
       
       print(newString);

       ShowAllCombinations(inputString, newString, point + 1);
   }  
}

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

Whatever is clear from question looks like we have to print all the subset of the string.

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

I think instead of 'pallindrome,' OP meant to say 'anagram.'

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

Write a program to find palindrome. And inverse the condition. If its palindrome skip it.

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

can we design a hash function which give same hash value if palindrome are passed....
position of char need to be assigned in a different way starting from both ends upto mid point.
like no of char+for each char(ascii of char*position);
eg,

abcde;
edcba;

no of char= 5
ascii =97,98,99,100,101
position=12321

hash value for abcde=5+(97*1+98*2+99*3+100*2+101*1) = 891
hash value for abcde=5+(101*1+100*2+99*3+98*2+99*1) = 891

- sachin aggarwal August 04, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

You could do a bijective mapping to a bitset or array of 1s and zeros.
If String has n characters, there are 2^n possibilities. Write a loop from 1 to 2^n, convert each to binary and then print only those positions that are 1.

- Anonymous August 19, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

just one more way to do it.

print all the subsets one by one and while printing each subset, keep adding them in reversed format in a prefix tree. each time you add a subset, check if its already present.

if it is discard it otherwise, add print and add it to prefix tree in reversed format.

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

public List<String> combination(char[] c,int i) {
		List<String> l = new ArrayList<String>();
		l.add(String.valueOf(c[i]));
		if(i+1 < c.length){
			List<String> s = combination(c,i+1);
			l.addAll(s);
			for(String st:s){
				l.add(c[i] + st);
			}
		}
		return l;
	}

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

This is subset problem.
Generate all subsets of a given set.

s("",abcd)
				   /        \
			s(a,bcd)            s("",bcd)
			/        \                   /         \
	             s(ab,cd)       s(ab,d)      s(ac,d)    s(a,d)
                	/    \              /    \           /   \           /    \
                      abcd    abc    abd     ab     acd    ac     ad      a


C ++ CODE

 void RecSubsets(string scanned, string unscanned)
{
     if(unscanned == "")
                  cout<<scanned;
     RecSubsets(scanned+unscanned[0] , unscanned.substr(1);
     RecSubsets(scanned, unscanned.substr(1));
}

- varun July 11, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I created the Recursion tree of the program, but didn't come up nicely in the comment.

- varun July 11, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Powerset {
private String str = "abcde"; // our string
private List<String> list = new ArrayList<>();

public static void main(String[] args) {
Powerset ps = new Powerset();
for (int i = 0; i < ps.str.length(); i++) { // traverse through all
// characters
ps.subs("", i);
}
Collections.sort(ps.list);
System.out.println("List-> " + ps.list + "size-> " + ps.list.size());
}

void subs(String substr, int index) {
String s = "" + str.charAt(index); // very important, create a variable
// on each stack
s = substr + s; // append the subset so far
//System.out.println(s); // print
list.add(s);

for (int i = index + 1; i < str.length(); i++)
subs(s, i); // call recursively

}
}

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

public class Combination {

	public static void main(String[] args) {
		String str = "abcde";
		String tmp="";
		
		System.out.println("Print all combinations: ");
		for(int i=0; i<str.length(); ++i) {
			tmp += str.charAt(i);
			
			printCombiantion(tmp, str.substring(i+1, str.length()), String.valueOf(str.charAt(i)));
		}
	}
	
	public static void printCombiantion(String s, String t, String indi) {
		System.out.println(indi);
		for(int i=0; i<t.length(); i++) {
			System.out.println(s+t.charAt(i));
		}
	}

}

- anom May 31, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Let me know if its a good solution or any changes. much appreciated!!!

- anom May 31, 2015 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

public class Combinations {
public static void main(String[] args) {
String[] a = "abcde".split("");
for (int x = 0; x < a.length - 1; x++) {
for (int y = x + 1; y < a.length; y++) {
System.out.print(a[x] + a[y] + "--");
}
System.out.println();
}

}
}

- Rajesh July 12, 2012 | 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