Queries with Fixed Length

  • + 0 comments
    public static List<Integer> solve(List<Integer> arr, List<Integer> queries) {
            // Write your code here
            int i, j, n = arr.size();
            List <Integer> result = new ArrayList<>();
            for (Integer query : queries) {
                List <Integer> max = new ArrayList<>();
                for (i = 0; i <= n - query; i++) {
                    max.add(Collections.max(arr.subList(i, i+query)));
                }
                result.add(Collections.min(max));
            }
            return result;
        }