This Python program is designed to calculate the maximum cost based on three inputs: an array of costs, an array of labels, and a daily count. The costs and labels are associated with each other, and the daily count is used to determine the frequency of calculation. The labels can be 'legal' or 'illegal', and the 'illegal' labels are ignored in the calculation.
CodeRankGPT is a tool powered by GPT-4 that quietly assists you during your coding interview, providing the solutions you need.
In real-time and absolutely undetectable 🥷
The solution works by iterating over the cost and labels arrays simultaneously. For each pair, the current cost is incremented by the cost value. If the label is 'illegal', the program continues to the next iteration without further action. If the label is not 'illegal', the current count is incremented. When the current count reaches the daily count, the maximum of the current maximum and the current cost is calculated and stored as the new maximum. The current count and current cost are then reset to zero. The function returns the maximum cost calculated.
import math
import os
import random
import re
import sys
def maxCost(cost, labels, dailyCount):
ans = 0
cur_cnt = 0
cur_cost = 0
for c, l in zip(cost, labels):
cur_cost += c
if l == 'illegal':
continue
cur_cnt += 1
if cur_cnt == dailyCount:
ans = max(ans, cur_cost)
cur_cnt = 0
cur_cost = 0
return ans
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
cost_count = int(input().strip())
cost = []
for _ in range(cost_count):
cost_item = int(input().strip())
cost.append(cost_item)
labels_count = int(input().strip())
labels = []
for _ in range(labels_count):
labels_item = input()
labels.append(labels_item)
dailyCount = int(input().strip())
result = maxCost(cost, labels, dailyCount)
fptr.write(str(result) + '\n')
fptr.close()
If you have a HackerRank Certification test or a coding interview coming up, you can use CodeRankGPT to your advantage. It will assist you during your test and help ensure you get the certification or the job.
AI is here now, and other candidates might be using it to get ahead and win the job. 🧐
The form has been successfully submitted.