This repository contains solutions to important problems from leetcode, codechef, codeforces, Interviewbit and Hackerearth.
- Fork this repository.
- Write the solution to the problem in your preferred language.
- Check if the problem folder is available or not (For eg., BFS, DFS etc problems should go into the graphs folder). If the problem folder is not available, then create the folder.
- Make sure that the code has comments and at the top, the problem link is given.
- Create Pull Request.
Thanks and Happy Coding!
Refer this post: https://leetcode.com/discuss/general-discussion/786126/python-powerful-ultimate-binary-search-template-solved-many-problems
Refer solved problems here
Tip: Whenever we have some problems which tells to find minimised max answer
, try to think binary search
.
Reference problems:
- Split Array Largest Sum
- Divide Chocolate
- Length of LIS
- Russian Doll Envelopes
- Find Indices of Ones
- Find minimum in rotated array
- Random Pick With Weight
- Number of triplets
- Find the safest path in the grid
- Prime Subtraction Operation
- Kth smallest element in row and column wise sorted matrix
Refer this post: https://leetcode.com/discuss/study-guide/1326900/graph-algorithms-problems-to-practice
Refer solved problems here
For 2d points, consider using indexes in adjacency map (Refer Detonate the Maximum Bombs)
Some more important problems
- Longest Increasing Path In a Matrix
- Maximum Score of a Node Sequence
- Alien Dictionary
- Maximum Number Of Invitations
- String Replacement Library
- Number of Islands II
- Maximum Minimum Path
- Path with Maximum Probability
- Critical connections in a network
- Find the safest path in the grid
Notice the use of max heap in Maximum Minimum Path
and Path with Maximum Probability
.
In union method, why do we set the parent which has greater size?
Refer these links
Let's say we have 2 nodes x and y in the union method
We find the parent and note down the sizes of the groups which have x and y.
Suppose the height of group containing x is heightX and similarly for y, it is heightY.
Case 1: heightX > heightY
If we attach node x to node y, the height would become heightX + 1
But if we attach node y to node x, the height would be height X
So we attach node y to node x.
Case 2: heightX = heightY
In this case, the height of the resultant set would be heightX + 1
Refer this post: https://leetcode.com/discuss/study-guide/2166045/line-sweep-algorithms
Refer solved problems here
Some important problems
- On Call Rotation Schedule
- Remove covered intervals (Sort by start time and then by end time in descending order)
- Maximum number of overlap
- Non overlapping intervals (Sort by end time)
- Minimum Number of Arrows to Burst Balloons
- Maximum Length of Pair Chain
Solve problems by keeping the state of the current player. (And we can also remove the current player state if we see that it is not used in the recursive function)
Refer:
Solve problems by the Difference of scores method
Refer:
Solve problems by sorting and greedy approach
(When the problem says that a player can pick any idx from the array for their score).
Refer:
Refer solved problems here
Refer this post: https://leetcode.com/discuss/study-guide/1360400/priority-queue-problems-to-practice
Refer solved problems here
Some important problems
- Reorganise Strings
- Time for turn
- Single threaded CPU
- Median in data stream
- Maximum Number of Events That Can Be Attended
Single Threaded CPU
and Maximum Number of Events that can be attended
are similar.
Refer this youtube link: Range Sum Query
Refer these problems:
Refer solved problems here
Some important problems
Refer solved problems here
Some important problems
Refer solved problems here
Some important problems:
Refer solved problems here
Some important problems:
Refer solved problems here
Some important problems:
Refer solved problems here
Some important problems:
Refer solved problems here
Some important problems:
Refer these posts