Skip to content

This Django application calculates the length of the longest substring without repeating characters, based on the logic implemented in an algorithm derived from a LeetCode problem

License

Notifications You must be signed in to change notification settings

Mike014/LongestSubstringApp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Longest Substring App

This Django application calculates the length of the longest substring without repeating characters, based on the logic implemented in an algorithm derived from a LeetCode problem. The solution to the problem can also be found in my LeetCode repository.

Features

  • Algorithm Integration: The logic for calculating the longest substring without repeating characters is implemented in algorithm.py and integrated into the Django app through the views.py file.
  • User Input: A simple HTML form allows users to input a string and calculate the result.
  • Database Storage: Results are saved in the database for record-keeping and debugging purposes.

Debugging Process

Initially, the app did not return the correct substring length. Here's the step-by-step debugging process that helped resolve the issue:

  1. Algorithm Verification:

    • The logic in algorithm.py was independently verified using unit tests to ensure correctness.
  2. Django Debugging:

    • The DEBUG setting in settings.py was set to TRUE:
      DEBUG = True
    • Debugging messages were added in views.py to trace request methods and ensure the correct flow of data:
      print("Received Request: ", request.method)
  3. Root Cause Analysis:

    • After testing, the issue was identified in the HTML template. The problem was in the line:
      <p>Longest Substring Length: {{ result.length_of_longest_substring }}</p>
      • The variable name did not match the field in the models.py file.
  4. Fix:

    • The incorrect variable name was corrected to:
      <p>Longest Substring Length: {{ result.length_of_longest_substring }}</p>

Files in the Project

  • algorithm.py: Contains the logic for calculating the longest substring without repeating characters.
  • views.py: Integrates the algorithm with Django views and handles user requests.
  • models.py: Defines the SubstringResult model for storing input strings and their corresponding results.
  • templates/substring/index.html: The HTML template for the user interface.

How to Run

  1. Clone the repository:
    git clone https://github.com/Mike014/LongestSubstringApp.git
    cd LongestSubstringApp
  2. Create and activate a virtual environment:
python3 -m venv venv
source venv/bin/activate
  1. Install dependencies:
    pip install -r requirements.txt
  2. Run migrations:
    python manage.py migrate
  3. Start the server:
    python manage.py runserver

Notes

  • The algorithm is based on my solution for the LeetCode problem linked above.
  • Debugging was essential to ensure the application logic worked seamlessly from the algorithm to the user interface.

About

This Django application calculates the length of the longest substring without repeating characters, based on the logic implemented in an algorithm derived from a LeetCode problem

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published