Problem 3: Veci

https://open.kattis.com/problems/veci

A couple approaches:

  1. Brute Force: because the input is at most 6 digits, you only need to check numbers between the input XX and 999999999999. You can check all numbers ii s.t. X<i999999 X < i \leq 999999. If any have the same digits as XX (can be checked by counting the # of each digit), output the smallest such ii. Otherwise, output 00.

  2. C++ has a next_permutation() function which finds the smallest permutation larger than a given input. This function returns true if successful, and false if there are no more valid permutations. Example usage:

string s = "27711";
next_permutation(s.begin(), s.end()); // s is now 71127

Last updated