1. 程式人生 > >Problem Solving Skills: Add Two Numbers

Problem Solving Skills: Add Two Numbers

Problem Solving Skills: Add Two Numbers

My thinking process to solve the Add Two Numbers problem

When I first solve this problem, I felt it could be a good example to show the importance of really understand the problem before you solve it.

Actually it is not a tough problem. The key is to ask good questions, figure out the corner cases and create examples to better understand it.

Add Two Numbers Problem

You can access the link above if you want to see the description and its examples.

1. Understand the problem. Ask questions.

The first step is to read the problem description. It seems silly but people just read the key points and sometimes don’t read really important info to handle corner cases.

When I read the problem description some questions were popping into my head. But before we can ask anything, let’s read the description info. We have:

  • 2 non negative integers linked lists
  • Both linked lists contain at least 1 element (non-empty)
  • Each node stores a single digit (numbers from zero to 9)
  • We need to sum each node and return a new linked list
  • We need to handle carry
  • We don’t know if those lists can have different sizes. And they can. Actually I needed to test it to know. This is an example of question you can ask the interviewer to clarify the problem