Skip to content

2025-05-09 v. 1.1.1: added "3005. Count Elements With Maximum Frequency" #40

New issue

Have a question about this project? Sign up for a free account to open an issue and contact its maintainers and the community.

By clicking “Sign up for ”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on ? Sign in to your account

Merged
merged 1 commit into from
May 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -40,6 +40,7 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
| 118. Pascal's Triangle | [Link](https://leetcode.com/problems/pascals-triangle/) | [Link](./lib/easy/118_pascals_triangle.dart) |
| 263. Ugly Number | [Link](https://lettcode.com/problems/ugly-number/) | [Link](./lib/easy/263_ugly_number.dart) |
| 500. Keyboard Row | [Link](https://leetcode.com/problems/keyboard-row/) | [Link](./lib/easy/500_keyboard_row.dart) |
| 3005. Count Elements With Maximum Frequency | [Link](https://leetcode.com/problems/count-elements-with-maximum-frequency/) | [Link](./lib/easy/3005_count_elements_with_maximum_frequency.dart) |
| 3120. Count the Number of Special Characters I | [Link](https://leetcode.com/problems/count-the-number-of-special-characters-i/) | [Link](./lib/easy/3120_count_the_number_of_special_characters_i.dart) |
| 3280. Convert Date to Binary | [Link](https://leetcode.com/problems/convert-date-to-binary/) | [Link](./lib/easy/3280_convert_date_to_binary.dart) |
| 3340. Check Balanced String | [Link](https://leetcode.com/problems/check-balanced-string/) | [Link](./lib/easy/3340_check_balanced_string.dart) |
Expand Down
22 changes: 22 additions & 0 deletions lib/easy/3005_count_elements_with_maximum_frequency.dart
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
class Solution {
int maxFrequencyElements(List<int> nums) {
final freq = {};
var maxFreq = 0;
var result = 0;

for (final num in nums) {
freq[num] = (freq[num] ?? 0) + 1;

if (freq[num] > maxFreq) {
maxFreq = freq[num];
result = 0;
}

if (freq[num] == maxFreq) {
result += maxFreq;
}
}

return result;
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
name: leetcode_dart
description: Some solved problems from https://leetcode.com on Dart
version: 1.1.0
version: 1.1.1
homepage: https://.com/fartem/leetcode-dart

environment:
Expand Down
30 changes: 30 additions & 0 deletions test/easy/3005_count_elements_with_maximum_frequency_test.dart
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
import 'package:leetcode_dart/easy/3005_count_elements_with_maximum_frequency.dart';
import 'package:test/test.dart';

void main() {
group(
'Example tests',
() {
final solution = Solution();

test(
'Test case 1',
() => expect(
4,
solution.maxFrequencyElements(
[1, 2, 2, 3, 1, 4],
),
),
);
test(
'Test case 2',
() => expect(
5,
solution.maxFrequencyElements(
[1, 2, 3, 4, 5],
),
),
);
},
);
}