0% found this document useful (0 votes)
5 views3 pages

Stacks Questions

Uploaded by

nikhilagarwal284
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)
5 views3 pages

Stacks Questions

Uploaded by

nikhilagarwal284
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
You are on page 1/ 3

Stacks

(Assignment Questions)

Question 1 : Given the head of a singly linked list, return true if it is a


Palindrome orfalse otherwise.[Go to Qs]

Examples :
Input: head = [1,2,2,1]
Output: true

Input: head = [1,2,3]


Output: false

Note - Use a stack to solve this problem.

Question 2 : Given an encoded string, return its decoded string.

The encoding rule is: k[encoded_string], where the encoded_string inside the
square brackets is being repeated exactly k times. Note that k is guaranteed to
be a positiveinteger.

You may assume that the input string is always valid; there are no extra white
spaces, square brackets are well-formed, etc. Furthermore, you may assume
that the original data does not contain any digits and that digits are only for
those repeat numbers, k. For example, there will not be input like 3a or 2[4]. [ Go
to Qs ]

Examples :
Input: s =
"3[a]2[bc]"
Output:
"aaabcbc"

Input: s =
"2[abc]3[cd]ef"
Output:
"abcabccdcdcdef

Question 3 : We have an absolute path for a file(Unix-style), simplify it. Note


that absolute path always begins with ‘/’(rootdirectory), a dot in path
represents current directory and double dot represents parent directory.[ Go to
Qs ]

Examples :
Input: path =
"/home//foo/"Output:
"/home/foo"
Explanation: Multiple consecutive slashes are replaced by a single one.

Input: path = "/home/user/Documents/../Pictures"


Output: "/home/user/Pictures"
Explanation: A double period ".." refers to the directory up a level.

Question 4 : Given n non-negative integers representing an elevation map


where thewidth of each bar is 1, compute how much water it can trap after
raining.[ Go to Qs ]
Examples :
Input: height = [7, 0, 4, 2, 5, 0, 6, 4, 0, 5]
Output: 25

Explanation: The above elevation map (black section) is represented by


the array [7, 0, 4, 2, 5, 0, 6, 4, 0, 5]. In this case, 25 units of rain water (blue section)
are being trapped.

https://telegram.me/+QGUyTripaP4zNTcx

https://telegram.me/+nEKeBr_yhXtmY2Yx

Say Hi to TG for Further Updates:


https://t.me/RepublicDayBot

#TGSFamily

You might also like