2#include "gtest/gtest.h"
9 namespace excel_sheet_column_title {
10 TEST(excel_sheet_column_title, case1) {
14 TEST(excel_sheet_column_title, case2) {
18 TEST(excel_sheet_column_title, case3) {
22 TEST(excel_sheet_column_title, case4) {
26 TEST(excel_sheet_column_title, case5) {
31 namespace majority_element {
32 TEST(majority_element, case1) {
34 int arr[] = {3, 2, 3};
35 auto vec = std::vector(arr, arr + 3);
36 ASSERT_EQ(3, sol.majorityElement(
vec));
39 TEST(majority_element, case2) {
41 int arr[] = {2, 2, 1, 1, 1, 2, 2};
42 auto vec = std::vector(arr, arr + 7);
43 ASSERT_EQ(2, sol.majorityElement(
vec));
46 TEST(majority_element, case3) {
48 int arr[] = {3, 2, 3};
49 auto vec = std::vector(arr, arr + 3);
50 ASSERT_EQ(3, sol.majorityElement(
vec));
54 namespace excel_sheet_column_number {
55 TEST(excel_sheet_column_number, case1) {
59 TEST(excel_sheet_column_number, case2) {
63 TEST(excel_sheet_column_number, case3) {
67 TEST(excel_sheet_column_number, case4) {
72 namespace concatenated_words {
73 TEST(concatenated_words, case1) {
74 basic_string<char> input[] = {
75 "cat",
"cats",
"catsdogcats",
"dog",
"dogcatsdog",
"hippopotamuses",
"rat",
77 auto vec = vector(begin(input), end(input));
79 string outputstr[] = {
"catsdogcats",
"dogcatsdog",
"ratcatdogcat"};
80 const auto output = vector(begin(outputstr), end(outputstr));
81 for(
const string &str: ans) {
82 ASSERT_TRUE(
find(output.cbegin(), output.cend(), str) != output.cend());
84 for(
const string &str: output) {
85 ASSERT_TRUE(
find(ans.cbegin(), ans.cend(), str) != ans.cend());
87 ASSERT_EQ(ans.size(), output.size());
90 TEST(concatenated_words, case2) {
91 basic_string<char> input[] = {
"cat",
"dog",
"catdog"};
92 auto vec = vector(begin(input), end(input));
94 string outputstr[] = {
"catdog"};
95 const auto output = vector(begin(outputstr), end(outputstr));
96 for(
const string &str: ans) {
97 ASSERT_TRUE(
find(output.cbegin(), output.cend(), str) != output.cend());
99 for(
const string &str: output) {
100 ASSERT_TRUE(
find(ans.cbegin(), ans.cend(), str) != ans.cend());
102 ASSERT_EQ(ans.size(), output.size());
105 TEST(concatenated_words, case4) {
106 basic_string<char> input[] = {
"nuqhmfj",
"mf",
"jf",
"n",
"u",
"q",
"h"};
107 auto vec = vector(begin(input), end(input));
109 const auto output = vector<string>();
110 for(
const string &str: ans) {
111 ASSERT_TRUE(
find(output.cbegin(), output.cend(), str) != output.cend());
113 for(
const string &str: output) {
114 ASSERT_TRUE(
find(ans.cbegin(), ans.cend(), str) != ans.cend());
116 ASSERT_EQ(ans.size(), output.size());
120 namespace count_special_quadruplets {
121 TEST(count_special_quadruplets, case1) {
122 int input[] = {1, 2, 3, 6};
123 auto vec = vector(begin(input), end(input));
127 TEST(count_special_quadruplets, case2) {
128 int input[] = {3, 3, 6, 4, 5};
129 auto vec = vector(begin(input), end(input));
133 TEST(count_special_quadruplets, case3) {
134 int input[] = {1, 1, 1, 3, 5};
135 auto vec = vector(begin(input), end(input));
139 TEST(count_special_quadruplets, case4) {
140 int input[] = {28, 8, 49, 85, 37, 90, 20, 8};
141 auto vec = vector(begin(input), end(input));
146 namespace hand_of_straights {
147 TEST(hand_of_straights, case1) {
148 int input[] = {1, 2, 3, 6, 2, 3, 4, 7, 8};
149 auto vec = vector(begin(input), end(input));
153 TEST(hand_of_straights, case2) {
154 int input[] = {1, 2, 3, 4, 5};
155 auto vec = vector(begin(input), end(input));
159 TEST(hand_of_straights, case3) {
160 int input[] = {1, 2, 3, 4, 5, 6};
161 auto vec = vector(begin(input), end(input));
165 TEST(hand_of_straights, case4) {
167 9, 13, 15, 23, 22, 25, 4, 4, 29, 15, 8, 23, 12, 19, 24, 17, 18, 11, 22, 24, 17, 17, 10, 23,
168 21, 18, 14, 18, 7, 6, 3, 6, 19, 11, 16, 11, 12, 13, 8, 26, 17, 20, 13, 19, 22, 21, 27, 9, 20,
169 15, 20, 27, 8, 13, 25, 23, 22, 15, 9, 14, 20, 10, 6, 5, 14, 12, 7, 16, 21, 18, 21, 24, 23,
170 10, 21, 16, 18, 16, 18, 5, 20, 19, 20, 10, 14, 26, 2, 9, 19, 12, 28, 17, 5, 7, 25, 22, 16,
172 auto vec = vector(begin(input), end(input));
177 namespace perfect_number {
199 namespace convert_bst_to_greater_tree {
200 TEST(convert_bst_to_greater_tree, case1) {
206 ASSERT_TRUE(*ans == *output);
210 namespace convert_1d_array_into_2d_array {
211 TEST(convert_1d_array_into_2d_array, case1) {
212 int input[4] = {1, 2, 3, 4};
213 auto vec = vector(begin(input), end(input));
215 int output1[] = {1, 2};
216 int output2[] = {3, 4};
217 const auto vec1 = vector(begin(output1), end(output1));
218 const auto vec2 = vector(begin(output2), end(output2));
219 auto vec_output = vector<vector<int>>();
220 vec_output.push_back(vec1);
221 vec_output.push_back(vec2);
222 ASSERT_EQ(vec_output, ans);
226 namespace elimination_game {
227 TEST(elimination_game, case1) {
240 namespace check_if_all_as_appears_before_all_bs {
241 TEST(check_if_all_as_appears_before_all_bs, case1) {
245 TEST(check_if_all_as_appears_before_all_bs, case2) {
249 TEST(check_if_all_as_appears_before_all_bs, case3) {
254 namespace number_of_laser_beams_in_a_bank {
255 TEST(number_of_laser_beams_in_a_bank, case1) {
256 string input[] = {
"011001",
"000000",
"010100",
"001000"};
257 auto vec = vector(begin(input), end(input));
261 TEST(number_of_laser_beams_in_a_bank, case2) {
262 string input[] = {
"000",
"111",
"000"};
263 auto vec = vector(begin(input), end(input));
268 namespace destroying_asteroids {
269 TEST(destroying_asteroids, case1) {
270 int input[] = {3, 9, 19, 5, 21};
271 auto vec = vector(begin(input), end(input));
275 TEST(destroying_asteroids, case2) {
276 int input[] = {4, 9, 23, 4};
277 auto vec = vector(begin(input), end(input));
282 namespace day_of_the_week {
304 namespace replace_all_s_to_avoid_consecutive_repeating_characters {
305 TEST(replace_all_s_to_avoid_consecutive_repeating_characters, case1) {
309 TEST(replace_all_s_to_avoid_consecutive_repeating_characters, case2) {
313 TEST(replace_all_s_to_avoid_consecutive_repeating_characters, case3) {
317 TEST(replace_all_s_to_avoid_consecutive_repeating_characters, case4) {
322 namespace simplify_path {
344 namespace maximum_nesting_depth_of_the_parentheses {
345 TEST(maximum_nesting_depth_of_the_parentheses, case1) {
349 TEST(maximum_nesting_depth_of_the_parentheses, case2) {
353 TEST(maximum_nesting_depth_of_the_parentheses, case3) {
357 TEST(maximum_nesting_depth_of_the_parentheses, case4) {
362 namespace gray_code {
364 int output[] = {0, 1, 3, 2};
365 const auto vec = vector(begin(output), end(output));
370 namespace minimum_swaps_to_group_all_1s_together_ii {
371 TEST(minimum_swaps_to_group_all_1s_together_ii, case1) {
372 int input[] = {0, 1, 0, 1, 1, 0, 0};
373 auto vec = vector(begin(input), end(input));
377 TEST(minimum_swaps_to_group_all_1s_together_ii, case2) {
378 int input[] = {0, 1, 1, 1, 0, 0, 1, 1, 0};
379 auto vec = vector(begin(input), end(input));
383 TEST(minimum_swaps_to_group_all_1s_together_ii, case3) {
384 int input[] = {1, 1, 0, 0, 1};
385 auto vec = vector(begin(input), end(input));
389 TEST(minimum_swaps_to_group_all_1s_together_ii, case4) {
390 int input[] = {1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0,
392 auto vec = vector(begin(input), end(input));
397 namespace count_words_obtained_after_adding_a_letter {
398 TEST(count_words_obtained_after_adding_a_letter, case1) {
399 string input1[] = {
"ant",
"act",
"tack"};
400 auto vec1 = vector(begin(input1), end(input1));
401 string input2[] = {
"tack",
"act",
"acti"};
402 auto vec2 = vector(begin(input2), end(input2));
406 TEST(count_words_obtained_after_adding_a_letter, case2) {
407 string input1[] = {
"ab",
"a"};
408 auto vec1 = vector(begin(input1), end(input1));
409 string input2[] = {
"abc",
"abcd"};
410 auto vec2 = vector(begin(input2), end(input2));
414 TEST(count_words_obtained_after_adding_a_letter, case3) {
415 string input1[] = {
"g",
"vf",
"ylpuk",
"nyf",
"gdj",
"j",
"fyqzg",
"sizec"};
416 auto vec1 = vector(begin(input1), end(input1));
417 string input2[] = {
"r",
"am",
"jg",
"umhjo",
"fov",
"lujy",
"b",
"uz",
"y"};
418 auto vec2 = vector(begin(input2), end(input2));
423 namespace slowest_key {
425 int input[] = {9, 29, 49, 50};
426 auto vec = vector(begin(input), end(input));
431 int input[] = {12, 23, 36, 46, 62};
432 auto vec = vector(begin(input), end(input));
437 namespace additive_number {
459 const char input[] = {
'2'};
464 const char input[] = {
'2',
'3',
'4'};
469 const char input[] = {
'2',
'3',
'4'};
474 const char input[] = {
'2',
'3',
'4'};
479 const char input[] = {
'1',
'2'};
484 const char input[] = {
'1',
'2',
'4'};
489 const char input[] = {
'3',
'2',
'4'};
494 const char input[] = {
'3',
'2',
'4',
'5'};
499 const char input[] = {
'3',
'2',
'4',
'5'};
504 const char input[] = {
'1',
'1',
'2'};
509 const char input[] = {
'1',
'1',
'2',
'3'};
514 const char input[] = {
'1',
'1',
'2',
'4'};
519 const char input[] = {
'1',
'1',
'2',
'3',
'3',
'4'};
524 namespace decode_the_slanted_ciphertext {
525 TEST(decode_the_slanted_ciphertext, case1) {
529 TEST(decode_the_slanted_ciphertext, case2) {
533 TEST(decode_the_slanted_ciphertext, case3) {
537 TEST(decode_the_slanted_ciphertext, case4) {
542 namespace increasing_triplet_subsequence {
543 TEST(increasing_triplet_subsequence, case1) {
544 int input[] = {1, 2, 3, 4, 5};
545 auto vec = vector(begin(input), end(input));
549 TEST(increasing_triplet_subsequence, case2) {
550 int input[] = {5, 4, 3, 2, 1};
551 auto vec = vector(begin(input), end(input));
555 TEST(increasing_triplet_subsequence, case3) {
556 int input[] = {2, 1, 5, 0, 4, 6};
557 auto vec = vector(begin(input), end(input));
561 TEST(increasing_triplet_subsequence, case4) {
562 int input[] = {20, 100, 10, 12, 5, 13};
563 auto vec = vector(begin(input), end(input));
568 namespace largest_number_at_least_twice_of_others {
569 TEST(largest_number_at_least_twice_of_others, case1) {
570 int input[] = {3, 6, 1, 0};
571 auto vec = vector(begin(input), end(input));
575 TEST(largest_number_at_least_twice_of_others, case2) {
576 int input[] = {1, 2, 3, 4};
577 auto vec = vector(begin(input), end(input));
581 TEST(largest_number_at_least_twice_of_others, case3) {
583 auto vec = vector(begin(input), end(input));
587 TEST(largest_number_at_least_twice_of_others, case4) {
588 int input[] = {0, 0, 0, 1};
589 auto vec = vector(begin(input), end(input));
593 TEST(largest_number_at_least_twice_of_others, case5) {
594 int input[] = {0, 0, 3, 2};
595 auto vec = vector(begin(input), end(input));
600 namespace permutations {
603 auto vec = vector(begin(input), end(input));
604 auto ans = vector<vector<int>>();
605 auto ans1 = vector<int>();
612 int input[] = {0, 1};
613 auto vec = vector(begin(input), end(input));
614 auto ans = vector<vector<int>>();
615 auto ans1 = vector<int>();
619 auto ans2 = vector<int>();
627 int input[] = {1, 2, 3};
628 auto vec = vector(begin(input), end(input));
629 auto ans = vector<vector<int>>();
630 int outputs[6][3] = {{1, 2, 3}, {1, 3, 2}, {2, 1, 3}, {2, 3, 1}, {3, 1, 2}, {3, 2, 1}};
631 for(
auto &output: outputs) {
632 ans.emplace_back(begin(output), end(output));
638 namespace calculate_money_in_leetcode_bank {
639 TEST(calculate_money_in_leetcode_bank, case1) {
643 TEST(calculate_money_in_leetcode_bank, case2) {
647 TEST(calculate_money_in_leetcode_bank, case3) {
652 namespace divide_a_string_into_groups_of_size_k {
653 TEST(divide_a_string_into_groups_of_size_k, case1) {
654 string output[] = {
"abc",
"def",
"ghi"};
655 const auto vec = vector(begin(output), end(output));
659 TEST(divide_a_string_into_groups_of_size_k, case2) {
660 string output[] = {
"abc",
"def",
"ghi",
"jxx"};
661 const auto vec = vector(begin(output), end(output));
665 TEST(divide_a_string_into_groups_of_size_k, case3) {
666 string output[] = {
"ctoyjrwt",
"ngqwtnnn"};
667 const auto vec = vector(begin(output), end(output));
672 namespace minimum_moves_to_reach_target_score {
673 TEST(minimum_moves_to_reach_target_score, case1) {
677 TEST(minimum_moves_to_reach_target_score, case2) {
681 TEST(minimum_moves_to_reach_target_score, case3) {
686 namespace maximum_running_time_of_n_computers {
687 TEST(maximum_running_time_of_n_computers, case1) {
688 int input[] = {3, 3, 3};
689 auto vec = vector(begin(input), end(input));
693 TEST(maximum_running_time_of_n_computers, case2) {
694 int input[] = {1, 1, 1, 1};
695 auto vec = vector(begin(input), end(input));
700 namespace coun_vowels_permutation {
701 TEST(coun_vowels_permutation, case1) {
705 TEST(coun_vowels_permutation, case2) {
709 TEST(coun_vowels_permutation, case3) {
714 namespace minimum_time_difference {
715 TEST(minimum_time_difference, case1) {
716 string input[] = {
"23:59",
"00:00"};
717 auto vec = vector(begin(input), end(input));
721 TEST(minimum_time_difference, case2) {
722 string input[] = {
"00:00",
"23:59",
"00:00"};
723 auto vec = vector(begin(input), end(input));
727 TEST(minimum_time_difference, case3) {
728 string input[] = {
"00:00",
"04:00",
"22:00"};
729 auto vec = vector(begin(input), end(input));
734 namespace contains_duplicate_ii {
735 TEST(contains_duplicate_ii, case1) {
736 int input[] = {1, 2, 3, 1};
737 auto vec = vector(begin(input), end(input));
741 TEST(contains_duplicate_ii, case2) {
742 int input[] = {1, 0, 1, 1};
743 auto vec = vector(begin(input), end(input));
747 TEST(contains_duplicate_ii, case3) {
748 int input[] = {1, 2, 3, 1, 2, 3};
749 auto vec = vector(begin(input), end(input));
754 namespace stone_game_ix {
756 int input[] = {2, 1};
757 auto vec = vector(begin(input), end(input));
763 auto vec = vector(begin(input), end(input));
768 int input[] = {5, 1, 2, 4, 3};
769 auto vec = vector(begin(input), end(input));
774 int input[] = {3, 4, 6, 6, 8, 9, 2, 4, 5};
775 auto vec = vector(begin(input), end(input));
780 int input[] = {2, 3, 7, 9, 4, 32, 2, 5, 8, 2, 6, 8, 3, 2, 6, 8, 3, 2, 5, 7, 8, 3, 5, 67, 8};
781 auto vec = vector(begin(input), end(input));
786 int input[] = {15, 20, 10, 13, 14, 15, 5, 2, 3};
787 auto vec = vector(begin(input), end(input));
792 namespace jump_game_iv {
794 int input[] = {100, -23, -23, 404, 100, 23, 23, 23, 3, 404};
795 auto vec = vector(begin(input), end(input));
801 auto vec = vector(begin(input), end(input));
806 int input[] = {7, 6, 9, 6, 9, 6, 9, 7};
807 auto vec = vector(begin(input), end(input));
812 int input[] = {6, 1, 9};
813 auto vec = vector(begin(input), end(input));
818 int input[] = {100, -23, -23, 404, 100, 23, 23, 23, 3, 404};
819 auto vec = vector(begin(input), end(input));
824 int input[] = {-76, 3, 66, -32, 64, 2, -19, -8, -5, -93, 80, -5, -76, -78, 64, 2, 16};
825 auto vec = vector(begin(input), end(input));
830 int input[] = {-10, -25, 58, -67, 28, 86, 58, -29, -10, -10, 45, -80, 86, 35, -10, 58, -10, -98, -9, -98, -10, -67, -29, -6, 74, 46, -29, -5, 58, 58, -17, 28, -4, -67, 28, -98, -4, 86, -29, -92, -67, 58, -76, -27, -9, 58, -92, -42, -27, -41, 58, -25, 74, -98, -92, -10, -67, -6, -17, -5, -29, -17, -4, 28, -17, -80, 35, -9, 32, -29, -76, 46, -29, -5, -27, 35, 74, -92, -4, -98, -9, -10, -4, -27, -92, 74, -98, -29, -42, -9, 45, -10, -98, 28};
831 auto vec = vector(begin(input), end(input));
837 auto vec = vector(begin(input), end(input));
842 namespace remove_palindromic_subsequences {
843 TEST(remove_palindromic_subsequences, case1) {
847 TEST(remove_palindromic_subsequences, case2) {
851 TEST(remove_palindromic_subsequences, case3) {
858 string input[] = {
"cat",
"bat",
"rat"};
859 auto vec = vector(begin(input), end(input));
864 string input[] = {
"a",
"b",
"c"};
865 auto vec = vector(begin(input), end(input));
870 string input[] = {
"a",
"aa",
"aaa",
"aaaa"};
871 auto vec = vector(begin(input), end(input));
876 string input[] = {
"catt",
"cat",
"bat",
"rat"};
877 auto vec = vector(begin(input), end(input));
882 string input[] = {
"ac",
"ab"};
883 auto vec = vector(begin(input), end(input));
884 ASSERT_EQ(
"it is ab that this solution is ac",
Solution::replaceWords(
vec,
"it is abnormal that this solution is accepted"));
888 namespace minimum_cost_of_buying_candies_with_discount {
889 TEST(minimum_cost_of_buying_candies_with_discount, case1) {
890 int input[] = {1, 2, 3};
891 auto vec = vector(begin(input), end(input));
895 TEST(minimum_cost_of_buying_candies_with_discount, case2) {
896 int input[] = {6, 5, 7, 9, 2, 2};
897 auto vec = vector(begin(input), end(input));
901 TEST(minimum_cost_of_buying_candies_with_discount, case3) {
902 int input[] = {5, 5};
903 auto vec = vector(begin(input), end(input));
908 namespace count_the_hidden_sequences {
909 TEST(count_the_hidden_sequences, case1) {
910 int input[] = {1, -3, 4};
911 auto vec = vector(begin(input), end(input));
915 TEST(count_the_hidden_sequences, case2) {
916 int input[] = {3, -4, 5, 1, -2};
917 auto vec = vector(begin(input), end(input));
921 TEST(count_the_hidden_sequences, case3) {
922 int input[] = {4, -7, 2};
923 auto vec = vector(begin(input), end(input));
928 namespace number_of_ways_to_divide_a_long_corridor {
929 TEST(number_of_ways_to_divide_a_long_corridor, case1) {
933 TEST(number_of_ways_to_divide_a_long_corridor, case2) {
937 TEST(number_of_ways_to_divide_a_long_corridor, case3) {
941 TEST(number_of_ways_to_divide_a_long_corridor, case4) {
945 TEST(number_of_ways_to_divide_a_long_corridor, case6) {
950 namespace count_elements_with_strictly_smaller_and_greater_elements {
951 TEST(count_elements_with_strictly_smaller_and_greater_elements, case1) {
952 int input[] = {11, 7, 2, 15};
953 auto vec = vector(begin(input), end(input));
957 TEST(count_elements_with_strictly_smaller_and_greater_elements, case2) {
958 int input[] = {-3, 3, 3, 90};
959 auto vec = vector(begin(input), end(input));
964 namespace rearrange_array_elements_by_sign {
965 TEST(rearrange_array_elements_by_sign, case1) {
966 int input[] = {3, 1, -2, -5, 2, -4};
967 auto vec_input = vector(begin(input), end(input));
968 int output[] = {3, -2, 1, -5, 2, -4};
969 const auto vec_output = vector(begin(output), end(output));
973 TEST(rearrange_array_elements_by_sign, case2) {
974 int input[] = {-1, 1};
975 auto vec_input = vector(begin(input), end(input));
976 int output[] = {1, -1};
977 const auto vec_output = vector(begin(output), end(output));
982 namespace find_all_lonely_numbers_in_the_array {
983 TEST(find_all_lonely_numbers_in_the_array, case1) {
984 int input[] = {10, 6, 5, 8};
985 auto vec_input = vector(begin(input), end(input));
986 int output[] = {10, 8};
987 const auto vec_output = vector(begin(output), end(output));
991 TEST(find_all_lonely_numbers_in_the_array, case2) {
992 int input[] = {1, 3, 5, 3};
993 auto vec_input = vector(begin(input), end(input));
994 int output[] = {1, 5};
995 const auto vec_output = vector(begin(output), end(output));
1000 namespace maximum_good_people_based_on_statements {
1001 TEST(maximum_good_people_based_on_statements, case1) {
1002 int input1[] = {2, 1, 2};
1003 int input2[] = {1, 2, 2};
1004 int input3[] = {2, 0, 2};
1005 vector<int> input[] = {vector(begin(input1), end(input1)), vector(begin(input2), end(input2)), vector(begin(input3), end(input3))};
1006 auto vec_input = vector(begin(input), end(input));
1010 TEST(maximum_good_people_based_on_statements, case2) {
1011 int input1[] = {2, 0};
1012 int input2[] = {0, 2};
1013 vector<int> input[] = {vector(begin(input1), end(input1)), vector(begin(input2), end(input2))};
1014 auto vec_input = vector(begin(input), end(input));
1019 namespace second_minimum_time_to_reach_destination {
1020 TEST(second_minimum_time_to_reach_destination, case1) {
1021 int inputs[][2] = {{1, 2}, {1, 3}, {1, 4}, {3, 4}, {4, 5}};
1022 auto vec = vector<vector<int>>();
1023 for(
const auto *input: inputs) {
1024 auto n_vec = vector<int>();
1026 n_vec[0] = input[0];
1027 n_vec[1] = input[1];
1028 vec.push_back(n_vec);
1033 TEST(second_minimum_time_to_reach_destination, case2) {
1034 int inputs[][2] = {{1, 2}};
1035 auto vec = vector<vector<int>>();
1036 for(
const auto *input: inputs) {
1037 auto n_vec = vector<int>();
1039 n_vec[0] = input[0];
1040 n_vec[1] = input[1];
1041 vec.push_back(n_vec);
1047 namespace count_of_matches_in_tournament {
1048 TEST(count_of_matches_in_tournament, case1) {
1052 TEST(count_of_matches_in_tournament, case2) {
1057 namespace number_of_valid_words_in_a_sentence {
1058 TEST(number_of_valid_words_in_a_sentence, case1) {
1062 TEST(number_of_valid_words_in_a_sentence, case2) {
1066 TEST(number_of_valid_words_in_a_sentence, case3) {
1070 TEST(number_of_valid_words_in_a_sentence, case4) {
1075 namespace pattern_matching_lcci {
1076 TEST(pattern_matching_lcci, case1) {
1080 TEST(pattern_matching_lcci, case2) {
1084 TEST(pattern_matching_lcci, case3) {
1088 TEST(pattern_matching_lcci, case4) {
1092 TEST(pattern_matching_lcci, case5) {
1096 TEST(pattern_matching_lcci, case6) {
1101 namespace map_of_highest_peak {
1103 int input[2][2] = {{0, 1}, {0, 0}};
1104 auto vec_in = vector<vector<int>>();
1106 for(
int i = 0; i < 2; i++) {
1107 vec_in[i] = vector(begin(input[i]), end(input[i]));
1109 int output[2][2] = {{1, 0}, {2, 1}};
1110 auto vec_out = vector<vector<int>>();
1112 for(
int i = 0; i < 2; i++) {
1113 vec_out[i] = vector(begin(output[i]), end(output[i]));
1119 int input[3][3] = {{0, 0, 1}, {1, 0, 0}, {0, 0, 0}};
1120 auto vec_in = vector<vector<int>>();
1122 for(
int i = 0; i < 3; i++) {
1123 vec_in[i] = vector(begin(input[i]), end(input[i]));
1125 int output[3][3] = {{1, 1, 0}, {0, 1, 1}, {1, 2, 2}};
1126 auto vec_out = vector<vector<int>>();
1128 for(
int i = 0; i < 3; i++) {
1129 vec_out[i] = vector(begin(output[i]), end(output[i]));
1135 namespace find_substring_with_given_hash_value {
1136 TEST(find_substring_with_given_hash_value, case1) {
1140 TEST(find_substring_with_given_hash_value, case2) {
1145 namespace groups_of_strings {
1147 string input[] = {
"a",
"b",
"ab",
"cde"};
1148 auto input_vec = vector(begin(input), end(input));
1149 int output[] = {2, 3};
1150 const auto output_vec = vector(begin(output), end(output));
1152 ASSERT_EQ(output_vec, sol.groupStrings(input_vec));
1156 string input[] = {
"a",
"ab",
"abc"};
1157 auto input_vec = vector(begin(input), end(input));
1158 int output[] = {1, 3};
1159 const auto output_vec = vector(begin(output), end(output));
1161 ASSERT_EQ(output_vec, sol.groupStrings(input_vec));
1165 string input[] = {
"qamp",
"am",
"khdrn"};
1166 auto input_vec = vector(begin(input), end(input));
1167 int output[] = {3, 1};
1168 const auto output_vec = vector(begin(output), end(output));
1170 ASSERT_EQ(output_vec, sol.groupStrings(input_vec));
1174 string input[] = {
"ghnv",
"uip",
"tenv",
"hvepx",
"e",
"ktc",
"byjdt",
"ulm",
"cae",
"ea"};
1175 auto input_vec = vector(begin(input), end(input));
1176 int output[] = {8, 3};
1177 const auto output_vec = vector(begin(output), end(output));
1179 ASSERT_EQ(output_vec, sol.groupStrings(input_vec));
1183 string input[] = {
"web",
"a",
"te",
"hsx",
"v",
"k",
"a",
"roh"};
1184 auto input_vec = vector(begin(input), end(input));
1185 int output[] = {5, 4};
1186 const auto output_vec = vector(begin(output), end(output));
1188 ASSERT_EQ(output_vec, sol.groupStrings(input_vec));
1192 namespace number_of_steps_to_reduce_a_number_to_zero {
1193 TEST(number_of_steps_to_reduce_a_number_to_zero, case1) {
1197 TEST(number_of_steps_to_reduce_a_number_to_zero, case2) {
1201 TEST(number_of_steps_to_reduce_a_number_to_zero, case3) {
1206 namespace longest_nice_substring {
1207 TEST(longest_nice_substring, case1) {
1211 TEST(longest_nice_substring, case2) {
1215 TEST(longest_nice_substring, case3) {
1219 TEST(longest_nice_substring, case4) {
1224 namespace reverse_prefix_of_word {
1225 TEST(reverse_prefix_of_word, case1) {
1229 TEST(reverse_prefix_of_word, case2) {
1233 TEST(reverse_prefix_of_word, case3) {
1238 namespace find_the_minimum_number_of_fibonacci_numbers_whose_sum_is_k {
1239 TEST(find_the_minimum_number_of_fibonacci_numbers_whose_sum_is_k, case1) {
1243 TEST(find_the_minimum_number_of_fibonacci_numbers_whose_sum_is_k, case2) {
1247 TEST(find_the_minimum_number_of_fibonacci_numbers_whose_sum_is_k, case3) {
1252 namespace number_of_rectangles_that_can_form_the_largest_square {
1253 TEST(number_of_rectangles_that_can_form_the_largest_square, case1) {
1254 vector<vector<int>> input = {{5, 8}, {3, 9}, {5, 12}, {16, 5}};
1258 TEST(number_of_rectangles_that_can_form_the_largest_square, case2) {
1259 vector<vector<int>> input = {{2, 3}, {3, 7}, {4, 3}, {3, 7}};
1264 namespace path_with_maximum_gold {
1265 TEST(path_with_maximum_gold, case1) {
1266 vector<vector<int>> input = {{0, 6, 0}, {5, 8, 7}, {0, 9, 0}};
1270 TEST(path_with_maximum_gold, case2) {
1271 vector<vector<int>> input = {{1, 0, 7}, {2, 0, 6}, {3, 4, 5}, {0, 3, 0}, {9, 0, 20}};
1276 namespace minimum_difference_in_sums_after_removal_of_elements {
1277 TEST(minimum_difference_in_sums_after_removal_of_elements, case1) {
1278 vector input = {3, 1, 2};
1282 TEST(minimum_difference_in_sums_after_removal_of_elements, case2) {
1283 vector input = {7, 9, 5, 8, 1, 3};
1288 namespace sum_of_unique_elements {
1289 TEST(sum_of_unique_elements, case1) {
1290 vector input = {1, 2, 3, 2};
1294 TEST(sum_of_unique_elements, case2) {
1295 vector input = {1, 1, 1, 1, 1};
1299 TEST(sum_of_unique_elements, case3) {
1300 vector input = {1, 2, 3, 4, 5};
1305 namespace smallest_value_of_the_rearranged_number {
1306 TEST(smallest_value_of_the_rearranged_number, case1) {
1310 TEST(smallest_value_of_the_rearranged_number, case2) {
1314 TEST(smallest_value_of_the_rearranged_number, case3) {
1319 namespace design_bitset {
1325 ASSERT_FALSE(bt.all());
1328 ASSERT_TRUE(bt.one());
1330 ASSERT_EQ(2, bt.count());
1331 ASSERT_EQ(
"01010", bt.toString());
1335 namespace longest_happy_string {
1336 TEST(longest_happy_string, case1) {
1340 TEST(longest_happy_string, case2) {
1345 namespace grid_illumination {
1347 vector<vector<int>> lamps = {{0, 0}, {4, 4}};
1348 vector<vector<int>> queries = {{1, 1}, {1, 0}};
1349 const vector output = {1, 0};
1354 vector<vector<int>> lamps = {{0, 0}, {4, 4}};
1355 vector<vector<int>> queries = {{1, 1}, {1, 1}};
1356 const vector output = {1, 1};
1361 vector<vector<int>> lamps = {{0, 0}, {0, 4}};
1362 vector<vector<int>> queries = {{0, 4}, {0, 1}, {1, 4}};
1363 const vector output = {1, 1, 0};
1368 vector<vector<int>> lamps = {{1, 1}};
1369 vector<vector<int>> queries = {{2, 0}, {1, 0}};
1370 const vector output = {1, 0};
1375 vector<vector<int>> lamps = {{2, 5}, {4, 2}, {0, 3}, {0, 5}, {1, 4}, {4, 2}, {3, 3}, {1, 0}};
1376 vector<vector<int>> queries = {{4, 3}, {3, 1}, {5, 3}, {0, 5}, {4, 4}, {3, 3}};
1377 const vector output = {1, 0, 1, 1, 0, 1};
1382 namespace count_number_of_pairs_with_absolute_difference_k {
1383 TEST(count_number_of_pairs_with_absolute_difference_k, case1) {
1384 vector input = {1, 2, 2, 1};
1388 TEST(count_number_of_pairs_with_absolute_difference_k, case2) {
1389 vector input = {1, 3};
1393 TEST(count_number_of_pairs_with_absolute_difference_k, case3) {
1394 vector input = {3, 2, 1, 5, 4};
1399 namespace simplified_fractions {
1400 TEST(simplified_fractions, case1) {
1401 const vector<string> output = {
"1/2"};
1405 TEST(simplified_fractions, case2) {
1406 const vector<string> output = {
"1/2",
"1/3",
"2/3"};
1410 TEST(simplified_fractions, case3) {
1411 const vector<string> output = {
"1/2",
"1/3",
"2/3",
"1/4",
"3/4"};
1416 namespace minimum_difference_between_highest_and_lowest_of_k_scores {
1417 TEST(minimum_difference_between_highest_and_lowest_of_k_scores, case1) {
1418 vector input = {90};
1422 TEST(minimum_difference_between_highest_and_lowest_of_k_scores, case2) {
1423 vector input = {9, 4, 1, 7};
1428 namespace number_of_enclaves {
1430 vector<vector<int>> input = {{0, 0, 0, 0}, {1, 0, 1, 0}, {0, 1, 1, 0}, {0, 0, 0, 0}};
1435 vector<vector<int>> input = {{0, 1, 1, 0}, {0, 0, 1, 0}, {0, 0, 1, 0}, {0, 0, 0, 0}};
1440 namespace maximum_number_of_balloons {
1441 TEST(maximum_number_of_balloons, case1) {
1445 TEST(maximum_number_of_balloons, case2) {
1449 TEST(maximum_number_of_balloons, case3) {
1454 namespace swap_adjacent_in_lr_string {
1455 TEST(swap_adjacent_in_lr_string, case1) {
1459 TEST(swap_adjacent_in_lr_string, case2) {
1463 TEST(swap_adjacent_in_lr_string, case3) {
1468 namespace count_operations_to_obtain_zero {
1469 TEST(count_operations_to_obtain_zero, case1) {
1473 TEST(count_operations_to_obtain_zero, case2) {
1478 namespace minimum_operations_to_make_the_array_alternating {
1479 TEST(minimum_operations_to_make_the_array_alternating, case1) {
1480 vector input = {3, 1, 3, 2, 4, 3};
1484 TEST(minimum_operations_to_make_the_array_alternating, case2) {
1485 vector input = {1, 2, 2, 2, 2};
1489 TEST(minimum_operations_to_make_the_array_alternating, case3) {
1490 vector input = {69, 91, 47, 74, 75, 94, 22, 100, 43, 50, 82, 47, 40, 51, 90, 27, 98, 85, 47, 14, 55, 82, 52, 9, 65, 90, 86, 45, 52, 52, 95, 40, 85, 3, 46, 77, 16, 59, 32, 22, 41, 87, 89, 78, 59, 78, 34, 26, 71, 9, 82, 68, 80, 74, 100, 6, 10, 53, 84, 80, 7, 87, 3, 82, 26, 26, 14, 37, 26, 58, 96, 73, 41, 2, 79, 43, 56, 74, 30, 71, 6, 100, 72, 93, 83, 40, 28, 79, 24};
1495 namespace removing_minimum_number_of_magic_beans {
1496 TEST(removing_minimum_number_of_magic_beans, case1) {
1497 vector input = {4, 1, 6, 5};
1501 TEST(removing_minimum_number_of_magic_beans, case2) {
1502 vector input = {2, 10, 3, 2};
1507 namespace maximum_and_sum_of_array {
1508 TEST(maximum_and_sum_of_array, case1) {
1509 vector input = {1, 2, 3, 4, 5, 6};
1513 TEST(maximum_and_sum_of_array, case2) {
1514 vector input = {1, 3, 10, 4, 7, 1};
1519 namespace single_element_in_a_sorted_array {
1520 TEST(single_element_in_a_sorted_array, case1) {
1521 vector input = {1, 1, 2, 3, 3, 4, 4, 8, 8};
1525 TEST(single_element_in_a_sorted_array, case2) {
1526 vector input = {3, 3, 7, 7, 10, 11, 11};
1531 namespace lucky_numbers_in_a_matrix {
1532 TEST(lucky_numbers_in_a_matrix, case1) {
1533 vector<vector<int>> input = {{3, 7, 8}, {9, 11, 13}, {15, 16, 17}};
1534 const vector output = {15};
1538 TEST(lucky_numbers_in_a_matrix, case2) {
1539 vector<vector<int>> input = {{1, 10, 4, 2}, {9, 3, 8, 7}, {15, 16, 17, 12}};
1540 const vector output = {12};
1544 TEST(lucky_numbers_in_a_matrix, case3) {
1545 vector<vector<int>> input = {{7, 8}, {1, 2}};
1546 const vector output = {7};
1551 namespace number_of_ways_to_reconstruct_a_tree {
1552 TEST(number_of_ways_to_reconstruct_a_tree, case1) {
1553 vector<vector<int>> input = {{1, 2}, {2, 3}};
1557 TEST(number_of_ways_to_reconstruct_a_tree, case2) {
1558 vector<vector<int>> input = {{1, 2}, {2, 3}, {1, 3}};
1562 TEST(number_of_ways_to_reconstruct_a_tree, case3) {
1563 vector<vector<int>> input = {{1, 2}, {2, 3}, {2, 4}, {1, 5}};
1568 namespace find_center_of_star_graph {
1569 TEST(find_center_of_star_graph, case1) {
1570 vector<vector<int>> input = {{1, 2}, {2, 3}, {4, 2}};
1574 TEST(find_center_of_star_graph, case2) {
1575 vector<vector<int>> input = {{1, 2}, {5, 1}, {1, 3}, {1, 4}};
1580 namespace knight_probability_in_chessboard {
1581 TEST(knight_probability_in_chessboard, case1) {
1583 ASSERT_EQ(0.06250, sol.knightProbability(3, 2, 0, 0));
1586 TEST(knight_probability_in_chessboard, case2) {
1588 ASSERT_EQ(1.00000, sol.knightProbability(1, 0, 0, 0));
1592 namespace count_equal_and_divisible_pairs_in_an_array {
1593 TEST(count_equal_and_divisible_pairs_in_an_array, case1) {
1594 vector input = {3, 1, 2, 2, 2, 1, 3};
1598 TEST(count_equal_and_divisible_pairs_in_an_array, case2) {
1599 vector input = {1, 2, 3, 4};
1604 namespace find_three_consecutive_integers_that_sum_to_a_given_number {
1605 TEST(find_three_consecutive_integers_that_sum_to_a_given_number, case1) {
1606 const vector<long long> output = {10, 11, 12};
1610 TEST(find_three_consecutive_integers_that_sum_to_a_given_number, case2) {
1611 const vector<long long> output = {};
1616 namespace maximum_split_of_positive_even_integers {
1617 TEST(maximum_split_of_positive_even_integers, case1) {
1618 const vector<long long> output = {2, 4, 6};
1622 TEST(maximum_split_of_positive_even_integers, case2) {
1623 const vector<long long> output = {};
1627 TEST(maximum_split_of_positive_even_integers, case3) {
1628 const vector<long long> output = {2, 4, 6, 16};
1633 namespace count_good_triplets_in_an_array {
1634 TEST(count_good_triplets_in_an_array, case1) {
1635 vector input1 = {2, 0, 1, 3};
1636 vector input2 = {0, 1, 2, 3};
1640 TEST(count_good_triplets_in_an_array, case2) {
1641 vector input1 = {4, 0, 1, 3, 2};
1642 vector input2 = {4, 1, 0, 2, 3};
1647 namespace count_integers_with_even_digit_sum {
1648 TEST(count_integers_with_even_digit_sum, case1) {
1652 TEST(count_integers_with_even_digit_sum, case2) {
1657 namespace construct_string_with_repeat_limit {
1658 TEST(construct_string_with_repeat_limit, case1) {
1662 TEST(construct_string_with_repeat_limit, case2) {
1666 TEST(construct_string_with_repeat_limit, case3) {
1671 namespace count_array_pairs_divisible_by_k {
1672 TEST(count_array_pairs_divisible_by_k, case1) {
1673 vector input = {1, 2, 3, 4, 5};
1677 TEST(count_array_pairs_divisible_by_k, case2) {
1678 vector input = {1, 2, 3, 4};
1682 TEST(count_array_pairs_divisible_by_k, case3) {
1683 vector input = {8, 10, 2, 5, 9, 6, 3, 8, 2};
1688 namespace leetcode717_1_bit_and_2_bit_characters {
1689 TEST(leetcode717_1_bit_and_2_bit_characters, case1) {
1690 vector input = {1, 0, 0};
1694 TEST(leetcode717_1_bit_and_2_bit_characters, case2) {
1695 vector input = {1, 1, 1, 0};
1700 namespace longest_mountain_in_array {
1701 TEST(longest_mountain_in_array, case1) {
1702 vector input = {2, 1, 4, 7, 3, 2, 5};
1706 TEST(longest_mountain_in_array, case2) {
1707 vector input = {2, 2, 2};
1712 namespace push_dominoes {
1722 namespace the_number_of_good_subsets {
1723 TEST(the_number_of_good_subsets, case1) {
1724 vector input = {1, 2, 3, 4};
1728 TEST(the_number_of_good_subsets, case2) {
1729 vector input = {4, 2, 3, 15};
1734 namespace reverse_only_letters {
1735 TEST(reverse_only_letters, case1) {
1739 TEST(reverse_only_letters, case2) {
1743 TEST(reverse_only_letters, case3) {
1748 namespace where_will_the_ball_fall {
1749 TEST(where_will_the_ball_fall, case1) {
1750 vector<vector<int>> input = {{1, 1, 1, -1, -1}, {1, 1, 1, -1, -1}, {-1, -1, -1, 1, 1}, {1, 1, 1, 1, -1}, {-1, -1, -1, -1, -1}};
1751 const vector output = {1, -1, -1, -1, -1};
1755 TEST(where_will_the_ball_fall, case2) {
1756 vector<vector<int>> input = {{-1}};
1757 const vector output = {-1};
1761 TEST(where_will_the_ball_fall, case3) {
1762 vector<vector<int>> input = {{1, 1, 1, 1, 1, 1}, {-1, -1, -1, -1, -1, -1}, {1, 1, 1, 1, 1, 1}, {-1, -1, -1, -1, -1, -1}};
1763 const vector output = {0, 1, 2, 3, 4, -1};
1768 namespace complex_number_multiplication {
1769 TEST(complex_number_multiplication, case1) {
1773 TEST(complex_number_multiplication, case2) {
1778 namespace counting_words_with_a_given_prefix {
1779 TEST(counting_words_with_a_given_prefix, case1) {
1780 vector<string> input = {
"pay",
"attention",
"practice",
"attend"};
1784 TEST(counting_words_with_a_given_prefix, case2) {
1785 vector<string> input = {
"leetcode",
"win",
"loops",
"success"};
1790 namespace minimum_number_of_steps_to_make_two_strings_anagram_ii {
1791 TEST(minimum_number_of_steps_to_make_two_strings_anagram_ii, case1) {
1795 TEST(minimum_number_of_steps_to_make_two_strings_anagram_ii, case2) {
1800 namespace maximum_difference_between_increasing_elements {
1801 TEST(maximum_difference_between_increasing_elements, case1) {
1802 vector input = {7, 1, 5, 4};
1806 TEST(maximum_difference_between_increasing_elements, case2) {
1807 vector input = {9, 4, 3, 2};
1811 TEST(maximum_difference_between_increasing_elements, case3) {
1812 vector input = {1, 5, 2, 10};
1817 namespace optimal_division {
1819 vector input = {1000, 100, 10, 2};
1824 vector input = {2, 3, 4};
1834 namespace minimum_time_to_complete_trips {
1835 TEST(minimum_time_to_complete_trips, case1) {
1836 vector input = {1, 2, 3};
1840 TEST(minimum_time_to_complete_trips, case2) {
1845 TEST(minimum_time_to_complete_trips, case3) {
1846 vector input = {5, 10, 10};
1851 namespace minimum_time_to_finish_the_race {
1852 TEST(minimum_time_to_finish_the_race, case1) {
1853 vector<vector<int>> input = {{2, 3}, {3, 4}};
1857 TEST(minimum_time_to_finish_the_race, case2) {
1858 vector<vector<int>> input = {{1, 10}, {2, 2}, {3, 4}};
1863 namespace maximum_number_of_achievable_transfer_requests {
1864 TEST(maximum_number_of_achievable_transfer_requests, case1) {
1865 vector<vector<int>> input = {{0, 1}, {1, 0}, {0, 1}, {1, 2}, {2, 0}, {3, 4}};
1869 TEST(maximum_number_of_achievable_transfer_requests, case2) {
1870 vector<vector<int>> input = {{0, 0}, {1, 2}, {2, 1}};
1874 TEST(maximum_number_of_achievable_transfer_requests, case3) {
1875 vector<vector<int>> input = {{0, 3}, {3, 1}, {1, 2}, {2, 0}};
1880 namespace zigzag_conversion {
1894 namespace find_the_closest_palindrome {
1895 TEST(find_the_closest_palindrome, case1) {
1899 TEST(find_the_closest_palindrome, case2) {
1903 TEST(find_the_closest_palindrome, case3) {
1907 TEST(find_the_closest_palindrome, case4) {
1911 TEST(find_the_closest_palindrome, case5) {
1915 TEST(find_the_closest_palindrome, case6) {
1919 TEST(find_the_closest_palindrome, case7) {
1923 TEST(find_the_closest_palindrome, case8) {
1927 TEST(find_the_closest_palindrome, case9) {
1932 namespace add_digits {
1942 namespace sum_of_subarray_ranges {
1943 TEST(sum_of_subarray_ranges, case1) {
1944 vector input = {1, 2, 3};
1948 TEST(sum_of_subarray_ranges, case2) {
1949 vector input = {1, 3, 3};
1953 TEST(sum_of_subarray_ranges, case3) {
1954 vector input = {4, -2, -3, 4, 1};
1959 namespace longest_uncommon_subsequence_i {
1960 TEST(longest_uncommon_subsequence_i, case1) {
1964 TEST(longest_uncommon_subsequence_i, case2) {
1968 TEST(longest_uncommon_subsequence_i, case3) {
1973 namespace most_frequent_number_following_key_in_an_array {
1974 TEST(most_frequent_number_following_key_in_an_array, case1) {
1975 vector input = {1, 100, 200, 1, 100};
1979 TEST(most_frequent_number_following_key_in_an_array, case2) {
1980 vector input = {2, 2, 2, 2, 3};
1985 namespace sort_the_jumbled_numbers {
1986 TEST(sort_the_jumbled_numbers, case1) {
1987 vector mapping = {8, 9, 4, 0, 2, 1, 3, 5, 7, 6};
1988 vector nums = {991, 338, 38};
1989 const vector output = {338, 38, 991};
1993 TEST(sort_the_jumbled_numbers, case2) {
1994 vector mapping = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
1995 vector nums = {789, 456, 123};
1996 const vector output = {123, 456, 789};
2001 namespace all_ancestors_of_a_node_in_a_directed_acyclic_graph {
2002 TEST(all_ancestors_of_a_node_in_a_directed_acyclic_graph, case1) {
2003 vector<vector<int>> input = {{0, 3}, {0, 4}, {1, 3}, {2, 4}, {2, 7}, {3, 5}, {3, 6}, {3, 7}, {4, 6}};
2004 const vector<vector<int>> output = {{}, {}, {}, {0, 1}, {0, 2}, {0, 1, 3}, {0, 1, 2, 3, 4}, {0, 1, 2, 3}};
2006 ASSERT_EQ(output, sol.getAncestors(8, input));
2009 TEST(all_ancestors_of_a_node_in_a_directed_acyclic_graph, case2) {
2010 vector<vector<int>> input = {{0, 1}, {0, 2}, {0, 3}, {0, 4}, {1, 2}, {1, 3}, {1, 4}, {2, 3}, {2, 4}, {3, 4}};
2011 const vector<vector<int>> output = {{}, {0}, {0, 1}, {0, 1, 2}, {0, 1, 2, 3}};
2013 ASSERT_EQ(output, sol.getAncestors(5, input));
2017 namespace minimum_number_of_moves_to_make_palindrome {
2018 TEST(minimum_number_of_moves_to_make_palindrome, case1) {
2022 TEST(minimum_number_of_moves_to_make_palindrome, case2) {
2026 TEST(minimum_number_of_moves_to_make_palindrome, case3) {
2031 namespace cells_in_a_range_on_an_excel_sheet {
2032 TEST(cells_in_a_range_on_an_excel_sheet, case1) {
2033 const vector<string> output = {
"K1",
"K2",
"L1",
"L2"};
2037 TEST(cells_in_a_range_on_an_excel_sheet, case2) {
2038 const vector<string> output = {
"A1",
"B1",
"C1",
"D1",
"E1",
"F1"};
2043 namespace append_k_integers_with_minimal_sum {
2044 TEST(append_k_integers_with_minimal_sum, case1) {
2045 vector input = {96, 44, 99, 25, 61, 84, 88, 18, 19, 33, 60, 86, 52, 19, 32, 47, 35, 50, 94, 17, 29, 98, 22, 21, 72, 100, 40, 84};
2049 TEST(append_k_integers_with_minimal_sum, case2) {
2050 vector input = {5, 6};
2054 TEST(append_k_integers_with_minimal_sum, case3) {
2055 vector input = {1, 4, 25, 10, 25};
2059 TEST(append_k_integers_with_minimal_sum, case4) {
2060 vector input = {1, 2};
2064 TEST(append_k_integers_with_minimal_sum, case5) {
2065 vector input = {2, 2, 2, 2};
2070 namespace replace_non_coprime_numbers_in_array {
2071 TEST(replace_non_coprime_numbers_in_array, case1) {
2072 vector input = {6, 4, 3, 2, 7, 6, 2};
2073 const vector output = {12, 7, 6};
2077 TEST(replace_non_coprime_numbers_in_array, case2) {
2078 vector input = {2, 2, 1, 1, 3, 3, 3};
2079 const vector output = {2, 1, 1, 3};
2084 namespace find_good_days_to_rob_the_bank {
2085 TEST(find_good_days_to_rob_the_bank, case1) {
2086 vector input = {5, 3, 3, 3, 5, 6, 2};
2087 const vector output = {2, 3};
2091 TEST(find_good_days_to_rob_the_bank, case2) {
2092 vector input = {1, 1, 1, 1, 1};
2093 const vector output = {0, 1, 2, 3, 4};
2097 TEST(find_good_days_to_rob_the_bank, case3) {
2098 vector input = {1, 2, 3, 4, 5, 6};
2099 const vector<int> output = {};
2103 TEST(find_good_days_to_rob_the_bank, case4) {
2104 vector input = {4, 3, 2, 1};
2105 const vector<int> output = {};
2120 namespace plates_between_candles {
2121 TEST(plates_between_candles, case1) {
2122 vector<vector<int>> input = {{2, 5}, {5, 9}};
2123 const vector output = {2, 3};
2127 TEST(plates_between_candles, case2) {
2128 vector<vector<int>> input = {{1, 17}, {4, 5}, {14, 17}, {5, 11}, {15, 16}};
2129 const vector output = {9, 0, 0, 0, 0};
2134 namespace smallest_rotation_with_highest_score {
2135 TEST(smallest_rotation_with_highest_score, case1) {
2136 vector input = {2, 3, 1, 4, 0};
2140 TEST(smallest_rotation_with_highest_score, case2) {
2141 vector input = {1, 3, 0, 2, 4};
2146 namespace count_nodes_with_the_highest_score {
2147 TEST(count_nodes_with_the_highest_score, case1) {
2148 vector input = {-1, 2, 0, 2, 0};
2152 TEST(count_nodes_with_the_highest_score, case2) {
2153 vector input = {-1, 2, 0};
2158 namespace max_area_of_island {
2160 vector<vector<int>> input = {{0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
2161 {0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0},
2162 {0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0},
2163 {0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0},
2164 {0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0},
2165 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
2166 {0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0},
2167 {0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0}};
2172 vector<vector<int>> input = {{0, 0, 0, 0, 0, 0, 0, 0}};
2177 namespace find_all_k_distant_indices_in_an_array {
2178 TEST(find_all_k_distant_indices_in_an_array, case1) {
2179 vector nums = {3, 4, 9, 1, 3, 9, 5};
2180 const vector output = {1, 2, 3, 4, 5, 6};
2184 TEST(find_all_k_distant_indices_in_an_array, case2) {
2185 vector nums = {2, 2, 2, 2, 2};
2186 const vector output = {0, 1, 2, 3, 4};
2191 namespace count_artifacts_that_can_be_extracted {
2192 TEST(count_artifacts_that_can_be_extracted, case1) {
2193 vector<vector<int>> artifacts = {{0, 0, 0, 0}, {0, 1, 1, 1}};
2194 vector<vector<int>> dig = {{0, 0}, {0, 1}};
2198 TEST(count_artifacts_that_can_be_extracted, case2) {
2199 vector<vector<int>> artifacts = {{0, 0, 0, 0}, {0, 1, 1, 1}};
2200 vector<vector<int>> dig = {{0, 0}, {0, 1}, {1, 1}};
2205 namespace maximize_the_topmost_element_after_k_moves {
2206 TEST(maximize_the_topmost_element_after_k_moves, case1) {
2207 vector nums = {5, 2, 2, 4, 0, 6};
2211 TEST(maximize_the_topmost_element_after_k_moves, case2) {
2217 namespace minimum_weighted_subgraph_with_the_required_paths {
2218 TEST(minimum_weighted_subgraph_with_the_required_paths, case1) {
2219 vector<vector<int>> edges = {{0, 2, 2}, {0, 5, 6}, {1, 0, 3}, {1, 4, 5}, {2, 1, 1}, {2, 3, 3}, {2, 3, 4}, {3, 4, 2}, {4, 5, 1}};
2223 TEST(minimum_weighted_subgraph_with_the_required_paths, case2) {
2224 vector<vector<int>> edges = {{0, 1, 1}, {2, 1, 1}};
2228 TEST(minimum_weighted_subgraph_with_the_required_paths, case3) {
2229 vector<vector<int>> edges = {{4, 2, 20}, {4, 3, 46}, {0, 1, 15}, {0, 1, 43}, {0, 1, 32}, {3, 1, 13}};
2233 TEST(minimum_weighted_subgraph_with_the_required_paths, case4) {
2234 vector<vector<int>> edges = {{31, 64, 44}, {31, 6, 14}, {46, 21, 45}, {46, 65, 27}, {46, 30, 46}, {31, 0, 14}, {31, 29, 40}, {46, 95, 6}, {46, 73, 62}, {31, 74, 16}, {31, 55, 35}, {46, 40, 89}, {46, 57, 93}, {31, 90, 27}, {46, 58, 59}, {46, 12, 80}, {31, 44, 26}, {46, 67, 82}, {31, 8, 64}, {31, 23, 15}, {31, 7, 27}, {31, 94, 33}, {31, 86, 36}, {31, 33, 61}, {46, 88, 46}, {46, 69, 76}, {46, 39, 89}, {46, 53, 17}, {31, 75, 69}, {31, 72, 30}, {46, 83, 87}, {31, 35, 86}, {31, 62, 84}, {46, 51, 47}, {46, 66, 16}, {46, 50, 85}, {46, 81, 65}, {46, 36, 89}, {46, 60, 21}, {46, 10, 76}, {31, 18, 70}, {46, 3, 93}, {31, 47, 52}, {46, 16, 61}, {31, 15, 77}, {46, 28, 3}, {31, 93, 53}, {46, 43, 94}, {31, 38, 25}, {46, 1, 42}, {31, 22, 49}, {46, 45, 55}, {46, 99, 43}, {46, 24, 90}, {31, 9, 28}, {46, 13, 15}, {46, 27, 93}, {46, 49, 83}, {31, 71, 51}, {31, 59, 93}, {31, 91, 98}, {31, 54, 67}, {31, 25, 75}, {31, 68, 24}, {31, 76, 13}, {31, 41, 31}, {31, 19, 36}, {31, 87, 37}, {46, 17, 70}, {46, 97, 46}, {46, 61, 82}, {46, 79, 74}, {46, 85, 18}, {46, 14, 74}, {31, 32, 60}, {46, 84, 69}, {31, 34, 69}, {31, 4, 13}, {46, 70, 27}, {31, 48, 27}, {31, 11, 63}, {46, 5, 14}, {46, 37, 88}, {31, 96, 70}, {46, 52, 17}, {46, 42, 9}, {46, 20, 68}, {31, 77, 79}, {31, 80, 68}, {46, 78, 13}, {46, 26, 48}, {46, 2, 10}, {46, 63, 6}, {31, 89, 66}, {31, 56, 96}, {46, 92, 36}, {46, 98, 12}, {46, 82, 94}, {8, 82, 84}, {92, 82, 23}, {40, 82, 98}, {39, 82, 67}, {86, 82, 37}, {75, 82, 21}};
2239 namespace utf_8_validation {
2241 vector data = {193, 130, 1};
2246 vector data = {235, 140, 4};
2251 vector data = {250, 145, 145, 145, 145};
2256 namespace minimum_index_sum_of_two_lists {
2257 TEST(minimum_index_sum_of_two_lists, case1) {
2258 vector<string> list1 = {
"Shogun",
"Tapioca Express",
"Burger King",
"KFC"};
2259 vector<string> list2 = {
"Piatti",
"The Grill at Torrey Pines",
"Hungry Hunter Steakhouse",
"Shogun"};
2260 const vector<string> output = {
"Shogun"};
2264 TEST(minimum_index_sum_of_two_lists, case2) {
2265 vector<string> list1 = {
"Shogun",
"Tapioca Express",
"Burger King",
"KFC"};
2266 vector<string> list2 = {
"KFC",
"Shogun",
"Burger King"};
2267 const vector<string> output = {
"Shogun"};
2272 namespace count_number_of_maximum_bitwise_or_subsets {
2273 TEST(count_number_of_maximum_bitwise_or_subsets, case1) {
2274 vector nums = {3, 1};
2278 TEST(count_number_of_maximum_bitwise_or_subsets, case2) {
2279 vector nums = {2, 2, 2};
2283 TEST(count_number_of_maximum_bitwise_or_subsets, case3) {
2284 vector nums = {3, 2, 1, 5};
2289 namespace all_oone_data_structure {
2290 TEST(all_oone_data_structure, case1) {
2307 namespace longest_word_in_dictionary {
2308 TEST(longest_word_in_dictionary, case1) {
2309 vector<string> words = {
"w",
"wo",
"wor",
"worl",
"world"};
2310 const string output =
"world";
2314 TEST(longest_word_in_dictionary, case2) {
2315 vector<string> words = {
"a",
"banana",
"app",
"appl",
"ap",
"apply",
"apple"};
2316 const string output =
"apple";
2321 namespace maximize_number_of_subsequences_in_a_string {
2322 TEST(maximize_number_of_subsequences_in_a_string, case1) {
2326 TEST(maximize_number_of_subsequences_in_a_string, case2) {
2331 namespace minimum_operations_to_halve_array_sum {
2332 TEST(minimum_operations_to_halve_array_sum, case1) {
2333 vector nums = {5, 19, 8, 1};
2337 TEST(minimum_operations_to_halve_array_sum, case2) {
2338 vector nums = {3, 8, 20};
2343 namespace minimum_white_tiles_after_covering_with_carpets {
2344 TEST(minimum_white_tiles_after_covering_with_carpets, case1) {
2348 TEST(minimum_white_tiles_after_covering_with_carpets, case2) {
2352 TEST(minimum_white_tiles_after_covering_with_carpets, case3) {
2357 namespace count_hills_and_valleys_in_an_array {
2358 TEST(count_hills_and_valleys_in_an_array, case1) {
2359 vector num = {2, 4, 1, 1, 6, 5};
2363 TEST(count_hills_and_valleys_in_an_array, case2) {
2364 vector num = {6, 6, 5, 5, 4, 1};
2369 namespace count_collisions_on_a_road {
2370 TEST(count_collisions_on_a_road, case1) {
2374 TEST(count_collisions_on_a_road, case2) {
2379 namespace maximum_points_in_an_archery_competition {
2380 TEST(maximum_points_in_an_archery_competition, case1) {
2381 vector aliceArrows = {1, 1, 0, 1, 0, 0, 2, 1, 0, 1, 2, 0};
2382 const vector output = {0, 0, 0, 0, 1, 1, 0, 0, 1, 2, 3, 1};
2386 TEST(maximum_points_in_an_archery_competition, case2) {
2387 vector aliceArrows = {0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 2};
2388 const vector output = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0};
2393 namespace the_time_when_the_network_becomes_idle {
2394 TEST(the_time_when_the_network_becomes_idle, case1) {
2395 vector<vector<int>> edges = {{0, 1}, {1, 2}};
2396 vector patience = {0, 2, 1};
2400 TEST(the_time_when_the_network_becomes_idle, case2) {
2401 vector<vector<int>> edges = {{0, 1}, {0, 2}, {1, 2}};
2402 vector patience = {0, 10, 10};
2407 namespace remove_colored_pieces_if_both_neighbors_are_the_same_color {
2408 TEST(remove_colored_pieces_if_both_neighbors_are_the_same_color, case1) {
2412 TEST(remove_colored_pieces_if_both_neighbors_are_the_same_color, case2) {
2416 TEST(remove_colored_pieces_if_both_neighbors_are_the_same_color, case3) {
2421 namespace k_th_smallest_in_lexicographical_order {
2422 TEST(k_th_smallest_in_lexicographical_order, case1) {
2426 TEST(k_th_smallest_in_lexicographical_order, case2) {
2431 namespace image_smoother {
2433 vector<vector<int>> img = {{1, 1, 1}, {1, 0, 1}, {1, 1, 1}};
2434 const vector<vector<int>> output = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}};
2439 vector<vector<int>> img = {{100, 200, 100}, {200, 50, 200}, {100, 200, 100}};
2440 const vector<vector<int>> output = {{137, 141, 137}, {141, 138, 141}, {137, 141, 137}};
2445 namespace factorial_trailing_zeroes {
2446 TEST(factorial_trailing_zeroes, case1) {
2450 TEST(factorial_trailing_zeroes, case2) {
2454 TEST(factorial_trailing_zeroes, case3) {
2459 namespace baseball_game {
2461 vector<string> ops = {
"5",
"2",
"C",
"D",
"+"};
2466 vector<string> ops = {
"5",
"-2",
"4",
"C",
"D",
"9",
"+",
"+"};
2471 vector<string> ops = {
"1"};
2476 namespace find_palindrome_with_fixed_length {
2477 TEST(find_palindrome_with_fixed_length, case1) {
2478 vector queries = {1, 2, 3, 4, 5, 90};
2479 const vector<long long> output = {101, 111, 121, 131, 141, 999};
2483 TEST(find_palindrome_with_fixed_length, case2) {
2484 vector queries = {2, 4, 6};
2485 const vector<long long> output = {1111, 1331, 1551};
2489 TEST(find_palindrome_with_fixed_length, case4) {
2490 vector queries = {10};
2491 const vector<long long> output = {191};
2495 TEST(find_palindrome_with_fixed_length, case5) {
2496 vector queries = {9};
2497 const vector<long long> output = {10801};
2501 TEST(find_palindrome_with_fixed_length, case7) {
2502 vector queries = {60};
2503 const vector<long long> output = {15951};
2508 namespace find_missing_observations {
2509 TEST(find_missing_observations, case1) {
2510 vector rolls = {3, 2, 4, 3};
2511 const vector output = {6, 6};
2515 TEST(find_missing_observations, case3) {
2516 vector rolls = {1, 2, 3, 4};
2517 const vector<int> output = {};
2522 namespace binary_number_with_alternating_bits {
2523 TEST(binary_number_with_alternating_bits, case1) {
2527 TEST(binary_number_with_alternating_bits, case2) {
2531 TEST(binary_number_with_alternating_bits, case3) {
2536 namespace maximize_the_confusion_of_an_exam {
2537 TEST(maximize_the_confusion_of_an_exam, case1) {
2541 TEST(maximize_the_confusion_of_an_exam, case2) {
2545 TEST(maximize_the_confusion_of_an_exam, case3) {
2549 TEST(maximize_the_confusion_of_an_exam, case4) {
2554 namespace find_servers_that_handled_most_number_of_requests {
2555 TEST(find_servers_that_handled_most_number_of_requests, case1) {
2556 vector arrival = {1, 2, 3, 4, 5};
2557 vector load = {5, 2, 3, 3, 3};
2558 const vector output = {1};
2562 TEST(find_servers_that_handled_most_number_of_requests, case2) {
2563 vector arrival = {1, 2, 3, 4};
2564 vector load = {1, 2, 1, 2};
2565 const vector output = {0};
2569 TEST(find_servers_that_handled_most_number_of_requests, case3) {
2570 vector arrival = {1, 2, 3};
2571 vector load = {10, 12, 11};
2572 const vector output = {0, 1, 2};
2576 TEST(find_servers_that_handled_most_number_of_requests, case4) {
2577 vector arrival = {1, 2, 3};
2578 vector load = {1000000000, 1, 1000000000};
2579 const vector output = {1};
2584 namespace self_dividing_numbers {
2585 TEST(self_dividing_numbers, case1) {
2586 const vector output = {1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 22};
2590 TEST(self_dividing_numbers, case2) {
2591 const vector output = {48, 55, 66, 77};
2596 namespace array_of_doubled_pairs {
2597 TEST(array_of_doubled_pairs, case1) {
2598 vector arr = {3, 1, 3, 6};
2602 TEST(array_of_doubled_pairs, case2) {
2603 vector arr = {2, 1, 2, 6};
2608 namespace strong_password_checker {
2609 TEST(strong_password_checker, case1) {
2613 TEST(strong_password_checker, case2) {
2617 TEST(strong_password_checker, case3) {
2621 TEST(strong_password_checker, case4) {
2625 TEST(strong_password_checker, case5) {
2630 namespace sum_of_scores_of_built_strings {
2631 TEST(sum_of_scores_of_built_strings, case1) {
2635 TEST(sum_of_scores_of_built_strings, case2) {
2640 namespace minimum_number_of_operations_to_convert_time {
2641 TEST(minimum_number_of_operations_to_convert_time, case1) {
2645 TEST(minimum_number_of_operations_to_convert_time, case2) {
2649 TEST(minimum_number_of_operations_to_convert_time, case3) {
2654 namespace find_players_with_zero_or_one_losses {
2655 TEST(find_players_with_zero_or_one_losses, case1) {
2656 vector<vector<int>> matches = {{1, 3},
2666 const vector<vector<int>> output = {{1, 2, 10}, {4, 5, 7, 8}};
2670 TEST(find_players_with_zero_or_one_losses, case2) {
2671 vector<vector<int>> matches = {{2, 3}, {1, 3}, {5, 4}, {6, 4}};
2672 const vector<vector<int>> output = {{1, 2, 5, 6}, {}};
2677 namespace maximum_candies_allocated_to_k_children {
2678 TEST(maximum_candies_allocated_to_k_children, case1) {
2679 vector candies = {5, 8, 6};
2683 TEST(maximum_candies_allocated_to_k_children, case2) {
2684 vector candies = {2, 5};
2688 TEST(maximum_candies_allocated_to_k_children, case3) {
2689 vector candies = {1, 2, 3, 4, 10};
2693 TEST(maximum_candies_allocated_to_k_children, case4) {
2694 vector candies = {123, 13300, 1000, 23, 11, 41, 311};
2699 namespace encrypt_and_decrypt_strings {
2700 TEST(encrypt_and_decrypt_strings, case1) {
2701 vector keys = {
'a',
'b',
'c',
'd'};
2702 vector<string> values = {
"ei",
"zf",
"ei",
"am"};
2703 vector<string> dictionary = {
"abcd",
"acbd",
"adbc",
"badc",
"dacb",
"cadb",
"cbda",
"abad"};
2704 auto enc =
Encrypter(keys, values, dictionary);
2705 ASSERT_EQ(
"eizfeiam", enc.encrypt(
"abcd"));
2706 ASSERT_EQ(2, enc.decrypt(
"eizfeiam"));
2710 namespace process_restricted_friend_requests {
2711 TEST(process_restricted_friend_requests, case1) {
2712 vector<vector<int>> restrictions = {{0, 1}};
2713 vector<vector<int>> requests = {{0, 2}, {2, 1}};
2714 const vector output = {
true,
false};
2718 TEST(process_restricted_friend_requests, case2) {
2719 vector<vector<int>> restrictions = {{0, 1}};
2720 vector<vector<int>> requests = {{1, 2}, {0, 2}};
2721 const vector output = {
true,
false};
2726 namespace prime_number_of_set_bits_in_binary_representation {
2727 TEST(prime_number_of_set_bits_in_binary_representation, case1) {
2731 TEST(prime_number_of_set_bits_in_binary_representation, case2) {
2736 namespace minimum_height_trees {
2737 TEST(minimum_height_trees, case1) {
2738 vector<vector<int>> edges = {{1, 0}, {1, 2}, {1, 3}};
2739 const vector output = {1};
2741 ASSERT_EQ(output, sol.findMinHeightTrees(4, edges));
2744 TEST(minimum_height_trees, case2) {
2745 vector<vector<int>> edges = {{3, 0}, {3, 1}, {3, 2}, {3, 4}, {5, 4}};
2746 const vector output = {3, 4};
2748 ASSERT_EQ(output, sol.findMinHeightTrees(6, edges));
2752 namespace rotate_string {
2762 namespace reaching_points {
2776 namespace maximum_product_after_k_increments {
2777 TEST(maximum_product_after_k_increments, case1) {
2778 vector nums = {0, 4};
2782 TEST(maximum_product_after_k_increments, case2) {
2783 vector nums = {6, 3, 3, 2};
2788 namespace maximum_total_beauty_of_the_gardens {
2789 TEST(maximum_total_beauty_of_the_gardens, case1) {
2790 vector flowers = {1, 3, 1, 1};
2794 TEST(maximum_total_beauty_of_the_gardens, case2) {
2795 vector flowers = {2, 4, 5, 3};
2799 TEST(maximum_total_beauty_of_the_gardens, case3) {
2800 vector flowers = {19, 17, 6, 9, 19};
2805 namespace count_numbers_with_unique_digits {
2806 TEST(count_numbers_with_unique_digits, case1) {
2810 TEST(count_numbers_with_unique_digits, case2) {
2815 namespace number_of_lines_to_write_string {
2816 TEST(number_of_lines_to_write_string, case1) {
2817 vector width = {10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10};
2818 const vector output = {3, 60};
2822 TEST(number_of_lines_to_write_string, case2) {
2823 vector width = {4, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10};
2824 const vector output = {2, 4};
2829 namespace permutation_in_string {
2830 TEST(permutation_in_string, case1) {
2834 TEST(permutation_in_string, case2) {
2838 TEST(permutation_in_string, case3) {
2843 namespace projection_area_of_3d_shapes {
2844 TEST(projection_area_of_3d_shapes, case1) {
2845 vector<vector<int>> grid = {{1, 2}, {3, 4}};
2849 TEST(projection_area_of_3d_shapes, case2) {
2850 vector<vector<int>> grid = {{2}};
2854 TEST(projection_area_of_3d_shapes, case3) {
2855 vector<vector<int>> grid = {{1, 0}, {0, 2}};
2860 namespace house_robber {
2862 vector nums = {1, 2, 3, 1};
2867 vector nums = {2, 7, 9, 3, 1};
2872 namespace triangle {
2874 vector<vector<int>> triangle = {{2}, {3, 4}, {6, 5, 7}, {4, 1, 8, 3}};
2879 vector<vector<int>> triangle = {{-10}};
2884 namespace lowest_common_ancestor_of_a_binary_search_tree {
2885 TEST(lowest_common_ancestor_of_a_binary_search_tree, case1) {
2900 namespace find_all_anagrams_in_a_string {
2901 TEST(find_all_anagrams_in_a_string, case1) {
2902 const string s =
"cbaebabacd";
2903 const string p =
"abc";
2904 const vector expected = {0, 6};
2908 TEST(find_all_anagrams_in_a_string, case2) {
2909 const string s =
"abab";
2910 const string p =
"ab";
2911 const vector expected = {0, 1, 2};
2916 namespace subarray_product_less_than_k {
2917 TEST(subarray_product_less_than_k, case1) {
2918 vector nums = {10, 5, 2, 6};
2923 TEST(subarray_product_less_than_k, case2) {
2924 vector nums = {1, 2, 3};
2930 namespace minimum_size_subarray_sum {
2931 TEST(minimum_size_subarray_sum, case1) {
2932 vector nums = {2, 3, 1, 2, 4, 3};
2933 const int target = 7;
2937 TEST(minimum_size_subarray_sum, case2) {
2938 vector nums = {1, 4, 4};
2939 const int target = 4;
2943 TEST(minimum_size_subarray_sum, case3) {
2944 vector nums = {1, 1, 1, 1, 1, 1, 1, 1};
2945 const int target = 11;
2949 TEST(minimum_size_subarray_sum, case4) {
2950 vector nums = {5, 1, 3, 5, 10, 7, 4, 9, 2, 8};
2951 const int target = 15;
2955 TEST(minimum_size_subarray_sum, case5) {
2956 vector nums = {10, 5, 13, 4, 8, 4, 5, 11, 14, 9, 16, 10, 20, 8};
2957 const int target = 80;
2962 namespace house_robber_ii {
2964 vector nums = {2, 3, 2};
2969 vector nums = {1, 2, 3, 1};
2974 vector nums = {1, 2, 3};
2979 namespace jump_game {
2981 vector nums = {2, 3, 1, 1, 4};
2986 vector nums = {3, 2, 1, 0, 4};
2991 namespace jump_game_ii {
2993 vector nums = {2, 3, 1, 1, 4};
2998 vector nums = {2, 3, 0, 1, 4};
3003 namespace unique_paths {
3013 namespace longest_palindromic_substring {
3014 TEST(longest_palindromic_substring, case1) {
3018 TEST(longest_palindromic_substring, case2) {
3022 TEST(longest_palindromic_substring, case3) {
3026 TEST(longest_palindromic_substring, case4) {
3030 TEST(longest_palindromic_substring, case5) {
3034 TEST(longest_palindromic_substring, case6) {
3039 namespace arithmetic_slices {
3041 vector nums = {1, 2, 3, 4};
3051 namespace decode_ways {
3069 namespace word_break {
3071 vector<string> wordDict = {
"leet",
"code"};
3072 const string s =
"leetcode";
3077 vector<string> wordDict = {
"apple",
"pen"};
3078 const string s =
"applepenapple";
3083 vector<string> wordDict = {
"cats",
"dog",
"sand",
"and",
"cat"};
3084 const string s =
"catsandog";
3089 namespace longest_increasing_subsequence {
3090 TEST(longest_increasing_subsequence, case1) {
3091 vector nums = {10, 9, 2, 5, 3, 7, 101, 18};
3095 TEST(longest_increasing_subsequence, case2) {
3096 vector nums = {0, 1, 0, 3, 2, 3};
3100 TEST(longest_increasing_subsequence, case3) {
3101 vector nums = {7, 7, 7, 7, 7, 7, 7};
3106 namespace number_of_longest_increasing_subsequence {
3107 TEST(number_of_longest_increasing_subsequence, case1) {
3108 vector nums = {1, 3, 5, 4, 7};
3112 TEST(number_of_longest_increasing_subsequence, case2) {
3113 vector nums = {2, 2, 2, 2, 2};
3118 namespace longest_common_subsequence {
3119 TEST(longest_common_subsequence, case1) {
3120 const string text1 =
"abcde";
3121 const string text2 =
"ace";
3125 TEST(longest_common_subsequence, case2) {
3126 const string text1 =
"abc";
3127 const string text2 =
"abc";
3131 TEST(longest_common_subsequence, case3) {
3132 const string text1 =
"abc";
3133 const string text2 =
"def";
3137 TEST(longest_common_subsequence, case4) {
3138 const string text1 =
"abcde";
3139 const string text2 =
"akccle";
3144 namespace delete_operation_for_two_strings {
3145 TEST(delete_operation_for_two_strings, case1) {
3146 const string s1 =
"sea";
3147 const string s2 =
"eat";
3151 TEST(delete_operation_for_two_strings, case2) {
3152 const string s1 =
"leetcode";
3153 const string s2 =
"etco";
3158 namespace edit_distance {
3160 const string word1 =
"horse";
3161 const string word2 =
"ros";
3166 const string word1 =
"intention";
3167 const string word2 =
"execution";
3172 namespace coin_change {
3174 vector coins = {1, 2, 5};
3175 const int amount = 11;
3181 const int amount = 3;
3187 const int amount = 0;
3192 vector coins = {186, 419, 83, 408};
3193 const int amount = 6249;
3199 const int amount = 3;
3204 namespace integer_break {
3216 namespace max_points_on_a_line {
3217 TEST(max_points_on_a_line, case1) {
3218 vector<vector<int>> points = {{1, 1}, {2, 2}, {3, 3}};
3222 TEST(max_points_on_a_line, case2) {
3223 vector<vector<int>> points = {{1, 1}, {3, 2}, {5, 3}, {4, 1}, {2, 3}, {1, 4}};
3228 namespace sort_colors {
3230 vector nums = {2, 0, 2, 1, 1, 0};
3232 const vector expected = {0, 0, 1, 1, 2, 2};
3233 ASSERT_EQ(expected, nums);
3237 vector nums = {2, 0, 1};
3239 const vector expected = {0, 1, 2};
3240 ASSERT_EQ(expected, nums);
3244 namespace kth_largest_element_in_an_array {
3245 TEST(kth_largest_element_in_an_array, case1) {
3246 vector nums = {3, 2, 1, 5, 6, 4};
3250 TEST(kth_largest_element_in_an_array, case2) {
3251 vector nums = {3, 2, 3, 1, 2, 4, 5, 5, 6};
3256 namespace merge_intervals {
3258 vector<vector<int>> intervals = {{1, 3}, {2, 6}, {8, 10}, {15, 18}};
3259 const vector<vector<int>> expected = {{1, 6}, {8, 10}, {15, 18}};
3264 vector<vector<int>> intervals = {{1, 4}, {4, 5}};
3265 const vector<vector<int>> expected = {{1, 5}};
3271 namespace search_a_2d_matrix_ii {
3272 TEST(search_a_2d_matrix_ii, case1) {
3273 vector<vector<int>> matrix = {{1, 4, 7, 11, 15}, {2, 5, 8, 12, 19}, {3, 6, 9, 16, 22}, {10, 13, 14, 17, 24}, {18, 21, 23, 26, 30}};
3277 TEST(search_a_2d_matrix_ii, case3) {
3278 vector<vector<int>> matrix = {{1, 1}};
3283 namespace serialize_and_deserialize_binary_tree {
3284 TEST(serialize_and_deserialize_binary_tree, case1) {
3285 const auto c =
Codec();
3286 const string serialized =
"[1,2,3,null,null,4,5]";
3288 ASSERT_EQ(serialized, c.serialize(
root));
3291 TEST(serialize_and_deserialize_binary_tree, case2) {
3292 const auto c =
Codec();
3293 const string serialized =
"[]";
3295 ASSERT_EQ(serialized, c.serialize(
root));
3298 TEST(serialize_and_deserialize_binary_tree, case3) {
3299 const auto c =
Codec();
3300 const string serialized =
"[1,null,2,3]";
3302 ASSERT_EQ(serialized, c.serialize(
root));
3305 TEST(serialize_and_deserialize_binary_tree, case4) {
3306 const auto c =
Codec();
3307 const string serialized =
"[1,2,3]";
3309 ASSERT_EQ(serialized, c.serialize(
root));
3312 TEST(serialize_and_deserialize_binary_tree, case5) {
3313 const auto c =
Codec();
3314 const string serialized =
"[5,4,7,3,null,2,null,-1,null,9]";
3316 ASSERT_EQ(serialized, c.serialize(
root));
3320 namespace task_scheduler {
3322 vector tasks = {
'A',
'A',
'A',
'B',
'B',
'B'};
3327 vector tasks = {
'A',
'A',
'A',
'B',
'B',
'B'};
3332 vector tasks = {
'A',
'A',
'A',
'A',
'A',
'A',
'B',
'C',
'D',
'E',
'F',
'G'};
3337 vector tasks = {
'A',
'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
'K',
'L',
'M',
'N',
'O',
'P',
'Q',
'R',
'S',
'T',
'U',
'V',
'W',
'X',
'Y',
'Z'};
3342 vector tasks = {
'A',
'B',
'C',
'A'};
3347 namespace spiral_matrix_ii {
3349 const vector<vector<int>> ans = {{1, 2, 3}, {8, 9, 4}, {7, 6, 5}};
3354 const vector<vector<int>> ans = {{1}};
3359 namespace non_overlapping_intervals {
3360 TEST(non_overlapping_intervals, case1) {
3361 vector<vector<int>> intervals = {{1, 2}, {2, 3}, {3, 4}, {1, 3}};
3365 TEST(non_overlapping_intervals, case2) {
3366 vector<vector<int>> intervals = {{1, 2}, {1, 2}, {1, 2}};
3370 TEST(non_overlapping_intervals, case3) {
3371 vector<vector<int>> intervals = {{1, 2}, {2, 3}};
3375 TEST(non_overlapping_intervals, case4) {
3376 vector<vector<int>> intervals = {{-52, 31}, {-73, -26}, {82, 97}, {-65, -11}, {-62, -49}, {95, 99}, {58, 95}, {-31, 49}, {66, 98}, {-63, 2}, {30, 47}, {-40, -26}};
3380 TEST(non_overlapping_intervals, case5) {
3381 vector<vector<int>> intervals = {{-25322, -4602}, {-35630, -28832}, {-33802, 29009}, {13393, 24550}, {-10655, 16361}, {-2835, 10053}, {-2290, 17156}, {1236, 14847}, {-45022, -1296}, {-34574, -1993}, {-14129, 15626}, {3010, 14502}, {42403, 45946}, {-22117, 13380}, {7337, 33635}, {-38153, 27794}, {47640, 49108}, {40578, 46264}, {-38497, -13790}, {-7530, 4977}, {-29009, 43543}, {-49069, 32526}, {21409, 43622}, {-28569, 16493}, {-28301, 34058}};
3386 namespace product_of_array_except_self {
3387 TEST(product_of_array_except_self, case1) {
3388 vector nums = {1, 2, 3, 4};
3389 const vector output = {24, 12, 8, 6};
3393 TEST(product_of_array_except_self, case2) {
3394 vector nums = {-1, 1, 0, -3, 3};
3395 const vector output = {0, 0, 9, 0, 0};
3400 namespace subarray_sum_equals_k {
3401 TEST(subarray_sum_equals_k, case1) {
3402 vector nums = {1, 1, 1};
3406 TEST(subarray_sum_equals_k, case2) {
3407 vector nums = {1, 2, 3};
3411 TEST(subarray_sum_equals_k, case3) {
3416 TEST(subarray_sum_equals_k, case4) {
3417 vector nums = {-1, -1, 1};
3421 TEST(subarray_sum_equals_k, case5) {
3422 vector nums = {-1, -1, 1};
3427 namespace partition_labels {
3429 const vector output = {9, 7, 8};
3434 const vector output = {10};
3439 namespace design_linked_list {
3445 ASSERT_EQ(2, mll.
get(1));
3447 ASSERT_EQ(3, mll.
get(1));
3451 namespace delete_node_in_a_bst {
3453 if(tn1 ==
nullptr != (tn2 ==
nullptr)) {
3456 if(tn1 !=
nullptr && tn2 !=
nullptr) {
3457 if(tn1->
val != tn2->
val) {
3470 TEST(delete_node_in_a_bst, case1) {
3475 ASSERT_TRUE(
equal(output, sol.deleteNode(
root, 3)));
3478 TEST(delete_node_in_a_bst, case2) {
3483 ASSERT_TRUE(
equal(output, sol.deleteNode(
root, 0)));
3486 TEST(delete_node_in_a_bst, case3) {
3491 ASSERT_TRUE(
equal(output, sol.deleteNode(
root, 0)));
3494 TEST(delete_node_in_a_bst, case4) {
3496 TreeNode *
root =
serialize_and_deserialize_binary_tree::Codec::deserialize(
"[3,2,5,null,null,4,10,null,null,8,15,7]");
3497 TreeNode *output =
serialize_and_deserialize_binary_tree::Codec::deserialize(
"[3,2,7,null,null,4,10,null,null,8,15]");
3499 ASSERT_TRUE(
equal(output, sol.deleteNode(
root, 5)));
3503 namespace missing_element_in_sorted_array {
3504 TEST(missing_element_in_sorted_array, case1) {
3505 vector nums = {4, 7, 9, 10};
3509 TEST(missing_element_in_sorted_array, case2) {
3510 vector nums = {4, 7, 9, 10};
3514 TEST(missing_element_in_sorted_array, case3) {
3515 vector nums = {1, 2, 4};
3520 namespace find_a_peak_element_ii {
3521 TEST(find_a_peak_element_ii, case1) {
3522 vector<vector<int>> mat = {{1, 4}, {3, 2}};
3523 const vector ans = {0, 1};
3527 TEST(find_a_peak_element_ii, case2) {
3528 vector<vector<int>> mat = {{10, 20, 15}, {21, 30, 14}, {7, 16, 32}};
3529 const vector ans = {2, 2};
3534 namespace divide_chocolate {
3536 vector sweetness = {1, 2, 3, 4, 5, 6, 7, 8, 9};
3541 vector sweetness = {5, 6, 7, 8, 9, 1, 2, 3, 4};
3546 vector sweetness = {1, 2, 2, 1, 2, 2, 1, 2, 2};
3551 namespace shortest_distance_to_target_color {
3552 TEST(shortest_distance_to_target_color, case1) {
3553 vector colors = {1, 1, 2, 1, 3, 2, 2, 3, 3};
3554 vector<vector<int>> queries = {{1, 3}, {2, 2}, {6, 1}};
3555 const vector ans = {3, 0, 3};
3559 TEST(shortest_distance_to_target_color, case2) {
3560 vector colors = {1, 2};
3561 vector<vector<int>> queries = {{0, 3}};
3562 const vector ans = {-1};
3567 namespace meeting_scheduler {
3569 vector<vector<int>> slots1 = {{10, 50}, {60, 120}, {140, 210}};
3570 vector<vector<int>> slots2 = {{0, 15}, {60, 70}};
3571 const vector ans = {60, 68};
3576 vector<vector<int>> slots1 = {{10, 50}, {60, 120}, {140, 210}};
3577 vector<vector<int>> slots2 = {{0, 15}, {60, 70}};
3578 const vector<int> ans = {};
3583 vector<vector<int>> slots1 = {{10, 60}};
3584 vector<vector<int>> slots2 = {{12, 17}, {21, 50}};
3585 const vector ans = {21, 29};
3590 namespace find_the_duplicate_number {
3591 TEST(find_the_duplicate_number, case1) {
3592 vector nums = {1, 3, 4, 2, 2};
3596 TEST(find_the_duplicate_number, case2) {
3597 vector nums = {3, 1, 3, 4, 2};
3601 TEST(find_the_duplicate_number, case3) {
3602 vector nums = {1, 4, 4, 2, 4};
3607 namespace trapping_rain_water {
3609 vector height = {0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1};
3614 vector height = {4, 2, 0, 3, 2, 5};
3619 namespace product_of_two_run_length_encoded_arrays {
3620 TEST(product_of_two_run_length_encoded_arrays, case1) {
3621 vector<vector<int>> encoded1 = {{1, 3}, {2, 3}};
3622 vector<vector<int>> encoded2 = {{6, 3}, {3, 3}};
3623 const vector<vector<int>> output = {{6, 6}};
3627 TEST(product_of_two_run_length_encoded_arrays, case2) {
3628 vector<vector<int>> encoded1 = {{1, 3}, {2, 1}, {3, 2}};
3629 vector<vector<int>> encoded2 = {{2, 3}, {3, 3}};
3630 const vector<vector<int>> output = {{2, 3}, {6, 1}, {9, 2}};
3635 namespace longest_substring_with_at_most_two_distinct_characters {
3636 TEST(longest_substring_with_at_most_two_distinct_characters, case1) {
3640 TEST(longest_substring_with_at_most_two_distinct_characters, case2) {
3645 namespace longest_substring_with_at_most_k_distinct_characters {
3646 TEST(longest_substring_with_at_most_k_distinct_characters, case1) {
3650 TEST(longest_substring_with_at_most_k_distinct_characters, case2) {
3655 namespace max_consecutive_ones_iii {
3656 TEST(max_consecutive_ones_iii, case1) {
3657 vector nums = {1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0};
3661 TEST(max_consecutive_ones_iii, case2) {
3662 vector nums = {0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1};
3667 namespace sliding_window_maximum {
3668 TEST(sliding_window_maximum, case1) {
3669 vector nums = {1, 3, -1, -3, 5, 3, 6, 7};
3670 const vector ans = {3, 3, 5, 5, 6, 7};
3674 TEST(sliding_window_maximum, case2) {
3676 const vector ans = {1};
3681 namespace minimum_window_substring {
3682 TEST(minimum_window_substring, case1) {
3686 TEST(minimum_window_substring, case2) {
3690 TEST(minimum_window_substring, case3) {
3695 namespace walls_and_gates {
3697 vector<vector<int>> rooms = {{2147483647, -1, 0, 2147483647}, {2147483647, 2147483647, 2147483647, -1}, {2147483647, -1, 2147483647, -1}, {0, -1, 2147483647, 2147483647}};
3698 const vector<vector<int>> ans = {{3, -1, 0, 1}, {2, 2, 1, -1}, {1, -1, 2, -1}, {0, -1, 3, 4}};
3700 ASSERT_EQ(ans, rooms);
3704 vector<vector<int>> rooms = {{2147483647}};
3705 const vector<vector<int>> ans = {{2147483647}};
3707 ASSERT_EQ(ans, rooms);
3711 vector<vector<int>> rooms = {{0}};
3712 const vector<vector<int>> ans = {{0}};
3714 ASSERT_EQ(ans, rooms);
3718 namespace pacific_atlantic_waterflow {
3719 TEST(pacific_atlantic_waterflow, case1) {
3720 vector<vector<int>> heights = {{1, 2, 2, 3, 5}, {3, 2, 3, 4, 4}, {2, 4, 5, 3, 1}, {6, 7, 1, 4, 5}, {5, 1, 1, 2, 4}};
3721 const vector<vector<int>> ans = {{0, 4}, {1, 3}, {1, 4}, {2, 2}, {3, 0}, {3, 1}, {4, 0}};
3725 TEST(pacific_atlantic_waterflow, case2) {
3726 vector<vector<int>> heights = {{2, 1}, {1, 2}};
3727 const vector<vector<int>> ans = {{0, 0}, {0, 1}, {1, 0}, {1, 1}};
3732 namespace kill_process {
3734 vector pid = {1, 3, 10, 5};
3735 vector ppid = {3, 0, 5, 3};
3736 const vector ans = {5, 10};
3743 const vector ans = {1};
3748 namespace open_the_lock {
3750 vector<string> deadends = {
"0201",
"0101",
"0102",
"1212",
"2002"};
3755 vector<string> deadends = {
"8888"};
3760 vector<string> deadends = {
"8887",
"8889",
"8878",
"8898",
"8788",
"8988",
"7888",
"9888"};
3765 namespace number_of_operations_to_make_network_connected {
3766 TEST(number_of_operations_to_make_network_connected, case1) {
3767 vector<vector<int>> connections = {{0, 1}, {0, 2}, {1, 2}};
3771 TEST(number_of_operations_to_make_network_connected, case2) {
3772 vector<vector<int>> connections = {{0, 1}, {0, 2}, {0, 3}, {1, 2}, {1, 3}};
3776 TEST(number_of_operations_to_make_network_connected, case3) {
3777 vector<vector<int>> connections = {{0, 1}, {0, 2}, {0, 3}, {1, 2}};
3781 TEST(number_of_operations_to_make_network_connected, case4) {
3782 vector<vector<int>> connections = {{0, 1}, {0, 2}, {3, 4}, {2, 3}};
3787 namespace minimum_cost_to_make_at_least_one_valid_path_in_a_grid {
3788 TEST(minimum_cost_to_make_at_least_one_valid_path_in_a_grid, case1) {
3789 vector<vector<int>> grid = {{1, 1, 1, 1}, {2, 2, 2, 2}, {1, 1, 1, 1}, {2, 2, 2, 2}};
3793 TEST(minimum_cost_to_make_at_least_one_valid_path_in_a_grid, case2) {
3794 vector<vector<int>> grid = {{1, 1, 3}, {3, 2, 2}, {1, 1, 4}};
3798 TEST(minimum_cost_to_make_at_least_one_valid_path_in_a_grid, case3) {
3799 vector<vector<int>> grid = {{1, 2}, {4, 3}};
3803 TEST(minimum_cost_to_make_at_least_one_valid_path_in_a_grid, case4) {
3804 vector<vector<int>> grid = {{2, 2, 2}, {2, 2, 2}};
3808 TEST(minimum_cost_to_make_at_least_one_valid_path_in_a_grid, case5) {
3809 vector<vector<int>> grid = {{4}};
3814 namespace critical_connections_in_a_network {
3815 TEST(critical_connections_in_a_network, case1) {
3816 vector<vector<int>> connections = {{0, 1}, {1, 2}, {2, 0}, {1, 3}};
3817 const vector<vector<int>> ans = {{1, 3}};
3821 TEST(critical_connections_in_a_network, case2) {
3822 vector<vector<int>> connections = {{0, 1}};
3823 const vector<vector<int>> ans = {{0, 1}};
3827 TEST(critical_connections_in_a_network, case3) {
3828 vector<vector<int>> connections = {{0, 1}, {1, 2}, {2, 0}, {1, 3}, {3, 4}, {4, 5}, {5, 3}};
3829 const vector<vector<int>> ans = {{1, 3}};
3834 namespace factor_combinations {
3836 const vector<vector<int>> ans = {};
3841 const vector<vector<int>> ans = {};
3846 const vector<vector<int>> ans = {{2, 6}, {2, 2, 3}, {3, 4}};
3851 const vector<vector<int>> ans = {{2, 16}, {2, 2, 8}, {2, 2, 2, 4}, {2, 2, 2, 2, 2}, {2, 4, 4}, {4, 8}};
3856 namespace decode_string {
3874 namespace n_queens {
3876 const vector<vector<string>> ans = {{
".Q..",
"...Q",
"Q...",
"..Q."}, {
"..Q.",
"Q...",
"...Q",
".Q.."}};
3881 const vector<vector<string>> ans = {{
"Q"}};
3886 namespace sudoku_solver {
3888 vector<vector<char>> board = {{
'5',
'3',
'.',
'.',
'7',
'.',
'.',
'.',
'.'}, {
'6',
'.',
'.',
'1',
'9',
'5',
'.',
'.',
'.'}, {
'.',
'9',
'8',
'.',
'.',
'.',
'.',
'6',
'.'}, {
'8',
'.',
'.',
'.',
'6',
'.',
'.',
'.',
'3'}, {
'4',
'.',
'.',
'8',
'.',
'3',
'.',
'.',
'1'}, {
'7',
'.',
'.',
'.',
'2',
'.',
'.',
'.',
'6'}, {
'.',
'6',
'.',
'.',
'.',
'.',
'2',
'8',
'.'}, {
'.',
'.',
'.',
'4',
'1',
'9',
'.',
'.',
'5'}, {
'.',
'.',
'.',
'.',
'8',
'.',
'.',
'7',
'9'}};
3891 const vector<vector<char>> ans = {{
'5',
'3',
'4',
'6',
'7',
'8',
'9',
'1',
'2'}, {
'6',
'7',
'2',
'1',
'9',
'5',
'3',
'4',
'8'}, {
'1',
'9',
'8',
'3',
'4',
'2',
'5',
'6',
'7'}, {
'8',
'5',
'9',
'7',
'6',
'1',
'4',
'2',
'3'}, {
'4',
'2',
'6',
'8',
'5',
'3',
'7',
'9',
'1'}, {
'7',
'1',
'3',
'9',
'2',
'4',
'8',
'5',
'6'}, {
'9',
'6',
'1',
'5',
'3',
'7',
'2',
'8',
'4'}, {
'2',
'8',
'7',
'4',
'1',
'9',
'6',
'3',
'5'}, {
'3',
'4',
'5',
'2',
'8',
'6',
'1',
'7',
'9'}};
3892 ASSERT_EQ(ans, board);
3896 namespace regular_expression_matching {
3897 TEST(regular_expression_matching, case1) {
3901 TEST(regular_expression_matching, case2) {
3905 TEST(regular_expression_matching, case3) {
3909 TEST(regular_expression_matching, case4) {
3914 namespace different_ways_to_add_parentheses {
3915 TEST(different_ways_to_add_parentheses, case1) {
3916 const vector ans = {0, 2};
3920 TEST(different_ways_to_add_parentheses, case2) {
3921 const vector ans = {-34, -14, -10, -10, 10};
3926 namespace remove_invalid_parentheses {
3927 TEST(remove_invalid_parentheses, case1) {
3928 const vector<string> ans = {
"(())()",
"()()()"};
3932 TEST(remove_invalid_parentheses, case2) {
3933 const vector<string> ans = {
"(a())()",
"(a)()()"};
3937 TEST(remove_invalid_parentheses, case3) {
3938 const vector<string> ans = {
""};
3942 TEST(remove_invalid_parentheses, case4) {
3943 const vector<string> ans = {
"x"};
3947 TEST(remove_invalid_parentheses, case5) {
3948 const vector<string> ans = {
"aaaaa"};
3953 namespace median_of_two_sorted_arrays {
3954 TEST(median_of_two_sorted_arrays, case1) {
3955 vector nums1 = {1, 3};
3960 TEST(median_of_two_sorted_arrays, case2) {
3961 vector nums1 = {1, 2};
3962 vector nums2 = {3, 4};
3966 TEST(median_of_two_sorted_arrays, case3) {
3967 vector nums1 = {1, 3};
3968 vector nums2 = {2, 7};
3973 namespace count_of_smaller_numbers_after_self {
3974 TEST(count_of_smaller_numbers_after_self, case1) {
3975 vector nums = {5, 2, 6, 1};
3976 const vector ans = {2, 1, 1, 0};
3981 TEST(count_of_smaller_numbers_after_self, case2) {
3983 const vector ans = {0};
3988 TEST(count_of_smaller_numbers_after_self, case3) {
3989 vector nums = {-1, -1};
3990 const vector ans = {0, 0};
3996 namespace best_time_to_buy_and_sell_stock_with_cooldown {
3997 TEST(best_time_to_buy_and_sell_stock_with_cooldown, case1) {
3998 vector prices = {1, 2, 3, 0, 2};
4002 TEST(best_time_to_buy_and_sell_stock_with_cooldown, case2) {
4003 vector prices = {1};
4007 TEST(best_time_to_buy_and_sell_stock_with_cooldown, case3) {
4008 vector prices = {1, 2};
4013 namespace best_time_to_buy_and_sell_stock_with_transaction_fee {
4014 TEST(best_time_to_buy_and_sell_stock_with_transaction_fee, case1) {
4015 vector prices = {1, 3, 2, 8, 4, 9};
4019 TEST(best_time_to_buy_and_sell_stock_with_transaction_fee, case2) {
4020 vector prices = {1, 3, 7, 5, 10, 3};
4025 namespace split_array_largest_sum {
4026 TEST(split_array_largest_sum, case1) {
4027 vector nums = {7, 2, 5, 10, 8};
4031 TEST(split_array_largest_sum, case2) {
4032 vector nums = {1, 2, 3, 4, 5};
4036 TEST(split_array_largest_sum, case3) {
4037 vector nums = {1, 4, 4};
4042 namespace maximal_square {
4044 vector<vector<char>> matrix = {{
'1',
'0',
'1',
'0',
'0'}, {
'1',
'0',
'1',
'1',
'1'}, {
'1',
'1',
'1',
'1',
'1'}, {
'1',
'0',
'0',
'1',
'0'}};
4049 vector<vector<char>> matrix = {{
'0',
'1'}, {
'1',
'0'}};
4054 vector<vector<char>> matrix = {{
'0'}};
4059 namespace maximal_rectangle {
4061 vector<vector<char>> matrix = {{
'1',
'0',
'1',
'0',
'0'}, {
'1',
'0',
'1',
'1',
'1'}, {
'1',
'1',
'1',
'1',
'1'}, {
'1',
'0',
'0',
'1',
'0'}};
4066 vector<vector<char>> matrix = {};
4071 vector<vector<char>> matrix = {{
'0'}};
4076 vector<vector<char>> matrix = {{
'1'}};
4081 vector<vector<char>> matrix = {{
'0',
'0'}};
4086 namespace predict_the_winner {
4088 vector nums = {1, 5, 2};
4093 vector nums = {1, 5, 233, 7};
4098 namespace palindrome_partitioning {
4099 TEST(palindrome_partitioning, case1) {
4100 const string s =
"aab";
4101 const vector<vector<string>> ans = {{
"a",
"a",
"b"}, {
"aa",
"b"}};
4105 TEST(palindrome_partitioning, case2) {
4106 const string s =
"a";
4107 const vector<vector<string>> ans = {{
"a"}};
4112 namespace palindrome_partitioning_ii {
4113 TEST(palindrome_partitioning_ii, case1) {
4114 const string s =
"aab";
4118 TEST(palindrome_partitioning_ii, case2) {
4119 const string s =
"a";
4123 TEST(palindrome_partitioning_ii, case3) {
4124 const string s =
"ab";
4129 namespace partition_equal_subset_sum {
4130 TEST(partition_equal_subset_sum, case1) {
4131 vector nums = {1, 5, 11, 5};
4135 TEST(partition_equal_subset_sum, case2) {
4136 vector nums = {1, 2, 3, 5};
4141 namespace minimum_cost_for_tickets {
4142 TEST(minimum_cost_for_tickets, case1) {
4143 vector days = {1, 4, 6, 7, 8, 20};
4144 vector costs = {2, 7, 15};
4148 TEST(minimum_cost_for_tickets, case2) {
4149 vector days = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 30, 31};
4150 vector costs = {2, 7, 15};
4155 namespace best_time_to_buy_and_sell_stock_iii {
4156 TEST(best_time_to_buy_and_sell_stock_iii, case1) {
4157 vector prices = {3, 3, 5, 0, 0, 3, 1, 4};
4161 TEST(best_time_to_buy_and_sell_stock_iii, case2) {
4162 vector prices = {1, 2, 3, 4, 5};
4166 TEST(best_time_to_buy_and_sell_stock_iii, case3) {
4167 vector prices = {7, 6, 4, 3, 1};
4171 TEST(best_time_to_buy_and_sell_stock_iii, case4) {
4172 vector prices = {1};
4177 namespace dungeon_game {
4179 vector<vector<int>> dungeon = {{-2, -3, 3}, {-5, -10, 1}, {10, 30, -5}};
4184 vector<vector<int>> dungeon = {{0}};
4189 vector<vector<int>> dungeon = {{29, -78, -52, -1, -38, 6, 24, -45, 35, -29}, {-48, -48, -52, 2, -96, -78, -96, 40, -78, -73}, {-31, -73, -19, 38, 14, -95, 28, -59, 29, -20}, {17, -86, 45, 15, -3, -53, 43, 42, -97, -1}, {20, -99, -4, -2, -87, -98, 7, -90, -33, -42}, {-77, -66, -54, -46, 38, -42, 3, -5, -45, -49}, {13, -13, -52, -63, 25, 9, -63, -6, -58, -86}, {-57, 38, -83, 41, -71, -18, 9, -57, 35, -33}, {-2, -2, -95, -85, -37, -9, -60, -95, -87, -99}, {46, -98, -77, -13, -76, 36, -38, -19, -63, 5}, {-66, -15, -45, -81, -51, 6, -29, -96, 6, 28}, {-22, 17, 34, -52, -14, -65, -17, -70, 10, -40}, {18, -37, 23, -76, -5, 4, -31, -59, -22, 30}, {-26, -12, -34, 9, -78, -53, -98, -37, -1, 29}, {-54, -94, 37, -8, 22, -16, -84, -100, -45, 13}, {25, -96, 28, -77, 5, -93, 4, 20, -41, -89}, {-90, -99, -47, 29, 14, -47, -78, -40, -56, 26}, {-82, -69, -56, -40, 6, 0, -20, 5, -39, -73}, {-100, 44, 11, 37, 43, 45, -23, 8, 16, 45}, {-33, 41, -89, -13, -63, 46, 17, 26, -65, 23}, {-48, 2, -32, -56, -55, -21, -63, -9, -23, -61}, {-56, 44, -34, 45, 45, -23, 41, 9, 7, -90}, {34, 49, -66, -41, 37, -56, -62, -71, 28, -87}, {-54, -36, -78, -37, -22, 27, -64, -58, -3, -70}, {-77, -23, -60, -99, 45, -47, -42, 9, -72, -3}, {30, 29, 2, -50, -46, 6, -72, 0, -39, -4}, {32, 29, -67, -38, -56, -43, 50, -65, -81, -3}, {31, -31, -93, 34, 40, 47, -28, -6, -60, 48}, {42, -68, -14, -94, -36, -26, 13, -96, -39, -71}, {-96, 1, 37, -42, 17, 1, 34, -30, -31, 48}, {-93, -24, 12, -15, -98, 49, 30, -73, -4, 16}, {-86, -35, -100, 4, 15, 14, -1, 47, -11, 46}, {-76, -67, 0, -95, 25, 5, -83, -54, 45, 30}, {-27, -84, 17, 9, -63, -39, 37, -69, -62, 24}, {-40, -37, -52, -39, 10, -69, -73, -51, 48, 27}, {5, -86, -92, -8, 37, -44, 33, 0, -83, -37}, {-82, 45, 23, -95, 15, 35, 27, -28, -80, -80}, {-57, 26, -52, -13, -65, -80, -18, 46, 11, -14}, {49, 23, 26, 9, 18, -57, -18, -82, -85, -10}, {38, -25, -11, -38, 44, -29, -14, -80, -16, 4}, {-46, 48, 39, -65, -59, -13, 47, -23, -58, -100}, {42, -69, -93, -18, 22, 5, -26, -77, -37, 20}, {30, 41, -34, -93, -74, -49, -89, -53, -18, -51}, {-3, 12, 28, 8, 28, -31, 4, -75, -57, -89}, {-70, 0, -6, -74, -14, 43, -53, -23, -76, -22}, {14, -82, -25, -14, 14, -78, -46, -16, 28, -72}, {5, 48, 45, -87, 20, -13, -63, -48, -7, -64}, {49, -3, -63, -43, -58, -23, -21, -60, 11, 15}, {-65, -58, -50, 47, 45, -93, -71, 20, -90, -58}, {-49, -62, -16, 11, 43, -31, -39, 13, -43, 30}, {8, -45, -98, -22, 10, -46, -51, -22, -81, -99}, {4, -87, -53, -53, -19, -38, 24, -42, -15, -21}, {-77, 30, -95, 39, 42, 10, 41, -40, -46, -51}, {-69, 45, -99, 14, -54, 35, 18, -46, 11, -80}, {-12, 50, -12, 50, 45, -58, 18, -19, 29, -24}, {-63, 12, -14, -28, -48, 42, -8, -67, -87, 43}, {9, -87, 26, -29, -53, -70, -11, -43, -88, 15}, {-1, -12, 15, -42, -44, 41, 22, -46, 7, -31}, {-13, 6, 11, 13, -98, -96, -54, -95, -84, -34}, {13, -47, -42, -94, -90, -86, 50, -91, 19, 48}, {-26, -66, -18, 45, -72, -60, -7, 40, 37, -45}, {-11, 15, 48, -70, -89, -92, 25, -82, -36, 23}, {27, -11, -4, 35, -32, -30, -33, 50, 29, -24}, {-32, 26, -10, -5, 25, -30, 18, -70, -98, -3}, {-80, -45, -65, 42, -84, -56, -50, -97, -13, -65}, {19, -41, 26, -11, -66, 18, -52, -16, 28, -22}, {45, -23, -79, -44, -38, -100, 8, 11, -99, -67}, {-8, -48, -20, -15, -11, -52, 20, 30, -43, 24}, {-49, 23, -58, -73, 18, 43, 26, 1, -33, 32}, {-15, 27, -49, -87, -72, -45, -56, -91, -30, -40}, {3, -55, -22, -44, -71, -100, -53, -99, -85, 14}, {-34, -67, 25, -93, -21, -4, -37, -92, 12, -97}, {-14, 17, -72, -3, -25, -44, -26, -98, 10, -68}, {-90, -97, -1, -31, -44, -27, 43, -77, -35, -77}, {28, -53, -27, -100, -51, -45, 45, -67, -70, -61}, {-24, -38, 40, 36, 39, 2, 43, -38, -64, 3}, {-77, -85, -54, -88, 41, -85, -57, -100, -93, -75}, {40, -98, -59, -60, -15, 39, -64, 32, -77, 13}, {-50, 9, -64, 28, -8, -61, -16, -79, -77, -69}, {10, 16, -54, 47, -11, -4, -54, -10, 3, -10}, {-76, -62, -78, -23, -34, -97, -17, -67, -23, 13}, {-67, -27, -74, -62, -56, -36, -9, -51, 6, 37}, {23, 32, -93, -3, 28, -35, -13, 11, 7, -99}, {-20, -54, -54, -82, -36, 8, 25, 38, 43, 32}, {-97, -71, 38, -73, 27, -71, 47, -69, -74, 19}, {-61, -10, 5, -84, 48, 49, 6, -86, -28, -48}, {20, -92, -54, -7, 2, -90, -68, 14, -32, -12}, {-27, -100, 18, -47, 5, -73, 10, -50, -91, -75}, {-30, -43, -31, -96, -34, -54, -72, -70, 32, -72}, {-51, -55, -17, 24, 39, 39, -35, 4, 19, -82}, {11, -14, -97, 10, 42, 28, -31, -61, -96, 38}, {-94, -78, -42, 10, -36, -72, 2, -26, 3, -68}, {-44, 23, 5, -82, -81, -38, 13, -76, 0, -20}, {-36, 1, -90, -65, -67, -14, -79, 46, 35, 30}, {-85, -79, -34, 46, -39, -79, 8, -61, -75, -100}, {-58, -54, -84, 5, -93, -55, 7, 19, -27, -24}, {1, -51, -30, -4, -39, -94, 32, 14, -46, -91}, {37, -4, -18, -16, 7, 4, -98, -63, -15, 44}, {-4, -55, -33, 30, -37, 43, 5, -13, -56, -17}, {-19, -74, -31, -64, -50, -72, -63, 50, 1, -10}};
4194 namespace course_schedule {
4196 vector<vector<int>> prerequisites = {{1, 0}};
4201 vector<vector<int>> prerequisites = {{1, 0}, {0, 1}};
4206 namespace course_schedule_ii {
4208 vector<vector<int>> prerequisites = {{1, 0}};
4209 const vector ans = {0, 1};
4214 vector<vector<int>> prerequisites = {{1, 0}, {2, 0}, {3, 1}, {3, 2}};
4215 const vector ans = {0, 1, 2, 3};
4220 vector<vector<int>> prerequisites = {};
4221 const vector ans = {0};
4226 namespace longest_increasing_path_in_a_matrix {
4227 TEST(longest_increasing_path_in_a_matrix, case1) {
4228 vector<vector<int>> matrix = {{9, 9, 4}, {6, 6, 8}, {2, 1, 1}};
4230 ASSERT_EQ(4, sol.longestIncreasingPath(matrix));
4233 TEST(longest_increasing_path_in_a_matrix, case2) {
4234 vector<vector<int>> matrix = {{3, 4, 5}, {3, 2, 6}, {2, 2, 1}};
4236 ASSERT_EQ(4, sol.longestIncreasingPath(matrix));
4239 TEST(longest_increasing_path_in_a_matrix, case3) {
4240 vector<vector<int>> matrix = {{1}};
4242 ASSERT_EQ(1, sol.longestIncreasingPath(matrix));
4245 TEST(longest_increasing_path_in_a_matrix, case4) {
4246 vector<vector<int>> matrix = {{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, {19, 18, 17, 16, 15, 14, 13, 12, 11, 10}, {20, 21, 22, 23, 24, 25, 26, 27, 28, 29}, {39, 38, 37, 36, 35, 34, 33, 32, 31, 30}, {40, 41, 42, 43, 44, 45, 46, 47, 48, 49}, {59, 58, 57, 56, 55, 54, 53, 52, 51, 50}, {60, 61, 62, 63, 64, 65, 66, 67, 68, 69}, {79, 78, 77, 76, 75, 74, 73, 72, 71, 70}, {80, 81, 82, 83, 84, 85, 86, 87, 88, 89}, {99, 98, 97, 96, 95, 94, 93, 92, 91, 90}, {100, 101, 102, 103, 104, 105, 106, 107, 108, 109}, {119, 118, 117, 116, 115, 114, 113, 112, 111, 110}, {120, 121, 122, 123, 124, 125, 126, 127, 128, 129}, {139, 138, 137, 136, 135, 134, 133, 132, 131, 130}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
4248 ASSERT_EQ(140, sol.longestIncreasingPath(matrix));
4252 namespace parallel_courses {
4254 vector<vector<int>> relations = {{1, 3}, {2, 3}};
4259 vector<vector<int>> relations = {{1, 3}, {2, 3}, {3, 1}};
4264 namespace alien_dictionary {
4266 vector<string> words = {
"wrt",
"wrf",
"er",
"ett",
"rftt"};
4271 vector<string> words = {
"z",
"x"};
4276 vector<string> words = {
"z",
"x",
"z"};
4281 vector<string> words = {
"z",
"z"};
4286 vector<string> words = {
"abc",
"ab"};
4291 namespace single_number_iii {
4293 vector nums = {1, 2, 1, 3, 2, 5};
4294 const vector ans = {3, 5};
4299 vector nums = {-1, 0};
4300 const vector ans = {-1, 0};
4305 vector nums = {0, 1};
4306 const vector ans = {1, 0};
4311 namespace shortest_path_to_get_all_keys {
4312 TEST(shortest_path_to_get_all_keys, case1) {
4313 vector<string> grid = {
"@.a.#",
"###.#",
"b.A.B"};
4317 TEST(shortest_path_to_get_all_keys, case2) {
4318 vector<string> grid = {
"@..aA",
"..B#.",
"....b"};
4322 TEST(shortest_path_to_get_all_keys, case3) {
4323 vector<string> grid = {
"@Aa"};
4327 TEST(shortest_path_to_get_all_keys, case4) {
4328 vector<string> grid = {
".@aA"};
4332 TEST(shortest_path_to_get_all_keys, case5) {
4333 vector<string> grid = {
"..#....##.",
"....d.#.D#",
"#...#.c...",
"..##.#..a.",
"...#....##",
"#....b....",
".#..#.....",
"..........",
".#..##..A.",
".B..C.#..@"};
4338 namespace minimum_number_of_k_consecutive_bit_flips {
4339 TEST(minimum_number_of_k_consecutive_bit_flips, case1) {
4340 vector nums = {0, 1, 0};
4344 TEST(minimum_number_of_k_consecutive_bit_flips, case2) {
4345 vector nums = {1, 1, 0};
4349 TEST(minimum_number_of_k_consecutive_bit_flips, case3) {
4350 vector nums = {0, 0, 0, 1, 0, 1, 1, 0};
4355 namespace lfu_cache {
4360 ASSERT_EQ(1, c.
get(1));
4362 ASSERT_EQ(-1, c.
get(2));
4363 ASSERT_EQ(3, c.
get(3));
4365 ASSERT_EQ(-1, c.
get(1));
4366 ASSERT_EQ(3, c.
get(3));
4367 ASSERT_EQ(4, c.
get(4));
4371 namespace leetcode454_4sum_ii {
4373 vector nums1 = {1, 2};
4374 vector nums2 = {-2, -1};
4375 vector nums3 = {-1, 2};
4376 vector nums4 = {0, 2};
4378 ASSERT_EQ(2, sol.
fourSumCount(nums1, nums2, nums3, nums4));
4387 ASSERT_EQ(1, sol.
fourSumCount(nums1, nums2, nums3, nums4));
4391 namespace maximum_size_subarray_sum_equals_k {
4392 TEST(maximum_size_subarray_sum_equals_k, case1) {
4393 vector nums = {1, -1, 5, -2, 3};
4397 TEST(maximum_size_subarray_sum_equals_k, case2) {
4398 vector nums = {-2, -1, 2, 1};
4403 namespace minimum_swaps_to_group_all_1s_together {
4404 TEST(minimum_swaps_to_group_all_1s_together, case1) {
4405 vector data = {1, 0, 1, 0, 1};
4409 TEST(minimum_swaps_to_group_all_1s_together, case2) {
4410 vector data = {0, 0, 0, 1, 0};
4414 TEST(minimum_swaps_to_group_all_1s_together, case3) {
4415 vector data = {1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1};
4419 TEST(minimum_swaps_to_group_all_1s_together, case4) {
4420 vector data = {1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1};
bool find(vector< unordered_set< int > > &g, int x, vector< bool > &st, vector< int > &match)
TEST(concatenated_words, case1)
TEST(excel_sheet_column_number, case1)
TEST(excel_sheet_column_title, case1)
TEST(majority_element, case1)
TEST(count_special_quadruplets, case1)
TEST(hand_of_straights, case1)
TEST(perfect_number, case1)
TEST(convert_bst_to_greater_tree, case1)
TEST(convert_1d_array_into_2d_array, case1)
TEST(elimination_game, case1)
TEST(check_if_all_as_appears_before_all_bs, case1)
TEST(number_of_laser_beams_in_a_bank, case1)
TEST(destroying_asteroids, case1)
TEST(day_of_the_week, case1)
TEST(replace_all_s_to_avoid_consecutive_repeating_characters, case1)
TEST(simplify_path, case1)
TEST(maximum_nesting_depth_of_the_parentheses, case1)
TEST(minimum_swaps_to_group_all_1s_together_ii, case1)
TEST(count_words_obtained_after_adding_a_letter, case1)
TEST(additive_number, case1)
TEST(decode_the_slanted_ciphertext, case1)
TEST(increasing_triplet_subsequence, case1)
TEST(largest_number_at_least_twice_of_others, case1)
TEST(permutations, case1)
TEST(calculate_money_in_leetcode_bank, case1)
TEST(divide_a_string_into_groups_of_size_k, case1)
TEST(minimum_moves_to_reach_target_score, case1)
TEST(maximum_running_time_of_n_computers, case1)
TEST(coun_vowels_permutation, case1)
TEST(minimum_time_difference, case1)
TEST(contains_duplicate_ii, case1)
TEST(stone_game_ix, case1)
TEST(jump_game_iv, case1)
TEST(remove_palindromic_subsequences, case1)
TEST(minimum_cost_of_buying_candies_with_discount, case1)
TEST(count_the_hidden_sequences, case1)
TEST(number_of_ways_to_divide_a_long_corridor, case1)
TEST(count_elements_with_strictly_smaller_and_greater_elements, case1)
TEST(rearrange_array_elements_by_sign, case1)
TEST(find_all_lonely_numbers_in_the_array, case1)
TEST(maximum_good_people_based_on_statements, case1)
TEST(second_minimum_time_to_reach_destination, case1)
TEST(count_of_matches_in_tournament, case1)
TEST(number_of_valid_words_in_a_sentence, case1)
TEST(pattern_matching_lcci, case1)
TEST(map_of_highest_peak, case1)
TEST(find_substring_with_given_hash_value, case1)
TEST(groups_of_strings, case1)
TEST(number_of_steps_to_reduce_a_number_to_zero, case1)
TEST(longest_nice_substring, case1)
TEST(reverse_prefix_of_word, case1)
TEST(find_the_minimum_number_of_fibonacci_numbers_whose_sum_is_k, case1)
TEST(number_of_rectangles_that_can_form_the_largest_square, case1)
TEST(path_with_maximum_gold, case1)
TEST(minimum_difference_in_sums_after_removal_of_elements, case1)
TEST(sum_of_unique_elements, case1)
TEST(smallest_value_of_the_rearranged_number, case1)
TEST(design_bitset, case1)
TEST(longest_happy_string, case1)
TEST(grid_illumination, case1)
TEST(count_number_of_pairs_with_absolute_difference_k, case1)
TEST(simplified_fractions, case1)
TEST(minimum_difference_between_highest_and_lowest_of_k_scores, case1)
TEST(number_of_enclaves, case1)
TEST(maximum_number_of_balloons, case1)
TEST(swap_adjacent_in_lr_string, case1)
TEST(count_operations_to_obtain_zero, case1)
TEST(minimum_operations_to_make_the_array_alternating, case1)
TEST(removing_minimum_number_of_magic_beans, case1)
TEST(maximum_and_sum_of_array, case1)
TEST(single_element_in_a_sorted_array, case1)
TEST(lucky_numbers_in_a_matrix, case1)
TEST(number_of_ways_to_reconstruct_a_tree, case1)
TEST(find_center_of_star_graph, case1)
TEST(knight_probability_in_chessboard, case1)
TEST(count_equal_and_divisible_pairs_in_an_array, case1)
TEST(find_three_consecutive_integers_that_sum_to_a_given_number, case1)
TEST(maximum_split_of_positive_even_integers, case1)
TEST(count_good_triplets_in_an_array, case1)
TEST(count_integers_with_even_digit_sum, case1)
TEST(construct_string_with_repeat_limit, case1)
TEST(count_array_pairs_divisible_by_k, case1)
TEST(leetcode717_1_bit_and_2_bit_characters, case1)
TEST(longest_mountain_in_array, case1)
TEST(push_dominoes, case1)
TEST(the_number_of_good_subsets, case1)
TEST(reverse_only_letters, case1)
TEST(where_will_the_ball_fall, case1)
TEST(complex_number_multiplication, case1)
TEST(maximum_difference_between_increasing_elements, case1)
TEST(optimal_division, case1)
TEST(counting_words_with_a_given_prefix, case1)
TEST(minimum_number_of_steps_to_make_two_strings_anagram_ii, case1)
TEST(minimum_time_to_complete_trips, case1)
TEST(minimum_time_to_finish_the_race, case1)
TEST(maximum_number_of_achievable_transfer_requests, case1)
TEST(zigzag_conversion, case1)
TEST(find_the_closest_palindrome, case1)
TEST(sum_of_subarray_ranges, case1)
TEST(longest_uncommon_subsequence_i, case1)
TEST(most_frequent_number_following_key_in_an_array, case1)
TEST(sort_the_jumbled_numbers, case1)
TEST(all_ancestors_of_a_node_in_a_directed_acyclic_graph, case1)
TEST(minimum_number_of_moves_to_make_palindrome, case1)
TEST(cells_in_a_range_on_an_excel_sheet, case1)
TEST(append_k_integers_with_minimal_sum, case1)
TEST(replace_non_coprime_numbers_in_array, case1)
TEST(find_good_days_to_rob_the_bank, case1)
TEST(plates_between_candles, case1)
TEST(smallest_rotation_with_highest_score, case1)
TEST(count_nodes_with_the_highest_score, case1)
TEST(max_area_of_island, case1)
TEST(find_all_k_distant_indices_in_an_array, case1)
TEST(count_artifacts_that_can_be_extracted, case1)
TEST(maximize_the_topmost_element_after_k_moves, case1)
TEST(minimum_weighted_subgraph_with_the_required_paths, case1)
TEST(utf_8_validation, case1)
TEST(minimum_index_sum_of_two_lists, case1)
TEST(count_number_of_maximum_bitwise_or_subsets, case1)
TEST(all_oone_data_structure, case1)
TEST(longest_word_in_dictionary, case1)
TEST(maximize_number_of_subsequences_in_a_string, case1)
TEST(minimum_operations_to_halve_array_sum, case1)
TEST(minimum_white_tiles_after_covering_with_carpets, case1)
TEST(count_hills_and_valleys_in_an_array, case1)
TEST(count_collisions_on_a_road, case1)
TEST(maximum_points_in_an_archery_competition, case1)
TEST(the_time_when_the_network_becomes_idle, case1)
TEST(remove_colored_pieces_if_both_neighbors_are_the_same_color, case1)
TEST(k_th_smallest_in_lexicographical_order, case1)
TEST(image_smoother, case1)
TEST(factorial_trailing_zeroes, case1)
TEST(baseball_game, case1)
TEST(find_palindrome_with_fixed_length, case1)
TEST(find_missing_observations, case1)
TEST(binary_number_with_alternating_bits, case1)
TEST(maximize_the_confusion_of_an_exam, case1)
TEST(find_servers_that_handled_most_number_of_requests, case1)
TEST(self_dividing_numbers, case1)
TEST(array_of_doubled_pairs, case1)
TEST(strong_password_checker, case1)
TEST(sum_of_scores_of_built_strings, case1)
TEST(minimum_number_of_operations_to_convert_time, case1)
TEST(find_players_with_zero_or_one_losses, case1)
TEST(maximum_candies_allocated_to_k_children, case1)
TEST(encrypt_and_decrypt_strings, case1)
TEST(process_restricted_friend_requests, case1)
TEST(prime_number_of_set_bits_in_binary_representation, case1)
TEST(minimum_height_trees, case1)
TEST(rotate_string, case1)
TEST(reaching_points, case1)
TEST(maximum_product_after_k_increments, case1)
TEST(maximum_total_beauty_of_the_gardens, case1)
TEST(count_numbers_with_unique_digits, case1)
TEST(number_of_lines_to_write_string, case1)
TEST(permutation_in_string, case1)
TEST(projection_area_of_3d_shapes, case1)
TEST(house_robber, case1)
TEST(lowest_common_ancestor_of_a_binary_search_tree, case1)
TEST(find_all_anagrams_in_a_string, case1)
TEST(subarray_product_less_than_k, case1)
TEST(minimum_size_subarray_sum, case1)
TEST(house_robber_ii, case1)
TEST(jump_game_ii, case1)
TEST(unique_paths, case1)
TEST(longest_palindromic_substring, case1)
TEST(arithmetic_slices, case1)
TEST(longest_increasing_subsequence, case1)
TEST(number_of_longest_increasing_subsequence, case1)
TEST(longest_common_subsequence, case1)
TEST(delete_operation_for_two_strings, case1)
TEST(edit_distance, case1)
TEST(integer_break, case1)
TEST(max_points_on_a_line, case1)
TEST(kth_largest_element_in_an_array, case1)
TEST(merge_intervals, case1)
TEST(search_a_2d_matrix_ii, case1)
TEST(serialize_and_deserialize_binary_tree, case1)
TEST(task_scheduler, case1)
TEST(spiral_matrix_ii, case1)
TEST(non_overlapping_intervals, case1)
TEST(product_of_array_except_self, case1)
TEST(subarray_sum_equals_k, case1)
TEST(partition_labels, case1)
TEST(design_linked_list, case1)
TEST(delete_node_in_a_bst, case1)
bool equal(TreeNode *tn1, TreeNode *tn2)
TEST(missing_element_in_sorted_array, case1)
TEST(find_a_peak_element_ii, case1)
TEST(divide_chocolate, case1)
TEST(shortest_distance_to_target_color, case1)
TEST(meeting_scheduler, case1)
TEST(find_the_duplicate_number, case1)
TEST(trapping_rain_water, case1)
TEST(product_of_two_run_length_encoded_arrays, case1)
TEST(longest_substring_with_at_most_two_distinct_characters, case1)
TEST(longest_substring_with_at_most_k_distinct_characters, case1)
TEST(max_consecutive_ones_iii, case1)
TEST(sliding_window_maximum, case1)
TEST(minimum_window_substring, case1)
TEST(walls_and_gates, case1)
TEST(pacific_atlantic_waterflow, case1)
TEST(kill_process, case1)
TEST(open_the_lock, case1)
TEST(number_of_operations_to_make_network_connected, case1)
TEST(minimum_cost_to_make_at_least_one_valid_path_in_a_grid, case1)
TEST(critical_connections_in_a_network, case1)
TEST(factor_combinations, case1)
TEST(decode_string, case1)
TEST(sudoku_solver, case1)
TEST(regular_expression_matching, case1)
TEST(different_ways_to_add_parentheses, case1)
TEST(remove_invalid_parentheses, case1)
TEST(median_of_two_sorted_arrays, case1)
TEST(count_of_smaller_numbers_after_self, case1)
TEST(best_time_to_buy_and_sell_stock_with_cooldown, case1)
TEST(best_time_to_buy_and_sell_stock_with_transaction_fee, case1)
TEST(split_array_largest_sum, case1)
TEST(maximal_square, case1)
TEST(maximal_rectangle, case1)
TEST(predict_the_winner, case1)
TEST(palindrome_partitioning, case1)
TEST(palindrome_partitioning_ii, case1)
TEST(partition_equal_subset_sum, case1)
TEST(minimum_cost_for_tickets, case1)
TEST(best_time_to_buy_and_sell_stock_iii, case1)
TEST(dungeon_game, case1)
TEST(course_schedule, case1)
TEST(course_schedule_ii, case1)
TEST(longest_increasing_path_in_a_matrix, case1)
TEST(parallel_courses, case1)
TEST(alien_dictionary, case1)
TEST(single_number_iii, case1)
TEST(shortest_path_to_get_all_keys, case1)
TEST(minimum_number_of_k_consecutive_bit_flips, case1)
TEST(leetcode454_4sum_ii, case1)
TEST(maximum_size_subarray_sum_equals_k, case1)
TEST(minimum_swaps_to_group_all_1s_together, case1)
static vector< string > findAllConcatenatedWordsInADict(vector< string > &)
static int titleToNumber(const string &columnTitle)
static string convertToTitle(int columnNumber)
static int countQuadruplets(vector< int > &)
static bool isNStraightHand(vector< int > &hand, int groupSize)
static bool checkPerfectNumber(int num)
static TreeNode * convertBST(TreeNode *root)
static vector< vector< int > > construct2DArray(vector< int > &original, int m, int n)
static int lastRemaining(int)
static bool checkString(const string &)
static int numberOfBeams(vector< string > &)
static bool asteroidsDestroyed(int mass, vector< int > &asteroids)
static string dayOfTheWeek(int day, int month, int year)
static string modifyString(string s)
static string simplifyPath(const string &path)
static int maxDepth(const string &s)
static vector< int > grayCode(int n)
static int minSwaps(vector< int > &nums)
static int wordCount(vector< string > &startWords, vector< string > &targetWords)
static char slowestKey(vector< int > &releaseTimes, string keysPressed)
static bool dfs(unsigned long long n1, unsigned long long n2, const char *, unsigned short length, unsigned short current)
static bool isAdditiveNumber(string num)
static unsigned long long str2ui(const char *, unsigned short start, unsigned short length)
将字符串的一个子串转换为整数
static bool equal(string, const char *, unsigned short start, unsigned short length)
判断一个字符串与另一个字符串的子串是否相等
static string decodeCiphertext(string encodedText, int rows)
static bool increasingTriplet(vector< int > &nums)
static int dominantIndex(vector< int > &nums)
static vector< vector< int > > permute(vector< int > &nums)
static int totalMoney(int n)
static vector< string > divideString(const string &s, int k, char fill)
static int minMoves(int target, int maxDoubles)
static long long maxRunTime(int n, vector< int > &batteries)
static int countVowelPermutation(int n)
static int findMinDifference(vector< string > &timePoints)
static bool containsNearbyDuplicate(vector< int > &nums, int k)
static bool stoneGameIX(vector< int > &stones)
static int minJumps(vector< int > &arr)
static int removePalindromeSub(string s)
static string replaceWords(vector< string > &dictionary, const string &sentence)
static int minimumCost(vector< int > &cost)
static int numberOfArrays(vector< int > &differences, int lower, int upper)
static int numberOfWays(string corridor)
static int countElements(vector< int > &nums)
static vector< int > rearrangeArray(vector< int > &nums)
static vector< int > findLonely(vector< int > &nums)
static int maximumGood(vector< vector< int > > &statements)
static int secondMinimum(int n, vector< vector< int > > &edges, int time, int change)
static int numberOfMatches(int n)
static int countValidWords(const string &sentence)
static bool patternMatching(const string &pattern, const string &value)
static vector< vector< int > > highestPeak(vector< vector< int > > &isWater)
static string subStrHash(string s, int power, int modulo, int k, int hashValue)
static int numberOfSteps(int num)
static string longestNiceSubstring(const string &s)
static string reversePrefix(string word, char ch)
static int findMinFibonacciNumbers(int k)
static int countGoodRectangles(vector< vector< int > > &rectangles)
static int getMaximumGold(vector< vector< int > > &grid)
static long long minimumDifference(vector< int > &nums)
static int sumOfUnique(vector< int > &nums)
static long long smallestNumber(long long num)
static string longestDiverseString(int a, int b, int c)
static vector< int > gridIllumination(int n, vector< vector< int > > &lamps, vector< vector< int > > &queries)
static int countKDifference(vector< int > &nums, int k)
static vector< string > simplifiedFractions(int n)
static int minimumDifference(vector< int > &nums, int k)
static int numEnclaves(vector< vector< int > > &grid)
static int maxNumberOfBalloons(const string &text)
static bool canTransform(const string &start, const string &end)
static int countOperations(int num1, int num2)
static int minimumOperations(vector< int > &nums)
static long long minimumRemoval(vector< int > &beans)
static int maximumANDSum(vector< int > &nums, int numSlots)
static int singleNonDuplicate(vector< int > &nums)
static vector< int > luckyNumbers(vector< vector< int > > &matrix)
static int checkWays(vector< vector< int > > &pairs)
static int findCenter(vector< vector< int > > &edges)
static int countPairs(vector< int > &nums, int k)
static vector< long long > sumOfThree(long long num)
static vector< long long > maximumEvenSplit(long long finalSum)
static long long goodTriplets(vector< int > &nums1, vector< int > &nums2)
static int countEven(int num)
static string repeatLimitedString(const string &s, int repeatLimit)
static long long coutPairs(vector< int > &nums, int k)
static bool isOneBitCharacter(vector< int > &bits)
static int longestMountain(vector< int > &arr)
static string pushDominoes(string dominoes)
static int numberOfGoodSubsets(vector< int > &nums)
static string reverseOnlyLetters(string s)
static vector< int > findBall(vector< vector< int > > &grid)
static string complexNumberMultiply(const string &num1, const string &num2)
static int maximumDifference(vector< int > &nums)
static string optimalDivision(vector< int > &nums)
static int prefixCount(vector< string > &words, string pref)
static int minSteps(const string &s, const string &t)
static long long minimumTime(vector< int > &time, int totalTrips)
static int minimumFinishTime(vector< vector< int > > &tires, int changeTime, int numLaps)
static int maximumRequests(int n, vector< vector< int > > &requests)
static string convert(string s, int numRows)
static string nearestPalindromic(const string &n)
static int addDigits(int num)
static long long subArrayRanges(vector< int > &nums)
static int findLUSlength(const string &a, const string &b)
static int mostFrequent(vector< int > &nums, int key)
static vector< int > sortJumbled(vector< int > &mapping, vector< int > &nums)
static int minMovesToMakePalindrome(string s)
static vector< string > cellsInRange(const string &s)
static long long minimalKSum(vector< int > &nums, int k)
static vector< int > replaceNonCoprimes(vector< int > &nums)
static vector< int > goodDaysToRobBank(vector< int > &security, int time)
static string convertToBase7(int num)
static vector< int > platesBetweenCandles(string s, vector< vector< int > > &queries)
static int bestRotation(vector< int > &nums)
static int countHighestScoreNodes(vector< int > &parents)
static int maxAreaOfIsland(vector< vector< int > > &grid)
static vector< int > findKDistantIndices(vector< int > &nums, int key, int k)
static int digArtifacts(int n, vector< vector< int > > &artifacts, vector< vector< int > > &dig)
static int maximumTop(vector< int > &nums, int k)
static long long minimumWeight(int n, vector< vector< int > > &edges, int src1, int src2, int dest)
static bool validUtf8(vector< int > &data)
static vector< string > findRestaurant(vector< string > &list1, vector< string > &list2)
static int countMaxOrSubsets(vector< int > &nums)
string getMaxKey()
Returns one of the keys with the maximal count.
string getMinKey()
Returns one of the keys with the minimum count.
void dec(const string &key)
Decrements the count of the string key by 1. If the count of key is 0 after the decrement,...
void inc(const string &key)
Increments the count of the string key by 1. If key does not exist in the data structure,...
static string longestWord(vector< string > &words)
static long long maximumSubsequenceCount(string text, string pattern)
static int halveArray(vector< int > &nums)
static int minimumWhiteTiles(string floor, int numCarpets, int carpetLen)
static int countHillValley(vector< int > &nums)
static int countCollisions(const string &directions)
static vector< int > maximumBobPoints(int numArrows, vector< int > &aliceArrows)
static int networkBecomesIdle(vector< vector< int > > &edges, vector< int > &patience)
static bool winnerOfGame(string colors)
static int findKthNumber(int n, int k)
static vector< vector< int > > imageSmoother(vector< vector< int > > &img)
static int trailingZeroes(int n)
static int calPoints(vector< string > &ops)
static vector< long long > kthPalindrome(vector< int > &queries, int intLength)
static vector< int > missingRolls(vector< int > &rolls, int mean, int n)
static bool hasAlternatingBits(int n)
static int maxConsecutiveAnswers(string answerKey, int k)
static vector< int > busiestServers(int k, vector< int > &arrival, vector< int > &load)
static vector< int > selfDividingNumbers(int left, int right)
static bool canReorderDoubled(vector< int > &arr)
static int strongPasswordChecker(const string &password)
static long long sumScores(string s)
static int convertTime(string current, string correct)
static vector< vector< int > > findWinners(vector< vector< int > > &matches)
static int maximumCandies(vector< int > &candies, long long k)
static vector< bool > friendRequests(int n, vector< vector< int > > &restrictions, vector< vector< int > > &requests)
static int countPrimeSetBits(int left, int right)
static bool rotateString(string s, const string &goal)
static bool reachingPoints(int sx, int sy, int tx, int ty)
static int maximumProduct(vector< int > &nums, int k)
static long long maximumBeauty(vector< int > &flowers, long long newFlowers, int target, int full, int partial)
static int countNumbersWithUniqueDigits(int n)
static vector< int > numberOfLines(vector< int > &widths, string s)
static bool checkInclusion(const string &s1, string s2)
static int projectionArea(vector< vector< int > > &grid)
static int rob(vector< int > &nums)
static int minimumTotal(vector< vector< int > > &triangle)
static TreeNode * lowestCommonAncestor(TreeNode *root, TreeNode *p, TreeNode *q)
static vector< int > findAnagrams(string s, const string &p)
static int numSubarrayProductLessThanK(vector< int > &nums, int k)
static int minSubArrayLen(int target, vector< int > &nums)
static int rob(vector< int > &nums)
static bool canJump(vector< int > &nums)
static int jump(vector< int > &nums)
static int uniquePaths(int m, int n)
static string longestPalindrome(string s)
static int numberOfArithmeticSlices(vector< int > &nums)
static int numDecodings(string s)
static bool wordBreak(const string &s, vector< string > &wordDict)
static int lengthOfLIS(vector< int > &nums)
static int findNumberOfLIS(vector< int > &nums)
static int longestCommonSubsequence(string text1, string text2)
static int minDistance(const string &word1, const string &word2)
static int minDistance(string word1, string word2)
static int coinChange(vector< int > &coins, int amount)
static int integerBreak(int n)
static int maxPoints(vector< vector< int > > &points)
static void sortColors(vector< int > &nums)
static int findKthLargest(vector< int > &nums, int k)
static vector< vector< int > > merge(vector< vector< int > > &intervals)
static bool searchMatrix(vector< vector< int > > &matrix, int target)
static TreeNode * deserialize(string data)
Decodes your encoded data to tree.
static int leastInterval(vector< char > &tasks, int n)
static vector< vector< int > > generateMatrix(int n)
static int eraseOverlapIntervals(vector< vector< int > > &intervals)
static vector< int > productExceptSelf(vector< int > &nums)
static int subarraySum(vector< int > &nums, int k)
static vector< int > partitionLabels(string s)
int get(int index) const
Get the value of the indexth node in the linked list. If the index is invalid, return -1.
void deleteAtIndex(int index)
Delete the indexth node in the linked list, if the index is valid.
void addAtHead(int val)
Add a node of value val before the first element of the linked list. After the insertion,...
void addAtTail(int val)
Append a node of value val as the last element of the linked list.
void addAtIndex(int index, int val)
Add a node of value val before the indexth node in the linked list. If index equals the length of the...
static int missingElement(vector< int > &nums, int k)
static vector< int > findPeakGrid(vector< vector< int > > &mat)
static int maximizeSweetness(vector< int > &sweetness, int k)
static vector< int > shortestDistanceColor(vector< int > &colors, vector< vector< int > > &queries)
static vector< int > minAvailableDuration(vector< vector< int > > &slots1, vector< vector< int > > &slots2, int duration)
static int findDuplicate(vector< int > &nums)
static int trap(vector< int > &height)
static vector< vector< int > > findRLEArray(vector< vector< int > > &encoded1, vector< vector< int > > &encoded2)
static int lengthOfLongestSubstringTwoDistinct(const string &s)
static int lengthOfLongestSubstringKDistinct(const string &s, int k)
static int longestOnes(vector< int > &nums, int k)
static vector< int > maxSlidingWindow(vector< int > &nums, int k)
static string minWindow(string s, const string &t)
static void wallsAndGates(vector< vector< int > > &rooms)
static vector< vector< int > > pacificAtlantic(vector< vector< int > > &heights)
static vector< int > killProcess(vector< int > &pid, vector< int > &ppid, int kill)
static int openLock(vector< string > &deadends, const string &target)
static int makeConnected(int n, vector< vector< int > > &connections)
static int minCost(vector< vector< int > > &grid)
static vector< vector< int > > criticalConnections(int n, vector< vector< int > > &connections)
static vector< vector< int > > getFactors(int n)
static string decodeString(string s)
static vector< vector< string > > solveNQueens(int n)
static void solveSudoku(vector< vector< char > > &board)
static bool isMatch(const string &s, const string &p)
static vector< int > diffWaysToCompute(const string &expression)
static vector< string > removeInvalidParentheses(const string &s)
static double findMedianSortedArrays(vector< int > &nums1, vector< int > &nums2)
vector< int > countSmaller(vector< int > &nums)
static int maxProfit(vector< int > &prices)
static int maxProfit(vector< int > &prices, int fee)
static int splitArray(vector< int > &nums, int m)
static int maximalSquare(vector< vector< char > > &matrix)
static int maximalRectangle(vector< vector< char > > &matrix)
static bool PredictTheWinner(vector< int > &nums)
static vector< vector< string > > partition(const string &s)
static int minCut(string s)
static bool canPartition(vector< int > &nums)
static int mincostTickets(vector< int > &days, vector< int > &costs)
static int maxProfit(vector< int > &prices)
static int calculateMinimumHP(vector< vector< int > > &dungeon)
static bool canFinish(int numCourses, vector< vector< int > > &prerequisites)
static vector< int > findOrder(int numCourses, vector< vector< int > > &prerequisites)
static int minimumSemesters(int n, vector< vector< int > > &relations)
static string alienOrder(vector< string > &words)
static vector< int > singleNumber(vector< int > &nums)
static int shortestPathAllKeys(vector< string > &grid)
static int minKBitFlips(vector< int > &nums, int k)
int get(int key)
如果键 key 存在于缓存中,则获取键的值,否则返回 -1 。
void put(int key, int value)
如果键 key 已存在,则变更其值;如果键不存在,请插入键值对。当缓存达到其容量 capacity 时,则应该在插入新项之前,移除最不经常使用的项。在此问题中,当存在平局(即两个或更多个键具有相同使用频...
int fourSumCount(vector< int > &nums1, vector< int > &nums2, vector< int > &nums3, vector< int > &nums4)
static int maxSubArrayLen(vector< int > &nums, int k)
static int minSwaps(vector< int > &data)