3 ms·
Don't sit down in front of your computer until you have a very good idea of how your algorithm is going to work and how to code it. Sit down in front of a piec
by i_don_t_know 8y ago
Don't sit down in front of your computer until you have a very good idea of how your algorithm is going to work and how to code it.
Sit down in front of a piece of paper with a pen. Draw diagrams to visualize the data structures that you're working with. Sketch different corner cases (for example, arrays of odd and even length). Informally (playfully) derive an algorithm to do what you want and convince yourself that it does what you want. Play through different cases on paper, maybe use markers (coins) to keep track of where you are. Write down the details so you don't have to keep them in your head.
I have plenty of experience now, but I still use paper and pencil when I have to solve a problem I haven't solved before. It's just so much easier to explore the problem on paper, to think about corner cases, to visualize the inputs, outputs, and intermediate data structures, and to wrap your head around everything.
- Tmp1234 8y agoI have been doing that, but as I said in response to another comment, I don't see what I'm missing or what's wrong until I start to code it. Either the test cases fail or I run into something that's easy to describe in pseudocode, but more difficult to describe in real code. It seems, at the time of using the paper and pencil, I would be trying to know what I don't know because it always seems fine before I start to code it and then I discover its not.