Compute sparse dot product and count islands
Company: Meta
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates competency in designing efficient algorithms for sparse data representations and for identifying connected components in grids, testing skills in handling large inputs, memory-efficient representations, and traversal/graph concepts.
Sparse Vector Dot Product
Constraints
- Inputs are provided as Python literals compatible with the function signature.
- Return a deterministic value exactly matching the requested output.
Examples
Input: ([1, 0, 0, 2, 3], [0, 3, 0, 4, 0])
Expected Output: 8
Explanation: Only index 3 contributes.
Input: ([0, 0, 0], [4, 5, 6])
Expected Output: 0
Explanation: All-zero sparse vector.
Input: ([-1, 0, 5, 0], [2, 9, -3, 4])
Expected Output: -17
Explanation: Negative products are included.
Hints
- Start with a direct data structure representation.
- Handle edge cases before the main loop.
Count Islands in a Binary Grid
Constraints
- Inputs are provided as Python literals compatible with the function signature.
- Return a deterministic value exactly matching the requested output.
Examples
Input: ([['1', '1', '0'], ['0', '1', '0'], ['1', '0', '1']],)
Expected Output: 3
Explanation: String grid with three islands.
Input: ([[1, 1, 0], [0, 1, 0], [1, 0, 1]],)
Expected Output: 3
Explanation: Integer grid uses the same rule.
Input: ([],)
Expected Output: 0
Explanation: Empty grid has no islands.
Hints
- Start with a direct data structure representation.
- Handle edge cases before the main loop.