

This is the solution for the single lock which is in another set of practice questions is the easy version of the above.

This is the table for explanation:
D0,1: goes down from 0 to 1
R0,1: goes right from 0 to 1

This is the solution:
def getMinCodeEntryTime(N: int, M: int, C: List[int]) -> int:
# Write your code here
row = list()
col = list()
C.append(1)
for i in range(M):
min_it = getMTFromAToB(N, C[i-1], C[i])
min_row = float('inf')
min_col = float('inf')
for j in range(i):
min_jt = getMTFromAToB(N, C[j-1], C[i])
min_row = min(min_row, row[j] + min_jt)
row[j] += min_it
min_col = min(min_col, col[j] + min_jt)
col[j] += min_it
if not row:
min_row = min_it
min_col = min_it
row.append(min_row)
col.append(min_col)
return min(*row, *col)