Hack4Hack

Daily Coding Quiz: Thursday, 29 October 2026

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

  1. A queue built on a circular array of size k: what is the time to enqueue when it is not full?

    DSA · easy · 33% of players got it right

    1. O(1)
    2. O(log k)
    3. O(k)
    4. Depends on the element

    Answer: A. O(1)

    Explanation: Write at the tail index and move it forward modulo k. Nothing shifts.

  2. Which data structure follows Last In, First Out (LIFO)?

    DSA · easy · 67% of players got it right

    1. Queue
    2. Stack
    3. Heap
    4. Linked list

    Answer: B. Stack

    Explanation: A stack pushes and pops from the same end, so the last item added is the first removed. A queue is FIFO.

  3. In a min-heap, where is the smallest element?

    DSA · easy · 67% of players got it right

    1. At a leaf
    2. At the root
    3. At the last index
    4. Anywhere

    Answer: B. At the root

    Explanation: Every parent is ≤ its children, so the minimum is always at the root (index 0 in the array form), readable in O(1).

  4. A trie (prefix tree) is best suited for:

    DSA · medium · 33% of players got it right

    1. Range sum queries
    2. Prefix search / autocomplete
    3. Shortest paths
    4. Finding the k-th largest element

    Answer: B. Prefix search / autocomplete

    Explanation: Each edge is a character, so all words with a prefix sit under one node. Finding them costs O(length of prefix) plus the output.

  5. In an adjacency list, how much memory does a graph with V vertices and E edges need?

    DSA · medium · 33% of players got it right

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

    Answer: C. O(V + E)

    Explanation: One list per vertex (V) plus one entry per edge (E, or 2E undirected). An adjacency matrix needs O(V²).

  6. Which problem is solved with the sliding-window technique in O(n)?

    DSA · medium · 33% of players got it right

    1. Longest substring without repeating characters
    2. Shortest path in a weighted graph
    3. Number of islands in a grid
    4. All subsets of a set

    Answer: A. Longest substring without repeating characters

    Explanation: Grow the window to the right and shrink it from the left whenever a character repeats; each index enters and leaves the window once.

  7. What is the time complexity of building a binary heap from n unsorted elements using bottom-up heapify?

    DSA · medium · 33% of players got it right

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

    Answer: A. O(n)

    Explanation: Most nodes are near the bottom and sift down only a short distance. Summing the work level by level gives O(n), not O(n log n).

  8. The 0/1 knapsack DP runs in O(n·W). Why is it still called “pseudo-polynomial”?

    DSA · hard · 33% of players got it right

    1. Because it uses recursion
    2. Because W is a number whose input size is only log W bits, so the time is exponential in the input length
    3. Because it only works for small n
    4. Because it gives approximate answers

    Answer: B. Because W is a number whose input size is only log W bits, so the time is exponential in the input length

    Explanation: Running time is polynomial in the value W, not in the number of bits needed to write W. Doubling the bits squares W.

  9. Which problems are NP-complete? (Select all that apply)

    DSA · hard · 33% of players got it right

    1. Boolean satisfiability (SAT)
    2. Shortest path with non-negative weights
    3. Decision version of the travelling salesman problem
    4. Sorting an array

    Answer: A. Boolean satisfiability (SAT); C. Decision version of the travelling salesman problem

    Explanation: SAT was the first problem proved NP-complete (Cook–Levin), and “is there a tour of length ≤ k?” is NP-complete. Shortest paths and sorting have polynomial algorithms.

  10. What is printed?

    DSA · hard · 33% of players got it right

    def count(grid):
        seen = set()
        def dfs(r, c):
            if (r, c) in seen or not (0 <= r < len(grid) and 0 <= c < len(grid[0])) or grid[r][c] == 0:
                return
            seen.add((r, c))
            for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                dfs(r + dr, c + dc)
        n = 0
        for r in range(len(grid)):
            for c in range(len(grid[0])):
                if grid[r][c] == 1 and (r, c) not in seen:
                    dfs(r, c)
                    n += 1
        return n
    
    print(count([[1, 1, 0, 0],
                 [0, 1, 0, 1],
                 [1, 0, 0, 1],
                 [0, 0, 1, 0]]))
    1. 3
    2. 4
    3. 5
    4. 6

    Answer: B. 4

    Explanation: Islands connect only up/down/left/right: {(0,0),(0,1),(1,1)}, {(1,3),(2,3)}, {(2,0)} and {(3,2)}: 4 islands. Diagonal cells do not join.

Top 10

  1. SREENIDHI F: 236 points (10/10)
  2. Vedant Gupta: 28 points (2/10)
  3. Atharva Tiwari: 0 points (0/10)

Play the next Daily Quiz at 4 PM IST