Given an array of integers A and multiple values in B which represents the indices of the array A around which left rotation of the array A needs to be performed.
Find the rotated array for each value and return the result in the from of a matrix where i’th row represents the rotated array for the i’th value in B.
Input Format
The first argument given is the integer array A.
The second argument given is the integer array B.
Output Format
Return the resultant matrix.
Constraints
1 <= length of both arrays <= 2000
-10^9 <= A[i] <= 10^9
0 <= B[i] <= 2000
public class Solution { public ArrayList<ArrayList<Integer>> solve(ArrayList<Integer> A, ArrayList<Integer> B) { ArrayList<ArrayList<Integer>> result = new ArrayList<>(); for (int i = 0; i < B.size(); i ++) { ArrayList<Integer> row = new ArrayList<>(); int pivot = B.get(i) % A.size(); row.addAll(A.subList(pivot, A.size())); row.addAll(A.subList(0, pivot)); result.add(row); } return result; } }