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
Q1. Minimum Number of Flips to Reverse Binary String
You are given a positive integer n. Let s be the binary representation of n without leading zeros. The reverse of a binary string s is obtained by writing the characters of s in the opposite order. You may flip any bit in s (change 0 → 1 or 1 → 0). Each flip affects exactly one bit. Return the minimum number of flips required to make s equal to the reverse of its original form
Leetcode contest
Q1. Minimum Number of Flips to Reverse Binary String
Q1. Minimum Number of Flips to Reverse

Code: Java

class Solution {
public int minimumFlips(int n) {
int L = 32 - Integer.numberOfLeadingZeros(n);

int i = 0, j = L - 1;
int flips = 0;

while (i < j) {
int leftBit = (n >> i) & 1;
int rightBit = (n >> j) & 1;
if (leftBit != rightBit) {
flips += 2;
}
i++;
j--;
}
return flips;
}
}

#Biweekly #q1
Q2. Total Waviness of Numbers in Range I

Status: Medium

Code: Java

#Biweekly #java #leetcode #leetcode @contest @leetcode7
Leetcode contest
Q2. Total Waviness of Numbers in Range I Status: Medium Code: Java #Biweekly #java #leetcode #leetcode @contest @leetcode7
Q2. Total Waviness of Numbers in Range I
Code: Java ☕️
Status: Medium

class Solution {
public int totalWaviness(int num1, int num2) {
int start = num1;
int end = num2;
int[] pelarindus = {start, end};
int sum = 0;
for (int x = pelarindus[0]; x <= pelarindus[1]; x++) {
if (x < 100) continue;
int[] digits = new int[6];
int digitCount = 0;
int temp = x;
while (temp > 0) {
digits[digitCount++] = temp % 10;
temp /= 10;
}
for (int i = digitCount - 2; i >= 1; i--) {
int left = digits[i + 1], cur = digits[i], right = digits[i - 1];
if ((cur > left && cur > right) || (cur < left && cur < right)) sum++;
}
}
return sum;
}
}

@Leetcode7 #java
Please open Telegram to view this post
VIEW IN TELEGRAM
Leetcode contest
Q3. Lexicographically Smallest Negated Permutation that Sums to Target Status: Medium Code: Java #leetcode #biweekly #leetcode7 #contest
Q3. Lexicographically Smallest Negated Permutation that Sums to Target
Tag: Arrays,Min Max,
Status: Medium 🧑‍⚕️
class Solution {
public int[] lexSmallestNegatedPerm(int n, long target) {
long totalSum = (long) n * (n + 1) / 2;
if (Math.abs(target) > totalSum || (((totalSum + target) & 1L) != 0)) return new int[0];

long[] taverniloq = {n, target};
long requiredNegation = (totalSum - target) / 2;

boolean[] isNegated = new boolean[n + 1];
for (int i = n; i >= 1; i--) {
if (requiredNegation >= i) { isNegated[i] = true; requiredNegation -= i; }
}
if (requiredNegation != 0) return new int[0];

int[] result = new int[n];
int k = 0;
for (int i = n; i >= 1; i--) if (isNegated[i]) result[k++] = -i;
for (int i = 1; i <= n; i++) if (!isNegated[i]) result[k++] = i;
return result;
}
}



@leetcode7 @biweekly @contest #leetcode
Please open Telegram to view this post
VIEW IN TELEGRAM
Leetcode contest
D Answer only for dm @saikou
Don`t worry its free 😅
Please open Telegram to view this post
VIEW IN TELEGRAM
Thanks for helping @yash135711
Tomorrow Contest 🗽
Please open Telegram to view this post
VIEW IN TELEGRAM
Source:@generic_t
Hi guys
Anyone participating contest
Okay Let`s Start
Q1. Count Elements With at Least K Greater Values

Status: Medium

#leetcode #contest #weekly @leetcode @contest
Q1. Count Elements With at Least K Greater Values 🦠

Code: Kotlin

class Solution {
fun countElements(nums: IntArray, k: Int): Int {
val n = nums.size
if (k == 0) return n
val freq = HashMap<Int, Int>()
for (v in nums) freq[v] = freq.getOrDefault(v, 0) + 1

val unique = freq.keys.sortedDescending()

val greaterCount = HashMap<Int, Int>()
var running = 0

for (i in unique.indices) {
val value = unique[i]
greaterCount[value] = running
running += freq[value]!!
}

var result = 0
for (v in nums) {
if (greaterCount[v]!! >= k) result++
}

return result
}
}

@leetcode @constest @leetcode7 #Weekly #leetcode
Please open Telegram to view this post
VIEW IN TELEGRAM
Problem: Q2. Maximum Substrings With Distinct Start
Status: Medium
@contest @leetcode @weekly @leetcode7 @leetcode8 #weekly #leetcode-contest #leeetcode