 Practice
Resources
Contests
Online IDE
New
Free Mock
Scaler
Practice
Improve your coding skills with our resources
Contests
Compete in popular contests with top coders
Scaler
Explore Offerings by SCALER ## Begin your success journey!

Full name *
Email *

By creating an account, I acknowledge that I have read and agree to InterviewBit’s Terms and Privacy Policy . ## Welcome back!

Email * # ARRAY_IMPL1

Predict the output of the following program :

``````
int* performOps(int *A, int len, int *blen) {
int i;
*blen = len * 2;
int *B = (int *)malloc((*blen) * sizeof(int));
for (i = 0; i < len; i++) {
B[i] = A[i];
B[i + len] = A[(len - i) % len];
}
return B;
}

``````

Lets say performOps was called with `len = 4`, and `A : [5, 10, 2, 1]`.

What would be the output of the following call :

``````
int blen;
int *B = performOps(A, len, &blen);
int i;
for (i = 0; i < blen; i++) {
printf("%d ", B[i]);
}
``````
``````
vector<int> performOps(vector<int> A) {
vector<int> B(2 * A.size(), 0);
for (int i = 0; i < A.size(); i++) {
B[i] = A[i];
B[i + A.size()] = A[(A.size() - i) % A.size()];
}
return B;
}

``````

Lets say performOps was called with `A : [5, 10, 2, 1]`. What would be the output of the following call :

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

``````
``````
ArrayList<Integer> performOps(ArrayList<Integer> A) {
ArrayList<Integer> B = new ArrayList<Integer>();
for (int i = 0; i < 2 * A.size(); i++) B.add(0);
for (int i = 0; i < A.size(); i++) {
B.set(i, A.get(i));
B.set(i + A.size(), A.get((A.size() - i) % A.size()));
}
return B;
}

``````

Lets say performOps was called with `A : [5, 10, 2, 1]`. What would be the output of the following call :

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

``````
``````def performOps(A):
blen = 2 * len(A)
B = *blen
for i in xrange(len(A)):
B[i] = A[i]
B[i + len(A)] = A[(len(A) - i) % len(A)]
return B

``````

Lets say performOps was called with `A : [5, 10, 2, 1]`. What would be the output of the following call :

``````B = performOps(A)
for i in xrange(len(B)):
print B[i],
``````
``````function performOps(A){
B = new Array(2 * A.length)

for (var i = 0; i < A.length; i++) {
B[i] = A[i];
B[i + A.length] = A[(A.length - i) % A.length];
}
return B;
}
``````

Lets say performOps was called with `A : [5, 10, 2, 1]`. What would be the output of the following call :

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

## Discussion Free Mock Assessment
Fill up the details for personalised experience.
All fields are mandatory
Current Employer *
Enter company name *
Select an option *
1992
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
Phone Number *
OTP will be sent to this number for verification
+1 *
+1
Change Number
Phone Number *
OTP will be sent to this number for verification
+1 *
+1
Change Number
1992
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
*Enter the expected year of graduation if you're student
Current Employer *
Company Name * 