Get complete algorithm solutions with complexity analysis, optimization, and interview tips.
Explain and optimize this algorithm/solve this coding problem: Problem: [Describe the problem or paste the LeetCode/HackerRank problem] Constraints: - Input: [Input type and range] - Output: [Expected output] - Time complexity requirement: [O(n), O(log n), etc.] - Space complexity requirement: [O(1), O(n), etc.] Provide: 1. Brute force solution with complexity analysis 2. Optimized solution with explanation 3. Code in [Python/JavaScript/Java/C++] 4. Step-by-step walkthrough with example 5. Edge cases to handle 6. Visual representation (ASCII art if helpful) 7. Alternative approaches 8. When to use this pattern 9. Related problems 10. Interview tips for this type of problem