long to understand it and found my solution too, hopefully it was working in my terminal (as far as I understood the question, input and output should be) but when I hit 'run test', it provide input() which I don't understand why.
The question was to find the maximum cost of legal as well as illegal (not working due to some reason while testing) laptops a company manufactures in a day where there is certain dailycount of legal laptop, but not illegal once.
The question said, maxCost(cost, labels, dailyCount) is a funtion which will test all this, I need to complete this function from scratch and it will take parameters as cost, labels, dailyCount as Integer array, string array, integer resp.
but input stdin was like: 1 2 3 4 1 3 legal illegal illegal legal 6 or 03097181903; I thought it will be somewhat like: cost = [2, 3, 50, 10, 99], label = ['legal', 'illegal', 'legal', 'legal', 'illegal'], dailyCount = 3.
what is this? Now I guess I need more understand of this.
I need help. Anyone can?
What have you tried so far? Show us the code of your attempt
Provide more context, e.g. link to the problem, what have you tried, etc.
they usually provide a function/method to transform the test input to necessary parameters format. This transform function is usually hidden from you (so you can solely focus on the main challenge).
I am not sure if I can provide the problem from the website because it was a certificate test for problem solving (basic) on hackerrank. But I'm pretty sure, I have written the question in much less words
`cost = [2, 2, 2, 2, 2] labels = ['legal', 'legal', 'illegal', 'illegal', 'illegal'] dailyCount = 2 def maxCost(cost, labels, dailyCount): result, k = 0, 0 for i, j in zip(cost, labels): if k == dailyCount: break if j == 'illegal': result += i elif j == 'legal': k += 1 result += i return result print(maxCost(cost, labels, dailyCount))` I know this looks noob code but this is what I could think to solve the problem.
time complexity (worst case) = O(n^2) due to zip function. using indexes will take it down to O(n)
Обсуждают сегодня