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
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
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 Group👇🏻
https://www.linkedin.com/posts/placementlelo_tcs-tcscodevita-career-activity-7262117016117886976-be3X
Share this with your friends 😇
https://www.linkedin.com/posts/placementlelo_tcs-tcscodevita-career-activity-7262117016117886976-be3X
Share this with your friends 😇
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 😇
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 😇
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 😇
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 😇
Forwarded from Goldman Sachs Exam Solutions
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
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
Forwarded from Goldman Sachs Exam Solutions
Desert Queen
C++
TCS CodeVita Zone 2
https://telegram.me/+_hn3cBQVbGliYTI9
#include <bits/stdc++.h>
using namespace std;
int dir[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
bool isValid(int x, int y, int n, const vector<vector<char>>& grid) {
return x >= 0 && x < n && y >= 0 && y < n && grid[x][y] != 'M';
}
// @PLACEMENTLELO
int fMW(int n, const vector<vector<char>>& grid, pair<int, int> start, pair<int, int> end) {
vector<vector<int>> placementlelo(n, vector<int>(n, INT_MAX));
queue<pair<int, int>> q;
https://telegram.me/+_hn3cBQVbGliYTI9
q.push(start);
placementlelo[start.first][start.second] = 0;
while (!q.empty()) {
auto [x, y] = q.front();
q.pop();
https://telegram.me/+_hn3cBQVbGliYTI9
for (int d = 0; d < 4; d++) {
int nx = x + dir[d][0];
int ny = y + dir[d][1];
if (isValid(nx, ny, n, grid)) {
int cost = (grid[x][y] == 'T' && grid[nx][ny] == 'T') ? 0 : 1;
if (placementlelo[x][y] + cost < placementlelo[nx][ny]) {
placementlelo[nx][ny] = placementlelo[x][y] + cost;
q.push({nx, ny});
}
}
}
}
https://telegram.me/+_hn3cBQVbGliYTI9
return placementlelo[end.first][end.second];
}
@PLACEMENTLELO
int main() {
int n;
cin >> n;
https://telegram.me/PLACEMENTLELO
vector<vector<char>> grid(n, vector<char>(n));
pair<int, int> start, end;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> grid[i][j];
if (grid[i][j] == 'S') start = {i, j};
if (grid[i][j] == 'E') end = {i, j};
}
}
int result = fMW(n, grid, start, end);
cout << result << endl;
return 0;
}
Desert Queen
C++
TCS CodeVita Zone 2
https://telegram.me/+_hn3cBQVbGliYTI9
C++
TCS CodeVita Zone 2
https://telegram.me/+_hn3cBQVbGliYTI9
#include <bits/stdc++.h>
using namespace std;
int dir[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
bool isValid(int x, int y, int n, const vector<vector<char>>& grid) {
return x >= 0 && x < n && y >= 0 && y < n && grid[x][y] != 'M';
}
// @PLACEMENTLELO
int fMW(int n, const vector<vector<char>>& grid, pair<int, int> start, pair<int, int> end) {
vector<vector<int>> placementlelo(n, vector<int>(n, INT_MAX));
queue<pair<int, int>> q;
https://telegram.me/+_hn3cBQVbGliYTI9
q.push(start);
placementlelo[start.first][start.second] = 0;
while (!q.empty()) {
auto [x, y] = q.front();
q.pop();
https://telegram.me/+_hn3cBQVbGliYTI9
for (int d = 0; d < 4; d++) {
int nx = x + dir[d][0];
int ny = y + dir[d][1];
if (isValid(nx, ny, n, grid)) {
int cost = (grid[x][y] == 'T' && grid[nx][ny] == 'T') ? 0 : 1;
if (placementlelo[x][y] + cost < placementlelo[nx][ny]) {
placementlelo[nx][ny] = placementlelo[x][y] + cost;
q.push({nx, ny});
}
}
}
}
https://telegram.me/+_hn3cBQVbGliYTI9
return placementlelo[end.first][end.second];
}
@PLACEMENTLELO
int main() {
int n;
cin >> n;
https://telegram.me/PLACEMENTLELO
vector<vector<char>> grid(n, vector<char>(n));
pair<int, int> start, end;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> grid[i][j];
if (grid[i][j] == 'S') start = {i, j};
if (grid[i][j] == 'E') end = {i, j};
}
}
int result = fMW(n, grid, start, end);
cout << result << endl;
return 0;
}
Desert Queen
C++
TCS CodeVita Zone 2
https://telegram.me/+_hn3cBQVbGliYTI9
Forwarded from Goldman Sachs Exam Solutions
Buzz Sale
C++
TCS CodeVita Zone 2
https://telegram.me/+_hn3cBQVbGliYTI9
#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;
https://telegram.me/PLACEMENTLELO
int main() {
int n;
cin >> n;
// @PLACEMENTLELO
vector<int> ids(n), costs(n);
for (int i = 0; i < n; i++) cin >> ids[i];
for (int i = 0; i < n; i++) cin >> costs[i];
int budget;
cin >> budget;
// @PLACEMENTLELO
int mfi = 0, mfw = 0;
for (int i = 0; i < n; i++) {
int buyCost = costs[i];
int maxQty = budget / buyCost;
// @PLACEMENTLELO
if (maxQty > 0) {
int cfi = 0;
int cfw = 0;
https://telegram.me/PLACEMENTLELO
for (int j = 0; j < n; j++) {
if (i != j && ids[i] % ids[j] == 0) {
cfi += maxQty;
cfw += costs[j] * maxQty;
}
}
// @PLACEMENTLELO
if (cfi > mfi ||
(cfi == mfi && cfw > mfw)) {
mfi = cfi;
mfw = cfw;
}
}
}
// @PLACEMENTLELO
cout << mfi << " " << mfw << endl;
return 0;
}
Buzz Sale
C++
TCS CodeVita Zone 2
https://telegram.me/+_hn3cBQVbGliYTI9
C++
TCS CodeVita Zone 2
https://telegram.me/+_hn3cBQVbGliYTI9
#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;
https://telegram.me/PLACEMENTLELO
int main() {
int n;
cin >> n;
// @PLACEMENTLELO
vector<int> ids(n), costs(n);
for (int i = 0; i < n; i++) cin >> ids[i];
for (int i = 0; i < n; i++) cin >> costs[i];
int budget;
cin >> budget;
// @PLACEMENTLELO
int mfi = 0, mfw = 0;
for (int i = 0; i < n; i++) {
int buyCost = costs[i];
int maxQty = budget / buyCost;
// @PLACEMENTLELO
if (maxQty > 0) {
int cfi = 0;
int cfw = 0;
https://telegram.me/PLACEMENTLELO
for (int j = 0; j < n; j++) {
if (i != j && ids[i] % ids[j] == 0) {
cfi += maxQty;
cfw += costs[j] * maxQty;
}
}
// @PLACEMENTLELO
if (cfi > mfi ||
(cfi == mfi && cfw > mfw)) {
mfi = cfi;
mfw = cfw;
}
}
}
// @PLACEMENTLELO
cout << mfi << " " << mfw << endl;
return 0;
}
Buzz Sale
C++
TCS CodeVita Zone 2
https://telegram.me/+_hn3cBQVbGliYTI9
Forwarded from Goldman Sachs Exam Solutions
Now, All 100% Correct TCS CodeVita Codes will be posted on both of these channels 👇🏻
1. https://telegram.me/PLACEMENTLELO
2. https://telegram.me/OFF_CAMPUS_JOBS_AND_INTERNSHIPS
Must Join both groups ✅
1. https://telegram.me/PLACEMENTLELO
2. https://telegram.me/OFF_CAMPUS_JOBS_AND_INTERNSHIPS
Must Join both groups ✅
✅ TCS CodeVita All 100% Correct Answers uploaded 👇🏻
https://youtu.be/3r4pYCrpXe8
https://youtu.be/3r4pYCrpXe8
Share this with your friends 😇
https://youtu.be/3r4pYCrpXe8
https://youtu.be/3r4pYCrpXe8
Share this with your friends 😇
Infosys Mass Hiring Internship:
Graduation Year: 2024 / 2025 / 2026 / 2027
Stipend: 25k to 50k per month
Apply Link: https://www.instagram.com/reel/DDURPp5yoBt
Graduation Year: 2024 / 2025 / 2026 / 2027
Stipend: 25k to 50k per month
Apply Link: https://www.instagram.com/reel/DDURPp5yoBt
Infosys SP Exam Answers will be uploaded here 👇🏻
https://telegram.me/+Xqpv6kw1D5k4OTI1
Infosys Exam Discussion Group 👇🏻
https://telegram.me/+njYA5MfMVcs5OTRl
✅ Must join both the groups !
Share these groups with your friends 😇
https://telegram.me/+Xqpv6kw1D5k4OTI1
Infosys Exam Discussion Group 👇🏻
https://telegram.me/+njYA5MfMVcs5OTRl
✅ Must join both the groups !
Share these groups with your friends 😇
Nation With NaMo - Government of India Mega Hiring:
Graduation Year: 2025 / 2026 / 2027 / 2028
Eligibility: 1st, 2nd, 3rd and 4th year College Students can apply in this
🤩 Placement and internship Offers for selected students at Nation With NaMo.
💸 Prizes worth ₹18 Lakhs and macbook are up for grabs.
Apply Link: https://www.instagram.com/reel/DDwpWEMSpxb
Must Apply ✅
Graduation Year: 2025 / 2026 / 2027 / 2028
Eligibility: 1st, 2nd, 3rd and 4th year College Students can apply in this
🤩 Placement and internship Offers for selected students at Nation With NaMo.
💸 Prizes worth ₹18 Lakhs and macbook are up for grabs.
Apply Link: https://www.instagram.com/reel/DDwpWEMSpxb
Must Apply ✅
TCS Mass Hiring:
TCS is Hiring for the role of Ninja and Digital.
Graduation Year: 2025
Salary:
Ninja - 3.36 LPA
Digital - 7 LPA
Location: Across India
Apply Link: https://www.instagram.com/reel/DENDfItSqSy
Telegram: https://telegram.me/PLACEMENTLELO
Registration Deadline: 23rd January 2025
TCS is Hiring for the role of Ninja and Digital.
Graduation Year: 2025
Salary:
Ninja - 3.36 LPA
Digital - 7 LPA
Location: Across India
Apply Link: https://www.instagram.com/reel/DENDfItSqSy
Telegram: https://telegram.me/PLACEMENTLELO
Registration Deadline: 23rd January 2025
Deloitte Mass Hiring:
Deloitte will be hiring 15,000 students through this opportunity.
Eligibility: BE / Btech / ME / Mtech / BCA / MCA / BBA / BSc / BBM / BMS / BFS / BCom
Apply Link: https://www.instagram.com/reel/DEm0KmES3Gw
Share this with your friends 😇
Must Apply ✅
Deloitte will be hiring 15,000 students through this opportunity.
Eligibility: BE / Btech / ME / Mtech / BCA / MCA / BBA / BSc / BBM / BMS / BFS / BCom
Apply Link: https://www.instagram.com/reel/DEm0KmES3Gw
Share this with your friends 😇
Must Apply ✅
Adobe Internship:
Graduation Year: 2024 / 2025 / 2026
Stipend: 1 Lakh per month
Apply Link: https://www.instagram.com/reel/DE7NskLyiRw
Graduation Year: 2024 / 2025 / 2026
Stipend: 1 Lakh per month
Apply Link: https://www.instagram.com/reel/DE7NskLyiRw
Deloitte NLA Complete Guide.pdf
453.1 KB
Deloitte NLA Complete Guide with previous year paper ✅
Share this with your friends 😇
Share this with your friends 😇
Deloitte NLA Exam Answers will be uploaded here 👇🏻
https://telegram.me/+19mMyesoV7llODI1
Deloitte NLA Discussion Group 👇🏻
https://telegram.me/+8B154b769wk4ZjY9
https://telegram.me/+19mMyesoV7llODI1
Deloitte NLA Discussion Group 👇🏻
https://telegram.me/+8B154b769wk4ZjY9
TCS HackQuest Exam Answers will be uploaded here 👇🏻
https://telegram.me/+_hn3cBQVbGliYTI9
TCS HackQuest Discussion Group 👇🏻
https://telegram.me/+oZ4x3k1RtXdkNWU1
Share this with your friends 😇
https://telegram.me/+_hn3cBQVbGliYTI9
TCS HackQuest Discussion Group 👇🏻
https://telegram.me/+oZ4x3k1RtXdkNWU1
Share this with your friends 😇