Code RoomNewsletter page layouts
EasyPrep Room Coding #4706

Newsletter page layouts

CodingAlgorithms & data structuresEntry–Mid~15 min

A newsletter is laid out by cutting its article list into consecutive pages. article_words[i] is the word count of article i, the articles keep the order they are given in, and a page holds one or more consecutive articles: at most max_articles of them, and their word counts must sum to at most page_limit. Return every valid layout as a string, namely the number of articles on each page joined by hyphens, so "2-1-3" puts two articles on the first page, one on the second and three on the third. Produce the layouts by growing the first page from one article upward and recursing on what is left, so every layout beginning with a one article page comes before any layout beginning with a two article page. An empty article list returns an empty list. There are at most 9 articles and every word count is positive.

Implement
split_newsletter_pages(article_words: list[int], page_limit: int, max_articles: int) → list[str]
Examples
in[[120,80,200],300,2]out["1-1-1","1-2","2-1"]
in[[100,100],250,2]out["1-1","2"]
in[[500],400,3]out[]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 15 min
InputExpectedGot
[[120,80,200],300,2]["1-1-1","1-2","2-1"]not run yetsample
[[100,100],250,2]["1-1","2"]not run yetsample
[[500],400,3][]not run yetsample