Created
March 2, 2017 15:45
-
-
Save ygrenzinger/468ae1153a874cbe2cf4618cba13e186 to your computer and use it in GitHub Desktop.
Find Missing Numbers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package interview; | |
import com.google.common.collect.Sets; | |
import org.junit.Test; | |
import java.util.*; | |
import static org.assertj.core.api.Assertions.assertThat; | |
public class FindMissingNumbersTest { | |
@Test | |
public void should_find_missing_number() { | |
Integer[] numbers = {3, 1, 5, 4, 6, 10, 8}; | |
//List<Integer> missingNumbers = findMissingNumbers1(numbers, 10); | |
List<Integer> missingNumbers = findMissingNumbers2(numbers, 18, 10); | |
assertThat(missingNumbers).contains(2, 7, 9); | |
} | |
private List<Integer> findMissingNumbers1(Integer[] ints, int limitMax) { | |
Set<Integer> mySet = Sets.newHashSet(ints); | |
List<Integer> missingNumbers = new ArrayList<>(); | |
for (int i = 0; i < limitMax; i++) { | |
if (!mySet.contains(i)) { | |
missingNumbers.add(i); | |
} | |
} | |
return missingNumbers; | |
} | |
private List<Integer> findMissingNumbers2(Integer[] ints, int sum, int limitMax) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment