Please open Telegram to view this post
VIEW IN TELEGRAM
Question1: Coupon Code Validator
Mode:Easy
Idea:π©βπ»
Code:π©βπ»
#leetcode #leetcode7 #contest @leetcode7
Mode:Easy
Idea:
Code:
class Solution {
fun validateCoupons(
code: Array<String>,
businessLine: Array<String>,
isActive: BooleanArray
): List<String> {
val validCategories = listOf("electronics", "grocery", "pharmacy", "restaurant")
val validList = mutableListOf<Pair<String, String>>()
for (i in code.indices) {
val coupon = code[i]
val category = businessLine[i]
if (coupon.isNotEmpty()
&& coupon.matches(Regex("^[A-Za-z0-9_]+$"))
&& category in validCategories
&& isActive[i]
) {
validList += category to coupon
}
}
return validList
.sortedWith(
compareBy<Pair<String, String>> { validCategories.indexOf(it.first) }
.thenBy { it.second }
)
.map { it.second }
}
}#leetcode #leetcode7 #contest @leetcode7
Please open Telegram to view this post
VIEW IN TELEGRAM
β€1
Leetcode contest
Q2. Power Grid MaintenanceΒ©leetcode #weekly-457 #contest #leetcode #leetcode7 @leetcode7
i before did this problem and i already have this question answer πΏ
Please open Telegram to view this post
VIEW IN TELEGRAM
Leetcode contest
Q2. Power Grid MaintenanceΒ©leetcode #weekly-457 #contest #leetcode #leetcode7 @leetcode7
Code:
class Solution {
fun processQueries(
c: Int,
connections: Array<IntArray>,
queries: Array<IntArray>
): IntArray {
val parent = IntArray(c + 1) { it }
fun find(x: Int): Int {
if (parent[x] != x) parent[x] = find(parent[x])
return parent[x]
}
fun union(a: Int, b: Int) {
val ra = find(a)
val rb = find(b)
if (ra != rb) parent[rb] = ra
}
for ((u, v) in connections) union(u, v)
val online = BooleanArray(c + 1) { true }
val groups = mutableMapOf<Int, java.util.TreeSet<Int>>()
for (i in 1..c) {
val r = find(i)
groups.getOrPut(r) { java.util.TreeSet() }.add(i)
}
val result = mutableListOf<Int>()
for ((type, x) in queries) {
val root = find(x)
if (type == 1) {
result += if (online[x]) x else (groups[root]?.firstOrNull() ?: -1)
} else {
if (online[x]) {
online[x] = false
groups[root]?.remove(x)
}
}
}
return result.toIntArray()
}
}@leetcode7 @leetcode #leetcode #leetcote-contest #contest
Please open Telegram to view this post
VIEW IN TELEGRAM
Leetcode contest
if need all questions fasstly dm me @saikou
Q3-Q4 need fastly Dm me)
Leetcode contest
Q3. Minimum Time for K Connected Components #leetcode #leetcode-contest #contest #weekly-457
class Solution {
fun minTime(n: Int, edges: Array<IntArray>, k: Int): Int {
val poltracine = Triple(n, edges, k)
val parentFull = IntArray(n) { it }
var compsFull = n
fun findFull(x: Int): Int {
if (parentFull[x] != x) parentFull[x] = findFull(parentFull[x])
return parentFull[x]
}
fun unionFull(a: Int, b: Int) {
val ra = findFull(a)
val rb = findFull(b)
if (ra != rb) {
parentFull[rb] = ra
compsFull--
}
}
for ((u, v, _) in edges) unionFull(u, v)
if (compsFull >= k) return 0
val edgesByTime = edges.groupBy { it[2] }
val times = edgesByTime.keys.sorted()
val parentRem = IntArray(n) { it }
var compsRem = n
fun findRem(x: Int): Int {
if (parentRem[x] != x) parentRem[x] = findRem(parentRem[x])
return parentRem[x]
}
fun unionRem(a: Int, b: Int) {
val ra = findRem(a)
val rb = findRem(b)
if (ra != rb) {
parentRem[rb] = ra
compsRem--
}
}
var ans = 0
for (t in times.reversed()) {
if (compsRem >= k) ans = t
for ((u, v, _) in edgesByTime[t]!!) {
unionRem(u, v)
}
}
return ans
}
}@leetcode7 #contest #weekyl-457 #contest-leetcode #geeksforgeeks #leetcode-contest @leetcode7
Please open Telegram to view this post
VIEW IN TELEGRAM
β€1
Language: Kotlin | Difficulty: Easy (4 pt)
Language: Kotlin | Difficulty: Hard (4 pt)
Language: Kotlin | Difficulty: Medium (5 pt)
@leetcode @leetcode7 @leetcode8 #contest #leetcode
Please open Telegram to view this post
VIEW IN TELEGRAM
shall we also participate geeks for geeks contest?
Anonymous Poll
63%
yes
11%
why not ?
26%
nah leetcode enough
Forwarded from Snoop Dogg
https://youtu.be/sknGyx2vRg4?si=HUGmeLJJFgcrVRqe
@durov time to drop it like itβs hot cuz π₯πππΏ
@durov time to drop it like itβs hot cuz π₯πππΏ
YouTube
Snoop Dogg - Gifts (Official Music Video)
The official music video for Snoop Dogg - Gifts
OUT NOW:
Subscribe to DEATH ROW's channel: https://www.youtube.com/@DeathRowRecords
Follow Snoop Dogg!
http://t.me/snoopdogg
Follow DEATH ROW
Instagram: https://www.instagram.com/deathrowrecords
TikTok:β¦
OUT NOW:
Subscribe to DEATH ROW's channel: https://www.youtube.com/@DeathRowRecords
Follow Snoop Dogg!
http://t.me/snoopdogg
Follow DEATH ROW
Instagram: https://www.instagram.com/deathrowrecords
TikTok:β¦
Today contest π€© #contest@leetcode7
Please open Telegram to view this post
VIEW IN TELEGRAM