Daily Coding Quiz: Sunday, 15 November 2026
All 10 coding questions with answers and explanations. 0 players took part.
What does this function return for f(5)?
DSA · easy
def f(n): if n <= 1: return 1 return n * f(n - 1)- 15
- 24
- 120
- 720
Answer: C. 120
Explanation: It is factorial: 5 × 4 × 3 × 2 × 1 = 120.
What is printed?
Python · easy
print(7 // 2, 7 % 2, 7 / 2)- 3 1 3.5
- 3.5 1 3
- 3 1 3
- 4 1 3.5
Answer: A. 3 1 3.5
Explanation: // is floor division (3), % is the remainder (1), and / always returns a float in Python 3 (3.5).
Which data structure gives O(log n) insert and O(1) access to the maximum?
DSA · medium
- Sorted array
- Max-heap
- Hash map
- Unsorted linked list
Answer: B. Max-heap
Explanation: A max-heap keeps the maximum at the root (O(1) peek) and inserts by sifting up the tree height (O(log n)). A sorted array needs O(n) to insert.
Which statements about gradient boosting (e.g. XGBoost, LightGBM) are true? (Select all that apply)
Machine Learning · medium
- Trees are built one after another, each correcting the previous errors
- Trees are built independently in parallel like a random forest
- A learning rate shrinks each tree’s contribution
- It can overfit if you add too many trees
Answer: A. Trees are built one after another, each correcting the previous errors; C. A learning rate shrinks each tree’s contribution; D. It can overfit if you add too many trees
Explanation: Boosting is sequential: each tree fits the residual errors (gradients) of the current ensemble. Shrinkage and early stopping keep it from overfitting.
In a Transformer, why is positional information added to the token embeddings?
AI & GenAI · medium
- To save memory
- Self-attention by itself ignores order, so position must be encoded explicitly
- To normalise the inputs
- To make tokens unique
Answer: B. Self-attention by itself ignores order, so position must be encoded explicitly
Explanation: Attention treats its input as a set. Sinusoidal, learned or rotary (RoPE) position encodings tell the model where each token is.
Predicted box A and ground-truth box B each have area 100 and overlap by 50. What is their IoU?
Computer Vision · medium
- 0.25
- 0.33
- 0.5
- 0.67
Answer: B. 0.33
Explanation: IoU = intersection / union = 50 / (100 + 100 − 50) = 50 / 150 ≈ 0.33.
The KMP string-matching algorithm runs in O(n + m) because it:
DSA · hard
- Hashes every substring
- Never moves the text pointer backwards, using a prefix-function (failure) table
- Sorts the pattern first
- Uses dynamic programming over all pairs of positions
Answer: B. Never moves the text pointer backwards, using a prefix-function (failure) table
Explanation: On a mismatch KMP jumps the pattern using the longest proper prefix that is also a suffix, so each text character is examined a bounded number of times.
What does this recursive CTE return?
SQL · hard
WITH RECURSIVE n(x) AS ( SELECT 1 UNION ALL SELECT x * 2 FROM n WHERE x < 20 ) SELECT SUM(x) FROM n;- 31
- 63
- 30
- 62
Answer: B. 63
Explanation: Rows: 1, 2, 4, 8, 16, then 32 (16 < 20 still passes, producing 32; 32 stops the recursion). 1+2+4+8+16+32 = 63.
PCA chooses its first principal component as the direction that:
Machine Learning · hard
- Best separates the classes
- Has the maximum variance of the projected data (the top eigenvector of the covariance matrix)
- Has the minimum variance
- Is aligned with the first feature
Answer: B. Has the maximum variance of the projected data (the top eigenvector of the covariance matrix)
Explanation: PCA is unsupervised: it ignores labels. Separating classes is what LDA does.
Why do residual (skip) connections help train very deep networks?
AI & GenAI · hard
- They reduce the number of parameters
- They give gradients a direct path backwards, easing vanishing gradients and letting layers learn small corrections
- They replace activation functions
- They make the network convex
Answer: B. They give gradients a direct path backwards, easing vanishing gradients and letting layers learn small corrections
Explanation: With y = x + F(x), the gradient always includes an identity term. ResNets and Transformers both rely on this to go dozens or hundreds of layers deep.