PetkoTrenev

Untitled

Mar 29th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. static boolean almostIncreasingSequence(int[] arr) {
  2. for (int i = 0; i < arr.length; i++) {
  3. if (isArrayIncreasing(arr, i))
  4. return true;
  5. }
  6.  
  7. return false;
  8. }
  9.  
  10. private static boolean isArrayIncreasing(int[] arr, int skipIndex) {
  11. final int[] max = {Integer.MIN_VALUE};
  12.  
  13. return Stream.concat(
  14. Arrays.stream(arr, 0, skipIndex).boxed(),
  15. Arrays.stream(arr, skipIndex + 1, arr.length).boxed()
  16. ).allMatch(n -> {
  17. boolean res = n > max[0];
  18. max[0] = n;
  19. return res;
  20. });
Advertisement
Add Comment
Please, Sign In to add comment