Sort by

recency

|

406 Discussions

|

  • + 0 comments

    Javascript :

    function counterGame(n) {
        // Write your code here
        let moveCount = 0;
        while (n > 1) {
            if ((n & (n - 1)) === 0) { 
                n = n / 2;
            } else {
                let highestPowerOf2 = 1;
                while (highestPowerOf2 * 2 < n) {
                    highestPowerOf2 *= 2;
                }
                n -= highestPowerOf2;
            }
            moveCount++;
        }
        return moveCount % 2 === 0 ? "Richard" : "Louise";
    }
    
  • + 0 comments

    More at https://github.com/pakbungdesu/hackerrank-problem-solving.git

    Python

    def counterGame(n):
        # initialize the count
        count = 0
    
        # play the game until n becomes 1
        while n > 1:
            # check if n is a power of 2
            if (n & (n - 1)) == 0:
                # if n is a power of 2, divide by 2
                n //= 2
            else:
                # if not, subtract the largest power of 2 less than n
                largest_power = 1 << (n.bit_length() - 1)
                n -= largest_power
            count += 1
        
        return "Louise" if count % 2 else "Richard"
    
  • + 0 comments

    public static String counterGame(long n) { // Write your code here int count=0;

        while(n!=1){
    
        if(((n)&(n-1))==0){
            n=n>>1;
        }
    
    
        else{
            n=n-Long.highestOneBit(n);
    
        }
    
         count++;
    
    }
    if(count%2==0){
        return "Richard";
    }
    return "Louise";
    
    }
    

    }

  • + 0 comments

    " //PANDEY JI

    class Result {

    public static String counterGame(long n) {
    // Write your code here
    int c=0;
    while(n!=1)
    {
        if((n&(n-1))==0)
        {
            n=n>>1;
        }
        else{
            n=n-Long.highestOneBit(n);
        }
        c++;
    }
    if(c%2==0){
       return "Richard";
    }
     return "Louise";
    }"
    
  • + 0 comments

    !/bin/python3

    import math import os import random import re import sys

    #

    Complete the 'maximumClusterQuality' function below.

    #

    The function is expected to return a LONG_INTEGER.

    The function accepts following parameters:

    1. INTEGER_ARRAY speed

    2. INTEGER_ARRAY reliability

    3. INTEGER maxMachines

    #

    def maximumClusterQuality(speed, reliability, maxMachines): from itertools import combinations

    max_quality = 0
    n = len(speed)
    
    for r in range(1, maxMachines + 1):
        for combo in combinations(range(n), r):
            total_speed = sum(speed[i] for i in combo)
            min_reliability = min(reliability[i] for i in combo)
            quality = total_speed * min_reliability
            max_quality = max(max_quality, quality)
    
    return max_quality
    

    if name == 'main': speed = [3, 6, 1, 3, 4] reliability = [2, 1, 3, 4, 5] maxMachines = 3 print(maximumClusterQuality(speed, reliability, maxMachines))

    fptr = open(os.environ['OUTPUT_PATH'], 'w')
    
    speed_count = int(input().strip())
    
    speed = []
    
    for _ in range(speed_count):
        speed_item = int(input().strip())
        speed.append(speed_item)
    
    reliability_count = int(input().strip())
    
    reliability = []
    
    for _ in range(reliability_count):
        reliability_item = int(input().strip())
        reliability.append(reliability_item)
    
    maxMachines = int(input().strip())
    
    result = maximumClusterQuality(speed, reliability, maxMachines)
    
    fptr.write(str(result) + '\n')
    
    fptr.close()