Похожие чаты

Have anyone attempted, Hackerrank's problem solving (basic) test? I took so

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?

7 ответов

37 просмотров

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

wannabe-lokesh Автор вопроса
Link 🪈
Provide more context, e.g. link to the problem, wh...

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

wannabe-lokesh Автор вопроса
Pedro Aguiar
What have you tried so far? Show us the code of y...

`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.

wannabe lokesh
`cost = [2, 2, 2, 2, 2] labels = ['legal', 'legal...

time complexity (worst case) = O(n^2) due to zip function. using indexes will take it down to O(n)

Похожие вопросы

Обсуждают сегодня

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта