#include <bits/stdc++.h>
#define ll unsigned long long int
using namespace std;
ll solve(ll arr[], ll n, ll b, ll x, ll pos) {
if(n == b)
return n;
ll idx = pos - 1;
for(ll i = n -1; i >= idx; --i) {
arr[i + 1] = arr[i];
}
arr[idx] = x;
return (n + 1);
}
signed main() {
ll t;
cin >> t;
while(t--) {
ll n;
cin >> n;
ll arr[n];
ll b;
cin >> b;
for(ll i = 0; i < b; ++i) {
cin >> arr[i];
}
ll x, pos;
cin >> x >> pos;
cout << solve(arr, n, b, x, pos) << endl;
}
cout << endl;
}
Input:
1 // testcases
5 // capacity of array
3 // number of elements to be inserting
3 4 7 // array elements
8 // element to be inserting
2 // position of the element
Output:
18446744073709551615
Which is wrong. Every time I run this code, it generates a new random big number like this. I want the output to be [3, 8, 4, 7]
Please explain what is going on, and how to solve this problem. Basically, whenever I run the program, it generates an unwanted big number. I tried many posible methods, but still the problem is the same.