Hack4Hack

Daily Coding Quiz: Thursday, 5 November 2026

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

  1. Inserting a new node at the head of a singly linked list takes:

    DSA · easy

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

    Answer: A. O(1)

    Explanation: Point the new node at the current head and make it the head: a constant number of pointer updates.

  2. Which technique is the classic way to check if a string of brackets like "({[]})" is balanced?

    DSA · easy

    1. Two pointers
    2. A stack
    3. Binary search
    4. Sorting

    Answer: B. A stack

    Explanation: Push each opening bracket; on a closing bracket, the top of the stack must be its match. Balanced if the stack ends empty.

  3. What is the worst-case time complexity of linear search?

    DSA · easy

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

    Answer: C. O(n)

    Explanation: If the item is last or missing, every one of the n elements is checked.

  4. Topological sort is possible only on which kind of graph?

    DSA · medium

    1. Any undirected graph
    2. A directed acyclic graph (DAG)
    3. A complete graph
    4. A weighted graph

    Answer: B. A directed acyclic graph (DAG)

    Explanation: A topological order puts every edge u→v with u before v. A cycle makes that impossible, so the graph must be a DAG.

  5. What is the time complexity of this code?

    DSA · medium

    i = 1
    while i < n:
        i *= 2
    1. O(n)
    2. O(log n)
    3. O(√n)
    4. O(n log n)

    Answer: B. O(log n)

    Explanation: i doubles each iteration (1, 2, 4, …), so it passes n after about log₂ n iterations.

  6. Which array is a valid min-heap (array form, children of i at 2i+1 and 2i+2)?

    DSA · medium

    1. [1, 3, 2, 7, 4, 5]
    2. [1, 5, 2, 3, 6, 4]
    3. [2, 1, 3, 4, 5, 6]
    4. [1, 3, 2, 7, 4, 1]

    Answer: A. [1, 3, 2, 7, 4, 5]

    Explanation: In [1,3,2,7,4,5] every parent is ≤ its children (1≤3,2; 3≤7,4; 2≤5). In the second, 5 > 3; in the third, 2 > 1; in the fourth, 2 > 1 at index 5.

  7. What is printed?

    DSA · medium

    from collections import deque
    q = deque([1, 2, 3])
    q.append(4)
    q.popleft()
    q.appendleft(0)
    print(list(q))
    1. [0, 2, 3, 4]
    2. [0, 1, 2, 3]
    3. [2, 3, 4, 0]
    4. [1, 2, 3, 4]

    Answer: A. [0, 2, 3, 4]

    Explanation: append(4) → [1,2,3,4]; popleft() removes 1 → [2,3,4]; appendleft(0) → [0,2,3,4].

  8. A segment tree over n elements supports range-sum queries and point updates in:

    DSA · hard

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

    Answer: B. O(log n) each

    Explanation: The tree has height O(log n). A query combines O(log n) nodes, and an update changes one leaf and its O(log n) ancestors.

  9. What is printed?

    DSA · hard

    def lis(a):
        import bisect
        tails = []
        for x in a:
            i = bisect.bisect_left(tails, x)
            if i == len(tails):
                tails.append(x)
            else:
                tails[i] = x
        return len(tails)
    
    print(lis([10, 9, 2, 5, 3, 7, 101, 18]))
    1. 3
    2. 4
    3. 5
    4. 8

    Answer: B. 4

    Explanation: This is the O(n log n) Longest Increasing Subsequence. One LIS is 2, 3, 7, 18 (or 2, 5, 7, 101), length 4.

  10. Which algorithm can find shortest paths when some edge weights are negative (but there is no negative cycle), and also detect a negative cycle?

    DSA · hard

    1. Dijkstra’s
    2. Bellman–Ford
    3. Prim’s
    4. BFS

    Answer: B. Bellman–Ford

    Explanation: Bellman–Ford relaxes every edge V−1 times. If a V-th pass still improves a distance, there is a negative cycle. Dijkstra’s can give wrong answers with negative edges.

Play the next Daily Quiz at 4 PM IST