Letters of a Sorted Word Missing From Another
Updated
Problem statement
You are given two words, word1 and word2. Each word is made of lowercase English letters and is sorted, so its letters are in alphabetical order. A letter may appear more than once.
Return the letters of word1 whose letter does not appear anywhere in word2, in the order they appear in word1.
Keep every copy. If word1 has a letter three times and word2 never uses that letter, the answer has it three times. If word2 uses the letter even once, every copy of it is dropped. If no letter is left, return the empty string.
Function
lettersMissingFromSecond(word1: String, word2: String) → StringExamples
Example 1
word1 = "aabcdd"word2 = "bdz"return = "aac"word2 has the letters b, d and z. In word1, drop every b and every d. The letters left are a, a and c, so the answer is "aac". Both copies of a stay.
Example 2
word1 = "ccxyz"word2 = "abc"return = "xyz"word2 has a, b and c, so both c's in word1 are dropped. The answer is "xyz".
Example 3
word1 = "mmm"word2 = "m"return = ""Every letter of word1 is m, and m appears in word2. One m in word2 is enough to drop all three, so the answer is the empty string.
Constraints
1 <= word1.length, word2.length <= 10000word1andword2contain only lowercase English letters.- Each word is sorted: its letters are in alphabetical order, and a letter may repeat.
More Bloomberg LP Phone Screen questions
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Fewest Coins CombinationPHONE SCREEN · Seen Nov 2026
- Recommend Films from Viewers Who Watched Everything You DidPHONE SCREEN · Seen Nov 2026
- Track New Values in Sorted OrderPHONE SCREEN · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Sparse Vector and Matrix OperationsPHONE SCREEN · Seen Oct 2026
- Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Check if a String Is a PalindromeCisco · PHONE SCREENCisco interview questions
- Halfway Course in a Single TrackCrunchyroll · PHONE SCREENCrunchyroll interview questions
- Reverse a StringAmazon · PHONE SCREEN
- Reverse a String ManuallyNewgen Software · PHONE SCREEN
- Reverse a String with Two PointersSnowflake · PHONE SCREENSnowflake interview questions
- Palindrome with One DeletionWhatNot · PHONE SCREENWhatNot interview questions
- Valid Word AbbreviationMeta · PHONE SCREENMeta interview questions
- Reverse a StringPersistent Systems · PHONE SCREEN
- Minimum Changes for Palindromic BlocksCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
- Reverse String In PlaceThe Walt Disney Company · OA · PHONE SCREENThe Walt Disney Company interview questions
Interview reports that mention this question
Bloomberg LP interview experiences
- Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
- Bloomberg SWE Intern Interview Questions: 68 Questions
- Bloomberg Interview Questions, Level Not Reported: 65 Questions
- Bloomberg Experienced Design & More: 126 Questions (Part 2 of 2)
- Bloomberg Experienced SWE Interviews: 167 Questions (Part 1 of 2)