FastPrepCommon Words from Two Readers
Problems/Common Words from Two Readers

Common Words from Two Readers

Akuna Capital logoAkuna Capital● MediumNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reports ask for the common words in two texts. They include queries on the words read so far and a follow-up with two tries. One short account does not make clear if it means words or characters, or how many sentences there are. We use the fuller reading: common words in two texts. We chose the operation codes, how to split text into words, whether case matters, distinct sorted output, what to return when empty, and the limits.

Our version is about 90% the same as the fuller reports.

Two readers consume words from firstText and secondText. Each reader starts before its first word. Process operations in order:

  • 0: consume the next word from firstText.
  • 1: consume the next word from secondText.
  • 2: return the distinct complete words that both readers have consumed so far.

Return one array of words for each query, in query order. Sort each array in ASCII lexicographic order: uppercase letters come before lowercase letters, and a word comes before any longer word that starts with it. A word appears at most once in a query result, even if a reader has consumed it many times.

Split each text on runs of ordinary spaces and ignore empty pieces. Words are case-sensitive. Only consumed words count: a word elsewhere in either text is invisible until that reader reaches it. A prefix alone is not a complete word. Queries do not advance either reader or clear their state.

An empty query result is an empty array. If there are no queries, return an empty outer array. To find the common words of the two full texts, consume every word from both texts before issuing a query.

Function

commonWords(firstText: String, secondText: String, operations: int[]) → String[][]

Examples

Example 1

firstText = "I have a fox"secondText = "fox is runing"operations = [0,0,0,0,1,1,1,2]return = [["fox"]]

After both texts are fully read, only fox appears in both. The other words occur in just one text.

Example 2

firstText = "ab abc ab"secondText = "abc ab"operations = [2,0,1,2,0,2,1,2,0,2]return = [[],[],["abc"],["ab","abc"],["ab","abc"]]

The first query has read nothing. After reading ab from the first text and abc from the second, the intersection is still empty: a prefix is not a complete matching word. Reading abc from the first text makes it common. Reading ab from the second makes both words common. The final repeated ab does not change the distinct result.

Example 3

firstText = "ab ac de ni"secondText = "ab ds fe ni"operations = [0,0,0,0,1,1,1,1,2]return = [["ab","ni"]]

Both texts are fully read before the query. Their common complete words are ab and ni, already in lexicographic order.

Constraints

  • 0 <= firstText.length, secondText.length <= 20000.
  • Each text contains only ASCII letters A-Z, a-z, and ordinary spaces.
  • Each nonempty word has between 1 and 30 letters.
  • 0 <= operations.length <= 5000.
  • Every operation is an integer between 0 and 2, inclusive.
  • A read operation is issued only when its reader has another word available.
  • The total number of words returned across all queries is at most 1000, counting the same word again if it appears in several query results.

More Akuna Capital Phone Screen questions

  • Match Orders by Price and Arrival TimeOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Biased Coin: Probability of Exactly h HeadsPHONE SCREEN · Seen Nov 2026
  • Positive Nth Root with Gradient DescentPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Two SumOA · PHONE SCREEN · Seen Sep 2026
  • Maximum Value in a Binary TreePHONE SCREEN · Seen Sep 2026
  • Tiered Expiring Item StorePHONE SCREEN · Seen Aug 2026
  • Statistics for the Latest K ValuesPHONE SCREEN · Seen Nov 2025
  • Remove Duplicates While Preserving OrderPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2025
  • Sliding Window MaximumPHONE SCREEN · Seen Oct 2025
  • Evaluate a PolynomialPHONE SCREEN · Seen Oct 2025

Similar questions at other companies

  • Design File SystemGoogle · PHONE SCREENGoogle interview questions
  • Maximum Move ScoreAmazon · PHONE SCREEN
  • Phrase Covering the Most WordsZip · PHONE SCREENZip interview questions
  • Indexed API Field Pattern QueriesStripe · PHONE SCREENStripe interview questions
  • Find Repeated Substrings Ignoring CaseDatadog · PHONE SCREENDatadog interview questions
  • Design a File System with PathsAirbnb · PHONE SCREENAirbnb interview questions
  • Highlight and Rank Overlapping CitationsHarvey · PHONE SCREEN · ONSITE INTERVIEWHarvey interview questions
  • Word Break IIWex · PHONE SCREEN
  • Word Break IIBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Transform Dotted Keys into a Nested MapProofpoint · ONSITE INTERVIEW

Akuna Capital interview experiences

  • Akuna Capital Quant Trader and QR Interviews: 5 Experiences
  • Akuna Capital JQR CodePair Rounds: 8 Experiences (Part 6 of 6)
  • Akuna Capital QR Probability Phones: 14 Experiences (Part 5 of 6)
  • Akuna Capital QR-ML Interviews: 11 Experiences (Part 4 of 6)
  • Akuna Capital QR Regression Rounds: 11 Experiences (Part 3 of 6)
  • Akuna Capital QR Coding Interviews: 17 Experiences (Part 2 of 6)
All Akuna Capital interview questionsSee Akuna Capital hiring insights
Saved
class Solution {
    public String[][] commonWords(String firstText, String secondText, int[] operations) {
        // write your code here
    }
}
Checking account…