LEETCODE: NON DECREASING SUBSEQUENCES SOLUTION IN KOTLIN

  1. Non-decreasing Subsequences Brute force recursive idea works. The only tricky part is handling the situation when there are a group of same digit.

Read more

LEETCODE: RESTORE IP ADDRESSES SOLUTION IN KOTLIN

  1. Restore IP Addresses This problem could be solved in recursive or iterative way. I chose to code in the iterative way.

Read more

LEETCODE: PALINDROME PARTITIONING SOLUTION IN KOTLIN

  1. Palindrome Partitioning The idea is to recursively partition the given string and check if the newly created partition forms a palindrome.

Read more

LEETCODE: FLIP STRING TO MONOTONE INCREASING KOTLIN SOLUTION

  1. 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?

Read more

LEETCODE: NUMBER OF GOOD PATHS SOLUTION IN KOTLIN

  1. Number of Good Paths Solution I found the problem somewhat harder than typical leetcode problems. My solution idea is as follows:

Read more

LEETCODE: BINARY TREE PREORDER TRAVERSAL IN KOTLIN

  1. Binary Tree Preorder Traversal Given the root of a binary tree, return the preorder traversal of its nodes’ values.

Read more

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 more

LEETCODE: 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