0

Help me with this DSA gfg problem "Count frequency of an element' but giving error - Abort signal from

https://sololearn.com/compiler-playground/c35X7MbSGAY3/?ref=app #include <iostream> using namespace std; int main() { int arr[5]={1,2,3,4,5}, N=sizeof(arr)/sizeof(int), P=5; cout<<"N: "<<N<<endl; int i; for(i=0;i<N;i++){ if(arr[i]>N) { cout<<"I am in else if"; arr[i]=0; } else if(N==1){ cout<<"I am in else if"; arr[i]=i+1; } } //Step 1 -Substract value by 1 for(i=0;i<N;i++) arr[i]--; //Step 2 -use modulo and add n for(i=0;i<N;i++){ arr[arr[i]%N]+=N; cout<<" Step2- arr"<<arr[i]%N<<" - "<<arr[arr[i]%N]<<endl; } //Step 3 - To find no of occurance for(i=0;i<N;i++){ arr[i]=arr[i]/N; cout<<" Step3- arr"<<i<<" - "<<arr[i]<<endl; } }

17th Jan 2024, 8:52 AM
Om Yele
Om Yele - avatar
4 Réponses
+ 2
carefully read the error message. i programming, it is very important to read and analyze the error message. it says you did not declare what vector is. you need to specify that you want to use vectors. #include <vector>
17th Jan 2024, 10:52 AM
Lisa
Lisa - avatar
+ 1
put the code in a script. it is easier to read and people can actually test it.
17th Jan 2024, 12:53 PM
Lisa
Lisa - avatar
0
Bro see the link which I attached is for reference purpose i.e that same code I wrote on gfg which is below main() . If you will give same input without that vector then I pasted one more code below the link . In that case output is working fine but if you will paste same code which is in the link on gfg then it returns an error . Abort signal from abort(3) (SIGABRT) Its Correct output is: 1 1 1 1 1 But actually code which I pasted below with same input then returning correct output. Same logic and code is written on code editor and one which is posted
17th Jan 2024, 12:46 PM
Om Yele
Om Yele - avatar
0
Sis, put the code in a script. What do you mean by that? See thing is simple - Code which I had pasted inside the sololearn link simply copy that and go to gfg and search for problem statement "Count frequency of an element " and paste it and run first compile then submit . Second thing is that code which I pasted above outside sololearn link that same code copy it and paste it in any online compiler . Then it will display the ans . According to test case it suppose to display 1 , 5 times which code is doing . But if that same code get pasted in gfg then it return error.
17th Jan 2024, 1:20 PM
Om Yele
Om Yele - avatar