Intuit | SDE 2 | 2 years experience

Difficulty: EASYCategory: InterviewExperienceFrequency: 1Asked On 2025-04-05Added By Anonymous
Source: Link

Round 1: Craft Coding Round

1Musical Instrument: 2Context: 3Musical Instrument works on frequencies. 4A good Musical play is a one in which each note always emits frequencies which are never the 5same. For simplicity we will assume frequencies to be the counts. 6For eg: 7{sa, re sa, ga,ma, ma, pa, ma} 8Sa is repeated 2 times 9Re -> 1 times 10Ga -> 1 times 11Ma -> 3 times. 12The above example is not a Good play, because the frequencies emitted are 2,1,1,3 (1 is repeated 13two times). To make it a good play, we have to the frequencies unique. 14 15How to make it as a good play ? 16For example: Remove 3 “Ma” and 1 “Re” (or “Ga”) . This becomes a good Musical play.But, Number 17of removals is 2. 18OR 19if I remove 1 “Ga” . Then each is repeated uniquely which aren't the same. Number of removals is 1. 20Minimum is min (2,1) = 1 21 22Problem Stmnt 23So given an array , you have to return the minimum number of removals needed to have unique 24frequencies. 25For example 26S = [aaabbbcc] 271) You can delete 2 'b's resulting in the good string "aaabcc". Total: 2 282) Another way is to delete 1 'b' and 1 'c' resulting in the good string "aaabbc". Total: 2 29Output: min (2,2) ~ 2 30S= [abcabc] 31 32You can delete 2 of either a, b , c and decrement the other by 1 (remove 2-a and 1-b) minimum 33removals is min (2+1) = 3 34Either remove 2a OR 2b OR 2c and decrement the rest by 1. So total is 3. 35S = ["bbcebab"] 36 37Output: 2 381 <= s < 10^5 39S contains LowerCase letters only.


Verdict: Rejected


Comments