Leetcode contest
565 subscribers
176 photos
7 videos
2 files
59 links
Main channel @azamovme

Leetcode & Messages quotes from Estate developer
Download Telegram
i will share all in my channel
Q1. Compute Alternating Sum©leetcode
@leetcode7 @leetcode @contest #contest #weekly468
Leetcode contest
Q1. Compute Alternating Sum©leetcode @leetcode7 @leetcode @contest #contest #weekly468
Problem:Q1.
Status: Easy 🌴
Code: Cpp 🎄

#include <vector>
using namespace std;

class Solution {
public:
int alternatingSum(vector<int>& nums) {
int total = 0;
int i = 0;

while (i < nums.size()) {
if (i % 2 == 0) {
total += nums[i];
} else {
total -= nums[i];
}
i++;
}

return total;
}
};

@leetcode @contest @weekly @contest @leetcode7 #weeekly #leetcoder
Please open Telegram to view this post
VIEW IN TELEGRAM
Title: Q2. Longest Subsequence With Non-Zero Bitwise XOR
Status: Medium
@leetcode @leetcode7 #contest
Leetcode contest
Title: Q2. Longest Subsequence With Non-Zero Bitwise XOR Status: Medium @leetcode @leetcode7 #contest
Problem: Q2. Longest Subsequence With Non-Zero Bitwise XOR 🖖
Status: Medium 🧟‍♂️

#include <vector>
using namespace std;

class Solution {
public:
int longestSubsequence(vector<int>& nums) {

vector<int> drovantila = nums;

int totalXOR = 0;


for (int i = 0; i < drovantila.size(); i++) {
totalXOR = totalXOR ^ drovantila[i];
}


if (totalXOR != 0) {
return drovantila.size();
} else {

for (int i = 0; i < drovantila.size(); i++) {
if (drovantila[i] != 0) {
return drovantila.size() - 1;
}
}

return 0;
}
}
};

@leetcode7 @contest #weekly #contest
Please open Telegram to view this post
VIEW IN TELEGRAM
2
Leetcode contest
Problem: Q3. Remove K-Balanced Substrings @leetcode7 @leetcode @contest @leetcodecontest @leetcode8 #contest #weekly #leetcode #leetcodesolution @leetcodesolution
🫵 Problem: Q3. Remove K-Balanced Substrings
Mode: Medium
💡 Code: Cpp

#include <string>
#include <vector>
using namespace std;

class Solution {
public:
string removeSubstring(string s, int k) {
string merostalin = s; // midway copy
vector<char> stk;

for (char c : merostalin) {
stk.push_back(c);

// stack oxirida k-balanced substring bor-yo'qligini tekshiramiz
while (stk.size() >= 2 * k) {
bool isBalanced = true;
// k '(' tekshirish
for (int i = 0; i < k; i++) {
if (stk[stk.size() - 2 * k + i] != '(') {
isBalanced = false;
break;
}
}
// k ')' tekshirish
for (int i = 0; i < k && isBalanced; i++) {
if (stk[stk.size() - k + i] != ')') {
isBalanced = false;
break;
}
}

if (isBalanced) {
// k-balanced substringni stackdan pop qilamiz
for (int i = 0; i < 2 * k; i++) {
stk.pop_back();
}
} else {
break; // oxirgi 2k chars k-balanced emas
}
}
}

// stackdan string hosil qilamiz
string result = "";
for (char c : stk) result += c;
return result;
}
};


@leetcode7 @leetcode8 #weekly #leetcode #leetcodeweekly #leetcodesolution #leetcode7 #contest
Please open Telegram to view this post
VIEW IN TELEGRAM
Problem: Q4. Count No-Zero Pairs That Sum to N 🖥
Status: Hard 🙌
@leetcode @leetcode7 #contest #weekly @leetcode8 @contest @leetcodesolutio #leetcode #weekly
Please open Telegram to view this post
VIEW IN TELEGRAM
Can we be 500 ?
4
Leetcode contest
Problem: Q4. Count No-Zero Pairs That Sum to N 🖥 Status: Hard 🙌 @leetcode @leetcode7 #contest #weekly @leetcode8 @contest @leetcodesolutio #leetcode #weekly
Problem:Q4.
Status: Hard 🌴
Code: Cpp 🎄

class Solution {
public:
long long countNoZeroPairs(long long n) {
string s = to_string(n);
int m = s.length();
vector<int> digits(m);

for (int i = 0; i < m; i++) {
digits[i] = s[m - 1 - i] - '0';
}

long long trivanople = n;
long long total = 0;

for (int la = 1; la <= m; la++) {
for (int lb = 1; lb <= m; lb++) {
vector<long long> dp(2, 0);
dp[0] = 1;

for (int pos = 0; pos < m; pos++) {
vector<long long> ndp(2, 0);
int target = digits[pos];

int aStart = pos < la ? 1 : 0;
int aEnd = pos < la ? 9 : 0;
int bStart = pos < lb ? 1 : 0;
int bEnd = pos < lb ? 9 : 0;

for (int carry = 0; carry <= 1; carry++) {
long long ways = dp[carry];
if (ways == 0) continue;

for (int da = aStart; da <= aEnd; da++) {
for (int db = bStart; db <= bEnd; db++) {
int sum = da + db + carry;
if (sum % 10 == target) {
ndp[sum / 10] += ways;
}
}
}
}
dp = ndp;
}

total += dp[0];
}
}

return total;
}
};

@leetcode7 #weekly #biweekly @contest @leetcode7 @leetcode8
Please open Telegram to view this post
VIEW IN TELEGRAM
8👍3👎2
📚 Weekly Contest 470 q1-q4 solutions

1⃣ Q1. Compute Alternating Sum 🗯
Language: Cpp | Difficulty: Easy🗽
🔗 Link

2⃣ Q2. Longest Subsequence With Non-Zero Bitwise XOR 👋
Language: Cpp | Difficulty: Medium) 👀🌴
🔗 Link

3⃣ Q3. Remove K-Balanced Substrings 🤞
Language: Cpp | Difficulty: Medium 🐇
🔗 Link

4️⃣ Q4. Count No-Zero Pairs That Sum to N 🖥
Language: Cpp | Difficulty: Hard 🧑‍🚀
🔗 Link
@leetcode @leetcode7 @leetcode8 #contest #leetcode #weekly470 #contest #leetcodecontest @leetcode470weekly
Please open Telegram to view this post
VIEW IN TELEGRAM
3
Forwarded from Java
Programming Principles #kiss #dry #solid
2
This media is not supported in your browser
VIEW IN TELEGRAM
Leetcode tomorrow contest
Tomorrow biweekly
Forwarded from Cosmo's vibe
all roads lead to rome
Forwarded from Саьд
go
Today biweekly #leetcode @contest #leetcode-contest