leetle

Daily challenge for 2025-12-11

345. Truncate String

Given a string s and an integer k, truncate the string to at most k characters. If the string is truncated, add "..." at the end.

If k is less than or equal to 3, just return the first k characters without ellipsis.

Example:
Input: s = "Hello World", k = 5
Output: "He..."

Example 2:
Input: s = "Hi", k = 5
Output: "Hi"

Run this challenge interactively in Python or JavaScript when the app loads.