Facebook

Closest Dessert Cost

LeetCode problem #1774

Sum of Mutated Array Closest to Target

LeetCode problem #1300

0/1 Knapsack

Find maximum value that can be obtained with given weight capacity

Add Two Numbers

Add two numbers represented as linked lists where digits are stored in reverse order

Binary Tree Inorder Traversal

Traverse a binary tree in inorder (left -> root -> right)

Binary Tree Preorder Traversal

Traverse a binary tree in preorder (root -> left -> right)

Boundary Traversal of Binary Tree

Traverse the boundary of a binary tree in anti-clockwise direction.

Breadth-First Search (BFS)

Implement breadth-first search traversal of a graph

Buy and Sell Stock (Maximum Profit)

Find the maximum profit from buying and selling stock with at most one transaction

Celebrity Problem

Find the celebrity in a party of n people using the minimum number of questions.

Check if String is Palindrome

Determine if a string reads the same forwards and backwards, ignoring case and non-alphanumeric characters.

Check if String is Rotation of Another

Determine if one string is a rotation of another string by checking if it can be formed by rotating the characters.

Circular Linked List Detection

Detect if a linked list has a cycle and find the starting point of the cycle

Coin Change (Minimum Coins)

Find the minimum number of coins needed to make a given amount

Coin Change II (Number of Ways)

Count the number of ways to make a given amount using coins

Construct Binary Tree from Preorder and Inorder Traversal

Construct a binary tree from preorder and inorder traversal sequences.

Convert Sorted Array to Binary Search Tree

Convert a sorted array to a height-balanced binary search tree.

Copy List with Random Pointer

Create a deep copy of a linked list where each node has a random pointer

Count and Say

Generate the nth term of the count-and-say sequence.

Count Good Nodes in Binary Tree

Count the number of nodes in a binary tree where the path from root to that node has no nodes with values greater than the current node.

Daily Temperatures

Find the number of days until a warmer temperature for each day.

Decode String

Decode a string encoded with the format k[encoded_string].

Delete Node in a Linked List

Delete a node from a linked list when you only have access to that node

Design Circular Queue

Design a circular queue with fixed size that supports enqueue, dequeue, front, rear, isEmpty, and isFull operations.

Detect Cycle in Directed Graph

Determine if a directed graph contains a cycle

Detect Cycle in Linked List

Detect if a linked list has a cycle using Floyd's cycle detection algorithm

Detect Cycle in Undirected Graph

Determine if an undirected graph contains a cycle

Diameter of Binary Tree

Find the diameter (longest path) of a binary tree.

Edit Distance

Find minimum operations to convert one string to another

Edit Distance (Levenshtein Distance)

Find the minimum number of operations (insert, delete, replace) required to transform one string into another.

Evaluate Reverse Polish Notation

Evaluate the value of an arithmetic expression in Reverse Polish Notation.

Expression Evaluation

Evaluate mathematical expressions with proper operator precedence and parentheses.

Fibonacci Numbers

Calculate the nth Fibonacci number using dynamic programming

Find Majority Element (Boyer-Moore Algorithm)

Find the majority element that appears more than n/2 times using Boyer-Moore majority vote algorithm

Find Middle of Linked List

Find the middle node of a linked list using the two-pointer technique

Find Missing Number (1 to n)

Find the missing number in an array containing n distinct numbers taken from 1, 2, 3, ..., n+1

First Unique Character in String

Find the first non-repeating character in a string and return its index.

Flatten Binary Tree to Linked List

Flatten a binary tree into a linked list in-place using preorder traversal.

Flatten Multilevel Linked List

Flatten a multilevel doubly linked list into a single level

Generate Permutations

Generate all possible permutations of a given string.

Group Anagrams

Group strings that are anagrams of each other together.

House Robber

Find maximum amount that can be robbed without robbing adjacent houses

Implement Queue

Implement a queue using arrays or linked lists with O(1) time complexity for all operations.

Implement Queue using Stacks

Implement a queue using two stacks with O(1) amortized time complexity for all operations.

Implement Stack using Queues

Implement a stack using two queues with O(1) amortized time complexity for all operations.

Implement strStr (Find Substring)

Find the first occurrence of a substring in a string, similar to strstr() function.

Intersection of Two Arrays

Find the intersection of two arrays and return the result as an array.

Intersection of Two Linked Lists

Find the intersection node of two linked lists

Invert Binary Tree

Invert (mirror) a binary tree by swapping left and right children

Level Order Traversal

Traverse a binary tree level by level from left to right.

Longest Common Prefix

Find the longest common prefix string amongst an array of strings.

Longest Common Subsequence

Find the length of the longest common subsequence between two strings

Longest Consecutive Sequence

Find the length of the longest consecutive elements sequence in an unsorted array.

Longest Increasing Subsequence

Find the length of the longest increasing subsequence in an array

Longest Repeated Substring

Find the longest substring that appears at least twice in a string

Lowest Common Ancestor

Find the lowest common ancestor of two nodes in a binary tree.

Max Stack

Design a stack that supports push, pop, top, peekMax, and popMax operations

Maximum Depth of Binary Tree

Find the maximum depth (height) of a binary tree

Maximum Path Sum

Find the maximum path sum in a binary tree.

Maximum Subarray Sum (Kadane's Algorithm)

Find the contiguous subarray with maximum sum using Kadane's algorithm

Merge k Sorted Linked Lists

Merge k sorted linked lists into one sorted linked list

Merge Two Sorted Lists

Merge two sorted linked lists into one sorted linked list

Minimum Insertions to Balance Parentheses

Find minimum insertions needed to balance parentheses string

Minimum Swaps to Sort Array

Find the minimum number of swaps required to sort an array.

Missing Number

Find the missing number in an array containing n distinct numbers taken from 0, 1, 2, ..., n.

Next Greater Element

Find the next greater element for each element in an array.

Number of Islands

Count the number of islands in a 2D grid

Palindrome Linked List

Check if a linked list is a palindrome using O(1) extra space

Partition List

Partition a linked list around a value x such that all nodes less than x come before nodes greater than or equal to x

Path Sum

Check if there exists a root-to-leaf path with given sum.

Postorder Traversal

Traverse binary tree in postorder (left, right, root)

Power of Two

Check if a given integer is a power of two.

Print All Root-to-Leaf Paths

Print all root-to-leaf paths in a binary tree

Product of Array Except Self

Return an array where each element is the product of all elements except the element at that index.

Regular Expression Matching

Implement regular expression matching with '.' and '*'

Remove Duplicates from Sorted List

Remove all duplicate values from a sorted linked list

Remove K Digits

Remove k digits from a number to make it as small as possible

Remove Nth Node From End of List

Remove the nth node from the end of a linked list in one pass

Reorder List

Reorder a linked list by interleaving nodes from the beginning and end

Reverse a Linked List

Reverse a singly linked list in-place

Reverse Bits

Reverse the bits of a given 32-bit unsigned integer.

Reverse Nodes in k-Group

Reverse every k consecutive nodes in a linked list

Reverse String

Reverse a string in-place using O(1) extra memory.

Rotate Linked List

Rotate a linked list to the right by k places

Serialization Formats Comparison

JSON vs Protocol Buffers vs Avro vs Thrift - choosing the right format

Single Number

Find the single number that appears once in an array where every other number appears twice.

Sliding Window Maximum

Find the maximum element in each sliding window of size k.

Sort Linked List

Sort a linked list in O(n log n) time using constant extra space

String Compression

Compress a string by replacing consecutive characters with character and count.

Strongly Connected Components

Find all strongly connected components in a directed graph

Subarray with Given Sum

Find a subarray with a given sum in an array of positive integers.

Swap Nodes in Pairs

Swap every two adjacent nodes in a linked list

Symmetric Tree

Check if a binary tree is symmetric around its center.

Three Sum (Triplets that Sum to Zero)

Find all unique triplets in the array which gives the sum of zero

Topological Sort

Find a linear ordering of vertices in a directed acyclic graph

Two Sum

Find two numbers in an array that add up to a target value.

Unique Paths in Grid

Count unique paths from top-left to bottom-right in a grid

Valid Parentheses

Check if a string containing only parentheses is valid.

Word Break

Determine if a string can be segmented into space-separated words from a dictionary.

Word Break II

Return all possible ways to break a string into dictionary words