#3533
Concatenated Divisibility
hard · 30.6% accepted · 48 likes · top 8%
array · dynamic programming · bit manipulation · bitmask
Description
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.
Solution