Task 1 - Equal Stacks
Task 1 - Equal Stacks
Task 1 - Equal Stacks
You have three stacks of cylinders where each cylinder has the same diameter,
but they may vary in height. You 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 you 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.
Sample Input -
534
32111
432
1141
Sample Output -
5
Code -
//JAVA, 20BCS7431
import java.util.Scanner;
import java.util.Vector;
class Solution{
public static int sum(Vector<Integer>
vec) { int s=0;
for(Integer i:vec)
s+=i;
return s;
}
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int b=sc.nextInt();
int c=sc.nextInt();
Vector <Integer> vec=new Vector<Integer>();
for(int i=0;i<a;i++)
vec.add(sc.nextInt());
Vector <Integer> st=new Vector<Integer>();
for(int i=0;i<b;i++)
st.add(sc.nextInt());
int sum1=sum(vec);
int sum2=sum(st);
int sum3=sum(arr);
int min=0;
while(sum1>=0 && sum2>=0 && sum3>=0){
if(sum1>sum2 || sum1>sum3) {
sum1-=vec.elementAt(0);
vec.removeElementAt(0);
}
if(sum2>sum3 || sum2>sum1) {
sum2-=st.elementAt(0);
st.removeElementAt(0);
}
if(sum3>sum1 || sum3>sum2) {
sum3-=arr.elementAt(0);
arr.removeElementAt(0);
}
Evaluation Grid (To be created as per the SOP and Assessment guidelines
by the faculty):
Sr. No. Parameters Marks Obtained Maximum Marks
1
2
3
4