bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch
🌱Newbie
0 XP
Back to starter track
āœļøFill the BlankjavascriptEasyArrays & Hashing

Starter: create a value

Drag the value that makes the name useful. Goal: Create a string value, store it in a variable, then return that variable.

Starter step 1 of 20Read code one line at a time

Recognize that a variable can hold a helper object.

Find the right-hand side of the assignment before worrying about the loop.

Problem Brief

Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.

Puzzle Hints
  1. Read the blank inside this exact statement: "const name = ___;".

  2. A variable starts by holding a concrete value. Here the name stores a string. The correct token works because it preserves the goal: Create a string value, store it in a variable, then return that variable.

  3. Check the variable that is read immediately after the blank; that usually tells you what the blank must produce.

Asked at 12 companies
AdobeAirbnbAmazon
Contains Duplicate — HashSet
hashmap
nums1231
1
5

Input: [1,2,3,1]. Use HashSet to detect duplicates

Map & Set in JavaScriptref

JavaScript provides Map for key-value pairs and Set for unique values. Both offer O(1) average lookup, insert, and delete. Unlike plain objects, Map preserves insertion order and allows any type as keys.

-new Map() — O(1) get/set/has/delete
-new Set() — O(1) add/has/delete, auto-deduplicates
-Map.get(key) returns undefined if missing
-for...of iterates Map entries as [key, value]
const map = new Map();
map.set('a', 1);    // set key-value
map.get('a');        // 1
map.has('a');        // true

const set = new Set([1, 2, 2, 3]);
set.size;            // 3 (deduped)
set.has(2);          // true
Official docs →
Map & Set in JavaScriptref

JavaScript provides Map for key-value pairs and Set for unique values. Both offer O(1) average lookup, insert, and delete. Unlike plain objects, Map preserves insertion order and allows any type as keys.

-new Map() — O(1) get/set/has/delete
-new Set() — O(1) add/has/delete, auto-deduplicates
-Map.get(key) returns undefined if missing
-for...of iterates Map entries as [key, value]
const map = new Map();
map.set('a', 1);    // set key-value
map.get('a');        // 1
map.has('a');        // true

const set = new Set([1, 2, 2, 3]);
set.size;            // 3 (deduped)
set.has(2);          // true
Official docs →
How to think: Hash Map / Setguide

You need O(1) lookups — checking if something exists, counting frequencies, or finding pairs.

1.Ask: "Am I searching for something repeatedly?" → Hash Map
2.Ask: "Do I need to check existence?" → Set
3.Ask: "Do I need to count occurrences?" → Map with value = count
4.Ask: "Do I need to find a pair that satisfies a condition?" → Store complement in Map
5.The tradeoff: O(n) extra space buys you O(1) per lookup

vs Nested loops (O(n²)): You're comparing every element against every other — a Map does it in one pass

vs Sorting (O(n log n)): You just need existence/frequency checks, not order

find pairtwo numbers thatfrequencycountduplicateanagramgroup by
How to think: Hash Map / Setguide

You need O(1) lookups — checking if something exists, counting frequencies, or finding pairs.

1.Ask: "Am I searching for something repeatedly?" → Hash Map
2.Ask: "Do I need to check existence?" → Set
3.Ask: "Do I need to count occurrences?" → Map with value = count
4.Ask: "Do I need to find a pair that satisfies a condition?" → Store complement in Map
5.The tradeoff: O(n) extra space buys you O(1) per lookup

vs Nested loops (O(n²)): You're comparing every element against every other — a Map does it in one pass

vs Sorting (O(n log n)): You just need existence/frequency checks, not order

find pairtwo numbers thatfrequencycountduplicateanagramgroup by

Drag tokens into the blanks

null
"Ada"
1// Goal: Create a string value, store it in a variable, then return that variable.
2function starterExample() {
3 const name = ___;
4 return name;
5}