TCS CodeVita Season 12 Solutions


Гео и язык канала: Индия, Английский
Категория: Карьера


TCS CodeVita Exam Answers will be uploaded here.
Latest Jobs and Internships are regularly uploaded here - @placementlelo
If you want any other exam answers for free : @exam_cheating_bot
Collaborations: @growth_admin

Связанные каналы  |  Похожие каналы

Гео и язык канала
Индия, Английский
Категория
Карьера
Статистика
Фильтр публикаций


Nation with NaMo Mass Hiring:

Graduation Year: 2025 / 2026 / 2027 / 2028

Stipend: 10k to 25k per month
Salary: 5 to 12 LPA

Apply Link: https://www.instagram.com/reel/DDwpWEMSpxb

Must Apply ✅

10k 1 41 8 28

Infosys Mass Hiring Internship:

Graduation Year: 2024 / 2025 / 2026 / 2027

Stipend: 25k to 50k per month

Apply Link: https://www.instagram.com/reel/DDURPp5yoBt

30.6k 1 121 28 45

How many questions have you solved ?
Опрос
  •  
  •   1
  •   2
  •   3
  •   4
  •   5
  •   6
9381 голосов

49k 0 7 99 121

Latest Off-Campus Jobs and Internships are Uploaded regularly here👇
1. https://telegram.me/PLACEMENTLELO

2. https://telegram.me/OFF_CAMPUS_JOBS_AND_INTERNSHIPS

✅ Must Join ✅


Toggle Challenge
Python
100% Correct Code ✅
TCS CodeVita Zone 2

https://telegram.me/+_hn3cBQVbGliYTI9

def placementlelo(valid_digits, fd):
pd = []
for digit, valid in valid_digits.items():
diff = sum(1 for a, b in zip(fd, valid) if a != b)
if diff == 0:
pd.append(digit)
elif diff == 1:
pd.append(digit)
return pd
https://telegram.me/PLACEMENTLELO

def solve():
sd = [input().strip() for _ in range(3)]
https://telegram.me/PLACEMENTLELO

fad = [input().strip() for _ in range(3)]

valid_digits = {}
for i in range(10):
valid_digits[i] = ''.join(sd[j][i*3:(i+1)*3] for j in range(3))

faulty_number = []
for i in range(len(fad[0]) // 3):
fd = ''.join(fad[j][i*3:(i+1)*3] for j in range(3))
pd = placementlelo(valid_digits, fd)
if not pd:
print("Invalid",end='')
return
faulty_number.append(pd)
https://telegram.me/PLACEMENTLELO

from itertools import product
ts = 0
for possible in product(*faulty_number):
ts += int(''.join(map(str, possible)))
print(ts,end='')
solve()

Toggle Challenge
Python
100% Correct Code ✅
TCS CodeVita Zone 2

https://telegram.me/+_hn3cBQVbGliYTI9

44.7k 0 333 1.7k 147

Best Competitive Programming and Coding Groups:

CodeChef Answers Group 👇
https://telegram.me/codechef_answers

Codeforces Answers Group 👇
https://telegram.me/codeforces_answers

Leetcode Answers Group👇
https://telegram.me/leetcode_answers

Coding Ninjas Answers Group 👇
https://telegram.me/+y6lKe5QXT1w2ODhl

Geeks For Geeks Answers Group👇
https://telegram.me/gfg_answers

Newton School Group 👇
https://telegram.me/newton_school_answers

AtCoder Group 👇
https://telegram.me/atcoder_answers

29.2k 0 53 245 32

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 ✅

35.8k 9 10 349 35

Block Extraction
C++
TCS CodeVita Zone 2

https://telegram.me/+_hn3cBQVbGliYTI9

#include
using namespace std;
https://telegram.me/PLACEMENTLELO

int main() {
int x, y;
cin >> x >> y;
vector z(x, vector(y));

for (int i = 0; i < x; ++i) {
for (int j = 0; j < y; ++j) {
cin >> z[i][j];
}
}
https://telegram.me/PLACEMENTLELO

int w;
cin >> w;

map a;
set b;
for (int i = 0; i < x; ++i) {
for (int j = 0; j < y; ++j) {
int c = z[i][j];
a[c].emplace_back(i, j);
b.insert(c);
}
}
https://telegram.me/PLACEMENTLELO

set d;
for (int i = 0; i < x; ++i) {
vector e;
for (int j = 0; j < y; ++j) {
if (z[i][j] == w) {
e.push_back(j);
}
}
if (!e.empty()) {
int f = *max_element(e.begin(), e.end());
for (int j = f + 1; j < y; ++j) {
int g = z[i][j];
if (g != w) {
d.insert(g);
}
}
}
}
https://telegram.me/PLACEMENTLELO

set h = b;
d.erase(w);
int i = 0;
for (auto j = d.begin(); j != d.end(); ++j) {
if (h.find(*j) != h.end()) {
h.erase(*j);
i++;
}
}
https://telegram.me/PLACEMENTLELO

auto k = [&](const set& l) -> set {
set m;
for (auto& n : l) {
for (auto& [o, p] : a[n]) {
if (o == x - 1) {
m.insert(n);
break;
}
}
}
https://telegram.me/PLACEMENTLELO

queue q;
for (auto& r : m) {
q.push(r);
}
while (!q.empty()) {
int s = q.front();
q.pop();
for (auto& t : l) {
if (m.find(t) != m.end()) continue;
bool u = false;
for (auto& [v, w] : a[t]) {
if (v + 1 < x) {
int x = z[v + 1][w];
if (m.find(x) != m.end()) {
u = true;
break;
}
}
}
if (u) {
m.insert(t);
q.push(t);
}
}
}
return m;
};
https://telegram.me/PLACEMENTLELO

while (true) {
set y = k(h);
set z;
for (auto& aa : h) {
if (y.find(aa) == y.end()) {
z.insert(aa);
}
}
if (z.empty()) break;
for (auto& bb : z) {
h.erase(bb);
i++;
}
}
https://telegram.me/PLACEMENTLELO

cout

37.6k 9 134 148 56

Maximum Area
C++
TCS CodeVita Zone 2

https://telegram.me/+_hn3cBQVbGliYTI9

#include
#include
#include
#include
#include
#include
using namespace std;
https://telegram.me/PLACEMENTLELO

int calculateArea(const vector& polygon) {
int n = polygon.size();
int area = 0;
for (int i = 0; i < n; i++) {
int j = (i + 1) % n;
area += polygon[i].first * polygon[j].second;
area -= polygon[j].first * polygon[i].second;
}
return abs(area) / 2;
}
https://telegram.me/PLACEMENTLELO

bool areConnected(pair a, pair b, pair& p1, pair& p2) {
return (p1 == a && p2 == b) || (p1 == b && p2 == a);
}

int main() {
int N;
cin >> N;

vector coordinates;
vector segments(N);
set points;
https://telegram.me/PLACEMENTLELO

for (int i = 0; i < N; i++) {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
coordinates.push_back({x1, y1});
coordinates.push_back({x2, y2});
points.insert({x1, y1});
points.insert({x2, y2});
}

vector polygon;
int placementlelo = 0;
https://telegram.me/PLACEMENTLELO

for (auto p1 = points.begin(); p1 != points.end(); ++p1) {
for (auto p2 = next(p1); p2 != points.end(); ++p2) {
polygon.push_back(*p1);
polygon.push_back(*p2);
placementlelo = max(placementlelo, calculateArea(polygon));
}
}
https://telegram.me/PLACEMENTLELO

cout

30.6k 9 324 132 48

TCS Cart
C++
100% Correct Code ✅
TCS CodeVita Zone 2

https://telegram.me/+_hn3cBQVbGliYTI9

#include
#include
#include
#include
#include
https://telegram.me/PLACEMENTLELO

using namespace std;

struct Point {
double x, y;
Point(double x = 0, double y = 0) : x(x), y(y) {}
};
https://telegram.me/PLACEMENTLELO

Point rotatePoint(const Point &p, double theta) {
return Point(p.x * cos(theta) - p.y * sin(theta),
p.x * sin(theta) + p.y * cos(theta));
}
https://telegram.me/PLACEMENTLELO

pair getBoundingBox(const vector &polygon, double theta) {
double minX = 1e9, maxX = -1e9, minY = 1e9, maxY = -1e9;
for (const auto &p : polygon) {
Point rotated = rotatePoint(p, theta);
minX = min(minX, rotated.x);
maxX = max(maxX, rotated.x);
minY = min(minY, rotated.y);
maxY = max(maxY, rotated.y);
}
return {maxX - minX, maxY - minY};
}
https://telegram.me/PLACEMENTLELO

int main() {
int N;
cin >> N;
vector polygon(N);
for (int i = 0; i < N; ++i) {
cin >> polygon[i].x >> polygon[i].y;
}
https://telegram.me/PLACEMENTLELO

double placementlelo = 1e9;
double bestWidth = 0, bestHeight = 0;
https://telegram.me/PLACEMENTLELO

for (int i = 0; i < 360; ++i) {
double angle = i * M_PI / 180.0;
auto [width, height] = getBoundingBox(polygon, angle);
double area = width * height;
if (area < placementlelo) {
placementlelo = area;
bestWidth = width;
bestHeight = height;
}
}
https://telegram.me/PLACEMENTLELO

if (bestWidth > bestHeight) {
swap(bestWidth, bestHeight);
}

cout

25.7k 9 214 62 53

Count Press
C++
100% Correct Code ✅
TCS CodeVita Zone 2

https://telegram.me/+_hn3cBQVbGliYTI9

#include
using namespace std;
https://telegram.me/PLACEMENTLELO

bool isP(int px, int py, const vector& placementlelo) {
int crossings = 0, vCount = placementlelo.size();
for (int i = 0; i < vCount; ++i) {
int vx1 = placementlelo[i].first, vy1 = placementlelo[i].second;
int vx2 = placementlelo[(i + 1) % vCount].first, vy2 = placementlelo[(i + 1) % vCount].second;
if (((vy1 py)) || ((vy2 py))) {
double intersectX = vx1 + (double)(py - vy1) * (vx2 - vx1) / (vy2 - vy1);
if (intersectX > px) crossings++;
}
}
return (crossings % 2) != 0;
}
https://telegram.me/PLACEMENTLELO

int main() {
ios::sync_with_stdio(false);
cin.tie(0);

int vertexCount;
cin >> vertexCount;
vector polygon(vertexCount);
int minX = INT_MAX, maxX = INT_MIN, minY = INT_MAX, maxY = INT_MIN;
https://telegram.me/PLACEMENTLELO

for (auto& ver : polygon) {
cin >> ver.first >> ver.second;
minX = min(minX, ver.first);
maxX = max(maxX, ver.first);
minY = min(minY, ver.second);
maxY = max(maxY, ver.second);
}
https://telegram.me/PLACEMENTLELO

int blockSize;
cin >> blockSize;

int width = maxX - minX + 1, height = maxY - minY + 1;
vector area(height, vector(width, 0));

for (int y = minY; y < maxY; ++y) {
for (int x = minX; x < maxX; ++x) {
if (isP(x + 0.5, y + 0.5, polygon)) {
area[y - minY][x - minX] = 1;
}
}
}
https://telegram.me/PLACEMENTLELO

vector fc;
for (int r = 0; r < height; ++r) {
for (int c = 0; c < width; ++c) {
if (area[r][c] == 1) {
fc.emplace_back(r, c);
}
}
}
https://telegram.me/PLACEMENTLELO

sort(fc.begin(), fc.end());

int minA = INT_MAX;

function explore = [&](int currIn, vector& currentGrid, int actionCount) {
if (actionCount >= minA) return;
while (currIn < fc.size() && currentGrid[fc[currIn].first][fc[currIn].second] == 0) {
currIn++;
}
if (currIn == fc.size()) {
minA = min(minA, actionCount);
return;
}
int currentY = fc[currIn].first, currentX = fc[currIn].second;
bool canPlaceBlock = true;

for (int dy = 0; dy < blockSize && canPlaceBlock; dy++) {
for (int dx = 0; dx < blockSize && canPlaceBlock; dx++) {
int newY = currentY + dy, newX = currentX + dx;
if (newY >= height or newX >= width or currentGrid[newY][newX] == 0) {
canPlaceBlock = false;
}
}
}
https://telegram.me/PLACEMENTLELO

if (canPlaceBlock) {
vector updatedGrid = currentGrid;
for (int dy = 0; dy < blockSize; dy++) {
for (int dx = 0; dx < blockSize; dx++) {
int newY = currentY + dy, newX = currentX + dx;
if (newY < height && newX < width) updatedGrid[newY][newX] = 0;
}
}
explore(currIn + 1, updatedGrid, actionCount + 1);
}
};
https://telegram.me/PLACEMENTLELO

explore(0, area, 0);

cout

25k 9 245 42 44

Plague 2050
Python
100% Correct Code ✅
TCS CodeVita Zone 2

https://telegram.me/+_hn3cBQVbGliYTI9

from collections import deque
https://telegram.me/PLACEMENTLELO

def infected_neighbors_count(placementlelo, a, b):
n = len(placementlelo)
count = 0
directions = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)]
for i in range(len(directions)):
dx, dy = directions[i]
nx, ny = a + dx, b + dy
if 0

25.1k 9 185 35 29

Toggle Challenge
Java
100% Correct Code ✅
TCS CodeVita Zone 2

https://telegram.me/+_hn3cBQVbGliYTI9

import java.util.*;

public class Toggle{
https://telegram.me/PLACEMENTLELO

public static List getPossibleDigits(Map validDigits, String fd) {
List potd = new ArrayList();

for (Map.Entry entry : validDigits.entrySet()) {
int mismatches = 0;
String pattern = entry.getValue();
https://telegram.me/PLACEMENTLELO

for (int i = 0; i < fd.length(); i++) {
if (fd.charAt(i) != pattern.charAt(i)) {
mismatches++;
}
}
https://telegram.me/PLACEMENTLELO

if (mismatches

28.4k 9 1.1k 109 84

Equation Puzzle
C++
100% Correct Code ✅
TCS CodeVita Zone 2

https://telegram.me/+_hn3cBQVbGliYTI9

https://telegram.me/PLACEMENTLELO

int main()
{
string e1, e2;
int r;
cin >> e1 >> e2 >> r;
int a1, b1, c1, d1, n1, a2, b2, c2, d2, n2;
sscanf(e1.c_str(), "%dx+%dy+%dz+%dw

29.3k 9 123 25 24

Segment Display
100% Correct Code ✅
C++

TCS CodeVita Zone 2
https://telegram.me/+_hn3cBQVbGliYTI9

#include
#include
#include
#include
#include

using namespace std;
https://telegram.me/PLACEMENTLELO

unordered_map alp = {
{92229, {'A', 'D'}}, {93339, {'B'}}, {92222, {'C', 'F'}}, {93333, {'E'}}, {92336, {'G'}},
{91119, {'H', 'N', 'U'}}, {22322, {'I'}}, {62229, {'J'}}, {92226, {'K'}}, {91111, {'L'}},
{91519, {'M', 'W'}}, {72227, {'O'}}, {92225, {'P'}}, {92339, {'Q'}}, {93336, {'R'}},
{63336, {'S'}}, {11911, {'T'}}, {71117, {'V'}}, {22122, {'X'}}, {62226, {'Y'}}, {23332, {'Z'}}
};
https://telegram.me/PLACEMENTLELO

char checkChr(int s, const vector& led) {
string valStr = "";
for (int i = 0; i < 5; i++) {
int t = 0;
for (int j = 0; j < 9; j++) {
t += led[j][s + i] - '0'; // Convert char to int
}
valStr += to_string(t);
}
int val = stoi(valStr);
if (val == 91519) {
return (led[0].substr(s, 5) == "11111") ? 'M' : 'W';
} else if (val == 91119) {
if (led[8].substr(s, 5) == "11111") return 'U';
if (led[4].substr(s, 5) == "11111") return 'H';
return 'N';
} else if (val == 92222) {
return (led[4].substr(s, 5) == "11111") ? 'F' : 'C';
} else if (val == 92229) {
return (led[8].substr(s, 5) == "11111") ? 'D' : 'A';
} else {
return alp[val][0];
}
}
https://telegram.me/PLACEMENTLELO

string solve(const vector& led) {
int tb = led[0].size();
string merged = led[0];
for (int i = 1; i < 9; i++) {
for (int j = 0; j < tb; j++) {
merged[j] = (merged[j] - '0' | led[i][j] - '0') + '0'; // Perform OR operation and convert back to char
}
}
https://telegram.me/PLACEMENTLELO

string result = "";
int s = 0;
while (s < tb) {
if (merged[s] == '1') {
result += checkChr(s, led);
s += 5; // Skip 5 positions
} else {
s++;
}
}
return result;
}
https://telegram.me/PLACEMENTLELO

int main() {
int t = 9;
vector led(t);
for (int i = 0; i < t; i++) {
cin >> led[i];
}
cout

35.3k 9 671 2.8k 148

TCS CodeVita All 100% Correct Answers uploaded 👇🏻
https://youtu.be/3r4pYCrpXe8
https://youtu.be/3r4pYCrpXe8

Share this with your friends 😇

35.2k 9 15 137 11

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 ✅


String Puzzle
C++

TCS CodeVita Zone 2
https://telegram.me/+_hn3cBQVbGliYTI9

#include
#include
#include
#include
#include
#include
using namespace std;
https://telegram.me/PLACEMENTLELO

unordered_map calculateLevels(unordered_map& graph, const string& root) {
unordered_map levels;
queue q;
q.push(make_pair(root, 1));

while (!q.empty()) {
pair current = q.front();
q.pop();
string node = current.first;
int level = current.second;
levels[node] = level;

for (const string& child : graph[node]) {
q.push(make_pair(child, level + 1));
}
}

return levels;
}
https://telegram.me/PLACEMENTLELO

int main() {
int n;
cin >> n;

unordered_map graph;
unordered_set children;
unordered_set nodes;

for (int i = 0; i < n; ++i) {
string parent, child;
cin >> parent >> child;
graph[parent].push_back(child);
children.insert(child);
nodes.insert(parent);
nodes.insert(child);
}
https://telegram.me/PLACEMENTLELO

string root;
for (const string& node : nodes) {
if (children.find(node) == children.end()) {
root = node;
break;
}
}
https://telegram.me/PLACEMENTLELO

unordered_map levels = calculateLevels(graph, root);

cin.ignore();
string inputLine, word;
getline(cin, inputLine);
stringstream ss(inputLine);

int totalValue = 0;

while (ss >> word) {
if (levels.find(word) != levels.end()) {
totalValue += levels[word];
} else {
totalValue += -1;
}
}
https://telegram.me/PLACEMENTLELO

cout

37.7k 9 361 57 42

Follow the WhatsApp channel fast guys 👇🏻
https://www.whatsapp.com/channel/0029Va4bojk90x2rq1LgdD1a


We will be uploading all the 100% Correct answers on whatsapp, so follow this channel fast else you will regret later 👇🏻
https://www.whatsapp.com/channel/0029Va4bojk90x2rq1LgdD1a

Показано 20 последних публикаций.