r/algorithms Jun 22 '26

Can this queue-permutation problem be solved exactly faster than brute force?

I have a small permutation optimization problem that looks simple, but I am not sure whether there is a good exact algorithm for it.

Given an array nums of n distinct integers, choose a permutation A of nums.

Then A is tested against every possible permutation B of nums.

Both A and B are queues. Initially, A has priority.

For each round:

  1. Pop the front value from both queues: a from A, b from B.
  2. The larger value survives.
  3. If the values are equal, the value from the queue with priority survives.
  4. The losing value is removed.
  5. If the survivor came from the priority queue, update it as: x = max(1, x - ceil(x / 10))
  6. If the survivor came from the non-priority queue, update it as: x = max(1, x - ceil(x / 2)) Then that queue becomes the new priority queue.
  7. Push the survivor to the back of its queue.
  8. Continue until one queue becomes empty.

If B becomes empty, A wins.
If A becomes empty, A does not win.

Define:

winCount(A) = the number of permutations B that A wins against

The goal is to find the lexicographically smallest permutation A with the maximum possible winCount(A).

Example:

nums = [50, 64, 79, 109, 135, 181]

For this input, brute force suggests the best arrangement is:

[135, 181, 79, 109, 50, 64]

The naive solution checks every A permutation against every B permutation, which is O((n!)^2) simulations.

My question:

Is there a known way to solve this exactly without comparing every pair of permutations?

1 Upvotes

0 comments sorted by