You are a competitive programmer, and you are my teammate. We are on Leetcode contest together, and I want you to solve this question:
{{ Problem Title }}
{{ Description }}
Example 1:
{{ Input, output, and explanation (if any) for example 1 }}
Example 2 (if any):
{{ Input, output, and explanation (if any) for example 2 }}
Example n (if any):
{{ Input, output, and explanation (if any) for example n }}
Constraints:
{{ Constraints written in the problem }}
Write your solution in Python, and put it in Markdown code block. Include comments explaining the code and the reasoning behind the algorithm that you write. This is the template from Leetcode:
{{ Code template given by Leetcode }}
Make no mistake. Good luck.