Mettl Coding Fundamentals and Logic 3 ā Questions and Answers
Question 1: What is the output of: print(3 ** 2 % 5)?
- 4 (Correct answer)
- 1
- 9
- 3
Correct answer: 4
3**2 = 9, and 9 % 5 = 4.
Question 2: Which Boolean expression is equivalent to NOT (A OR B)?
- NOT A AND NOT B (Correct answer)
- NOT A OR NOT B
- A AND B
- NOT A OR B
Correct answer: NOT A AND NOT B
By De Morgan's Law, NOT(A OR B) = NOT A AND NOT B.
Question 3: What is the worst-case space complexity of a recursive function that calls itself n times?
- O(1)
- O(log n)
- O(n) (Correct answer)
- O(n²)
Correct answer: O(n)
Each recursive call adds a frame to the call stack, consuming O(n) space in the worst case.
Question 4: A function takes an array and reverses it in-place. What is the minimum number of swaps needed to reverse an array of length 6?
- 6
- 5
- 3 (Correct answer)
- 2
Correct answer: 3
Reversing an array of length n requires ān/2ā swaps; for n=6 that is 3.
Question 5: Which of the following is NOT a characteristic of object-oriented programming?
- Encapsulation
- Polymorphism
- Pointer arithmetic (Correct answer)
- Inheritance
Correct answer: Pointer arithmetic
Pointer arithmetic is a low-level procedural concept, not a pillar of OOP.
Question 6: What does the modulo operator (%) return for the expression -7 % 3 in most languages?
- -1 (Correct answer)
- 2
- 1
- -2
Correct answer: -1
In most languages, -7 % 3 = -1 because -7 = (-2)*3 + (-1).
Question 7: Which traversal of a binary search tree visits nodes in ascending sorted order?
- Pre-order
- Post-order
- In-order (Correct answer)
- Level-order
Correct answer: In-order
In-order traversal (left ā root ā right) of a BST visits keys in sorted ascending order.
What is the output of: print(3 ** 2 % 5)?