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];
}

- Anonymous February 14, 2012 | Flag Reply
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[10][10];
    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;
}

- Prathamesh February 15, 2012 | Flag Reply
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.

- Anonymous February 14, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

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.

- Selmeczy, P├ęter February 15, 2012 | Flag
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;
}

- comonad February 15, 2012 | Flag Reply
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[][5], int i, int n)
{
    if(i > n)
        return;
    cout << a[n-i][i] << " ";
    i++;
    printDiagonal(a, i, n);
}

- Anonymous February 15, 2012 | Flag Reply
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]);
}
}

- aragon February 15, 2012 | Flag Reply
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]); 
	}

}

- aragon February 15, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>
using namespace std;


int printDiagonal(int a[100][100], int n, int m)
{
    if(m!=0)
            printDiagonal(a, n, m-1);
    
            cout<<a[n-m][m]<<"\t";
            return 0;    
}

int main()
{
    int a[100][100];
    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;
}

- Random February 15, 2012 | Flag Reply
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 - ]);
}

- Ashot Madatyan February 19, 2012 | Flag Reply
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]);
}

- ashot madatyan February 19, 2012 | Flag Reply
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[][10],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[10][10];
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;
}

- narayan kunal March 05, 2012 | Flag Reply
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]);
}
}

- Rudra March 13, 2012 | Flag Reply
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)

- Pavan Dittakavi May 03, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I want output diagonal wise
0
13
245
8

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

I want output diagonal wise
0
13
245
8

- Anonymous September 06, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

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

- Durgesh February 14, 2012 | Flag Reply
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];
}

- Ali_BABA February 14, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

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

- Anonymous February 14, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

try this..

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

- Random February 15, 2012 | Flag


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