Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
bb79a56
Create 547. Number of Provinces.py
iamAntimPal Apr 13, 2025
f84de95
Create readme.md
iamAntimPal Apr 13, 2025
ebbbf97
Update readme.md
iamAntimPal Apr 13, 2025
4921139
Update readme.md
iamAntimPal Apr 13, 2025
e8e609c
Update readme.md
iamAntimPal Apr 13, 2025
3f5805a
Update readme.md
iamAntimPal Apr 13, 2025
155df68
Create 1466. Reorder Routes to Make All Paths Lead to the City Zero.py
iamAntimPal Apr 13, 2025
a537160
Update 1466. Reorder Routes to Make All Paths Lead to the City Zero.py
iamAntimPal Apr 13, 2025
ec8e559
Create readme.md
iamAntimPal Apr 13, 2025
fc9ce07
Update readme.md
iamAntimPal Apr 13, 2025
eeb231b
Update readme.md
iamAntimPal Apr 13, 2025
7cda876
Create 399. Evaluate Division.py
iamAntimPal Apr 13, 2025
52d86e5
Create readme.md
iamAntimPal Apr 13, 2025
27f6877
Update readme.md
iamAntimPal Apr 13, 2025
52f041e
Update readme.md
iamAntimPal Apr 13, 2025
c2cab0d
Update readme.md
iamAntimPal Apr 13, 2025
75b0d69
Create 1926. Nearest Exit from Entrance in Maze.py
iamAntimPal Apr 13, 2025
81436f6
Update 1926. Nearest Exit from Entrance in Maze.py
iamAntimPal Apr 13, 2025
7b6a527
Create readme.md
iamAntimPal Apr 13, 2025
a8f1784
Update readme.md
iamAntimPal Apr 13, 2025
bd1e786
Update readme.md
iamAntimPal Apr 13, 2025
c2f630d
Create 994. Rotting Oranges.py
iamAntimPal Apr 13, 2025
be5d947
Update 994. Rotting Oranges.py
iamAntimPal Apr 13, 2025
99d0895
Create readme.md
iamAntimPal Apr 13, 2025
45ead19
Update readme.md
iamAntimPal Apr 13, 2025
c1ae45f
Update readme.md
iamAntimPal Apr 13, 2025
c758f06
Update readme.md
iamAntimPal Apr 13, 2025
3c6175b
Update readme.md
iamAntimPal Apr 13, 2025
7a62e84
Create 215. Kth Largest Element in an Array.py
iamAntimPal Apr 13, 2025
4f820d9
Update 215. Kth Largest Element in an Array.py
iamAntimPal Apr 13, 2025
8f3b3ea
Create readme.md
iamAntimPal Apr 13, 2025
6157eca
Update readme.md
iamAntimPal Apr 13, 2025
b95de6a
Update readme.md
iamAntimPal Apr 13, 2025
81a77b9
Update readme.md
iamAntimPal Apr 13, 2025
95fdaf2
Create 2336. Smallest Number in Infinite Set.py
iamAntimPal Apr 13, 2025
32f7349
Update 2336. Smallest Number in Infinite Set.py
iamAntimPal Apr 13, 2025
5a82498
Create readme.md
iamAntimPal Apr 13, 2025
526b073
Update readme.md
iamAntimPal Apr 13, 2025
09ad0f9
Update readme.md
iamAntimPal Apr 13, 2025
42ff5df
Update readme.md
iamAntimPal Apr 13, 2025
685533f
Create 2542. Maximum Subsequence Score.py
iamAntimPal Apr 13, 2025
a90a74a
Update 2542. Maximum Subsequence Score.py
iamAntimPal Apr 13, 2025
3122e02
Create readme.md
iamAntimPal Apr 13, 2025
8841dc6
Update readme.md
iamAntimPal Apr 13, 2025
bde5941
Update readme.md
iamAntimPal Apr 13, 2025
365883f
Update readme.md
iamAntimPal Apr 13, 2025
fea20b3
Update readme.md
iamAntimPal Apr 13, 2025
e68f211
Update readme.md
iamAntimPal Apr 13, 2025
2f88f05
Update readme.md
iamAntimPal Apr 13, 2025
8fa13fc
Update readme.md
iamAntimPal Apr 13, 2025
eace70f
Update readme.md
iamAntimPal Apr 13, 2025
2332c4d
Update readme.md
iamAntimPal Apr 13, 2025
55191a2
Update readme.md
iamAntimPal Apr 13, 2025
c2a2600
Create 2462. Total Cost to Hire K Workers.py
iamAntimPal Apr 13, 2025
a6ef70a
Update 2462. Total Cost to Hire K Workers.py
iamAntimPal Apr 13, 2025
a0eecde
Create readme.md
iamAntimPal Apr 13, 2025
1d83d88
Update readme.md
iamAntimPal Apr 13, 2025
0f03af6
Update readme.md
iamAntimPal Apr 13, 2025
2722671
Update readme.md
iamAntimPal Apr 13, 2025
1b89102
Create 374. Guess Number Higher or Lower.py
iamAntimPal Apr 13, 2025
4e2110a
Update 374. Guess Number Higher or Lower.py
iamAntimPal Apr 13, 2025
2713a38
Create readme.md
iamAntimPal Apr 13, 2025
456bb04
Update readme.md
iamAntimPal Apr 13, 2025
64caa83
Update readme.md
iamAntimPal Apr 13, 2025
ff5a4db
Update readme.md
iamAntimPal Apr 13, 2025
8e5c9c7
Create 2300. Successful Pairs of Spells and Potions.py
iamAntimPal Apr 13, 2025
1c286f5
Update 2300. Successful Pairs of Spells and Potions.py
iamAntimPal Apr 13, 2025
1b19895
Create readme.md
iamAntimPal Apr 13, 2025
5321987
adding readme.md gile
iamAntimPal Apr 13, 2025
e9a59a8
this is awsome
iamAntimPal Apr 13, 2025
67ca631
this is awsome
iamAntimPal Apr 13, 2025
f5c7469
Update README.md
iamAntimPal Apr 13, 2025
f089cef
Update README.md
iamAntimPal Apr 13, 2025
00e6e8e
Update README.md
iamAntimPal Apr 13, 2025
38af1a5
Update README.md
iamAntimPal Apr 13, 2025
82c8639
Update README.md
iamAntimPal Apr 13, 2025
692968f
Update README.md
iamAntimPal Apr 13, 2025
c111634
Update README.md
iamAntimPal Apr 13, 2025
8d036b0
Update README.md
iamAntimPal Apr 13, 2025
ebbf812
Update readme.md
iamAntimPal Apr 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
217 changes: 215 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,215 @@
# LeetCode-in-Python
LeeteCode-in-Python is a GitHub repo with Python solutions to LeetCode problems. It offers clean, efficient, and well-documented code for interview prep, competitive programming, and mastering algorithms. Solutions are categorized by difficulty and include explanations for clarity. Regularly updated, it emphasizes Pythonic practices.
# LeetCode Python Solutions

![LeetCode Logo](https://upload.wikimedia.org/wikipedia/commons/1/19/LeetCode_logo_black.png)

This repository contains Python solutions for various LeetCode problems. Each problem is organized in its own directory under the `Solution/` folder, with a `readme.md` file providing the problem description, examples, constraints, and solutions in multiple programming languages.

## 🌟 Why Use This Repository?

#### **"Success is the sum of small efforts, repeated day in and day out."** — Robert Collier

This repository is designed to help you:

- **Master Problem-Solving**: Tackle a wide range of LeetCode problems with clear and concise solutions.
- **Learn Efficiently**: Understand optimized approaches and advanced techniques.
- **Stay Motivated**: Progress step by step, and see your skills grow with every solved problem.
- **Collaborate and Contribute**: Join a community of learners and developers to share knowledge and improve together.

Whether you're preparing for coding interviews, enhancing your algorithmic skills, or just exploring the joy of problem-solving, this repository is your companion on the journey to success.

---

## 📑 Table of Contents

- [🚀 Features](#-features)
- [📂 Repository Structure](#-repository-structure)
- [🛠️ How to Use](#️-how-to-use)
- [🌟 Highlights](#-highlights)
- [🤝 Contributing](#-contributing)
- [Steps to Contribute](#steps-to-contribute)
- [Contribution Graph](#contribution-graph)
- [📜 License](#-license)
- [📊 Statistics](#-statistics)
- [📌 Quick Links](#-quick-links)
- [Index of LeetCode Python Solutions](#index-of-leetcode-python-solutions)

## 🚀 Features

- **Comprehensive Solutions**: Includes Python solutions for a wide range of LeetCode problems.
- **Multi-Language Support**: Problem descriptions and solutions are available in multiple programming languages.
- **Organized Structure**: Each problem is neatly organized in its own directory with a dedicated `readme.md` file.
- **Interactive and Informative**: Easy-to-navigate structure with detailed explanations and examples.

## 📂 Repository Structure

```mermaid
graph TD
A[Root Directory] --> B[LICENSE]
A --> C[README.md]
A --> D[.gitattribute]
A --> E[Solution/]
A --> E12[gitignore]
A --> E14[workflow]
E --> F[LeetCode Qutions]
F --> |follow instructions| F1[README.md]
G[Readme.md]
F --> |Edit For Contribute| G1[Solutions.py]
```

## 🛠️ How to Use

1. Navigate to the `Solution/` folder.
2. Find the directory corresponding to the problem you are interested in (e.g., `104. Maximum Depth of Binary Tree`).
3. Open the `readme.md` file for the problem description, examples, and solutions.
4. Review the Python solution in the `.py` file.

## 🌟 Highlights

- **Beginner-Friendly**: Solutions are written in a clear and concise manner, making them easy to understand.
- **Advanced Techniques**: Includes optimized solutions for complex problems.
- **Regular Updates**: The repository is continuously updated with new problems and solutions.

## 🤝 Contributing

Contributions are welcome! If you have a better solution or additional test cases, feel free to submit a pull request.

### Steps to Contribute

1. Fork the repository.
2. Create a new branch for your changes.
3. Add your solution or update an existing one.
4. Commit your changes with a descriptive message.
5. Submit a pull request.

### Contribution Graph

```mermaid
graph TD
A[Contributors] --> B[Add New Solutions]
A --> C[Fix Bugs in Existing Solutions]
A --> D[Improve Documentation]
A --> E[Add Test Cases]
B --> F[Python Solutions]
B --> G[Multi-Language Support]
C --> H[Code Optimization]
D --> I[Update README.md]
D --> J[Add Problem Descriptions]
E --> K[Edge Cases]
E --> L[Performance Tests]
```

### Contribution Graph

```mermaid
graph TB;
A[Contributors] --> B[Fork]
B --> C[Clone in your system]
C --> D[Create Branch]
D --> E[Add Solution or Update Existing One]
E --> F[Commit Changes]
F --> G[Push Changes]
E --> L[Add Performance]
L --> M[Add Test Cases]
M --> N[Add Edge Cases]
N --> O[ Performance Tests] -->H
G --> H[Create Pull Request]
H --> I[Merge Pull Request]
I --> J[Add Reviewer of owner]
J --> K[Add lebels]

```

## 📜 License

This repository is licensed under the MIT License. See the `LICENSE` file for more details.

---

## 📊 Statistics

- **Total Problems Solved**: 100+ (and counting!)
- **Languages Supported**: Python, Java, C++, Go, TypeScript
- **Difficulty Levels**: Easy, Medium, Hard

---

## 📌 Quick Links

- [LeetCode Website](https://leetcode.com/)
- [Contribute to this Repo](https://github.com/your-repo-link)
- [MIT License](LICENSE)

---

![Happy Coding](https://media.giphy.com/media/3o7abldj0b3rxrZUxW/giphy.gif)

## Index of LeetCode Python Solutions

This index provides a quick overview of all the problems and solutions available in this repository. Each problem is organized under the `Solution/` folder, and older solutions are stored in the `privious/` folder.

## 📂 Solution Directory

### Problems by ID

- [**1004. Max Consecutive Ones III**](Solution/1004.%20Max%20Consecutive%20Ones%20III/readme.md)
- [**104. Maximum Depth of Binary Tree**](Solution/104.%20Maximum%20Depth%20of%20Binary%20Tree/readme.md)
- [**11. Container With Most Water**](Solution/11.%20Container%20With%20Most%20Water/readme.md)
- [**1161. Maximum Level Sum of a Binary Tree**](Solution/1161.%20Maximum%20Level%20Sum%20of%20a%20Binary%20Tree/readme.md)
- [**1207. Unique Number of Occurrences**](Solution/1207.%20Unique%20Number%20of%20Occurrences/readme.md)
- [**1372. Longest ZigZag Path in a Binary Tree**](Solution/1372.%20Longest%20ZigZag%20Path%20in%20a%20Binary%20Tree/readme.md)
- [**1448. Count Good Nodes in Binary Tree**](Solution/1448.%20Count%20Good%20Nodes%20in%20Binary%20Tree/readme.md)
- [**1456. Maximum Number of Vowels in a Substring of Given Length**](Solution/1456.%20Maximum%20Number%20of%20Vowels%20in%20a%20Substring%20of%20Given%20Length/readme.md)
- [**1466. Reorder Routes to Make All Paths Lead to the City Zero**](Solution/1466.%20Reorder%20Routes%20to%20Make%20All%20Paths%20Lead%20to%20the%20City%20Zero/readme.md)
- [**1493. Longest Subarray of 1's After Deleting One Element**](Solution/1493.%20Longest%20Subarray%20of%201's%20After%20Deleting%20One%20Element/readme.md)
- [**151. Reverse Words in a String**](Solution/151.%20Reverse%20Words%20in%20a%20String/readme.md)
- [**1657. Determine if Two Strings Are Close**](Solution/1657.%20Determine%20if%20Two%20Strings%20Are%20Close/readme.md)
- [**1679. Max Number of K-Sum Pairs**](Solution/1679.%20Max%20Number%20of%20K-Sum%20Pairs/readme.md)
- [**1732. Find the Highest Altitude**](Solution/1732.%20Find%20the%20Highest%20Altitude/readme.md)
- [**1926. Nearest Exit from Entrance in Maze**](Solution/1926.%20Nearest%20Exit%20from%20Entrance%20in%20Maze/readme.md)
- [**199. Binary Tree Right Side View**](Solution/199.%20Binary%20Tree%20Right%20Side%20View/readme.md)
- [**206. Reverse Linked List**](Solution/206.%20Reverse%20Linked%20List/readme.md)
- [**2095. Delete the Middle Node of a Linked List**](Solution/2095.%20Delete%20the%20Middle%20Node%20of%20a%20Linked%20List/readme.md)
- [**2130. Maximum Twin Sum of a Linked List**](Solution/2130.%20Maximum%20Twin%20Sum%20of%20a%20Linked%20List/readme.md)
- [**215. Kth Largest Element in an Array**](Solution/215.%20Kth%20Largest%20Element%20in%20an%20Array/readme.md)
- [**2215. Find the Difference of Two Arrays**](Solution/2215.%20Find%20the%20Difference%20of%20Two%20Arrays/readme.md)
- [**2336. Smallest Number in Infinite Set**](Solution/2336.%20Smallest%20Number%20in%20Infinite%20Set/readme.md)
- [**2352. Equal Row and Column Pairs**](Solution/2352.%20Equal%20Row%20and%20Column%20Pairs/readme.md)
- [**236. Lowest Common Ancestor of a Binary Tree**](Solution/236.%20Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree/readme.md)
- [**238. Product of Array Except Self**](Solution/238.%20Product%20of%20Array%20Except%20Self/readme.md)
- [**2390. Removing Stars From a String**](Solution/2390.%20Removing%20Stars%20From%20a%20String/readme.md)
- [**2462. Total Cost to Hire K Workers**](Solution/2462.%20Total%20Cost%20to%20Hire%20K%20Workers/readme.md)
- [**2542. Maximum Subsequence Score**](Solution/2542.%20Maximum%20Subsequence%20Score/readme.md)
- [**283. Move Zeroes**](Solution/283.%20Move%20Zeroes/readme.md)
- [**328. Odd Even Linked List**](Solution/328.%20Odd%20Even%20Linked%20List/readme.md)
- [**334. Increasing Triplet Subsequence**](Solution/334.%20Increasing%20Triplet%20Subsequence/readme.md)
- [**345. Reverse Vowels of a String**](Solution/345.%20Reverse%20Vowels%20of%20a%20String/readme.md)
- [**374. Guess Number Higher or Lower**](Solution/374.%20Guess%20Number%20Higher%20or%20Lower/readme.md)
- [**392. Is Subsequence**](Solution/392.%20Is%20Subsequence/readme.md)
- [**394. Decode String**](Solution/394.%20Decode%20String/readme.md)
- [**399. Evaluate Division**](Solution/399.%20Evaluate%20Division/readme.md)
- [**437. Path Sum III**](Solution/437.%20Path%20Sum%20III/readme.md)
- [**443. String Compression**](Solution/443.%20String%20Compression/readme.md)
- [**450. Delete Node in a BST**](Solution/450.%20Delete%20Node%20in%20a%20BST/readme.md)
- [**547. Number of Provinces**](Solution/547.%20Number%20of%20Provinces/readme.md)
- [**643. Maximum Average Subarray I**](Solution/643.%20Maximum%20Average%20Subarray%20I/readme.md)
- [**649. Dota2 Senate**](Solution/649.%20Dota2%20Senate/readme.md)
- [**700. Search in a Binary Search Tree**](Solution/700.%20Search%20in%20a%20Binary%20Search%20Tree/readme.md)
- [**724. Find Pivot Index**](Solution/724.%20Find%20Pivot%20Index/readme.md)
- [**735. Asteroid Collision**](Solution/735.%20Asteroid%20Collision/readme.md)
- [**841. Keys and Rooms**](Solution/841.%20Keys%20and%20Rooms/readme.md)

## 📂 Previous Solutions Directory

### Problems by ID

- [**2115. Find All Possible Recipes from Given Supplies**](privious/2115.%20Find%20All%20Possible%20Recipes%20from%20Given%20Supplies.py)
- [**2206. Divide Array Into Equal Pairs**](privious/2206.%20Divide%20Array%20Into%20Equal%20Pairs.py)
- [**2226. Maximum Candies Allocated to K Children**](privious/2226.%20Maximum%20Candies%20Allocated%20to%20K%20Children.py)
- [**2560. House Robber IV**](privious/2560.%20House%20Robber%20IV.py)
- [**2594. Minimum Time to Repair Cars**](privious/2594.%20Minimum%20Time%20to%20Repair%20Cars.py)
- [**3356. Zero Array Transformation II**](privious/3356.%20Zero%20Array%20Transformation%20II.py)

---

For detailed problem descriptions and solutions, navigate to the respective directories.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Solution:
def minReorder(self, n: int, connections: List[List[int]]) -> int:
def dfs(a: int, fa: int) -> int:
return sum(c + dfs(b, a) for b, c in g[a] if b != fa)

g = [[] for _ in range(n)]
for a, b in connections:
g[a].append((b, 1))
g[b].append((a, 0))
return dfs(0, -1)
Loading