LC 3815 - Design Auction System

Approach This problem is simple, maintain unordered_map for the itemID, for each itermID maintain userId mapping to the bid, and also store this pair inside a unordered_set for fast query. Need to chekc if hte itemId and userId is still inside the hashmap (get 1 WA on this … ) . Code class AuctionSystem { public: unordered_map<int, set<pair<int,int>, greater<pair<int,int>>> > mp; // itemId -> unordered_map<int, unordered_map<int, int> > mp2; // itemId -> AuctionSystem() { mp.clear(); mp2.clear(); } void addBid(int userId, int itemId, int bidAmount) { auto& st = mp[itemId]; auto& st2 = mp2[itemId]; if(st2.count(userId)) { int bid = st2[userId]; st.erase({bid, userId}); st.insert({bidAmount, userId}); st2[userId] = bidAmount; } else { st.insert({bidAmount, userId}); st2[userId] = bidAmount; } } void updateBid(int userId, int itemId, int newAmount) { auto& st = mp[itemId]; auto& st2 = mp2[itemId]; int bid = st2[userId]; st.erase({bid, userId}); st.insert({newAmount, userId}); st2[userId] = newAmount; } void removeBid(int userId, int itemId) { auto& st = mp[itemId]; auto& st2 = mp2[itemId]; int bid = st2[userId]; st.erase({bid, userId}); st2.erase(userId); } int getHighestBidder(int itemId) { return mp.count(itemId) && mp[itemId].size() != 0 ? mp[itemId].begin()->second : -1; } };

January 18, 2026 · 1 min

LC 3814 - Maximum Capacity Within Budget

Approach The problem is to seletc at most 2 datas, and we can seperate this into two problems: select 1 and select 2. For selcet 1, it is really simple, we just get the max capcacity that the cost is smaller then budget. For select 2, we use two pointer to do this in linear time. We sort the data by cost and then try to match from the end. ...

January 18, 2026 · 2 min

LC 3813 - Vowel-Consonant Score

Approach simple problem, calcualte vowel and consonant and do division. Code class Solution { public: int vowelConsonantScore(string s) { int v = 0; int con = 0; for(const char& c: s) { if(c < 'a' || c > 'z') continue; if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' ) ++v; else ++con; } return con == 0 ? 0 : v / con; } };

January 18, 2026 · 1 min