Hack4Hack

Daily Coding Quiz: Monday, 26 October 2026

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

  1. What is the time complexity of binary search on a sorted array of n elements?

    DSA · easy

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

    Answer: B. O(log n)

    Explanation: Each comparison halves the remaining range, so at most about log₂ n steps are needed.

  2. What is printed?

    Python · easy

    print(7 // 2, 7 % 2, 7 / 2)
    1. 3 1 3.5
    2. 3.5 1 3
    3. 3 1 3
    4. 4 1 3.5

    Answer: A. 3 1 3.5

    Explanation: // is floor division (3), % is the remainder (1), and / always returns a float in Python 3 (3.5).

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

  4. How many distinct ways are there to climb 5 stairs taking 1 or 2 steps at a time?

    DSA · medium

    1. 5
    2. 8
    3. 10
    4. 13

    Answer: B. 8

    Explanation: ways(n) = ways(n−1) + ways(n−2) with ways(1)=1, ways(2)=2: 1, 2, 3, 5, 8. It is the Fibonacci sequence.

  5. What is printed?

    Python · medium

    x = 10
    def f():
        x = 20
        def g():
            nonlocal x
            x += 1
        g()
        return x
    print(f(), x)
    1. 21 10
    2. 21 21
    3. 11 10
    4. 20 10

    Answer: A. 21 10

    Explanation: nonlocal makes g change f’s x (20 → 21). The global x stays 10.

  6. What is printed?

    Python · medium

    def add(item, box=[]):
        box.append(item)
        return box
    
    add(1)
    print(add(2))
    1. [2]
    2. [1, 2]
    3. []
    4. An error

    Answer: B. [1, 2]

    Explanation: Default values are evaluated once, when the function is defined. Both calls share the same list. Use box=None and create the list inside.

  7. What is printed?

    Python · medium

    print(sorted(["banana", "Apple", "cherry"]))
    1. ['Apple', 'banana', 'cherry']
    2. ['apple', 'banana', 'cherry']
    3. ['banana', 'cherry', 'Apple']
    4. ['cherry', 'banana', 'Apple']

    Answer: A. ['Apple', 'banana', 'cherry']

    Explanation: Strings sort by code point, and capital letters come before lowercase ones, so "Apple" is first here. Use key=str.lower to sort case-insensitively.

  8. Which statement about strongly connected components (SCCs) is true?

    DSA · hard

    1. They only exist in undirected graphs
    2. Tarjan’s and Kosaraju’s algorithms find all SCCs in O(V + E)
    3. Finding SCCs needs O(V³) Floyd–Warshall
    4. Every DAG has exactly one SCC

    Answer: B. Tarjan’s and Kosaraju’s algorithms find all SCCs in O(V + E)

    Explanation: Both run DFS-based passes in linear time. In a DAG every vertex is its own SCC, so a DAG with V vertices has V SCCs.

  9. What is printed?

    Python · hard

    def gen():
        x = yield 1
        yield x * 10
    
    g = gen()
    print(next(g), g.send(5))
    1. 1 50
    2. 1 10
    3. 1 None
    4. TypeError

    Answer: A. 1 50

    Explanation: next(g) runs to the first yield and gives 1. send(5) resumes the generator, making the paused yield expression evaluate to 5, so the next yield gives 50.

  10. What is printed?

    Python · hard

    class Counter:
        count = 0
        def __init__(self):
            self.count += 1
    
    a, b = Counter(), Counter()
    print(Counter.count, a.count, b.count)
    1. 0 1 1
    2. 2 2 2
    3. 2 1 2
    4. 0 0 0

    Answer: A. 0 1 1

    Explanation: self.count += 1 reads the class attribute (0) but writes a new instance attribute. The class attribute is never changed. Write Counter.count += 1 to share it.

Play the next Daily Quiz at 4 PM IST