Created
October 1, 2017 14:10
-
-
Save IvoIvanov77/3b9f59669b80049114a1495dd74d091d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package data_representation_and_manipulation.exercises; | |
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.util.Arrays; | |
import java.util.Comparator; | |
import java.util.List; | |
import java.util.stream.Collectors; | |
public class OverlappingIntervals { | |
public static void main(String[] args) throws IOException { | |
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); | |
int n = Integer.parseInt(reader.readLine()); | |
int[][] matrix = new int[n][2]; | |
for (int i = 0; i < n ; i++) { | |
int[] array = Arrays.stream(reader.readLine().split(",\\s*")) | |
.mapToInt(Integer::valueOf) | |
.toArray(); | |
matrix[i] = array; | |
} | |
List<int[]> list = Arrays.stream(matrix).sorted(Comparator.comparingInt(arr -> arr[0])) | |
.collect(Collectors.toList()); | |
for (int i = 0; i < list.size() - 1; i++) { | |
if(list.get(i)[1] >= list.get(i + 1)[0]){ | |
System.out.println("true"); | |
return; | |
} | |
} | |
System.out.println("false"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment