PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates string parsing and tokenization, frequency counting of elements, time-window filtering of events, and the ability to sort results with deterministic tie-breaking rules.

  • medium
  • F5Networks
  • Coding & Algorithms
  • Software Engineer

Find Top Hashtags

Company: F5Networks

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Take-home Project

You are given two arrays of length `n`: - `tweets[i]`: the content of the `i`-th tweet as a string - `timestamps[i]`: the publish time of the `i`-th tweet as an integer You are also given two integers: - `currentTime` - `timeWindow` Consider only tweets whose timestamp falls within the inclusive time interval: `[currentTime - timeWindow, currentTime]` A hashtag is any token in a tweet that starts with `#`. Count hashtag popularity by the number of times each hashtag appears in the tweets within the time window. Return the most popular at most 3 hashtags. Sort hashtags by descending count. If two hashtags have the same count, sort them lexicographically ascending. If fewer than 3 hashtags appear in the time window, return all of them.

Quick Answer: This question evaluates string parsing and tokenization, frequency counting of elements, time-window filtering of events, and the ability to sort results with deterministic tie-breaking rules.

You are given two arrays of length `n`: - `tweets[i]`: the content of the `i`-th tweet as a string - `timestamps[i]`: the publish time of the `i`-th tweet as an integer You are also given two integers `currentTime` and `timeWindow`. Consider only tweets whose timestamp falls within the inclusive interval `[currentTime - timeWindow, currentTime]`. A hashtag is any whitespace-delimited token in a tweet that starts with `#` (and has at least one character after the `#`). Count hashtag popularity by the number of times each hashtag appears across the tweets within the time window. Return the most popular **at most 3** hashtags. Sort hashtags by descending count; break ties by lexicographically ascending hashtag. If fewer than 3 distinct hashtags appear in the window, return all of them. Return the result as a list of hashtag strings (each including the leading `#`).

Constraints

  • 1 <= n <= 10^5 (tweets and timestamps have equal length)
  • Each tweet is a whitespace-separated string of tokens
  • A hashtag is a token starting with '#' followed by at least one character
  • 0 <= timestamps[i], currentTime <= 10^9
  • 0 <= timeWindow <= currentTime
  • Window bounds are inclusive: [currentTime - timeWindow, currentTime]

Examples

Input: (['Loving #python and #coding', 'I love #python', '#python rocks but #java too', '#old tweet'], [100, 90, 80, 10], 100, 30)

Expected Output: ['#python', '#coding', '#java']

Explanation: Window is [70, 100]; the tweet at ts=10 is excluded. #python appears 3 times, #coding once, #java once. Ties (#coding vs #java) broken lexicographically: '#coding' < '#java'.

Input: (['#a #b #c #d #e', '#a #b', '#a'], [50, 50, 50], 50, 0)

Expected Output: ['#a', '#b', '#c']

Explanation: Window [50,50] includes all three tweets. #a=3, #b=2, #c=1 (#d, #e each 1). Top 3 by count then name: #a, #b, #c.

Input: (['#tie1 #tie2', '#tie1 #tie2'], [5, 5], 10, 10)

Expected Output: ['#tie1', '#tie2']

Explanation: Both hashtags appear twice; only 2 distinct hashtags so all are returned, ordered lexicographically since counts tie.

Input: ([], [], 100, 50)

Expected Output: []

Explanation: No tweets, so no hashtags.

Input: (['no hashtags here', 'just text'], [5, 6], 10, 10)

Expected Output: []

Explanation: In-window tweets contain no tokens starting with '#'.

Input: (['#late', '#intime'], [200, 50], 100, 60)

Expected Output: ['#intime']

Explanation: Window [40,100]; ts=200 is excluded, ts=50 is included. Only #intime survives.

Input: (['#z #z #y #y #x', '#w'], [5, 5], 5, 5)

Expected Output: ['#y', '#z', '#w']

Explanation: Counts: #z=2, #y=2, #x=1, #w=1. Sorted by count desc then name asc: #y and #z (both 2, #y<#z), then #w (#w<#x) fills the third slot. #x is dropped by the at-most-3 cap.

Hints

  1. First filter to the tweets whose timestamp lies in the inclusive window [currentTime - timeWindow, currentTime].
  2. Split each surviving tweet on whitespace and keep only tokens that start with '#' (with something after it); tally them in a hash map.
  3. Sort the (hashtag, count) pairs by count descending, then by hashtag ascending, and take the first 3. Tie-breaking on the hashtag string is what distinguishes equal-count tags.
Last updated: Jun 26, 2026

Loading coding console...

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
  • AI Coding 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.