01
Variables and types
JavaScript variables can hold different values, and all ordinary numbers use the Number type.
const count = 3;
const label = "items";
console.log(label, count);Output: items 3
Beginner path · JavaScript
Updated 2026-10-21JavaScript suits learners who already build for the web and want to practise DSA without switching languages. Arrays, Map and Set are useful, but JavaScript has no built-in heap and its Number and sorting rules need special attention.
01
JavaScript variables can hold different values, and all ordinary numbers use the Number type.
const count = 3;
const label = "items";
console.log(label, count);Output: items 3
02
Scanning arrays and state machines depend on branches and iteration.
let total = 0;
for (const value of [2, 4, 5]) {
if (value % 2 === 0) total += value;
}
console.log(total);Output: 6
03
Functions keep an algorithm's inputs, output and local state together.
function double(value) {
return value * 2;
}
console.log(double(6));Output: 12
04
Tree traversal and divide-and-conquer call the same function on smaller input.
function countdown(n) {
if (n === 0) return;
console.log(n);
countdown(n - 1);
}
countdown(3);Output: 3
2
1
05
Arrays provide indexed storage and are the base for stacks, queues and heaps.
const numbers = [3, 1, 2];
numbers.push(4);
console.log(numbers[1], numbers.length);Output: 1 4
06
String indexing and slicing appear in parsing, matching and two-pointer problems.
const word = "level";
console.log(word === [...word].reverse().join(""));Output: true
07
Map and Set give direct membership and frequency operations without converting keys to strings.
const seen = new Set([2, 4]);
const counts = new Map([["a", 2]]);
console.log(seen.has(4), counts.get("a"));Output: true 2
08
Array assignment shares the same object; use a shallow or deep copy intentionally.
const first = [1, 2];
const second = [...first, 3];
console.log(first, second);Output: [ 1, 2 ] [ 1, 2, 3 ]
09
A class can model a linked-list or tree node with fields and references.
class Node {
constructor(value) { this.value = value; }
}
console.log(new Node(7).value);Output: 7
10
Array.sort needs an explicit numeric comparator for algorithmic ordering.
const items = [["b", 2], ["a", 1]];
items.sort((a, b) => a[1] - b[1]);
console.log(items);Output: [ [ 'a', 1 ], [ 'b', 2 ] ]
11
Browser exercises often provide a string, while judge runners expose input through a platform-specific harness.
const input = "2 4";
const values = input.trim().split(/\s+/).map(Number);
console.log(values[0] + values[1]);Output: 6
| Structure | JavaScript type | Key operations |
|---|---|---|
| Dynamic array | Array | push/pop at end; indexing O(1) |
| String building | Array + join | push pieces, then join once |
| Hash map | Map | get/set, any key, insertion order |
| Hash set | Set | add/has, any value, insertion order |
| Stack | Array | push/pop at the end |
| Queue | Array + head index | push at end, read then advance head |
| Deque | Array | push/pop at end; avoid shift/unshift |
| Priority queue | None built in | implement a binary heap or use a library |
| Ordered map | None built in | use sorted arrays or a library |
| Sorting | Array.sort | pass (a, b) => a - b for numbers |
Follow the SDE roadmap order. Each topic starts with two Easy problems from the curated set.
Ready to move on when you can solve both without looking at a solution.
Ready to move on when you can solve both without looking at a solution.
Ready to move on when you can solve both without looking at a solution.
Ready to move on when you can solve both without looking at a solution.
Ready to move on when you can solve both without looking at a solution.
Ready to move on when you can solve both without looking at a solution.
Ready to move on when you can solve both without looking at a solution.
Ready to move on when you can solve both without looking at a solution.
Ready to move on when you can solve both without looking at a solution.
Ready to move on when you can solve both without looking at a solution.
Ready to move on when you can solve both without looking at a solution.
Ready to move on when you can solve both without looking at a solution.
Ready to move on when you can solve both without looking at a solution.
Ready to move on when you can solve both without looking at a solution.
Ready to move on when you can solve both without looking at a solution.
Ready to move on when you can solve both without looking at a solution.
Ready to move on when you can solve both without looking at a solution.
Ready to move on when you can solve both without looking at a solution.
Ready to move on when you can solve both without looking at a solution.
Ready to move on when you can solve both without looking at a solution.
Ready to move on when you can solve both without looking at a solution.
Ready to move on when you can solve both without looking at a solution.
Array.prototype.shift is O(n) because the remaining items move. Keep a head index and read queue[head++] instead.
There is no built-in heap or priority queue. Implement a binary heap or use a library when the problem needs one.
Numbers are doubles and integers are exact only up to Number.MAX_SAFE_INTEGER, which is 2^53 - 1. Use BigInt beyond that boundary.
Array.sort compares values as strings by default, so [10, 9, 1].sort() becomes [1, 10, 9]. Pass (a, b) => a - b.
Object keys become strings. Map accepts any key and preserves insertion order, so use it when key identity matters.
Use an array with a head index: push new items at the end and read queue[head++] instead of calling shift.
Array.sort compares string representations by default. Pass (a, b) => a - b for numeric ascending order.
No built-in priority queue exists. Implement a binary heap or choose a small library with the operations your problem needs.