/leetcode

LeetCode problem solutions and tests.

Primary LanguagePython

LeetCode Interview Questions

A set of solutions to LeetCode and HackerRank questions that I solved in preparation for software engineering interviews at tech companies. All of these questions are available on LeetCode or HackerRank, and some of them require a subscription to LeetCode Premium.

Overview

Having recently graduated from Georgia Tech's OMSCS program, I finished my last semester with an algorithms course, which provided the necessary theoretical background for me start practicing with LeetCode problems almost immediately upon starting my job search. Additionally, I reviewed the following resources concurrently with online practice:

  • Cracking the Coding Interview, 6th Edition
  • Elements of Programming Interviews in Python

Questions

I used Anki to track and review the questions that I completed throughout the process. These are organized by specific subcategories, where a set of questions in one subcategory can and should be solved by applying a common pattern or set of patterns.

Arrays

Easy

  1. Best Time to Buy and Sell Stock
  2. Best Time to Buy and Sell Stock II
  3. Contains Duplicate
  4. Find All Numbers Disappeared in an Array
  5. Jewels and Stones
  6. Majority Element
  7. Merge Sorted Array
  8. Move Zeroes
  9. Pascal's Triangle
  10. Plus One
  11. Remove Duplicates from Sorted Array
  12. Rotate Array
  13. Shortest Distance to a Character
  14. Single Number
  15. Two Sum

Medium

  1. Container With Most Water
  2. Find All Duplicates in an Array
  3. Find the Duplicate Number
  4. Next Permutation
  5. Product of Array Except Self
  6. Search in Rotated Sorted Array

Hard

  1. First Missing Positive
  2. Longest Consecutive Sequence
Backtracking

Easy

  1. Letter Case Permutation

Medium

  1. Subsets
  2. Subsets II
  3. Permutations
  4. Permutations II
  5. Combinations
  6. Combination Sum
  7. Combination Sum II
  8. Combination Sum III
  9. Generate Parentheses
  10. Target Sum
  11. Palindrome Partitioning
  12. Partition to K Equal Sum Subsets
  13. Letter Combinations of a Phone Number
  14. Generalized Abbreviation
  15. Minesweeper

Hard

  1. Sudoku Solver
  2. N-Queens
Bitwise Operations

Easy

  1. Sum of Two Integers
  2. Missing Number
  3. Number of 1 Bits
  4. Reverse Bits

Medium

  1. Counting Bits
Design

Easy

  1. Logger Rate Limiter
  2. Design HashMap

Medium

  1. Design Hit Counter
  2. Time Based Key-Value Store
Dynamic Programming

Easy

  1. Climbing Stairs
  2. House Robber
  3. Maximum Subarray
  4. Range Sum Query - Immutable

Medium

  1. House Robber II
  2. Coin Change
  3. Maximum Product Subarray
  4. Longest Increasing Subsequence
  5. Longest Palindromic Substring
  6. Word Break
  7. Combination Sum IV
  8. Decode Ways
  9. Unique Paths
  10. Palindromic Substrings
  11. Number of Longest Increasing Subsequence
  12. Partition Equal Subset Sum
  13. Best Time to Buy and Sell Stock with Cooldown

Hard

  1. Best Time to Buy and Sell Stock III
  2. Longest Valid Parentheses
  3. Word Break II
Fast and Slow Pointers

Easy

  1. Linked List Cycle
  2. Middle of the Linked List
  3. Palindrome Linked List
  4. Remove Linked List Elements
  5. Remove Duplicates from Sorted List

Medium

  1. Linked List Cycle II
  2. Add Two Numbers
  3. Remove Nth Node From End Of List
  4. Sort List
  5. Reorder List
Graphs

Medium

  1. Clone Graph
  2. Friend Circles
  3. Graph Valid Tree
  4. Number of Connected Components in an Undirected Graph
  5. Number of Islands
  6. Pacific Atlantic Water Flow
Greedy

Easy

  1. Lemonade Change
Intervals

Easy

  1. Meeting Rooms

Medium

  1. Merge Intervals
  2. Interval List Intersections
  3. Non-overlapping Intervals
  4. Meeting Rooms II
  5. Task Scheduler
  6. Minimum Number of Arrows to Burst Balloons

Hard

  1. Insert Interval
  2. Employee Free Time
Linked Lists

Easy

  1. Merge Two Sorted Lists
  2. Reverse Linked List
  3. Intersection of Two Linked Lists
  4. Delete Node in a Linked List

Medium

  1. Reverse Linked List II
  2. Rotate List
  3. Swap Nodes in Pairs
  4. Odd Even Linked List

Hard

  1. Merge K Sorted Lists
  2. Reverse Nodes in k-Group
Math

Easy

  1. Greatest Common Divisor of Strings
  2. Subtract the Product and Sum of Digits of an Integer
  3. Reverse Integer
Matrices

Medium

  1. Set Matrix Zeroes
  2. Spiral Matrix
  3. Rotate Image
  4. Word Search
  5. Kth Smallest Element in a Sorted Matrix
Sliding Window

Medium

  1. Minimum Size Subarray Sum
  2. Fruit Into Baskets
  3. Longest Repeating Character Replacement
  4. Longest Substring Without Repeating Characters

Hard

  1. Sliding Window Maximum
  2. Minimum Number of K Consecutive Bit Flips
  3. Substring with Concatenation of All Words
Stacks and Queues

Easy

  1. Valid Parentheses
  2. Min Stack

Medium

  1. Evaluate Reverse Polish Notation
Top K Elements

Medium

  1. Kth Smallest Element in a BST
  2. K Closest Points to Origin
  3. Top K Frequent Elements
  4. Sort Characters By Frequency
  5. Kth Largest Element in an Array
  6. Find K Closest Elements
  7. Reorganize String

Hard

  1. Rearrange String k Distance Apart
  2. Course Schedule III
  3. Maximum Frequency Stack
Topological Sort

Medium

  1. Course Schedule
  2. Course Schedule II
  3. Minimum Height Trees

Hard

  1. Alien Dictionary
  2. Sequence Reconstruction
Tree: BFS

Easy

  1. Binary Tree Level Order Traversal II
  2. Average of Levels in Binary Tree
  3. Minimum Depth of Binary Tree

Medium

  1. Binary Tree Level Order Traversal
  2. Binary Tree Zigzag Level Order Traversal
  3. Populating Next Right Pointers in Each Node
  4. Populating Next Right Pointers in Each Node II
  5. Binary Tree Right Side View
  6. All Nodes Distance K in Binary Tree
  7. Boundary of Binary Tree
Tree: Binary Search

Easy

  1. Binary Search
  2. Find Smallest Letter Greater Than Target
  3. Peak Index in a Mountain Array
  4. First Bad Version

Medium

  1. Find Minimum in Rotated Sorted Array
  2. Find Peak Element
  3. Search in Rotated Sorted Array II
  4. Search a 2D Matrix
  5. Search a 2D Matrix II

Hard

  1. Count of Range Sum
Tree: DFS

Easy

  1. Diameter of Binary Tree
  2. Find Leaves of Binary Tree
  3. Invert Binary Tree
  4. Lowest Common Ancestor of a Binary Search Tree
  5. Maximum Depth of Binary Tree
  6. Merge Two Binary Trees
  7. Path Sum
  8. Same Tree
  9. Subtree of Another Tree

Medium

  1. Construct Binary Tree from Preorder and Inorder Traversal
  2. Implement Trie (Prefix Tree)
  3. Lowest Common Ancestor of a Binary Tree
  4. Maximum Average Subtree
  5. Maximum Binary Tree
  6. Maximum Width of Binary Tree
  7. Path Sum II
  8. Path Sum III
  9. Validate Binary Search Tree

Hard

  1. Binary Tree Maximum Path Sum
  2. Serialize and Deserialize Binary Tree
  3. Word Search II
Two Heaps

Hard

  1. Find Median from Data Stream
  2. Sliding Window Median
  3. IPO
Two Pointers

Easy

  1. Backspace String Compare
  2. Implement strStr()
  3. Intersection of Two Arrays II
  4. Reverse String
  5. Squares of a Sorted Array
  6. Two Sum II - Input array is sorted
  7. Valid Palindrome

Medium

  1. 3Sum
  2. 3Sum Closest
  3. Subarrays with Product Less than K
  4. Sort Colours

Hard

  1. Minimum Window Substring
  2. Trapping Rain Water

Sources

The questions were almost exclusively sourced from the following resources: