Hack4Hack

Daily Coding Quiz: Tuesday, 17 November 2026

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

  1. Which sorting algorithm repeatedly swaps adjacent elements that are in the wrong order?

    DSA · easy

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

    Answer: C. Bubble sort

    Explanation: Bubble sort compares neighbours and swaps them, so large values “bubble” to the end on each pass. It is O(n²).

  2. What does this return?

    SQL · easy

    SELECT name FROM employees WHERE name LIKE 'M%';
    -- names: Asha, Ravi, Meera, Kabir, Neha
    1. Meera
    2. Meera, Neha
    3. Asha, Meera
    4. No rows

    Answer: A. Meera

    Explanation: 'M%' matches names starting with M. % is any run of characters and _ is exactly one.

  3. Which JOIN returns every row from the left table, with NULLs where there is no match on the right?

    SQL · easy

    1. INNER JOIN
    2. LEFT JOIN
    3. CROSS JOIN
    4. SELF JOIN

    Answer: B. LEFT JOIN

    Explanation: LEFT (OUTER) JOIN keeps all left rows. INNER JOIN keeps only rows that match on both sides.

  4. What is the space complexity of a recursive DFS on a tree of height h (ignoring the output)?

    DSA · medium

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

    Answer: B. O(h)

    Explanation: The call stack holds one frame per level on the current root-to-node path, so at most h + 1 frames.

  5. Which statements are true about a VIEW? (Select all that apply)

    SQL · medium

    1. It is a stored query
    2. By default it does not store a copy of the data
    3. It always makes queries faster
    4. It can hide columns from users

    Answer: A. It is a stored query; B. By default it does not store a copy of the data; D. It can hide columns from users

    Explanation: A view is a named SELECT that runs when queried, so it is not automatically faster (materialized views, which store results, are a different feature). Views are often used to expose only some columns.

  6. Table A has 3 rows and table B has 4 rows. How many rows does SELECT * FROM A CROSS JOIN B return?

    SQL · medium

    1. 7
    2. 12
    3. 4
    4. 3

    Answer: B. 12

    Explanation: A cross join pairs every row of A with every row of B: 3 × 4 = 12 (a Cartesian product).

  7. What does this return?

    SQL · medium

    -- Table employees(id, name, dept, salary):
    -- (1, Asha,  Eng,   90)
    -- (2, Ravi,  Eng,   70)
    -- (3, Meera, Sales, 60)
    -- (4, Kabir, Sales, 60)
    -- (5, Neha,  HR,    NULL)
    SELECT dept, COUNT(*) AS n
    FROM employees
    GROUP BY dept
    HAVING COUNT(*) > 1
    ORDER BY dept;
    1. Eng 2, Sales 2
    2. Eng 2, HR 1, Sales 2
    3. Sales 2
    4. Eng 2

    Answer: A. Eng 2, Sales 2

    Explanation: Eng and Sales have 2 employees each; HR has 1 and is filtered out by HAVING.

  8. What is the minimum number of comparisons any comparison-based sort needs in the worst case?

    DSA · hard

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

    Answer: B. Θ(n log n)

    Explanation: There are n! possible orders, and a decision tree with n! leaves has height ≥ log₂(n!) = Θ(n log n). Counting sort beats this only by not comparing.

  9. What does this return?

    SQL · hard

    SELECT * FROM a WHERE id NOT IN (SELECT a_id FROM b);
    -- a.id: 1, 2, 3
    -- b.a_id: 1, NULL
    1. 2, 3
    2. No rows
    3. 1
    4. 1, 2, 3

    Answer: B. No rows

    Explanation: id NOT IN (1, NULL) means id <> 1 AND id <> NULL. Comparing with NULL is unknown, so no row qualifies. NOT EXISTS does not have this trap.

  10. What does the running total return for the third row?

    SQL · hard

    SELECT d, amt, SUM(amt) OVER (ORDER BY d) AS running
    FROM sales;
    -- rows (d, amt): ('2026-01-01', 10), ('2026-01-02', 20), ('2026-01-02', 5), ('2026-01-03', 7)
    1. 30
    2. 35
    3. 5
    4. 42

    Answer: B. 35

    Explanation: With ORDER BY and no frame clause the default frame is RANGE … CURRENT ROW, which includes all peers with the same d. Both 2026-01-02 rows show 10 + 20 + 5 = 35. Use ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW for a strict row-by-row total.

Play the next Daily Quiz at 4 PM IST