fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.lang.*;
  4. import java.util.*;
  5. import java.util.stream.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. int[] counting = new int[] { 1, 0, -1, -2, -1, -2, -1, 0, 1, 2, 1, 0, -1, 0, 1, 2 };
  13.  
  14. int[] zeroIndices = IntStream.range(0, counting.length)
  15. .filter(i -> counting[i] == 0)
  16. .toArray();
  17.  
  18. long count = IntStream.range(1, zeroIndices.length)
  19. .mapToObj(zixix -> Arrays.copyOfRange(counting, zeroIndices[zixix - 1] + 1, zeroIndices[zixix]))
  20. .filter(range -> Arrays.stream(range).anyMatch(c -> c < 0))
  21. .count();
  22.  
  23. System.out.println("Count: " + count);
  24. }
  25. }
Success #stdin #stdout 0.15s 2184192KB
stdin
Standard input is empty
stdout
Count: 2