Greedy Number

Greedy Number

Your mission here is to find the biggest possible number using specific rules.

  • The number has a specific length, passed through the second argument.
  • The number consists of digits passed through the first argument.
  • Every digit can be used only once.
  • The order of the digits remains the same.
  • It is always enough digits for the resulting number.

Input: Two arguments. String and Integer

Output: String.

Example:

assert greedy_number("571", 2) == "71"
assert greedy_number("12", 1) == "2"
assert greedy_number("763832", 3) == "832"
assert greedy_number("4368534743453", 5) == "87453"

Precondition: length of the string(1st argument) is bigger or equal integer(2nd argument).

40