Hack4Hack

Daily Coding Quiz: Wednesday, 4 November 2026

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

  1. Which traversal of a binary search tree visits the keys in sorted order?

    DSA · easy · 100% of players got it right

    1. Preorder
    2. Postorder
    3. Inorder
    4. Level order

    Answer: C. Inorder

    Explanation: Inorder visits left subtree, node, right subtree. In a BST every left key is smaller and every right key larger, so the output is sorted.

  2. What does feature scaling (e.g. standardisation) do?

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

    1. Removes outliers
    2. Puts features on comparable scales, such as mean 0 and standard deviation 1
    3. Adds new features
    4. Balances the classes

    Answer: B. Puts features on comparable scales, such as mean 0 and standard deviation 1

    Explanation: Distance-based models (k-NN, SVM) and gradient descent behave badly when one feature ranges 0–1 and another 0–100,000. Tree models usually don’t need it.

  3. Which algorithm is unsupervised?

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

    1. Logistic regression
    2. K-means clustering
    3. Random forest classifier
    4. Linear regression

    Answer: B. K-means clustering

    Explanation: K-means groups unlabelled points by similarity. The others learn from labelled examples.

  4. A Union-Find (disjoint set) structure is the standard helper in which algorithm?

    DSA · medium · 100% of players got it right

    1. Dijkstra’s shortest path
    2. Kruskal’s minimum spanning tree
    3. Binary search
    4. KMP string matching

    Answer: B. Kruskal’s minimum spanning tree

    Explanation: Kruskal’s adds edges in order of weight and must check quickly whether an edge joins two different components. Union-Find answers that in near O(1).

  5. How does a random forest reduce overfitting compared with a single decision tree?

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

    1. It prunes one tree very deeply
    2. It averages many trees trained on bootstrap samples with random feature subsets
    3. It uses gradient descent
    4. It removes outliers automatically

    Answer: B. It averages many trees trained on bootstrap samples with random feature subsets

    Explanation: Bagging plus feature randomness makes the trees less correlated, so averaging them cuts variance a lot without raising bias much.

  6. You scaled features using the mean and standard deviation of the whole dataset, then split it into train and test. What went wrong?

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

    1. Nothing
    2. Data leakage: test-set statistics influenced training
    3. Underfitting
    4. The features are now categorical

    Answer: B. Data leakage: test-set statistics influenced training

    Explanation: Fit preprocessing on the training split only, then apply it to the test split (a scikit-learn Pipeline does this for you, including inside cross-validation).

  7. On a dataset where 99% of transactions are not fraud, why is accuracy a poor metric?

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

    1. Accuracy can’t be computed on imbalanced data
    2. A model that always predicts “not fraud” scores 99% while catching no fraud
    3. Accuracy is only for regression
    4. It overweights the minority class

    Answer: B. A model that always predicts “not fraud” scores 99% while catching no fraud

    Explanation: Use precision, recall, F1, PR-AUC or a cost-based metric that reflects missing the rare class.

  8. What is the amortised time per append to a dynamic array that doubles its capacity when full?

    DSA · hard · 100% of players got it right

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

    Answer: A. O(1)

    Explanation: Copying happens at sizes 1, 2, 4, …, n, totalling under 2n copies for n appends, so each append costs O(1) amortised, though a single append can be O(n).

  9. What does the kernel trick in an SVM let you do?

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

    1. Train without labels
    2. Fit a linear separator in a high-dimensional feature space using only dot products, without computing that space explicitly
    3. Avoid choosing a regularisation constant
    4. Turn an SVM into a decision tree

    Answer: B. Fit a linear separator in a high-dimensional feature space using only dot products, without computing that space explicitly

    Explanation: Replacing x·z with K(x, z), e.g. an RBF kernel, is equivalent to working in a much larger (even infinite) space. This gives non-linear boundaries at the cost of a kernel matrix.

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

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

    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.

Top 10

  1. Tushar: 227 points (10/10)

Play the next Daily Quiz at 4 PM IST