totop.app’s Post

View organization page for totop.app

84 followers

Most devs fail sliding window problems in interviews. Not because they don't know the algorithm. Because they can't explain why it works. Here's the mental model that changes everything: Brute force checks every substring from scratch → O(n³) Sliding window reuses what you already know → O(n) The key insight: when you hit a duplicate character, you don't restart. You just shrink from the left until the duplicate is gone. Two pointers. One set. Linear time. while s[right] in char_set: char_set.remove(s[left]) left += 1 That single loop is the entire trick. Each character is visited at most twice — once added, once removed. That's why it's O(n) despite the nested while. I've seen candidates code this correctly and still get rejected. Because when the interviewer asked "why is this linear?" they froze. Complexity analysis isn't a bonus point. It's the interview. Can you explain O(n) vs O(n²) to a 5-year-old? #TechInterviews #Python #Algorithms #SoftwareEngineering #CodingInterview

  • graphical user interface

Love this. The 'Two pointers, one set' mental model is exactly how it should be taught. It’s not just about memorizing the template; it's about understanding the efficiency of data reuse. Quality advice for anyone prepping right now! 🚀

See more comments

To view or add a comment, sign in

Explore content categories