xyz Interview Question for Software Analysts


Country: United States
Interview Type: Written Test




Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <iostream>
#include <vector>
#include <limits>

using namespace std;

vector<pair<int, int>> findMaxMinimumPositions(vector<vector<int>>& grid) {
int n = grid.size();
int maxMinimum = numeric_limits<int>::min();
vector<pair<int, int>> positions;

// Iterate over each block in the grid
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
int minimum = numeric_limits<int>::max();

// Calculate the minimum amount considering all neighboring blocks
for (int dx = -1; dx <= 1; dx++) {
for (int dy = -1; dy <= 1; dy++) {
int ni = i + dx;
int nj = j + dy;

if (ni >= 0 && ni < n && nj >= 0 && nj < n) {
minimum = min(minimum, grid[ni][nj]);
}
}
}

// Update the maximum minimum amount and positions
if (minimum > maxMinimum) {
maxMinimum = minimum;
positions.clear();
positions.push_back({i + 1, j + 1});
} else if (minimum == maxMinimum) {
positions.push_back({i + 1, j + 1});
}
}
}

return positions;
}

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

vector<vector<int>> grid(N, vector<int>(N));

// Read the grid description
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
char delimiter;
cin >> grid[i][j];
if (j < N - 1) {
cin >> delimiter;
}
}
}

// Find the positions with the maximum minimum amount
vector<pair<int, int>> positions = findMaxMinimumPositions(grid);

// Print the positions
for (const auto& pos : positions) {
cout << pos.first << "#" << pos.second << endl;
}

return 0;
}

- Vijith Pramod G July 05, 2023 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <iostream>
#include <vector>
#include <limits>

using namespace std;

vector<pair<int, int>> findMaxMinimumPositions(vector<vector<int>>& grid) {
int n = grid.size();
int maxMinimum = numeric_limits<int>::min();
vector<pair<int, int>> positions;

// Iterate over each block in the grid
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
int minimum = numeric_limits<int>::max();

// Calculate the minimum amount considering all neighboring blocks
for (int dx = -1; dx <= 1; dx++) {
for (int dy = -1; dy <= 1; dy++) {
int ni = i + dx;
int nj = j + dy;

if (ni >= 0 && ni < n && nj >= 0 && nj < n) {
minimum = min(minimum, grid[ni][nj]);
}
}
}

// Update the maximum minimum amount and positions
if (minimum > maxMinimum) {
maxMinimum = minimum;
positions.clear();
positions.push_back({i + 1, j + 1});
} else if (minimum == maxMinimum) {
positions.push_back({i + 1, j + 1});
}
}
}

return positions;
}

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

vector<vector<int>> grid(N, vector<int>(N));

// Read the grid description
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
char delimiter;
cin >> grid[i][j];
if (j < N - 1) {
cin >> delimiter;
}
}
}

// Find the positions with the maximum minimum amount
vector<pair<int, int>> positions = findMaxMinimumPositions(grid);

// Print the positions
for (const auto& pos : positions) {
cout << pos.first << "#" << pos.second << endl;
}

return 0;
}

- Vijith Pramod G July 05, 2023 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More