msatanzeel's blog

By msatanzeel, history, 4 years ago, In English

Today there was Google's Kickstart round H and I have a doubt in the question 3 of it, here's that link to the problem , I have solved this using a doubly linked list data structure for efficient replacements and anyone can easily analyze that over all time time complexity is O(n) , here's is the link to my code.Can someone please tell the reason for the TLE over large inputs..

  • Vote: I like it
  • +1
  • Vote: I do not like it

»
4 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

It can't hurt to try fast IO.

»
4 years ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

Have you tried to replace unordered_set with set? unordered_set is unreliable and hackable.

UPD. unordered_map too.

  • »
    »
    4 years ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Yeah, first I used ordered, but then I thought the TLE would be because of the extra logn factor ,so I switched to unordered ones

»
4 years ago, hide # |
 
Vote: I like it +4 Vote: I do not like it

As a start: you're iterating through the entire list every time you check its length.