Leet Codecheck If N Double Exists And Donald Knuth On Guessing

Example 1:

Input: arr = [10,2,5,3]
Output: true
Explanation: N = 10 is the double of M = 5,that is, 10 = 2 * 5.

1. GUESS

  • not looking, not googling, just guessing, visualizing, walking with it for a while and coming up with…
  • …two-pointers and temporary hash table implemented as a dictionary
ugly & slooow

2. LEARN

3. IMPROVE

  • single-pass with the use of python set as a temporary hash table
  • the hash table does not contain doubles and halves, but items themselves
  • the check is performed within the loop
improved

4. DONALD KNUTH ON “GUESS → LEARN → IMPROVE” LOOP

5. LINKS

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Pavol Kutaj

Pavol Kutaj

Infrastructure Support Engineer/Technical Writer (Snowplow Analytics) with a passion for Python/writing documentation. More about me: https://pavol.kutaj.com