We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 183ec92 commit 00237c8Copy full SHA for 00237c8
1399. Count Largest Group
@@ -0,0 +1,24 @@
1
+class Solution {
2
+public:
3
+ int digitSum(int num){
4
+ int sum = 0;
5
+ while(num > 0){
6
+ sum += num%10;
7
+ num /= 10;
8
+ }
9
+ return sum;
10
11
+ int countLargestGroup(int n) {
12
+ unordered_map<int, int> freq;
13
+ int maxi = 0;
14
+ for(int i=1;i<=n;i++){
15
+ freq[digitSum(i)]++;
16
+ maxi = max(maxi, freq[digitSum(i)]);
17
18
+ int count = 0;
19
+ for(auto i:freq){
20
+ if(i.second == maxi) count++;
21
22
+ return count;
23
24
+};
0 commit comments