You receive a collection of login records named logs, with each entry formatted as logs[i] = [ip, machine, status]:
ip: identifies the IP address of the connecting client.machine: names the host the client tried to access.status: is either "failed" or "success".Produce a list containing each IP address that recorded one or more failed login attempts. Order the result by failed-attempt total from highest to lowest. When two IPs have equal failed totals, place the lexicographically smaller IP address first.
Although machine appears in every record, it does not affect the returned list.
Example 1:
Input: logs = [["172.16.0.4","db-node","failed"],["172.16.0.4","web-node","failed"],["172.16.0.4","db-node","success"],["10.1.2.8","web-node","failed"],["10.1.2.8","cache-node","failed"],["10.1.2.8","db-node","failed"]]
Output: ["10.1.2.8","172.16.0.4"]
Explanation:
10.1.2.8 has 3 failed logins, whereas 172.16.0.4 has 2, so the former is listed ahead of the latter.
logs = [["172.16.0.4", "db-node", "failed"], ["172.16.0.4", "web-node", "failed"], ["172.16.0.4", "db-node", "success"], ["10.1.2.8", "web-node", "failed"], ["10.1.2.8", "cache-node", "failed"], ["10.1.2.8"…["10.1.2.8","172.16.0.4"]
| 0 | 1 | 2 | |
|---|---|---|---|
| 0 | 172.1… | db-no… | failed |
| 1 | 172.1… | web-n… | failed |
| 2 | 172.1… | db-no… | succe… |
| 3 | 10.1.… | web-n… | failed |
| 4 | 10.1.… | cache… | failed |
| 5 | 10.1.… | db-no… | failed |
We have a list of login records. Each record contains IP, machine, and status.
Example 2:
Input: logs = [["172.20.0.3","api-node","failed"],["172.20.0.9","api-node","failed"]]
Output: ["172.20.0.3","172.20.0.9"]
Explanation:
Each IP has exactly 1 failed attempt. Lexicographic ordering resolves the tie, placing 172.20.0.3 before 172.20.0.9.
Example 3:
Input: logs = [["203.0.113.7","mail-node","success"]]
Output: []
Explanation:
Because the log contains no failures, no IP address is included.
0 <= logs.length <= 10^5logs[i] contains exactly 3 elements.status can only be "failed" or "success".ip and machine are non-empty strings with length no greater than 50.logs = [["172.16.0.4", "db-node", "failed"], ["172.16.0.4", "web-node", "failed"], ["172.16.0.4", "db-node", "success"], ["10.1.2.8", "web-node", "failed"], ["10.1.2.8", "cache-node", "failed"], ["10.1.2.8"…["10.1.2.8","172.16.0.4"]
| 0 | 1 | 2 | |
|---|---|---|---|
| 0 | 172.1… | db-no… | failed |
| 1 | 172.1… | web-n… | failed |
| 2 | 172.1… | db-no… | succe… |
| 3 | 10.1.… | web-n… | failed |
| 4 | 10.1.… | cache… | failed |
| 5 | 10.1.… | db-no… | failed |
We have a list of login records. Each record contains IP, machine, and status.