Count Duplicate Characters
Updated
Problem statement
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) → intExamples
Example 1
s = "Mississippi"return = 3M 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 = 2a 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 = 0Each of the three characters appears once, so no character repeats and the answer is 0.
Constraints
1 <= s.length <= 105sconsists 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