Defanging an IP Address - Problem
Given a valid (IPv4) IP address, return a defanged version of that IP address.
A defanged IP address replaces every period "." with "[.]".
Input & Output
Example 1 — Basic Case
$
Input:
address = "1.1.1.1"
›
Output:
"1[.]1[.]1[.]1"
💡 Note:
Replace each dot with [.]: 1.1.1.1 becomes 1[.]1[.]1[.]1
Example 2 — Standard IP
$
Input:
address = "255.100.50.0"
›
Output:
"255[.]100[.]50[.]0"
💡 Note:
Each dot is replaced with [.] while numbers remain unchanged
Example 3 — Different Numbers
$
Input:
address = "192.168.1.1"
›
Output:
"192[.]168[.]1[.]1"
💡 Note:
Three dots become three [.] replacements
Constraints
-
The given
addressis a valid IPv4 address.
Visualization
Tap to expand
Understanding the Visualization
1
Input
Valid IPv4 address with dots
2
Process
Replace each dot with [.]
3
Output
Defanged IP address
Key Takeaway
🎯 Key Insight: Simple string replacement - replace all dots with [.] brackets
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code