FastPrepNetwork Bridge Port Allocator
Problems/Network Bridge Port Allocator

Network Bridge Port Allocator

Rippling logoRippling● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Our choices for this exercise: get always hands out the free port with the smallest number, and it returns -1 when every port is in use. The calls arrive as a list of names with their numbers, and the answer holds only what each get returned. The limits and examples are new. The tests check only the returned ports, so a plain scan from port 0 also passes. They check neither a logarithmic-time get nor the one-bit-per-port memory goal. The editorial teaches both.

The report is a post from March 27, 2023, whose title names a Rippling phone round. Because the device was short on memory, the interviewer wanted the bit array kept and get made to run in logarithmic time. Before that, the author had tried an array of booleans and then a set, and the post ends with the author's Java class. The post sets the task up as a pretend firmware job on a network bridge. Every port there has an ID, and the number of ports is fixed. Releasing a port that is already unused must do nothing. Otherwise a release makes the port usable again, and get hands out an unused port and marks it as in use. In the post's example, get gives None once no port is left, and the ports come back in no fixed order.

The post does not say which free port get should pick, and it gives no limits.

Our version is about 80% the same as the reported question.

A network bridge has n ports, numbered 0 to n - 1. At the start, every port is free. Build a port manager that supports two calls:

  • get(): pick the free port with the smallest number, mark it as in use, and return its number. If no port is free, return -1.
  • free(port): mark port as free again. If that port is already free, nothing changes.

You get the calls in order: operations[i] is the call's name and args[i] holds its number, if any. Return an array with the value returned by every get call, in order. A free call adds nothing to the array.

Function

managePorts(n: int, operations: String[], args: int[][]) → int[]

Examples

Example 1

n = 4operations = ["get","get","get","free","free","get","get","get","free","get"]args = [[],[],[],[1],[1],[],[],[],[0],[]]return = [0,1,2,1,3,-1,0]

The first three get calls hand out 0, 1 and 2. Port 1 is then freed twice; the second free finds it already free and changes nothing. The next get returns 1, the smallest free port. Then 3 is the only free port, and after that all four are in use, so the next get returns -1. Port 0 is freed, so the last get returns 0.

Example 2

n = 1operations = ["free","get","get","free","get"]args = [[0],[],[],[0],[]]return = [0,-1,0]

Freeing port 0 at the start does nothing, because every port starts free. The first get returns 0, and the second returns -1 because the only port is in use. After port 0 is freed, get returns 0 again.

Example 3

n = 6operations = ["get","get","get","get","free","free","get","get","get"]args = [[],[],[],[],[1],[3],[],[],[]]return = [0,1,2,3,1,3,4]

The first four calls hand out 0 to 3. Port 1 is freed first and port 3 second, but get always picks the smallest free number, so the next calls return 1, then 3, then 4.

Constraints

  • 1 <= n <= 100000
  • 1 <= operations.length <= 10000 and args.length == operations.length
  • Each operations[i] is "get" or "free", and args[i] is [] for "get" and [port] for "free".
  • 0 <= port < n

More Rippling Phone Screen questions

  • Filter, Sort, and Deduplicate Scheduled TasksPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Stateful Log Transform and SearchPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Dependency-Aware Task SchedulerPHONE SCREEN · Seen Nov 2026
  • Delivery Cost Tracker with Effective-Dated RatesPHONE SCREEN · Seen Nov 2026
  • Camel CardsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Best and Worst Camel Card CompletionsPHONE SCREEN · Seen Nov 2026
  • Corporate Card Expense RulesOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • In-Memory Priority Task SchedulerPHONE SCREEN · Seen Oct 2026
  • Limit an Organization Tree's HeightPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Median Across N Sorted ArraysPHONE SCREEN · Seen Oct 2026

Similar questions at other companies

  • Running Medians and PercentilesStackAdapt · PHONE SCREENStackAdapt interview questions
  • Task Scheduler with Prerequisites and Execution PathsBrex · PHONE SCREEN
  • Streaming Median of Trade PricesXantium · PHONE SCREEN
  • Top K Pins with Insert and QueryPinterest · PHONE SCREENPinterest interview questions
  • Alert Engine with a Repeat IntervalChronosphere · PHONE SCREEN
  • Worst-Performing Ads by CTR in a Campaign TreeUber · PHONE SCREENUber interview questions
  • Timer Job Scheduler Wake-upsRedNote · PHONE SCREEN
  • Balanced Session ManagerPalantir · PHONE SCREENPalantir interview questions
  • Design a Food Rating SystemApple · PHONE SCREENApple interview questions
  • Key-Value Store on a Block DeviceLambda · PHONE SCREEN

Interview reports that mention this question

  • Rippling No-Level Older Reports: 31 Experiences (Part 6 of 6)

Rippling interview experiences

  • Rippling No-Level Onsite Loops: 24 Experiences (Part 5 of 6)
  • Rippling No-Level Screens and Loops: 18 Experiences (Part 4 of 6)
  • Rippling No-Level Coding Screens: 37 Experiences (Part 3 of 6)
  • Rippling No-Level Design, Screens: 30 Experiences (Part 2 of 6)
  • Rippling SWE Interviews, No Level: 156 Experiences (Part 1 of 6)
All Rippling interview questionsSee Rippling hiring insights
Saved
class Solution {
    public int[] managePorts(int n, String[] operations, int[][] args) {
        // Write your code here.
    }
}
Checking account…