Stack Questions
rubyabdullah.0928@[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.
rubyabdullah.0928@[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