Coding questions · BlackRock
Implement sorting and set intersection with input parsing
This question evaluates proficiency in algorithm design and implementation, specifically sorting algorithms, set intersection logic, input parsing, and analysis of time/space complexity and algorithm stability within the Coding & Algorithms domain.
Write two functions and explain your approach in under two minutes after coding: (A) Sorting: Implement sort_numbers(nums: List[int]) -> List[int] that returns nums in non-decreasing order without using built-in sort; use a standard algorithm and describe time/space complexity and stability. (B) Set Intersection: Implement intersect_sets(a: Iterable[int], b: Iterable[int]) -> List[int] that returns the unique elements present in both a and b in ascending order; describe time/space complexity and key edge cases (e.g., empty inputs, duplicates). Assume you must handle input parsing yourself (no helpers), and you will have two fixed test cases with a single allowed submission.
Sort Numbers Without Built-in Sort
Return the numbers in non-decreasing order using merge sort.
Examples
Example 1
Input: ([3,1,2,1],)
Output: [1, 1, 2, 3]
Explanation: Duplicates.
Example 2
Input: ([],)
Output: []
Explanation: Empty input.
Hints
- Choose a representation that makes the core operation simple.
- Handle empty and boundary inputs before the main algorithm.
Sorted Set Intersection
Return unique elements present in both inputs in ascending order.
Examples
Example 1
Input: ([1,2,2,3], [2,2,4])
Output: [2]
Explanation: Unique intersection.
Example 2
Input: ([], [1])
Output: []
Explanation: Empty input.
Hints
- Choose a representation that makes the core operation simple.
- Handle empty and boundary inputs before the main algorithm.