Sort by

recency

|

47 Discussions

|

  • + 0 comments

    !/bin/python3

    import math import os import random import re import sys

    #

    Complete the 'billboards' function below.

    #

    The function is expected to return an INTEGER.

    The function accepts following parameters:

    1. INTEGER k

    2. INTEGER_ARRAY revenue

    # def billboards(n,k, revenue): N,K=n,k total = sum(revenue)

    if K == N:
        return (total)
    else:
        x = revenue[: K + 1]
    
        min_value = min(x)
        min_index = x.index(min_value)
    
        for i in range(K + 1, N):
            if i - min_index >= K:
                min_value = min(x[i - (K + 1) : i + 1])
                min_index = x.index(min_value)
    
            x.append(min_value + revenue[i])
    
            if x[i] < min_value:
                min_value = x[i]
                min_index = i
    
        return (total - min(x[N - (K + 1) :]))
    

    if name == 'main': fptr = open(os.environ['OUTPUT_PATH'], 'w')

    first_multiple_input = input().rstrip().split()
    
    n = int(first_multiple_input[0])
    
    k = int(first_multiple_input[1])
    
    revenue = []
    
    for _ in range(n):
        revenue_item = int(input().strip())
        revenue.append(revenue_item)
    
    result = billboards(n,k, revenue)
    
    fptr.write(str(result) + '\n')
    
    fptr.close()
    
  • + 0 comments

    Phew, so finally solved this after weeks. It basically comes down to idea of min_queue problem. i.e, you can look up minimum of 'M' consecutive terms as you move from left to right in an array in O(1).

  • + 0 comments

    Phew, so finally solved this after weeks. It basically comes down to idea of min_queue problem. i.e, you can look up minimum of 'M' consecutive terms as you move from left to right in an array in O(1). Salah Al Din Metro Station Dubai

  • + 0 comments

    Here is my solution in java, javascript, python, C, C++, Csharp HackerRank Billboards Problem Solution

  • + 0 comments

    Here is Billboards problem solution - https://programs.programmingoneonone.com/2021/07/hackerrank-billboards-problem-solution.html