FastPrepCount Duplicate Characters
Problems/Count Duplicate Characters

Count Duplicate Characters

Zillow logoZillow● EasyFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported at Zillow by a candidate for a Software Engineering role in Los Angeles who interviewed in October 2020 and did not get an offer; they found the process fair overall. It opened with a live coding session on an online platform, where the candidate got two medium-level algorithm problems. The last round was two interviews, each with a different engineer: an algorithms interview that the candidate rates as easy, and an interview on working with data in Python. The report lists two questions: whether a binary tree is a mirror image of itself, and a task to count duplicate values in a string.

The report does not say which round asked the counting task. It is a short task, and the report rates the last round's algorithms interview as easy while the first problems were medium-level, so we place it in the last round and treat that round as an onsite interview; that is our reading.

The report does not say what the count covers or what the answer looks like. Our reading: the values are the string's characters, and the function countDuplicates gets the string s and returns how many different characters appear in it more than once, each counted one time however often it repeats. Treating upper-case and lower-case letters as different characters is our choice, and so are the limits (1 to 100,000 characters, English letters and digits only).

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

You are given a string s.

Return how many different characters appear in s more than once. A character that repeats is counted one time, no matter how many times it appears.

Upper-case and lower-case letters are different characters, so A and a are counted separately.

Function

countDuplicates(s: String) → int

Examples

Example 1

s = "Mississippi"return = 3

M appears once. i appears 4 times, s appears 4 times and p appears 2 times. Three different characters repeat, so the answer is 3.

Example 2

s = "Aardvark"return = 2

a appears 2 times and r appears 2 times. A appears once and is a different character from a. d, v and k appear once each. The answer is 2.

Example 3

s = "z9Q"return = 0

Each of the three characters appears once, so no character repeats and the answer is 0.

Constraints

  • 1 <= s.length <= 105
  • s consists of English letters (upper-case and lower-case) and digits.

More Zillow Onsite Interview questions

  • Valid ParenthesesPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2025
  • Build a Hash TablePHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2023
  • Spiral MatrixPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2022
  • First Subarray with the Largest SumOA · ONSITE INTERVIEW · Seen Aug 2021
  • Decision Tree Classifier from ScratchONSITE INTERVIEW · Seen Nov 2019
  • Find Median from Data StreamPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2018
  • LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2016
  • Tic-Tac-Toe Winner on a Huge BoardPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2016
  • Most Frequent Three-Page SequencesPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2016
  • Maximum Path Sum in a GridONSITE INTERVIEW · Seen Apr 2016

Similar questions at other companies

  • Non-Repeating CharacterAutodesk · ONSITE INTERVIEWAutodesk interview questions
  • Container Ledger with TradesFlexport · ONSITE INTERVIEWFlexport interview questions
  • Count Adjacent Symbol Pairs for BPEAmazon · ONSITE INTERVIEW
  • Count a User's Actions in an Event LogMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Map and Accumulate Learning QueriesPalantir · ONSITE INTERVIEWPalantir interview questions
  • Filter Pins by Excluded IDsPinterest · ONSITE INTERVIEWPinterest interview questions
  • First Non-Repeating CharacterGoldman Sachs · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
  • Longest Dictionary Word from Nine LettersGoogle · ONSITE INTERVIEWGoogle interview questions
  • Minimum Replacements to Make Two Strings AnagramsBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Logger Rate LimiterAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
All Zillow interview questionsSee Zillow hiring insights
Saved
class Solution {
    public int countDuplicates(String s) {
        // Write your code here.
    }
}
Checking account…