is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.
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.
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.
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.
import java.util.ArrayList;
- gauravkishan June 01, 2017class Solution {
public ArrayList<ArrayList<Integer>> findSets(int[] nums, int k, int target) {
int setSize = nums.length;
int maxElement = 1 << setSize;
// 1 << 3 = 1000
// 0 1 2 3 4 5 6 7, 7 = 111
ArrayList<ArrayList<Integer>> output = new ArrayList<ArrayList<Integer>>();
for(int i = 0; i < maxElement; i++) {
ArrayList<Integer> foundSet = convertIntToSet(nums, i);
output.add(foundSet);
}
for(ArrayList<Integer> eachSet: output) {
for(Integer setElement : eachSet) {
System.out.print(setElement + " ");
}
System.out.println("");
}
ArrayList<ArrayList<Integer>> finalOut = new ArrayList<ArrayList<Integer>>();
for(ArrayList<Integer> eachSet : output) {
if(eachSet.size() != k) {
continue;
}
int sum = 0;
for(Integer setElement : eachSet) {
sum += setElement;
}
if(sum == target) {
finalOut.add(eachSet);
}
}
return finalOut;
}
//
public ArrayList<Integer> convertIntToSet(int[] num, int index) {
ArrayList<Integer> findSet = new ArrayList<Integer>();
int counter = 0;
while(index > 0) {
int indexBit = 1 & index;
if(indexBit == 1) {
findSet.add(num[counter]);
}
index = index >> 1;
counter++;
}
return findSet;
}
public static void main(String[] args) {
Solution solution = new Solution();
int[] nums = {-1,6,9,-4};
// output = 170 (-5,85,90)
// output = 170 (90,30,50)
// k = 3
// n = 10
// [2 3]
// - - -
//generate all possible subsets of size k
ArrayList<ArrayList<Integer>> output = solution.findSets(nums, 2, 5);
//solution.findSets(nums);
for(ArrayList<Integer> eachSet: output) {
for(Integer setElement : eachSet) {
System.out.print(setElement + " ");
}
System.out.println("");
}
}
}