/Python.Challenges

A collection of Python solutions to various coding challenges.

Primary LanguagePythonMIT LicenseMIT

LeetCode Hackerrank Codewars Exercism



Python Coding Challenges

A collection of my solutions to various coding challenges, grouped by difficulty.

GitHub commit activity GitHub last commit (by committer) Maintenance GitHub repo size GitHub License

Static Badge Static Badge

⚠️ Please attempt these exercises on your own. ⚠️

Purpose

Hi 👋, I'm George!

This repository acts as my diary, of sorts, to mark progress as I traverse the world of competitive programming and elevate my skill level to achieve Mastery of the Python language.

You can go peruse these exercises and try them yourself in any order you like. They are grouped by Platform of origin, then difficulty level and finally alphabetically by their title for easy access.

Happy coding! 🥳

Share with the Community

Please consider, leaving a Star🌟

Additionally, consider sharing it with the community using the badges below.

Reddit Ycombinator Twitter Facebook Linkedin

Repository Roadmap


Status Goal Progress Report ETA
🚧 Create Indexes for Each Difficulty Level in progress 📅 13/01/2024
📅 Create a Template for each Challenge README.md scheduled 📅 19/01/2024
🚧 Create Template for initiating a README.md & empty solution.py. in progress 📅 13/01/2024
✔️ Create Links for Each Challenge Folder under Index. ready 📅 11/01/2024
📅 Automate the update process. scheduled 📅 03/02/2024
🚧 Fix the Share Buttons in progress 📅 14/01/2024

Updates

  • Should I reconsider notes.txt to be a notes.md ?
  • Create a database for Challenges.
  • Minimize requests to only new challenges.

Input

  • Challenge Link

Logic

  • Fetch description inside notes?
  • Fetch automatic tests?
  • Overwite wars.py with sample code provided?

Output

  • Open wars.py + notes inside VS Code ?

Add.py

Input

  • Set a new argument -s for "submit --yes" if the want the contents of wars.py to be submitted as their solution.
  • Set a new argument -n for "notes" if they want the contents of notes file to be sumbitted as their notes for the challenge.

Validation

  • Check valid username
  • Check Template.md file exists.
    • Check Template.md file valid.
    • Determine Challenge Path

Output

  • Open folder? or open solutions.py using VS Code.

Improvements

  • What to do when API request fails?
  • Query database

Update.py - Update Database

Input

  • Platform
  • Username

Logic

  • Validation methods
  • Fetch User info based on Platform
  • Update Database [only with new challenges] - key [id]
  • Retrieve File Structure.
  • Ask user if missing challenges should be added automatically to his folder structure. Yes = call add.py for each one (no arguments). No = exit().

Output

  • "Updating the database..."
  • "Acquired {number} new challenges. Update your folder structure automatically? Y/N --default yes."

Functions.py

Notes

  • Seperate functions based on their use? (Validation, API, Output etc.)

  • Seperate functions used under update.py and add.py in different files.

  • Common ones should be in one shared file.

  • Parse Credentials

    • Find a way for the user to set username per platform in the database.
    • if "-u" is used once, it should be the new default for certain platform. This means that if I use "add.py -l "codewars.com....." -u "george123" then, under Codewars, in the database "george123" must be saved as the new default.
  • Get user info -> Update Database.

    • Must gather data until all pages are completed.
    • Find which do not exist in database.
    • Add new Ones to the database.

Completed ✓

  • Configure YAPF.
  • Set up a usage guide for the add.py client.

Coding Style

Almost every problem has a long, verbose and short, concise solution. IMHO, a long descriptive solution is almost always preferred over a cryptic one-liner. The exception being, a shared understanding of the code by the entire development team.

Having said that, in the process of tackling these challenges, I find myself opting for concise code with Pythonic syntax, as my main goal is to match the preferred solution (as voted by the platform's audience) to each individual challenge.

Repository Updates

If you opt to watch this repository, you will notice a consistent effort to refactor and optimize my code. Sometimes for efficiency, sometimes for readability. Sometimes for both.

You might also find code be refractored as a more targeted solution to a generic problem. That happens because, in the process of tackling these challenges, small snippets of reusable code tend to arise, those, end up in my Visual Code Snippets (JSON) to be used when the opportunity emerges.

Lessons Learned

Practicing algorithmic problems has helped me improve my algorithmic thinking. It has also helped me during interviews, by allowing me to be more confident with walking people through my thinking as I tackle problems.

Although, the Biggest Lesson I learned in tackling this endless supply of questions is understanding that there always a long way to go. The only way to truly emerge victorious is to focus on yourself and keep challenging him/her consistently.

On the same note, don't let failures stop you; not being able to answer a question is okay, as long as you take the initiative to improve.

Methodology

The higher the difficulty, the more I tend to tackle problems recursively, this means that, I tend to go for the most verbose and intentionally slower solution at first; working my way to a more efficient and concise one.

Tackling problems in a logical sequence is vital to my process. With each iteration, I refactor my code, moving closer and closer to the optimal solution. By the time, I finally submit my code for verification to any online platform, I am positive my code is able to pass the test suite and has little to no room for improvement based on my current understanding and knowledge of Python.

Multiple Solutions

As you might have noticed, some challenges include more than one solution, that's either because I attempted the challenge multiple times as my knowledge level progressed or because occasionally, two or more competing solutions will arise as I am thinking the problem through. When that happens, if I can't immediately differentiate the best solution across the set, I pursue them all, sequentially of course.

In case the resulting solutions are similar in nature and performance, then both are included for achiving purposes.

Enviroment

As part of this exploration into competitive coding, I have created a seperate repository; a local coding environment, functionally similar to most code editors, as a means of recursively testing my code as I am improving it.

You can find the project here along with details on how to set it up for yourself.

Performance

A quick way to compare between solutions' execution speed is Perfpy.

Additionally, included under this project is my code performance tester, using cProfiler where you can test the efficiency of your solutions or compare your answers against mine.

Start your own Journey

Step 1 - Mirroring

git clone https://github.com/gzachariadis/Python.Challenges.git
cd Python.Challenges

Step 2 - Configuring Credentials

python config.py --configure --platform Codewars --username [username]

Example Usages

python config.py --configure --platform Exercism --username george1234
python config.py --configure --default-template my_Template.md

Step 3 - Creating New Entry

python .\add.py --link [URL]

Usage

Usage: python add.py [options]
    Options:
      "-h", "--help"            Show this help message and exit
      "-l", "--link"            Specify the challenge url (required)
      "-u", "--username"        Specify your username (required)
      "-t", "--template"        Specify Template file
      "-s", "--submit"          Submit wars.py as solution file
      "-n", "--notes"           Submit notes as solution notes

Step 4 - Updating Manually (Optional)

python .\update.py --platform [Platform] --username [Username]

Usage

Usage: python update.py [options]
    Options:
      "-h", "--help"            Show this help message and exit
      "-u", "--username"        Specify your username (required)
      "-a", "--append"          Append to folder structure (default no)

Step 5 - Create your own Template

Modify the Template.md file according to your needs, or create one yourself.

Careful when changing the "id" inside of the HTML tags, as they are used to fill the content accordingly.

Progress Statistics

Platform Expert Challenging Proficient Moderate Novice
Codewars 0 0 0 0 0
Leet Code 0 0 0 0 0
Hacker Rank 0 0 0 0 0
Exercism 0 0 0 0 0

Mastery Rankings

alt rank

Repository Structure

├── Codewars/
│    │
│    ├── 8-kyu/
│    │    ├── Challenge Title/
│    │    │                 └── solution.py
│    │    │                 └── README.md
│    │    │
│    │    ├── Challenge Title/
│    │    │                 └── solution_1.py
│    │    │                 └── solution_2.py
│    │    │                 └── notes.txt
│    │    │                 └── README.md
│    │    │
│    │    └── ...
│    │
│    ├── 7-kyu/
│    │    ├── Challenge Title/
│    │    │                  └── solution_1.py
│    │    │                  └── solution_2.py
│    │    │                  └── README.md
│    │    │
│    │    ├── Challenge Title/
│    │    │                  └── solution.py
│    │    │                  └── notes.txt
│    │    │                  └── README.md
│    │    │
│    │    └── ...
│    │
│    │
│    └── README.md - Challenges indexed and grouped by difficulty.
│    │
│    │
├── HackerRank/
│    │
│    │
│    │
│    │
│    │
│    └── README.md - Challenges indexed and grouped by difficulty.
│    │
│    │
├──  Exercism/
│    │
│    │
│    │
│    │
│    └── README.md - Challenges indexed and grouped by difficulty.
│    │
│    │
├──  Leetcode/
│    │
│    │
│    │
│    │
│    │
│    └── README.md - Challenges indexed and grouped by difficulty.
│    │

FAQ

Why aren't challenge descriptions automatically pulled from APIs?

I prefer to write my own descriptions to any challenges for several reasons; The clarity of my own thoughts for one, gives me a more familiar feel. I find most author's descriptions are lacking in that same clarity.

Additionally, I write long verbose descriptions which more effectively accompany my short-form answers.

Author Notes

You acknowledge and agree that your use of the repository materials is at your own risk. The author accepts no responsibility or liability whatsoever for any consequences arising directly or indirectly from any action or inaction taken by you on the basis of, or in reliance on, any information or material contained in or linked to this repository. The information contained in this repository is provided "as is" with no warranties of completeness, accuracy, usefulness, or timeliness. The author reserves the right to change any of the items used or contained in the repository at any time without notice.

Using material from this repository to gain rank in any of these platforms, violates each individual Platform's Policy and might result in getting you banned. Consider yourself warned.