Expiring Authentication Token Manager
Updated
Problem statement
You are given a token lifetime timeToLive and an ordered array of authentication-manager operations operations.
Each operation is an array of three strings: [type, tokenId, currentTime]. The supported operation types are:
GENERATE: create the unique tokentokenIdatcurrentTime. Its expiration time becomescurrentTime + timeToLive.RENEW: iftokenIdexists and is unexpired atcurrentTime, reset its expiration time tocurrentTime + timeToLive. Otherwise, ignore the operation.COUNT: count the tokens that are unexpired atcurrentTime. For this operation,tokenIdis the empty string.
A token is unexpired at time t exactly when its expiration time is strictly greater than t. Therefore, a token is already expired at the instant equal to its expiration time.
Return one count for every COUNT operation, preserving query order. GENERATE and RENEW operations do not add values to the returned array.
Function
countUnexpiredTokens(timeToLive: int, operations: String[][]) → int[]Examples
Example 1
timeToLive = 5operations = [["GENERATE","aaa","1"],["RENEW","aaa","2"],["COUNT","","6"],["GENERATE","bbb","7"],["RENEW","aaa","8"],["RENEW","bbb","10"],["COUNT","","12"]]return = [1,1]Token aaa first expires at time 6, then renewal at time 2 moves its expiration to 7, so the count at time 6 is 1. It is expired by time 8, so that renewal is ignored. Token bbb is renewed from expiration time 12 to 15, so the count at time 12 is also 1.
Example 2
timeToLive = 3operations = [["GENERATE","alpha","1"],["COUNT","","3"],["COUNT","","4"]]return = [1,0]Token alpha expires at time 4. It is unexpired at time 3 but expired at time 4.
Example 3
timeToLive = 4operations = [["RENEW","ghost","1"],["GENERATE","x","2"],["GENERATE","y","3"],["RENEW","x","4"],["COUNT","","5"],["COUNT","","7"],["COUNT","","8"]]return = [2,1,0]Renewing the missing token ghost has no effect. Renewal moves token x's expiration to time 8, while token y expires at time 7. The three counts are therefore 2, 1, and 0.
Constraints
1 <= timeToLive <= 10^8.1 <= operations.length <= 2000.- Every operation contains exactly three strings and uses one of
GENERATE,RENEW, orCOUNT. - Every non-empty
tokenIdcontains from1through10lowercase English letters. - Every token ID used by
GENERATEis unique. - Operation times are decimal integers from
1through10^8and are strictly increasing across the array.
More IBM Online Assessment questions
- Missing IntervalsOA · Seen Nov 2026
- Last Object Exit TimeOA · Seen Nov 2026
- Count Peaks and ValleysOA · Seen Nov 2026
- Count Strictly Increasing Contiguous WindowsOA · Seen Nov 2026
- Total Each Letter's Count in an Encoded StringOA · Seen Nov 2026
- Count Servers With No Requests in a Time WindowOA · Seen Nov 2026
- Maximum Easy Tasks After RearrangingOA · Seen Nov 2026
- Tree Pythagorean TriplesOA · Seen Oct 2026
- Minimum Power-of-Two Removal OperationsOA · Seen Oct 2026
- Maximum Compatible Time WindowsOA · Seen Oct 2026
Similar questions at other companies
- Progressive Banking SystemAirbnb · OAAirbnb interview questions
- Weighted LFU CacheIMC Trading · OAIMC Trading interview questions
- Weighted LFU CacheMicrosoft · OAMicrosoft interview questions
- Cloud Compute Credits SystemCoinbase · OACoinbase interview questions
- Multi-Level Inventory Storage SystemOptiver · OA · PHONE SCREENOptiver interview questions
- Paged KV Cache AccessNVIDIA · PHONE SCREENNVIDIA interview questions
- Design Authentication ManagerOracle · ONSITE INTERVIEWOracle interview questions
- Key-Value Store on a Block DeviceLambda · PHONE SCREEN
- Design Authentication ManagerApple · PHONE SCREENApple interview questions
- Thread-Safe Task Storage and Worker DispatchNuro · ONSITE INTERVIEWNuro interview questions