Episode 7 — DSA with JavaScript / 7.8 — Advanced Array Problems

7.8.b — Multi-Dimensional Arrays

<< 7.8 Overview


2D arrays (matrices)

A 2D array is an array of arrays — visualized as a grid.

     col 0  col 1  col 2  col 3
row 0 [ 1,    2,     3,     4  ]
row 1 [ 5,    6,     7,     8  ]
row 2 [ 9,   10,    11,    12  ]

Creating 2D arrays

// 3×4 matrix filled with zeros
const matrix = Array.from({ length: 3 }, () => Array(4).fill(0));

// From values
const m = [
    [1, 2, 3, 4],
    [5, 6, 7, 8],
    [9, 10, 11, 12],
];
#include <vector>
using namespace std;

// 3×4 matrix filled with zeros
vector<vector<int>> matrix(3, vector<int>(4, 0));

Accessing elements

matrix[row][col];    // access
matrix[1][2] = 99;   // update

Traversing

for (let i = 0; i < matrix.length; i++) {
    for (let j = 0; j < matrix[i].length; j++) {
        console.log(matrix[i][j]);
    }
}

Spiral traversal

Matrix:               Spiral order:
┌─────────────────┐   1→2→3→4→8→12→11→10→9→5→6→7
│  1   2   3   4  │
│  5   6   7   8  │
│  9  10  11  12  │
└─────────────────┘
function spiralOrder(matrix) {
    if (!matrix.length) return [];
    const result = [];
    let top = 0, bottom = matrix.length - 1;
    let left = 0, right = matrix[0].length - 1;
    while (top <= bottom && left <= right) {
        for (let i = left; i <= right; i++) result.push(matrix[top][i]);
        top++;
        for (let i = top; i <= bottom; i++) result.push(matrix[i][right]);
        right--;
        if (top <= bottom)
            for (let i = right; i >= left; i--) result.push(matrix[bottom][i]);
        bottom--;
        if (left <= right)
            for (let i = bottom; i >= top; i--) result.push(matrix[i][left]);
        left++;
    }
    return result;
}
vector<int> spiralOrder(vector<vector<int>>& matrix) {
    vector<int> result;
    if (matrix.empty()) return result;
    int top = 0, bottom = matrix.size()-1, left = 0, right = matrix[0].size()-1;
    while (top <= bottom && left <= right) {
        for (int i = left; i <= right; i++) result.push_back(matrix[top][i]);
        top++;
        for (int i = top; i <= bottom; i++) result.push_back(matrix[i][right]);
        right--;
        if (top <= bottom) for (int i = right; i >= left; i--) result.push_back(matrix[bottom][i]);
        bottom--;
        if (left <= right) for (int i = bottom; i >= top; i--) result.push_back(matrix[i][left]);
        left++;
    }
    return result;
}

Matrix rotation (90° clockwise)

Original:     Rotated 90°:
1 2 3         7 4 1
4 5 6    →    8 5 2
7 8 9         9 6 3

Step 1: Transpose (swap rows and cols)
1 4 7
2 5 8
3 6 9

Step 2: Reverse each row
7 4 1
8 5 2
9 6 3 ✓
function rotate(matrix) {
    const n = matrix.length;
    // Transpose
    for (let i = 0; i < n; i++)
        for (let j = i + 1; j < n; j++)
            [matrix[i][j], matrix[j][i]] = [matrix[j][i], matrix[i][j]];
    // Reverse each row
    for (let i = 0; i < n; i++) matrix[i].reverse();
}
void rotate(vector<vector<int>>& matrix) {
    int n = matrix.size();
    for (int i = 0; i < n; i++)
        for (int j = i+1; j < n; j++)
            swap(matrix[i][j], matrix[j][i]);
    for (auto& row : matrix) reverse(row.begin(), row.end());
}

Search in sorted 2D matrix

Each row sorted, first element of each row > last element of previous row.

function searchMatrix(matrix, target) {
    const m = matrix.length, n = matrix[0].length;
    let lo = 0, hi = m * n - 1;
    while (lo <= hi) {
        const mid = Math.floor((lo + hi) / 2);
        const val = matrix[Math.floor(mid / n)][mid % n];
        if (val === target) return true;
        if (val < target) lo = mid + 1;
        else hi = mid - 1;
    }
    return false;
}

Time: O(log(m×n)) | Space: O(1)


Set matrix zeroes

function setZeroes(matrix) {
    const m = matrix.length, n = matrix[0].length;
    let firstRowZero = false, firstColZero = false;
    for (let j = 0; j < n; j++) if (matrix[0][j] === 0) firstRowZero = true;
    for (let i = 0; i < m; i++) if (matrix[i][0] === 0) firstColZero = true;
    for (let i = 1; i < m; i++)
        for (let j = 1; j < n; j++)
            if (matrix[i][j] === 0) { matrix[i][0] = 0; matrix[0][j] = 0; }
    for (let i = 1; i < m; i++)
        for (let j = 1; j < n; j++)
            if (matrix[i][0] === 0 || matrix[0][j] === 0) matrix[i][j] = 0;
    if (firstRowZero) for (let j = 0; j < n; j++) matrix[0][j] = 0;
    if (firstColZero) for (let i = 0; i < m; i++) matrix[i][0] = 0;
}

Scenario bank (multi-dimensional arrays)

7.8b-001 — Diagonal traversal (v1)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-002 — Anti-diagonal traversal (v2)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-003 — Zigzag traversal (v3)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-004 — Matrix multiplication (v4)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-005 — Matrix transpose (v5)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-006 — Island counting (DFS/BFS) (v6)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-007 — Word search in grid (v7)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-008 — Game of Life (v8)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-009 — Maximal square (v9)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-010 — Rotate matrix 180 degrees (v10)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-011 — Matrix layer rotation (v11)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-012 — Toeplitz matrix check (v12)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-013 — Sparse matrix representation (v13)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-014 — Matrix exponentiation (v14)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-015 — Sudoku validator (v15)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-016 — Flood fill (v16)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-017 — Shortest path in grid (BFS) (v17)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-018 — Number of distinct islands (v18)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-019 — Battleship game board (v19)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-020 — Pascal's triangle as 2D array (v20)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-021 — Diagonal traversal (v21)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-022 — Anti-diagonal traversal (v22)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-023 — Zigzag traversal (v23)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-024 — Matrix multiplication (v24)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-025 — Matrix transpose (v25)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-026 — Island counting (DFS/BFS) (v26)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-027 — Word search in grid (v27)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-028 — Game of Life (v28)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-029 — Maximal square (v29)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-030 — Rotate matrix 180 degrees (v30)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-031 — Matrix layer rotation (v31)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-032 — Toeplitz matrix check (v32)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-033 — Sparse matrix representation (v33)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-034 — Matrix exponentiation (v34)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-035 — Sudoku validator (v35)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-036 — Flood fill (v36)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-037 — Shortest path in grid (BFS) (v37)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-038 — Number of distinct islands (v38)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-039 — Battleship game board (v39)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-040 — Pascal's triangle as 2D array (v40)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-041 — Diagonal traversal (v41)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-042 — Anti-diagonal traversal (v42)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-043 — Zigzag traversal (v43)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-044 — Matrix multiplication (v44)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-045 — Matrix transpose (v45)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-046 — Island counting (DFS/BFS) (v46)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-047 — Word search in grid (v47)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-048 — Game of Life (v48)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-049 — Maximal square (v49)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-050 — Rotate matrix 180 degrees (v50)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-051 — Matrix layer rotation (v51)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-052 — Toeplitz matrix check (v52)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-053 — Sparse matrix representation (v53)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-054 — Matrix exponentiation (v54)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-055 — Sudoku validator (v55)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-056 — Flood fill (v56)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-057 — Shortest path in grid (BFS) (v57)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-058 — Number of distinct islands (v58)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-059 — Battleship game board (v59)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-060 — Pascal's triangle as 2D array (v60)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-061 — Diagonal traversal (v61)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-062 — Anti-diagonal traversal (v62)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-063 — Zigzag traversal (v63)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-064 — Matrix multiplication (v64)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-065 — Matrix transpose (v65)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-066 — Island counting (DFS/BFS) (v66)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-067 — Word search in grid (v67)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-068 — Game of Life (v68)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-069 — Maximal square (v69)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-070 — Rotate matrix 180 degrees (v70)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-071 — Matrix layer rotation (v71)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-072 — Toeplitz matrix check (v72)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-073 — Sparse matrix representation (v73)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-074 — Matrix exponentiation (v74)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-075 — Sudoku validator (v75)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-076 — Flood fill (v76)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-077 — Shortest path in grid (BFS) (v77)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-078 — Number of distinct islands (v78)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-079 — Battleship game board (v79)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-080 — Pascal's triangle as 2D array (v80)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-081 — Diagonal traversal (v81)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-082 — Anti-diagonal traversal (v82)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-083 — Zigzag traversal (v83)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-084 — Matrix multiplication (v84)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-085 — Matrix transpose (v85)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-086 — Island counting (DFS/BFS) (v86)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-087 — Word search in grid (v87)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-088 — Game of Life (v88)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-089 — Maximal square (v89)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-090 — Rotate matrix 180 degrees (v90)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-091 — Matrix layer rotation (v91)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-092 — Toeplitz matrix check (v92)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-093 — Sparse matrix representation (v93)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-094 — Matrix exponentiation (v94)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-095 — Sudoku validator (v95)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-096 — Flood fill (v96)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-097 — Shortest path in grid (BFS) (v97)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-098 — Number of distinct islands (v98)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-099 — Battleship game board (v99)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-100 — Pascal's triangle as 2D array (v100)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-101 — Diagonal traversal (v101)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-102 — Anti-diagonal traversal (v102)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-103 — Zigzag traversal (v103)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-104 — Matrix multiplication (v104)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-105 — Matrix transpose (v105)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-106 — Island counting (DFS/BFS) (v106)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-107 — Word search in grid (v107)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-108 — Game of Life (v108)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-109 — Maximal square (v109)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-110 — Rotate matrix 180 degrees (v110)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-111 — Matrix layer rotation (v111)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-112 — Toeplitz matrix check (v112)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-113 — Sparse matrix representation (v113)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-114 — Matrix exponentiation (v114)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-115 — Sudoku validator (v115)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-116 — Flood fill (v116)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-117 — Shortest path in grid (BFS) (v117)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-118 — Number of distinct islands (v118)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-119 — Battleship game board (v119)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-120 — Pascal's triangle as 2D array (v120)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-121 — Diagonal traversal (v121)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-122 — Anti-diagonal traversal (v122)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-123 — Zigzag traversal (v123)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-124 — Matrix multiplication (v124)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-125 — Matrix transpose (v125)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-126 — Island counting (DFS/BFS) (v126)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-127 — Word search in grid (v127)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-128 — Game of Life (v128)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-129 — Maximal square (v129)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-130 — Rotate matrix 180 degrees (v130)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-131 — Matrix layer rotation (v131)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-132 — Toeplitz matrix check (v132)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-133 — Sparse matrix representation (v133)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-134 — Matrix exponentiation (v134)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-135 — Sudoku validator (v135)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-136 — Flood fill (v136)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-137 — Shortest path in grid (BFS) (v137)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-138 — Number of distinct islands (v138)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-139 — Battleship game board (v139)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-140 — Pascal's triangle as 2D array (v140)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-141 — Diagonal traversal (v141)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-142 — Anti-diagonal traversal (v142)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-143 — Zigzag traversal (v143)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-144 — Matrix multiplication (v144)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-145 — Matrix transpose (v145)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-146 — Island counting (DFS/BFS) (v146)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-147 — Word search in grid (v147)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-148 — Game of Life (v148)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-149 — Maximal square (v149)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-150 — Rotate matrix 180 degrees (v150)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-151 — Matrix layer rotation (v151)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-152 — Toeplitz matrix check (v152)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-153 — Sparse matrix representation (v153)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-154 — Matrix exponentiation (v154)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-155 — Sudoku validator (v155)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-156 — Flood fill (v156)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-157 — Shortest path in grid (BFS) (v157)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-158 — Number of distinct islands (v158)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-159 — Battleship game board (v159)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-160 — Pascal's triangle as 2D array (v160)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-161 — Diagonal traversal (v161)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-162 — Anti-diagonal traversal (v162)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-163 — Zigzag traversal (v163)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-164 — Matrix multiplication (v164)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-165 — Matrix transpose (v165)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-166 — Island counting (DFS/BFS) (v166)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-167 — Word search in grid (v167)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-168 — Game of Life (v168)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-169 — Maximal square (v169)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8b-170 — Rotate matrix 180 degrees (v170)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.