first solution is
public static List<Integer> solve(List<Integer> arr, List<Integer> queries) {
List result = new ArrayList();
queries.forEach(k -> {
List<List<Integer>> partitionedList = new ArrayList<>();
for (int s = 0; s <= arr.size() - k; s++) {
partitionedList.add(arr.subList(s, s+k));
}
List<Integer> maxes = partitionedList.stream().map(m -> Collections.max(m)).collect(toList());
result.add(Collections.min(maxes));
});
return result;
}
List result = new ArrayList();
queries.forEach(k -> {
List<List<Integer>> partitionedList = new ArrayList<>();
for (int s = 0; s <= arr.size() - k; s++) {
partitionedList.add(arr.subList(s, s+k));
}
List<Integer> maxes = partitionedList.stream().map(m -> Collections.max(m)).collect(toList());
result.add(Collections.min(maxes));
});
return result;
}
which is working fine but some is getting timeouts
now optimizations.
No comments:
Post a Comment