I just started doing preparation for interviews, but im having trouble recognizing the optimal solution
Problem: For a given IP Address, replace every "." with "[.]"
Input: address = "18.104.22.168" Output: "1[.]1[.]1[.]1"
def defang(x): lst =  for i in x: if i == ".": lst.append("[" + i + "]") else: lst.append(i) return lst adress = "255.100.50.0" tmp = defrang(adress) x='' for i in tmp: x+=i print(x)
adress = "255.100.50.0" print("[.]".join(adress.split('.')))
Which one you think is better? The first doesnt rely on built-in methods but it creates a new list (more memory wasted?)
The second seems better but is it a problem that it relies on built-in methods?
In general idk what level of abstraction is requested by the interviewers, so any advice is welcome (regarding this specific solution or whatever else)