Sum of Pipeline Response Times
Updated
Problem statement
A system has n components. Component i has response time responseTime[i].
Any non-empty group of components forms a pipeline. The components in a group do not need to be next to each other, and their order does not matter. The response time of a pipeline is the largest response time in it multiplied by the number of components in it.
Add up the response times of all 2^n - 1 pipelines. Components with equal times are still different components, so groups that use different components count separately.
Return the sum modulo 10^9 + 7.
Function
totalPipelineResponseTime(responseTime: int[]) → intExamples
Example 1
responseTime = [2,3,5]return = 51There are 7 non-empty pipelines:
[2]: 2 x 1 = 2[3]: 3 x 1 = 3[5]: 5 x 1 = 5[2, 3]: 3 x 2 = 6[2, 5]: 5 x 2 = 10[3, 5]: 5 x 2 = 10[2, 3, 5]: 5 x 3 = 15
The total is 2 + 3 + 5 + 6 + 10 + 10 + 15 = 51.
Example 2
responseTime = [3,1,2]return = 31The order of the components does not matter. The 7 pipelines give: [3] 3, [1] 1, [2] 2, [3, 1] 3 x 2 = 6, [3, 2] 3 x 2 = 6, [1, 2] 2 x 2 = 4, and [3, 1, 2] 3 x 3 = 9.
The total is 3 + 1 + 2 + 6 + 6 + 4 + 9 = 31.
Example 3
responseTime = [4,4]return = 16The two components are different even though their times are equal. Each one alone gives 4, and both together give 4 x 2 = 8.
The total is 4 + 4 + 8 = 16.
Example 4
responseTime = [1000000000,1000000000,1000000000]return = 999999923Every pipeline has a largest time of 1000000000. The three single components give 1000000000 each, the three pairs give 2000000000 each, and the whole group gives 3000000000.
The total is 3000000000 + 6000000000 + 3000000000 = 12000000000. Taken modulo 10^9 + 7, that is 12000000000 - 11 x 1000000007 = 999999923.
Constraints
1 <= responseTime.length <= 10^51 <= responseTime[i] <= 10^9
More Bloomberg LP interview questions
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Longest Distance in a Frequency-Limited NetworkOA · Seen Sep 2026
- Maximum Redundancy After One Segment FlipOA · 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
- Product of Subset MaximaArcesium · OAArcesium interview questions
- Capping Portfolio WeightsCapstone Investment Advisors · OA
- Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
- Macaron Order PriceOpenAI · OAOpenAI interview questions
- Get Triplet CountIBM · OAIBM interview questions
- Linear InterpolatorTwo Sigma · OATwo Sigma interview questions
- Count Reverse-Digit PairsVisa · OAVisa interview questions
- Get Triplet CountPoint72 · OAPoint72 interview questions
- Stable Robot ConfigurationsAmazon · OA
- REST API: Energy BarRippling · OARippling 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