JuniorString

Defanging an IP Address

Given a valid IPv4 IP address, return a defanged version of that IP address.

A defanged IP address replaces every period "." with "[.]".

Example 1
Inputaddress = "1.1.1.1"
Output"1[.]1[.]1[.]1"
Each period in the IP address is replaced with [.].
Example 2
Inputaddress = "255.100.50.0"
Output"255[.]100[.]50[.]0"
Each period in the IP address is replaced with [.].

Constraints

  • The given address is a valid IPv4 address.

Asked at 7 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate