Skip to content

Commit f42dba3

Browse files
authored
Merge pull request #39 from fartem/3471-Find-the-Largest-Almost-Missing-Integer
2025-05-08 v. 1.1.0: added "3471. Find the Largest Almost Missing Integer"
2 parents 11a2359 + 27d5820 commit f42dba3

4 files changed

+71
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,6 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
4343
| 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) |
4444
| 3280. Convert Date to Binary | [Link](https://leetcode.com/problems/convert-date-to-binary/) | [Link](./lib/easy/3280_convert_date_to_binary.dart) |
4545
| 3340. Check Balanced String | [Link](https://leetcode.com/problems/check-balanced-string/) | [Link](./lib/easy/3340_check_balanced_string.dart) |
46+
| 3471. Find the Largest Almost Missing Integer | [Link](https://leetcode.com/problems/check-balanced-string/) | [Link](./lib/easy/3471_find_the_largest_almost_missing_integer.dart) |
4647
| 3516. Find Closest Person | [Link](https://leetcode.com/problems/find-closest-person/) | [Link](./lib/easy/3516_find_closest_person.dart) |
4748
| 3536. Maximum Product of Two Digits | [Link](https://leetcode.com/problems/maximum-product-of-two-digits/) | [Link](./lib/easy/3536_maximum_product_of_two_digits.dart) |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Solution {
2+
int largestInteger(List<int> nums, int k) {
3+
if (nums.length == k) {
4+
return nums.reduce((a, b) => a > b ? a : b);
5+
}
6+
7+
final count = <int, int>{};
8+
9+
for (int i = 0; i <= nums.length - k; i++) {
10+
final sub = nums.sublist(i, i + k);
11+
12+
for (final num in sub) {
13+
count[num] = (count[num] ?? 0) + 1;
14+
}
15+
}
16+
17+
var result = -1;
18+
19+
for (final entry in count.entries) {
20+
if (entry.value == 1 && entry.key > result) {
21+
result = entry.key;
22+
}
23+
}
24+
25+
return result;
26+
}
27+
}

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: leetcode_dart
22
description: Some solved problems from https://leetcode.com on Dart
3-
version: 1.0.9
3+
version: 1.1.0
44
homepage: https://github.com/fartem/leetcode-dart
55

66
environment:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import 'package:leetcode_dart/easy/3471_find_the_largest_almost_missing_integer.dart';
2+
import 'package:test/test.dart';
3+
4+
void main() {
5+
group(
6+
'Example tests',
7+
() {
8+
final solution = Solution();
9+
10+
test(
11+
'Test case 1',
12+
() => expect(
13+
7,
14+
solution.largestInteger(
15+
[3, 9, 2, 1, 7],
16+
3,
17+
),
18+
),
19+
);
20+
test(
21+
'Test case 2',
22+
() => expect(
23+
3,
24+
solution.largestInteger(
25+
[3, 9, 7, 2, 1, 7],
26+
4,
27+
),
28+
),
29+
);
30+
test(
31+
'Test case 3',
32+
() => expect(
33+
-1,
34+
solution.largestInteger(
35+
[0, 0],
36+
1,
37+
),
38+
),
39+
);
40+
},
41+
);
42+
}

0 commit comments

Comments
 (0)