Space Complexity
Space complexity is a measure, expressed in Big O notation, of how much memory an algorithm requires to run as a function of the size of its input.
53 resources across 2 libraries
Glossary Terms(6)
Amortized Time Complexity
Amortized time complexity is the average time cost per operation over a worst-case sequence of operations, used to describe algorithms where occasional expensi…
Space Complexity
Space complexity is a measure, expressed in Big O notation, of how much memory an algorithm requires to run as a function of the size of its input.
Master Theorem
The Master Theorem is a formula that directly determines the asymptotic time complexity of divide-and-conquer recurrences of the form T(n) = aT(n/b) + f(n), wi…
Sliding Window Maximum
Sliding Window Maximum refers to both a classic algorithmic problem — finding the maximum element in every contiguous window of fixed size k as it slides acros…
Longest Common Subsequence
Longest Common Subsequence (LCS) is the problem of finding the longest sequence of elements that appears in the same relative order in two given sequences, wit…
Knapsack Problem
The Knapsack Problem is a classic optimization problem in which a set of items, each with a weight and a value, must be selected to maximize total value withou…
Interview Questions(47)
What is Big O Notation?
Big O notation describes how an algorithm’s running time or memory usage grows as the input size grows, focusing on the dominant term and ignoring constant fac…
Merge Sort vs Quick Sort: What is the Difference?
Merge sort splits an array in half, recursively sorts both halves, then merges them, guaranteeing O(n log n) time and stability at the cost of O(n) extra space…
What is the Difference Between Time and Space Complexity?
Time complexity measures how the number of operations an algorithm performs grows with input size, while space complexity measures how the memory it needs grow…
What is the Two Pointer Technique?
The two pointer technique uses two index variables that move through a data structure — typically a sorted array or a linked list — to solve problems in O(n) t…
What is Heap Sort?
Heap sort builds a max-heap from the input array, then repeatedly swaps the root (the current maximum) with the last unsorted element and sifts the reduced hea…
What is Insertion Sort?
Insertion sort builds the final sorted array one element at a time by taking each new element and shifting it leftward past every larger already-sorted element…
What is Selection Sort?
Selection sort repeatedly scans the unsorted portion of an array to find the minimum element and swaps it into place at the front, giving an O(n²) comparison-b…
What is Shell Sort?
Shell sort is an in-place comparison sort that generalizes insertion sort by first comparing and swapping elements far apart using a shrinking gap sequence, mo…
What is Bubble Sort?
Bubble sort repeatedly steps through an array comparing each pair of adjacent elements and swapping them if they are out of order, so on every full pass the la…
Solve the Two Sum Problem
The optimal solution to Two Sum scans the array once while keeping a hash map of value to index, checking on every element whether its complement (target minus…
What is Kadane's Algorithm?
Kadane's algorithm finds the maximum sum of a contiguous subarray in O(n) time and O(1) space by scanning once and, at each position, deciding whether to exten…
What is the Dutch National Flag Problem?
The Dutch National Flag problem asks you to sort an array containing only three distinct values (classically 0s, 1s, and 2s) into three contiguous groups in a…
How Do You Solve the Trapping Rain Water Problem?
The Trapping Rain Water problem, given an array of bar heights, is solved optimally with a two-pointer approach in O(n) time and O(1) space: water trapped abov…
Edit Distance Problem: How Would You Solve It?
Edit distance (Levenshtein distance) is solved with dynamic programming: dp[i][j] holds the minimum number of insertions, deletions, and substitutions to turn…
How Do You Find the Longest Common Subsequence?
The longest common subsequence (LCS) of two strings is the longest sequence of characters that appears in both strings in the same relative order but not neces…
How Do You Find the Longest Increasing Subsequence?
The longest increasing subsequence (LIS) is the longest subsequence of an array in which elements strictly increase, solvable in O(n^2) with straightforward dy…
How Do You Find the Longest Common Substring?
The longest common substring is the longest contiguous block of characters that appears identically in both strings, found with a 2D dynamic programming table…
How Do You Solve the Subset Sum Problem?
Subset sum asks whether some subset of a given set of numbers adds up exactly to a target value, solved with a 2D (or space-optimized 1D) dynamic programming t…
What is a Bloom Filter?
A Bloom filter is a space-efficient probabilistic data structure that tests whether an element is possibly in a set or definitely not in a set, using a bit arr…
How Do You Detect a Cycle in a Linked List?
You detect a cycle in a linked list by walking it with two pointers moving at different speeds — a slow pointer advancing one node at a time and a fast pointer…
What is Floyd’s Cycle Detection Algorithm?
Floyd’s cycle detection algorithm, also called the tortoise-and-hare algorithm, finds whether a linked structure contains a cycle and, with a second phase, loc…
How Do You Find the Middle of a Linked List?
You find the middle of a linked list in a single pass using the slow-fast pointer technique: advance a slow pointer one node at a time and a fast pointer two n…
How Do You Clone a Linked List with a Random Pointer?
You clone a linked list where each node has both a next pointer and a random pointer (which may point anywhere in the list or to null) by first mapping every o…
How Would You Design a Min Stack?
A min stack supports push, pop, top, and getMin all in O(1) by maintaining a second, auxiliary stack that tracks the minimum value at each point in the main st…
Showing 24 of 47.