Here are the precise instructions you can paste into the README.md file for your GitHub Classroom assignment:
Write a Python function that finds the longest substring of a given string that contains exactly K unique characters. If no such substring exists, return 0.
def longest_substring_k_unique(s: str, k: int) -> int:-
Example 1:
Input: S = "araaci", K = 2 Output: 4 Explanation: The longest substring with exactly 2 unique characters is "araa". -
Example 2:
Input: S = "cbbebi", K = 3 Output: 5 Explanation: The longest substring with exactly 3 unique characters is "cbbeb" or "bbebi". -
Example 3:
Input: S = "aa", K = 1 Output: 2 Explanation: The longest substring with exactly 1 unique character is "aa".
- The string
Swill have at least one character and at most 10^6 characters. - The integer
Kwill be between 1 and the number of distinct characters in the string.
-
Fork the Assignment Repository:
- Click on the "Fork" button in the top right corner of this repository to fork it into your own GitHub account.
-
Clone Your Forked Repository:
- Clone the repository to your local machine using the following command in your terminal:
git clone https://github.com/<your-github-username>/source-code-management-exercise.git
- Replace
<your-github-username>with your GitHub username.
- Clone the repository to your local machine using the following command in your terminal:
-
Create a New Branch:
- In your local repository, create a new branch to work on your solution:
git checkout -b gcd-feature
- In your local repository, create a new branch to work on your solution:
-
Implement Your Solution:
- Implement the
longest_substring_k_uniquefunction in the providedsolution.pyfile. Ensure your code handles edge cases and test it thoroughly before submission.
- Implement the
-
Commit Your Changes:
- Once you’ve written and tested your solution, stage and commit the changes:
git add solution.py git commit -m "Implemented solution for longest substring with K unique characters"
- Once you’ve written and tested your solution, stage and commit the changes:
-
Push the Changes:
- Push your changes to the
gcd-featurebranch on your forked repository:git push origin gcd-feature
- Push your changes to the
-
Create a Pull Request:
- Go to your forked repository on GitHub.
- Click the "Compare & pull request" button to create a pull request back to the original repository.
- Make sure you are comparing your
gcd-featurebranch with themainbranch of the original repository. - Submit the pull request.
Once you submit your pull request, you will be assigned a peer’s solution to review. Follow these steps for peer review:
-
Review the Peer’s Code:
- Check the peer’s code for correctness, efficiency, and readability.
- Provide constructive feedback and suggest improvements where necessary.
-
Submit Your Feedback:
- Use the GitHub review feature to submit your feedback.
Please make sure your pull request is submitted before the deadline: [INSERT DEADLINE DATE].
- Ensure your code follows the required Python function signature.
- Make sure your solution is efficient and can handle large inputs (up to 10^6 characters).
- Be respectful and constructive in your peer reviews.