Find out the errors in the given code. Write the correct code and attach the output: #include using namespace std class Solution{ public: void rearrange(long *arr, int n) { int k = 0, j = n - 1, max = arr[n - 1] + 1; for (int i = 0; i < += 2) ) * max; for (int i = 1; i < n; i += 2) arr[i] += (arr[k++] % max) * max; for (int i = 0; i < n; i++) arr[i] /= m { int t; cin >> t; while(t--){ cin >> n; long long arr[n]; for(int i = 0;i
Find out the errors in the given code. Write the correct code and attach the output:
#include <bits/stdc>
using namespace std
class Solution{
public:
void rearrange(long *arr, int n)
{
int k = 0, j = n - 1, max = arr[n - 1] + 1;
for (int i = 0; i < += 2)
) * max;
for (int i = 1; i < n; i += 2)
arr[i] += (arr[k++] % max) * max;
for (int i = 0; i < n; i++)
arr[i] /= m
{
int t;
cin >> t;
while(t--){
cin >> n;
long long arr[n];
for(int i = 0;i<n;i++){
}
Solution ob;
ob rearrange(arr, n);
for (int i = 0; i < n; +)
cout << arr[i] << " ";
return 0;
}
Step by step
Solved in 2 steps with 2 images