Skip to content
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 number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
| 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) |
| 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) |
| 3516. Find Closest Person | [Link](https://leetcode.com/problems/find-closest-person/) | [Link](./lib/easy/3516_find_closest_person.dart) |
| 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) |
27 changes: 27 additions & 0 deletions lib/easy/3471_find_the_largest_almost_missing_integer.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class Solution {
int largestInteger(List<int> nums, int k) {
if (nums.length == k) {
return nums.reduce((a, b) => a > b ? a : b);
}

final count = <int, int>{};

for (int i = 0; i <= nums.length - k; i++) {
final sub = nums.sublist(i, i + k);

for (final num in sub) {
count[num] = (count[num] ?? 0) + 1;
}
}

var result = -1;

for (final entry in count.entries) {
if (entry.value == 1 && entry.key > result) {
result = entry.key;
}
}

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

environment:
Expand Down
42 changes: 42 additions & 0 deletions test/easy/3471_find_the_largest_almost_missing_integer_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import 'package:leetcode_dart/easy/3471_find_the_largest_almost_missing_integer.dart';
import 'package:test/test.dart';

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

test(
'Test case 1',
() => expect(
7,
solution.largestInteger(
[3, 9, 2, 1, 7],
3,
),
),
);
test(
'Test case 2',
() => expect(
3,
solution.largestInteger(
[3, 9, 7, 2, 1, 7],
4,
),
),
);
test(
'Test case 3',
() => expect(
-1,
solution.largestInteger(
[0, 0],
1,
),
),
);
},
);
}