Sort by

recency

|

89 Discussions

|

  • + 0 comments

    Solution worked to 7 test. Java 8

    static HashSet<String> set;
    
        static {
            set = new HashSet<>();
            int n = 800;
            set.add("1");
            for (int i = 0; i <= n - 1; ++i) {
                set.add(BigInteger.ONE.shiftLeft(i).toString());
            }
        }
    
        static int twoTwo(String s){
            int count = 0;
            for (int i = 0; i < s.length();i++){
                if (s.charAt(i)=='0') continue;
                for (int j = i; j < s.length(); j++) {
                    if (set.contains(s.substring(i,j+1))){
                        count++;
                    }
                }
            }
            System.out.println(count);
            return count;
        }
    
  • + 1 comment

    Here is my solution in java, javascript, python, C, C++, csharp HackerRank Two Two Problem Solution

  • + 0 comments

    the key is to use a trie data structure I did it in C so I need to code a very basic trie DS from scratch

  • + 0 comments

    here is the solution of Two Two Click Here

  • + 1 comment

    I was able to solve it using Python 3 after 7 attempts and got top 34% so I optimized it further using bit operator but same result, can anyone help me to optmized it further:

    Here is the code

    import os
    import sys
    
    MAX_EXP = 800
    
    def make_two_power_set():
        return {1 << i for i in range(MAX_EXP+1)}
    
    def count_matches(digits, powers):
        return sum(digits.count(str(power)) for power in powers)
    
    if __name__ == '__main__':
        two_power_set = make_two_power_set()
        fptr = open(os.environ['OUTPUT_PATH'], 'w')
    
        t = int(sys.stdin.readline().rstrip())
    
        for t_itr in range(t):
            a = sys.stdin.readline().rstrip()
    
            result = count_matches(a, two_power_set)
    
            fptr.write(str(result) + '\n')
    
        fptr.close()