Sort by

recency

|

402 Discussions

|

  • + 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()
    
  • + 0 comments

    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))

  • + 0 comments

    link bhejo

  • + 0 comments

    TS Solution

    function counterGame(n: number): string { let turns = 0; while (n > 1) { // If n is a power of 2, right-shift it by 1 (divide by 2) if ((n & (n - 1)) === 0) { n >>= 1; //console.log(bit shifting right. dividing by two) } else { // If n is not a power of 2, subtract the largest power of 2 less than n let nBigInt = BigInt(n); let binary = nBigInt.toString(2);

            //console.log(`iterating over n as binary: `${binary}, binary length: $`{binary.length}`);
    
            let furthestOne = BigInt(binary.length - 1); // Highest bit position (from right)
            nBigInt -= BigInt(1) << furthestOne; // Use BigInt to perform the shift
    
            //console.log(`Removing nearest power of two: ${BigInt(1) << furthestOne}`);
            //console.log(`New n: ${nBigInt}`);
    
    // Convert back to a regular number if needed
            n = Number(nBigInt);
        }
    
        turns++;
        //console.log(`new n: `${n} ran $`{turns} times`)
    }
    
    // If `turns` is odd, Louise wins; if even, Richard wins
    return turns % 2 === 1 ? "Louise" : "Richard";
    

    }

  • + 0 comments

    Python 3 - broke it up into 2 functions for readability

    def rules_game_check_log2(n):
        num= math.log2(n)
        if num.is_integer():
            num = num
            n = n / 2
        else:
            num = 2 ** math.floor(math.log2(n))
            n = n - num
        return n
    
    def counterGame(n):
        start = 0
        while n >= 1:
            n = rules_game_check_log2(n)
            start += 1
            print(start)
    
        return "Louise" if start % 2 == 0 else "Richard"