Hack4Hack

Daily Coding Quiz: Monday, 2 November 2026

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

  1. Which of these is a stable sorting algorithm by default?

    DSA · easy · 100% of players got it right

    1. Quick sort
    2. Heap sort
    3. Merge sort
    4. Selection sort

    Answer: C. Merge sort

    Explanation: Merge sort keeps equal elements in their original order (take from the left half on ties). Standard quick, heap and selection sort do not.

  2. What is printed?

    Python · easy · 0% of players got it right

    s = "Python"
    print(s[-1], s[::-1])
    1. n nohtyP
    2. P nohtyP
    3. n Python
    4. nohtyP n

    Answer: A. n nohtyP

    Explanation: s[-1] is the last character; a step of −1 walks the string backwards, reversing it.

  3. Which keyword creates a generator function?

    Python · easy · 100% of players got it right

    1. return
    2. yield
    3. async
    4. lambda

    Answer: B. yield

    Explanation: A function containing yield returns a generator: it produces values lazily, pausing at each yield.

  4. Floyd’s “tortoise and hare” algorithm is mainly used to:

    DSA · medium · 0% of players got it right

    1. Sort a linked list
    2. Detect a cycle in a linked list
    3. Reverse a linked list
    4. Merge two sorted lists

    Answer: B. Detect a cycle in a linked list

    Explanation: One pointer moves 1 step, the other 2. If there is a cycle the fast pointer eventually meets the slow one; if not, it reaches the end.

  5. What is printed?

    Python · medium · 0% of players got it right

    a = [1, 2, 3]
    b = a
    b += [4]
    print(a)
    1. [1, 2, 3]
    2. [1, 2, 3, 4]
    3. [4]
    4. An error

    Answer: B. [1, 2, 3, 4]

    Explanation: b = a makes both names point to the same list, and += on a list extends it in place, so a sees the change.

  6. What is printed?

    Python · medium · 0% of players got it right

    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 printed?

    Python · medium · 0% of players got it right

    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.

  8. What is the time complexity of the classic dynamic-programming solution to the Longest Common Subsequence of strings of length m and n?

    DSA · hard · 0% of players got it right

    1. O(m + n)
    2. O(m · n)
    3. O(2^(m+n))
    4. O((m + n) log(m + n))

    Answer: B. O(m · n)

    Explanation: The DP table has (m+1)(n+1) cells and each is filled in O(1) from its neighbours.

  9. What is printed?

    Python · hard · 0% of players got it right

    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 · 0% of players got it right

    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.

Top 10

  1. Sriharini Kalidas: 24 points (2/10)

Play the next Daily Quiz at 4 PM IST