- Write a program that find and print the longest string in astack of strings.
For example, Stack[Hello, Yes, Good Morning, Good Evening, Where is the ATM machine?,no].
The longest string is“Where is the ATM machine?”.
You are not allowedto use collections utilities or transforming it to an array to findthe maximum length. You will have to use stack to pop and compareeach of the items for the longest string. The original stack mustremain intact with the same content after the search operation.
Original Stack:
[Hello, Yes, GoodMorning, Good Evening, Where is the ATM machine?, no]
The longest stringis: “Where is the ATM machine?”
Stack contents afterthe search:
[Hello, Yes, GoodMorning, Good Evening, Where is the ATM machine?, no]
Expert Answer
Answer to Write a program that find and print the longest string in a stack of strings. For example, Stack [Hello, Yes, Good Morn…