## Adobe Interview Question for Software Engineer in Tests

Country: India
Interview Type: In-Person

Comment hidden because of low score. Click to expand.
1
of 3 vote

``````void printDiagonal(int a[][],int n)
{
for(int i=n-1,j=0;i>=0;i--,j++)
cout<<" "<<a[i][j];
}``````

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

``````#include<stdio.h>
#include<stdlib.h>

int main()
{
int i, j, row, col, a;
printf("\nEnter the number of rows and columns\n");
scanf("%d %d", &row, &col);
printf("\nEnter the elements row-wise\n");
for(i = 0; i < row; i++)
for(j = 0; j < col; j++)
scanf("%d", &a[i][j]);
for(i = 0; i < row; i++)
{
for(j = 0; j < col; j++)
printf("%d\t", a[i][j]);
printf("\n");
}
printf("\nFollowing are the elements from left-bottom to right-top\n");
for(i = row - 1, j = 0; i >= 0; i--, j++)
{
printf("%d\t", a[i][j]);
}
system("pause");
return 0;
}``````

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

I am very sure the question is not as simple as it seems. The interviewer wanted me to avoid loops.

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

To avoid loops? So perhaps he/she was looking for a recursive solution (which is a hidden loop in anyway!) On the other hand to write recursion for this is kind of problems is overkill.

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

``````template<class M>
void printDiagonal(const M& rowmajor,std::size_t n)
{
for(std::size_t r=n,c=0;r--;++c)
std::cout << rowmajor[r][c] << std::endl;
}``````

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

``````Below code is without using loops
int n=5;
printDiagonal(a, 0, n-1);

void printDiagonal(int a[], int i, int n)
{
if(i > n)
return;
cout << a[n-i][i] << " ";
i++;
printDiagonal(a, i, n);
}``````

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

/*
matrix with order(nxn)
*/
for(int i=n-1; i>=0; ) {
for(int j=0; j<n; j++, i--) {
System.out.println(matrix[i][j]);
}
}

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

``````/*
matrix with order(nxn)
*/
for(int i=n-1; i>=0; ) {
for(int j=0; j<n; j++, i--) {
System.out.println(matrix[i][j]);
}``````

}

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

``````#include<iostream>
using namespace std;

int printDiagonal(int a, int n, int m)
{
if(m!=0)
printDiagonal(a, n, m-1);

cout<<a[n-m][m]<<"\t";
return 0;
}

int main()
{
int a;
int n;

cout<<"Enter the value of N in NxN matrix : ";
cin>>n;

for(int i=0; i<n; i++)
{
for(int j=0; j<n; j++)
{
a[i][j] = i*n +j;
}
}

for(int i=0; i<n; i++)
{
for(int j=0; j<n; j++)
{
cout<<a[i][j]<<"  ";
}cout<<"\n";
}cout<<"\n\n";
//
printDiagonal(a, n-1, n-1);

system("pause");
return 0;
}``````

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

``````void print_bl_tr_diag(int a[][], int n)
{
for (int j = n - 1; j >= 0; j--)
printf("%d\n", a[j][n - j - ]);
}``````

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

When the interviewer said "wo loops", I presume he meant wo nested loops. Anyway, below is the single loop solution, though we could also implement it with recursion, which as noted earlier, would be an overkill.

``````void print_bl_tr_diag(int a[][], int n)
{
for (int j = n - 1; j >= 0; j--)
printf("%d\n", a[j][n - j - 1]);
}``````

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

//Given an n*n matrix. Print the main diagonal elements starting from bottom-left to top-right.
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void diag(int a[],int i,int j,int n)
{
if(i<0 || j>n-1)
{
getch();
exit(0);
}
printf("%d\t",a[i][j]);
diag(a,i-1,j+1,n);
}
int main()
{
int n,i,j,a;
printf("Enter the value of n(n*n)\n");
scanf("%d",&n);
printf("Enter the matrix\n");
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
diag(a,n-1,0,n);
return 0;
}

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

As the given matrix is a square matrix , so we can print the diagonal matrix as follows-

for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
if(i==j)
printf("%d ",a[i][j]);
}
}

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

This would do.

Code:
for(int i=0;i<n;i++)
sum = sum + a[i][n-1-i];

Complexity:
O(n)

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

I want output diagonal wise
0
13
245
8

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

I want output diagonal wise
0
13
245
8

Comment hidden because of low score. Click to expand.
-1
of 1 vote

void printDiagonal(int (*arr), int row){
int j = 0;
int i ;
for(i =( row-1) ;i >=0 ; i--){
printf("%d",arr[i][j]);
j++;
}
}

Comment hidden because of low score. Click to expand.
-2
of 2 vote

void printDiagonal(int a[][],int n)
{
for(int i=n-1;i>=0;i--)
cout<<" "<<a[i][i];
}

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

this is wrong... your program prints other diagonal, not the one given in question

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

try this..

void printDiagonal(int a[][], int n)
{
for(int i =0; i<n; i++)
cout<<a[n-i-1][i]<<"\t";
}

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.

### 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.