Back to problems

Two-Direction Justified Newspaper Layout

Algorithm · ByteDance · Medium

You are given a list of paragraphs. Each paragraph consists of a sequence of words and an alignment flag indicating whether the text should be aligned to the left or to the right. You are also given a maximum line width, width. Your task is to lay out all paragraphs into lines according to the following rules, and then render the entire result inside a border of * characters. Layout algorithm Word packing — For each paragraph independently, pack its words greedily into…

Loading the rest of the question…