Hack4Hack

Daily Coding Quiz: Wednesday, 28 October 2026

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

  1. Accessing the element at index i of an array takes:

    DSA · easy · 0% of players got it right

    1. O(1)
    2. O(log n)
    3. O(i)
    4. O(n)

    Answer: A. O(1)

    Explanation: Array elements sit in contiguous memory, so the address is base + i × size: one calculation, no matter how large the array.

  2. Predicting house prices from size and location is which kind of problem?

    Machine Learning · easy · 100% of players got it right

    1. Classification
    2. Regression
    3. Clustering
    4. Dimensionality reduction

    Answer: B. Regression

    Explanation: The target is a continuous number, so it is regression. Predicting a category (spam / not spam) would be classification.

  3. A model scores 99% on training data and 62% on test data. This is most likely:

    Machine Learning · easy · 100% of players got it right

    1. Underfitting
    2. Overfitting
    3. Data leakage
    4. A perfect model

    Answer: B. Overfitting

    Explanation: A big gap between training and test performance means the model memorised the training set instead of learning patterns that generalise.

  4. What is the worst-case time complexity of quick sort?

    DSA · medium · 0% of players got it right

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

    Answer: C. O(n²)

    Explanation: If the pivot is always the smallest or largest element (e.g. first element on sorted input), partitions are n−1 and 0, giving n + (n−1) + … = O(n²).

  5. Increasing k in k-NN generally:

    Machine Learning · medium · 0% of players got it right

    1. Increases variance, decreases bias
    2. Decreases variance, increases bias (smoother boundary)
    3. Has no effect
    4. Always improves accuracy

    Answer: B. Decreases variance, increases bias (smoother boundary)

    Explanation: k = 1 follows every noisy point (high variance). Larger k averages over more neighbours, smoothing the boundary but possibly missing real detail.

  6. What does an ROC-AUC of 0.5 mean?

    Machine Learning · medium · 0% of players got it right

    1. Perfect classifier
    2. No better than random ranking
    3. 50% accuracy exactly
    4. The model is always wrong

    Answer: B. No better than random ranking

    Explanation: AUC is the chance a random positive is scored above a random negative. 0.5 is coin-flip ranking; 1.0 is perfect.

  7. A cancer test flags 100 people; 80 really have cancer. Out of 120 people who have cancer, 80 were flagged. What are precision and recall?

    Machine Learning · medium · 0% of players got it right

    1. Precision 80%, recall 66.7%
    2. Precision 66.7%, recall 80%
    3. Both 80%
    4. Precision 40%, recall 80%

    Answer: A. Precision 80%, recall 66.7%

    Explanation: Precision = TP / flagged = 80/100 = 80%. Recall = TP / actual positives = 80/120 ≈ 66.7%.

  8. What does this print?

    DSA · hard · 0% of players got it right

    from functools import lru_cache
    
    @lru_cache(None)
    def ways(n, k):
        # ways to write n as an ordered sum of parts each <= k
        if n == 0:
            return 1
        return sum(ways(n - p, k) for p in range(1, min(n, k) + 1))
    
    print(ways(4, 2))
    1. 3
    2. 4
    3. 5
    4. 8

    Answer: C. 5

    Explanation: Ordered sums of 4 using 1s and 2s: 1111, 112, 121, 211, 22 → 5. With k=2 it is the stair-climbing Fibonacci again: ways(4) = 5.

  9. The bias–variance decomposition of expected squared error is:

    Machine Learning · hard · 0% of players got it right

    1. Bias + Variance
    2. Bias² + Variance + irreducible noise
    3. Bias × Variance
    4. Variance − Bias²

    Answer: B. Bias² + Variance + irreducible noise

    Explanation: E[(y − ŷ)²] = Bias[ŷ]² + Var[ŷ] + σ². The noise term σ² is a floor no model can beat.

  10. Why does logistic regression use log-loss (cross-entropy) instead of mean squared error?

    Machine Learning · hard · 0% of players got it right

    1. MSE cannot be computed for probabilities
    2. With a sigmoid, MSE gives a non-convex loss with weak gradients, while log-loss is convex and matches maximum likelihood
    3. Log-loss is faster to compute
    4. MSE always overfits

    Answer: B. With a sigmoid, MSE gives a non-convex loss with weak gradients, while log-loss is convex and matches maximum likelihood

    Explanation: Cross-entropy is the negative log-likelihood of a Bernoulli model. Combined with a sigmoid it is convex in the weights, so gradient descent finds the global optimum.

Top 10

  1. Vaishanavi Patil: 28 points (2/10)

Play the next Daily Quiz at 4 PM IST