Want to improve this question? Add details and clarify the problem by editing this post.
Closed 11 hours ago.
Improve this questionSuppose each machine needs at least one generator next to it. Write a function to print out the least generators I need given an input row.
At first I think this question is easy to solve if I write a lot of "If-else" clauses. But I cannot find out how to think this question in a structured way.
Input1: row = "MIIM". Here "M" refers machine, "I" refers interval. Each interval can contain one generator.
Output1: 2 Two generators needed for two machines.Inp开发者_运维技巧ut2: row = "IMIMI".
Output2: 1 Two machines can share one generator.
精彩评论