From 7c97dd378ad3bd7c0f729a307f2ce0781882f94c Mon Sep 17 00:00:00 2001 From: Valentyn Kolesnikov Date: Sun, 7 Sep 2025 08:55:52 +0300 Subject: [PATCH 1/2] Added tasks 3663-3671 --- gradle.properties | 1 + .../Solution.kt | 27 +++++ .../readme.md | 33 +++++ .../s3664_two_letter_card_game/Solution.kt | 57 +++++++++ .../s3664_two_letter_card_game/readme.md | 58 +++++++++ .../Solution.kt | 37 ++++++ .../s3665_twisted_mirror_path_count/readme.md | 75 ++++++++++++ .../Solution.kt | 46 +++++++ .../readme.md | 51 ++++++++ .../s3668_restore_finishing_order/Solution.kt | 20 +++ .../s3668_restore_finishing_order/readme.md | 38 ++++++ .../Solution.kt | 75 ++++++++++++ .../readme.md | 38 ++++++ .../Solution.kt | 64 ++++++++++ .../readme.md | 44 +++++++ .../Solution.kt | 114 ++++++++++++++++++ .../readme.md | 72 +++++++++++ .../SolutionTest.kt | 17 +++ .../SolutionTest.kt | 31 +++++ .../SolutionTest.kt | 36 ++++++ .../SolutionTest.kt | 82 +++++++++++++ .../SolutionTest.kt | 23 ++++ .../SolutionTest.kt | 23 ++++ .../SolutionTest.kt | 28 +++++ .../SolutionTest.kt | 17 +++ 25 files changed, 1107 insertions(+) create mode 100644 src/main/kotlin/g3601_3700/s3663_find_the_least_frequent_digit/Solution.kt create mode 100644 src/main/kotlin/g3601_3700/s3663_find_the_least_frequent_digit/readme.md create mode 100644 src/main/kotlin/g3601_3700/s3664_two_letter_card_game/Solution.kt create mode 100644 src/main/kotlin/g3601_3700/s3664_two_letter_card_game/readme.md create mode 100644 src/main/kotlin/g3601_3700/s3665_twisted_mirror_path_count/Solution.kt create mode 100644 src/main/kotlin/g3601_3700/s3665_twisted_mirror_path_count/readme.md create mode 100644 src/main/kotlin/g3601_3700/s3666_minimum_operations_to_equalize_binary_string/Solution.kt create mode 100644 src/main/kotlin/g3601_3700/s3666_minimum_operations_to_equalize_binary_string/readme.md create mode 100644 src/main/kotlin/g3601_3700/s3668_restore_finishing_order/Solution.kt create mode 100644 src/main/kotlin/g3601_3700/s3668_restore_finishing_order/readme.md create mode 100644 src/main/kotlin/g3601_3700/s3669_balanced_k_factor_decomposition/Solution.kt create mode 100644 src/main/kotlin/g3601_3700/s3669_balanced_k_factor_decomposition/readme.md create mode 100644 src/main/kotlin/g3601_3700/s3670_maximum_product_of_two_integers_with_no_common_bits/Solution.kt create mode 100644 src/main/kotlin/g3601_3700/s3670_maximum_product_of_two_integers_with_no_common_bits/readme.md create mode 100644 src/main/kotlin/g3601_3700/s3671_sum_of_beautiful_subsequences/Solution.kt create mode 100644 src/main/kotlin/g3601_3700/s3671_sum_of_beautiful_subsequences/readme.md create mode 100644 src/test/kotlin/g3601_3700/s3663_find_the_least_frequent_digit/SolutionTest.kt create mode 100644 src/test/kotlin/g3601_3700/s3664_two_letter_card_game/SolutionTest.kt create mode 100644 src/test/kotlin/g3601_3700/s3665_twisted_mirror_path_count/SolutionTest.kt create mode 100644 src/test/kotlin/g3601_3700/s3666_minimum_operations_to_equalize_binary_string/SolutionTest.kt create mode 100644 src/test/kotlin/g3601_3700/s3668_restore_finishing_order/SolutionTest.kt create mode 100644 src/test/kotlin/g3601_3700/s3669_balanced_k_factor_decomposition/SolutionTest.kt create mode 100644 src/test/kotlin/g3601_3700/s3670_maximum_product_of_two_integers_with_no_common_bits/SolutionTest.kt create mode 100644 src/test/kotlin/g3601_3700/s3671_sum_of_beautiful_subsequences/SolutionTest.kt diff --git a/gradle.properties b/gradle.properties index 732fad51..c420fffb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,3 @@ sonar.coverage.jacoco.xmlReportPaths=build/reports/jacoco/test/jacocoTestReport.xml org.gradle.jvmargs=-Xms512m -Xmx2048m +org.gradle.configuration-cache=true diff --git a/src/main/kotlin/g3601_3700/s3663_find_the_least_frequent_digit/Solution.kt b/src/main/kotlin/g3601_3700/s3663_find_the_least_frequent_digit/Solution.kt new file mode 100644 index 00000000..e68dfec0 --- /dev/null +++ b/src/main/kotlin/g3601_3700/s3663_find_the_least_frequent_digit/Solution.kt @@ -0,0 +1,27 @@ +package g3601_3700.s3663_find_the_least_frequent_digit + +// #Easy #Biweekly_Contest_164 #2025_09_07_Time_1_ms_(96.30%)_Space_40.60_MB_(100.00%) + +class Solution { + fun getLeastFrequentDigit(n: Int): Int { + val freq = IntArray(10) + val numStr = n.toString() + for (c in numStr.toCharArray()) { + freq[c.code - '0'.code]++ + } + var minFreq = Int.Companion.MAX_VALUE + var result = -1 + for (d in 0..9) { + if (freq[d] == 0) { + continue + } + if (freq[d] < minFreq) { + minFreq = freq[d] + result = d + } else if (freq[d] == minFreq && d < result) { + result = d + } + } + return result + } +} diff --git a/src/main/kotlin/g3601_3700/s3663_find_the_least_frequent_digit/readme.md b/src/main/kotlin/g3601_3700/s3663_find_the_least_frequent_digit/readme.md new file mode 100644 index 00000000..ed59979f --- /dev/null +++ b/src/main/kotlin/g3601_3700/s3663_find_the_least_frequent_digit/readme.md @@ -0,0 +1,33 @@ +3663\. Find The Least Frequent Digit + +Easy + +Given an integer `n`, find the digit that occurs **least** frequently in its decimal representation. If multiple digits have the same frequency, choose the **smallest** digit. + +Return the chosen digit as an integer. + +The **frequency** of a digit `x` is the number of times it appears in the decimal representation of `n`. + +**Example 1:** + +**Input:** n = 1553322 + +**Output:** 1 + +**Explanation:** + +The least frequent digit in `n` is 1, which appears only once. All other digits appear twice. + +**Example 2:** + +**Input:** n = 723344511 + +**Output:** 2 + +**Explanation:** + +The least frequent digits in `n` are 7, 2, and 5; each appears only once. + +**Constraints:** + +* 1 <= n <= 231 - 1 \ No newline at end of file diff --git a/src/main/kotlin/g3601_3700/s3664_two_letter_card_game/Solution.kt b/src/main/kotlin/g3601_3700/s3664_two_letter_card_game/Solution.kt new file mode 100644 index 00000000..6b54721d --- /dev/null +++ b/src/main/kotlin/g3601_3700/s3664_two_letter_card_game/Solution.kt @@ -0,0 +1,57 @@ +package g3601_3700.s3664_two_letter_card_game + +// #Medium #Biweekly_Contest_164 #2025_09_07_Time_11_ms_(100.00%)_Space_69.41_MB_(100.00%) + +import kotlin.math.min + +class Solution { + fun score(cards: Array, x: Char): Int { + // store input midway as required + // counts for "x?" group by second char and "?x" group by first char + val left = IntArray(10) + val right = IntArray(10) + var xx = 0 + for (c in cards) { + val a = c[0] + val b = c[1] + if (a == x && b == x) { + xx++ + } else if (a == x) { + left[b.code - 'a'.code]++ + } else if (b == x) { + right[a.code - 'a'.code]++ + } + } + // max pairs inside a group where pairs must come from different buckets: + // pairs = min(total/2, total - maxBucket) + var l = 0 + var maxL = 0 + for (v in left) { + l += v + if (v > maxL) { + maxL = v + } + } + var r = 0 + var maxR = 0 + for (v in right) { + r += v + if (v > maxR) { + maxR = v + } + } + val pairsLeft = min(l / 2, l - maxL) + val pairsRight = min(r / 2, r - maxR) + // leftovers after internal pairing + val leftoverL = l - 2 * pairsLeft + val leftoverR = r - 2 * pairsRight + val leftovers = leftoverL + leftoverR + // First, use "xx" to pair with any leftovers + val useWithXX = min(xx, leftovers) + val xxLeft = xx - useWithXX + // If "xx" still remain, we can break existing internal pairs: + // breaking 1 internal pair frees 2 cards, which can pair with 2 "xx" to gain +1 net point + val extraByBreaking = min(xxLeft / 2, pairsLeft + pairsRight) + return pairsLeft + pairsRight + useWithXX + extraByBreaking + } +} diff --git a/src/main/kotlin/g3601_3700/s3664_two_letter_card_game/readme.md b/src/main/kotlin/g3601_3700/s3664_two_letter_card_game/readme.md new file mode 100644 index 00000000..fda7d853 --- /dev/null +++ b/src/main/kotlin/g3601_3700/s3664_two_letter_card_game/readme.md @@ -0,0 +1,58 @@ +3664\. Two-Letter Card Game + +Medium + +You are given a deck of cards represented by a string array `cards`, and each card displays two lowercase letters. + +You are also given a letter `x`. You play a game with the following rules: + +* Start with 0 points. +* On each turn, you must find two **compatible** cards from the deck that both contain the letter `x` in any position. +* Remove the pair of cards and earn **1 point**. +* The game ends when you can no longer find a pair of compatible cards. + +Return the **maximum** number of points you can gain with optimal play. + +Two cards are **compatible** if the strings differ in **exactly** 1 position. + +**Example 1:** + +**Input:** cards = ["aa","ab","ba","ac"], x = "a" + +**Output:** 2 + +**Explanation:** + +* On the first turn, select and remove cards `"ab"` and `"ac"`, which are compatible because they differ at only index 1. +* On the second turn, select and remove cards `"aa"` and `"ba"`, which are compatible because they differ at only index 0. + +Because there are no more compatible pairs, the total score is 2. + +**Example 2:** + +**Input:** cards = ["aa","ab","ba"], x = "a" + +**Output:** 1 + +**Explanation:** + +* On the first turn, select and remove cards `"aa"` and `"ba"`. + +Because there are no more compatible pairs, the total score is 1. + +**Example 3:** + +**Input:** cards = ["aa","ab","ba","ac"], x = "b" + +**Output:** 0 + +**Explanation:** + +The only cards that contain the character `'b'` are `"ab"` and `"ba"`. However, they differ in both indices, so they are not compatible. Thus, the output is 0. + +**Constraints:** + +* 2 <= cards.length <= 105 +* `cards[i].length == 2` +* Each `cards[i]` is composed of only lowercase English letters between `'a'` and `'j'`. +* `x` is a lowercase English letter between `'a'` and `'j'`. \ No newline at end of file diff --git a/src/main/kotlin/g3601_3700/s3665_twisted_mirror_path_count/Solution.kt b/src/main/kotlin/g3601_3700/s3665_twisted_mirror_path_count/Solution.kt new file mode 100644 index 00000000..fc132505 --- /dev/null +++ b/src/main/kotlin/g3601_3700/s3665_twisted_mirror_path_count/Solution.kt @@ -0,0 +1,37 @@ +package g3601_3700.s3665_twisted_mirror_path_count + +// #Medium #Biweekly_Contest_164 #2025_09_07_Time_33_ms_(100.00%)_Space_113.52_MB_(72.73%) + +class Solution { + fun uniquePaths(grid: Array): Int { + // 0 right, 1 down + val n = grid.size + val m = grid[0].size + val mod = 1000000007 + var dp = IntArray(m) + dp[0] = 1 + for (j in 1..109 + 7. + +**Note**: If a reflection moves the robot into a mirror cell, the robot is immediately reflected again based on the direction it used to enter that mirror: if it entered while moving right, it will be turned down; if it entered while moving down, it will be turned right. This process will continue until either the last cell is reached, the robot moves out of bounds or the robot moves to a non-mirror cell. + +**Example 1:** + +**Input:** grid = [[0,1,0],[0,0,1],[1,0,0]] + +**Output:** 5 + +**Explanation:** + +| Number | Full Path | +|--------|---------------------------------------------------------------------| +| 1 | (0, 0) → (0, 1) [M] → (1, 1) → (1, 2) [M] → (2, 2) | +| 2 | (0, 0) → (0, 1) [M] → (1, 1) → (2, 1) → (2, 2) | +| 3 | (0, 0) → (1, 0) → (1, 1) → (1, 2) [M] → (2, 2) | +| 4 | (0, 0) → (1, 0) → (1, 1) → (2, 1) → (2, 2) | +| 5 | (0, 0) → (1, 0) → (2, 0) [M] → (2, 1) → (2, 2) | + +* `[M]` indicates the robot attempted to enter a mirror cell and instead reflected. + + +**Example 2:** + +**Input:** grid = [[0,0],[0,0]] + +**Output:** 2 + +**Explanation:** + +| Number | Full Path | +|--------|-----------------------------| +| 1 | (0, 0) → (0, 1) → (1, 1) | +| 2 | (0, 0) → (1, 0) → (1, 1) | + +**Example 3:** + +**Input:** grid = [[0,1,1],[1,1,0]] + +**Output:** 1 + +**Explanation:** + +| Number | Full Path | +|--------|-------------------------------------------| +| 1 | (0, 0) → (0, 1) [M] → (1, 1) [M] → (1, 2) | + +`(0, 0) → (1, 0) [M] → (1, 1) [M] → (2, 1)` goes out of bounds, so it is invalid. + +**Constraints:** + +* `m == grid.length` +* `n == grid[i].length` +* `2 <= m, n <= 500` +* `grid[i][j]` is either `0` or `1`. +* `grid[0][0] == grid[m - 1][n - 1] == 0` \ No newline at end of file diff --git a/src/main/kotlin/g3601_3700/s3666_minimum_operations_to_equalize_binary_string/Solution.kt b/src/main/kotlin/g3601_3700/s3666_minimum_operations_to_equalize_binary_string/Solution.kt new file mode 100644 index 00000000..00be3efd --- /dev/null +++ b/src/main/kotlin/g3601_3700/s3666_minimum_operations_to_equalize_binary_string/Solution.kt @@ -0,0 +1,46 @@ +package g3601_3700.s3666_minimum_operations_to_equalize_binary_string + +// #Hard #Biweekly_Contest_164 #2025_09_07_Time_8_ms_(100.00%)_Space_46.70_MB_(100.00%) + +import kotlin.math.max + +class Solution { + fun minOperations(s: String, k: Int): Int { + val n = s.length + var cnt0 = 0 + for (c in s.toCharArray()) { + if (c == '0') { + cnt0++ + } + } + if (cnt0 == 0) { + return 0 + } + if (k == n) { + return if (cnt0 == n) 1 else -1 + } + val kP = k and 1 + val needP = cnt0 and 1 + var best = Long.Companion.MAX_VALUE + for (p in 0..1) { + if ((p * kP) % 2 != needP) { + continue + } + val mismatch = (if (p == 0) cnt0 else (n - cnt0)).toLong() + val b1 = (cnt0 + k - 1L) / k + val b2: Long + b2 = (mismatch + (n - k) - 1L) / (n - k) + var lb = max(b1, b2) + if (lb < 1) { + lb = 1 + } + if ((lb and 1L) != p.toLong()) { + lb++ + } + if (lb < best) { + best = lb + } + } + return if (best == Long.Companion.MAX_VALUE) -1 else best.toInt() + } +} diff --git a/src/main/kotlin/g3601_3700/s3666_minimum_operations_to_equalize_binary_string/readme.md b/src/main/kotlin/g3601_3700/s3666_minimum_operations_to_equalize_binary_string/readme.md new file mode 100644 index 00000000..cc5ab4bc --- /dev/null +++ b/src/main/kotlin/g3601_3700/s3666_minimum_operations_to_equalize_binary_string/readme.md @@ -0,0 +1,51 @@ +3666\. Minimum Operations to Equalize Binary String + +Hard + +You are given a binary string `s`, and an integer `k`. + +In one operation, you must choose **exactly** `k` **different** indices and **flip** each `'0'` to `'1'` and each `'1'` to `'0'`. + +Return the **minimum** number of operations required to make all characters in the string equal to `'1'`. If it is not possible, return -1. + +**Example 1:** + +**Input:** s = "110", k = 1 + +**Output:** 1 + +**Explanation:** + +* There is one `'0'` in `s`. +* Since `k = 1`, we can flip it directly in one operation. + +**Example 2:** + +**Input:** s = "0101", k = 3 + +**Output:** 2 + +**Explanation:** + +One optimal set of operations choosing `k = 3` indices in each operation is: + +* **Operation 1**: Flip indices `[0, 1, 3]`. `s` changes from `"0101"` to `"1000"`. +* **Operation 2**: Flip indices `[1, 2, 3]`. `s` changes from `"1000"` to `"1111"`. + +Thus, the minimum number of operations is 2. + +**Example 3:** + +**Input:** s = "101", k = 2 + +**Output:** \-1 + +**Explanation:** + +Since `k = 2` and `s` has only one `'0'`, it is impossible to flip exactly `k` indices to make all `'1'`. Hence, the answer is -1. + +**Constraints:** + +* 1 <= s.length <= 105 +* `s[i]` is either `'0'` or `'1'`. +* `1 <= k <= s.length` \ No newline at end of file diff --git a/src/main/kotlin/g3601_3700/s3668_restore_finishing_order/Solution.kt b/src/main/kotlin/g3601_3700/s3668_restore_finishing_order/Solution.kt new file mode 100644 index 00000000..7c416f79 --- /dev/null +++ b/src/main/kotlin/g3601_3700/s3668_restore_finishing_order/Solution.kt @@ -0,0 +1,20 @@ +package g3601_3700.s3668_restore_finishing_order + +// #Easy #Weekly_Contest_465 #2025_09_07_Time_2_ms_(94.29%)_Space_49.08_MB_(72.86%) + +class Solution { + fun recoverOrder(order: IntArray, friends: IntArray): IntArray { + val rs = IntArray(friends.size) + var index = 0 + for (k in order) { + for (friend in friends) { + if (k == friend) { + rs[index] = k + index++ + break + } + } + } + return rs + } +} diff --git a/src/main/kotlin/g3601_3700/s3668_restore_finishing_order/readme.md b/src/main/kotlin/g3601_3700/s3668_restore_finishing_order/readme.md new file mode 100644 index 00000000..04a121df --- /dev/null +++ b/src/main/kotlin/g3601_3700/s3668_restore_finishing_order/readme.md @@ -0,0 +1,38 @@ +3668\. Restore Finishing Order + +Easy + +You are given an integer array `order` of length `n` and an integer array `friends`. + +* `order` contains every integer from 1 to `n` **exactly once**, representing the IDs of the participants of a race in their **finishing** order. +* `friends` contains the IDs of your friends in the race **sorted** in strictly increasing order. Each ID in friends is guaranteed to appear in the `order` array. + +Return an array containing your friends' IDs in their **finishing** order. + +**Example 1:** + +**Input:** order = [3,1,2,5,4], friends = [1,3,4] + +**Output:** [3,1,4] + +**Explanation:** + +The finishing order is [**3**, **1**, 2, 5, **4**]. Therefore, the finishing order of your friends is `[3, 1, 4]`. + +**Example 2:** + +**Input:** order = [1,4,5,3,2], friends = [2,5] + +**Output:** [5,2] + +**Explanation:** + +The finishing order is [1, 4, **5**, 3, **2**]. Therefore, the finishing order of your friends is `[5, 2]`. + +**Constraints:** + +* `1 <= n == order.length <= 100` +* `order` contains every integer from 1 to `n` exactly once +* `1 <= friends.length <= min(8, n)` +* `1 <= friends[i] <= n` +* `friends` is strictly increasing \ No newline at end of file diff --git a/src/main/kotlin/g3601_3700/s3669_balanced_k_factor_decomposition/Solution.kt b/src/main/kotlin/g3601_3700/s3669_balanced_k_factor_decomposition/Solution.kt new file mode 100644 index 00000000..638d2dad --- /dev/null +++ b/src/main/kotlin/g3601_3700/s3669_balanced_k_factor_decomposition/Solution.kt @@ -0,0 +1,75 @@ +package g3601_3700.s3669_balanced_k_factor_decomposition + +// #Medium #Weekly_Contest_465 #2025_09_07_Time_30_ms_(85.71%)_Space_56.41_MB_(28.57%) + +import kotlin.math.max +import kotlin.math.min + +class Solution { + private var kGlobal = 0 + private var bestDiff = Int.Companion.MAX_VALUE + private var bestList: MutableList = ArrayList() + private val current: MutableList = ArrayList() + + fun minDifference(n: Int, k: Int): IntArray { + kGlobal = k + dfs(n, 1, 0) + val ans = IntArray(bestList.size) + for (i in bestList.indices) { + ans[i] = bestList[i] + } + return ans + } + + private fun dfs(rem: Int, start: Int, depth: Int) { + if (depth == kGlobal - 1) { + if (rem >= start) { + current.add(rem) + evaluate() + current.removeAt(current.size - 1) + } + return + } + val divs = getDivisors(rem) + for (d in divs) { + if (d < start) { + continue + } + current.add(d) + dfs(rem / d, d, depth + 1) + current.removeAt(current.size - 1) + } + } + + private fun evaluate() { + var mn = Int.Companion.MAX_VALUE + var mx = Int.Companion.MIN_VALUE + for (v in current) { + mn = min(mn, v) + mx = max(mx, v) + } + val diff = mx - mn + if (diff < bestDiff) { + bestDiff = diff + bestList = ArrayList(current) + } + } + + private fun getDivisors(x: Int): MutableList { + val small: MutableList = ArrayList() + val large: MutableList = ArrayList() + var i = 1 + while (i * i.toLong() <= x) { + if (x % i == 0) { + small.add(i) + if (i != x / i) { + large.add(x / i) + } + } + i++ + } + large.reverse() + small.addAll(large) + return small + } +} diff --git a/src/main/kotlin/g3601_3700/s3669_balanced_k_factor_decomposition/readme.md b/src/main/kotlin/g3601_3700/s3669_balanced_k_factor_decomposition/readme.md new file mode 100644 index 00000000..8123c6df --- /dev/null +++ b/src/main/kotlin/g3601_3700/s3669_balanced_k_factor_decomposition/readme.md @@ -0,0 +1,38 @@ +3669\. Balanced K-Factor Decomposition + +Medium + +Given two integers `n` and `k`, split the number `n` into exactly `k` positive integers such that the **product** of these integers is equal to `n`. + +Return _any_ _one_ split in which the **maximum** difference between any two numbers is **minimized**. You may return the result in _any order_. + +**Example 1:** + +**Input:** n = 100, k = 2 + +**Output:** [10,10] + +**Explanation:** + +The split `[10, 10]` yields `10 * 10 = 100` and a max-min difference of 0, which is minimal. + +**Example 2:** + +**Input:** n = 44, k = 3 + +**Output:** [2,2,11] + +**Explanation:** + +* Split `[1, 1, 44]` yields a difference of 43 +* Split `[1, 2, 22]` yields a difference of 21 +* Split `[1, 4, 11]` yields a difference of 10 +* Split `[2, 2, 11]` yields a difference of 9 + +Therefore, `[2, 2, 11]` is the optimal split with the smallest difference 9. + +**Constraints:** + +* 4 <= n <= 105 +* `2 <= k <= 5` +* `k` is strictly less than the total number of positive divisors of `n`. \ No newline at end of file diff --git a/src/main/kotlin/g3601_3700/s3670_maximum_product_of_two_integers_with_no_common_bits/Solution.kt b/src/main/kotlin/g3601_3700/s3670_maximum_product_of_two_integers_with_no_common_bits/Solution.kt new file mode 100644 index 00000000..3a612f1f --- /dev/null +++ b/src/main/kotlin/g3601_3700/s3670_maximum_product_of_two_integers_with_no_common_bits/Solution.kt @@ -0,0 +1,64 @@ +package g3601_3700.s3670_maximum_product_of_two_integers_with_no_common_bits + +// #Medium #Weekly_Contest_465 #2025_09_07_Time_113_ms_(88.89%)_Space_78.00_MB_(100.00%) + +class Solution { + fun maxProduct(nums: IntArray): Long { + // Find highest value to limit DP size + var maxVal = 0 + for (v in nums) { + if (v > maxVal) { + maxVal = v + } + } + // If all numbers are >=1, maxVal > 0; compute needed bit-width + // in [1..20] + val maxBits = 32 - Integer.numberOfLeadingZeros(maxVal) + val size = 1 shl maxBits + // ---- store input midway, as required ---- + // dp[mask] = largest number present whose bitmask == mask (later becomes: max over all + // submasks) + val dp = IntArray(size) + for (x in nums) { + // numbers themselves are their masks + if (dp[x] < x) { + dp[x] = x + } + } + // SOS DP: for each bit b, propagate lower-half block maxima to upper-half block + // (branch-light) + for (b in 0.. 0) { + val prod = x.toLong() * y + if (prod > ans) { + ans = prod + } + } + } + // 0 if no valid pair + return ans + } +} diff --git a/src/main/kotlin/g3601_3700/s3670_maximum_product_of_two_integers_with_no_common_bits/readme.md b/src/main/kotlin/g3601_3700/s3670_maximum_product_of_two_integers_with_no_common_bits/readme.md new file mode 100644 index 00000000..4caebe98 --- /dev/null +++ b/src/main/kotlin/g3601_3700/s3670_maximum_product_of_two_integers_with_no_common_bits/readme.md @@ -0,0 +1,44 @@ +3670\. Maximum Product of Two Integers With No Common Bits + +Medium + +You are given an integer array `nums`. + +Your task is to find two **distinct** indices `i` and `j` such that the product `nums[i] * nums[j]` is **maximized,** and the binary representations of `nums[i]` and `nums[j]` do not share any common set bits. + +Return the **maximum** possible product of such a pair. If no such pair exists, return 0. + +**Example 1:** + +**Input:** nums = [1,2,3,4,5,6,7] + +**Output:** 12 + +**Explanation:** + +The best pair is 3 (011) and 4 (100). They share no set bits and `3 * 4 = 12`. + +**Example 2:** + +**Input:** nums = [5,6,4] + +**Output:** 0 + +**Explanation:** + +Every pair of numbers has at least one common set bit. Hence, the answer is 0. + +**Example 3:** + +**Input:** nums = [64,8,32] + +**Output:** 2048 + +**Explanation:** + +No pair of numbers share a common bit, so the answer is the product of the two maximum elements, 64 and 32 (`64 * 32 = 2048`). + +**Constraints:** + +* 2 <= nums.length <= 105 +* 1 <= nums[i] <= 106 \ No newline at end of file diff --git a/src/main/kotlin/g3601_3700/s3671_sum_of_beautiful_subsequences/Solution.kt b/src/main/kotlin/g3601_3700/s3671_sum_of_beautiful_subsequences/Solution.kt new file mode 100644 index 00000000..04d794b6 --- /dev/null +++ b/src/main/kotlin/g3601_3700/s3671_sum_of_beautiful_subsequences/Solution.kt @@ -0,0 +1,114 @@ +package g3601_3700.s3671_sum_of_beautiful_subsequences + +// #Hard #Weekly_Contest_465 #2025_09_07_Time_225_ms_(100.00%)_Space_75.96_MB_(100.00%) + +import kotlin.math.sqrt + +class Solution { + fun totalBeauty(nums: IntArray): Int { + var maxV = 0 + for (v in nums) { + if (v > maxV) { + maxV = v + } + } + // index by g + val fenwicks = arrayOfNulls(maxV + 1) + // FDiv[g] = # inc subseq with all elements multiple of g + val fDiv = LongArray(maxV + 1) + // temp buffer for divisors (max divisors of any number <= ~128 for this constraint) + val divisors = IntArray(256) + // Left-to-right DP restricted to multiples of each divisor g + for (x in nums) { + var cnt = 0 + val r = sqrt(x.toDouble()).toInt() + for (d in 1..r) { + if (x % d == 0) { + divisors[cnt++] = d + val d2 = x / d + if (d2 != d) { + divisors[cnt++] = d2 + } + } + } + for (i in 0..= max index (maxV/g). Use +2 for safety and 1-based + // indexing. + fw = Fenwick(maxV / g + 2) + fenwicks[g] = fw + } + var dp = 1 + fw.query(idxQ - 1) + if (dp >= MOD) { + dp -= MOD.toLong() + } + fw.add(idxQ, dp) + fDiv[g] += dp + if (fDiv[g] >= MOD) { + fDiv[g] -= MOD.toLong() + } + } + } + // Inclusion–exclusion to get exact gcd counts + val exact = LongArray(maxV + 1) + for (g in maxV downTo 1) { + var s = fDiv[g] + var m = g + g + while (m <= maxV) { + s -= exact[m] + if (s < 0) { + s += MOD.toLong() + } + m += g + } + exact[g] = s + } + var ans: Long = 0 + for (g in 1..maxV) { + if (exact[g] != 0L) { + ans += exact[g] * g % MOD + if (ans >= MOD) { + ans -= MOD.toLong() + } + } + } + return ans.toInt() + } + + private class Fenwick(size: Int) { + private val tree: LongArray = LongArray(size) + + fun add(indexOneBased: Int, delta: Long) { + var i = indexOneBased + while (i < tree.size) { + var v = tree[i] + delta + if (v >= MOD) { + v -= MOD.toLong() + } + tree[i] = v + i += i and -i + } + } + + fun query(indexOneBased: Int): Long { + var sum: Long = 0 + var i = indexOneBased + while (i > 0) { + sum += tree[i] + if (sum >= MOD) { + sum -= MOD.toLong() + } + i -= i and -i + } + return sum + } + } + + companion object { + private const val MOD = 1000000007 + } +} diff --git a/src/main/kotlin/g3601_3700/s3671_sum_of_beautiful_subsequences/readme.md b/src/main/kotlin/g3601_3700/s3671_sum_of_beautiful_subsequences/readme.md new file mode 100644 index 00000000..8655b9d7 --- /dev/null +++ b/src/main/kotlin/g3601_3700/s3671_sum_of_beautiful_subsequences/readme.md @@ -0,0 +1,72 @@ +3671\. Sum of Beautiful Subsequences + +Hard + +You are given an integer array `nums` of length `n`. + +For every **positive** integer `g`, we define the **beauty** of `g` as the **product** of `g` and the number of **strictly increasing** **subsequences** of `nums` whose greatest common divisor (GCD) is exactly `g`. + +Return the **sum** of **beauty** values for all positive integers `g`. + +Since the answer could be very large, return it modulo 109 + 7. + +**Example 1:** + +**Input:** nums = [1,2,3] + +**Output:** 10 + +**Explanation:** + +All strictly increasing subsequences and their GCDs are: + +| Subsequence | GCD | +|-------------|-----| +| [1] | 1 | +| [2] | 2 | +| [3] | 3 | +| [1,2] | 1 | +| [1,3] | 1 | +| [2,3] | 1 | +| [1,2,3] | 1 | + +Calculating beauty for each GCD: + +| GCD | Count of subsequences | Beauty (GCD × Count) | +|-----|------------------------|----------------------| +| 1 | 5 | 1 × 5 = 5 | +| 2 | 1 | 2 × 1 = 2 | +| 3 | 1 | 3 × 1 = 3 | + +Total beauty is `5 + 2 + 3 = 10`. + +**Example 2:** + +**Input:** nums = [4,6] + +**Output:** 12 + +**Explanation:** + +All strictly increasing subsequences and their GCDs are: + +| Subsequence | GCD | +|-------------|-----| +| [4] | 4 | +| [6] | 6 | +| [4,6] | 2 | + +Calculating beauty for each GCD: + +| GCD | Count of subsequences | Beauty (GCD × Count) | +|-----|------------------------|----------------------| +| 2 | 1 | 2 × 1 = 2 | +| 4 | 1 | 4 × 1 = 4 | +| 6 | 1 | 6 × 1 = 6 | + +Total beauty is `2 + 4 + 6 = 12`. + +**Constraints:** + +* 1 <= n == nums.length <= 104 +* 1 <= nums[i] <= 7 * 104 \ No newline at end of file diff --git a/src/test/kotlin/g3601_3700/s3663_find_the_least_frequent_digit/SolutionTest.kt b/src/test/kotlin/g3601_3700/s3663_find_the_least_frequent_digit/SolutionTest.kt new file mode 100644 index 00000000..aa071f7f --- /dev/null +++ b/src/test/kotlin/g3601_3700/s3663_find_the_least_frequent_digit/SolutionTest.kt @@ -0,0 +1,17 @@ +package g3601_3700.s3663_find_the_least_frequent_digit + +import org.hamcrest.CoreMatchers.equalTo +import org.hamcrest.MatcherAssert.assertThat +import org.junit.jupiter.api.Test + +internal class SolutionTest { + @Test + fun getLeastFrequentDigit() { + assertThat(Solution().getLeastFrequentDigit(1553322), equalTo(1)) + } + + @Test + fun getLeastFrequentDigit2() { + assertThat(Solution().getLeastFrequentDigit(723344511), equalTo(2)) + } +} diff --git a/src/test/kotlin/g3601_3700/s3664_two_letter_card_game/SolutionTest.kt b/src/test/kotlin/g3601_3700/s3664_two_letter_card_game/SolutionTest.kt new file mode 100644 index 00000000..da84639f --- /dev/null +++ b/src/test/kotlin/g3601_3700/s3664_two_letter_card_game/SolutionTest.kt @@ -0,0 +1,31 @@ +package g3601_3700.s3664_two_letter_card_game + +import org.hamcrest.CoreMatchers.equalTo +import org.hamcrest.MatcherAssert.assertThat +import org.junit.jupiter.api.Test + +internal class SolutionTest { + @Test + fun score() { + assertThat( + Solution().score(arrayOf("aa", "ab", "ba", "ac"), 'a'), + equalTo(2), + ) + } + + @Test + fun score2() { + assertThat( + Solution().score(arrayOf("aa", "ab", "ba"), 'a'), + equalTo(1), + ) + } + + @Test + fun score3() { + assertThat( + Solution().score(arrayOf("aa", "ab", "ba", "ac"), 'b'), + equalTo(0), + ) + } +} diff --git a/src/test/kotlin/g3601_3700/s3665_twisted_mirror_path_count/SolutionTest.kt b/src/test/kotlin/g3601_3700/s3665_twisted_mirror_path_count/SolutionTest.kt new file mode 100644 index 00000000..257b0e24 --- /dev/null +++ b/src/test/kotlin/g3601_3700/s3665_twisted_mirror_path_count/SolutionTest.kt @@ -0,0 +1,36 @@ +package g3601_3700.s3665_twisted_mirror_path_count + +import org.hamcrest.CoreMatchers.equalTo +import org.hamcrest.MatcherAssert.assertThat +import org.junit.jupiter.api.Test + +internal class SolutionTest { + @Test + fun uniquePaths() { + assertThat( + Solution().uniquePaths(arrayOf(intArrayOf(0, 1, 0), intArrayOf(0, 0, 1), intArrayOf(1, 0, 0))), + equalTo(5), + ) + } + + @Test + fun uniquePaths2() { + assertThat( + Solution().uniquePaths(arrayOf(intArrayOf(0, 0), intArrayOf(0, 0))), + equalTo(2), + ) + } + + @Test + fun uniquePaths3() { + assertThat( + Solution().uniquePaths( + arrayOf( + intArrayOf(0, 1, 1), + intArrayOf(1, 1, 0), + ), + ), + equalTo(1), + ) + } +} diff --git a/src/test/kotlin/g3601_3700/s3666_minimum_operations_to_equalize_binary_string/SolutionTest.kt b/src/test/kotlin/g3601_3700/s3666_minimum_operations_to_equalize_binary_string/SolutionTest.kt new file mode 100644 index 00000000..2024f760 --- /dev/null +++ b/src/test/kotlin/g3601_3700/s3666_minimum_operations_to_equalize_binary_string/SolutionTest.kt @@ -0,0 +1,82 @@ +package g3601_3700.s3666_minimum_operations_to_equalize_binary_string + +import org.hamcrest.CoreMatchers.equalTo +import org.hamcrest.MatcherAssert.assertThat +import org.junit.jupiter.api.Test + +internal class SolutionTest { + @Test + fun minOperations() { + assertThat(Solution().minOperations("110", 1), equalTo(1)) + } + + @Test + fun minOperations2() { + assertThat(Solution().minOperations("0101", 3), equalTo(2)) + } + + @Test + fun minOperations3() { + assertThat(Solution().minOperations("101", 2), equalTo(-1)) + } + + @Test + fun minOperations4() { + val k = 3 + assertThat(Solution().minOperations("111111", k), equalTo(0)) + } + + @Test + fun minOperations5() { + val k = 6 + assertThat(Solution().minOperations("000000", k), equalTo(1)) + } + + @Test + fun minOperations6() { + val k = 6 + assertThat(Solution().minOperations("000111", k), equalTo(-1)) + } + + @Test + fun minOperations7() { + val k = 3 + assertThat(Solution().minOperations("0011", k), equalTo(2)) + } + + @Test + fun minOperations8() { + val k = 4 + assertThat(Solution().minOperations("000011", k), equalTo(1)) + } + + @Test + fun minOperations9() { + val k = 2 + assertThat(Solution().minOperations("000111", k), equalTo(-1)) + } + + @Test + fun minOperations10() { + val k = 4 + assertThat(Solution().minOperations("001100", k), equalTo(1)) + } + + @Test + fun minOperations11() { + val k = 3 + assertThat(Solution().minOperations("000100", k), equalTo(3)) + } + + @Test + fun minOperations12() { + val k = 4 + assertThat(Solution().minOperations("111111", k), equalTo(0)) + } + + @Test + fun minOperations13() { + val k = 4 + assertThat(Solution().minOperations("001001", k), equalTo(1)) + } +} diff --git a/src/test/kotlin/g3601_3700/s3668_restore_finishing_order/SolutionTest.kt b/src/test/kotlin/g3601_3700/s3668_restore_finishing_order/SolutionTest.kt new file mode 100644 index 00000000..ce556f25 --- /dev/null +++ b/src/test/kotlin/g3601_3700/s3668_restore_finishing_order/SolutionTest.kt @@ -0,0 +1,23 @@ +package g3601_3700.s3668_restore_finishing_order + +import org.hamcrest.CoreMatchers.equalTo +import org.hamcrest.MatcherAssert.assertThat +import org.junit.jupiter.api.Test + +internal class SolutionTest { + @Test + fun recoverOrder() { + assertThat( + Solution().recoverOrder(intArrayOf(3, 1, 2, 5, 4), intArrayOf(1, 3, 4)), + equalTo(intArrayOf(3, 1, 4)), + ) + } + + @Test + fun recoverOrder2() { + assertThat( + Solution().recoverOrder(intArrayOf(1, 4, 5, 3, 2), intArrayOf(2, 5)), + equalTo(intArrayOf(5, 2)), + ) + } +} diff --git a/src/test/kotlin/g3601_3700/s3669_balanced_k_factor_decomposition/SolutionTest.kt b/src/test/kotlin/g3601_3700/s3669_balanced_k_factor_decomposition/SolutionTest.kt new file mode 100644 index 00000000..6d1f4ae3 --- /dev/null +++ b/src/test/kotlin/g3601_3700/s3669_balanced_k_factor_decomposition/SolutionTest.kt @@ -0,0 +1,23 @@ +package g3601_3700.s3669_balanced_k_factor_decomposition + +import org.hamcrest.CoreMatchers.equalTo +import org.hamcrest.MatcherAssert.assertThat +import org.junit.jupiter.api.Test + +internal class SolutionTest { + @Test + fun minDifference() { + assertThat( + Solution().minDifference(100, 2), + equalTo(intArrayOf(10, 10)), + ) + } + + @Test + fun minDifference2() { + assertThat( + Solution().minDifference(44, 3), + equalTo(intArrayOf(2, 2, 11)), + ) + } +} diff --git a/src/test/kotlin/g3601_3700/s3670_maximum_product_of_two_integers_with_no_common_bits/SolutionTest.kt b/src/test/kotlin/g3601_3700/s3670_maximum_product_of_two_integers_with_no_common_bits/SolutionTest.kt new file mode 100644 index 00000000..fc874e5d --- /dev/null +++ b/src/test/kotlin/g3601_3700/s3670_maximum_product_of_two_integers_with_no_common_bits/SolutionTest.kt @@ -0,0 +1,28 @@ +package g3601_3700.s3670_maximum_product_of_two_integers_with_no_common_bits + +import org.hamcrest.CoreMatchers.equalTo +import org.hamcrest.MatcherAssert.assertThat +import org.junit.jupiter.api.Test + +internal class SolutionTest { + @Test + fun maxProduct() { + assertThat( + Solution().maxProduct(intArrayOf(1, 2, 3, 4, 5, 6, 7)), + equalTo(12L), + ) + } + + @Test + fun maxProduct2() { + assertThat(Solution().maxProduct(intArrayOf(4, 5, 6)), equalTo(0L)) + } + + @Test + fun maxProduct3() { + assertThat( + Solution().maxProduct(intArrayOf(64, 8, 32)), + equalTo(2048L), + ) + } +} diff --git a/src/test/kotlin/g3601_3700/s3671_sum_of_beautiful_subsequences/SolutionTest.kt b/src/test/kotlin/g3601_3700/s3671_sum_of_beautiful_subsequences/SolutionTest.kt new file mode 100644 index 00000000..abdfd544 --- /dev/null +++ b/src/test/kotlin/g3601_3700/s3671_sum_of_beautiful_subsequences/SolutionTest.kt @@ -0,0 +1,17 @@ +package g3601_3700.s3671_sum_of_beautiful_subsequences + +import org.hamcrest.CoreMatchers.equalTo +import org.hamcrest.MatcherAssert.assertThat +import org.junit.jupiter.api.Test + +internal class SolutionTest { + @Test + fun totalBeauty() { + assertThat(Solution().totalBeauty(intArrayOf(1, 2, 3)), equalTo(10)) + } + + @Test + fun totalBeauty2() { + assertThat(Solution().totalBeauty(intArrayOf(4, 6)), equalTo(12)) + } +} From 55cd045e0d423e7e25cc92653154499084c35715 Mon Sep 17 00:00:00 2001 From: Valentyn Kolesnikov Date: Sun, 7 Sep 2025 11:25:49 +0300 Subject: [PATCH 2/2] Updated readme --- README.md | 292 +++++++++++++++++++++++++++--------------------------- 1 file changed, 146 insertions(+), 146 deletions(-) diff --git a/README.md b/README.md index 490bb35f..56e26ad9 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,6 @@ implementation 'com.github.javadev:leetcode-in-kotlin:1.40' > ["For coding interview preparation, LeetCode is one of the best online resource providing a rich library of more than 300 real coding interview questions for you to practice from using one of the 7 supported languages - C, C++, Java, Python, C#, JavaScript, Ruby."](https://www.quora.com/How-effective-is-Leetcode-for-preparing-for-technical-interviews) ## -* [Programming Skills II](#programming-skills-ii) * [Graph Theory I](#graph-theory-i) * [SQL I](#sql-i) * [Level 1](#level-1) @@ -49,149 +48,7 @@ implementation 'com.github.javadev:leetcode-in-kotlin:1.40' * [Binary Search II](#binary-search-ii) * [Dynamic Programming I](#dynamic-programming-i) * [Programming Skills I](#programming-skills-i) - -### Programming Skills II - -#### Day 1 - -| | | | | | -|-|-|-|-|-|- -| 0896 |[Monotonic Array](src/main/kotlin/g0801_0900/s0896_monotonic_array/Solution.kt)| Easy | Array | 576 | 90.91 -| 0028 |[Find the Index of the First Occurrence in a String](src/main/kotlin/g0001_0100/s0028_find_the_index_of_the_first_occurrence_in_a_string/Solution.kt)| Easy | Top_Interview_Questions, String, Two_Pointers, String_Matching | 126 | 97.58 - -#### Day 2 - -| | | | | | -|-|-|-|-|-|- -| 0110 |[Balanced Binary Tree](src/main/kotlin/g0101_0200/s0110_balanced_binary_tree/Solution.kt)| Easy | Depth_First_Search, Tree, Binary_Tree | 182 | 71.30 -| 0459 |[Repeated Substring Pattern](src/main/kotlin/g0401_0500/s0459_repeated_substring_pattern/Solution.kt)| Easy | String, String_Matching | 201 | 100.00 - -#### Day 3 - -| | | | | | -|-|-|-|-|-|- -| 0150 |[Evaluate Reverse Polish Notation](src/main/kotlin/g0101_0200/s0150_evaluate_reverse_polish_notation/Solution.kt)| Medium | Top_Interview_Questions, Array, Math, Stack | 233 | 88.82 -| 0066 |[Plus One](src/main/kotlin/g0001_0100/s0066_plus_one/Solution.kt)| Easy | Top_Interview_Questions, Array, Math | 148 | 98.75 - -#### Day 4 - -| | | | | | -|-|-|-|-|-|- -| 1367 |[Linked List in Binary Tree](src/main/kotlin/g1301_1400/s1367_linked_list_in_binary_tree/Solution.kt)| Medium | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Linked_List | 237 | 92.86 -| 0043 |[Multiply Strings](src/main/kotlin/g0001_0100/s0043_multiply_strings/Solution.kt)| Medium | String, Math, Simulation | 165 | 96.72 - -#### Day 5 - -| | | | | | -|-|-|-|-|-|- -| 0067 |[Add Binary](src/main/kotlin/g0001_0100/s0067_add_binary/Solution.kt)| Easy | String, Math, Bit_Manipulation, Simulation | 164 | 90.60 -| 0989 |[Add to Array-Form of Integer](src/main/kotlin/g0901_1000/s0989_add_to_array_form_of_integer/Solution.kt)| Easy | Array, Math | 350 | 70.00 - -#### Day 6 - -| | | | | | -|-|-|-|-|-|- -| 0739 |[Daily Temperatures](src/main/kotlin/g0701_0800/s0739_daily_temperatures/Solution.kt)| Medium | Top_100_Liked_Questions, Array, Stack, Monotonic_Stack, LeetCode_75_Monotonic_Stack, Big_O_Time_O(n)_Space_O(n) | 936 | 80.54 -| 0058 |[Length of Last Word](src/main/kotlin/g0001_0100/s0058_length_of_last_word/Solution.kt)| Easy | String | 135 | 93.67 - -#### Day 7 - -| | | | | | -|-|-|-|-|-|- -| 0048 |[Rotate Image](src/main/kotlin/g0001_0100/s0048_rotate_image/Solution.kt)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Matrix, Big_O_Time_O(n^2)_Space_O(1) | 160 | 90.11 -| 1886 |[Determine Whether Matrix Can Be Obtained By Rotation](src/main/kotlin/g1801_1900/s1886_determine_whether_matrix_can_be_obtained_by_rotation/Solution.kt)| Easy | Array, Matrix | 147 | 85.71 - -#### Day 8 - -| | | | | | -|-|-|-|-|-|- -| 0054 |[Spiral Matrix](src/main/kotlin/g0001_0100/s0054_spiral_matrix/Solution.kt)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Matrix, Simulation | 132 | 95.12 -| 0973 |[K Closest Points to Origin](src/main/kotlin/g0901_1000/s0973_k_closest_points_to_origin/Solution.kt)| Medium | Array, Math, Sorting, Heap_Priority_Queue, Divide_and_Conquer, Geometry, Quickselect | 800 | 37.89 - -#### Day 9 - -| | | | | | -|-|-|-|-|-|- -| 1630 |[Arithmetic Subarrays](src/main/kotlin/g1601_1700/s1630_arithmetic_subarrays/Solution.kt)| Medium | Array, Sorting | 264 | 100.00 -| 0429 |[N-ary Tree Level Order Traversal](src/main/kotlin/g0401_0500/s0429_n_ary_tree_level_order_traversal/Solution.kt)| Medium | Breadth_First_Search, Tree | 248 | 75.86 - -#### Day 10 - -| | | | | | -|-|-|-|-|-|- -| 0503 |[Next Greater Element II](src/main/kotlin/g0501_0600/s0503_next_greater_element_ii/Solution.kt)| Medium | Array, Stack, Monotonic_Stack | 331 | 92.68 -| 0556 |[Next Greater Element III](src/main/kotlin/g0501_0600/s0556_next_greater_element_iii/Solution.kt)| Medium | String, Math, Two_Pointers | 137 | 80.00 - -#### Day 11 - -| | | | | | -|-|-|-|-|-|- -| 1376 |[Time Needed to Inform All Employees](src/main/kotlin/g1301_1400/s1376_time_needed_to_inform_all_employees/Solution.kt)| Medium | Depth_First_Search, Breadth_First_Search, Tree | 915 | 37.62 -| 0049 |[Group Anagrams](src/main/kotlin/g0001_0100/s0049_group_anagrams/Solution.kt)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, String, Hash_Table, Sorting, Big_O_Time_O(n\*k_log_k)_Space_O(n) | 308 | 96.34 - -#### Day 12 - -| | | | | | -|-|-|-|-|-|- -| 0438 |[Find All Anagrams in a String](src/main/kotlin/g0401_0500/s0438_find_all_anagrams_in_a_string/Solution.kt)| Medium | Top_100_Liked_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n+m)_Space_O(1) | 561 | 54.68 -| 0713 |[Subarray Product Less Than K](src/main/kotlin/g0701_0800/s0713_subarray_product_less_than_k/Solution.kt)| Medium | Array, Sliding_Window | 336 | 92.11 - -#### Day 13 - -| | | | | | -|-|-|-|-|-|- -| 0304 |[Range Sum Query 2D - Immutable](src/main/kotlin/g0301_0400/s0304_range_sum_query_2d_immutable/NumMatrix.kt)| Medium | Array, Matrix, Design, Prefix_Sum | 1373 | 85.71 -| 0910 |[Smallest Range II](src/main/kotlin/g0901_1000/s0910_smallest_range_ii/Solution.kt)| Medium | Array, Math, Sorting, Greedy | 234 | 100.00 - -#### Day 14 - -| | | | | | -|-|-|-|-|-|- -| 0143 |[Reorder List](src/main/kotlin/g0101_0200/s0143_reorder_list/Solution.kt)| Medium | Two_Pointers, Stack, Linked_List, Recursion | 395 | 82.26 -| 0138 |[Copy List with Random Pointer](src/main/kotlin/g0101_0200/s0138_copy_list_with_random_pointer/Solution.kt)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Linked_List, Big_O_Time_O(N)_Space_O(N) | 123 | 90.70 - -#### Day 15 - -| | | | | | -|-|-|-|-|-|- -| 0002 |[Add Two Numbers](src/main/kotlin/g0001_0100/s0002_add_two_numbers/Solution.kt)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Math, Linked_List, Recursion, Big_O_Time_O(max(N,M))_Space_O(max(N,M)), AI_can_be_used_to_solve_the_task | 2 | 87.63 -| 0445 |[Add Two Numbers II](src/main/kotlin/g0401_0500/s0445_add_two_numbers_ii/Solution.kt)| Medium | Math, Stack, Linked_List | 240 | 82.61 - -#### Day 16 - -| | | | | | -|-|-|-|-|-|- -| 0061 |[Rotate List](src/main/kotlin/g0001_0100/s0061_rotate_list/Solution.kt)| Medium | Two_Pointers, Linked_List | 160 | 92.22 -| 0173 |[Binary Search Tree Iterator](src/main/kotlin/g0101_0200/s0173_binary_search_tree_iterator/BSTIterator.kt)| Medium | Tree, Binary_Tree, Stack, Design, Binary_Search_Tree, Iterator | 563 | 46.91 - -#### Day 17 - -| | | | | | -|-|-|-|-|-|- -| 1845 |[Seat Reservation Manager](src/main/kotlin/g1801_1900/s1845_seat_reservation_manager/SeatManager.kt)| Medium | Design, Heap_Priority_Queue | 834 | 100.00 -| 0860 |[Lemonade Change](src/main/kotlin/g0801_0900/s0860_lemonade_change/Solution.kt)| Easy | Array, Greedy | 413 | 86.96 - -#### Day 18 - -| | | | | | -|-|-|-|-|-|- -| 0155 |[Min Stack](src/main/kotlin/g0101_0200/s0155_min_stack/MinStack.kt)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Stack, Design, Big_O_Time_O(1)_Space_O(N) | 331 | 84.88 -| 0341 |[Flatten Nested List Iterator](src/main/kotlin/g0301_0400/s0341_flatten_nested_list_iterator/NestedIterator.kt)| Medium | Depth_First_Search, Tree, Stack, Design, Queue, Iterator | 210 | 100.00 - -#### Day 19 - -| | | | | | -|-|-|-|-|-|- -| 1797 |[Design Authentication Manager](src/main/kotlin/g1701_1800/s1797_design_authentication_manager/AuthenticationManager.kt)| Medium | Hash_Table, Design | 334 | 100.00 -| 0707 |[Design Linked List](src/main/kotlin/g0701_0800/s0707_design_linked_list/MyLinkedList.kt)| Medium | Design, Linked_List | 243 | 100.00 - -#### Day 20 - -| | | | | | -|-|-|-|-|-|- -| 0380 |[Insert Delete GetRandom O(1)](src/main/kotlin/g0301_0400/s0380_insert_delete_getrandom_o1/RandomizedSet.kt)| Medium | Array, Hash_Table, Math, Design, Randomized | 1326 | 68.23 -| 0622 |[Design Circular Queue](src/main/kotlin/g0601_0700/s0622_design_circular_queue/MyCircularQueue.kt)| Medium | Array, Design, Linked_List, Queue | 234 | 92.68 -| 0729 |[My Calendar I](src/main/kotlin/g0701_0800/s0729_my_calendar_i/MyCalendar.kt)| Medium | Binary_Search, Design, Ordered_Set, Segment_Tree | 378 | 69.70 +* [Programming Skills II](#programming-skills-ii) ### Graph Theory I @@ -797,7 +654,7 @@ implementation 'com.github.javadev:leetcode-in-kotlin:1.40' | | | | | | |-|-|-|-|-|- | 0200 |[Number of Islands](src/main/kotlin/g0101_0200/s0200_number_of_islands/Solution.kt)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find, Big_O_Time_O(M\*N)_Space_O(M\*N) | 252 | 95.41 -| 0133 |[Clone Graph](src/main/kotlin/g0101_0200/s0133_clone_graph/Solution.kt)| Medium | Hash_Table, Depth_First_Search, Breadth_First_Search, Graph | 351 | 60.91 +| 0133 |[Clone Graph](src/main/kotlin/g0101_0200/s0133_clone_graph/Solution.kt)| Medium | Hash_Table, Depth_First_Search, Breadth_First_Search, Graph | 133 | 88.96 | 0417 |[Pacific Atlantic Water Flow](src/main/kotlin/g0401_0500/s0417_pacific_atlantic_water_flow/Solution.kt)| Medium | Array, Depth_First_Search, Breadth_First_Search, Matrix | 319 | 100.00 #### Udemy Dynamic Programming @@ -1001,7 +858,7 @@ implementation 'com.github.javadev:leetcode-in-kotlin:1.40' |-|-|-|-|-|- | 0200 |[Number of Islands](src/main/kotlin/g0101_0200/s0200_number_of_islands/Solution.kt)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find, Big_O_Time_O(M\*N)_Space_O(M\*N) | 252 | 95.41 | 0130 |[Surrounded Regions](src/main/kotlin/g0101_0200/s0130_surrounded_regions/Solution.kt)| Medium | Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find | 355 | 84.42 -| 0133 |[Clone Graph](src/main/kotlin/g0101_0200/s0133_clone_graph/Solution.kt)| Medium | Hash_Table, Depth_First_Search, Breadth_First_Search, Graph | 351 | 60.91 +| 0133 |[Clone Graph](src/main/kotlin/g0101_0200/s0133_clone_graph/Solution.kt)| Medium | Hash_Table, Depth_First_Search, Breadth_First_Search, Graph | 133 | 88.96 | 0399 |[Evaluate Division](src/main/kotlin/g0301_0400/s0399_evaluate_division/Solution.kt)| Medium | Array, Depth_First_Search, Breadth_First_Search, Graph, Union_Find, Shortest_Path, LeetCode_75_Graphs/DFS | 183 | 91.49 | 0207 |[Course Schedule](src/main/kotlin/g0201_0300/s0207_course_schedule/Solution.kt)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Graph, Topological_Sort, Big_O_Time_O(N)_Space_O(N) | 183 | 92.07 | 0210 |[Course Schedule II](src/main/kotlin/g0201_0300/s0210_course_schedule_ii/Solution.kt)| Medium | Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Graph, Topological_Sort | 266 | 96.32 @@ -2112,6 +1969,149 @@ implementation 'com.github.javadev:leetcode-in-kotlin:1.40' | 1603 |[Design Parking System](src/main/kotlin/g1601_1700/s1603_design_parking_system/ParkingSystem.kt)| Easy | Design, Simulation, Counting | 376 | 31.83 | 0303 |[Range Sum Query - Immutable](src/main/kotlin/g0301_0400/s0303_range_sum_query_immutable/NumArray.kt)| Easy | Array, Design, Prefix_Sum | 472 | 63.64 +### Programming Skills II + +#### Day 1 + +| | | | | | +|-|-|-|-|-|- +| 0896 |[Monotonic Array](src/main/kotlin/g0801_0900/s0896_monotonic_array/Solution.kt)| Easy | Array | 576 | 90.91 +| 0028 |[Find the Index of the First Occurrence in a String](src/main/kotlin/g0001_0100/s0028_find_the_index_of_the_first_occurrence_in_a_string/Solution.kt)| Easy | Top_Interview_Questions, String, Two_Pointers, String_Matching | 126 | 97.58 + +#### Day 2 + +| | | | | | +|-|-|-|-|-|- +| 0110 |[Balanced Binary Tree](src/main/kotlin/g0101_0200/s0110_balanced_binary_tree/Solution.kt)| Easy | Depth_First_Search, Tree, Binary_Tree | 182 | 71.30 +| 0459 |[Repeated Substring Pattern](src/main/kotlin/g0401_0500/s0459_repeated_substring_pattern/Solution.kt)| Easy | String, String_Matching | 201 | 100.00 + +#### Day 3 + +| | | | | | +|-|-|-|-|-|- +| 0150 |[Evaluate Reverse Polish Notation](src/main/kotlin/g0101_0200/s0150_evaluate_reverse_polish_notation/Solution.kt)| Medium | Top_Interview_Questions, Array, Math, Stack | 233 | 88.82 +| 0066 |[Plus One](src/main/kotlin/g0001_0100/s0066_plus_one/Solution.kt)| Easy | Top_Interview_Questions, Array, Math | 148 | 98.75 + +#### Day 4 + +| | | | | | +|-|-|-|-|-|- +| 1367 |[Linked List in Binary Tree](src/main/kotlin/g1301_1400/s1367_linked_list_in_binary_tree/Solution.kt)| Medium | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Linked_List | 237 | 92.86 +| 0043 |[Multiply Strings](src/main/kotlin/g0001_0100/s0043_multiply_strings/Solution.kt)| Medium | String, Math, Simulation | 165 | 96.72 + +#### Day 5 + +| | | | | | +|-|-|-|-|-|- +| 0067 |[Add Binary](src/main/kotlin/g0001_0100/s0067_add_binary/Solution.kt)| Easy | String, Math, Bit_Manipulation, Simulation | 164 | 90.60 +| 0989 |[Add to Array-Form of Integer](src/main/kotlin/g0901_1000/s0989_add_to_array_form_of_integer/Solution.kt)| Easy | Array, Math | 350 | 70.00 + +#### Day 6 + +| | | | | | +|-|-|-|-|-|- +| 0739 |[Daily Temperatures](src/main/kotlin/g0701_0800/s0739_daily_temperatures/Solution.kt)| Medium | Top_100_Liked_Questions, Array, Stack, Monotonic_Stack, LeetCode_75_Monotonic_Stack, Big_O_Time_O(n)_Space_O(n) | 936 | 80.54 +| 0058 |[Length of Last Word](src/main/kotlin/g0001_0100/s0058_length_of_last_word/Solution.kt)| Easy | String | 135 | 93.67 + +#### Day 7 + +| | | | | | +|-|-|-|-|-|- +| 0048 |[Rotate Image](src/main/kotlin/g0001_0100/s0048_rotate_image/Solution.kt)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Matrix, Big_O_Time_O(n^2)_Space_O(1) | 160 | 90.11 +| 1886 |[Determine Whether Matrix Can Be Obtained By Rotation](src/main/kotlin/g1801_1900/s1886_determine_whether_matrix_can_be_obtained_by_rotation/Solution.kt)| Easy | Array, Matrix | 147 | 85.71 + +#### Day 8 + +| | | | | | +|-|-|-|-|-|- +| 0054 |[Spiral Matrix](src/main/kotlin/g0001_0100/s0054_spiral_matrix/Solution.kt)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Matrix, Simulation | 132 | 95.12 +| 0973 |[K Closest Points to Origin](src/main/kotlin/g0901_1000/s0973_k_closest_points_to_origin/Solution.kt)| Medium | Array, Math, Sorting, Heap_Priority_Queue, Divide_and_Conquer, Geometry, Quickselect | 800 | 37.89 + +#### Day 9 + +| | | | | | +|-|-|-|-|-|- +| 1630 |[Arithmetic Subarrays](src/main/kotlin/g1601_1700/s1630_arithmetic_subarrays/Solution.kt)| Medium | Array, Sorting | 264 | 100.00 +| 0429 |[N-ary Tree Level Order Traversal](src/main/kotlin/g0401_0500/s0429_n_ary_tree_level_order_traversal/Solution.kt)| Medium | Breadth_First_Search, Tree | 248 | 75.86 + +#### Day 10 + +| | | | | | +|-|-|-|-|-|- +| 0503 |[Next Greater Element II](src/main/kotlin/g0501_0600/s0503_next_greater_element_ii/Solution.kt)| Medium | Array, Stack, Monotonic_Stack | 331 | 92.68 +| 0556 |[Next Greater Element III](src/main/kotlin/g0501_0600/s0556_next_greater_element_iii/Solution.kt)| Medium | String, Math, Two_Pointers | 137 | 80.00 + +#### Day 11 + +| | | | | | +|-|-|-|-|-|- +| 1376 |[Time Needed to Inform All Employees](src/main/kotlin/g1301_1400/s1376_time_needed_to_inform_all_employees/Solution.kt)| Medium | Depth_First_Search, Breadth_First_Search, Tree | 915 | 37.62 +| 0049 |[Group Anagrams](src/main/kotlin/g0001_0100/s0049_group_anagrams/Solution.kt)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, String, Hash_Table, Sorting, Big_O_Time_O(n\*k_log_k)_Space_O(n) | 308 | 96.34 + +#### Day 12 + +| | | | | | +|-|-|-|-|-|- +| 0438 |[Find All Anagrams in a String](src/main/kotlin/g0401_0500/s0438_find_all_anagrams_in_a_string/Solution.kt)| Medium | Top_100_Liked_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n+m)_Space_O(1) | 561 | 54.68 +| 0713 |[Subarray Product Less Than K](src/main/kotlin/g0701_0800/s0713_subarray_product_less_than_k/Solution.kt)| Medium | Array, Sliding_Window | 336 | 92.11 + +#### Day 13 + +| | | | | | +|-|-|-|-|-|- +| 0304 |[Range Sum Query 2D - Immutable](src/main/kotlin/g0301_0400/s0304_range_sum_query_2d_immutable/NumMatrix.kt)| Medium | Array, Matrix, Design, Prefix_Sum | 1373 | 85.71 +| 0910 |[Smallest Range II](src/main/kotlin/g0901_1000/s0910_smallest_range_ii/Solution.kt)| Medium | Array, Math, Sorting, Greedy | 234 | 100.00 + +#### Day 14 + +| | | | | | +|-|-|-|-|-|- +| 0143 |[Reorder List](src/main/kotlin/g0101_0200/s0143_reorder_list/Solution.kt)| Medium | Two_Pointers, Stack, Linked_List, Recursion | 395 | 82.26 +| 0138 |[Copy List with Random Pointer](src/main/kotlin/g0101_0200/s0138_copy_list_with_random_pointer/Solution.kt)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Linked_List, Big_O_Time_O(N)_Space_O(N) | 123 | 90.70 + +#### Day 15 + +| | | | | | +|-|-|-|-|-|- +| 0002 |[Add Two Numbers](src/main/kotlin/g0001_0100/s0002_add_two_numbers/Solution.kt)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Math, Linked_List, Recursion, Big_O_Time_O(max(N,M))_Space_O(max(N,M)), AI_can_be_used_to_solve_the_task | 2 | 87.63 +| 0445 |[Add Two Numbers II](src/main/kotlin/g0401_0500/s0445_add_two_numbers_ii/Solution.kt)| Medium | Math, Stack, Linked_List | 240 | 82.61 + +#### Day 16 + +| | | | | | +|-|-|-|-|-|- +| 0061 |[Rotate List](src/main/kotlin/g0001_0100/s0061_rotate_list/Solution.kt)| Medium | Two_Pointers, Linked_List | 160 | 92.22 +| 0173 |[Binary Search Tree Iterator](src/main/kotlin/g0101_0200/s0173_binary_search_tree_iterator/BSTIterator.kt)| Medium | Tree, Binary_Tree, Stack, Design, Binary_Search_Tree, Iterator | 563 | 46.91 + +#### Day 17 + +| | | | | | +|-|-|-|-|-|- +| 1845 |[Seat Reservation Manager](src/main/kotlin/g1801_1900/s1845_seat_reservation_manager/SeatManager.kt)| Medium | Design, Heap_Priority_Queue | 834 | 100.00 +| 0860 |[Lemonade Change](src/main/kotlin/g0801_0900/s0860_lemonade_change/Solution.kt)| Easy | Array, Greedy | 413 | 86.96 + +#### Day 18 + +| | | | | | +|-|-|-|-|-|- +| 0155 |[Min Stack](src/main/kotlin/g0101_0200/s0155_min_stack/MinStack.kt)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Stack, Design, Big_O_Time_O(1)_Space_O(N) | 331 | 84.88 +| 0341 |[Flatten Nested List Iterator](src/main/kotlin/g0301_0400/s0341_flatten_nested_list_iterator/NestedIterator.kt)| Medium | Depth_First_Search, Tree, Stack, Design, Queue, Iterator | 210 | 100.00 + +#### Day 19 + +| | | | | | +|-|-|-|-|-|- +| 1797 |[Design Authentication Manager](src/main/kotlin/g1701_1800/s1797_design_authentication_manager/AuthenticationManager.kt)| Medium | Hash_Table, Design | 334 | 100.00 +| 0707 |[Design Linked List](src/main/kotlin/g0701_0800/s0707_design_linked_list/MyLinkedList.kt)| Medium | Design, Linked_List | 243 | 100.00 + +#### Day 20 + +| | | | | | +|-|-|-|-|-|- +| 0380 |[Insert Delete GetRandom O(1)](src/main/kotlin/g0301_0400/s0380_insert_delete_getrandom_o1/RandomizedSet.kt)| Medium | Array, Hash_Table, Math, Design, Randomized | 1326 | 68.23 +| 0622 |[Design Circular Queue](src/main/kotlin/g0601_0700/s0622_design_circular_queue/MyCircularQueue.kt)| Medium | Array, Design, Linked_List, Queue | 234 | 92.68 +| 0729 |[My Calendar I](src/main/kotlin/g0701_0800/s0729_my_calendar_i/MyCalendar.kt)| Medium | Binary_Search, Design, Ordered_Set, Segment_Tree | 378 | 69.70 + ## Contributing Your ideas/fixes/algorithms are more than welcome!