## Adobe Interview Question for Java Developers

• 0

Country: India
Interview Type: In-Person

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

Subset sum problem.

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?

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???

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???

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

{bakwas}

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;

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

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;

}

}

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

``````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;

}

}``````

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;

}

}``````

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;
}

} }}}

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;

}

}``````

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)

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

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

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

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)

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

@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...

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

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

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

Comment hidden because of low score. Click to expand.

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.

### 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.