Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write in java 8 You have three stacks of cylinders where each cylinder has the same diameter, but they may vary in height. You can

write in java 8

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribedimage text in transcribed

image text in transcribedimage text in transcribed

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. Example hl = [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 hl (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. Function Description Complete the equalStacks function in the editor below. equalStacks has the following parameters: int h1 [n 1]: the first array of heights int h2[n2] the second array of heights int h33]: the third array of heights Returns int: the height of the stacks when they are equalized Input Format The first line contains three space-separated integers, nl, 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 nl 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 hi, List h2, List h3) { // Write your code here } 32 public class Solution { 33 public static void main(String[] args) throws IOException { 34 BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in); 35 BufferedWriter bufferedwriter = new BufferedWriter(new FileWriter(System.getenv ("OUTPUT_PATH"))); 36 37 String[] firstMultipleInput = bufferedReader.readLine().replaceAll("\\s+$", "").split(" "); 38 39 int nl = Integer.parseInt(firstMultipleInput[0]); 40 41 int n2 = Integer.parseInt(firstMultipleInput[1]); 42 43 int n3 = Integer.parseInt(firstMultipleInput[2]); 44 45 List hi = Stream.of(bufferedReader.readLine().replaceAll("\\s+$", "").split("")) 46 .map (Integer::parseInt) 47 .collect(tolist()); 48 List h2 = Stream.of (bufferedReader.readLine().replaceAll("\\$+$", "").split("")) .map(Integer::parseInt) .collect(tolist()); List h3 = Stream.of (bufferedReader.readLine().replaceAll("\\$+$", "").split("")) .map(Integer::parseInt) .collect(tolist(); 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 int result = Result.equalStacks (hi, h2, h3); bufferedWriter.write(String.valueof(result)); bufferedwriter.newLine(); bufferedReader.close(); bufferedwriter.close(); }<1>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

AWS Certified Database Study Guide Specialty DBS-C01 Exam

Authors: Matheus Arrais, Rene Martinez Bravet, Leonardo Ciccone, Angie Nobre Cocharero, Erika Kurauchi, Hugo Rozestraten

1st Edition

1119778956, 978-1119778950

Students also viewed these Databases questions

Question

How to solve maths problems with examples

Answered: 1 week ago

Question

How many Tables Will Base HCMSs typically have? Why?

Answered: 1 week ago

Question

What is the process of normalization?

Answered: 1 week ago