Concatenated Divisibility

You are given an array of positive integers nums and a positive integer k.

A permutation of nums is said to form a divisible concatenation if, when you concatenate the decimal representations of the numbers in the order specified by the permutation, the resulting number is divisible by k.

Return the lexicographically smallest permutation, when considered as a list of integers, that forms a divisible concatenation. If no such permutation exists, return an empty list.

Example 1
Inputnums = [3,12,45], k = 5
Output[3,12,45]
The lexicographically smallest permutation that forms a divisible concatenation is [3,12,45].
Example 2
Inputnums = [10,5], k = 10
Output[5,10]
The lexicographically smallest permutation that forms a divisible concatenation is [5,10].

Constraints

  • 1 <= nums.length <= 13
  • 1 <= nums[i] <= 10^5
  • 1 <= k <= 100

Asked at 1 companies

Practice questions like this out loud in a mock coding interview with a live AI interviewer. First one free.

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, what to keep, what's wrong, and the complexity of your solution.

Sign in to evaluate