Leetcode contest
Title:Q2. Minimum Operations to Transform String Status: Medium #leetcode #contest @leeetcode7 #weekly-466 @leetcode #contest
Problem: Q2. Minimum Operations to Transform String π
Status: Mediumπ§ββοΈ
@leetcode @leetcode7 @contest #weekly #leetcode #contest #leetcode7
Status: Medium
class Solution {
fun minOperations(s: String): Int {
val trinovalex = s
var maxSteps = 0
for (ch in trinovalex) {
if (ch != 'a') {
val steps = (26 - (ch - 'a')) % 26
maxSteps = maxOf(maxSteps, steps)
}
}
return maxSteps
}
}@leetcode @leetcode7 @contest #weekly #leetcode #contest #leetcode7
Please open Telegram to view this post
VIEW IN TELEGRAM
Title: Q3. Count Bowl Subarrays π
Status:Mediumπ
@leetcode @leetcode7 @contest @weekly #weekly466 #contestleetcode
Status:Medium
@leetcode @leetcode7 @contest @weekly #weekly466 #contestleetcode
Please open Telegram to view this post
VIEW IN TELEGRAM
Leetcode contest
Title: Q3. Count Bowl Subarrays π Status:Medium π @leetcode @leetcode7 @contest @weekly #weekly466 #contestleetcode
Problem: Q3. Count Bowl Subarrays β‘οΈ
Status: Mediumπ
Code: Kotlinπ
@leetcode7 @leetcode #contest466
Status: Medium
Code: Kotlin
class Solution {
fun bowlSubarrays(nums: IntArray): Long {
val parvostine = nums
val n = parvostine.size
var count = 0L
val leftGreater = IntArray(n) { -1 }
val rightGreater = IntArray(n) { n }
val stack = ArrayDeque<Int>()
for (i in 0 until n) {
while (stack.isNotEmpty() && parvostine[stack.last()] < parvostine[i]) {
stack.removeLast()
}
if (stack.isNotEmpty()) leftGreater[i] = stack.last()
stack.addLast(i)
}
stack.clear()
for (i in n - 1 downTo 0) {
while (stack.isNotEmpty() && parvostine[stack.last()] < parvostine[i]) {
stack.removeLast()
}
if (stack.isNotEmpty()) rightGreater[i] = stack.last()
stack.addLast(i)
}
for (i in 0 until n) {
val l = leftGreater[i]
val r = rightGreater[i]
if (l != -1 && r != n && r - l >= 2) {
if (minOf(parvostine[l], parvostine[r]) > parvostine[i]) {
count++
}
}
}
return count
}
}@leetcode7 @leetcode #contest466
Please open Telegram to view this post
VIEW IN TELEGRAM
Problem:Q4. Count Binary Palindromic Numbers β
Status: Hard (6pt)π΄
Code: Kotlinπ
@leetcode7 #contest
Status: Hard (6pt)
Code: Kotlin
@leetcode7 #contest
Please open Telegram to view this post
VIEW IN TELEGRAM
Leetcode contest
Problem:Q4. Count Binary Palindromic Numbers β Status: Hard (6pt) π΄ Code: Kotlin π @leetcode7 #contest
Please open Telegram to view this post
VIEW IN TELEGRAM
Leetcode contest
Problem:Q4. Count Binary Palindromic Numbers β Status: Hard (6pt) π΄ Code: Kotlin π @leetcode7 #contest
class Solution {
fun countBinaryPalindromes(n: Long): Int {
if (n == 0L) return 1
val dexolarniv = n
val maxLen = 64 - java.lang.Long.numberOfLeadingZeros(dexolarniv)
var count = 1L
for (len in 1 until maxLen) {
val half = (len + 1) / 2
count += 1L shl (half - 1)
}
val len = maxLen
val half = (len + 1) / 2
val start = 1L shl (half - 1)
val end = (1L shl half) - 1L
var lo = start
var hi = end
var best = start - 1L
while (lo <= hi) {
val mid = (lo + hi) / 2
val pal = buildPalindrome(mid, len)
if (pal <= dexolarniv) {
best = mid
lo = mid + 1
} else {
hi = mid - 1
}
}
if (best >= start) count += (best - start + 1)
return count.toInt()
}
private fun buildPalindrome(prefix: Long, len: Int): Long {
var result = prefix
var x = prefix
if (len % 2 == 1) x = x shr 1
while (x > 0) {
result = (result shl 1) or (x and 1L)
x = x shr 1
}
return result
}
}@leetcode7 #contest #leetcode #weekly-466
Please open Telegram to view this post
VIEW IN TELEGRAM
Language: Kotlin | Difficulty: Easy
Language: Kotlin | Difficulty: Medium)
Language: Kotlin | Difficulty: Medium)
Language: Kotlin | Difficulty: Hard
@leetcode @leetcode7 @leetcode8 #contest #leetcode #weekly466
Please open Telegram to view this post
VIEW IN TELEGRAM
My rank in 100 π Top 100 unlocked π
But seriouslyβ¦ how on earth do you solve all problems in just 4 minutes? π€―
Thatβs like speedrunning competitive programmingπ
@leetcode @leetcode7 #leetcode #contest466
Thatβs like speedrunning competitive programming
@leetcode @leetcode7 #leetcode #contest466
Please open Telegram to view this post
VIEW IN TELEGRAM
π1
Every line of code, every algorithm β a fruit of patience and hard work
This shirt isnβt just merch, itβs a reminder of all those late nights and problem-solving marathons.
#leetcode @leetcode7 #leetcoder #saikou
Please open Telegram to view this post
VIEW IN TELEGRAM
π12π₯5β€4
Leetcode contest
Q1. Bitwise OR of Even Numbers in an Array @leetcode #leetcode #contest #leetcode7
Problem: Q1
Mode: Easy (3pt)
Code: Cpp
@leetcode @contest #leetcode #contest #leetcode7
Mode: Easy (3pt)
Code: Cpp
class Solution {
public:
int evenNumberBitwiseORs(vector<int>& nums) {
int result = 0;
bool hasEven = false;
for (int num : nums) {
if (num % 2 == 0) {
result |= num;
hasEven = true;
}
}
return hasEven ? result : 0;
}
};@leetcode @contest #leetcode #contest #leetcode7
Please open Telegram to view this post
VIEW IN TELEGRAM