Manasa and Sub-sequences

Sort by

recency

|

8 Discussions

|

  • + 0 comments

    Anyone has any ideas for optimizing my code in Java ? I have failed for the 2 last tests..

    static long solve(String s) {
            BigInteger sum = BigInteger.valueOf(Character.getNumericValue(s.charAt(0)));
            for(int i=1;i<s.length();i++){
                sum = sum.multiply(BigInteger.valueOf(11)).add(BigInteger.valueOf(2).pow(i).multiply(BigInteger.valueOf(Character.getNumericValue(s.charAt(i)))));
            }
            return sum.mod(BigInteger.valueOf(1000000007)).longValue();
        }
    
  • + 0 comments

    We have to find out the summation of all subset number of a given number . So , let's find a pattern which will give us the idea to work out the solution . Assume given number abc

    Then all the seven subset numbers will be 
    
    1)  (100*a +10*b + c ) 
    
    2)  ( 10*b +c )
    
    3)  (10*a + b) 
    
    4)  (10*a + c )
    
    5)  a
    
    6) b
    
    7)  c
    
    --------------------------------------------------------------------
    121 a  +  22 b + 4 c
    
    2^0 * 11^2 * a  =  121 a
    
    2^1 * 11^1 * b =   22 b
    
    2^2 * 11^ 0 * c= 4 c
    
    So , pattern we get .That's all . Now do code 
                                   
    															 
    

    My code https://github.com/joy-mollick/Problem-Solving-Solutions-Math-Greedy-/blob/master/HackerRank-Manasa%20and%20Sub-sequences.cpp

  • + 0 comments

    Hi @levpolka ,
    Can you please explain how you get this formula by looking at quetion.

  • + 2 comments

    My formula :

    10a + b ---> 11a + 2b

    100a + 10b + c ---> 11(11a + 2b) + 4c

    1000a + 100b + 10c + d ---> 11(11(11a + 2b) + 4c) + 8d

    And so on.

  • + 0 comments

    Hmm powers of 11 and powers of 2 sure are handy for solving this.