Skip to content

Commit

Permalink
Merge pull request neetcode-gh#2044 from alexprudhomme/1189-maximum-n…
Browse files Browse the repository at this point in the history
…umber-of-balloons.cs

Create: 1189-maximum-number-of-balloons.cs
  • Loading branch information
tahsintunan authored Jan 16, 2023
2 parents e1997e8 + dd235ea commit 3838bb5
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions csharp/1189-maximum-number-of-balloons.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
public class Solution {
public int MaxNumberOfBalloons(string text) {
var charCounts = text.GroupBy(c => c)
.ToDictionary(g => g.Key, g => g.Count());
var balloonCounts = "balloon".GroupBy(c => c)
.ToDictionary(g => g.Key, g => g.Count());

int result = text.Length;
foreach (var balloonCount in balloonCounts) {
if (charCounts.ContainsKey(balloonCount.Key)) {
result = Math.Min(result, charCounts[balloonCount.Key] / balloonCount.Value);
} else {
result = 0;
break;
}
}
return result;
}
}

0 comments on commit 3838bb5

Please sign in to comment.