You have assumed that size of the array is 100 while it is given in the question that size can be up to 10^6. So in your for loop you will be accessing array out of bounds.
You are creating character array of length of 50 to store the given string whose length can be equal to 50. Each character array used to store string("%s" format specifier) automatically adds null character(’\0’) in the end. So you actually need length+1 memory to store.
and this the code #include <stdio.h>
long long int a[1000006];
int main()
{
long long int n,k,i,co=0,max=0;
scanf(“%lld %lld”,&n,&k);
for(i=1;i<=n;i++)
{
scanf(“%lld”,&a[i]);
if(max<a[i])
max=a[i];
}
long long int c[max+1];
for(i=0;i<=max;i++)
c[i]=0;
for(i=1;i<=n;i++)
c[a[i]]++;
for(i=1;i<k;i=i+2)
{
if(c[i]>0)
co++;
}
printf(“%lld\n”,co);
return 0;
}
thank u…
aUtama[10] aCari[10]
You are declaring maximum size as 10. However constraint on maximum size is sadly not specified. Set it to 10000 as that worked in many accepted solutions.
why am i getting this runtime error for this code to execute patterns
output : 1 2 4
3 5 7
6 8 9
my code looks like :-
#include <iostream>
using namespace std;
int main () {
int i;
int N;
int num = 1;
cin>>N;
for (int z=0; z<N; z++) {
cin>>i;
int ARR[i][i];
for (int a=1,b=1; a<=i;a++){
//This is to step down for i rows in a matrix represened by 2d array
for (int x=a, y = b; y<=i; y++)
{
ARR[x][y]= -1;
}
} // have assigned every element of the array as -1
for (int a=1,b=1; a<=i;a++){
//This is 11 21 31
for (int x=a, y = b; y<=i; y++)
{
for(int d=x , e=y; d<=i && e>=1; d++,e--) {
if (ARR[d][e]==-1) {
ARR[d][e] = num;
num++;
}
}
}
}
for (int a=1,b=1; a<=i;a++){
//This is 11 21 31
for (int x=a, y = b; y<=i; y++)
{
cout<<ARR[x][y]<<" ";
}
cout<<endl;
}
}
return 0;
}
the memory it sows to be used is 15.232 kB
can anyone also provide me with the amendments for the same code to run it successfully ??