FastPrepExtract Hashtags from a Tweet
Problems/Extract Hashtags from a Tweet

Extract Hashtags from a Tweet

eBay logoeBay● EasyFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This comes from the third round of a four-round eBay Software Engineer loop that ended in an offer. That round paired one coding task with a system design discussion. The coding task was to pull the tagged words out of a short social media post. The report shows one sample post with two tags and the list it should produce, and we keep it as Example 1.

It does not say which characters a tag word may contain, what a # with nothing usable after it gives, whether a # stuck to the end of a word still counts, whether repeated tags are kept or merged, whether letter case changes, what order the list uses, how long the post can be, or what the function looks like. We chose these: a tag word is the letters, digits and underscores right after a #, up to the first other character; a # with no such character gives nothing; a # counts wherever it sits; every repeat is kept with its case unchanged, in the order seen; the post is 0 to 1000 printable ASCII characters; and the function takes the post and returns the list of words. We added three examples of our own.

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

Given a string tweet, return every hashtag word in it, in the order the words appear.

A hashtag is a # followed by one or more word characters. A word character is an English letter (a to z or A to Z), a digit 0 to 9, or an underscore _. The hashtag word is the longest run of word characters right after the #, without the # itself. It ends at the first character that is not a word character, or at the end of tweet.

  • A # that is not followed by a word character starts no hashtag. This includes a # at the end of tweet and a # followed by a space, a punctuation mark or another #.
  • A # starts a hashtag wherever it appears, even right after a letter, so a#b contains the hashtag word b.
  • Keep each hashtag word exactly as written, with the same uppercase and lowercase letters. If a word appears more than once, keep it once for each time it appears.

If tweet has no hashtags, return an empty list.

Function

extractHashtags(tweet: String) → List<String>

Examples

Example 1

tweet = "this is a tweet! #awesome #lovingit"return = ["awesome","lovingit"]

The first # is followed by awesome, which ends at the space. The second is followed by lovingit, which ends at the end of the string. The ! is not part of any hashtag. So the answer is ["awesome","lovingit"].

Example 2

tweet = "#Day1 of #100DaysOfCode: #day1!"return = ["Day1","100DaysOfCode","day1"]

Digits are word characters, so Day1 and 100DaysOfCode are whole words. 100DaysOfCode ends at the colon, and day1 ends at the !. Day1 and day1 differ only in case, and both are kept as written. So the answer is ["Day1","100DaysOfCode","day1"].

Example 3

tweet = "C#, F# and ## are not tags #"return = []

Each # here is followed by a comma, a space or another #, or is the last character. None of these is a word character, so no # starts a hashtag, and the answer is the empty list [].

Example 4

tweet = "##go#up #go"return = ["go","up","go"]

The first # is followed by another #, so it starts nothing. The second starts go, which ends at the next #. That # starts up, which ends at the space. The last # starts go again, and the repeat is kept. So the answer is ["go","up","go"].

Constraints

  • 0 <= tweet.length <= 1000
  • tweet consists of printable ASCII characters (character codes 32 to 126), including spaces.

More eBay Onsite Interview questions

  • Validate Ada Integer LiteralONSITE INTERVIEW · Seen Nov 2026
  • Count Distinct Pairs With Sum KONSITE INTERVIEW · Seen Nov 2026
  • Diameter of Binary TreeONSITE INTERVIEW · Seen Nov 2026
  • Count Staircases with Strictly Increasing StepsONSITE INTERVIEW · Seen Oct 2026
  • Hierarchical Permission CheckONSITE INTERVIEW · Seen Oct 2026
  • Matrix MultiplicationONSITE INTERVIEW · Seen Oct 2026
  • N-Queens Solution CountONSITE INTERVIEW · Seen Oct 2026
  • Gas StationONSITE INTERVIEW · Seen Oct 2026
  • Onion-Peel Layers of a Binary TreeONSITE INTERVIEW · Seen Oct 2026
  • Container With Most WaterONSITE INTERVIEW · Seen Aug 2026

Similar questions at other companies

  • Non-Repeating CharacterAutodesk · ONSITE INTERVIEWAutodesk interview questions
  • Container Ledger with TradesFlexport · ONSITE INTERVIEWFlexport interview questions
  • Christmas Tree with N TiersVerily · ONSITE INTERVIEW
  • Longest Common PrefixKotak Mahindra Bank · PHONE SCREEN · ONSITE INTERVIEWKotak Mahindra Bank interview questions
  • Valid ParenthesesMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Count Adjacent Symbol Pairs for BPEAmazon · ONSITE INTERVIEW
  • Longest Spoken PrefixElevenLabs · ONSITE INTERVIEWElevenLabs interview questions
  • Palindrome Check Ignoring SymbolsWalmart · ONSITE INTERVIEWWalmart interview questions
  • Reverse a String Keeping Dashes in PlaceNykaa · ONSITE INTERVIEWNykaa interview questions
  • Implement tail -nConfluent · PHONE SCREEN · ONSITE INTERVIEWConfluent interview questions
All eBay interview questionsSee eBay hiring insights
Saved
class Solution {
    public List<String> extractHashtags(String tweet) {
        // Write your code here.
    }
}
Checking account…