Lecture Note for April 21, 2019 - Calculator Project (Cont.)

Review

Last week’s homework:

  • Caesar Cipher – https://www.hackerrank.com/challenges/caesar-cipher-1/problem
  • Closest Numbers - https://www.hackerrank.com/challenges/closest-numbers/problem
  • Find the Median - https://www.hackerrank.com/challenges/find-the-median/problem

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 - Don’t waste time solving easy problems. Challenge yourself.

Quiz

class Solution:
    def isUnique(self, s: str) -> bool:
	# TODO: Determin if a string has all unique characters.
        pass


sol = Solution()
assert sol.isUnique('abc') == True
assert sol.isUnique('abcda') == False

Technique - Hashtable / Dictionary

Using built-in dictionary

counter = {}
if c not in s:
    counter[a] = 1
else:
    counter[a] += 1

Using defaultdict

from collections import defaultdict

counter = defaultdict(int)
counter[a] += 1

Using Counter class

from collections import Counter

counter = Counter()
counter[a] += 1

Exercise

  • Ransom Note: https://www.hackerrank.com/challenges/ctci-ransom-note/problem

Nano Project - Calculator (Cont.)

  1. Use Bootstra / CSS to polish your calculator: https://getbootstrap.com/docs/4.0/getting-started/introduction/
  2. Once finished, create an html file on your homepage /portfolio/calc.html
  3. (Homework) Create a blog on how to create a calculator, and put a link to your calculator

alt text

Practice

  • Two-Sum - https://leetcode.com/problems/two-sum/
  • Reverse-Integer - https://leetcode.com/problems/reverse-integer/
  • Palindrome Number - https://leetcode.com/problems/palindrome-number/

Next week - Mock Competition

Homework:

  • Complete the questions in Practice
  • Create a blog on how to create a calculator, and put a link to your calculator
  • Using GoDaddy.com, find an available domain name for your website
Written on April 21, 2019