Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static boolean almostIncreasingSequence(int[] arr) {
- for (int i = 0; i < arr.length; i++) {
- if (isArrayIncreasing(arr, i))
- return true;
- }
- return false;
- }
- private static boolean isArrayIncreasing(int[] arr, int skipIndex) {
- final int[] max = {Integer.MIN_VALUE};
- return Stream.concat(
- Arrays.stream(arr, 0, skipIndex).boxed(),
- Arrays.stream(arr, skipIndex + 1, arr.length).boxed()
- ).allMatch(n -> {
- boolean res = n > max[0];
- max[0] = n;
- return res;
- });
Advertisement
Add Comment
Please, Sign In to add comment