Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
isaiahliu committed Dec 25, 2024
1 parent afdd328 commit d92a22e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/main/kotlin/p25xx/Problem2500.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ fun main() {
fun deleteGreatestValue(grid: Array<IntArray>): Int {
grid.forEach { it.sort() }

return grid[0].indices.map { i ->
grid.map { it[i] }.max()
}.sum()
return grid[0].indices.sumOf { i ->
grid.maxOf { it[i] }
}
}
}

Expand Down
37 changes: 37 additions & 0 deletions src/main/kotlin/p30xx/Problem3083.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package p30xx

import util.expect

fun main() {
class Solution {
fun isSubstringPresent(s: String): Boolean {
val befores = Array(26) { hashSetOf<Int>() }
val afters = Array(26) { hashSetOf<Int>() }

s.forEachIndexed { index, ch ->
s.getOrNull(index - 1)?.also {
if (it - 'a' in afters[ch - 'a']) {
return true
}

befores[ch - 'a'] += it - 'a'
}
s.getOrNull(index + 1)?.also {
if (it - 'a' in befores[ch - 'a']) {
return true
}

afters[ch - 'a'] += it - 'a'
}
}

return false
}
}

expect {
Solution().isSubstringPresent(
""
)
}
}

0 comments on commit d92a22e

Please sign in to comment.