Yesterday I have attended for an interview. He gave me few programming questions to solve. When I solved them, the interviewer said it can be done in better Time complexity. I was so much depressed that I cannot do the program in the best time complexity. Finally I am not able to get through the interview process. But what I want to know is how can we do in best time for any problem? What should be my approach to reach that state? I know the perfect answer is practice. But still I want to know how and what ways to do a program such that it runs in less time and use best memory. What books I have to read? What problems I have to practice?
P.S: I know this is not a technical question. But please let me know how can I do that.
One of the best books about algorithms, data structures, time and space complexity is Introduction to Algorithms. I can also recommend you to read following books for good preparation for an interview: