Leetcode contest
Today contest #leetcode
Weekly contest @leetcode3 lets pray for me for joining
Hello everyone, I’m back after a 3-week vacation. I’m ready to start running the channel again. Thanks to all the new members for joining! 🥂
Please open Telegram to view this post
VIEW IN TELEGRAM
http4k — a set of functional tools for HTTP applications
http4k is a lightweight yet fully functional toolkit for working with HTTP, written in pure Kotlin.
http4k allows you to write applications as simple Kotlin functions. For example, here is a simple echo server:
@KotlinSenior
http4k is a lightweight yet fully functional toolkit for working with HTTP, written in pure Kotlin.
http4k allows you to write applications as simple Kotlin functions. For example, here is a simple echo server:
val app: HttpHandler = { request: Request -> Response(OK).body(request.body) }
val server = app.asServer(SunHttp(8000)).start()@KotlinSenior
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
#Biweekly #q1
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
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
@Leetcode7 #java
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
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; …
Q3. Lexicographically Smallest Negated Permutation that Sums to Target
Status: Medium
Code: Java
#leetcode #biweekly #leetcode7 #contest
Status: Medium
Code: Java
#leetcode #biweekly #leetcode7 #contest
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🧑⚕️
@leetcode7 @biweekly @contest #leetcode
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
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)…
Please open Telegram to view this post
VIEW IN TELEGRAM