Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
5 isn't a peak there, 6 is greater than it. And 6 can't be a peak because of this:
One of your test cases is still not correct, i mean this one:
v: [ 2 1 3 2 2 2 2 5 6 ] peaks: [ 3 ] --- pos: [ 2 ]
You have two peaks instead of just one: [ 2 1 3 2 2 2 2 5 6 ] at positions: 2 (peak 3 )and also at 7 (peak 5)
Issue not specified, closing.
@ziemowit141, it seems your helper function is wrong, and there're mistakes in your code not related to the algorithm.
should_pass_all_fixed_and_edge_assertions
Data:
2 ,3 ,6 ,4 ,1 ,2 ,3 ,2 ,
2 ,3 ,6 ,4 ,1 ,2 ,3 ,2 ,1 ,2 ,2 ,2 ,
1 ,3 ,1 ,2 ,2 ,2 ,2 ,
1 ,3 ,1 ,2 ,2 ,2 ,
Expected: [ 2 ]
Actual: [ 2, 4 ]
on none of this data sets my program locally shows peak at index 4.
Note: I'm still learning, all criticism about readibility of my code is welcome.
///////////////
bool func(vector& vec, int* a) checks cases like:
1,2,2,2,2 - no peak
1,2,2,2,1 - peak
if(&vec[0] - (a + 1) == vec.size() - 1) - checks if we are going out of vector's scope and stops recursion in cases like 1,2,2,2,2
///////////////
CODE:
#include
#include
using namespace std;
bool func(vector& vec, int* a){
if(&vec[0] - (a + 1) == vec.size() - 1)
{
if(*a >= *(a+1))
return false;
else
return true;
}
if(*a > *(a+1))
return true;
if(*a == *(a+1))
return func(vec, a+1);
return false;
}
PeakData pick_peaks(vector v) {
PeakData result;
for(int i = 1; i < v.size() - 1; i++){
if(v[i] > v[i - 1] && func(v, &v[i]) ){
result.pos.push_back(i);
result.peaks.push_back(v[i]);
}
}
return result;
}
THANK YOU VEARY MUCH FOR HELP!! :)
150 completions in C++ including one I've just done. Could you give an example of a test you can't pass but you think you should be passing (i.e. input array,
pos
andpeaks
array you return, error message you receive)? Alternatively, one of you could post your solution here with aspoiler
tag (and preferrably with the proper code-block markdown).Also, can verify that the fixed tests posted above by @Alderi-Tokori are all correct and in case you fail them, your algo is 100% NOT working correctly.
The same story here, any solution to get points for this task? I've tried my code locally and it computes peaks from failing test cases correctly :/
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
yea having the same issue, even managed to get my hands on some of the random test cases and on my machine the awnser was what was expected by the test cases.
Fixed. (
#include
seems to be not necessary.)