Episode 7 — DSA with JavaScript / 7.3 — Arrays

7.3.a — Array Basics & Manipulation

<< 7.3 Overview


What is an array?

An array is a contiguous collection of elements, each identified by an index.

Index:  0     1     2     3     4
      ┌─────┬─────┬─────┬─────┬─────┐
      │  10 │  20 │  30 │  40 │  50 │
      └─────┴─────┴─────┴─────┴─────┘
  • Fixed-size in C/C++ (at compile time)
  • Dynamic in JavaScript (resizable at runtime)
  • 0-indexed in both languages

Creating arrays

JavaScript

// Literal
const nums = [10, 20, 30, 40, 50];

// Constructor
const zeros = new Array(5).fill(0);  // [0, 0, 0, 0, 0]

// Array.from
const range = Array.from({ length: 5 }, (_, i) => i + 1);
// [1, 2, 3, 4, 5]

C++

#include <iostream>
#include <vector>
using namespace std;

int main() {
    // C-style array (fixed size)
    int arr[5] = {10, 20, 30, 40, 50};

    // vector (dynamic)
    vector<int> nums = {10, 20, 30, 40, 50};

    // Fill with zeros
    vector<int> zeros(5, 0);

    // Range
    vector<int> range(5);
    for (int i = 0; i < 5; i++) range[i] = i + 1;

    return 0;
}

Accessing elements

const arr = [10, 20, 30, 40, 50];

arr[0];             // 10 (first)
arr[arr.length - 1]; // 50 (last)
arr[2];             // 30 (third)
arr[-1];            // undefined (no negative indexing in JS)
arr.at(-1);         // 50 (ES2022 — negative indexing)
vector<int> arr = {10, 20, 30, 40, 50};

arr[0];             // 10
arr[arr.size() - 1]; // 50
arr.at(2);          // 30 (with bounds checking)
arr.front();        // 10
arr.back();         // 50

Traversal

JavaScript

const fruits = ["apple", "banana", "cherry"];

// for loop
for (let i = 0; i < fruits.length; i++) {
    console.log(i, fruits[i]);
}

// for...of
for (const fruit of fruits) {
    console.log(fruit);
}

// forEach
fruits.forEach((fruit, i) => console.log(i, fruit));

C++

vector<string> fruits = {"apple", "banana", "cherry"};

// Index-based
for (int i = 0; i < fruits.size(); i++) {
    cout << i << " " << fruits[i] << endl;
}

// Range-based
for (const auto& fruit : fruits) {
    cout << fruit << endl;
}

Basic operations

Insertion

Before:  [10, 20, 30, 40]
Insert 25 at index 2:
Step 1: Shift right  → [10, 20, __, 30, 40]
Step 2: Place 25     → [10, 20, 25, 30, 40]
const arr = [10, 20, 30, 40];

// At end — O(1)
arr.push(50);         // [10, 20, 30, 40, 50]

// At beginning — O(n)
arr.unshift(5);       // [5, 10, 20, 30, 40, 50]

// At index — O(n)
arr.splice(2, 0, 25); // [5, 10, 25, 20, 30, 40, 50]
vector<int> arr = {10, 20, 30, 40};

// At end — O(1) amortized
arr.push_back(50);

// At beginning — O(n)
arr.insert(arr.begin(), 5);

// At index 2 — O(n)
arr.insert(arr.begin() + 2, 25);

Deletion

Before:  [10, 20, 30, 40, 50]
Delete at index 2:
Step 1: Remove 30    → [10, 20, __, 40, 50]
Step 2: Shift left   → [10, 20, 40, 50]
const arr = [10, 20, 30, 40, 50];

// From end — O(1)
arr.pop();            // removes 50

// From beginning — O(n)
arr.shift();          // removes 10

// At index — O(n)
arr.splice(1, 1);     // removes element at index 1
vector<int> arr = {10, 20, 30, 40, 50};

// From end — O(1)
arr.pop_back();

// At index — O(n)
arr.erase(arr.begin() + 1);

Update

arr[2] = 99;  // O(1) — direct access
arr[2] = 99;  // O(1)

Array operations complexity

OperationArray (JS)vector (C++)
Access by indexO(1)O(1)
Push (end)O(1) amortizedO(1) amortized
Pop (end)O(1)O(1)
Unshift (front)O(n)O(n)
Shift (front)O(n)O(n)
Insert at indexO(n)O(n)
Delete at indexO(n)O(n)
Search (unsorted)O(n)O(n)
Search (sorted)O(log n)O(log n)

Common array methods

JavaScript

const arr = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3];

arr.length;                    // 10
arr.includes(4);               // true
arr.indexOf(5);                // 4 (first occurrence)
arr.lastIndexOf(5);            // 8
arr.find(x => x > 4);         // 5 (first match)
arr.findIndex(x => x > 4);    // 4

// Transformations (return new array)
arr.map(x => x * 2);          // [6, 2, 8, ...]
arr.filter(x => x > 3);       // [4, 5, 9, 6, 5]
arr.reduce((sum, x) => sum + x, 0);  // 39

// Sorting (mutates)
arr.sort((a, b) => a - b);    // ascending
arr.reverse();                 // in-place reverse

// Slicing (does not mutate)
arr.slice(2, 5);               // elements at index 2, 3, 4
arr.concat([7, 8]);            // new array with appended elements

C++

#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;

vector<int> arr = {3, 1, 4, 1, 5, 9, 2, 6, 5, 3};

// Size
arr.size();

// Search
find(arr.begin(), arr.end(), 4);  // iterator to first 4

// Sort
sort(arr.begin(), arr.end());  // ascending

// Reverse
reverse(arr.begin(), arr.end());

// Sum
accumulate(arr.begin(), arr.end(), 0);  // 39

// Min / Max
*min_element(arr.begin(), arr.end());
*max_element(arr.begin(), arr.end());

Reverse an array in-place

Before: [1, 2, 3, 4, 5]

Step 1: swap(0, 4) → [5, 2, 3, 4, 1]
Step 2: swap(1, 3) → [5, 4, 3, 2, 1]
Step 3: left=2, right=2 → stop

After:  [5, 4, 3, 2, 1]
function reverseArray(arr) {
    let left = 0, right = arr.length - 1;
    while (left < right) {
        [arr[left], arr[right]] = [arr[right], arr[left]];
        left++;
        right--;
    }
    return arr;
}
void reverseArray(vector<int>& arr) {
    int left = 0, right = arr.size() - 1;
    while (left < right) {
        swap(arr[left], arr[right]);
        left++;
        right--;
    }
}

Time: O(n) | Space: O(1)


Find max and min

function findMinMax(arr) {
    let min = arr[0], max = arr[0];
    for (let i = 1; i < arr.length; i++) {
        if (arr[i] < min) min = arr[i];
        if (arr[i] > max) max = arr[i];
    }
    return { min, max };
}
pair<int,int> findMinMax(const vector<int>& arr) {
    int mn = arr[0], mx = arr[0];
    for (int i = 1; i < arr.size(); i++) {
        mn = min(mn, arr[i]);
        mx = max(mx, arr[i]);
    }
    return {mn, mx};
}

Remove duplicates from sorted array

Input:  [1, 1, 2, 2, 3, 4, 4, 5]

i=0: writeIdx=1, arr[1]=2 → [1, 2, ...]
i=1: skip (same as prev)
i=2: writeIdx=2, arr[2]=3 → [1, 2, 3, ...]
...

Output: [1, 2, 3, 4, 5] (first 5 elements)
function removeDuplicates(arr) {
    if (arr.length === 0) return 0;
    let writeIdx = 1;
    for (let i = 1; i < arr.length; i++) {
        if (arr[i] !== arr[i - 1]) {
            arr[writeIdx] = arr[i];
            writeIdx++;
        }
    }
    return writeIdx;
}
int removeDuplicates(vector<int>& arr) {
    if (arr.empty()) return 0;
    int writeIdx = 1;
    for (int i = 1; i < arr.size(); i++) {
        if (arr[i] != arr[i-1]) {
            arr[writeIdx++] = arr[i];
        }
    }
    return writeIdx;
}

Time: O(n) | Space: O(1)


Scenario bank (array basics)

7.3a-001 — Find the second largest element in an array (variation 1)

  • Level: Beginner
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-002 — Rotate an array by k positions to the right (variation 2)

  • Level: Beginner
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-003 — Move all zeros to the end of the array (variation 3)

  • Level: Beginner
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-004 — Check if an array is sorted (variation 4)

  • Level: Beginner
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-005 — Merge two sorted arrays into one sorted array (variation 5)

  • Level: Beginner
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-006 — Find the missing number in 1 to N (variation 6)

  • Level: Beginner
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-007 — Count frequency of each element (variation 7)

  • Level: Beginner
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-008 — Find intersection of two arrays (variation 8)

  • Level: Beginner
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-009 — Find union of two arrays (variation 9)

  • Level: Beginner
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-010 — Check if two arrays are equal (same elements, same order) (variation 10)

  • Level: Beginner
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-011 — Left rotate an array by one position (variation 11)

  • Level: Beginner
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-012 — Find the element that appears once (others appear twice) (variation 12)

  • Level: Beginner
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-013 — Rearrange array in alternating positive and negative (variation 13)

  • Level: Beginner
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-014 — Find leaders in an array (greater than all to the right) (variation 14)

  • Level: Beginner
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-015 — Find the largest sum contiguous subarray (Kadane intro) (variation 15)

  • Level: Beginner
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-016 — Remove a specific value from array in-place (variation 16)

  • Level: Beginner
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-017 — Find the duplicate in an array of n+1 elements (1 to n) (variation 17)

  • Level: Beginner
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-018 — Separate even and odd numbers (variation 18)

  • Level: Beginner
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-019 — Find the kth smallest element (partial sort) (variation 19)

  • Level: Beginner
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-020 — Check if array can be divided into pairs with sum divisible by k (variation 20)

  • Level: Beginner
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-021 — Find the second largest element in an array (variation 21)

  • Level: Beginner
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-022 — Rotate an array by k positions to the right (variation 22)

  • Level: Beginner
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-023 — Move all zeros to the end of the array (variation 23)

  • Level: Beginner
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-024 — Check if an array is sorted (variation 24)

  • Level: Beginner
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-025 — Merge two sorted arrays into one sorted array (variation 25)

  • Level: Beginner
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-026 — Find the missing number in 1 to N (variation 26)

  • Level: Beginner
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-027 — Count frequency of each element (variation 27)

  • Level: Beginner
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-028 — Find intersection of two arrays (variation 28)

  • Level: Beginner
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-029 — Find union of two arrays (variation 29)

  • Level: Beginner
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-030 — Check if two arrays are equal (same elements, same order) (variation 30)

  • Level: Beginner
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-031 — Left rotate an array by one position (variation 31)

  • Level: Beginner
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-032 — Find the element that appears once (others appear twice) (variation 32)

  • Level: Beginner
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-033 — Rearrange array in alternating positive and negative (variation 33)

  • Level: Beginner
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-034 — Find leaders in an array (greater than all to the right) (variation 34)

  • Level: Beginner
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-035 — Find the largest sum contiguous subarray (Kadane intro) (variation 35)

  • Level: Beginner
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-036 — Remove a specific value from array in-place (variation 36)

  • Level: Beginner
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-037 — Find the duplicate in an array of n+1 elements (1 to n) (variation 37)

  • Level: Beginner
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-038 — Separate even and odd numbers (variation 38)

  • Level: Beginner
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-039 — Find the kth smallest element (partial sort) (variation 39)

  • Level: Beginner
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-040 — Check if array can be divided into pairs with sum divisible by k (variation 40)

  • Level: Beginner
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-041 — Find the second largest element in an array (variation 41)

  • Level: Beginner
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-042 — Rotate an array by k positions to the right (variation 42)

  • Level: Beginner
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-043 — Move all zeros to the end of the array (variation 43)

  • Level: Beginner
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-044 — Check if an array is sorted (variation 44)

  • Level: Beginner
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-045 — Merge two sorted arrays into one sorted array (variation 45)

  • Level: Beginner
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-046 — Find the missing number in 1 to N (variation 46)

  • Level: Beginner
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-047 — Count frequency of each element (variation 47)

  • Level: Beginner
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-048 — Find intersection of two arrays (variation 48)

  • Level: Beginner
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-049 — Find union of two arrays (variation 49)

  • Level: Beginner
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-050 — Check if two arrays are equal (same elements, same order) (variation 50)

  • Level: Beginner
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-051 — Left rotate an array by one position (variation 51)

  • Level: Intermediate
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-052 — Find the element that appears once (others appear twice) (variation 52)

  • Level: Intermediate
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-053 — Rearrange array in alternating positive and negative (variation 53)

  • Level: Intermediate
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-054 — Find leaders in an array (greater than all to the right) (variation 54)

  • Level: Intermediate
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-055 — Find the largest sum contiguous subarray (Kadane intro) (variation 55)

  • Level: Intermediate
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-056 — Remove a specific value from array in-place (variation 56)

  • Level: Intermediate
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-057 — Find the duplicate in an array of n+1 elements (1 to n) (variation 57)

  • Level: Intermediate
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-058 — Separate even and odd numbers (variation 58)

  • Level: Intermediate
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-059 — Find the kth smallest element (partial sort) (variation 59)

  • Level: Intermediate
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-060 — Check if array can be divided into pairs with sum divisible by k (variation 60)

  • Level: Intermediate
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-061 — Find the second largest element in an array (variation 61)

  • Level: Intermediate
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-062 — Rotate an array by k positions to the right (variation 62)

  • Level: Intermediate
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-063 — Move all zeros to the end of the array (variation 63)

  • Level: Intermediate
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-064 — Check if an array is sorted (variation 64)

  • Level: Intermediate
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-065 — Merge two sorted arrays into one sorted array (variation 65)

  • Level: Intermediate
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-066 — Find the missing number in 1 to N (variation 66)

  • Level: Intermediate
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-067 — Count frequency of each element (variation 67)

  • Level: Intermediate
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-068 — Find intersection of two arrays (variation 68)

  • Level: Intermediate
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-069 — Find union of two arrays (variation 69)

  • Level: Intermediate
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-070 — Check if two arrays are equal (same elements, same order) (variation 70)

  • Level: Intermediate
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-071 — Left rotate an array by one position (variation 71)

  • Level: Intermediate
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-072 — Find the element that appears once (others appear twice) (variation 72)

  • Level: Intermediate
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-073 — Rearrange array in alternating positive and negative (variation 73)

  • Level: Intermediate
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-074 — Find leaders in an array (greater than all to the right) (variation 74)

  • Level: Intermediate
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-075 — Find the largest sum contiguous subarray (Kadane intro) (variation 75)

  • Level: Intermediate
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-076 — Remove a specific value from array in-place (variation 76)

  • Level: Intermediate
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-077 — Find the duplicate in an array of n+1 elements (1 to n) (variation 77)

  • Level: Intermediate
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-078 — Separate even and odd numbers (variation 78)

  • Level: Intermediate
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-079 — Find the kth smallest element (partial sort) (variation 79)

  • Level: Intermediate
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-080 — Check if array can be divided into pairs with sum divisible by k (variation 80)

  • Level: Intermediate
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-081 — Find the second largest element in an array (variation 81)

  • Level: Intermediate
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-082 — Rotate an array by k positions to the right (variation 82)

  • Level: Intermediate
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-083 — Move all zeros to the end of the array (variation 83)

  • Level: Intermediate
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-084 — Check if an array is sorted (variation 84)

  • Level: Intermediate
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-085 — Merge two sorted arrays into one sorted array (variation 85)

  • Level: Intermediate
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-086 — Find the missing number in 1 to N (variation 86)

  • Level: Intermediate
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-087 — Count frequency of each element (variation 87)

  • Level: Intermediate
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-088 — Find intersection of two arrays (variation 88)

  • Level: Intermediate
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-089 — Find union of two arrays (variation 89)

  • Level: Intermediate
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-090 — Check if two arrays are equal (same elements, same order) (variation 90)

  • Level: Intermediate
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-091 — Left rotate an array by one position (variation 91)

  • Level: Intermediate
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-092 — Find the element that appears once (others appear twice) (variation 92)

  • Level: Intermediate
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-093 — Rearrange array in alternating positive and negative (variation 93)

  • Level: Intermediate
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-094 — Find leaders in an array (greater than all to the right) (variation 94)

  • Level: Intermediate
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-095 — Find the largest sum contiguous subarray (Kadane intro) (variation 95)

  • Level: Intermediate
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-096 — Remove a specific value from array in-place (variation 96)

  • Level: Intermediate
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-097 — Find the duplicate in an array of n+1 elements (1 to n) (variation 97)

  • Level: Intermediate
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-098 — Separate even and odd numbers (variation 98)

  • Level: Intermediate
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-099 — Find the kth smallest element (partial sort) (variation 99)

  • Level: Intermediate
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-100 — Check if array can be divided into pairs with sum divisible by k (variation 100)

  • Level: Intermediate
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-101 — Find the second largest element in an array (variation 101)

  • Level: Intermediate
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-102 — Rotate an array by k positions to the right (variation 102)

  • Level: Intermediate
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-103 — Move all zeros to the end of the array (variation 103)

  • Level: Intermediate
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-104 — Check if an array is sorted (variation 104)

  • Level: Intermediate
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-105 — Merge two sorted arrays into one sorted array (variation 105)

  • Level: Intermediate
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-106 — Find the missing number in 1 to N (variation 106)

  • Level: Intermediate
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-107 — Count frequency of each element (variation 107)

  • Level: Intermediate
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-108 — Find intersection of two arrays (variation 108)

  • Level: Intermediate
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-109 — Find union of two arrays (variation 109)

  • Level: Intermediate
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-110 — Check if two arrays are equal (same elements, same order) (variation 110)

  • Level: Intermediate
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-111 — Left rotate an array by one position (variation 111)

  • Level: Intermediate
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-112 — Find the element that appears once (others appear twice) (variation 112)

  • Level: Intermediate
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-113 — Rearrange array in alternating positive and negative (variation 113)

  • Level: Intermediate
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-114 — Find leaders in an array (greater than all to the right) (variation 114)

  • Level: Intermediate
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-115 — Find the largest sum contiguous subarray (Kadane intro) (variation 115)

  • Level: Intermediate
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-116 — Remove a specific value from array in-place (variation 116)

  • Level: Intermediate
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-117 — Find the duplicate in an array of n+1 elements (1 to n) (variation 117)

  • Level: Intermediate
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-118 — Separate even and odd numbers (variation 118)

  • Level: Intermediate
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-119 — Find the kth smallest element (partial sort) (variation 119)

  • Level: Intermediate
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-120 — Check if array can be divided into pairs with sum divisible by k (variation 120)

  • Level: Intermediate
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-121 — Find the second largest element in an array (variation 121)

  • Level: Advanced
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-122 — Rotate an array by k positions to the right (variation 122)

  • Level: Advanced
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-123 — Move all zeros to the end of the array (variation 123)

  • Level: Advanced
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-124 — Check if an array is sorted (variation 124)

  • Level: Advanced
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-125 — Merge two sorted arrays into one sorted array (variation 125)

  • Level: Advanced
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-126 — Find the missing number in 1 to N (variation 126)

  • Level: Advanced
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-127 — Count frequency of each element (variation 127)

  • Level: Advanced
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-128 — Find intersection of two arrays (variation 128)

  • Level: Advanced
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-129 — Find union of two arrays (variation 129)

  • Level: Advanced
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-130 — Check if two arrays are equal (same elements, same order) (variation 130)

  • Level: Advanced
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-131 — Left rotate an array by one position (variation 131)

  • Level: Advanced
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-132 — Find the element that appears once (others appear twice) (variation 132)

  • Level: Advanced
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-133 — Rearrange array in alternating positive and negative (variation 133)

  • Level: Advanced
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-134 — Find leaders in an array (greater than all to the right) (variation 134)

  • Level: Advanced
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-135 — Find the largest sum contiguous subarray (Kadane intro) (variation 135)

  • Level: Advanced
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-136 — Remove a specific value from array in-place (variation 136)

  • Level: Advanced
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-137 — Find the duplicate in an array of n+1 elements (1 to n) (variation 137)

  • Level: Advanced
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-138 — Separate even and odd numbers (variation 138)

  • Level: Advanced
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-139 — Find the kth smallest element (partial sort) (variation 139)

  • Level: Advanced
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-140 — Check if array can be divided into pairs with sum divisible by k (variation 140)

  • Level: Advanced
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-141 — Find the second largest element in an array (variation 141)

  • Level: Advanced
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-142 — Rotate an array by k positions to the right (variation 142)

  • Level: Advanced
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-143 — Move all zeros to the end of the array (variation 143)

  • Level: Advanced
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-144 — Check if an array is sorted (variation 144)

  • Level: Advanced
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-145 — Merge two sorted arrays into one sorted array (variation 145)

  • Level: Advanced
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-146 — Find the missing number in 1 to N (variation 146)

  • Level: Advanced
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-147 — Count frequency of each element (variation 147)

  • Level: Advanced
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-148 — Find intersection of two arrays (variation 148)

  • Level: Advanced
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-149 — Find union of two arrays (variation 149)

  • Level: Advanced
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-150 — Check if two arrays are equal (same elements, same order) (variation 150)

  • Level: Advanced
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-151 — Left rotate an array by one position (variation 151)

  • Level: Advanced
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-152 — Find the element that appears once (others appear twice) (variation 152)

  • Level: Advanced
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-153 — Rearrange array in alternating positive and negative (variation 153)

  • Level: Advanced
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-154 — Find leaders in an array (greater than all to the right) (variation 154)

  • Level: Advanced
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-155 — Find the largest sum contiguous subarray (Kadane intro) (variation 155)

  • Level: Advanced
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-156 — Remove a specific value from array in-place (variation 156)

  • Level: Advanced
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-157 — Find the duplicate in an array of n+1 elements (1 to n) (variation 157)

  • Level: Advanced
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-158 — Separate even and odd numbers (variation 158)

  • Level: Advanced
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-159 — Find the kth smallest element (partial sort) (variation 159)

  • Level: Advanced
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-160 — Check if array can be divided into pairs with sum divisible by k (variation 160)

  • Level: Advanced
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-161 — Find the second largest element in an array (variation 161)

  • Level: Advanced
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-162 — Rotate an array by k positions to the right (variation 162)

  • Level: Advanced
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-163 — Move all zeros to the end of the array (variation 163)

  • Level: Advanced
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-164 — Check if an array is sorted (variation 164)

  • Level: Advanced
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-165 — Merge two sorted arrays into one sorted array (variation 165)

  • Level: Advanced
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-166 — Find the missing number in 1 to N (variation 166)

  • Level: Advanced
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-167 — Count frequency of each element (variation 167)

  • Level: Advanced
  • Approach: Single pass
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-168 — Find intersection of two arrays (variation 168)

  • Level: Advanced
  • Approach: Two pointers
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-169 — Find union of two arrays (variation 169)

  • Level: Advanced
  • Approach: Hash map
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.

7.3a-170 — Check if two arrays are equal (same elements, same order) (variation 170)

  • Level: Advanced
  • Approach: Sorting
  • Time: O(n) or O(n log n) depending on approach.
  • Space: O(1) or O(n) depending on approach.
  • Edge cases: empty array, single element, all same, all negative.
  • JS & C++: Implement in both languages.