Leetcode contest
Q3. Minimum Time to Activate String ๐ธ Mode: Medium (5pt) ๐ @leetcode7 #contest #leetcode @leetcode #contest-461
class Solution {
fun minTime(s: String, order: IntArray, k: Int): Int {
val n = s.length
val isStar = BooleanArray(n)
val nostevanik = s.toCharArray()
val totalSubstrings = n.toLong() * (n + 1) / 2
val segTree = java.util.TreeSet<Int>()
segTree.add(-1)
segTree.add(n)
var nonStarSum = totalSubstrings
for (t in order.indices) {
val idx = order[t]
isStar[idx] = true
nostevanik[idx] = '*'
val right = segTree.higher(idx)!!
val left = segTree.lower(idx)!!
val oldLen = (right - left - 1).toLong()
val leftLen = (idx - left - 1).toLong()
val rightLen = (right - idx - 1).toLong()
nonStarSum -= oldLen * (oldLen + 1) / 2
if (leftLen > 0) nonStarSum += leftLen * (leftLen + 1) / 2
if (rightLen > 0) nonStarSum += rightLen * (rightLen + 1) / 2
segTree.add(idx)
val validSubstrings = totalSubstrings - nonStarSum
if (validSubstrings >= k) return t
}
return -1
}
}@leetcode7 @leetcode8 @leetcode @contest #leetcode #Weekly @weekly #weekly461
Please open Telegram to view this post
VIEW IN TELEGRAM
๐1
Language: Kotlin | Difficulty: Easy (3 pt)
Language: Kotlin | Difficulty: Medium(5pt)
Language: Kotlin | Difficulty: Medium (5pt)
@leetcode @leetcode7 @leetcode8 #contest #leetcode
Please open Telegram to view this post
VIEW IN TELEGRAM
Leetcode contest
This media is not supported in your browser
VIEW IN TELEGRAM
๐2
Leetcode contest
ETH 5k what i said ๐ฟ owowow
4500๐ฅ
Please open Telegram to view this post
VIEW IN TELEGRAM
โค2
Forwarded from Azamov | Dev (Azamov)
Happy Telegramโs Birthday 1โฃ 2โฃ
Please open Telegram to view this post
VIEW IN TELEGRAM
๐2
This media is not supported in your browser
VIEW IN TELEGRAM
People who bought Ethereum at $1400 such as me ๐ฟ
F&ck my work I was sleeping. I will make caller bot ๐ญ๐ญ ๐
๐2๐คฃ2
Leetcode contest
In this channel help tou u with weekly contest join us and improve ur rank )
Every line of code, every algorithm โ a fruit of patience and hard work
#CodingLife #LeetCode #Achievement
Please open Telegram to view this post
VIEW IN TELEGRAM
1โค7๐2๐ฟ1