n projects, and project i has stages[i] stages left. Each week you complete exactly one stage of some project, but you may not work on the same project two weeks in a row.
The work stops once every stage is done, or once the only stages left belong to the project you worked on last week. Choosing the order wisely, return the largest number of weeks you can keep working.stages=[2, 2, 1] → 5
For instance, the order 0, 1, 0, 1, 2 finishes all five stages with no project twice in a row.
stages=[6, 1, 1] → 5
The order 0, 1, 0, 2, 0 gives five weeks. After that only project 0 has stages left, and it was just worked on, so the work stops.
stages=[4] → 1
stages=[2, 2, 1]
5
Run checks the first 3 tests in your browser. Submit checks all 83 tests on the server, hidden ones included.