Dontony's blog

By Dontony, history, 4 years ago, In English

Can anyone explain to me why I am getting TLE in this problem:- https://codeforces.net/contest/1526/problem/D. Here is my submission:- https://codeforces.net/contest/1526/submission/117731679. I just iterated over all the 24 permutations of "ANOT" and then formed the string and found the minimum swaps required for this string in O(n).(the counting part is taken from GFG which works in O(n)).

Thank you.

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

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

Your result checking function is too slow. It is at least O(result) as you're incrementing the result by one. And this is O(N^2) for some cases.