From bbf4d956dd788a922826d1728c3ef6a954203e49 Mon Sep 17 00:00:00 2001 From: Anton <63557005+kotler-dev@users.noreply.github.com> Date: Sun, 22 Oct 2023 02:36:47 +0300 Subject: [PATCH 01/16] Exercise/id1 (#path) * exercise/id1 --- src/main/kotlin/exercise100/easy/id1/Description1.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/exercise100/easy/id1/Description1.md b/src/main/kotlin/exercise100/easy/id1/Description1.md index 38f0f46..3f542ce 100644 --- a/src/main/kotlin/exercise100/easy/id1/Description1.md +++ b/src/main/kotlin/exercise100/easy/id1/Description1.md @@ -38,8 +38,8 @@ Constraints: - `-10^9 <= target <= 10^9` - Only one valid answer exist. -| Id | Description | Solution | Test | Difficulty | +| ID | Description | Solution | Test | Difficulty | |:--:|:------------|:--------------------------:|:-------------------------------------------------------------------------------:|:----------:| | 1 | Two Sum | [solution](./Solution1.kt) | [test](../../../../../../src/test/kotlin/exercise100/easy/id1/Solution1Test.kt) | Easy | -:top: [Back to all topics](../../../../../../../../../blob/master/README.md) \ No newline at end of file +:top: [Back to all topics](https://github.com/kotler-dev/kotlin-leetcode) From 2747db9a0e3765f8da538b351fb5ad2fb6e11caa Mon Sep 17 00:00:00 2001 From: Kotler Date: Sun, 22 Oct 2023 12:24:13 +0300 Subject: [PATCH 02/16] exercise/id121 --- README.md | 24 +--- .../exercise100/easy/id121/Description121.md | 37 ++++++ .../exercise100/easy/id121/Solution121.kt | 115 ++++++++++++++++++ .../exercise100/easy/id121/Solution121Test.kt | 29 +++++ 4 files changed, 187 insertions(+), 18 deletions(-) create mode 100644 src/main/kotlin/exercise100/easy/id121/Description121.md create mode 100644 src/main/kotlin/exercise100/easy/id121/Solution121.kt create mode 100644 src/test/kotlin/exercise100/easy/id121/Solution121Test.kt diff --git a/README.md b/README.md index e3ef4e3..cd455a0 100644 --- a/README.md +++ b/README.md @@ -47,24 +47,12 @@ My Kotlin exercises with tests from [Leetcode](https://leetcode.com/kotlerdev) #### Array -| ID | Description | Solution | Test | Difficulty | -|:----:|:----------------------------------------------------------------|:-------------------------------------------------------------:|:-------------------------------------------------------------:|:----------:| -| 1 | [Two Sum](src/main/kotlin/exercise100/easy/id1/Description1.md) | [solution](src/main/kotlin/exercise100/easy/id1/Solution1.kt) | [test](src/test/kotlin/exercise100/easy/id1/Solution1Test.kt) | Easy | -| 121 | [Best Time to Buy and Sell stock Easy]() | [solution]() | [test]() | Easy | -| 169 | [Majority Element]() | [solution]() | [test]() | Easy | -| 1000 | [Contains Duplicate]() | [solution]() | [test]() | Easy | - -### Template - -| ID | Description | Solution | Test | Difficulty | -|:----:|:--------------------------------------------------------------|:-------------------------------------------------------------:|:-------------------------------------------------------------:|:----------:| -| 0000 | [Title](src/main/kotlin/exercise100/easy/id1/Description1.md) | [solution](src/main/kotlin/exercise100/easy/id1/Solution1.kt) | [test](src/test/kotlin/exercise100/easy/id1/Solution1Test.kt) | Easy | -| 0000 | [Title](src/main/kotlin/exercise100/easy/id1/Description1.md) | [solution](src/main/kotlin/exercise100/easy/id1/Solution1.kt) | [test](src/test/kotlin/exercise100/easy/id1/Solution1Test.kt) | Medium | -| 0000 | [Title](src/main/kotlin/exercise100/easy/id1/Description1.md) | [solution](src/main/kotlin/exercise100/easy/id1/Solution1.kt) | [test](src/test/kotlin/exercise100/easy/id1/Solution1Test.kt) | Hard | - -![GitHub license](https://img.shields.io/badge/Difficulty-Easy-61904f) -![GitHub license](https://img.shields.io/badge/Difficulty-Medium-548af7) -![GitHub license](https://img.shields.io/badge/Difficulty-Hard-a571e6) +| ID | Description | Solution | Test | Difficulty | +|:----:|:-------------------------------------------------------------------------------------------------|:-----------------------------------------------------------------:|:-----------------------------------------------------------------:|:----------:| +| 1 | [Two Sum](src/main/kotlin/exercise100/easy/id1/Description1.md) | [solution](src/main/kotlin/exercise100/easy/id1/Solution1.kt) | [test](src/test/kotlin/exercise100/easy/id1/Solution1Test.kt) | Easy | +| 121 | [Best Time to Buy and Sell stock Easy](src/main/kotlin/exercise100/easy/id121/Description121.md) | [solution](src/main/kotlin/exercise100/easy/id121/Solution121.kt) | [test](src/test/kotlin/exercise100/easy/id121/Solution121Test.kt) | Easy | +| 169 | [Majority Element]() | [solution]() | [test]() | Easy | +| 1000 | [Contains Duplicate]() | [solution]() | [test]() | Easy | [//]: # (https://www.techinterviewhandbook.org/grind75?weeks=26&hours=40&grouping=topics) diff --git a/src/main/kotlin/exercise100/easy/id121/Description121.md b/src/main/kotlin/exercise100/easy/id121/Description121.md new file mode 100644 index 0000000..759fb9e --- /dev/null +++ b/src/main/kotlin/exercise100/easy/id121/Description121.md @@ -0,0 +1,37 @@ +[//]: # (Copyright [2023] [Anton Kotler kotler.developer@gmail.com] License MIT) + +# Best Time to Buy and Sell Stock + +![GitHub license](https://img.shields.io/badge/Difficulty-Easy-61904f) + +You are given an array `prices` where `prices[i]` is the price of a given stock on the `i'th` day. +You want to maximize your profit by choosing a singl to buy one stock and choosing a different day in the future to sell +that stock. +Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return `0`. + +Example 1: + +``` +Input: prices = [7,1,5,3,6,4] +Output: 5 +Explanation: Buy on day 2 (prices = 1) and sell on day 5 (price = 6), profit = 6 - 1 = 5. +Note that buying on day 2 and selling on day 1 is not allowed because you must buy before you sell. +``` + +Example 2: + +``` +Input: prices = [7,6,4,3,1] +Output: 0 +``` + +Constraints: + +- `1 <= prices.length <= 10^5` +- `0 <= prices[i] <= 10^4` + +| ID | Description | Solution | Test | Difficulty | +|:---:|:--------------------------------|:----------------------------:|:-----------------------------------------------------------------------------------:|:----------:| +| 121 | Best Time to Buy and Sell Stock | [solution](./Solution121.kt) | [test](../../../../../../src/test/kotlin/exercise100/easy/id121/Solution121Test.kt) | Easy | + +:top: [Back to all topics](https://github.com/kotler-dev/kotlin-leetcode) diff --git a/src/main/kotlin/exercise100/easy/id121/Solution121.kt b/src/main/kotlin/exercise100/easy/id121/Solution121.kt new file mode 100644 index 0000000..e947acc --- /dev/null +++ b/src/main/kotlin/exercise100/easy/id121/Solution121.kt @@ -0,0 +1,115 @@ +package exercise100.easy.id121 + +class Solution121 { + fun maxProfit(prices: IntArray): Int { + if (prices.size < 2) return 0 + var profit = 0 + var min = Int.MAX_VALUE + var max = 0 + + for (i in 0.. max) max = prices[i] + if (max - min > profit) profit = max - min + } + return profit + } + + /* + + fun maxProfit(prices: IntArray): Int { + if (prices.size < 2) return 0 + var profit = 0 + var min = Int.MAX_VALUE + var max = 0 + + val minn = prices.slice(1.. max) max = prices[i] + if (max - min > profit) profit = max - min + } + return profit + } + + fun maxProfit(prices: IntArray): Int { + if (prices.size < 2) return 0 + var profit = 0 + for (i in prices.indices) { + for (j in i + 1.. profit) { + profit = prices[j] - prices[i] + } + } + } + return profit + } + + fun maxProfit(prices: IntArray): Int { + if (prices.size < 2) return 0 + var profit = 0 + + val min = prices.slice(0..prices.size - 1).indices.minBy { prices[it] } + val minIndex = prices.lastIndexOf(prices[min]) + val p = prices.slice(minIndex..prices.size - 1) + + val max = p.indices.maxBy { p[it] } + val maxIndex = p.lastIndexOf(p[max]) + + val result = p[maxIndex] - prices[minIndex] + if (result > profit) profit = result + return profit + } + + fun maxProfit(prices: IntArray): Int { + var profit = 0 + for ((index, value) in prices.withIndex()) { + val i1 = index + 1 + if (i1 < prices.size) { + if (prices[i1] > value) { + val max = prices.slice(i1..prices.size - 1).max() + if (profit < max - value) { + profit = max - value + } + } + } + } + return profit + } + + fun maxProfit(prices: IntArray): Int { + var profit = 0 + + val minIndex = prices.indices.minBy { prices[it] } ?: 0 + val slice = prices.slice(minIndex..prices.size - 1) + val maxIndex = slice.indices.maxBy { slice[it] } ?: 0 + val result = slice[maxIndex] - prices[minIndex] + + if (result > profit) profit = result + + return profit + } + + fun maxProfit(prices: IntArray): Int { + if (prices.size < 2) return 0 + var profit = 0 + val maxSlice = prices.slice(1..prices.size - 1) + val maxIndex = maxSlice.indices.maxBy { maxSlice[it] } ?: 0 + val minSlice = prices.slice(0..maxSlice.lastIndexOf(maxSlice[maxIndex])) + val minIndex = minSlice.indices.minBy { minSlice[it] } ?: 0 + val result = maxSlice[maxIndex] - minSlice[minIndex] + if (result > profit) profit = result + return profit + } + +*/ +} \ No newline at end of file diff --git a/src/test/kotlin/exercise100/easy/id121/Solution121Test.kt b/src/test/kotlin/exercise100/easy/id121/Solution121Test.kt new file mode 100644 index 0000000..34128ae --- /dev/null +++ b/src/test/kotlin/exercise100/easy/id121/Solution121Test.kt @@ -0,0 +1,29 @@ +package exercise100.easy.id121 + +import io.kotest.assertions.print.print +import io.kotest.core.spec.style.FunSpec +import io.kotest.datatest.WithDataTestName +import io.kotest.datatest.withData +import io.kotest.matchers.shouldBe + +data class TestCase( + val prices: IntArray, + val expected: Int, +) : WithDataTestName { + override fun dataTestName(): String = expected.print().value +} + +class Solution121Test : FunSpec({ + context("shouldBe") { + withData( + nameFn = { "Input: ${it.prices.print().value}, Expected: ${it.expected.print().value}" }, + TestCase(prices = intArrayOf(7, 1, 5, 3, 6, 4), expected = 5), + TestCase(prices = intArrayOf(7, 6, 4, 3, 1), expected = 0), + TestCase(prices = intArrayOf(2, 4, 1), expected = 2), + TestCase(prices = intArrayOf(2, 1, 2, 0, 1), expected = 1), + TestCase(prices = intArrayOf(3, 3, 5, 0, 0, 3, 1, 4), expected = 4), + ) { (prices, expected) -> + Solution121().maxProfit(prices) shouldBe expected + } + } +}) \ No newline at end of file From a812d990d9463bb024172d2f2158e9cc03a8e337 Mon Sep 17 00:00:00 2001 From: Kotler Date: Sun, 22 Oct 2023 14:10:15 +0300 Subject: [PATCH 03/16] exercise/id169 --- .../exercise100/easy/id169/Description169.md | 37 +++++++++++++++++++ .../exercise100/easy/id169/Solution169.kt | 19 ++++++++++ .../exercise100/easy/id169/Solution169Test.kt | 26 +++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 src/main/kotlin/exercise100/easy/id169/Description169.md create mode 100644 src/main/kotlin/exercise100/easy/id169/Solution169.kt create mode 100644 src/test/kotlin/exercise100/easy/id169/Solution169Test.kt diff --git a/src/main/kotlin/exercise100/easy/id169/Description169.md b/src/main/kotlin/exercise100/easy/id169/Description169.md new file mode 100644 index 0000000..8d61371 --- /dev/null +++ b/src/main/kotlin/exercise100/easy/id169/Description169.md @@ -0,0 +1,37 @@ +[//]: # (Copyright [2023] [Anton Kotler kotler.developer@gmail.com] License MIT) + +# Majority Element + +![Difficulty](https://img.shields.io/badge/Difficulty-Easy-61904f) + +Given an array `nums` of size `n`, return the majority element. +The majority element is the element that appears more than `|n / 2|` times. +You may assume that the majority element always exists in the array. + +Example 1: + +``` +Input: nums = [3,2,3] +Output: 3 +``` + +Example 2: + +``` +Input: nums = [2,2,1,1,1,2,2] +Output: 2 +``` + +Constraints: + +- `n == nums.length` +- `1 <= n <= 5 * 10^4` +- `-10^9 <= nums[i] <= 10^9` + +Follow-up: Could you solve the problem in linear time and in `O(1)` space? + +| ID | Description | Solution | Test | Difficulty | +|:---:|:-----------------|:----------------------------:|:-----------------------------------------------------------------------------------:|:----------:| +| 169 | Majority Element | [solution](./Solution169.kt) | [test](../../../../../../src/test/kotlin/exercise100/easy/id169/Solution169Test.kt) | Easy | + +:top: [Back to all topics](https://github.com/kotler-dev/kotlin-leetcode) diff --git a/src/main/kotlin/exercise100/easy/id169/Solution169.kt b/src/main/kotlin/exercise100/easy/id169/Solution169.kt new file mode 100644 index 0000000..19cef11 --- /dev/null +++ b/src/main/kotlin/exercise100/easy/id169/Solution169.kt @@ -0,0 +1,19 @@ +package exercise100.easy.id169 + +class Solution169 { + fun majorityElement(nums: IntArray): Int { + val hm = HashMap() + nums.forEach { + val n = hm[it] + if (n == null) hm[it] = 0 + if (n != null) hm[it] = n + 1 + } + return hm.maxBy { n -> n.value }.key + } + + /* + + + + */ +} \ No newline at end of file diff --git a/src/test/kotlin/exercise100/easy/id169/Solution169Test.kt b/src/test/kotlin/exercise100/easy/id169/Solution169Test.kt new file mode 100644 index 0000000..fe62c13 --- /dev/null +++ b/src/test/kotlin/exercise100/easy/id169/Solution169Test.kt @@ -0,0 +1,26 @@ +package exercise100.easy.id169 + +import io.kotest.assertions.print.print +import io.kotest.core.spec.style.FunSpec +import io.kotest.datatest.WithDataTestName +import io.kotest.datatest.withData +import io.kotest.matchers.shouldBe + +data class TestCase( + val prices: IntArray, + val expected: Int, +) : WithDataTestName { + override fun dataTestName(): String = expected.print().value +} + +class Solution169Test : FunSpec({ + context("shouldBe") { + withData( + nameFn = { "Input: ${it.prices.print().value}, Expected: ${it.expected.print().value}" }, + TestCase(prices = intArrayOf(3, 2, 3), expected = 3), + TestCase(prices = intArrayOf(2, 2, 1, 1, 1, 2, 2), expected = 2), + ) { (prices, expected) -> + Solution169().majorityElement(prices) shouldBe expected + } + } +}) \ No newline at end of file From 8f5edf509850d652a927faf911adc9f05ca2c0e8 Mon Sep 17 00:00:00 2001 From: Kotler Date: Sun, 22 Oct 2023 14:22:15 +0300 Subject: [PATCH 04/16] exercise/id169 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cd455a0..fb1a3d5 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ My Kotlin exercises with tests from [Leetcode](https://leetcode.com/kotlerdev) |:----:|:-------------------------------------------------------------------------------------------------|:-----------------------------------------------------------------:|:-----------------------------------------------------------------:|:----------:| | 1 | [Two Sum](src/main/kotlin/exercise100/easy/id1/Description1.md) | [solution](src/main/kotlin/exercise100/easy/id1/Solution1.kt) | [test](src/test/kotlin/exercise100/easy/id1/Solution1Test.kt) | Easy | | 121 | [Best Time to Buy and Sell stock Easy](src/main/kotlin/exercise100/easy/id121/Description121.md) | [solution](src/main/kotlin/exercise100/easy/id121/Solution121.kt) | [test](src/test/kotlin/exercise100/easy/id121/Solution121Test.kt) | Easy | -| 169 | [Majority Element]() | [solution]() | [test]() | Easy | +| 169 | [Majority Element](src/main/kotlin/exercise100/easy/id169/Description169.md) | [solution](src/main/kotlin/exercise100/easy/id169/Solution169.kt) | [test](src/test/kotlin/exercise100/easy/id169/Solution169Test.kt) | Easy | | 1000 | [Contains Duplicate]() | [solution]() | [test]() | Easy | [//]: # (https://www.techinterviewhandbook.org/grind75?weeks=26&hours=40&grouping=topics) From aa6251f57357baa0a4563c3a23c5c0a8e6609903 Mon Sep 17 00:00:00 2001 From: Kotler Date: Sun, 22 Oct 2023 20:00:29 +0300 Subject: [PATCH 05/16] Update path --- .../kotlin/{exercise100 => exercise}/easy/id1/Description1.md | 2 +- src/main/kotlin/{exercise100 => exercise}/easy/id1/Solution1.kt | 2 +- .../{exercise100 => exercise}/easy/id121/Description121.md | 2 +- .../kotlin/{exercise100 => exercise}/easy/id121/Solution121.kt | 2 +- .../{exercise100 => exercise}/easy/id169/Description169.md | 2 +- .../kotlin/{exercise100 => exercise}/easy/id169/Solution169.kt | 2 +- .../kotlin/{exercise100 => exercise}/easy/id1/Solution1Test.kt | 2 +- .../{exercise100 => exercise}/easy/id121/Solution121Test.kt | 2 +- .../{exercise100 => exercise}/easy/id169/Solution169Test.kt | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) rename src/main/kotlin/{exercise100 => exercise}/easy/id1/Description1.md (94%) rename src/main/kotlin/{exercise100 => exercise}/easy/id1/Solution1.kt (96%) rename src/main/kotlin/{exercise100 => exercise}/easy/id121/Description121.md (92%) rename src/main/kotlin/{exercise100 => exercise}/easy/id121/Solution121.kt (99%) rename src/main/kotlin/{exercise100 => exercise}/easy/id169/Description169.md (92%) rename src/main/kotlin/{exercise100 => exercise}/easy/id169/Solution169.kt (91%) rename src/test/kotlin/{exercise100 => exercise}/easy/id1/Solution1Test.kt (98%) rename src/test/kotlin/{exercise100 => exercise}/easy/id121/Solution121Test.kt (97%) rename src/test/kotlin/{exercise100 => exercise}/easy/id169/Solution169Test.kt (96%) diff --git a/src/main/kotlin/exercise100/easy/id1/Description1.md b/src/main/kotlin/exercise/easy/id1/Description1.md similarity index 94% rename from src/main/kotlin/exercise100/easy/id1/Description1.md rename to src/main/kotlin/exercise/easy/id1/Description1.md index 3f542ce..45de6a8 100644 --- a/src/main/kotlin/exercise100/easy/id1/Description1.md +++ b/src/main/kotlin/exercise/easy/id1/Description1.md @@ -40,6 +40,6 @@ Constraints: | ID | Description | Solution | Test | Difficulty | |:--:|:------------|:--------------------------:|:-------------------------------------------------------------------------------:|:----------:| -| 1 | Two Sum | [solution](./Solution1.kt) | [test](../../../../../../src/test/kotlin/exercise100/easy/id1/Solution1Test.kt) | Easy | +| 1 | Two Sum | [solution](./Solution1.kt) | [test](../../../../../../src/test/kotlin/exercise/easy/id1/Solution1Test.kt) | Easy | :top: [Back to all topics](https://github.com/kotler-dev/kotlin-leetcode) diff --git a/src/main/kotlin/exercise100/easy/id1/Solution1.kt b/src/main/kotlin/exercise/easy/id1/Solution1.kt similarity index 96% rename from src/main/kotlin/exercise100/easy/id1/Solution1.kt rename to src/main/kotlin/exercise/easy/id1/Solution1.kt index 4470f3f..e948958 100644 --- a/src/main/kotlin/exercise100/easy/id1/Solution1.kt +++ b/src/main/kotlin/exercise/easy/id1/Solution1.kt @@ -1,4 +1,4 @@ -package exercise100.easy.id1 +package exercise.easy.id1 class Solution1 { fun twoSum(nums: IntArray, target: Int): IntArray { diff --git a/src/main/kotlin/exercise100/easy/id121/Description121.md b/src/main/kotlin/exercise/easy/id121/Description121.md similarity index 92% rename from src/main/kotlin/exercise100/easy/id121/Description121.md rename to src/main/kotlin/exercise/easy/id121/Description121.md index 759fb9e..8f9dd5b 100644 --- a/src/main/kotlin/exercise100/easy/id121/Description121.md +++ b/src/main/kotlin/exercise/easy/id121/Description121.md @@ -32,6 +32,6 @@ Constraints: | ID | Description | Solution | Test | Difficulty | |:---:|:--------------------------------|:----------------------------:|:-----------------------------------------------------------------------------------:|:----------:| -| 121 | Best Time to Buy and Sell Stock | [solution](./Solution121.kt) | [test](../../../../../../src/test/kotlin/exercise100/easy/id121/Solution121Test.kt) | Easy | +| 121 | Best Time to Buy and Sell Stock | [solution](./Solution121.kt) | [test](../../../../../../src/test/kotlin/exercise/easy/id121/Solution121Test.kt) | Easy | :top: [Back to all topics](https://github.com/kotler-dev/kotlin-leetcode) diff --git a/src/main/kotlin/exercise100/easy/id121/Solution121.kt b/src/main/kotlin/exercise/easy/id121/Solution121.kt similarity index 99% rename from src/main/kotlin/exercise100/easy/id121/Solution121.kt rename to src/main/kotlin/exercise/easy/id121/Solution121.kt index e947acc..c0cd7d9 100644 --- a/src/main/kotlin/exercise100/easy/id121/Solution121.kt +++ b/src/main/kotlin/exercise/easy/id121/Solution121.kt @@ -1,4 +1,4 @@ -package exercise100.easy.id121 +package exercise.easy.id121 class Solution121 { fun maxProfit(prices: IntArray): Int { diff --git a/src/main/kotlin/exercise100/easy/id169/Description169.md b/src/main/kotlin/exercise/easy/id169/Description169.md similarity index 92% rename from src/main/kotlin/exercise100/easy/id169/Description169.md rename to src/main/kotlin/exercise/easy/id169/Description169.md index 8d61371..9ecea66 100644 --- a/src/main/kotlin/exercise100/easy/id169/Description169.md +++ b/src/main/kotlin/exercise/easy/id169/Description169.md @@ -32,6 +32,6 @@ Follow-up: Could you solve the problem in linear time and in `O(1)` space? | ID | Description | Solution | Test | Difficulty | |:---:|:-----------------|:----------------------------:|:-----------------------------------------------------------------------------------:|:----------:| -| 169 | Majority Element | [solution](./Solution169.kt) | [test](../../../../../../src/test/kotlin/exercise100/easy/id169/Solution169Test.kt) | Easy | +| 169 | Majority Element | [solution](./Solution169.kt) | [test](../../../../../test/kotlin/exercise/easy/id169/Solution169Test.kt) | Easy | :top: [Back to all topics](https://github.com/kotler-dev/kotlin-leetcode) diff --git a/src/main/kotlin/exercise100/easy/id169/Solution169.kt b/src/main/kotlin/exercise/easy/id169/Solution169.kt similarity index 91% rename from src/main/kotlin/exercise100/easy/id169/Solution169.kt rename to src/main/kotlin/exercise/easy/id169/Solution169.kt index 19cef11..24b5d1c 100644 --- a/src/main/kotlin/exercise100/easy/id169/Solution169.kt +++ b/src/main/kotlin/exercise/easy/id169/Solution169.kt @@ -1,4 +1,4 @@ -package exercise100.easy.id169 +package exercise.easy.id169 class Solution169 { fun majorityElement(nums: IntArray): Int { diff --git a/src/test/kotlin/exercise100/easy/id1/Solution1Test.kt b/src/test/kotlin/exercise/easy/id1/Solution1Test.kt similarity index 98% rename from src/test/kotlin/exercise100/easy/id1/Solution1Test.kt rename to src/test/kotlin/exercise/easy/id1/Solution1Test.kt index 5999eb5..86608eb 100644 --- a/src/test/kotlin/exercise100/easy/id1/Solution1Test.kt +++ b/src/test/kotlin/exercise/easy/id1/Solution1Test.kt @@ -1,4 +1,4 @@ -package exercise100.easy.id1 +package exercise.easy.id1 import io.kotest.assertions.print.print import io.kotest.core.spec.style.FunSpec diff --git a/src/test/kotlin/exercise100/easy/id121/Solution121Test.kt b/src/test/kotlin/exercise/easy/id121/Solution121Test.kt similarity index 97% rename from src/test/kotlin/exercise100/easy/id121/Solution121Test.kt rename to src/test/kotlin/exercise/easy/id121/Solution121Test.kt index 34128ae..3df4104 100644 --- a/src/test/kotlin/exercise100/easy/id121/Solution121Test.kt +++ b/src/test/kotlin/exercise/easy/id121/Solution121Test.kt @@ -1,4 +1,4 @@ -package exercise100.easy.id121 +package exercise.easy.id121 import io.kotest.assertions.print.print import io.kotest.core.spec.style.FunSpec diff --git a/src/test/kotlin/exercise100/easy/id169/Solution169Test.kt b/src/test/kotlin/exercise/easy/id169/Solution169Test.kt similarity index 96% rename from src/test/kotlin/exercise100/easy/id169/Solution169Test.kt rename to src/test/kotlin/exercise/easy/id169/Solution169Test.kt index fe62c13..9452694 100644 --- a/src/test/kotlin/exercise100/easy/id169/Solution169Test.kt +++ b/src/test/kotlin/exercise/easy/id169/Solution169Test.kt @@ -1,4 +1,4 @@ -package exercise100.easy.id169 +package exercise.easy.id169 import io.kotest.assertions.print.print import io.kotest.core.spec.style.FunSpec From 1c708db9c1b823835ab9312fb0b613bfacfa0c6f Mon Sep 17 00:00:00 2001 From: Kotler Date: Sun, 22 Oct 2023 20:00:45 +0300 Subject: [PATCH 06/16] exercise/id217 --- README.md | 12 +- .../exercise/easy/id217/Description217.md | 40 ++++++ .../kotlin/exercise/easy/id217/Solution217.kt | 125 ++++++++++++++++++ .../exercise/easy/id217/Solution217Test.kt | 36 +++++ 4 files changed, 207 insertions(+), 6 deletions(-) create mode 100644 src/main/kotlin/exercise/easy/id217/Description217.md create mode 100644 src/main/kotlin/exercise/easy/id217/Solution217.kt create mode 100644 src/test/kotlin/exercise/easy/id217/Solution217Test.kt diff --git a/README.md b/README.md index fb1a3d5..62d2fa9 100644 --- a/README.md +++ b/README.md @@ -47,12 +47,12 @@ My Kotlin exercises with tests from [Leetcode](https://leetcode.com/kotlerdev) #### Array -| ID | Description | Solution | Test | Difficulty | -|:----:|:-------------------------------------------------------------------------------------------------|:-----------------------------------------------------------------:|:-----------------------------------------------------------------:|:----------:| -| 1 | [Two Sum](src/main/kotlin/exercise100/easy/id1/Description1.md) | [solution](src/main/kotlin/exercise100/easy/id1/Solution1.kt) | [test](src/test/kotlin/exercise100/easy/id1/Solution1Test.kt) | Easy | -| 121 | [Best Time to Buy and Sell stock Easy](src/main/kotlin/exercise100/easy/id121/Description121.md) | [solution](src/main/kotlin/exercise100/easy/id121/Solution121.kt) | [test](src/test/kotlin/exercise100/easy/id121/Solution121Test.kt) | Easy | -| 169 | [Majority Element](src/main/kotlin/exercise100/easy/id169/Description169.md) | [solution](src/main/kotlin/exercise100/easy/id169/Solution169.kt) | [test](src/test/kotlin/exercise100/easy/id169/Solution169Test.kt) | Easy | -| 1000 | [Contains Duplicate]() | [solution]() | [test]() | Easy | +| ID | Description | Solution | Test | Difficulty | +|:---:|:-------------------------------------------------------------------------------------------------|:-----------------------------------------------------------------:|:-----------------------------------------------------------------:|:----------:| +| 1 | [Two Sum](src/main/kotlin/exercise/easy/id1/Description1.md) | [solution](src/main/kotlin/exercise/easy/id1/Solution1.kt) | [test](src/test/kotlin/exercise/easy/id1/Solution1Test.kt) | Easy | +| 121 | [Best Time to Buy and Sell stock Easy](src/main/kotlin/exercise/easy/id121/Description121.md) | [solution](src/main/kotlin/exercise/easy/id121/Solution121.kt) | [test](src/test/kotlin/exercise/easy/id121/Solution121Test.kt) | Easy | +| 169 | [Majority Element](src/main/kotlin/exercise/easy/id169/Description169.md) | [solution](src/main/kotlin/exercise/easy/id169/Solution169.kt) | [test](src/test/kotlin/exercise/easy/id169/Solution169Test.kt) | Easy | +| 217 | [Contains Duplicate](src/main/kotlin/exercise/easy/id217/Description217.md)) | [solution](src/main/kotlin/exercise/easy/id217/Solution217.kt) | [test](src/test/kotlin/exercise/easy/id217/Solution217Test.kt) | Easy | [//]: # (https://www.techinterviewhandbook.org/grind75?weeks=26&hours=40&grouping=topics) diff --git a/src/main/kotlin/exercise/easy/id217/Description217.md b/src/main/kotlin/exercise/easy/id217/Description217.md new file mode 100644 index 0000000..2507a3a --- /dev/null +++ b/src/main/kotlin/exercise/easy/id217/Description217.md @@ -0,0 +1,40 @@ +[//]: # (Copyright [2023] [Anton Kotler kotler.developer@gmail.com] License MIT) + +# Contains Duplicates + +Given an integer array `nums`, return `true` if any value appears at least twice in the array, and return `false` if +every element is distinct. + +![Difficulty](https://img.shields.io/badge/Difficulty-Easy-61904f) + +Example 1: + +``` +Input: nums = [1,2,3,1] +Output: true +``` + +Example 2: + +``` +Input: nums = [1,2,3,4] +Output: false +``` + +Example 3: + +``` +Input: nums = [1,1,1,3,3,4,3,2,4,2] +Output: true +``` + +Constraints: + +- `1 <= nums.legth <= 10^5` +- `-10^9 <= nums[i] <= 10^9` + +| ID | Description | Solution | Test | Difficulty | +|:---:|:--------------------|:----------------------------:|:--------------------------------------------------------------------------------:|:----------:| +| 217 | Contains Duplicates | [solution](./Solution217.kt) | [test](../../../../../../src/test/kotlin/exercise/easy/id217/Solution217Test.kt) | Easy | + +:top: [Back to all topics](https://github.com/kotler-dev/kotlin-leetcode) diff --git a/src/main/kotlin/exercise/easy/id217/Solution217.kt b/src/main/kotlin/exercise/easy/id217/Solution217.kt new file mode 100644 index 0000000..ffdf02e --- /dev/null +++ b/src/main/kotlin/exercise/easy/id217/Solution217.kt @@ -0,0 +1,125 @@ +package exercise.easy.id217 + +class Solution217 { + fun containsDuplicate(nums: IntArray) = nums.size > nums.toSet().size + + /* + + fun containsDuplicate(nums: IntArray): Boolean { + val hashSet = HashSet() + nums.forEach { + if (!hashSet.add(it)) + return true + } + return false + } + + fun containsDuplicate(nums: IntArray): Boolean { + if (nums.size < 2) return false + val hs = HashSet() + var end = nums.size - 1 + var index = 0 + var middle = nums.size / 2 + + if (end % 2 == 0) { + hs.add(nums[index]) + middle++ + index++ + } + + for (start in index..() + var end = nums.size - 1 + val middle = nums.size / 2 + + if (end >= 4) hs.add(nums[middle]) + + for (start in 0..middle) { + if (!hs.contains(nums[start])) hs.add(nums[start]) else return true + if (!hs.contains(nums[end])) hs.add(nums[end]) else return true + if (end == middle) return false + end-- + } + return false + } + + fun containsDuplicate(nums: IntArray): Boolean { + val hs = HashSet() + var end = nums.size - 1 + var backStep = nums.size / 2 + var forwardStep = backStep + 1 + + if ((backStep - 1) % 2 != 0) { + hs.add(nums[backStep]) + backStep -= 1 + forwardStep += 1 + } + + for (start in 0..= 42) { + if (!hs.contains(nums[backStep])) hs.add(nums[backStep--]) else return true + if (!hs.contains(nums[forwardStep])) hs.add(nums[forwardStep++]) else return true + } + } + return false + } + + fun containsDuplicate(nums: IntArray): Boolean { + val hs = HashSet() + val first = 0 + var end = nums.size - 1 + var backStep = nums.size / 2 - 1 + var forwardStep = backStep + 1 + + for (start in 0..nums.size / 2 - 1) { + if (!hs.contains(nums[start])) hs.add(nums[start]) else return true + if (!hs.contains(nums[end])) hs.add(nums[end]) else return true + if (nums.size > 3) { + if (!hs.contains(nums[backStep])) hs.add(nums[backStep]) else return true + if (!hs.contains(nums[forwardStep])) hs.add(nums[forwardStep]) else return true + if (backStep - 1 != start) backStep-- + if (forwardStep + 1 != end) forwardStep++ + } + if (end - 1 != forwardStep) end-- + } + return false + } + + fun containsDuplicate(nums: IntArray): Boolean { + var flag = false + var dupl = -1 + for ((index, value) in nums.withIndex()) { + if (flag == false) { + if (index == nums.size - 1) return false + flag = searchDuplicate(nums.slice(index+1..nums.size - 1), value) + } else { + return flag + } + } + return false + } + + fun searchDuplicate(arr: List, dupl: Int): Boolean { + arr.forEach { + if (it == dupl) { + println("arr:$arr, dupl$dupl") + return true + } + } + return false + } + + */ +} \ No newline at end of file diff --git a/src/test/kotlin/exercise/easy/id217/Solution217Test.kt b/src/test/kotlin/exercise/easy/id217/Solution217Test.kt new file mode 100644 index 0000000..14a6e94 --- /dev/null +++ b/src/test/kotlin/exercise/easy/id217/Solution217Test.kt @@ -0,0 +1,36 @@ +package exercise.easy.id217 + +import io.kotest.assertions.print.print +import io.kotest.core.spec.style.FunSpec +import io.kotest.datatest.WithDataTestName +import io.kotest.datatest.withData +import io.kotest.matchers.shouldBe + +data class TestCase( + val nums: IntArray, + val expected: Boolean, +) : WithDataTestName { + override fun dataTestName(): String = expected.print().value +} + +class Solution217Test : FunSpec({ + context("shouldBe") { + withData( + nameFn = { "Input: ${it.nums.print().value}, Expected: ${it.expected.print().value}" }, + TestCase(nums = intArrayOf(0), expected = false), + TestCase(nums = intArrayOf(0, 0), expected = true), + TestCase(nums = intArrayOf(3, 1), expected = false), + TestCase(nums = intArrayOf(3, 2, 3), expected = true), + TestCase(nums = intArrayOf(1, 2, 3, 1), expected = true), + TestCase(nums = intArrayOf(1, 2, 3, 4), expected = false), + TestCase(nums = intArrayOf(0, 1, 2, 3, 7, 4, 5, 42, 101, 6, 8, 7, 11, 12, 13, 14), expected = true), + TestCase(nums = intArrayOf(1, 1, 1, 3, 3, 4, 3, 2, 4, 2), expected = true), + TestCase(nums = intArrayOf(13, 18, 22, 22), expected = true), + TestCase(nums = intArrayOf(2, 14, 18, 22, 22), expected = true), + TestCase(nums = intArrayOf(1, 5, -2, -4, 0), expected = false), + TestCase(nums = intArrayOf(1000000000, 1000000000, 11), expected = true), + ) { (prices, expected) -> + Solution217().containsDuplicate(prices) shouldBe expected + } + } +}) \ No newline at end of file From f820e34236c77c2c4ec2b10077c3cd4f3dbb735e Mon Sep 17 00:00:00 2001 From: Kotler Date: Sun, 22 Oct 2023 22:29:07 +0300 Subject: [PATCH 07/16] exercise/id283 --- README.md | 7 +-- .../exercise/easy/id283/Description283.md | 46 ++++++++++++++++++ .../kotlin/exercise/easy/id283/Solution283.kt | 48 +++++++++++++++++++ .../exercise/easy/id283/Solution283Test.kt | 29 +++++++++++ 4 files changed, 127 insertions(+), 3 deletions(-) create mode 100644 src/main/kotlin/exercise/easy/id283/Description283.md create mode 100644 src/main/kotlin/exercise/easy/id283/Solution283.kt create mode 100644 src/test/kotlin/exercise/easy/id283/Solution283Test.kt diff --git a/README.md b/README.md index 62d2fa9..6094ede 100644 --- a/README.md +++ b/README.md @@ -47,12 +47,13 @@ My Kotlin exercises with tests from [Leetcode](https://leetcode.com/kotlerdev) #### Array -| ID | Description | Solution | Test | Difficulty | -|:---:|:-------------------------------------------------------------------------------------------------|:-----------------------------------------------------------------:|:-----------------------------------------------------------------:|:----------:| +| ID | Description | Solution | Test | Difficulty | +|:---:|:----------------------------------------------------------------------------------------------|:-----------------------------------------------------------------:|:-----------------------------------------------------------------:|:----------:| | 1 | [Two Sum](src/main/kotlin/exercise/easy/id1/Description1.md) | [solution](src/main/kotlin/exercise/easy/id1/Solution1.kt) | [test](src/test/kotlin/exercise/easy/id1/Solution1Test.kt) | Easy | | 121 | [Best Time to Buy and Sell stock Easy](src/main/kotlin/exercise/easy/id121/Description121.md) | [solution](src/main/kotlin/exercise/easy/id121/Solution121.kt) | [test](src/test/kotlin/exercise/easy/id121/Solution121Test.kt) | Easy | | 169 | [Majority Element](src/main/kotlin/exercise/easy/id169/Description169.md) | [solution](src/main/kotlin/exercise/easy/id169/Solution169.kt) | [test](src/test/kotlin/exercise/easy/id169/Solution169Test.kt) | Easy | -| 217 | [Contains Duplicate](src/main/kotlin/exercise/easy/id217/Description217.md)) | [solution](src/main/kotlin/exercise/easy/id217/Solution217.kt) | [test](src/test/kotlin/exercise/easy/id217/Solution217Test.kt) | Easy | +| 217 | [Contains Duplicate](src/main/kotlin/exercise/easy/id217/Description217.md) | [solution](src/main/kotlin/exercise/easy/id217/Solution217.kt) | [test](src/test/kotlin/exercise/easy/id217/Solution217Test.kt) | Easy | +| 283 | [Move Zeroes](src/main/kotlin/exercise/easy/id283/Description283.md) | [solution](src/main/kotlin/exercise/easy/id283/Solution283.kt) | [test](src/test/kotlin/exercise/easy/id283/Solution283Test.kt) | Easy | [//]: # (https://www.techinterviewhandbook.org/grind75?weeks=26&hours=40&grouping=topics) diff --git a/src/main/kotlin/exercise/easy/id283/Description283.md b/src/main/kotlin/exercise/easy/id283/Description283.md new file mode 100644 index 0000000..07016c6 --- /dev/null +++ b/src/main/kotlin/exercise/easy/id283/Description283.md @@ -0,0 +1,46 @@ +[//]: # (Copyright [2023] [Anton Kotler kotler.developer@gmail.com] License MIT) + +# Move Zeroes + +Given an integer array `nums`, move all `0`'s to the end of it while maintaining the relative order of the non-zero +elements. +Note that you must do this in-place without making a copy of the array. + +![Difficulty](https://img.shields.io/badge/Difficulty-Easy-61904f) + +Example 1: + +[0, 1, 0, 3, 12] + +[index 1] +[1, 0] + +``` +Input: nums = [0,1,0,3,12] +Output: [1,3,12,0,0] +``` + +Example 2: + +``` +Input: nums = [0] +Output: [0] +``` + +Example 3: + +``` +Input: nums = [1,1,1,3,3,4,3,2,4,2] +Output: true +``` + +Constraints: + +- `1 <= nums.length <= 10^4` +- `-2^31 <= nums[i] <= 2^31 - 1` + +| ID | Description | Solution | Test | Difficulty | +|:---:|:------------|:----------------------------:|:--------------------------------------------------------------------------------:|:----------:| +| 283 | Move Zeroes | [solution](./Solution283.kt) | [test](../../../../../../src/test/kotlin/exercise/easy/id283/Solution283Test.kt) | Easy | + +:top: [Back to all topics](https://github.com/kotler-dev/kotlin-leetcode) diff --git a/src/main/kotlin/exercise/easy/id283/Solution283.kt b/src/main/kotlin/exercise/easy/id283/Solution283.kt new file mode 100644 index 0000000..f1af637 --- /dev/null +++ b/src/main/kotlin/exercise/easy/id283/Solution283.kt @@ -0,0 +1,48 @@ +package exercise.easy.id283 + +class Solution283 { + fun moveZeroes(nums: IntArray): Unit { + if (nums.size >= 2) { + var index = 0 + for (num in nums) { + if (num != 0) nums[index++] = num + } + for (i in nums.size - 1 downTo index) { + nums[i] = 0 + } + } + } + + /* + + fun moveZeroes(nums: IntArray): Unit { + if (nums.size >= 2) { + val box = IntArray(nums.size){0} + var index = 0 + for (num in nums) { + if (num != 0) box[index++] = num + } + for ((i, num) in box.withIndex()) { + nums[i] = num + } + } + println(nums.toList()) + } + + fun moveZeroes(nums: IntArray): Unit { + if (nums.size > 2) { + val hm = HashMap() + var key = 0 + + for ((index, num) in nums.withIndex()) { + if (num == 0) hm[key] = index + if (num != 0 && hm[key] != null) { + nums[hm[key++]!!] = num + nums[index] = 0 + } + } + } + } + + */ +} \ No newline at end of file diff --git a/src/test/kotlin/exercise/easy/id283/Solution283Test.kt b/src/test/kotlin/exercise/easy/id283/Solution283Test.kt new file mode 100644 index 0000000..7313354 --- /dev/null +++ b/src/test/kotlin/exercise/easy/id283/Solution283Test.kt @@ -0,0 +1,29 @@ +package exercise.easy.id283 + +import io.kotest.assertions.print.print +import io.kotest.core.spec.style.FunSpec +import io.kotest.datatest.WithDataTestName +import io.kotest.datatest.withData +import io.kotest.matchers.equals.shouldBeEqual +import io.kotest.matchers.shouldBe + +data class TestCase( + val nums: IntArray, + val expected: IntArray, +) : WithDataTestName { + override fun dataTestName(): String = expected.print().value +} + +class Solution283Test : FunSpec({ + context("shouldBe") { + withData( + nameFn = { "Input: ${it.nums.print().value}, Expected: ${it.expected.print().value}" }, + TestCase(nums = intArrayOf(0, 1, 0, 3, 12), expected = intArrayOf(1, 3, 12, 0, 0)), + TestCase(nums = intArrayOf(0), expected = intArrayOf(0)), + TestCase(nums = intArrayOf(0, 1), expected = intArrayOf(1, 0)), + ) { (nums, expected) -> + Solution283().moveZeroes(nums) + nums.toList() shouldBeEqual expected.toList() + } + } +}) \ No newline at end of file From d52afa885e3608ec25a648ea3d3d63adb90ee494 Mon Sep 17 00:00:00 2001 From: Kotler Date: Mon, 23 Oct 2023 13:24:33 +0300 Subject: [PATCH 08/16] exercise/id283 --- src/main/kotlin/exercise/easy/id283/Description283.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/main/kotlin/exercise/easy/id283/Description283.md b/src/main/kotlin/exercise/easy/id283/Description283.md index 07016c6..d72a407 100644 --- a/src/main/kotlin/exercise/easy/id283/Description283.md +++ b/src/main/kotlin/exercise/easy/id283/Description283.md @@ -10,11 +10,6 @@ Note that you must do this in-place without making a copy of the array. Example 1: -[0, 1, 0, 3, 12] - -[index 1] -[1, 0] - ``` Input: nums = [0,1,0,3,12] Output: [1,3,12,0,0] From 817719fc323401590eda6b86ac246f9da7325f9d Mon Sep 17 00:00:00 2001 From: Kotler Date: Mon, 23 Oct 2023 22:02:38 +0300 Subject: [PATCH 09/16] exercise/id977 --- .../exercise/easy/id977/Description977.md | 36 +++++++++++++++++++ .../kotlin/exercise/easy/id977/Solution977.kt | 31 ++++++++++++++++ .../exercise/easy/id977/Solution977Test.kt | 26 ++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 src/main/kotlin/exercise/easy/id977/Description977.md create mode 100644 src/main/kotlin/exercise/easy/id977/Solution977.kt create mode 100644 src/test/kotlin/exercise/easy/id977/Solution977Test.kt diff --git a/src/main/kotlin/exercise/easy/id977/Description977.md b/src/main/kotlin/exercise/easy/id977/Description977.md new file mode 100644 index 0000000..4a95039 --- /dev/null +++ b/src/main/kotlin/exercise/easy/id977/Description977.md @@ -0,0 +1,36 @@ +[//]: # (Copyright [2023] [Anton Kotler kotler.developer@gmail.com] License MIT) + +# Squares of a Sorted Array + +Given an integer array `nums` sorted in non-decreasing order, return an array of the squares of each number sorted in +non-decreasing order. + +![Difficulty](https://img.shields.io/badge/Difficulty-Easy-61904f) + +Example 1: + +``` +Input: nums = [-4,-1,0,3,10] +Output: [0,1,9,16,100] +Explanation: After squaring, the array becomes [16,1,0,9,100]. +After sorting, it becomes [0,1,9,16,100]. +``` + +Example 2: + +``` +Input: nums = [-7,-3,2,3,11] +Output: [4,9,9,49,121] +``` + +Constraints: + +- `1 <= nums.length <= 104` +- `-104 <= nums[i] <= 104` +- `nums is sorted in non-decreasing order` + +| ID | Description | Solution | Test | Difficulty | +|:---:|:--------------------------|:----------------------------:|:--------------------------------------------------------------------------------:|:----------:| +| 977 | Squares of a Sorted Array | [solution](./Solution977.kt) | [test](../../../../../../src/test/kotlin/exercise/easy/id977/Solution977Test.kt) | Easy | + +:top: [Back to all topics](https://github.com/kotler-dev/kotlin-leetcode) diff --git a/src/main/kotlin/exercise/easy/id977/Solution977.kt b/src/main/kotlin/exercise/easy/id977/Solution977.kt new file mode 100644 index 0000000..254bb65 --- /dev/null +++ b/src/main/kotlin/exercise/easy/id977/Solution977.kt @@ -0,0 +1,31 @@ +package exercise.easy.id977 + +class Solution977 { + fun sortedSquares(nums: IntArray): IntArray { + for (index in nums.indices) { + nums[index] *= nums[index] + } + + var flag: Boolean + do { + flag = false + for (index in 1.. nums[index]) { + nums[index - 1] = nums[index] + nums[index] = box + flag = true + } + } + } while (flag) + return nums + } + + /* + + fun sortedSquares(nums: IntArray): IntArray { + return nums.toList().map { it * it }.sorted().toIntArray() + } + + */ +} \ No newline at end of file diff --git a/src/test/kotlin/exercise/easy/id977/Solution977Test.kt b/src/test/kotlin/exercise/easy/id977/Solution977Test.kt new file mode 100644 index 0000000..8b3188a --- /dev/null +++ b/src/test/kotlin/exercise/easy/id977/Solution977Test.kt @@ -0,0 +1,26 @@ +package exercise.easy.id977 + +import io.kotest.assertions.print.print +import io.kotest.core.spec.style.FunSpec +import io.kotest.datatest.WithDataTestName +import io.kotest.datatest.withData +import io.kotest.matchers.shouldBe + +data class TestCase( + val nums: IntArray, + val expected: IntArray, +) : WithDataTestName { + override fun dataTestName(): String = expected.print().value +} + +class Solution977Test : FunSpec({ + context("shouldBe") { + withData( + nameFn = { "Input: ${it.nums.print().value}, Expected: ${it.expected.print().value}" }, + TestCase(nums = intArrayOf(-4, -1, 0, 3, 10), expected = intArrayOf(0, 1, 9, 16, 100)), + TestCase(nums = intArrayOf(-7, -3, 2, 3, 11), expected = intArrayOf(4, 9, 9, 49, 121)), + ) { (nums, expected) -> + Solution977().sortedSquares(nums) shouldBe expected + } + } +}) \ No newline at end of file From f5e082bec41c65e915c1603719e1c1cc93da2646 Mon Sep 17 00:00:00 2001 From: Kotler Date: Mon, 23 Oct 2023 22:10:04 +0300 Subject: [PATCH 10/16] exercise/id977 --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6094ede..16f3746 100644 --- a/README.md +++ b/README.md @@ -47,13 +47,14 @@ My Kotlin exercises with tests from [Leetcode](https://leetcode.com/kotlerdev) #### Array -| ID | Description | Solution | Test | Difficulty | -|:---:|:----------------------------------------------------------------------------------------------|:-----------------------------------------------------------------:|:-----------------------------------------------------------------:|:----------:| +| ID | Description | Solution | Test | Difficulty | +|:---:|:----------------------------------------------------------------------------------------------|:--------------------------------------------------------------:|:--------------------------------------------------------------:|:----------:| | 1 | [Two Sum](src/main/kotlin/exercise/easy/id1/Description1.md) | [solution](src/main/kotlin/exercise/easy/id1/Solution1.kt) | [test](src/test/kotlin/exercise/easy/id1/Solution1Test.kt) | Easy | | 121 | [Best Time to Buy and Sell stock Easy](src/main/kotlin/exercise/easy/id121/Description121.md) | [solution](src/main/kotlin/exercise/easy/id121/Solution121.kt) | [test](src/test/kotlin/exercise/easy/id121/Solution121Test.kt) | Easy | | 169 | [Majority Element](src/main/kotlin/exercise/easy/id169/Description169.md) | [solution](src/main/kotlin/exercise/easy/id169/Solution169.kt) | [test](src/test/kotlin/exercise/easy/id169/Solution169Test.kt) | Easy | | 217 | [Contains Duplicate](src/main/kotlin/exercise/easy/id217/Description217.md) | [solution](src/main/kotlin/exercise/easy/id217/Solution217.kt) | [test](src/test/kotlin/exercise/easy/id217/Solution217Test.kt) | Easy | | 283 | [Move Zeroes](src/main/kotlin/exercise/easy/id283/Description283.md) | [solution](src/main/kotlin/exercise/easy/id283/Solution283.kt) | [test](src/test/kotlin/exercise/easy/id283/Solution283Test.kt) | Easy | +| 977 | [Squares of a Sorted Array](src/main/kotlin/exercise/easy/id977/Description977.md) | [solution](src/main/kotlin/exercise/easy/id977/Solution977.kt) | [test](src/test/kotlin/exercise/easy/id977/Solution977Test.kt) | Easy | [//]: # (https://www.techinterviewhandbook.org/grind75?weeks=26&hours=40&grouping=topics) From 6fc09cd0e09b1eaa4e399e90289e89a3fd6a2898 Mon Sep 17 00:00:00 2001 From: Kotler Date: Wed, 25 Oct 2023 12:03:12 +0300 Subject: [PATCH 11/16] exercise/id57 --- README.md | 1 + .../exercise/medium/id57/Description57.md | 51 ++++++ .../kotlin/exercise/medium/id57/Solution57.kt | 169 ++++++++++++++++++ .../exercise/medium/id57/Solution57Test.kt | 56 ++++++ 4 files changed, 277 insertions(+) create mode 100644 src/main/kotlin/exercise/medium/id57/Description57.md create mode 100644 src/main/kotlin/exercise/medium/id57/Solution57.kt create mode 100644 src/test/kotlin/exercise/medium/id57/Solution57Test.kt diff --git a/README.md b/README.md index 16f3746..2340d56 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ My Kotlin exercises with tests from [Leetcode](https://leetcode.com/kotlerdev) | 217 | [Contains Duplicate](src/main/kotlin/exercise/easy/id217/Description217.md) | [solution](src/main/kotlin/exercise/easy/id217/Solution217.kt) | [test](src/test/kotlin/exercise/easy/id217/Solution217Test.kt) | Easy | | 283 | [Move Zeroes](src/main/kotlin/exercise/easy/id283/Description283.md) | [solution](src/main/kotlin/exercise/easy/id283/Solution283.kt) | [test](src/test/kotlin/exercise/easy/id283/Solution283Test.kt) | Easy | | 977 | [Squares of a Sorted Array](src/main/kotlin/exercise/easy/id977/Description977.md) | [solution](src/main/kotlin/exercise/easy/id977/Solution977.kt) | [test](src/test/kotlin/exercise/easy/id977/Solution977Test.kt) | Easy | +| 57 | [Insert Internal](src/main/kotlin/exercise/medium/id57/Description57.md) | [solution](src/main/kotlin/exercise/medium/id57/Solution57.kt) | [test](src/test/kotlin/exercise/medium/id57/Solution57Test.kt) | Medium | [//]: # (https://www.techinterviewhandbook.org/grind75?weeks=26&hours=40&grouping=topics) diff --git a/src/main/kotlin/exercise/medium/id57/Description57.md b/src/main/kotlin/exercise/medium/id57/Description57.md new file mode 100644 index 0000000..a71c380 --- /dev/null +++ b/src/main/kotlin/exercise/medium/id57/Description57.md @@ -0,0 +1,51 @@ +[//]: # (Copyright [2023] [Anton Kotler kotler.developer@gmail.com] License MIT) + +# Insert Internal + +![Difficulty](https://img.shields.io/badge/Difficulty-Medium-548af7) + +You are given an array of non-overlapping intervals `intervals` where `intervals[i] = [start(i), end(i)]` represent the +start and the end of the `i'th` interval and `intervals` is sorted in ascending order by `start(i)`. You are also given +an interval `newInterval = [start, end]` that represents the start and end of another interval. + +Insert `newInrerval` into `intervals` such that `intervals` is still sorted in ascending order by `start(i)` +and `intervals` still does not have any overlaping intervals (merged overlaping intervals if necessary). + +Return `intervals` after the insertion. + +Example 1: + +``` +Input: intervals = [[1,3], [6,9]], newIntervals = [2,5] +Output: [[1,5],[6,9]] +``` + +Example 2: + +``` +Input: intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], target = 6 +Output: [[1,2],[3,10],[12,16]] +Explanation: Because the new interval [4,8] overlaping with [3,5],[6,7],[8,10] +``` + +Example 3: + +``` +Input: intervals = [3,3], target = 6 +Output: [0,1] +``` + +Constraints: + +- `0 <= intervals.length <= 104` +- `intervals[i].length == 2` +- `0 <= starti <= endi <= 105` +- `intervals` is sorted by `start(i)` in ascending order +- newInterval.length == 2 +- `0 <= start <= end <= 105` + +| ID | Description | Solution | Test | Difficulty | +|:--:|:----------------|:---------------------------:|:--------------------------------------------------------------------------------:|:----------:| +| 57 | Insert Interval | [solution](./Solution57.kt) | [test](../../../../../../src/test/kotlin/exercise/medium/id57/Solution57Test.kt) | Easy | + +:top: [Back to all topics](https://github.com/kotler-dev/kotlin-leetcode) diff --git a/src/main/kotlin/exercise/medium/id57/Solution57.kt b/src/main/kotlin/exercise/medium/id57/Solution57.kt new file mode 100644 index 0000000..8a89914 --- /dev/null +++ b/src/main/kotlin/exercise/medium/id57/Solution57.kt @@ -0,0 +1,169 @@ +package exercise.medium.id57 + +import kotlin.math.max +import kotlin.math.min + +class Solution57 { + fun insert(intervals: Array, newInterval: IntArray): Array { + + if (intervals.isEmpty()) return arrayOf(newInterval) + if (newInterval.isEmpty()) return intervals + + println("[${newInterval[0]}, ${newInterval[1]}]") + + var start = newInterval[0] + var end = newInterval[1] + val left = 0 + val right = 1 + + val merged = mutableListOf() + var index = 0 + while (index < intervals.size && intervals[index][right] < start) { + merged.add(intervals[index]) + index++ + } + + + while (index < intervals.size && intervals[index][left] <= end) { + start = min(start, intervals[index][left]) + end = max(end, intervals[index][right]) + index++ + } + + merged.add(intArrayOf(start, end)) + + while (index < intervals.size) { + merged.add(intervals[index]) + index++ + } + + return merged.toTypedArray() + } + /* + + fun insert(intervals: Array, newInterval: IntArray): Array { + + if (intervals.isEmpty()) return arrayOf(newInterval) + + println("[${newInterval[0]}, ${newInterval[1]}]") + + val start = newInterval[0] + val end = newInterval[1] + val left = 0 + val right = 1 + + val merged1 = mutableListOf() + var index1 = 0 + while (index1 < intervals.size && intervals[index1][right] < start) { + merged1.add(intervals[index1]) + index1++ + } + + if (intervals.size == 1) index1-- + + val merged2 = mutableListOf() + var index2 = intervals.size - 1 + while (index2 >= 0 && intervals[index2][left] > end) { + merged2.add(intervals[index2]) + index2-- + } + + if (intervals.size > 1) { + val min = min(start, intervals[index1][left]) + val max = max(end, intervals[index2][right]) + merged1.add(intArrayOf(min, max)) + } + merged2.forEach { merged1.add(it) } + + return merged1.toTypedArray() + } + + var index2 = index + while (index2 < intervals.size) { + if (intervals[index2][left] > end) { + array.add(intervals[index2]) + index2++ + } + } + + for ((index, arr) in intervals.withIndex()) { + if (arr[right] < start) { + array.add(arr) + } + } + + + while (index < intervals.size ) { + val value = intervals[index][right] + if (value < start) { + array.add(intervals[index]) + } else if (value < intervals[index][leftIndex]) { + intervals[index][right] = end + array.add(intervals[index]) + sliceStart = index + break + } + } + + for (index in intervals.indices) { + val value = intervals[index][rightIndex] + if (value < start) { + array.add(intervals[index]) + } else if (value < intervals[index][leftIndex]) { + intervals[index][rightIndex] = end + array.add(intervals[index]) + sliceStart = index + break + } + } + + fun insert(intervals: Array, newInterval: IntArray): Array { + + println("[${newInterval[0]}, ${newInterval[1]}]") + + val arrayFlatten = mutableListOf() + for (index in intervals.indices) { + arrayFlatten.add(intervals[index][0]) + arrayFlatten.add(intervals[index][1]) + } + + val arrayNonOverlapping = mutableListOf() + for (index in 0.. ${arrayFlatten[index]}") + arrayNonOverlapping.add(arrayFlatten[index]) + + } + } + val arr = mutableListOf() + for (index in 0..arrayNonOverlapping.size - 1 step 2) { + arr.add(intArrayOf(arrayNonOverlapping[index], arrayNonOverlapping[index + 1])) + } + + return arr.toTypedArray() + } + + fun insert(intervals: Array, newInterval: IntArray): Array { + println("[${newInterval[0]}, ${newInterval[1]}]") + val list = intervals.flatMap { it.asIterable() }.toMutableList() + val start = newInterval[0] + val end = newInterval[1] + if (start !in list) list.add(start) + if (end !in list) list.add(end) + list.sort() + var shiftLeft = 1 + var shiftRight = 1 + if (list.size % 2 != 0) shiftLeft-- + val part1: List = list.slice(0.. = list.slice(list.indexOf(end) + shiftRight.. = listOf(part1, part2).flatten() + val arr2 = mutableListOf() + for (index in 0..part3.size - 1 step 2) { + arr2.add(intArrayOf(part3[index], part3[index + 1])) + } + return arr2.toTypedArray() + } + + */ +} \ No newline at end of file diff --git a/src/test/kotlin/exercise/medium/id57/Solution57Test.kt b/src/test/kotlin/exercise/medium/id57/Solution57Test.kt new file mode 100644 index 0000000..171f70b --- /dev/null +++ b/src/test/kotlin/exercise/medium/id57/Solution57Test.kt @@ -0,0 +1,56 @@ +package exercise.medium.id57 + +import io.kotest.assertions.print.print +import io.kotest.core.spec.style.FunSpec +import io.kotest.datatest.WithDataTestName +import io.kotest.datatest.withData +import io.kotest.matchers.shouldBe + +data class TestCase( + val intervals: Array, + val newInterval: IntArray, + val expected: Array, +) : WithDataTestName { + override fun dataTestName(): String = expected.print().value +} + +class Solution57Test : FunSpec({ + context("shouldBe") { + withData( + nameFn = { "Input: ${it.intervals.print().value}, newInterval: ${it.newInterval.print().value}, Expected: ${it.expected.print().value}" }, + TestCase( + intervals = arrayOf( + intArrayOf(1, 2), + intArrayOf(3, 5), + intArrayOf(6, 7), + intArrayOf(8, 10), + intArrayOf(12, 16) + ), + newInterval = intArrayOf(4, 8), + expected = arrayOf(intArrayOf(1, 2), intArrayOf(3, 10), intArrayOf(12, 16)) + ), + TestCase( + intervals = arrayOf(intArrayOf(1, 3), intArrayOf(6, 9)), + newInterval = intArrayOf(2, 5), + expected = arrayOf(intArrayOf(1, 5), intArrayOf(6, 9)) + ), + TestCase( + intervals = arrayOf(), + newInterval = intArrayOf(2, 5), + expected = arrayOf(intArrayOf(2, 5)) + ), + TestCase( + intervals = arrayOf(intArrayOf(1, 5)), + newInterval = intArrayOf(6, 8), + expected = arrayOf(intArrayOf(1, 5), intArrayOf(6, 8)) + ), + TestCase( + intervals = arrayOf(intArrayOf(1, 5)), + newInterval = intArrayOf(2, 3), + expected = arrayOf(intArrayOf(1, 5)) + ) + ) { (intervals, newInterval, expected) -> + Solution57().insert(intervals, newInterval) shouldBe expected + } + } +}) From c7fc5d2450a08bb61a84e38f0728c9bc4213bbe8 Mon Sep 17 00:00:00 2001 From: Kotler Date: Wed, 25 Oct 2023 12:09:10 +0300 Subject: [PATCH 12/16] exercise/id57 --- src/main/kotlin/exercise/medium/id57/Description57.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/exercise/medium/id57/Description57.md b/src/main/kotlin/exercise/medium/id57/Description57.md index a71c380..941e408 100644 --- a/src/main/kotlin/exercise/medium/id57/Description57.md +++ b/src/main/kotlin/exercise/medium/id57/Description57.md @@ -46,6 +46,6 @@ Constraints: | ID | Description | Solution | Test | Difficulty | |:--:|:----------------|:---------------------------:|:--------------------------------------------------------------------------------:|:----------:| -| 57 | Insert Interval | [solution](./Solution57.kt) | [test](../../../../../../src/test/kotlin/exercise/medium/id57/Solution57Test.kt) | Easy | +| 57 | Insert Interval | [solution](./Solution57.kt) | [test](../../../../../../src/test/kotlin/exercise/medium/id57/Solution57Test.kt) | Medium | :top: [Back to all topics](https://github.com/kotler-dev/kotlin-leetcode) From 00f23e9c8d5765bdc5080ea2a8e74a80132b4915 Mon Sep 17 00:00:00 2001 From: Kotler Date: Wed, 25 Oct 2023 22:43:42 +0300 Subject: [PATCH 13/16] exercise/id3 --- README.md | 10 ++++- .../exercise/medium/id3/Description3.md | 42 +++++++++++++++++++ .../kotlin/exercise/medium/id3/Solution3.kt | 17 ++++++++ .../exercise/medium/id3/Solution3Test.kt | 22 ++++++++++ 4 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 src/main/kotlin/exercise/medium/id3/Description3.md create mode 100644 src/main/kotlin/exercise/medium/id3/Solution3.kt create mode 100644 src/test/kotlin/exercise/medium/id3/Solution3Test.kt diff --git a/README.md b/README.md index 2340d56..03880ba 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ My Kotlin exercises with tests from [Leetcode](https://leetcode.com/kotlerdev) [//]: # (- [Linked List](#linked-list)) -[//]: # (- [String](#string)) +- [String](#string) [//]: # (- [Binary Tree](#binary-tree)) @@ -55,7 +55,13 @@ My Kotlin exercises with tests from [Leetcode](https://leetcode.com/kotlerdev) | 217 | [Contains Duplicate](src/main/kotlin/exercise/easy/id217/Description217.md) | [solution](src/main/kotlin/exercise/easy/id217/Solution217.kt) | [test](src/test/kotlin/exercise/easy/id217/Solution217Test.kt) | Easy | | 283 | [Move Zeroes](src/main/kotlin/exercise/easy/id283/Description283.md) | [solution](src/main/kotlin/exercise/easy/id283/Solution283.kt) | [test](src/test/kotlin/exercise/easy/id283/Solution283Test.kt) | Easy | | 977 | [Squares of a Sorted Array](src/main/kotlin/exercise/easy/id977/Description977.md) | [solution](src/main/kotlin/exercise/easy/id977/Solution977.kt) | [test](src/test/kotlin/exercise/easy/id977/Solution977Test.kt) | Easy | -| 57 | [Insert Internal](src/main/kotlin/exercise/medium/id57/Description57.md) | [solution](src/main/kotlin/exercise/medium/id57/Solution57.kt) | [test](src/test/kotlin/exercise/medium/id57/Solution57Test.kt) | Medium | +| 57 | [Insert Internal](src/main/kotlin/exercise/medium/id57/Description57.md) | [solution](src/main/kotlin/exercise/medium/id57/Solution57.kt) | [test](src/test/kotlin/exercise/medium/id57/Solution57Test.kt) | Medium | + +#### String + +| ID | Description | Solution | Test | Difficulty | +|:--:|:------------------------------------------------------------------------------------------------------|:------------------------------------------------------------:|:------------------------------------------------------------:|:----------:| +| 3 | [Longest Substring Without Repeating Characters](src/main/kotlin/exercise/medium/id3/Description3.md) | [solution](src/main/kotlin/exercise/medium/id3/Solution3.kt) | [test](src/test/kotlin/exercise/medium/id3/Solution3Test.kt) | Medium | [//]: # (https://www.techinterviewhandbook.org/grind75?weeks=26&hours=40&grouping=topics) diff --git a/src/main/kotlin/exercise/medium/id3/Description3.md b/src/main/kotlin/exercise/medium/id3/Description3.md new file mode 100644 index 0000000..c059829 --- /dev/null +++ b/src/main/kotlin/exercise/medium/id3/Description3.md @@ -0,0 +1,42 @@ +[//]: # (Copyright [2023] [Anton Kotler kotler.developer@gmail.com] License MIT) + +# Longest Substring Without Repeating Characters + +![Difficulty](https://img.shields.io/badge/Difficulty-Medium-548af7) + +Given a string `s`, find the length of the longest substring without repeating characters. + +Example 1: + +``` +Input: s = "abcabcbb" +Output: 3 +``` + +Example 2: + +``` +Input: s = "bbbbb" +Output: 1 +Explanation: The answer is `b`, with the length of 1. +``` + +Example 3: + +``` +Input: s = "pwwkew" +Output: 3 +Explanation: The answer is `wke`, with the length of 3. +Notice that the answer must be a substring, `pwke` is a subsequence and not a substring. +``` + +Constraints: + +- `0 <= s.length <= 5 * 10^4` +- `s` consists of English letters, digits, symbols and spaces. + +| ID | Description | Solution | Test | Difficulty | +|:--:|:-----------------------------------------------|:--------------------------:|:------------------------------------------------------------------------------:|:----------:| +| 3 | Longest Substring Without Repeating Characters | [solution](./Solution3.kt) | [test](../../../../../../src/test/kotlin/exercise/medium/id3/Solution3Test.kt) | Medium | + +:top: [Back to all topics](https://github.com/kotler-dev/kotlin-leetcode) diff --git a/src/main/kotlin/exercise/medium/id3/Solution3.kt b/src/main/kotlin/exercise/medium/id3/Solution3.kt new file mode 100644 index 0000000..ef051d7 --- /dev/null +++ b/src/main/kotlin/exercise/medium/id3/Solution3.kt @@ -0,0 +1,17 @@ +package exercise.medium.id3 + + +class Solution3 { + fun lengthOfLongestSubstring(s: String): Int { + + var longest: String + + return 0 + } + +/* + + + +*/ +} \ No newline at end of file diff --git a/src/test/kotlin/exercise/medium/id3/Solution3Test.kt b/src/test/kotlin/exercise/medium/id3/Solution3Test.kt new file mode 100644 index 0000000..138e1b0 --- /dev/null +++ b/src/test/kotlin/exercise/medium/id3/Solution3Test.kt @@ -0,0 +1,22 @@ +package exercise.medium.id3 + +import io.kotest.assertions.print.print +import io.kotest.core.spec.style.FunSpec +import io.kotest.datatest.withData +import io.kotest.matchers.shouldBe + +data class TestCase(val s: String, val expected: Int) + +class Solution3Test : FunSpec({ + + context(name = "shouldBe") { + withData( + nameFn = { "s: ${it.s.print().value}, expected: ${it.expected.print().value}" }, + TestCase("abcabcbb", expected = 3), + TestCase("bbbbb", expected = 1), + TestCase("pwwkew", expected = 3), + ) { (s, expected) -> + Solution3().lengthOfLongestSubstring(s) shouldBe expected + } + } +}) From 3975d761200a5355f71ffd1fecf672b7912e1847 Mon Sep 17 00:00:00 2001 From: Kotler Date: Thu, 26 Oct 2023 14:54:00 +0300 Subject: [PATCH 14/16] exercise/id3 --- .../kotlin/exercise/medium/id3/Solution3.kt | 75 ++++++++++++++++++- .../exercise/medium/id3/Solution3Test.kt | 9 +++ 2 files changed, 82 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/exercise/medium/id3/Solution3.kt b/src/main/kotlin/exercise/medium/id3/Solution3.kt index ef051d7..88fdaa3 100644 --- a/src/main/kotlin/exercise/medium/id3/Solution3.kt +++ b/src/main/kotlin/exercise/medium/id3/Solution3.kt @@ -4,14 +4,85 @@ package exercise.medium.id3 class Solution3 { fun lengthOfLongestSubstring(s: String): Int { - var longest: String + if (s.length == 0) return 0 + if (s.length == 1) return 1 - return 0 + var longest: String = "" + var maxLength: Int = 0 + var start = 0 + + + for (l in start.. maxLength) maxLength = longest.length + } else { + if (longest.length > maxLength) maxLength = longest.length + println("s: ${s}, longest: ${longest}") + longest = "" + s[i] + } + } + start += longest.length - 1 + } + return maxLength } /* + // Output Limit Exceeded + fun lengthOfLongestSubstring(s: String): Int { + + if (s.length == 0) return 0 + if (s.length == 1) return 1 + var longest: String = "" + var maxLength: Int = 0 + + for (l in 0.. maxLength) maxLength = longest.length + } else { + if (longest.length > maxLength) maxLength = longest.length + println("s: ${s}, longest: ${longest}") + longest = "" + s[i] + } + } + } + return maxLength + } + + fun lengthOfLongestSubstring(s: String): Int { + + if (s.length == 0) return 0 + if (s.length == 1) return 1 + + var longest: String = "" + var maxLength: Int = 0 + + // прохождение по символу всей строки + // символ + 1 != (входит в подстроку) увеличить макс длину вложенной строки + // если встретился повторный символ, сброс подстроки + + for (index in 0.. maxLength) maxLength = longest.length + } else { + if (longest.length > maxLength) maxLength = longest.length + println("s: ${s}, longest: ${longest}") + longest = "" + s[index] + } + } + return maxLength + } */ } \ No newline at end of file diff --git a/src/test/kotlin/exercise/medium/id3/Solution3Test.kt b/src/test/kotlin/exercise/medium/id3/Solution3Test.kt index 138e1b0..a88bcfd 100644 --- a/src/test/kotlin/exercise/medium/id3/Solution3Test.kt +++ b/src/test/kotlin/exercise/medium/id3/Solution3Test.kt @@ -15,6 +15,15 @@ class Solution3Test : FunSpec({ TestCase("abcabcbb", expected = 3), TestCase("bbbbb", expected = 1), TestCase("pwwkew", expected = 3), + TestCase(" ", expected = 1), + TestCase("", expected = 0), + TestCase("au", expected = 2), + TestCase("dvdf", expected = 3), + TestCase("asjrgapa", expected = 6), +// TestCase( +// "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCD", +// expected = 6 +// ), ) { (s, expected) -> Solution3().lengthOfLongestSubstring(s) shouldBe expected } From b45c728a6c68f1237f8b905189e686445593e830 Mon Sep 17 00:00:00 2001 From: Kotler Date: Sat, 28 Oct 2023 00:31:25 +0300 Subject: [PATCH 15/16] exercise/id15 --- README.md | 1 + .../exercise/medium/id15/Description15.md | 49 +++++++++++++++++++ .../kotlin/exercise/medium/id15/Solution15.kt | 41 ++++++++++++++++ .../exercise/medium/id15/Solution15Test.kt | 42 ++++++++++++++++ 4 files changed, 133 insertions(+) create mode 100644 src/main/kotlin/exercise/medium/id15/Description15.md create mode 100644 src/main/kotlin/exercise/medium/id15/Solution15.kt create mode 100644 src/test/kotlin/exercise/medium/id15/Solution15Test.kt diff --git a/README.md b/README.md index 03880ba..290427c 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ My Kotlin exercises with tests from [Leetcode](https://leetcode.com/kotlerdev) | 217 | [Contains Duplicate](src/main/kotlin/exercise/easy/id217/Description217.md) | [solution](src/main/kotlin/exercise/easy/id217/Solution217.kt) | [test](src/test/kotlin/exercise/easy/id217/Solution217Test.kt) | Easy | | 283 | [Move Zeroes](src/main/kotlin/exercise/easy/id283/Description283.md) | [solution](src/main/kotlin/exercise/easy/id283/Solution283.kt) | [test](src/test/kotlin/exercise/easy/id283/Solution283Test.kt) | Easy | | 977 | [Squares of a Sorted Array](src/main/kotlin/exercise/easy/id977/Description977.md) | [solution](src/main/kotlin/exercise/easy/id977/Solution977.kt) | [test](src/test/kotlin/exercise/easy/id977/Solution977Test.kt) | Easy | +| 15 | [3Sum](src/main/kotlin/exercise/medium/id15/Description15.md) | [solution](src/main/kotlin/exercise/medium/id15/Solution15.kt) | [test](src/test/kotlin/exercise/medium/id15/Solution15Test.kt) | Medium | | 57 | [Insert Internal](src/main/kotlin/exercise/medium/id57/Description57.md) | [solution](src/main/kotlin/exercise/medium/id57/Solution57.kt) | [test](src/test/kotlin/exercise/medium/id57/Solution57Test.kt) | Medium | #### String diff --git a/src/main/kotlin/exercise/medium/id15/Description15.md b/src/main/kotlin/exercise/medium/id15/Description15.md new file mode 100644 index 0000000..4d10e1b --- /dev/null +++ b/src/main/kotlin/exercise/medium/id15/Description15.md @@ -0,0 +1,49 @@ +[//]: # (Copyright [2023] [Anton Kotler kotler.developer@gmail.com] License MIT) + +# 3Sum + +![Difficulty](https://img.shields.io/badge/Difficulty-Medium-548af7) + +Given an integer array nums, return all the triples `[nums[i], nums[j]], nums[k]]`, such that `i != j`, `i != k`, +and `j != k`, and `nums[i] + nums[j] + nums[k] == 0`. +Notice that the solution set must not contain duplicate triplets. + +Example 1: + +``` +Input: nums = [-1,0,1,2,-1,-4] +Output: [[-1,-1,2],[-1,0,1]] +Explanation: +nums[0] + nums[1] + nums[2] = (-1) + 0 + 1 = 0. +nums[1] + nums[2] + nums[4] = 0 + 1 + (-1) = 0. +nums[0] + nums[3] + nums[4] = (-1) + 2 + (-1) = 0. +The distinct triplets are [-1,0,1] and [-1,-1,2]. +Notice that the order of the output and the order of the triplets does not matter. +``` + +Example 2: + +``` +Input: nums = [0,1,1] +Output: [] +Explanation: The only possible triplet does not sum up to 0. +``` + +Example 3: + +``` +Input: nums = [0,0,0] +Output: [[0,0,0]] +Explanation: The only possible triplet sums up to 0. +``` + +Constraints: + +- `3 <= nums.length <= 3000` +- `-10^5 <= nums[i] <= 10^5` + +| ID | Description | Solution | Test | Difficulty | +|:--:|:------------|:---------------------------:|:--------------------------------------------------------------------------------:|:----------:| +| 15 | 3Sum | [solution](./Solution15.kt) | [test](../../../../../../src/test/kotlin/exercise/medium/id15/Solution15Test.kt) | Medium | + +:top: [Back to all topics](https://github.com/kotler-dev/kotlin-leetcode) diff --git a/src/main/kotlin/exercise/medium/id15/Solution15.kt b/src/main/kotlin/exercise/medium/id15/Solution15.kt new file mode 100644 index 0000000..c634b43 --- /dev/null +++ b/src/main/kotlin/exercise/medium/id15/Solution15.kt @@ -0,0 +1,41 @@ +package exercise.medium.id15 + + +class Solution15 { + fun threeSum(nums: IntArray): List> { + if (nums.isEmpty() || nums.size < 3) return emptyList() + + val numList = mutableListOf>() + var currentIndex = 0 + + + while (currentIndex < nums.size) { + var shiftIndex = 0 + val list = mutableListOf(0, 0, 0) + list[0] = nums[currentIndex] + var step = 1 + + while (shiftIndex < nums.size) { + if (shiftIndex != currentIndex) { + list[step] = nums[shiftIndex] + step++ + if (step == 3) { + println("current: ${currentIndex}, list3: ${list}") +// if ((list[0] != list[1]) && (list[0] != list[2]) && (list[1] != list[2])) { + if ((list[0] + list[1] + list[2] == 0)) { + list.sort() + if (list !in numList) numList.add(list.toList()) + } + step = 1 + shiftIndex-- + } + } + shiftIndex++ + } + currentIndex++ + } + println(numList) + + return numList + } +} \ No newline at end of file diff --git a/src/test/kotlin/exercise/medium/id15/Solution15Test.kt b/src/test/kotlin/exercise/medium/id15/Solution15Test.kt new file mode 100644 index 0000000..b80214a --- /dev/null +++ b/src/test/kotlin/exercise/medium/id15/Solution15Test.kt @@ -0,0 +1,42 @@ +package exercise.medium.id15 + +import io.kotest.assertions.print.print +import io.kotest.core.spec.style.FunSpec +import io.kotest.datatest.withData +import io.kotest.matchers.collections.shouldContainAll +import io.kotest.matchers.equals.shouldBeEqual +import io.kotest.matchers.shouldBe + +data class TestCase(val nums: IntArray, val expected: List>) + +class Solution15Test : FunSpec({ + + context("shouldBe") { + withData( + nameFn = { "${it.nums.print().value}, expected: ${it.expected.print().value}" }, + TestCase( + nums = intArrayOf(-1, 0, 1, 2, -1, -4, -2, -3, 3, 0, 4), expected = listOf( + listOf(-4, 0, 4), + listOf(-4, 1, 3), + listOf(-3, -1, 4), + listOf(-3, 0, 3), + listOf(-3, 1, 2), + listOf(-2, -1, 3), + listOf(-2, 0, 2), + listOf(-1, -1, 2), + listOf(-1, 0, 1), + ) + ), + TestCase( + nums = intArrayOf(3, 0, -2, -1, 1, 2), + expected = listOf(listOf(-2, -1, 3), listOf(-2, 0, 2), listOf(-1, 0, 1)) + ), + TestCase(nums = intArrayOf(-1, 0, 1, 2, -1, -4), expected = listOf(listOf(-1, -1, 2), listOf(-1, 0, 1))), + TestCase(nums = intArrayOf(0, 0, 0), expected = listOf(listOf(0, 0, 0))), + TestCase(nums = intArrayOf(0, 0, 0, 0), expected = listOf(listOf(0, 0, 0))), + TestCase(nums = intArrayOf(0, 1, 1), expected = emptyList()), + ) { (nums, expected) -> + Solution15().threeSum(nums) shouldContainAll expected + } + } +}) From 729f38d4cf6fa92a4048c83f764128373bd5075e Mon Sep 17 00:00:00 2001 From: Kotler Date: Sat, 28 Oct 2023 21:32:59 +0300 Subject: [PATCH 16/16] exercise/id238 --- README.md | 21 +++++----- .../exercise/medium/id238/Description238.md | 39 +++++++++++++++++++ .../exercise/medium/id238/Solution238.kt | 16 ++++++++ .../exercise/medium/id238/Solution238Test.kt | 20 ++++++++++ 4 files changed, 86 insertions(+), 10 deletions(-) create mode 100644 src/main/kotlin/exercise/medium/id238/Description238.md create mode 100644 src/main/kotlin/exercise/medium/id238/Solution238.kt create mode 100644 src/test/kotlin/exercise/medium/id238/Solution238Test.kt diff --git a/README.md b/README.md index 290427c..4ad11d6 100644 --- a/README.md +++ b/README.md @@ -47,16 +47,17 @@ My Kotlin exercises with tests from [Leetcode](https://leetcode.com/kotlerdev) #### Array -| ID | Description | Solution | Test | Difficulty | -|:---:|:----------------------------------------------------------------------------------------------|:--------------------------------------------------------------:|:--------------------------------------------------------------:|:----------:| -| 1 | [Two Sum](src/main/kotlin/exercise/easy/id1/Description1.md) | [solution](src/main/kotlin/exercise/easy/id1/Solution1.kt) | [test](src/test/kotlin/exercise/easy/id1/Solution1Test.kt) | Easy | -| 121 | [Best Time to Buy and Sell stock Easy](src/main/kotlin/exercise/easy/id121/Description121.md) | [solution](src/main/kotlin/exercise/easy/id121/Solution121.kt) | [test](src/test/kotlin/exercise/easy/id121/Solution121Test.kt) | Easy | -| 169 | [Majority Element](src/main/kotlin/exercise/easy/id169/Description169.md) | [solution](src/main/kotlin/exercise/easy/id169/Solution169.kt) | [test](src/test/kotlin/exercise/easy/id169/Solution169Test.kt) | Easy | -| 217 | [Contains Duplicate](src/main/kotlin/exercise/easy/id217/Description217.md) | [solution](src/main/kotlin/exercise/easy/id217/Solution217.kt) | [test](src/test/kotlin/exercise/easy/id217/Solution217Test.kt) | Easy | -| 283 | [Move Zeroes](src/main/kotlin/exercise/easy/id283/Description283.md) | [solution](src/main/kotlin/exercise/easy/id283/Solution283.kt) | [test](src/test/kotlin/exercise/easy/id283/Solution283Test.kt) | Easy | -| 977 | [Squares of a Sorted Array](src/main/kotlin/exercise/easy/id977/Description977.md) | [solution](src/main/kotlin/exercise/easy/id977/Solution977.kt) | [test](src/test/kotlin/exercise/easy/id977/Solution977Test.kt) | Easy | -| 15 | [3Sum](src/main/kotlin/exercise/medium/id15/Description15.md) | [solution](src/main/kotlin/exercise/medium/id15/Solution15.kt) | [test](src/test/kotlin/exercise/medium/id15/Solution15Test.kt) | Medium | -| 57 | [Insert Internal](src/main/kotlin/exercise/medium/id57/Description57.md) | [solution](src/main/kotlin/exercise/medium/id57/Solution57.kt) | [test](src/test/kotlin/exercise/medium/id57/Solution57Test.kt) | Medium | +| ID | Description | Solution | Test | Difficulty | +|:---:|:----------------------------------------------------------------------------------------------|:----------------------------------------------------------------:|:----------------------------------------------------------------:|:----------:| +| 1 | [Two Sum](src/main/kotlin/exercise/easy/id1/Description1.md) | [solution](src/main/kotlin/exercise/easy/id1/Solution1.kt) | [test](src/test/kotlin/exercise/easy/id1/Solution1Test.kt) | Easy | +| 121 | [Best Time to Buy and Sell stock Easy](src/main/kotlin/exercise/easy/id121/Description121.md) | [solution](src/main/kotlin/exercise/easy/id121/Solution121.kt) | [test](src/test/kotlin/exercise/easy/id121/Solution121Test.kt) | Easy | +| 169 | [Majority Element](src/main/kotlin/exercise/easy/id169/Description169.md) | [solution](src/main/kotlin/exercise/easy/id169/Solution169.kt) | [test](src/test/kotlin/exercise/easy/id169/Solution169Test.kt) | Easy | +| 217 | [Contains Duplicate](src/main/kotlin/exercise/easy/id217/Description217.md) | [solution](src/main/kotlin/exercise/easy/id217/Solution217.kt) | [test](src/test/kotlin/exercise/easy/id217/Solution217Test.kt) | Easy | +| 283 | [Move Zeroes](src/main/kotlin/exercise/easy/id283/Description283.md) | [solution](src/main/kotlin/exercise/easy/id283/Solution283.kt) | [test](src/test/kotlin/exercise/easy/id283/Solution283Test.kt) | Easy | +| 977 | [Squares of a Sorted Array](src/main/kotlin/exercise/easy/id977/Description977.md) | [solution](src/main/kotlin/exercise/easy/id977/Solution977.kt) | [test](src/test/kotlin/exercise/easy/id977/Solution977Test.kt) | Easy | +| 15 | [3Sum](src/main/kotlin/exercise/medium/id15/Description15.md) | [solution](src/main/kotlin/exercise/medium/id15/Solution15.kt) | [test](src/test/kotlin/exercise/medium/id15/Solution15Test.kt) | Medium | +| 57 | [Insert Internal](src/main/kotlin/exercise/medium/id57/Description57.md) | [solution](src/main/kotlin/exercise/medium/id57/Solution57.kt) | [test](src/test/kotlin/exercise/medium/id57/Solution57Test.kt) | Medium | +| 238 | [Product of Array Except Self](src/main/kotlin/exercise/medium/id238/Description238.md) | [solution](src/main/kotlin/exercise/medium/id238/Solution238.kt) | [test](src/test/kotlin/exercise/medium/id238/Solution238Test.kt) | Medium | #### String diff --git a/src/main/kotlin/exercise/medium/id238/Description238.md b/src/main/kotlin/exercise/medium/id238/Description238.md new file mode 100644 index 0000000..06ef3bf --- /dev/null +++ b/src/main/kotlin/exercise/medium/id238/Description238.md @@ -0,0 +1,39 @@ +[//]: # (Copyright [2023] [Anton Kotler kotler.developer@gmail.com] License MIT) + +# Product of Array Except Self + +![Difficulty](https://img.shields.io/badge/Difficulty-Medium-548af7) + +Given an integer array `nums`, return an array `answer` such that `answer[i]` is equal ti the product of all the +elements of `nums` except `nums[i]`. +The product of any prefix or suffix of `nums` is guaranteed to fit in a 32-bit integer. +You must write an algorithm that runs in `O(n)` time and without using the division operation. + +Example 1: + +``` +Input: nums = [1,2,3,4] +Output: [24,12,8,6] +``` + +Example 2: + +``` +Input: nums = [-1,1,0,-3,3] +Output: [0,0,9,0,0] +``` + +Constraints: + +- `2 <= nums.length <= 10^5` +- `-30 <= nums[i] <= 30` +- The product of any prefix or suffix of `nums` is guaranteed to fit in a 32-bit integer. + +Follow up: Can uou solve the problem in `O(1)` extra space complexity? +The output array does not count as extra space for space complexity analysis. + +| ID | Description | Solution | Test | Difficulty | +|:---:|:-----------------------------|:----------------------------:|:----------------------------------------------------------------------------------:|:----------:| +| 238 | Product of Array Except Self | [solution](./Solution238.kt) | [test](../../../../../../src/test/kotlin/exercise/medium/id238/Solution238Test.kt) | Medium | + +:top: [Back to all topics](https://github.com/kotler-dev/kotlin-leetcode) diff --git a/src/main/kotlin/exercise/medium/id238/Solution238.kt b/src/main/kotlin/exercise/medium/id238/Solution238.kt new file mode 100644 index 0000000..a41f233 --- /dev/null +++ b/src/main/kotlin/exercise/medium/id238/Solution238.kt @@ -0,0 +1,16 @@ +package exercise.medium.id238 + + +class Solution238 { + fun productExceptSelf(nums: IntArray): IntArray { + val result = IntArray(nums.size) + for (i in nums.indices) { + var acc = 1 + for (j in nums.indices) { + if (i != j) acc *= nums[j] + } + result[i] = acc + } + return result + } +} \ No newline at end of file diff --git a/src/test/kotlin/exercise/medium/id238/Solution238Test.kt b/src/test/kotlin/exercise/medium/id238/Solution238Test.kt new file mode 100644 index 0000000..ca46b3a --- /dev/null +++ b/src/test/kotlin/exercise/medium/id238/Solution238Test.kt @@ -0,0 +1,20 @@ +package exercise.medium.id238 + +import io.kotest.assertions.print.print +import io.kotest.core.spec.style.FunSpec +import io.kotest.datatest.withData +import io.kotest.matchers.shouldBe + +data class TestCase(val nums: IntArray, val expected: IntArray) + +class Solution238Test : FunSpec({ + context("shouldBe") { + withData( + nameFn = { "nums: ${it.nums.print().value}, expected: ${it.expected.print().value}" }, + TestCase(nums = intArrayOf(1, 2, 3, 4), expected = intArrayOf(24, 12, 8, 6)), + TestCase(nums = intArrayOf(-1, 1, 0, -3, 3), expected = intArrayOf(0, 0, 9, 0, 0)), + ) { (nums, expected) -> + Solution238().productExceptSelf(nums) shouldBe expected + } + } +})