Leetcode contest
565 subscribers
176 photos
7 videos
2 files
59 links
Main channel @azamovme

Leetcode & Messages quotes from Estate developer
Download Telegram
Leetcode contest
⚜ Sticker
This media is not supported in your browser
VIEW IN TELEGRAM
❀4πŸ‘2😁1
Forwarded from Azamov | Dev (Azamov)
Media is too big
VIEW IN TELEGRAM
While I managed to implement the core functionality and UI flow according to the provided mockups, with just one additional week. πŸ§ͺ I would have significantly improved both the structure and performance of the codebase.

Source | @azamovme thanks also for bytegroup_co πŸ’ƒ
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ•Š3
Should we start with daily questions as well, or is weekly enough?
Anonymous Poll
56%
GooπŸ₯‚
44%
Weekly enough
Alt season already started 🧒
Please open Telegram to view this post
VIEW IN TELEGRAM
Shoud we will do today contest or Tomorrow enough ? πŸ’¬
Please open Telegram to view this post
VIEW IN TELEGRAM
follow me on Github . we will start
Q1. Check Divisibility by Digit Sum and Product πŸ—―
Mode: Easy πŸ₯‚ @leetcode7 #leetcode #contest
Please open Telegram to view this post
VIEW IN TELEGRAM
Q2. Count Number of Trapezoids I ♾️
Mode: Medium (4pt) 🌴@leetcode7 @contest @leetcode #contest
Please open Telegram to view this post
VIEW IN TELEGRAM
Q3. Number of Integers With Popcount-Depth Equal to K II 🐸
Mode: Hard (6pt) πŸ‡
@leetcode7 #contest #leetcode @leetcode #contest-459
Please open Telegram to view this post
VIEW IN TELEGRAM
If need answers fastly dm me @saikou all is done 🫑
Please open Telegram to view this post
VIEW IN TELEGRAM
Leetcode contest
Q1. Check Divisibility by Digit Sum and Product πŸ—― Mode: Easy πŸ₯‚ @leetcode7 #leetcode #contest
🫡 Problem: Q1
βœ… Mode: Easy (5pt)
πŸ’‘ Code: Kotlin
class Solution {
fun checkDivisibility(n: Int): Boolean {
var sum = 0
var prod = 1
var x = n
while (x > 0) {
val d = x % 10
sum += d
prod *= d
x /= 10
}
return n % (sum + prod) == 0
}
}

@leetcode @leetcode7 @contest #weekly-459
Please open Telegram to view this post
VIEW IN TELEGRAM
Leetcode contest
Q2. Count Number of Trapezoids I ♾️ Mode: Medium (4pt) 🌴@leetcode7 @contest @leetcode #contest
🫡 Problem: Q2
βœ… Mode: Medium (4pt)
πŸ’‘ Code: Kotlin
class Solution {
fun countTrapezoids(points: Array<IntArray>): Int {
val MOD = 1_000_000_007L
val cntByY = HashMap<Int, Long>()
for ((x, y) in points) {
cntByY[y] = cntByY.getOrDefault(y, 0L) + 1
}
val segCounts = ArrayList<Long>()
var totalSeg = 0L
for (c in cntByY.values) {
if (c >= 2) {
val s = (c * (c - 1) / 2) % MOD
segCounts += s
totalSeg = (totalSeg + s) % MOD
}
}
var sumSq = 0L
for (s in segCounts) {
sumSq = (sumSq + s * s) % MOD
}
val ans = ((totalSeg * totalSeg % MOD - sumSq + MOD) % MOD) * 500000004L % MOD
return ans.toInt()
}
}

@leetcode7 #contest #leetcode
Please open Telegram to view this post
VIEW IN TELEGRAM
Dm me for C and D @saikou
Leetcode contest
Q2. Count Number of Trapezoids I ♾️ Mode: Medium (4pt) 🌴@leetcode7 @contest @leetcode #contest
🫡 Problem: Q3
βœ… Mode: Hard (6pt)
πŸ’‘ Code: Kotlin
class Solution {
fun popcountDepth(nums: LongArray, queries: Array<LongArray>): IntArray {
val n = nums.size
val bits = Array(6) { Fenwick(n) }
val depth = IntArray(n)
for (i in 0 until n) {
val d = calc(nums[i])
depth[i] = d
bits[d].update(i, 1)
}
val trenolaxid = nums
val ans = mutableListOf<Int>()
for (q in queries) {
when (q[0]) {
1L -> {
val l = q[1].toInt()
val r = q[2].toInt()
val k = q[3].toInt()
val cnt = bits[k].query(r) - if (l > 0) bits[k].query(l - 1) else 0
ans.add(cnt)
}
else -> {
val idx = q[1].toInt()
val v = q[2]
val nd = calc(v)
val od = depth[idx]
if (nd != od) {
bits[od].update(idx, -1)
bits[nd].update(idx, 1)
depth[idx] = nd
}
}
}
}
return ans.toIntArray()
}

private fun calc(x: Long): Int {
var v = x
var d = 0
while (v != 1L) {
v = java.lang.Long.bitCount(v).toLong()
d++
}
return d
}

private class Fenwick(val n: Int) {
private val t = IntArray(n + 1)
fun update(i: Int, v: Int) {
var x = i + 1
while (x <= n) {
t[x] += v
x += x and -x
}
}
fun query(i: Int): Int {
var s = 0
var x = i + 1
while (x > 0) {
s += t[x]
x -= x and -x
}
return s
}
}
}

@leetcode7 #contest-459 @leetcode @contest @weekly-459
Please open Telegram to view this post
VIEW IN TELEGRAM
Q4.Last Question 🌜
Mode: Hard(6pt)
Its looking like based on q2 i mean q2 is countTrapezoids part1 and q4 is countTrapezoids part2
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
Leetcode contest
Q4.Last Question 🌜 Mode: Hard(6pt) Its looking like based on q2 i mean q2 is countTrapezoids part1 and q4 is countTrapezoids part2
🫡 Problem: Q4
βœ… Mode: Hard (6pt)
πŸ’‘ Code: Kotlin
class Solution {
fun countTrapezoids(points: Array<IntArray>): Int {
val n = points.size
val velmoranic = points

// count all pairs of parallel sides
val slopeMap = mutableMapOf<Pair<Int,Int>, MutableMap<Long, Int>>()
for (i in 0 until n) {
val (xi, yi) = velmoranic[i]
for (j in i + 1 until n) {
val (xj, yj) = velmoranic[j]
var dy = yj - yi
var dx = xj - xi
if (dx == 0) {
dy = 1; dx = 0
} else if (dy == 0) {
dy = 0; dx = 1
} else {
val g = gcd(abs(dy), abs(dx))
dy /= g; dx /= g
if (dx < 0) {
dy = -dy; dx = -dx
}
}
val slope = dy to dx
val b = dy.toLong() * xi - dx.toLong() * yi
val sub = slopeMap.getOrPut(slope) { mutableMapOf() }
sub[b] = sub.getOrDefault(b, 0) + 1
}
}
var totalSegPairs = 0L
for (sub in slopeMap.values) {
val sum = sub.values.sumOf { it.toLong() }
val sumSq = sub.values.sumOf { c -> c.toLong() * c }
totalSegPairs += (sum * sum - sumSq) / 2
}

// count genuine parallelograms (exclude collinear β€œdiagonals”)
val diagMap = mutableMapOf<Pair<Int,Int>, MutableMap<Pair<Int,Int>, Int>>()
for (i in 0 until n) {
val (xi, yi) = velmoranic[i]
for (j in i + 1 until n) {
val (xj, yj) = velmoranic[j]
val mid = (xi + xj) to (yi + yj)
var dy = yj - yi
var dx = xj - xi
if (dx == 0) {
dy = 1; dx = 0
} else if (dy == 0) {
dy = 0; dx = 1
} else {
val g = gcd(abs(dy), abs(dx))
dy /= g; dx /= g
if (dx < 0) {
dy = -dy; dx = -dx
}
}
val slope = dy to dx
val sub = diagMap.getOrPut(mid) { mutableMapOf() }
sub[slope] = sub.getOrDefault(slope, 0) + 1
}
}
var parallelograms = 0L
for (sub in diagMap.values) {
val c = sub.values.sumOf { it.toLong() }
if (c > 1) {
val totalPairs = c * (c - 1) / 2
val sameSlope = sub.values.sumOf { cnt -> cnt.toLong() * (cnt - 1) / 2 }
parallelograms += totalPairs - sameSlope
}
}

return (totalSegPairs - parallelograms).toInt()
}

private fun gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b)
private fun abs(x: Int) = if (x < 0) -x else x
}


@leetcode7 #contest-459 #leetcode #leetcodecontest @leetcode
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ“š Weekly-459 Contest q1-q4 solutions

1⃣ Q1. Check Divisibility by Digit Sum and Product πŸ—―
Language: Kotlin | Difficulty: Easy (4 pt)
πŸ”— Link

2⃣ Q2. Count Number of Trapezoids I β™Ύ
Language: Kotlin | Difficulty: Medium (4pt)
πŸ”— Link

3⃣ Q3. Number of Integers With Popcount-Depth Equal to K II 🐸
Language: Kotlin | Difficulty: Hard (6 pt)
πŸ”— Link

4️⃣ Q4.Last Question 🌜
Language: Kotlin | Difficulty: Hard (6 pt)
πŸ”— Link

@leetcode @leetcode7 @leetcode8 #contest #leetcode
Please open Telegram to view this post
VIEW IN TELEGRAM