• + 0 comments

    Java Streams with better efficiency:

      
    Deque<Integer> deque = new ArrayDeque<>(a);
    
    IntStream.rangeClosed(1, k).forEach(value -> {
        Integer last = deque.pollLast();
        deque.addFirst(last);
    });
    
    List<Integer> dequeList = new ArrayList<>(deque);
    
    return queries.stream()
            .map(dequeList::get)
            .collect(Collectors.toList());