DSA cheatsheet
Syntax snippets and quick notes for revision.
DSA Introduction
function uniqueValues(values) {
const seen = new Set();
return values.filter((value) => {
if (seen.has(value)) return false;
seen.add(value);
return true;
});
}Use this dsa introduction pattern when a DSA task needs a small, readable starting point.
Time Complexity
function uniqueValues(values) {
const seen = new Set();
return values.filter((value) => {
if (seen.has(value)) return false;
seen.add(value);
return true;
});
}Use this time complexity pattern when a DSA task needs a small, readable starting point.
Space Complexity
function uniqueValues(values) {
const seen = new Set();
return values.filter((value) => {
if (seen.has(value)) return false;
seen.add(value);
return true;
});
}Use this space complexity pattern when a DSA task needs a small, readable starting point.
Arrays
function uniqueValues(values) {
const seen = new Set();
return values.filter((value) => {
if (seen.has(value)) return false;
seen.add(value);
return true;
});
}Use this arrays pattern when a DSA task needs a small, readable starting point.
Strings
function uniqueValues(values) {
const seen = new Set();
return values.filter((value) => {
if (seen.has(value)) return false;
seen.add(value);
return true;
});
}Use this strings pattern when a DSA task needs a small, readable starting point.
Objects and Hash Maps
function uniqueValues(values) {
const seen = new Set();
return values.filter((value) => {
if (seen.has(value)) return false;
seen.add(value);
return true;
});
}Use this objects and hash maps pattern when a DSA task needs a small, readable starting point.
Recursion
function uniqueValues(values) {
const seen = new Set();
return values.filter((value) => {
if (seen.has(value)) return false;
seen.add(value);
return true;
});
}Use this recursion pattern when a DSA task needs a small, readable starting point.
Sorting
function uniqueValues(values) {
const seen = new Set();
return values.filter((value) => {
if (seen.has(value)) return false;
seen.add(value);
return true;
});
}Use this sorting pattern when a DSA task needs a small, readable starting point.
Searching
function uniqueValues(values) {
const seen = new Set();
return values.filter((value) => {
if (seen.has(value)) return false;
seen.add(value);
return true;
});
}Use this searching pattern when a DSA task needs a small, readable starting point.
Stack
function uniqueValues(values) {
const seen = new Set();
return values.filter((value) => {
if (seen.has(value)) return false;
seen.add(value);
return true;
});
}Use this stack pattern when a DSA task needs a small, readable starting point.
Queue
function uniqueValues(values) {
const seen = new Set();
return values.filter((value) => {
if (seen.has(value)) return false;
seen.add(value);
return true;
});
}Use this queue pattern when a DSA task needs a small, readable starting point.
Linked List
function uniqueValues(values) {
const seen = new Set();
return values.filter((value) => {
if (seen.has(value)) return false;
seen.add(value);
return true;
});
}Use this linked list pattern when a DSA task needs a small, readable starting point.