Company: Nutanix

Difficulty: medium

Problem Statement

Text Justification Given words and a width `W`, format them into lines of exactly `W` characters. Pack as many words as possible in each line. For every line except the last, distribute extra spaces as evenly as possible between words; when they do not divide evenly, earlier gaps receive one more space. The last line is left-justified with single spaces and trailing spaces. Input Format The first line contains `N W`. The second line contains `N` space-separated words. Output Format Print each justified line. Trailing spaces are significant. Constraints `1 <= N <= 1000`, `1 <= W <= 1000`, and every word length is at most `W`. Notes Words are lowercase English strings. A line containing one word is padded on its right.

More Nutanix OA questionsInterview experiences