If you take any CSE class, you will be required to write many programs over the semester. Depending on your style and approach to coding, you can take a single hour to finish the program or five hours. Ideally, you want to look over the programming assignment before you actually start coding. This may sound obvious, but not everyone will completely analyze the details of the assignment before starting. Because of the way the instructions are written, a student may be tempted to start coding in a procedural manner without knowing what may be ahead. This approach will usually lead to bugs in your code because some parts of the program may not be optimized for other parts. If you have a full understanding of the assignment before you begin, it will be much easier to map out your course of action.
One of the other important factors of being successful in your assignments is time management. Different people need different amounts of time to finish an assignment. If you are the type that likes to code without hassle, it would be better to start early and do a little everyday. Even if you are the type that likes to do all of it in one go, you should try to attempt the assignment a little beforehand. Personally, I am the type that likes to be somewhat pressured because it forces me to use my brain a bit harder, though this is not recommended.
Basically, if your approach to coding is not producing results, you need to change or it will hurt in the long run.