Hack4Hack

Daily Coding Quiz: Tuesday, 27 October 2026

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

  1. Which problem is a classic use of the two-pointer technique on a sorted array?

    DSA · easy · 25% of players got it right

    1. Find two numbers that add up to a target
    2. Find the median of a stream
    3. Detect a cycle in a graph
    4. Find all permutations

    Answer: A. Find two numbers that add up to a target

    Explanation: Start one pointer at each end: if the sum is too small move the left pointer right, if too big move the right pointer left. O(n) total.

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

    SQL · easy · 75% of players got it right

    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.

  3. What does this return?

    SQL · easy · 50% of players got it right

    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.

  4. The recurrence T(n) = 2T(n/2) + O(n) solves to:

    DSA · medium · 25% of players got it right

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

    Answer: B. O(n log n)

    Explanation: This is merge sort: log n levels of recursion, each doing O(n) total work. Master theorem case 2.

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

    SQL · medium · 25% of players got it right

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

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

    SQL · medium · 25% of players got it right

    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.

  7. What does this return?

    SQL · medium · 25% of players got it right

    -- 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. With union by rank and path compression, the amortised cost of a Union-Find operation is:

    DSA · hard · 50% of players got it right

    1. O(log n)
    2. O(α(n)), inverse Ackermann
    3. O(√n)
    4. O(1) worst case

    Answer: B. O(α(n)), inverse Ackermann

    Explanation: Tarjan proved the amortised bound is O(α(n)); α grows so slowly it is ≤ 4 for any practical n, but it is not strictly constant.

  9. What does this recursive CTE return?

    SQL · hard · 50% of players got it right

    WITH RECURSIVE n(x) AS (
      SELECT 1
      UNION ALL
      SELECT x * 2 FROM n WHERE x < 20
    )
    SELECT SUM(x) FROM n;
    1. 31
    2. 63
    3. 30
    4. 62

    Answer: B. 63

    Explanation: Rows: 1, 2, 4, 8, 16, then 32 (16 < 20 still passes, producing 32; 32 stops the recursion). 1+2+4+8+16+32 = 63.

  10. What does this return?

    SQL · hard · 50% of players got it right

    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.

Top 10

  1. Sathvik S A: 206 points (8/10)
  2. Sneha Pal: 138 points (6/10)
  3. Nitin Singh: 26 points (2/10)
  4. Devika Srivastava: 0 points (0/10)

Play the next Daily Quiz at 4 PM IST