DEV Community

Leetcode Solutions Series' Articles

Back to seanpgallivan's Series
Solution: Next Permutation
Cover image for Solution: Next Permutation

Solution: Next Permutation

101
Comments
3 min read
Solution: Trim a Binary Search Tree
Cover image for Solution: Trim a Binary Search Tree

Solution: Trim a Binary Search Tree

23
Comments
3 min read
Leetcode Solutions Index
Cover image for Leetcode Solutions Index

Leetcode Solutions Index

59
Comments 2
11 min read
Solution: Minimize Deviation in Array
Cover image for Solution: Minimize Deviation in Array

Solution: Minimize Deviation in Array

6
Comments 2
4 min read
Solution: Vertical Order Traversal of a Binary Tree
Cover image for Solution: Vertical Order Traversal of a Binary Tree

Solution: Vertical Order Traversal of a Binary Tree

5
Comments
4 min read
Solution: Count Ways to Make Array With Product
Cover image for Solution: Count Ways to Make Array With Product

Solution: Count Ways to Make Array With Product

3
Comments
5 min read
Solution: Smallest String With A Given Numeric Value
Cover image for Solution: Smallest String With A Given Numeric Value

Solution: Smallest String With A Given Numeric Value

2
Comments 2
3 min read
Solution: Linked List Cycle
Cover image for Solution: Linked List Cycle

Solution: Linked List Cycle

6
Comments
3 min read
Solution: Path With Minimum Effort
Cover image for Solution: Path With Minimum Effort

Solution: Path With Minimum Effort

5
Comments
4 min read
Solution: Concatenation of Consecutive Binary Numbers
Cover image for Solution: Concatenation of Consecutive Binary Numbers

Solution: Concatenation of Consecutive Binary Numbers

5
Comments
2 min read
Solution: Minimum Operations to Make a Subsequence
Cover image for Solution: Minimum Operations to Make a Subsequence

Solution: Minimum Operations to Make a Subsequence

6
Comments
3 min read
Solution: Longest Harmonious Subsequence
Cover image for Solution: Longest Harmonious Subsequence

Solution: Longest Harmonious Subsequence

4
Comments
2 min read
Solution: Simplify Path
Cover image for Solution: Simplify Path

Solution: Simplify Path

5
Comments
3 min read
Solution: Building Boxes
Cover image for Solution: Building Boxes

Solution: Building Boxes

4
Comments
3 min read
Solution: Decode XORed Permutation
Cover image for Solution: Decode XORed Permutation

Solution: Decode XORed Permutation

5
Comments
3 min read
Solution: Binary Tree Right Side View
Cover image for Solution: Binary Tree Right Side View

Solution: Binary Tree Right Side View

6
Comments
2 min read
Solution: Find Kth Largest XOR Coordinate Value
Cover image for Solution: Find Kth Largest XOR Coordinate Value

Solution: Find Kth Largest XOR Coordinate Value

6
Comments
5 min read
Solution: Change Minimum Characters to Satisfy One of Three Conditions
Cover image for Solution: Change Minimum Characters to Satisfy One of Three Conditions

Solution: Change Minimum Characters to Satisfy One of Three Conditions

8
Comments
5 min read
Solution: Shortest Distance to a Character
Cover image for Solution: Shortest Distance to a Character

Solution: Shortest Distance to a Character

6
Comments
3 min read
Solution: Peeking Iterator
Cover image for Solution: Peeking Iterator

Solution: Peeking Iterator

5
Comments
3 min read
Solution: Convert BST to Greater Tree
Cover image for Solution: Convert BST to Greater Tree

Solution: Convert BST to Greater Tree

4
Comments
2 min read
Solution: Copy List with Random Pointer
Cover image for Solution: Copy List with Random Pointer

Solution: Copy List with Random Pointer

8
Comments 1
3 min read
Solution: Valid Anagram
Cover image for Solution: Valid Anagram

Solution: Valid Anagram

8
Comments 1
2 min read
Solution: Number of Steps to Reduce a Number to Zero
Cover image for Solution: Number of Steps to Reduce a Number to Zero

Solution: Number of Steps to Reduce a Number to Zero

6
Comments 3
2 min read
Solution: Shortest Path in Binary Matrix
Cover image for Solution: Shortest Path in Binary Matrix

Solution: Shortest Path in Binary Matrix

11
Comments
5 min read
Solution: Is Graph Bipartite?
Cover image for Solution: Is Graph Bipartite?

Solution: Is Graph Bipartite?

5
Comments 1
4 min read
Solution: Maximum Score From Removing Substrings (ver. 1)
Cover image for Solution: Maximum Score From Removing Substrings (ver. 1)

Solution: Maximum Score From Removing Substrings (ver. 1)

6
Comments
4 min read
Solution: Maximum Score From Removing Substrings (ver. 2)
Cover image for Solution: Maximum Score From Removing Substrings (ver. 2)

Solution: Maximum Score From Removing Substrings (ver. 2)

9
Comments
4 min read
Solution: Sort the Matrix Diagonally
Cover image for Solution: Sort the Matrix Diagonally

Solution: Sort the Matrix Diagonally

8
Comments
4 min read
Solution: The K Weakest Rows in a Matrix (ver. 1)
Cover image for Solution: The K Weakest Rows in a Matrix (ver. 1)

Solution: The K Weakest Rows in a Matrix (ver. 1)

6
Comments
4 min read
Solution: The K Weakest Rows in a Matrix (ver. 2)
Cover image for Solution: The K Weakest Rows in a Matrix (ver. 2)

Solution: The K Weakest Rows in a Matrix (ver. 2)

9
Comments
5 min read
Solution: Letter Case Permutation
Cover image for Solution: Letter Case Permutation

Solution: Letter Case Permutation

9
Comments 1
3 min read
Solution: Container With Most Water
Cover image for Solution: Container With Most Water

Solution: Container With Most Water

25
Comments 5
4 min read
Solution: Arithmetic Slices
Cover image for Solution: Arithmetic Slices

Solution: Arithmetic Slices

9
Comments
4 min read
Solution: Minimum Remove to Make Valid Parentheses
Cover image for Solution: Minimum Remove to Make Valid Parentheses

Solution: Minimum Remove to Make Valid Parentheses

10
Comments 1
4 min read
Solution: Roman to Integer
Cover image for Solution: Roman to Integer

Solution: Roman to Integer

84
Comments 25
4 min read
Solution: Broken Calculator
Cover image for Solution: Broken Calculator

Solution: Broken Calculator

9
Comments 2
4 min read
Solution: Find the Most Competitive Subsequence
Cover image for Solution: Find the Most Competitive Subsequence

Solution: Find the Most Competitive Subsequence

7
Comments
3 min read
Solution: Longest Word in Dictionary through Deleting
Cover image for Solution: Longest Word in Dictionary through Deleting

Solution: Longest Word in Dictionary through Deleting

4
Comments
3 min read
Solution: Search a 2D Matrix II
Cover image for Solution: Search a 2D Matrix II

Solution: Search a 2D Matrix II

7
Comments 1
3 min read
Solution: Score of Parentheses
Cover image for Solution: Score of Parentheses

Solution: Score of Parentheses

8
Comments
3 min read
Solution: Shortest Unsorted Continuous Subarray
Cover image for Solution: Shortest Unsorted Continuous Subarray

Solution: Shortest Unsorted Continuous Subarray

8
Comments
4 min read
Solution: Validate Stack Sequences
Cover image for Solution: Validate Stack Sequences

Solution: Validate Stack Sequences

6
Comments
3 min read
Solution: Divide Two Integers (ver. 1)
Cover image for Solution: Divide Two Integers (ver. 1)

Solution: Divide Two Integers (ver. 1)

9
Comments
4 min read
Solution: Divide Two Integers (ver. 2)
Cover image for Solution: Divide Two Integers (ver. 2)

Solution: Divide Two Integers (ver. 2)

7
Comments
3 min read
Solution: Maximum Frequency Stack
Cover image for Solution: Maximum Frequency Stack

Solution: Maximum Frequency Stack

8
Comments
4 min read
Solution: Distribute Candies
Cover image for Solution: Distribute Candies

Solution: Distribute Candies

6
Comments
3 min read
Solution: Set Mismatch (ver. 1)
Cover image for Solution: Set Mismatch (ver. 1)

Solution: Set Mismatch (ver. 1)

10
Comments
3 min read
Solution: Set Mismatch (ver. 2)
Cover image for Solution: Set Mismatch (ver. 2)

Solution: Set Mismatch (ver. 2)

9
Comments 4
3 min read
Solution: Missing Number
Cover image for Solution: Missing Number

Solution: Missing Number

6
Comments 3
2 min read
Solution: Intersection of Two Linked Lists
Cover image for Solution: Intersection of Two Linked Lists

Solution: Intersection of Two Linked Lists

45
Comments 1
4 min read
Solution: Average of Levels in Binary Tree
Cover image for Solution: Average of Levels in Binary Tree

Solution: Average of Levels in Binary Tree

17
Comments
3 min read
Solution: Short Encoding of Words (ver. 1)
Cover image for Solution: Short Encoding of Words (ver. 1)

Solution: Short Encoding of Words (ver. 1)

6
Comments
4 min read
Solution: Design HashMap (ver. 1)
Cover image for Solution: Design HashMap (ver. 1)

Solution: Design HashMap (ver. 1)

25
Comments 3
3 min read
Solution: Short Encoding of Words (ver. 2)
Cover image for Solution: Short Encoding of Words (ver. 2)

Solution: Short Encoding of Words (ver. 2)

8
Comments
5 min read
Solution: Design HashMap (ver. 2)
Cover image for Solution: Design HashMap (ver. 2)

Solution: Design HashMap (ver. 2)

21
Comments
6 min read
Solution: Remove Palindromic Subsequences
Cover image for Solution: Remove Palindromic Subsequences

Solution: Remove Palindromic Subsequences

5
Comments
3 min read
Solution: Add One Row to Tree
Cover image for Solution: Add One Row to Tree

Solution: Add One Row to Tree

13
Comments
4 min read
Solution: Integer to Roman
Cover image for Solution: Integer to Roman

Solution: Integer to Roman

16
Comments 2
3 min read
Solution: Coin Change
Cover image for Solution: Coin Change

Solution: Coin Change

11
Comments 1
4 min read
Solution: Check If a String Contains All Binary Codes of Size K
Cover image for Solution: Check If a String Contains All Binary Codes of Size K

Solution: Check If a String Contains All Binary Codes of Size K

15
Comments
4 min read
Solution: Binary Trees With Factors
Cover image for Solution: Binary Trees With Factors

Solution: Binary Trees With Factors

9
Comments 2
4 min read
Solution: Swapping Nodes in a Linked List
Cover image for Solution: Swapping Nodes in a Linked List

Solution: Swapping Nodes in a Linked List

19
Comments
3 min read
Solution: Encode and Decode TinyURL
Cover image for Solution: Encode and Decode TinyURL

Solution: Encode and Decode TinyURL

15
Comments
3 min read
Solution: Best Time to Buy and Sell Stock with Transaction Fee
Cover image for Solution: Best Time to Buy and Sell Stock with Transaction Fee

Solution: Best Time to Buy and Sell Stock with Transaction Fee

17
Comments
4 min read
Solution: Generate Random Point in a Circle
Cover image for Solution: Generate Random Point in a Circle

Solution: Generate Random Point in a Circle

25
Comments
4 min read
Solution: Wiggle Subsequence
Cover image for Solution: Wiggle Subsequence

Solution: Wiggle Subsequence

9
Comments
3 min read
Solution: Keys and Rooms
Cover image for Solution: Keys and Rooms

Solution: Keys and Rooms

20
Comments
3 min read
Solution: Design Underground System
Cover image for Solution: Design Underground System

Solution: Design Underground System

12
Comments
5 min read
Solution: Reordered Power of 2
Cover image for Solution: Reordered Power of 2

Solution: Reordered Power of 2

5
Comments 1
3 min read
Solution: Vowel Spellchecker
Cover image for Solution: Vowel Spellchecker

Solution: Vowel Spellchecker

17
Comments
5 min read
Solution: 3Sum With Multiplicity
Cover image for Solution: 3Sum With Multiplicity

Solution: 3Sum With Multiplicity

6
Comments
6 min read
Solution: Advantage Shuffle
Cover image for Solution: Advantage Shuffle

Solution: Advantage Shuffle

10
Comments
4 min read
Solution: Pacific Atlantic Water Flow
Cover image for Solution: Pacific Atlantic Water Flow

Solution: Pacific Atlantic Water Flow

7
Comments
5 min read
Solution: Word Subsets
Cover image for Solution: Word Subsets

Solution: Word Subsets

7
Comments 4
5 min read
Solution: Palindromic Substrings
Cover image for Solution: Palindromic Substrings

Solution: Palindromic Substrings

9
Comments
3 min read
Solution: Reconstruct Original Digits from English
Cover image for Solution: Reconstruct Original Digits from English

Solution: Reconstruct Original Digits from English

9
Comments
4 min read
Solution: Flip Binary Tree To Match Preorder Traversal
Cover image for Solution: Flip Binary Tree To Match Preorder Traversal

Solution: Flip Binary Tree To Match Preorder Traversal

7
Comments
4 min read
Solution: Russian Doll Envelopes
Cover image for Solution: Russian Doll Envelopes

Solution: Russian Doll Envelopes

10
Comments 1
4 min read
Solution: Stamping The Sequence
Cover image for Solution: Stamping The Sequence

Solution: Stamping The Sequence

8
Comments
5 min read
Solution: Palindrome Linked List
Cover image for Solution: Palindrome Linked List

Solution: Palindrome Linked List

24
Comments 3
4 min read
Solution: Ones and Zeroes
Cover image for Solution: Ones and Zeroes

Solution: Ones and Zeroes

21
Comments
4 min read
Solution: Longest Valid Parentheses
Cover image for Solution: Longest Valid Parentheses

Solution: Longest Valid Parentheses

18
Comments 4
4 min read
Solution: Design Circular Queue
Cover image for Solution: Design Circular Queue

Solution: Design Circular Queue

15
Comments 1
7 min read
Solution: Global and Local Inversions
Cover image for Solution: Global and Local Inversions

Solution: Global and Local Inversions

14
Comments
3 min read
Solution: Minimum Operations to Make Array Equal
Cover image for Solution: Minimum Operations to Make Array Equal

Solution: Minimum Operations to Make Array Equal

12
Comments
4 min read
Solution: Determine if String Halves Are Alike
Cover image for Solution: Determine if String Halves Are Alike

Solution: Determine if String Halves Are Alike

9
Comments 2
3 min read
Solution: Letter Combinations of a Phone Number
Cover image for Solution: Letter Combinations of a Phone Number

Solution: Letter Combinations of a Phone Number

27
Comments 2
4 min read
Solution: Verifying an Alien Dictionary
Cover image for Solution: Verifying an Alien Dictionary

Solution: Verifying an Alien Dictionary

10
Comments
4 min read
Solution: Longest Increasing Path in a Matrix
Cover image for Solution: Longest Increasing Path in a Matrix

Solution: Longest Increasing Path in a Matrix

5
Comments
4 min read
Solution: Deepest Leaves Sum
Cover image for Solution: Deepest Leaves Sum

Solution: Deepest Leaves Sum

6
Comments
4 min read
Solution: Beautiful Arrangement II
Cover image for Solution: Beautiful Arrangement II

Solution: Beautiful Arrangement II

12
Comments
4 min read
Solution: Flatten Nested List Iterator
Cover image for Solution: Flatten Nested List Iterator

Solution: Flatten Nested List Iterator

12
Comments 1
3 min read
Solution: Partition List
Cover image for Solution: Partition List

Solution: Partition List

13
Comments 3
3 min read
Solution: Fibonacci Number
Cover image for Solution: Fibonacci Number

Solution: Fibonacci Number

9
Comments
3 min read
Solution: Remove All Adjacent Duplicates in String II
Cover image for Solution: Remove All Adjacent Duplicates in String II

Solution: Remove All Adjacent Duplicates in String II

19
Comments 7
6 min read
Solution: Number of Submatrices That Sum to Target
Cover image for Solution: Number of Submatrices That Sum to Target

Solution: Number of Submatrices That Sum to Target

10
Comments 1
4 min read
Solution: Remove Nth Node From End of List
Cover image for Solution: Remove Nth Node From End of List

Solution: Remove Nth Node From End of List

17
Comments 8
4 min read
Solution: Combination Sum IV
Cover image for Solution: Combination Sum IV

Solution: Combination Sum IV

10
Comments 1
5 min read
Solution: N-ary Tree Preorder Traversal
Cover image for Solution: N-ary Tree Preorder Traversal

Solution: N-ary Tree Preorder Traversal

16
Comments
3 min read
Solution: Triangle
Cover image for Solution: Triangle

Solution: Triangle

24
Comments
4 min read
Solution: Brick Wall
Cover image for Solution: Brick Wall

Solution: Brick Wall

6
Comments
4 min read
Solution: Count Binary Substrings
Cover image for Solution: Count Binary Substrings

Solution: Count Binary Substrings

13
Comments 4
3 min read
Solution: Critical Connections in a Network
Cover image for Solution: Critical Connections in a Network

Solution: Critical Connections in a Network

10
Comments
5 min read
Solution: Rotate Image
Cover image for Solution: Rotate Image

Solution: Rotate Image

13
Comments 1
4 min read
Solution: Furthest Building You Can Reach
Cover image for Solution: Furthest Building You Can Reach

Solution: Furthest Building You Can Reach

18
Comments 2
5 min read
Solution: Power of Three
Cover image for Solution: Power of Three

Solution: Power of Three

14
Comments 1
3 min read
Solution: Unique Paths II
Cover image for Solution: Unique Paths II

Solution: Unique Paths II

9
Comments
4 min read
Solution: Find First and Last Position of Element in Sorted Array
Cover image for Solution: Find First and Last Position of Element in Sorted Array

Solution: Find First and Last Position of Element in Sorted Array

22
Comments
4 min read
Solution: Powerful Integers
Cover image for Solution: Powerful Integers

Solution: Powerful Integers

9
Comments
3 min read
Solution: Prefix and Suffix Search
Cover image for Solution: Prefix and Suffix Search

Solution: Prefix and Suffix Search

20
Comments 4
5 min read
Solution: Course Schedule III
Cover image for Solution: Course Schedule III

Solution: Course Schedule III

15
Comments 1
4 min read
Solution: Running Sum of 1d Array
Cover image for Solution: Running Sum of 1d Array

Solution: Running Sum of 1d Array

19
Comments 1
3 min read
Solution: Non-decreasing Array
Cover image for Solution: Non-decreasing Array

Solution: Non-decreasing Array

30
Comments 1
4 min read
Solution: Jump Game II
Cover image for Solution: Jump Game II

Solution: Jump Game II

10
Comments 1
3 min read
Solution: Convert Sorted List to Binary Search Tree
Cover image for Solution: Convert Sorted List to Binary Search Tree

Solution: Convert Sorted List to Binary Search Tree

16
Comments 2
4 min read
Solution: Delete Operation for Two Strings
Cover image for Solution: Delete Operation for Two Strings

Solution: Delete Operation for Two Strings

13
Comments 2
4 min read
Solution: Super Palindromes
Cover image for Solution: Super Palindromes

Solution: Super Palindromes

9
Comments
7 min read
Solution: Construct Target Array With Multiple Sums
Cover image for Solution: Construct Target Array With Multiple Sums

Solution: Construct Target Array With Multiple Sums

10
Comments 3
5 min read
Solution: Count Primes
Cover image for Solution: Count Primes

Solution: Count Primes

16
Comments 1
3 min read
Solution: Maximum Points You Can Obtain from Cards
Cover image for Solution: Maximum Points You Can Obtain from Cards

Solution: Maximum Points You Can Obtain from Cards

11
Comments 1
3 min read
Solution: Range Sum Query 2D - Immutable
Cover image for Solution: Range Sum Query 2D - Immutable

Solution: Range Sum Query 2D - Immutable

9
Comments
5 min read
Solution: Ambiguous Coordinates
Cover image for Solution: Ambiguous Coordinates

Solution: Ambiguous Coordinates

10
Comments
5 min read
Solution: Flatten Binary Tree to Linked List
Cover image for Solution: Flatten Binary Tree to Linked List

Solution: Flatten Binary Tree to Linked List

22
Comments 1
7 min read
Solution: Valid Number
Cover image for Solution: Valid Number

Solution: Valid Number

14
Comments 1
4 min read
Solution: Binary Tree Cameras
Cover image for Solution: Binary Tree Cameras

Solution: Binary Tree Cameras

13
Comments