Skip to content

This repository is my journey on Leetcode. It contains my solutions to Leetcode problems with different programming languages, along with a brief explanation of the approach I used to solve each one

Notifications You must be signed in to change notification settings

danielpaez-dev/Leetcode-solutions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

80 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Leetcode Solutions

JavaScript Python TypeScript MySQL Status

English | EspaΓ±ol

Welcome to my collection of Leetcode solutions! Here you'll find my approaches and solutions to various Leetcode problems in different programming languages.

LinkedIn GitHub

Index


πŸ› οΈ Problem-Solving Approach

A structured approach is crucial for efficiently tackling LeetCode problems and developing strong problem-solving skills. This process emphasizes critical thinking and understanding over simply finding a working solution.

πŸ’‘ I utilize the Pomodoro Technique to maintain focus and prevent burnout during problem-solving sessions. This involves working in focused 25-minute intervals, followed by 5-minute breaks. Resources: Forest or Pomofocus

Here's my step-by-step approach:

  1. 🧠 Understand the Problem

    • Read the problem statement carefully, multiple times if necessary. If you're having difficulty with English, you might consider using DeepL translator, a way better alternative than Google translator.
    • Re-read the statement, highlighting key concepts, constraints, and requirements. Clearly identify the inputs and desired outputs.
    • You can use the snipping tool (Windows) or any other alternatives for Mac/Linux to capture any relevant information.
    • Simplify and break down complex problems into smaller, more manageable subproblems. Divide and conquer!
    • A good way of knowing if you truly understand the problem is imaging that you are teaching somebody else the problems with your own words.
  2. πŸ“ Break down the problem and brainstorm solutions

    • Study and analyze the provided examples to fully understand the expected behavior and create additional test cases if needed, including edge cases (e.g., empty inputs, maximum values) to deepen your understanding of the problem.
    • Sketch a flowchart or other diagram type to visualize the input-output flow if necessary. These are some useful tools you may include for this taks:
      • Draw.io
      • Lucidchart
      • Figma
      • AlgoMonster - A highly useful tool not just for creating flowcharts, but also for understanding the best data structures, algorithms, and other problem-solving techniques.
  3. 🧩 Identify the Problem Type

    • Categorize the problem: Is it related to search, sorting, optimization, graph traversal, or another common type?
    • Identify applicable patterns or techniques: Sliding window, divide and conquer, backtracking, two pointers, dynamic programming, etc.
  4. πŸ› οΈ Choose the Right Data Structures

    • Select the most suitable data structures for the problem:
      • Arrays, hash maps, heaps, trees, graphs, etc.
    • Evaluate the time and space complexities for any scenario needed (Big O).
    • This is a usefull resource for deciding wich data structure, pattern or algorithm should you use.

    Data Structures Credit to: https://www.softwaretestinghelp.com/data-structures-in-cpp/

  5. ✍️ Draft a Direct Solution (Pseudocode)

    • Develop a straightforward, initial solution using pseudocode. This serves as a baseline and helps identify potential bottlenecks and find beter solutions later.
    • Estimate the time and space complexity of this initial approach.
  6. ⚑ Optimize the Solution

    • Explore ways to enhance the algorithm's efficiency:
      • Can a different data structure reduce complexity?
      • Can redundant computations be eliminated?
    • Compare alternative approaches and select the most efficient one based on time and space complexity.
  7. πŸ§ͺ Test with Pseudocode

    • Validate the optimized solution using test cases on paper or in pseudocode.
    • Ensure it handles all edge cases correctly.
  8. πŸ§‘β€πŸ’» Implement the Solution in Code

    • Translate the pseudocode into your preferred programming language. Leetcode allows you to use a vast variety of programming languages such as: C++, Java, Pyhton, C, C#, JavaScript, TypeScript, PHP, Swift, Kotlin, Dart, Go, Ruby, Scala, Rust, Racket, Erlang and Elixir.
    • Ensure the code is clean, modular, and follows best practices.
  9. πŸ”§ Refactor for Clarity

    • Simplify complex logic and improve code readability.
    • Add comments to explain key sections of the code.
  10. Submit and Reviewβœ…

    • Submit the solution on Leetcode and create the markdown. It will help to clarify what you've done.
    • Review and analyze high-rated solutions: Don't just check if your solution works – actively learn from others! Analyze high-rated solutions to identify alternative approaches, optimizations, and best practices.
  11. Learn and Practice πŸ“˜

    • Study better solutions, focusing on techniques or optimizations you may have missed.
    • Reimplement those solutions to solidify your understanding.
  12. πŸ”„ Iterate and Improve

    • If you discover new insights or patterns, revisit and refine your solution.
    • Keep iterating until you're confident it's the best possible approach. Improvement takes timeβ€”sometimes months or even years. After submitting your solution, always review others' approaches to learn from them and apply these lessons to this and to future problems. There's no shame in studying someone else's solution; Don’t skip this step, it is a key part of the learning process.

πŸ“ Note

If you're feeling stuck or frustrated during the process, consider taking a longer break or continuing the next day. Sometimes, giving your mind some rest leads to better solutions. Don't forget to stay active with regular exercise, and make sure you're getting enough sleep and proper nutrition and hydration. Believe it or not this will help you solve problems more effectively.

By following this systematic process, I ensure that my solutions are not only correct but also efficient and well-documented. Here is a valuable resource of a similar procedure: Link

Back to Top

πŸ’» Solutions

Below is a list of Leetcode problems that I have solved. Each entry includes a link to the problem, my solution, and its difficulty level.

# Title Solution Difficulty
1 Two Sum My Solution Easy
11 Container With Most Water My Solution Medium
13 Roman to Integer My Solution Easy
14 Longest Common Prefix My Solution Easy
26 Remove Duplicates from Sorted Array My Solution Easy
27 Remove Element My Solution Easy
28 Find the Index of the First Occurrence in a String My Solution Easy
35 Search Insert Position My Solution Easy
58 Length of Last Word My Solution Easy
66 Plus One My Solution Easy
69 Sqrt(x) My Solution Easy
70 Climbing Stairs My Solution Easy
104 Maximum Depth of Binary Tree My Solution Easy
136 Single Number My Solution Easy
151 Reverse Words In A String My Solution Medium
175 Combine Two Tables My Solution Easy
283 Move Zeroes My Solution Easy
334 Increasing Triplet Subsequence My Solution Medium
338 Counting Bits My Solution Easy
345 Reverse Vowels of a String My Solution Easy
374 Guess Number Higher or Lower My Solution Easy
392 Is Subsequence My Solution Easy
577 Employee Bonus My Solution Easy
596 Classes More Than 5 Students My Solution Easy
605 Can Place Flowers My Solution Easy
643 Maximum Average Subarray I My Solution Easy
704 Binary Search My Solution Easy
724 Find Pivot Index My Solution Easy
735 Asteroid Collision My Solution Medium
875 Koko Eating Bananas My Solution Medium
1068 Product Sales Analysis I My Solution Easy
1071 Greatest Common Divisor of Strings My Solution Easy
1148 Article Views I My Solution Easy
1207 Unique Number of Occurrences My Solution Easy
1280 Students and Examinations My Solution Easy
1378 Replace Employee ID With The Unique Identifier My Solution Easy
1431 Kids With the Greatest Number of Candies My Solution Easy
1456 Maximum Number of Vowels in a Substring of Given Length My Solution Medium
1679 Max Number of K-Sum Pairs My Solution Medium
1683 Invalid Tweets My Solution Easy
1732 Find the Highest Altitude My Solution Easy
1757 Recyclable and Low Fat Products My Solution Easy
1768 Merge Strings Alternately My Solution Easy
1929 Concatenation of Array My Solution Easy
2206 Divide Array Into Equal Pairs My Solution Easy
2215 Find the Difference of Two Arrays My Solution Easy
2300 Successful Pairs of Spells and Potions My Solution Medium
2390 Removing Stars From a String My Solution Medium
2703 Return Length of Arguments Passed My Solution Easy

Back to Top

About

This repository is my journey on Leetcode. It contains my solutions to Leetcode problems with different programming languages, along with a brief explanation of the approach I used to solve each one

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published