Home
Blog
Marc Lester Tan
Categories
Android (25)
Arduino (8)
Others (4)
Coursera (2)
Personal (2)
Presentations (2)
Appengine (1)
Investing (1)
Ios (1)
Presentation (1)
Python (1)
Quadcopter (1)
Posts
158 posts
««
«
1
2
3
4
»
»»
Game of Life
Sep 23, 2019
2 minutes read
Here’s a medium problem of which I found out a weird behavior, probably a bug in LeetCode. ...
Kotlin
Leetcode
Shortest Completing Word
Sep 19, 2019
One minute read
The idea to solve this problem is to first create a histogram of characters for the license plate. Then, for each word, and for each character of the word, check if it exists in our histogram and if it is, then reduce the count. If the total sum of the histogram is zero then that means the word completes our license plate and is a candidate for the answer. ...
Kotlin
Leetcode
Max Consecutive Ones
Sep 19, 2019
One minute read
I’m starting to enjoy binary related problems particularly bit manipulation. But this time, it’s just plain loop that monitors max count of consecutive ones. Easy peasy. ...
Kotlin
Leetcode
Design HashSet
Sep 19, 2019
One minute read
Another simple problem with simple solution :) ...
Kotlin
Leetcode
Verifying an Alien Dictionary
Sep 19, 2019
One minute read
My answer to this problem is very verbose and I didn’t like it but it works so ¯_(ツ)_/¯. ...
Kotlin
Leetcode
Partition Array Into Three Parts With Equal Sum
Sep 19, 2019
One minute read
Easy problem with easy solution. ...
Kotlin
Leetcode
Number of Days in a Month
Sep 19, 2019
One minute read
This is rather easier if you can have access to a calendar to check if a certain year is a leap year, otherwise, you need to memorize this criteria to check if a year is a leap year: ...
Kotlin
Leetcode
Distance Between Bus Stops
Sep 18, 2019
One minute read
Ok, I cheated on this one by looking at other people’s solution. I initially tried hard to compute the clockwise and counterclockwise sum without realizing that I can actually just compute the clockwise and subtract it from the total sum. Duh! But I reimplemented the idea using Kotlin’s way so give me credit even just for a bit :D ...
Kotlin
Leetcode
Reverse Linked List
Sep 17, 2019
One minute read
This could be one of the most commonly asked questions in LC. This question has been asked in interviews for the following companies: Amazon, Microsoft, Google, Mathworks, Apple, Oracle, Uber etc. ...
Kotlin
Leetcode
Index Pairs of a String
Sep 16, 2019
One minute read
I’ve used Brute-force to solve this problem. Other people used Trie to solve but I’m not yet familiar with it. ...
Kotlin
Leetcode
Binary Number With Alternating Bits
Sep 16, 2019
One minute read
I’m starting to get comfortable with bit manipulation and here’s another problem that I’ve solved in just a few amount of time. ...
Kotlin
Leetcode
Goat Latin
Sep 16, 2019
One minute read
Easy problem with a short solution. ...
Kotlin
Leetcode
Complement of Base 10 Integer
Sep 16, 2019
One minute read
This is an interesting easy problem. ...
Kotlin
Leetcode
Flip-Game
Sep 11, 2019
One minute read
This is another easy LC problem with easy solution. ...
Kotlin
Leetcode
Invert Binary Tree
Sep 11, 2019
One minute read
I initially tried to solve this iteratively but I couldn’t figure out the solution. Recursive approach seems to be the best and easiest way. ...
Kotlin
Leetcode
Average of Levels in Binary Tree
Sep 11, 2019
One minute read
Another problem that can be solved easily using recursion and with the help of Kotlin’s operator, everything becomes easy-peasy. ...
Kotlin
Leetcode
Binary Gap
Sep 11, 2019
One minute read
This is a bit manipulation problem and the solution, although a bit verbose is really efficient beating 100% of all submission for Kotlin. ...
Kotlin
Leetcode
Sum of Root to Leaf Binary Numbers
Sep 11, 2019
One minute read
I solved this problem initially using Java but here’s a similar implementation using Kotlin. ...
Kotlin
Leetcode
Fizz Buzz
Sep 11, 2019
One minute read
Another elegant solution for easy LC problem. ...
Kotlin
Leetcode
Prime Number of Set Bits in Binary Representation
Sep 11, 2019
One minute read
This solution for easy LC problem is very concise the easy to understand don’t you think? ...
Kotlin
Leetcode
Next Greater Element I
Sep 10, 2019
One minute read
Another easy to understand solution for an easy-level LC problem. ...
Kotlin
Leetcode
Palindrome Permutation
Sep 10, 2019
One minute read
I cheated on this easy problem a little bit by looking at the suggested hints. ...
Kotlin
Leetcode
Uncommon Words From Two Sentences
Sep 6, 2019
One minute read
I really don’t like my solution for this one but it’s enough for now. Maybe one way to optimize this is not to use the map and filter operators and just use pure for-loops. ...
Kotlin
Leetcode
Single Number
Sep 5, 2019
One minute read
This is an easy but very tricky problem specially if you aren’t too familiar with logical operations. ...
Kotlin
Leetcode
Baseball Game
Sep 5, 2019
One minute read
Another problem with a very straighforward answer. ...
Kotlin
Leetcode
Island-Perimeter
Sep 5, 2019
2 minutes read
This is definitely an easy one because all you have to do is to that if a block is filled up, check the four conditions: ...
Kotlin
Leetcode
Binary Tree Right Side View
Sep 4, 2019
2 minutes read
Here’s one of my favorite questions in LC. I like this because it looks complicated as it may seem but the approach to the solution is very simple. ...
Kotlin
Leetcode
Valid Palindrome
Sep 4, 2019
One minute read
Another easy problem and probably one of the most commonly asked questions in interviews. ...
Kotlin
Leetcode
Last Stone Weight
Sep 4, 2019
One minute read
Is there any other way to solve this without using PriorityQueue? One could use a list and sort it always everytime a new non-zero value is created from smashing the rocks together but that won’t be that much different than using PriorityQueue which sorts the elements in every offer ...
Kotlin
Leetcode
Toeplitz Matrix
Sep 3, 2019
One minute read
Not the cleanest solution but so far this is the only solution I can think of for this easy LC problem. ...
Kotlin
Leetcode
Sum of Even Numbers After Queries
Sep 2, 2019
2 minutes read
My first solution to this easy problem passed but only faster than 6% of submissions which means we still have some room for improvements. ...
Kotlin
Leetcode
Compare Strings by Frequency of the Smallest Character
Sep 2, 2019
One minute read
This easy problem looks intimidating at first because the description looks complicated but when you analyze it further, the solution is actually straightforward. ...
Kotlin
Leetcode
Number Complement
Sep 2, 2019
One minute read
Here’s another easy problem which can be solved by applying logical operators. ...
Kotlin
Leetcode
Keyboard Row
Sep 2, 2019
One minute read
This is another one of those problems that I was able to solve in less than 5 minutes. ...
Kotlin
Leetcode
Power of Two
Sep 2, 2019
2 minutes read
Another beautiful solution to an easy LC problem. ...
Kotlin
Leetcode
Find Words That Can Be Formed by Characters
Aug 31, 2019
One minute read
For this easy LC problem, the solution is to first, create a map of all the characters in chars and their corresponding count or occurences. We will use occurences later on to count the available characters that can still be used. ...
Kotlin
Leetcode
Happy Number
Aug 30, 2019
One minute read
This easy problem looks simple at first but it gets very tricky specially when finding out if your loop already started in an endless loop. I did try a couple of ideas without using a list to keep track of previous sums but all didn’t work. Eventually I ended up using a mutableList to maintain a list of previous sums so I can look up and see if the new sum has been solved before. If it is, then it means we entered into an endless loop already. ...
Kotlin
Leetcode
Jewels and Stones
Aug 30, 2019
One minute read
This probably is one the shortest solutions I’ve ever written to a problem in LC. ...
Kotlin
Leetcode
Reverse Integer
Aug 30, 2019
One minute read
Another super easy problem using math operations. The problem asks us to reverse the digits of an integer. For example, 123 should return 321. You should also maintain the original sign of the number whether it’s positive or negative. This problem took me about 3 minutes to solve. ...
Kotlin
Leetcode
Best Time to Buy and Sell Stock
Aug 29, 2019
One minute read
This easy LC problem is just a reword or a variation of a problem that finds a pair with the maximum difference. This can be solved in O(n) because we can calculate the mininum number and maximum difference at the same time as we go through each of the array elements. ...
Kotlin
Leetcode
Subsets
Aug 29, 2019
2 minutes read
The idea to the solution for this medium LC problem is to use bit manipulation to iterate through all possible combination of bits and use this bits to generate the list of subsets. For example, a given array is [1,2,3], you could represent a subset of {1,2,3} as 111, {1,2} as 110, {1} as 100 and so on and so forth. ...
Kotlin
Leetcode
Maximum Subarray
Aug 29, 2019
One minute read
Another easy LC problem. Most solutions will probably have O(n^2) or worst but here’s an another solution which has an O(n) time complexity. ...
Kotlin
Leetcode
Two Sum
Aug 29, 2019
One minute read
This is one of the easiest problem on LC as this has the highest acceptance rate as of now. ...
Kotlin
Leetcode
Maximum Binary Tree
Aug 28, 2019
2 minutes read
We can solve this medium LC problem by recursively finding the index of the highest value (let’s call it as maxIndex) then splitting the array into two subarrays starting from 0 to maxIndex - 1 and maxIndex + 1 to array’s size - 1. We construct the tree everytime we encounter the max value. ...
Kotlin
Leetcode
Binary Search Tree to Greater Sum Tree
Aug 26, 2019
One minute read
The solution to this medium LC problem involves traversing the tree using inorder traversal. In-order traversal means the left node gets the priority, followed by the root node then right node. ...
Kotlin
Leetcode
Transpose Matrix
Aug 26, 2019
One minute read
Another short solution for this easy LC problem. ...
Kotlin
Leetcode
Single-Row Keyboard
Aug 25, 2019
One minute read
I solved this easy LC problem in less than 5 minutes. Solution is very easy and straightforward. I provided two solutions: One that uses the map operator and another using the good ‘ole for loop. ...
Kotlin
Leetcode
K Closest Points to Origin
Aug 24, 2019
2 minutes read
To solve this medium LC problem, you must first define a function to calculate the Euclidian distance of two points. In this case, we have to find the distance between a point and the origin (0, 0). ...
Kotlin
Leetcode
Number of Lines to Write String
Aug 24, 2019
One minute read
The solution to this easy LC problem is quite simple and I think the code is also self-explanatory so I won’t say that much about this solution. ...
Kotlin
Leetcode
Remove All Adjacent Duplicates in String
Aug 24, 2019
One minute read
Not the fastest solution for this easy LC problem but it’s readable and easy to understand so I’m fine with this. ...
Kotlin
Leetcode