c - Which data type should be used for storing an integer as large as 10^9 in an array? -




i have code problem wherein have find frequency of minimum integer among integers scanned. have declared array of type size_t on machine has sizeof 8 bytes, tried data type unsigned long, still getting runtime error on final submission on hackerearth of code.

i have checked , verified there no issue code since 3 test cases have passed on given input failing remaining test cases, issue data type used storing number.

please guide me proper data type should use. problem mentioned on below link:

https://www.hackerearth.com/practice/data-structures/arrays/1-d/practice-problems/algorithm/monk-and-lucky-minimum-3/

code:

#include <stdio.h> #include<stdlib.h>  size_t a[100001]={0}; int main() {     int test_no,i;      scanf(" %d",&test_no);     for(i=0;i<test_no;i++)     {         int j,n ;         size_t x,min;         scanf(" %d",&n);         for(j=0;j<n;j++)         {             scanf(" %zu",&x);             a[x]++;             if(j==0)             {                 min=x;             }             if(x<=min)             {                 min=x;             }         }         if(a[min]%2==0 && a[min]!=0) //in case if every integer occurs once entries of count 0 , he'll unlucky          {             printf("unlucky \n");         }         else         {             printf("lucky \n") ;         }     }      return 0; } 

a long long @ least 64 bit signed type, , more capable of storing number of magnitude.

modern c compilers (c99 onwards) required support it.

(by way, don't need retain numbers in array in order compute minimum or maximum - rather can store attained extremes.)





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -