This is a list of solutions written for more than 300+ problems from leetcode. These cover various problems from Easy, Medium, and Hard solutions. Quite often, we get stuck solving problems when preparing for our interviews and it can be quite stressful. This is a compilation of all my solutions which I hope will help you become better at coding and enjoy the process of solving challanges.
Most of these problems are solved using C++. My goal is to publish solutions for these problems in Java, and Python as well.
- Add to Array-Form of Integer
- Find the intersection of two arrays
- Find the intersection of three arrays
- Find the maximum consecutive ones in an array
- Create a target array in a pre-specified format
- Decompress Run-Length Encoded List
- Find the fixed point in an array
- Number of Good Pairs
- H-Index Calculator
- Interval List Intersections
- Monotonic Array
- Find the Kth Positive Element in an array
- Longest Continuous Increasing Subsequence
- Check if the coordinates are in a straight line
- Make Two Arrays Equal by Reversing Sub-arrays
- Merge N Sorted Arrays
- Find the missing number from an array
- Find the missing ranges from an array
- Move Zeroes
- Nested List Weight Sum
- Kids With the Greatest Number of Candies
- Plus One
- For each element of an array find the product except itself
- Range Sum Query
- Rotate Array
- Find the running sum from an array
- Sentence Similarity
- Shifting Letters
- Sort Array By Parity
- Sort By Increasing Frequency
- Find the third maximum element in an array
- Combinations
- Combinations With Duplicates
- Generate Subsets
- Letter Case Permutation
- Palindromic Partitioning
- Parantheses Generator
- Remove Invalid Paranthese
- Count the number of 1 bits in a number
- Counting Bits
- Reverse the bits in a number
- Find the number that occurs once
- Subset XOR Sum
- Barber Shop Problem
- The Dining Philosophers Problem
- Reader Writer Lock
- Reader Writer Lock (No Starvation)
- Synchronous Executor
- Uber Rider Share Problem
- Climbing Stairs
- Count Substrings That Differ by One Character
- Count Sorted Vowel Strings
- Decode Ways
- Divisor Game
- Egg Drop
- Find a number in the fibonacci sequence
- First Bad Version
- Get Maximum in Generated Array
- Interleaving String
- Is Subsequence
- Find the sum of the maximum subarray with consecutive elements
- N-th Tribonacci Number
- Palindrome Validator
- Palindromic Substrings
- Partition Array Maximum Sum
- Partition Equal Subset Sum
- Pascal Triangle
- Rotated Digits
- Target Sum
- Unique Paths
- Word Break
- Word Break-II
- Find a valid format for an alien dictionary
- Binary Watch
- Deep copy a graph
- Find the number of connected components in a graph
- Find if there exists a valid course schedule
- Find a valid course schedule
- Employee Importance
- Find Center Of Graph
- Find If Path Exists
- Find Town Judge
- Find if a graph is a valid tree
- Keys And Rooms
- Minimum Vertices To Nodes
- Reorder Routes to Make All Paths Lead to the City Zero
- Calculate the minimum network delay
- Number of Provinces
- Parallel Courses
- All Paths from Source Lead to Destination
- All Paths From Source to Target
- Reconstruct Itinerary
- Letter Tile Possibilities
- Can Place Flowers
- Maximum Score
- Maximum Swap
- Maximum Units on a Truck
- Find the container with the maximum water
- Best Time To Buy And Sell Stocks
- Verifying an Alien Dictionary
- Continuous Subarray Sum
- Check if a duplicate exists in an array in O(N)
- Remove Duplicates from Sorted Array
- First Unique Character in a String
- Find all collection of four elements that have sum equal to K
- Group Anagrams
- Group Shifted Strings
- Design a HitCounter
- Count number of jewels and stones in a collection
- Logger Rate Limiter
- Find the majority element in an array
- Find the missing number in an array
- Number of matching subsequences in an array
- Design an Ordered Stream
- Insert Delete GetRandom O(1)
- Random Pick Index
- Shortest Completing Word
- Dot Product of Two Sparse Vectors
- Subarray Sum Equals K
- 3Sum - Find a triplet with a given sum
- Design a time-based key-value data structure
- Design a Trie
- Tweet Counts Per Frequency
- Find if there are two numbers with a specific target sum
- Two Sum III - Data structure design
- Uncommon Words from Two Sentences
- Word Pattern
- K Closest Points to Origin
- Top K Frequent Elements
- Kth Largest Element in an Array
- Kth Smallest Element in a Sorted Matrix
- Kth Largest Element in a Stream
- Last Stone Weight
- Maximum Average Pass Ratio
- Reorganize String
- Reorganize String
- Sort Characters By Frequency
- Top K Frequent Words
- Insert new interval in non-overlapping intervals
- Find non-overlapping meeting rooms
- Merge all overlapping intervals
- Binary Tree To Doubly Linked List
- Detect a cycle in a linked-list
- Delete Node in a Linked List
- Write an algoritm to find the middle of a linked-list
- Insert into a Sorted Circular Linked List
- Intersection of Two Linked Lists
- Merge Two Sorted Lists
- Reverse a linked-list
- Design an LRU Cache
- Merge k Sorted Lists
- Palindrome Linked List
- Write an algorithm to re-order a linked-list
- Design a SkipList
- Swap Nodes in Pairs
- Add Two Numbers
- Best Meeting Spot
- Farmland Groups
- Flood Fill
- Island Perimeter
- Longest Line Of Ones
- Max Area Of Island
- Minimum Path Sum
- Number Of Islands
- Find the customer with the maximum wealth
- Find spiral order in a matrix
- Tic Tac Toe
- Toeplitz Matrix
- Find word in a matrix
- Accounts Merge
- Robot Bounded In Circle
- Fizz Buzz
- Find the longest consecutive element sequence
- Moving Average
- Nested Iterator
- Num Teams
- Reverse a 32-bit integer
- Roman To Integer
- Strobogrammatic Number
- Underground System
- Valid Parantheses
- Valid Perfect Square
- Word Dictionary
- Bubble Sort
- Sort colors in a collection
- Heap Sort
- Calculate a student's top five average
- Insert Sort
- Merge Sort
- Minimum Difference Between Largest and Smallest Value in Three Moves
- Quick Sort
- Reorder Data in Log Files
- Sort strings in a sentence
- Text Justification
- Two Sum Less Than K
- Check if two strings are valid anagrams
- Asteroid Collision
- Basic Calculator
- Crawler Log Folder
- Make The String Great
- Make String Valid
- Max Nesting Depth
- Max Stack
- Min Stack
- Implement Queue using Stacks
- Remove duplicates from sorted array
- Check if a string has valid parantheses
- Add Binary
- Add String
- Backspace String Compare
- Buddy Strings
- Design an algorithm to encode a list of strings to a string
- Excel Sheet Column Title
- Goat Latin
- Given a valid IPv4 address, find a defanged version of that IP address
- Isomorphic Strings
- Is Subsequence
- Length of Last Word
- Find the longest common prefix from an array of strings
- Find a happy substring from a given string
- Longest Substring Without Repeating Characters
- Longest Uncommon Subsequence I
- Orderly Queue
- Implement strStr()
- Palindrome Permutation
- Ransom Note
- Reverse String
- Reverse Vowels
- Shuffle String
- Decode String
- Find the Difference
- Implement strStr()
- String to Integer (atoi)
- Valid Palindrome
- Remove Vowels from a String
- Check if Word Equals Summation of Two Words
- Average of Levels in Binary Tree
- Balanced Binary Tree
- Diameter of Binary Tree
- Binary Tree Maximum Path Sum
- Binary Tree Tilt
- Validate a binary search tree
- Binary Search Tree Iterator
- Find the Kth smallest element in a binary search tree
- Construct Binary Tree from Preorder and Inorder Traversal
- Closest Binary Search Tree Value
- Convert Sorted Array to Binary Search Tree
- All Elements in Two Binary Search Trees
- Increasing Order Search Tree
- Invert a binary tree
- Print the level order traversal of a binary tree
- Find the lowest common ancestor of two nodes in a subtree
- Find the maximum depth of a binary tree
- Merge Two Binary Trees
- Minimum Depth of Binary Tree
- Minimum Distance Between BST Nodes
- Find if a path has a specific sum
- Print the level order traversal of a tree
- Range Sum of a binary search tree
- Remove Nth Node From End of List
- Validate if a tree is a subtree of another tree
- Write an algorithm to encode/decode an N-ary tree
- Compare two binary tress
- Check If Two Expression Trees are Equivalent
- Vertical Order Traversal of a Binary Tree
- Ravi Tandon Hi there. I am Ravi Tandon. I have spent more than a decade building software at Flipkart, ThoughtSpot, and Spotnana. I was previously a Staff Software Engineer at ThoughtSpot and built a Natural Language Understanding Engine. I have published more than 5 research papers, and have multiple patents on building Search Engines. You can connect with me on LinkedIn, Twitter, or Email
- Ankit Kumar Hey, This is Ankit Kumar. I have more than 2 years of experience in the industry. I am currently working at WeaveHQ as a Software Engineer and building internal and deployment tools for weave platform engineering. Before Weave, I worked at Samsung Electronics. I love to read & write about system designs, devops, developer experience, deployments, infrastructures and architecture. Follow and Subscribe here: Medium and Substack