loading...

How to Solve a Coding Challenge

123jackcole profile image Jack Cole ・2 min read

Recently I've been doing LeetCode's weekly contests and I recommend anyone wanting to practice for interviews do them as well. The contests are great because they mimic the environment of a real interview. You are given a set amount of time (often 90 minutes) to solve several problems that increase in difficulty. The tests do a good job of imitating a high pressure environment rather than practicing problems in a lax setting.

After repeatedly taking these contests I feel that I've nailed down a method that works for me for solving problems and wanted to share. Anyway lets jump into how I solve each problem.

  1. Take the time to read the problem 2-3 times until I'm confident I understand it. If I have a few confusions I continue to the next step anyway which is...
  2. Examine the test cases and make sure I understand why the test inputs lead to the test outputs.
  3. If you're given the expected time complexity you can narrow down approaches they want you to use. For example, if they want you to do an O(log n) search you can first try a binary search.
  4. At this point I think about how I'm going to approach the problem while looking at the provided code as well as the provided constraints.
  5. Always try to think of edge cases that could cause problems before you code as well as while you are coding

Thanks for reading! I'd love to hear what works for you when you're solving a coding problem and how what you think I should do differently.

Discussion

pic
Editor guide
Collapse
mariobatalha profile image
Mário Batalha

Pretty cool, I was looking for a quiz to solve some logic problems, this post helped me as well. Do you know other websites for training logic?