Hack4Hack

Daily Coding Quiz: Sunday, 15 November 2026

All 10 coding questions with answers and explanations. 0 players took part.

  1. What does this function return for f(5)?

    DSA · easy

    def f(n):
        if n <= 1:
            return 1
        return n * f(n - 1)
    1. 15
    2. 24
    3. 120
    4. 720

    Answer: C. 120

    Explanation: It is factorial: 5 × 4 × 3 × 2 × 1 = 120.

  2. What is printed?

    Python · easy

    print(7 // 2, 7 % 2, 7 / 2)
    1. 3 1 3.5
    2. 3.5 1 3
    3. 3 1 3
    4. 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).

  3. Which data structure gives O(log n) insert and O(1) access to the maximum?

    DSA · medium

    1. Sorted array
    2. Max-heap
    3. Hash map
    4. 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.

  4. Which statements about gradient boosting (e.g. XGBoost, LightGBM) are true? (Select all that apply)

    Machine Learning · medium

    1. Trees are built one after another, each correcting the previous errors
    2. Trees are built independently in parallel like a random forest
    3. A learning rate shrinks each tree’s contribution
    4. 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.

  5. In a Transformer, why is positional information added to the token embeddings?

    AI & GenAI · medium

    1. To save memory
    2. Self-attention by itself ignores order, so position must be encoded explicitly
    3. To normalise the inputs
    4. 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.

  6. Predicted box A and ground-truth box B each have area 100 and overlap by 50. What is their IoU?

    Computer Vision · medium

    1. 0.25
    2. 0.33
    3. 0.5
    4. 0.67

    Answer: B. 0.33

    Explanation: IoU = intersection / union = 50 / (100 + 100 − 50) = 50 / 150 ≈ 0.33.

  7. The KMP string-matching algorithm runs in O(n + m) because it:

    DSA · hard

    1. Hashes every substring
    2. Never moves the text pointer backwards, using a prefix-function (failure) table
    3. Sorts the pattern first
    4. 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.

  8. 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;
    1. 31
    2. 63
    3. 30
    4. 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.

  9. PCA chooses its first principal component as the direction that:

    Machine Learning · hard

    1. Best separates the classes
    2. Has the maximum variance of the projected data (the top eigenvector of the covariance matrix)
    3. Has the minimum variance
    4. 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.

  10. Why do residual (skip) connections help train very deep networks?

    AI & GenAI · hard

    1. They reduce the number of parameters
    2. They give gradients a direct path backwards, easing vanishing gradients and letting layers learn small corrections
    3. They replace activation functions
    4. 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.

Play the next Daily Quiz at 4 PM IST