├── .gitignore ├── README.md ├── algorithms ├── 0001-0500 │ ├── 0001_two-sum_1_AC.cpp │ ├── 0002_add-two-numbers_1_AC.cpp │ ├── 0003_longest-substring-without-repeating-characters_1_AC.cpp │ ├── 0004_median-of-two-sorted-arrays_1_AC.cpp │ ├── 0004_median-of-two-sorted-arrays_2_AC.cpp │ ├── 0005_longest-palindromic-substring_1_AC.cpp │ ├── 0005_longest-palindromic-substring_2_AC.cpp │ ├── 0006_zigzag-conversion_1_AC.cpp │ ├── 0007_reverse-integer_1_AC.cpp │ ├── 0008_string-to-integer-atoi_1_AC.cpp │ ├── 0009_palindrome-number_1_AC.cpp │ ├── 0010_regular-expression-matching_1_AC.cpp │ ├── 0011_container-with-most-water_1_AC.cpp │ ├── 0012_integer-to-roman_1_AC.cpp │ ├── 0013_roman-to-integer_1_AC.cpp │ ├── 0014_longest-common-prefix_1_AC.cpp │ ├── 0015_3sum_1_AC.cpp │ ├── 0016_3sum-closest_1_AC.cpp │ ├── 0017_letter-combinations-of-a-phone-number_1_AC.cpp │ ├── 0018_4sum_1_AC.cpp │ ├── 0019_remove-nth-node-from-end-of-list_1_AC.cpp │ ├── 0020_valid-parentheses_1_AC.cpp │ ├── 0021_merge-two-sorted-lists_1_AC.cpp │ ├── 0022_generate-parentheses_1_AC.cpp │ ├── 0023_merge-k-sorted-lists_1_AC.cpp │ ├── 0024_swap-nodes-in-pairs_1_AC.cpp │ ├── 0025_reverse-nodes-in-k-group_1_AC.cpp │ ├── 0026_remove-duplicates-from-sorted-array_1_AC.cpp │ ├── 0027_remove-element_1_AC.cpp │ ├── 0028_find-the-index-of-the-first-occurrence-in-a-string_1_AC.cpp │ ├── 0028_find-the-index-of-the-first-occurrence-in-a-string_2_AC.cpp │ ├── 0028_find-the-index-of-the-first-occurrence-in-a-string_3_AC.cpp │ ├── 0029_divide-two-integers_1_AC.cpp │ ├── 0030_substring-with-concatenation-of-all-words_1_AC.cpp │ ├── 0031_next-permutation_1_AC.cpp │ ├── 0032_longest-valid-parentheses_1_AC.cpp │ ├── 0033_search-in-rotated-sorted-array_1_AC.cpp │ ├── 0034_find-first-and-last-position-of-element-in-sorted-array_1_AC.cpp │ ├── 0035_search-insert-position_1_AC.cpp │ ├── 0036_valid-sudoku_1_AC.cpp │ ├── 0037_sudoku-solver_1_AC.cpp │ ├── 0038_count-and-say_1_AC.cpp │ ├── 0039_combination-sum_1_AC.cpp │ ├── 0040_combination-sum-ii_1_AC.cpp │ ├── 0041_first-missing-positive_1_AC.cpp │ ├── 0042_trapping-rain-water_1_AC.cpp │ ├── 0043_multiply-strings_1_AC.cpp │ ├── 0044_wildcard-matching_1_AC.cpp │ ├── 0045_jump-game-ii_1_AC.cpp │ ├── 0046_permutations_1_AC.cpp │ ├── 0046_permutations_2_AC.cpp │ ├── 0047_permutations-ii_1_AC.cpp │ ├── 0048_rotate-image_1_AC.cpp │ ├── 0049_group-anagrams_1_AC.cpp │ ├── 0050_powx-n_1_AC.cpp │ ├── 0051_n-queens_1_AC.cpp │ ├── 0052_n-queens-ii_1_AC.cpp │ ├── 0053_maximum-subarray_1_AC.cpp │ ├── 0054_spiral-matrix_1_AC.cpp │ ├── 0055_jump-game_1_AC.cpp │ ├── 0056_merge-intervals_1_AC.cpp │ ├── 0057_insert-interval_1_AC.cpp │ ├── 0058_length-of-last-word_1_AC.cpp │ ├── 0059_spiral-matrix-ii_1_AC.cpp │ ├── 0060_permutation-sequence_1_AC.cpp │ ├── 0061_rotate-list_1_AC.cpp │ ├── 0062_unique-paths_1_AC.cpp │ ├── 0063_unique-paths-ii_1_AC.cpp │ ├── 0064_minimum-path-sum_1_AC.cpp │ ├── 0065_valid-number_1_AC.cpp │ ├── 0066_plus-one_1_AC.cpp │ ├── 0067_add-binary_1_AC.cpp │ ├── 0068_text-justification_1_AC.cpp │ ├── 0069_sqrtx_1_AC.cpp │ ├── 0070_climbing-stairs_1_AC.cpp │ ├── 0071_simplify-path_1_AC.cpp │ ├── 0072_edit-distance_1_AC.cpp │ ├── 0073_set-matrix-zeroes_1_AC.cpp │ ├── 0074_search-a-2d-matrix_1_AC.cpp │ ├── 0075_sort-colors_1_AC.cpp │ ├── 0076_minimum-window-substring_1_AC.cpp │ ├── 0077_combinations_1_AC.cpp │ ├── 0077_combinations_2_AC.cpp │ ├── 0078_subsets_1_AC.cpp │ ├── 0078_subsets_2_AC.cpp │ ├── 0079_word-search_1_AC.cpp │ ├── 0080_remove-duplicates-from-sorted-array-ii_1_AC.cpp │ ├── 0081_search-in-rotated-sorted-array-ii_1_AC.cpp │ ├── 0082_remove-duplicates-from-sorted-list-ii_1_AC.cpp │ ├── 0083_remove-duplicates-from-sorted-list_1_AC.cpp │ ├── 0084_largest-rectangle-in-histogram_1_AC.cpp │ ├── 0085_maximal-rectangle_1_AC.cpp │ ├── 0086_partition-list_1_AC.cpp │ ├── 0087_scramble-string_1_AC.cpp │ ├── 0088_merge-sorted-array_1_AC.cpp │ ├── 0089_gray-code_1_AC.cpp │ ├── 0090_subsets-ii_1_AC.cpp │ ├── 0091_decode-ways_1_AC.cpp │ ├── 0092_reverse-linked-list-ii_1_AC.cpp │ ├── 0093_restore-ip-addresses_1_AC.cpp │ ├── 0094_binary-tree-inorder-traversal_1_AC.cpp │ ├── 0094_binary-tree-inorder-traversal_2_AC.cpp │ ├── 0095_unique-binary-search-trees-ii_1_AC.cpp │ ├── 0096_unique-binary-search-trees_1_AC.cpp │ ├── 0097_interleaving-string_1_AC.cpp │ ├── 0098_validate-binary-search-tree_1_AC.cpp │ ├── 0099_recover-binary-search-tree_1_AC.cpp │ ├── 0099_recover-binary-search-tree_2_AC.cpp │ ├── 0100_same-tree_1_AC.cpp │ ├── 0101_symmetric-tree_1_AC.cpp │ ├── 0101_symmetric-tree_2_AC.cpp │ ├── 0102_binary-tree-level-order-traversal_1_AC.cpp │ ├── 0102_binary-tree-level-order-traversal_2_AC.cpp │ ├── 0103_binary-tree-zigzag-level-order-traversal_1_AC.cpp │ ├── 0104_maximum-depth-of-binary-tree_1_AC.cpp │ ├── 0105_construct-binary-tree-from-preorder-and-inorder-traversal_1_AC.cpp │ ├── 0106_construct-binary-tree-from-inorder-and-postorder-traversal_1_AC.cpp │ ├── 0107_binary-tree-level-order-traversal-ii_1_AC.cpp │ ├── 0108_convert-sorted-array-to-binary-search-tree_1_AC.cpp │ ├── 0109_convert-sorted-list-to-binary-search-tree_1_AC.cpp │ ├── 0110_balanced-binary-tree_1_AC.cpp │ ├── 0111_minimum-depth-of-binary-tree_1_AC.cpp │ ├── 0112_path-sum_1_AC.cpp │ ├── 0113_path-sum-ii_1_AC.cpp │ ├── 0114_flatten-binary-tree-to-linked-list_1_AC.cpp │ ├── 0115_distinct-subsequences_1_AC.cpp │ ├── 0116_populating-next-right-pointers-in-each-node_1_AC.cpp │ ├── 0117_populating-next-right-pointers-in-each-node-ii_1_AC.cpp │ ├── 0117_populating-next-right-pointers-in-each-node-ii_2_AC.cpp │ ├── 0118_pascals-triangle_1_AC.cpp │ ├── 0119_pascals-triangle-ii_1_AC.cpp │ ├── 0120_triangle_1_AC.cpp │ ├── 0121_best-time-to-buy-and-sell-stock_1_AC.cpp │ ├── 0122_best-time-to-buy-and-sell-stock-ii_1_AC.cpp │ ├── 0123_best-time-to-buy-and-sell-stock-iii_1_AC.cpp │ ├── 0124_binary-tree-maximum-path-sum_1_AC.cpp │ ├── 0125_valid-palindrome_1_AC.cpp │ ├── 0126_word-ladder-ii_1_AC.cpp │ ├── 0127_word-ladder_1_AC.cpp │ ├── 0128_longest-consecutive-sequence_1_AC.cpp │ ├── 0129_sum-root-to-leaf-numbers_1_AC.cpp │ ├── 0130_surrounded-regions_1_AC.cpp │ ├── 0131_palindrome-partitioning_1_AC.cpp │ ├── 0132_palindrome-partitioning-ii_1_AC.cpp │ ├── 0133_clone-graph_1_AC.cpp │ ├── 0134_gas-station_1_AC.cpp │ ├── 0135_candy_1_AC.cpp │ ├── 0136_single-number_1_AC.cpp │ ├── 0137_single-number-ii_1_AC.cpp │ ├── 0138_copy-list-with-random-pointer_1_AC.cpp │ ├── 0138_copy-list-with-random-pointer_2_AC.cpp │ ├── 0139_word-break_1_AC.cpp │ ├── 0140_word-break-ii_1_AC.cpp │ ├── 0141_linked-list-cycle_1_AC.cpp │ ├── 0141_linked-list-cycle_2_AC.cpp │ ├── 0142_linked-list-cycle-ii_1_AC.cpp │ ├── 0142_linked-list-cycle-ii_2_AC.cpp │ ├── 0143_reorder-list_1_AC.cpp │ ├── 0144_binary-tree-preorder-traversal_1_AC.cpp │ ├── 0144_binary-tree-preorder-traversal_2_AC.cpp │ ├── 0145_binary-tree-postorder-traversal_1_AC.cpp │ ├── 0145_binary-tree-postorder-traversal_2_AC.cpp │ ├── 0146_lru-cache_1_AC.cpp │ ├── 0146_lru-cache_2_AC.cpp │ ├── 0147_insertion-sort-list_1_AC.cpp │ ├── 0148_sort-list_1_AC.cpp │ ├── 0149_max-points-on-a-line_1_AC.cpp │ ├── 0150_evaluate-reverse-polish-notation_1_AC.cpp │ ├── 0151_reverse-words-in-a-string_1_AC.cpp │ ├── 0152_maximum-product-subarray_1_AC.cpp │ ├── 0153_find-minimum-in-rotated-sorted-array_1_AC.cpp │ ├── 0154_find-minimum-in-rotated-sorted-array-ii_1_AC.cpp │ ├── 0155_min-stack_1_AC.cpp │ ├── 0156_binary-tree-upside-down_1_AC.cpp │ ├── 0157_read-n-characters-given-read4_1_AC.cpp │ ├── 0158_read-n-characters-given-read4-ii-call-multiple-times_1_AC.cpp │ ├── 0159_longest-substring-with-at-most-two-distinct-characters_1_AC.cpp │ ├── 0160_intersection-of-two-linked-lists_1_AC.cpp │ ├── 0160_intersection-of-two-linked-lists_2_AC.cpp │ ├── 0160_intersection-of-two-linked-lists_3_AC.cpp │ ├── 0161_one-edit-distance_1_AC.cpp │ ├── 0162_find-peak-element_1_AC.cpp │ ├── 0162_find-peak-element_2_AC.cpp │ ├── 0163_missing-ranges_1_AC.cpp │ ├── 0164_maximum-gap_1_AC.cpp │ ├── 0165_compare-version-numbers_1_AC.cpp │ ├── 0166_fraction-to-recurring-decimal_1_AC.cpp │ ├── 0167_two-sum-ii-input-array-is-sorted_1_AC.cpp │ ├── 0168_excel-sheet-column-title_1_AC.cpp │ ├── 0169_majority-element_1_AC.cpp │ ├── 0170_two-sum-iii-data-structure-design_1_AC.cpp │ ├── 0170_two-sum-iii-data-structure-design_2_AC.py │ ├── 0171_excel-sheet-column-number_1_AC.cpp │ ├── 0172_factorial-trailing-zeroes_1_AC.cpp │ ├── 0173_binary-search-tree-iterator_1_AC.cpp │ ├── 0174_dungeon-game_1_AC.cpp │ ├── 0179_largest-number_1_AC.cpp │ ├── 0186_reverse-words-in-a-string-ii_1_AC.cpp │ ├── 0187_repeated-dna-sequences_1_AC.cpp │ ├── 0188_best-time-to-buy-and-sell-stock-iv_1_AC.cpp │ ├── 0188_best-time-to-buy-and-sell-stock-iv_2_AC.cpp │ ├── 0189_rotate-array_1_AC.cpp │ ├── 0190_reverse-bits_1_AC.cpp │ ├── 0190_reverse-bits_2_AC.cpp │ ├── 0191_number-of-1-bits_1_AC.cpp │ ├── 0198_house-robber_1_AC.cpp │ ├── 0199_binary-tree-right-side-view_1_AC.cpp │ ├── 0199_binary-tree-right-side-view_2_AC.cpp │ ├── 0200_number-of-islands_1_AC.cpp │ ├── 0201_bitwise-and-of-numbers-range_1_AC.cpp │ ├── 0202_happy-number_1_AC.cpp │ ├── 0202_happy-number_2_AC.py │ ├── 0203_remove-linked-list-elements_1_AC.cpp │ ├── 0204_count-primes_1_AC.cpp │ ├── 0205_isomorphic-strings_1_AC.cpp │ ├── 0206_reverse-linked-list_1_AC.cpp │ ├── 0207_course-schedule_1_AC.cpp │ ├── 0208_implement-trie-prefix-tree_1_AC.cpp │ ├── 0209_minimum-size-subarray-sum_1_AC.cpp │ ├── 0210_course-schedule-ii_1_AC.cpp │ ├── 0211_design-add-and-search-words-data-structure_1_AC.cpp │ ├── 0212_word-search-ii_1_AC.cpp │ ├── 0213_house-robber-ii_1_AC.cpp │ ├── 0214_shortest-palindrome_1_AC.cpp │ ├── 0215_kth-largest-element-in-an-array_1_AC.cpp │ ├── 0216_combination-sum-iii_1_AC.cpp │ ├── 0217_contains-duplicate_1_AC.cpp │ ├── 0218_the-skyline-problem_1_AC.cpp │ ├── 0219_contains-duplicate-ii_1_AC.cpp │ ├── 0220_contains-duplicate-iii_1_AC.cpp │ ├── 0221_maximal-square_1_AC.cpp │ ├── 0222_count-complete-tree-nodes_1_AC.cpp │ ├── 0223_rectangle-area_1_AC.cpp │ ├── 0224_basic-calculator_1_AC.cpp │ ├── 0225_implement-stack-using-queues_1_AC.cpp │ ├── 0226_invert-binary-tree_1_AC.cpp │ ├── 0227_basic-calculator-ii_1_AC.cpp │ ├── 0228_summary-ranges_1_AC.cpp │ ├── 0229_majority-element-ii_1_AC.cpp │ ├── 0230_kth-smallest-element-in-a-bst_1_AC.cpp │ ├── 0231_power-of-two_1_AC.cpp │ ├── 0232_implement-queue-using-stacks_1_AC.cpp │ ├── 0233_number-of-digit-one_1_AC.cpp │ ├── 0234_palindrome-linked-list_1_AC.cpp │ ├── 0235_lowest-common-ancestor-of-a-binary-search-tree_1_AC.cpp │ ├── 0236_lowest-common-ancestor-of-a-binary-tree_1_AC.cpp │ ├── 0237_delete-node-in-a-linked-list_1_AC.cpp │ ├── 0238_product-of-array-except-self_1_AC.cpp │ ├── 0239_sliding-window-maximum_1_AC.cpp │ ├── 0240_search-a-2d-matrix-ii_1_AC.cpp │ ├── 0241_different-ways-to-add-parentheses_1_AC.cpp │ ├── 0242_valid-anagram_1_AC.cpp │ ├── 0242_valid-anagram_2_AC.cpp │ ├── 0242_valid-anagram_3_AC.cpp │ ├── 0243_shortest-word-distance_1_AC.cpp │ ├── 0244_shortest-word-distance-ii_1_AC.cpp │ ├── 0245_shortest-word-distance-iii_1_AC.cpp │ ├── 0246_strobogrammatic-number_1_AC.cpp │ ├── 0247_strobogrammatic-number-ii_1_AC.cpp │ ├── 0248_strobogrammatic-number-iii_1_AC.cpp │ ├── 0249_group-shifted-strings_1_AC.cpp │ ├── 0250_count-univalue-subtrees_1_AC.cpp │ ├── 0251_flatten-2d-vector_1_AC.cpp │ ├── 0252_meeting-rooms_1_AC.cpp │ ├── 0253_meeting-rooms-ii_1_AC.cpp │ ├── 0254_factor-combinations_1_AC.cpp │ ├── 0255_verify-preorder-sequence-in-binary-search-tree_1_AC.cpp │ ├── 0256_paint-house_1_AC.cpp │ ├── 0257_binary-tree-paths_1_AC.cpp │ ├── 0258_add-digits_1_AC.cpp │ ├── 0259_3sum-smaller_1_AC.cpp │ ├── 0260_single-number-iii_1_AC.cpp │ ├── 0261_graph-valid-tree_1_AC.cpp │ ├── 0263_ugly-number_1_AC.cpp │ ├── 0264_ugly-number-ii_1_AC.cpp │ ├── 0265_paint-house-ii_1_AC.cpp │ ├── 0266_palindrome-permutation_1_AC.cpp │ ├── 0267_palindrome-permutation-ii_1_AC.cpp │ ├── 0268_missing-number_1_AC.cpp │ ├── 0269_alien-dictionary_1_AC.cpp │ ├── 0270_closest-binary-search-tree-value_1_AC.cpp │ ├── 0271_encode-and-decode-strings_1_AC.cpp │ ├── 0272_closest-binary-search-tree-value-ii_1_AC.cpp │ ├── 0273_integer-to-english-words_1_AC.cpp │ ├── 0274_h-index_1_AC.cpp │ ├── 0275_h-index-ii_1_AC.cpp │ ├── 0276_paint-fence_1_AC.cpp │ ├── 0277_find-the-celebrity_1_AC.cpp │ ├── 0278_first-bad-version_1_AC.cpp │ ├── 0279_perfect-squares_1_AC.cpp │ ├── 0280_wiggle-sort_1_AC.cpp │ ├── 0281_zigzag-iterator_1_AC.cpp │ ├── 0282_expression-add-operators_1_AC.cpp │ ├── 0283_move-zeroes_1_AC.cpp │ ├── 0284_peeking-iterator_1_AC.cpp │ ├── 0285_inorder-successor-in-bst_1_AC.cpp │ ├── 0286_walls-and-gates_1_AC.cpp │ ├── 0287_find-the-duplicate-number_1_AC.cpp │ ├── 0287_find-the-duplicate-number_2_AC.cpp │ ├── 0288_unique-word-abbreviation_1_AC.cpp │ ├── 0289_game-of-life_1_AC.cpp │ ├── 0290_word-pattern_1_AC.cpp │ ├── 0291_word-pattern-ii_1_AC.cpp │ ├── 0292_nim-game_1_AC.cpp │ ├── 0293_flip-game_1_AC.cpp │ ├── 0294_flip-game-ii_1_AC.cpp │ ├── 0295_find-median-from-data-stream_1_AC.cpp │ ├── 0296_best-meeting-point_1_AC.cpp │ ├── 0297_serialize-and-deserialize-binary-tree_1_AC.cpp │ ├── 0298_binary-tree-longest-consecutive-sequence_1_AC.cpp │ ├── 0299_bulls-and-cows_1_AC.cpp │ ├── 0300_longest-increasing-subsequence_1_AC.cpp │ ├── 0301_remove-invalid-parentheses_1_AC.cpp │ ├── 0302_smallest-rectangle-enclosing-black-pixels_1_AC.cpp │ ├── 0302_smallest-rectangle-enclosing-black-pixels_2_AC.cpp │ ├── 0303_range-sum-query-immutable_1_AC.cpp │ ├── 0304_range-sum-query-2d-immutable_1_AC.cpp │ ├── 0305_number-of-islands-ii_1_AC.cpp │ ├── 0306_additive-number_1_AC.cpp │ ├── 0307_range-sum-query-mutable_1_AC.cpp │ ├── 0308_range-sum-query-2d-mutable_1_AC.cpp │ ├── 0309_best-time-to-buy-and-sell-stock-with-cooldown_1_AC.cpp │ ├── 0310_minimum-height-trees_1_AC.cpp │ ├── 0311_sparse-matrix-multiplication_1_AC.cpp │ ├── 0312_burst-balloons_1_AC.cpp │ ├── 0313_super-ugly-number_1_AC.cpp │ ├── 0314_binary-tree-vertical-order-traversal_1_AC.cpp │ ├── 0315_count-of-smaller-numbers-after-self_1_AC.cpp │ ├── 0316_remove-duplicate-letters_1_AC.cpp │ ├── 0317_shortest-distance-from-all-buildings_1_AC.cpp │ ├── 0318_maximum-product-of-word-lengths_1_AC.cpp │ ├── 0319_bulb-switcher_1_AC.cpp │ ├── 0320_generalized-abbreviation_1_AC.cpp │ ├── 0321_create-maximum-number_1_AC.cpp │ ├── 0322_coin-change_1_AC.cpp │ ├── 0323_number-of-connected-components-in-an-undirected-graph_1_AC.cpp │ ├── 0324_wiggle-sort-ii_1_AC.cpp │ ├── 0325_maximum-size-subarray-sum-equals-k_1_AC.cpp │ ├── 0326_power-of-three_1_AC.cpp │ ├── 0326_power-of-three_2_AC.cpp │ ├── 0327_count-of-range-sum_1_AC.cpp │ ├── 0328_odd-even-linked-list_1_AC.cpp │ ├── 0329_longest-increasing-path-in-a-matrix_1_AC.cpp │ ├── 0330_patching-array_1_AC.cpp │ ├── 0331_verify-preorder-serialization-of-a-binary-tree_1_AC.cpp │ ├── 0332_reconstruct-itinerary_1_AC.cpp │ ├── 0333_largest-bst-subtree_1_AC.cpp │ ├── 0334_increasing-triplet-subsequence_1_AC.cpp │ ├── 0335_self-crossing_1_AC.cpp │ ├── 0336_palindrome-pairs_1_AC.cpp │ ├── 0336_palindrome-pairs_2_AC.py │ ├── 0337_house-robber-iii_1_AC.cpp │ ├── 0338_counting-bits_1_AC.cpp │ ├── 0339_nested-list-weight-sum_1_AC.cpp │ ├── 0340_longest-substring-with-at-most-k-distinct-characters_1_AC.cpp │ ├── 0341_flatten-nested-list-iterator_1_AC.cpp │ ├── 0342_power-of-four_1_AC.cpp │ ├── 0342_power-of-four_2_AC.cpp │ ├── 0343_integer-break_1_AC.cpp │ ├── 0344_reverse-string_1_AC.cpp │ ├── 0344_reverse-string_2_AC.cpp │ ├── 0345_reverse-vowels-of-a-string_1_AC.cpp │ ├── 0346_moving-average-from-data-stream_1_AC.cpp │ ├── 0347_top-k-frequent-elements_1_AC.cpp │ ├── 0348_design-tic-tac-toe_1_AC.cpp │ ├── 0349_intersection-of-two-arrays_1_AC.cpp │ ├── 0350_intersection-of-two-arrays-ii_1_AC.cpp │ ├── 0351_android-unlock-patterns_1_AC.cpp │ ├── 0352_data-stream-as-disjoint-intervals_1_AC.cpp │ ├── 0353_design-snake-game_1_AC.cpp │ ├── 0354_russian-doll-envelopes_1_AC.cpp │ ├── 0354_russian-doll-envelopes_2_AC.cpp │ ├── 0355_design-twitter_1_AC.cpp │ ├── 0356_line-reflection_1_AC.cpp │ ├── 0357_count-numbers-with-unique-digits_1_AC.cpp │ ├── 0358_rearrange-string-k-distance-apart_1_AC.cpp │ ├── 0359_logger-rate-limiter_1_AC.cpp │ ├── 0360_sort-transformed-array_1_AC.cpp │ ├── 0361_bomb-enemy_1_AC.cpp │ ├── 0362_design-hit-counter_1_AC.cpp │ ├── 0363_max-sum-of-rectangle-no-larger-than-k_1_AC.cpp │ ├── 0364_nested-list-weight-sum-ii_1_AC.cpp │ ├── 0365_water-and-jug-problem_1_AC.cpp │ ├── 0366_find-leaves-of-binary-tree_1_AC.cpp │ ├── 0367_valid-perfect-square_1_AC.cpp │ ├── 0368_largest-divisible-subset_1_AC.cpp │ ├── 0369_plus-one-linked-list_1_AC.cpp │ ├── 0370_range-addition_1_AC.cpp │ ├── 0371_sum-of-two-integers_1_AC.cpp │ ├── 0372_super-pow_1_AC.cpp │ ├── 0373_find-k-pairs-with-smallest-sums_1_AC.cpp │ ├── 0374_guess-number-higher-or-lower_1_AC.cpp │ ├── 0375_guess-number-higher-or-lower-ii_1_AC.cpp │ ├── 0376_wiggle-subsequence_1_AC.cpp │ ├── 0377_combination-sum-iv_1_AC.cpp │ ├── 0378_kth-smallest-element-in-a-sorted-matrix_1_AC.cpp │ ├── 0379_design-phone-directory_1_AC.cpp │ ├── 0379_design-phone-directory_2_AC.cpp │ ├── 0380_insert-delete-getrandom-o1_1_AC.cpp │ ├── 0381_insert-delete-getrandom-o1-duplicates-allowed_1_AC.cpp │ ├── 0382_linked-list-random-node_1_AC.cpp │ ├── 0383_ransom-note_1_AC.cpp │ ├── 0384_shuffle-an-array_1_AC.cpp │ ├── 0385_mini-parser_1_AC.cpp │ ├── 0386_lexicographical-numbers_1_AC.cpp │ ├── 0387_first-unique-character-in-a-string_1_AC.cpp │ ├── 0388_longest-absolute-file-path_1_AC.cpp │ ├── 0389_find-the-difference_1_AC.cpp │ ├── 0389_find-the-difference_2_AC.cpp │ ├── 0390_elimination-game_1_AC.cpp │ ├── 0391_perfect-rectangle_1_AC.cpp │ ├── 0392_is-subsequence_1_AC.cpp │ ├── 0393_utf-8-validation_1_AC.cpp │ ├── 0394_decode-string_1_AC.cpp │ ├── 0395_longest-substring-with-at-least-k-repeating-characters_1_AC.cpp │ ├── 0396_rotate-function_1_AC.cpp │ ├── 0397_integer-replacement_1_AC.cpp │ ├── 0398_random-pick-index_1_AC.cpp │ ├── 0398_random-pick-index_2_AC.py │ ├── 0399_evaluate-division_1_AC.cpp │ ├── 0400_nth-digit_1_AC.cpp │ ├── 0401_binary-watch_1_AC.cpp │ ├── 0402_remove-k-digits_1_AC.cpp │ ├── 0403_frog-jump_1_AC.cpp │ ├── 0404_sum-of-left-leaves_1_AC.cpp │ ├── 0405_convert-a-number-to-hexadecimal_1_AC.cpp │ ├── 0406_queue-reconstruction-by-height_1_AC.cpp │ ├── 0406_queue-reconstruction-by-height_2_AC.cpp │ ├── 0407_trapping-rain-water-ii_1_AC.cpp │ ├── 0408_valid-word-abbreviation_1_AC.cpp │ ├── 0409_longest-palindrome_1_AC.cpp │ ├── 0410_split-array-largest-sum_1_AC.cpp │ ├── 0410_split-array-largest-sum_2_AC.cpp │ ├── 0410_split-array-largest-sum_3_AC.py │ ├── 0411_minimum-unique-word-abbreviation_1_AC.cpp │ ├── 0412_fizz-buzz_1_AC.cpp │ ├── 0413_arithmetic-slices_1_AC.cpp │ ├── 0414_third-maximum-number_1_AC.cpp │ ├── 0415_add-strings_1_AC.cpp │ ├── 0416_partition-equal-subset-sum_1_AC.cpp │ ├── 0417_pacific-atlantic-water-flow_1_AC.cpp │ ├── 0418_sentence-screen-fitting_1_AC.cpp │ ├── 0419_battleships-in-a-board_1_AC.cpp │ ├── 0420_strong-password-checker_1_AC.cpp │ ├── 0421_maximum-xor-of-two-numbers-in-an-array_1_AC.cpp │ ├── 0422_valid-word-square_1_AC.cpp │ ├── 0423_reconstruct-original-digits-from-english_1_AC.cpp │ ├── 0424_longest-repeating-character-replacement_1_AC.cpp │ ├── 0425_word-squares_1_AC.cpp │ ├── 0426_convert-binary-search-tree-to-sorted-doubly-linked-list_1_AC.py │ ├── 0427_construct-quad-tree_1_AC.cpp │ ├── 0428_serialize-and-deserialize-n-ary-tree_1_AC.py │ ├── 0429_n-ary-tree-level-order-traversal_1_AC.cpp │ ├── 0430_flatten-a-multilevel-doubly-linked-list_1_AC.py │ ├── 0431_encode-n-ary-tree-to-binary-tree_1_AC.py │ ├── 0432_all-oone-data-structure_1_AC.cpp │ ├── 0432_all-oone-data-structure_2_AC.py │ ├── 0433_minimum-genetic-mutation_1_AC.py │ ├── 0434_number-of-segments-in-a-string_1_AC.cpp │ ├── 0435_non-overlapping-intervals_1_AC.cpp │ ├── 0435_non-overlapping-intervals_2_AC.cpp │ ├── 0436_find-right-interval_1_AC.cpp │ ├── 0437_path-sum-iii_1_AC.cpp │ ├── 0437_path-sum-iii_2_AC.cpp │ ├── 0438_find-all-anagrams-in-a-string_1_AC.cpp │ ├── 0439_ternary-expression-parser_1_AC.cpp │ ├── 0440_k-th-smallest-in-lexicographical-order_1_AC.cpp │ ├── 0441_arranging-coins_1_AC.cpp │ ├── 0442_find-all-duplicates-in-an-array_1_AC.cpp │ ├── 0443_string-compression_1_AC.cpp │ ├── 0444_sequence-reconstruction_1_AC.cpp │ ├── 0445_add-two-numbers-ii_1_AC.cpp │ ├── 0446_arithmetic-slices-ii-subsequence_1_AC.cpp │ ├── 0447_number-of-boomerangs_1_AC.cpp │ ├── 0448_find-all-numbers-disappeared-in-an-array_1_AC.cpp │ ├── 0448_find-all-numbers-disappeared-in-an-array_2_AC.cpp │ ├── 0449_serialize-and-deserialize-bst_1_AC.cpp │ ├── 0450_delete-node-in-a-bst_1_AC.cpp │ ├── 0451_sort-characters-by-frequency_1_AC.cpp │ ├── 0452_minimum-number-of-arrows-to-burst-balloons_1_AC.cpp │ ├── 0453_minimum-moves-to-equal-array-elements_1_AC.cpp │ ├── 0454_4sum-ii_1_AC.cpp │ ├── 0455_assign-cookies_1_AC.cpp │ ├── 0456_132-pattern_1_AC.cpp │ ├── 0457_circular-array-loop_1_AC.py │ ├── 0459_repeated-substring-pattern_1_AC.cpp │ ├── 0460_lfu-cache_1_AC.cpp │ ├── 0461_hamming-distance_1_AC.cpp │ ├── 0462_minimum-moves-to-equal-array-elements-ii_1_AC.cpp │ ├── 0463_island-perimeter_1_AC.cpp │ ├── 0464_can-i-win_1_AC.cpp │ ├── 0465_optimal-account-balancing_1_AC.cpp │ ├── 0466_count-the-repetitions_1_AC.cpp │ ├── 0467_unique-substrings-in-wraparound-string_1_AC.cpp │ ├── 0468_validate-ip-address_1_AC.cpp │ ├── 0469_convex-polygon_1_AC.cpp │ ├── 0470_implement-rand10-using-rand7_1_AC.py │ ├── 0471_encode-string-with-shortest-length_1_AC.cpp │ ├── 0472_concatenated-words_1_AC.cpp │ ├── 0473_matchsticks-to-square_1_AC.cpp │ ├── 0474_ones-and-zeroes_1_AC.cpp │ ├── 0475_heaters_1_AC.cpp │ ├── 0476_number-complement_1_AC.cpp │ ├── 0477_total-hamming-distance_1_AC.cpp │ ├── 0478_generate-random-point-in-a-circle_1_AC.py │ ├── 0479_largest-palindrome-product_1_AC.cpp │ ├── 0480_sliding-window-median_1_AC.cpp │ ├── 0481_magical-string_1_AC.cpp │ ├── 0482_license-key-formatting_1_AC.cpp │ ├── 0483_smallest-good-base_1_AC.cpp │ ├── 0484_find-permutation_1_AC.cpp │ ├── 0485_max-consecutive-ones_1_AC.cpp │ ├── 0486_predict-the-winner_1_AC.cpp │ ├── 0487_max-consecutive-ones-ii_1_AC.cpp │ ├── 0488_zuma-game_1_AC.cpp │ ├── 0489_robot-room-cleaner_1_AC.py │ ├── 0490_the-maze_1_AC.cpp │ ├── 0491_non-decreasing-subsequences_1_AC.cpp │ ├── 0492_construct-the-rectangle_1_AC.cpp │ ├── 0493_reverse-pairs_1_AC.cpp │ ├── 0494_target-sum_1_AC.cpp │ ├── 0495_teemo-attacking_1_AC.cpp │ ├── 0496_next-greater-element-i_1_AC.cpp │ ├── 0497_random-point-in-non-overlapping-rectangles_1_AC.py │ ├── 0498_diagonal-traverse_1_AC.cpp │ ├── 0499_the-maze-iii_1_AC.cpp │ └── 0500_keyboard-row_1_AC.cpp ├── 0501-1000 │ ├── 0501_find-mode-in-binary-search-tree_1_AC.cpp │ ├── 0502_ipo_1_AC.cpp │ ├── 0503_next-greater-element-ii_1_AC.cpp │ ├── 0504_base-7_1_AC.cpp │ ├── 0505_the-maze-ii_1_AC.cpp │ ├── 0506_relative-ranks_1_AC.cpp │ ├── 0507_perfect-number_1_AC.cpp │ ├── 0508_most-frequent-subtree-sum_1_AC.cpp │ ├── 0509_fibonacci-number_1_AC.cpp │ ├── 0510_inorder-successor-in-bst-ii_1_AC.py │ ├── 0513_find-bottom-left-tree-value_1_AC.cpp │ ├── 0514_freedom-trail_1_AC.cpp │ ├── 0515_find-largest-value-in-each-tree-row_1_AC.cpp │ ├── 0516_longest-palindromic-subsequence_1_AC.cpp │ ├── 0517_super-washing-machines_1_AC.cpp │ ├── 0518_coin-change-ii_1_AC.py │ ├── 0519_random-flip-matrix_1_AC.py │ ├── 0519_random-flip-matrix_2_AC.py │ ├── 0520_detect-capital_1_AC.cpp │ ├── 0521_longest-uncommon-subsequence-i_1_AC.cpp │ ├── 0522_longest-uncommon-subsequence-ii_1_AC.cpp │ ├── 0523_continuous-subarray-sum_1_AC.cpp │ ├── 0524_longest-word-in-dictionary-through-deleting_1_AC.cpp │ ├── 0525_contiguous-array_1_AC.cpp │ ├── 0526_beautiful-arrangement_1_AC.cpp │ ├── 0527_word-abbreviation_1_AC.cpp │ ├── 0528_random-pick-with-weight_1_AC.py │ ├── 0529_minesweeper_1_AC.cpp │ ├── 0530_minimum-absolute-difference-in-bst_1_AC.cpp │ ├── 0531_lonely-pixel-i_1_AC.cpp │ ├── 0532_k-diff-pairs-in-an-array_1_AC.cpp │ ├── 0533_lonely-pixel-ii_1_AC.cpp │ ├── 0535_encode-and-decode-tinyurl_1_AC.cpp │ ├── 0536_construct-binary-tree-from-string_1_AC.cpp │ ├── 0537_complex-number-multiplication_1_AC.cpp │ ├── 0538_convert-bst-to-greater-tree_1_AC.cpp │ ├── 0539_minimum-time-difference_1_AC.cpp │ ├── 0540_single-element-in-a-sorted-array_1_AC.cpp │ ├── 0541_reverse-string-ii_1_AC.cpp │ ├── 0542_01-matrix_1_AC.cpp │ ├── 0543_diameter-of-binary-tree_1_AC.cpp │ ├── 0544_output-contest-matches_1_AC.cpp │ ├── 0545_boundary-of-binary-tree_1_AC.py │ ├── 0546_remove-boxes_1_AC.cpp │ ├── 0547_number-of-provinces_1_AC.cpp │ ├── 0548_split-array-with-equal-sum_1_AC.py │ ├── 0549_binary-tree-longest-consecutive-sequence-ii_1_AC.py │ ├── 0551_student-attendance-record-i_1_AC.cpp │ ├── 0552_student-attendance-record-ii_1_AC.cpp │ ├── 0553_optimal-division_1_AC.cpp │ ├── 0554_brick-wall_1_AC.cpp │ ├── 0555_split-concatenated-strings_1_AC.py │ ├── 0556_next-greater-element-iii_1_AC.cpp │ ├── 0557_reverse-words-in-a-string-iii_1_AC.cpp │ ├── 0558_logical-or-of-two-binary-grids-represented-as-quad-trees_1_AC.cpp │ ├── 0559_maximum-depth-of-n-ary-tree_1_AC.cpp │ ├── 0560_subarray-sum-equals-k_1_AC.cpp │ ├── 0561_array-partition_1_AC.cpp │ ├── 0562_longest-line-of-consecutive-one-in-matrix_1_AC.py │ ├── 0563_binary-tree-tilt_1_AC.cpp │ ├── 0564_find-the-closest-palindrome_1_AC.cpp │ ├── 0565_array-nesting_1_AC.cpp │ ├── 0566_reshape-the-matrix_1_AC.cpp │ ├── 0567_permutation-in-string_1_AC.cpp │ ├── 0568_maximum-vacation-days_1_AC.py │ ├── 0572_subtree-of-another-tree_1_AC.cpp │ ├── 0573_squirrel-simulation_1_AC.py │ ├── 0575_distribute-candies_1_AC.cpp │ ├── 0576_out-of-boundary-paths_1_AC.cpp │ ├── 0581_shortest-unsorted-continuous-subarray_1_AC.cpp │ ├── 0582_kill-process_1_AC.cpp │ ├── 0583_delete-operation-for-two-strings_1_AC.cpp │ ├── 0587_erect-the-fence_1_AC.cpp │ ├── 0588_design-in-memory-file-system_1_AC.cpp │ ├── 0589_n-ary-tree-preorder-traversal_1_AC.cpp │ ├── 0590_n-ary-tree-postorder-traversal_1_AC.cpp │ ├── 0591_tag-validator_1_AC.cpp │ ├── 0592_fraction-addition-and-subtraction_1_AC.cpp │ ├── 0593_valid-square_1_AC.cpp │ ├── 0594_longest-harmonious-subsequence_1_AC.cpp │ ├── 0598_range-addition-ii_1_AC.cpp │ ├── 0599_minimum-index-sum-of-two-lists_1_AC.cpp │ ├── 0600_non-negative-integers-without-consecutive-ones_1_AC.cpp │ ├── 0604_design-compressed-string-iterator_1_AC.py │ ├── 0605_can-place-flowers_1_AC.cpp │ ├── 0606_construct-string-from-binary-tree_1_AC.cpp │ ├── 0609_find-duplicate-file-in-system_1_AC.cpp │ ├── 0611_valid-triangle-number_1_AC.cpp │ ├── 0616_add-bold-tag-in-string_1_AC.py │ ├── 0617_merge-two-binary-trees_1_AC.cpp │ ├── 0621_task-scheduler_1_AC.cpp │ ├── 0622_design-circular-queue_1_AC.py │ ├── 0623_add-one-row-to-tree_1_AC.cpp │ ├── 0624_maximum-distance-in-arrays_1_AC.cpp │ ├── 0625_minimum-factorization_1_AC.cpp │ ├── 0628_maximum-product-of-three-numbers_1_AC.cpp │ ├── 0629_k-inverse-pairs-array_1_AC.cpp │ ├── 0630_course-schedule-iii_1_AC.cpp │ ├── 0632_smallest-range-covering-elements-from-k-lists_1_AC.cpp │ ├── 0633_sum-of-square-numbers_1_AC.cpp │ ├── 0634_find-the-derangement-of-an-array_1_AC.py │ ├── 0635_design-log-storage-system_1_AC.cpp │ ├── 0636_exclusive-time-of-functions_1_AC.cpp │ ├── 0637_average-of-levels-in-binary-tree_1_AC.cpp │ ├── 0638_shopping-offers_1_AC.cpp │ ├── 0639_decode-ways-ii_1_AC.cpp │ ├── 0640_solve-the-equation_1_AC.cpp │ ├── 0641_design-circular-deque_1_AC.py │ ├── 0642_design-search-autocomplete-system_1_AC.py │ ├── 0643_maximum-average-subarray-i_1_AC.cpp │ ├── 0644_maximum-average-subarray-ii_1_AC.cpp │ ├── 0645_set-mismatch_1_AC.cpp │ ├── 0646_maximum-length-of-pair-chain_1_AC.cpp │ ├── 0647_palindromic-substrings_1_AC.cpp │ ├── 0648_replace-words_1_AC.cpp │ ├── 0649_dota2-senate_1_AC.cpp │ ├── 0650_2-keys-keyboard_1_AC.cpp │ ├── 0651_4-keys-keyboard_1_AC.py │ ├── 0652_find-duplicate-subtrees_1_AC.cpp │ ├── 0653_two-sum-iv-input-is-a-bst_1_AC.cpp │ ├── 0654_maximum-binary-tree_1_AC.cpp │ ├── 0654_maximum-binary-tree_2_AC.cpp │ ├── 0655_print-binary-tree_1_AC.cpp │ ├── 0657_robot-return-to-origin_1_AC.cpp │ ├── 0658_find-k-closest-elements_1_AC.cpp │ ├── 0659_split-array-into-consecutive-subsequences_1_AC.cpp │ ├── 0661_image-smoother_1_AC.cpp │ ├── 0662_maximum-width-of-binary-tree_1_AC.cpp │ ├── 0663_equal-tree-partition_1_AC.py │ ├── 0665_non-decreasing-array_1_AC.cpp │ ├── 0666_path-sum-iv_1_AC.py │ ├── 0667_beautiful-arrangement-ii_1_AC.cpp │ ├── 0669_trim-a-binary-search-tree_1_AC.cpp │ ├── 0670_maximum-swap_1_AC.cpp │ ├── 0671_second-minimum-node-in-a-binary-tree_1_AC.cpp │ ├── 0672_bulb-switcher-ii_1_AC.cpp │ ├── 0673_number-of-longest-increasing-subsequence_1_AC.py │ ├── 0674_longest-continuous-increasing-subsequence_1_AC.cpp │ ├── 0675_cut-off-trees-for-golf-event_1_AC.py │ ├── 0676_implement-magic-dictionary_1_AC.cpp │ ├── 0677_map-sum-pairs_1_AC.cpp │ ├── 0678_valid-parenthesis-string_1_AC.py │ ├── 0678_valid-parenthesis-string_2_AC.py │ ├── 0679_24-game_1_AC.py │ ├── 0680_valid-palindrome-ii_1_AC.cpp │ ├── 0681_next-closest-time_1_AC.py │ ├── 0682_baseball-game_1_AC.cpp │ ├── 0684_redundant-connection_1_AC.cpp │ ├── 0686_repeated-string-match_1_AC.cpp │ ├── 0687_longest-univalue-path_1_AC.cpp │ ├── 0688_knight-probability-in-chessboard_1_AC.cpp │ ├── 0690_employee-importance_1_AC.cpp │ ├── 0692_top-k-frequent-words_1_AC.cpp │ ├── 0693_binary-number-with-alternating-bits_1_AC.cpp │ ├── 0694_number-of-distinct-islands_1_AC.py │ ├── 0695_max-area-of-island_1_AC.cpp │ ├── 0696_count-binary-substrings_1_AC.cpp │ ├── 0697_degree-of-an-array_1_AC.cpp │ ├── 0698_partition-to-k-equal-sum-subsets_1_AC.cpp │ ├── 0700_search-in-a-binary-search-tree_1_AC.cpp │ ├── 0701_insert-into-a-binary-search-tree_1_AC.py │ ├── 0702_search-in-a-sorted-array-of-unknown-size_1_AC.py │ ├── 0703_kth-largest-element-in-a-stream_1_AC.cpp │ ├── 0704_binary-search_1_AC.cpp │ ├── 0705_design-hashset_1_AC.cpp │ ├── 0706_design-hashmap_1_AC.cpp │ ├── 0707_design-linked-list_1_AC.cpp │ ├── 0708_insert-into-a-sorted-circular-linked-list_1_AC.py │ ├── 0709_to-lower-case_1_AC.cpp │ ├── 0712_minimum-ascii-delete-sum-for-two-strings_1_AC.cpp │ ├── 0713_subarray-product-less-than-k_1_AC.cpp │ ├── 0714_best-time-to-buy-and-sell-stock-with-transaction-fee_1_AC.cpp │ ├── 0716_max-stack_1_AC.py │ ├── 0717_1-bit-and-2-bit-characters_1_AC.cpp │ ├── 0718_maximum-length-of-repeated-subarray_1_AC.cpp │ ├── 0719_find-k-th-smallest-pair-distance_1_AC.py │ ├── 0720_longest-word-in-dictionary_1_AC.cpp │ ├── 0721_accounts-merge_1_AC.py │ ├── 0722_remove-comments_1_AC.py │ ├── 0723_candy-crush_1_AC.py │ ├── 0724_find-pivot-index_1_AC.cpp │ ├── 0725_split-linked-list-in-parts_1_AC.cpp │ ├── 0726_number-of-atoms_1_AC.py │ ├── 0728_self-dividing-numbers_1_AC.cpp │ ├── 0729_my-calendar-i_1_AC.cpp │ ├── 0731_my-calendar-ii_1_AC.py │ ├── 0732_my-calendar-iii_1_AC.py │ ├── 0733_flood-fill_1_AC.cpp │ ├── 0734_sentence-similarity_1_AC.cpp │ ├── 0735_asteroid-collision_1_AC.cpp │ ├── 0737_sentence-similarity-ii_1_AC.cpp │ ├── 0738_monotone-increasing-digits_1_AC.py │ ├── 0739_daily-temperatures_1_AC.py │ ├── 0740_delete-and-earn_1_AC.py │ ├── 0741_cherry-pickup_1_AC.py │ ├── 0742_closest-leaf-in-a-binary-tree_1_AC.py │ ├── 0743_network-delay-time_1_AC.cpp │ ├── 0744_find-smallest-letter-greater-than-target_1_AC.cpp │ ├── 0745_prefix-and-suffix-search_1_AC.cpp │ ├── 0746_min-cost-climbing-stairs_1_AC.cpp │ ├── 0747_largest-number-at-least-twice-of-others_1_AC.cpp │ ├── 0748_shortest-completing-word_1_AC.cpp │ ├── 0749_contain-virus_1_AC.cpp │ ├── 0750_number-of-corner-rectangles_1_AC.py │ ├── 0751_ip-to-cidr_1_AC.py │ ├── 0752_open-the-lock_1_AC.py │ ├── 0753_cracking-the-safe_1_AC.py │ ├── 0754_reach-a-number_1_AC.cpp │ ├── 0755_pour-water_1_AC.py │ ├── 0756_pyramid-transition-matrix_1_AC.py │ ├── 0758_bold-words-in-string_1_AC.py │ ├── 0759_employee-free-time_1_AC.py │ ├── 0760_find-anagram-mappings_1_AC.py │ ├── 0761_special-binary-string_1_AC.py │ ├── 0762_prime-number-of-set-bits-in-binary-representation_1_AC.cpp │ ├── 0763_partition-labels_1_AC.py │ ├── 0764_largest-plus-sign_1_AC.py │ ├── 0766_toeplitz-matrix_1_AC.py │ ├── 0767_reorganize-string_1_AC.py │ ├── 0769_max-chunks-to-make-sorted_1_AC.py │ ├── 0771_jewels-and-stones_1_AC.cpp │ ├── 0773_sliding-puzzle_1_AC.py │ ├── 0775_global-and-local-inversions_1_AC.py │ ├── 0776_split-bst_1_AC.py │ ├── 0777_swap-adjacent-in-lr-string_1_AC.py │ ├── 0779_k-th-symbol-in-grammar_1_AC.py │ ├── 0781_rabbits-in-forest_1_AC.py │ ├── 0783_minimum-distance-between-bst-nodes_1_AC.py │ ├── 0784_letter-case-permutation_1_AC.py │ ├── 0785_is-graph-bipartite_1_AC.py │ ├── 0786_k-th-smallest-prime-fraction_1_AC.py │ ├── 0787_cheapest-flights-within-k-stops_1_AC.py │ ├── 0788_rotated-digits_1_AC.py │ ├── 0789_escape-the-ghosts_1_AC.py │ ├── 0790_domino-and-tromino-tiling_1_AC.py │ ├── 0791_custom-sort-string_1_AC.py │ ├── 0792_number-of-matching-subsequences_1_AC.py │ ├── 0794_valid-tic-tac-toe-state_1_AC.py │ ├── 0795_number-of-subarrays-with-bounded-maximum_1_AC.py │ ├── 0796_rotate-string_1_AC.py │ ├── 0797_all-paths-from-source-to-target_1_AC.py │ ├── 0799_champagne-tower_1_AC.py │ ├── 0800_similar-rgb-color_1_AC.py │ ├── 0801_minimum-swaps-to-make-sequences-increasing_1_AC.py │ ├── 0802_find-eventual-safe-states_1_AC.py │ ├── 0804_unique-morse-code-words_1_AC.py │ ├── 0806_number-of-lines-to-write-string_1_AC.py │ ├── 0807_max-increase-to-keep-city-skyline_1_AC.py │ ├── 0808_soup-servings_1_AC.py │ ├── 0809_expressive-words_1_AC.py │ ├── 0811_subdomain-visit-count_1_AC.py │ ├── 0812_largest-triangle-area_1_AC.py │ ├── 0813_largest-sum-of-averages_1_AC.py │ ├── 0814_binary-tree-pruning_1_AC.py │ ├── 0815_bus-routes_1_AC.py │ ├── 0816_ambiguous-coordinates_1_AC.py │ ├── 0817_linked-list-components_1_AC.py │ ├── 0819_most-common-word_1_AC.py │ ├── 0820_short-encoding-of-words_1_AC.py │ ├── 0821_shortest-distance-to-a-character_1_AC.py │ ├── 0822_card-flipping-game_1_AC.py │ ├── 0823_binary-trees-with-factors_1_AC.py │ ├── 0824_goat-latin_1_AC.py │ ├── 0825_friends-of-appropriate-ages_1_AC.py │ ├── 0826_most-profit-assigning-work_1_AC.py │ ├── 0830_positions-of-large-groups_1_AC.py │ ├── 0831_masking-personal-information_1_AC.py │ ├── 0832_flipping-an-image_1_AC.py │ ├── 0833_find-and-replace-in-string_1_AC.py │ ├── 0834_sum-of-distances-in-tree_1_AC.py │ ├── 0835_image-overlap_1_AC.py │ ├── 0836_rectangle-overlap_1_AC.py │ ├── 0837_new-21-game_1_AC.py │ ├── 0838_push-dominoes_1_AC.py │ ├── 0840_magic-squares-in-grid_1_AC.py │ ├── 0841_keys-and-rooms_1_AC.py │ ├── 0842_split-array-into-fibonacci-sequence_1_AC.py │ ├── 0843_guess-the-word_1_AC.py │ ├── 0844_backspace-string-compare_1_AC.py │ ├── 0845_longest-mountain-in-array_1_AC.py │ ├── 0846_hand-of-straights_1_AC.py │ ├── 0847_shortest-path-visiting-all-nodes_1_AC.py │ ├── 0848_shifting-letters_1_AC.py │ ├── 0849_maximize-distance-to-closest-person_1_AC.py │ ├── 0851_loud-and-rich_1_AC.py │ ├── 0852_peak-index-in-a-mountain-array_1_AC.py │ ├── 0853_car-fleet_1_AC.py │ ├── 0855_exam-room_1_AC.py │ ├── 0856_score-of-parentheses_1_AC.py │ ├── 0857_minimum-cost-to-hire-k-workers_1_AC.py │ ├── 0858_mirror-reflection_1_AC.py │ ├── 0859_buddy-strings_1_AC.py │ ├── 0860_lemonade-change_1_AC.py │ ├── 0861_score-after-flipping-matrix_1_AC.py │ ├── 0863_all-nodes-distance-k-in-binary-tree_1_AC.py │ ├── 0865_smallest-subtree-with-all-the-deepest-nodes_1_AC.py │ ├── 0866_prime-palindrome_1_AC.py │ ├── 0867_transpose-matrix_1_AC.py │ ├── 0868_binary-gap_1_AC.py │ ├── 0869_reordered-power-of-2_1_AC.py │ ├── 0870_advantage-shuffle_1_AC.py │ ├── 0872_leaf-similar-trees_1_AC.py │ ├── 0873_length-of-longest-fibonacci-subsequence_1_AC.py │ ├── 0874_walking-robot-simulation_1_AC.py │ ├── 0875_koko-eating-bananas_1_AC.py │ ├── 0876_middle-of-the-linked-list_1_AC.py │ ├── 0877_stone-game_1_AC.py │ ├── 0877_stone-game_2_AC.py │ ├── 0880_decoded-string-at-index_1_AC.py │ ├── 0881_boats-to-save-people_1_AC.py │ ├── 0883_projection-area-of-3d-shapes_1_AC.py │ ├── 0884_uncommon-words-from-two-sentences_1_AC.py │ ├── 0885_spiral-matrix-iii_1_AC.py │ ├── 0886_possible-bipartition_1_AC.py │ ├── 0888_fair-candy-swap_1_AC.py │ ├── 0889_construct-binary-tree-from-preorder-and-postorder-traversal_1_AC.py │ ├── 0890_find-and-replace-pattern_1_AC.py │ ├── 0892_surface-area-of-3d-shapes_1_AC.py │ ├── 0893_groups-of-special-equivalent-strings_1_AC.py │ ├── 0894_all-possible-full-binary-trees_1_AC.py │ ├── 0895_maximum-frequency-stack_1_AC.py │ ├── 0896_monotonic-array_1_AC.py │ ├── 0897_increasing-order-search-tree_1_AC.py │ ├── 0898_bitwise-ors-of-subarrays_1_AC.py │ ├── 0899_orderly-queue_1_AC.py │ ├── 0900_rle-iterator_1_AC.py │ ├── 0901_online-stock-span_1_AC.py │ ├── 0904_fruit-into-baskets_1_AC.py │ ├── 0905_sort-array-by-parity_1_AC.py │ ├── 0908_smallest-range-i_1_AC.py │ ├── 0909_snakes-and-ladders_1_AC.py │ ├── 0910_smallest-range-ii_1_AC.py │ ├── 0911_online-election_1_AC.py │ ├── 0912_sort-an-array_1_AC.py │ ├── 0914_x-of-a-kind-in-a-deck-of-cards_1_AC.py │ ├── 0915_partition-array-into-disjoint-intervals_1_AC.py │ ├── 0916_word-subsets_1_AC.py │ ├── 0917_reverse-only-letters_1_AC.py │ ├── 0918_maximum-sum-circular-subarray_1_AC.py │ ├── 0919_complete-binary-tree-inserter_1_AC.py │ ├── 0921_minimum-add-to-make-parentheses-valid_1_AC.py │ ├── 0922_sort-array-by-parity-ii_1_AC.py │ ├── 0923_3sum-with-multiplicity_1_AC.py │ ├── 0925_long-pressed-name_1_AC.py │ ├── 0926_flip-string-to-monotone-increasing_1_AC.py │ ├── 0929_unique-email-addresses_1_AC.py │ ├── 0930_binary-subarrays-with-sum_1_AC.py │ ├── 0931_minimum-falling-path-sum_1_AC.py │ ├── 0932_beautiful-array_1_AC.py │ ├── 0933_number-of-recent-calls_1_AC.py │ ├── 0934_shortest-bridge_1_AC.py │ ├── 0935_knight-dialer_1_AC.py │ ├── 0937_reorder-data-in-log-files_1_AC.py │ ├── 0938_range-sum-of-bst_1_AC.cpp │ ├── 0939_minimum-area-rectangle_1_AC.py │ ├── 0941_valid-mountain-array_1_AC.py │ ├── 0942_di-string-match_1_AC.py │ ├── 0944_delete-columns-to-make-sorted_1_AC.py │ ├── 0945_minimum-increment-to-make-array-unique_1_AC.py │ ├── 0946_validate-stack-sequences_1_AC.py │ ├── 0947_most-stones-removed-with-same-row-or-column_1_AC.py │ ├── 0948_bag-of-tokens_1_AC.py │ ├── 0949_largest-time-for-given-digits_1_AC.py │ ├── 0950_reveal-cards-in-increasing-order_1_AC.py │ ├── 0951_flip-equivalent-binary-trees_1_AC.py │ ├── 0953_verifying-an-alien-dictionary_1_AC.py │ ├── 0954_array-of-doubled-pairs_1_AC.py │ ├── 0955_delete-columns-to-make-sorted-ii_1_AC.py │ ├── 0957_prison-cells-after-n-days_1_AC.py │ ├── 0958_check-completeness-of-a-binary-tree_1_AC.py │ ├── 0959_regions-cut-by-slashes_1_AC.py │ ├── 0961_n-repeated-element-in-size-2n-array_1_AC.py │ ├── 0962_maximum-width-ramp_1_AC.py │ ├── 0963_minimum-area-rectangle-ii_1_AC.py │ ├── 0965_univalued-binary-tree_1_AC.py │ ├── 0966_vowel-spellchecker_1_AC.py │ ├── 0967_numbers-with-same-consecutive-differences_1_AC.py │ ├── 0969_pancake-sorting_1_AC.py │ ├── 0970_powerful-integers_1_AC.py │ ├── 0971_flip-binary-tree-to-match-preorder-traversal_1_AC.py │ ├── 0973_k-closest-points-to-origin_1_AC.py │ ├── 0974_subarray-sums-divisible-by-k_1_AC.py │ ├── 0975_odd-even-jump_1_AC.py │ ├── 0976_largest-perimeter-triangle_1_AC.py │ ├── 0977_squares-of-a-sorted-array_1_AC.py │ ├── 0978_longest-turbulent-subarray_1_AC.py │ ├── 0979_distribute-coins-in-binary-tree_1_AC.py │ ├── 0980_unique-paths-iii_1_AC.py │ ├── 0981_time-based-key-value-store_1_AC.py │ ├── 0983_minimum-cost-for-tickets_1_AC.py │ ├── 0984_string-without-aaa-or-bbb_1_AC.py │ ├── 0985_sum-of-even-numbers-after-queries_1_AC.py │ ├── 0986_interval-list-intersections_1_AC.py │ ├── 0987_vertical-order-traversal-of-a-binary-tree_1_AC.py │ ├── 0988_smallest-string-starting-from-leaf_1_AC.py │ ├── 0989_add-to-array-form-of-integer_1_AC.py │ ├── 0990_satisfiability-of-equality-equations_1_AC.py │ ├── 0991_broken-calculator_1_AC.py │ ├── 0992_subarrays-with-k-different-integers_1_AC.py │ ├── 0993_cousins-in-binary-tree_1_AC.py │ ├── 0994_rotting-oranges_1_AC.py │ ├── 0995_minimum-number-of-k-consecutive-bit-flips_1_AC.py │ ├── 0997_find-the-town-judge_1_AC.py │ ├── 0998_maximum-binary-tree-ii_1_AC.py │ └── 0999_available-captures-for-rook_1_AC.py ├── 1001-1500 │ ├── 1002_find-common-characters_1_AC.py │ ├── 1003_check-if-word-is-valid-after-substitutions_1_AC.py │ ├── 1004_max-consecutive-ones-iii_1_AC.py │ ├── 1005_maximize-sum-of-array-after-k-negations_1_AC.py │ ├── 1006_clumsy-factorial_1_AC.py │ ├── 1007_minimum-domino-rotations-for-equal-row_1_AC.py │ ├── 1008_construct-binary-search-tree-from-preorder-traversal_1_AC.py │ ├── 1009_complement-of-base-10-integer_1_AC.py │ ├── 1010_pairs-of-songs-with-total-durations-divisible-by-60_1_AC.py │ ├── 1011_capacity-to-ship-packages-within-d-days_1_AC.py │ ├── 1013_partition-array-into-three-parts-with-equal-sum_1_AC.py │ ├── 1014_best-sightseeing-pair_1_AC.py │ ├── 1015_smallest-integer-divisible-by-k_1_AC.py │ ├── 1016_binary-string-with-substrings-representing-1-to-n_1_AC.py │ ├── 1017_convert-to-base-2_1_AC.py │ ├── 1018_binary-prefix-divisible-by-5_1_AC.py │ ├── 1019_next-greater-node-in-linked-list_1_AC.py │ ├── 1020_number-of-enclaves_1_AC.py │ ├── 1021_remove-outermost-parentheses_1_AC.py │ ├── 1022_sum-of-root-to-leaf-binary-numbers_1_AC.py │ ├── 1023_camelcase-matching_1_AC.py │ ├── 1024_video-stitching_1_AC.py │ ├── 1025_divisor-game_1_AC.py │ ├── 1026_maximum-difference-between-node-and-ancestor_1_AC.py │ ├── 1027_longest-arithmetic-subsequence_1_AC.py │ ├── 1028_recover-a-tree-from-preorder-traversal_1_AC.py │ ├── 1029_two-city-scheduling_1_AC.py │ ├── 1030_matrix-cells-in-distance-order_1_AC.py │ ├── 1031_maximum-sum-of-two-non-overlapping-subarrays_1_AC.py │ ├── 1033_moving-stones-until-consecutive_1_AC.py │ ├── 1034_coloring-a-border_1_AC.py │ ├── 1035_uncrossed-lines_1_AC.py │ ├── 1037_valid-boomerang_1_AC.py │ ├── 1038_binary-search-tree-to-greater-sum-tree_1_AC.py │ ├── 1039_minimum-score-triangulation-of-polygon_1_AC.py │ ├── 1040_moving-stones-until-consecutive-ii_1_AC.py │ ├── 1041_robot-bounded-in-circle_1_AC.py │ ├── 1042_flower-planting-with-no-adjacent_1_AC.py │ ├── 1043_partition-array-for-maximum-sum_1_AC.py │ ├── 1046_last-stone-weight_1_AC.py │ ├── 1047_remove-all-adjacent-duplicates-in-string_1_AC.py │ ├── 1048_longest-string-chain_1_AC.py │ ├── 1049_last-stone-weight-ii_1_AC.py │ ├── 1051_height-checker_1_AC.py │ ├── 1052_grumpy-bookstore-owner_1_AC.py │ ├── 1053_previous-permutation-with-one-swap_1_AC.py │ ├── 1054_distant-barcodes_1_AC.py │ ├── 1055_shortest-way-to-form-string_1_AC.py │ ├── 1056_confusing-number_1_AC.py │ ├── 1057_campus-bikes_1_AC.py │ ├── 1058_minimize-rounding-error-to-meet-target_1_AC.py │ ├── 1059_all-paths-from-source-lead-to-destination_1_AC.py │ ├── 1060_missing-element-in-sorted-array_1_AC.py │ ├── 1061_lexicographically-smallest-equivalent-string_1_AC.py │ ├── 1062_longest-repeating-substring_1_AC.py │ ├── 1063_number-of-valid-subarrays_1_AC.py │ ├── 1064_fixed-point_1_AC.py │ ├── 1065_index-pairs-of-a-string_1_AC.py │ ├── 1066_campus-bikes-ii_1_AC.py │ ├── 1071_greatest-common-divisor-of-strings_1_AC.py │ ├── 1072_flip-columns-for-maximum-number-of-equal-rows_1_AC.py │ ├── 1073_adding-two-negabinary-numbers_1_AC.py │ ├── 1074_number-of-submatrices-that-sum-to-target_1_AC.py │ ├── 1078_occurrences-after-bigram_1_AC.py │ ├── 1079_letter-tile-possibilities_1_AC.py │ ├── 1080_insufficient-nodes-in-root-to-leaf-paths_1_AC.py │ ├── 1081_smallest-subsequence-of-distinct-characters_1_AC.py │ ├── 1085_sum-of-digits-in-the-minimum-number_1_AC.py │ ├── 1086_high-five_1_AC.py │ ├── 1087_brace-expansion_1_AC.py │ ├── 1089_duplicate-zeros_1_AC.py │ ├── 1090_largest-values-from-labels_1_AC.py │ ├── 1091_shortest-path-in-binary-matrix_1_AC.py │ ├── 1093_statistics-from-a-large-sample_1_AC.py │ ├── 1094_car-pooling_1_AC.py │ ├── 1096_brace-expansion-ii_1_AC.py │ ├── 1099_two-sum-less-than-k_1_AC.py │ ├── 1100_find-k-length-substrings-with-no-repeated-characters_1_AC.py │ ├── 1101_the-earliest-moment-when-everyone-become-friends_1_AC.py │ ├── 1102_path-with-maximum-minimum-value_1_AC.py │ ├── 1103_distribute-candies-to-people_1_AC.py │ ├── 1104_path-in-zigzag-labelled-binary-tree_1_AC.py │ ├── 1105_filling-bookcase-shelves_1_AC.py │ ├── 1106_parsing-a-boolean-expression_1_AC.py │ ├── 1108_defanging-an-ip-address_1_AC.cpp │ ├── 1109_corporate-flight-bookings_1_AC.py │ ├── 1109_corporate-flight-bookings_2_AC.py │ ├── 1109_corporate-flight-bookings_3_AC.py │ ├── 1110_delete-nodes-and-return-forest_1_AC.py │ ├── 1111_maximum-nesting-depth-of-two-valid-parentheses-strings_1_AC.py │ ├── 1118_number-of-days-in-a-month_1_AC.py │ ├── 1119_remove-vowels-from-a-string_1_AC.py │ ├── 1120_maximum-average-subtree_1_AC.py │ ├── 1122_relative-sort-array_1_AC.py │ ├── 1123_lowest-common-ancestor-of-deepest-leaves_1_AC.py │ ├── 1123_lowest-common-ancestor-of-deepest-leaves_2_AC.py │ ├── 1128_number-of-equivalent-domino-pairs_1_AC.py │ ├── 1129_shortest-path-with-alternating-colors_1_AC.py │ ├── 1130_minimum-cost-tree-from-leaf-values_1_AC.py │ ├── 1131_maximum-of-absolute-value-expression_1_AC.py │ ├── 1133_largest-unique-number_1_AC.py │ ├── 1134_armstrong-number_1_AC.py │ ├── 1135_connecting-cities-with-minimum-cost_1_AC.py │ ├── 1137_n-th-tribonacci-number_1_AC.py │ ├── 1138_alphabet-board-path_1_AC.py │ ├── 1139_largest-1-bordered-square_1_AC.py │ ├── 1140_stone-game-ii_1_AC.py │ ├── 1143_longest-common-subsequence_1_AC.py │ ├── 1144_decrease-elements-to-make-array-zigzag_1_AC.py │ ├── 1145_binary-tree-coloring-game_1_AC.py │ ├── 1146_snapshot-array_1_AC.py │ ├── 1150_check-if-a-number-is-majority-element-in-a-sorted-array_1_AC.py │ ├── 1151_minimum-swaps-to-group-all-1s-together_1_AC.py │ ├── 1152_analyze-user-website-visit-pattern_1_AC.py │ ├── 1154_day-of-the-year_1_AC.py │ ├── 1155_number-of-dice-rolls-with-target-sum_1_AC.py │ ├── 1156_swap-for-longest-repeated-character-substring_1_AC.py │ ├── 1160_find-words-that-can-be-formed-by-characters_1_AC.py │ ├── 1161_maximum-level-sum-of-a-binary-tree_1_AC.py │ ├── 1162_as-far-from-land-as-possible_1_AC.py │ ├── 1165_single-row-keyboard_1_AC.py │ ├── 1166_design-file-system_1_AC.py │ ├── 1167_minimum-cost-to-connect-sticks_1_AC.py │ ├── 1170_compare-strings-by-frequency-of-the-smallest-character_1_AC.py │ ├── 1171_remove-zero-sum-consecutive-nodes-from-linked-list_1_AC.py │ ├── 1175_prime-arrangements_1_AC.py │ ├── 1176_diet-plan-performance_1_AC.py │ ├── 1177_can-make-palindrome-from-substring_1_AC.py │ ├── 1180_count-substrings-with-only-one-distinct-letter_1_AC.py │ ├── 1181_before-and-after-puzzle_1_AC.py │ ├── 1182_shortest-distance-to-target-color_1_AC.py │ ├── 1184_distance-between-bus-stops_1_AC.py │ ├── 1185_day-of-the-week_1_AC.py │ ├── 1186_maximum-subarray-sum-with-one-deletion_1_AC.py │ ├── 1189_maximum-number-of-balloons_1_AC.py │ ├── 1190_reverse-substrings-between-each-pair-of-parentheses_1_AC.py │ ├── 1191_k-concatenation-maximum-sum_1_AC.py │ ├── 1196_how-many-apples-can-you-put-into-the-basket_1_AC.py │ ├── 1197_minimum-knight-moves_1_AC.py │ ├── 1198_find-smallest-common-element-in-all-rows_1_AC.py │ ├── 1200_minimum-absolute-difference_1_AC.py │ ├── 1201_ugly-number-iii_1_AC.py │ ├── 1202_smallest-string-with-swaps_1_AC.py │ ├── 1203_sort-items-by-groups-respecting-dependencies_1_AC.py │ ├── 1207_unique-number-of-occurrences_1_AC.py │ ├── 1208_get-equal-substrings-within-budget_1_AC.py │ ├── 1209_remove-all-adjacent-duplicates-in-string-ii_1_AC.py │ ├── 1213_intersection-of-three-sorted-arrays_1_AC.py │ ├── 1214_two-sum-bsts_1_AC.py │ ├── 1215_stepping-numbers_1_AC.py │ ├── 1217_minimum-cost-to-move-chips-to-the-same-position_1_AC.py │ ├── 1218_longest-arithmetic-subsequence-of-given-difference_1_AC.py │ ├── 1219_path-with-maximum-gold_1_AC.py │ ├── 1221_split-a-string-in-balanced-strings_1_AC.cpp │ ├── 1222_queens-that-can-attack-the-king_1_AC.py │ ├── 1223_dice-roll-simulation_1_AC.py │ ├── 1227_airplane-seat-assignment-probability_1_AC.py │ ├── 1228_missing-number-in-arithmetic-progression_1_AC.py │ ├── 1229_meeting-scheduler_1_AC.py │ ├── 1230_toss-strange-coins_1_AC.py │ ├── 1232_check-if-it-is-a-straight-line_1_AC.py │ ├── 1233_remove-sub-folders-from-the-filesystem_1_AC.py │ ├── 1236_web-crawler_1_AC.py │ ├── 1237_find-positive-integer-solution-for-a-given-equation_1_AC.py │ ├── 1238_circular-permutation-in-binary-representation_1_AC.py │ ├── 1239_maximum-length-of-a-concatenated-string-with-unique-characters_1_AC.py │ ├── 1243_array-transformation_1_AC.py │ ├── 1244_design-a-leaderboard_1_AC.cpp │ ├── 1245_tree-diameter_1_AC.py │ ├── 1247_minimum-swaps-to-make-strings-equal_1_AC.py │ ├── 1248_count-number-of-nice-subarrays_1_AC.py │ ├── 1249_minimum-remove-to-make-valid-parentheses_1_AC.py │ ├── 1252_cells-with-odd-values-in-a-matrix_1_AC.cpp │ ├── 1253_reconstruct-a-2-row-binary-matrix_1_AC.py │ ├── 1254_number-of-closed-islands_1_AC.py │ ├── 1255_maximum-score-words-formed-by-letters_1_AC.py │ ├── 1256_encode-number_1_AC.py │ ├── 1257_smallest-common-region_1_AC.py │ ├── 1258_synonymous-sentences_1_AC.py │ ├── 1260_shift-2d-grid_1_AC.py │ ├── 1261_find-elements-in-a-contaminated-binary-tree_1_AC.py │ ├── 1262_greatest-sum-divisible-by-three_1_AC.py │ ├── 1265_print-immutable-linked-list-in-reverse_1_AC.py │ ├── 1266_minimum-time-visiting-all-points_1_AC.cpp │ ├── 1267_count-servers-that-communicate_1_AC.py │ ├── 1267_count-servers-that-communicate_2_AC.py │ ├── 1268_search-suggestions-system_1_AC.py │ ├── 1271_hexspeak_1_AC.py │ ├── 1272_remove-interval_1_AC.py │ ├── 1273_delete-tree-nodes_1_AC.py │ ├── 1275_find-winner-on-a-tic-tac-toe-game_1_AC.py │ ├── 1276_number-of-burgers-with-no-waste-of-ingredients_1_AC.py │ ├── 1277_count-square-submatrices-with-all-ones_1_AC.py │ ├── 1277_count-square-submatrices-with-all-ones_2_AC.py │ ├── 1281_subtract-the-product-and-sum-of-digits-of-an-integer_1_AC.cpp │ ├── 1282_group-the-people-given-the-group-size-they-belong-to_1_AC.py │ ├── 1283_find-the-smallest-divisor-given-a-threshold_1_AC.py │ ├── 1284_minimum-number-of-flips-to-convert-binary-matrix-to-zero-matrix_1_AC.py │ ├── 1286_iterator-for-combination_1_AC.py │ ├── 1287_element-appearing-more-than-25-in-sorted-array_1_AC.py │ ├── 1288_remove-covered-intervals_1_AC.py │ ├── 1289_minimum-falling-path-sum-ii_1_AC.py │ ├── 1290_convert-binary-number-in-a-linked-list-to-integer_1_AC.cpp │ ├── 1291_sequential-digits_1_AC.py │ ├── 1292_maximum-side-length-of-a-square-with-sum-less-than-or-equal-to-threshold_1_AC.py │ ├── 1295_find-numbers-with-even-number-of-digits_1_AC.cpp │ ├── 1296_divide-array-in-sets-of-k-consecutive-numbers_1_AC.py │ ├── 1297_maximum-number-of-occurrences-of-a-substring_1_AC.py │ ├── 1299_replace-elements-with-greatest-element-on-right-side_1_AC.py │ ├── 1300_sum-of-mutated-array-closest-to-target_1_AC.py │ ├── 1302_deepest-leaves-sum_1_AC.py │ ├── 1304_find-n-unique-integers-sum-up-to-zero_1_AC.py │ ├── 1305_all-elements-in-two-binary-search-trees_1_AC.py │ ├── 1306_jump-game-iii_1_AC.py │ ├── 1309_decrypt-string-from-alphabet-to-integer-mapping_1_AC.py │ ├── 1310_xor-queries-of-a-subarray_1_AC.py │ ├── 1311_get-watched-videos-by-your-friends_1_AC.py │ ├── 1312_minimum-insertion-steps-to-make-a-string-palindrome_1_AC.py │ ├── 1313_decompress-run-length-encoded-list_1_AC.cpp │ ├── 1314_matrix-block-sum_1_AC.py │ ├── 1315_sum-of-nodes-with-even-valued-grandparent_1_AC.py │ ├── 1317_convert-integer-to-the-sum-of-two-no-zero-integers_1_AC.py │ ├── 1318_minimum-flips-to-make-a-or-b-equal-to-c_1_AC.py │ ├── 1319_number-of-operations-to-make-network-connected_1_AC.py │ ├── 1323_maximum-69-number_1_AC.cpp │ ├── 1324_print-words-vertically_1_AC.py │ ├── 1325_delete-leaves-with-a-given-value_1_AC.py │ ├── 1328_break-a-palindrome_1_AC.py │ ├── 1329_sort-the-matrix-diagonally_1_AC.py │ ├── 1331_rank-transform-of-an-array_1_AC.py │ ├── 1332_remove-palindromic-subsequences_1_AC.py │ ├── 1333_filter-restaurants-by-vegan-friendly-price-and-distance_1_AC.py │ ├── 1334_find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance_1_AC.py │ ├── 1337_the-k-weakest-rows-in-a-matrix_1_AC.py │ ├── 1338_reduce-array-size-to-the-half_1_AC.py │ ├── 1339_maximum-product-of-splitted-binary-tree_1_AC.py │ ├── 1340_jump-game-v_1_AC.py │ ├── 1342_number-of-steps-to-reduce-a-number-to-zero_1_AC.py │ ├── 1343_number-of-sub-arrays-of-size-k-and-average-greater-than-or-equal-to-threshold_1_AC.py │ ├── 1344_angle-between-hands-of-a-clock_1_AC.py │ ├── 1346_check-if-n-and-its-double-exist_1_AC.py │ ├── 1347_minimum-number-of-steps-to-make-two-strings-anagram_1_AC.py │ ├── 1351_count-negative-numbers-in-a-sorted-matrix_1_AC.py │ ├── 1351_count-negative-numbers-in-a-sorted-matrix_2_AC.py │ ├── 1352_product-of-the-last-k-numbers_1_AC.py │ ├── 1356_sort-integers-by-the-number-of-1-bits_1_AC.py │ ├── 1357_apply-discount-every-n-orders_1_AC.py │ ├── 1358_number-of-substrings-containing-all-three-characters_1_AC.py │ ├── 1359_count-all-valid-pickup-and-delivery-options_1_AC.py │ ├── 1360_number-of-days-between-two-dates_1_AC.py │ ├── 1361_validate-binary-tree-nodes_1_AC.py │ ├── 1362_closest-divisors_1_AC.py │ ├── 1365_how-many-numbers-are-smaller-than-the-current-number_1_AC.py │ ├── 1366_rank-teams-by-votes_1_AC.py │ ├── 1367_linked-list-in-binary-tree_1_AC.py │ ├── 1370_increasing-decreasing-string_1_AC.py │ ├── 1371_find-the-longest-substring-containing-vowels-in-even-counts_1_AC.py │ ├── 1372_longest-zigzag-path-in-a-binary-tree_1_AC.py │ ├── 1374_generate-a-string-with-characters-that-have-odd-counts_1_AC.py │ ├── 1375_number-of-times-binary-string-is-prefix-aligned_1_AC.py │ ├── 1376_time-needed-to-inform-all-employees_1_AC.py │ ├── 1379_find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree_1_AC.py │ ├── 1380_lucky-numbers-in-a-matrix_1_AC.py │ ├── 1381_design-a-stack-with-increment-operation_1_AC.py │ ├── 1382_balance-a-binary-search-tree_1_AC.py │ ├── 1385_find-the-distance-value-between-two-arrays_1_AC.py │ ├── 1386_cinema-seat-allocation_1_AC.py │ ├── 1387_sort-integers-by-the-power-value_1_AC.py │ ├── 1389_create-target-array-in-the-given-order_1_AC.py │ ├── 1390_four-divisors_1_AC.py │ ├── 1391_check-if-there-is-a-valid-path-in-a-grid_1_AC.py │ ├── 1394_find-lucky-integer-in-an-array_1_AC.py │ ├── 1395_count-number-of-teams_1_AC.py │ ├── 1396_design-underground-system_1_AC.py │ ├── 1399_count-largest-group_1_AC.py │ ├── 1400_construct-k-palindrome-strings_1_AC.py │ ├── 1401_circle-and-rectangle-overlapping_1_AC.py │ ├── 1402_reducing-dishes_1_AC.py │ ├── 1402_reducing-dishes_2_AC.py │ ├── 1403_minimum-subsequence-in-non-increasing-order_1_AC.py │ ├── 1404_number-of-steps-to-reduce-a-number-in-binary-representation-to-one_1_AC.py │ ├── 1405_longest-happy-string_1_AC.py │ ├── 1406_stone-game-iii_1_AC.py │ ├── 1408_string-matching-in-an-array_1_AC.py │ ├── 1409_queries-on-a-permutation-with-key_1_AC.py │ ├── 1409_queries-on-a-permutation-with-key_2_AC.py │ ├── 1410_html-entity-parser_1_AC.py │ ├── 1411_number-of-ways-to-paint-n-3-grid_1_AC.py │ ├── 1413_minimum-value-to-get-positive-step-by-step-sum_1_AC.py │ ├── 1414_find-the-minimum-number-of-fibonacci-numbers-whose-sum-is-k_1_AC.py │ ├── 1415_the-k-th-lexicographical-string-of-all-happy-strings-of-length-n_1_AC.py │ ├── 1417_reformat-the-string_1_AC.py │ ├── 1418_display-table-of-food-orders-in-a-restaurant_1_AC.py │ ├── 1419_minimum-number-of-frogs-croaking_1_AC.py │ ├── 1420_build-array-where-you-can-find-the-maximum-exactly-k-comparisons_1_AC.py │ ├── 1422_maximum-score-after-splitting-a-string_1_AC.py │ ├── 1423_maximum-points-you-can-obtain-from-cards_1_AC.py │ ├── 1424_diagonal-traverse-ii_1_AC.py │ ├── 1426_counting-elements_1_AC.py │ ├── 1427_perform-string-shifts_1_AC.py │ ├── 1428_leftmost-column-with-at-least-a-one_1_AC.py │ ├── 1429_first-unique-number_1_AC.py │ ├── 1430_check-if-a-string-is-a-valid-sequence-from-root-to-leaves-path-in-a-binary-tree_1_AC.py │ ├── 1431_kids-with-the-greatest-number-of-candies_1_AC.py │ ├── 1433_check-if-a-string-can-break-another-string_1_AC.py │ ├── 1436_destination-city_1_AC.py │ ├── 1437_check-if-all-1s-are-at-least-length-k-places-away_1_AC.py │ ├── 1438_longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit_1_AC.py │ ├── 1441_build-an-array-with-stack-operations_1_AC.py │ ├── 1442_count-triplets-that-can-form-two-arrays-of-equal-xor_1_AC.py │ ├── 1443_minimum-time-to-collect-all-apples-in-a-tree_1_AC.py │ ├── 1446_consecutive-characters_1_AC.py │ ├── 1447_simplified-fractions_1_AC.py │ ├── 1448_count-good-nodes-in-binary-tree_1_AC.py │ ├── 1450_number-of-students-doing-homework-at-a-given-time_1_AC.py │ ├── 1451_rearrange-words-in-a-sentence_1_AC.py │ ├── 1452_people-whose-list-of-favorite-companies-is-not-a-subset-of-another-list_1_AC.py │ ├── 1455_check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence_1_AC.py │ ├── 1456_maximum-number-of-vowels-in-a-substring-of-given-length_1_AC.py │ ├── 1457_pseudo-palindromic-paths-in-a-binary-tree_1_AC.py │ ├── 1460_make-two-arrays-equal-by-reversing-subarrays_1_AC.py │ ├── 1461_check-if-a-string-contains-all-binary-codes-of-size-k_1_AC.py │ ├── 1462_course-schedule-iv_1_AC.py │ ├── 1463_cherry-pickup-ii_1_AC.py │ ├── 1464_maximum-product-of-two-elements-in-an-array_1_AC.py │ ├── 1466_reorder-routes-to-make-all-paths-lead-to-the-city-zero_1_AC.py │ ├── 1469_find-all-the-lonely-nodes_1_AC.py │ ├── 1470_shuffle-the-array_1_AC.py │ ├── 1471_the-k-strongest-values-in-an-array_1_AC.py │ ├── 1472_design-browser-history_1_AC.py │ ├── 1474_delete-n-nodes-after-m-nodes-of-a-linked-list_1_AC.py │ ├── 1475_final-prices-with-a-special-discount-in-a-shop_1_AC.py │ ├── 1476_subrectangle-queries_1_AC.py │ ├── 1480_running-sum-of-1d-array_1_AC.py │ ├── 1481_least-number-of-unique-integers-after-k-removals_1_AC.py │ ├── 1482_minimum-number-of-days-to-make-m-bouquets_1_AC.py │ ├── 1485_clone-binary-tree-with-random-pointer_1_AC.py │ ├── 1486_xor-operation-in-an-array_1_AC.py │ ├── 1489_find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree_1_AC.py │ ├── 1490_clone-n-ary-tree_1_AC.py │ ├── 1491_average-salary-excluding-the-minimum-and-maximum-salary_1_AC.py │ ├── 1492_the-kth-factor-of-n_1_AC.py │ ├── 1493_longest-subarray-of-1s-after-deleting-one-element_1_AC.py │ └── 1496_path-crossing_1_AC.py ├── 1501-2000 │ ├── 1502_can-make-arithmetic-progression-from-sequence_1_AC.py │ ├── 1503_last-moment-before-all-ants-fall-out-of-a-plank_1_AC.py │ ├── 1504_count-submatrices-with-all-ones_1_AC.py │ ├── 1506_find-root-of-n-ary-tree_1_AC.py │ ├── 1507_reformat-date_1_AC.py │ ├── 1508_range-sum-of-sorted-subarray-sums_1_AC.py │ ├── 1509_minimum-difference-between-largest-and-smallest-value-in-three-moves_1_AC.py │ ├── 1512_number-of-good-pairs_1_AC.py │ ├── 1514_path-with-maximum-probability_1_AC.py │ ├── 1518_water-bottles_1_AC.py │ ├── 1519_number-of-nodes-in-the-sub-tree-with-the-same-label_1_AC.py │ ├── 1522_diameter-of-n-ary-tree_1_AC.py │ ├── 1523_count-odd-numbers-in-an-interval-range_1_AC.py │ ├── 1525_number-of-good-ways-to-split-a-string_1_AC.py │ ├── 1526_minimum-number-of-increments-on-subarrays-to-form-a-target-array_1_AC.py │ ├── 1528_shuffle-string_1_AC.py │ ├── 1529_minimum-suffix-flips_1_AC.py │ ├── 1530_number-of-good-leaf-nodes-pairs_1_AC.py │ ├── 1534_count-good-triplets_1_AC.py │ ├── 1535_find-the-winner-of-an-array-game_1_AC.py │ ├── 1539_kth-missing-positive-number_1_AC.py │ ├── 1541_minimum-insertions-to-balance-a-parentheses-string_1_AC.py │ ├── 1544_make-the-string-great_1_AC.py │ ├── 1545_find-kth-bit-in-nth-binary-string_1_AC.py │ ├── 1550_three-consecutive-odds_1_AC.py │ ├── 1551_minimum-operations-to-make-array-equal_1_AC.py │ ├── 1552_magnetic-force-between-two-balls_1_AC.py │ ├── 1556_thousand-separator_1_AC.py │ ├── 1557_minimum-number-of-vertices-to-reach-all-nodes_1_AC.py │ ├── 1558_minimum-numbers-of-function-calls-to-make-target-array_1_AC.py │ ├── 1560_most-visited-sector-in-a-circular-track_1_AC.py │ ├── 1561_maximum-number-of-coins-you-can-get_1_AC.py │ ├── 1566_detect-pattern-of-length-m-repeated-k-or-more-times_1_AC.py │ ├── 1566_detect-pattern-of-length-m-repeated-k-or-more-times_2_AC.py │ ├── 1570_dot-product-of-two-sparse-vectors_1_AC.py │ ├── 1572_matrix-diagonal-sum_1_AC.py │ ├── 1574_shortest-subarray-to-be-removed-to-make-array-sorted_1_AC.py │ ├── 1574_shortest-subarray-to-be-removed-to-make-array-sorted_2_AC.py │ ├── 1575_count-all-possible-routes_1_AC.py │ ├── 1576_replace-all-s-to-avoid-consecutive-repeating-characters_1_AC.py │ ├── 1578_minimum-time-to-make-rope-colorful_1_AC.py │ ├── 1579_remove-max-number-of-edges-to-keep-graph-fully-traversable_1_AC.py │ ├── 1582_special-positions-in-a-binary-matrix_1_AC.py │ ├── 1583_count-unhappy-friends_1_AC.py │ ├── 1584_min-cost-to-connect-all-points_1_AC.py │ ├── 1588_sum-of-all-odd-length-subarrays_1_AC.py │ ├── 1588_sum-of-all-odd-length-subarrays_2_AC.py │ ├── 1592_rearrange-spaces-between-words_1_AC.py │ ├── 1593_split-a-string-into-the-max-number-of-unique-substrings_1_AC.py │ ├── 1598_crawler-log-folder_1_AC.py │ ├── 1600_throne-inheritance_1_AC.py │ ├── 1601_maximum-number-of-achievable-transfer-requests_1_AC.py │ ├── 1602_find-nearest-right-node-in-binary-tree_1_AC.py │ ├── 1603_design-parking-system_1_AC.py │ ├── 1605_find-valid-matrix-given-row-and-column-sums_1_AC.py │ ├── 1608_special-array-with-x-elements-greater-than-or-equal-x_1_AC.py │ ├── 1609_even-odd-tree_1_AC.py │ ├── 1611_minimum-one-bit-operations-to-make-integers-zero_1_AC.py │ ├── 1612_check-if-two-expression-trees-are-equivalent_1_AC.py │ ├── 1614_maximum-nesting-depth-of-the-parentheses_1_AC.py │ ├── 1615_maximal-network-rank_1_AC.py │ ├── 1617_count-subtrees-with-max-distance-between-cities_1_AC.py │ ├── 1619_mean-of-array-after-removing-some-elements_1_AC.py │ ├── 1624_largest-substring-between-two-equal-characters_1_AC.py │ ├── 1625_lexicographically-smallest-string-after-applying-operations_1_AC.py │ ├── 1628_design-an-expression-tree-with-evaluate-function_1_AC.py │ ├── 1629_slowest-key_1_AC.py │ ├── 1630_arithmetic-subarrays_1_AC.py │ ├── 1631_path-with-minimum-effort_1_AC.py │ ├── 1636_sort-array-by-increasing-frequency_1_AC.py │ ├── 1637_widest-vertical-area-between-two-points-containing-no-points_1_AC.py │ ├── 1638_count-substrings-that-differ-by-one-character_1_AC.py │ ├── 1640_check-array-formation-through-concatenation_1_AC.py │ ├── 1641_count-sorted-vowel-strings_1_AC.py │ ├── 1646_get-maximum-in-generated-array_1_AC.py │ ├── 1647_minimum-deletions-to-make-character-frequencies-unique_1_AC.py │ ├── 1650_lowest-common-ancestor-of-a-binary-tree-iii_1_AC.py │ ├── 1652_defuse-the-bomb_1_AC.py │ ├── 1653_minimum-deletions-to-make-string-balanced_1_AC.py │ ├── 1656_design-an-ordered-stream_1_AC.py │ ├── 1657_determine-if-two-strings-are-close_1_AC.py │ ├── 1660_correct-a-binary-tree_1_AC.py │ ├── 1662_check-if-two-string-arrays-are-equivalent_1_AC.py │ ├── 1663_smallest-string-with-a-given-numeric-value_1_AC.py │ ├── 1664_ways-to-make-a-fair-array_1_AC.py │ ├── 1668_maximum-repeating-substring_1_AC.py │ ├── 1669_merge-in-between-linked-lists_1_AC.py │ ├── 1670_design-front-middle-back-queue_1_AC.py │ ├── 1672_richest-customer-wealth_1_AC.py │ ├── 1673_find-the-most-competitive-subsequence_1_AC.py │ ├── 1676_lowest-common-ancestor-of-a-binary-tree-iv_1_AC.py │ ├── 1678_goal-parser-interpretation_1_AC.py │ ├── 1679_max-number-of-k-sum-pairs_1_AC.py │ ├── 1680_concatenation-of-consecutive-binary-numbers_1_AC.py │ ├── 1684_count-the-number-of-consistent-strings_1_AC.py │ ├── 1685_sum-of-absolute-differences-in-a-sorted-array_1_AC.py │ ├── 1686_stone-game-vi_1_AC.py │ ├── 1688_count-of-matches-in-tournament_1_AC.py │ ├── 1689_partitioning-into-minimum-number-of-deci-binary-numbers_1_AC.py │ ├── 1690_stone-game-vii_1_AC.py │ ├── 1694_reformat-phone-number_1_AC.py │ ├── 1695_maximum-erasure-value_1_AC.py │ ├── 1700_number-of-students-unable-to-eat-lunch_1_AC.py │ ├── 1701_average-waiting-time_1_AC.py │ ├── 1704_determine-if-string-halves-are-alike_1_AC.py │ ├── 1706_where-will-the-ball-fall_1_AC.py │ ├── 1708_largest-subarray-length-k_1_AC.py │ ├── 1710_maximum-units-on-a-truck_1_AC.py │ ├── 1716_calculate-money-in-leetcode-bank_1_AC.py │ ├── 1717_maximum-score-from-removing-substrings_1_AC.py │ ├── 1718_construct-the-lexicographically-largest-valid-sequence_1_AC.py │ ├── 1720_decode-xored-array_1_AC.py │ ├── 1721_swapping-nodes-in-a-linked-list_1_AC.py │ ├── 1725_number-of-rectangles-that-can-form-the-largest-square_1_AC.py │ ├── 1726_tuple-with-same-product_1_AC.py │ ├── 1727_largest-submatrix-with-rearrangements_1_AC.py │ ├── 1732_find-the-highest-altitude_1_AC.py │ ├── 1734_decode-xored-permutation_1_AC.py │ ├── 1736_latest-time-by-replacing-hidden-digits_1_AC.py │ ├── 1738_find-kth-largest-xor-coordinate-value_1_AC.py │ ├── 1740_find-distance-in-a-binary-tree_1_AC.py │ ├── 1742_maximum-number-of-balls-in-a-box_1_AC.py │ ├── 1743_restore-the-array-from-adjacent-pairs_1_AC.py │ ├── 1748_sum-of-unique-elements_1_AC.py │ ├── 1749_maximum-absolute-sum-of-any-subarray_1_AC.py │ ├── 1750_minimum-length-of-string-after-deleting-similar-ends_1_AC.py │ ├── 1752_check-if-array-is-sorted-and-rotated_1_AC.py │ ├── 1753_maximum-score-from-removing-stones_1_AC.py │ ├── 1756_design-most-recently-used-queue_1_AC.py │ ├── 1758_minimum-changes-to-make-alternating-binary-string_1_AC.py │ ├── 1759_count-number-of-homogenous-substrings_1_AC.py │ ├── 1760_minimum-limit-of-balls-in-a-bag_1_AC.py │ ├── 1762_buildings-with-an-ocean-view_1_AC.py │ ├── 1763_longest-nice-substring_1_AC.py │ ├── 1764_form-array-by-concatenating-subarrays-of-another-array_1_AC.py │ ├── 1765_map-of-highest-peak_1_AC.py │ ├── 1768_merge-strings-alternately_1_AC.py │ ├── 1769_minimum-number-of-operations-to-move-all-balls-to-each-box_1_AC.py │ ├── 1773_count-items-matching-a-rule_1_AC.py │ ├── 1775_equal-sum-arrays-with-minimum-number-of-operations_1_AC.py │ ├── 1779_find-nearest-point-that-has-the-same-x-or-y-coordinate_1_AC.py │ ├── 1780_check-if-number-is-a-sum-of-powers-of-three_1_AC.py │ ├── 1781_sum-of-beauty-of-all-substrings_1_AC.py │ ├── 1784_check-if-binary-string-has-at-most-one-segment-of-ones_1_AC.py │ ├── 1790_check-if-one-string-swap-can-make-strings-equal_1_AC.py │ ├── 1791_find-center-of-star-graph_1_AC.py │ ├── 1792_maximum-average-pass-ratio_1_AC.py │ ├── 1793_maximum-score-of-a-good-subarray_1_AC.py │ ├── 1796_second-largest-digit-in-a-string_1_AC.py │ ├── 1797_design-authentication-manager_1_AC.py │ ├── 1798_maximum-number-of-consecutive-values-you-can-make_1_AC.py │ ├── 1800_maximum-ascending-subarray-sum_1_AC.py │ ├── 1801_number-of-orders-in-the-backlog_1_AC.py │ ├── 1805_number-of-different-integers-in-a-string_1_AC.py │ ├── 1806_minimum-number-of-operations-to-reinitialize-a-permutation_1_AC.py │ ├── 1807_evaluate-the-bracket-pairs-of-a-string_1_AC.py │ ├── 1812_determine-color-of-a-chessboard-square_1_AC.py │ ├── 1816_truncate-sentence_1_AC.py │ ├── 1817_finding-the-users-active-minutes_1_AC.py │ ├── 1822_sign-of-the-product-of-an-array_1_AC.py │ ├── 1823_find-the-winner-of-the-circular-game_1_AC.py │ ├── 1826_faulty-sensor_1_AC.py │ ├── 1827_minimum-operations-to-make-the-array-increasing_1_AC.py │ ├── 1828_queries-on-number-of-points-inside-a-circle_1_AC.py │ ├── 1829_maximum-xor-for-each-query_1_AC.py │ ├── 1832_check-if-the-sentence-is-pangram_1_AC.py │ ├── 1833_maximum-ice-cream-bars_1_AC.py │ ├── 1836_remove-duplicates-from-an-unsorted-linked-list_1_AC.py │ ├── 1837_sum-of-digits-in-base-k_1_AC.py │ ├── 1839_longest-substring-of-all-vowels-in-order_1_AC.py │ ├── 1844_replace-all-digits-with-characters_1_AC.py │ ├── 1845_seat-reservation-manager_1_AC.py │ ├── 1846_maximum-element-after-decreasing-and-rearranging_1_AC.py │ ├── 1848_minimum-distance-to-the-target-element_1_AC.py │ ├── 1850_minimum-adjacent-swaps-to-reach-the-kth-smallest-number_1_AC.py │ ├── 1852_distinct-numbers-in-each-subarray_1_AC.py │ ├── 1854_maximum-population-year_1_AC.py │ ├── 1855_maximum-distance-between-a-pair-of-values_1_AC.py │ ├── 1859_sorting-the-sentence_1_AC.py │ ├── 1860_incremental-memory-leak_1_AC.py │ ├── 1861_rotating-the-box_1_AC.py │ ├── 1863_sum-of-all-subset-xor-totals_1_AC.py │ ├── 1865_finding-pairs-with-a-certain-sum_1_AC.py │ ├── 1869_longer-contiguous-segments-of-ones-than-zeros_1_AC.py │ ├── 1874_minimize-product-sum-of-two-arrays_1_AC.py │ ├── 1876_substrings-of-size-three-with-distinct-characters_1_AC.py │ ├── 1877_minimize-maximum-pair-sum-in-array_1_AC.py │ ├── 1880_check-if-word-equals-summation-of-two-words_1_AC.py │ ├── 1884_egg-drop-with-2-eggs-and-n-floors_1_AC.py │ ├── 1886_determine-whether-matrix-can-be-obtained-by-rotation_1_AC.py │ ├── 1887_reduction-operations-to-make-the-array-elements-equal_1_AC.py │ ├── 1893_check-if-all-the-integers-in-a-range-are-covered_1_AC.py │ ├── 1894_find-the-student-that-will-replace-the-chalk_1_AC.py │ ├── 1895_largest-magic-square_1_AC.py │ ├── 1897_redistribute-characters-to-make-all-strings-equal_1_AC.py │ ├── 1899_merge-triplets-to-form-target-triplet_1_AC.py │ ├── 1901_find-a-peak-element-ii_1_AC.py │ ├── 1903_largest-odd-number-in-string_1_AC.py │ ├── 1905_count-sub-islands_1_AC.py │ ├── 1909_remove-one-element-to-make-the-array-strictly-increasing_1_AC.py │ ├── 1910_remove-all-occurrences-of-a-substring_1_AC.py │ ├── 1911_maximum-alternating-subsequence-sum_1_AC.py │ ├── 1913_maximum-product-difference-between-two-pairs_1_AC.py │ ├── 1915_number-of-wonderful-substrings_1_AC.py │ ├── 1920_build-array-from-permutation_1_AC.py │ ├── 1921_eliminate-maximum-number-of-monsters_1_AC.py │ ├── 1925_count-square-sum-triples_1_AC.py │ ├── 1929_concatenation-of-array_1_AC.py │ ├── 1930_unique-length-3-palindromic-subsequences_1_AC.py │ ├── 1933_check-if-string-is-decomposable-into-value-equal-substrings_1_AC.py │ ├── 1935_maximum-number-of-words-you-can-type_1_AC.py │ ├── 1940_longest-common-subsequence-between-sorted-arrays_1_AC.py │ ├── 1941_check-if-all-characters-have-equal-number-of-occurrences_1_AC.py │ ├── 1942_the-number-of-the-smallest-unoccupied-chair_1_AC.py │ ├── 1943_describe-the-painting_1_AC.py │ ├── 1944_number-of-visible-people-in-a-queue_1_AC.py │ ├── 1945_sum-of-digits-of-string-after-convert_1_AC.py │ ├── 1947_maximum-compatibility-score-sum_1_AC.py │ ├── 1952_three-divisors_1_AC.py │ ├── 1954_minimum-garden-perimeter-to-collect-enough-apples_1_AC.py │ ├── 1957_delete-characters-to-make-fancy-string_1_AC.py │ ├── 1961_check-if-string-is-a-prefix-of-array_1_AC.py │ ├── 1962_remove-stones-to-minimize-the-total_1_AC.py │ ├── 1963_minimum-number-of-swaps-to-make-the-string-balanced_1_AC.py │ ├── 1964_find-the-longest-valid-obstacle-course-at-each-position_1_AC.py │ ├── 1967_number-of-strings-that-appear-as-substrings-in-word_1_AC.py │ ├── 1968_array-with-elements-not-equal-to-average-of-neighbors_1_AC.py │ ├── 1971_find-if-path-exists-in-graph_1_AC.py │ ├── 1973_count-nodes-equal-to-sum-of-descendants_1_AC.py │ ├── 1974_minimum-time-to-type-word-using-special-typewriter_1_AC.py │ ├── 1975_maximum-matrix-sum_1_AC.py │ ├── 1979_find-greatest-common-divisor-of-array_1_AC.py │ ├── 1980_find-unique-binary-string_1_AC.py │ ├── 1984_minimum-difference-between-highest-and-lowest-of-k-scores_1_AC.py │ ├── 1991_find-the-middle-index-in-array_1_AC.py │ ├── 1992_find-all-groups-of-farmland_1_AC.py │ ├── 1995_count-special-quadruplets_1_AC.py │ └── 2000_reverse-prefix-of-word_1_AC.py ├── 2001-2500 │ ├── 2001_number-of-pairs-of-interchangeable-rectangles_1_AC.py │ ├── 2002_maximum-product-of-the-length-of-two-palindromic-subsequences_1_AC.py │ ├── 2006_count-number-of-pairs-with-absolute-difference-k_1_AC.py │ ├── 2011_final-value-of-variable-after-performing-operations_1_AC.py │ ├── 2013_detect-squares_1_AC.py │ ├── 2016_maximum-difference-between-increasing-elements_1_AC.py │ ├── 2022_convert-1d-array-into-2d-array_1_AC.py │ ├── 2023_number-of-pairs-of-strings-with-concatenation-equal-to-target_1_AC.py │ ├── 2024_maximize-the-confusion-of-an-exam_1_AC.py │ ├── 2027_minimum-moves-to-convert-string_1_AC.py │ ├── 2028_find-missing-observations_1_AC.py │ ├── 2032_two-out-of-three_1_AC.py │ ├── 2033_minimum-operations-to-make-a-uni-value-grid_1_AC.py │ ├── 2037_minimum-number-of-moves-to-seat-everyone_1_AC.py │ ├── 2038_remove-colored-pieces-if-both-neighbors-are-the-same-color_1_AC.py │ ├── 2039_the-time-when-the-network-becomes-idle_1_AC.py │ ├── 2042_check-if-numbers-are-ascending-in-a-sentence_1_AC.py │ ├── 2043_simple-bank-system_1_AC.py │ ├── 2044_count-number-of-maximum-bitwise-or-subsets_1_AC.py │ ├── 2045_second-minimum-time-to-reach-destination_1_AC.py │ ├── 2046_sort-linked-list-already-sorted-using-absolute-values_1_AC.py │ ├── 2047_number-of-valid-words-in-a-sentence_1_AC.py │ ├── 2049_count-nodes-with-the-highest-score_1_AC.py │ ├── 2050_parallel-courses-iii_1_AC.py │ ├── 2053_kth-distinct-string-in-an-array_1_AC.py │ ├── 2054_two-best-non-overlapping-events_1_AC.py │ ├── 2057_smallest-index-with-equal-value_1_AC.py │ ├── 2058_find-the-minimum-and-maximum-number-of-nodes-between-critical-points_1_AC.py │ ├── 2062_count-vowel-substrings-of-a-string_1_AC.py │ ├── 2063_vowels-of-all-substrings_1_AC.py │ ├── 2064_minimized-maximum-of-products-distributed-to-any-store_1_AC.py │ ├── 2068_check-whether-two-strings-are-almost-equivalent_1_AC.py │ ├── 2070_most-beautiful-item-for-each-query_1_AC.py │ ├── 2073_time-needed-to-buy-tickets_1_AC.py │ ├── 2073_time-needed-to-buy-tickets_2_AC.py │ ├── 2074_reverse-nodes-in-even-length-groups_1_AC.py │ ├── 2078_two-furthest-houses-with-different-colors_1_AC.py │ ├── 2079_watering-plants_1_AC.py │ ├── 2083_substrings-that-begin-and-end-with-the-same-letter_1_AC.py │ ├── 2085_count-common-words-with-one-occurrence_1_AC.py │ ├── 2087_minimum-cost-homecoming-of-a-robot-in-a-grid_1_AC.py │ ├── 2088_count-fertile-pyramids-in-a-land_1_AC.py │ ├── 2089_find-target-indices-after-sorting-array_1_AC.py │ ├── 2091_removing-minimum-and-maximum-from-array_1_AC.py │ ├── 2094_finding-3-digit-even-numbers_1_AC.py │ ├── 2095_delete-the-middle-node-of-a-linked-list_1_AC.py │ ├── 2096_step-by-step-directions-from-a-binary-tree-node-to-another_1_AC.py │ ├── 2097_valid-arrangement-of-pairs_1_AC.py │ ├── 2099_find-subsequence-of-length-k-with-the-largest-sum_1_AC.py │ ├── 2102_sequentially-ordinal-rank-tracker_1_AC.py │ ├── 2103_rings-and-rods_1_AC.py │ ├── 2104_sum-of-subarray-ranges_1_AC.py │ ├── 2108_find-first-palindromic-string-in-the-array_1_AC.py │ ├── 2109_adding-spaces-to-a-string_1_AC.py │ ├── 2110_number-of-smooth-descent-periods-of-a-stock_1_AC.py │ ├── 2113_elements-in-array-after-removing-and-replacing-elements_1_AC.py │ ├── 2114_maximum-number-of-words-found-in-sentences_1_AC.py │ ├── 2115_find-all-possible-recipes-from-given-supplies_1_AC.py │ ├── 2119_a-number-after-a-double-reversal_1_AC.py │ ├── 2120_execution-of-all-suffix-instructions-staying-in-a-grid_1_AC.py │ ├── 2124_check-if-all-as-appears-before-all-bs_1_AC.py │ ├── 2125_number-of-laser-beams-in-a-bank_1_AC.py │ ├── 2126_destroying-asteroids_1_AC.py │ ├── 2129_capitalize-the-title_1_AC.py │ ├── 2130_maximum-twin-sum-of-a-linked-list_1_AC.py │ ├── 2133_check-if-every-row-and-column-contains-all-numbers_1_AC.py │ ├── 2134_minimum-swaps-to-group-all-1s-together-ii_1_AC.py │ ├── 2136_earliest-possible-day-of-full-bloom_1_AC.py │ ├── 2138_divide-a-string-into-groups-of-size-k_1_AC.py │ ├── 2139_minimum-moves-to-reach-target-score_1_AC.py │ ├── 2140_solving-questions-with-brainpower_1_AC.py │ ├── 2144_minimum-cost-of-buying-candies-with-discount_1_AC.py │ ├── 2148_count-elements-with-strictly-smaller-and-greater-elements_1_AC.py │ ├── 2149_rearrange-array-elements-by-sign_1_AC.py │ ├── 2150_find-all-lonely-numbers-in-the-array_1_AC.py │ ├── 2154_keep-multiplying-found-values-by-two_1_AC.py │ ├── 2155_all-divisions-with-the-highest-score-of-a-binary-array_1_AC.py │ ├── 2160_minimum-sum-of-four-digit-number-after-splitting-digits_1_AC.py │ ├── 2161_partition-array-according-to-given-pivot_1_AC.py │ ├── 2164_sort-even-and-odd-indices-independently_1_AC.py │ ├── 2165_smallest-value-of-the-rearranged-number_1_AC.py │ ├── 2169_count-operations-to-obtain-zero_1_AC.py │ ├── 2176_count-equal-and-divisible-pairs-in-an-array_1_AC.py │ ├── 2177_find-three-consecutive-integers-that-sum-to-a-given-number_1_AC.py │ ├── 2178_maximum-split-of-positive-even-integers_1_AC.py │ ├── 2180_count-integers-with-even-digit-sum_1_AC.py │ ├── 2181_merge-nodes-in-between-zeros_1_AC.py │ ├── 2182_construct-string-with-repeat-limit_1_AC.py │ ├── 2185_counting-words-with-a-given-prefix_1_AC.py │ ├── 2186_minimum-number-of-steps-to-make-two-strings-anagram-ii_1_AC.py │ ├── 2190_most-frequent-number-following-key-in-an-array_1_AC.py │ ├── 2191_sort-the-jumbled-numbers_1_AC.py │ ├── 2192_all-ancestors-of-a-node-in-a-directed-acyclic-graph_1_AC.py │ ├── 2194_cells-in-a-range-on-an-excel-sheet_1_AC.py │ ├── 2196_create-binary-tree-from-descriptions_1_AC.py │ ├── 2200_find-all-k-distant-indices-in-an-array_1_AC.py │ ├── 2201_count-artifacts-that-can-be-extracted_1_AC.py │ ├── 2206_divide-array-into-equal-pairs_1_AC.py │ ├── 2210_count-hills-and-valleys-in-an-array_1_AC.py │ ├── 2215_find-the-difference-of-two-arrays_1_AC.py │ ├── 2220_minimum-bit-flips-to-convert-number_1_AC.py │ ├── 2221_find-triangular-sum-of-an-array_1_AC.py │ ├── 2222_number-of-ways-to-select-buildings_1_AC.py │ ├── 2224_minimum-number-of-operations-to-convert-time_1_AC.py │ ├── 2225_find-players-with-zero-or-one-losses_1_AC.py │ ├── 2231_largest-number-after-digit-swaps-by-parity_1_AC.py │ ├── 2232_minimize-result-by-adding-parentheses-to-expression_1_AC.py │ ├── 2235_add-two-integers_1_AC.py │ ├── 2236_root-equals-sum-of-children_1_AC.py │ ├── 2239_find-closest-number-to-zero_1_AC.py │ ├── 2240_number-of-ways-to-buy-pens-and-pencils_1_AC.py │ ├── 2243_calculate-digit-sum-of-a-string_1_AC.py │ ├── 2244_minimum-rounds-to-complete-all-tasks_1_AC.py │ ├── 2248_intersection-of-multiple-arrays_1_AC.py │ ├── 2249_count-lattice-points-inside-a-circle_1_AC.py │ ├── 2255_count-prefixes-of-a-given-string_1_AC.py │ ├── 2257_count-unguarded-cells-in-the-grid_1_AC.py │ ├── 2259_remove-digit-from-number-to-maximize-result_1_AC.py │ ├── 2260_minimum-consecutive-cards-to-pick-up_1_AC.py │ ├── 2261_k-divisible-elements-subarrays_1_AC.py │ ├── 2264_largest-3-same-digit-number-in-string_1_AC.py │ ├── 2265_count-nodes-equal-to-average-of-subtree_1_AC.py │ ├── 2269_find-the-k-beauty-of-a-number_1_AC.py │ ├── 2273_find-resultant-array-after-removing-anagrams_1_AC.py │ ├── 2274_maximum-consecutive-floors-without-special-floors_1_AC.py │ ├── 2275_largest-combination-with-bitwise-and-greater-than-zero_1_AC.py │ ├── 2278_percentage-of-letter-in-string_1_AC.py │ ├── 2279_maximum-bags-with-full-capacity-of-rocks_1_AC.py │ ├── 2283_check-if-number-has-equal-digit-count-and-digit-value_1_AC.py │ ├── 2284_sender-with-largest-word-count_1_AC.py │ ├── 2285_maximum-total-importance-of-roads_1_AC.py │ ├── 2287_rearrange-characters-to-make-target-string_1_AC.py │ ├── 2290_minimum-obstacle-removal-to-reach-corner_1_AC.py │ ├── 2293_min-max-game_1_AC.py │ ├── 2294_partition-array-such-that-maximum-difference-is-k_1_AC.py │ ├── 2295_replace-elements-in-an-array_1_AC.py │ ├── 2299_strong-password-checker-ii_1_AC.py │ ├── 2303_calculate-amount-paid-in-taxes_1_AC.py │ ├── 2304_minimum-path-cost-in-a-grid_1_AC.py │ ├── 2305_fair-distribution-of-cookies_1_AC.py │ ├── 2309_greatest-english-letter-in-upper-and-lower-case_1_AC.py │ ├── 2315_count-asterisks_1_AC.py │ ├── 2317_maximum-xor-after-operations_1_AC.py │ ├── 2319_check-if-matrix-is-x-matrix_1_AC.py │ ├── 2325_decode-the-message_1_AC.py │ ├── 2326_spiral-matrix-iv_1_AC.py │ ├── 2331_evaluate-boolean-binary-tree_1_AC.py │ ├── 2335_minimum-amount-of-time-to-fill-cups_1_AC.py │ ├── 2336_smallest-number-in-infinite-set_1_AC.py │ ├── 2337_move-pieces-to-obtain-a-string_1_AC.py │ ├── 2341_maximum-number-of-pairs-in-array_1_AC.py │ ├── 2342_max-sum-of-a-pair-with-equal-sum-of-digits_1_AC.py │ ├── 2347_best-poker-hand_1_AC.py │ ├── 2348_number-of-zero-filled-subarrays_1_AC.py │ ├── 2350_shortest-impossible-sequence-of-rolls_1_AC.py │ ├── 2351_first-letter-to-appear-twice_1_AC.py │ ├── 2352_equal-row-and-column-pairs_1_AC.py │ ├── 2357_make-array-zero-by-subtracting-equal-amounts_1_AC.py │ ├── 2358_maximum-number-of-groups-entering-a-competition_1_AC.py │ ├── 2363_merge-similar-items_1_AC.py │ ├── 2365_task-scheduler-ii_1_AC.py │ ├── 2367_number-of-arithmetic-triplets_1_AC.py │ ├── 2368_reachable-nodes-with-restrictions_1_AC.py │ ├── 2369_check-if-there-is-a-valid-partition-for-the-array_1_AC.py │ ├── 2373_largest-local-values-in-a-matrix_1_AC.py │ ├── 2375_construct-smallest-number-from-di-string_1_AC.py │ ├── 2379_minimum-recolors-to-get-k-consecutive-black-blocks_1_AC.py │ ├── 2380_time-needed-to-rearrange-a-binary-string_1_AC.py │ ├── 2383_minimum-hours-of-training-to-win-a-competition_1_AC.py │ ├── 2385_amount-of-time-for-binary-tree-to-be-infected_1_AC.py │ ├── 2389_longest-subsequence-with-limited-sum_1_AC.py │ ├── 2390_removing-stars-from-a-string_1_AC.py │ ├── 2391_minimum-amount-of-time-to-collect-garbage_1_AC.py │ ├── 2392_build-a-matrix-with-conditions_1_AC.py │ ├── 2395_find-subarrays-with-equal-sum_1_AC.py │ ├── 2396_strictly-palindromic-number_1_AC.py │ ├── 2397_maximum-rows-covered-by-columns_1_AC.py │ ├── 2399_check-distances-between-same-letters_1_AC.py │ ├── 2401_longest-nice-subarray_1_AC.py │ ├── 2404_most-frequent-even-element_1_AC.py │ ├── 2405_optimal-partition-of-string_1_AC.py │ ├── 2406_divide-intervals-into-minimum-number-of-groups_1_AC.py │ ├── 2409_count-days-spent-together_1_AC.py │ ├── 2410_maximum-matching-of-players-with-trainers_1_AC.py │ ├── 2413_smallest-even-multiple_1_AC.py │ ├── 2414_length-of-the-longest-alphabetical-continuous-substring_1_AC.py │ ├── 2415_reverse-odd-levels-of-binary-tree_1_AC.py │ ├── 2418_sort-the-people_1_AC.py │ ├── 2419_longest-subarray-with-maximum-bitwise-and_1_AC.py │ ├── 2423_remove-letter-to-equalize-frequency_1_AC.py │ ├── 2424_longest-uploaded-prefix_1_AC.py │ ├── 2425_bitwise-xor-of-all-pairings_1_AC.py │ ├── 2427_number-of-common-factors_1_AC.py │ ├── 2428_maximum-sum-of-an-hourglass_1_AC.py │ ├── 2432_the-employee-that-worked-on-the-longest-task_1_AC.py │ ├── 2433_find-the-original-array-of-prefix-xor_1_AC.py │ ├── 2437_number-of-valid-clock-times_1_AC.py │ ├── 2441_largest-positive-integer-that-exists-with-its-negative_1_AC.py │ ├── 2442_count-number-of-distinct-integers-after-reverse-operations_1_AC.py │ ├── 2444_count-subarrays-with-fixed-bounds_1_AC.py │ ├── 2446_determine-if-two-events-have-conflict_1_AC.py │ ├── 2447_number-of-subarrays-with-gcd-equal-to-k_1_AC.py │ ├── 2449_minimum-number-of-operations-to-make-arrays-similar_1_AC.py │ ├── 2451_odd-string-difference_1_AC.py │ ├── 2452_words-within-two-edits-of-dictionary_1_AC.py │ ├── 2455_average-value-of-even-numbers-that-are-divisible-by-three_1_AC.py │ ├── 2460_apply-operations-to-an-array_1_AC.py │ ├── 2465_number-of-distinct-averages_1_AC.py │ ├── 2466_count-ways-to-build-good-strings_1_AC.py │ ├── 2469_convert-the-temperature_1_AC.py │ ├── 2471_minimum-number-of-operations-to-sort-a-binary-tree-by-level_1_AC.py │ ├── 2475_number-of-unequal-triplets-in-array_1_AC.py │ ├── 2477_minimum-fuel-cost-to-report-to-the-capital_1_AC.py │ ├── 2481_minimum-cuts-to-divide-a-circle_1_AC.py │ ├── 2482_difference-between-ones-and-zeros-in-row-and-column_1_AC.py │ ├── 2483_minimum-penalty-for-a-shop_1_AC.py │ ├── 2485_find-the-pivot-integer_1_AC.py │ ├── 2486_append-characters-to-string-to-make-subsequence_1_AC.py │ ├── 2487_remove-nodes-from-linked-list_1_AC.py │ ├── 2490_circular-sentence_1_AC.py │ ├── 2491_divide-players-into-teams-of-equal-skill_1_AC.py │ ├── 2492_minimum-score-of-a-path-between-two-cities_1_AC.py │ ├── 2496_maximum-value-of-a-string-in-an-array_1_AC.py │ ├── 2498_frog-jump-ii_1_AC.py │ └── 2500_delete-greatest-value-in-each-row_1_AC.py ├── 2501-3000 │ ├── 2501_longest-square-streak-in-an-array_1_AC.py │ ├── 2502_design-memory-allocator_1_AC.py │ ├── 2506_count-pairs-of-similar-strings_1_AC.py │ ├── 2511_maximum-enemy-forts-that-can-be-captured_1_AC.py │ ├── 2515_shortest-distance-to-target-string-in-a-circular-array_1_AC.py │ ├── 2516_take-k-of-each-character-from-left-and-right_1_AC.py │ ├── 2517_maximum-tastiness-of-candy-basket_1_AC.py │ ├── 2520_count-the-digits-that-divide-a-number_1_AC.py │ ├── 2521_distinct-prime-factors-of-product-of-array_1_AC.py │ ├── 2525_categorize-box-according-to-criteria_1_AC.py │ ├── 2527_find-xor-beauty-of-array_1_AC.py │ ├── 2529_maximum-count-of-positive-integer-and-negative-integer_1_AC.py │ ├── 2530_maximal-score-after-applying-k-operations_1_AC.py │ ├── 2535_difference-between-element-sum-and-digit-sum-of-an-array_1_AC.py │ ├── 2536_increment-submatrices-by-one_1_AC.py │ ├── 2537_count-the-number-of-good-subarrays_1_AC.py │ ├── 2540_minimum-common-value_1_AC.py │ ├── 2542_maximum-subsequence-score_1_AC.py │ ├── 2544_alternating-digit-sum_1_AC.py │ ├── 2545_sort-the-students-by-their-kth-score_1_AC.py │ ├── 2549_count-distinct-numbers-on-board_1_AC.py │ ├── 2551_put-marbles-in-bags_1_AC.py │ ├── 2553_separate-the-digits-in-an-array_1_AC.py │ ├── 2554_maximum-number-of-integers-to-choose-from-a-range-i_1_AC.py │ ├── 2558_take-gifts-from-the-richest-pile_1_AC.py │ ├── 2559_count-vowel-strings-in-ranges_1_AC.py │ ├── 2562_find-the-array-concatenation-value_1_AC.py │ ├── 2566_maximum-difference-by-remapping-a-digit_1_AC.py │ ├── 2568_minimum-impossible-or_1_AC.py │ ├── 2570_merge-two-2d-arrays-by-summing-values_1_AC.py │ ├── 2571_minimum-operations-to-reduce-an-integer-to-0_1_AC.py │ ├── 2574_left-and-right-sum-differences_1_AC.py │ ├── 2578_split-with-minimum-sum_1_AC.py │ ├── 2579_count-total-number-of-colored-cells_1_AC.py │ ├── 2582_pass-the-pillow_1_AC.py │ ├── 2583_kth-largest-sum-in-a-binary-tree_1_AC.py │ ├── 2586_count-the-number-of-vowel-strings-in-range_1_AC.py │ ├── 2588_count-the-number-of-beautiful-subarrays_1_AC.py │ ├── 2591_distribute-money-to-maximum-children_1_AC.py │ ├── 2592_maximize-greatness-of-an-array_1_AC.py │ ├── 2592_maximize-greatness-of-an-array_2_AC.py │ ├── 2593_find-score-of-an-array-after-marking-all-elements_1_AC.py │ ├── 2595_number-of-even-and-odd-bits_1_AC.py │ ├── 2596_check-knight-tour-configuration_1_AC.py │ ├── 2597_the-number-of-beautiful-subsets_1_AC.py │ ├── 2600_k-items-with-the-maximum-sum_1_AC.py │ ├── 2601_prime-subtraction-operation_1_AC.py │ ├── 2605_form-smallest-number-from-two-digit-arrays_1_AC.py │ ├── 2606_find-the-substring-with-maximum-cost_1_AC.py │ ├── 2609_find-the-longest-balanced-substring-of-a-binary-string_1_AC.py │ ├── 2610_convert-an-array-into-a-2d-array-with-conditions_1_AC.py │ ├── 2614_prime-in-diagonal_1_AC.py │ ├── 2639_find-the-width-of-columns-of-a-grid_1_AC.py │ ├── 2640_find-the-score-of-all-prefixes-of-an-array_1_AC.py │ ├── 2641_cousins-in-binary-tree-ii_1_AC.py │ ├── 2642_design-graph-with-shortest-path-calculator_1_AC.py │ ├── 2643_row-with-maximum-ones_1_AC.py │ ├── 2644_find-the-maximum-divisibility-score_1_AC.py │ ├── 2651_calculate-delayed-arrival-time_1_AC.py │ ├── 2652_sum-multiples_1_AC.py │ ├── 2656_maximum-sum-with-exactly-k-elements_1_AC.py │ ├── 2657_find-the-prefix-common-array-of-two-arrays_1_AC.py │ ├── 2658_maximum-number-of-fish-in-a-grid_1_AC.py │ ├── 2660_determine-the-winner-of-a-bowling-game_1_AC.py │ ├── 2670_find-the-distinct-difference-array_1_AC.py │ ├── 2672_number-of-adjacent-elements-with-the-same-color_1_AC.py │ ├── 2673_make-costs-of-paths-equal-in-a-binary-tree_1_AC.py │ ├── 2678_number-of-senior-citizens_1_AC.py │ ├── 2679_sum-in-a-matrix_1_AC.py │ ├── 2682_find-the-losers-of-the-circular-game_1_AC.py │ ├── 2683_neighboring-bitwise-xor_1_AC.py │ ├── 2684_maximum-number-of-moves-in-a-grid_1_AC.py │ ├── 2685_count-the-number-of-complete-components_1_AC.py │ ├── 2696_minimum-string-length-after-removing-substrings_1_AC.py │ ├── 2697_lexicographically-smallest-palindrome_1_AC.py │ ├── 2698_find-the-punishment-number-of-an-integer_1_AC.py │ ├── 2706_buy-two-chocolates_1_AC.py │ ├── 2707_extra-characters-in-a-string_1_AC.py │ ├── 2710_remove-trailing-zeros-from-a-string_1_AC.py │ ├── 2711_difference-of-number-of-distinct-values-on-diagonals_1_AC.py │ ├── 2712_minimum-cost-to-make-all-characters-equal_1_AC.py │ ├── 2716_minimize-string-length_1_AC.py │ ├── 2717_semi-ordered-permutation_1_AC.py │ ├── 2729_check-if-the-number-is-fascinating_1_AC.py │ ├── 2733_neither-minimum-nor-maximum_1_AC.py │ ├── 2739_total-distance-traveled_1_AC.py │ ├── 2740_find-the-value-of-the-partition_1_AC.py │ ├── 2744_find-maximum-number-of-string-pairs_1_AC.py │ ├── 2745_construct-the-longest-new-string_1_AC.py │ ├── 2748_number-of-beautiful-pairs_1_AC.py │ ├── 2760_longest-even-odd-subarray-with-threshold_1_AC.py │ ├── 2762_continuous-subarrays_1_AC.py │ ├── 2765_longest-alternating-subarray_1_AC.py │ ├── 2766_relocate-marbles_1_AC.py │ ├── 2767_partition-string-into-minimum-beautiful-substrings_1_AC.py │ ├── 2769_find-the-maximum-achievable-number_1_AC.py │ ├── 2778_sum-of-squares-of-special-elements_1_AC.py │ ├── 2779_maximum-beauty-of-an-array-after-applying-operation_1_AC.py │ ├── 2780_minimum-index-of-a-valid-split_1_AC.py │ ├── 2784_check-if-array-is-good_1_AC.py │ ├── 2785_sort-vowels-in-a-string_1_AC.py │ ├── 2788_split-strings-by-separator_1_AC.py │ ├── 2798_number-of-employees-who-met-the-target_1_AC.py │ ├── 2799_count-complete-subarrays-in-an-array_1_AC.py │ ├── 2806_account-balance-after-rounded-purchase_1_AC.py │ ├── 2807_insert-greatest-common-divisors-in-linked-list_1_AC.py │ ├── 2810_faulty-keyboard_1_AC.py │ ├── 2815_max-pair-sum-in-an-array_1_AC.py │ ├── 2816_double-a-number-represented-as-a-linked-list_1_AC.py │ ├── 2824_count-pairs-whose-sum-is-less-than-target_1_AC.py │ ├── 2825_make-string-a-subsequence-using-cyclic-increments_1_AC.py │ ├── 2828_check-if-a-string-is-an-acronym-of-words_1_AC.py │ ├── 2829_determine-the-minimum-sum-of-a-k-avoiding-array_1_AC.py │ ├── 2833_furthest-point-from-origin_1_AC.py │ ├── 2839_check-if-strings-can-be-made-equal-with-operations-i_1_AC.py │ ├── 2840_check-if-strings-can-be-made-equal-with-operations-ii_1_AC.py │ ├── 2843_count-symmetric-integers_1_AC.py │ ├── 2848_points-that-intersect-with-cars_1_AC.py │ ├── 2855_minimum-right-shifts-to-sort-the-array_1_AC.py │ ├── 2859_sum-of-values-at-indices-with-k-set-bits_1_AC.py │ ├── 2860_happy-students_1_AC.py │ ├── 2864_maximum-odd-binary-number_1_AC.py │ ├── 2869_minimum-operations-to-collect-elements_1_AC.py │ ├── 2870_minimum-number-of-operations-to-make-array-empty_1_AC.py │ ├── 2872_maximum-number-of-k-divisible-components_1_AC.py │ ├── 2873_maximum-value-of-an-ordered-triplet-i_1_AC.py │ ├── 2894_divisible-and-non-divisible-sums-difference_1_AC.py │ ├── 2895_minimum-processing-time_1_AC.py │ ├── 2899_last-visited-integers_1_AC.py │ ├── 2900_longest-unequal-adjacent-groups-subsequence-i_1_AC.py │ ├── 2903_find-indices-with-index-and-value-difference-i_1_AC.py │ ├── 2908_minimum-sum-of-mountain-triplets-i_1_AC.py │ ├── 2909_minimum-sum-of-mountain-triplets-ii_1_AC.py │ ├── 2913_subarrays-distinct-element-sum-of-squares-i_1_AC.py │ ├── 2914_minimum-number-of-changes-to-make-binary-string-beautiful_1_AC.py │ ├── 2917_find-the-k-or-of-an-array_1_AC.py │ ├── 2923_find-champion-i_1_AC.py │ ├── 2924_find-champion-ii_1_AC.py │ ├── 2928_distribute-candies-among-children-i_1_AC.py │ ├── 2930_number-of-strings-which-can-be-rearranged-to-contain-substring_1_AC.py │ ├── 2932_maximum-strong-pair-xor-i_1_AC.py │ ├── 2937_make-three-strings-equal_1_AC.py │ ├── 2938_separate-black-and-white-balls_1_AC.py │ ├── 2942_find-words-containing-character_1_AC.py │ ├── 2946_matrix-similarity-after-cyclic-shifts_1_AC.py │ ├── 2947_count-beautiful-substrings-i_1_AC.py │ ├── 2951_find-the-peaks_1_AC.py │ ├── 2952_minimum-number-of-coins-to-be-added_1_AC.py │ ├── 2956_find-common-elements-between-two-arrays_1_AC.py │ ├── 2957_remove-adjacent-almost-equal-characters_1_AC.py │ ├── 2958_length-of-longest-subarray-with-at-most-k-frequency_1_AC.py │ ├── 2960_count-tested-devices-after-test-operations_1_AC.py │ ├── 2962_count-subarrays-where-max-element-appears-at-least-k-times_1_AC.py │ ├── 2965_find-missing-and-repeated-values_1_AC.py │ ├── 2966_divide-array-into-arrays-with-max-difference_1_AC.py │ ├── 2970_count-the-number-of-incremovable-subarrays-i_1_AC.py │ ├── 2971_find-polygon-with-the-largest-perimeter_1_AC.py │ ├── 2974_minimum-number-game_1_AC.py │ ├── 2976_minimum-cost-to-convert-string-i_1_AC.py │ ├── 2980_check-if-bitwise-or-has-trailing-zeros_1_AC.py │ ├── 2981_find-longest-special-substring-that-occurs-thrice-i_1_AC.py │ ├── 2996_smallest-missing-integer-greater-than-sequential-prefix-sum_1_AC.py │ ├── 2997_minimum-number-of-operations-to-make-array-xor-equal-to-k_1_AC.py │ └── 3000_maximum-area-of-longest-diagonal-rectangle_1_AC.py └── 3001-3500 │ ├── 3005_count-elements-with-maximum-frequency_1_AC.py │ ├── 3010_divide-an-array-into-subarrays-with-minimum-cost-i_1_AC.py │ ├── 3011_find-if-array-can-be-sorted_1_AC.py │ ├── 3014_minimum-number-of-pushes-to-type-word-i_1_AC.py │ ├── 3015_count-the-number-of-houses-at-a-certain-distance-i_1_AC.py │ ├── 3016_minimum-number-of-pushes-to-type-word-ii_1_AC.py │ ├── 3019_number-of-changing-keys_1_AC.py │ ├── 3024_type-of-triangle_1_AC.py │ ├── 3028_ant-on-the-boundary_1_AC.py │ ├── 3033_modify-the-matrix_1_AC.py │ ├── 3034_number-of-subarrays-that-match-a-pattern-i_1_AC.py │ ├── 3038_maximum-number-of-operations-with-the-same-score-i_1_AC.py │ ├── 3039_apply-operations-to-make-string-empty_1_AC.py │ ├── 3042_count-prefix-and-suffix-pairs-i_1_AC.py │ ├── 3043_find-the-length-of-the-longest-common-prefix_1_AC.py │ ├── 3046_split-the-array_1_AC.py │ ├── 3065_minimum-operations-to-exceed-threshold-value-i_1_AC.py │ ├── 3067_count-pairs-of-connectable-servers-in-a-weighted-tree-network_1_AC.py │ ├── 3068_find-the-maximum-sum-of-node-values_1_AC.py │ ├── 3069_distribute-elements-into-two-arrays-i_1_AC.py │ ├── 3070_count-submatrices-with-top-left-element-and-sum-less-than-k_1_AC.py │ ├── 3071_minimum-operations-to-write-the-letter-y-on-a-grid_1_AC.py │ ├── 3074_apple-redistribution-into-boxes_1_AC.py │ ├── 3075_maximize-happiness-of-selected-children_1_AC.py │ ├── 3079_find-the-sum-of-encrypted-integers_1_AC.py │ ├── 3083_existence-of-a-substring-in-a-string-and-its-reverse_1_AC.py │ ├── 3090_maximum-length-substring-with-two-occurrences_1_AC.py │ ├── 3095_shortest-subarray-with-or-at-least-k-i_1_AC.py │ ├── 3097_shortest-subarray-with-or-at-least-k-ii_1_AC.py │ ├── 3099_harshad-number_1_AC.py │ ├── 3100_water-bottles-ii_1_AC.py │ ├── 3101_count-alternating-subarrays_1_AC.py │ ├── 3105_longest-strictly-increasing-or-strictly-decreasing-subarray_1_AC.py │ ├── 3106_lexicographically-smallest-string-after-operations-with-constraint_1_AC.py │ ├── 3110_score-of-a-string_1_AC.py │ ├── 3111_minimum-rectangles-to-cover-points_1_AC.py │ ├── 3114_latest-time-you-can-obtain-after-replacing-characters_1_AC.py │ ├── 3115_maximum-prime-difference_1_AC.py │ ├── 3120_count-the-number-of-special-characters-i_1_AC.py │ ├── 3127_make-a-square-with-the-same-color_1_AC.py │ ├── 3131_find-the-integer-added-to-array-i_1_AC.py │ ├── 3133_minimum-array-end_1_AC.py │ ├── 3136_valid-word_1_AC.py │ ├── 3137_minimum-number-of-operations-to-make-word-k-periodic_1_AC.py │ ├── 3142_check-if-grid-satisfies-conditions_1_AC.py │ ├── 3146_permutation-difference-between-two-strings_1_AC.py │ ├── 3151_special-array-i_1_AC.py │ ├── 3158_find-the-xor-of-numbers-which-appear-twice_1_AC.py │ ├── 3159_find-occurrences-of-an-element-in-an-array_1_AC.py │ ├── 3162_find-the-number-of-good-pairs-i_1_AC.py │ ├── 3163_string-compression-iii_1_AC.py │ ├── 3168_minimum-number-of-chairs-in-a-waiting-room_1_AC.py │ ├── 3174_clear-digits_1_AC.py │ ├── 3178_find-the-child-who-has-the-ball-after-k-seconds_1_AC.py │ ├── 3179_find-the-n-th-value-after-k-seconds_1_AC.py │ ├── 3184_count-pairs-that-form-a-complete-day-i_1_AC.py │ ├── 3190_find-minimum-operations-to-make-all-elements-divisible-by-three_1_AC.py │ ├── 3191_minimum-operations-to-make-binary-array-elements-equal-to-one-i_1_AC.py │ ├── 3192_minimum-operations-to-make-binary-array-elements-equal-to-one-ii_1_AC.py │ ├── 3194_minimum-average-of-smallest-and-largest-elements_1_AC.py │ ├── 3195_find-the-minimum-area-to-cover-all-ones-i_1_AC.py │ ├── 3200_maximum-height-of-a-triangle_1_AC.py │ ├── 3206_alternating-groups-i_1_AC.py │ ├── 3210_find-the-encrypted-string_1_AC.py │ ├── 3211_generate-binary-strings-without-adjacent-zeros_1_AC.py │ ├── 3212_count-submatrices-with-equal-frequency-of-x-and-y_1_AC.py │ ├── 3216_lexicographically-smallest-string-after-a-swap_1_AC.py │ ├── 3217_delete-nodes-from-linked-list-present-in-array_1_AC.py │ ├── 3218_minimum-cost-for-cutting-cake-i_1_AC.py │ ├── 3222_find-the-winning-player-in-coin-game_1_AC.py │ ├── 3223_minimum-length-of-string-after-operations_1_AC.py │ ├── 3226_number-of-bit-changes-to-make-two-integers-equal_1_AC.py │ ├── 3227_vowels-game-in-a-string_1_AC.py │ ├── 3228_maximum-number-of-operations-to-move-ones-to-the-end_1_AC.py │ ├── 3232_find-if-digit-game-can-be-won_1_AC.py │ ├── 3238_find-the-number-of-winning-players_1_AC.py │ ├── 3239_minimum-number-of-flips-to-make-binary-grid-palindromic-i_1_AC.py │ ├── 3242_design-neighbor-sum-service_1_AC.py │ ├── 3243_shortest-distance-after-road-addition-queries-i_1_AC.py │ ├── 3243_shortest-distance-after-road-addition-queries-i_2_AC.py │ ├── 3248_snake-in-matrix_1_AC.py │ ├── 3249_count-the-number-of-good-nodes_1_AC.py │ ├── 3254_find-the-power-of-k-size-subarrays-i_1_AC.py │ ├── 3258_count-substrings-that-satisfy-k-constraint-i_1_AC.py │ ├── 3264_final-array-state-after-k-multiplication-operations-i_1_AC.py │ ├── 3270_find-the-key-of-the-numbers_1_AC.py │ ├── 3271_hash-divided-string_1_AC.py │ ├── 3274_check-if-two-chessboard-squares-have-the-same-color_1_AC.py │ ├── 3280_convert-date-to-binary_1_AC.py │ ├── 3285_find-indices-of-stable-mountains_1_AC.py │ ├── 3289_the-two-sneaky-numbers-of-digitville_1_AC.py │ ├── 3300_minimum-element-after-replacement-with-digit-sum_1_AC.py │ ├── 3304_find-the-k-th-character-in-string-game-i_1_AC.py │ ├── 3309_maximum-possible-number-by-binary-concatenation_1_AC.py │ ├── 3310_remove-methods-from-project_1_AC.py │ ├── 3314_construct-the-minimum-bitwise-array-i_1_AC.py │ ├── 3318_find-x-sum-of-all-k-long-subarrays-i_1_AC.py │ ├── 3319_k-th-largest-perfect-subtree-size-in-binary-tree_1_AC.py │ ├── 3324_find-the-sequence-of-strings-appeared-on-the-screen_1_AC.py │ ├── 3325_count-substrings-with-k-frequency-characters-i_1_AC.py │ ├── 3330_find-the-original-typed-string-i_1_AC.py │ ├── 3331_find-subtree-sizes-after-changes_1_AC.py │ ├── 3340_check-balanced-string_1_AC.py │ ├── 3345_smallest-divisible-digit-product-i_1_AC.py │ ├── 3349_adjacent-increasing-subarrays-detection-i_1_AC.py │ ├── 3354_make-array-elements-equal-to-zero_1_AC.py │ ├── 3360_stone-removal-game_1_AC.py │ ├── 3361_shift-distance-between-two-strings_1_AC.py │ ├── 3364_minimum-positive-sum-subarray_1_AC.py │ ├── 3365_rearrange-k-substrings-to-form-target-string_1_AC.py │ ├── 3370_smallest-number-with-all-set-bits_1_AC.py │ └── 3387_maximize-amount-after-two-days-of-conversions_1_AC.py ├── concurrency ├── 1114_print-in-order_1_AC.py ├── 1115_print-foobar-alternately_1_AC.py ├── 1116_print-zero-even-odd_1_AC.py ├── 1117_building-h2o_1_AC.py ├── 1188_design-bounded-blocking-queue_1_AC.py ├── 1195_fizz-buzz-multithreaded_1_AC.py ├── 1226_the-dining-philosophers_1_AC.py ├── 1242_web-crawler-multithreaded_1_AC.py └── 1279_traffic-light-controlled-intersection_1_AC.py ├── database ├── 0175_combine-two-tables_1_AC.sql ├── 0176_second-highest-salary_1_AC.sql ├── 0177_nth-highest-salary_1_AC.sql ├── 0178_rank-scores_1_AC.sql ├── 0180_consecutive-numbers_1_AC.sql ├── 0181_employees-earning-more-than-their-managers_1_AC.sql ├── 0182_duplicate-emails_1_AC.sql ├── 0183_customers-who-never-order_1_AC.sql ├── 0184_department-highest-salary_1_AC.sql ├── 0185_department-top-three-salaries_1_AC.sql ├── 0196_delete-duplicate-emails_1_AC.sql ├── 0197_rising-temperature_1_AC.sql ├── 0511_game-play-analysis-i_1_AC.sql ├── 0512_game-play-analysis-ii_1_AC.sql ├── 0534_game-play-analysis-iii_1_AC.sql ├── 0550_game-play-analysis-iv_1_AC.sql ├── 0570_managers-with-at-least-5-direct-reports_1_AC.sql ├── 0574_winning-candidate_1_AC.sql ├── 0577_employee-bonus_1_AC.sql ├── 0578_get-highest-answer-rate-question_1_AC.sql ├── 0580_count-student-number-in-departments_1_AC.sql ├── 0584_find-customer-referee_1_AC.sql ├── 0585_investments-in-2016_1_AC.sql ├── 0586_customer-placing-the-largest-number-of-orders_1_AC.sql ├── 0595_big-countries_1_AC.sql ├── 0596_classes-more-than-5-students_1_AC.sql ├── 0597_friend-requests-i-overall-acceptance-rate_1_AC.sql ├── 0602_friend-requests-ii-who-has-the-most-friends_1_AC.sql ├── 0603_consecutive-available-seats_1_AC.sql ├── 0607_sales-person_1_AC.sql ├── 0608_tree-node_1_AC.sql ├── 0610_triangle-judgement_1_AC.sql ├── 0612_shortest-distance-in-a-plane_1_AC.sql ├── 0613_shortest-distance-in-a-line_1_AC.sql ├── 0614_second-degree-follower_1_AC.sql ├── 0619_biggest-single-number_1_AC.sql ├── 0620_not-boring-movies_1_AC.sql ├── 0626_exchange-seats_1_AC.sql ├── 0627_swap-salary_1_AC.sql ├── 1045_customers-who-bought-all-products_1_AC.sql ├── 1050_actors-and-directors-who-cooperated-at-least-three-times_1_AC.sql ├── 1068_product-sales-analysis-i_1_AC.sql ├── 1069_product-sales-analysis-ii_1_AC.sql ├── 1070_product-sales-analysis-iii_1_AC.sql ├── 1075_project-employees-i_1_AC.sql ├── 1076_project-employees-ii_1_AC.sql ├── 1077_project-employees-iii_1_AC.sql ├── 1077_project-employees-iii_2_AC.sql ├── 1082_sales-analysis-i_1_AC.sql ├── 1083_sales-analysis-ii_1_AC.sql ├── 1084_sales-analysis-iii_1_AC.sql ├── 1098_unpopular-books_1_AC.sql ├── 1107_new-users-daily-count_1_AC.sql ├── 1112_highest-grade-for-each-student_1_AC.sql ├── 1113_reported-posts_1_AC.sql ├── 1126_active-businesses_1_AC.sql ├── 1132_reported-posts-ii_1_AC.sql ├── 1141_user-activity-for-the-past-30-days-i_1_AC.sql ├── 1142_user-activity-for-the-past-30-days-ii_1_AC.sql ├── 1148_article-views-i_1_AC.sql ├── 1149_article-views-ii_1_AC.sql ├── 1158_market-analysis-i_1_AC.sql ├── 1164_product-price-at-a-given-date_1_AC.sql ├── 1173_immediate-food-delivery-i_1_AC.sql ├── 1174_immediate-food-delivery-ii_1_AC.sql ├── 1179_reformat-department-table_1_AC.sql ├── 1193_monthly-transactions-i_1_AC.sql ├── 1204_last-person-to-fit-in-the-elevator_1_AC.sql ├── 1205_monthly-transactions-ii_1_AC.sql ├── 1211_queries-quality-and-percentage_1_AC.sql ├── 1212_team-scores-in-football-tournament_1_AC.sql ├── 1241_number-of-comments-per-post_1_AC.sql ├── 1251_average-selling-price_1_AC.sql ├── 1264_page-recommendations_1_AC.sql ├── 1270_all-people-report-to-the-given-manager_1_AC.sql ├── 1280_students-and-examinations_AC.sql ├── 1285_find-the-start-and-end-number-of-continuous-ranges_1_AC.sql ├── 1294_weather-type-in-each-country_1_AC.sql ├── 1303_find-the-team-size_1_AC.sql ├── 1308_running-total-for-different-genders_1_AC.sql ├── 1321_restaurant-growth_1_AC.sql ├── 1322_ads-performance_1_AC.sql ├── 1322_ads-performance_2_AC.sql ├── 1327_list-the-products-ordered-in-a-period_1_AC.sql ├── 1341_movie-rating_1_AC.sql ├── 1350_students-with-invalid-departments_1_AC.sql ├── 1355_activity-participants_1_AC.sql ├── 1364_number-of-trusted-contacts-of-a-customer_1_AC.sql ├── 1378_replace-employee-id-with-the-unique-identifier_1_AC.sql ├── 1384_total-sales-amount-by-year_1_AC.sql └── 1393_capital-gainloss_1_AC.sql ├── explore ├── 30-day-leetcoding-challenge │ ├── 3283_single-number_1_AC.py │ ├── 3284_happy-number_1_AC.py │ ├── 3285_maximum-subarray_1_AC.py │ ├── 3286_move-zeros_1_AC.py │ ├── 3287_best-time-to-buy-and-sell-stock-ii_1_AC.py │ ├── 3288_group-anagrams_1_AC.py │ ├── 3289_counting-elements_1_AC.py │ ├── 3290_middle-of-the-linked-list_1_AC.py │ ├── 3291_backspace-string-compare_1_AC.py │ ├── 3292_min-stack_1_AC.py │ ├── 3293_diameter-of-binary-tree_1_AC.py │ ├── 3297_last-stone-weight_1_AC.py │ ├── 3298_contiguous-array_1_AC.py │ ├── 3299_perform-string-shifts_1_AC.py │ ├── 3300_product-of-array-except-self_1_AC.py │ ├── 3301_valid-parenthesis-string_1_AC.py │ ├── 3302_number-of-islands_1_AC.py │ ├── 3303_minimum-path-sum_1_AC.py │ ├── 3304_search-in-rotated-sorted-array_1_AC.py │ ├── 3305_construct-binary-search-tree-from-preorder-traversal_1_AC.py │ ├── 3306_leftmost-column-with-at-least-a-one_1_AC.py │ ├── 3307_subarray-sum-equals-k_1_AC.py │ ├── 3308_bitwise-and-of-numbers-range_1_AC.py │ ├── 3309_lru-cache_1_AC.py │ ├── 3310_jump-game_1_AC.py │ ├── 3311_longest-common-subsequence_1_AC.py │ ├── 3312_maximal-square_1_AC.py │ ├── 3313_first-unique-number_1_AC.py │ ├── 3314_binary-tree-maximum-path-sum_1_AC.cpp │ └── 3315-check-if-a-string-is-a-valid-sequence-from-root-to-leaves-path-in-a-binary-tree_1_AC.py ├── adobe │ ├── 2489_two-sum_1_AC.cpp │ ├── 2490_longest-substring-without-repeating-characters_1_AC.cpp │ ├── 2491_container-with-most-water_1_AC.cpp │ ├── 2492_integer-to-roman_1_AC.cpp │ ├── 2493_roman-to-integer_1_AC.cpp │ ├── 2494_longest-common-prefix_1_AC.cpp │ ├── 2495_3sum_1_AC.cpp │ ├── 2496_3sum-closest_1_AC.cpp │ ├── 2497_4sum_1_AC.cpp │ ├── 2498_substring-with-concatenation-of-all-words_1_AC.cpp │ ├── 2499_spiral-matrix_1_AC.cpp │ ├── 2500_product-of-array-except-self_1_AC.py │ ├── 2501_missing-number_1_AC.cpp │ ├── 2502_find-all-numbers-disappeared-in-an-array_1_AC.cpp │ ├── 2503_positions-of-large-groups_1_AC.py │ ├── 2504_unique-email-addresses_1_AC.py │ ├── 2505_add-two-numbers_1_AC.cpp │ ├── 2506_remove-nth-node-from-end-of-list_1_AC.cpp │ ├── 2507_merge-two-sorted-lists_1_AC.cpp │ ├── 2508_copy-list-with-random-pointer_1_AC.cpp │ ├── 2509_linked-list-cycle_1_AC.cpp │ ├── 2510_reverse-linked-list_1_AC.cpp │ ├── 2511_median-of-two-sorted-arrays_1_AC.cpp │ ├── 2512_search-insert-position_1_AC.cpp │ ├── 2513_longest-palindromic-substring_1_AC.cpp │ ├── 2514_regular-expression-matching_1_AC.py │ ├── 2516_best-time-to-buy-and-sell-stock_1_AC.cpp │ ├── 2517_maximum-product-subarray_1_AC.cpp │ ├── 2518_longest-increasing-subsequence_1_AC.cpp │ ├── 2520_reverse-integer_1_AC.cpp │ ├── 2524_tenth-line_1_AC.sh │ ├── 2525_add-digits_1_AC.cpp │ ├── 2526_nth-digit_1_AC.cpp │ ├── 2527_encode-and-decode-tinyurl_1_AC.cpp │ ├── 2529_jewels-and-stones_1_AC.cpp │ ├── 2530_rectangle-overlap_1_AC.py │ ├── 2531_merge-k-sorted-lists_1_AC.cpp │ ├── 2532_simplify-path_1_AC.cpp │ ├── 2533_basic-calculator_1_AC.cpp │ ├── 2534_remove-k-digits_1_AC.cpp │ ├── 2535_lru-cache_1_AC.cpp │ ├── 2538_sum-of-left-leaves_1_AC.cpp │ ├── 2539_combine-two-tables_1_AC.sql │ ├── 2540_nth-highest-salary_1_AC.sql │ ├── 2541_department-top-three-salaries_1_AC.sql │ ├── 2542_big-countries_1_AC.sql │ ├── 2543_binary-tree-inorder-traversal_1_AC.cpp │ ├── 2544_validate-binary-search-tree_1_AC.cpp │ ├── 2545_binary-tree-zigzag-level-order-traversal_1_AC.cpp │ ├── 2546_perfect-squares_1_AC.cpp │ ├── 2547_maximum-subarray_1_AC.py │ ├── 2548_climbing-stairs_1_AC.cpp │ ├── 2549_maximal-rectangle_1_AC.cpp │ ├── 2550_min-stack_1_AC.py │ └── 2551_merge-intervals_1_AC.cpp ├── amazon │ ├── 0478_lru-cache_1_AC.cpp │ ├── 0480_first-unique-character-in-a-string_1_AC.cpp │ ├── 0481_integer-to-english-words_1_AC.cpp │ ├── 0482_kth-largest-element-in-an-array_1_AC.cpp │ ├── 0483_word-ladder-ii_1_AC.cpp │ ├── 0489_longest-palindromic-substring_1_AC.cpp │ ├── 0495_find-median-from-data-stream_1_AC.cpp │ ├── 0497_meeting-rooms-ii_1_AC.cpp │ ├── 0499_product-of-array-except-self_1_AC.py │ ├── 0502_compare-version-numbers_1_AC.cpp │ ├── 0503_min-stack_1_AC.py │ ├── 0505_best-time-to-buy-and-sell-stock_1_AC.cpp │ ├── 0506_binary-tree-level-order-traversal_1_AC.cpp │ ├── 0507_symmetric-tree_1_AC.cpp │ ├── 0508_two-sum_1_AC.cpp │ ├── 0512_merge-k-sorted-lists_1_AC.cpp │ ├── 0513_add-two-numbers_1_AC.cpp │ ├── 0514_validate-binary-search-tree_1_AC.cpp │ ├── 0517_design-tic-tac-toe_1_AC.cpp │ ├── 0521_letter-combinations-of-a-phone-number_1_AC.cpp │ ├── 0894_number-of-islands_1_AC.py │ ├── 0902_minimum-window-substring_1_AC.cpp │ ├── 2961_longest-substring-without-repeating-characters_1_AC.cpp │ ├── 2962_string-to-integer-atoi_1_AC.cpp │ ├── 2963_container-with-most-water_1_AC.cpp │ ├── 2964_integer-to-roman_1_AC.cpp │ ├── 2965_roman-to-integer_1_AC.cpp │ ├── 2966_3sum_1_AC.cpp │ ├── 2967_3sum-closest_1_AC.cpp │ ├── 2968_implement-strstr_1_AC.cpp │ ├── 2969_rotate-image_1_AC.cpp │ ├── 2970_group-anagrams_1_AC.py │ ├── 2971_missing-number_1_AC.cpp │ ├── 2972_valid-parentheses_1_AC.cpp │ ├── 2973_most-common-word_1_AC.py │ ├── 2974_reorder-log-files_1_AC.py │ ├── 2975_trapping-rain-water_1_AC.cpp │ ├── 2976_merge-two-sorted-lists_1_AC.cpp │ ├── 2977_reverse-nodes-in-k-group_1_AC.cpp │ ├── 2978_copy-list-with-random-pointer_1_AC.cpp │ ├── 2979_reverse-linked-list_1_AC.cpp │ ├── 2980_binary-tree-zigzag-level-order-traversal_1_AC.cpp │ ├── 2981_binary-tree-maximum-path-sum_1_AC.cpp │ ├── 2982_word-ladder_1_AC.cpp │ ├── 2983_course-schedule_1_AC.cpp │ ├── 2984_lowest-common-ancestor-of-a-binary-tree_1_AC.py │ ├── 2985_diameter-of-binary-tree_1_AC.py │ ├── 2986_cut-off-trees-for-golf-event_1_AC.py │ ├── 2987_flood-fill_1_AC.cpp │ ├── 2988_generate-parentheses_1_AC.cpp │ ├── 2989_word-search_1_AC.cpp │ ├── 2990_word-search-ii_1_AC.cpp │ ├── 2991_median-of-two-sorted-arrays_1_AC.cpp │ ├── 2992_search-in-rotated-sorted-array_1_AC.py │ ├── 2993_merge-intervals_1_AC.cpp │ ├── 2994_two-sum-ii-input-array-is-sorted_1_AC.cpp │ ├── 2995_top-k-frequent-elements_1_AC.cpp │ ├── 2996_k-closest-points-to-origin_1_AC.py │ ├── 2997_word-break_1_AC.cpp │ ├── 2998_coin-change_1_AC.cpp │ ├── 2999_serialize-and-deserialize-binary-tree_1_AC.cpp │ ├── 3000_design-search-autocomplete-system_1_AC.py │ ├── 3001_maximum-frequency-stack_1_AC.py │ ├── 3002_reverse-integer_1_AC.cpp │ ├── 3003_second-highest-salary_1_AC.sql │ ├── 3004_partition-labels_1_AC.py │ ├── 3005_prison-cells-after-n-days_1_AC.py │ └── 3285_maximum-subarray_1_AC.py ├── apple │ ├── 2008_two-sum_1_AC.cpp │ ├── 2009_longest-substring-without-repeating-characters_1_AC.cpp │ ├── 2010_string-to-integer-atoi_1_AC.cpp │ ├── 2012_3sum_1_AC.cpp │ ├── 2015_spiral-matrix_1_AC.cpp │ ├── 2017_minimum-window-substring_1_AC.cpp │ ├── 2018_first-unique-character-in-a-string_1_AC.cpp │ ├── 2021_add-two-numbers_1_AC.cpp │ ├── 2022_merge-two-sorted-lists_1_AC.cpp │ ├── 2024_reverse-linked-list_1_AC.cpp │ ├── 2025_median-of-two-sorted-arrays_1_AC.cpp │ ├── 2026_merge-intervals_1_AC.cpp │ ├── 2027_valid-anagram_1_AC.cpp │ ├── 2028_longest-palindromic-substring_1_AC.cpp │ ├── 2029_maximum-subarray_1_AC.cpp │ ├── 2034_reverse-integer_1_AC.cpp │ ├── 2035_rank-scores_1_AC.sql │ ├── 2040_sparse-matrix-multiplication_1_AC.cpp │ ├── 2042_fizz-buzz_1_AC.cpp │ ├── 2044_trapping-rain-water_1_AC.cpp │ ├── 2048_number-of-islands_1_AC.cpp │ ├── 2049_longest-increasing-path-in-a-matrix_1_AC.cpp │ ├── 2053_lru-cache_1_AC.cpp │ ├── 3106_integer-to-roman_1_AC.cpp │ ├── 3107_roman-to-integer_1_AC.cpp │ ├── 3108_3sum-closest_1_AC.cpp │ ├── 3109_4sum_1_AC.cpp │ ├── 3110_group-anagrams_1_AC.cpp │ ├── 3111_valid-palindrome_1_AC.cpp │ ├── 3112_majority-element-ii_1_AC.cpp │ ├── 3113_product-of-array-except-self_1_AC.cpp │ ├── 3114_missing-number_1_AC.cpp │ ├── 3115_subarray-sum-equals-k_1_AC.cpp │ ├── 3116_squares-of-a-sorted-array_1_AC.py │ ├── 3117_valid-parentheses_1_AC.cpp │ ├── 3118_same-tree_1_AC.cpp │ ├── 3119_maximum-depth-of-binary-tree_1_AC.cpp │ ├── 3120_clone-graph_1_AC.cpp │ ├── 3121_lowest-common-ancestor-of-a-binary-tree_1_AC.py │ ├── 3122_diameter-of-binary-tree_1_AC.py │ ├── 3123_letter-combinations-of-a-phone-number_1_AC.cpp │ ├── 3124_generate-parentheses_1_AC.cpp │ ├── 3125_combination-sum_1_AC.cpp │ ├── 3126_permutations_1_AC.cpp │ ├── 3127_subsets_1_AC.cpp │ ├── 3128_word-search_1_AC.cpp │ ├── 3129_search-in-rotated-sorted-array_1_AC.cpp │ ├── 3130_sort-colors_1_AC.cpp │ ├── 3131_intersection-of-two-arrays_1_AC.cpp │ ├── 3132_intersection-of-two-arrays-ii_1_AC.cpp │ ├── 3133_top-k-frequent-words_1_AC.cpp │ ├── 3134_k-closest-points-to-origin_1_AC.py │ ├── 3135_regular-expression-matching_1_AC.py │ ├── 3136_best-time-to-buy-and-sell-stock_1_AC.cpp │ ├── 3137_word-break_1_AC.cpp │ ├── 3138_min-stack_1_AC.py │ ├── 3139_flatten-nested-list-iterator_1_AC.cpp │ ├── 3140_insert-delete-getrandom-o1_1_AC.cpp │ ├── 3141_valid-sudoku_1_AC.cpp │ ├── 3142_combine-two-tables_1_AC.sql │ ├── 3143_happy-number_1_AC.py │ └── 3144_jewels-and-stones_1_AC.cpp ├── array-and-string │ ├── 1144_find-pivot-index_1_AC.cpp │ ├── 1147_largest-number-at-least-twice-of-others_1_AC.cpp │ ├── 1148_plus-one_1_AC.cpp │ ├── 1151_remove-element_1_AC.cpp │ ├── 1153_two-sum-ii-input-array-is-sorted_1_AC.cpp │ ├── 1154_array-partition-i_1_AC.cpp │ ├── 1160_add-binary_1_AC.cpp │ ├── 1161_implement-strstr_1_AC.cpp │ ├── 1162_longest-common-prefix_1_AC.cpp │ ├── 1164_reverse-words-in-a-string_1_AC.cpp │ ├── 1165_reverse-words-in-a-string-iii_1_AC.cpp │ ├── 1167_diagonal-traverse_1_AC.cpp │ ├── 1168_spiral-matrix_1_AC.cpp │ ├── 1170_pascals-triangle_1_AC.cpp │ ├── 1171_pascals-triangle-ii_1_AC.cpp │ ├── 1173_remove-duplicates-from-sorted-array_1_AC.cpp │ ├── 1174_move-zeros_1_AC.py │ ├── 1182_rotate-array_1_AC.cpp │ ├── 1183_reverse-string_1_AC.cpp │ ├── 1299_minimum-size-subarray-sum_1_AC.cpp │ └── 1301_max-consecutive-ones_1_AC.cpp ├── binary-search │ ├── 0944_search-for-a-range_1_AC.cpp │ ├── 0945_find-k-closest-elements_1_AC.py │ ├── 0946_find-peak-element_1_AC.cpp │ ├── 0947_first-bad-version_1_AC.cpp │ ├── 0948_find-peak-element_1_AC.cpp │ ├── 0949_find-minimum-in-rotated-sorted-array_1_AC.cpp │ ├── 0950_sqrtx_1_AC.cpp │ ├── 0951_guess-number-higher-or-lower_1_AC.cpp │ ├── 0952_search-in-rotated-sorted-array_1_AC.cpp │ ├── 0977_find-smallest-letter-greater-than-target_1_AC.cpp │ ├── 0978_valid-perfect-square_1_AC.cpp │ ├── 0982_powx-n_1_AC.cpp │ ├── 1028_closest-binary-search-tree-value_1_AC.cpp │ ├── 1029_intersection-of-two-arrays-ii_1_AC.cpp │ ├── 1031_find-minimum-in-rotated-sorted-array-ii_1_AC.cpp │ ├── 1033_find-minimum-in-rotated-sorted-array_1_AC.cpp │ ├── 1034_intersection-of-two-arrays_1_AC.cpp │ ├── 1035_two-sum-ii-input-array-is-sorted_1_AC.cpp │ ├── 1038_binary-search_1_AC.cpp │ ├── 1039_find-the-duplicate-number_1_AC.cpp │ ├── 1040_median-of-two-sorted-arrays_1_AC.cpp │ ├── 1041_find-k-th-smallest-pair-distance_1_AC.py │ ├── 1042_split-array-largest-sum_1_AC.cpp │ └── 1061_search-in-a-sorted-array-of-unknown-size_1_AC.py ├── bloomberg │ ├── 0373_first-unique-character-in-a-string_1_AC.cpp │ ├── 0375_number-of-islands_1_AC.cpp │ ├── 0378_populating-next-right-pointers-in-each-node_1_AC.cpp │ ├── 0379_populating-next-right-pointers-in-each-node-ii_1_AC.cpp │ ├── 0381_validate-binary-search-tree_1_AC.cpp │ ├── 0382_trapping-rain-water_1_AC.cpp │ ├── 0383_move-zeros_1_AC.py │ ├── 0384_valid-parentheses_1_AC.cpp │ ├── 0385_add-two-numbers_1_AC.cpp │ ├── 0389_alien-dictionary_1_AC.cpp │ ├── 0392_merge-sorted-array_1_AC.cpp │ ├── 0395_spiral-matrix_1_AC.cpp │ ├── 0402_string-compression_1_AC.cpp │ ├── 0405_search-in-rotated-sorted-array_1_AC.cpp │ ├── 0408_sliding-window-maximum_1_AC.cpp │ ├── 0411_kth-smallest-element-in-a-bst_1_AC.cpp │ ├── 0417_word-break_1_AC.cpp │ ├── 0423_moving-average-from-data-stream_1_AC.cpp │ ├── 0431_reverse-linked-list_1_AC.cpp │ ├── 0432_sort-characters-by-frequency_1_AC.cpp │ ├── 0433_lru-cache_1_AC.cpp │ ├── 2919_two-sum_1_AC.cpp │ ├── 2920_longest-substring-without-repeating-characters_1_AC.cpp │ ├── 2921_3sum_1_AC.cpp │ ├── 2922_pascals-triangle_1_AC.cpp │ ├── 2923_integer-to-english-words_1_AC.cpp │ ├── 2924_subarray-sum-equals-k_1_AC.cpp │ ├── 2925_candy-crush_1_AC.py │ ├── 2926_merge-two-sorted-lists_1_AC.cpp │ ├── 2927_reverse-linked-list-ii_1_AC.cpp │ ├── 2928_copy-list-with-random-pointer_1_AC.cpp │ ├── 2929_add-two-numbers-ii_1_AC.cpp │ ├── 2930_construct-binary-tree-from-preorder-and-inorder-traversal_1_AC.cpp │ ├── 2931_flatten-binary-tree-to-linked-list_1_AC.cpp │ ├── 2932_binary-tree-right-side-view_1_AC.cpp │ ├── 2933_decode-string_1_AC.cpp │ ├── 2934_flatten-a-multilevel-doubly-linked-list_1_AC.py │ ├── 2935_meeting-rooms-ii_1_AC.cpp │ ├── 2936_top-k-frequent-words_1_AC.cpp │ ├── 2937_median-of-two-sorted-arrays_1_AC.cpp │ ├── 2938_merge-intervals_1_AC.cpp │ ├── 2939_valid-anagram_1_AC.cpp │ ├── 2940_longest-palindromic-substring_1_AC.cpp │ ├── 2941_maximum-subarray_1_AC.py │ ├── 2942_reverse-integer_1_AC.cpp │ └── 2943_word-search_1_AC.cpp ├── data-structure-tree │ ├── 0535_maximum-depth-of-binary-tree_1_AC.cpp │ ├── 0536_symmetric-tree_1_AC.cpp │ ├── 0537_path-sum_1_AC.cpp │ ├── 0538_count-univalue-subtrees_1_AC.cpp │ ├── 0928_binary-tree-preorder-traversal_1_AC.cpp │ ├── 0929_binary-tree-inorder-traversal_1_AC.cpp │ ├── 0930_binary-tree-postorder-traversal_1_AC.cpp │ ├── 0931_binary-tree-level-order-traversal_1_AC.cpp │ ├── 0932_lowest-common-ancestor-of-a-binary-tree_1_AC.py │ ├── 0942_construct-binary-tree-from-inorder-and-postorder-traversal_1_AC.cpp │ ├── 0943_construct-binary-tree-from-preorder-and-inorder-traversal_1_AC.cpp │ ├── 0994_populating-next-right-pointers-in-each-node_1_AC.cpp │ ├── 0995_serialize-and-deserialize-binary-tree_1_AC.cpp │ └── 1016_populating-next-right-pointers-in-each-node-ii_1_AC.cpp ├── decision-tree │ ├── 2650_calculate-entropy_1_AC.py │ └── 2651_calculate-maximum-information-gain_1_AC.py ├── facebook │ ├── 0262_move-zeros_1_AC.py │ ├── 0263_add-binary_1_AC.cpp │ ├── 0264_decode-ways_1_AC.cpp │ ├── 0266_validate-binary-search-tree_1_AC.cpp │ ├── 0267_letter-combinations-of-a-phone-number_1_AC.cpp │ ├── 0268_read-n-characters-given-read4_1_AC.cpp │ ├── 0269_read-n-characters-given-read4-ii-call-multiple-times_1_AC.cpp │ ├── 0270_intersection-of-two-arrays-ii_1_AC.cpp │ ├── 0271_serialize-and-deserialize-binary-tree_1_AC.cpp │ ├── 0272_first-bad-version_1_AC.cpp │ ├── 0273_integer-to-english-words_1_AC.cpp │ ├── 0274_number-of-islands_1_AC.py │ ├── 0277_clone-graph_1_AC.cpp │ ├── 0278_subsets_1_AC.cpp │ ├── 0279_search-in-rotated-sorted-array_1_AC.py │ ├── 0280_binary-tree-paths_1_AC.cpp │ ├── 0283_3sum_1_AC.cpp │ ├── 0285_minimum-window-substring_1_AC.cpp │ ├── 0288_valid-palindrome_1_AC.cpp │ ├── 0289_valid-palindrome-ii_1_AC.cpp │ ├── 0291_diameter-of-binary-tree_1_AC.py │ ├── 0292_permutations_1_AC.cpp │ ├── 0293_permutations-ii_1_AC.cpp │ ├── 0298_binary-tree-vertical-order-traversal_1_AC.cpp │ ├── 0300_add-and-search-word-data-structure-design_1_AC.cpp │ ├── 0301_merge-two-sorted-lists_1_AC.cpp │ ├── 0303_binary-search-tree-iterator_1_AC.cpp │ ├── 0304_best-time-to-buy-and-sell-stock_1_AC.cpp │ ├── 0307_regular-expression-matching_1_AC.py │ ├── 0308_divide-two-integers_1_AC.cpp │ ├── 0309_merge-sorted-array_1_AC.cpp │ ├── 0310_merge-intervals_1_AC.cpp │ ├── 0311_lru-cache_1_AC.cpp │ ├── 0314_second-highest-salary_1_AC.sql │ ├── 0315_nth-highest-salary_1_AC.sql │ ├── 0316_customers-who-never-order_1_AC.sql │ ├── 0317_department-top-three-salaries_1_AC.sql │ ├── 0319_add-two-numbers_1_AC.cpp │ ├── 0322_flatten-binary-tree-to-linked-list_1_AC.cpp │ ├── 0324_remove-invalid-parentheses_1_AC.cpp │ ├── 0326_friend-requests-i-overall-acceptance-rate_1_AC.sql │ ├── 0327_friend-requests-ii-who-has-the-most-friends_1_AC.sql │ ├── 0544_convert-binary-search-tree-to-sorted-doubly-linked-list_1_AC.py │ ├── 3008_longest-substring-without-repeating-characters_1_AC.cpp │ ├── 3009_string-to-integer-atoi_1_AC.cpp │ ├── 3010_roman-to-integer_1_AC.cpp │ ├── 3011_remove-duplicates-from-sorted-array_1_AC.cpp │ ├── 3012_next-permutation_1_AC.cpp │ ├── 3013_multiply-strings_1_AC.cpp │ ├── 3014_group-anagrams_1_AC.py │ ├── 3015_one-edit-distance_1_AC.cpp │ ├── 3016_product-of-array-except-self_1_AC.py │ ├── 3017_longest-substring-with-at-most-k-distinct-characters_1_AC.cpp │ ├── 3018_validate-ip-address_1_AC.cpp │ ├── 3019_subarray-sum-equals-k_1_AC.py │ ├── 3020_copy-list-with-random-pointer_1_AC.cpp │ ├── 3021_reorder-list_1_AC.cpp │ ├── 3022_binary-tree-maximum-path-sum_1_AC.cpp │ ├── 3023_binary-tree-right-side-view_1_AC.cpp │ ├── 3024_lowest-common-ancestor-of-a-binary-tree_1_AC.py │ ├── 3025_alien-dictionary_1_AC.cpp │ ├── 3026_shortest-distance-from-all-buildings_1_AC.cpp │ ├── 3027_accounts-merge_1_AC.py │ ├── 3028_is-graph-bipartite_1_AC.py │ ├── 3029_strobogrammatic-number-ii_1_AC.cpp │ ├── 3030_find-first-and-last-position-of-element-in-sorted-array_1_AC.cpp │ ├── 3031_powx-n_1_AC.cpp │ ├── 3032_find-peak-element_1_AC.cpp │ ├── 3033_intersection-of-two-arrays_1_AC.cpp │ ├── 3034_longest-palindromic-substring_1_AC.cpp │ ├── 3035_longest-valid-parentheses_1_AC.cpp │ ├── 3036_word-break_1_AC.cpp │ ├── 3037_range-sum-query-2d-immutable_1_AC.cpp │ ├── 3038_continuous-subarray-sum_1_AC.cpp │ ├── 3039_expression-add-operators_1_AC.cpp │ ├── 3040_find-all-anagrams-in-a-string_1_AC.cpp │ ├── 3041_permutation-in-string_1_AC.cpp │ ├── 3042_verifying-an-alien-dictionary_1_AC.py │ └── 3043_interval-list-intersections_1_AC.py ├── fun-with-arrays │ ├── 3157_move-zeros_1_AC.py │ ├── 3228_height-checker_1_AC.py │ ├── 3230_max-consecutive-ones-ii_1_AC.cpp │ ├── 3231_third-maximum-number_1_AC.cpp │ ├── 3237_find-numbers-with-even-number-of-digits_1_AC.cpp │ ├── 3238_max-consecutive-ones_1_AC.cpp │ ├── 3240_squares-of-a-sorted-array_1_AC.py │ ├── 3245_duplicate-zeros_1_AC.py │ ├── 3247_remove-element_1_AC.cpp │ ├── 3248_remove-duplicates-from-sorted-array_1_AC.cpp │ ├── 3250_check-if-n-and-its-double-exist_1_AC.py │ ├── 3251_valid-mountain-array_1_AC.py │ ├── 3253_merge-sorted-array_1_AC.py │ ├── 3258_remove-duplicates-from-sorted-array_1_AC.cpp │ ├── 3259_replace-elements-with-greatest-element-on-right-side_1_AC.py │ ├── 3260_sort-array-by-parity_1_AC.py │ ├── 3261_squares-of-a-sorted-array_1_AC.py │ └── 3270_find-all-numbers-disappeared-in-an-array_1_AC.cpp ├── google │ ├── 0331_evaluate-division_1_AC.cpp │ ├── 0339_plus-one_1_AC.cpp │ ├── 0341_trapping-rain-water_1_AC.cpp │ ├── 0342_merge-k-sorted-lists_1_AC.cpp │ ├── 0345_minimum-window-substring_1_AC.cpp │ ├── 0361_kth-largest-element-in-an-array_1_AC.cpp │ ├── 0370_word-squares_1_AC.cpp │ ├── 0399_strobogrammatic-number-ii_1_AC.cpp │ ├── 0436_read-n-characters-given-read4-ii-call-multiple-times_1_AC.cpp │ ├── 0445_insert-interval_1_AC.cpp │ ├── 0450_merge-intervals_1_AC.cpp │ ├── 0451_longest-palindromic-substring_1_AC.cpp │ ├── 0462_word-search-ii_1_AC.cpp │ ├── 0467_valid-parentheses_1_AC.cpp │ ├── 0471_next-closest-time_1_AC.py │ ├── 0472_license-key-formatting_1_AC.py │ ├── 0477_range-sum-query-2d-mutable_1_AC.cpp │ ├── 0484_android-unlock-patterns_1_AC.cpp │ ├── 1340_robot-room-cleaner_1_AC.py │ ├── 3044_unique-email-addresses_1_AC.py │ ├── 3045_odd-even-jump_1_AC.py │ ├── 3046_fruit-into-baskets_1_AC.py │ ├── 3047_longest-substring-without-repeating-characters_1_AC.cpp │ ├── 3048_container-with-most-water_1_AC.cpp │ ├── 3049_3sum_1_AC.cpp │ ├── 3050_next-permutation_1_AC.cpp │ ├── 3051_multiply-strings_1_AC.cpp │ ├── 3052_rotate-image_1_AC.cpp │ ├── 3053_jump-game_1_AC.cpp │ ├── 3054_longest-substring-with-at-most-two-distinct-characters_1_AC.cpp │ ├── 3055_missing-ranges_1_AC.cpp │ ├── 3056_expressive-words_1_AC.py │ ├── 3057_find-and-replace-in-string_1_AC.py │ ├── 3058_maximize-distance-to-closest-person_1_AC.py │ ├── 3059_meeting-rooms-ii_1_AC.cpp │ ├── 3060_backspace-string-compare_1_AC.py │ ├── 3061_minimum-cost-to-hire-k-workers_1_AC.py │ ├── 3062_k-closest-points-to-origin_1_AC.py │ ├── 3063_add-two-numbers_1_AC.cpp │ ├── 3064_remove-nth-node-from-end-of-list_1_AC.cpp │ ├── 3065_merge-two-sorted-lists_1_AC.cpp │ ├── 3066_copy-list-with-random-pointer_1_AC.cpp │ ├── 3067_binary-tree-maximum-path-sum_1_AC.cpp │ ├── 3068_word-ladder_1_AC.cpp │ ├── 3069_number-of-islands_1_AC.cpp │ ├── 3070_course-schedule-ii_1_AC.cpp │ ├── 3071_count-complete-tree-nodes_1_AC.cpp │ ├── 3072_longest-increasing-path-in-a-matrix_1_AC.cpp │ ├── 3073_decode-string_1_AC.cpp │ ├── 3074_diameter-of-binary-tree_1_AC.cpp │ ├── 3075_cracking-the-safe_1_AC.py │ ├── 3076_most-stones-removed-with-same-row-or-column_1_AC.py │ ├── 3077_flip-equivalent-binary-trees_1_AC.py │ ├── 3078_letter-combinations-of-a-phone-number_1_AC.cpp │ ├── 3079_generate-parentheses_1_AC.cpp │ ├── 3080_median-of-two-sorted-arrays_1_AC.cpp │ ├── 3081_find-first-and-last-position-of-element-in-sorted-array_1_AC.cpp │ ├── 3082_valid-anagram_1_AC.cpp │ ├── 3083_count-of-smaller-numbers-after-self_1_AC.cpp │ ├── 3084_peak-index-in-a-mountain-array_1_AC.py │ ├── 3085_maximum-subarray_1_AC.py │ ├── 3086_best-time-to-buy-and-sell-stock_1_AC.cpp │ ├── 3087_maximum-product-subarray_1_AC.cpp │ ├── 3088_coin-change_1_AC.cpp │ ├── 3089_split-array-largest-sum_1_AC.cpp │ ├── 3090_lru-cache_1_AC.cpp │ ├── 3091_min-stack_1_AC.cpp │ ├── 3092_serialize-and-deserialize-binary-tree_1_AC.cpp │ ├── 3093_logger-rate-limiter_1_AC.cpp │ ├── 3094_insert-delete-getrandom-o1_1_AC.cpp │ ├── 3095_design-search-autocomplete-system_1_AC.py │ ├── 3096_reverse-integer_1_AC.cpp │ ├── 3097_candy_1_AC.cpp │ ├── 3098_isomorphic-strings_1_AC.cpp │ ├── 3099_strobogrammatic-number_1_AC.cpp │ ├── 3100_bulls-and-cows_1_AC.cpp │ ├── 3101_my-calendar-ii_1_AC.py │ ├── 3102_jewels-and-stones_1_AC.cpp │ ├── 3103_swap-adjacent-in-lr-string_1_AC.py │ ├── 3104_guess-the-word_1_AC.py │ └── 3105_minimum-area-rectangle_1_AC.py ├── hash-table │ ├── 1105_intersection-of-two-arrays_1_AC.cpp │ ├── 1112_contains-duplicate_1_AC.cpp │ ├── 1115_two-sum_1_AC.cpp │ ├── 1117_isomorphic-strings_1_AC.cpp │ ├── 1120_first-unique-character-in-a-string_1_AC.cpp │ ├── 1121_contains-duplicate-ii_1_AC.cpp │ ├── 1122_logger-rate-limiter_1_AC.cpp │ ├── 1124_group-anagrams_1_AC.py │ ├── 1125_group-shifted-strings_1_AC.cpp │ ├── 1126_valid-sudoku_1_AC.cpp │ ├── 1127_find-duplicate-subtrees_1_AC.cpp │ ├── 1131_happy-number_1_AC.py │ ├── 1133_top-k-frequent-elements_1_AC.cpp │ ├── 1134_4sum-ii_1_AC.cpp │ ├── 1135_longest-substring-without-repeating-characters_1_AC.cpp │ ├── 1136_jewels-and-stones_1_AC.cpp │ ├── 1137_unique-word-abbreviation_1_AC.cpp │ ├── 1139_design-hashset_1_AC.cpp │ ├── 1140_design-hashmap_1_AC.cpp │ ├── 1141_insert-delete-getrandom-o1_1_AC.cpp │ ├── 1176_single-number_1_AC.py │ ├── 1177_minimum-index-sum-of-two-lists_1_AC.cpp │ ├── 1178_intersection-of-two-arrays-ii_1_AC.cpp │ └── 1179_two-sum-iii-data-structure-design_1_AC.py ├── introduction-to-data-structure-binary-search-tree │ ├── 0997_validate-binary-search-tree_1_AC.cpp │ ├── 0998_inorder-successor-in-bst_1_AC.cpp │ ├── 1000_search-in-a-binary-search-tree_1_AC.cpp │ ├── 1003_insert-into-a-binary-search-tree_1_AC.py │ ├── 1006_delete-node-in-a-bst_1_AC.cpp │ ├── 1008_binary-search-tree-iterator_1_AC.cpp │ ├── 1012_lowest-common-ancestor-of-a-binary-search-tree_1_AC.cpp │ ├── 1013_contains-duplicate-iii_1_AC.cpp │ ├── 1015_convert-sorted-array-to-binary-search-tree_1_AC.cpp │ ├── 1018_kth-largest-element-in-a-stream_1_AC.cpp │ └── 1027_balanced-binary-tree_1_AC.cpp ├── linked-list │ ├── 1205_reverse-linked-list_1_AC.cpp │ ├── 1207_remove-linked-list-elements_1_AC.cpp │ ├── 1208_odd-even-linked-list_1_AC.cpp │ ├── 1209_palindrome-linked-list_1_AC.cpp │ ├── 1212_linked-list-cycle_1_AC.cpp │ ├── 1214_linked-list-cycle-ii_1_AC.cpp │ ├── 1215_intersection-of-two-linked-lists_1_AC.cpp │ ├── 1225_flatten-a-multilevel-doubly-linked-list_1_AC.py │ ├── 1226_insert-into-a-cyclic-sorted-list_1_AC.py │ ├── 1227_merge-two-sorted-lists_1_AC.cpp │ ├── 1228_add-two-numbers_1_AC.cpp │ ├── 1229_copy-list-with-random-pointer_1_AC.cpp │ ├── 1290_design-linked-list_1_AC.cpp │ ├── 1294_design-linked-list_1_AC.cpp │ ├── 1295_rotate-list_1_AC.cpp │ └── 1296_remove-nth-node-from-end-of-list_1_AC.cpp ├── linkedin │ ├── 1958_valid-parentheses_1_AC.cpp │ ├── 1959_evaluate-reverse-polish-notation_1_AC.cpp │ ├── 1961_exclusive-time-of-functions_1_AC.cpp │ ├── 1962_permutations_1_AC.cpp │ ├── 1963_permutations-ii_1_AC.cpp │ ├── 1964_factor-combinations_1_AC.cpp │ ├── 1965_powx-n_1_AC.cpp │ ├── 1966_merge-intervals_1_AC.cpp │ ├── 1968_valid-number_1_AC.cpp │ ├── 1969_text-justification_1_AC.cpp │ ├── 1970_minimum-window-substring_1_AC.cpp │ ├── 1971_shortest-word-distance_1_AC.cpp │ ├── 1972_can-place-flowers_1_AC.cpp │ ├── 1973_edit-distance_1_AC.cpp │ ├── 1974_maximum-product-subarray_1_AC.cpp │ ├── 1975_paint-house-ii_1_AC.cpp │ ├── 1978_partition-to-k-equal-sum-subsets_1_AC.cpp │ ├── 1981_binary-tree-level-order-traversal_1_AC.cpp │ ├── 1983_word-ladder_1_AC.cpp │ ├── 1984_binary-tree-upside-down_1_AC.cpp │ ├── 1985_number-of-islands_1_AC.py │ ├── 1986_lowest-common-ancestor-of-a-binary-search-tree_1_AC.cpp │ ├── 1987_lowest-common-ancestor-of-a-binary-tree_1_AC.py │ ├── 1989_closest-binary-search-tree-value-ii_1_AC.cpp │ ├── 1991_nested-list-weight-sum_1_AC.cpp │ ├── 1992_nested-list-weight-sum-ii_1_AC.cpp │ ├── 1993_find-leaves-of-binary-tree_1_AC.cpp │ ├── 1996_second-minimum-node-in-a-binary-tree_1_AC.cpp │ ├── 1999_isomorphic-strings_1_AC.cpp │ ├── 2000_two-sum-iii-data-structure-design_1_AC.py │ ├── 2001_shortest-word-distance-ii_1_AC.cpp │ ├── 2002_serialize-and-deserialize-binary-tree_1_AC.cpp │ ├── 2003_flatten-nested-list-iterator_1_AC.cpp │ ├── 2004_insert-delete-getrandom-o1_1_AC.cpp │ ├── 2005_all-oone-data-structure_1_AC.cpp │ ├── 2006_max-stack_1_AC.py │ ├── 2007_design-hashmap_1_AC.cpp │ ├── 2907_two-sum_1_AC.cpp │ ├── 2908_integer-to-english-words_1_AC.cpp │ ├── 2909_find-the-celebrity_1_AC.cpp │ ├── 2910_combination-sum_1_AC.cpp │ ├── 2911_search-in-rotated-sorted-array_1_AC.py │ ├── 2912_find-first-and-last-position-of-element-in-sorted-array_1_AC.cpp │ ├── 2913_sqrtx_1_AC.cpp │ ├── 2914_random-pick-with-weight_1_AC.py │ ├── 2915_kth-largest-element-in-an-array_1_AC.cpp │ ├── 2916_maximum-subarray_1_AC.py │ ├── 2917_paint-house_1_AC.cpp │ └── 2918_maximum-depth-of-binary-tree_1_AC.cpp ├── microsoft │ ├── 0152_validate-binary-search-tree_1_AC.cpp │ ├── 0153_binary-tree-inorder-traversal_1_AC.cpp │ ├── 0154_search-a-2d-matrix_1_AC.cpp │ ├── 0155_wildcard-matching_1_AC.cpp │ ├── 0156_longest-increasing-subsequence_1_AC.cpp │ ├── 0157_the-skyline-problem_1_AC.cpp │ ├── 0161_lru-cache_1_AC.cpp │ ├── 0162_valid-palindrome_1_AC.cpp │ ├── 0163_populating-next-right-pointers-in-each-node-ii_1_AC.cpp │ ├── 0164_binary-tree-level-order-traversal_1_AC.cpp │ ├── 0165_letter-combinations-of-a-phone-number_1_AC.cpp │ ├── 0166_reverse-words-in-a-string_1_AC.cpp │ ├── 0168_copy-list-with-random-pointer_1_AC.cpp │ ├── 0169_reverse-linked-list_1_AC.cpp │ ├── 0170_add-two-numbers_1_AC.cpp │ ├── 0171_string-to-integer-atoi_1_AC.cpp │ ├── 0173_two-sum_1_AC.cpp │ ├── 0174_maximum-subarray_1_AC.py │ ├── 0175_merge-two-sorted-lists_1_AC.cpp │ ├── 0178_spiral-matrix_1_AC.cpp │ ├── 0179_valid-parentheses_1_AC.cpp │ ├── 0180_longest-palindromic-substring_1_AC.cpp │ ├── 0181_lowest-common-ancestor-of-a-binary-tree_1_AC.py │ ├── 0182_lowest-common-ancestor-of-a-binary-search-tree_1_AC.cpp │ ├── 0183_excel-sheet-column-number_1_AC.cpp │ ├── 0184_linked-list-cycle_1_AC.cpp │ ├── 0185_number-of-islands_1_AC.cpp │ ├── 0186_best-time-to-buy-and-sell-stock_1_AC.cpp │ ├── 0187_reverse-string_1_AC.cpp │ ├── 0188_integer-to-english-words_1_AC.cpp │ ├── 0189_regular-expression-matching_1_AC.py │ ├── 0191_search-in-rotated-sorted-array_1_AC.cpp │ ├── 0192_populating-next-right-pointers-in-each-node_1_AC.cpp │ ├── 0193_sort-colors_1_AC.cpp │ ├── 0194_find-the-celebrity_1_AC.cpp │ ├── 0195_search-a-2d-matrix-ii_1_AC.cpp │ ├── 0196_construct-binary-tree-from-preorder-and-inorder-traversal_1_AC.cpp │ ├── 0197_binary-tree-zigzag-level-order-traversal_1_AC.cpp │ ├── 0198_roman-to-integer_1_AC.cpp │ ├── 0200_group-anagrams_1_AC.py │ ├── 0201_serialize-and-deserialize-binary-tree_1_AC.cpp │ ├── 0202_rotate-image_1_AC.cpp │ ├── 0203_set-matrix-zeroes_1_AC.cpp │ ├── 0205_add-two-numbers-ii_1_AC.cpp │ ├── 0206_find-minimum-in-rotated-sorted-array_1_AC.cpp │ ├── 0207_find-minimum-in-rotated-sorted-array-ii_1_AC.cpp │ ├── 0208_single-number_1_AC.py │ ├── 0209_merge-k-sorted-lists_1_AC.cpp │ ├── 0210_clone-graph_1_AC.cpp │ ├── 0211_trapping-rain-water_1_AC.cpp │ ├── 0212_intersection-of-two-linked-lists_1_AC.cpp │ ├── 0213_reverse-words-in-a-string-ii_1_AC.cpp │ ├── 0256_word-search-ii_1_AC.cpp │ ├── 0257_remove-duplicates-from-sorted-array_1_AC.cpp │ ├── 0258_merge-sorted-array_1_AC.cpp │ ├── 0890_median-of-two-sorted-arrays_1_AC.cpp │ ├── 0891_serialize-and-deserialize-bst_1_AC.cpp │ └── 0892_implement-trie-prefix-tree_1_AC.cpp ├── n-ary-tree │ ├── 0915_n-ary-tree-level-order-traversal_1_AC.cpp │ ├── 0919_maximum-depth-of-n-ary-tree_1_AC.cpp │ ├── 0920_encode-n-ary-tree-to-binary-tree_1_AC.py │ ├── 0924_serialize-and-deserialize-n-ary-tree_1_AC.py │ ├── 0925_n-ary-tree-preorder-traversal_1_AC.cpp │ └── 0926_n-ary-tree-postorder-traversal_1_AC.cpp ├── queue-stack │ ├── 1337_design-circular-queue_1_AC.py │ ├── 1360_min-stack_1_AC.py │ ├── 1361_valid-parentheses_1_AC.cpp │ ├── 1363_daily-temperatures_1_AC.py │ ├── 1368_moving-average-from-data-stream_1_AC.cpp │ ├── 1371_perfect-squares_1_AC.cpp │ ├── 1373_walls-and-gates_1_AC.cpp │ ├── 1374_number-of-islands_1_AC.py │ ├── 1375_open-the-lock_1_AC.py │ ├── 1379_decode-string_1_AC.cpp │ ├── 1380_number-of-islands_1_AC.py │ ├── 1383_binary-tree-inorder-traversal_1_AC.cpp │ ├── 1386_implement-queue-using-stacks_1_AC.cpp │ ├── 1387_implement-stack-using-queues_1_AC.cpp │ ├── 1388_01-matrix_1_AC.cpp │ ├── 1389_target-sum_1_AC.cpp │ ├── 1391_keys-and-rooms_1_AC.py │ ├── 1392_clone-graph_1_AC.cpp │ ├── 1393_flood-fill_1_AC.cpp │ └── 1394_evaluate-reverse-polish-notation_1_AC.cpp ├── recursion-i │ ├── 1440_reverse-string_1_AC.cpp │ ├── 1661_fibonacci-number_1_AC.cpp │ ├── 1662_climbing-stairs_1_AC.cpp │ ├── 1675_k-th-symbol-in-grammar_1_AC.py │ ├── 1681_swap-nodes-in-pairs_1_AC.cpp │ ├── 2375_maximum-depth-of-binary-tree_1_AC.cpp │ ├── 2378_reverse-linked-list_1_AC.cpp │ ├── 2380_powx-n_1_AC.cpp │ ├── 2382_merge-two-sorted-lists_1_AC.cpp │ ├── 2384_unique-binary-search-trees-ii_1_AC.cpp │ ├── 3233_search-in-a-binary-search-tree_1_AC.cpp │ └── 3234_pascals-triangle-ii_1_AC.cpp ├── recursion-ii │ ├── 2772_generate-parentheses_1_AC.cpp │ ├── 2774_binary-tree-inorder-traversal_1_AC.cpp │ ├── 2784_binary-tree-level-order-traversal_1_AC.cpp │ ├── 2794_robot-room-cleaner_1_AC.py │ ├── 2796_sudoku-solver_1_AC.cpp │ ├── 2798_combinations_1_AC.cpp │ ├── 2804_n-queens-ii_1_AC.cpp │ ├── 2872_search-a-2d-matrix-ii_1_AC.cpp │ ├── 2874_validate-binary-search-tree_1_AC.cpp │ ├── 2894_same-tree_1_AC.cpp │ ├── 2899_convert-binary-search-tree-to-sorted-doubly-linked-list_1_AC.py │ ├── 2901_largest-rectangle-in-histogram_1_AC.cpp │ ├── 2903_permutations_1_AC.cpp │ ├── 2905_letter-combinations-of-a-phone-number_1_AC.cpp │ ├── 2944_sort-an-array_1_AC.py │ └── 3006_the-skyline-problem_1_AC.cpp ├── top-interview-questions-easy │ ├── 0546_two-sum_1_AC.cpp │ ├── 0549_single-number_1_AC.cpp │ ├── 0553_delete-node-in-a-linked-list_1_AC.cpp │ ├── 0555_maximum-depth-of-binary-tree_1_AC.cpp │ ├── 0559_plus-one_1_AC.cpp │ ├── 0560_reverse-linked-list_1_AC.cpp │ ├── 0562_min-stack_1_AC.cpp │ ├── 0564_best-time-to-buy-and-sell-stock-ii_1_AC.cpp │ ├── 0565_number-of-1-bits_1_AC.cpp │ ├── 0566_maximum-subarray_1_AC.cpp │ ├── 0567_move-zeroes_1_AC.cpp │ ├── 0569_climbing-stairs_1_AC.cpp │ ├── 0572_best-time-to-buy-and-sell-stock_1_AC.cpp │ ├── 0576_house-robber_1_AC.cpp │ ├── 0578_contains-duplicate_1_AC.cpp │ ├── 0587_merge-sorted-array_1_AC.cpp │ ├── 0601_pascals-triangle_1_AC.cpp │ ├── 0603_remove-nth-node-from-end-of-list_1_AC.cpp │ ├── 0625_validate-binary-search-tree_1_AC.cpp │ ├── 0627_symmetric-tree_1_AC.cpp │ ├── 0628_binary-tree-level-order-traversal_2_AC.cpp │ ├── 0631_convert-sorted-array-to-binary-search-tree_1_AC.cpp │ ├── 0646_rotate-array_1_AC.cpp │ ├── 0648_reverse-bits_1_AC.cpp │ ├── 0670_shuffle-an-array_1_AC.cpp │ ├── 0674_intersection-of-two-arrays-ii_1_AC.cpp │ ├── 0721_valid-parentheses_1_AC.cpp │ ├── 0722_missing-number_1_AC.cpp │ ├── 0727_remove-duplicates-from-sorted-array_1_AC.cpp │ ├── 0743_fizz-buzz_1_AC.cpp │ ├── 0744_count-primes_1_AC.cpp │ ├── 0745_power-of-three_1_AC.cpp │ ├── 0762_hamming-distance_1_AC.cpp │ ├── 0769_valid-sudoku_1_AC.cpp │ ├── 0770_rotate-image_1_AC.cpp │ ├── 0771_merge-two-sorted-lists_1_AC.cpp │ ├── 0772_palindrome-linked-list_1_AC.cpp │ ├── 0773_linked-list-cycle_1_AC.cpp │ ├── 0774_first-bad-version_1_AC.cpp │ ├── 0878_roman-to-integer_1_AC.cpp │ ├── 0879_reverse-string_1_AC.cpp │ ├── 0880_reverse-integer_1_AC.cpp │ ├── 0881_first-unique-character-in-a-string_1_AC.cpp │ ├── 0882_valid-anagram_1_AC.cpp │ ├── 0883_valid-palindrome_1_AC.cpp │ ├── 0884_string-to-integer-atoi_1_AC.cpp │ ├── 0885_implement-strstr_1_AC.cpp │ ├── 0886_count-and-say_1_AC.cpp │ └── 0887_longest-common-prefix_1_AC.cpp ├── top-interview-questions-hard │ ├── 0827_product-of-array-except-self_1_AC.py │ ├── 0828_spiral-matrix_1_AC.cpp │ ├── 0829_4sum-ii_1_AC.cpp │ ├── 0830_container-with-most-water_1_AC.cpp │ ├── 0831_game-of-life_1_AC.cpp │ ├── 0832_first-missing-positive_1_AC.cpp │ ├── 0833_longest-consecutive-sequence_1_AC.cpp │ ├── 0834_find-the-duplicate-number_1_AC.cpp │ ├── 0835_longest-substring-with-at-most-k-distinct-characters_1_AC.cpp │ ├── 0836_basic-calculator-ii_1_AC.cpp │ ├── 0837_sliding-window-maximum_1_AC.cpp │ ├── 0838_minimum-window-substring_1_AC.cpp │ ├── 0839_merge-k-sorted-lists_1_AC.cpp │ ├── 0840_sort-list_1_AC.cpp │ ├── 0841_copy-list-with-random-pointer_1_AC.cpp │ ├── 0842_word-ladder_1_AC.cpp │ ├── 0843_surrounded-regions_1_AC.cpp │ ├── 0844_lowest-common-ancestor-of-a-binary-tree_1_AC.py │ ├── 0845_binary-tree-maximum-path-sum_1_AC.cpp │ ├── 0846_friend-circles_1_AC.cpp │ ├── 0847_course-schedule_1_AC.cpp │ ├── 0848_course-schedule-ii_1_AC.cpp │ ├── 0849_longest-increasing-path-in-a-matrix_1_AC.cpp │ ├── 0850_alien-dictionary_1_AC.cpp │ ├── 0851_count-of-smaller-numbers-after-self_1_AC.cpp │ ├── 0852_palindrome-partitioning_1_AC.cpp │ ├── 0853_word-search-ii_1_AC.cpp │ ├── 0854_remove-invalid-parentheses_1_AC.cpp │ ├── 0855_wildcard-matching_1_AC.cpp │ ├── 0856_regular-expression-matching_1_AC.py │ ├── 0857_wiggle-sort-ii_1_AC.cpp │ ├── 0858_kth-smallest-element-in-a-sorted-matrix_1_AC.cpp │ ├── 0859_median-of-two-sorted-arrays_1_AC.cpp │ ├── 0860_maximum-product-subarray_1_AC.cpp │ ├── 0861_decode-ways_1_AC.cpp │ ├── 0862_best-time-to-buy-and-sell-stock-with-cooldown_1_AC.cpp │ ├── 0863_perfect-squares_1_AC.cpp │ ├── 0864_word-break_1_AC.cpp │ ├── 0865_word-break-ii_1_AC.cpp │ ├── 0866_burst-balloons_1_AC.cpp │ ├── 0867_lru-cache_1_AC.py │ ├── 0868_implement-trie-prefix-tree_1_AC.cpp │ ├── 0869_flatten-nested-list-iterator_1_AC.cpp │ ├── 0870_find-median-from-data-stream_1_AC.cpp │ ├── 0871_range-sum-query-2d-mutable_1_AC.cpp │ ├── 0872_largest-number_1_AC.cpp │ ├── 0873_max-points-on-a-line_1_AC.cpp │ ├── 0874_queue-reconstruction-by-height_1_AC.py │ ├── 0875_trapping-rain-water_1_AC.cpp │ ├── 0876_the-skyline-problem_1_AC.cpp │ └── 0877_largest-rectangle-in-histogram_1_AC.cpp ├── top-interview-questions-medium │ ├── 0776_3sum_1_AC.cpp │ ├── 0777_set-matrix-zeroes_1_AC.cpp │ ├── 0778_group-anagrams_1_AC.py │ ├── 0779_longest-substring-without-repeating-characters_1_AC.cpp │ ├── 0780_longest-palindromic-substring_1_AC.cpp │ ├── 0781_increasing-triplet-subsequence_1_AC.cpp │ ├── 0782_missing-ranges_1_AC.cpp │ ├── 0783_add-two-numbers_1_AC.cpp │ ├── 0784_odd-even-linked-list_1_AC.cpp │ ├── 0785_intersection-of-two-linked-lists_1_AC.cpp │ ├── 0786_binary-tree-inorder-traversal_1_AC.cpp │ ├── 0787_binary-tree-zigzag-level-order-traversal_1_AC.cpp │ ├── 0788_construct-binary-tree-from-preorder-and-inorder-traversal_1_AC.cpp │ ├── 0789_populating-next-right-pointers-in-each-node_1_AC.cpp │ ├── 0790_kth-smallest-element-in-a-bst_1_AC.cpp │ ├── 0791_inorder-successor-in-bst_1_AC.cpp │ ├── 0792_number-of-islands_1_AC.py │ ├── 0793_letter-combinations-of-a-phone-number_1_AC.cpp │ ├── 0794_generate-parentheses_1_AC.cpp │ ├── 0795_permutations_1_AC.cpp │ ├── 0796_subsets_1_AC.cpp │ ├── 0797_word-search_1_AC.cpp │ ├── 0798_sort-colors_1_AC.cpp │ ├── 0799_top-k-frequent-elements_1_AC.cpp │ ├── 0800_kth-largest-element-in-an-array_1_AC.cpp │ ├── 0801_find-peak-element_1_AC.cpp │ ├── 0802_search-for-a-range_1_AC.cpp │ ├── 0803_merge-intervals_1_AC.cpp │ ├── 0804_search-in-rotated-sorted-array_1_AC.py │ ├── 0805_meeting-rooms-ii_1_AC.cpp │ ├── 0806_search-a-2d-matrix-ii_1_AC.cpp │ ├── 0807_jump-game_1_AC.py │ ├── 0808_unique-paths_1_AC.cpp │ ├── 0809_coin-change_1_AC.cpp │ ├── 0810_longest-increasing-subsequence_1_AC.cpp │ ├── 0811_flatten-2d-vector_1_AC.cpp │ ├── 0812_serialize-and-deserialize-binary-tree_1_AC.cpp │ ├── 0813_insert-delete-getrandom-o1_1_AC.cpp │ ├── 0814_design-tic-tac-toe_1_AC.cpp │ ├── 0815_happy-number_1_AC.py │ ├── 0816_factorial-trailing-zeroes_1_AC.cpp │ ├── 0817_excel-sheet-column-number_1_AC.cpp │ ├── 0818_powx-n_1_AC.cpp │ ├── 0819_sqrtx_1_AC.cpp │ ├── 0820_divide-two-integers_1_AC.cpp │ ├── 0821_fraction-to-recurring-decimal_1_AC.cpp │ ├── 0822_sum-of-two-integers_1_AC.cpp │ ├── 0823_evaluate-reverse-polish-notation_1_AC.cpp │ ├── 0824_majority-element_1_AC.cpp │ ├── 0825_find-the-celebrity_1_AC.cpp │ └── 0826_task-scheduler_1_AC.cpp ├── trie │ ├── 1047_implement-trie-prefix-tree_1_AC.cpp │ ├── 1052_add-and-search-word-data-structure-design_1_AC.cpp │ ├── 1053_replace-words_1_AC.cpp │ ├── 1054_design-search-autocomplete-system_1_AC.py │ ├── 1055_word-squares_1_AC.cpp │ ├── 1056_word-search-ii_1_AC.cpp │ ├── 1057_maximum-xor-of-two-numbers-in-an-array_1_AC.cpp │ ├── 1058_map-sum-pairs_1_AC.cpp │ └── 1138_palindrome-pairs_1_AC.py ├── uber │ ├── 1682_two-sum_1_AC.cpp │ ├── 1683_find-first-and-last-position-of-element-in-sorted-array_1_AC.cpp │ ├── 1684_group-anagrams_1_AC.py │ ├── 1685_text-justification_1_AC.cpp │ ├── 1686_minimum-window-substring_1_AC.cpp │ ├── 1687_validate-ip-address_1_AC.cpp │ ├── 1688_letter-combinations-of-a-phone-number_1_AC.cpp │ ├── 1689_subsets_1_AC.cpp │ ├── 1690_valid-sudoku_1_AC.cpp │ ├── 1691_candy_1_AC.cpp │ ├── 1692_fraction-to-recurring-decimal_1_AC.cpp │ ├── 1693_number-of-islands-ii_1_AC.cpp │ ├── 1694_random-pick-index_1_AC.cpp │ ├── 1695_encode-and-decode-tinyurl_1_AC.cpp │ ├── 1696_solve-the-equation_1_AC.cpp │ ├── 1697_construct-quad-tree_1_AC.cpp │ ├── 1698_random-pick-with-weight_1_AC.py │ ├── 1699_trapping-rain-water_1_AC.cpp │ ├── 1700_basic-calculator_1_AC.cpp │ ├── 1701_meeting-rooms-ii_1_AC.cpp │ ├── 1702_task-scheduler_1_AC.cpp │ ├── 1703_exclusive-time-of-functions_1_AC.cpp │ ├── 1704_employee-free-time_1_AC.py │ ├── 1705_merge-intervals_1_AC.cpp │ ├── 1706_word-ladder-ii_1_AC.cpp │ ├── 1707_number-of-islands_1_AC.py │ ├── 1708_walls-and-gates_1_AC.cpp │ ├── 1709_remove-invalid-parentheses_1_AC.cpp │ ├── 1710_24-game_1_AC.py │ ├── 1711_max-area-of-island_1_AC.cpp │ ├── 1712_bus-routes_1_AC.py │ ├── 1713_shortest-bridge_1_AC.py │ ├── 1714_word-break_1_AC.cpp │ ├── 1715_perfect-squares_1_AC.cpp │ ├── 1716_russian-doll-envelopes_1_AC.cpp │ ├── 1717_maximum-vacation-days_1_AC.py │ ├── 1718_cherry-pickup_1_AC.py │ ├── 1719_lru-cache_1_AC.py │ ├── 1720_serialize-and-deserialize-binary-tree_1_AC.cpp │ ├── 1721_moving-average-from-data-stream_1_AC.cpp │ ├── 1722_design-snake-game_1_AC.cpp │ ├── 1723_logger-rate-limiter_1_AC.cpp │ ├── 1724_design-hit-counter_1_AC.cpp │ ├── 1725_insert-delete-getrandom-o1-duplicates-allowed_1_AC.cpp │ ├── 1726_design-search-autocomplete-system_1_AC.py │ ├── 1727_reconstruct-itinerary_1_AC.cpp │ ├── 1728_evaluate-division_1_AC.cpp │ ├── 1729_find-duplicate-subtrees_1_AC.cpp │ ├── 1730_print-binary-tree_1_AC.cpp │ ├── 1731_serialize-and-deserialize-n-ary-tree_1_AC.py │ ├── 2486_merge-two-sorted-lists_1_AC.cpp │ └── 2487_merge-k-sorted-lists_1_AC.cpp └── yelp │ ├── 0087_two-sum_1_AC.cpp │ ├── 0093_longest-substring-without-repeating-characters_1_AC.cpp │ ├── 0216_group-anagrams_1_AC.py │ ├── 0217_minimum-index-sum-of-two-lists_1_AC.cpp │ ├── 0219_longest-common-prefix_1_AC.cpp │ ├── 0220_longest-palindromic-substring_1_AC.cpp │ ├── 0221_spiral-matrix_1_AC.cpp │ ├── 0222_copy-list-with-random-pointer_1_AC.cpp │ ├── 0223_integer-to-english-words_1_AC.cpp │ ├── 0224_letter-combinations-of-a-phone-number_1_AC.cpp │ ├── 0225_word-break_1_AC.cpp │ ├── 0226_lru-cache_1_AC.cpp │ ├── 0227_reconstruct-itinerary_1_AC.cpp │ ├── 0228_word-ladder_1_AC.cpp │ ├── 0229_best-time-to-buy-and-sell-stock_1_AC.cpp │ ├── 0232_isomorphic-strings_1_AC.cpp │ ├── 0234_sentence-screen-fitting_1_AC.cpp │ ├── 0235_regular-expression-matching_1_AC.py │ ├── 0238_course-schedule_1_AC.cpp │ ├── 0239_merge-two-sorted-lists_1_AC.cpp │ ├── 0248_generate-parentheses_1_AC.cpp │ ├── 0250_3sum_1_AC.cpp │ ├── 0252_merge-intervals_1_AC.cpp │ ├── 0253_meeting-rooms-ii_1_AC.cpp │ ├── 0255_top-k-frequent-words_1_AC.cpp │ ├── 0397_insert-delete-getrandom-o1_1_AC.cpp │ ├── 2945_merge-sorted-array_1_AC.cpp │ ├── 2946_pascals-triangle_1_AC.cpp │ ├── 2947_basic-calculator-ii_1_AC.cpp │ ├── 2948_product-of-array-except-self_1_AC.cpp │ ├── 2949_find-the-closest-palindrome_1_AC.cpp │ ├── 2950_number-of-islands_1_AC.cpp │ ├── 2951_combination-sum_1_AC.cpp │ ├── 2952_meeting-rooms_1_AC.cpp │ ├── 2953_random-pick-with-weight_1_AC.py │ ├── 2954_sliding-window-maximum_1_AC.cpp │ ├── 2955_top-k-frequent-elements_1_AC.cpp │ ├── 2956_maximum-subarray_1_AC.py │ ├── 2957_maximum-product-subarray_1_AC.cpp │ ├── 2958_maximal-square_1_AC.cpp │ ├── 2959_logger-rate-limiter_1_AC.cpp │ └── 2960_valid-square_1_AC.cpp ├── misc ├── add-difficulty.py ├── add-id.py ├── change-url.py └── solve-rate.py ├── mock ├── facbook-phone-202005160237 │ ├── 1.docx │ ├── 1.pdf │ ├── 1_AC.py │ ├── 2.docx │ ├── 2.pdf │ ├── 2_AC.py │ ├── 3.docx │ ├── 3.pdf │ ├── 3_AC.py │ ├── result.docx │ └── result.pdf └── google-oa-202005160200 │ ├── 1.docx │ ├── 1.pdf │ ├── 1_AC.py │ ├── 2.docx │ ├── 2.pdf │ ├── 2_AC.py │ ├── result.docx │ └── result.pdf ├── review ├── README.md ├── algorithms-review-0001-0500.md ├── algorithms-review-0501-1000.md ├── algorithms-review-1001-1500.md ├── algorithms-review-1501-2000.md ├── algorithms-review-2001-2500.md ├── algorithms-review-2501-3000.md ├── algorithms-review-3001-3500.md └── deprecated │ ├── algorithms-review-0001-0100.md │ ├── algorithms-review-0101-0200.md │ ├── algorithms-review-0201-0300.md │ ├── algorithms-review-0301-0400.md │ ├── algorithms-review-0401-0500.md │ ├── algorithms-review-0501-0600.md │ └── algorithms-review-0601-0700.md └── shell ├── 0192_word-frequency_1_AC.sh ├── 0193_valid-phone-numbers_1_AC.sh ├── 0194_transpose-file_1_AC.sh └── 0195_tenth-line_1_AC.sh /algorithms/0001-0500/0009_palindrome-number_1_AC.cpp: -------------------------------------------------------------------------------- 1 | // easy 2 | class Solution { 3 | public: 4 | bool isPalindrome(int x) { 5 | if (x < 0) { 6 | return false; 7 | } 8 | const int R = 10; 9 | int x1 = x; 10 | int r = 0; 11 | while (x1 > 0) { 12 | r = r * R + x1 % R; 13 | x1 /= R; 14 | } 15 | return r == x; 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /algorithms/0001-0500/0027_remove-element_1_AC.cpp: -------------------------------------------------------------------------------- 1 | // easy 2 | class Solution { 3 | public: 4 | int removeElement(vector& nums, int val) { 5 | int n = nums.size(); 6 | int i = 0; 7 | int j = 0; 8 | while (i < n) { 9 | if (nums[i] == val) { 10 | ++i; 11 | } else { 12 | nums[j++] = nums[i++]; 13 | } 14 | } 15 | return j; 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /algorithms/0001-0500/0058_length-of-last-word_1_AC.cpp: -------------------------------------------------------------------------------- 1 | // easy 2 | class Solution { 3 | public: 4 | int lengthOfLastWord(string s) { 5 | int n = s.size(); 6 | int i = n - 1; 7 | while (i >= 0 && s[i] == ' ') { 8 | --i; 9 | } 10 | int j = i; 11 | while (j >= 0 && s[j] != ' ') { 12 | --j; 13 | } 14 | return i - j; 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /algorithms/0001-0500/0070_climbing-stairs_1_AC.cpp: -------------------------------------------------------------------------------- 1 | // easy 2 | // Fibonacci 3 | class Solution { 4 | public: 5 | int climbStairs(int n) { 6 | if (n < 0) { 7 | return 0; 8 | } 9 | int f1 = 0; 10 | int f2 = 1; 11 | int f3 = 1; 12 | int i; 13 | for (i = 0; i < n; ++i) { 14 | f3 = f1 + f2; 15 | f1 = f2; 16 | f2 = f3; 17 | } 18 | return f3; 19 | } 20 | }; 21 | -------------------------------------------------------------------------------- /algorithms/0001-0500/0122_best-time-to-buy-and-sell-stock-ii_1_AC.cpp: -------------------------------------------------------------------------------- 1 | // medium 2 | class Solution { 3 | public: 4 | int maxProfit(vector& prices) { 5 | int n = prices.size(); 6 | int i; 7 | int res = 0; 8 | for (i = 1; i < n; ++i) { 9 | if (prices[i] > prices[i - 1]) { 10 | res += prices[i] - prices[i - 1]; 11 | } 12 | } 13 | return res; 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /algorithms/0001-0500/0136_single-number_1_AC.cpp: -------------------------------------------------------------------------------- 1 | // easy 2 | class Solution { 3 | public: 4 | int singleNumber(vector& nums) { 5 | int n = nums.size(); 6 | int i; 7 | int res = 0; 8 | for (i = 0; i < n; ++i) { 9 | res ^= nums[i]; 10 | } 11 | return res; 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /algorithms/0001-0500/0162_find-peak-element_1_AC.cpp: -------------------------------------------------------------------------------- 1 | // medium 2 | class Solution { 3 | public: 4 | int findPeakElement(vector& nums) { 5 | int n = nums.size(); 6 | int i; 7 | for (i = 0; i < n - 1; ++i) { 8 | if (nums[i] > nums[i + 1]) { 9 | break; 10 | } 11 | } 12 | return i; 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /algorithms/0001-0500/0172_factorial-trailing-zeroes_1_AC.cpp: -------------------------------------------------------------------------------- 1 | // medium 2 | class Solution { 3 | public: 4 | int trailingZeroes(int n) { 5 | int sum = 0; 6 | while (n > 0) { 7 | sum += (n /= 5); 8 | } 9 | return sum; 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /algorithms/0001-0500/0190_reverse-bits_1_AC.cpp: -------------------------------------------------------------------------------- 1 | // easy 2 | #include 3 | 4 | class Solution { 5 | public: 6 | uint32_t reverseBits(uint32_t n) { 7 | uint32_t r = 0u; 8 | int i; 9 | for (i = 0; i < 32; ++i) { 10 | r = (r << 1u) | (n & 1u); 11 | n >>= 1u; 12 | } 13 | return r; 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /algorithms/0001-0500/0191_number-of-1-bits_1_AC.cpp: -------------------------------------------------------------------------------- 1 | // easy 2 | class Solution { 3 | public: 4 | int hammingWeight(uint32_t n) { 5 | int cnt = 0; 6 | while (n != 0) { 7 | n &= n - 1; 8 | ++cnt; 9 | } 10 | return cnt; 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /algorithms/0001-0500/0198_house-robber_1_AC.cpp: -------------------------------------------------------------------------------- 1 | // medium 2 | #include 3 | using std::max; 4 | 5 | class Solution { 6 | public: 7 | int rob(vector& nums) { 8 | int n = nums.size(); 9 | int f1, f2, f3; 10 | f1 = f2 = f3 = 0; 11 | int i; 12 | for (i = 0; i < n; ++i) { 13 | f3 = max(f1 + nums[i], f2); 14 | f1 = f2; 15 | f2 = f3; 16 | } 17 | return f3; 18 | } 19 | }; 20 | -------------------------------------------------------------------------------- /algorithms/0001-0500/0201_bitwise-and-of-numbers-range_1_AC.cpp: -------------------------------------------------------------------------------- 1 | // medium 2 | class Solution { 3 | public: 4 | int rangeBitwiseAnd(int m, int n) { 5 | if (m == 0) { 6 | return 0; 7 | } 8 | int x = n; 9 | while (x > m) { 10 | x = (x & x - 1); 11 | } 12 | return x; 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /algorithms/0001-0500/0202_happy-number_2_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # two liner 3 | class Solution: 4 | def isHappy(self, n: int) -> bool: 5 | f = lambda x, y: True if x == 1 else False if x in y else f(sum([int(c) ** 2 for c in str(x)]), y | set([x])) 6 | return f(n, set()) 7 | -------------------------------------------------------------------------------- /algorithms/0001-0500/0231_power-of-two_1_AC.cpp: -------------------------------------------------------------------------------- 1 | // easy 2 | class Solution { 3 | public: 4 | bool isPowerOfTwo(int n) { 5 | return n > 0 && (n & n - 1) == 0; 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /algorithms/0001-0500/0242_valid-anagram_2_AC.cpp: -------------------------------------------------------------------------------- 1 | // easy 2 | #include 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | bool isAnagram(string s, string t) { 8 | if (s.size() != t.size()) { 9 | return false; 10 | } 11 | sort(s.begin(), s.end()); 12 | sort(t.begin(), t.end()); 13 | return s == t; 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /algorithms/0001-0500/0258_add-digits_1_AC.cpp: -------------------------------------------------------------------------------- 1 | // easy 2 | // Digital root. 3 | class Solution { 4 | public: 5 | int addDigits(int num) { 6 | return num > 0 ? (num + 8) % 9 + 1 : 0; 7 | } 8 | }; 9 | -------------------------------------------------------------------------------- /algorithms/0001-0500/0268_missing-number_1_AC.cpp: -------------------------------------------------------------------------------- 1 | // easy 2 | #include 3 | 4 | class Solution { 5 | public: 6 | int missingNumber(vector& nums) { 7 | int64_t sum = 0; 8 | int n = nums.size(); 9 | int i; 10 | for (i = 0; i < n; ++i) { 11 | sum += nums[i]; 12 | } 13 | return 1LL * n * (n + 1) / 2 - sum; 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /algorithms/0001-0500/0283_move-zeroes_1_AC.cpp: -------------------------------------------------------------------------------- 1 | // easy 2 | class Solution { 3 | public: 4 | void moveZeroes(vector& nums) { 5 | int n = nums.size(); 6 | int i, j; 7 | i = j = 0; 8 | while (i < n) { 9 | if (nums[i] != 0) { 10 | nums[j++] = nums[i]; 11 | } 12 | ++i; 13 | } 14 | while (j < n) { 15 | nums[j++] = 0; 16 | } 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /algorithms/0001-0500/0292_nim-game_1_AC.cpp: -------------------------------------------------------------------------------- 1 | // easy 2 | class Solution { 3 | public: 4 | bool canWinNim(int n) { 5 | return n % 4 != 0; 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /algorithms/0001-0500/0319_bulb-switcher_1_AC.cpp: -------------------------------------------------------------------------------- 1 | // medium 2 | // This is a simple but very elegant problem, to show the power of math thinking. 3 | // I still remember the day when I explained this to my ex-girlfriend on a dinner table. 4 | // Smiles fade, words echo, but science never dies. 5 | #include 6 | using std::sqrt; 7 | 8 | class Solution { 9 | public: 10 | int bulbSwitch(int n) { 11 | return (int)sqrt(n); 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /algorithms/0001-0500/0326_power-of-three_1_AC.cpp: -------------------------------------------------------------------------------- 1 | // easy 2 | // Iteration. 3 | class Solution { 4 | public: 5 | bool isPowerOfThree(int n) { 6 | if (n <= 0) { 7 | return false; 8 | } 9 | while (n != 1) { 10 | if (n % 3 != 0) { 11 | return false; 12 | } 13 | n /= 3; 14 | } 15 | return true; 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /algorithms/0001-0500/0326_power-of-three_2_AC.cpp: -------------------------------------------------------------------------------- 1 | // easy 2 | // Sloppy solution by log() and exp(). 3 | // Using natural logarithm will result in WA. 4 | // Using FP arithmetics on integers is bad practice. 5 | #include 6 | using std::log; 7 | using std::exp; 8 | 9 | class Solution { 10 | public: 11 | bool isPowerOfThree(int n) { 12 | if (n <= 0) { 13 | return false; 14 | } 15 | return int(pow(3.0, int(log10(1.0 * n) / log10(3.0)))) == n; 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /algorithms/0001-0500/0338_counting-bits_1_AC.cpp: -------------------------------------------------------------------------------- 1 | // easy 2 | // O(n) DP 3 | class Solution { 4 | public: 5 | vector countBits(int num) { 6 | vector dp(num + 1, 0); 7 | int i; 8 | for (i = 1; i <= num; ++i) { 9 | dp[i] = dp[i & i - 1] + 1; 10 | } 11 | return dp; 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /algorithms/0001-0500/0342_power-of-four_1_AC.cpp: -------------------------------------------------------------------------------- 1 | // easy 2 | // Naive 3 | class Solution { 4 | public: 5 | bool isPowerOfFour(int num) { 6 | if (num <= 0) { 7 | return false; 8 | } 9 | while ((num & 0x3) == 0) { 10 | num >>= 2; 11 | } 12 | return num == 1; 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /algorithms/0001-0500/0342_power-of-four_2_AC.cpp: -------------------------------------------------------------------------------- 1 | // easy 2 | // Using logarithm 3 | #include 4 | using std::log10; 5 | 6 | class Solution { 7 | public: 8 | bool isPowerOfFour(int num) { 9 | if (num <= 0) { 10 | return false; 11 | } 12 | int lg = int(log10(1.0 * num) / log10(4.0)); 13 | return 1 << (2 * lg) == num; 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /algorithms/0001-0500/0344_reverse-string_1_AC.cpp: -------------------------------------------------------------------------------- 1 | // easy 2 | #include 3 | using std::reverse; 4 | 5 | class Solution { 6 | public: 7 | string reverseString(string s) { 8 | reverse(s.begin(), s.end()); 9 | return s; 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /algorithms/0001-0500/0344_reverse-string_2_AC.cpp: -------------------------------------------------------------------------------- 1 | // easy 2 | #include 3 | using std::swap; 4 | 5 | class Solution { 6 | public: 7 | string reverseString(string s) { 8 | int n = s.size(); 9 | int i = 0; 10 | int j = n - 1; 11 | while (i < j) { 12 | swap(s[i++], s[j--]); 13 | } 14 | return s; 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /algorithms/0001-0500/0367_valid-perfect-square_1_AC.cpp: -------------------------------------------------------------------------------- 1 | // easy 2 | class Solution { 3 | public: 4 | bool isPerfectSquare(int num) { 5 | int ll = 1; 6 | int rr = num; 7 | int mm; 8 | while (rr - ll > 1) { 9 | mm = ll + (rr - ll >> 1); 10 | if (mm <= num / mm) { 11 | ll = mm; 12 | } else { 13 | rr = mm; 14 | } 15 | } 16 | return ll * ll == num; 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /algorithms/0001-0500/0389_find-the-difference_2_AC.cpp: -------------------------------------------------------------------------------- 1 | // easy 2 | #include 3 | using std::sort; 4 | 5 | class Solution { 6 | public: 7 | char findTheDifference(string s, string t) { 8 | sort(s.begin(), s.end()); 9 | sort(t.begin(), t.end()); 10 | int i; 11 | int n = s.size(); 12 | for (i = 0; i < n; ++i) { 13 | if (s[i] != t[i]) { 14 | break; 15 | } 16 | } 17 | return t[i]; 18 | } 19 | }; 20 | -------------------------------------------------------------------------------- /algorithms/0001-0500/0392_is-subsequence_1_AC.cpp: -------------------------------------------------------------------------------- 1 | // easy 2 | class Solution { 3 | public: 4 | bool isSubsequence(string s, string t) { 5 | int ls = s.size(); 6 | int lt = t.size(); 7 | int i = 0; 8 | int j = 0; 9 | while (i < ls && j < lt) { 10 | if (s[i] == t[j]) { 11 | ++i; 12 | } 13 | ++j; 14 | } 15 | return i == ls; 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /algorithms/0001-0500/0441_arranging-coins_1_AC.cpp: -------------------------------------------------------------------------------- 1 | // easy 2 | #include 3 | using std::sqrt; 4 | 5 | class Solution { 6 | public: 7 | int arrangeCoins(int n) { 8 | if (n <= 0) { 9 | return 0; 10 | } 11 | return int((sqrt(8.0 * n + 1.0) - 1.0) / 2.0); 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /algorithms/0001-0500/0461_hamming-distance_1_AC.cpp: -------------------------------------------------------------------------------- 1 | // easy 2 | class Solution { 3 | public: 4 | int hammingDistance(int x, int y) { 5 | x ^= y; 6 | int cnt = 0; 7 | while (x != 0) { 8 | x = x & x - 1; 9 | ++cnt; 10 | } 11 | return cnt; 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /algorithms/0001-0500/0492_construct-the-rectangle_1_AC.cpp: -------------------------------------------------------------------------------- 1 | // easy 2 | #include 3 | using std::sqrt; 4 | 5 | class Solution { 6 | public: 7 | vector constructRectangle(int area) { 8 | int rt = sqrt(area); 9 | while (rt > 1 && area % rt != 0) { 10 | --rt; 11 | } 12 | vector res; 13 | res.push_back(area / rt); 14 | res.push_back(rt); 15 | return res; 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /algorithms/0501-1000/0509_fibonacci-number_1_AC.cpp: -------------------------------------------------------------------------------- 1 | // easy 2 | class Solution { 3 | public: 4 | int fib(int N) { 5 | if (N < 2) { 6 | return N; 7 | } 8 | int i; 9 | int f1 = 0, f2 = 1, f3; 10 | for (i = 2; i <= N; ++i) { 11 | f3 = f1 + f2; 12 | f1 = f2; 13 | f2 = f3; 14 | } 15 | return f3; 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /algorithms/0501-1000/0518_coin-change-ii_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/coin-change-2/ 3 | # knapsack 4 | class Solution: 5 | def change(self, amount: int, coins: List[int]) -> int: 6 | n = amount 7 | dp = [0 for i in range(n + 1)] 8 | 9 | dp[0] = 1 10 | for c in coins: 11 | for i in range(c, n + 1): 12 | dp[i] += dp[i - c] 13 | return dp[n] 14 | -------------------------------------------------------------------------------- /algorithms/0501-1000/0541_reverse-string-ii_1_AC.cpp: -------------------------------------------------------------------------------- 1 | // easy 2 | #include 3 | #include 4 | using std::reverse; 5 | using std::string; 6 | 7 | class Solution { 8 | public: 9 | string reverseStr(string s, int k) { 10 | int ls = s.size(); 11 | int i, j; 12 | for (i = 0; i < ls; i += 2 * k) { 13 | reverse(s.begin() + i, s.begin() + i + min(k, ls - i)); 14 | } 15 | 16 | return s; 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /algorithms/0501-1000/0633_sum-of-square-numbers_1_AC.cpp: -------------------------------------------------------------------------------- 1 | // medium 2 | #include 3 | using std::sqrt; 4 | 5 | class Solution { 6 | public: 7 | bool judgeSquareSum(int c) { 8 | int i, j; 9 | for (i = 0; 2LL * i * i <= c; ++i) { 10 | j = (int)sqrt(c - i * i); 11 | if (j * j == c - i * i) { 12 | return true; 13 | } 14 | } 15 | return false; 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /algorithms/0501-1000/0657_robot-return-to-origin_1_AC.cpp: -------------------------------------------------------------------------------- 1 | // easy 2 | #include 3 | #include 4 | using std::string; 5 | using std::unordered_map; 6 | 7 | class Solution { 8 | public: 9 | bool judgeCircle(string moves) { 10 | unordered_map um; 11 | for (auto &c: moves) { 12 | ++um[c]; 13 | } 14 | return (um['L'] == um['R'] && um['U'] == um['D']); 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /algorithms/0501-1000/0709_to-lower-case_1_AC.cpp: -------------------------------------------------------------------------------- 1 | // easy 2 | // to-lower-case 3 | #include 4 | using std::isupper; 5 | 6 | class Solution { 7 | public: 8 | string toLowerCase(string str) { 9 | int ls = str.size(); 10 | for (int i = 0; i < ls; ++i) { 11 | if (isupper(str[i])) { 12 | str[i] = str[i] - 'A' + 'a'; 13 | } 14 | } 15 | return str; 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /algorithms/0501-1000/0717_1-bit-and-2-bit-characters_1_AC.cpp: -------------------------------------------------------------------------------- 1 | // easy 2 | class Solution { 3 | public: 4 | bool isOneBitCharacter(vector& bits) { 5 | int n = bits.size(); 6 | int i; 7 | int len; 8 | 9 | i = 0; 10 | while (i < n) { 11 | len = (bits[i] == 0 ? 1 : 2); 12 | i += len; 13 | } 14 | return len == 1; 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /algorithms/0501-1000/0744_find-smallest-letter-greater-than-target_1_AC.cpp: -------------------------------------------------------------------------------- 1 | // easy 2 | #include 3 | #include 4 | using std::upper_bound; 5 | using std::vector; 6 | 7 | class Solution { 8 | public: 9 | char nextGreatestLetter(vector& letters, char target) { 10 | auto &a = letters; 11 | int n = a.size(); 12 | int i = upper_bound(a.begin(), a.end(), target) - a.begin(); 13 | if (i == n) { 14 | i = 0; 15 | } 16 | return a[i]; 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /algorithms/0501-1000/0760_find-anagram-mappings_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/find-anagram-mappings/ 3 | # 1AC 4 | class Solution: 5 | def anagramMappings(self, A: List[int], B: List[int]) -> List[int]: 6 | mb = {} 7 | for i, v in enumerate(B): 8 | if not v in mb: 9 | mb[v] = [] 10 | mb[v].append(i) 11 | res = [] 12 | for v in A: 13 | res.append(mb[v].pop()) 14 | return res 15 | -------------------------------------------------------------------------------- /algorithms/0501-1000/0796_rotate-string_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/rotate-string/ 3 | class Solution: 4 | def rotateString(self, A: str, B: str) -> bool: 5 | s = A + A 6 | return len(A) == len(B) and s.find(B) != -1 7 | -------------------------------------------------------------------------------- /algorithms/0501-1000/0832_flipping-an-image_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/flipping-an-image/ 3 | class Solution: 4 | def flipAndInvertImage(self, A: List[List[int]]) -> List[List[int]]: 5 | return [[1 - x for x in row[::-1]] for row in A] 6 | -------------------------------------------------------------------------------- /algorithms/0501-1000/0836_rectangle-overlap_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/rectangle-overlap/ 3 | class Solution: 4 | def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool: 5 | rec3 = [max(rec1[0], rec2[0]), max(rec1[1], rec2[1]),\ 6 | min(rec1[2], rec2[2]), min(rec1[3], rec2[3])] 7 | rec3[0] = min(rec3[0], rec3[2]) 8 | rec3[1] = min(rec3[1], rec3[3]) 9 | return (rec3[2] - rec3[0]) * (rec3[3] - rec3[1]) > 0 10 | -------------------------------------------------------------------------------- /algorithms/0501-1000/0852_peak-index-in-a-mountain-array_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/peak-index-in-a-mountain-array/ 3 | class Solution: 4 | def peakIndexInMountainArray(self, A: List[int]) -> int: 5 | n = len(A) 6 | for i in range(1, n - 1): 7 | if A[i] > A[i - 1] and A[i] > A[i + 1]: 8 | return i 9 | -------------------------------------------------------------------------------- /algorithms/0501-1000/0859_buddy-strings_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/buddy-strings/ 3 | class Solution: 4 | def buddyStrings(self, A: str, B: str) -> bool: 5 | if len(A) != len(B): 6 | return False 7 | n = len(A) 8 | if A == B: 9 | return len(set(A)) < n 10 | diff = [ord(A[i]) - ord(B[i]) for i in range(n) if A[i] != B[i]] 11 | return len(diff) == 2 and sum(diff) == 0 12 | -------------------------------------------------------------------------------- /algorithms/0501-1000/0867_transpose-matrix_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/transpose-matrix/ 3 | class Solution: 4 | def transpose(self, A: List[List[int]]) -> List[List[int]]: 5 | n = len(A) 6 | m = len(A[0]) 7 | B = [[0 for j in range(n)] for i in range(m)] 8 | for i in range(n): 9 | for j in range(m): 10 | B[j][i] = A[i][j] 11 | return B 12 | -------------------------------------------------------------------------------- /algorithms/0501-1000/0868_binary-gap_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/binary-gap/ 3 | class Solution: 4 | def binaryGap(self, N: int) -> int: 5 | n = N 6 | p1 = -1 7 | p2 = 0 8 | res = 0 9 | while n != 0: 10 | if (n & 1) == 1: 11 | if p1 != -1: 12 | res = max(res, p2 - p1) 13 | p1 = p2 14 | n >>= 1 15 | p2 += 1 16 | return res 17 | -------------------------------------------------------------------------------- /algorithms/0501-1000/0869_reordered-power-of-2_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/reordered-power-of-2/ 3 | class Solution: 4 | def __init__(self): 5 | self.st2 = set() 6 | for i in range(31): 7 | self.st2.add(''.join(sorted(str(2 ** i)))) 8 | 9 | def reorderedPowerOf2(self, N: int) -> bool: 10 | return ''.join(sorted(str(N))) in self.st2 11 | -------------------------------------------------------------------------------- /algorithms/0501-1000/0877_stone-game_2_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/stone-game/ 3 | # the brain teaser way 4 | class Solution: 5 | def stoneGame(self, piles: List[int]) -> bool: 6 | return True 7 | -------------------------------------------------------------------------------- /algorithms/0501-1000/0888_fair-candy-swap_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/fair-candy-swap/ 3 | class Solution: 4 | def fairCandySwap(self, A: List[int], B: List[int]) -> List[int]: 5 | sa = sum(A) 6 | sb = sum(B) 7 | diff = (sa - sb) // 2 8 | sta = set(A) 9 | stb = set(B) 10 | for xa in sta: 11 | if (xa - diff) in stb: 12 | return [xa, xa - diff] 13 | return None 14 | -------------------------------------------------------------------------------- /algorithms/0501-1000/0893_groups-of-special-equivalent-strings_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/groups-of-special-equivalent-strings/ 3 | class Solution: 4 | def numSpecialEquivGroups(self, A: List[str]) -> int: 5 | def getEquivalent(s): 6 | return ''.join(sorted(s[0::2]) + sorted(s[1::2])) 7 | 8 | a = [getEquivalent(s) for s in A] 9 | eg = set() 10 | for s in a: 11 | eg.add(s) 12 | return len(eg) 13 | -------------------------------------------------------------------------------- /algorithms/0501-1000/0908_smallest-range-i_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/smallest-range-i/ 3 | class Solution: 4 | def smallestRangeI(self, A: List[int], K: int) -> int: 5 | return max(0, max(A) - min(A) - 2 * K) 6 | -------------------------------------------------------------------------------- /algorithms/0501-1000/0976_largest-perimeter-triangle_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/largest-perimeter-triangle/ 3 | class Solution: 4 | def largestPerimeter(self, A: List[int]) -> int: 5 | a = sorted(A) 6 | a.reverse() 7 | n = len(a) 8 | res = 0 9 | for i in range(n - 2): 10 | if a[i] - a[i + 1] < a[i + 2]: 11 | res = sum(a[i: i + 3]) 12 | break 13 | return res 14 | -------------------------------------------------------------------------------- /algorithms/0501-1000/0991_broken-calculator_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/broken-calculator/ 3 | class Solution: 4 | def brokenCalc(self, X: int, Y: int) -> int: 5 | x, y = X, Y 6 | if x >= y: 7 | return x - y 8 | res = 0 9 | while x < y: 10 | if y % 2 == 0: 11 | y //= 2 12 | else: 13 | y += 1 14 | res += 1 15 | res += x - y 16 | return res 17 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1009_complement-of-base-10-integer_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/complement-of-base-10-integer/ 3 | from math import floor, log2 4 | 5 | class Solution: 6 | def bitwiseComplement(self, N: int) -> int: 7 | if N == 0: 8 | return 1 9 | return (1 << int(floor(log2(N)) + 1)) - 1 - N 10 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1016_binary-string-with-substrings-representing-1-to-n_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/binary-string-with-substrings-representing-1-to-n/ 3 | # Seriously, I can't think of any but brute-force. 4 | class Solution: 5 | def queryString(self, S: str, N: int) -> bool: 6 | for i in range(1, N + 1): 7 | bs = bin(i)[2:] 8 | if S.find(bs) == -1: 9 | return False 10 | return True 11 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1017_convert-to-base-2_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/convert-to-base-2/ 3 | # a bit tricky 4 | class Solution: 5 | def baseNeg2(self, N: int) -> str: 6 | n = N 7 | if n == 0: 8 | return '0' 9 | 10 | res = [] 11 | while n != 0: 12 | res.append(chr(ord('0') + (n & 1))) 13 | # key here 14 | n = -(n >> 1) 15 | return ''.join(res[::-1]) 16 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1018_binary-prefix-divisible-by-5_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/binary-prefix-divisible-by-5/ 3 | class Solution: 4 | def prefixesDivBy5(self, A: List[int]) -> List[bool]: 5 | res = [] 6 | val = 0 7 | for x in A: 8 | val = (val << 1) + x 9 | res.append(val % 5 == 0) 10 | return res 11 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1051_height-checker_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/height-checker/ 3 | # this problem is not clearly worded 4 | class Solution: 5 | def heightChecker(self, heights: List[int]) -> int: 6 | heights_sorted = sorted(heights) 7 | count = 0 8 | for i in range(len(heights)): 9 | if heights[i] != heights_sorted[i]: 10 | count += 1 11 | return count 12 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1056_confusing-number_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/confusing-number/ 3 | class Solution: 4 | def confusingNumber(self, N: int) -> bool: 5 | mm = dict(zip(list('01689'), list('01986'))) 6 | s1 = str(N) 7 | s2 = ''.join([mm[c] for c in s1[::-1] if c in mm]) 8 | return len(s1) == len(s2) and s1 != s2 9 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1078_occurrences-after-bigram_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/occurrences-after-bigram/ 3 | class Solution: 4 | def findOcurrences(self, text: str, first: str, second: str) -> List[str]: 5 | arr = text.strip().split(' ') 6 | n = len(arr) 7 | res = [] 8 | for i in range(n - 2): 9 | if arr[i] == first and arr[i + 1] == second: 10 | res.append(arr[i + 2]) 11 | return res 12 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1085_sum-of-digits-in-the-minimum-number_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/sum-of-digits-in-the-minimum-number/ 3 | # 1AC, boring 4 | class Solution: 5 | def sumOfDigits(self, A: List[int]) -> int: 6 | def sumDigit(x): 7 | res = 0 8 | while x != 0: 9 | res += x % 10 10 | x //= 10 11 | return res 12 | 13 | return 1 - sumDigit(min(A)) % 2 14 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1118_number-of-days-in-a-month_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/number-of-days-in-a-month/ 3 | # 1AC 4 | class Solution: 5 | def numberOfDays(self, Y: int, M: int) -> int: 6 | md = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] 7 | if M != 2: 8 | return md[M] 9 | if Y % 400 == 0 or (Y % 100 != 0 and Y % 4 == 0): 10 | return md[M] + 1 11 | return md[M] 12 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1119_remove-vowels-from-a-string_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/replace-employee-id-with-the-unique-identifier/ 3 | # 1AC 4 | import re 5 | 6 | class Solution: 7 | def removeVowels(self, S: str) -> str: 8 | return re.sub('[aeiou]', '', S) 9 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1122_relative-sort-array_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/relative-sort-array/ 3 | class Solution: 4 | def relativeSortArray(self, arr1: List[int], arr2: List[int]) -> List[int]: 5 | m2 = dict((x, i) for i, x in enumerate(arr2)) 6 | arr_idx1 = [m2[x] for x in arr1 if x in m2] 7 | head = [arr2[i] for i in sorted(arr_idx1)] 8 | tail = sorted([x for x in arr1 if not x in m2]) 9 | return head + tail 10 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1134_armstrong-number_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/armstrong-number/ 3 | # 1AC 4 | class Solution: 5 | def isArmstrong(self, N: int) -> bool: 6 | ps = 0 7 | sn = str(N) 8 | k = len(sn) 9 | for c in sn: 10 | ps += (ord(c) - ord('0')) ** k 11 | return ps == N 12 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1137_n-th-tribonacci-number_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/n-th-tribonacci-number/ 3 | class Solution: 4 | def tribonacci(self, n: int) -> int: 5 | f = [0, 1, 1] 6 | if n < 3: 7 | return f[n] 8 | for i in range(3, n + 1): 9 | x = sum(f) 10 | f = [f[1], f[2], x] 11 | return f[2] 12 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1154_day-of-the-year_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/day-of-the-year/ 3 | import datetime 4 | 5 | class Solution: 6 | def dayOfYear(self, date: str) -> int: 7 | dt = datetime.datetime.strptime(date, '%Y-%m-%d') 8 | dd = dt.date() 9 | d0 = datetime.date(dd.year, 1, 1) 10 | delta = dd - d0 11 | return delta.days + 1 12 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1165_single-row-keyboard_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/single-row-keyboard/ 3 | # 1AC 4 | class Solution: 5 | def calculateTime(self, keyboard: str, word: str) -> int: 6 | mm = {} 7 | for i, c in enumerate(keyboard): 8 | mm[c] = i 9 | c0 = keyboard[0] 10 | res = 0 11 | for c in word: 12 | res += abs(mm[c] - mm[c0]) 13 | c0 = c 14 | return res 15 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1184_distance-between-bus-stops_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/distance-between-bus-stops/ 3 | class Solution: 4 | def distanceBetweenBusStops(self, distance: List[int], start: int, destination: int) -> int: 5 | if start > destination: 6 | return self.distanceBetweenBusStops(distance, destination, start) 7 | a = distance 8 | sa = sum(a) 9 | s1 = sum(a[start: destination]) 10 | return min(s1, sa - s1) 11 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1185_day-of-the-week_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/day-of-the-week/ 3 | from datetime import date 4 | from calendar import day_name 5 | 6 | class Solution: 7 | def dayOfTheWeek(self, day: int, month: int, year: int) -> str: 8 | dt = date(year, month, day) 9 | wd = dt.weekday() 10 | return day_name[wd] 11 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1196_how-many-apples-can-you-put-into-the-basket_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/how-many-apples-can-you-put-into-the-basket/ 3 | # 1AC, sort and count 4 | class Solution: 5 | def maxNumberOfApples(self, arr: List[int]) -> int: 6 | a = arr 7 | a.sort() 8 | val = 5000 9 | res = 0 10 | for x in a: 11 | if val < x: 12 | break 13 | val -= x 14 | res += 1 15 | return res 16 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1207_unique-number-of-occurrences_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/unique-number-of-occurrences/ 3 | class Solution: 4 | def uniqueOccurrences(self, arr: List[int]) -> bool: 5 | m = {} 6 | for x in arr: 7 | if not x in m: 8 | m[x] = 0 9 | m[x] += 1 10 | counts = m.values() 11 | return len(counts) == len(set(counts)) 12 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1217_minimum-cost-to-move-chips-to-the-same-position_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/play-with-chips/ 3 | class Solution: 4 | def minCostToMoveChips(self, chips: List[int]) -> int: 5 | n = len(chips) 6 | odd = len([x for x in chips if x % 2 == 1]) 7 | even = n - odd 8 | return min(odd, even) 9 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1227_airplane-seat-assignment-probability_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/airplane-seat-assignment-probability/ 3 | class Solution: 4 | def nthPersonGetsNthSeat(self, n: int) -> float: 5 | dp = 1.0 6 | for i in range(2, n + 1): 7 | dp = 1.0 / i + (i - 2.0) / i * dp 8 | return dp 9 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1228_missing-number-in-arithmetic-progression_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/missing-number-in-arithmetic-progression/ 3 | class Solution: 4 | def missingNumber(self, arr: List[int]) -> int: 5 | a = arr 6 | n = len(a) 7 | d = (a[n - 1] - a[0]) // n 8 | if d == 0: 9 | return a[0] 10 | i = 1 11 | while a[i] - a[i - 1] == d: 12 | i += 1 13 | return a[i] - d 14 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1256_encode-number_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/encode-number/ 3 | # 1AC, same idea, but three times the work with C++ 4 | class Solution: 5 | def encode(self, num: int) -> str: 6 | if num == 0: 7 | return '' 8 | n = num + 1 9 | bl = n.bit_length() - 1 10 | m = 1 << bl 11 | s = '{{:0{}b}}'.format(bl) 12 | s = s.format(n - m) 13 | return s 14 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1271_hexspeak_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/hexspeak/ 3 | import re 4 | 5 | class Solution: 6 | def toHexspeak(self, num: str) -> str: 7 | hn = hex(int(num))[2:].upper() 8 | if re.search('[2-9]', hn): 9 | return 'ERROR' 10 | hn = re.sub('0', 'O', hn) 11 | hn = re.sub('1', 'I', hn) 12 | return hn 13 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1304_find-n-unique-integers-sum-up-to-zero_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/find-n-unique-integers-sum-up-to-zero/ 3 | class Solution: 4 | def sumZero(self, n: int) -> List[int]: 5 | a1 = list(range(1, n // 2 + 1)) 6 | a2 = [-x for x in a1] 7 | a3 = a1 + a2 8 | if n % 2 == 1: 9 | a3.append(0) 10 | return a3 11 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1310_xor-queries-of-a-subarray_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/xor-queries-of-a-subarray/ 3 | class Solution: 4 | def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]: 5 | n = len(arr) 6 | apx = [0 for i in range(n + 1)] 7 | for i in range(n): 8 | apx[i + 1] = apx[i] ^ arr[i] 9 | res = [] 10 | for i1, i2 in queries: 11 | res.append(apx[i2 + 1] ^ apx[i1]) 12 | return res 13 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1331_rank-transform-of-an-array_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/rank-transform-of-an-array/ 3 | class Solution: 4 | def arrayRankTransform(self, arr: List[int]) -> List[int]: 5 | arr_sorted = sorted(set(arr)) 6 | m = dict([(x, i + 1) for i, x in enumerate(arr_sorted)]) 7 | res = [m[x] for x in arr] 8 | return res 9 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1337_the-k-weakest-rows-in-a-matrix_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/the-k-weakest-rows-in-a-matrix/ 3 | class Solution: 4 | def kWeakestRows(self, mat: List[List[int]], k: int) -> List[int]: 5 | a1 = list(map(sum, mat)) 6 | a2 = list(enumerate(a1)) 7 | a2.sort(key=lambda x: x[1]) 8 | a3 = list(map(lambda x: x[0], a2)) 9 | return a3[:k] 10 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1342_number-of-steps-to-reduce-a-number-to-zero_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/number-of-steps-to-reduce-a-number-to-zero/ 3 | class Solution: 4 | def numberOfSteps (self, num: int) -> int: 5 | res = 0 6 | while num != 0: 7 | if num % 2 == 0: 8 | num //= 2 9 | else: 10 | num -= 1 11 | res += 1 12 | return res 13 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1344_angle-between-hands-of-a-clock_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/angle-between-hands-of-a-clock/ 3 | class Solution: 4 | def angleClock(self, hour: int, minutes: int) -> float: 5 | am = 360.0 * minutes / 60 6 | ah = 360.0 * (hour % 12 + minutes / 60.0) / 12.0 7 | res = abs(am - ah) 8 | return min(res, 360.0 - res) 9 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1359_count-all-valid-pickup-and-delivery-options_1_AC.py: -------------------------------------------------------------------------------- 1 | # hard 2 | # https://leetcode.com/problems/count-all-valid-pickup-and-delivery-options/ 3 | # how is this hard? 4 | class Solution: 5 | def countOrders(self, n: int) -> int: 6 | MOD = int(1e9 + 7) 7 | 8 | res = 1 9 | for i in range(2, n + 1): 10 | res = res * ((2 * i - 1) * i) % MOD 11 | return res 12 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1365_how-many-numbers-are-smaller-than-the-current-number_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number/ 3 | from bisect import bisect_left 4 | 5 | class Solution: 6 | def smallerNumbersThanCurrent(self, nums: List[int]) -> List[int]: 7 | a = sorted(nums) 8 | res = [] 9 | for x in nums: 10 | i = bisect_left(a, x) 11 | res.append(i) 12 | return res 13 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1374_generate-a-string-with-characters-that-have-odd-counts_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/generate-a-string-with-characters-that-have-odd-counts/ 3 | # what's the point? 4 | class Solution: 5 | def generateTheString(self, n: int) -> str: 6 | if n % 2 == 0: 7 | res = ['a' for i in range(n - 1)] + ['b'] 8 | else: 9 | res = ['a' for i in range(n)] 10 | return ''.join(res) 11 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1402_reducing-dishes_2_AC.py: -------------------------------------------------------------------------------- 1 | # hard 2 | # https://leetcode.com/problems/reducing-dishes/ 3 | # this is greedy 4 | class Solution: 5 | def maxSatisfaction(self, satisfaction: List[int]) -> int: 6 | a = satisfaction 7 | a.sort() 8 | 9 | res, cur, ps = 0, 0, 0 10 | n = len(a) 11 | for i in range(n - 1, -1, -1): 12 | ps += a[i] 13 | cur += ps 14 | res = max(res, cur) 15 | return res 16 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1409_queries-on-a-permutation-with-key_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/queries-on-a-permutation-with-key/ 3 | # 1AC, just brute-force 4 | class Solution: 5 | def processQueries(self, queries: List[int], m: int) -> List[int]: 6 | a = list(range(1, m + 1)) 7 | res = [] 8 | for q in queries: 9 | i = a.index(q) 10 | res.append(i) 11 | del a[i] 12 | a.insert(0, q) 13 | return res 14 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1413_minimum-value-to-get-positive-step-by-step-sum_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/minimum-value-to-get-positive-step-by-step-sum/ 3 | # 1AC 4 | class Solution: 5 | def minStartValue(self, nums: List[int]) -> int: 6 | min_sm = sm = 0 7 | for x in nums: 8 | sm += x 9 | min_sm = min(min_sm, sm) 10 | res = 1 - min(0, min_sm) 11 | return res 12 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1424_diagonal-traverse-ii_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/diagonal-traverse-ii/ 3 | # careful, it's not a matrix, could be sparse 4 | class Solution: 5 | def findDiagonalOrder(self, nums: List[List[int]]) -> List[int]: 6 | ai = [] 7 | for i, r in enumerate(nums): 8 | ai += [(i + j, j, i) for j in range(len(r))] 9 | ai.sort() 10 | 11 | res = [nums[i][j] for _, j, i in ai] 12 | return res 13 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1427_perform-string-shifts_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/529/week-2/3299/ 3 | # 1AC 4 | class Solution: 5 | def stringShift(self, s: str, shift: List[List[int]]) -> str: 6 | ls = len(s) 7 | k = 0 8 | for dr, am in shift: 9 | k += (2 * dr - 1) * am 10 | k %= ls 11 | k = (ls - k) % ls 12 | return s[k:] + s[:k] 13 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1431_kids-with-the-greatest-number-of-candies_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/kids-with-the-greatest-number-of-candies/ 3 | # 1AC 4 | class Solution: 5 | def kidsWithCandies(self, candies: List[int], extraCandies: int) -> List[bool]: 6 | max_c = max(candies) 7 | res = [] 8 | for c in candies: 9 | res.append(c + extraCandies >= max_c) 10 | return res 11 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1446_consecutive-characters_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/consecutive-characters/ 3 | # 1AC 4 | class Solution: 5 | def maxPower(self, s: str) -> int: 6 | n = len(s) 7 | res = 0 8 | i = 0 9 | while i < n: 10 | j = i + 1 11 | while j < n and s[j] == s[i]: 12 | j += 1 13 | res = max(res, j - i) 14 | i = j 15 | return res 16 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1450_number-of-students-doing-homework-at-a-given-time_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/number-of-students-doing-homework-at-a-given-time/ 3 | # 1AC 4 | class Solution: 5 | def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int: 6 | n = len(startTime) 7 | res = 0 8 | for i in range(n): 9 | if queryTime >= startTime[i] and queryTime <= endTime[i]: 10 | res += 1 11 | return res 12 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1451_rearrange-words-in-a-sentence_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/rearrange-words-in-a-sentence/ 3 | class Solution: 4 | def arrangeWords(self, text: str) -> str: 5 | a = [(len(w), i, w) for i, w in enumerate(text.lower().split())] 6 | a.sort() 7 | 8 | a1 = [x[2] for x in a] 9 | a1[0] = a1[0].capitalize() 10 | 11 | return ' '.join(a1) 12 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1455_check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/ 3 | # 1AC 4 | import re 5 | 6 | class Solution: 7 | def isPrefixOfWord(self, sentence: str, searchWord: str) -> int: 8 | for i, s in enumerate(re.split('\s+', sentence.strip())): 9 | if s.startswith(searchWord): 10 | return i + 1 11 | return -1 12 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1460_make-two-arrays-equal-by-reversing-subarrays_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/make-two-arrays-equal-by-reversing-subarrays/ 3 | # 1AC, order is irrelevant 4 | class Solution: 5 | def canBeEqual(self, target: List[int], arr: List[int]) -> bool: 6 | return sorted(arr) == sorted(target) 7 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1464_maximum-product-of-two-elements-in-an-array_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/maximum-product-of-two-elements-in-an-array/ 3 | # 1AC, pointless 4 | class Solution: 5 | def maxProduct(self, nums: List[int]) -> int: 6 | a = sorted(nums) 7 | return (a[-1] - 1) * (a[-2] - 1) 8 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1470_shuffle-the-array_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/shuffle-the-array/ 3 | # 1AC 4 | class Solution: 5 | def shuffle(self, nums: List[int], n: int) -> List[int]: 6 | res = [] 7 | for i in range(n): 8 | res.append(nums[i]) 9 | res.append(nums[i + n]) 10 | return res 11 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1480_running-sum-of-1d-array_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/running-sum-of-1d-array/ 3 | # 1AC 4 | class Solution: 5 | def runningSum(self, nums: List[int]) -> List[int]: 6 | cs = 0 7 | res = [] 8 | for x in nums: 9 | cs += x 10 | res.append(cs) 11 | return res 12 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1486_xor-operation-in-an-array_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/xor-operation-in-an-array/ 3 | # 1AC, brute force 4 | class Solution: 5 | def xorOperation(self, n: int, start: int) -> int: 6 | res = 0 7 | for i in range(n): 8 | res ^= (start + 2 * i) 9 | return res 10 | -------------------------------------------------------------------------------- /algorithms/1001-1500/1491_average-salary-excluding-the-minimum-and-maximum-salary_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/ 3 | # 1AC 4 | class Solution: 5 | def average(self, salary: List[int]) -> float: 6 | return (sum(salary) - max(salary) - min(salary)) / (len(salary) - 2) 7 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1502_can-make-arithmetic-progression-from-sequence_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/can-make-arithmetic-progression-from-sequence/ 3 | # 1AC 4 | class Solution: 5 | def canMakeArithmeticProgression(self, arr: List[int]) -> bool: 6 | a = sorted(arr) 7 | dt = a[1] - a[0] 8 | for i in range(1, len(a) - 1): 9 | if a[i + 1] - a[i] != dt: 10 | return False 11 | return True 12 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1503_last-moment-before-all-ants-fall-out-of-a-plank_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/last-moment-before-all-ants-fall-out-of-a-plank/ 3 | # the collision is equivalent to nothing 4 | class Solution: 5 | def getLastMoment(self, n: int, left: List[int], right: List[int]) -> int: 6 | res = 0 7 | for x in left: 8 | res = max(res, x) 9 | for x in right: 10 | res = max(res, n - x) 11 | return res 12 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1512_number-of-good-pairs_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/number-of-good-pairs/ 3 | # 1AC 4 | class Solution: 5 | def numIdenticalPairs(self, nums: List[int]) -> int: 6 | mm = {} 7 | for x in nums: 8 | if x in mm: 9 | mm[x] += 1 10 | else: 11 | mm[x] = 1 12 | res = 0 13 | for k, v in mm.items(): 14 | res += v * (v - 1) // 2 15 | return res 16 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1518_water-bottles_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/water-bottles/ 3 | # 1AC, simulation 4 | class Solution: 5 | def numWaterBottles(self, numBottles: int, numExchange: int) -> int: 6 | nw, nb = numBottles, 0 7 | res = 0 8 | while nw > 0 or nb >= numExchange: 9 | res += nw 10 | nb += nw 11 | nw = nb // numExchange 12 | nb = nb % numExchange 13 | return res 14 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1523_count-odd-numbers-in-an-interval-range_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/count-odd-numbers-in-an-interval-range/ 3 | # well, can't be to caught off guard 4 | class Solution: 5 | def countOdds(self, low: int, high: int) -> int: 6 | res = (high - low + 1) // 2 7 | if (high & 1) and (low & 1): 8 | res += 1 9 | return res 10 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1528_shuffle-string_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/shuffle-string/ 3 | # 1AC 4 | class Solution: 5 | def restoreString(self, s: str, indices: List[int]) -> str: 6 | n = len(s) 7 | mm = dict(zip(indices, list(range(n)))) 8 | rev_indices = [mm[i] for i in range(n)] 9 | return ''.join([s[rev_indices[i]] for i in range(n)]) 10 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1550_three-consecutive-odds_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/three-consecutive-odds/ 3 | # 1AC 4 | class Solution: 5 | def threeConsecutiveOdds(self, arr: List[int]) -> bool: 6 | n = len(arr) 7 | i = 0 8 | while i < n: 9 | j = i 10 | while j < n and arr[j] % 2 == 1: 11 | j += 1 12 | if j - i >= 3: 13 | return True 14 | i = j + 1 15 | return False 16 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1551_minimum-operations-to-make-array-equal_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/minimum-operations-to-make-array-equal/ 3 | # 1AC, a bit arithmetics 4 | class Solution: 5 | def minOperations(self, n: int) -> int: 6 | if n & 1: 7 | return (n * n - 1) // 4 8 | else: 9 | return n * n // 4 10 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1556_thousand-separator_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/thousand-separator/ 3 | # 1AC 4 | import re 5 | 6 | class Solution: 7 | def thousandSeparator(self, n: int) -> str: 8 | s = str(n) 9 | nr = len(s) % 3 10 | nr = nr if nr != 0 else 3 11 | s0, s1 = s[:nr], s[nr:] 12 | if len(s1) > 0: 13 | s1 = re.sub(r'(\d{3})', r'.\1', s1) 14 | return s0 + s1 15 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1557_minimum-number-of-vertices-to-reach-all-nodes_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/minimum-number-of-vertices-to-reach-all-nodes/ 3 | # 1AC, indegree zero 4 | from collections import defaultdict 5 | 6 | class Solution: 7 | def findSmallestSetOfVertices(self, n: int, edges: List[List[int]]) -> List[int]: 8 | mm = defaultdict(lambda: 0) 9 | for x, y in edges: 10 | mm[y] += 1 11 | return [x for x in range(n) if not x in mm] 12 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1561_maximum-number-of-coins-you-can-get_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/maximum-number-of-coins-you-can-get/ 3 | # 1AC, greedy 4 | class Solution: 5 | def maxCoins(self, piles: List[int]) -> int: 6 | a = sorted(piles) 7 | n = len(a) 8 | return sum(a[n // 3: n: 2]) 9 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1566_detect-pattern-of-length-m-repeated-k-or-more-times_2_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/detect-pattern-of-length-m-repeated-k-or-more-times/ 3 | # use regex 4 | import re 5 | 6 | class Solution: 7 | def containsPattern(self, arr: List[int], m: int, k: int) -> bool: 8 | s = ''.join([chr(x) for x in arr]) 9 | return re.search(r'(.{{{}}})\1{{{}}}'.format(m, k - 1), s) is not None 10 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1572_matrix-diagonal-sum_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/matrix-diagonal-sum/ 3 | # 1AC 4 | class Solution: 5 | def diagonalSum(self, mat: List[List[int]]) -> int: 6 | n = len(mat) 7 | res = 0 8 | for i in range(n): 9 | res += mat[i][i] + mat[i][n - 1 - i] 10 | if n & 1: 11 | res -= mat[n // 2][n // 2] 12 | return res 13 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1588_sum-of-all-odd-length-subarrays_2_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/sum-of-all-odd-length-subarrays/ 3 | # O(n) 4 | class Solution: 5 | def sumOddLengthSubarrays(self, arr: List[int]) -> int: 6 | n = len(arr) 7 | res = 0 8 | for i, val in enumerate(arr): 9 | x, y = i + 1, n - i 10 | cc = (x // 2) * (y // 2) + ((x + 1) // 2) * ((y + 1) // 2) 11 | res += cc * val 12 | return res 13 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1598_crawler-log-folder_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/crawler-log-folder/ 3 | # 1AC 4 | class Solution: 5 | def minOperations(self, logs: List[str]) -> int: 6 | cnt = 0 7 | for op in logs: 8 | if op == './': 9 | continue 10 | elif op == '../': 11 | cnt = max(0, cnt - 1) 12 | else: 13 | cnt += 1 14 | return cnt 15 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1619_mean-of-array-after-removing-some-elements_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/mean-of-array-after-removing-some-elements/ 3 | # 1AC 4 | class Solution: 5 | def trimMean(self, arr: List[int]) -> float: 6 | a = sorted(arr) 7 | n = len(a) 8 | nr = n // 20 9 | return sum(a[nr: -nr]) / (n - 2 * nr) 10 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1662_check-if-two-string-arrays-are-equivalent_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/ 3 | # 1AC 4 | class Solution: 5 | def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool: 6 | return ''.join(word1) == ''.join(word2) 7 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1672_richest-customer-wealth_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/richest-customer-wealth/ 3 | # 1AC 4 | class Solution: 5 | def maximumWealth(self, accounts: List[List[int]]) -> int: 6 | max_sm = -1 7 | for a in accounts: 8 | max_sm = max(max_sm, sum(a)) 9 | return max_sm 10 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1678_goal-parser-interpretation_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/goal-parser-interpretation/ 3 | # 1AC 4 | import re 5 | 6 | class Solution: 7 | def interpret(self, command: str) -> str: 8 | s = command 9 | s = re.sub('\(\)', 'o', s) 10 | s = re.sub('\(al\)', 'al', s) 11 | return s 12 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1688_count-of-matches-in-tournament_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/count-of-matches-in-tournament/ 3 | # 1AC 4 | class Solution: 5 | def numberOfMatches(self, n: int) -> int: 6 | res = 0 7 | while n > 1: 8 | res += (n // 2) 9 | n = (n + 1) // 2 10 | return res 11 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1689_partitioning-into-minimum-number-of-deci-binary-numbers_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers/ 3 | # 1AC, that's a joke 4 | class Solution: 5 | def minPartitions(self, n: str) -> int: 6 | return max([int(c) for c in n]) 7 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1708_largest-subarray-length-k_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/largest-subarray-length-k/ 3 | # 1AC, the trick is about distinctness 4 | 5 | class Solution: 6 | def largestSubarray(self, nums: List[int], k: int) -> List[int]: 7 | n = len(nums) 8 | max_i = 0 9 | for i in range(n - k + 1): 10 | if nums[i] > nums[max_i]: 11 | max_i = i 12 | return nums[max_i: max_i + k] 13 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1716_calculate-money-in-leetcode-bank_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/calculate-money-in-leetcode-bank/ 3 | # that's awkward... 4 | class Solution: 5 | def totalMoney(self, n: int) -> int: 6 | nw = n // 7 7 | return 28 * nw + 7 * nw * (nw - 1) // 2 + (2 * nw + 1 + n % 7) * (n % 7) // 2 8 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1720_decode-xored-array_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/decode-xored-array/ 3 | # 1AC 4 | class Solution: 5 | def decode(self, encoded: List[int], first: int) -> List[int]: 6 | res = [first] 7 | cur = first 8 | for x in encoded: 9 | cur ^= x 10 | res.append(cur) 11 | return res 12 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1732_find-the-highest-altitude_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/find-the-highest-altitude/ 3 | # 1AC 4 | class Solution: 5 | def largestAltitude(self, gain: List[int]) -> int: 6 | res, cur = 0, 0 7 | for x in gain: 8 | cur += x 9 | res = max(res, cur) 10 | return res 11 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1748_sum-of-unique-elements_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/sum-of-unique-elements/ 3 | # 1AC 4 | class Solution: 5 | def sumOfUnique(self, nums: List[int]) -> int: 6 | mm = {} 7 | for x in nums: 8 | if x in mm: 9 | mm[x] += 1 10 | else: 11 | mm[x] = 1 12 | res = 0 13 | for k, v in mm.items(): 14 | if v == 1: 15 | res += k 16 | return res 17 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1773_count-items-matching-a-rule_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/count-items-matching-a-rule/ 3 | # 1AC 4 | class Solution: 5 | def countMatches(self, items: List[List[str]], ruleKey: str, ruleValue: str) -> int: 6 | mp = {'type': 0, 'color': 1, 'name': 2} 7 | ri = mp[ruleKey] 8 | res = 0 9 | for x in items: 10 | if x[ri] == ruleValue: 11 | res += 1 12 | return res 13 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1780_check-if-number-is-a-sum-of-powers-of-three_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/check-if-number-is-a-sum-of-powers-of-three/ 3 | # convert to base 3 and check for digit 1 4 | class Solution: 5 | def checkPowersOfThree(self, n: int) -> bool: 6 | while n > 0: 7 | d = n % 3 8 | n //= 3 9 | if d != 0 and d != 1: 10 | return False 11 | return True 12 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1796_second-largest-digit-in-a-string_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/second-largest-digit-in-a-string/ 3 | # 1AC 4 | import re 5 | 6 | class Solution: 7 | def secondHighest(self, s: str) -> int: 8 | a = sorted(set(list(re.sub(r'\D', '', s)))) 9 | return int(a[-2]) if len(a) >= 2 else -1 10 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1805_number-of-different-integers-in-a-string_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/number-of-different-integers-in-a-string/ 3 | import re 4 | 5 | class Solution: 6 | def numDifferentIntegers(self, word: str) -> int: 7 | s = re.sub(r'\D+', ' ', word) 8 | a = [int(x) for x in s.strip().split()] 9 | return len(set(a)) 10 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1812_determine-color-of-a-chessboard-square_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/determine-color-of-a-chessboard-square/ 3 | # 1AC 4 | class Solution: 5 | def squareIsWhite(self, coordinates: str) -> bool: 6 | return (ord(coordinates[0]) - ord('a') + int(coordinates[1])) % 2 == 0 7 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1816_truncate-sentence_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/truncate-sentence/ 3 | # 1AC 4 | class Solution: 5 | def truncateSentence(self, s: str, k: int) -> str: 6 | ws = s.strip().split() 7 | return ' '.join(ws[: min(k, len(ws))]) 8 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1822_sign-of-the-product-of-an-array_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/sign-of-the-product-of-an-array/ 3 | # 1AC 4 | class Solution: 5 | def arraySign(self, nums: List[int]) -> int: 6 | res = 1 7 | for x in nums: 8 | sig = 1 if x > 0 else -1 if x < 0 else 0 9 | res *= sig 10 | return res 11 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1823_find-the-winner-of-the-circular-game_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/find-the-winner-of-the-circular-game/ 3 | # 1AC, Josephus circle, 1-indexed 4 | class Solution: 5 | def findTheWinner(self, n: int, k: int) -> int: 6 | res = 1 7 | for i in range(2, n + 1): 8 | res = (res + k - 1) % i + 1 9 | return res 10 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1827_minimum-operations-to-make-the-array-increasing_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/ 3 | # 1AC 4 | class Solution: 5 | def minOperations(self, nums: List[int]) -> int: 6 | n = len(nums) 7 | res = 0 8 | for i in range(1, n): 9 | if nums[i] < nums[i - 1] + 1: 10 | res += nums[i - 1] + 1 - nums[i] 11 | nums[i] = nums[i - 1] + 1 12 | return res 13 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1832_check-if-the-sentence-is-pangram_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/check-if-the-sentence-is-pangram/ 3 | # 1AC 4 | class Solution: 5 | def checkIfPangram(self, sentence: str) -> bool: 6 | return len(set(sentence.lower())) == 26 7 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1833_maximum-ice-cream-bars_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/maximum-ice-cream-bars/ 3 | # 1AC, medium? 4 | class Solution: 5 | def maxIceCream(self, costs: List[int], coins: int) -> int: 6 | costs.sort() 7 | res = 0 8 | for x in costs: 9 | if coins >= x: 10 | coins -= x 11 | res += 1 12 | else: 13 | break 14 | return res 15 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1837_sum-of-digits-in-base-k_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/sum-of-digits-in-base-k/ 3 | # 1AC 4 | class Solution: 5 | def sumBase(self, n: int, k: int) -> int: 6 | if n < 0: 7 | return self.sumBase(-n, k) 8 | res = 0 9 | while n > 0: 10 | res += n % k 11 | n //= k 12 | return res 13 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1844_replace-all-digits-with-characters_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/replace-all-digits-with-characters/ 3 | # 1AC 4 | class Solution: 5 | def replaceDigits(self, s: str) -> str: 6 | res = [] 7 | for i, ch in enumerate(s): 8 | if i & 1: 9 | res.append(chr(ord(old_ch) + int(ch))) 10 | else: 11 | old_ch = ch 12 | res.append(ch) 13 | return ''.join(res) 14 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1859_sorting-the-sentence_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/sorting-the-sentence/ 3 | # 1AC 4 | 5 | class Solution: 6 | def sortSentence(self, s: str) -> str: 7 | ws = s.split() 8 | res = [0 for _ in range(len(ws))] 9 | for w_i in ws: 10 | w = w_i[:-1] 11 | i = int(w_i[-1]) - 1 12 | res[i] = w 13 | return ' '.join(res) 14 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1874_minimize-product-sum-of-two-arrays_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/minimize-product-sum-of-two-arrays/ 3 | # 1AC, a teaser 4 | 5 | class Solution: 6 | def minProductSum(self, nums1: List[int], nums2: List[int]) -> int: 7 | a1 = sorted(nums1) 8 | a2 = sorted(nums2, reverse=True) 9 | return sum([a1[i] * a2[i] for i in range(len(a1))]) 10 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1876_substrings-of-size-three-with-distinct-characters_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/substrings-of-size-three-with-distinct-characters/ 3 | # 1AC, no-brainer 4 | 5 | class Solution: 6 | def countGoodSubstrings(self, s: str) -> int: 7 | n = len(s) 8 | res = 0 9 | for i in range(2, n): 10 | if s[i] != s[i - 1] and s[i - 1] != s[i - 2] and s[i] != s[i - 2]: 11 | res += 1 12 | return res 13 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1877_minimize-maximum-pair-sum-in-array_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/ 3 | # 1AC, sort it 4 | 5 | class Solution: 6 | def minPairSum(self, nums: List[int]) -> int: 7 | a = sorted(nums) 8 | n = len(a) 9 | 10 | i = 0 11 | res = 0 12 | while i < n - 1 - i: 13 | res = max(res, a[i] + a[n - 1 - i]) 14 | i += 1 15 | return res 16 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1894_find-the-student-that-will-replace-the-chalk_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/find-the-student-that-will-replace-the-chalk/ 3 | class Solution: 4 | def chalkReplacer(self, chalk: List[int], k: int) -> int: 5 | sm = sum(chalk) 6 | k %= sm 7 | 8 | i = 0 9 | while True: 10 | if k < chalk[i]: 11 | break 12 | k -= chalk[i] 13 | i += 1 14 | return i 15 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1903_largest-odd-number-in-string_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/largest-odd-number-in-string/ 3 | 4 | class Solution: 5 | def largestOddNumber(self, num: str) -> str: 6 | n = len(num) 7 | i = n - 1 8 | while i >= 0: 9 | if (ord(num[i]) - ord('0')) % 2 == 1: 10 | break 11 | i -= 1 12 | if i == -1: 13 | return '' 14 | return num[:i + 1] 15 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1910_remove-all-occurrences-of-a-substring_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/remove-all-occurrences-of-a-substring/ 3 | # 1AC, brute-force 4 | 5 | class Solution: 6 | def removeOccurrences(self, s: str, part: str) -> str: 7 | while True: 8 | i = s.find(part) 9 | if i == -1: 10 | break 11 | s = s[:i] + s[i + len(part):] 12 | return s 13 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1913_maximum-product-difference-between-two-pairs_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/maximum-product-difference-between-two-pairs/ 3 | # 1AC, all positive 4 | 5 | class Solution: 6 | def maxProductDifference(self, nums: List[int]) -> int: 7 | a = sorted(nums) 8 | return a[-1] * a[-2] - a[0] * a[1] 9 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1920_build-array-from-permutation_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/build-array-from-permutation/ 3 | # 1AC, permute 4 | 5 | class Solution: 6 | def buildArray(self, nums: List[int]) -> List[int]: 7 | n = len(nums) 8 | res = [] 9 | for i in range(n): 10 | res.append(nums[nums[i]]) 11 | return res 12 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1929_concatenation-of-array_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/concatenation-of-array/ 3 | # 1AC 4 | 5 | class Solution: 6 | def getConcatenation(self, nums: List[int]) -> List[int]: 7 | return nums + nums 8 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1945_sum-of-digits-of-string-after-convert_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/sum-of-digits-of-string-after-convert/ 3 | # 1AC 4 | 5 | class Solution: 6 | def getLucky(self, s: str, k: int) -> int: 7 | sd = ''.join([str(ord(c) - ord('a') + 1) for c in s]) 8 | 9 | for ki in range(k): 10 | if len(sd) < 2: 11 | break 12 | sd = str(sum([int(c) for c in sd])) 13 | return int(sd) 14 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1967_number-of-strings-that-appear-as-substrings-in-word_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/number-of-strings-that-appear-as-substrings-in-word/ 3 | # 1AC 4 | 5 | class Solution: 6 | def numOfStrings(self, patterns: List[str], word: str) -> int: 7 | res = 0 8 | for p in patterns: 9 | if word.find(p) != -1: 10 | res += 1 11 | return res 12 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1974_minimum-time-to-type-word-using-special-typewriter_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/minimum-time-to-type-word-using-special-typewriter/ 3 | # 1AC, simulation 4 | 5 | class Solution: 6 | def minTimeToType(self, word: str) -> int: 7 | res = 0 8 | x = 0 9 | for c in word: 10 | i = ord(c) - ord('a') 11 | res += min((i + 26 - x) % 26, (x + 26 - i) % 26) + 1 12 | x = i 13 | return res 14 | -------------------------------------------------------------------------------- /algorithms/1501-2000/1979_find-greatest-common-divisor-of-array_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/find-greatest-common-divisor-of-array/ 3 | # 1AC 4 | 5 | class Solution: 6 | def findGCD(self, nums: List[int]) -> int: 7 | x1, x2 = min(nums), max(nums) 8 | return self.gcd(x1, x2) 9 | 10 | def gcd(self, x, y): 11 | if x > y: 12 | return self.gcd(y, x) 13 | while x != 0: 14 | x, y = y % x, x 15 | return y 16 | -------------------------------------------------------------------------------- /algorithms/1501-2000/2000_reverse-prefix-of-word_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/reverse-prefix-of-word/ 3 | 4 | class Solution: 5 | def reversePrefix(self, word: str, ch: str) -> str: 6 | idx = word.find(ch) 7 | if idx == -1: 8 | return word 9 | return word[:idx + 1][::-1] + word[idx + 1:] 10 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2011_final-value-of-variable-after-performing-operations_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/final-value-of-variable-after-performing-operations/ 3 | # 1AC 4 | 5 | class Solution: 6 | def finalValueAfterOperations(self, operations: List[str]) -> int: 7 | mm = {'++X': +1, 'X++': +1, '--X': -1, 'X--': -1} 8 | x = 0 9 | for op in operations: 10 | x += mm[op] 11 | return x 12 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2027_minimum-moves-to-convert-string_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/minimum-moves-to-convert-string/ 3 | # 1AC, no-brainer 4 | 5 | class Solution: 6 | def minimumMoves(self, s: str) -> int: 7 | ls = len(s) 8 | res = 0 9 | i = 0 10 | while i < ls: 11 | if s[i] == 'X': 12 | res += 1 13 | i += 3 14 | else: 15 | i += 1 16 | return res 17 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2032_two-out-of-three_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/two-out-of-three/ 3 | # 1AC 4 | 5 | class Solution: 6 | def twoOutOfThree(self, nums1: List[int], nums2: List[int], nums3: List[int]) -> List[int]: 7 | s1, s2, s3 = set(nums1), set(nums2), set(nums3) 8 | return list((s1 & s2) | (s2 & s3) | (s3 & s1)) 9 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2042_check-if-numbers-are-ascending-in-a-sentence_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence/ 3 | # 1AC 4 | import re 5 | 6 | class Solution: 7 | def areNumbersAscending(self, s: str) -> bool: 8 | nums = [int(w) for w in s.split() if re.match(r'^\d+$', w)] 9 | n = len(nums) 10 | for i in range(n - 1): 11 | if nums[i] >= nums[i + 1]: 12 | return False 13 | return True 14 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2057_smallest-index-with-equal-value_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/smallest-index-with-equal-value/ 3 | # 1AC 4 | 5 | class Solution: 6 | def smallestEqual(self, nums: List[int]) -> int: 7 | for i, x in enumerate(nums): 8 | if i % 10 == x: 9 | return i 10 | return -1 11 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2063_vowels-of-all-substrings_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/vowels-of-all-substrings/ 3 | # how many times does one letter appear in all substrings? 4 | class Solution: 5 | def countVowels(self, word: str) -> int: 6 | vw = set('aeiou') 7 | n = len(word) 8 | 9 | res = 0 10 | for i, c in enumerate(word): 11 | if not c in vw: 12 | continue 13 | res += (i + 1) * (n - i) 14 | return res 15 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2078_two-furthest-houses-with-different-colors_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/two-furthest-houses-with-different-colors/ 3 | # 1AC, brute-force 4 | 5 | class Solution: 6 | def maxDistance(self, colors: List[int]) -> int: 7 | n = len(colors) 8 | for k in range(n - 1, 0, -1): 9 | for i in range(n - k): 10 | if colors[i] != colors[i + k]: 11 | return k 12 | return -1 13 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2089_find-target-indices-after-sorting-array_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/find-target-indices-after-sorting-array/ 3 | # 1AC 4 | 5 | class Solution: 6 | def targetIndices(self, nums: List[int], target: int) -> List[int]: 7 | a = sorted(nums) 8 | res = [] 9 | for i, x in enumerate(a): 10 | if x == target: 11 | res.append(i) 12 | return res 13 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2099_find-subsequence-of-length-k-with-the-largest-sum_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/find-subsequence-of-length-k-with-the-largest-sum/ 3 | # 1AC 4 | 5 | class Solution: 6 | def maxSubsequence(self, nums: List[int], k: int) -> List[int]: 7 | ai = [(x, i) for i, x in enumerate(nums)] 8 | ai.sort() 9 | ai_topk = ai[-k:] 10 | ai_topk.sort(key=lambda tp: tp[1]) 11 | 12 | return [tp[0] for tp in ai_topk] 13 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2103_rings-and-rods_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/rings-and-rods/ 3 | # 1AC, bit ops 4 | 5 | class Solution: 6 | def countPoints(self, rings: str) -> int: 7 | mb = {'R': 1, 'G': 2, 'B': 4} 8 | md = [0 for i in range(10)] 9 | n = len(rings) // 2 10 | for i in range(n): 11 | col, pos = rings[2 * i], ord(rings[2 * i + 1]) - ord('1') 12 | md[pos] |= mb[col] 13 | return len([x for x in md if x == 7]) 14 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2114_maximum-number-of-words-found-in-sentences_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/maximum-number-of-words-found-in-sentences/ 3 | # 1AC, one-liner 4 | 5 | class Solution: 6 | def mostWordsFound(self, sentences: List[str]) -> int: 7 | return max([len(sen.split()) for sen in sentences]) 8 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2119_a-number-after-a-double-reversal_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | class Solution: 3 | def isSameAfterReversals(self, num: int) -> bool: 4 | def reverseDigits(x): 5 | x1 = 0 6 | R = 10 7 | while x != 0: 8 | x1 = x1 * R + x % R 9 | x //= R 10 | return x1 11 | 12 | return num == reverseDigits(reverseDigits(num)) 13 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2126_destroying-asteroids_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/destroying-asteroids/ 3 | # isn't this that ad game "hero war"? 4 | # should be easy 5 | class Solution: 6 | def asteroidsDestroyed(self, mass: int, asteroids: List[int]) -> bool: 7 | asteroids.sort() 8 | for ast in asteroids: 9 | if mass >= ast: 10 | mass += ast 11 | else: 12 | return False 13 | return True 14 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2129_capitalize-the-title_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/capitalize-the-title/ 3 | class Solution: 4 | def capitalizeTitle(self, title: str) -> str: 5 | def process(w): 6 | return w.lower() if len(w) <= 2 else w[0].upper() + w[1:].lower() 7 | 8 | return ' '.join(map(process, title.split())) 9 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2138_divide-a-string-into-groups-of-size-k_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/divide-a-string-into-groups-of-size-k/ 3 | class Solution: 4 | def divideString(self, s: str, k: int, fill: str) -> List[str]: 5 | n = len(s) 6 | if n % k != 0: 7 | s = s + fill * (k - n % k) 8 | n = len(s) 9 | 10 | return [s[i: i + k] for i in range(0, n, k)] 11 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2144_minimum-cost-of-buying-candies-with-discount_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/minimum-cost-of-buying-candies-with-discount/ 3 | class Solution: 4 | def minimumCost(self, cost: List[int]) -> int: 5 | a = sorted(cost, reverse=True) 6 | n = len(a) 7 | 8 | res = sum(a) 9 | for i in range(0, n, 3): 10 | if i + 2 < n: 11 | res -= a[i + 2] 12 | 13 | return res 14 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2154_keep-multiplying-found-values-by-two_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/keep-multiplying-found-values-by-two/ 3 | class Solution: 4 | def findFinalValue(self, nums: List[int], original: int) -> int: 5 | st = set(nums) 6 | while original in st: 7 | original *= 2 8 | return original 9 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2160_minimum-sum-of-four-digit-number-after-splitting-digits_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/minimum-sum-of-four-digit-number-after-splitting-digits/ 3 | class Solution: 4 | def minimumSum(self, num: int) -> int: 5 | a = sorted(map(int, str(num))) 6 | return (a[0] * 10 + a[3]) + (a[1] * 10 + a[2]) 7 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2169_count-operations-to-obtain-zero_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/count-operations-to-obtain-zero/ 3 | # gcd operation 4 | 5 | class Solution: 6 | def countOperations(self, num1: int, num2: int) -> int: 7 | if num1 < num2: 8 | return self.countOperations(num2, num1) 9 | if num2 == 0: 10 | return 0 11 | return num1 // num2 + self.countOperations(num2, num1 % num2) 12 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2177_find-three-consecutive-integers-that-sum-to-a-given-number_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/find-three-consecutive-integers-that-sum-to-a-given-number/ 3 | # this is absurd 4 | 5 | class Solution: 6 | def sumOfThree(self, num: int) -> List[int]: 7 | if num % 3 == 0: 8 | x = num // 3 9 | return [x - 1, x, x + 1] 10 | else: 11 | return [] 12 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2185_counting-words-with-a-given-prefix_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/counting-words-with-a-given-prefix/ 3 | class Solution: 4 | def prefixCount(self, words: List[str], pref: str) -> int: 5 | return len([w for w in words if w.startswith(pref)]) 6 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2220_minimum-bit-flips-to-convert-number_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/minimum-bit-flips-to-convert-number/ 3 | class Solution: 4 | def minBitFlips(self, start: int, goal: int) -> int: 5 | diff = start ^ goal 6 | cnt = 0 7 | while diff != 0: 8 | diff &= diff - 1 9 | cnt += 1 10 | return cnt 11 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2224_minimum-number-of-operations-to-convert-time_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/minimum-number-of-operations-to-convert-time/ 3 | class Solution: 4 | def convertTime(self, current: str, correct: str) -> int: 5 | def getMinutes(s): 6 | return int(s[:2]) * 60 + int(s[3:]) 7 | 8 | diff = getMinutes(correct) - getMinutes(current) 9 | return diff // 60 + diff % 60 // 15 + diff % 15 // 5 + diff % 5 10 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2235_add-two-integers_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/add-two-integers/ 3 | class Solution: 4 | def sum(self, num1: int, num2: int) -> int: 5 | return num1 + num2 6 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2236_root-equals-sum-of-children_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/root-equals-sum-of-children/ 3 | # Definition for a binary tree node. 4 | # class TreeNode: 5 | # def __init__(self, val=0, left=None, right=None): 6 | # self.val = val 7 | # self.left = left 8 | # self.right = right 9 | class Solution: 10 | def checkTree(self, root: Optional[TreeNode]) -> bool: 11 | return root.val == root.left.val + root.right.val 12 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2255_count-prefixes-of-a-given-string_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/count-prefixes-of-a-given-string/ 3 | class Solution: 4 | def countPrefixes(self, words: List[str], s: str) -> int: 5 | return len([w for w in words if s.startswith(w)]) 6 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2269_find-the-k-beauty-of-a-number_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/find-the-k-beauty-of-a-number/ 3 | class Solution: 4 | def divisorSubstrings(self, num: int, k: int) -> int: 5 | s = str(num) 6 | n = len(s) 7 | res = 0 8 | for i in range(n - k + 1): 9 | sub = int(s[i: i + k]) 10 | if sub != 0 and num % sub == 0: 11 | res += 1 12 | 13 | return res 14 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2278_percentage-of-letter-in-string_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/percentage-of-letter-in-string/ 3 | class Solution: 4 | def percentageLetter(self, s: str, letter: str) -> int: 5 | cc = 0 6 | for c in s: 7 | if c == letter: 8 | cc += 1 9 | return int(cc / len(s) * 100.0) 10 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2293_min-max-game_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/min-max-game/ 3 | class Solution: 4 | def minMaxGame(self, nums: List[int]) -> int: 5 | a = nums 6 | while len(a) > 1: 7 | n = len(a) // 2 8 | a1 = [0 for i in range(n)] 9 | for i in range(n): 10 | a1[i] = min(a[i << 1], a[(i << 1) + 1]) if i % 2 == 0 else max(a[i << 1], a[(i << 1) + 1]) 11 | a = a1 12 | return a[0] 13 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2315_count-asterisks_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/count-asterisks/ 3 | class Solution: 4 | def countAsterisks(self, s: str) -> int: 5 | fp = 0 6 | res = 0 7 | for c in s: 8 | if c == '|': 9 | fp = 1 - fp 10 | elif c == '*': 11 | res += 1 if fp == 0 else 0 12 | return res 13 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2317_maximum-xor-after-operations_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/maximum-xor-after-operations/ 3 | # total teaser 4 | class Solution: 5 | def maximumXOR(self, nums: List[int]) -> int: 6 | res = 0 7 | for x in nums: 8 | res |= x 9 | 10 | return res 11 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2325_decode-the-message_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/decode-the-message/ 3 | class Solution: 4 | def decodeMessage(self, key: str, message: str) -> str: 5 | mm = {' ': ' '} 6 | idx = 0 7 | for c in key: 8 | if c in mm or c == ' ': 9 | continue 10 | mm[c] = chr(ord('a') + idx) 11 | idx += 1 12 | return ''.join([mm[c] for c in message]) 13 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2351_first-letter-to-appear-twice_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/first-letter-to-appear-twice/ 3 | class Solution: 4 | def repeatedCharacter(self, s: str) -> str: 5 | st = set() 6 | for c in s: 7 | if c in st: 8 | return c 9 | else: 10 | st.add(c) 11 | return c 12 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2357_make-array-zero-by-subtracting-equal-amounts_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/make-array-zero-by-subtracting-equal-amounts/ 3 | class Solution: 4 | def minimumOperations(self, nums: List[int]) -> int: 5 | st = set(nums) 6 | if 0 in st: 7 | st.remove(0) 8 | return len(st) 9 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2365_task-scheduler-ii_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/task-scheduler-ii/ 3 | class Solution: 4 | def taskSchedulerII(self, tasks: List[int], space: int) -> int: 5 | wait = {} 6 | day = 0 7 | for x in tasks: 8 | if x in wait and day < wait[x]: 9 | day = wait[x] 10 | 11 | day += 1 12 | wait[x] = day + space 13 | return day 14 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2367_number-of-arithmetic-triplets_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/number-of-arithmetic-triplets/ 3 | class Solution: 4 | def arithmeticTriplets(self, nums: List[int], diff: int) -> int: 5 | st = set(nums) 6 | 7 | res = 0 8 | n = len(nums) 9 | for i in range(n - 2): 10 | if nums[i] + diff in st and nums[i] + 2 * diff in st: 11 | res += 1 12 | return res 13 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2390_removing-stars-from-a-string_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/removing-stars-from-a-string/ 3 | class Solution: 4 | def removeStars(self, s: str) -> str: 5 | st = [] 6 | for c in s: 7 | if c == '*': 8 | if len(st) > 0: 9 | st.pop() 10 | else: 11 | st.append(c) 12 | 13 | return ''.join(st) 14 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2395_find-subarrays-with-equal-sum_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/find-subarrays-with-equal-sum/ 3 | class Solution: 4 | def findSubarrays(self, nums: List[int]) -> bool: 5 | st = set() 6 | for i in range(len(nums) - 1): 7 | val = nums[i] + nums[i + 1] 8 | if val in st: 9 | return True 10 | st.add(val) 11 | return False 12 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2413_smallest-even-multiple_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/smallest-even-multiple/ 3 | # what? 4 | class Solution: 5 | def smallestEvenMultiple(self, n: int) -> int: 6 | return n if n % 2 == 0 else 2 * n 7 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2418_sort-the-people_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/sort-the-people/ 3 | class Solution: 4 | def sortPeople(self, names: List[str], heights: List[int]) -> List[str]: 5 | return list(map(lambda x: x[1], sorted(zip(heights, names), reverse=True))) 6 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2433_find-the-original-array-of-prefix-xor_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/find-the-original-array-of-prefix-xor/ 3 | # medium? 4 | class Solution: 5 | def findArray(self, pref: List[int]) -> List[int]: 6 | res = [pref[0]] 7 | n = len(pref) 8 | for i in range(1, n): 9 | res.append(pref[i - 1] ^ pref[i]) 10 | 11 | return res 12 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2441_largest-positive-integer-that-exists-with-its-negative_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/ 3 | class Solution: 4 | def findMaxK(self, nums: List[int]) -> int: 5 | st = set(nums) 6 | res = -1 7 | for x in nums: 8 | if x <= 0 or not -x in st: 9 | continue 10 | if res == -1 or res < x: 11 | res = x 12 | return res 13 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2446_determine-if-two-events-have-conflict_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/determine-if-two-events-have-conflict/ 3 | class Solution: 4 | def haveConflict(self, event1: List[str], event2: List[str]) -> bool: 5 | return max(event1[0], event2[0]) <= min(event1[1], event2[1]) 6 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2455_average-value-of-even-numbers-that-are-divisible-by-three_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three/ 3 | class Solution: 4 | def averageValue(self, nums: List[int]) -> int: 5 | a = [x for x in nums if x % 6 == 0] 6 | return sum(a) // len(a) if len(a) > 0 else 0 7 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2465_number-of-distinct-averages_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/number-of-distinct-averages/ 3 | class Solution: 4 | def distinctAverages(self, nums: List[int]) -> int: 5 | st = set() 6 | a = sorted(nums) 7 | n = len(a) 8 | i1, i2 = 0, n - 1 9 | while i1 <= i2: 10 | st.add(a[i1] + a[i2]) 11 | i1 += 1 12 | i2 -= 1 13 | return len(st) 14 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2469_convert-the-temperature_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/convert-the-temperature/ 3 | class Solution: 4 | def convertTemperature(self, celsius: float) -> List[float]: 5 | return [celsius + 273.15, celsius * 1.8 + 32.0] 6 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2481_minimum-cuts-to-divide-a-circle_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/minimum-cuts-to-divide-a-circle/ 3 | # teaser 4 | class Solution: 5 | def numberOfCuts(self, n: int) -> int: 6 | return 0 if n == 1 else n if n % 2 != 0 else n // 2 7 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2486_append-characters-to-string-to-make-subsequence_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/append-characters-to-string-to-make-subsequence/ 3 | class Solution: 4 | def appendCharacters(self, s: str, t: str) -> int: 5 | ti = 0 6 | ns, nt = len(s), len(t) 7 | for si in range(ns): 8 | if ti == nt: 9 | break 10 | if s[si] == t[ti]: 11 | ti += 1 12 | 13 | return nt - ti 14 | -------------------------------------------------------------------------------- /algorithms/2001-2500/2490_circular-sentence_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/circular-sentence/ 3 | class Solution: 4 | def isCircularSentence(self, sentence: str) -> bool: 5 | words = sentence.split() 6 | n = len(words) 7 | for i in range(n): 8 | if words[i][-1] != words[(i + 1) % n][0]: 9 | return False 10 | return True 11 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2520_count-the-digits-that-divide-a-number_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/count-the-digits-that-divide-a-number/ 3 | class Solution: 4 | def countDigits(self, num: int) -> int: 5 | res = 0 6 | val = num 7 | while val > 0: 8 | d = val % 10 9 | val //= 10 10 | if num % d == 0: 11 | res += 1 12 | 13 | return res 14 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2527_find-xor-beauty-of-array_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/find-xor-beauty-of-array/ 3 | # this is ridiculous, wild guess 4 | class Solution: 5 | def xorBeauty(self, nums: List[int]) -> int: 6 | res = 0 7 | for x in nums: 8 | res ^= x 9 | return res 10 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2529_maximum-count-of-positive-integer-and-negative-integer_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/maximum-count-of-positive-integer-and-negative-integer/ 3 | from bisect import bisect_left, bisect_right 4 | 5 | class Solution: 6 | def maximumCount(self, nums: List[int]) -> int: 7 | nneg = bisect_left(nums, 0) 8 | npos = len(nums) - bisect_right(nums, 0) 9 | 10 | return max(npos, nneg) 11 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2535_difference-between-element-sum-and-digit-sum-of-an-array_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/difference-between-element-sum-and-digit-sum-of-an-array/ 3 | class Solution: 4 | def differenceOfSum(self, nums: List[int]) -> int: 5 | sm1 = sum(nums) 6 | sm2 = 0 7 | for x in nums: 8 | while x != 0: 9 | sm2 += x % 10 10 | x //= 10 11 | 12 | return abs(sm1 - sm2) 13 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2544_alternating-digit-sum_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/alternating-digit-sum/ 3 | class Solution: 4 | def alternateDigitSum(self, n: int) -> int: 5 | odd = True 6 | sm = 0 7 | while n != 0: 8 | d = n % 10 9 | n //= 10 10 | sm += d if odd else -d 11 | odd = not odd 12 | return -sm if odd else sm 13 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2549_count-distinct-numbers-on-board_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/count-distinct-numbers-on-board/ 3 | class Solution: 4 | def distinctIntegers(self, n: int) -> int: 5 | return 1 if n == 1 else n - 1 6 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2553_separate-the-digits-in-an-array_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/separate-the-digits-in-an-array/ 3 | class Solution: 4 | def separateDigits(self, nums: List[int]) -> List[int]: 5 | digs = [] 6 | res = [] 7 | for x in nums: 8 | while x != 0: 9 | digs.append(x % 10) 10 | x //= 10 11 | while digs: 12 | res.append(digs.pop()) 13 | return res 14 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2568_minimum-impossible-or_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/minimum-impossible-or/ 3 | # must be a teaser, it is indeed 4 | class Solution: 5 | def minImpossibleOR(self, nums: List[int]) -> int: 6 | nums.sort() 7 | res = 0 8 | for x in nums: 9 | if x > res + 1: 10 | break 11 | res |= x 12 | res += 1 13 | 14 | return res 15 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2578_split-with-minimum-sum_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/split-with-minimum-sum/ 3 | class Solution: 4 | def splitNum(self, num: int) -> int: 5 | digs = sorted(str(num)) 6 | d1, d2 = [], [] 7 | for i, d in enumerate(digs): 8 | if i % 2 == 0: 9 | d1.append(d) 10 | else: 11 | d2.append(d) 12 | return int(''.join(d1)) + int(''.join(d2)) 13 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2579_count-total-number-of-colored-cells_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/count-total-number-of-colored-cells/ 3 | # isn't this pure math? 4 | # (1, 1), (2, 5), (3, 13), (4, 25), ... 5 | class Solution: 6 | def coloredCells(self, n: int) -> int: 7 | return 2 * n * n - 2 * n + 1 8 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2582_pass-the-pillow_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/pass-the-pillow/ 3 | class Solution: 4 | def passThePillow(self, n: int, time: int) -> int: 5 | time %= 2 * (n - 1) 6 | return time + 1 if time < n else n - (time - n + 1) 7 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2586_count-the-number-of-vowel-strings-in-range_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/count-the-number-of-vowel-strings-in-range/ 3 | class Solution: 4 | def vowelStrings(self, words: List[str], left: int, right: int) -> int: 5 | vow = set('aeiou') 6 | res = 0 7 | for i in range(left, right + 1): 8 | if words[i][0] in vow and words[i][-1] in vow: 9 | res += 1 10 | return res 11 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2591_distribute-money-to-maximum-children_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/distribute-money-to-maximum-children/ 3 | class Solution: 4 | def distMoney(self, money: int, children: int) -> int: 5 | if money < children: 6 | return -1 7 | if money > 8 * children: 8 | return children - 1 9 | if money == 8 * (children - 1) + 4: 10 | return children - 2 11 | return (money - children) // 7 12 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2600_k-items-with-the-maximum-sum_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/k-items-with-the-maximum-sum/ 3 | class Solution: 4 | def kItemsWithMaximumSum(self, numOnes: int, numZeros: int, numNegOnes: int, k: int) -> int: 5 | if k <= numOnes: 6 | return k 7 | if k <= numOnes + numZeros: 8 | return numOnes 9 | return numOnes - (k - numOnes - numZeros) 10 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2640_find-the-score-of-all-prefixes-of-an-array_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/find-the-score-of-all-prefixes-of-an-array/ 3 | class Solution: 4 | def findPrefixScore(self, nums: List[int]) -> List[int]: 5 | res = [] 6 | cur = 0 7 | mx = 0 8 | for x in nums: 9 | mx = max(mx, x) 10 | cur += x + mx 11 | res.append(cur) 12 | return res 13 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2643_row-with-maximum-ones_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/row-with-maximum-ones/ 3 | class Solution: 4 | def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]: 5 | max_cc, max_i = 0, 0 6 | n= len(mat) 7 | for i in range(n): 8 | cc = sum(mat[i]) 9 | if cc > max_cc: 10 | max_cc, max_i = cc, i 11 | return [max_i, max_cc] 12 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2651_calculate-delayed-arrival-time_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/calculate-delayed-arrival-time/ 3 | class Solution: 4 | def findDelayedArrivalTime(self, arrivalTime: int, delayedTime: int) -> int: 5 | return (arrivalTime + delayedTime) % 24 6 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2656_maximum-sum-with-exactly-k-elements_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/maximum-sum-with-exactly-k-elements/ 3 | class Solution: 4 | def maximizeSum(self, nums: List[int], k: int) -> int: 5 | return max(nums) * k + k * (k - 1) // 2 6 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2678_number-of-senior-citizens_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/number-of-senior-citizens/ 3 | class Solution: 4 | def countSeniors(self, details: List[str]) -> int: 5 | return len([x for x in [int(s[11: 13]) for s in details] if x > 60]) 6 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2683_neighboring-bitwise-xor_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/neighboring-bitwise-xor/ 3 | # flip every element and you get the same xor result 4 | # so, it doesn't matter 5 | class Solution: 6 | def doesValidArrayExist(self, derived: List[int]) -> bool: 7 | n = len(derived) 8 | a = [0 for i in range(n)] 9 | for i in range(n - 1): 10 | a[i + 1] = a[i] ^ derived[i] 11 | return a[0] == a[n - 1] ^ derived[n - 1] 12 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2706_buy-two-chocolates_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/buy-two-chocolates/ 3 | class Solution: 4 | def buyChoco(self, prices: List[int], money: int) -> int: 5 | prices.sort() 6 | min_val = prices[0] + prices[1] 7 | return money - min_val if min_val <= money else money 8 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2710_remove-trailing-zeros-from-a-string_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/remove-trailing-zeros-from-a-string/ 3 | class Solution: 4 | def removeTrailingZeros(self, num: str) -> str: 5 | i = len(num) - 1 6 | while i > 0 and num[i] == '0': 7 | i -= 1 8 | return num[: i + 1] 9 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2716_minimize-string-length_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/minimize-string-length/description/ 3 | class Solution: 4 | def minimizedStringLength(self, s: str) -> int: 5 | return len(set(s)) 6 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2729_check-if-the-number-is-fascinating_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/check-if-the-number-is-fascinating/ 3 | class Solution: 4 | def isFascinating(self, n: int) -> bool: 5 | s = '{}{}{}'.format(n, 2 * n, 3 * n) 6 | st = set(s) 7 | return len(s) == 9 and len(st) == 9 and (not '0' in st) 8 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2733_neither-minimum-nor-maximum_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/neither-minimum-nor-maximum/ 3 | class Solution: 4 | def findNonMinOrMax(self, nums: List[int]) -> int: 5 | min_val = min(nums) 6 | max_val = max(nums) 7 | for x in nums: 8 | if x != min_val and x != max_val: 9 | return x 10 | return -1 11 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2740_find-the-value-of-the-partition_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/find-the-value-of-the-partition/ 3 | # should be "easy" 4 | class Solution: 5 | def findValueOfPartition(self, nums: List[int]) -> int: 6 | nums.sort() 7 | res = nums[-1] - nums[0] 8 | n = len(nums) 9 | 10 | for i in range(n - 1): 11 | res = min(res, nums[i + 1] - nums[i]) 12 | return res 13 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2769_find-the-maximum-achievable-number_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/find-the-maximum-achievable-number/ 3 | class Solution: 4 | def theMaximumAchievableX(self, num: int, t: int) -> int: 5 | return num + 2 * t 6 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2778_sum-of-squares-of-special-elements_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/sum-of-squares-of-special-elements/ 3 | class Solution: 4 | def sumOfSquares(self, nums: List[int]) -> int: 5 | return sum([x * x for i, x in enumerate(nums) if len(nums) % (i + 1) == 0]) 6 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2784_check-if-array-is-good_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/check-if-array-is-good/ 3 | class Solution: 4 | def isGood(self, nums: List[int]) -> bool: 5 | nums.sort() 6 | n = len(nums) - 1 7 | for i in range(n): 8 | if nums[i] != i + 1: 9 | return False 10 | return nums[n] == n 11 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2788_split-strings-by-separator_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/split-strings-by-separator/ 3 | class Solution: 4 | def splitWordsBySeparator(self, words: List[str], separator: str) -> List[str]: 5 | res = [] 6 | for w in words: 7 | res += [s for s in w.split(separator) if len(s) > 0] 8 | return res 9 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2798_number-of-employees-who-met-the-target_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/number-of-employees-who-met-the-target/ 3 | class Solution: 4 | def numberOfEmployeesWhoMetTarget(self, hours: List[int], target: int) -> int: 5 | return sum([h >= target for h in hours]) 6 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2806_account-balance-after-rounded-purchase_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/account-balance-after-rounded-purchase/ 3 | class Solution: 4 | def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int: 5 | pa = purchaseAmount 6 | if pa % 10 >= 5: 7 | pa += 10 8 | pa = pa // 10 * 10 9 | return 100 - pa 10 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2810_faulty-keyboard_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/faulty-keyboard/ 3 | class Solution: 4 | def finalString(self, s: str) -> str: 5 | res = [] 6 | for c in s: 7 | if c == 'i': 8 | res = res[::-1] 9 | else: 10 | res.append(c) 11 | res = ''.join(res) 12 | return res 13 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2828_check-if-a-string-is-an-acronym-of-words_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/check-if-a-string-is-an-acronym-of-words/ 3 | class Solution: 4 | def isAcronym(self, words: List[str], s: str) -> bool: 5 | return s == ''.join([w[0] for w in words]) 6 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2833_furthest-point-from-origin_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/furthest-point-from-origin/ 3 | class Solution: 4 | def furthestDistanceFromOrigin(self, moves: str) -> int: 5 | nl, nr, n_ = 0, 0, 0 6 | for c in moves: 7 | if c == 'L': 8 | nl += 1 9 | elif c == 'R': 10 | nr += 1 11 | else: 12 | n_ += 1 13 | return abs(nl - nr) + n_ 14 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2839_check-if-strings-can-be-made-equal-with-operations-i_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/check-if-strings-can-be-made-equal-with-operations-i/ 3 | class Solution: 4 | def canBeEqual(self, s1: str, s2: str) -> bool: 5 | for i in range(2): 6 | if not ((s1[i] == s2[i] and s1[i + 2] == s2[i + 2]) or \ 7 | (s1[i] == s2[i + 2] and s1[i + 2] == s2[i])): 8 | return False 9 | return True 10 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2840_check-if-strings-can-be-made-equal-with-operations-ii_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/check-if-strings-can-be-made-equal-with-operations-ii/ 3 | class Solution: 4 | def checkStrings(self, s1: str, s2: str) -> bool: 5 | tp1 = (''.join(sorted(s1[::2])), ''.join(sorted(s1[1::2]))) 6 | tp2 = (''.join(sorted(s2[::2])), ''.join(sorted(s2[1::2]))) 7 | return tp1 == tp2 8 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2864_maximum-odd-binary-number_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/maximum-odd-binary-number/ 3 | class Solution: 4 | def maximumOddBinaryNumber(self, s: str) -> str: 5 | n0, n1 = 0, 0 6 | for c in s: 7 | if c == '0': 8 | n0 += 1 9 | else: 10 | n1 += 1 11 | return ''.join(['1' for _ in range(n1 - 1)] + ['0' for _ in range(n0)] + ['1']) 12 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2894_divisible-and-non-divisible-sums-difference_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/divisible-and-non-divisible-sums-difference/ 3 | class Solution: 4 | def differenceOfSums(self, n: int, m: int) -> int: 5 | sm = n * (n + 1) // 2 6 | num2 = (n // m) * (n // m + 1) // 2 * m 7 | num1 = sm - num2 8 | return num1 - num2 9 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2913_subarrays-distinct-element-sum-of-squares-i_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/subarrays-distinct-element-sum-of-squares-i/ 3 | class Solution: 4 | def sumCounts(self, nums: List[int]) -> int: 5 | n = len(nums) 6 | res = 0 7 | for i in range(n): 8 | st = set() 9 | for j in range(i, n): 10 | st.add(nums[j]) 11 | res += len(st) ** 2 12 | return res 13 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2923_find-champion-i_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/find-champion-i/ 3 | class Solution: 4 | def findChampion(self, grid: List[List[int]]) -> int: 5 | n = len(grid) 6 | for j in range(n): 7 | cc = 0 8 | for i in range(n): 9 | cc += grid[i][j] 10 | if cc == 0: 11 | return j 12 | return -1 13 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2938_separate-black-and-white-balls_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/separate-black-and-white-balls/ 3 | # only move 0s and ignore 1s (vice versa) 4 | class Solution: 5 | def minimumSteps(self, s: str) -> int: 6 | # move 0 to the left 7 | res = 0 8 | j = 0 9 | for i, c in enumerate(s): 10 | if c == '0': 11 | res += i - j 12 | j += 1 13 | return res 14 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2942_find-words-containing-character_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/find-words-containing-character/ 3 | class Solution: 4 | def findWordsContaining(self, words: List[str], x: str) -> List[int]: 5 | return [i for i in range(len(words)) if x in words[i]] 6 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2951_find-the-peaks_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/find-the-peaks/ 3 | class Solution: 4 | def findPeaks(self, mountain: List[int]) -> List[int]: 5 | return [i for i in range(1, len(mountain) - 1) \ 6 | if mountain[i] > mountain[i - 1] and mountain[i] > mountain[i + 1]] 7 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2956_find-common-elements-between-two-arrays_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/find-common-elements-between-two-arrays/ 3 | class Solution: 4 | def findIntersectionValues(self, nums1: List[int], nums2: List[int]) -> List[int]: 5 | st1 = set(nums1) 6 | st2 = set(nums2) 7 | return [len([x for x in nums1 if x in st2]), len([x for x in nums2 if x in st1])] 8 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2960_count-tested-devices-after-test-operations_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/count-tested-devices-after-test-operations/ 3 | class Solution: 4 | def countTestedDevices(self, batteryPercentages: List[int]) -> int: 5 | cur = 1 6 | res = 0 7 | for x in batteryPercentages: 8 | if x < cur: 9 | continue 10 | cur += 1 11 | res += 1 12 | return res 13 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2974_minimum-number-game_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/minimum-number-game/ 3 | class Solution: 4 | def numberGame(self, nums: List[int]) -> List[int]: 5 | res = sorted(nums) 6 | n = len(res) 7 | for i in range(0, n, 2): 8 | res[i], res[i + 1] = res[i + 1], res[i] 9 | return res 10 | -------------------------------------------------------------------------------- /algorithms/2501-3000/2980_check-if-bitwise-or-has-trailing-zeros_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/check-if-bitwise-or-has-trailing-zeros/ 3 | class Solution: 4 | def hasTrailingZeros(self, nums: List[int]) -> bool: 5 | return len([x for x in nums if x % 2 == 0]) >= 2 6 | -------------------------------------------------------------------------------- /algorithms/2501-3000/3000_maximum-area-of-longest-diagonal-rectangle_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/maximum-area-of-longest-diagonal-rectangle/ 3 | class Solution: 4 | def areaOfMaxDiagonal(self, dimensions: List[List[int]]) -> int: 5 | res = (-1, -1) 6 | for w, h in dimensions: 7 | d2, a = w * w + h * h, w * h 8 | if (d2, a) > res: 9 | res = (d2, a) 10 | return res[1] 11 | -------------------------------------------------------------------------------- /algorithms/3001-3500/3010_divide-an-array-into-subarrays-with-minimum-cost-i_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/divide-an-array-into-subarrays-with-minimum-cost-i/ 3 | class Solution: 4 | def minimumCost(self, nums: List[int]) -> int: 5 | return nums[0] + sum(sorted(nums[1:])[:2]) 6 | -------------------------------------------------------------------------------- /algorithms/3001-3500/3014_minimum-number-of-pushes-to-type-word-i_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/minimum-number-of-pushes-to-type-word-i/ 3 | class Solution: 4 | def minimumPushes(self, word: str) -> int: 5 | res = 0 6 | push = 1 7 | n = len(word) 8 | while n > 0: 9 | res += min(n, 8) * push 10 | n -= min(n, 8) 11 | push += 1 12 | return res 13 | -------------------------------------------------------------------------------- /algorithms/3001-3500/3019_number-of-changing-keys_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/number-of-changing-keys/ 3 | class Solution: 4 | def countKeyChanges(self, s: str) -> int: 5 | s = s.lower() 6 | n = len(s) 7 | res = 0 8 | for i in range(1, n): 9 | if s[i] != s[i - 1]: 10 | res += 1 11 | return res 12 | -------------------------------------------------------------------------------- /algorithms/3001-3500/3024_type-of-triangle_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/type-of-triangle/ 3 | class Solution: 4 | def triangleType(self, nums: List[int]) -> str: 5 | a, b, c = sorted(nums) 6 | if a == b and b == c: 7 | return 'equilateral' 8 | if a + b <= c: 9 | return 'none' 10 | if a == b or b == c: 11 | return 'isosceles' 12 | return 'scalene' 13 | -------------------------------------------------------------------------------- /algorithms/3001-3500/3028_ant-on-the-boundary_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/ant-on-the-boundary/ 3 | # poor description 4 | class Solution: 5 | def returnToBoundaryCount(self, nums: List[int]) -> int: 6 | pos = 0 7 | res = 0 8 | for x in nums: 9 | pos += x 10 | if pos == 0: 11 | res += 1 12 | return res 13 | -------------------------------------------------------------------------------- /algorithms/3001-3500/3046_split-the-array_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/split-the-array/ 3 | class Solution: 4 | def isPossibleToSplit(self, nums: List[int]) -> bool: 5 | mm = {} 6 | for x in nums: 7 | if not x in mm: 8 | mm[x] = 1 9 | else: 10 | mm[x] += 1 11 | return max(mm.values()) <= 2 12 | -------------------------------------------------------------------------------- /algorithms/3001-3500/3074_apple-redistribution-into-boxes_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/apple-redistribution-into-boxes/ 3 | class Solution: 4 | def minimumBoxes(self, apple: List[int], capacity: List[int]) -> int: 5 | capacity.sort(reverse=True) 6 | sm = sum(apple) 7 | 8 | res = 0 9 | for c in capacity: 10 | sm -= c 11 | res += 1 12 | if sm <= 0: 13 | break 14 | return res 15 | -------------------------------------------------------------------------------- /algorithms/3001-3500/3075_maximize-happiness-of-selected-children_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/maximize-happiness-of-selected-children/ 3 | # why is this medium? 4 | class Solution: 5 | def maximumHappinessSum(self, happiness: List[int], k: int) -> int: 6 | happiness.sort(reverse=True) 7 | res = 0 8 | for i in range(k): 9 | res += max(happiness[i] - i, 0) 10 | return res 11 | -------------------------------------------------------------------------------- /algorithms/3001-3500/3083_existence-of-a-substring-in-a-string-and-its-reverse_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/existence-of-a-substring-in-a-string-and-its-reverse/ 3 | class Solution: 4 | def isSubstringPresent(self, s: str) -> bool: 5 | n = len(s) 6 | rs = s[::-1] 7 | for i in range(n - 1): 8 | if s[i: i + 2] in rs: 9 | return True 10 | return False 11 | -------------------------------------------------------------------------------- /algorithms/3001-3500/3099_harshad-number_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/harshad-number/ 3 | class Solution: 4 | def sumOfTheDigitsOfHarshadNumber(self, x: int) -> int: 5 | sm = self.sumDigit(x) 6 | return sm if x % sm == 0 else -1 7 | 8 | def sumDigit(self, x): 9 | sm = 0 10 | while x != 0: 11 | sm += x % 10 12 | x //= 10 13 | return sm 14 | -------------------------------------------------------------------------------- /algorithms/3001-3500/3110_score-of-a-string_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/score-of-a-string/ 3 | class Solution: 4 | def scoreOfString(self, s: str) -> int: 5 | n = len(s) 6 | res = 0 7 | for i in range(1, n): 8 | res += abs(ord(s[i]) - ord(s[i - 1])) 9 | return res 10 | -------------------------------------------------------------------------------- /algorithms/3001-3500/3120_count-the-number-of-special-characters-i_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/count-the-number-of-special-characters-i/ 3 | class Solution: 4 | def numberOfSpecialChars(self, word: str) -> int: 5 | st = set(word) 6 | res = 0 7 | for c in st: 8 | if c.islower() and c.upper() in st: 9 | res += 1 10 | return res 11 | -------------------------------------------------------------------------------- /algorithms/3001-3500/3131_find-the-integer-added-to-array-i_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/find-the-integer-added-to-array-i/ 3 | class Solution: 4 | def addedInteger(self, nums1: List[int], nums2: List[int]) -> int: 5 | return min(nums2) - min(nums1) 6 | -------------------------------------------------------------------------------- /algorithms/3001-3500/3151_special-array-i_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/special-array-i/ 3 | class Solution: 4 | def isArraySpecial(self, nums: List[int]) -> bool: 5 | n = len(nums) 6 | for i in range(1, n): 7 | if (nums[i] - nums[i - 1]) % 2 == 0: 8 | return False 9 | return True 10 | -------------------------------------------------------------------------------- /algorithms/3001-3500/3158_find-the-xor-of-numbers-which-appear-twice_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/find-the-xor-of-numbers-which-appear-twice/ 3 | class Solution: 4 | def duplicateNumbersXOR(self, nums: List[int]) -> int: 5 | st = set() 6 | res = 0 7 | for x in nums: 8 | if x in st: 9 | res ^= x 10 | st.add(x) 11 | return res 12 | -------------------------------------------------------------------------------- /algorithms/3001-3500/3159_find-occurrences-of-an-element-in-an-array_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/find-occurrences-of-an-element-in-an-array/ 3 | # should be "easy" 4 | class Solution: 5 | def occurrencesOfElement(self, nums: List[int], queries: List[int], x: int) -> List[int]: 6 | n = len(nums) 7 | idx = [i for i in range(n) if nums[i] == x] 8 | 9 | res = [idx[q - 1] if q <= len(idx) else -1 for q in queries] 10 | return res 11 | -------------------------------------------------------------------------------- /algorithms/3001-3500/3162_find-the-number-of-good-pairs-i_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/find-the-number-of-good-pairs-i/ 3 | class Solution: 4 | def numberOfPairs(self, nums1: List[int], nums2: List[int], k: int) -> int: 5 | n1, n2 = len(nums1), len(nums2) 6 | res = 0 7 | for i in range(n1): 8 | for j in range(n2): 9 | if nums1[i] % (k * nums2[j]) == 0: 10 | res += 1 11 | return res 12 | -------------------------------------------------------------------------------- /algorithms/3001-3500/3168_minimum-number-of-chairs-in-a-waiting-room_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/minimum-number-of-chairs-in-a-waiting-room/ 3 | class Solution: 4 | def minimumChairs(self, s: str) -> int: 5 | cc = 0 6 | max_cc = 0 7 | for c in s: 8 | if c == 'E': 9 | cc += 1 10 | max_cc = max(max_cc, cc) 11 | else: 12 | cc -= 1 13 | return max_cc 14 | -------------------------------------------------------------------------------- /algorithms/3001-3500/3174_clear-digits_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/clear-digits/ 3 | class Solution: 4 | def clearDigits(self, s: str) -> str: 5 | st = [] 6 | for c in s: 7 | if c.isalpha(): 8 | st.append(c) 9 | elif c.isdigit(): 10 | if len(st) > 0: 11 | st.pop() 12 | return ''.join(st) 13 | -------------------------------------------------------------------------------- /algorithms/3001-3500/3178_find-the-child-who-has-the-ball-after-k-seconds_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/find-the-child-who-has-the-ball-after-k-seconds/ 3 | class Solution: 4 | def numberOfChild(self, n: int, k: int) -> int: 5 | k %= 2 * (n - 1) 6 | if k <= n - 1: 7 | return k 8 | else: 9 | return 2 * (n - 1) - k 10 | -------------------------------------------------------------------------------- /algorithms/3001-3500/3179_find-the-n-th-value-after-k-seconds_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/find-the-n-th-value-after-k-seconds/ 3 | # exactly 4 | class Solution: 5 | def valueAfterKSeconds(self, n: int, k: int) -> int: 6 | MOD = int(1e9 + 7) 7 | 8 | a = [1 for i in range(n)] 9 | for _ in range(k): 10 | for i in range(1, n): 11 | a[i] = (a[i] + a[i - 1]) % MOD 12 | return a[n - 1] 13 | -------------------------------------------------------------------------------- /algorithms/3001-3500/3190_find-minimum-operations-to-make-all-elements-divisible-by-three_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/find-minimum-operations-to-make-all-elements-divisible-by-three/ 3 | class Solution: 4 | def minimumOperations(self, nums: List[int]) -> int: 5 | return len([x for x in nums if x % 3 != 0]) 6 | -------------------------------------------------------------------------------- /algorithms/3001-3500/3200_maximum-height-of-a-triangle_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/maximum-height-of-a-triangle/ 3 | class Solution: 4 | def maxHeightOfTriangle(self, red: int, blue: int) -> int: 5 | return max(self.simulate([red, blue]), self.simulate([blue, red])) 6 | 7 | def simulate(self, a): 8 | f = 0 9 | n = 1 10 | while a[f] >= n: 11 | a[f] -= n 12 | f = 1 - f 13 | n += 1 14 | return n - 1 15 | -------------------------------------------------------------------------------- /algorithms/3001-3500/3206_alternating-groups-i_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/alternating-groups-i/ 3 | class Solution: 4 | def numberOfAlternatingGroups(self, colors: List[int]) -> int: 5 | n = len(colors) 6 | return len([i for i in range(n) if \ 7 | colors[i] != colors[(i + n - 1) % n] and colors[i] != colors[(i + 1) % n]]) 8 | -------------------------------------------------------------------------------- /algorithms/3001-3500/3222_find-the-winning-player-in-coin-game_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/find-the-winning-player-in-coin-game/ 3 | class Solution: 4 | def winningPlayer(self, x: int, y: int) -> str: 5 | round = min(x, y // 4) 6 | return 'Alice' if round % 2 == 1 else 'Bob' 7 | -------------------------------------------------------------------------------- /algorithms/3001-3500/3226_number-of-bit-changes-to-make-two-integers-equal_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/number-of-bit-changes-to-make-two-integers-equal/ 3 | class Solution: 4 | def minChanges(self, n: int, k: int) -> int: 5 | if (n & k) != k: 6 | return -1 7 | 8 | n ^= k 9 | res = 0 10 | while n != 0: 11 | n &= n - 1 12 | res += 1 13 | return res 14 | -------------------------------------------------------------------------------- /algorithms/3001-3500/3227_vowels-game-in-a-string_1_AC.py: -------------------------------------------------------------------------------- 1 | # medium 2 | # https://leetcode.com/problems/vowels-game-in-a-string/ 3 | # this is BS 4 | class Solution: 5 | def doesAliceWin(self, s: str) -> bool: 6 | vw = set('aeiou') 7 | cc = len([c for c in s if c in vw]) 8 | return cc > 0 9 | -------------------------------------------------------------------------------- /algorithms/3001-3500/3232_find-if-digit-game-can-be-won_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/find-if-digit-game-can-be-won/ 3 | class Solution: 4 | def canAliceWin(self, nums: List[int]) -> bool: 5 | sm1 = sum([x for x in nums if x >= 1 and x <= 9]) 6 | sm2 = sum(nums) - sm1 7 | return sm1 != sm2 8 | -------------------------------------------------------------------------------- /algorithms/3001-3500/3274_check-if-two-chessboard-squares-have-the-same-color_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/check-if-two-chessboard-squares-have-the-same-color/ 3 | class Solution: 4 | def checkTwoChessboards(self, coordinate1: str, coordinate2: str) -> bool: 5 | c1, c2 = coordinate1, coordinate2 6 | return ((ord(c1[0]) - ord(c2[0])) + (ord(c1[1]) - ord(c2[1]))) % 2 == 0 7 | -------------------------------------------------------------------------------- /algorithms/3001-3500/3285_find-indices-of-stable-mountains_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/find-indices-of-stable-mountains/ 3 | class Solution: 4 | def stableMountains(self, height: List[int], threshold: int) -> List[int]: 5 | n = len(height) 6 | return [i for i in range(1, n) if height[i - 1] > threshold] 7 | -------------------------------------------------------------------------------- /algorithms/3001-3500/3289_the-two-sneaky-numbers-of-digitville_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/the-two-sneaky-numbers-of-digitville/ 3 | class Solution: 4 | def getSneakyNumbers(self, nums: List[int]) -> List[int]: 5 | st = set() 6 | res = [] 7 | for x in nums: 8 | if x in st: 9 | res.append(x) 10 | st.add(x) 11 | return res 12 | -------------------------------------------------------------------------------- /algorithms/3001-3500/3300_minimum-element-after-replacement-with-digit-sum_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/minimum-element-after-replacement-with-digit-sum/ 3 | class Solution: 4 | def minElement(self, nums: List[int]) -> int: 5 | return min([self.sumDigits(x) for x in nums]) 6 | 7 | def sumDigits(self, x): 8 | res = 0 9 | while x != 0: 10 | res += x % 10 11 | x //= 10 12 | return res 13 | -------------------------------------------------------------------------------- /algorithms/3001-3500/3304_find-the-k-th-character-in-string-game-i_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/find-the-k-th-character-in-string-game-i/ 3 | class Solution: 4 | def kthCharacter(self, k: int) -> str: 5 | s = 'a' 6 | while len(s) < k: 7 | s1 = [] 8 | for c in s: 9 | s1.append(chr((ord(c) - ord('a') + 1) % 26 + ord('a'))) 10 | s1 = ''.join(s1) 11 | s += s1 12 | return s[k - 1] 13 | -------------------------------------------------------------------------------- /algorithms/3001-3500/3314_construct-the-minimum-bitwise-array-i_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/construct-the-minimum-bitwise-array-i/ 3 | # really tricky 4 | class Solution: 5 | def minBitwiseArray(self, nums: List[int]) -> List[int]: 6 | res = [] 7 | for x in nums: 8 | if (x & 1) == 0: 9 | res.append(-1) 10 | continue 11 | res.append((x & x + 1) | (((x ^ x + 1) + 1) >> 2) - 1) 12 | return res 13 | -------------------------------------------------------------------------------- /algorithms/3001-3500/3330_find-the-original-typed-string-i_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/find-the-original-typed-string-i/ 3 | class Solution: 4 | def possibleStringCount(self, word: str) -> int: 5 | n = len(word) 6 | res = 1 7 | i = 0 8 | while i < n: 9 | j = i + 1 10 | while j < n and word[i] == word[j]: 11 | j += 1 12 | res += j - i - 1 13 | i = j 14 | 15 | return res 16 | -------------------------------------------------------------------------------- /algorithms/3001-3500/3340_check-balanced-string_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/check-balanced-string/ 3 | class Solution: 4 | def isBalanced(self, num: str) -> bool: 5 | sm0, sm1 = 0, 0 6 | for i, c in enumerate(num): 7 | if i % 2 == 0: 8 | sm0 += int(c) 9 | else: 10 | sm1 += int(c) 11 | return sm0 == sm1 12 | -------------------------------------------------------------------------------- /algorithms/3001-3500/3360_stone-removal-game_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/stone-removal-game/ 3 | class Solution: 4 | def canAliceWin(self, n: int) -> bool: 5 | k = 10 6 | cc = 0 7 | while n >= k: 8 | n -= k 9 | k -= 1 10 | cc += 1 11 | return cc % 2 == 1 12 | -------------------------------------------------------------------------------- /algorithms/3001-3500/3370_smallest-number-with-all-set-bits_1_AC.py: -------------------------------------------------------------------------------- 1 | # easy 2 | # https://leetcode.com/problems/smallest-number-with-all-set-bits/ 3 | class Solution: 4 | def smallestNumber(self, n: int) -> int: 5 | while (n & n + 1) != 0: 6 | n |= n + 1 7 | return n 8 | -------------------------------------------------------------------------------- /database/0175_combine-two-tables_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/combine-two-tables/ 2 | -- 1AC 3 | SELECT p.firstname, 4 | p.lastname, 5 | a.city, 6 | a.state 7 | FROM person p 8 | LEFT JOIN address a 9 | ON p.personid = a.personid; 10 | -------------------------------------------------------------------------------- /database/0176_second-highest-salary_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/second-highest-salary/ 2 | -- if else 3 | SELECT IF((SELECT Count(DISTINCT salary) 4 | FROM employee) >= 2, (SELECT salary 5 | FROM employee 6 | ORDER BY salary DESC 7 | LIMIT 1, 1), NULL) SecondHighestSalary; 8 | -------------------------------------------------------------------------------- /database/0177_nth-highest-salary_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/nth-highest-salary/ 2 | -- stored procedure, from the old tales 3 | CREATE function getnthhighestsalary(n INT) 4 | returns INT 5 | begin 6 | DECLARE m INT; 7 | 8 | SET m = n - 1; 9 | 10 | RETURN ( SELECT CASE WHEN Count(DISTINCT salary) > m THEN (SELECT DISTINCT( 11 | salary) 12 | FROM employee ORDER BY salary DESC LIMIT m, 1) ELSE NULL end FROM 13 | employee ); 14 | end 15 | -------------------------------------------------------------------------------- /database/0178_rank-scores_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/rank-scores/ 2 | -- 1AC, dense_rank exactly 3 | select 4 | score, 5 | dense_rank() over ( 6 | order by 7 | score desc) rank 8 | from 9 | scores; 10 | -------------------------------------------------------------------------------- /database/0181_employees-earning-more-than-their-managers_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/employees-earning-more-than-their-managers/ 2 | -- 1AC 3 | SELECT e1.name Employee 4 | FROM employee e1 5 | INNER JOIN employee e2 6 | ON e1.managerid = e2.id 7 | WHERE e1.salary > e2.salary; 8 | -------------------------------------------------------------------------------- /database/0182_duplicate-emails_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/duplicate-emails/ 2 | -- 1AC 3 | SELECT email 4 | FROM person 5 | GROUP BY email 6 | HAVING Count(email) > 1; 7 | -------------------------------------------------------------------------------- /database/0183_customers-who-never-order_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/customers-who-never-order/ 2 | -- 1AC 3 | SELECT c.name Customers 4 | FROM customers c 5 | LEFT JOIN orders o 6 | ON c.id = o.customerid 7 | WHERE o.customerid IS NULL; 8 | -------------------------------------------------------------------------------- /database/0196_delete-duplicate-emails_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/delete-duplicate-emails/ 2 | -- 1AC, table must be copied so as to query and delete at the same time 3 | DELETE FROM person 4 | WHERE id NOT IN (SELECT Min(p.id) 5 | FROM (SELECT * 6 | FROM person) p 7 | GROUP BY p.email); 8 | -------------------------------------------------------------------------------- /database/0197_rising-temperature_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/rising-temperature/ 2 | -- date add 3 | SELECT w1.id 4 | FROM weather w1 5 | INNER JOIN weather w2 6 | ON Date_add(w1.recorddate, INTERVAL -1 day) = w2.recorddate 7 | WHERE w1.temperature > w2.temperature; 8 | -------------------------------------------------------------------------------- /database/0511_game-play-analysis-i_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/game-play-analysis-i/ 2 | -- 1AC 3 | SELECT `player_id`, 4 | Min(`event_date`) "first_login" 5 | FROM `activity` 6 | GROUP BY `player_id`; -------------------------------------------------------------------------------- /database/0512_game-play-analysis-ii_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/game-play-analysis-ii/ 2 | -- not very clean 3 | SELECT DISTINCT a.player_id, 4 | a.device_id 5 | FROM activity a 6 | INNER JOIN (SELECT player_id, 7 | Min(event_date) event_date 8 | FROM activity 9 | GROUP BY player_id) amd 10 | ON a.player_id = amd.player_id 11 | WHERE a.event_date = amd.event_date; 12 | -------------------------------------------------------------------------------- /database/0570_managers-with-at-least-5-direct-reports_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/managers-with-at-least-5-direct-reports/ 2 | -- 1AC 3 | SELECT e.name 4 | FROM employee e 5 | INNER JOIN (SELECT managerid 6 | FROM employee 7 | WHERE managerid IS NOT NULL 8 | GROUP BY managerid 9 | HAVING Count(id) >= 5) m 10 | ON e.id = m.managerid; 11 | -------------------------------------------------------------------------------- /database/0574_winning-candidate_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/winning-candidate/ 2 | -- 1AC 3 | select 4 | c.Name 5 | from 6 | Candidate c 7 | inner join 8 | ( 9 | select 10 | CandidateId, 11 | count(CandidateId) cc 12 | from 13 | Vote 14 | group by 15 | CandidateId 16 | ) 17 | vc 18 | on c.id = vc.CandidateId 19 | order by 20 | vc.cc desc limit 1; 21 | -------------------------------------------------------------------------------- /database/0577_employee-bonus_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/employee-bonus/ 2 | -- 1AC 3 | SELECT e.name, 4 | b.bonus 5 | FROM employee e 6 | LEFT JOIN bonus b 7 | ON e.empid = b.empid 8 | WHERE b.bonus IS NULL 9 | OR b.bonus < 1000; 10 | -------------------------------------------------------------------------------- /database/0578_get-highest-answer-rate-question_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/get-highest-answer-rate-question/ 2 | -- 1AC, quite the number of downvotes 3 | select 4 | question_id survey_log 5 | from 6 | survey_log 7 | group by 8 | question_id 9 | order by 10 | sum(action = 'answer') / sum(action = 'show') desc limit 1; 11 | -------------------------------------------------------------------------------- /database/0584_find-customer-referee_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/find-customer-referee/ 2 | -- 1AC 3 | SELECT name 4 | FROM customer 5 | WHERE referee_id != 2 6 | OR referee_id IS NULL; 7 | -------------------------------------------------------------------------------- /database/0595_big-countries_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/big-countries/ 2 | SELECT `name`, 3 | `population`, 4 | `area` 5 | FROM `world` 6 | WHERE `population` > 25000000 7 | OR `area` > 3000000; -------------------------------------------------------------------------------- /database/0596_classes-more-than-5-students_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/classes-more-than-5-students/ 2 | SELECT class 3 | FROM courses 4 | GROUP BY class 5 | HAVING Count(DISTINCT student) >= 5; 6 | -------------------------------------------------------------------------------- /database/0597_friend-requests-i-overall-acceptance-rate_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/friend-requests-i-overall-acceptance-rate/ 2 | -- 1AC, count / count 3 | SELECT Round(Ifnull((SELECT Count(DISTINCT requester_id, accepter_id) 4 | FROM request_accepted) / (SELECT 5 | Count(DISTINCT sender_id, send_to_id) 6 | FROM friend_request), 0), 2) 7 | accept_rate; 8 | -------------------------------------------------------------------------------- /database/0602_friend-requests-ii-who-has-the-most-friends_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/friend-requests-ii-who-has-the-most-friends/ 2 | -- 1AC, straightforward 3 | select 4 | f.id, 5 | count(f.id) num 6 | from 7 | ( 8 | select 9 | requester_id id 10 | from 11 | request_accepted 12 | union all 13 | select 14 | accepter_id id 15 | from 16 | request_accepted 17 | ) 18 | f 19 | group by 20 | f.id 21 | order by 22 | num desc limit 1; 23 | -------------------------------------------------------------------------------- /database/0610_triangle-judgement_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/triangle-judgement/ 2 | -- 1AC, a + b > c 3 | SELECT *, 4 | CASE 5 | WHEN Least(x, y, z) + ( x + y + z - Least(x, y, z) - Greatest(x, y, z) 6 | ) > 7 | Greatest(x, y, z) THEN 'Yes' 8 | ELSE 'No' 9 | end triangle 10 | FROM triangle; 11 | -------------------------------------------------------------------------------- /database/0612_shortest-distance-in-a-plane_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/shortest-distance-in-a-plane/ 2 | -- 1AC, math ops 3 | SELECT Round(Min(Sqrt(Pow(p1.x - p2.x, 2) + Pow(p1.y - p2.y, 2))), 2) shortest 4 | FROM point_2d p1 5 | INNER JOIN point_2d p2 6 | ON p1.x != p2.x 7 | OR p1.y != p2.y; 8 | -------------------------------------------------------------------------------- /database/0613_shortest-distance-in-a-line_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/shortest-distance-in-a-line/ 2 | -- 1AC, SQL Server lag function 3 | SELECT x - Lag(x, 1) over (ORDER BY x) shortest 4 | FROM point 5 | ORDER BY shortest 6 | offset 1 rows 7 | FETCH next 1 rows only; -------------------------------------------------------------------------------- /database/0614_second-degree-follower_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/second-degree-follower/ 2 | -- too sloppy 3 | select distinct 4 | followee follower, 5 | count(distinct follower) num 6 | from 7 | follow 8 | where 9 | followee in 10 | ( 11 | select 12 | follower 13 | from 14 | follow 15 | ) 16 | group by 17 | followee 18 | order by 19 | followee; 20 | -------------------------------------------------------------------------------- /database/0619_biggest-single-number_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/biggest-single-number/ 2 | -- 1AC 3 | SELECT Max(un.num) num 4 | FROM (SELECT num 5 | FROM my_numbers 6 | GROUP BY num 7 | HAVING Count(num) = 1) un; 8 | -------------------------------------------------------------------------------- /database/0620_not-boring-movies_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/not-boring-movies/ 2 | -- 1AC 3 | SELECT * 4 | FROM cinema 5 | WHERE id % 2 = 1 6 | AND description != 'boring' 7 | ORDER BY rating DESC; 8 | -------------------------------------------------------------------------------- /database/0627_swap-salary_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/swap-salary/ 2 | -- 1AC, case statement 3 | UPDATE salary 4 | SET sex = CASE sex 5 | WHEN 'm' THEN 'f' 6 | WHEN 'f' THEN 'm' 7 | end; 8 | -------------------------------------------------------------------------------- /database/1045_customers-who-bought-all-products_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/customers-who-bought-all-products/ 2 | -- 1AC 3 | SELECT customer_id 4 | FROM customer 5 | GROUP BY customer_id 6 | HAVING Count(DISTINCT product_key) = (SELECT Count(DISTINCT product_key) 7 | FROM product); 8 | -------------------------------------------------------------------------------- /database/1050_actors-and-directors-who-cooperated-at-least-three-times_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/actors-and-directors-who-cooperated-at-least-three-times/ 2 | -- 1AC 3 | SELECT actor_id, 4 | director_id 5 | FROM actordirector 6 | GROUP BY actor_id, 7 | director_id 8 | HAVING Count(timestamp) >= 3; 9 | -------------------------------------------------------------------------------- /database/1068_product-sales-analysis-i_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/product-sales-analysis-i/ 2 | -- 1AC 3 | SELECT p.`product_name`, 4 | s.`year`, 5 | s.`price` 6 | FROM `sales` s 7 | LEFT JOIN `product` p 8 | ON s.`product_id` = p.`product_id`; -------------------------------------------------------------------------------- /database/1069_product-sales-analysis-ii_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/product-sales-analysis-ii/ 2 | -- 1AC 3 | SELECT `product_id`, 4 | Sum(`quantity`) "total_quantity" 5 | FROM `sales` 6 | GROUP BY `product_id`; -------------------------------------------------------------------------------- /database/1075_project-employees-i_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/project-employees-i/ 2 | -- 1AC 3 | SELECT pe.project_id, 4 | Round(Avg(experience_years), 2) average_years 5 | FROM (SELECT p.project_id, 6 | p.employee_id, 7 | e.experience_years 8 | FROM project p 9 | LEFT JOIN employee e 10 | ON p.employee_id = e.employee_id) pe 11 | GROUP BY pe.project_id; 12 | -------------------------------------------------------------------------------- /database/1076_project-employees-ii_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/project-employees-ii/ 2 | -- 1AC, max count 3 | SELECT project_id 4 | FROM project 5 | GROUP BY project_id 6 | HAVING Count(employee_id) = (SELECT Count(employee_id) ec 7 | FROM project 8 | GROUP BY project_id 9 | ORDER BY ec DESC 10 | LIMIT 1); 11 | -------------------------------------------------------------------------------- /database/1082_sales-analysis-i_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/sales-analysis-i/ 2 | -- 1AC, user variable is disabled 3 | SELECT seller_id 4 | FROM sales 5 | GROUP BY seller_id 6 | HAVING Sum(price) = (SELECT Sum(price) sp 7 | FROM sales 8 | GROUP BY seller_id 9 | ORDER BY sp DESC 10 | LIMIT 1); 11 | -------------------------------------------------------------------------------- /database/1113_reported-posts_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/reported-posts/ 2 | -- 1AC 3 | SELECT extra report_reason, 4 | Count(DISTINCT( post_id )) report_count 5 | FROM actions 6 | WHERE action_date = {d'2019-07-04'} 7 | AND action = 'report' 8 | GROUP BY extra; 9 | -------------------------------------------------------------------------------- /database/1141_user-activity-for-the-past-30-days-i_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/user-activity-for-the-past-30-days-i/ 2 | -- 1AC 3 | SELECT activity_date day, 4 | Count(DISTINCT( user_id )) active_users 5 | FROM activity 6 | WHERE Datediff({d'2019-07-27'}, activity_date) BETWEEN 0 AND 29 7 | GROUP BY activity_date; 8 | -------------------------------------------------------------------------------- /database/1142_user-activity-for-the-past-30-days-ii_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/user-activity-for-the-past-30-days-ii/ 2 | -- not very clean 3 | SELECT Round(Ifnull(Avg(usc.sc), 0), 2) average_sessions_per_user 4 | FROM (SELECT Count(DISTINCT session_id) sc 5 | FROM activity 6 | WHERE Datediff({d'2019-07-27'}, activity_date) BETWEEN 0 AND 29 7 | GROUP BY user_id) usc; 8 | -------------------------------------------------------------------------------- /database/1148_article-views-i_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/article-views-i/ 2 | -- 1AC 3 | -- Runtime: 244 ms, faster than 99.88% of MySQL online submissions for Article Views I. 4 | -- Memory Usage: 0B, less than 100.00% of MySQL online submissions for Article Views I. 5 | SELECT author_id id 6 | FROM views 7 | WHERE author_id = viewer_id 8 | GROUP BY author_id 9 | HAVING Count(viewer_id) > 0; 10 | -------------------------------------------------------------------------------- /database/1149_article-views-ii_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/article-views-ii/ 2 | -- 1AC 3 | select distinct 4 | viewer_id id 5 | from 6 | Views 7 | group by 8 | viewer_id, 9 | view_date 10 | having 11 | count(distinct article_id) > 1; 12 | -------------------------------------------------------------------------------- /database/1173_immediate-food-delivery-i_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/immediate-food-delivery-i/ 2 | -- 1AC, count with primary key 3 | SELECT Round(Count(`delivery_id`) / (SELECT Count(`delivery_id`) 4 | FROM `delivery`) * 100.0, 2) 5 | "immediate_percentage" 6 | FROM `delivery` 7 | WHERE `order_date` = `customer_pref_delivery_date`; -------------------------------------------------------------------------------- /database/1303_find-the-team-size_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/find-the-team-size/ 2 | -- 1AC 3 | SELECT e.`employee_id`, 4 | ts.`team_size` 5 | FROM `employee` e 6 | INNER JOIN (SELECT `team_id`, 7 | Count(`employee_id`) "team_size" 8 | FROM `employee` 9 | GROUP BY `team_id`) ts 10 | ON e.`team_id` = ts.`team_id`; -------------------------------------------------------------------------------- /database/1322_ads-performance_2_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/ads-performance/ 2 | -- using avg() for percentage is better 3 | SELECT ad_id, 4 | Round(Ifnull(Avg(100 * ( action = 'Clicked' ) / ( action != 'Ignored' )), 5 | 0), 2) 6 | ctr 7 | FROM ads 8 | GROUP BY ad_id 9 | ORDER BY ctr DESC, 10 | ad_id; 11 | -------------------------------------------------------------------------------- /database/1350_students-with-invalid-departments_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/students-with-invalid-departments/ 2 | -- 1AC 3 | SELECT dt.`id`, 4 | dt.`name` 5 | FROM (SELECT d.`id` AS did, 6 | s.`id`, 7 | s.`name` 8 | FROM `students` s 9 | LEFT JOIN `departments` d 10 | ON s.`department_id` = d.`id` 11 | WHERE d.`id` IS NULL) dt; -------------------------------------------------------------------------------- /database/1378_replace-employee-id-with-the-unique-identifier_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/replace-employee-id-with-the-unique-identifier/ 2 | -- 1AC, first SQL question 3 | SELECT e.`unique_id`, 4 | e.`name` 5 | FROM `employees` e 6 | LEFT JOIN `employeeuni` eu 7 | ON e.`id` == eu.`id`; -------------------------------------------------------------------------------- /explore/30-day-leetcoding-challenge/3283_single-number_1_AC.py: -------------------------------------------------------------------------------- 1 | # https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/528/week-1/3283/ 2 | # 1AC 3 | class Solution: 4 | def singleNumber(self, nums: List[int]) -> int: 5 | res = 0 6 | for x in nums: 7 | res ^= x 8 | return res 9 | -------------------------------------------------------------------------------- /explore/30-day-leetcoding-challenge/3285_maximum-subarray_1_AC.py: -------------------------------------------------------------------------------- 1 | # https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/528/week-1/3285/ 2 | # 1AC 3 | class Solution: 4 | def maxSubArray(self, nums: List[int]) -> int: 5 | res = max(nums) 6 | if res <= 0: 7 | return res 8 | res = sm = 0 9 | for x in nums: 10 | sm += x 11 | res = max(res, sm) 12 | sm = max(sm, 0) 13 | return res 14 | -------------------------------------------------------------------------------- /explore/30-day-leetcoding-challenge/3287_best-time-to-buy-and-sell-stock-ii_1_AC.py: -------------------------------------------------------------------------------- 1 | # https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/528/week-1/3287/ 2 | # 1AC 3 | class Solution: 4 | def maxProfit(self, prices: List[int]) -> int: 5 | p = prices 6 | n = len(p) 7 | res = 0 8 | for i in range(n - 1): 9 | res += max(0, p[i + 1] - p[i]) 10 | return res 11 | -------------------------------------------------------------------------------- /explore/30-day-leetcoding-challenge/3288_group-anagrams_1_AC.py: -------------------------------------------------------------------------------- 1 | # https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/528/week-1/3288/ 2 | # 1AC 3 | from collections import defaultdict 4 | 5 | class Solution: 6 | def groupAnagrams(self, strs: List[str]) -> List[List[str]]: 7 | mm = defaultdict(list) 8 | for s in strs: 9 | mm[''.join(sorted(s))].append(s) 10 | return list(mm.values()) 11 | -------------------------------------------------------------------------------- /explore/30-day-leetcoding-challenge/3299_perform-string-shifts_1_AC.py: -------------------------------------------------------------------------------- 1 | # https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/529/week-2/3299/ 2 | # 1AC 3 | class Solution: 4 | def stringShift(self, s: str, shift: List[List[int]]) -> str: 5 | ls = len(s) 6 | k = 0 7 | for dr, am in shift: 8 | k += (2 * dr - 1) * am 9 | k %= ls 10 | k = (ls - k) % ls 11 | return s[k:] + s[:k] 12 | -------------------------------------------------------------------------------- /explore/30-day-leetcoding-challenge/3308_bitwise-and-of-numbers-range_1_AC.py: -------------------------------------------------------------------------------- 1 | # https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/531/week-4/3308/ 2 | class Solution: 3 | def rangeBitwiseAnd(self, m: int, n: int) -> int: 4 | while n > m: 5 | n &= n - 1 6 | return n 7 | -------------------------------------------------------------------------------- /explore/30-day-leetcoding-challenge/3310_jump-game_1_AC.py: -------------------------------------------------------------------------------- 1 | # https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/531/week-4/3310/ 2 | class Solution: 3 | def canJump(self, nums: List[int]) -> bool: 4 | a = nums 5 | n = len(a) 6 | i = j = 0 7 | while i <= j and i < n: 8 | j = max(j, i + a[i]) 9 | i += 1 10 | return j >= n - 1 11 | -------------------------------------------------------------------------------- /explore/adobe/2501_missing-number_1_AC.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | class Solution { 4 | public: 5 | int missingNumber(vector& nums) { 6 | int64_t sum = 0; 7 | int n = nums.size(); 8 | int i; 9 | for (i = 0; i < n; ++i) { 10 | sum += nums[i]; 11 | } 12 | return 1LL * n * (n + 1) / 2 - sum; 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /explore/adobe/2524_tenth-line_1_AC.sh: -------------------------------------------------------------------------------- 1 | # https://leetcode.com/problems/tenth-line/ 2 | # Read from the file file.txt and output the tenth line to stdout. 3 | cat file.txt | tail -n +10 | head -n 1 4 | -------------------------------------------------------------------------------- /explore/adobe/2525_add-digits_1_AC.cpp: -------------------------------------------------------------------------------- 1 | // Digital root. 2 | class Solution { 3 | public: 4 | int addDigits(int num) { 5 | return num > 0 ? (num + 8) % 9 + 1 : 0; 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /explore/adobe/2530_rectangle-overlap_1_AC.py: -------------------------------------------------------------------------------- 1 | # https://leetcode.com/problems/rectangle-overlap/ 2 | class Solution: 3 | def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool: 4 | rec3 = [max(rec1[0], rec2[0]), max(rec1[1], rec2[1]),\ 5 | min(rec1[2], rec2[2]), min(rec1[3], rec2[3])] 6 | rec3[0] = min(rec3[0], rec3[2]) 7 | rec3[1] = min(rec3[1], rec3[3]) 8 | return (rec3[2] - rec3[0]) * (rec3[3] - rec3[1]) > 0 9 | -------------------------------------------------------------------------------- /explore/adobe/2539_combine-two-tables_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/explore/interview/card/apple/348/others/3142/ 2 | -- 1AC 3 | SELECT p.firstname, 4 | p.lastname, 5 | a.city, 6 | a.state 7 | FROM person p 8 | LEFT JOIN address a 9 | ON p.personid = a.personid; 10 | -------------------------------------------------------------------------------- /explore/adobe/2540_nth-highest-salary_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/nth-highest-salary/ 2 | -- stored procedure, from the old tales 3 | CREATE function getnthhighestsalary(n INT) 4 | returns INT 5 | begin 6 | DECLARE m INT; 7 | 8 | SET m = n - 1; 9 | 10 | RETURN ( SELECT CASE WHEN Count(DISTINCT salary) > m THEN (SELECT DISTINCT( 11 | salary) 12 | FROM employee ORDER BY salary DESC LIMIT m, 1) ELSE NULL end FROM 13 | employee ); 14 | end 15 | -------------------------------------------------------------------------------- /explore/adobe/2542_big-countries_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/big-countries/ 2 | SELECT `name`, 3 | `population`, 4 | `area` 5 | FROM `world` 6 | WHERE `population` > 25000000 7 | OR `area` > 3000000; -------------------------------------------------------------------------------- /explore/adobe/2547_maximum-subarray_1_AC.py: -------------------------------------------------------------------------------- 1 | # https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/528/week-1/3285/ 2 | # 1AC 3 | class Solution: 4 | def maxSubArray(self, nums: List[int]) -> int: 5 | res = max(nums) 6 | if res <= 0: 7 | return res 8 | res = sm = 0 9 | for x in nums: 10 | sm += x 11 | res = max(res, sm) 12 | sm = max(sm, 0) 13 | return res 14 | -------------------------------------------------------------------------------- /explore/adobe/2548_climbing-stairs_1_AC.cpp: -------------------------------------------------------------------------------- 1 | // Fibonacci 2 | class Solution { 3 | public: 4 | int climbStairs(int n) { 5 | if (n < 0) { 6 | return 0; 7 | } 8 | int f1 = 0; 9 | int f2 = 1; 10 | int f3 = 1; 11 | int i; 12 | for (i = 0; i < n; ++i) { 13 | f3 = f1 + f2; 14 | f1 = f2; 15 | f2 = f3; 16 | } 17 | return f3; 18 | } 19 | }; 20 | -------------------------------------------------------------------------------- /explore/amazon/2970_group-anagrams_1_AC.py: -------------------------------------------------------------------------------- 1 | # https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/528/week-1/3288/ 2 | # 1AC 3 | from collections import defaultdict 4 | 5 | class Solution: 6 | def groupAnagrams(self, strs: List[str]) -> List[List[str]]: 7 | mm = defaultdict(list) 8 | for s in strs: 9 | mm[''.join(sorted(s))].append(s) 10 | return list(mm.values()) 11 | -------------------------------------------------------------------------------- /explore/amazon/2971_missing-number_1_AC.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | class Solution { 4 | public: 5 | int missingNumber(vector& nums) { 6 | int64_t sum = 0; 7 | int n = nums.size(); 8 | int i; 9 | for (i = 0; i < n; ++i) { 10 | sum += nums[i]; 11 | } 12 | return 1LL * n * (n + 1) / 2 - sum; 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /explore/amazon/3003_second-highest-salary_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/second-highest-salary/ 2 | -- if else 3 | SELECT IF((SELECT Count(DISTINCT salary) 4 | FROM employee) >= 2, (SELECT salary 5 | FROM employee 6 | ORDER BY salary DESC 7 | LIMIT 1, 1), NULL) SecondHighestSalary; 8 | -------------------------------------------------------------------------------- /explore/amazon/3285_maximum-subarray_1_AC.py: -------------------------------------------------------------------------------- 1 | # https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/528/week-1/3285/ 2 | # 1AC 3 | class Solution: 4 | def maxSubArray(self, nums: List[int]) -> int: 5 | res = max(nums) 6 | if res <= 0: 7 | return res 8 | res = sm = 0 9 | for x in nums: 10 | sm += x 11 | res = max(res, sm) 12 | sm = max(sm, 0) 13 | return res 14 | -------------------------------------------------------------------------------- /explore/apple/2035_rank-scores_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/explore/interview/card/apple/348/others/2035/ 2 | -- 1AC, dense_rank exactly 3 | select 4 | score, 5 | dense_rank() over ( 6 | order by 7 | score desc) rank 8 | from 9 | scores; 10 | -------------------------------------------------------------------------------- /explore/apple/3114_missing-number_1_AC.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | class Solution { 4 | public: 5 | int missingNumber(vector& nums) { 6 | int64_t sum = 0; 7 | int n = nums.size(); 8 | int i; 9 | for (i = 0; i < n; ++i) { 10 | sum += nums[i]; 11 | } 12 | return 1LL * n * (n + 1) / 2 - sum; 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /explore/apple/3142_combine-two-tables_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/explore/interview/card/apple/348/others/3142/ 2 | -- 1AC 3 | SELECT p.firstname, 4 | p.lastname, 5 | a.city, 6 | a.state 7 | FROM person p 8 | LEFT JOIN address a 9 | ON p.personid = a.personid; 10 | -------------------------------------------------------------------------------- /explore/apple/3143_happy-number_1_AC.py: -------------------------------------------------------------------------------- 1 | # https://leetcode.com/explore/interview/card/apple/348/others/3143/ 2 | class Solution: 3 | def isHappy(self, n: int) -> bool: 4 | st = set() 5 | while n != 1: 6 | if n in st: 7 | return False 8 | st.add(n) 9 | sm = 0 10 | v = n 11 | while v != 0: 12 | sm += (v % 10) ** 2 13 | v //= 10 14 | n = sm 15 | return n == 1 16 | -------------------------------------------------------------------------------- /explore/array-and-string/1151_remove-element_1_AC.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int removeElement(vector& nums, int val) { 4 | int n = nums.size(); 5 | int i = 0; 6 | int j = 0; 7 | while (i < n) { 8 | if (nums[i] == val) { 9 | ++i; 10 | } else { 11 | nums[j++] = nums[i++]; 12 | } 13 | } 14 | return j; 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /explore/array-and-string/1183_reverse-string_1_AC.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using std::swap; 3 | 4 | class Solution { 5 | public: 6 | void reverseString(vector& s) { 7 | int n = s.size(); 8 | int i = 0; 9 | int j = n - 1; 10 | while (i < j) { 11 | swap(s[i++], s[j--]); 12 | } 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /explore/binary-search/0977_find-smallest-letter-greater-than-target_1_AC.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using std::upper_bound; 4 | using std::vector; 5 | 6 | class Solution { 7 | public: 8 | char nextGreatestLetter(vector& letters, char target) { 9 | auto &a = letters; 10 | int n = a.size(); 11 | int i = upper_bound(a.begin(), a.end(), target) - a.begin(); 12 | if (i == n) { 13 | i = 0; 14 | } 15 | return a[i]; 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /explore/binary-search/0978_valid-perfect-square_1_AC.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isPerfectSquare(int num) { 4 | int ll = 1; 5 | int rr = num; 6 | int mm; 7 | while (rr - ll > 1) { 8 | mm = ll + (rr - ll >> 1); 9 | if (mm <= num / mm) { 10 | ll = mm; 11 | } else { 12 | rr = mm; 13 | } 14 | } 15 | return ll * ll == num; 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /explore/bloomberg/2941_maximum-subarray_1_AC.py: -------------------------------------------------------------------------------- 1 | # https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/528/week-1/3285/ 2 | # 1AC 3 | class Solution: 4 | def maxSubArray(self, nums: List[int]) -> int: 5 | res = max(nums) 6 | if res <= 0: 7 | return res 8 | res = sm = 0 9 | for x in nums: 10 | sm += x 11 | res = max(res, sm) 12 | sm = max(sm, 0) 13 | return res 14 | -------------------------------------------------------------------------------- /explore/facebook/0314_second-highest-salary_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/second-highest-salary/ 2 | -- if else 3 | SELECT IF((SELECT Count(DISTINCT salary) 4 | FROM employee) >= 2, (SELECT salary 5 | FROM employee 6 | ORDER BY salary DESC 7 | LIMIT 1, 1), NULL) SecondHighestSalary; 8 | -------------------------------------------------------------------------------- /explore/facebook/0315_nth-highest-salary_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/nth-highest-salary/ 2 | -- stored procedure, from the old tales 3 | CREATE function getnthhighestsalary(n INT) 4 | returns INT 5 | begin 6 | DECLARE m INT; 7 | 8 | SET m = n - 1; 9 | 10 | RETURN ( SELECT CASE WHEN Count(DISTINCT salary) > m THEN (SELECT DISTINCT( 11 | salary) 12 | FROM employee ORDER BY salary DESC LIMIT m, 1) ELSE NULL end FROM 13 | employee ); 14 | end 15 | -------------------------------------------------------------------------------- /explore/facebook/0316_customers-who-never-order_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/customers-who-never-order/ 2 | -- 1AC 3 | SELECT c.name Customers 4 | FROM customers c 5 | LEFT JOIN orders o 6 | ON c.id = o.customerid 7 | WHERE o.customerid IS NULL; 8 | -------------------------------------------------------------------------------- /explore/facebook/0326_friend-requests-i-overall-acceptance-rate_1_AC.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/friend-requests-i-overall-acceptance-rate/ 2 | -- 1AC, count / count 3 | SELECT Round(Ifnull((SELECT Count(DISTINCT requester_id, accepter_id) 4 | FROM request_accepted) / (SELECT 5 | Count(DISTINCT sender_id, send_to_id) 6 | FROM friend_request), 0), 2) 7 | accept_rate; 8 | -------------------------------------------------------------------------------- /explore/facebook/3011_remove-duplicates-from-sorted-array_1_AC.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int removeDuplicates(vector& nums) { 4 | int n = nums.size(); 5 | int i, j, k; 6 | i = j = k = 0;; 7 | while (i < n) { 8 | nums[k++] = nums[i]; 9 | j = i + 1; 10 | while (j < n && nums[i] == nums[j]) { 11 | ++j; 12 | } 13 | i = j; 14 | } 15 | return k; 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /explore/facebook/3014_group-anagrams_1_AC.py: -------------------------------------------------------------------------------- 1 | # https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/528/week-1/3288/ 2 | # 1AC 3 | from collections import defaultdict 4 | 5 | class Solution: 6 | def groupAnagrams(self, strs: List[str]) -> List[List[str]]: 7 | mm = defaultdict(list) 8 | for s in strs: 9 | mm[''.join(sorted(s))].append(s) 10 | return list(mm.values()) 11 | -------------------------------------------------------------------------------- /explore/fun-with-arrays/3228_height-checker_1_AC.py: -------------------------------------------------------------------------------- 1 | # https://leetcode.com/problems/height-checker/ 2 | # this problem is not clearly worded 3 | class Solution: 4 | def heightChecker(self, heights: List[int]) -> int: 5 | heights_sorted = sorted(heights) 6 | count = 0 7 | for i in range(len(heights)): 8 | if heights[i] != heights_sorted[i]: 9 | count += 1 10 | return count 11 | -------------------------------------------------------------------------------- /explore/fun-with-arrays/3247_remove-element_1_AC.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int removeElement(vector& nums, int val) { 4 | int n = nums.size(); 5 | int i = 0; 6 | int j = 0; 7 | while (i < n) { 8 | if (nums[i] == val) { 9 | ++i; 10 | } else { 11 | nums[j++] = nums[i++]; 12 | } 13 | } 14 | return j; 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /explore/google/0472_license-key-formatting_1_AC.py: -------------------------------------------------------------------------------- 1 | # https://leetcode.com/explore/interview/card/google/67/sql-2/472/ 2 | import re 3 | 4 | class Solution: 5 | def licenseKeyFormatting(self, S: str, K: int) -> str: 6 | s = re.sub('-', '', S) 7 | n = len(s) 8 | r = n % K 9 | res = [s[:r]] if r > 0 else [] 10 | res += [s[r + i * K: r + (i + 1) * K] for i in range(n // K)] 11 | return ('-'.join(res)).upper() 12 | -------------------------------------------------------------------------------- /explore/google/3082_valid-anagram_1_AC.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class Solution { 5 | public: 6 | bool isAnagram(string s, string t) { 7 | if (s.size() != t.size()) { 8 | return false; 9 | } 10 | sort(s.begin(), s.end()); 11 | sort(t.begin(), t.end()); 12 | return s == t; 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /explore/google/3084_peak-index-in-a-mountain-array_1_AC.py: -------------------------------------------------------------------------------- 1 | # https://leetcode.com/problems/peak-index-in-a-mountain-array/ 2 | class Solution: 3 | def peakIndexInMountainArray(self, A: List[int]) -> int: 4 | n = len(A) 5 | for i in range(1, n - 1): 6 | if A[i] > A[i - 1] and A[i] > A[i + 1]: 7 | return i 8 | -------------------------------------------------------------------------------- /explore/google/3085_maximum-subarray_1_AC.py: -------------------------------------------------------------------------------- 1 | # https://leetcode.com/explore/interview/card/google/64/dynamic-programming-4/3085/ 2 | # 1AC 3 | class Solution: 4 | def maxSubArray(self, nums: List[int]) -> int: 5 | res = max(nums) 6 | if res <= 0: 7 | return res 8 | res = sm = 0 9 | for x in nums: 10 | sm += x 11 | res = max(res, sm) 12 | sm = max(sm, 0) 13 | return res 14 | -------------------------------------------------------------------------------- /explore/hash-table/1124_group-anagrams_1_AC.py: -------------------------------------------------------------------------------- 1 | # https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/528/week-1/3288/ 2 | # 1AC 3 | from collections import defaultdict 4 | 5 | class Solution: 6 | def groupAnagrams(self, strs: List[str]) -> List[List[str]]: 7 | mm = defaultdict(list) 8 | for s in strs: 9 | mm[''.join(sorted(s))].append(s) 10 | return list(mm.values()) 11 | -------------------------------------------------------------------------------- /explore/hash-table/1176_single-number_1_AC.py: -------------------------------------------------------------------------------- 1 | # https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/528/week-1/3283/ 2 | # 1AC 3 | class Solution: 4 | def singleNumber(self, nums: List[int]) -> int: 5 | res = 0 6 | for x in nums: 7 | res ^= x 8 | return res 9 | -------------------------------------------------------------------------------- /explore/linkedin/2916_maximum-subarray_1_AC.py: -------------------------------------------------------------------------------- 1 | # https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/528/week-1/3285/ 2 | # 1AC 3 | class Solution: 4 | def maxSubArray(self, nums: List[int]) -> int: 5 | res = max(nums) 6 | if res <= 0: 7 | return res 8 | res = sm = 0 9 | for x in nums: 10 | sm += x 11 | res = max(res, sm) 12 | sm = max(sm, 0) 13 | return res 14 | -------------------------------------------------------------------------------- /explore/microsoft/0174_maximum-subarray_1_AC.py: -------------------------------------------------------------------------------- 1 | # https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/528/week-1/3285/ 2 | # 1AC 3 | class Solution: 4 | def maxSubArray(self, nums: List[int]) -> int: 5 | res = max(nums) 6 | if res <= 0: 7 | return res 8 | res = sm = 0 9 | for x in nums: 10 | sm += x 11 | res = max(res, sm) 12 | sm = max(sm, 0) 13 | return res 14 | -------------------------------------------------------------------------------- /explore/microsoft/0187_reverse-string_1_AC.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using std::swap; 3 | 4 | class Solution { 5 | public: 6 | void reverseString(vector& s) { 7 | int n = s.size(); 8 | int i = 0; 9 | int j = n - 1; 10 | while (i < j) { 11 | swap(s[i++], s[j--]); 12 | } 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /explore/microsoft/0200_group-anagrams_1_AC.py: -------------------------------------------------------------------------------- 1 | # https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/528/week-1/3288/ 2 | # 1AC 3 | from collections import defaultdict 4 | 5 | class Solution: 6 | def groupAnagrams(self, strs: List[str]) -> List[List[str]]: 7 | mm = defaultdict(list) 8 | for s in strs: 9 | mm[''.join(sorted(s))].append(s) 10 | return list(mm.values()) 11 | -------------------------------------------------------------------------------- /explore/microsoft/0208_single-number_1_AC.py: -------------------------------------------------------------------------------- 1 | # https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/528/week-1/3283/ 2 | # 1AC 3 | class Solution: 4 | def singleNumber(self, nums: List[int]) -> int: 5 | res = 0 6 | for x in nums: 7 | res ^= x 8 | return res 9 | -------------------------------------------------------------------------------- /explore/microsoft/0257_remove-duplicates-from-sorted-array_1_AC.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int removeDuplicates(vector& nums) { 4 | int n = nums.size(); 5 | int i, j, k; 6 | i = j = k = 0;; 7 | while (i < n) { 8 | nums[k++] = nums[i]; 9 | j = i + 1; 10 | while (j < n && nums[i] == nums[j]) { 11 | ++j; 12 | } 13 | i = j; 14 | } 15 | return k; 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /explore/recursion-i/1440_reverse-string_1_AC.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using std::swap; 3 | 4 | class Solution { 5 | public: 6 | void reverseString(vector& s) { 7 | int n = s.size(); 8 | int i = 0; 9 | int j = n - 1; 10 | while (i < j) { 11 | swap(s[i++], s[j--]); 12 | } 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /explore/recursion-i/1661_fibonacci-number_1_AC.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int fib(int N) { 4 | if (N < 2) { 5 | return N; 6 | } 7 | int i; 8 | int f1 = 0, f2 = 1, f3; 9 | for (i = 2; i <= N; ++i) { 10 | f3 = f1 + f2; 11 | f1 = f2; 12 | f2 = f3; 13 | } 14 | return f3; 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /explore/recursion-i/1662_climbing-stairs_1_AC.cpp: -------------------------------------------------------------------------------- 1 | // Fibonacci 2 | class Solution { 3 | public: 4 | int climbStairs(int n) { 5 | if (n < 0) { 6 | return 0; 7 | } 8 | int f1 = 0; 9 | int f2 = 1; 10 | int f3 = 1; 11 | int i; 12 | for (i = 0; i < n; ++i) { 13 | f3 = f1 + f2; 14 | f1 = f2; 15 | f2 = f3; 16 | } 17 | return f3; 18 | } 19 | }; 20 | -------------------------------------------------------------------------------- /explore/recursion-i/1675_k-th-symbol-in-grammar_1_AC.py: -------------------------------------------------------------------------------- 1 | # https://leetcode.com/problems/k-th-symbol-in-grammar/ 2 | # 1AC 3 | class Solution: 4 | def kthGrammar(self, N: int, K: int) -> int: 5 | a = [] 6 | K -= 1 7 | while N > 1: 8 | a.append(K) 9 | K >>= 1 10 | N -= 1 11 | n = len(a) 12 | f = 0 13 | for i in range(n - 1, -1, -1): 14 | if a[i] & 1: 15 | f = 1 - f 16 | return f 17 | -------------------------------------------------------------------------------- /explore/top-interview-questions-easy/0549_single-number_1_AC.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int singleNumber(vector& nums) { 4 | int n = nums.size(); 5 | int i; 6 | int res = 0; 7 | for (i = 0; i < n; ++i) { 8 | res ^= nums[i]; 9 | } 10 | return res; 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /explore/top-interview-questions-easy/0564_best-time-to-buy-and-sell-stock-ii_1_AC.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxProfit(vector& prices) { 4 | int n = prices.size(); 5 | int i; 6 | int res = 0; 7 | for (i = 1; i < n; ++i) { 8 | if (prices[i] > prices[i - 1]) { 9 | res += prices[i] - prices[i - 1]; 10 | } 11 | } 12 | return res; 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /explore/top-interview-questions-easy/0565_number-of-1-bits_1_AC.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int hammingWeight(uint32_t n) { 4 | int cnt = 0; 5 | while (n != 0) { 6 | n &= n - 1; 7 | ++cnt; 8 | } 9 | return cnt; 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /explore/top-interview-questions-easy/0567_move-zeroes_1_AC.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | void moveZeroes(vector& nums) { 4 | int n = nums.size(); 5 | int i, j; 6 | i = j = 0; 7 | while (i < n) { 8 | if (nums[i] != 0) { 9 | nums[j++] = nums[i]; 10 | } 11 | ++i; 12 | } 13 | while (j < n) { 14 | nums[j++] = 0; 15 | } 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /explore/top-interview-questions-easy/0569_climbing-stairs_1_AC.cpp: -------------------------------------------------------------------------------- 1 | // Fibonacci 2 | class Solution { 3 | public: 4 | int climbStairs(int n) { 5 | if (n < 0) { 6 | return 0; 7 | } 8 | int f1 = 0; 9 | int f2 = 1; 10 | int f3 = 1; 11 | int i; 12 | for (i = 0; i < n; ++i) { 13 | f3 = f1 + f2; 14 | f1 = f2; 15 | f2 = f3; 16 | } 17 | return f3; 18 | } 19 | }; 20 | -------------------------------------------------------------------------------- /explore/top-interview-questions-easy/0576_house-robber_1_AC.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using std::max; 3 | 4 | class Solution { 5 | public: 6 | int rob(vector& nums) { 7 | int n = nums.size(); 8 | int f1, f2, f3; 9 | f1 = f2 = f3 = 0; 10 | int i; 11 | for (i = 0; i < n; ++i) { 12 | f3 = max(f1 + nums[i], f2); 13 | f1 = f2; 14 | f2 = f3; 15 | } 16 | return f3; 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /explore/top-interview-questions-easy/0648_reverse-bits_1_AC.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | class Solution { 4 | public: 5 | uint32_t reverseBits(uint32_t n) { 6 | uint32_t r = 0u; 7 | int i; 8 | for (i = 0; i < 32; ++i) { 9 | r = (r << 1u) | (n & 1u); 10 | n >>= 1u; 11 | } 12 | return r; 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /explore/top-interview-questions-easy/0722_missing-number_1_AC.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | class Solution { 4 | public: 5 | int missingNumber(vector& nums) { 6 | int64_t sum = 0; 7 | int n = nums.size(); 8 | int i; 9 | for (i = 0; i < n; ++i) { 10 | sum += nums[i]; 11 | } 12 | return 1LL * n * (n + 1) / 2 - sum; 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /explore/top-interview-questions-easy/0745_power-of-three_1_AC.cpp: -------------------------------------------------------------------------------- 1 | // Iteration. 2 | class Solution { 3 | public: 4 | bool isPowerOfThree(int n) { 5 | if (n <= 0) { 6 | return false; 7 | } 8 | while (n != 1) { 9 | if (n % 3 != 0) { 10 | return false; 11 | } 12 | n /= 3; 13 | } 14 | return true; 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /explore/top-interview-questions-easy/0762_hamming-distance_1_AC.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int hammingDistance(int x, int y) { 4 | x ^= y; 5 | int cnt = 0; 6 | while (x != 0) { 7 | x = x & x - 1; 8 | ++cnt; 9 | } 10 | return cnt; 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /explore/top-interview-questions-easy/0879_reverse-string_1_AC.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using std::swap; 3 | 4 | class Solution { 5 | public: 6 | void reverseString(vector& s) { 7 | int n = s.size(); 8 | int i = 0; 9 | int j = n - 1; 10 | while (i < j) { 11 | swap(s[i++], s[j--]); 12 | } 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /explore/top-interview-questions-hard/0862_best-time-to-buy-and-sell-stock-with-cooldown_1_AC.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhuli19901106/leetcode-zhuli/933f857f16370d7d0408fc77ae4b41ff04ecf214/explore/top-interview-questions-hard/0862_best-time-to-buy-and-sell-stock-with-cooldown_1_AC.cpp -------------------------------------------------------------------------------- /explore/top-interview-questions-hard/0874_queue-reconstruction-by-height_1_AC.py: -------------------------------------------------------------------------------- 1 | # https://leetcode.com/explore/interview/card/top-interview-questions-hard/124/others/874/ 2 | # that's a clever solution 3 | class Solution: 4 | def reconstructQueue(self, people: List[List[int]]) -> List[List[int]]: 5 | ap = people 6 | ap.sort(key=lambda x: (-x[0], x[1])) 7 | res = [] 8 | for h, i in ap: 9 | res.insert(i, [h, i]) 10 | return res 11 | -------------------------------------------------------------------------------- /explore/top-interview-questions-medium/0778_group-anagrams_1_AC.py: -------------------------------------------------------------------------------- 1 | # https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/528/week-1/3288/ 2 | # 1AC 3 | from collections import defaultdict 4 | 5 | class Solution: 6 | def groupAnagrams(self, strs: List[str]) -> List[List[str]]: 7 | mm = defaultdict(list) 8 | for s in strs: 9 | mm[''.join(sorted(s))].append(s) 10 | return list(mm.values()) 11 | -------------------------------------------------------------------------------- /explore/top-interview-questions-medium/0807_jump-game_1_AC.py: -------------------------------------------------------------------------------- 1 | # https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/531/week-4/3310/ 2 | class Solution: 3 | def canJump(self, nums: List[int]) -> bool: 4 | a = nums 5 | n = len(a) 6 | i = j = 0 7 | while i <= j and i < n: 8 | j = max(j, i + a[i]) 9 | i += 1 10 | return j >= n - 1 11 | -------------------------------------------------------------------------------- /explore/top-interview-questions-medium/0816_factorial-trailing-zeroes_1_AC.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int trailingZeroes(int n) { 4 | int sum = 0; 5 | while (n > 0) { 6 | sum += (n /= 5); 7 | } 8 | return sum; 9 | } 10 | }; 11 | -------------------------------------------------------------------------------- /explore/uber/1684_group-anagrams_1_AC.py: -------------------------------------------------------------------------------- 1 | # https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/528/week-1/3288/ 2 | # 1AC 3 | from collections import defaultdict 4 | 5 | class Solution: 6 | def groupAnagrams(self, strs: List[str]) -> List[List[str]]: 7 | mm = defaultdict(list) 8 | for s in strs: 9 | mm[''.join(sorted(s))].append(s) 10 | return list(mm.values()) 11 | -------------------------------------------------------------------------------- /explore/yelp/0216_group-anagrams_1_AC.py: -------------------------------------------------------------------------------- 1 | # https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/528/week-1/3288/ 2 | # 1AC 3 | from collections import defaultdict 4 | 5 | class Solution: 6 | def groupAnagrams(self, strs: List[str]) -> List[List[str]]: 7 | mm = defaultdict(list) 8 | for s in strs: 9 | mm[''.join(sorted(s))].append(s) 10 | return list(mm.values()) 11 | -------------------------------------------------------------------------------- /explore/yelp/2956_maximum-subarray_1_AC.py: -------------------------------------------------------------------------------- 1 | # https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/528/week-1/3285/ 2 | # 1AC 3 | class Solution: 4 | def maxSubArray(self, nums: List[int]) -> int: 5 | res = max(nums) 6 | if res <= 0: 7 | return res 8 | res = sm = 0 9 | for x in nums: 10 | sm += x 11 | res = max(res, sm) 12 | sm = max(sm, 0) 13 | return res 14 | -------------------------------------------------------------------------------- /mock/facbook-phone-202005160237/1.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhuli19901106/leetcode-zhuli/933f857f16370d7d0408fc77ae4b41ff04ecf214/mock/facbook-phone-202005160237/1.docx -------------------------------------------------------------------------------- /mock/facbook-phone-202005160237/1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhuli19901106/leetcode-zhuli/933f857f16370d7d0408fc77ae4b41ff04ecf214/mock/facbook-phone-202005160237/1.pdf -------------------------------------------------------------------------------- /mock/facbook-phone-202005160237/1_AC.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | class Solution: 4 | def isPalindrome(self, s: str) -> bool: 5 | s = re.sub('[^a-z0-9]', '', s.lower()) 6 | n = len(s) 7 | i = 0 8 | while i < n - 1 - i: 9 | if s[i] != s[n - 1 - i]: 10 | return False 11 | i += 1 12 | return True 13 | -------------------------------------------------------------------------------- /mock/facbook-phone-202005160237/2.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhuli19901106/leetcode-zhuli/933f857f16370d7d0408fc77ae4b41ff04ecf214/mock/facbook-phone-202005160237/2.docx -------------------------------------------------------------------------------- /mock/facbook-phone-202005160237/2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhuli19901106/leetcode-zhuli/933f857f16370d7d0408fc77ae4b41ff04ecf214/mock/facbook-phone-202005160237/2.pdf -------------------------------------------------------------------------------- /mock/facbook-phone-202005160237/3.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhuli19901106/leetcode-zhuli/933f857f16370d7d0408fc77ae4b41ff04ecf214/mock/facbook-phone-202005160237/3.docx -------------------------------------------------------------------------------- /mock/facbook-phone-202005160237/3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhuli19901106/leetcode-zhuli/933f857f16370d7d0408fc77ae4b41ff04ecf214/mock/facbook-phone-202005160237/3.pdf -------------------------------------------------------------------------------- /mock/facbook-phone-202005160237/result.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhuli19901106/leetcode-zhuli/933f857f16370d7d0408fc77ae4b41ff04ecf214/mock/facbook-phone-202005160237/result.docx -------------------------------------------------------------------------------- /mock/facbook-phone-202005160237/result.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhuli19901106/leetcode-zhuli/933f857f16370d7d0408fc77ae4b41ff04ecf214/mock/facbook-phone-202005160237/result.pdf -------------------------------------------------------------------------------- /mock/google-oa-202005160200/1.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhuli19901106/leetcode-zhuli/933f857f16370d7d0408fc77ae4b41ff04ecf214/mock/google-oa-202005160200/1.docx -------------------------------------------------------------------------------- /mock/google-oa-202005160200/1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhuli19901106/leetcode-zhuli/933f857f16370d7d0408fc77ae4b41ff04ecf214/mock/google-oa-202005160200/1.pdf -------------------------------------------------------------------------------- /mock/google-oa-202005160200/1_AC.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def checkRecord(self, s: str) -> bool: 3 | n = len(s) 4 | i = 0 5 | na = 0 6 | while i < n: 7 | j = i 8 | while j < n and s[j] == s[i]: 9 | j += 1 10 | if s[i] == 'A': 11 | na += j - i 12 | if s[i] == 'L' and j - i > 2: 13 | return False 14 | i = j 15 | return na <= 1 16 | -------------------------------------------------------------------------------- /mock/google-oa-202005160200/2.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhuli19901106/leetcode-zhuli/933f857f16370d7d0408fc77ae4b41ff04ecf214/mock/google-oa-202005160200/2.docx -------------------------------------------------------------------------------- /mock/google-oa-202005160200/2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhuli19901106/leetcode-zhuli/933f857f16370d7d0408fc77ae4b41ff04ecf214/mock/google-oa-202005160200/2.pdf -------------------------------------------------------------------------------- /mock/google-oa-202005160200/result.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhuli19901106/leetcode-zhuli/933f857f16370d7d0408fc77ae4b41ff04ecf214/mock/google-oa-202005160200/result.docx -------------------------------------------------------------------------------- /mock/google-oa-202005160200/result.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhuli19901106/leetcode-zhuli/933f857f16370d7d0408fc77ae4b41ff04ecf214/mock/google-oa-202005160200/result.pdf -------------------------------------------------------------------------------- /shell/0192_word-frequency_1_AC.sh: -------------------------------------------------------------------------------- 1 | # https://leetcode.com/problems/word-frequency/ 2 | # Read from the file words.txt and output the word frequency list to stdout. 3 | # I hate regex 4 | cat words.txt | sed 's/^\s\+//g' | sed 's/\s\+$//g' | sed 's/\s\+/ /g' | tr ' ' '\n' | sort | uniq -c | sort -n -r -k 1 | awk '{print $2" "$1}' 5 | -------------------------------------------------------------------------------- /shell/0193_valid-phone-numbers_1_AC.sh: -------------------------------------------------------------------------------- 1 | # https://leetcode.com/problems/valid-phone-numbers/ 2 | # Read from the file file.txt and output all valid phone numbers to stdout. 3 | cat file.txt | grep -E "(^[0-9]{3}\-[0-9]{3}\-[0-9]{4}$)|(^\([0-9]{3}\) [0-9]{3}\-[0-9]{4}$)" 4 | -------------------------------------------------------------------------------- /shell/0194_transpose-file_1_AC.sh: -------------------------------------------------------------------------------- 1 | # Read from the file file.txt and print its transposed content to stdout. 2 | # cut and paste 3 | for i in $(seq 1 $(cat file.txt | head -n 1 | awk '{print NF}')); do cut -d' ' -f"$i" file.txt | paste -d' ' -s; done 4 | -------------------------------------------------------------------------------- /shell/0195_tenth-line_1_AC.sh: -------------------------------------------------------------------------------- 1 | # https://leetcode.com/problems/tenth-line/ 2 | # Read from the file file.txt and output the tenth line to stdout. 3 | cat file.txt | tail -n +10 | head -n 1 4 | --------------------------------------------------------------------------------