IBM Coding Exam Answers
2.45K subscribers
13 photos
70 links
Download Telegram
#include<bits/stdc++.h>
using namespace std;

void mark(int xa, int ya, int ha, vector<vector<int>> &matrix, vector<vector<int>> &visited) {
int rows = matrix.size(), cols = matrix[0].size();
visited[xa][ya] = 1;
int delta[5] = {-1, 0, +1, 0, -1};
for(int i = 0; i < 4; i++) {
int ax = xa + delta[i];
int ay = ya + delta[i+1];
if(min(ax, ay) >= 0 && ax < rows && ay < cols && matrix[ax][ay] <= ha && !visited[ax][ay]) {
mark(ax, ay, ha, matrix, visited);
}
}
}

void go2(int x, int y, int cell, vector<vector<int>> &matrix, vector<vector<int>> &visited) {
int rows = matrix.size(), cols = matrix[0].size();
int delta[5] = {-1, 0, +1, 0, -1};
visited[x][y] = 0;
for(int i = 0; i < 4; i++) {
int nx = x + delta[i];
int ny = y + delta[i+1];
if(min(nx, ny) >= 0 && nx < rows && ny < cols && matrix[nx][ny] == cell && visited[nx][ny]) {
go2(nx, ny, cell, matrix, visited);
}
}
}

int main() {
int rows, cols;
cin >> rows >> cols;
vector<vector<int>> matrix(rows, vector<int>(cols)), visited(rows, vector<int>(cols, 0));
for(int i = 0; i < rows; i++)
for(int j = 0; j < cols; j++)
cin >> matrix[i][j];

int x, y, h;
cin >> x >> y >> h;

if(matrix[x][y] == 0) mark(x, y, h, matrix, visited);

int count = 0;
for(int i = 0; i < rows; i++) {
for(int j = 0; j < cols; j++) {
if(visited[i][j]) {
count += matrix[i][j] != 0;
go2(i, j, matrix[i][j], matrix, visited);
}
}
}

if (count == 0) cout << "NONE";
else cout << count;

return 0;
}

BlackBeard Code

Pls share

https://t.me/TCS_Codevita_Exam_Help
This media is not supported in your browser
VIEW IN TELEGRAM
SUBSCRIBE FAST... I AM ALREADY UPLOADING ALOT OF CODE
This media is not supported in your browser
VIEW IN TELEGRAM
100 SUBS DONE.. which new code you want?
Decide fast
This media is not supported in your browser
VIEW IN TELEGRAM
Fencing Code
C++
TCS Codevita

https://t.me/TCS_Codevita_Exam_Help

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int x, y, x1, y1, x2, y2;
    cin >> x >> y >> x1 >> y1 >> x2 >> y2;
   
    x = abs(x);
    y = abs(y);
    x1 = abs(x1);
    y1 = abs(y1);
    x2 = abs(x2);
    y2 = abs(y2);
   
    int r1 = sqrt(((x1 - x) * (x1 - x)) + ((y1 - y) * (y1 - y)));
    int r2 = sqrt(((x2 - x) * (x2 - x)) + ((y2 - y) * (y2 - y)));
   
    int a1 = M_PI * r1 * r1;
    int a2 = M_PI * r2 * r2;
   
    if (a2 > a1)
    {
        int e = a2 - a1;
        int f = sqrt(e);
        int g = f * f;
        int h = g - e;
        int i = h * 20;
        cout << "Krishna " << i;
    }
    else if (a1 > a2)
    {
        int p = a1 - a2;
        int q = p * 20;
        cout << "Shiva " << q;
    }
    else if (a1 == a2)
    {
        cout << "-1";
    }

    return 0;
}

Fencing Code
C++
TCS Codevita

https://t.me/TCS_Codevita_Exam_Help
This media is not supported in your browser
VIEW IN TELEGRAM
SUBSCRIBE MORE.... SHARE THIS CHANNEL
I have... Bubble Sort, Password Generator and Captcha Code
#include<bits/stdc++.h>
using namespace std;

int main()
{
int x, y, x1, y1, x2, y2;
cin >> x >> y >> x1 >> y1 >> x2 >> y2;

x = abs(x);
y = abs(y);
x1 = abs(x1);
y1 = abs(y1);
x2 = abs(x2);
y2 = abs(y2);

int r1 = sqrt(((x1 - x) * (x1 - x)) + ((y1 - y) * (y1 - y)));
int r2 = sqrt(((x2 - x) * (x2 - x)) + ((y2 - y) * (y2 - y)));

int a1 = M_PI * r1 * r1;
int a2 = M_PI * r2 * r2;

if (a2 > a1)
{
int e = a2 - a1;
int f = sqrt(e);
int g = f * f;
int h = g - e;
int i = h * 20;
cout << "Krishna " << i;
}
else if (a1 > a2)
{
int p = a1 - a2;
int q = p * 20;
cout << "Shiva " << q;
}
else if (a1 == a2)
{
cout << "-1";
}

return 0;
}

Fencing Problem

Pls share

https://t.me/TCS_Codevita_Exam_Help
This media is not supported in your browser
VIEW IN TELEGRAM
Sports Day
Pytho
n
TCS Codevita


def ans(numbers):
numbers.sort()
n = len(numbers)
placementlelo = 0

for i in range(n):
efficiency = 0
priority = 1

for j in range(i, n):
efficiency += numbers[j] * priority
priority += 1

if efficiency > placementlelo:
placementlelo = efficiency

return placementlelo

numbers = list(map(int, input().split()))

result = ans(numbers)
if(result>0):
print(result, end="")
else:
print(0, end="")

Sports Day
Pytho
n
TCS Codevita


Pls share

https://t.me/TCS_Codevita_Exam_Help
This media is not supported in your browser
VIEW IN TELEGRAM
SUBSCRIBE MORE.... SHARE THIS CHANNEL

NEXT UPCOMING CODES:

BUBBLE SORT

Password Generator
Also For Discussion.. You can Join: @Codeing_Are