Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8438687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:47:03+00:00 2026-06-10T07:47:03+00:00

It’s a programming puzzle which goes like: A number is said to be brilliant

  • 0

It’s a programming puzzle which goes like: “A number is said to be brilliant if the product of all digits of its substrings have a unique value.”

Example : 263 (2, 6, 3, 2*6 = 12, 6*3 = 18) is brilliant.

But 236 (2, 3, 6, 2*3 = 6, 3*6 = 18) is not brilliant.

We take only substrings, not subsequences.

I was thinking maybe we can apply Dynamic Programming here because of repeated product calculations? What other solutions can we have for it? (This isn’t a homework question.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T07:47:04+00:00Added an answer on June 10, 2026 at 7:47 am

    Here’s one way of solving it using dynamic programming:

    Assume we have the number d0 d1 … dN as input.

    The idea is to create a table, where cell (i, j) store the product di · di+1 · … · dj. This can be done efficiently since the cell at (i, j) can be computed by multiplying the number at (i-1, j) by di.

    Since i (the start index) must be less than or equal to j (the end index), we’ll focus on the lower left triangle of the table.

    After generating the table, we check for duplicate entries.

    Here’s a concrete example solution for input 2673:

    1. We allocate a matrix, M, with dimensions 4 × 4.

      enter image description here

    2. We start by filling in the diagonals, Mi,i with di:

      enter image description here

    3. We then go row by row, and fill in Mi,j with di ·Mi-1,j

      enter image description here

    4. The result looks like

      enter image description here

    5. To check for duplicates, we collect the products (2, 12, 6, 84, 42, 7, 252, 126, 21, 3), sort them (2, 3, 6, 7, 12, 21, 42, 84, 126, 252), and loop through to see if two consecutive numbers are equal. If so we return false, otherwise true.

    In Java code:

    Here’s a working DP solution, O(n2).

    public static boolean isColorful(int num) {
    
        // Some initialization
        String str = "" + num;
        int[] digits = new int[str.length()];
        for (int i = 0; i < str.length(); i++)
            digits[i] = str.charAt(i) - '0';
        int[][] dpmatrix = new int[str.length()][str.length()];
    
        // Fill in diagonal: O(N)
        for (int i = 0; i < digits.length; i++)
            dpmatrix[i][i] = digits[i];
    
        // Fill in lower left triangle: O(N^2)
        for (int i = 0; i < str.length(); i++)
            for (int j = 0; j < i; j++)
                dpmatrix[i][j] = digits[i] * dpmatrix[i-1][j];
    
        // Check for dups: O(N^2)
        int[] nums = new int[digits.length * (digits.length+1) / 2];
        for (int i = 0, j = 0; i < digits.length; i++, j += i)
            System.arraycopy(dpmatrix[i], 0, nums, j, i+1);
    
        Arrays.sort(nums);
    
        for (int i = 0; i < nums.length - 1; i++)
            if (nums[i] == nums[i+1])
                return false;
    
        return true;
    }
    

    For DP-interested readers I can recommend the somewhat similar question/answer over here:

    • Find the number of occurrences of a subsequence in a string
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
I would like to run a str_replace or preg_replace which looks for certain words
I'm trying to select an H1 element which is the second-child in its group
I have an autohotkey script which looks up a word in a bilingual dictionary
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.