Episode 7 — DSA with JavaScript / 7.11 — Hashing Set and Map

7.11.a — Set & Map Fundamentals

<< 7.11 Overview


What is hashing?

Hashing maps data to a fixed-size value (hash) for O(1) average lookups.

Hash function: key → index
  "apple" → hash → 3
  "banana" → hash → 7
  "cherry" → hash → 1

Bucket array:
  [0]: empty
  [1]: "cherry"
  [2]: empty
  [3]: "apple"
  ...
  [7]: "banana"

Set in JavaScript

A Set stores unique values. No duplicates.

const set = new Set();
set.add(1);           // {1}
set.add(2);           // {1, 2}
set.add(1);           // {1, 2} — duplicate ignored
set.has(1);           // true
set.delete(2);        // {1}
set.size;             // 1
set.clear();          // {}

// From array
const unique = new Set([1, 2, 2, 3, 3, 3]);  // {1, 2, 3}
const arr = [...unique];                       // [1, 2, 3]

Set methods

MethodDescriptionTime
add(value)Add valueO(1)
delete(value)Remove valueO(1)
has(value)Check existenceO(1)
clear()Remove allO(n)
sizeCount of elementsO(1)

C++ — unordered_set

#include <unordered_set>
using namespace std;

unordered_set<int> s;
s.insert(1);           // {1}
s.insert(2);           // {1, 2}
s.count(1);            // 1 (exists)
s.erase(2);            // {1}
s.size();              // 1
s.clear();

Map in JavaScript

A Map stores key-value pairs with O(1) average operations.

const map = new Map();
map.set("name", "Alice");
map.set("age", 25);
map.get("name");          // "Alice"
map.has("age");           // true
map.delete("age");
map.size;                 // 1

// Iteration
for (const [key, value] of map) {
    console.log(`${key}: ${value}`);
}

Map methods

MethodDescriptionTime
set(key, value)Add/updateO(1)
get(key)Retrieve valueO(1)
delete(key)Remove entryO(1)
has(key)Check key existsO(1)
clear()Remove allO(n)
sizeCount of entriesO(1)

C++ — unordered_map

#include <unordered_map>
using namespace std;

unordered_map<string, int> map;
map["name"] = 1;
map.count("name");    // 1
map.erase("name");

Map vs Object in JavaScript

FeatureMapObject
Key typesAny typeString/Symbol only
OrderInsertion orderNot guaranteed
Sizemap.sizeObject.keys(obj).length
PerformanceBetter for frequent add/deleteBetter for static
Iterationfor...of directlyNeed Object.keys()
PrototypeNo inherited keysHas prototype chain

Algorithms using Set & Map

Two Sum (O(n) with Map)

function twoSum(arr, target) {
    const map = new Map();
    for (let i = 0; i < arr.length; i++) {
        const comp = target - arr[i];
        if (map.has(comp)) return [map.get(comp), i];
        map.set(arr[i], i);
    }
    return null;
}

Find duplicates

function findDuplicates(arr) {
    const seen = new Set();
    const dups = new Set();
    for (const x of arr) {
        if (seen.has(x)) dups.add(x);
        else seen.add(x);
    }
    return [...dups];
}

Intersection of two arrays

function intersection(a, b) {
    const setA = new Set(a);
    return b.filter(x => setA.has(x));
}

Group anagrams

function groupAnagrams(strs) {
    const map = new Map();
    for (const s of strs) {
        const key = s.split("").sort().join("");
        if (!map.has(key)) map.set(key, []);
        map.get(key).push(s);
    }
    return [...map.values()];
}

Longest consecutive sequence

function longestConsecutive(nums) {
    const set = new Set(nums);
    let longest = 0;
    for (const n of set) {
        if (!set.has(n - 1)) {
            let len = 1, curr = n;
            while (set.has(curr + 1)) { curr++; len++; }
            longest = Math.max(longest, len);
        }
    }
    return longest;
}

Subarray sum equals K

function subarraySum(nums, k) {
    const map = new Map([[0, 1]]);
    let sum = 0, count = 0;
    for (const n of nums) {
        sum += n;
        if (map.has(sum - k)) count += map.get(sum - k);
        map.set(sum, (map.get(sum) || 0) + 1);
    }
    return count;
}

Valid anagram

function isAnagram(s, t) {
    if (s.length !== t.length) return false;
    const freq = new Map();
    for (const c of s) freq.set(c, (freq.get(c) || 0) + 1);
    for (const c of t) {
        if (!freq.get(c)) return false;
        freq.set(c, freq.get(c) - 1);
    }
    return true;
}

Collision handling

Chaining:
  bucket[3] → "apple" → "date" → null

Open addressing (linear probing):
  hash("apple") = 3, bucket[3] taken → try 4, 5, ...

Scenario bank (hashing)

7.11a-001 — Count frequency of elements (v1)

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

7.11a-002 — Find first repeating element (v2)

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

7.11a-003 — Find first non-repeating element (v3)

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

7.11a-004 — Check if array has duplicates (v4)

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

7.11a-005 — Union and intersection of arrays (v5)

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

7.11a-006 — Longest subarray with equal 0s and 1s (v6)

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

7.11a-007 — Count distinct elements in window (v7)

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

7.11a-008 — Find pair with given sum (v8)

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

7.11a-009 — Top K frequent elements (v9)

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

7.11a-010 — Find all pairs with difference K (v10)

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

7.11a-011 — Group elements by frequency (v11)

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

7.11a-012 — Contiguous array (equal 0s and 1s) (v12)

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

7.11a-013 — Subarray with zero sum (v13)

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

7.11a-014 — Longest substring without repeat (set) (v14)

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

7.11a-015 — Check if permutation exists (v15)

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

7.11a-016 — Count subarrays with distinct count K (v16)

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

7.11a-017 — Design LRU cache (v17)

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

7.11a-018 — Design HashMap from scratch (v18)

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

7.11a-019 — Implement frequency sort (v19)

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

7.11a-020 — Find itinerary reconstruction (v20)

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

7.11a-021 — Count frequency of elements (v21)

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

7.11a-022 — Find first repeating element (v22)

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

7.11a-023 — Find first non-repeating element (v23)

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

7.11a-024 — Check if array has duplicates (v24)

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

7.11a-025 — Union and intersection of arrays (v25)

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

7.11a-026 — Longest subarray with equal 0s and 1s (v26)

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

7.11a-027 — Count distinct elements in window (v27)

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

7.11a-028 — Find pair with given sum (v28)

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

7.11a-029 — Top K frequent elements (v29)

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

7.11a-030 — Find all pairs with difference K (v30)

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

7.11a-031 — Group elements by frequency (v31)

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

7.11a-032 — Contiguous array (equal 0s and 1s) (v32)

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

7.11a-033 — Subarray with zero sum (v33)

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

7.11a-034 — Longest substring without repeat (set) (v34)

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

7.11a-035 — Check if permutation exists (v35)

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

7.11a-036 — Count subarrays with distinct count K (v36)

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

7.11a-037 — Design LRU cache (v37)

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

7.11a-038 — Design HashMap from scratch (v38)

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

7.11a-039 — Implement frequency sort (v39)

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

7.11a-040 — Find itinerary reconstruction (v40)

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

7.11a-041 — Count frequency of elements (v41)

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

7.11a-042 — Find first repeating element (v42)

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

7.11a-043 — Find first non-repeating element (v43)

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

7.11a-044 — Check if array has duplicates (v44)

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

7.11a-045 — Union and intersection of arrays (v45)

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

7.11a-046 — Longest subarray with equal 0s and 1s (v46)

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

7.11a-047 — Count distinct elements in window (v47)

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

7.11a-048 — Find pair with given sum (v48)

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

7.11a-049 — Top K frequent elements (v49)

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

7.11a-050 — Find all pairs with difference K (v50)

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

7.11a-051 — Group elements by frequency (v51)

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

7.11a-052 — Contiguous array (equal 0s and 1s) (v52)

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

7.11a-053 — Subarray with zero sum (v53)

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

7.11a-054 — Longest substring without repeat (set) (v54)

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

7.11a-055 — Check if permutation exists (v55)

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

7.11a-056 — Count subarrays with distinct count K (v56)

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

7.11a-057 — Design LRU cache (v57)

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

7.11a-058 — Design HashMap from scratch (v58)

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

7.11a-059 — Implement frequency sort (v59)

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

7.11a-060 — Find itinerary reconstruction (v60)

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

7.11a-061 — Count frequency of elements (v61)

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

7.11a-062 — Find first repeating element (v62)

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

7.11a-063 — Find first non-repeating element (v63)

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

7.11a-064 — Check if array has duplicates (v64)

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

7.11a-065 — Union and intersection of arrays (v65)

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

7.11a-066 — Longest subarray with equal 0s and 1s (v66)

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

7.11a-067 — Count distinct elements in window (v67)

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

7.11a-068 — Find pair with given sum (v68)

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

7.11a-069 — Top K frequent elements (v69)

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

7.11a-070 — Find all pairs with difference K (v70)

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

7.11a-071 — Group elements by frequency (v71)

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

7.11a-072 — Contiguous array (equal 0s and 1s) (v72)

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

7.11a-073 — Subarray with zero sum (v73)

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

7.11a-074 — Longest substring without repeat (set) (v74)

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

7.11a-075 — Check if permutation exists (v75)

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

7.11a-076 — Count subarrays with distinct count K (v76)

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

7.11a-077 — Design LRU cache (v77)

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

7.11a-078 — Design HashMap from scratch (v78)

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

7.11a-079 — Implement frequency sort (v79)

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

7.11a-080 — Find itinerary reconstruction (v80)

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

7.11a-081 — Count frequency of elements (v81)

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

7.11a-082 — Find first repeating element (v82)

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

7.11a-083 — Find first non-repeating element (v83)

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

7.11a-084 — Check if array has duplicates (v84)

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

7.11a-085 — Union and intersection of arrays (v85)

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

7.11a-086 — Longest subarray with equal 0s and 1s (v86)

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

7.11a-087 — Count distinct elements in window (v87)

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

7.11a-088 — Find pair with given sum (v88)

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

7.11a-089 — Top K frequent elements (v89)

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

7.11a-090 — Find all pairs with difference K (v90)

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

7.11a-091 — Group elements by frequency (v91)

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

7.11a-092 — Contiguous array (equal 0s and 1s) (v92)

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

7.11a-093 — Subarray with zero sum (v93)

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

7.11a-094 — Longest substring without repeat (set) (v94)

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

7.11a-095 — Check if permutation exists (v95)

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

7.11a-096 — Count subarrays with distinct count K (v96)

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

7.11a-097 — Design LRU cache (v97)

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

7.11a-098 — Design HashMap from scratch (v98)

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

7.11a-099 — Implement frequency sort (v99)

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

7.11a-100 — Find itinerary reconstruction (v100)

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

7.11a-101 — Count frequency of elements (v101)

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

7.11a-102 — Find first repeating element (v102)

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

7.11a-103 — Find first non-repeating element (v103)

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

7.11a-104 — Check if array has duplicates (v104)

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

7.11a-105 — Union and intersection of arrays (v105)

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

7.11a-106 — Longest subarray with equal 0s and 1s (v106)

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

7.11a-107 — Count distinct elements in window (v107)

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

7.11a-108 — Find pair with given sum (v108)

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

7.11a-109 — Top K frequent elements (v109)

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

7.11a-110 — Find all pairs with difference K (v110)

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

7.11a-111 — Group elements by frequency (v111)

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

7.11a-112 — Contiguous array (equal 0s and 1s) (v112)

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

7.11a-113 — Subarray with zero sum (v113)

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

7.11a-114 — Longest substring without repeat (set) (v114)

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

7.11a-115 — Check if permutation exists (v115)

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

7.11a-116 — Count subarrays with distinct count K (v116)

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

7.11a-117 — Design LRU cache (v117)

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

7.11a-118 — Design HashMap from scratch (v118)

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

7.11a-119 — Implement frequency sort (v119)

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

7.11a-120 — Find itinerary reconstruction (v120)

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

7.11a-121 — Count frequency of elements (v121)

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

7.11a-122 — Find first repeating element (v122)

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

7.11a-123 — Find first non-repeating element (v123)

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

7.11a-124 — Check if array has duplicates (v124)

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

7.11a-125 — Union and intersection of arrays (v125)

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

7.11a-126 — Longest subarray with equal 0s and 1s (v126)

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

7.11a-127 — Count distinct elements in window (v127)

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

7.11a-128 — Find pair with given sum (v128)

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

7.11a-129 — Top K frequent elements (v129)

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

7.11a-130 — Find all pairs with difference K (v130)

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

7.11a-131 — Group elements by frequency (v131)

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

7.11a-132 — Contiguous array (equal 0s and 1s) (v132)

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

7.11a-133 — Subarray with zero sum (v133)

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

7.11a-134 — Longest substring without repeat (set) (v134)

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

7.11a-135 — Check if permutation exists (v135)

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

7.11a-136 — Count subarrays with distinct count K (v136)

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

7.11a-137 — Design LRU cache (v137)

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

7.11a-138 — Design HashMap from scratch (v138)

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

7.11a-139 — Implement frequency sort (v139)

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

7.11a-140 — Find itinerary reconstruction (v140)

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

7.11a-141 — Count frequency of elements (v141)

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

7.11a-142 — Find first repeating element (v142)

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

7.11a-143 — Find first non-repeating element (v143)

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

7.11a-144 — Check if array has duplicates (v144)

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

7.11a-145 — Union and intersection of arrays (v145)

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

7.11a-146 — Longest subarray with equal 0s and 1s (v146)

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

7.11a-147 — Count distinct elements in window (v147)

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

7.11a-148 — Find pair with given sum (v148)

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

7.11a-149 — Top K frequent elements (v149)

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

7.11a-150 — Find all pairs with difference K (v150)

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

7.11a-151 — Group elements by frequency (v151)

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

7.11a-152 — Contiguous array (equal 0s and 1s) (v152)

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

7.11a-153 — Subarray with zero sum (v153)

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

7.11a-154 — Longest substring without repeat (set) (v154)

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

7.11a-155 — Check if permutation exists (v155)

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

7.11a-156 — Count subarrays with distinct count K (v156)

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

7.11a-157 — Design LRU cache (v157)

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

7.11a-158 — Design HashMap from scratch (v158)

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

7.11a-159 — Implement frequency sort (v159)

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

7.11a-160 — Find itinerary reconstruction (v160)

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

7.11a-161 — Count frequency of elements (v161)

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

7.11a-162 — Find first repeating element (v162)

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

7.11a-163 — Find first non-repeating element (v163)

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

7.11a-164 — Check if array has duplicates (v164)

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

7.11a-165 — Union and intersection of arrays (v165)

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

7.11a-166 — Longest subarray with equal 0s and 1s (v166)

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

7.11a-167 — Count distinct elements in window (v167)

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

7.11a-168 — Find pair with given sum (v168)

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

7.11a-169 — Top K frequent elements (v169)

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

7.11a-170 — Find all pairs with difference K (v170)

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