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
Leetcode contest
Q2. Maximum Total Subarray Value I Status: Medium π΄ @leetcode7 #leetcode #contest
Problem: Q2
Code: Kotlin
@leetcode @leetcode7 #leetcode #contest
Code: Kotlin
class Solution {
fun maxTotalValue(nums: IntArray, k: Int): Long {
val sormadexin = nums
if (nums.isEmpty()) return 0L
val minVal = nums.minOrNull() ?: 0
val maxVal = nums.maxOrNull() ?: 0
return k.toLong() * (maxVal - minVal)
}
}@leetcode @leetcode7 #leetcode #contest
Please open Telegram to view this post
VIEW IN TELEGRAM
Problem: Q3. β‘οΈ
Status: Mediumπ
Code: Kotlinπ
@leetcode7 #leetcode #contest #weekly466
Status: Medium
Code: Kotlin
class Solution {
fun minSplitMerge(nums1: IntArray, nums2: IntArray): Int {
val start = nums1.toList()
val target = nums2.toList()
if (start == target) return 0
val visited = mutableSetOf<List<Int>>()
val queue: ArrayDeque<Pair<List<Int>, Int>> = ArrayDeque()
queue.add(start to 0)
visited.add(start)
while (queue.isNotEmpty()) {
val (curr, steps) = queue.removeFirst()
val n = curr.size
for (l in 0 until n) {
for (r in l until n) {
val sub = curr.subList(l, r + 1)
val remain = curr.subList(0, l) + curr.subList(r + 1, n)
for (pos in 0..remain.size) {
val next = remain.subList(0, pos) + sub + remain.subList(pos, remain.size)
if (next == target) return steps + 1
if (visited.add(next)) {
queue.add(next to steps + 1)
}
}
}
}
}
return -1
}
}@leetcode7 #leetcode #contest #weekly466
Please open Telegram to view this post
VIEW IN TELEGRAM
β€1
#include <vector>
#include <queue>
#include <set>
#include <tuple>
#include <algorithm>
using namespace std;
class Solution {
public:
long long maxTotalValue(vector<int>& nums, int k) {
int n = nums.size();
vector<int> log_table(n+1, 0);
if (n >= 1) log_table[1] = 0;
for (int i = 2; i <= n; i++) {
log_table[i] = log_table[i/2] + 1;
}
int LOG = log_table[n] + 1;
vector<vector<int>> st_max(n, vector<int>(LOG, 0));
vector<vector<int>> st_min(n, vector<int>(LOG, 0));
for (int i = 0; i < n; i++) {
st_max[i][0] = nums[i];
st_min[i][0] = nums[i];
}
for (int j = 1; j < LOG; j++) {
int step = (1 << (j-1));
for (int i = 0; i + (1 << j) <= n; i++) {
st_max[i][j] = max(st_max[i][j-1], st_max[i+step][j-1]);
st_min[i][j] = min(st_min[i][j-1], st_min[i+step][j-1]);
}
}
auto query = [&](int l, int r) {
int len = r - l + 1;
int j = log_table[len];
int max_val = max(st_max[l][j], st_max[r - (1 << j) + 1][j]);
int min_val = min(st_min[l][j], st_min[r - (1 << j) + 1][j]);
return (long long) max_val - min_val;
};
priority_queue<tuple<long long, int, int>> pq;
set<pair<int, int>> visited;
long long initial_range = query(0, n-1);
pq.push({initial_range, 0, n-1});
visited.insert({0, n-1});
long long ans = 0;
for (int i = 0; i < k; i++) {
if (pq.empty()) break;
auto [range, l, r] = pq.top();
pq.pop();
ans += range;
if (l + 1 <= r) {
pair<int, int> next1 = {l+1, r};
if (visited.find(next1) == visited.end()) {
visited.insert(next1);
long long new_range = query(l+1, r);
pq.push({new_range, l+1, r});
}
}
if (l <= r - 1) {
pair<int, int> next2 = {l, r-1};
if (visited.find(next2) == visited.end()) {
visited.insert(next2);
long long new_range = query(l, r-1);
pq.push({new_range, l, r-1});
}
}
}
return ans;
} };
@leetcode7 #contest #leetcode #weekly-468 @weekly @weekly468 #weekly468 leetcode
Please open Telegram to view this post
VIEW IN TELEGRAM
β€1
Language: Cpp | Difficulty: Easy
Language: Kotlin | Difficulty: Medium)
Language: Kotlin | Difficulty: Medium)
Language: Cpp | Difficulty: Hard
@leetcode @leetcode7 @leetcode8 #contest #leetcode #weekly468 #contest #leetcodecontest
Please open Telegram to view this post
VIEW IN TELEGRAM