Похожие чаты

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 ответов

31 просмотр

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 Автор вопроса
Bread pup ▲⬤ ×▫︎
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)

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

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

а через ESC-код ?
Alexey Kulakov
29
30500 за редактор? )
Владимир
47
Чёт не понял, я ж правильной функцией воспользовался чтобы вывести отладочную информацию? но что-то она не ловится
notme
18
У меня есть функция где происходит это: write_bit(buffer, 1); write_bit(buffer, 0); write_bit(buffer, 1); write_bit(buffer, 1); write_bit(buffer, 1); w...
~
13
any reference of this implementation?
BitBuddha
29
Ⓐrtto, [4/23/24 7:02 PM] Please explain more fully how it is not working exactly, and what are the steps you are taking, and what error messages come or what happens. Ⓐrtto, ...
Ezza Kezza
2
sounds like people have lost their kaspa on tradeogre... does this mean tradeogre not trustworthy?
Ezza Kezza
15
Страшнейшая правда про списки ЦБ. С первых дней жизни P2P сферы, молодые человеки, начитавшись законодательной базы и "внутренних" документов, решили, что им противостоит сер...
Foxcool
3
Недавно Google Project Zero нашёл багу в SQLite с помощью LLM, о чём достаточно было шумно в определённых интернетах, которые сопровождались рассказами, что скоро всех "ибешни...
Alex Sherbakov
5
So much speculation in the last week. So much volatility in price. This is because Hedera has a GC that isn't using the network it's governing. Why aren't people asking why a...
Summit Seeker R
9
Карта сайта