SlidingWindow { public String minWindowOrdered(String S, String T) { char[] cs = S.toCharArray(), ct = T.toCharArray(); int[][] dp = new int[ct.length][cs.length + 1]; for (int i = 0; i < ct.length; i++) { for (int j = 0; j <= cs.length; j++) { dp[i][j] = -1; } } for (int i = 0; i < ct.length; i++) { for (int j = 1; j <= cs.length; j++) { if (ct[i] == cs[j - 1]) { if (i == 0) { dp[i][j] = j - 1; } else { dp[i][j] = dp[i - 1][j - 1]; } } else { dp[i][j] = dp[i][j - 1]; } } } int start = -1, len = Integer.MAX_VALUE; for (int i = 1; i <= cs.length; i++) { int s = dp[ct.length - 1][i]; if (s != -1 && i - s < len) { len = i - s; start = s; } } if (start == -1) { return ""; } else { return S.substring(start, start + len); } }  static int[] maxSlidingWindow(int[] nums, int k); String minWindowOrdered(String S, String T); String minWindowUnordered(String s, String t); static double[] medianSlidingWindow(int[] nums, int k);  }
@Test(dataProvider = "minSlideWindosDP") public void testMin(String S, String T, String expected) { assertEquals(new SlidingWindow().minWindowOrdered(S, T), expected); }