After I have flattened int [][] into IntStream. I need to "split it back" into small 2 dimensional arrays following this algorithm:
IntSream [1,2,3,4] -> int [][] finalArr {{1,2},{2,3},{3,4}}
Basically,combining two nearest elements into array. I feel that it's possible to get over using flatMap again, but I can't figure out. Any suggestions?
codeint differentSquares(int[][] matrix) { // if(matrix[0].length<2 || matrix[1].length<2)return 0; Stream<int[]> stream = Arrays.stream(matrix); IntStream intStream = stream.filter(i->i.length>=2).flatMapToInt(x->Arrays.stream(x)); // intStream.forEach(System.out::println); return ...; }codeIntStreamconsist of a sequence of consecutive integers (such as[1, 2, 3, 4]), or could it also be any list of numbers (such as[1, 4, 3, 2])?