Problem statement

https://leetcode.com/problems/slowest-key/

Solution

This is a kind of problems, where you probably spend more time reading problem statement, than solving it. What we need to do is just check all keys and how much time we press then and then choose the biggest one. We can do it with oneliner, using functionality of zip function.

Complexity

It is O(n) for time and O(1) for space, because zip is iterator and do not use additional memory.

Code

class Solution:
    def slowestKey(self, T, K):
        return max((t2 - t1, k) for t1, t2, k in zip(chain([0], T), T, K))[1]