Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Pinterest
Share On Reddit
Share On Stumbleupon
Contact us
Hide Buttons

Colorful Numbers

Objec­tive: Given a num­ber, find out whether its col­or­ful or not.

Col­or­ful Num­ber: When in a given num­ber, prod­uct of every digit of a sub-sequence are dif­fer­ent. That num­ber is called Col­or­ful Num­ber. 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.

Ref­er­ence :


  • Insert all the dig­its into hast table
  • Cre­ate a pow­er­set of dig­its except empty set (Power Set)
  • Mul­ti­ply all the dig­its in the indi­vid­ual pow­er­set and insert into Hash Table.
  • If any point, num­ber already present in the Hash table, return false



326 Colorful?? false
3245 Colorful?? true

You may also like...

  • Sai Yashod­har Vinay

    here we can do in dif­fer­ent way.

    1. if 0 is there then return False;
    Eg: 123065
    2.If num­bers are repeat­ing then return False;
    Eg: 13345 we have to worry about the con­tri­bu­tion of com­pos­ite num­bers only.Because prime can­not be split.
    so we have to check for
    6-> check 3,2
    8-> 4,2