InterviewBit - Colorful Number Solution - The Coding Shala
Home >> Programming Questions >> Colorful Number
InterviewBit Colorful Number Solution
In this post, you will learn how to solve InterviewBit's Colorful Number Problem and its solution in Java.
A colorful number is if 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 this number is a COLORFUL number since the product of every digit of a contiguous subsequence is different.
N = 23
2 3 23
2 -> 2
3 -> 3
23 -> 6
this number is a COLORFUL number since the product of every digit of a sub-sequence is different.
Colorful number java Program
We will use HashSet to check if the number is a colorful number or not. We will generate every possible number and find their product and will check if the current product is in HashSet or not.
Other Posts You May Like
- Check if a given string is palindrome or not
- Leetcode - climbing stairs
- Hackerrank - Happy new year chaos
- Hackerrank - minimum swaps 2
- Leetcode - jewels and stones