Render Wrapped Two-Party Chat Lines
Problem statement
Each message is [sender, text], where sender is 1 or 2. Split text into consecutive character chunks of at most contentWidth; preserve every character, including spaces. An empty text produces one empty chunk.
Pad every chunk with spaces to exactly totalWidth: sender 1 is left-aligned and sender 2 is right-aligned. Return all rendered lines in message order.
Function
renderChat(messages: String[][], contentWidth: int, totalWidth: int) → String[]Examples
Example 1
messages = [["1","hello"],["2","world"]]contentWidth = 5totalWidth = 8return = ["hello "," world"]The same-width texts align to opposite sides.
Example 2
messages = [["1","abcdef"]]contentWidth = 3totalWidth = 5return = ["abc ","def "]Text is divided into consecutive chunks.
Constraints
1 <= contentWidth <= totalWidth <= 1000- The total message text length is at most
100000.