Quick Overview

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.

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.

Add Two Matrices

Return the elementwise sum of two same-shaped matrices.

Constraints

  • Inputs are Python literals matching the function signature.
  • Return a deterministic exact-match value.

Examples

Input: ([[1,2],[3,4]], [[5,6],[7,8]])

Expected Output: [[6, 8], [10, 12]]

Explanation: Add corresponding entries.

Input: ([], [])

Expected Output: []

Explanation: Empty matrices return empty output.

Hints

  1. Clarify edge cases before coding.
  2. Keep outputs deterministic when several valid answers exist.

Count Name Occurrences

Return a dictionary mapping each name to its frequency.

Constraints

  • Inputs are Python literals matching the function signature.
  • Return a deterministic exact-match value.

Examples

Input: (["Amy","Bob","Amy"],)

Expected Output: {'Amy': 2, 'Bob': 1}

Explanation: Amy appears twice.

Input: ([],)

Expected Output: {}

Explanation: No names means no counts.

Hints

  1. Clarify edge cases before coding.
  2. Keep outputs deterministic when several valid answers exist.

Longest Consecutive Sequence

Return the length of the longest consecutive integer sequence that can be formed from nums.

Constraints

  • Inputs are Python literals matching the function signature.
  • Return a deterministic exact-match value.

Examples

Input: ([100,4,200,1,3,2],)

Expected Output: 4

Explanation: The longest run is 1,2,3,4.

Input: ([0,3,7,2,5,8,4,6,0,1],)

Expected Output: 9

Explanation: The longest run is 0 through 8.

Hints

  1. Clarify edge cases before coding.
  2. Keep outputs deterministic when several valid answers exist.

Loading coding console...