I was given this problem from a friend and I've been wondering how it would be solved.
Given an array of n distinct positive integers a1, a2, ...an and a positive integer k. What is the most optimal permutation of the above array such that if then S mod k would be the smallest?
Time Limit 1s with n ≤ 26; k ≤ 26; ai ≤ 26 for all i.