Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@

| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
|-|-|-|-|-|-
| 0343 |[Integer Break](src/main/kotlin/g0301_0400/s0343_integer_break)| Medium | Dynamic_Programming, Math | 218 | 63.89
| 0279 |[Perfect Squares](src/main/kotlin/g0201_0300/s0279_perfect_squares)| Medium | Top_Interview_Questions, Dynamic_Programming, Math, Breadth_First_Search | 176 | 98.80

### Programming Skills I
Expand Down Expand Up @@ -512,6 +513,7 @@

| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
|-|-|-|-|-|-
| 0365 |[Water and Jug Problem](src/main/kotlin/g0301_0400/s0365_water_and_jug_problem)| Medium | Math, Depth_First_Search, Breadth_First_Search | 130 | 100.00

#### Day 12 Breadth First Search

Expand Down Expand Up @@ -835,6 +837,7 @@

| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
|-|-|-|-|-|-
| 0344 |[Reverse String](src/main/kotlin/g0301_0400/s0344_reverse_string)| Easy | Top_Interview_Questions, String, Two_Pointers, Recursion | 445 | 69.75
| 0014 |[Longest Common Prefix](src/main/kotlin/g0001_0100/s0014_longest_common_prefix)| Easy | Top_Interview_Questions, String | 209 | 88.86
| 0187 |[Repeated DNA Sequences](src/main/kotlin/g0101_0200/s0187_repeated_dna_sequences)| Medium | String, Hash_Table, Bit_Manipulation, Sliding_Window, Hash_Function, Rolling_Hash | 319 | 79.03
| 0003 |[Longest Substring Without Repeating Characters](src/main/kotlin/g0001_0100/s0003_longest_substring_without_repeating_characters)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window | 258 | 91.09
Expand Down Expand Up @@ -941,6 +944,7 @@
| 0297 |[Serialize and Deserialize Binary Tree](src/main/kotlin/g0201_0300/s0297_serialize_and_deserialize_binary_tree)| Hard | Top_Interview_Questions, String, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Design | 475 | 78.85
| 0124 |[Binary Tree Maximum Path Sum](src/main/kotlin/g0101_0200/s0124_binary_tree_maximum_path_sum)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Depth_First_Search, Tree, Binary_Tree | 331 | 74.42
| 0098 |[Validate Binary Search Tree](src/main/kotlin/g0001_0100/s0098_validate_binary_search_tree)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree | 330 | 41.38
| 0337 |[House Robber III](src/main/kotlin/g0301_0400/s0337_house_robber_iii)| Medium | Dynamic_Programming, Depth_First_Search, Tree, Binary_Tree | 282 | 84.62
| 0236 |[Lowest Common Ancestor of a Binary Tree](src/main/kotlin/g0201_0300/s0236_lowest_common_ancestor_of_a_binary_tree)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree | 386 | 45.21

#### Udemy Trie and Heap
Expand Down Expand Up @@ -1021,6 +1025,7 @@

| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
|-|-|-|-|-|-
| 0350 |[Intersection of Two Arrays II](src/main/kotlin/g0301_0400/s0350_intersection_of_two_arrays_ii)| Easy | Top_Interview_Questions, Array, Hash_Table, Sorting, Binary_Search, Two_Pointers | 321 | 73.37
| 0121 |[Best Time to Buy and Sell Stock](src/main/kotlin/g0101_0200/s0121_best_time_to_buy_and_sell_stock)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming | 609 | 94.06

#### Day 4 Array
Expand Down Expand Up @@ -1134,6 +1139,7 @@

| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
|-|-|-|-|-|-
| 0334 |[Increasing Triplet Subsequence](src/main/kotlin/g0301_0400/s0334_increasing_triplet_subsequence)| Medium | Top_Interview_Questions, Array, Greedy | 672 | 60.61
| 0238 |[Product of Array Except Self](src/main/kotlin/g0201_0300/s0238_product_of_array_except_self)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Prefix_Sum | 669 | 48.96
| 0560 |[Subarray Sum Equals K](src/main/kotlin/g0501_0600/s0560_subarray_sum_equals_k)| Medium | Top_100_Liked_Questions, Array, Hash_Table, Prefix_Sum | 692 | 53.27

Expand Down Expand Up @@ -1268,6 +1274,7 @@

| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
|-|-|-|-|-|-
| 0344 |[Reverse String](src/main/kotlin/g0301_0400/s0344_reverse_string)| Easy | Top_Interview_Questions, String, Two_Pointers, Recursion | 445 | 69.75

#### Day 5 Two Pointers

Expand Down Expand Up @@ -1457,6 +1464,7 @@
|-|-|-|-|-|-
| 0072 |[Edit Distance](src/main/kotlin/g0001_0100/s0072_edit_distance)| Hard | Top_100_Liked_Questions, String, Dynamic_Programming | 320 | 63.53
| 0322 |[Coin Change](src/main/kotlin/g0301_0400/s0322_coin_change)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Breadth_First_Search | 332 | 50.68
| 0343 |[Integer Break](src/main/kotlin/g0301_0400/s0343_integer_break)| Medium | Dynamic_Programming, Math | 218 | 63.89

#### Day 19 Bit Manipulation

Expand Down Expand Up @@ -1493,6 +1501,7 @@

| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
|-|-|-|-|-|-
| 0367 |[Valid Perfect Square](src/main/kotlin/g0301_0400/s0367_valid_perfect_square)| Easy | Math, Binary_Search | 137 | 94.55

#### Day 4

Expand Down Expand Up @@ -1533,6 +1542,7 @@

| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
|-|-|-|-|-|-
| 0350 |[Intersection of Two Arrays II](src/main/kotlin/g0301_0400/s0350_intersection_of_two_arrays_ii)| Easy | Top_Interview_Questions, Array, Hash_Table, Sorting, Binary_Search, Two_Pointers | 321 | 73.37

#### Day 11

Expand Down Expand Up @@ -1564,13 +1574,33 @@
| 0416 |[Partition Equal Subset Sum](src/main/kotlin/g0401_0500/s0416_partition_equal_subset_sum)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Level_2_Day_13_Dynamic_Programming | 509 | 57.56
| 0394 |[Decode String](src/main/kotlin/g0301_0400/s0394_decode_string)| Medium | Top_100_Liked_Questions, String, Stack, Recursion, Level_1_Day_14_Stack, Udemy_Strings | 224 | 64.86
| 0378 |[Kth Smallest Element in a Sorted Matrix](src/main/kotlin/g0301_0400/s0378_kth_smallest_element_in_a_sorted_matrix)| Medium | Top_Interview_Questions, Array, Sorting, Binary_Search, Matrix, Heap_Priority_Queue | 522 | 59.78
| 0368 |[Largest Divisible Subset](src/main/kotlin/g0301_0400/s0368_largest_divisible_subset)| Medium | Array, Dynamic_Programming, Math, Sorting | 412 | 73.33
| 0367 |[Valid Perfect Square](src/main/kotlin/g0301_0400/s0367_valid_perfect_square)| Easy | Math, Binary_Search, Binary_Search_I_Day_3 | 137 | 94.55
| 0365 |[Water and Jug Problem](src/main/kotlin/g0301_0400/s0365_water_and_jug_problem)| Medium | Math, Depth_First_Search, Breadth_First_Search, Graph_Theory_I_Day_11_Breadth_First_Search | 130 | 100.00
| 0363 |[Max Sum of Rectangle No Larger Than K](src/main/kotlin/g0301_0400/s0363_max_sum_of_rectangle_no_larger_than_k)| Hard | Array, Dynamic_Programming, Binary_Search, Matrix, Ordered_Set | 243 | 100.00
| 0357 |[Count Numbers with Unique Digits](src/main/kotlin/g0301_0400/s0357_count_numbers_with_unique_digits)| Medium | Dynamic_Programming, Math, Backtracking | 104 | 100.00
| 0355 |[Design Twitter](src/main/kotlin/g0301_0400/s0355_design_twitter)| Medium | Hash_Table, Design, Heap_Priority_Queue, Linked_List | 288 | 68.75
| 0354 |[Russian Doll Envelopes](src/main/kotlin/g0301_0400/s0354_russian_doll_envelopes)| Hard | Array, Dynamic_Programming, Sorting, Binary_Search | 788 | 100.00
| 0352 |[Data Stream as Disjoint Intervals](src/main/kotlin/g0301_0400/s0352_data_stream_as_disjoint_intervals)| Hard | Binary_Search, Design, Ordered_Set | 905 | 75.00
| 0350 |[Intersection of Two Arrays II](src/main/kotlin/g0301_0400/s0350_intersection_of_two_arrays_ii)| Easy | Top_Interview_Questions, Array, Hash_Table, Sorting, Binary_Search, Two_Pointers, Data_Structure_I_Day_3_Array, Binary_Search_I_Day_10 | 321 | 73.37
| 0349 |[Intersection of Two Arrays](src/main/kotlin/g0301_0400/s0349_intersection_of_two_arrays)| Easy | Array, Hash_Table, Sorting, Binary_Search, Two_Pointers | 346 | 66.99
| 0347 |[Top K Frequent Elements](src/main/kotlin/g0301_0400/s0347_top_k_frequent_elements)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Sorting, Heap_Priority_Queue, Counting, Divide_and_Conquer, Quickselect, Bucket_Sort, Data_Structure_II_Day_20_Heap_Priority_Queue | 268 | 99.74
| 0345 |[Reverse Vowels of a String](src/main/kotlin/g0301_0400/s0345_reverse_vowels_of_a_string)| Easy | String, Two_Pointers | 349 | 80.63
| 0344 |[Reverse String](src/main/kotlin/g0301_0400/s0344_reverse_string)| Easy | Top_Interview_Questions, String, Two_Pointers, Recursion, Algorithm_I_Day_4_Two_Pointers, Udemy_Strings | 445 | 69.75
| 0343 |[Integer Break](src/main/kotlin/g0301_0400/s0343_integer_break)| Medium | Dynamic_Programming, Math, Algorithm_II_Day_18_Dynamic_Programming, Dynamic_Programming_I_Day_21 | 218 | 63.89
| 0342 |[Power of Four](src/main/kotlin/g0301_0400/s0342_power_of_four)| Easy | Math, Bit_Manipulation, Recursion | 150 | 92.11
| 0338 |[Counting Bits](src/main/kotlin/g0301_0400/s0338_counting_bits)| Easy | Top_100_Liked_Questions, Dynamic_Programming, Bit_Manipulation, Udemy_Bit_Manipulation | 186 | 99.26
| 0337 |[House Robber III](src/main/kotlin/g0301_0400/s0337_house_robber_iii)| Medium | Dynamic_Programming, Depth_First_Search, Tree, Binary_Tree, Udemy_Tree_Stack_Queue | 282 | 84.62
| 0336 |[Palindrome Pairs](src/main/kotlin/g0301_0400/s0336_palindrome_pairs)| Hard | Array, String, Hash_Table, Trie | 2451 | 67.33
| 0335 |[Self Crossing](src/main/kotlin/g0301_0400/s0335_self_crossing)| Hard | Array, Math, Geometry | 477 | 100.00
| 0334 |[Increasing Triplet Subsequence](src/main/kotlin/g0301_0400/s0334_increasing_triplet_subsequence)| Medium | Top_Interview_Questions, Array, Greedy, Data_Structure_II_Day_5_Array | 672 | 60.61
| 0332 |[Reconstruct Itinerary](src/main/kotlin/g0301_0400/s0332_reconstruct_itinerary)| Hard | Depth_First_Search, Graph, Eulerian_Circuit | 240 | 93.88
| 0331 |[Verify Preorder Serialization of a Binary Tree](src/main/kotlin/g0301_0400/s0331_verify_preorder_serialization_of_a_binary_tree)| Medium | String, Tree, Binary_Tree, Stack | 335 | 70.00
| 0330 |[Patching Array](src/main/kotlin/g0301_0400/s0330_patching_array)| Hard | Array, Greedy | 201 | 100.00
| 0329 |[Longest Increasing Path in a Matrix](src/main/kotlin/g0301_0400/s0329_longest_increasing_path_in_a_matrix)| Hard | Top_Interview_Questions, Dynamic_Programming, Depth_First_Search, Breadth_First_Search, Graph, Memoization, Topological_Sort | 322 | 92.65
| 0328 |[Odd Even Linked List](src/main/kotlin/g0301_0400/s0328_odd_even_linked_list)| Medium | Top_Interview_Questions, Linked_List, Level_2_Day_4_Linked_List, Udemy_Linked_List | 216 | 86.96
| 0327 |[Count of Range Sum](src/main/kotlin/g0301_0400/s0327_count_of_range_sum)| Hard | Array, Binary_Search, Ordered_Set, Divide_and_Conquer, Segment_Tree, Binary_Indexed_Tree, Merge_Sort | 638 | 100.00
| 0326 |[Wiggle Sort II](src/main/kotlin/g0301_0400/s0326_power_of_three)| Easy | Top_Interview_Questions, Math, Recursion | 413 | 76.12
| 0326 |[Power of Three](src/main/kotlin/g0301_0400/s0326_power_of_three)| Easy | Top_Interview_Questions, Math, Recursion | 413 | 76.12
| 0324 |[Wiggle Sort II](src/main/kotlin/g0301_0400/s0324_wiggle_sort_ii)| Medium | Top_Interview_Questions, Array, Sorting, Divide_and_Conquer, Quickselect | 545 | 57.14
| 0322 |[Coin Change](src/main/kotlin/g0301_0400/s0322_coin_change)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Breadth_First_Search, Algorithm_II_Day_18_Dynamic_Programming, Dynamic_Programming_I_Day_20, Level_2_Day_12_Dynamic_Programming | 332 | 50.68
| 0321 |[Create Maximum Number](src/main/kotlin/g0301_0400/s0321_create_maximum_number)| Hard | Greedy, Stack, Monotonic_Stack | 209 | 100.00
Expand Down
3 changes: 1 addition & 2 deletions src/main/kotlin/g0001_0100/s0015_3sum/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@ Notice that the solution set must not contain duplicate triplets.
## Solution

```kotlin
import java.util.Arrays
import kotlin.collections.ArrayList

class Solution {
fun threeSum(nums: IntArray): List<List<Int>> {
Arrays.sort(nums)
nums.sort()
val len = nums.size
val result: MutableList<List<Int>> = ArrayList()
var l: Int
Expand Down
4 changes: 1 addition & 3 deletions src/main/kotlin/g0001_0100/s0016_3sum_closest/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ You may assume that each input would have exactly one solution.
## Solution

```kotlin
import java.util.Arrays

class Solution {
fun threeSumClosest(nums: IntArray?, target: Int): Int {
if (nums == null || nums.size < 3) {
Expand All @@ -44,7 +42,7 @@ class Solution {
if (nums.size == 3) {
return nums[0] + nums[1] + nums[2]
}
Arrays.sort(nums)
nums.sort()
val n = nums.size
var sum = nums[0] + nums[1] + nums[2]
for (i in 0 until n - 2) {
Expand Down
4 changes: 1 addition & 3 deletions src/main/kotlin/g0001_0100/s0018_4sum/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ You may return the answer in **any order**.
## Solution

```kotlin
import java.util.Arrays

class Solution {
fun fourSum(nums: IntArray, target: Int): List<List<Int>> {
val ret: MutableList<List<Int>> = ArrayList()
Expand All @@ -45,7 +43,7 @@ class Solution {
if (nums[0] == 1000000000 && nums[1] == 1000000000) {
return ret
}
Arrays.sort(nums)
nums.sort()
for (i in 0 until nums.size - 3) {
if (i != 0 && nums[i] == nums[i - 1]) {
continue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,13 @@ Each number in `candidates` may only be used **once** in the combination.
## Solution

```kotlin
import java.util.Arrays
import java.util.LinkedList

class Solution {
fun combinationSum2(candidates: IntArray, target: Int): List<List<Int>> {
val sums: MutableList<List<Int>> = ArrayList()
// optimize
Arrays.sort(candidates)
candidates.sort()
combinationSum(candidates, target, 0, sums, LinkedList())
return sums
}
Expand Down
4 changes: 1 addition & 3 deletions src/main/kotlin/g0001_0100/s0049_group_anagrams/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,12 @@ An **Anagram** is a word or phrase formed by rearranging the letters of a differ
## Solution

```kotlin
import java.util.Arrays

class Solution {
fun groupAnagrams(strs: Array<String>): List<List<String>> {
val hm: MutableMap<String, MutableList<String>> = HashMap()
for (s in strs) {
val ch = s.toCharArray()
Arrays.sort(ch)
ch.sort()
val temp = String(ch)
hm.computeIfAbsent(
temp
Expand Down
6 changes: 1 addition & 5 deletions src/main/kotlin/g0001_0100/s0056_merge_intervals/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,9 @@ Given an array of `intervals` where <code>intervals[i] = [start<sub>i</sub>, end
## Solution

```kotlin
import java.util.Arrays

class Solution {
fun merge(intervals: Array<IntArray>): Array<IntArray> {
Arrays.sort(
intervals
) { a: IntArray, b: IntArray ->
intervals.sortWith { a: IntArray, b: IntArray ->
Integer.compare(
a[0],
b[0]
Expand Down
4 changes: 1 addition & 3 deletions src/main/kotlin/g0001_0100/s0090_subsets_ii/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@ The solution set **must not** contain duplicate subsets. Return the solution in
## Solution

```kotlin
import java.util.Arrays

class Solution {
var allComb: MutableList<List<Int>> = ArrayList()
var comb: MutableList<Int> = ArrayList()
lateinit var nums: IntArray
fun subsetsWithDup(nums: IntArray): List<List<Int>> {
Arrays.sort(nums)
nums.sort()
this.nums = nums
dfs(0)
allComb.add(ArrayList())
Expand Down
4 changes: 1 addition & 3 deletions src/main/kotlin/g0101_0200/s0164_maximum_gap/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,13 @@ You must write an algorithm that runs in linear time and uses linear extra space
## Solution

```kotlin
import java.util.Arrays

class Solution {
fun maximumGap(nums: IntArray): Int {
if (nums.size < 2) {
return 0
}
var ret = Int.MIN_VALUE
Arrays.sort(nums)
nums.sort()
for (i in 0 until nums.size - 1) {
if (nums[i + 1] - nums[i] > ret) {
ret = nums[i + 1] - nums[i]
Expand Down
4 changes: 1 addition & 3 deletions src/main/kotlin/g0101_0200/s0179_largest_number/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,14 @@ Since the result may be very large, so you need to return a string instead of an
## Solution

```kotlin
import java.util.Arrays

class Solution {
fun largestNumber(nums: IntArray): String {
val n = nums.size
val s = arrayOfNulls<String>(n)
for (i in 0 until n) {
s[i] = nums[i].toString()
}
Arrays.sort(s) { a: String?, b: String? ->
s.sortWith { a: String?, b: String? ->
(b + a).compareTo(
a + b
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@ You must solve it in `O(n)` time complexity.
## Solution

```kotlin
import java.util.Arrays

class Solution {
fun findKthLargest(nums: IntArray, k: Int): Int {
val n = nums.size
Arrays.sort(nums)
nums.sort()
return nums[n - k]
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/main/kotlin/g0301_0400/s0324_wiggle_sort_ii/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ You may assume the input array always has a valid answer.
## Solution

```kotlin
import java.util.Arrays

class Solution {
fun wiggleSort(nums: IntArray) {
Arrays.sort(nums)
nums.sort()
val result = IntArray(nums.size)
var index = nums.size - 1
var i = 1
Expand Down
34 changes: 21 additions & 13 deletions src/main/kotlin/g0301_0400/s0326_power_of_three/readme.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,43 @@
[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)

## 324\. Wiggle Sort II
## 326\. Power of Three

Medium
Easy

Given an integer array `nums`, reorder it such that `nums[0] < nums[1] > nums[2] < nums[3]...`.
Given an integer `n`, return _`true` if it is a power of three. Otherwise, return `false`_.

You may assume the input array always has a valid answer.
An integer `n` is a power of three, if there exists an integer `x` such that <code>n == 3<sup>x</sup></code>.

**Example 1:**

**Input:** nums = [1,5,1,1,6,4]
**Input:** n = 27

**Output:** [1,6,1,5,1,4]
**Output:** true

**Explanation:** [1,4,1,5,1,6] is also accepted.
**Explanation:** 27 = 3<sup>3</sup>

**Example 2:**

**Input:** nums = [1,3,2,2,3,1]
**Input:** n = 0

**Output:** [2,3,1,3,1,2]
**Output:** false

**Explanation:** There is no x where 3<sup>x</sup> = 0.

**Example 3:**

**Input:** n = -1

**Output:** false

**Explanation:** There is no x where 3<sup>x</sup> = (-1).

**Constraints:**

* <code>1 <= nums.length <= 5 * 10<sup>4</sup></code>
* `0 <= nums[i] <= 5000`
* It is guaranteed that there will be an answer for the given input `nums`.
* <code>-2<sup>31</sup> <= n <= 2<sup>31</sup> - 1</code>

**Follow Up:** Can you do it in `O(n)` time and/or **in-place** with `O(1)` extra space?
**Follow up:** Could you solve it without loops/recursion?

## Solution

Expand Down
Loading