FastPrepAuthentication System
Problems/Authentication System

Authentication System

Microsoft logoMicrosoft● MediumINTERNNEW GRADOA

Updated Nov 2026

QuestionFunctionExamples

Problem statement

Special thanks: 🌷 A special thank you to our lovely, amazing frenz who shared that this question appeared again on October 5, 2026 and November 19, 2026! ദ്ദി ˉ͈̀꒳ˉ͈́ )✧ 🩷

Implement a session-based authentication system that manages user sessions using unique token IDs and a configurable time-to-live (time_to_live, or TTL) measured in seconds.

When a token is generated, its expiration time is current_time + time_to_live. A token may be renewed only while it is still unexpired; a successful renewal resets its expiration time to current_time + time_to_live.

Process every string in queries in the given order. The system must support these three operations:

  1. generate <token_id> <current_time>: At current_time, create a new token with the specified ID. Its expiration time is current_time + time_to_live.
  2. renew <token_id> <current_time>: At current_time, extend an existing unexpired token's expiration time to current_time + time_to_live. Ignore the request if the token does not exist or has already expired.
  3. count <current_time>: Return the number of unexpired tokens at current_time.

Important: Token expiration is evaluated before processing any action at the same timestamp. If a token's expiration time is exactly equal to current_time, the token is expired and cannot be renewed or counted.

Function

getUnexpiredTokens(time_to_live: int, queries: String[]) → int[]

Examples

Example 1

time_to_live = 5queries = ["generate aaa 1","renew aaa 2","count 6","generate bbb 7","renew aaa 8","renew bbb 10","count 15"]return = [1,0]

At time 6, token aaa is the only unexpired token, so the first count is 1. At time 15, all tokens have expired, so the second count is 0.

Example 2

time_to_live = 35queries = ["generate token1 3","count 4","generate token2 6","count 7","generate token3 11","count 41"]return = [1,2,1]
  1. After generate token1 3, token1 expires at time 38.
  2. At count 4, only token1 is unexpired, so the result is 1.
  3. After generate token2 6, token2 expires at time 41.
  4. At count 7, token1 and token2 are unexpired, so the result is 2.
  5. After generate token3 11, token3 expires at time 46.
  6. At count 41, token1 has expired, token2 expires at the same timestamp and is therefore already expired, and token3 remains unexpired. The result is 1.

Example 3

time_to_live = 9queries = ["generate token1 3","renew token1 5","generate token2 7","renew token2 8","generate token3 9","count 12"]return = [3]
  1. After generate token1 3, token1 expires at time 12.
  2. After renew token1 5, its expiration time becomes 14.
  3. After generate token2 7, token2 expires at time 16.
  4. After renew token2 8, its expiration time becomes 17.
  5. After generate token3 9, token3 expires at time 18.
  6. At count 12, all three tokens are unexpired, so the result is 3.

More Microsoft Online Assessment questions

  • Maximum Score with Prime JumpsOA · Seen Dec 2026
  • Minimum Non-Adjacent Selection CapabilityOA · Seen Dec 2026
  • Maximum String OperationsOA · Seen Nov 2026
  • Minimum Cost to Process Priority TasksOA · Seen Nov 2026
  • Most Visited Sprint MarkerOA · Seen Nov 2026
  • Maximum Escape Game ScoreOA · Seen Nov 2026
  • Count Subarrays with a Perfect-Square ProductOA · Seen Nov 2026
  • Maximum Interactive Team SizeOA · Seen Nov 2026
  • Maximize Pipeline Throughput Under a Scaling BudgetOA · Seen Nov 2026
  • Minimum Cost K-Capable ModelsOA · Seen Nov 2026

Similar questions at other companies

  • LRU CacheTypeSafe AI · OA
  • Bank Accounts with Balance HistoryMeta · OAMeta interview questions
  • Out-of-Order Bank Ledger BalancesPerplexity AI · OAPerplexity AI interview questions
  • Corporate Card Expense RulesRippling · OA · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • Parcel Event TrackingAirbnb · OAAirbnb interview questions
  • Process Banking OperationsVercel · OA
  • Expiring Authentication Token ManagerIBM · OAIBM interview questions
  • Layer History with Batch Undo and RedoFigma · OA · PHONE SCREENFigma interview questions
  • Event Statistics AggregatorWells Fargo · OAWells Fargo interview questions
  • Temporal Key-Field Database with Prefix ScansThe Trade Desk · OA

Microsoft interview experiences

  • Microsoft OA Questions, October 2026: 4 Experiences
  • Microsoft Experienced SWE Phone Screen: 1 Experience
  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public int[] getUnexpiredTokens(int time_to_live, String[] queries) {
      // write your code here
    }
}
Checking account…