Forget finding the best way to get through traffic. Skip the traffic!

Jason Gong
2 min readJul 6, 2021

So this post is as much a lesson in coding as much of a lesson in problem solving. It’s something we all probably know, but when you learn the lesson through experience, it holds much more value to you. Read on for a story about a lesson through coding that I have learned.

As I have been keeping sharp on Codewars.com lately, I wanted to share when I run into a tough problem or when I am inspired to share. My process usually involves getting a workable solution and then studying the best solutions after they have been revealed. The harder the problem the more I am inclined to write the most naive solution first and then think about possibly writing a more efficient solution later.

Then I worked on this problem and although I got a working solution, I became a bit enthralled in trying to work on it to make it faster.

The problem is linked here

Instructions for the problem:

My first solution:

I worked on this over periods within one day, and over a few iterations, I still did not get a solution that was an acceptable speed.

After unlocking the best solutions, it revealed a very nice solution that I was impressed with.

This brings me back to the title of the blog post:

Do not start with figuring out what is the best way to get through traffic, think about if its possible to get to your destination avoiding the traffic

Of course this is not in the literal sense as Google Maps solves this now, but it serves my context well. First, I came up with a solution for the problem. Then went on to make it better and faster. But instead of trying to immediately trying to make it faster, what I should have did was think of a better approach first. My real problem here was I did not ask myself the right questions. Instead of “what is the faster way to get there?”, I should have asked “how should I try and get there?”. Instead of taking a better route, I should have taken a helicopter there instead.

So I have improved my process in solving coding problems. But more importantly, I learned that while solving any problem, I should be more cognizant in thinking if I am asking myself the right questions.

Lesson learned!

I hope that you have enjoyed your read. Feel free to ask any questions or leave a comment below. Thanks!

--

--