PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCareers
|Home/Coding & Algorithms/Bloomberg

Count friend requests based on age rules

Last updated: Mar 29, 2026

Quick Overview

This question evaluates algorithmic problem-solving skills involving array processing, counting and combinatorics under conditional constraints and frequency handling.

  • medium
  • Bloomberg
  • Coding & Algorithms
  • Software Engineer

Count friend requests based on age rules

Company: Bloomberg

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## Problem You are given an array `ages`, where `ages[i]` is the age of the `i`-th person. A person of age **A** will send a **friend request** to a person of age **B** if all conditions hold: 1. \(B > 0.5 \times A + 7\) 2. \(B \le A\) Each request is **directed** (A→B). A person cannot send a request to themselves. Return the **total number of friend requests** that will be sent. ## Input - `ages`: integer array ## Output - An integer: total number of directed friend requests. ## Constraints (you may assume typical interview bounds) - \(1 \le n \le 2\times 10^4\) - \(1 \le ages[i] \le 120\) ## Examples 1) `ages = [16, 16]` - Each 16-year-old can request the other (since \(16 > 0.5\cdot16 + 7 = 15\) and \(16 \le 16\)) - Total = 2 2) `ages = [20, 30, 100, 110, 120]` - Compute total directed requests that satisfy the rules.

Quick Answer: This question evaluates algorithmic problem-solving skills involving array processing, counting and combinatorics under conditional constraints and frequency handling.

Related Interview Questions

  • Solve meeting and tree problems - Bloomberg (easy)
  • Minimize travel cost with two cities - Bloomberg (easy)
  • Check connectivity between two subway stations - Bloomberg (easy)
  • Design a data structure for dynamic top‑K frequency - Bloomberg (hard)
  • Find tree root and bucket numbers - Bloomberg (hard)
Bloomberg logo
Bloomberg
Dec 15, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
10
0

Problem

You are given an array ages, where ages[i] is the age of the i-th person. A person of age A will send a friend request to a person of age B if all conditions hold:

  1. B>0.5×A+7B > 0.5 \times A + 7B>0.5×A+7
  2. B≤AB \le AB≤A

Each request is directed (A→B). A person cannot send a request to themselves.

Return the total number of friend requests that will be sent.

Input

  • ages : integer array

Output

  • An integer: total number of directed friend requests.

Constraints (you may assume typical interview bounds)

  • 1≤n≤2×1041 \le n \le 2\times 10^41≤n≤2×104
  • 1≤ages[i]≤1201 \le ages[i] \le 1201≤ages[i]≤120

Examples

  1. ages = [16, 16]
  • Each 16-year-old can request the other (since 16>0.5⋅16+7=1516 > 0.5\cdot16 + 7 = 1516>0.5⋅16+7=15 and 16≤1616 \le 1616≤16 )
  • Total = 2
  1. ages = [20, 30, 100, 110, 120]
  • Compute total directed requests that satisfy the rules.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Bloomberg•More Software Engineer•Bloomberg Software Engineer•Bloomberg Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • Careers
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.