I have been approaching code challenges in different ways but I think I finally found my own approach so I am writing this post to share about my experience and hopefully this can be helpful for others:
- When I am facing a code challenge, I try to break down the problem in english first (let’s be honest, I use spanish if its too complicated) and if I am not familiar with the problem, I solve the problem without coding and sometimes I only use pen and paper (maybe because I think better when I have some visual guides)
- After I completely understand the input and output of the problem, I start writing my pseudo code (which is basically just english statements of the steps ) and I avoid using method’s names or any programming words because that could create some bias on how to approach the problem.
- Then, I check for any exceptions that I should considerate and add them to my pseudo code.
- Afterwards, based on my pseudo code, I start developing my driver code and breaking down my pseudo code where I start using programming terminology
- Finally, I start developing my code using different tools to debug (ex.debugger, puts), try the code (ex. irb), and keep updating my driving code.
Ex. Here is a method that was develop through breaking down a pseudocode:
# the missed destinations for current city
def missed_destinations(chosen_road)
# An array of all the roads left behind
roads_left_behind = roads_available.reject {|road| road == chosen_road }
# collect the destination left behind with those roads
roads_left_behind.map { |road| road.the_city_opposite(@current_city)}end
- I learned how important is to also research about other types of algorithms or other approaches that could be use to solve the problem. That way, after implementing my code, I could also compare with other approaches and learn through that as well.
Currently learning:
- I am trying to learn how to manage the stress of time pressure when I have to solve algorithms or code challenges during my interview while pairing. Sometimes, I panic and freeze but being honest about it and sharing my thoughts with my interviewers are helping a lot.