How to write code for 'Hard' problems during phone interview?
Anonymous User
254

This is a very basic question but still want to raise it here to see what others think about it.
I am solving LC 76 and the problem I am facing is that I lose track of values in variables while implementing the solution.
After reading the question, I figured out an algorithm by drawing diagrams and by digging into how will variables/program-state change under different possible conditions. I followed a couple of examples and executed those examples on paper and the algorithm made sense.

But when I tried to convert it to code in one sitting (under 30 min), I lost track of how the variables will change under different conditions.

To be specific, the solution to the problem here https://leetcode.com/problems/minimum-window-substring/solution/ has at least 5 variables to keep track of the state of the solution (l,r, formed, window_counts,ans) and at least 4 conditional statements. I find it really to keep track of all these things in mind and if I use paper to track some of these things, it takes a lot more time than an interview setting.

I know practice is going to help me but is there anything else that can help me? How do you guys do it?

Comments (2)