FastPrepLongest Distance in a Frequency-Limited Network
Problems/Longest Distance in a Frequency-Limited Network

Longest Distance in a Frequency-Limited Network

Bloomberg LP logoBloomberg LP● MediumNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This is the second coding task from a Bloomberg online assessment report for 2027 full-time roles. The report names the four inputs, lets a path pass between neighbors only when their frequencies are within 1 of each other, and asks for the farthest pair among devices able to reach each other.

It never says how distance is measured or what to return when no pair qualifies. Here, distance counts the fewest usable links on a path joining the pair, and the answer is 0 when no pair can reach each other. Devices are numbered from 0, no link repeats or joins a device to itself, and the limits of 1000 devices and 3000 links are our choices.

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

A network has networkNodes devices, numbered 0 to networkNodes - 1. Link i joins devices networkFrom[i] and networkTo[i] and works in both directions. Device i uses frequency frequency[i].

A link can carry a message only when the frequencies of its two devices differ by at most 1. Two devices can communicate when some path of these usable links joins them.

The distance between two devices that can communicate is the smallest number of usable links on a path between them.

Return the largest distance over all pairs of devices that can communicate. If no two devices can communicate, return 0.

Function

maxCommunicationDistance(networkNodes: int, networkFrom: int[], networkTo: int[], frequency: int[]) → int

Examples

Example 1

networkNodes = 5networkFrom = [0,1,2,3]networkTo = [1,2,3,4]frequency = [1,2,3,2,1]return = 4

The devices form a line 0 - 1 - 2 - 3 - 4 with frequencies 1, 2, 3, 2, 1. Each link joins frequencies that differ by 1, so every link can be used.

Devices 0 and 4 can talk, and the shortest usable path between them has 4 links. No pair is farther apart, so the answer is 4.

Example 2

networkNodes = 4networkFrom = [0,1,2,0]networkTo = [1,2,3,3]frequency = [1,3,2,1]return = 3

The link 0 - 1 joins frequencies 1 and 3, which differ by 2, so it cannot be used. The links 1 - 2, 2 - 3 and 0 - 3 can be used.

Device 0 reaches device 1 only through 0 - 3 - 2 - 1, which has 3 links. That is the largest distance, so the answer is 3.

Example 3

networkNodes = 6networkFrom = [0,1,2,3,4]networkTo = [1,2,3,4,0]frequency = [2,2,2,2,2,3]return = 2

Devices 0 to 4 form a ring and all have frequency 2. Device 5 has no links, so it cannot talk to anyone.

On a ring of 5 devices, the two ways around always give one path of at most 2 links. So the farthest pair is 2 links apart, and the answer is 2.

Example 4

networkNodes = 3networkFrom = [0,1]networkTo = [1,2]frequency = [1,3,1]return = 0

Both links join frequency 1 and frequency 3, so neither can be used. No two devices can talk, so the answer is 0.

Constraints

  • 1 <= networkNodes <= 1000
  • 0 <= networkFrom.length == networkTo.length <= 3000
  • 0 <= networkFrom[i], networkTo[i] < networkNodes and networkFrom[i] != networkTo[i]
  • No two links join the same pair of devices.
  • frequency.length == networkNodes
  • Each frequency[i] is 1, 2 or 3.

More Bloomberg LP interview questions

  • Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Maximum Redundancy After One Segment FlipOA · Seen Sep 2026
  • Sum of Pipeline Response TimesOA · Seen Sep 2026
  • Merge IntervalsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
  • Design an Ordered StreamOA · PHONE SCREEN · ONSITE INTERVIEW · Seen May 2026
  • Count Teams Outscoring a Target TeamOA · Seen Feb 2023
  • Ashley Loves Numbers (Financial Engineer)OA · Seen Nov 2019
  • Consecutive Sum (Financial Engineer Intern)OA · Seen Nov 2019
  • Find Longest ChainOA · Seen Sep 2017
  • N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Delivery Management SystemAkuna Capital · OAAkuna Capital interview questions
  • Shortest Path from an Encoded GraphIntuit · OAIntuit interview questions
  • Find Minimum City HopsAmazon · OA
  • Grid ExplorationIMC Trading · OAIMC Trading interview questions
  • Shortest Route Through a Traced MazeDuolingo · OADuolingo interview questions
  • Shortest Path in an Unweighted GraphPeopleStrong · OAPeopleStrong interview questions
  • Drone Delivery with Battery Swap StationsCisco · OACisco interview questions
  • Fire Station Response BillLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
  • Shortest Word Chain Between Two WordsFanatics · PHONE SCREEN
  • Shortest Path Node Count Avoiding Broken NodesGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions

Bloomberg LP interview experiences

  • Bloomberg SWE Phone Screen and Onsite: 1 Experience
  • Bloomberg SWE Phone Screens with Two Teams: 1 Experience
  • Bloomberg AI Interview, Hiring Level Not Reported: 2 Experiences
  • Bloomberg Experienced SWE AI Coding Interviews: 2 Experiences
  • Bloomberg New Grad AI-Assisted Coding Rounds: 3 Experiences
  • Bloomberg New Grad SWE AI-Assisted Coding Rounds: 1 Experience
All Bloomberg LP interview questionsSee Bloomberg LP hiring insights
Saved
class Solution {
    public int maxCommunicationDistance(int networkNodes, int[] networkFrom, int[] networkTo, int[] frequency) {
        // Write your code here.
    }
}
Checking account…