Cody

Problem 43975. Permute the unique values of a vector without sorting

Given a vector A, return the matrix B, wherein each row contains a permutation of the unique values in original vector while retaining the original order of A. Permutations should operate on repeated numbers in indexed order.

For example, if A = [2 5 3 4 2 1 3], the function should return:

 [2 5 3 4 1;
  2 5 4 1 3;
  5 3 4 2 1;
  5 4 2 1 3]

This result is due to two repeated values: 2, at indices 1 & 5 and 3, at indices 3 & 7. The permutations of repeated numbers to include are then:

 1 3 (i.e., remove elements at indices 5 & 7, resulting in [2 5 3 4 1])
 1 7 (i.e., remove elements at indices 3 & 5, resulting in [2 5 4 1 3])
 5 3 (i.e., remove elements at indices 1 & 7, resulting in [5 3 4 2 1])
 5 7 (i.e., remove elements at indices 1 & 3, resulting in [5 4 2 1 3])

Solution Stats

66.67% Correct | 33.33% Incorrect
Last solution submitted on Jan 15, 2019

Problem Comments

Solution Comments

Recent Solvers10

Suggested Problems

More from this Author3