When submitting a solution in C++, please select either C++14 (GCC 6-32) or C++17 (GCC 7-32) as your compiler. ×

godwinaustin's blog

By godwinaustin, history, 7 years ago, In English
  • Vote: I like it
  • -9
  • Vote: I do not like it

| Write comment?
»
7 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Iterate over all sub arrays of size k(include n->k-1 for the circle) where k is total number of knights.Check the minimum swaps(number of non-knights) needed in each subarray.There are O(n) such sub arrays.Rather than iterating you can maintain prefix count of number of knights.