Coding examples mostly taken from leetcode.com.