Problems: Task 1: Equal Stacks Code: import java.util.*; public class EqualStacks { public static void main(String[] args) { Scanner I = new Scanner(System.in); int n1 = I.nextInt(); int n2 = I.nextInt(); int n3 = I.nextInt(); int[] h1 = new int[n1]; int[] h2 = new int[n2]; int[] h3 = new int[n3]; for (int i = n1 - 1; i >= 0; i--) { h1[i] = I.nextInt(); } for (int i = n2 - 1; i >= 0; i--) { h2[i] = I.nextInt(); } for (int i = n3 - 1; i >= 0; i--) { h3[i] = I.nextInt(); } int sum1 = 0, sum2 = 0, sum3 = 0; for (int height : h1) { sum1 += height; } for (int height : h2) { sum2 += height; } for (int height : h3) { sum3 += height; } while (!(sum1 == sum2 && sum2 == sum3)) { if (sum1 >= sum2 && sum1 >= sum3) { sum1 -= h1[--n1]; } else if (sum2 >= sum1 && sum2 >= sum3) { sum2 -= h2[--n2]; } else if (sum3 >= sum1 && sum3 >= sum2) { sum3 -= h3[--n3]; } } System.out.println(sum1); } } Task 2: Game of Two Stacks Code: import java.io.*; import java.math.*; import java.security.*; import java.text.*; import java.util.*; import java.util.concurrent.*; import java.util.regex.*; class Result { public static int twoStacks(int maxSum, List a, List b) { int maxScore = 0; List cumSumA = new ArrayList<>(); cumSumA.add(0L); for (int i = 0; i < a.size(); i++) { cumSumA.add(cumSumA.get(i) + a.get(i)); } List cumSumB = new ArrayList<>(); cumSumB.add(0L); for (int i = 0; i < b.size(); i++) { cumSumB.add(cumSumB.get(i) + b.get(i)); } int j = cumSumB.size() - 1; for (int i= 0; i < cumSumA.size(); i++) { if(cumSumA.get(i) > maxSum) { break; } while (j > 0 && cumSumA.get(i) + cumSumB.get(j) > maxSum) {j--; } maxScore = Math.max(maxScore, i + j); } return maxScore; } } public class Solution { public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamRea der(System.in)); BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System .getenv("OUTPUT_PATH"))); int g = Integer.parseInt(bufferedReader.readLine().trim()); for (int gItr = 0; gItr < g; gItr++) { String[] firstMultipleInput = bufferedReader.readLine().replaceAll("\\s+$", "").split(" "); int n = Integer.parseInt(firstMultipleInput[0]); int m = Integer.parseInt(firstMultipleInput[1]); int maxSum = Integer.parseInt(firstMultipleInput[2]); String[] aTemp = bufferedReader.readLine().replaceAll("\\s+$", "").split(" "); List a = new ArrayList<>(); for (int i = 0; i < n; i++) { int aItem = Integer.parseInt(aTemp[i]); a.add(aItem); } String[] bTemp = bufferedReader.readLine().replaceAll("\\s+$", "").split(" "); List b = new ArrayList<>(); for (int i = 0; i < m; i++) { int bItem = Integer.parseInt(bTemp[i]); b.add(bItem); } int result = Result.twoStacks(maxSum, a, b); bufferedWriter.write(String.valueOf(result)); bufferedWriter.newLine(); } bufferedReader.close(); bufferedWriter.close(); } } Learning Outcomes: 1. I have learnt the concept of Stacks. 2. Understanding the concept of calculating cumulative sums. 3. Logic building is enhanced. 4. Learnt how to take input and showcase the output providing a clear result.