For Given Number N find if its COLORFUL number or not

Number is COLORFUL number if product of every digit of a contiguous subsequence is different.

A number can be broken into different contiguous sub-subsequence parts. Suppose, a number 3245 can be broken into parts like 3 2 4 5 32 24 45 324 245 and having product as below. 3 -> 3 2 -> 2 4 -> 4 5 -> 5 32 -> 3 x 2 -> 6 24 -> 2 x 4 -> 8 45 -> 4 x 5 -> 20 324 -> 3 x 2 x 4 -> 24 245 -> 2 x 4 x 5 -> 40 Product of each combination is different hence 3245 is a COLORFUL number.

Return 0/1

Solution

Approach is to explore all combinations and check product of the all digits. Hashing can be helpful here to store product value of previous explored combination.

Code

Output

1

We acknowledge you to write a comment if you have a better solution or having any doubt on the above topic.

Leave a Reply

Your email address will not be published. Required fields are marked *