LongestIncreasingSubsequence { public static int longest(int[] array) { int[] longest = IntStream.range(0, array.length).map(i -> Integer.MIN_VALUE).toArray(); int len = 0; for (int v : array) { int pos = Arrays.binarySearch(longest,0, len, v); if (pos < 0) { int insert = (-pos) - 1; if (insert >= len) { longest[len++] = v; } else { longest[insert] = v; } } } return len; }  static int longest(int[] array);  }
@Test(dataProvider = "longestIncreasingSubsequenceTestObjects") public void test(int[] testArray, int longestSubsequenceLength) { assertEquals(LongestIncreasingSubsequence.longest(testArray), longestSubsequenceLength); }