Hack4Hack

Daily Coding Quiz: Sunday, 1 November 2026

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

  1. Which sorting algorithm repeatedly swaps adjacent elements that are in the wrong order?

    DSA · easy

    1. Merge sort
    2. Quick sort
    3. Bubble sort
    4. Heap sort

    Answer: C. Bubble sort

    Explanation: Bubble sort compares neighbours and swaps them, so large values “bubble” to the end on each pass. It is O(n²).

  2. Which of these is immutable?

    Python · easy

    1. list
    2. dict
    3. set
    4. tuple

    Answer: D. tuple

    Explanation: A tuple cannot be changed after it is created, which is also why tuples (of hashable items) can be dictionary keys.

  3. Which clause filters groups after GROUP BY?

    SQL · easy

    1. WHERE
    2. HAVING
    3. ORDER BY
    4. LIMIT

    Answer: B. HAVING

    Explanation: WHERE filters rows before grouping; HAVING filters the groups, so it can use aggregates like COUNT(*) > 5.

  4. What is the space complexity of a recursive DFS on a tree of height h (ignoring the output)?

    DSA · medium

    1. O(1)
    2. O(h)
    3. O(n log n)
    4. O(2^h)

    Answer: B. O(h)

    Explanation: The call stack holds one frame per level on the current root-to-node path, so at most h + 1 frames.

  5. 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.

  6. 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.

  7. 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.

  8. What is the minimum number of comparisons any comparison-based sort needs in the worst case?

    DSA · hard

    1. Θ(n)
    2. Θ(n log n)
    3. Θ(n²)
    4. Θ(log n)

    Answer: B. Θ(n log n)

    Explanation: There are n! possible orders, and a decision tree with n! leaves has height ≥ log₂(n!) = Θ(n log n). Counting sort beats this only by not comparing.

  9. What is printed?

    Python · hard

    print(all([]), any([]), bool([[]]))
    1. True False True
    2. False False False
    3. True True True
    4. False False True

    Answer: A. True False True

    Explanation: all() of nothing is True (no element is false), any() of nothing is False. [[]] is a non-empty list, so it is truthy even though its item is empty.

  10. What does the running total return for the third row?

    SQL · hard

    SELECT d, amt, SUM(amt) OVER (ORDER BY d) AS running
    FROM sales;
    -- rows (d, amt): ('2026-01-01', 10), ('2026-01-02', 20), ('2026-01-02', 5), ('2026-01-03', 7)
    1. 30
    2. 35
    3. 5
    4. 42

    Answer: B. 35

    Explanation: With ORDER BY and no frame clause the default frame is RANGE … CURRENT ROW, which includes all peers with the same d. Both 2026-01-02 rows show 10 + 20 + 5 = 35. Use ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW for a strict row-by-row total.

Play the next Daily Quiz at 4 PM IST