Colorful Numbers

Objective: Given a number, find out whether its colorful or not.

Colorful Number: When in a given number, product of every digit of a sub-sequence are different. That number is called Colorful Number. See Example


Given Number : 3245
Output : Colorful
Number 3245 can be broken into parts like 3 2 4 5 32 24 45 324 245.
this number is a colorful number, since product of every digit of a sub-sequence are different.
That is, 3 2 4 5 (3*2)=6 (2*4)=8 (4*5)=20, (3*2*4)= 24 (2*4*5)= 40

Given Number : 326
Output : Not Colorful.
326 is not a colorful number as it generates 3 2 6 (3*2)=6 (2*6)=12.

Reference :


  • Insert all the digits into hast table
  • Create a powerset of digits except empty set (Power Set)
  • Multiply all the digits in the individual powerset and insert into Hash Table.
  • If any point, number already present in the Hash table, return false



326 Colorful?? false
3245 Colorful?? true

1 thought on “Colorful Numbers”

  1. here we can do in different way.

    1. if 0 is there then return False;
    Eg: 123065
    2.If numbers are repeating then return False;
    Eg: 13345 we have to worry about the contribution of composite numbers only.Because prime cannot be split.
    so we have to check for
    6-> check 3,2
    8-> 4,2


Leave a Reply to Sai Yashodhar Vinay Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.