Hack4Hack

Daily Coding Quiz: Monday, 16 November 2026

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

  1. Which data structure does breadth-first search (BFS) use to decide which node to visit next?

    DSA · easy

    1. Stack
    2. Queue
    3. Priority queue
    4. Hash set

    Answer: B. Queue

    Explanation: BFS explores level by level: nodes are visited in the order they were discovered, which is exactly a FIFO queue. DFS uses a stack (or recursion).

  2. What is printed?

    Python · easy

    nums = [1, 2, 3, 4, 5]
    print(nums[1:4])
    1. [1, 2, 3, 4]
    2. [2, 3, 4]
    3. [2, 3, 4, 5]
    4. [1, 2, 3]

    Answer: B. [2, 3, 4]

    Explanation: Slices include the start index and exclude the end: indexes 1, 2 and 3.

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

  4. Kadane’s algorithm finds:

    DSA · medium

    1. The longest increasing subsequence
    2. The maximum sum of a contiguous subarray
    3. The shortest path in a DAG
    4. The k-th smallest element

    Answer: B. The maximum sum of a contiguous subarray

    Explanation: Track the best sum ending at each index: max(x, best_ending_here + x). The best of those is the answer, in one O(n) pass.

  5. What is printed?

    Python · medium

    a = [[0] * 2] * 2
    a[0][0] = 1
    print(a)
    1. [[1, 0], [0, 0]]
    2. [[1, 0], [1, 0]]
    3. [[1, 1], [0, 0]]
    4. An error

    Answer: B. [[1, 0], [1, 0]]

    Explanation: * 2 on the outer list copies the reference, so both rows are the same list object. Use [[0] * 2 for _ in range(2)] for independent rows.

  6. What is printed?

    Python · medium

    from collections import Counter
    c = Counter("mississippi")
    print(c.most_common(2))
    1. [('i', 4), ('s', 4)]
    2. [('s', 4), ('i', 4)]
    3. [('i', 4), ('p', 2)]
    4. [('m', 1), ('i', 4)]

    Answer: A. [('i', 4), ('s', 4)]

    Explanation: i and s both appear 4 times. Ties keep the order in which elements were first seen, and i (index 1) appears before s (index 2).

  7. What is the time complexity of Dijkstra’s algorithm with a binary heap on a graph with V vertices and E edges?

    DSA · hard

    1. O(V²)
    2. O((V + E) log V)
    3. O(V + E)
    4. O(E · V)

    Answer: B. O((V + E) log V)

    Explanation: Each vertex is extracted once and each edge may push or decrease a key, each costing O(log V). With a Fibonacci heap it improves to O(E + V log V).

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

  9. What is printed?

    Python · hard

    def deco(fn):
        def wrap(*a):
            return fn(*a) * 2
        return wrap
    
    @deco
    @deco
    def three():
        return 3
    
    print(three())
    1. 6
    2. 9
    3. 12
    4. 3

    Answer: C. 12

    Explanation: Stacked decorators apply bottom-up: three = deco(deco(three)). The inner wrapper doubles 3 to 6, the outer doubles that to 12.

  10. What is printed?

    Python · hard

    x = [1, 2, 3]
    y = x[:]
    z = x
    x.append(4)
    print(len(y), len(z), y is x, z is x)
    1. 3 4 False True
    2. 4 4 False True
    3. 3 3 True True
    4. 4 4 True True

    Answer: A. 3 4 False True

    Explanation: x[:] makes a shallow copy (a new list), so y keeps 3 items. z is just another name for x.

Play the next Daily Quiz at 4 PM IST