Algorithms, C++

My dynamic programming journey [2] – Coin change problem

As suggested in both Quora and StackOverflow, the coin change problem should be the second problems for beginner to solve. There are actually multiple variations of this problem, however, my approach will be finishing the basic version first, which is: Given a set of coins with values, find the possible way to form N (order is not considered). Example: Given…

Continue Reading

Algorithms, C++

My dynamic programming journey [1] – Fib with memorization

It is rather complicated to consider the advance level of dynamic programming at the beginning, so I have decided to start with a basic example: finding Fibonacci numbers. Since the concepts of recursion and memorization are often required in dynamic programming, therefore, I have implemented a version of memorization. Set base case of 0 and 1 equal to 1 Check…

Continue Reading

Algorithms, C++

Breadth first search

Steps: Add root to queue If left child not null, add it to queue If right child not null, add it to queue Repeat 2 & 3 until the queue is empty

 

Algorithms, C++, std

std::map

Simple insert

  Access to second element using key (C++ 11)

  Iterate

  Find element

 

C++, LeetCode

Unordered Map

According to the documentation, the average searching complexity is O(1), by looking more into unordered_map.find()

It is redirected to lower_bound, passing in the original key value

For _Traits, it’s the template operators (open hashing I supposed), for the iterator defined within the _Traits class

   

LeetCode

1. Two Sum

 

 

LeetCode

7. Reverse Integer

Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 Note: The input is assumed to be a 32-bit signed integer. Your function should return 0 when the reversed integer overflows.

C++, ProjectEuler+

[ProjectEuler+] #8: Largest product in a series

Using string & substr instead of int for large result

C++, ProjectEuler+

[ProjectEuler+] #6: Sum square difference

C++, ProjectEuler+

[ProjectEuler+] #5: Smallest multiple