LeetCode Weekly Solutions
7.28K subscribers
34 photos
11 files
101 links
Latest Jobs and Internships are regularly uploaded here : https://t.me/placementlelo

If you want any other exam answers for free : @exam_cheating_bot

Collaborations: @growth_admin
Download Telegram
Goldman Sachs Exam 100% Correct Answers are uploaded here 👇🏻
https://youtu.be/BYwtNx7zaMg
https://youtu.be/BYwtNx7zaMg

Share with your friends 😇
Cognizant Exam Answers will be uploaded here 👇🏻
https://telegram.me/+Q_kf6B6EFexiNmU9

Cognizant Exam Discussion Group 👇🏻
https://telegram.me/+8B154b769wk4ZjY9

Share this with your friends 😇
Cognizant
Database Query Question

https://telegram.me/+Q_kf6B6EFexiNmU9
Cognizant
Database Query Question

https://telegram.me/+Q_kf6B6EFexiNmU9

SELECT instructor.first_name AS "First Name", instructor.last_name AS "Last Name"
FROM instructor
WHERE instructor.type = 'full-time'
  AND instructor.last_name LIKE 'C%';

Cognizant
Database Query Question

https://telegram.me/PLACEMENTLELO
Forwarded from Placement Lelo 2.0
Google Hiring Software Engineer:

Graduation Year: 2024 / 2023

Salary: 35 to 40 LPA
Location: Bengaluru / Gurgaon / Hyderabad / Mumbai / Pune

Apply Link: https://tinyurl.com/55ehdkdj

Telegram: https://telegram.me/OFF_CAMPUS_JOBS_AND_INTERNSHIPS
Bulk hiring is open for these 4 companies:

1. Capgemini
2. Accenture
3. Reliance
4. TCS

Last Date to Apply: 6 October

We have uploaded all the details in the LinkedIn post.

Post Link: https://bit.ly/mass_hiring

Make sure to apply to all 4 opportunities.

Share this with your friends 😇
Leetcode Weekly 419
A
C++

https://telegram.me/+_hn3cBQVbGliYTI9

#include <vector>
#include <unordered_map>
#include <algorithm>

using namespace std;

class Solution {
public:
vector<int> findXSum(vector<int>& nums, int k, int x) {
int n = nums.size();
vector<int> answer;

for (int i = 0; i <= n - k; ++i) {
unordered_map<int, int> frequency;
for (int j = i; j < i + k; ++j) {
frequency[nums[j]]++;
}

vector<pair<int, int>> freqList;
for (const auto& entry : frequency) {
freqList.push_back({entry.second, entry.first});
}

sort(freqList.begin(), freqList.end(), [](const pair<int, int>& a, const pair<int, int>& b) {
if (a.first != b.first) return a.first > b.first;
return a.second > b.second;
});

int sum = 0;
int count = 0;
for (const auto& entry : freqList) {
int frequency = entry.first;
int value = entry.second;
if (count >= x) break;
sum += frequency * value;
count++;
}

answer.push_back(sum);
}

return answer;
}
};

Leetcode Weekly 419
A
C++

https://telegram.me/+_hn3cBQVbGliYTI9
Leetcode Weekly 419
B
C++
https://telegram.me/+_hn3cBQVbGliYTI9

class Solution {
public:
pair<bool, int> checkPerfect(TreeNode* node) {
if (!node) return {true, 0};

auto leftResult = checkPerfect(node->left);
auto rightResult = checkPerfect(node->right);

if (leftResult.first && rightResult.first && leftResult.second == rightResult.second) {
return {true, leftResult.second + rightResult.second + 1};
}

return {false, 0};
}

void gatherPerfectSizes(TreeNode* node, vector<int>& subtreeSizes) {
if (!node) return;

auto result = checkPerfect(node);
if (result.first) {
subtreeSizes.push_back(result.second);
}

gatherPerfectSizes(node->left, subtreeSizes);
gatherPerfectSizes(node->right, subtreeSizes);
}

int kthLargestPerfectSubtree(TreeNode* root, int k) {
vector<int> subtreeSizes;
gatherPerfectSizes(root, subtreeSizes);

if (subtreeSizes.empty()) return -1;

sort(subtreeSizes.rbegin(), subtreeSizes.rend());

return (k <= subtreeSizes.size()) ? subtreeSizes[k - 1] : -1;
}
};

Leetcode Weekly 419
B
C++
https://telegram.me/+_hn3cBQVbGliYTI9
Leetcode Weekly 419
C
Python

https://telegram.me/+Q_kf6B6EFexiNmU9

MOD = 10**9 + 7

class Solution:
def countWinningSequences(self, s: str) -> int:
n = len(s)

win_against = {'F': 'W', 'W': 'E', 'E': 'F'}

memo = {}

def dp(i, last_bob_move, score_diff):
if i == n:
return 1 if score_diff > 0 else 0

if (i, last_bob_move, score_diff) in memo:
return memo[(i, last_bob_move, score_diff)]

total_ways = 0
alice_move = s[i]

for bob_move in 'FWE':
if bob_move == last_bob_move:
continue

new_score_diff = score_diff
if bob_move == win_against[alice_move]:
new_score_diff += 1
elif win_against[bob_move] == alice_move:
new_score_diff -= 1

total_ways = (total_ways + dp(i + 1, bob_move, new_score_diff)) % MOD

memo[(i, last_bob_move, score_diff)] = total_ways
return total_ways

return dp(0, None, 0)

Leetcode Weekly 419
C
Python

https://telegram.me/+Q_kf6B6EFexiNmU9
TCS CodeVita Exam Answers will be uploaded here 👇🏻
https://telegram.me/+_hn3cBQVbGliYTI9

TCS CodeVita Discussion Group 👇🏻
https://telegram.me/+oZ4x3k1RtXdkNWU1

Must join both the groups !

Share these groups with your friends and help them get a job 😇
TCS CodeVita All 100% Correct Answers uploaded 👇🏻
https://youtu.be/a9wgj8hm20g
https://youtu.be/a9wgj8hm20g

Share this with your friends 😇
TCS CodeVita Round 1 Zone 2:

TCS CodeVita Exam Answers will be uploaded here 👇🏻

https://telegram.me/+_hn3cBQVbGliYTI9

TCS CodeVita Discussion Group 👇🏻
https://telegram.me/+oZ4x3k1RtXdkNWU1

Must join both the groups !

Share these groups with your friends and help them get a job 😇
String Obsession
C++

TCS CodeVita Zone 2
100% Correct Code

https://telegram.me/+_hn3cBQVbGliYTI9

#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
https://telegram.me/+_hn3cBQVbGliYTI9

using namespace std;

int dp(string& s, vector<string>& v, unordered_map<string, int>& memo) {

if (memo.count(s)) return memo[s];
// @PLACEMENTLELO
int placementlelo = 0;
https://telegram.me/+_hn3cBQVbGliYTI9

for (auto& x : v) {
size_t pos = s.find(x);
// @PLACEMENTLELO
if (pos != string::npos) {
string new_string = s.substr(0, pos) + s.substr(pos + x.size());
placementlelo = max(placementlelo, 1 + dp(new_string, v, memo));
}
}
// @PLACEMENTLELO
return memo[s] = placementlelo;
}

int main() {
int n;
cin >> n;
// @PLACEMENTLELO
vector<string> substrings(n);
for (int i = 0; i < n; ++i) {
cin >> substrings[i];
}
https://telegram.me/+_hn3cBQVbGliYTI9

string mainString;
cin >> mainString;
// @PLACEMENTLELO
unordered_map<string, int> memo;

cout << dp(mainString, substrings, memo);

return 0;
}
https://telegram.me/+_hn3cBQVbGliYTI9

String Obsession
C++

TCS CodeVita Zone 2
100% Correct Code

https://telegram.me/PLACEMENTLELO