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
»
»»
Plus One
Jul 8, 2020
One minute read
For this problem, the approach is really straightforward, just add 1 to each of the digit and making sure that the carry is considered as well. ...
Kotlin
Leetcode
Array
Binary
Binary Tree Level Order Traversal II
Jul 2, 2020
2 minutes read
Today, we’re going to solve a variation of the Binary Tree Level Order Traversal. ...
Kotlin
Leetcode
BFS
DFS
Arranging Coins
Jul 1, 2020
3 minutes read
For the month of July, I decided to get back onto "Leetcoding" after almost 2 weeks of hiatus from solving algorithmic problems. Every month since April this year, Leetcode organizes this 30-day challenge where each day, you have to solve 1 problem. For today, we are going to solve a problem called "Arranging Coins". ...
Kotlin
Leetcode
Binary Search
Making Safe Functions
Jun 26, 2020
2 minutes read
When we write Kotlin functions, it’s important that we make sure that our code is stable and behave correctly. It’s also important to be clear as to what the function expects in order to behave correctly. ...
Kotlin
Good News
Jun 26, 2020
One minute read
It’s been more than a week since I got the result of a 1-year long preparation and I can still feel the excitement, disbelief and nirvana all throughout my body :). I will share more details about it in the upcoming days. ...
Range Sum Query 2D
Feb 27, 2020
2 minutes read
Here’s a hard LC problem which is actually just a variation of the Range Sum Query problem but instead, you have to work on a 2D data. ...
Java
Leetcode
Fenwick Tree
Binary Index Tree
Filling Bookcase Shelves
Feb 16, 2020
2 minutes read
Another medium LC problem in which we are asked to arrange the books in a bookshelf with certain width and try to minimize the total height of the books after the arrangement. ...
Java
Leetcode
Dynamic Programming
Largest Values From Labels
Feb 16, 2020
2 minutes read
For this medium LC problem, I’m presenting two variations of my solution: Using array and another using PriorityQueue. ...
Java
Leetcode
Shortest Distance to Target Color
Feb 13, 2020
2 minutes read
The solution here for this medium LC problem might not be the fastest but I think it’s really clean and concise and easy to understand. ...
Java
Leetcode
Array
TreeSet
Alphabet Board Path
Feb 13, 2020
2 minutes read
It took me about 20 minutes to think about the solution for this medium LC problem and just few minutes to actually implement the code. ...
Java
Leetcode
String
Brace Expansion II
Feb 13, 2020
One minute read
This is a follow-up question for the Brace Expansion problem earlier and the only difference is that now, the braces can be nested multiple times. ...
Java
Leetcode
String
Brace Expansion
Feb 13, 2020
One minute read
This medium LC problem asks us to return all the words formed by expanding the characters inside the braces and appending it to all the other characters present in the string. ...
Java
Leetcode
String
Contain All Alphabet
Feb 12, 2020
2 minutes read
Recently, somebody posted a problem that was asked in his Google Phone Interview. The first problem was easy and could be solved with an O(n) algorithm. 1. Find out if a string contains all alphabet characters in their respective order. ...
Java
Leetcode
String
Redundant Connection
Feb 9, 2020
2 minutes read
This medium LC problem is about finding the edge which causes the tree to have a cycle. ...
Java
Leetcode
Union-Find
Connecting Cities With Minimum Cost
Feb 9, 2020
2 minutes read
This medium LC problem is basically a minimum spanning tree problem therefore we can use Kruskal’s algorithm to solve it. ...
Java
Leetcode
Kruskal
Union-Find
Network Delay Time
Feb 9, 2020
2 minutes read
This medium LC question can be solved by using Djikstra algorithm. The goal is to find the individual distances of nodes from a given node. Then, the maximum distance will be the total network delay time. The time complexity for this algorithm is O(NlogN + E), N = number of nodes and E = number of edges. ...
Java
Leetcode
Djikstra
Most Stones Removed With Same Row or Column
Nov 20, 2019
One minute read
This medium LC question is really difficult to solve if you don’t have any background about Disjoint Sets. ...
Kotlin
Leetcode
Tips
Campus Bikes II
Oct 26, 2019
One minute read
Here’s a medium (problem)[https://leetcode.com/problems/campus-bikes-ii/] which can be solved by using backtracking. Since the problem mentioned about minimizing the sum of distances for a possible combination of workers and bikes, we can use backtracking to go through all possible combinations of bikes and workers. We also keep track of the minimum sum and use that as the final answer. ...
Kotlin
Leetcode
Tips
Range Sum Query Immutable
Oct 23, 2019
2 minutes read
An easy level question with an interesting solution. ...
Kotlin
Leetcode
Tips
Character Mapping
Oct 5, 2019
One minute read
This isn’t a solution to a problem but this could be really handy when solving some problems on LC particularly when you need to create a histogram of characters in a particular string. For example, the word “leetcode” will have a histogram of: ...
Kotlin
Leetcode
Tips
Set Mismatch
Oct 4, 2019
One minute read
To solve this problem, you need to know the arithmetic progression formula. ...
Kotlin
Leetcode
Invalid Transactions
Oct 1, 2019
2 minutes read
Starting today, I will try to solve mostly medium level LC questions as I’ve solved about 75% of easy questions. This one seems to be quite easy as it only involves straightforward logic. ...
Kotlin
Leetcode
Word Pattern
Sep 30, 2019
One minute read
The solution to this problem is very easy but I struggled a little bit because I was focusing more on finding a regex to represent the pattern. ...
Kotlin
Leetcode
1-Bit and 2-Bit Characters
Sep 29, 2019
One minute read
The idea to solve this problem is to first, get the total number of bits then iterate through each bit and if the previous bit is 1, then deduct 2 from the total number of bits. If it’s a 0, then deduct only 1. In the end, if the total number of bits is equal to 1, then last character must be a 1-bit character. ...
Kotlin
Leetcode
Search in a Sorted Array of Unknown Size
Sep 29, 2019
One minute read
Honestly, this should be an easy-level problem as it only involves binary search. ...
Kotlin
Leetcode
Binary Watch
Sep 29, 2019
One minute read
As I’ve mentioned before, I really enjoy solving problems involving bit manipulation and this is one of the many problems that are fun to solve with. ...
Kotlin
Leetcode
Valid Word Square
Sep 29, 2019
One minute read
This is a fun problem to solve and also relatively very easy. I was able to solve this with just one try. ...
Kotlin
Leetcode
Binary Tree Level Order Traversal II
Sep 29, 2019
One minute read
The solution for this problem is the same as the other similarly named problem. Except at the end, we just have to reverse the list before returning it. ...
Kotlin
Leetcode
Minimum Depth of Binary Tree
Sep 29, 2019
One minute read
Here’s another shot at a tree traversal problem. This solution uses Depth-First Traversal. ...
Kotlin
Leetcode
Valid Mountain Array
Sep 29, 2019
One minute read
The idea for this problem is to first find the index of the peak. Peak is defined as A[i-1] < A[i] > A[i+1]. ...
Kotlin
Leetcode
Get Equal Substrings Within Budget
Sep 29, 2019
One minute read
The approach for this problem is to use sliding window technique after getting an array of all the costs involved per character. ...
Kotlin
Leetcode
Reverse Bits
Sep 28, 2019
2 minutes read
This problem does not support Kotlin yet so I have to do it in Java. ...
Java
Leetcode
Minimum Index Sum of Two Lists
Sep 28, 2019
One minute read
The solution for this problem is to loop through any of the list and each time a word exists in both lists, then get the sum of their indexes and use that as the key to store the word in a hashmap. Also, keep track of the lowest key of the map so that later on, you can use that to return the answer. ...
Kotlin
Leetcode
First Unique Character in a String
Sep 27, 2019
One minute read
Most problems like this one can be solved by using the character count map. This approach is very effective as it can give you O(n) time complexity. ...
Kotlin
Leetcode
Majority Element
Sep 27, 2019
One minute read
Writing code in Kotlin brings so much fun particularly when solving Leetcode problems such as this one. ...
Kotlin
Leetcode
Rotated Digits
Sep 27, 2019
One minute read
For this problem, the idea is to swap each digit with their corresponding 180-degree values and use Integer.parseInt to verify if it’s still a valid number. If yes, check also if it’s not equal to the original number as this may also affect the validity of the number. ...
Kotlin
Leetcode
Occurrences After Bigram
Sep 27, 2019
One minute read
Another easy one with a straightforward answer. ...
Kotlin
Leetcode
Merge Intervals
Sep 26, 2019
One minute read
This is one of the commonly asked questions in LC as there were about 22 companies who’ve used this question in their interviews. ...
Kotlin
Leetcode
Minimum Absolute Difference
Sep 26, 2019
One minute read
The idea to solve this problem is to sort the input array and then use a sliding window approach to find the minimum absolute difference between two consecutive elements. If we find a new low, then clear the result and add the current elements. Add more elements if the current diff is equal to the lowest diff so far. ...
Kotlin
Leetcode
How Many Apples Can You Put Into the Basket
Sep 26, 2019
One minute read
Straightforward solution for this easy problem ...
Kotlin
Leetcode
Prime Palindrome
Sep 26, 2019
One minute read
This is one tough medium problem and I had to look at the official solution to solve this. I can solve for smaller numbers but once it gets to 7+ digits then I always get the Time Limit Exceeded result. ...
Kotlin
Leetcode
Excel Sheet Column Number
Sep 25, 2019
One minute read
One of the favorite problems in LC because the problem looks simple but the solution involves quite a bit of analysis. ...
Kotlin
Leetcode
Detect Capital
Sep 25, 2019
One minute read
The easiest way to solve this problem is to count the number of uppercase character. We can easily do that by using map and Character.isUpperCase functions. ...
Kotlin
Leetcode
Meeting Rooms
Sep 25, 2019
One minute read
I never expect that the solution for this problem would be this easy so here it goes. ...
Kotlin
Leetcode
Roman to Integer
Sep 25, 2019
One minute read
I solved this using Java before so this is just a re-implementation in Kotlin language. ...
Kotlin
Leetcode
Two Sum IV - Input Is a BST
Sep 25, 2019
2 minutes read
This is a fun problem as it really makes you think of how to improve your solution. There are multiple ways of solving this such as iterating through the tree and collecting all the values in a hash set. Then loop through the hash set and find if there are any entry equals to k - current element. ...
Kotlin
Leetcode
Contains-DuplicateII
Sep 24, 2019
One minute read
This is a variation of the previous problem. Again, this is best solved using hashmap. ...
Kotlin
Leetcode
Contains-Duplicate
Sep 24, 2019
One minute read
There are multiple ways to solve this problem. One could sort the arrays and check element by element if two consecutive items are equal. ...
Kotlin
Leetcode
Find the Difference
Sep 23, 2019
One minute read
Just another easy problem. ...
Kotlin
Leetcode
Single Element in a Sorted Array
Sep 23, 2019
2 minutes read
This medium problem can be solved easily by few lines of code with O(n) time complexity. ...
Kotlin
Leetcode