Solve matrix add, frequency count, longest consecutive
Company: Disney
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: Medium
Interview Round: Technical Screen
You are asked to solve the following 3 coding tasks (in any language). Implement each as a function.
## 1) Add two matrices
**Input:** Two 2D integer arrays `A` and `B`, each of shape `m x n`.
**Task:** Return a new matrix `C` of shape `m x n` where `C[i][j] = A[i][j] + B[i][j]`.
**Assumptions:**
- `A` and `B` have the same dimensions.
**Example:**
- `A = [[1,2],[3,4]]`, `B = [[5,6],[7,8]]` → `[[6,8],[10,12]]`
---
## 2) Count occurrences of names
**Input:** A list/array of strings `names`.
**Task:** Return a dictionary / hash map from name → frequency (count of how many times it appears).
**Example:**
- `names = ["Amy","Bob","Amy"]` → `{ "Amy": 2, "Bob": 1 }`
---
## 3) Longest consecutive sequence
**Input:** An integer array `nums` (can contain duplicates and negative numbers).
**Task:** Return the length of the longest sequence of consecutive integers that can be formed from the elements of `nums` (order in the array does not matter).
**Complexity requirement:** Aim for **O(n)** time using a hash set (typical “Longest Consecutive Sequence” problem).
**Examples:**
- `nums = [100,4,200,1,3,2]` → `4` (sequence `1,2,3,4`)
- `nums = [0,3,7,2,5,8,4,6,0,1]` → `9` (sequence `0..8`)
**Clarifications:**
- Duplicates should not inflate the sequence length.
- If `nums` is empty, return `0`.
Quick Answer: This question evaluates proficiency in basic numerical and array operations (matrix addition), associative data structures for frequency counting (hash maps), and set-based algorithmic reasoning for the longest consecutive sequence problem.