-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathincorrectPasscode.py
78 lines (58 loc) · 2.59 KB
/
incorrectPasscode.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"""https://app.codesignal.com/company-challenges/dropbox/ffibMFaS7mzKZkAE3
One Very Important User (VIU) has a Very Confidential Document (VCD) stored on his Dropbox account.
He doesn't let anyone see the VCD, especially his roommates who often have access to his devices.
Opening the Dropbox mobile app on the VIU's tablet requires a four-digit passcode. To ensure the confidentiality of
the stored information, the device is locked out of Dropbox after 10 consecutive failed passcode attempts. We need
to implement a function that given an array of attempts made throughout the day and the correct passcode checks to
see if the device should be locked, i.e. 10 or more consecutive failed passcode attempts were made.
Example
For
passcode = "1111" and
attempts = ["1111", "4444",
"9999", "3333",
"8888", "2222",
"7777", "0000",
"6666", "7285",
"5555", "1111"]
the output should be
incorrectPasscodeAttempts(passcode, attempts) = true.
The first attempt is correct, so the user must have successfully logged in. However, the next 10 consecutive attempts
are incorrect, so the device should be locked. Thus, the output should be true.
Input/Output
[execution time limit] 4 seconds (py)
[input] string passcode
String consisting of exactly 4 digits representing the correct passcode.
Guaranteed constraints:
passcode.length = 4.
[input] array.string attempts
Array representing the passcode attempts in the order they were made. Each element of attempts is a string
consisting of exactly 4 digits.
Guaranteed constraints:
0 ≤ attempts.length ≤ 20,
attempts[i].length = 4.
[output] boolean
true if 10 or more consecutive failed passcode attempts were made, false otherwise.
"""
import unittest
def incorrectPasscodeAttempts(passcode, attempts):
wrongAttempts = 0
for i in attempts:
if i == passcode and wrongAttempts < 10:
wrongAttempts = 0
else:
wrongAttempts += 1
if wrongAttempts < 10:
return False
return True
print(incorrectPasscodeAttempts("1112", ["1111",
"1111",
"1111",
"1111",
"1111",
"1111",
"1111",
"1111",
"1111",
"1111",
"1111",
"1111"]))