FastPrepAggregate Matching IPv4 Addresses Across Responses
Problems/Aggregate Matching IPv4 Addresses Across Responses

Aggregate Matching IPv4 Addresses Across Responses

Pinterest logoPinterest● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Pinterest phone screen. The report describes two HTTP reads that need sign-in. From the first, you pull out the valid IP addresses. From the second, you count and sort them. Here the input is plain text, and the parsing, the filtering, the counting, and the order all stay.

You get two HTTP response bodies, each already split into text lines: firstResponseLines and secondResponseLines. Split every line into tokens wherever there is whitespace.

First, find the valid IPv4 addresses among the tokens of firstResponseLines. Each different address you find there is a target. Then go through secondResponseLines and count how many times each target shows up as a token.

A token is a valid IPv4 address only if it has exactly four parts separated by dots, and each part is a decimal number from 0 through 255. A part may be 0, but otherwise it must not start with a zero. Ignore every other token.

Return one string "ip count" for each target that shows up in the second response. Put higher counts first. When counts tie, put the smaller address first, comparing the parts as numbers from left to right.

Function

aggregateIpCounts(firstResponseLines: String[], secondResponseLines: String[]) → String[]

Examples

Example 1

firstResponseLines = ["allow 10.0.0.1 192.168.1.2","duplicate 10.0.0.1"]secondResponseLines = ["10.0.0.1 8.8.8.8 10.0.0.1","192.168.1.2"]return = ["10.0.0.1 2","192.168.1.2 1"]

The first response holds two different addresses. One of them appears twice, but it is still one target, so there are two targets. In the second response, that repeated target shows up twice and the other target once. The address that never appears in the first response is not counted.

Example 2

firstResponseLines = ["1.2.3.4 1.2.3.5"]secondResponseLines = ["1.2.3.5 1.2.3.4"]return = ["1.2.3.4 1","1.2.3.5 1"]

Both addresses are targets, and each shows up once in the second response. The counts tie, so the address with the smaller last part comes first, even though it appears second in that response.

Constraints

  • Each input contains at most 20000 lines and 200000 total tokens.
  • Each token contains at most 100 characters.
  • Counts fit in a signed 32-bit integer.

More Pinterest Phone Screen questions

  • Shortest Pin Path Through TopicsPHONE SCREEN · Seen Nov 2026
  • Top K Pins with Insert and QueryPHONE SCREEN · Seen Nov 2026
  • Pins Violation Log QueriesPHONE SCREEN · Seen Nov 2026
  • Sparse Matrix Addition and MultiplicationPHONE SCREEN · Seen Nov 2026
  • Minimum Bus Routes to a DestinationPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Delete and Compact a Forest SubtreePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Optimal Account BalancingPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Escape Room LeaderboardPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Shortest Way to Form a Target StringPHONE SCREEN · Seen Sep 2026
  • Time-Ordered Elevator DispatchPHONE SCREEN · Seen Sep 2026

Similar questions at other companies

  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • Group AnagramsWorkday · PHONE SCREEN
  • Bank Account Balances (Part 2): Monthly ReconciliationStripe · PHONE SCREENStripe interview questions
  • Time-Aware Search AutocompleteRoblox · PHONE SCREENRoblox interview questions
  • Top Ten Most Frequent Words in a BookRobinhood · PHONE SCREENRobinhood interview questions
  • Group AnagramsEPAM · PHONE SCREENEPAM interview questions
  • Diff Two Filesystem Hash TreesCursor · PHONE SCREENCursor interview questions
  • Find Duplicate File GroupsAnthropic · PHONE SCREENAnthropic interview questions
  • Group AnagramsJFrog · PHONE SCREEN
  • Top K Frequent WordsRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions

Pinterest interview experiences

  • Pinterest Experienced MLE Phone Screen: 1 Experience
All Pinterest interview questionsSee Pinterest hiring insights
Saved
class Solution {
    public String[] aggregateIpCounts(String[] firstResponseLines, String[] secondResponseLines) {
        // Write your code here.
    }
}
Checking account…