Daily Coding Quiz: Tuesday, 3 November 2026
All 10 coding questions with answers and explanations. 0 players took part.
How many edges does a tree with n nodes have?
DSA · easy
- n
- n − 1
- n + 1
- 2n
Answer: B. n − 1
Explanation: A tree is connected and acyclic: every node except the root has exactly one edge to its parent, giving n − 1 edges.
Which statement removes all rows from a table but keeps the table itself?
SQL · easy
- DROP TABLE
- DELETE TABLE
- TRUNCATE TABLE
- REMOVE TABLE
Answer: C. TRUNCATE TABLE
Explanation: TRUNCATE empties the table quickly (and in MySQL resets AUTO_INCREMENT). DROP deletes the table definition too. DELETE without WHERE also removes all rows, row by row.
What does this return?
SQL · easy
-- 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 COUNT(*), COUNT(salary) FROM employees;- 5, 5
- 5, 4
- 4, 4
- 4, 5
Answer: B. 5, 4
Explanation: COUNT(*) counts rows (5). COUNT(column) skips NULLs, and Neha’s salary is NULL, so 4.
What does this return for nums = [2, 7, 11, 15], target = 9?
DSA · medium
def solve(nums, target): seen = {} for i, x in enumerate(nums): if target - x in seen: return [seen[target - x], i] seen[x] = i return []- [0, 1]
- [1, 0]
- [2, 7]
- []
Answer: A. [0, 1]
Explanation: At i=1 (x=7), 9−7=2 is already in seen at index 0, so it returns [0, 1]. This is the O(n) hash-map solution to Two Sum.
Which query finds the second-highest distinct salary?
SQL · medium
- SELECT MAX(salary) FROM employees WHERE salary < (SELECT MAX(salary) FROM employees)
- SELECT salary FROM employees ORDER BY salary LIMIT 2
- SELECT MAX(salary) - 1 FROM employees
- SELECT salary FROM employees WHERE salary = 2
Answer: A. SELECT MAX(salary) FROM employees WHERE salary < (SELECT MAX(salary) FROM employees)
Explanation: Take the maximum among salaries below the overall maximum. ORDER BY salary DESC LIMIT 1 OFFSET 1 also works only if there are no duplicates at the top; DISTINCT fixes that.
What does this return?
SQL · medium
SELECT COALESCE(NULL, NULL, 'x', 'y'), NULLIF(5, 5), IFNULL(NULL, 0); -- MySQL- x, NULL, 0
- NULL, 5, 0
- y, 0, NULL
- x, 5, 0
Answer: A. x, NULL, 0
Explanation: COALESCE returns the first non-NULL argument. NULLIF(a, b) is NULL when a = b. IFNULL(a, b) is MySQL’s two-argument COALESCE.
A composite index exists on (last_name, first_name). Which WHERE clause can use it best?
SQL · medium
- WHERE first_name = 'Ravi'
- WHERE last_name = 'Shah'
- WHERE UPPER(last_name) = 'SHAH'
- WHERE first_name LIKE '%vi'
Answer: B. WHERE last_name = 'Shah'
Explanation: A B-tree index on (a, b) is sorted by a first, so it helps filters on its leftmost column. Wrapping the column in a function, or filtering only on b, generally prevents its use.
You need the k largest of n numbers arriving as a stream, using little memory. The best approach:
DSA · hard
- Sort everything at the end: O(n log n) time, O(n) memory
- A min-heap of size k: O(n log k) time, O(k) memory
- A max-heap of all n elements
- A hash set of size k
Answer: B. A min-heap of size k: O(n log k) time, O(k) memory
Explanation: Keep the k largest so far in a min-heap: if a new number beats the heap’s minimum, replace it. Only k items are ever stored.
Which query returns the highest-paid employee in every department (ties included)?
SQL · hard
- SELECT dept, name, MAX(salary) FROM employees GROUP BY dept
- SELECT dept, name, salary FROM (SELECT *, RANK() OVER (PARTITION BY dept ORDER BY salary DESC) r FROM employees) t WHERE r = 1
- SELECT dept, name, salary FROM employees ORDER BY salary DESC LIMIT 1
- SELECT DISTINCT dept, MAX(name) FROM employees
Answer: B. SELECT dept, name, salary FROM (SELECT *, RANK() OVER (PARTITION BY dept ORDER BY salary DESC) r FROM employees) t WHERE r = 1
Explanation: Ranking within each department and keeping rank 1 returns the right name with ties. The GROUP BY version selects a name not tied to the MAX (an error under ONLY_FULL_GROUP_BY, an arbitrary name otherwise).
Which isolation level prevents dirty reads, non-repeatable reads and phantom reads (per the SQL standard)?
SQL · hard
- READ UNCOMMITTED
- READ COMMITTED
- REPEATABLE READ
- SERIALIZABLE
Answer: D. SERIALIZABLE
Explanation: Only SERIALIZABLE forbids all three in the standard. (MySQL InnoDB’s default REPEATABLE READ also blocks most phantoms using next-key locks.)