FastPrepIn-Memory URL Shortener
Problems/In-Memory URL Shortener

In-Memory URL Shortener

Revolut logoRevolut● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Revolut phone screen. The report asks for a URL-shortening service whose path becomes letters and digits. It does not give the interface you can run or the rule for tokens. This version keeps it in memory with fixed shorten and restore operations, and Base62 paths. Our version is about 76% the same as the reported question.

Implement the core of an in-memory URL shortener. The service starts empty and processes operations from left to right. The parallel values array supplies each operation's argument.

  • shorten receives a long URL. If the URL has appeared before, return its existing token. Otherwise assign the next positive integer ID, starting at 1, encode it in Base62 using the alphabet 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ, store both directions of the mapping, and return the token.
  • restore receives a token returned by an earlier shorten operation and returns its original long URL.

Return one string result for every operation, in order. Tokens are path components only; do not prepend a domain.

Function

runUrlShortener(operations: String[], values: String[]) → String[]

Examples

Example 1

operations = ["shorten","shorten","restore","shorten","restore"]values = ["https://example.com/articles/alpha","https://example.com/docs/beta","1","https://example.com/articles/alpha","2"]return = ["1","2","https://example.com/articles/alpha","1","https://example.com/docs/beta"]

The first two distinct URLs receive tokens 1 and 2. Restoring token 1 returns the first URL, and shortening that URL again reuses token 1.

Example 2

operations = ["shorten","shorten","shorten","shorten","shorten","shorten","shorten","shorten","shorten","shorten","restore"]values = ["u1","u2","u3","u4","u5","u6","u7","u8","u9","u10","a"]return = ["1","2","3","4","5","6","7","8","9","a","u10"]

The tenth positive ID is encoded as a in the declared Base62 alphabet, and restoring that token returns the tenth URL.

Constraints

  • 1 <= operations.length <= 2 * 10^5
  • values.length == operations.length
  • Each operation is exactly shorten or restore.
  • A long URL is nonempty and has length at most 2000.
  • Every restore token was returned by an earlier shorten operation in the same batch.

More Revolut Phone Screen questions

  • Bounded Service Instance RegistryPHONE SCREEN · Seen Oct 2026

Similar questions at other companies

  • Text Embedding and Vector SearchNike, Inc. · PHONE SCREEN · ONSITE INTERVIEWNike, Inc. interview questions
  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • File Storage ServiceCresta · PHONE SCREENCresta interview questions
  • Return Every Matching DecryptionDuolingo · PHONE SCREENDuolingo interview questions
  • Design a Food Rating SystemApple · PHONE SCREENApple interview questions
  • Reorderable Task Scheduler With CooldownWaymo · PHONE SCREENWaymo interview questions
  • Hierarchical In-Memory File SystemClay · PHONE SCREEN
  • Design File SystemGoogle · PHONE SCREENGoogle interview questions
  • Numeric Poker OperationsRippling · PHONE SCREENRippling interview questions
  • Reference-Counted Deduplicating File SystemCitadel · PHONE SCREENCitadel interview questions
All Revolut interview questionsSee Revolut hiring insights
Saved
class Solution {
    public String[] runUrlShortener(String[] operations, String[] values) {
        // write your code here
    }
}
Checking account…