Build a tiny version of the Unix cat command. Given a list of lines, return them joined by newline characters (\n) so they print one per line.
Lines can be blank, and the list can be empty (the result is then an empty string).
Function signature:
def cat(self, lines: List[str]) -> str:
Example:
Input: lines = ["hello", "world", "foo"] Output: "hello\nworld\nfoo" When printed: hello world foo
Think of the output as one big string where each input line is separated from the next by a newline character. You don't need to loop and concatenate manually — Python has a built-in helper for this.
Use the string method
"\n".join(lines) — this glues every element of lines together with "\n" in between.
The full solution is a one-liner:
class Solution:
def cat(self, lines):
return "\n".join(lines)
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check
