Lecture Note for April 28, 2019 - GeekDojo Mock Contest 1
Review
Last week’s homework:
- Two-Sum - https://leetcode.com/problems/two-sum/
Tips on solving problems
- Read a problem statement twice! (Don’t solve a wrong problem!)
- Measure twice, cut once! (Write a concrete example on a paper, write an algorithm or peusdo-code, and test the algorithm before starting to write code)
- After solving a problem, study Editorial and view solutions in Discussion.
- Upsolve - After competition, solve problems that you couldn’t finish. If you do this, you are already ahead of 99% of others.
Cheatsheet
Iterating 2D list
A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
# Iterate 2D list
for i in range(len(A)):
for j in range(len(A[0]):
print(A[i][j])
Hashtable
from collections import defaultdict
my_dict = defaultdict(int) # Create a dictionary where value is integer
my_dct['a'] = 1
Homework:
- Upsolve the Mock Contest 1 - www.hackerrank.com/geekdojo-mock-competition-1
Written on April 28, 2019