PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Meta

Solve counting and frequency coding tasks

Last updated: Mar 29, 2026

Quick Overview

This question evaluates algorithmic skills in counting, frequency analysis, constraint-based pair counting, and stream-oriented tokenization and ranking, and is categorized under Coding & Algorithms for software engineer roles.

  • medium
  • Meta
  • Coding & Algorithms
  • Software Engineer

Solve counting and frequency coding tasks

Company: Meta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given two separate coding tasks. ## Task 1: Count valid “friend requests” You are given an array `ages[]` of integers representing users’ ages. A user of age `A` can send a friend request to a user of age `B` **iff** all conditions hold: - `B <= 0.5 * A + 7` is **false** (i.e., `B` must be strictly greater than `0.5*A + 7`) - `B > A` is **false** (i.e., `B <= A`) - If `B > 100`, then `A >= 100` (i.e., users under 100 cannot request users over 100) Each ordered pair `(i, j)` with `i != j` counts as one request if `ages[i]` can request `ages[j]`. **Output:** return the total number of valid friend requests. **Constraints (typical interview scale):** - `1 <= n <= 2e4` - `1 <= ages[i] <= 120` ## Task 2: Top-N frequent words from a text source You are given an input text source (conceptually a file/stream) containing words separated by whitespace and/or punctuation. **Goal:** return the `N` most frequent words along with their counts. **Requirements/clarifications:** - Define how you tokenize words (e.g., case-insensitive, strip punctuation). - If multiple words have the same frequency, define a deterministic tie-break (e.g., lexicographic order). - The input may be too large to fit into memory as a single string; assume you can read line-by-line. **Input:** a stream of text and an integer `N`. **Output:** a list of up to `N` `(word, count)` pairs sorted by decreasing count (and tie-break rule). **Constraints (typical interview scale):** - Total tokens can be large (e.g., millions) - `1 <= N <= number_of_distinct_words`

Quick Answer: This question evaluates algorithmic skills in counting, frequency analysis, constraint-based pair counting, and stream-oriented tokenization and ranking, and is categorized under Coding & Algorithms for software engineer roles.

Related Interview Questions

  • Find Shortest Unique Prefixes - Meta (medium)
  • Compute Exclusive Execution Times - Meta (medium)
  • Solve Tree Columns And Maze Variants - Meta (medium)
  • Solve Tree Diameter and Palindromic Counts - Meta (medium)
  • Simulate Monster Team Battles - Meta (hard)
Meta logo
Meta
Jan 5, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
2
0
Loading...

You are given two separate coding tasks.

Task 1: Count valid “friend requests”

You are given an array ages[] of integers representing users’ ages.

A user of age A can send a friend request to a user of age B iff all conditions hold:

  • B <= 0.5 * A + 7 is false (i.e., B must be strictly greater than 0.5*A + 7 )
  • B > A is false (i.e., B <= A )
  • If B > 100 , then A >= 100 (i.e., users under 100 cannot request users over 100)

Each ordered pair (i, j) with i != j counts as one request if ages[i] can request ages[j].

Output: return the total number of valid friend requests.

Constraints (typical interview scale):

  • 1 <= n <= 2e4
  • 1 <= ages[i] <= 120

Task 2: Top-N frequent words from a text source

You are given an input text source (conceptually a file/stream) containing words separated by whitespace and/or punctuation.

Goal: return the N most frequent words along with their counts.

Requirements/clarifications:

  • Define how you tokenize words (e.g., case-insensitive, strip punctuation).
  • If multiple words have the same frequency, define a deterministic tie-break (e.g., lexicographic order).
  • The input may be too large to fit into memory as a single string; assume you can read line-by-line.

Input: a stream of text and an integer N. Output: a list of up to N (word, count) pairs sorted by decreasing count (and tie-break rule).

Constraints (typical interview scale):

  • Total tokens can be large (e.g., millions)
  • 1 <= N <= number_of_distinct_words

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

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

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • 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.