FastPrepDelivery Service
Problems/Delivery Service

Delivery Service

InMobi logoInMobi● HardFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an InMobi full-time online assessment. The report does not show the output section or examples. Our version is about 98% the same as the reported question.

A logistics network spans n cities numbered 1 through n. Each day has a morning shift and an afternoon shift.

The network uses 2 * n state nodes:

  • Nodes 1 through n are the morning states of cities 1 through n.
  • Nodes n + 1 through 2 * n are the afternoon states. Node i + n is the afternoon state of city i.

The array routes lists scheduled directed courier routes. Each entry [u, v] means that a package can travel from state node u to state node v.

Within every city i, a package can always transition from its morning state i to its afternoon state i + n. It can never transition automatically from afternoon back to morning. These implicit morning-to-afternoon transitions are not included in routes.

A delivery from city u to city v is possible if a package starting at the morning state of city u can reach either the morning state or the afternoon state of city v by following scheduled routes and implicit transitions.

Return the number of ordered city pairs (u, v) for which delivery is impossible.

Function

countImpossibleDeliveries(n: int, routes: int[][]) → long

Examples

Example 1

n = 2routes = []return = 2

Each city can reach only itself through its implicit morning-to-afternoon transition. The impossible ordered pairs are (1, 2) and (2, 1).

Example 2

n = 3routes = [[1,2],[2,3]]return = 3

City 1 can deliver to every city, city 2 cannot deliver to city 1, and city 3 cannot deliver to cities 1 or 2. Therefore, 3 ordered pairs are impossible.

Example 3

n = 2routes = [[3,2]]return = 1

Node 3 is the afternoon state of city 1. City 1 reaches node 3 through its implicit transition and then reaches the morning state of city 2 through the scheduled route. City 2 still cannot deliver to city 1, so exactly one ordered pair is impossible.

Constraints

  • 1 ≤ n ≤ 50,000
  • 0 ≤ routes.length ≤ 100,000
  • routes[i].length = 2
  • 1 ≤ routes[i][0], routes[i][1] ≤ 2 * n

More InMobi Online Assessment questions

  • Validate a Bracket SequenceOA · Seen Oct 2026
  • Count Substrings Matching with One Adjacent SwapOA · Seen Oct 2026
  • Maximum Subarray with Start and End WindowsOA · Seen Oct 2026
  • Minimum Service Cold StartsOA · Seen Oct 2026
  • Range Maximum Subarray Sum QueriesOA · Seen Oct 2026
  • Connected Components with Divisor ThresholdOA · Seen Aug 2026
  • Maximize Impression ValueOA · Seen Aug 2026
  • Supply Path OptimizationOA · Seen Aug 2026
  • Shared InterestOA · Seen Jun 2026
  • Temporal AnomaliesOA · Seen Jun 2026

Similar questions at other companies

  • Detect a Cycle in Directed Hate RelationshipsArcesium · OAArcesium interview questions
  • Can You Finish All Courses?Intuit · OAIntuit interview questions
  • Module Rebuild CostsAirbnb · OAAirbnb interview questions
  • Visit Desired Attractions Without Reusing a TrailDuolingo · PHONE SCREENDuolingo interview questions
  • Course Order and CycleAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Deepest Common Ancestors in a Multi-Parent DAGSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Least-Strong Common DefeaterConfluent · PHONE SCREENConfluent interview questions
  • Course ScheduleOracle · ONSITE INTERVIEWOracle interview questions
  • Package Install OrderVerily · ONSITE INTERVIEW
  • Task Build Order and File-Change RerunsVanta · PHONE SCREEN
All InMobi interview questionsSee InMobi hiring insights
Saved
class Solution {
    public long countImpossibleDeliveries(int n, int[][] routes) {
      // write your code here
    }
}
Checking account…