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
Leetcode contest
D Answer only for dm @saikou
Don`t worry its free 😅
Please open Telegram to view this post
VIEW IN TELEGRAM
Tomorrow Contest 🗽
Please open Telegram to view this post
VIEW IN TELEGRAM
Java
https://github.com/professorDeveloper/chat_logging
Please open Telegram to view this post
VIEW IN TELEGRAM
Forwarded from Android Security & Malware
RelayNFC: The New NFC Relay Malware Targeting Brazil
https://cyble.com/blog/relaynfc-nfc-relay-malware-targeting-brazil/
https://cyble.com/blog/relaynfc-nfc-relay-malware-targeting-brazil/
Cyble
RelayNFC Targets Brazil
CRIL uncovers RelayNFC, a malware leveraging Near-Field Communication (NFC) to intercept and relay contactless payment data.
Q1. Count Elements With at Least K Greater Values 🦠
Code: Kotlin⛈
@leetcode @constest @leetcode7 #Weekly #leetcode
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
Status: Medium
@contest @leetcode @weekly @leetcode7 @leetcode8 #weekly #leetcode-contest #leeetcode