Блог пользователя _aditya

Автор _aditya, история, 6 лет назад, По-английски

i encountered this problem on a hiring contest and dont think its editorial will be provided. It goes like there's an array of n numbers and a number k is given. both n,k<=10^5 arr[i]<=10^5 we have to find minimum number of swaps so that all numbers greater than k are clubber together.

  • Проголосовать: нравится
  • +2
  • Проголосовать: не нравится

»
6 лет назад, # |
Rev. 4   Проголосовать: нравится 0 Проголосовать: не нравится

Removed

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    help me with this case. array=3,4,1,1,5,6,1,1,7,8,9 k=3

    now we fix 6. no we have to bring 3,4 closer to 6 that can be done by either swapping them with first pair of 1 or second pair.

    if we do with first pair ,no of swaps resulting will be 4

    for second it will be two.

»
6 лет назад, # |
  Проголосовать: нравится +4 Проголосовать: не нравится

Please, clarify your swapping mechanism. Can I sawp any i , j (1 <= i,j <= n) . or I can swap two consecutive elements :\ ?

»
6 лет назад, # |
Rev. 2   Проголосовать: нравится +3 Проголосовать: не нравится

I think challage is still live on hackerearth, almost after every hiring they provide solution after some time.So please wait for challange to Complete.

»
6 лет назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

Let's say there are p numbers greater than k in the given array. Then we have to find subarray of size p that contains maximum numbers greater than k. Answer will be numbers that are less than k in that subarray . You can do it in O(n) .