Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
There seems to be an implicit assumption in the solution that the problem statem...

hj3yoo

Mar 3, 2022

There seems to be an implicit assumption in the solution that the problem statement doesn't specify: wouldn't this greedy algorithm work only if you can invest in one project at a time?

What if investing in two smaller project will yield higher profit than investing in the project that yields the highest profit?

ex: capitals=[1,1,2], profits=[3,4,6], numberOfProjects=2, initialCapital=2

0

0

Comments
Comments
Design Gurus
Design Gurus4 years ago

There is no such requirement of investing in only one project. You are restricted to invest in a certain number of projects.

What output did you expect for the given input?

The current implementation returns "12". That is:

2 (initial capital)+ 6 (3rd project) + 4 (2...

I
Ivy 3 years ago

It would have been helpful to specify in the problem statement that a given project can only be invested in once.

On this page