❖
1. You are given a string that consists of lower-case English letters and brackets.
Reverse the strings in each pair of matching parentheses, starting from the innermost one.
Your result should not contain any brackets.
{DSA Question: +20 Score / +10 Score (if cheated)}
i) Example 1:
Input: s = "(abcd)"
Output: "dcba"
ii) Example 2:
Input: s = "(u(love)i)"
Output: "iloveu"
Explanation: The substring "love" is reversed first, then the whole string is reversed.
iii) Example 3:
Input: s = "(ed(et(oc))el)"
Output: "leetcode"
Explanation: First, we reverse the substring "oc", then "etco", and finally, the whole
string.
Additional Testcases: (Input,Output) => ("a(bcdefghijkl(mno)p)q" , "apmnolkjihgfedcbq"),
("asda(lol)(jjk)" , "asdalolkjj”)
Constraints: only contains lower case English characters and parentheses. It is guaranteed
that all parentheses are balanced [Equal numbers of ‘(’ and ‘)’].
2. Given below is a block of Python Code. There’s an error in this code. Identify the error and
correct the code. Additional Rules:
i) For every unsuccessful run of the code, 0.5 points will be deducted.
ii) If the code runs successfully within 1 attempt, a bonus of 5 points will be rewarded.
iii) if a detailed documentation (comments) of code (inputs, what it does, output) is done, a
bonus of 10 points will be rewarded.
{Debugging Question: +20 Score / +10 Score (if cheated)}
def fifo(ref,no_of_frame):
j=0
hit,fault=0,'0'
queue={}
frame = []
for i in range(len(ref)):
if ref[i] not in frame:
hit+=1
elif j==3:
frame[queue.pop(0)]=i
fault+=1
queue.append(i)
else:
frame[j]=i
j+=1
fault+=1
queue.append(i)
return ["Hit":hit,"Fault":fault]
frame = input(' Enter the number of frames: ')
ref = [i for i in int(input(' Enter the refernce string: ')).split(' ')]
hit_fault = fifo(ref=frame,no_of_frame=ref)
print(hit_fault)
3. Create a calculator that performs addition, subtraction, division, modulus operation.
Additional Constraints:
i) Tells user ‘Incorrect Number is entered’ if character that is not a digit.
ii) Take care of all exceptions (i.e. Division by zero)
iii) Create a proper interface that includes options to perform arithmetic options and to exit
the calculator
{Program Question: +20 Score / +10 Score (if cheated)}
Sample Structure:
def add(a,b):
# code
def sub(a,b):
# code
def multiply(a,b):
# code
def division(a,b):
# code
def modulus(a,b):
# code
def interface():
#code
def not_a_number(a):
# code
interface()