LRU Cache Solution Doubt

I've arrived to this solution for LRU Cache Problem(LRU Cache) but it's giving TLE now, but I've submitted the same code 1 year ago, and it got submitted.
So, my question is this, If i get asked this LRU cache question in an interview, so can I use my this solution in interview or not?

class LRUCache {
public:
    unordered_map<int, int> mp;
    list<int> l;
    int cap;
    LRUCache(int capacity) {
        cap = capacity;
    }
    
    int get(int key) {
        if(!mp.count(key))  return -1;
        l.remove(key);
        l.push_back(key);
        return mp[key];
    }
    
    void put(int key, int value) {
        if(mp.count(key)){
            l.remove(key);
            mp.erase(key);
        }
        if(l.size()==cap){
            int f = l.front();
            l.pop_front();
            mp.erase(f);
        }
        l.push_back(key);
        mp[key] = value;
    }
};
Comments (0)