How can I make my solution to "Climbing the Leaderboard" not time out?
\$\DeclareMathOperator{\Oh}{O}\$Frankly, the code in the HackerRank editor is a large mess.  It is promoting crap like #include &lt;bits/stdc++.h&gt; and using namespace std;, and the code contains many problems: int for traversing a std::vector, copying containers around, etc.  Not to mention bad practices like i++, explicitly calling fout.close(), not using standard algorithm, etc.  It really shouldn't be like that.

In your code, the whole getPosition function is redundant.  Use std::lower_bound instead.  And since std::vector::erase is \$\Oh(n)\$, the code is \$\Oh(n^2)\$, which is unnecessary inefficient.

The problem is very simple and can be finished in several lines without sacrificing readability:

using score_t = long;
using rank_t = long;

// scores is passed by value to take advantage of possible optimization.
rank_t get_rank(std::vector&lt;score_t&gt; scores, score_t alice_score)
{
    scores.erase(std::unique(scores.begin(), scores.end()), scores.end());

    auto it = std::lower_bound(scores.begin(), scores.end(), alice_score, std::greater&lt;&gt;{});
    return it - scores.begin() + 1;
}


The code is \$\Oh(n)\$ and I don't think you can do better.  Note that each score of Alice's is independent, so it makes no sense to process them together in a function.  I used long because the problem seems to require numbers as large as \$10^9\$.  scores will be modified in the function, so instead of making a copy manually, we let the compiler do so for us in the parameter list.  This enables possible optimization opportunities.

Here, we used two standard algorithms:


std::unique, which "removes" adjacent equal elements.  Standard algorithms cannot change the size of scores via iterators, so std::unique makes sure that the first \$N\$ elements are the result, where \$N\$ is the number of elements in the result.  The rest of the elements are placed in a valid but otherwise unspecified state.  Then, we call erase to erase these garbage elements.  This is also known as the remove-erase idiom.
std::lower_bound, which performs a binary search and returns the first element that compares not "less" than the provided value.  By default, "less" is defined by &lt;, thus operating on an ascending sequence.  In this case, we use std::greater&lt;&gt; to define "less" by &gt;, so that std::lower_bound is adapted to work on a descending sequence.




Now let's go through your code: (regardless of whether the code is what hackerrank gives you)

int getPosition(vector&lt;int&gt; scores,int value,int start,int end){


As I said, this function is provided by the standard library and you shouldn't be reinventing your own without a good reason.  If you want to see how the standard version looks like, there is an example implementation at cppreference.



vector&lt;int&gt; climbingLeaderboard(vector&lt;int&gt; scores, vector&lt;int&gt; alice) {


As I said before, this function is illogical.  It should handle one Alice-score at a time.  Also, climbingLeaderboard isn't really a good function name.

Passing scores by value is justified because you modify it in the functions, but passing alice by value introduces an unnecessary copy.  It should be passed by const reference instead.  And int is not only a magic type, but also a type that is not sufficiently large here.



int i=1;
while(1){
    if(i == scores.size()){
        break;
    }
    if(scores[i]==scores[i-1]){
        scores.erase(scores.begin() + i);
        continue;
    }
    i++;
}


Space.  Also, I am not sure what you are trying to achieve with the while (1) loop here: you are obfuscating the code by refusing to place the condition in the proper place.  And int isn't the correct type to use here.  Use size_type (or at least a named type).  ++i should be used instead of i++ in a discarded value expression.

And you are essentially reimplementing the \$\Oh(n)\$ std::unique in a \$\Oh(n^2)\$ way.  Just use the standard algorithm and avoid reinventing the wheel.



vector&lt;int&gt; results;
int endValue = scores.size()-1;


In this particular case, we know that !scores.empty(), but storing the result in a int is still inadvisable.  Use auto or std::vector&lt;int&gt;::size_type.



for(int j=0;j&lt;alice.size();j++){
    endValue = getPosition(scores,alice[j],0,endValue);
    results.insert(results.end(),endValue+1);
}


Again, space.  And ++j not j++.  And the third line is just

results.push_back(endValue + 1);


There is no reason to use insert + iterator here.



    return results;

    }


Is the weird indentation a copy-paste problem?