LEETCODE: NON DECREASING SUBSEQUENCES SOLUTION IN KOTLIN
- Non-decreasing Subsequences Brute force recursive idea works. The only tricky part is handling the situation when there are a group of same digit.
LEETCODE: RESTORE IP ADDRESSES SOLUTION IN KOTLIN
- Restore IP Addresses This problem could be solved in recursive or iterative way. I chose to code in the iterative way.
LEETCODE: PALINDROME PARTITIONING SOLUTION IN KOTLIN
- Palindrome Partitioning The idea is to recursively partition the given string and check if the newly created partition forms a palindrome.
LEETCODE: FLIP STRING TO MONOTONE INCREASING KOTLIN SOLUTION
- Flip String to Monotone Increasing At each position, consider two scenarios: How many digits do we need to change if we want to make everything 0 until this position and everything 1 starting from this index?
LEETCODE: NUMBER OF GOOD PATHS SOLUTION IN KOTLIN
- Number of Good Paths Solution I found the problem somewhat harder than typical leetcode problems. My solution idea is as follows:
LEETCODE: BINARY TREE PREORDER TRAVERSAL IN KOTLIN
- Binary Tree Preorder Traversal Given the root of a binary tree, return the preorder traversal of its nodes’ values.
LEETCODE: MAX POINTS ON A LINE IN KOTLIN
The basic idea is translating all the points with respect to each point. Then find and count the slope using map of [x/gcd(x,y), y/gcd(x.
Read moreLEETCODE: GAS STATION SOLUTION IN KOTLIN
class Solution { fun canCompleteCircuit(gas: IntArray, cost: IntArray): Int { val gain = gas.zip(cost).map { it.first - it.second } val gainAppended = gain.
Read more