Based on the problem in GeeksForGeeks [here][1]. I came across a solution [here][2].↵
↵
The question is as follows↵
↵
Given an array arr[] of N integers. Do the following operation n-1 times. ↵
For every Kth operation:↵
↵
Right rotate the array clockwise by 1.↵
↵
Delete the (n-k+1)th last element.↵
↵
Now, find the element which is left at last.↵
↵
If (n-k+1)th last element doesnt exist, delete the first.↵
↵
Can someone please help me understand the solution.↵
Primarily I need help in the following block:↵
↵
if(n==1) cout<<arr[0]<<endl;↵
else if(n%2) {↵
ll ind = n-3;↵
ind = floor(ind/4);↵
ind = 3+ind;↵
cout<<arr[ind-1]<<endl;↵
} else {↵
ll ind = n-2;↵
ind = floor(ind/4);↵
ind = 2+ind;↵
cout<<arr[ind-1]<<endl;↵
}↵
↵
[1]: https://practice.geeksforgeeks.org/problems/rotate-and-delete/0↵
[2]: https://ide.geeksforgeeks.org/pkbUpmrCFi
↵
The question is as follows↵
↵
Given an array arr[] of N integers. Do the following operation n-1 times. ↵
For every Kth operation:↵
↵
Right rotate the array clockwise by 1.↵
↵
Delete the (n-k+1)th last element.↵
↵
Now, find the element which is left at last.↵
↵
If (n-k+1)th last element doesnt exist, delete the first.↵
↵
Can someone please help me understand the solution.↵
Primarily I need help in the following block:↵
↵
if(n==1) cout<<arr[0]<<endl;↵
else if(n%2) {↵
ll ind = n-3;↵
ind = floor(ind/4);↵
ind = 3+ind;↵
cout<<arr[ind-1]<<endl;↵
} else {↵
ll ind = n-2;↵
ind = floor(ind/4);↵
ind = 2+ind;↵
cout<<arr[ind-1]<<endl;↵
}↵
↵
[1]: https://practice.geeksforgeeks.org/problems/rotate-and-delete/0↵
[2]: https://ide.geeksforgeeks.org/pkbUpmrCFi