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:
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
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
- Non overlapping intervals (Sort by end time)
- Remove covered intervals (Sort by start time and then by end time in descending order)
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
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 these posts