A media access control address (MAC address) is a unique identifier assigned to network interfaces for communications on the physical network segment.
The standard (IEEE 802) format for printing MAC-48 addresses in human-friendly form is six groups of two hexadecimal digits (
F), separated by hyphens (e.g.
inputString = "00-1B-63-84-45-E6", the output should be
isMAC48Address(inputString) = true;
inputString = "Z1-1B-63-84-45-E6", the output should be
isMAC48Address(inputString) = false;
inputString = "not a MAC-48 address", the output should be
isMAC48Address(inputString) = false.
- [time limit] 4000ms (py)
- [input] string inputStringConstraints:
15 ≤ inputString.length ≤ 20.
- [output] boolean
inputStringcorresponds to MAC-48 address naming rules,
r = inputString.split('-')
for x in r:
We get the input as a string, so, we should be able to split it by “-” and we should have 6 parts. First if statement checks this. Then, for each of these parts, we should be able to typecast it to hexadecimal integer. If we get error while converting, then it contains an illegal character. Sometimes, we can get something like, 3-4-5-6-7-8. This has 6 parts and each of them can be converted to hexadecimal numbers but is an illegal mac address. The correct form would be 03-04-05-06-07-08. Therefore, we need to check if these are all length=2 or not, too.