Mayank has three stacks of cylinders where each cylinder has the same diameter, but they may vary in height. He can change the height of a stack by removing and discarding its topmost cylinder any number of times.
Find the maximum possible height of the stacks such that all of the stacks are exactly the same height. This means he must remove zero or more cylinders from the top of zero or more of the three stacks until they are all the same height, then return the height. Help Mayank !
Example:
h1=[1,2,1,1]
h2=[1,1,2]
h3=[1,1]
There are 4,3 and 2 cylinders in the three stacks, with their heights in the three arrays. Remove the top 2 cylinders from h1 (heights = [1, 2]) and from h2 (heights = [1, 1]) so that the three stacks all are 2 units tall. Return 2
as the answer.
Note: An empty stack is still a stack
Input Format
The first line contains three space-separated integers,n1,n2 , and n3, the numbers of cylinders in stacks 1 ,2 , and
3.
The subsequent lines describe the respective heights of each cylinder in a stack from top to bottom:
-> The second line contains n1 space-separated integers, the cylinder heights in stack 1. The first element is the top cylinder of the stack.
->The third line contains n2 space-separated integers, the cylinder heights in stack 2. The first element is the top cylinder of the stack.
->The fourth line contains n3 space-separated integers, the cylinder heights in stack 3. The first element is the top cylinder of the stack.
Constraints:
0 < n1,n2,n3<=10^5
0 < Height of any cylinder <= 100