Welcome to my LeetCode Challenges repository. This repository contains my personal solutions and approaches to various coding challenges from LeetCode. These challenges span a wide range of topics and difficulty levels in the field of algorithms and data structures.
LeetCode is a platform for preparing technical coding interviews. It provides a vast collection of coding challenges that cover a wide range of topics, including algorithms, data structures, databases, and more. This repository is a collection of my solutions to these challenges, along with explanations and insights into my thought process.
Below is a list of some of the challenges included in this repository. Each challenge is located in its respective directory under the `challengues` folder.
-
Challenge 1: Two Sum
- Solution:
challengues/two-sum/index.js - Description: Find two numbers in an array that add up to a specific target.
- Link: LeetCode Problem
- Solution:
-
Challenge 2: Add Two Numbers
- Solution:
challengues/add-two-numbers/index.js - Description: Add two numbers represented by linked lists.
- Link: LeetCode Problem
- Solution:
-
Challenge 3: Longest Substring Without Repeating Characters
- Solution:
challengues/longest-substring-without-repeating-characters/index.js - Description: Find the length of the longest substring without repeating characters.
- Link: LeetCode Problem
- Solution:
-
Challenge 4: Median of Two Sorted Arrays
- Solution:
challengues/median-of-two-sorted-arrays/index.js - Description: Find the median of two sorted arrays.
- Link: LeetCode Problem
- Solution:
-
Challenge 5: Longest Palindromic Substring
- Solution:
challengues/longest-palindromic-substring/index.js - Description: Find the longest palindromic substring in a given string.
- Link: LeetCode Problem
- Solution:
-
Challenge 6: Zigzag Conversion
- Solution:
challengues/zigzag-conversion/index.js - Description: Convert a string to zigzag pattern on a given number of rows.
- Link: LeetCode Problem
- Solution:
-
Challenge 7: Reverse Integer
- Solution:
challengues/reverse-integer/index.js - Description: Reverse digits of an integer.
- Link: LeetCode Problem
- Solution:
-
Challenge 8: String to Integer (atoi)
- Solution:
challengues/string-to-integer-atoi/index.js - Description: Implement the
atoifunction to convert a string to an integer. - Link: LeetCode Problem
- Solution:
-
Challenge 9: Palindrome Number
- Solution:
challengues/palindrome-number/index.js - Description: Determine whether an integer is a palindrome.
- Link: LeetCode Problem
- Solution:
-
Challenge 10: Regular Expression Matching
- Solution:
challengues/regular-expression-matching/index.js - Description: Implement regular expression matching with support for
.and*. - Link: LeetCode Problem
- Solution:
-
Challenge 11: Container With Most Water
- Solution:
challengues/container-with-most-water/index.js - Description: Find two lines that together with the x-axis form a container that holds the most water.
- Link: LeetCode Problem
- Solution:
-
Challenge 12: Running Sum of 1d Array
- Solution:
challengues/running-sum-of-1d-array/index.js - Description: Given an array nums. We define a running sum of an array as runningSum[i] = sum(nums[0]…nums[i]). Return the running sum of nums.
- Link: LeetCode Problem
- Solution:
-
Challenge 13: Richest Customer Wealth
- Solution:
challengues/richest-customer-wealth/index.js - Description: You are given an m x n integer grid accounts where accounts[i][j] is the amount of money the i(th) customer has in the jth bank. Return the wealth that the richest customer has. A customer's wealth is the amount of money they have in all their bank accounts. The richest customer is the customer that has the maximum wealth.
- Link: LeetCode Problem
- Solution:
-
Challenge 14: Fizz Buzz
- Solution:
challengues/fizz-buzz/index.js - Description: Given an integer n, return a string array answer (1-indexed) where: answer[i] == "FizzBuzz" if i is divisible by 3 and 5. answer[i] == "Fizz" if i is divisible by 3. answer[i] == "Buzz" if i is divisible by 5. answer[i] == i (as a string) if none of the above conditions are true.
- Link: LeetCode Problem
- Solution:
-
Challenge 15: Number of Steps to Reduce a Number to Zero
- Solution:
challengues/number-of-steps-to-reduce-a-number-to-zero/index.js - Description: Given an integer num, return the number of steps to reduce it to zero. In one step, if the current number is even, you have to divide it by 2, otherwise, you have to subtract 1 from it.
- Link: LeetCode Problem
- Solution:
-
Challenge 16: Middle of the Linked List
- Solution:
challengues/middle-of-the-linked-list/index.js - Description: Given the head of a singly linked list, return the middle node of the linked list. If there are two middle nodes, return the second middle node.
- Link: LeetCode Problem
- Solution:
-
Challenge 17: Maximum Depth of Binary Tree
- Solution:
challengues/maximum-depth-of-binary-tree/index.js - Description: A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
- Link: LeetCode Problem
- Solution:
-
Challenge 18: Reformat The String
- Solution:
challengues/reformat-the-string/index.js - Description: Find a permutation of the string where no letter is followed by another letter and no digit is followed by another digit. That is, no two adjacent characters have the same type. Return the reformatted string or return an empty string if it is impossible to reformat the string.
- Link: LeetCode Problem
- Solution:
-
Challenge 19: 2696. Minimum String Length After Removing Substrings
- Solution:
challengues/minimum-string-length-after-removing-substrings/index.js - Description: You are given a string s consisting only of uppercase English letters. You can remove any occurrence of one of the substrings "AB" or "CD" from s. Return the minimum possible length of the resulting string that you can obtain.
- Link: LeetCode Problem
- Solution:
-
Clone the repository:
git clone https://github.com/Khanos/leetcode-challenges.git cd leetcode-challenges -
Install the dependencies:
npm install
This repository uses Jest for testing JavaScript solutions and Python's unittest module for testing Python solutions.
To run all JavaScript tests:
```sh
npm run test:javascript
```
To run all Python tests:
```sh
npm run test:python
```
Contributions are welcome! If you have a better solution or a new challenge to add, please fork the repository and submit a pull request.
1. Fork the repository.
2. Create a new branch (git checkout -b feature-branch).
3. Make your changes.
4. Commit your changes (git commit -am 'Add new feature').
5. Push to the branch (git push origin feature-branch).
6. Create a new Pull Request.
Distributed under the MIT License. See LICENSE for more information.