Skip to content

This repository contains important problem solutions from various sites. If you like this repo, please star it๐Ÿ˜„.

License

Notifications You must be signed in to change notification settings

arhankundu99/Important-Algo-and-Data-structures

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Important Algo and Data structures

This repository contains solutions to important problems from leetcode, codechef, codeforces, Interviewbit and Hackerearth.

How to Contribute

  1. Fork this repository.
  2. Write the solution to the problem in your preferred language.
  3. 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.
  4. Make sure that the code has comments and at the top, the problem link is given.
  5. Create Pull Request.

Thanks and Happy Coding!

Binary Search

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:

  1. Split Array Largest Sum
  2. Divide Chocolate
  3. Length of LIS
  4. Russian Doll Envelopes
  5. Find Indices of Ones
  6. Find minimum in rotated array
  7. Random Pick With Weight
  8. Number of triplets
  9. Find the safest path in the grid
  10. Prime Subtraction Operation
  11. Kth smallest element in row and column wise sorted matrix

Graphs

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

Notice the use of max heap in Maximum Minimum Path and Path with Maximum Probability.

Bipartite matching

DSU complexity analysis

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

Line Sweep

Refer this post: https://leetcode.com/discuss/study-guide/2166045/line-sweep-algorithms

Refer solved problems here

Some important problems

Sort by end time problems

Interval problems

Game theory

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

Priority queue

Refer this post: https://leetcode.com/discuss/study-guide/1360400/priority-queue-problems-to-practice

Refer solved problems here

Some important problems

Single Threaded CPU and Maximum Number of Events that can be attended are similar.

Segment tree

Refer this youtube link: Range Sum Query

Refer these problems:

Tries

Refer solved problems here

Some important problems

TreeMap / TreeSet

Refer solved problems here

Some important problems

Binary tree

Refer solved problems here

Some important problems:

Dynamic Programming

Refer solved problems here

Some important problems:

Stacks

Refer solved problems here

Some important problems:

Queue

Valid Draw

Inplement data structures

Refer solved problems here

Some important problems:

Math

Refer solved problems here

Some important problems:

Rate limiting

Refer these posts

About

This repository contains important problem solutions from various sites. If you like this repo, please star it๐Ÿ˜„.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •