You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Do some examples on paper/mind, find **relationship** between input and output,
45
-
finally, test some cases.
46
-
47
-
Try solve the problem **On paper first**.
42
+
Do some examples on paper or on your mind. The trick is to find the correct **relationships** between input and output.
43
+
Finally, you can test some cases and fine-tune your approach for special cases.
48
44
49
-
Write algorithm. Pseudocode.
45
+
Writing the algorithm can be done by writing the _pseudocode_.
50
46
51
-
Example 1 [Code included]: Write an algorithm /code that counts the difference
47
+
Question 1: Write an algorithm/program that returns the difference
52
48
of two dates.
53
49
54
-
Ask yourself:
55
-
56
-
Dates, DF, are all the inputs are valid? 1st data 2nd Second date must not be
57
-
older than 1: invalid input
50
+
**Step 1: Ask yourself the following questions**
58
51
59
-
How input are encoded? (yyyy,mm,dd)
60
-
61
-
Output return a number because we can do things with return value rather
62
-
printing it
52
+
Q: For inputs (dates), what are the valid inputs?
53
+
Q: How input are encoded? (yyyy,mm,dd)
54
+
Q: Possible output returns? (an integer)
63
55
64
56

65
57
66
-
First code: writing a block that makes the solution to work. Solve with a single
67
-
simple case.
58
+
**Step 2: Write simple code that works partially for the problem**
59
+
- Chances are, you need to consider all possible conditions. Often, this results in getting stuck in finding the perfect solutions. Hence, its advisable that you find the simplest solution that works. E,g, solve with a single simple case.
68
60
61
+
Tips:
69
62
Break into simple parts so that we can see our progress.
70
-
71
63
Write simple small codes that work
72
-
73
-
No need to figure out all the details. Consider that you will procrastinate
0 commit comments