Skip to content

Instantly share code, notes, and snippets.

@dalinaum
Created July 3, 2023 07:09
Show Gist options
  • Save dalinaum/17e2ad088647d326ca3097e902cfc9b8 to your computer and use it in GitHub Desktop.
Save dalinaum/17e2ad088647d326ca3097e902cfc9b8 to your computer and use it in GitHub Desktop.
programmers 181923
class Solution {
public int[] solution(int[] arr, int[][] queries) {
int[] answer = new int[queries.length];
for (int i = 0; i < queries.length; i++) {
final int s = queries[i][0];
final int e = queries[i][1];
final int k = queries[i][2];
int minValue = Integer.MAX_VALUE;
for (int j = s; j <= e; j++) {
final int current = arr[j];
if (current > k) {
minValue = Math.min(minValue, current);
}
}
if (minValue != Integer.MAX_VALUE) {
answer[i] = minValue;
} else {
answer[i] = -1;
}
}
return answer;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment