Bead Ornaments

Sort by

recency

|

10 Discussions

|

  • + 0 comments

    This is not a good general interview level question, its premise is entirely based on a specific formula in graph theory without stating what it is. This type of question just tests if you know/remember a certain topic and can translate it to code. Not to mention the explanations are low quality in that it tells you to just imagine a tree using undefined terms like path and star instead of just providing a graphic? It tells you you're wrong for thinking its permutations, instead just think of a tree like you're supposed to already know Cayley's Formula and Kirchoff's theorem but if you did know it then the hint is circular and useless because then you wouldn't be trying to solve it using permutations. The writing of this challenge isn't even near the tier of previous ones that actually provide Wikipedia sources and graphics of what topics are being tested here.

  • + 0 comments

    I've read this problem multiple times and I still don't know how it is trying to make these beads. This is the first problem out of all the problems thus far that I can't even understand the premise (even the examples aren't good enough). If you're counting tree configurations rather than linear arrangements, why is there no picture of a freaking tree?

    This problem needs a rewrite if anyone on this website is paying attention.

  • + 0 comments

    I could not figure out the correct answer for [4]. Here is my manual solution, which is 6 instead of the official answer of 16:

        1) 1234,2341,3412,4123
        2) 1243,2431,4312,3124
        3) 1324,3241,2413,4132
        4) 1342,3421,4213,2134
        5) 1423,4231,2314,3142
        6) 1432,4321,3214,2143
    
  • + 0 comments

    Python

    def beadOrnaments(b):
        sumColor=0
        intercolor=1
        for color in b:
            intercolor*=color**(color-1)
            sumColor+=color
        intercolor*=sumColor**(len(b)-2)
        return int(intercolor%(10**9+7))
    
  • + 0 comments

    Java8

    private static final long MOD = 1000000007;
    
    public static long power(long a, int pow) {
        long res = a % MOD;
        int count = 1;
        
        while (count < pow) {
            res = (res * a) % MOD;
            count++;
        }
        if (pow == 0) {
            return 1;
        }
        
        return res;
    }
    
    public static int beadOrnaments(List<Integer> b) {
    // Write your code here
        int n = b.size();
        
        long sum = 0;
        long trees = 1;
        
        for (Integer i : b) {
            sum = (sum + i) % MOD;
            
            //this i - 2 + 1 is also from Cayley formula
            //first: number of sub trees are found using power(i, i - 2)
            //one leaf of a sub tree will connect with root of another
            //   sub tree
            //hence there are i ways of connecting as there should be 
            //   i leaves in each tree
            //therefore power(i, i - 2) * i == power(i, i - 2 + 1)
            
            trees = (trees * power(i, i - 2 + 1)) % MOD;
        }
        
        if (n >= 2) {
            
            //Cayley formular 
            //https://www.geeksforgeeks.org/cayleys-formula/
            
            trees = (trees * power(sum, n - 2)) % MOD;
        }
        else {
            trees = (long) Math.floor(trees / sum);
        }
                
        return (int) (trees % MOD); 
    }