K02
Word Masker
Problem Statement & Objective
A customer support platform masks user comments before displaying them on a shared screen. The policy is: the FIRST and LAST character of every word must remain visible, while all middle characters are replaced with '*'. Words are separated by a single space, and spaces are preserved intact. Words of length 2 or less remain completely unchanged.
Function Signature (Python)
word_masker(sentence: str) -> strInput & Output Contract
Output Rule:Masked sentence string. Number of words and space positions match input identically. Empty string returns empty string.
System Constraints
0 <= cumle.length <= 10^4
cumle contains only lowercase ASCII letters and single spaces
No leading, trailing, or consecutive spacesExample Execution Walkthrough
cumle = "merhaba dunya"
"merhaba" (7 chars) -> m + 5 asterisks + a -> "m*****a"
"dunya" (5 chars) -> d + 3 asterisks + a -> "d***a"
result: "m*****a d***a"Example Test Scenarios (3)
Example 1
Input:
["merhaba dunya"]Expected Output:
"m*****a d***a"Example 2: Two Words
Input:
["python mulakat"]Expected Output:
"p****n m*****t"Example 3: Short and Medium
Input:
["o ve ben"]Expected Output:
"o ve b*n"