You're analyzing login attempts from a server.
Write a function:
detect_suspicious(logins)
Each login is:
[username, success]
Return the usernames that have 3 or more consecutive failed login attempts.
Test Cases
detect_suspicious([("ali", False), ("ali", False), ("ali", False)])
Expected:
["ali"]
detect_suspicious([("ali", False), ("ali", True), ("ali", False), ("ali", False)])
Expected:
[]
detect_suspicious([("ali", False), ("bob", False), ("ali", False), ("ali", False), ("bob", False)])
Expected:
["ali"]
detect_suspicious([("ali", False), ("ali", False), ("ali", True), ("ali", False), ("ali", False), ("ali", False)])
Expected:
["ali"]
🔥 BONUS:
What if the attacker changes usernames after every failed attempt?
For example:
[("admin", False), ("admin1", False), ("admin2", False), ("admin3", False)]
How would you detect this pattern?
⚠️ No spoilers in the comments. Let everyone try first.
Good luck! 🕷️