 Practice
Resources
Contests
Online IDE
New
Free Mock
Events New Scaler
Practice
Improve your coding skills with our resources
Contests
Compete in popular contests with top coders Events
Attend free live masterclass hosted by top tech professionals
New
Scaler
Explore Offerings by SCALER # ARRAY_2D

Predict the output of the following program :

``````
int** performOps(int **A, int m, int n, int *len1, int *len2) {
int i, j;
*len1 = m;
*len2 = n;
int **B = (int **)malloc((*len1) * sizeof(int *));
for (i = 0; i < *len1; i++) {
B[i] = (int *)malloc((*len2) * sizeof(int));
}

for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
B[i][n - 1 - j] = A[i][j];
}
}
return B;
}

``````

Lets say performOps was called with `m = 3, n = 4`, and `A : [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]] `.

What would be the output of the following call :

``````
int len1, len2;
int **B = performOps(A, m, n, &len1, &len2);
int i, j;
for (i = 0; i < len1; i++) {
for (j = 0; j < len2; j++) {
printf("%d ", B[i][j]);
}
}
``````
``````
vector<vector<int> > performOps(vector<vector<int> > &A) {
vector<vector<int> > B;
B.resize(A.size());
for (int i = 0; i < A.size(); i++) {
B[i].resize(A[i].size());
for (int j = 0; j < A[i].size(); j++) {
B[i][A[i].size() - 1 - j] = A[i][j];
}
}
return B;
}

``````

Lets say performOps was called with `A : [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]] `.

What would be the output of the following call :

``````
vector<vector<int> > B = performOps(A);
for (int i = 0; i < B.size(); i++) {
for (int j = 0; j < B[i].size(); j++) cout<<B[i][j]<<" ";
}

``````
``````
ArrayList<ArrayList<Integer>> performOps(ArrayList<ArrayList<Integer>> A) {
ArrayList<ArrayList<Integer>> B = new ArrayList<ArrayList<Integer>>();
for (int i = 0; i < A.size(); i++) {

for (int j = 0; j < A.get(i).size(); j++) {
}

for (int j = 0; j < A.get(i).size(); j++) {
B.get(i).set(A.get(i).size() - 1 - j, A.get(i).get(j));
}
}
return B;
}

``````

Lets say performOps was called with `A : [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]] `.

What would be the output of the following call :

``````
ArrayList<ArrayList<Integer>> B = performOps(A);
for (int i = 0; i < B.size(); i++) {
for (int j = 0; j < B.get(i).size(); j++) {
System.out.print(B.get(i).get(j) + " ");
}
}

``````
``````def performOps(A):
m = len(A)
n = len(A)
B = []
for i in xrange(len(A)):
B.append( * n)
for j in xrange(len(A[i])):
B[i][n - 1 - j] = A[i][j]
return B

``````

Lets say performOps was called with `A : [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]] `. What would be the output of the following call :

``````B = performOps(A)
for i in xrange(len(B)):
for j in xrange(len(B[i])):
print B[i][j],
``````
``````function performOps(A){
m= A.length
n=A.length
B=[]
for(i = 0; i < m;i++){
B.push(new Array(n));
for(j=0;j< n;j++){
B[i][n-1-j] = A[i][j]
}
}
return B
}
``````

Lets say performOps was called with `A : [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]] `. What would be the output of the following call :

``````B = performOps(A)
for (i = 0; i < B.length; i++) {
for (j = 0; j < B[i].length; j++)
process.stdout.write(B[i][j]+" ");
}
``````
Hints
• Solution Approach
• Complete Solution

## Discussion Free Mock Assessment
Fill up the details for personalised experience.
Phone Number *
OTP will be sent to this number for verification
+1 *
+1
Change Number
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
*Enter the expected year of graduation if you're student
Current Employer
Company Name
College/University Name
Job Title
Job Title
Software Development Engineer (Backend)
Software Development Engineer (Frontend)
Software Development Engineer (Full Stack)
Data Scientist
Android Engineer
iOS Engineer
Devops Engineer
Support Engineer
Research Engineer
Engineering Intern
QA Engineer
Co-founder
SDET
Product Manager
Product Designer
Backend Architect
Program Manager
Release Engineer 