K02

Word Masker

Junior Level Candidate
Target Time: 15 - 20 Minutes
Type: STRING

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) -> str

Input & 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 spaces

Example 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"
Loading Python Editor...
Input Parameters
[
  "merhaba dunya"
]
Expected Output
"m*****a d***a"