Input: N = 5, arr[] = {1, 2, 3, 4, 5}, K = 7
Output: 1
Explanation:
The given array arr[] reduces as follows:
{1, 2, 3, 4, 5} -> {2, 6, 3, 4}
{2, 6, 3, 4} -> {6, 6, 3}
{6, 6, 3} -> {2, 6}
{2, 6} -> {1}
The last element of A is 1.
Input: N = 5, arr[] = {2, 4, 7, 11, 3}, K = 12
Output: 3
Explanation:
The given array arr[] reduces as follows:
{2, 4, 7, 11, 3} -> {4, 5, 7, 11}
{4, 5, 7, 11} -> {5, 3, 7}
{5, 3, 7} -> {0, 3}
{0, 3} -> {3}
The last element of A is 3.