Loading problem...
A platform security team audits raw access logs and needs a frequency report of malformed IPv4 strings.
Table: Logs
An IPv4 string is invalid if at least one of the following is true:
Task: Return every invalid IP string with how many times it appears in Logs.
Output requirements:
Supported submission environments:
Logs:
| log_id | ip | status_code |
|--------|---------------|-------------|
| 1 | 192.168.1.1 | 200 |
| 2 | 256.1.2.3 | 404 |
| 3 | 192.168.001.1 | 200 |
| 4 | 192.168.1.1 | 200 |
| 5 | 192.168.1 | 500 |
| 6 | 256.1.2.3 | 404 |[
{"ip":"256.1.2.3","invalid_count":2},
{"ip":"192.168.1","invalid_count":1},
{"ip":"192.168.001.1","invalid_count":1}
]256.1.2.3 is invalid because 256 > 255. 192.168.001.1 is invalid due to leading zeros. 192.168.1 is invalid because it has only 3 octets.
Logs:
| log_id | ip | status_code |
|--------|-----------|-------------|
| 10 | 300.1.1.1 | 404 |
| 11 | 300.1.1.1 | 500 |
| 12 | 01.2.3.4 | 400 |
| 13 | 01.2.3.4 | 401 |
| 14 | 1.2.3 | 404 |
| 15 | 1.2.3 | 500 |
| 16 | 8.8.8.8 | 200 |[
{"ip":"300.1.1.1","invalid_count":2},
{"ip":"1.2.3","invalid_count":2},
{"ip":"01.2.3.4","invalid_count":2}
]All three invalid IPs appear twice, so tie-breaking is done by ip in descending lexicographic order.
Logs:
| log_id | ip | status_code |
|--------|-----------------|-------------|
| 20 | 0.0.0.0 | 200 |
| 21 | 1.2.3.4 | 200 |
| 22 | 255.255.255.255 | 500 |
| 23 | 192.168.10.20 | 404 |[]All rows contain valid IPv4 addresses, so the result is empty.
Constraints