0% found this document useful (0 votes)
4 views2 pages

Stack Questions

The document presents four programming questions related to data structures and algorithms. The questions include checking if a linked list is a palindrome, simplifying a Unix-style file path, decoding an encoded string, and calculating trapped rainwater using a stack. Each question is accompanied by sample inputs and outputs for clarity.

Uploaded by

erankushkumar777
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Stack Questions

The document presents four programming questions related to data structures and algorithms. The questions include checking if a linked list is a palindrome, simplifying a Unix-style file path, decoding an encoded string, and calculating trapped rainwater using a stack. Each question is accompanied by sample inputs and outputs for clarity.

Uploaded by

erankushkumar777
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Stack Questions

25124ankush2020ece@[Link]
Question 1 :
Palindrome Linked List
We have a singly linked list of characters, write a function that returns true if the given list is a
palindrome, else false.

Input : A->B->C->B->A
Output : Yes It is Palindrome

Question 2 :
Simplify Path
We hava an absolute path for a file (Unix-style), simplify it. Note that absolute path always begin
with ‘/’ ( root directory ), a dot in path represent current directory and double dot represents
parent directory.

Sample Input 1 : /apnacollege/


Sample Output 1 : /apnacollege

Sample Input 1 : /a/..


Sample Output 1 : /

Question 3 :
Decode a string
We have an encoded string s and the task is to decode it. The pattern in which the strings are
encoded is as follows.

Sample Input 1 : 2[cv]


Sample Output 1 : cvcv

Sample Input 2 : 3[b2[v]]L


Sample Output 2 : bvvbvvbvv

Question 4 :
Trapping Rain Water
We have an array of N non-negative integers arr[] representing an elevation map where the
width of each bar is 1, compute how much water it is able to trap after raining.

25124ankush2020ece@[Link]
Note: We have already solved this Question using Arrays but you have to now solve this using
a Stack.

Sample Input 1 : [7 0 4 2 5 0 6 4 0 6]
Sample Output 1 : 25

You might also like