Not able to pass all test cases on SPOJ

I am getting wrong answer on SPOJ. Please help me where I am wrong with my solution

Here is my code:

Hey @akabhi83229
Only one correction on line 28 it should be <n

   for(int i = 0; i < n; i++){  // instead of <=n

Thanks for pointing it out. It got resolved.

Hey I have one doubt regarding time complexity. Since we are using while loop inside for loop in our code. Its complexity should be o(square n) right assuming all want first rank?? But it was said in previous lecture that its complexity is O(n)…Why ?

hey @akabhi83229
Rank value is from 1 to n and we are inputting it n times
and saving it in our map to hold the freq of ranks
so if we add all the values of team array it will be n

So two loops are

for(int rank = 1; rank <= n; rank++){
while(team[rank]){

Here first loop is running n times but team[rank] for all i’s while have total value as n
so complexity will be 2*n i.e O(n)

Thanks for the clarification

1 Like