Showing posts with label hackerrank. Show all posts
Showing posts with label hackerrank. Show all posts

Sunday, April 16, 2023

solving hackerrank Queries with Fixed Length

 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;
}
 
which is working fine but some is getting timeouts
 
now optimizations. 

playwright in junie

  { "mcpServers" : { "playwright" : { "command" : "npx" , "args" : [ ...