Skip to content

Instantly share code, notes, and snippets.

@sreeprasad
Created August 16, 2019 06:17
Show Gist options
  • Save sreeprasad/b48ae5bd3d815064c62c894a1dd3dd47 to your computer and use it in GitHub Desktop.
Save sreeprasad/b48ae5bd3d815064c62c894a1dd3dd47 to your computer and use it in GitHub Desktop.
public void takeExam(int N) throws Exception {
TestData[] array = new TestData[N];
for(int i=0;i<N;i++) {
array[i] = new TestData(input.nextInt(), input.nextInt());
}
Arrays.sort(array, (x,y) -> {
return (x.actual!=y.actual) ? (x.actual-y.actual) : (x.allowed-y.allowed);
});
int best = -1;
for(int i=0;i<N;i++) {
if (best <=array[i].allowed) {
best = array[i].allowed;
} else {
best = array[i].actual;
}
}
System.out.printf("%d\n", best);
}
class TestData {
int actual, allowed;
public TestData(int actual, int allowed) {
this.actual = actual;
this.allowed = allowed;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment