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 address is a valid IPv4 address.

Visualization

Tap to expand
Defanging IP Address: Making Dots SafeInput1.1.1.1Find dots (.)Replace with [.]Output1[.]1[.]1[.]1
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
Asked in
Amazon 15 Google 8
185.0K Views
Low Frequency
~5 min Avg. Time
1.5K Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen