Pergunta de entrevista da empresa Goldman Sachs

Coderpad interview: Given an array of non negative integers, find the smallest sub array that at least equals a value x that is also passed to the function.

Resposta da entrevista

Sigiloso

11 de dez. de 2019

private static List finSubset(int[] arr, int x) { int sum = 0; List subsetList = new ArrayList(); for(int i = 0; i x){sum = 0; subsetList.clear();} if(sum == x){ return subsetList; }else if(sum > x){ //remove head while(sum > 0 && subsetList.size()>0){ int temp = subsetList.remove(0); sum-=temp; } } } return subsetList; }