Persistent Systems Interview Question for Software Engineer / Developers


Country: India
Interview Type: Written Test




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

If i am not wrong, this question is actually sum of subsets

- ayusun September 14, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class SubSetSumProblem {
	
	public static void main(String s[]){
		
		int set[] = {3, 34, 4, 12, 5, 2};
		int sum = 9;
		System.out.println(isSum(set, 0, 5, sum));
	}
	
	public static boolean isSum(int arr[] , int fromIdx, int toIdx, int sum){
		if(fromIdx == toIdx){
			if(arr[fromIdx] == sum)
				return true;
			else
				return false;
		}
		
		boolean prob1Rslt = isSum(arr , 0 , toIdx -1 , sum - arr[toIdx]);
		boolean prob2Rslt = isSum(arr , 0 , toIdx -1 , sum );
		
		return prob1Rslt || prob2Rslt;
		
	}
}

- Anshul Zunke September 14, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I tried implementing basic approach provided in

geeksforgeeks / dynamic-programming-subset-sum-problem/

- Anshul Zunke September 14, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

class Solution {
public static int solution(int[] A, int S) {

int output=0;
int length=0;
int temp=0;
int temp1=0;
for(int i=0;i<A.length;i++){
for(int j=i+1;j<A.length;j++){
output=new Integer(A[i]) + new Integer(A[j]);
if(output==S){
length++;
temp=j-i;
if(temp>temp1){
temp1=temp;
}

}
}
}
if(length!=0){
return temp1+1;
}else{
return -1;
}
}

public static void main (String args[]){
int[]arr1={0,1,-1,1,4,-1,0};

System.out.println(" Highest Length is ="+solution(arr1,5));
}
}

- Shoumo Das January 04, 2015 | 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