Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
b9137d7
add 2537
Ashwagandha-coder Apr 16, 2025
705b312
add 2537 hashmap approach
Ashwagandha-coder Apr 16, 2025
62106d7
del comments
Ashwagandha-coder Apr 16, 2025
d336421
add 169
Ashwagandha-coder Apr 17, 2025
2fae4f8
add 2176
Ashwagandha-coder Apr 17, 2025
441255b
add 38
Ashwagandha-coder Apr 18, 2025
2b90bf1
new problem in progress
Ashwagandha-coder Apr 20, 2025
781180f
add 1399
Ashwagandha-coder Apr 23, 2025
0ebf441
add 2799
Ashwagandha-coder Apr 24, 2025
5195f0d
add 2799 prod variant
Ashwagandha-coder Apr 25, 2025
2160d93
add 58 easy problem
Ashwagandha-coder Apr 25, 2025
db8605c
add 58 prod variant
Ashwagandha-coder Apr 25, 2025
d8facc1
add 12
Ashwagandha-coder Apr 25, 2025
21d80fa
add 12 prod variant
Ashwagandha-coder Apr 25, 2025
553a57d
change for estetic
Ashwagandha-coder Apr 25, 2025
dccae42
add 380
Ashwagandha-coder Apr 26, 2025
fc8b82b
add 42
Ashwagandha-coder Apr 27, 2025
dac7287
add 55
Ashwagandha-coder Apr 27, 2025
97d6228
add 55 alt sol
Ashwagandha-coder Apr 27, 2025
a8ea181
add 45
Ashwagandha-coder Apr 28, 2025
a73b0d4
add 189
Ashwagandha-coder Apr 28, 2025
0491963
small change
Ashwagandha-coder Apr 28, 2025
b505a52
add 3392
Ashwagandha-coder Apr 28, 2025
1697528
add 30
Ashwagandha-coder Apr 30, 2025
0289d5f
add prod variants for 30
Ashwagandha-coder Apr 30, 2025
a4b6d5a
add 3392 prod variant
Ashwagandha-coder Apr 30, 2025
bcaeacf
add 1295
Ashwagandha-coder Apr 30, 2025
7adaf0f
change README.md
Ashwagandha-coder Apr 30, 2025
c01d445
add 2962
Ashwagandha-coder Apr 30, 2025
45a2ee2
change comments
Ashwagandha-coder Apr 30, 2025
cd931f6
add 228
Ashwagandha-coder May 1, 2025
b922510
saving
Ashwagandha-coder May 1, 2025
aaa4f18
add 1128
Ashwagandha-coder May 4, 2025
c127efe
add 1128 prod variant
Ashwagandha-coder May 5, 2025
7773fc6
add 1920
Ashwagandha-coder May 6, 2025
ff76035
add 56
Ashwagandha-coder May 7, 2025
e05c039
add 56 for prod variant
Ashwagandha-coder May 7, 2025
14b6f52
add new prod variant
Ashwagandha-coder May 7, 2025
ebf47db
add 1920 prod variant
Ashwagandha-coder May 7, 2025
97aada2
add 209
Ashwagandha-coder May 7, 2025
b9762b1
add 992
Ashwagandha-coder May 8, 2025
b250072
add 2062
Ashwagandha-coder May 9, 2025
28ae95a
save execute
Ashwagandha-coder May 9, 2025
53f6450
add 2062 hash map variant
Ashwagandha-coder May 9, 2025
5124568
add 2062 prod variant
Ashwagandha-coder May 9, 2025
ee51f9a
add yet prod variants for 2062
Ashwagandha-coder May 9, 2025
60fc210
add 3364
Ashwagandha-coder May 9, 2025
3751203
add two variants with todo
Ashwagandha-coder May 9, 2025
a8a0f31
small change 3364
Ashwagandha-coder May 11, 2025
a93b9cd
add 2918
Ashwagandha-coder May 11, 2025
b68de14
save exe
Ashwagandha-coder May 11, 2025
0e2ec6e
add 1550
Ashwagandha-coder May 11, 2025
6c9171e
add prod variants for 1550 and middle element ext fun
Ashwagandha-coder May 11, 2025
07c5469
add 2094 in hashMap
Ashwagandha-coder May 12, 2025
264beb3
add 2094 alternative solution
Ashwagandha-coder May 12, 2025
90dc0ae
add impl rabin - karp and 187 problem
Ashwagandha-coder May 13, 2025
b92c78a
add prod variant for 187
Ashwagandha-coder May 13, 2025
8f39780
change exe
Ashwagandha-coder May 13, 2025
a967948
add 1044 rabin karp
Ashwagandha-coder May 14, 2025
0e50fe9
add 1763
Ashwagandha-coder May 14, 2025
84da99d
add 3024
Ashwagandha-coder May 19, 2025
204efc4
add 2653
Ashwagandha-coder May 19, 2025
54d091b
add 2760
Ashwagandha-coder May 19, 2025
cc2a0c0
add 2760 alt sol
Ashwagandha-coder May 20, 2025
2a9b1dd
add 2653
Ashwagandha-coder May 20, 2025
e2068ac
change location 73 set zeros matrix
Ashwagandha-coder May 21, 2025
a911a48
add 3355
Ashwagandha-coder May 22, 2025
30622df
add 1052
Ashwagandha-coder May 22, 2025
89493b6
add 1052 prod variant
Ashwagandha-coder May 22, 2025
cc4195f
add yet prod variant
Ashwagandha-coder May 22, 2025
249fb06
add 2932
Ashwagandha-coder May 23, 2025
3ba11d3
add 3090
Ashwagandha-coder May 24, 2025
53a186e
add 2398
Ashwagandha-coder May 24, 2025
762f062
add 413
Ashwagandha-coder May 24, 2025
bfeea60
add 413 alt sol
Ashwagandha-coder May 24, 2025
36ecd96
add 2131
Ashwagandha-coder May 25, 2025
2fdee3e
add 2131 alt sol
Ashwagandha-coder May 25, 2025
3fd5e06
add 3206
Ashwagandha-coder May 26, 2025
a48d2a6
add 1652
Ashwagandha-coder May 26, 2025
bc7afaa
add 594
Ashwagandha-coder May 27, 2025
6abf309
add 594 prod variant
Ashwagandha-coder May 27, 2025
447ee35
add yet variant
Ashwagandha-coder May 27, 2025
eceea88
add 284
Ashwagandha-coder May 29, 2025
ede2ed6
small change
Ashwagandha-coder May 29, 2025
034db12
add 1286
Ashwagandha-coder May 30, 2025
5183eb0
add 341
Ashwagandha-coder Jun 1, 2025
661f4d7
add 341
Ashwagandha-coder Jun 1, 2025
33b4dd4
add 900
Ashwagandha-coder Jun 2, 2025
54d6692
add 438
Ashwagandha-coder Jun 3, 2025
8f5167c
small changes
Ashwagandha-coder Jun 3, 2025
a9c2d15
add 933
Ashwagandha-coder Jun 4, 2025
d0c5583
add 901
Ashwagandha-coder Jun 4, 2025
8cbcfbd
add 3442
Ashwagandha-coder Jun 10, 2025
42a1acf
add 2016
Ashwagandha-coder Jun 16, 2025
0191c5e
add 2016 alternative solution
Ashwagandha-coder Jun 16, 2025
6bd6675
add 2016
Ashwagandha-coder Jun 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
# solution algorithm problems
# Contest Kotlin

![Kotlin](https://img.shields.io/badge/kotlin-%237F52FF.svg?style=for-the-badge&logo=kotlin&logoColor=white)
![Android Studio](https://img.shields.io/badge/Android%20Studio-3DDC84.svg?style=for-the-badge&logo=android-studio&logoColor=white)

## Task
# Description

This repository contains problems of leetcode. We might use this repo how get solution for define
problem from leetcode. Also We might clone this repo and run or debug problems in android studio.

# How to use

1. Each problem will be in contest module
2. Each problem have a few solutions. Main solution with using down level code. Alternative Solution
with other approaches. Prod Variant - this code might be in prod in application or service. This
code using std lib kotlin
3. For search each problem have kotlin doc with name and number problem. Also each problem have tag
for commit for search in github.
4. Each Topic have package which contains problem

- [leetcode task](app/src/main/java/com/leetcode_kotlin/AlgorithmLeetcode.kt)
- [codeWars task](app/src/main/java/com/leetcode_kotlin/AlgorithmCodeWars.kt)
30 changes: 0 additions & 30 deletions app/src/main/java/com/leetcode_kotlin/AlgorithmLeetcode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -578,36 +578,6 @@ fun findDuplicates(nums: IntArray): List<Int> {
return ans
}

/**
* 73. Set Matrix Zeroes
*/


fun setZeroes(matrix: Array<IntArray>) {
val m = matrix.size
val n = matrix[0].size

val forRows = BooleanArray(m)
val forCols = BooleanArray(n)

for (i in 0 until m) {
for (j in 0 until n) {
if (matrix[i][j] == 0) {
forRows[i] = true
forCols[j] = true
}
}
}


for (i in 0 until m) {
for (j in 0 until n) {
if (forRows[i] || forCols[j]) {
matrix[i][j] = 0
}
}
}
}

/**
* 48. Rotate Image
Expand Down
37 changes: 0 additions & 37 deletions app/src/main/java/com/leetcode_kotlin/AlgorithmProdVariant.kt
Original file line number Diff line number Diff line change
Expand Up @@ -580,43 +580,6 @@ fun heightProdVariant(root: TreeNode?): Int = when {
else -> 1 + maxOf(heightProdVariant(root?.left), heightProdVariant(root?.right))
}

/**
* 73. Set Matrix Zeroes
* Prod Variant
*/

fun setZeroesProdVariant(matrix: Array<IntArray>) {
val m = matrix.size
val n = matrix[0].size
var firstRowZero = false
var firstColZero = false


matrix.forEachIndexed { i, row ->
row.forEachIndexed { j, value ->
if (value == 0) {
if (i == 0) firstRowZero = true
if (j == 0) firstColZero = true
matrix[i][0] = 0
matrix[0][j] = 0
}
}
}


for (i in 1 until m) {
for (j in 1 until n) {
if (matrix[i][0] == 0 || matrix[0][j] == 0) {
matrix[i][j] = 0
}
}
}


if (firstRowZero) matrix[0].fill(0)
if (firstColZero) for (i in 0 until m) matrix[i][0] = 0
}

/**
* 287. Find the Duplicate Number
* Prod Variant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -926,51 +926,6 @@ fun canBreak(start: Int, s: String, trie: TrieWordBreak): Boolean {
return false
}

/**
* 73. Set Matrix Zeroes
* Alternative Solution
*/

fun setZeroesAltSolution(matrix: Array<IntArray>) {
val m = matrix.size
val n = matrix[0].size
var firstRowZero = false
var firstColZero = false


for (i in 0 until m) {
for (j in 0 until n) {
if (matrix[i][j] == 0) {
if (i == 0) firstRowZero = true
if (j == 0) firstColZero = true
matrix[i][0] = 0
matrix[0][j] = 0
}
}
}


for (i in 1 until m) {
for (j in 1 until n) {
if (matrix[i][0] == 0 || matrix[0][j] == 0) {
matrix[i][j] = 0
}
}
}


if (firstRowZero) {
for (j in 0 until n) {
matrix[0][j] = 0
}
}
if (firstColZero) {
for (i in 0 until m) {
matrix[i][0] = 0
}
}
}

/**
* 230. Kth Smallest Element in a BST
* Alt Solution
Expand Down
12 changes: 6 additions & 6 deletions contest/src/main/java/com/github/contest/CustomEXT.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.github.contest

fun MutableMap<Int, Int>.removeIfEmptyBucket(key: Int) {
this[key] = this.getOrDefault(key, 0) - 1

fun <K, V> MutableMap<K, V>.removeIfEmptyBucket(key: K) {
if (this[key] == 0) this.remove(key)
}


fun Any.printData(label: String) {
println("$label $this")
fun <K> MutableMap<K, Int>.reduceCount(key: K) {
this[key] = this.getOrDefault(key, 0) - 1
removeIfEmptyBucket(key)
}


inline fun abs(number: Int): Int = when {
fun abs(number: Int): Int = when {
number < 0 -> number * -1
else -> number
}
56 changes: 55 additions & 1 deletion contest/src/main/java/com/github/contest/Execute.kt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,70 @@ fun pivotArrayAlternativeSolution(nums: IntArray, pivot: Int): IntArray {

return result
}


/**
* 73. Set Matrix Zeroes
* Alternative Solution
*/

fun setZeroesAltSolution(matrix: Array<IntArray>) {
val m = matrix.size
val n = matrix[0].size
var firstRowZero = false
var firstColZero = false


for (i in 0 until m) {
for (j in 0 until n) {
if (matrix[i][j] == 0) {
if (i == 0) firstRowZero = true
if (j == 0) firstColZero = true
matrix[i][0] = 0
matrix[0][j] = 0
}
}
}


for (i in 1 until m) {
for (j in 1 until n) {
if (matrix[i][0] == 0 || matrix[0][j] == 0) {
matrix[i][j] = 0
}
}
}


if (firstRowZero) {
for (j in 0 until n) {
matrix[0][j] = 0
}
}
if (firstColZero) {
for (i in 0 until m) {
matrix[i][0] = 0
}
}
}

/**
* 2016. Maximum Difference Between Increasing Elements
* Alternative Solution
*/

fun maximumDifferenceAlternativeSolution(nums: IntArray): Int {
var diff = -1
var minVal = Int.MAX_VALUE

for (i in nums.indices) {
when {
nums[i] < minVal -> minVal = minOf(minVal, nums[i])
else -> if (nums[i] > minVal) diff = maxOf(diff, nums[i] - minVal) else continue
}
}

return diff
}


Loading