Created
July 3, 2023 07:09
-
-
Save dalinaum/17e2ad088647d326ca3097e902cfc9b8 to your computer and use it in GitHub Desktop.
programmers 181923
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
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