Похожие чаты

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

9 просмотров

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 Автор вопроса
harꭑony5 (⊙ ◡ ⦿︎) ↺
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)

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

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

я не магистр хаскеля, но разве не может лейзи тип конвертнуться в не-лейзи запросив вычисление содержимого прям при инициализации?
deadgnom32 λ madao
83
читать файл максимально быстро? странный вопрос))
zamtmn
53
30 BCH videos in Hausa Language successfully delivered. In December 2023, I created a Flipstarter to produce Bitcoin Cash videos in the Hausa language for greater outreach an...
Munnir
5
bhai koi aur group ha crpto discussion ke liye?
ashu bhardwaj
12
I saw that? Again sounds very good for WOD i am DYP investor and holder, from which WOD was created right? Ill ask the question again Dhoni do i as a DYP holder for more than ...
DavidAkaLugi
9
Интересно, а майкрософт 365 может запустится на линукс минт?
Лисицка
18
How to create an OS in C? what to study?
Linus
18
Всем доброго вечера! Хочу поделиться своим злоключением с человеком, который, как оказалось сюда тоже скидывал свое резюме. Жаль, что я вашу группу не нашел раньше… человек ки...
Роман Ахмедзянов
4
братва! где куличи брать?
Alöscha
25
тоесть, указав return eax, сгенерируется никому ненужная инструкция mov eax,eax ?
Aiwan \ (•◡•) / _bot
24
Карта сайта