MTrajK
coding-problems
Python

Solutions for various coding/algorithmic problems and many useful resources for learning algorithms and data structures

Last updated Jul 7, 2026
3.4k
Stars
631
Forks
1
Issues
+2
Stars/day
Attention Score
75
Language breakdown
Python 100.0%
β–Έ Files click to expand
README

Coding Problems

Here you can find solutions for various coding/algorithmic problems and many useful resources for learning algorithms and data structures.\ Also, this repo will be updated with new solutions and resources from time to time.

Note that this repo is meant to be used for learning and researching purposes only and it is not meant to be used for production.

Solutions

Algorithms and data structures are not language-specific (it's true that some languages are faster, and some are easier to use), but if you are good with the logic and pseudocode, any language would be good.\ So I've decided to use Python) because I think it's very close to pseudocode and it's easily readable (so it'll be easy for someone from another environment to implement the same solutions).\ As I said previously, all solutions are written in Python (more precisely, Python 3), using the Built-in Functions (print, len, range, sorted, sum, min, max, etc...) and a few modules from the Python Standard Library like:

So, to execute these solutions there is no need from installing any external packages. \ Coding style and name conventions are described in the official PEP8 page.

Note that I'm not the author of these problems, they are from sites like LeetCode (you can find more than 40 sites like this in the Training Sites section). Only the solutions and explanations are mine. If you find any bug or incorrect implementation (or faster/better implementation) in this repo, please let me know by opening an issue or pull request.

Template

For easier navigation into the solutions, each file with a solution in this repo will have the following template:

'''
Problem Name

Problem explanation.

Input: XXX Output: XXX Output explanation: XXX

========================================= Solution 1 explanation. Time Complexity: O(X) Space Complexity: O(X) Solution 2 explanation. (some of the problems are solved in more than one way) Time Complexity: O(X) Space Complexity: O(X) '''

##############

Solution 1 #

##############

def nameofsolution_1(params): # description of code pass

##############

Solution 2 #

##############

def nameofsolution_2(params): # description of code pass

###########

Testing #

###########

Test 1

Correct result => 'result1'

test_val = 'example1' print(nameofsolution1(testval)) print(nameofsolution2(testval))

Test 2

Correct result => 'result2'

test_val = 'example2' print(nameofsolution1(testval)) print(nameofsolution2(testval))

Note that here I'm using the simplest way of testing, printing the results using the print method. Why? Because I think that the bigger part of the users of this repo isn't familiar with unit testing and I wanted this part to be intuitive. Btw, I strongly recommend using some unit testing framework for this kind of testing. The Python Standard Library contains a great framework for unit testing called unittest, or you can install some third-party unit testing framework like pytest.

Categories

Each solution/problem in this repo belongs to one of these categories:

  • Arrays - Array Manipulations, Sorting, Binary Search, Divide and Conquer, Sliding Window, etc.
  • Linked Lists - Linked List Searching, Pointer Manipulations, etc.
  • Trees - Binary Search Trees, Tree Traversals: Breadth-First (Level Order) Traversal, Depth-First Traversal (Inorder, Preorder, Postorder), etc.
  • Hashing DS - Hashing Data Structures: Sets/HashSets and Dictionaries/HashMaps.
  • Dynamic Programming - 2D and 1D Dynamic Programming, LCS, LIS, Knapsack, etc.
  • Strings - String Manipulations, Reversing, Encodings/Decodings, etc.
  • Math - GCD, LCM, Factorization, Geometry, Math Formulas, etc.
  • Other - Backtracking, BFS, DFS, Stacks, Queues, Deques, Priority Queues (Heaps), Matrices, etc.

Learning Resources

The learning resources are divided into 4 categories: Courses, Books, Training Sites, Other Resources.

Courses

Collection of free courses from one of the best CS universities.

  • Stanford University
- Algorithms Specialization (Coursera) * Divide and Conquer, Sorting and Searching, and Randomized Algorithms * Graph Search, Shortest Paths, and Data Structures * Greedy Algorithms, Minimum Spanning Trees, and Dynamic Programming * Shortest Paths Revisited, NP-Complete Problems and What To Do About Them - Introduction to Programming Contests - CS 97SI
  • Princeton University
- Algorithms Part 1 (Coursera) - Algorithms Part 2 (Coursera) - Analysis of Algorithms (Coursera)
  • UC San Diego
- Data Structures and Algorithms Specialization (Coursera) * Algorithmic Toolbox * Data Structures * Algorithms on Graphs * Algorithms on Strings * Advanced Algorithms and Complexity - Data Structures and Performance (Coursera) - edX * Data Structures Fundamentals * Algorithmic Design and Techniques * Graph Algorithms * Data Structures: An Active Learning Approach
  • MIT University
- Introduction to algorithms 2005 - Official MIT page with resources. Note: this course is the old 6.046J course (the new name is Design and analysis of algorithms, you can find it below). - Introduction to algorithms 2011 - 6.006 - Official MIT page with resources - Design and analysis of algorithms - 6.046J - Official MIT page with resources - Advanced Data Structures - 6.851 - Official MIT page with resources - Advanced Algorithms 2016 - 6.854 - Official MIT page with resources - Programming for the Puzzled 2018 - 6.S095 - Official MIT page with resources
  • Harvard University
- Advanced algorithms - CS224
  • UC Berkeley
- Data Structures - CS61B - Efficient Algorithms and Intractable Problems - CS170 - YouTube videos

Books

Several books that have made an impression on me:

Training Sites

If the problems from LeetCode are not enough and you need more problems like those, you can find much more on these platforms:

Other Resources

  • Geeks For Geeks - The site which all interested in algorithms (no matter if beginners or experts) should know! YouTube channel with many useful videos.
  • The Algorithms - Python - Great GitHub repo with many algorithms written in Python (Link from the same repo written in other programming languages).
  • CP Algorithms - Great page with excellent explanations for various algorithms.
  • Visualizers:
- USFCA Visualization Tool - Great tool for visualizing data structures and algorithms, created by the University of San Francisco. - VisuAlgo - Another great tool for visualizing data structures and algorithms through animation. - Algorithm Visualizer - Interactive online platform that visualizes algorithms from code. This platform is an open-source project, here you can find the source code.
  • Courses and tutorials (but not from universities like the Courses section):
- Google - Intro to Data Structures and Algorithms - Free course on Udacity offered by Google. - HackerEarth - Tutorials and Practice - Practice problems and learn about many algorithms and data structures needed for competitive programming. - KhanAcademy - Algorithms - Good explanations for some basic algorithms. - Tutorialspoint - Data Structures and Algorithms - Another platform with good explanations, also Tutorialspoint has free tutorials for almost everything related to CS! - Programiz - Data Structures and Algorithms - One more platform which explains the data structures and algorithms in a simple and interesting way. - Hackr.io - Data Structures and Algorithms Tutorials and Courses - Big collection of tutorials and courses. - Scaler - Data Structures Tutorial - Interesting and interactive explanations of some basic data structures.
  • YouTube playlists with tutorials:
- Data Structures by mycodeschool - Data Structures by HackerRank - Algorithms by HackerRank

Β© 2026 GitRepoTrend Β· MTrajK/coding-problems Β· Updated daily from GitHub