Samsung Interview Question for fresherss


Country: India
Interview Type: Written Test




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

sample input ?

- sks September 06, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

2
5 6 2 1 3
0 0 5 3 6 0
0 0 2 0 2 0
3 3 1 3 7 0
0 0 0 0 0 0
0 0 0 0 0 0
5 6 2 2 6
3 0 0 0 0 3
2 0 0 0 0 6
1 3 1 1 3 1
2 0 2 0 0 2
0 0 4 3 1 1

- anubha September 09, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

2
5 6 2 1 3
0 0 5 3 6 0
0 0 2 0 2 0
3 3 1 3 7 0
0 0 0 0 0 0
0 0 0 0 0 0
5 6 2 2 6
3 0 0 0 0 3
2 0 0 0 0 6
1 3 1 1 3 1
2 0 2 0 0 2
0 0 4 3 1 1

- anu September 09, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

class endoScope {
public static Scanner scn = new Scanner(System.in);

public static void main(String args[]) throws Exception {
int T = scn.nextInt();
while (T-- > 0) {
int N = scn.nextInt();
int M = scn.nextInt();
int R = scn.nextInt();
int C = scn.nextInt();
int L = scn.nextInt();

int[][] Maze = new int[N][M];
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
Maze[i][j] = scn.nextInt();
}
}
boolean[][] visit = new boolean[N][M];
int[][] dist = new int[N][M];

int[] up = { 0, 1, 1, 0, 1, 0, 0, 1 };
int[] down = { 0, 1, 1, 0, 0, 1, 1, 0 };
int[] left = { 0, 1, 0, 1, 0, 0, 1, 1 };
int[] right = { 0, 1, 0, 1, 1, 1, 0, 0 };

myQueue Q = new myQueue();
if(Maze[R][C] != 0){
Q.add(new Pair(R, C));
visit[R][C] = true;
dist[R][C] = 1;
}

while (!Q.isEmpty()) {
Pair elem = Q.remove();

int x = elem.x;
int y = elem.y;

if (x - 1 >= 0 && up[Maze[x][y]] == 1 && down[Maze[x - 1][y]] == 1 && !visit[x - 1][y]) {
int d = dist[x][y] + 1;
if (d <= L) {
Q.add(new Pair(x - 1, y));
visit[x - 1][y] = true;
dist[x - 1][y] = d;
}
}

if (x + 1 < N && down[Maze[x][y]] == 1 && up[Maze[x + 1][y]] == 1 && !visit[x + 1][y]) {
int d = dist[x][y] + 1;
if (d <= L) {
Q.add(new Pair(x + 1, y));
visit[x + 1][y] = true;
dist[x + 1][y] = d;
}
}

if (y - 1 >= 0 && left[Maze[x][y]] == 1 && right[Maze[x][y - 1]] == 1 && !visit[x][y - 1]) {
int d = dist[x][y] + 1;
if (d <= L) {
Q.add(new Pair(x, y - 1));
visit[x][y - 1] = true;
dist[x][y - 1] = d;
}
}

if (y + 1 < M && right[Maze[x][y]] == 1 && left[Maze[x][y + 1]] == 1 && !visit[x][y + 1]) {
int d = dist[x][y] + 1;
if (d <= L) {
Q.add(new Pair(x, y + 1));
visit[x][y + 1] = true;
dist[x][y + 1] = d;
}
}
}

int count = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
if (dist[i][j] > 0) {
count++;
}
}
}
System.out.println(count);
}
}

static class myQueue {
Pair[] Q = new Pair[1000000];
int front;
int rear;

myQueue() {
front = 0;
rear = 0;
}

public void add(Pair el) {
Q[rear++] = el;
}

public Pair remove() {
return Q[front++];
}

public boolean isEmpty() {
return front == rear;
}
}

static class Pair {
int x;
int y;

Pair(int x1, int y1) {
this.x = x1;
this.y = y1;
}
}
}

- Anonymous September 27, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

class endoScope {
public static Scanner scn = new Scanner(System.in);

public static void main(String args[]) throws Exception {
int T = scn.nextInt();
while (T-- > 0) {
int N = scn.nextInt();
int M = scn.nextInt();
int R = scn.nextInt();
int C = scn.nextInt();
int L = scn.nextInt();

int[][] Maze = new int[N][M];
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
Maze[i][j] = scn.nextInt();
}
}
boolean[][] visit = new boolean[N][M];
int[][] dist = new int[N][M];

int[] up = { 0, 1, 1, 0, 1, 0, 0, 1 };
int[] down = { 0, 1, 1, 0, 0, 1, 1, 0 };
int[] left = { 0, 1, 0, 1, 0, 0, 1, 1 };
int[] right = { 0, 1, 0, 1, 1, 1, 0, 0 };

myQueue Q = new myQueue();
if(Maze[R][C] != 0){
Q.add(new Pair(R, C));
visit[R][C] = true;
dist[R][C] = 1;
}

while (!Q.isEmpty()) {
Pair elem = Q.remove();

int x = elem.x;
int y = elem.y;

if (x - 1 >= 0 && up[Maze[x][y]] == 1 && down[Maze[x - 1][y]] == 1 && !visit[x - 1][y]) {
int d = dist[x][y] + 1;
if (d <= L) {
Q.add(new Pair(x - 1, y));
visit[x - 1][y] = true;
dist[x - 1][y] = d;
}
}

if (x + 1 < N && down[Maze[x][y]] == 1 && up[Maze[x + 1][y]] == 1 && !visit[x + 1][y]) {
int d = dist[x][y] + 1;
if (d <= L) {
Q.add(new Pair(x + 1, y));
visit[x + 1][y] = true;
dist[x + 1][y] = d;
}
}

if (y - 1 >= 0 && left[Maze[x][y]] == 1 && right[Maze[x][y - 1]] == 1 && !visit[x][y - 1]) {
int d = dist[x][y] + 1;
if (d <= L) {
Q.add(new Pair(x, y - 1));
visit[x][y - 1] = true;
dist[x][y - 1] = d;
}
}

if (y + 1 < M && right[Maze[x][y]] == 1 && left[Maze[x][y + 1]] == 1 && !visit[x][y + 1]) {
int d = dist[x][y] + 1;
if (d <= L) {
Q.add(new Pair(x, y + 1));
visit[x][y + 1] = true;
dist[x][y + 1] = d;
}
}
}

int count = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
if (dist[i][j] > 0) {
count++;
}
}
}
System.out.println(count);
}
}

static class myQueue {
Pair[] Q = new Pair[1000000];
int front;
int rear;

myQueue() {
front = 0;
rear = 0;
}

public void add(Pair el) {
Q[rear++] = el;
}

public Pair remove() {
return Q[front++];
}

public boolean isEmpty() {
return front == rear;
}
}

static class Pair {
int x;
int y;

Pair(int x1, int y1) {
this.x = x1;
this.y = y1;
}
}
}

- Ankit-java soln September 27, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

class endoScope {
public static Scanner scn = new Scanner(System.in);

public static void main(String args[]) throws Exception {
int T = scn.nextInt();
while (T-- > 0) {
int N = scn.nextInt();
int M = scn.nextInt();
int R = scn.nextInt();
int C = scn.nextInt();
int L = scn.nextInt();

int[][] Maze = new int[N][M];
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
Maze[i][j] = scn.nextInt();
}
}
boolean[][] visit = new boolean[N][M];
int[][] dist = new int[N][M];

int[] up = { 0, 1, 1, 0, 1, 0, 0, 1 };
int[] down = { 0, 1, 1, 0, 0, 1, 1, 0 };
int[] left = { 0, 1, 0, 1, 0, 0, 1, 1 };
int[] right = { 0, 1, 0, 1, 1, 1, 0, 0 };

myQueue Q = new myQueue();
if(Maze[R][C] != 0){
Q.add(new Pair(R, C));
visit[R][C] = true;
dist[R][C] = 1;
}

while (!Q.isEmpty()) {
Pair elem = Q.remove();

int x = elem.x;
int y = elem.y;

if (x - 1 >= 0 && up[Maze[x][y]] == 1 && down[Maze[x - 1][y]] == 1 && !visit[x - 1][y]) {
int d = dist[x][y] + 1;
if (d <= L) {
Q.add(new Pair(x - 1, y));
visit[x - 1][y] = true;
dist[x - 1][y] = d;
}
}

if (x + 1 < N && down[Maze[x][y]] == 1 && up[Maze[x + 1][y]] == 1 && !visit[x + 1][y]) {
int d = dist[x][y] + 1;
if (d <= L) {
Q.add(new Pair(x + 1, y));
visit[x + 1][y] = true;
dist[x + 1][y] = d;
}
}

if (y - 1 >= 0 && left[Maze[x][y]] == 1 && right[Maze[x][y - 1]] == 1 && !visit[x][y - 1]) {
int d = dist[x][y] + 1;
if (d <= L) {
Q.add(new Pair(x, y - 1));
visit[x][y - 1] = true;
dist[x][y - 1] = d;
}
}

if (y + 1 < M && right[Maze[x][y]] == 1 && left[Maze[x][y + 1]] == 1 && !visit[x][y + 1]) {
int d = dist[x][y] + 1;
if (d <= L) {
Q.add(new Pair(x, y + 1));
visit[x][y + 1] = true;
dist[x][y + 1] = d;
}
}
}

int count = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
if (dist[i][j] > 0) {
count++;
}
}
}
System.out.println(count);
}
}

static class myQueue {
Pair[] Q = new Pair[1000000];
int front;
int rear;

myQueue() {
front = 0;
rear = 0;
}

public void add(Pair el) {
Q[rear++] = el;
}

public Pair remove() {
return Q[front++];
}

public boolean isEmpty() {
return front == rear;
}
}

static class Pair {
int x;
int y;

Pair(int x1, int y1) {
this.x = x1;
this.y = y1;
}
}
}

- Ankit-java soln September 27, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

class endoScope {
public static Scanner scn = new Scanner(System.in);

public static void main(String args[]) throws Exception {
int T = scn.nextInt();
while (T-- > 0) {
int N = scn.nextInt();
int M = scn.nextInt();
int R = scn.nextInt();
int C = scn.nextInt();
int L = scn.nextInt();

int[][] Maze = new int[N][M];
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
Maze[i][j] = scn.nextInt();
}
}
boolean[][] visit = new boolean[N][M];
int[][] dist = new int[N][M];

int[] up = { 0, 1, 1, 0, 1, 0, 0, 1 };
int[] down = { 0, 1, 1, 0, 0, 1, 1, 0 };
int[] left = { 0, 1, 0, 1, 0, 0, 1, 1 };
int[] right = { 0, 1, 0, 1, 1, 1, 0, 0 };

myQueue Q = new myQueue();
if(Maze[R][C] != 0){
Q.add(new Pair(R, C));
visit[R][C] = true;
dist[R][C] = 1;
}

while (!Q.isEmpty()) {
Pair elem = Q.remove();

int x = elem.x;
int y = elem.y;

if (x - 1 >= 0 && up[Maze[x][y]] == 1 && down[Maze[x - 1][y]] == 1 && !visit[x - 1][y]) {
int d = dist[x][y] + 1;
if (d <= L) {
Q.add(new Pair(x - 1, y));
visit[x - 1][y] = true;
dist[x - 1][y] = d;
}
}

if (x + 1 < N && down[Maze[x][y]] == 1 && up[Maze[x + 1][y]] == 1 && !visit[x + 1][y]) {
int d = dist[x][y] + 1;
if (d <= L) {
Q.add(new Pair(x + 1, y));
visit[x + 1][y] = true;
dist[x + 1][y] = d;
}
}

if (y - 1 >= 0 && left[Maze[x][y]] == 1 && right[Maze[x][y - 1]] == 1 && !visit[x][y - 1]) {
int d = dist[x][y] + 1;
if (d <= L) {
Q.add(new Pair(x, y - 1));
visit[x][y - 1] = true;
dist[x][y - 1] = d;
}
}

if (y + 1 < M && right[Maze[x][y]] == 1 && left[Maze[x][y + 1]] == 1 && !visit[x][y + 1]) {
int d = dist[x][y] + 1;
if (d <= L) {
Q.add(new Pair(x, y + 1));
visit[x][y + 1] = true;
dist[x][y + 1] = d;
}
}
}

int count = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
if (dist[i][j] > 0) {
count++;
}
}
}
System.out.println(count);
}
}

static class myQueue {
Pair[] Q = new Pair[1000000];
int front;
int rear;

myQueue() {
front = 0;
rear = 0;
}

public void add(Pair el) {
Q[rear++] = el;
}

public Pair remove() {
return Q[front++];
}

public boolean isEmpty() {
return front == rear;
}
}

static class Pair {
int x;
int y;

Pair(int x1, int y1) {
this.x = x1;
this.y = y1;
}
}
}

- Anonymous November 14, 2018 | 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