Adobe Interview Question for Java Developers


Country: India
Interview Type: In-Person




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

Subset sum problem.

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

combinations of two numbers or multiple numbers? if two numbers, it can be done by n(log n). how about the case of multiple numbers then?

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

is it only two numbers or we can take any numbers for consideration for summation???

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

is it only two numbers or can we take more than two into consideration for summation???

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

{bakwas}

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

void printsubset(int a[],int size)
{ for(int i=0;i<size;i++)
cout<<a[i]<<" ";
cout<<"\n";
}
void subset(int s[],int t[],int ssize,int tsize,int sum,int ite,int const targetsum)
{ if(targetsum==sum)
{ printsubset(t,tsize);
subset(s,t,ssize,tsize-1,sum-s[ite],ite+1,targetsum);
return
}
else
{ for(int i=ite;i<ssize;i++)
{ t[tsize]=s[i];
subset(s,t,ssize,tsize+1,sum+s[i],i+1,targetsum);
}
}
}
I assumed that initially ite=0; t[] is empty, sum=0 ; tsise=0 targetsum isgiven sum;

- Mukesh Kumar Dhaker October 01, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

import java.io.IOException;

public class FindingCombination {



public static void main(String[] args) throws IOException{
int[] arr = {1,3,23,76,908,34,256,12,43,11,2,-10};
System.out.println(combination(arr,13));

}

public static String combination(int[] arr, int data){
String comb = "";
for(int i=0;i<arr.length;i++){
int temp = data - arr[i];
for(int j=0;j<arr.length;j++){
if(temp == arr[j]){
comb = comb + " ("+arr[j]+","+arr[i]+")";
}
}

}
return comb;

}

}

- Shahid Akhtar April 13, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

import java.io.IOException;

public class FindingCombination {
	
	
	
	public static void main(String[] args) throws IOException{
		int[] arr = {1,3,23,76,908,34,256,12,43,11,2,-10};
		System.out.println(combination(arr,13));
		
	}
	
	public static String combination(int[] arr, int data){
		String comb = "";
		for(int i=0;i<arr.length;i++){
			int temp = data - arr[i];
			for(int j=0;j<arr.length;j++){
				if(temp == arr[j]){
					comb = comb + " ("+arr[j]+","+arr[i]+")";
				}
			}
			
		}
		return comb;
		
	}

}

- Shahid Akhtar April 13, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.io.IOException;

public class FindingCombination {
	
	
	
	public static void main(String[] args) throws IOException{
		int[] arr = {1,3,23,76,908,34,256,12,43,11,2,-10};
		System.out.println(combination(arr,13));
		
	}
	
	public static String combination(int[] arr, int data){
		String comb = "";
		for(int i=0;i<arr.length;i++){
			int temp = data - arr[i];
			for(int j=0;j<arr.length;j++){
				if(temp == arr[j]){
					comb = comb + " ("+arr[j]+","+arr[i]+")";
				}
			}
			
		}
		return comb;
		
	}

}

- Shahid Akhtar April 13, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.io.IOException;
public class FindingCombination {
public static void main(String[] args) throws IOException{
int[] arr = {1,3,23,76,908,34,256,12,43,11,2,-10};
System.out.println(combination(arr,13));
}
public static String combination(int[] arr, int data){
String comb = "";
for(int i=0;i<arr.length;i++){
int temp = data - arr[i];
for(int j=0;j<arr.length;j++){
if(temp == arr[j]){
comb = comb + " ("+arr[j]+","+arr[i]+")";
}
}
}
return comb;
}

} }}}

- Shahid Akhtar April 13, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.io.IOException;

public class FindingCombination {
	
	
	
	public static void main(String[] args) throws IOException{
		int[] arr = {1,3,23,76,908,34,256,12,43,11,2,-10};
		System.out.println(combination(arr,13));
		
	}
	
	public static String combination(int[] arr, int data){
		String comb = "";
		for(int i=0;i<arr.length;i++){
			int temp = data - arr[i];
			for(int j=0;j<arr.length;j++){
				if(temp == arr[j]){
					comb = comb + " ("+arr[j]+","+arr[i]+")";
				}
			}
			
		}
		return comb;
		
	}

}

- Shahid Akhtar April 13, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 3 vote

It can be done as follows.
1. Sort the list in ascending order (takes O(nlgn))
2. Read the list from begining
3. For each element read search (13 - element read) value from the list.
Seaching in list takes lgn and in worst case the time complexity will be O(nlgn)

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

Can u please explain how to do this by an example?

- shani July 12, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

This way it will be O(n^2). Do this :
1) Sort- o(nlogn)(say increasing sorted)
2) int i=0, j=n-1;
3) while(i<j) if ( a[i]+a[j]==13) print i,j;
else if (a[i]+a[j] <13 ) i++ else j--;

Second approach do hash. and when inserting any new element just check if 13-element is already in hash. This will be O(n)

- Yoda July 12, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@yoda: i think ur approach is wrong, what u r checking is sum of 2 elements while as per the question it can be a sub-array... this problem is same as subarray sum problem which can be done by recursion and DP...

- fire and ice July 30, 2012 | Flag
Comment hidden because of low score. Click to expand.
-2
of 2 vote

Sort it in nLogn and then it can be found in )(n). So the total is )(nlogn).... Can we do better?I dont think so

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

Can u elaborate how will you find in O(n) , having sorted array

- shani July 12, 2012 | Flag
Comment hidden because of low score. Click to expand.


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