Coding Fundamentals and Logic Flashcards
7 cards from real Mettl practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.
Read the first 7 Coding Fundamentals and Logic flashcards as text
Which of the following correctly defines recursion?
Answer: A function that calls itself to solve a smaller instance
Recursion is when a function calls itself with a smaller input, converging toward a base case.
What is the result of the bitwise AND operation: 12 & 10?
Answer: 8
12 = 1100₂ and 10 = 1010₂; AND gives 1000₂ = 8.
A stack currently holds [1, 2, 3] (3 is on top). After pop(), push(4), pop(), what is on top?
Answer: 2
pop() removes 3 → stack [1,2]; push(4) → [1,2,4]; pop() removes 4 → top is 2.
Which of the following is a valid reason to use a queue over a stack?
Answer: Print job scheduling
Print job scheduling uses FIFO ordering — the first job submitted is the first printed.
What is the output of this code snippet? def mystery(n): return n * (n + 1) // 2 print(mystery(4))
Answer: 10
mystery(4) = 4 * 5 // 2 = 20 // 2 = 10, the sum of integers 1 through 4.
Which of the following statements about immutable objects is correct?
Answer: Their state cannot be modified after creation
Immutable objects have a fixed state that cannot be altered after they are created.
What does short-circuit evaluation mean in logical expressions?
Answer: Evaluation stops as soon as the result is determined
Short-circuit evaluation stops at the first operand that determines the outcome, e.g., False AND X skips X.