Coding Test Week 2
Date: 16 – 10 - 2025
Part A – MCQs (3 * 2 = 6 marks)
Q1. What is the Big O time complexity for solving the classic Tower of Hanoi puzzle
with n disks?
A) O(n2)
B) O(nlogn)
C) O(2n)
D) O(n!)
Q2. In Python, consider the following code. What will be the final value of B?
Python
A = [1, 2, 3]
B =A
[Link](4)
A = [5, 6, 7]
print(B)
A) [1, 2, 3]
B) [1, 2, 3, 4]
C) [5, 6, 7]
D) [5, 6, 7, 4]
Q3. What is the worst-case time complexity for the search operation in an array-based
Hash Table (using separate chaining) that stores n elements?
A) O(1)
B) O(logn)
C) O(n)
D) O(n2)
Part B – Coding (2 * 9.5 = 19 marks)
Q4. Maximum Subarray Sum
Write a program that takes a list of integers (which can include negative numbers) and
finds the contiguous subarray within it that has the largest sum, and then prints that
sum. Your solution should run in O(n) time complexity.
Example Input:
-2 1 -3 4 -1 2 1 -5 4
Expected Output:
6 (The subarray [4, -1, 2, 1] sums to 6)
Q5. Valid Parentheses
Write a program that takes a string containing only the characters (, ), {, }, [ and ] as
input. Determine if the input string is valid. A string is valid if:
1. Open brackets must be closed by the same type of brackets.
2. Open brackets must be closed in the correct order.
Example Input 1:
([]{})
Expected Output 1:
Valid
Example Input 2:
([)]
Expected Output 2:
Invalid