Posted on

Description

Submission

class Solution {
public:
    char slowestKey(vector<int>& releaseTimes, string keysPressed) {
        int n = releaseTimes.size();
        releaseTimes.insert(releaseTimes.begin(), 0);
        
        int maxInterval = 0;
        char maxChar = 0;
        for(int i = 1; i <= n; ++i) {
            int interval = releaseTimes[i] - releaseTimes[i-1];
            
            if(interval > maxInterval) {
                maxInterval = interval;
                maxChar = keysPressed[i-1];  
            } else if(interval == maxInterval && keysPressed[i-1] > maxChar){
                maxChar = keysPressed[i-1];
            }
        }
        return maxChar;
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *