PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Meta

Compute sparse dot product and count islands

Last updated: Mar 29, 2026

Quick Overview

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.

  • medium
  • Meta
  • Coding & Algorithms
  • Software Engineer

Compute sparse dot product and count islands

Company: Meta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are asked to solve two coding problems. ## Problem 1: Sparse vector dot product Given two vectors **A** and **B** of the same length **n** (potentially large, e.g., up to 100,000), most entries are zero. Implement a function (or a small class API) to compute the dot product: \[ A \cdot B = \sum_{i=0}^{n-1} A_i \times B_i \] **Input representation (sparse):** Each vector is provided as a list of non-zero entries, e.g. a list of pairs `(index, value)` sorted by index (or equivalently a map from index to value). **Output:** Return the integer dot product. **Constraints/notes:** - Indices are in `[0, n-1]`. - Values can be negative. - Aim for time proportional to the number of non-zero entries. ## Problem 2: Count connected islands in a grid Given an `m x n` 2D grid of characters (or integers) where `'1'` represents land and `'0'` represents water, count the number of **islands**. An island is a maximal set of land cells connected **4-directionally** (up, down, left, right). **Input:** `grid[m][n]` containing `'0'`/`'1'`. **Output:** The number of islands. **Constraints/notes:** - You may modify the grid in-place or use auxiliary memory. - Consider edge cases like empty grid, all water, all land, and thin grids (1 row/1 column).

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.

Related Interview Questions

  • Solve Tree Columns And Maze Variants - Meta (medium)
  • Solve Tree Diameter and Palindromic Counts - Meta (medium)
  • Simulate Monster Team Battles - Meta (hard)
  • Solve a Key-Door Corridor Maze - Meta (medium)
  • Solve Array Merge and Parentheses Cleanup - Meta (medium)
Meta logo
Meta
Feb 11, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
2
0

You are asked to solve two coding problems.

Problem 1: Sparse vector dot product

Given two vectors A and B of the same length n (potentially large, e.g., up to 100,000), most entries are zero.

Implement a function (or a small class API) to compute the dot product:

A⋅B=∑i=0n−1Ai×BiA \cdot B = \sum_{i=0}^{n-1} A_i \times B_iA⋅B=∑i=0n−1​Ai​×Bi​

Input representation (sparse): Each vector is provided as a list of non-zero entries, e.g. a list of pairs (index, value) sorted by index (or equivalently a map from index to value).

Output: Return the integer dot product.

Constraints/notes:

  • Indices are in [0, n-1] .
  • Values can be negative.
  • Aim for time proportional to the number of non-zero entries.

Problem 2: Count connected islands in a grid

Given an m x n 2D grid of characters (or integers) where '1' represents land and '0' represents water, count the number of islands.

An island is a maximal set of land cells connected 4-directionally (up, down, left, right).

Input: grid[m][n] containing '0'/'1'.

Output: The number of islands.

Constraints/notes:

  • You may modify the grid in-place or use auxiliary memory.
  • Consider edge cases like empty grid, all water, all land, and thin grids (1 row/1 column).

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Meta•More Software Engineer•Meta Software Engineer•Meta Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.