Citi interview question

Some dp problem with factory lines