n2
in spiral order.
+
+**Example 1:**
+
+
+
+**Input:** n = 3
+
+**Output:** [[1,2,3],[8,9,4],[7,6,5]]
+
+**Example 2:**
+
+**Input:** n = 1
+
+**Output:** [[1]]
+
+**Constraints:**
+
+* `1 <= n <= 20`
+
+## Solution
+
+```kotlin
+class Solution {
+ fun generateMatrix(n: Int): Arraykth
permutation sequence.
+
+**Example 1:**
+
+**Input:** n = 3, k = 3
+
+**Output:** "213"
+
+**Example 2:**
+
+**Input:** n = 4, k = 9
+
+**Output:** "2314"
+
+**Example 3:**
+
+**Input:** n = 3, k = 1
+
+**Output:** "123"
+
+**Constraints:**
+
+* `1 <= n <= 9`
+* `1 <= k <= n!`
+
+## Solution
+
+```kotlin
+@Suppress("NAME_SHADOWING")
+class Solution {
+ fun getPermutation(n: Int, k: Int): String {
+ var k = k
+ val res = CharArray(n)
+ // We want the permutation sequence to be zero-indexed
+ k = k - 1
+ // The set bits indicate the available digits
+ var a = (1 shl n) - 1
+ var m = 1
+ for (i in 2 until n) {
+ // m = (n - 1)!
+ m *= i
+ }
+ for (i in 0 until n) {
+ var b = a
+ for (j in 0 until k / m) {
+ b = b and b - 1
+ }
+ // b is the bit corresponding to the digit we want
+ b = b and b.inv() + 1
+ res[i] = ('1'.code + Integer.bitCount(b - 1)).toChar()
+ // Remove b from the set of available digits
+ a = a and b.inv()
+ k %= m
+ m /= Math.max(1, n - i - 1)
+ }
+ return String(res)
+ }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g0001_0100/s0061_rotate_list/readme.md b/src/main/kotlin/g0001_0100/s0061_rotate_list/readme.md
new file mode 100644
index 00000000..625f1d3f
--- /dev/null
+++ b/src/main/kotlin/g0001_0100/s0061_rotate_list/readme.md
@@ -0,0 +1,80 @@
+[](https://github.com/javadev/LeetCode-in-Kotlin)
+[](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 61\. Rotate List
+
+Medium
+
+Given the `head` of a linked list, rotate the list to the right by `k` places.
+
+**Example 1:**
+
+
+
+**Input:** head = [1,2,3,4,5], k = 2
+
+**Output:** [4,5,1,2,3]
+
+**Example 2:**
+
+
+
+**Input:** head = [0,1,2], k = 4
+
+**Output:** [2,0,1]
+
+**Constraints:**
+
+* The number of nodes in the list is in the range `[0, 500]`.
+* `-100 <= Node.val <= 100`
+* 0 <= k <= 2 * 109
+
+## Solution
+
+```kotlin
+import com_github_leetcode.ListNode
+
+/**
+ * Example:
+ * var li = ListNode(5)
+ * var v = li.`val`
+ * Definition for singly-linked list.
+ * class ListNode(var `val`: Int) {
+ * var next: ListNode? = null
+ * }
+ */
+class Solution {
+ fun rotateRight(head: ListNode?, k: Int): ListNode? {
+ if (head == null || k == 0) {
+ return head
+ }
+ var tail = head
+ // find the count and let tail points to last node
+ var count = 1
+ while (tail != null && tail.next != null) {
+ count++
+ tail = tail.next
+ }
+ // calculate number of times to rotate by count modulas
+ val times = k % count
+ if (times == 0) {
+ return head
+ }
+ var temp = head
+ // iterate and go to the K+1 th node from the end or count - K - 1 node from
+ // start
+ var i = 1
+ while (i <= count - times - 1 && temp != null) {
+ temp = temp.next
+ i++
+ }
+ var newHead: ListNode? = null
+ if (temp != null && tail != null) {
+ newHead = temp.next
+ temp.next = null
+ tail.next = head
+ }
+ return newHead
+ }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g0001_0100/s0063_unique_paths_ii/readme.md b/src/main/kotlin/g0001_0100/s0063_unique_paths_ii/readme.md
new file mode 100644
index 00000000..c3d5e947
--- /dev/null
+++ b/src/main/kotlin/g0001_0100/s0063_unique_paths_ii/readme.md
@@ -0,0 +1,85 @@
+[](https://github.com/javadev/LeetCode-in-Kotlin)
+[](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 63\. Unique Paths II
+
+Medium
+
+You are given an `m x n` integer array `grid`. There is a robot initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m-1][n-1]`). The robot can only move either down or right at any point in time.
+
+An obstacle and space are marked as `1` or `0` respectively in `grid`. A path that the robot takes cannot include **any** square that is an obstacle.
+
+Return _the number of possible unique paths that the robot can take to reach the bottom-right corner_.
+
+The testcases are generated so that the answer will be less than or equal to 2 * 109
.
+
+**Example 1:**
+
+
+
+**Input:** obstacleGrid = \[\[0,0,0],[0,1,0],[0,0,0]]
+
+**Output:** 2
+
+**Explanation:** There is one obstacle in the middle of the 3x3 grid above.
+
+There are two ways to reach the bottom-right corner:
+
+1. Right -> Right -> Down -> Down
+
+2. Down -> Down -> Right -> Right
+
+**Example 2:**
+
+
+
+**Input:** obstacleGrid = \[\[0,1],[0,0]]
+
+**Output:** 1
+
+**Constraints:**
+
+* `m == obstacleGrid.length`
+* `n == obstacleGrid[i].length`
+* `1 <= m, n <= 100`
+* `obstacleGrid[i][j]` is `0` or `1`.
+
+## Solution
+
+```kotlin
+class Solution {
+ fun uniquePathsWithObstacles(obstacleGrid: Arrayith
digit of the integer. The digits are ordered from most significant to least significant in left-to-right order. The large integer does not contain any leading `0`'s.
+
+Increment the large integer by one and return _the resulting array of digits_.
+
+**Example 1:**
+
+**Input:** digits = [1,2,3]
+
+**Output:** [1,2,4]
+
+**Explanation:**
+
+The array represents the integer 123.
+
+Incrementing by one gives 123 + 1 = 124.
+
+Thus, the result should be [1,2,4].
+
+**Example 2:**
+
+**Input:** digits = [4,3,2,1]
+
+**Output:** [4,3,2,2]
+
+**Explanation:**
+
+The array represents the integer 4321.
+
+Incrementing by one gives 4321 + 1 = 4322.
+
+Thus, the result should be [4,3,2,2].
+
+**Example 3:**
+
+**Input:** digits = [9]
+
+**Output:** [1,0]
+
+**Explanation:**
+
+The array represents the integer 9.
+
+Incrementing by one gives 9 + 1 = 10.
+
+Thus, the result should be [1,0].
+
+**Constraints:**
+
+* `1 <= digits.length <= 100`
+* `0 <= digits[i] <= 9`
+* `digits` does not contain any leading `0`'s.
+
+## Solution
+
+```kotlin
+class Solution {
+ fun plusOne(digits: IntArray): IntArray {
+ val num = 1
+ var carry = 0
+ var sum: Int
+ for (i in digits.indices.reversed()) {
+ sum = if (i == digits.size - 1) {
+ digits[i] + carry + num
+ } else {
+ digits[i] + carry
+ }
+ carry = sum / 10
+ digits[i] = sum % 10
+ }
+ if (carry != 0) {
+ val ans = IntArray(digits.size + 1)
+ ans[0] = carry
+ System.arraycopy(digits, 0, ans, 1, ans.size - 1)
+ return ans
+ }
+ return digits
+ }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g0001_0100/s0067_add_binary/readme.md b/src/main/kotlin/g0001_0100/s0067_add_binary/readme.md
new file mode 100644
index 00000000..e3b5fc92
--- /dev/null
+++ b/src/main/kotlin/g0001_0100/s0067_add_binary/readme.md
@@ -0,0 +1,56 @@
+[](https://github.com/javadev/LeetCode-in-Kotlin)
+[](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 67\. Add Binary
+
+Easy
+
+Given two binary strings `a` and `b`, return _their sum as a binary string_.
+
+**Example 1:**
+
+**Input:** a = "11", b = "1"
+
+**Output:** "100"
+
+**Example 2:**
+
+**Input:** a = "1010", b = "1011"
+
+**Output:** "10101"
+
+**Constraints:**
+
+* 1 <= a.length, b.length <= 104
+* `a` and `b` consist only of `'0'` or `'1'` characters.
+* Each string does not contain leading zeros except for the zero itself.
+
+## Solution
+
+```kotlin
+class Solution {
+ fun addBinary(a: String, b: String): String {
+ val aArray = a.toCharArray()
+ val bArray = b.toCharArray()
+ val sb = StringBuilder()
+ var i = aArray.size - 1
+ var j = bArray.size - 1
+ var carry = 0
+ while (i >= 0 || j >= 0) {
+ val sum = (if (i >= 0) aArray[i] - '0' else 0) + (if (j >= 0) bArray[j] - '0' else 0) + carry
+ sb.append(sum % 2)
+ carry = sum / 2
+ if (i >= 0) {
+ i--
+ }
+ if (j >= 0) {
+ j--
+ }
+ }
+ if (carry != 0) {
+ sb.append(carry)
+ }
+ return sb.reverse().toString()
+ }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g0001_0100/s0068_text_justification/readme.md b/src/main/kotlin/g0001_0100/s0068_text_justification/readme.md
new file mode 100644
index 00000000..11ac92e9
--- /dev/null
+++ b/src/main/kotlin/g0001_0100/s0068_text_justification/readme.md
@@ -0,0 +1,128 @@
+[](https://github.com/javadev/LeetCode-in-Kotlin)
+[](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 68\. Text Justification
+
+Hard
+
+Given an array of strings `words` and a width `maxWidth`, format the text such that each line has exactly `maxWidth` characters and is fully (left and right) justified.
+
+You should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad extra spaces `' '` when necessary so that each line has exactly `maxWidth` characters.
+
+Extra spaces between words should be distributed as evenly as possible. If the number of spaces on a line does not divide evenly between words, the empty slots on the left will be assigned more spaces than the slots on the right.
+
+For the last line of text, it should be left-justified and no extra space is inserted between words.
+
+**Note:**
+
+* A word is defined as a character sequence consisting of non-space characters only.
+* Each word's length is guaranteed to be greater than 0 and not exceed maxWidth.
+* The input array `words` contains at least one word.
+
+**Example 1:**
+
+**Input:** words = ["This", "is", "an", "example", "of", "text", "justification."], maxWidth = 16
+
+**Output:** [ "This is an", "example of text", "justification. " ]
+
+**Example 2:**
+
+**Input:** words = ["What","must","be","acknowledgment","shall","be"], maxWidth = 16
+
+**Output:** [ "What must be", "acknowledgment ", "shall be " ]
+
+**Explanation:** Note that the last line is "shall be " instead of "shall be", because the last line must be left-justified instead of fully-justified. Note that the second line is also left-justified becase it contains only one word.
+
+**Example 3:**
+
+**Input:** words = ["Science","is","what","we","understand","well","enough","to","explain","to","a","computer.","Art","is","everything","else","we","do"], maxWidth = 20
+
+**Output:** [ "Science is what we", "understand well", "enough to explain to", "a computer. Art is", "everything else we", "do " ]
+
+**Constraints:**
+
+* `1 <= words.length <= 300`
+* `1 <= words[i].length <= 20`
+* `words[i]` consists of only English letters and symbols.
+* `1 <= maxWidth <= 100`
+* `words[i].length <= maxWidth`
+
+## Solution
+
+```kotlin
+class Solution {
+ fun fullJustify(words: Arrayx ** 0.5
.
+
+**Example 1:**
+
+**Input:** x = 4
+
+**Output:** 2
+
+**Example 2:**
+
+**Input:** x = 8
+
+**Output:** 2
+
+**Explanation:** The square root of 8 is 2.82842..., and since the decimal part is truncated, 2 is returned.
+
+**Constraints:**
+
+* 0 <= x <= 231 - 1
+
+## Solution
+
+```kotlin
+class Solution {
+ fun mySqrt(x: Int): Int {
+ var start = 1
+ var end = x / 2
+ var sqrt = start + (end - start) / 2
+ if (x == 0) {
+ return 0
+ }
+ while (start <= end) {
+ if (sqrt == x / sqrt) {
+ return sqrt
+ } else if (sqrt > x / sqrt) {
+ end = sqrt - 1
+ } else if (sqrt < x / sqrt) {
+ start = sqrt + 1
+ }
+ sqrt = start + (end - start) / 2
+ }
+ return if (sqrt > x / sqrt) {
+ sqrt - 1
+ } else {
+ sqrt
+ }
+ }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g0001_0100/s0071_simplify_path/readme.md b/src/main/kotlin/g0001_0100/s0071_simplify_path/readme.md
new file mode 100644
index 00000000..643e2143
--- /dev/null
+++ b/src/main/kotlin/g0001_0100/s0071_simplify_path/readme.md
@@ -0,0 +1,87 @@
+[](https://github.com/javadev/LeetCode-in-Kotlin)
+[](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 71\. Simplify Path
+
+Medium
+
+Given a string `path`, which is an **absolute path** (starting with a slash `'/'`) to a file or directory in a Unix-style file system, convert it to the simplified **canonical path**.
+
+In a Unix-style file system, a period `'.'` refers to the current directory, a double period `'..'` refers to the directory up a level, and any multiple consecutive slashes (i.e. `'//'`) are treated as a single slash `'/'`. For this problem, any other format of periods such as `'...'` are treated as file/directory names.
+
+The **canonical path** should have the following format:
+
+* The path starts with a single slash `'/'`.
+* Any two directories are separated by a single slash `'/'`.
+* The path does not end with a trailing `'/'`.
+* The path only contains the directories on the path from the root directory to the target file or directory (i.e., no period `'.'` or double period `'..'`)
+
+Return _the simplified **canonical path**_.
+
+**Example 1:**
+
+**Input:** path = "/home/"
+
+**Output:** "/home"
+
+**Explanation:** Note that there is no trailing slash after the last directory name.
+
+**Example 2:**
+
+**Input:** path = "/../"
+
+**Output:** "/"
+
+**Explanation:** Going one level up from the root directory is a no-op, as the root level is the highest level you can go.
+
+**Example 3:**
+
+**Input:** path = "/home//foo/"
+
+**Output:** "/home/foo"
+
+**Explanation:** In the canonical path, multiple consecutive slashes are replaced by a single one.
+
+**Constraints:**
+
+* `1 <= path.length <= 3000`
+* `path` consists of English letters, digits, period `'.'`, slash `'/'` or `'_'`.
+* `path` is a valid absolute Unix path.
+
+## Solution
+
+```kotlin
+import java.util.ArrayDeque
+import java.util.Deque
+
+class Solution {
+ fun simplifyPath(path: String): String {
+ val stk: Deque1 <= nums.length <= 3 * 104
+* -104 <= nums[i] <= 104
+* `nums` is sorted in **non-decreasing** order.
+
+## Solution
+
+```kotlin
+class Solution {
+ fun removeDuplicates(nums: IntArray): Int {
+ var i = 0
+ var k = 0
+ var count = 0
+ while (i < nums.size - 1) {
+ ++count
+ if (count <= 2) {
+ nums[k++] = nums[i]
+ }
+ if (nums[i] != nums[i + 1]) {
+ count = 0
+ i++
+ continue
+ }
+ i++
+ }
+ ++count
+ if (count <= 2) {
+ nums[k++] = nums[i]
+ }
+ return k
+ }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g0001_0100/s0081_search_in_rotated_sorted_array_ii/readme.md b/src/main/kotlin/g0001_0100/s0081_search_in_rotated_sorted_array_ii/readme.md
new file mode 100644
index 00000000..6386730d
--- /dev/null
+++ b/src/main/kotlin/g0001_0100/s0081_search_in_rotated_sorted_array_ii/readme.md
@@ -0,0 +1,58 @@
+[](https://github.com/javadev/LeetCode-in-Kotlin)
+[](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 81\. Search in Rotated Sorted Array II
+
+Medium
+
+There is an integer array `nums` sorted in non-decreasing order (not necessarily with **distinct** values).
+
+Before being passed to your function, `nums` is **rotated** at an unknown pivot index `k` (`0 <= k < nums.length`) such that the resulting array is `[nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]]` (**0-indexed**). For example, `[0,1,2,4,4,4,5,6,6,7]` might be rotated at pivot index `5` and become `[4,5,6,6,7,0,1,2,4,4]`.
+
+Given the array `nums` **after** the rotation and an integer `target`, return `true` _if_ `target` _is in_ `nums`_, or_ `false` _if it is not in_ `nums`_._
+
+You must decrease the overall operation steps as much as possible.
+
+**Example 1:**
+
+**Input:** nums = [2,5,6,0,0,1,2], target = 0
+
+**Output:** true
+
+**Example 2:**
+
+**Input:** nums = [2,5,6,0,0,1,2], target = 3
+
+**Output:** false
+
+**Constraints:**
+
+* `1 <= nums.length <= 5000`
+* -104 <= nums[i] <= 104
+* `nums` is guaranteed to be rotated at some pivot.
+* -104 <= target <= 104
+
+**Follow up:** This problem is similar to [Search in Rotated Sorted Array](/problems/search-in-rotated-sorted-array/description/), but `nums` may contain **duplicates**. Would this affect the runtime complexity? How and why?
+
+## Solution
+
+```kotlin
+class Solution {
+ fun search(nums: IntArray, target: Int): Boolean {
+ return binary(nums, 0, nums.size - 1, target)
+ }
+
+ private fun binary(a: IntArray, i: Int, j: Int, t: Int): Boolean {
+ if (i > j) {
+ return false
+ }
+ val mid = (i + j) / 2
+ if (a[mid] == t) {
+ return true
+ }
+ val c1 = binary(a, i, mid - 1, t)
+ val c2 = binary(a, mid + 1, j, t)
+ return c1 || c2
+ }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g0001_0100/s0082_remove_duplicates_from_sorted_list_ii/readme.md b/src/main/kotlin/g0001_0100/s0082_remove_duplicates_from_sorted_list_ii/readme.md
new file mode 100644
index 00000000..3f90cf15
--- /dev/null
+++ b/src/main/kotlin/g0001_0100/s0082_remove_duplicates_from_sorted_list_ii/readme.md
@@ -0,0 +1,75 @@
+[](https://github.com/javadev/LeetCode-in-Kotlin)
+[](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 82\. Remove Duplicates from Sorted List II
+
+Medium
+
+Given the `head` of a sorted linked list, _delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list_. Return _the linked list **sorted** as well_.
+
+**Example 1:**
+
+
+
+**Input:** head = [1,2,3,3,4,4,5]
+
+**Output:** [1,2,5]
+
+**Example 2:**
+
+
+
+**Input:** head = [1,1,1,2,3]
+
+**Output:** [2,3]
+
+**Constraints:**
+
+* The number of nodes in the list is in the range `[0, 300]`.
+* `-100 <= Node.val <= 100`
+* The list is guaranteed to be **sorted** in ascending order.
+
+## Solution
+
+```kotlin
+import com_github_leetcode.ListNode
+
+/*
+ * Example:
+ * var li = ListNode(5)
+ * var v = li.`val`
+ * Definition for singly-linked list.
+ * class ListNode(var `val`: Int) {
+ * var next: ListNode? = null
+ * }
+ */
+class Solution {
+ fun deleteDuplicates(head: ListNode?): ListNode? {
+ if (head == null || head.next == null) {
+ return head
+ }
+ val dummy = ListNode(0)
+ var prev: ListNode? = dummy
+ prev!!.next = head
+ var curr = head.next
+ while (curr != null) {
+ var flagFoundDuplicate = false
+ while (curr != null && prev!!.next!!.`val` == curr.`val`) {
+ flagFoundDuplicate = true
+ curr = curr.next
+ }
+ if (flagFoundDuplicate) {
+ prev!!.next = curr
+ if (curr != null) {
+ curr = curr.next
+ }
+ } else {
+ prev = prev!!.next
+ prev!!.next = curr
+ curr = curr!!.next
+ }
+ }
+ return dummy.next
+ }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g0001_0100/s0083_remove_duplicates_from_sorted_list/readme.md b/src/main/kotlin/g0001_0100/s0083_remove_duplicates_from_sorted_list/readme.md
new file mode 100644
index 00000000..a814e3f2
--- /dev/null
+++ b/src/main/kotlin/g0001_0100/s0083_remove_duplicates_from_sorted_list/readme.md
@@ -0,0 +1,64 @@
+[](https://github.com/javadev/LeetCode-in-Kotlin)
+[](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 83\. Remove Duplicates from Sorted List
+
+Easy
+
+Given the `head` of a sorted linked list, _delete all duplicates such that each element appears only once_. Return _the linked list **sorted** as well_.
+
+**Example 1:**
+
+
+
+**Input:** head = [1,1,2]
+
+**Output:** [1,2]
+
+**Example 2:**
+
+
+
+**Input:** head = [1,1,2,3,3]
+
+**Output:** [1,2,3]
+
+**Constraints:**
+
+* The number of nodes in the list is in the range `[0, 300]`.
+* `-100 <= Node.val <= 100`
+* The list is guaranteed to be **sorted** in ascending order.
+
+## Solution
+
+```kotlin
+import com_github_leetcode.ListNode
+
+/*
+ * Example:
+ * var li = ListNode(5)
+ * var v = li.`val`
+ * Definition for singly-linked list.
+ * class ListNode(var `val`: Int) {
+ * var next: ListNode? = null
+ * }
+ */
+class Solution {
+ fun deleteDuplicates(head: ListNode?): ListNode? {
+ if (head == null) {
+ return null
+ }
+ var current: ListNode = head
+ var next = current.next
+ while (null != next) {
+ if (current.`val` == next.`val`) {
+ current.next = next.next
+ } else {
+ current = next
+ }
+ next = current.next
+ }
+ return head
+ }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g0001_0100/s0085_maximal_rectangle/readme.md b/src/main/kotlin/g0001_0100/s0085_maximal_rectangle/readme.md
new file mode 100644
index 00000000..659097ac
--- /dev/null
+++ b/src/main/kotlin/g0001_0100/s0085_maximal_rectangle/readme.md
@@ -0,0 +1,125 @@
+[](https://github.com/javadev/LeetCode-in-Kotlin)
+[](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 85\. Maximal Rectangle
+
+Hard
+
+Given a `rows x cols` binary `matrix` filled with `0`'s and `1`'s, find the largest rectangle containing only `1`'s and return _its area_.
+
+**Example 1:**
+
+
+
+**Input:** matrix = \[\["1","0","1","0","0"],["1","0","1","1","1"],["1","1","1","1","1"],["1","0","0","1","0"]]
+
+**Output:** 6
+
+**Explanation:** The maximal rectangle is shown in the above picture.
+
+**Example 2:**
+
+**Input:** matrix = \[\["0"]]
+
+**Output:** 0
+
+**Example 3:**
+
+**Input:** matrix = \[\["1"]]
+
+**Output:** 1
+
+**Constraints:**
+
+* `rows == matrix.length`
+* `cols == matrix[i].length`
+* `1 <= row, cols <= 200`
+* `matrix[i][j]` is `'0'` or `'1'`.
+
+## Solution
+
+```kotlin
+class Solution {
+ fun maximalRectangle(matrix: ArrayWe can use an array nLeftGeq[] of size n to simulate a stack. nLeftGeq[i] = the number
+ * of elements to the left of [i] having value greater than or equal to a[i] (including a[i]
+ * itself). It is also the index difference between [i] and the next index on the top of the
+ * stack.
+ */
+ val n = heights.size
+ if (n == 0) {
+ return 0
+ }
+ val nLeftGeq = IntArray(n)
+ // the number of elements to the left
+ // of [i] with value >= heights[i]
+ nLeftGeq[0] = 1
+ // preIdx=the index of stack.peek(), res=max area so far
+ var preIdx = 0
+ var res = 0
+ for (i in 1 until n) {
+ nLeftGeq[i] = 1
+ // notice that preIdx = i - 1 = peek()
+ while (preIdx >= 0 && heights[i] < heights[preIdx]) {
+ res = Math.max(res, heights[preIdx] * (nLeftGeq[preIdx] + i - preIdx - 1))
+ // pop()
+ nLeftGeq[i] += nLeftGeq[preIdx]
+ // peek() current top
+ preIdx = preIdx - nLeftGeq[preIdx]
+ }
+ if (preIdx >= 0 && heights[i] == heights[preIdx]) {
+ // pop()
+ nLeftGeq[i] += nLeftGeq[preIdx]
+ }
+ // otherwise nothing to do
+ preIdx = i
+ }
+ // compute the rest largest rectangle areas with (indices of) bases
+ // on stack
+ while (preIdx >= 0 && 0 < heights[preIdx]) {
+ res = Math.max(res, heights[preIdx] * (nLeftGeq[preIdx] + n - preIdx - 1))
+ // peek() current top
+ preIdx = preIdx - nLeftGeq[preIdx]
+ }
+ return res
+ }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g0001_0100/s0086_partition_list/readme.md b/src/main/kotlin/g0001_0100/s0086_partition_list/readme.md
new file mode 100644
index 00000000..534e8e1a
--- /dev/null
+++ b/src/main/kotlin/g0001_0100/s0086_partition_list/readme.md
@@ -0,0 +1,70 @@
+[](https://github.com/javadev/LeetCode-in-Kotlin)
+[](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 86\. Partition List
+
+Medium
+
+Given the `head` of a linked list and a value `x`, partition it such that all nodes **less than** `x` come before nodes **greater than or equal** to `x`.
+
+You should **preserve** the original relative order of the nodes in each of the two partitions.
+
+**Example 1:**
+
+
+
+**Input:** head = [1,4,3,2,5,2], x = 3
+
+**Output:** [1,2,2,4,3,5]
+
+**Example 2:**
+
+**Input:** head = [2,1], x = 2
+
+**Output:** [1,2]
+
+**Constraints:**
+
+* The number of nodes in the list is in the range `[0, 200]`.
+* `-100 <= Node.val <= 100`
+* `-200 <= x <= 200`
+
+## Solution
+
+```kotlin
+import com_github_leetcode.ListNode
+
+/*
+ * Example:
+ * var li = ListNode(5)
+ * var v = li.`val`
+ * Definition for singly-linked list.
+ * class ListNode(var `val`: Int) {
+ * var next: ListNode? = null
+ * }
+ */
+@Suppress("NAME_SHADOWING")
+class Solution {
+ fun partition(head: ListNode?, x: Int): ListNode? {
+ var head = head
+ var nHead: ListNode? = ListNode(0)
+ var nTail: ListNode? = ListNode(0)
+ val ptr = nTail
+ val temp = nHead
+ while (head != null) {
+ val nNext = head.next
+ if (head.`val` < x) {
+ nHead!!.next = head
+ nHead = nHead.next
+ } else {
+ nTail!!.next = head
+ nTail = nTail.next
+ }
+ head = nNext
+ }
+ nTail!!.next = null
+ nHead!!.next = ptr!!.next
+ return temp!!.next
+ }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g0001_0100/s0087_scramble_string/readme.md b/src/main/kotlin/g0001_0100/s0087_scramble_string/readme.md
new file mode 100644
index 00000000..707a97f7
--- /dev/null
+++ b/src/main/kotlin/g0001_0100/s0087_scramble_string/readme.md
@@ -0,0 +1,60 @@
+[](https://github.com/javadev/LeetCode-in-Kotlin)
+[](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 86\. Partition List
+
+Medium
+
+Given the `head` of a linked list and a value `x`, partition it such that all nodes **less than** `x` come before nodes **greater than or equal** to `x`.
+
+You should **preserve** the original relative order of the nodes in each of the two partitions.
+
+**Example 1:**
+
+
+
+**Input:** head = [1,4,3,2,5,2], x = 3
+
+**Output:** [1,2,2,4,3,5]
+
+**Example 2:**
+
+**Input:** head = [2,1], x = 2
+
+**Output:** [1,2]
+
+**Constraints:**
+
+* The number of nodes in the list is in the range `[0, 200]`.
+* `-100 <= Node.val <= 100`
+* `-200 <= x <= 200`
+
+## Solution
+
+```kotlin
+class Solution {
+ fun isScramble(s1: String, s2: String): Boolean {
+ val n = s1.length
+ val dp = Array(n) { Array(n) { BooleanArray(n + 1) } }
+ for (len in 1..n) {
+ for (i in 0..n - len) {
+ for (j in 0..n - len) {
+ if (len == 1) {
+ dp[i][j][len] = s1[i] == s2[j]
+ } else {
+ var k = 1
+ while (k < len && !dp[i][j][len]) {
+ dp[i][j][len] = (
+ dp[i][j][k] && dp[i + k][j + k][len - k] ||
+ dp[i][j + len - k][k] && dp[i + k][j][len - k]
+ )
+ k++
+ }
+ }
+ }
+ }
+ }
+ return dp[0][0][n]
+ }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g0001_0100/s0088_merge_sorted_array/readme.md b/src/main/kotlin/g0001_0100/s0088_merge_sorted_array/readme.md
new file mode 100644
index 00000000..457b3e98
--- /dev/null
+++ b/src/main/kotlin/g0001_0100/s0088_merge_sorted_array/readme.md
@@ -0,0 +1,65 @@
+[](https://github.com/javadev/LeetCode-in-Kotlin)
+[](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 88\. Merge Sorted Array
+
+Easy
+
+You are given two integer arrays `nums1` and `nums2`, sorted in **non-decreasing order**, and two integers `m` and `n`, representing the number of elements in `nums1` and `nums2` respectively.
+
+**Merge** `nums1` and `nums2` into a single array sorted in **non-decreasing order**.
+
+The final sorted array should not be returned by the function, but instead be _stored inside the array_ `nums1`. To accommodate this, `nums1` has a length of `m + n`, where the first `m` elements denote the elements that should be merged, and the last `n` elements are set to `0` and should be ignored. `nums2` has a length of `n`.
+
+**Example 1:**
+
+**Input:** nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3
+
+**Output:** [1,2,2,3,5,6]
+
+**Explanation:** The arrays we are merging are [1,2,3] and [2,5,6]. The result of the merge is [1,2,2,3,5,6] with the underlined elements coming from nums1.
+
+**Example 2:**
+
+**Input:** nums1 = [1], m = 1, nums2 = [], n = 0
+
+**Output:** [1]
+
+**Explanation:** The arrays we are merging are [1] and []. The result of the merge is [1].
+
+**Example 3:**
+
+**Input:** nums1 = [0], m = 0, nums2 = [1], n = 1
+
+**Output:** [1]
+
+**Explanation:** The arrays we are merging are [] and [1]. The result of the merge is [1]. Note that because m = 0, there are no elements in nums1. The 0 is only there to ensure the merge result can fit in nums1.
+
+**Constraints:**
+
+* `nums1.length == m + n`
+* `nums2.length == n`
+* `0 <= m, n <= 200`
+* `1 <= m + n <= 200`
+* -109 <= nums1[i], nums2[j] <= 109
+
+**Follow up:** Can you come up with an algorithm that runs in `O(m + n)` time?
+
+## Solution
+
+```kotlin
+class Solution {
+ fun merge(nums1: IntArray, m: Int, nums2: IntArray, n: Int) {
+ var i = m - 1
+ var j = nums1.size - 1
+ var p2 = n - 1
+ while (p2 >= 0) {
+ if (i >= 0 && nums1[i] > nums2[p2]) {
+ nums1[j--] = nums1[i--]
+ } else {
+ nums1[j--] = nums2[p2--]
+ }
+ }
+ }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g0001_0100/s0089_gray_code/readme.md b/src/main/kotlin/g0001_0100/s0089_gray_code/readme.md
new file mode 100644
index 00000000..09b82c9d
--- /dev/null
+++ b/src/main/kotlin/g0001_0100/s0089_gray_code/readme.md
@@ -0,0 +1,61 @@
+[](https://github.com/javadev/LeetCode-in-Kotlin)
+[](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 89\. Gray Code
+
+Medium
+
+An **n-bit gray code sequence** is a sequence of 2n
integers where:
+
+* Every integer is in the **inclusive** range [0, 2n - 1]
,
+* The first integer is `0`,
+* An integer appears **no more than once** in the sequence,
+* The binary representation of every pair of **adjacent** integers differs by **exactly one bit**, and
+* The binary representation of the **first** and **last** integers differs by **exactly one bit**.
+
+Given an integer `n`, return _any valid **n-bit gray code sequence**_.
+
+**Example 1:**
+
+**Input:** n = 2
+
+**Output:** [0,1,3,2]
+
+**Explanation:** The binary representation of [0,1,3,2] is [00,01,11,10]. - 00 and 01 differ by one bit - 01 and 11 differ by one bit - 11 and 10 differ by one bit - 10 and 00 differ by one bit [0,2,3,1] is also a valid gray code sequence, whose binary representation is [00,10,11,01]. - 00 and 10 differ by one bit - 10 and 11 differ by one bit - 11 and 01 differ by one bit - 01 and 00 differ by one bit
+
+**Example 2:**
+
+**Input:** n = 1
+
+**Output:** [0,1]
+
+**Constraints:**
+
+* `1 <= n <= 16`
+
+## Solution
+
+```kotlin
+@Suppress("NAME_SHADOWING")
+class Solution {
+ fun grayCode(n: Int): List> = ArrayList()
+ var comb: MutableList
> {
+ Arrays.sort(nums)
+ this.nums = nums
+ dfs(0)
+ allComb.add(ArrayList())
+ return allComb
+ }
+
+ private fun dfs(start: Int) {
+ if (start > nums.size) {
+ return
+ }
+ for (i in start until nums.size) {
+ if (i > start && nums[i] == nums[i - 1]) {
+ continue
+ }
+ comb.add(nums[i])
+ allComb.add(ArrayList(comb))
+ dfs(i + 1)
+ comb.removeAt(comb.size - 1)
+ }
+ }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g0001_0100/s0091_decode_ways/readme.md b/src/main/kotlin/g0001_0100/s0091_decode_ways/readme.md
new file mode 100644
index 00000000..8e010655
--- /dev/null
+++ b/src/main/kotlin/g0001_0100/s0091_decode_ways/readme.md
@@ -0,0 +1,81 @@
+[](https://github.com/javadev/LeetCode-in-Kotlin)
+[](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 91\. Decode Ways
+
+Medium
+
+A message containing letters from `A-Z` can be **encoded** into numbers using the following mapping:
+
+'A' -> "1" 'B' -> "2" ... 'Z' -> "26"
+
+To **decode** an encoded message, all the digits must be grouped then mapped back into letters using the reverse of the mapping above (there may be multiple ways). For example, `"11106"` can be mapped into:
+
+* `"AAJF"` with the grouping `(1 1 10 6)`
+* `"KJF"` with the grouping `(11 10 6)`
+
+Note that the grouping `(1 11 06)` is invalid because `"06"` cannot be mapped into `'F'` since `"6"` is different from `"06"`.
+
+Given a string `s` containing only digits, return _the **number** of ways to **decode** it_.
+
+The test cases are generated so that the answer fits in a **32-bit** integer.
+
+**Example 1:**
+
+**Input:** s = "12"
+
+**Output:** 2
+
+**Explanation:** "12" could be decoded as "AB" (1 2) or "L" (12).
+
+**Example 2:**
+
+**Input:** s = "226"
+
+**Output:** 3
+
+**Explanation:** "226" could be decoded as "BZ" (2 26), "VF" (22 6), or "BBF" (2 2 6).
+
+**Example 3:**
+
+**Input:** s = "06"
+
+**Output:** 0
+
+**Explanation:** "06" cannot be mapped to "F" because of the leading zero ("6" is different from "06").
+
+**Constraints:**
+
+* `1 <= s.length <= 100`
+* `s` contains only digits and may contain leading zero(s).
+
+## Solution
+
+```kotlin
+class Solution {
+ fun numDecodings(s: String): Int {
+ if (s[0] == '0') {
+ return 0
+ }
+ val n = s.length
+ val f = IntArray(n + 1)
+ // Auxiliary
+ f[0] = 1
+ f[1] = 1
+ for (i in 2..n) {
+ // Calculate the independent number
+ if (s[i - 1] != '0') {
+ // As long as the current character is not 0, it means that the previous decoding
+ // number can be inherited
+ f[i] = f[i - 1]
+ }
+ // Calculate the number of combinations
+ val twodigits = (s[i - 2] - '0') * 10 + (s[i - 1] - '0')
+ if (twodigits >= 10 && twodigits <= 26) {
+ f[i] += f[i - 2]
+ }
+ }
+ return f[n]
+ }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g0001_0100/s0092_reverse_linked_list_ii/readme.md b/src/main/kotlin/g0001_0100/s0092_reverse_linked_list_ii/readme.md
new file mode 100644
index 00000000..27ea38fc
--- /dev/null
+++ b/src/main/kotlin/g0001_0100/s0092_reverse_linked_list_ii/readme.md
@@ -0,0 +1,104 @@
+[](https://github.com/javadev/LeetCode-in-Kotlin)
+[](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 92\. Reverse Linked List II
+
+Medium
+
+Given the `head` of a singly linked list and two integers `left` and `right` where `left <= right`, reverse the nodes of the list from position `left` to position `right`, and return _the reversed list_.
+
+**Example 1:**
+
+
+
+**Input:** head = [1,2,3,4,5], left = 2, right = 4
+
+**Output:** [1,4,3,2,5]
+
+**Example 2:**
+
+**Input:** head = [5], left = 1, right = 1
+
+**Output:** [5]
+
+**Constraints:**
+
+* The number of nodes in the list is `n`.
+* `1 <= n <= 500`
+* `-500 <= Node.val <= 500`
+* `1 <= left <= right <= n`
+
+**Follow up:** Could you do it in one pass?
+
+## Solution
+
+```kotlin
+import com_github_leetcode.ListNode
+
+/*
+ * Example:
+ * var li = ListNode(5)
+ * var v = li.`val`
+ * Definition for singly-linked list.
+ * class ListNode(var `val`: Int) {
+ * var next: ListNode? = null
+ * }
+ */
+@Suppress("NAME_SHADOWING")
+class Solution {
+ fun reverseBetween(head: ListNode?, left: Int, right: Int): ListNode? {
+ var head = head
+ var right = right
+ if (left == right) {
+ return head
+ }
+ var prev: ListNode? = null
+ var temp = head
+ val start: ListNode?
+ var k = left
+ while (temp != null && k > 1) {
+ prev = temp
+ temp = temp.next
+ k--
+ }
+ if (left > 1 && prev != null) {
+ prev.next = null
+ }
+ var prev1: ListNode? = null
+ start = temp
+ while (temp != null && right - left >= 0) {
+ prev1 = temp
+ temp = temp.next
+ right--
+ }
+ if (prev1 != null) {
+ prev1.next = null
+ }
+ if (left > 1 && prev != null) {
+ prev.next = reverse(start)
+ } else {
+ head = reverse(start)
+ prev = head
+ }
+ while (prev!!.next != null) {
+ prev = prev.next
+ }
+ prev.next = temp
+ return head
+ }
+
+ fun reverse(head: ListNode?): ListNode? {
+ var p: ListNode?
+ var q: ListNode?
+ var r: ListNode? = null
+ p = head
+ while (p != null) {
+ q = p.next
+ p.next = r
+ r = p
+ p = q
+ }
+ return r
+ }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g0001_0100/s0093_restore_ip_addresses/readme.md b/src/main/kotlin/g0001_0100/s0093_restore_ip_addresses/readme.md
new file mode 100644
index 00000000..83128548
--- /dev/null
+++ b/src/main/kotlin/g0001_0100/s0093_restore_ip_addresses/readme.md
@@ -0,0 +1,75 @@
+[](https://github.com/javadev/LeetCode-in-Kotlin)
+[](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 93\. Restore IP Addresses
+
+Medium
+
+A **valid IP address** consists of exactly four integers separated by single dots. Each integer is between `0` and `255` (**inclusive**) and cannot have leading zeros.
+
+* For example, `"0.1.2.201"` and `"192.168.1.1"` are **valid** IP addresses, but `"0.011.255.245"`, `"192.168.1.312"` and `"192.168@1.1"` are **invalid** IP addresses.
+
+Given a string `s` containing only digits, return _all possible valid IP addresses that can be formed by inserting dots into_ `s`. You are **not** allowed to reorder or remove any digits in `s`. You may return the valid IP addresses in **any** order.
+
+**Example 1:**
+
+**Input:** s = "25525511135"
+
+**Output:** ["255.255.11.135","255.255.111.35"]
+
+**Example 2:**
+
+**Input:** s = "0000"
+
+**Output:** ["0.0.0.0"]
+
+**Example 3:**
+
+**Input:** s = "101023"
+
+**Output:** ["1.0.10.23","1.0.102.3","10.1.0.23","10.10.2.3","101.0.2.3"]
+
+**Constraints:**
+
+* `1 <= s.length <= 20`
+* `s` consists of digits only.
+
+## Solution
+
+```kotlin
+class Solution() {
+ fun restoreIpAddresses(s: String): List
s = s1 + s2 + ... + sn
+* t = t1 + t2 + ... + tm
+* `|n - m| <= 1`
+* The **interleaving** is s1 + t1 + s2 + t2 + s3 + t3 + ...
or t1 + s1 + t2 + s2 + t3 + s3 + ...
+
+**Note:** `a + b` is the concatenation of strings `a` and `b`.
+
+**Example 1:**
+
+
+
+**Input:** s1 = "aabcc", s2 = "dbbca", s3 = "aadbbcbcac"
+
+**Output:** true
+
+**Explanation:** One way to obtain s3 is: Split s1 into s1 = "aa" + "bc" + "c", and s2 into s2 = "dbbc" + "a". Interleaving the two splits, we get "aa" + "dbbc" + "bc" + "a" + "c" = "aadbbcbcac". Since s3 can be obtained by interleaving s1 and s2, we return true.
+
+**Example 2:**
+
+**Input:** s1 = "aabcc", s2 = "dbbca", s3 = "aadbbbaccc"
+
+**Output:** false
+
+**Explanation:** Notice how it is impossible to interleave s2 with any other string to obtain s3.
+
+**Example 3:**
+
+**Input:** s1 = "", s2 = "", s3 = ""
+
+**Output:** true
+
+**Constraints:**
+
+* `0 <= s1.length, s2.length <= 100`
+* `0 <= s3.length <= 200`
+* `s1`, `s2`, and `s3` consist of lowercase English letters.
+
+**Follow up:** Could you solve it using only `O(s2.length)` additional memory space?
+
+## Solution
+
+```kotlin
+class Solution {
+ fun isInterleave(s1: String, s2: String, s3: String): Boolean {
+ if (s3.length != s1.length + s2.length) {
+ return false
+ }
+ val cache = Array(s1.length + 1) { arrayOfNulls> {
var localRoot: TreeNode? = root
diff --git a/src/main/kotlin/g0101_0200/s0105_construct_binary_tree_from_preorder_and_inorder_traversal/readme.md b/src/main/kotlin/g0101_0200/s0105_construct_binary_tree_from_preorder_and_inorder_traversal/readme.md
index d0f7fd87..9da626b9 100644
--- a/src/main/kotlin/g0101_0200/s0105_construct_binary_tree_from_preorder_and_inorder_traversal/readme.md
+++ b/src/main/kotlin/g0101_0200/s0105_construct_binary_tree_from_preorder_and_inorder_traversal/readme.md
@@ -37,6 +37,16 @@ Given two integer arrays `preorder` and `inorder` where `preorder` is the preord
import com_github_leetcode.TreeNode
import java.util.HashMap
+/*
+ * Example:
+ * var ti = TreeNode(5)
+ * var v = ti.`val`
+ * Definition for a binary tree node.
+ * class TreeNode(var `val`: Int) {
+ * var left: TreeNode? = null
+ * var right: TreeNode? = null
+ * }
+ */
class Solution {
private var j = 0
private val map: MutableMap