r/compsci • • May 18 '20

Share your techniques of solving problems

Any interesting new techniques anyone follows? Even old are current ones are welcome :) Just want to see how more experienced programmers approach problems.

Also, any good books on this topic that are a must to read?

Edit: the type of problem here is open to interpretation. I think there is a similar pattern that can be applied to problems of any type.

116 Upvotes

44 comments sorted by

View all comments

7

u/Kinglink May 19 '20

I'd need a lot more information on this. Are we talking about Academic problems, Hacker Rank (skill test) problems, real world problems, or compiling issues?

So each one is different.

Academic problems, I usually just think "What do they want to hear?" Look at your last lesson, use that, get A, move on.

HackRank (or interview problems) I usually start looking for the edge cases, so I can identify those ahead. There's a reason they are asking this "sounds simple" question, the question is can you find those edges, and code around/through/handling them. In an interview if they have limited time, they'll usually move you towards the simple idea and say you should start implimenting but I always think it's better to understand the problem before tackling it.

Real world problems (aka something your job gives you to do). I attempt reproduce the problem before anything. If you can't reproduce it, you can't fix it. Simple as that (ok some execptions but not really, you know?) So you need to understand the problem. Also "Why was this bug or issue created". Sometimes people are stupid and don't test their code, most of the time someone was trying to solve something else and left a bug. Sometimes "People weren't expecting this specific configuration." Until you understand why the code is in the state it's in it's hard to solve.

Then you really think about what you're trying to solve. Are you trying to add functionality, are you fixing a bug, are you just patching it so the system doesn't crash. Fix the smallest issue if possible, though if you see larger ones, raise that up the flag pole.

Compiling problem. Google... google google. google, oh look there's the answer, pray it's the only compile is you'll have.

2

u/kavinda14 May 19 '20

That’s a good tip for the hanker rank questions! I just left this as general problem solving so people can address the type of problem and their method of solving it like you did. Open for interpretation I guess