diff --git a/README.md b/README.md index ee21d0b8..0301b0c4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ [![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) > ["For coding interview preparation, LeetCode is one of the best online resource providing a rich library of more than 300 real coding interview questions for you to practice from using one of the 7 supported languages - C, C++, Java, Python, C#, JavaScript, Ruby."](https://www.quora.com/How-effective-is-Leetcode-for-preparing-for-technical-interviews) -* [Level 2](#level-2) * [Udemy](#udemy) * [Data Structure I](#data-structure-i) * [Data Structure II](#data-structure-ii) @@ -16,152 +15,7 @@ * [Graph Theory I](#graph-theory-i) * [SQL I](#sql-i) * [Level 1](#level-1) - -### Level 2 - -#### Day 1 Implementation/Simulation - -| | | | | | -|-|-|-|-|-|- -| 0202 |[Happy Number](src/main/kotlin/g0201_0300/s0202_happy_number)| Easy | Top_Interview_Questions, Hash_Table, Math, Two_Pointers | 261 | 45.08 -| 0054 |[Spiral Matrix](src/main/kotlin/g0001_0100/s0054_spiral_matrix)| Medium | Top_Interview_Questions, Array, Matrix, Simulation | 224 | 62.50 -| 1706 |[Where Will the Ball Fall](src/main/kotlin/g1701_1800/s1706_where_will_the_ball_fall)| Medium | Array, Dynamic_Programming, Depth_First_Search, Matrix, Simulation | 270 | 67.86 - -#### Day 2 String - -| | | | | | -|-|-|-|-|-|- -| 0014 |[Longest Common Prefix](src/main/kotlin/g0001_0100/s0014_longest_common_prefix)| Easy | Top_Interview_Questions, String | 209 | 88.86 -| 0043 |[Multiply Strings](src/main/kotlin/g0001_0100/s0043_multiply_strings)| Medium | String, Math, Simulation | 390 | 56.25 - -#### Day 3 Linked List - -| | | | | | -|-|-|-|-|-|- -| 0019 |[Remove Nth Node From End of List](src/main/kotlin/g0001_0100/s0019_remove_nth_node_from_end_of_list)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Two_Pointers, Linked_List | 180 | 91.58 -| 0234 |[Palindrome Linked List](src/main/kotlin/g0201_0300/s0234_palindrome_linked_list)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Two_Pointers, Stack, Linked_List, Recursion | 641 | 79.53 - -#### Day 4 Linked List - -| | | | | | -|-|-|-|-|-|- -| 0328 |[Odd Even Linked List](src/main/kotlin/g0301_0400/s0328_odd_even_linked_list)| Medium | Top_Interview_Questions, Linked_List | 216 | 86.96 -| 0148 |[Sort List](src/main/kotlin/g0101_0200/s0148_sort_list)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Sorting, Two_Pointers, Linked_List, Divide_and_Conquer, Merge_Sort | 820 | 61.70 - -#### Day 5 Greedy - -| | | | | | -|-|-|-|-|-|- -| 0621 |[Task Scheduler](src/main/kotlin/g0601_0700/s0621_task_scheduler)| Medium | Array, Hash_Table, Sorting, Greedy, Heap_Priority_Queue, Counting | 266 | 98.36 - -#### Day 6 Tree - -| | | | | | -|-|-|-|-|-|- -| 0226 |[Invert Binary Tree](src/main/kotlin/g0201_0300/s0226_invert_binary_tree)| Easy | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 233 | 54.90 -| 0110 |[Balanced Binary Tree](src/main/kotlin/g0101_0200/s0110_balanced_binary_tree)| Easy | Depth_First_Search, Tree, Binary_Tree | 310 | 63.63 - -#### Day 7 Tree - -| | | | | | -|-|-|-|-|-|- -| 0543 |[Diameter of Binary Tree](src/main/kotlin/g0501_0600/s0543_diameter_of_binary_tree)| Easy | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree | 307 | 43.93 -| 0437 |[Path Sum III](src/main/kotlin/g0401_0500/s0437_path_sum_iii)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree | 403 | 54.12 - -#### Day 8 Binary Search - -| | | | | | -|-|-|-|-|-|- -| 0074 |[Search a 2D Matrix](src/main/kotlin/g0001_0100/s0074_search_a_2d_matrix)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix | 290 | 40.17 -| 0033 |[Search in Rotated Sorted Array](src/main/kotlin/g0001_0100/s0033_search_in_rotated_sorted_array)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search | 184 | 86.08 - -#### Day 9 Binary Search Tree - -| | | | | | -|-|-|-|-|-|- -| 0108 |[Convert Sorted Array to Binary Search Tree](src/main/kotlin/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree)| Easy | Top_Interview_Questions, Array, Tree, Binary_Tree, Binary_Search_Tree, Divide_and_Conquer | 334 | 35.39 -| 0230 |[Kth Smallest Element in a BST](src/main/kotlin/g0201_0300/s0230_kth_smallest_element_in_a_bst)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree | 393 | 33.33 -| 0173 |[Binary Search Tree Iterator](src/main/kotlin/g0101_0200/s0173_binary_search_tree_iterator)| Medium | Tree, Binary_Tree, Stack, Design, Binary_Search_Tree, Iterator | 563 | 46.91 - -#### Day 10 Graph/BFS/DFS - -| | | | | | -|-|-|-|-|-|- -| 0994 |[Rotting Oranges](src/main/kotlin/g0901_1000/s0994_rotting_oranges)| Medium | Array, Breadth_First_Search, Matrix | 164 | 82.95 -| 0417 |[Pacific Atlantic Water Flow](src/main/kotlin/g0401_0500/s0417_pacific_atlantic_water_flow)| Medium | Array, Depth_First_Search, Breadth_First_Search, Matrix | 319 | 100.00 - -#### Day 11 Graph/BFS/DFS - -| | | | | | -|-|-|-|-|-|- -| 0210 |[Course Schedule II](src/main/kotlin/g0201_0300/s0210_course_schedule_ii)| Medium | Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Graph, Topological_Sort | 266 | 96.32 -| 0815 |[Bus Routes](src/main/kotlin/g0801_0900/s0815_bus_routes)| Hard | Array, Hash_Table, Breadth_First_Search | 429 | 100.00 - -#### Day 12 Dynamic Programming - -| | | | | | -|-|-|-|-|-|- -| 0198 |[House Robber](src/main/kotlin/g0101_0200/s0198_house_robber)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming | 156 | 92.24 -| 0322 |[Coin Change](src/main/kotlin/g0301_0400/s0322_coin_change)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Breadth_First_Search | 332 | 50.68 - -#### Day 13 Dynamic Programming - -| | | | | | -|-|-|-|-|-|- -| 0416 |[Partition Equal Subset Sum](src/main/kotlin/g0401_0500/s0416_partition_equal_subset_sum)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming | 204 | 98.82 -| 0152 |[Maximum Product Subarray](src/main/kotlin/g0101_0200/s0152_maximum_product_subarray)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming | 253 | 88.42 - -#### Day 14 Sliding Window/Two Pointer - -| | | | | | -|-|-|-|-|-|- -| 0003 |[Longest Substring Without Repeating Characters](src/main/kotlin/g0001_0100/s0003_longest_substring_without_repeating_characters)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window | 258 | 91.09 -| 0016 |[3Sum Closest](src/main/kotlin/g0001_0100/s0016_3sum_closest)| Medium | Array, Sorting, Two_Pointers | 413 | 95.05 -| 0076 |[Minimum Window Substring](src/main/kotlin/g0001_0100/s0076_minimum_window_substring)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window | 346 | 85.20 - -#### Day 15 Tree - -| | | | | | -|-|-|-|-|-|- -| 0100 |[Same Tree](src/main/kotlin/g0001_0100/s0100_same_tree)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 208 | 72.24 -| 0101 |[Symmetric Tree](src/main/kotlin/g0101_0200/s0101_symmetric_tree)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 190 | 91.36 -| 0199 |[Binary Tree Right Side View](src/main/kotlin/g0101_0200/s0199_binary_tree_right_side_view)| Medium | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 194 | 92.89 - -#### Day 16 Design - -| | | | | | -|-|-|-|-|-|- -| 0232 |[Implement Queue using Stacks](src/main/kotlin/g0201_0300/s0232_implement_queue_using_stacks)| Easy | Stack, Design, Queue | 258 | 70.86 -| 0155 |[Min Stack](src/main/kotlin/g0101_0200/s0155_min_stack)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Stack, Design | 331 | 84.88 -| 0208 |[Implement Trie (Prefix Tree)](src/main/kotlin/g0201_0300/s0208_implement_trie_prefix_tree)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Design, Trie | 689 | 61.00 - -#### Day 17 Interval - -| | | | | | -|-|-|-|-|-|- -| 0057 |[Insert Interval](src/main/kotlin/g0001_0100/s0057_insert_interval)| Medium | Array | 257 | 99.52 -| 0056 |[Merge Intervals](src/main/kotlin/g0001_0100/s0056_merge_intervals)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting | 320 | 94.22 - -#### Day 18 Stack - -| | | | | | -|-|-|-|-|-|- -| 0735 |[Asteroid Collision](src/main/kotlin/g0701_0800/s0735_asteroid_collision)| Medium | Array, Stack | 243 | 100.00 -| 0227 |[Basic Calculator II](src/main/kotlin/g0201_0300/s0227_basic_calculator_ii)| Medium | Top_Interview_Questions, String, Math, Stack | 383 | 62.50 - -#### Day 19 Union Find - -| | | | | | -|-|-|-|-|-|- -| 0547 |[Number of Provinces](src/main/kotlin/g0501_0600/s0547_number_of_provinces)| Medium | Depth_First_Search, Breadth_First_Search, Graph, Union_Find | 229 | 79.73 -| 0947 |[Most Stones Removed with Same Row or Column](src/main/kotlin/g0901_1000/s0947_most_stones_removed_with_same_row_or_column)| Medium | Depth_First_Search, Graph, Union_Find | 200 | 100.00 - -#### Day 20 Brute Force/Backtracking - -| | | | | | -|-|-|-|-|-|- -| 0039 |[Combination Sum](src/main/kotlin/g0001_0100/s0039_combination_sum)| Medium | Top_100_Liked_Questions, Array, Backtracking | 317 | 86.85 -| 0046 |[Permutations](src/main/kotlin/g0001_0100/s0046_permutations)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Backtracking | 186 | 100.00 +* [Level 2](#level-2) ### Udemy @@ -1811,10 +1665,440 @@ | 1046 |[Last Stone Weight](src/main/kotlin/g1001_1100/s1046_last_stone_weight)| Easy | Array, Heap_Priority_Queue | 123 | 100.00 | 0692 |[Top K Frequent Words](src/main/kotlin/g0601_0700/s0692_top_k_frequent_words)| Medium | String, Hash_Table, Sorting, Heap_Priority_Queue, Counting, Trie, Bucket_Sort | 239 | 81.10 +### Level 2 + +#### Day 1 Implementation/Simulation + +| | | | | | +|-|-|-|-|-|- +| 0202 |[Happy Number](src/main/kotlin/g0201_0300/s0202_happy_number)| Easy | Top_Interview_Questions, Hash_Table, Math, Two_Pointers | 261 | 45.08 +| 0054 |[Spiral Matrix](src/main/kotlin/g0001_0100/s0054_spiral_matrix)| Medium | Top_Interview_Questions, Array, Matrix, Simulation | 224 | 62.50 +| 1706 |[Where Will the Ball Fall](src/main/kotlin/g1701_1800/s1706_where_will_the_ball_fall)| Medium | Array, Dynamic_Programming, Depth_First_Search, Matrix, Simulation | 270 | 67.86 + +#### Day 2 String + +| | | | | | +|-|-|-|-|-|- +| 0014 |[Longest Common Prefix](src/main/kotlin/g0001_0100/s0014_longest_common_prefix)| Easy | Top_Interview_Questions, String | 209 | 88.86 +| 0043 |[Multiply Strings](src/main/kotlin/g0001_0100/s0043_multiply_strings)| Medium | String, Math, Simulation | 390 | 56.25 + +#### Day 3 Linked List + +| | | | | | +|-|-|-|-|-|- +| 0019 |[Remove Nth Node From End of List](src/main/kotlin/g0001_0100/s0019_remove_nth_node_from_end_of_list)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Two_Pointers, Linked_List | 180 | 91.58 +| 0234 |[Palindrome Linked List](src/main/kotlin/g0201_0300/s0234_palindrome_linked_list)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Two_Pointers, Stack, Linked_List, Recursion | 641 | 79.53 + +#### Day 4 Linked List + +| | | | | | +|-|-|-|-|-|- +| 0328 |[Odd Even Linked List](src/main/kotlin/g0301_0400/s0328_odd_even_linked_list)| Medium | Top_Interview_Questions, Linked_List | 216 | 86.96 +| 0148 |[Sort List](src/main/kotlin/g0101_0200/s0148_sort_list)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Sorting, Two_Pointers, Linked_List, Divide_and_Conquer, Merge_Sort | 820 | 61.70 + +#### Day 5 Greedy + +| | | | | | +|-|-|-|-|-|- +| 2131 |[Longest Palindrome by Concatenating Two Letter Words](src/main/kotlin/g2101_2200/s2131_longest_palindrome_by_concatenating_two_letter_words)| Medium | Array, String, Hash_Table, Greedy, Counting | 607 | 90.00 +| 0621 |[Task Scheduler](src/main/kotlin/g0601_0700/s0621_task_scheduler)| Medium | Array, Hash_Table, Sorting, Greedy, Heap_Priority_Queue, Counting | 266 | 98.36 + +#### Day 6 Tree + +| | | | | | +|-|-|-|-|-|- +| 0226 |[Invert Binary Tree](src/main/kotlin/g0201_0300/s0226_invert_binary_tree)| Easy | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 233 | 54.90 +| 0110 |[Balanced Binary Tree](src/main/kotlin/g0101_0200/s0110_balanced_binary_tree)| Easy | Depth_First_Search, Tree, Binary_Tree | 310 | 63.63 + +#### Day 7 Tree + +| | | | | | +|-|-|-|-|-|- +| 0543 |[Diameter of Binary Tree](src/main/kotlin/g0501_0600/s0543_diameter_of_binary_tree)| Easy | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree | 307 | 43.93 +| 0437 |[Path Sum III](src/main/kotlin/g0401_0500/s0437_path_sum_iii)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree | 403 | 54.12 + +#### Day 8 Binary Search + +| | | | | | +|-|-|-|-|-|- +| 0074 |[Search a 2D Matrix](src/main/kotlin/g0001_0100/s0074_search_a_2d_matrix)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix | 290 | 40.17 +| 0033 |[Search in Rotated Sorted Array](src/main/kotlin/g0001_0100/s0033_search_in_rotated_sorted_array)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search | 184 | 86.08 + +#### Day 9 Binary Search Tree + +| | | | | | +|-|-|-|-|-|- +| 0108 |[Convert Sorted Array to Binary Search Tree](src/main/kotlin/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree)| Easy | Top_Interview_Questions, Array, Tree, Binary_Tree, Binary_Search_Tree, Divide_and_Conquer | 334 | 35.39 +| 0230 |[Kth Smallest Element in a BST](src/main/kotlin/g0201_0300/s0230_kth_smallest_element_in_a_bst)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree | 393 | 33.33 +| 0173 |[Binary Search Tree Iterator](src/main/kotlin/g0101_0200/s0173_binary_search_tree_iterator)| Medium | Tree, Binary_Tree, Stack, Design, Binary_Search_Tree, Iterator | 563 | 46.91 + +#### Day 10 Graph/BFS/DFS + +| | | | | | +|-|-|-|-|-|- +| 0994 |[Rotting Oranges](src/main/kotlin/g0901_1000/s0994_rotting_oranges)| Medium | Array, Breadth_First_Search, Matrix | 164 | 82.95 +| 0417 |[Pacific Atlantic Water Flow](src/main/kotlin/g0401_0500/s0417_pacific_atlantic_water_flow)| Medium | Array, Depth_First_Search, Breadth_First_Search, Matrix | 319 | 100.00 + +#### Day 11 Graph/BFS/DFS + +| | | | | | +|-|-|-|-|-|- +| 0210 |[Course Schedule II](src/main/kotlin/g0201_0300/s0210_course_schedule_ii)| Medium | Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Graph, Topological_Sort | 266 | 96.32 +| 0815 |[Bus Routes](src/main/kotlin/g0801_0900/s0815_bus_routes)| Hard | Array, Hash_Table, Breadth_First_Search | 429 | 100.00 + +#### Day 12 Dynamic Programming + +| | | | | | +|-|-|-|-|-|- +| 0198 |[House Robber](src/main/kotlin/g0101_0200/s0198_house_robber)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming | 156 | 92.24 +| 0322 |[Coin Change](src/main/kotlin/g0301_0400/s0322_coin_change)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Breadth_First_Search | 332 | 50.68 + +#### Day 13 Dynamic Programming + +| | | | | | +|-|-|-|-|-|- +| 0416 |[Partition Equal Subset Sum](src/main/kotlin/g0401_0500/s0416_partition_equal_subset_sum)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming | 204 | 98.82 +| 0152 |[Maximum Product Subarray](src/main/kotlin/g0101_0200/s0152_maximum_product_subarray)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming | 253 | 88.42 + +#### Day 14 Sliding Window/Two Pointer + +| | | | | | +|-|-|-|-|-|- +| 0003 |[Longest Substring Without Repeating Characters](src/main/kotlin/g0001_0100/s0003_longest_substring_without_repeating_characters)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window | 258 | 91.09 +| 0016 |[3Sum Closest](src/main/kotlin/g0001_0100/s0016_3sum_closest)| Medium | Array, Sorting, Two_Pointers | 413 | 95.05 +| 0076 |[Minimum Window Substring](src/main/kotlin/g0001_0100/s0076_minimum_window_substring)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window | 346 | 85.20 + +#### Day 15 Tree + +| | | | | | +|-|-|-|-|-|- +| 0100 |[Same Tree](src/main/kotlin/g0001_0100/s0100_same_tree)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 208 | 72.24 +| 0101 |[Symmetric Tree](src/main/kotlin/g0101_0200/s0101_symmetric_tree)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 190 | 91.36 +| 0199 |[Binary Tree Right Side View](src/main/kotlin/g0101_0200/s0199_binary_tree_right_side_view)| Medium | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 194 | 92.89 + +#### Day 16 Design + +| | | | | | +|-|-|-|-|-|- +| 0232 |[Implement Queue using Stacks](src/main/kotlin/g0201_0300/s0232_implement_queue_using_stacks)| Easy | Stack, Design, Queue | 258 | 70.86 +| 0155 |[Min Stack](src/main/kotlin/g0101_0200/s0155_min_stack)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Stack, Design | 331 | 84.88 +| 0208 |[Implement Trie (Prefix Tree)](src/main/kotlin/g0201_0300/s0208_implement_trie_prefix_tree)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Design, Trie | 689 | 61.00 + +#### Day 17 Interval + +| | | | | | +|-|-|-|-|-|- +| 0057 |[Insert Interval](src/main/kotlin/g0001_0100/s0057_insert_interval)| Medium | Array | 257 | 99.52 +| 0056 |[Merge Intervals](src/main/kotlin/g0001_0100/s0056_merge_intervals)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting | 320 | 94.22 + +#### Day 18 Stack + +| | | | | | +|-|-|-|-|-|- +| 0735 |[Asteroid Collision](src/main/kotlin/g0701_0800/s0735_asteroid_collision)| Medium | Array, Stack | 243 | 100.00 +| 0227 |[Basic Calculator II](src/main/kotlin/g0201_0300/s0227_basic_calculator_ii)| Medium | Top_Interview_Questions, String, Math, Stack | 383 | 62.50 + +#### Day 19 Union Find + +| | | | | | +|-|-|-|-|-|- +| 0547 |[Number of Provinces](src/main/kotlin/g0501_0600/s0547_number_of_provinces)| Medium | Depth_First_Search, Breadth_First_Search, Graph, Union_Find | 229 | 79.73 +| 0947 |[Most Stones Removed with Same Row or Column](src/main/kotlin/g0901_1000/s0947_most_stones_removed_with_same_row_or_column)| Medium | Depth_First_Search, Graph, Union_Find | 200 | 100.00 + +#### Day 20 Brute Force/Backtracking + +| | | | | | +|-|-|-|-|-|- +| 0039 |[Combination Sum](src/main/kotlin/g0001_0100/s0039_combination_sum)| Medium | Top_100_Liked_Questions, Array, Backtracking | 317 | 86.85 +| 0046 |[Permutations](src/main/kotlin/g0001_0100/s0046_permutations)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Backtracking | 186 | 100.00 + ## Algorithms | # | Title | Difficulty | Tag | Time, ms | Time, % |------|----------------|-------------|-------------|----------|-------- +| 2412 |[Minimum Money Required Before Transactions](src/main/kotlin/g2401_2500/s2412_minimum_money_required_before_transactions)| Hard | Array, Sorting, Greedy | 965 | 100.00 +| 2411 |[Smallest Subarrays With Maximum Bitwise OR](src/main/kotlin/g2401_2500/s2411_smallest_subarrays_with_maximum_bitwise_or)| Medium | Array, Binary_Search, Bit_Manipulation, Sliding_Window | 562 | 100.00 +| 2410 |[Maximum Matching of Players With Trainers](src/main/kotlin/g2401_2500/s2410_maximum_matching_of_players_with_trainers)| Medium | Array, Sorting, Greedy, Two_Pointers | 565 | 83.33 +| 2409 |[Count Days Spent Together](src/main/kotlin/g2401_2500/s2409_count_days_spent_together)| Easy | String, Math | 143 | 60.00 +| 2407 |[Longest Increasing Subsequence II](src/main/kotlin/g2401_2500/s2407_longest_increasing_subsequence_ii)| Hard | Array, Dynamic_Programming, Divide_and_Conquer, Queue, Segment_Tree, Binary_Indexed_Tree, Monotonic_Queue | 518 | 100.00 +| 2406 |[Divide Intervals Into Minimum Number of Groups](src/main/kotlin/g2401_2500/s2406_divide_intervals_into_minimum_number_of_groups)| Medium | Array, Sorting, Greedy, Two_Pointers, Heap_Priority_Queue, Prefix_Sum | 772 | 100.00 +| 2405 |[Optimal Partition of String](src/main/kotlin/g2401_2500/s2405_optimal_partition_of_string)| Medium | String, Hash_Table, Greedy | 185 | 100.00 +| 2404 |[Most Frequent Even Element](src/main/kotlin/g2401_2500/s2404_most_frequent_even_element)| Easy | Array, Hash_Table, Counting | 349 | 90.91 +| 2402 |[Meeting Rooms III](src/main/kotlin/g2401_2500/s2402_meeting_rooms_iii)| Hard | Array, Sorting, Heap_Priority_Queue | 976 | 100.00 +| 2401 |[Longest Nice Subarray](src/main/kotlin/g2401_2500/s2401_longest_nice_subarray)| Medium | Array, Bit_Manipulation, Sliding_Window | 507 | 100.00 +| 2400 |[Number of Ways to Reach a Position After Exactly k Steps](src/main/kotlin/g2301_2400/s2400_number_of_ways_to_reach_a_position_after_exactly_k_steps)| Medium | Dynamic_Programming, Math, Combinatorics | 126 | 100.00 +| 2399 |[Check Distances Between Same Letters](src/main/kotlin/g2301_2400/s2399_check_distances_between_same_letters)| Easy | Array, String, Hash_Table | 173 | 66.67 +| 2398 |[Maximum Number of Robots Within Budget](src/main/kotlin/g2301_2400/s2398_maximum_number_of_robots_within_budget)| Hard | Array, Binary_Search, Heap_Priority_Queue, Prefix_Sum, Sliding_Window, Queue | 507 | 100.00 +| 2397 |[Maximum Rows Covered by Columns](src/main/kotlin/g2301_2400/s2397_maximum_rows_covered_by_columns)| Medium | Array, Matrix, Bit_Manipulation, Backtracking, Enumeration | 154 | 100.00 +| 2396 |[Strictly Palindromic Number](src/main/kotlin/g2301_2400/s2396_strictly_palindromic_number)| Medium | Math, Two_Pointers, Brainteaser | 130 | 58.06 +| 2395 |[Find Subarrays With Equal Sum](src/main/kotlin/g2301_2400/s2395_find_subarrays_with_equal_sum)| Easy | Array, Hash_Table | 143 | 100.00 +| 2392 |[Build a Matrix With Conditions](src/main/kotlin/g2301_2400/s2392_build_a_matrix_with_conditions)| Hard | Array, Matrix, Graph, Topological_Sort | 706 | 100.00 +| 2391 |[Minimum Amount of Time to Collect Garbage](src/main/kotlin/g2301_2400/s2391_minimum_amount_of_time_to_collect_garbage)| Medium | Array, String, Prefix_Sum | 537 | 100.00 +| 2390 |[Removing Stars From a String](src/main/kotlin/g2301_2400/s2390_removing_stars_from_a_string)| Medium | String, Stack, Simulation | 337 | 62.92 +| 2389 |[Longest Subsequence With Limited Sum](src/main/kotlin/g2301_2400/s2389_longest_subsequence_with_limited_sum)| Easy | Array, Sorting, Greedy, Binary_Search, Prefix_Sum | 257 | 80.00 +| 2386 |[Find the K-Sum of an Array](src/main/kotlin/g2301_2400/s2386_find_the_k_sum_of_an_array)| Hard | Array, Sorting, Heap_Priority_Queue | 675 | 100.00 +| 2385 |[Amount of Time for Binary Tree to Be Infected](src/main/kotlin/g2301_2400/s2385_amount_of_time_for_binary_tree_to_be_infected)| Medium | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 609 | 100.00 +| 2384 |[Largest Palindromic Number](src/main/kotlin/g2301_2400/s2384_largest_palindromic_number)| Medium | String, Hash_Table, Greedy | 252 | 100.00 +| 2383 |[Minimum Hours of Training to Win a Competition](src/main/kotlin/g2301_2400/s2383_minimum_hours_of_training_to_win_a_competition)| Easy | Array, Greedy | 156 | 100.00 +| 2382 |[Maximum Segment Sum After Removals](src/main/kotlin/g2301_2400/s2382_maximum_segment_sum_after_removals)| Hard | Array, Prefix_Sum, Union_Find, Ordered_Set | 857 | 50.00 +| 2381 |[Shifting Letters II](src/main/kotlin/g2301_2400/s2381_shifting_letters_ii)| Medium | Array, String, Prefix_Sum | 669 | 100.00 +| 2380 |[Time Needed to Rearrange a Binary String](src/main/kotlin/g2301_2400/s2380_time_needed_to_rearrange_a_binary_string)| Medium | String, Dynamic_Programming, Simulation | 149 | 100.00 +| 2379 |[Minimum Recolors to Get K Consecutive Black Blocks](src/main/kotlin/g2301_2400/s2379_minimum_recolors_to_get_k_consecutive_black_blocks)| Easy | String, Sliding_Window | 132 | 95.24 +| 2376 |[Count Special Integers](src/main/kotlin/g2301_2400/s2376_count_special_integers)| Hard | Dynamic_Programming, Math | 125 | 100.00 +| 2375 |[Construct Smallest Number From DI String](src/main/kotlin/g2301_2400/s2375_construct_smallest_number_from_di_string)| Medium | String, Greedy, Stack, Backtracking | 156 | 66.67 +| 2374 |[Node With Highest Edge Score](src/main/kotlin/g2301_2400/s2374_node_with_highest_edge_score)| Medium | Hash_Table, Graph | 673 | 100.00 +| 2373 |[Largest Local Values in a Matrix](src/main/kotlin/g2301_2400/s2373_largest_local_values_in_a_matrix)| Easy | Array, Matrix | 264 | 100.00 +| 2370 |[Longest Ideal Subsequence](src/main/kotlin/g2301_2400/s2370_longest_ideal_subsequence)| Medium | String, Hash_Table, Dynamic_Programming | 255 | 100.00 +| 2369 |[Check if There is a Valid Partition For The Array](src/main/kotlin/g2301_2400/s2369_check_if_there_is_a_valid_partition_for_the_array)| Medium | Array, Dynamic_Programming | 533 | 100.00 +| 2368 |[Reachable Nodes With Restrictions](src/main/kotlin/g2301_2400/s2368_reachable_nodes_with_restrictions)| Medium | Array, Hash_Table, Depth_First_Search, Breadth_First_Search, Tree, Graph | 1199 | 76.92 +| 2367 |[Number of Arithmetic Triplets](src/main/kotlin/g2301_2400/s2367_number_of_arithmetic_triplets)| Easy | Array, Hash_Table, Two_Pointers, Enumeration | 146 | 91.18 +| 2366 |[Minimum Replacements to Sort the Array](src/main/kotlin/g2301_2400/s2366_minimum_replacements_to_sort_the_array)| Hard | Array, Math, Greedy | 433 | 100.00 +| 2365 |[Task Scheduler II](src/main/kotlin/g2301_2400/s2365_task_scheduler_ii)| Medium | Array, Hash_Table, Simulation | 595 | 100.00 +| 2364 |[Count Number of Bad Pairs](src/main/kotlin/g2301_2400/s2364_count_number_of_bad_pairs)| Medium | Array, Hash_Table | 590 | 100.00 +| 2363 |[Merge Similar Items](src/main/kotlin/g2301_2400/s2363_merge_similar_items)| Easy | Array, Hash_Table, Sorting, Ordered_Set | 320 | 100.00 +| 2360 |[Longest Cycle in a Graph](src/main/kotlin/g2301_2400/s2360_longest_cycle_in_a_graph)| Hard | Depth_First_Search, Graph, Topological_Sort | 517 | 80.00 +| 2359 |[Find Closest Node to Given Two Nodes](src/main/kotlin/g2301_2400/s2359_find_closest_node_to_given_two_nodes)| Medium | Depth_First_Search, Graph | 552 | 40.00 +| 2358 |[Maximum Number of Groups Entering a Competition](src/main/kotlin/g2301_2400/s2358_maximum_number_of_groups_entering_a_competition)| Medium | Array, Math, Greedy, Binary_Search | 441 | 100.00 +| 2357 |[Make Array Zero by Subtracting Equal Amounts](src/main/kotlin/g2301_2400/s2357_make_array_zero_by_subtracting_equal_amounts)| Easy | Array, Hash_Table, Sorting, Heap_Priority_Queue, Simulation | 156 | 78.95 +| 2356 |[Number of Unique Subjects Taught by Each Teacher](src/main/kotlin/g2301_2400/s2356_number_of_unique_subjects_taught_by_each_teacher)| Easy | Database | 839 | 96.77 +| 2354 |[Number of Excellent Pairs](src/main/kotlin/g2301_2400/s2354_number_of_excellent_pairs)| Hard | Array, Hash_Table, Binary_Search, Bit_Manipulation | 700 | 100.00 +| 2353 |[Design a Food Rating System](src/main/kotlin/g2301_2400/s2353_design_a_food_rating_system)| Medium | Hash_Table, Design, Heap_Priority_Queue, Ordered_Set | 1204 | 100.00 +| 2352 |[Equal Row and Column Pairs](src/main/kotlin/g2301_2400/s2352_equal_row_and_column_pairs)| Medium | Array, Hash_Table, Matrix, Simulation | 339 | 100.00 +| 2351 |[First Letter to Appear Twice](src/main/kotlin/g2301_2400/s2351_first_letter_to_appear_twice)| Easy | String, Hash_Table, Counting | 122 | 100.00 +| 2350 |[Shortest Impossible Sequence of Rolls](src/main/kotlin/g2301_2400/s2350_shortest_impossible_sequence_of_rolls)| Hard | Array, Hash_Table, Greedy | 495 | 100.00 +| 2349 |[Design a Number Container System](src/main/kotlin/g2301_2400/s2349_design_a_number_container_system)| Medium | Hash_Table, Design, Heap_Priority_Queue, Ordered_Set | 1011 | 100.00 +| 2348 |[Number of Zero-Filled Subarrays](src/main/kotlin/g2301_2400/s2348_number_of_zero_filled_subarrays)| Medium | Array, Math | 559 | 80.00 +| 2347 |[Best Poker Hand](src/main/kotlin/g2301_2400/s2347_best_poker_hand)| Easy | Array, Hash_Table, Counting | 146 | 33.33 +| 2344 |[Minimum Deletions to Make Array Divisible](src/main/kotlin/g2301_2400/s2344_minimum_deletions_to_make_array_divisible)| Hard | Array, Math, Sorting, Heap_Priority_Queue, Number_Theory | 542 | 100.00 +| 2343 |[Query Kth Smallest Trimmed Number](src/main/kotlin/g2301_2400/s2343_query_kth_smallest_trimmed_number)| Medium | Array, String, Sorting, Heap_Priority_Queue, Divide_and_Conquer, Quickselect, Radix_Sort | 382 | 100.00 +| 2342 |[Max Sum of a Pair With Equal Sum of Digits](src/main/kotlin/g2301_2400/s2342_max_sum_of_a_pair_with_equal_sum_of_digits)| Medium | Array, Hash_Table, Sorting, Heap_Priority_Queue | 636 | 83.33 +| 2341 |[Maximum Number of Pairs in Array](src/main/kotlin/g2301_2400/s2341_maximum_number_of_pairs_in_array)| Easy | Array, Hash_Table, Sorting | 160 | 100.00 +| 2338 |[Count the Number of Ideal Arrays](src/main/kotlin/g2301_2400/s2338_count_the_number_of_ideal_arrays)| Hard | Dynamic_Programming, Math, Number_Theory, Combinatorics | 201 | 100.00 +| 2337 |[Move Pieces to Obtain a String](src/main/kotlin/g2301_2400/s2337_move_pieces_to_obtain_a_string)| Medium | String, Two_Pointers | 261 | 100.00 +| 2336 |[Smallest Number in Infinite Set](src/main/kotlin/g2301_2400/s2336_smallest_number_in_infinite_set)| Medium | Hash_Table, Design, Heap_Priority_Queue | 308 | 95.45 +| 2335 |[Minimum Amount of Time to Fill Cups](src/main/kotlin/g2301_2400/s2335_minimum_amount_of_time_to_fill_cups)| Easy | Array, Greedy, Heap_Priority_Queue | 140 | 100.00 +| 2334 |[Subarray With Elements Greater Than Varying Threshold](src/main/kotlin/g2301_2400/s2334_subarray_with_elements_greater_than_varying_threshold)| Hard | Array, Stack, Union_Find, Monotonic_Stack | 889 | 100.00 +| 2333 |[Minimum Sum of Squared Difference](src/main/kotlin/g2301_2400/s2333_minimum_sum_of_squared_difference)| Medium | Array, Math, Sorting, Heap_Priority_Queue | 502 | 100.00 +| 2332 |[The Latest Time to Catch a Bus](src/main/kotlin/g2301_2400/s2332_the_latest_time_to_catch_a_bus)| Medium | Array, Sorting, Binary_Search, Two_Pointers | 522 | 75.00 +| 2331 |[Evaluate Boolean Binary Tree](src/main/kotlin/g2301_2400/s2331_evaluate_boolean_binary_tree)| Easy | Depth_First_Search, Tree, Binary_Search | 199 | 91.67 +| 2328 |[Number of Increasing Paths in a Grid](src/main/kotlin/g2301_2400/s2328_number_of_increasing_paths_in_a_grid)| Hard | Array, Dynamic_Programming, Depth_First_Search, Breadth_First_Search, Matrix, Graph, Memoization, Topological_Sort | 689 | 79.53 +| 2327 |[Number of People Aware of a Secret](src/main/kotlin/g2301_2400/s2327_number_of_people_aware_of_a_secret)| Medium | Dynamic_Programming, Simulation, Queue | 121 | 100.00 +| 2326 |[Spiral Matrix IV](src/main/kotlin/g2301_2400/s2326_spiral_matrix_iv)| Medium | Array, Matrix, Simulation, Linked_List | 908 | 66.67 +| 2325 |[Decode the Message](src/main/kotlin/g2301_2400/s2325_decode_the_message)| Easy | String, Hash_Table | 169 | 96.88 +| 2322 |[Minimum Score After Removals on a Tree](src/main/kotlin/g2301_2400/s2322_minimum_score_after_removals_on_a_tree)| Hard | Array, Depth_First_Search, Tree, Bit_Manipulation | 412 | 100.00 +| 2321 |[Maximum Score Of Spliced Array](src/main/kotlin/g2301_2400/s2321_maximum_score_of_spliced_array)| Hard | Array, Dynamic_Programming | 497 | 50.00 +| 2320 |[Count Number of Ways to Place Houses](src/main/kotlin/g2301_2400/s2320_count_number_of_ways_to_place_houses)| Medium | Dynamic_Programming | 122 | 100.00 +| 2319 |[Check if Matrix Is X-Matrix](src/main/kotlin/g2301_2400/s2319_check_if_matrix_is_x_matrix)| Easy | Array, Matrix | 247 | 100.00 +| 2318 |[Number of Distinct Roll Sequences](src/main/kotlin/g2301_2400/s2318_number_of_distinct_roll_sequences)| Hard | Dynamic_Programming, Memoization | 441 | 100.00 +| 2317 |[Maximum XOR After Operations](src/main/kotlin/g2301_2400/s2317_maximum_xor_after_operations)| Medium | Array, Math, Bit_Manipulation | 373 | 100.00 +| 2316 |[Count Unreachable Pairs of Nodes in an Undirected Graph](src/main/kotlin/g2301_2400/s2316_count_unreachable_pairs_of_nodes_in_an_undirected_graph)| Medium | Depth_First_Search, Breadth_First_Search, Graph, Union_Find | 981 | 87.50 +| 2315 |[Count Asterisks](src/main/kotlin/g2301_2400/s2315_count_asterisks)| Easy | String | 137 | 94.44 +| 2312 |[Selling Pieces of Wood](src/main/kotlin/g2301_2400/s2312_selling_pieces_of_wood)| Hard | Backtracking | 396 | 100.00 +| 2311 |[Longest Binary Subsequence Less Than or Equal to K](src/main/kotlin/g2301_2400/s2311_longest_binary_subsequence_less_than_or_equal_to_k)| Medium | String, Dynamic_Programming, Greedy, Memoization | 140 | 100.00 +| 2310 |[Sum of Numbers With Units Digit K](src/main/kotlin/g2301_2400/s2310_sum_of_numbers_with_units_digit_k)| Medium | Math | 133 | 100.00 +| 2309 |[Greatest English Letter in Upper and Lower Case](src/main/kotlin/g2301_2400/s2309_greatest_english_letter_in_upper_and_lower_case)| Easy | Array | 154 | 87.50 +| 2306 |[Naming a Company](src/main/kotlin/g2301_2400/s2306_naming_a_company)| Hard | Array, String, Hash_Table, Bit_Manipulation, Enumeration | 590 | 100.00 +| 2305 |[Fair Distribution of Cookies](src/main/kotlin/g2301_2400/s2305_fair_distribution_of_cookies)| Medium | Array, Dynamic_Programming, Bit_Manipulation, Backtracking, Bitmask | 255 | 100.00 +| 2304 |[Minimum Path Cost in a Grid](src/main/kotlin/g2301_2400/s2304_minimum_path_cost_in_a_grid)| Medium | Array, Dynamic_Programming, Matrix | 1048 | 100.00 +| 2303 |[Calculate Amount Paid in Taxes](src/main/kotlin/g2301_2400/s2303_calculate_amount_paid_in_taxes)| Easy | Array, Simulation | 213 | 100.00 +| 2302 |[Count Subarrays With Score Less Than K](src/main/kotlin/g2301_2400/s2302_count_subarrays_with_score_less_than_k)| Hard | Array, Binary_Search, Prefix_Sum, Sliding_Window | 556 | 100.00 +| 2301 |[Match Substring After Replacement](src/main/kotlin/g2301_2400/s2301_match_substring_after_replacement)| Hard | Array, String, Hash_Table, String_Matching | 343 | 100.00 +| 2300 |[Successful Pairs of Spells and Potions](src/main/kotlin/g2201_2300/s2300_successful_pairs_of_spells_and_potions)| Medium | Array, Sorting, Binary_Search, Two_Pointers | 818 | 72.22 +| 2299 |[Strong Password Checker II](src/main/kotlin/g2201_2300/s2299_strong_password_checker_ii)| Easy | String | 139 | 100.00 +| 2296 |[Design a Text Editor](src/main/kotlin/g2201_2300/s2296_design_a_text_editor)| Hard | String, Stack, Design, Simulation, Linked_List, Doubly_Linked_List | 1268 | 100.00 +| 2295 |[Replace Elements in an Array](src/main/kotlin/g2201_2300/s2295_replace_elements_in_an_array)| Medium | Array, Hash_Table, Simulation | 913 | 100.00 +| 2294 |[Partition Array Such That Maximum Difference Is K](src/main/kotlin/g2201_2300/s2294_partition_array_such_that_maximum_difference_is_k)| Medium | Array, Sorting, Greedy | 747 | 33.33 +| 2293 |[Min Max Game](src/main/kotlin/g2201_2300/s2293_min_max_game)| Easy | Array, Simulation | 183 | 100.00 +| 2290 |[Minimum Obstacle Removal to Reach Corner](src/main/kotlin/g2201_2300/s2290_minimum_obstacle_removal_to_reach_corner)| Hard | Array, Breadth_First_Search, Matrix, Heap_Priority_Queue, Graph, Shortest_Path | 765 | 100.00 +| 2289 |[Steps to Make Array Non-decreasing](src/main/kotlin/g2201_2300/s2289_steps_to_make_array_non_decreasing)| Medium | Array, Stack, Linked_List, Monotonic_Stack | 509 | 50.00 +| 2288 |[Apply Discount to Prices](src/main/kotlin/g2201_2300/s2288_apply_discount_to_prices)| Medium | String | 465 | 100.00 +| 2287 |[Rearrange Characters to Make Target String](src/main/kotlin/g2201_2300/s2287_rearrange_characters_to_make_target_string)| Easy | String, Hash_Table, Counting | 122 | 100.00 +| 2286 |[Booking Concert Tickets in Groups](src/main/kotlin/g2201_2300/s2286_booking_concert_tickets_in_groups)| Hard | Binary_Search, Design, Segment_Tree, Binary_Indexed_Tree | 1292 | 100.00 +| 2285 |[Maximum Total Importance of Roads](src/main/kotlin/g2201_2300/s2285_maximum_total_importance_of_roads)| Medium | Sorting, Greedy, Heap_Priority_Queue, Graph | 947 | 100.00 +| 2284 |[Sender With Largest Word Count](src/main/kotlin/g2201_2300/s2284_sender_with_largest_word_count)| Medium | Array, String, Hash_Table, Counting | 672 | 100.00 +| 2283 |[Check if Number Has Equal Digit Count and Digit Value](src/main/kotlin/g2201_2300/s2283_check_if_number_has_equal_digit_count_and_digit_value)| Easy | String, Hash_Table, Counting | 136 | 100.00 +| 2281 |[Sum of Total Strength of Wizards](src/main/kotlin/g2201_2300/s2281_sum_of_total_strength_of_wizards)| Hard | Array, Stack, Prefix_Sum, Monotonic_Stack | 673 | 100.00 +| 2280 |[Minimum Lines to Represent a Line Chart](src/main/kotlin/g2201_2300/s2280_minimum_lines_to_represent_a_line_chart)| Medium | Array, Math, Sorting, Geometry, Number_Theory | 765 | 100.00 +| 2279 |[Maximum Bags With Full Capacity of Rocks](src/main/kotlin/g2201_2300/s2279_maximum_bags_with_full_capacity_of_rocks)| Medium | Array, Sorting, Greedy | 551 | 80.00 +| 2278 |[Percentage of Letter in String](src/main/kotlin/g2201_2300/s2278_percentage_of_letter_in_string)| Easy | String | 122 | 100.00 +| 2276 |[Count Integers in Intervals](src/main/kotlin/g2201_2300/s2276_count_integers_in_intervals)| Hard | Design, Ordered_Set, Segment_Tree | 1256 | 100.00 +| 2275 |[Largest Combination With Bitwise AND Greater Than Zero](src/main/kotlin/g2201_2300/s2275_largest_combination_with_bitwise_and_greater_than_zero)| Medium | Array, Hash_Table, Bit_Manipulation, Counting | 426 | 100.00 +| 2274 |[Maximum Consecutive Floors Without Special Floors](src/main/kotlin/g2201_2300/s2274_maximum_consecutive_floors_without_special_floors)| Medium | Array, Sorting | 532 | 100.00 +| 2273 |[Find Resultant Array After Removing Anagrams](src/main/kotlin/g2201_2300/s2273_find_resultant_array_after_removing_anagrams)| Easy | Array, String, Hash_Table, Sorting | 200 | 93.75 +| 2272 |[Substring With Largest Variance](src/main/kotlin/g2201_2300/s2272_substring_with_largest_variance)| Hard | Array, Dynamic_Programming | 338 | 100.00 +| 2271 |[Maximum White Tiles Covered by a Carpet](src/main/kotlin/g2201_2300/s2271_maximum_white_tiles_covered_by_a_carpet)| Medium | Array, Sorting, Greedy, Binary_Search, Prefix_Sum | 692 | 100.00 +| 2270 |[Number of Ways to Split Array](src/main/kotlin/g2201_2300/s2270_number_of_ways_to_split_array)| Medium | Array, Prefix_Sum | 627 | 36.36 +| 2269 |[Find the K-Beauty of a Number](src/main/kotlin/g2201_2300/s2269_find_the_k_beauty_of_a_number)| Easy | String, Math, Sliding_Window | 123 | 100.00 +| 2267 |[Check if There Is a Valid Parentheses String Path](src/main/kotlin/g2201_2300/s2267_check_if_there_is_a_valid_parentheses_string_path)| Hard | Array, Dynamic_Programming, Matrix | 408 | 100.00 +| 2266 |[Count Number of Texts](src/main/kotlin/g2201_2300/s2266_count_number_of_texts)| Medium | String, Hash_Table, Dynamic_Programming, Math | 216 | 100.00 +| 2265 |[Count Nodes Equal to Average of Subtree](src/main/kotlin/g2201_2300/s2265_count_nodes_equal_to_average_of_subtree)| Medium | Depth_First_Search, Tree, Binary_Tree | 174 | 100.00 +| 2264 |[Largest 3-Same-Digit Number in String](src/main/kotlin/g2201_2300/s2264_largest_3_same_digit_number_in_string)| Easy | String | 145 | 100.00 +| 2262 |[Total Appeal of A String](src/main/kotlin/g2201_2300/s2262_total_appeal_of_a_string)| Hard | String, Hash_Table, Dynamic_Programming | 202 | 100.00 +| 2261 |[K Divisible Elements Subarrays](src/main/kotlin/g2201_2300/s2261_k_divisible_elements_subarrays)| Medium | Array, Hash_Table, Trie, Enumeration, Hash_Function, Rolling_Hash | 263 | 100.00 +| 2260 |[Minimum Consecutive Cards to Pick Up](src/main/kotlin/g2201_2300/s2260_minimum_consecutive_cards_to_pick_up)| Medium | Array, Hash_Table, Sliding_Window | 646 | 33.33 +| 2259 |[Remove Digit From Number to Maximize Result](src/main/kotlin/g2201_2300/s2259_remove_digit_from_number_to_maximize_result)| Easy | String, Greedy, Enumeration | 137 | 100.00 +| 2258 |[Escape the Spreading Fire](src/main/kotlin/g2201_2300/s2258_escape_the_spreading_fire)| Hard | Array, Breadth_First_Search, Binary_Search, Matrix | 304 | 100.00 +| 2257 |[Count Unguarded Cells in the Grid](src/main/kotlin/g2201_2300/s2257_count_unguarded_cells_in_the_grid)| Medium | Array, Matrix, Simulation | 901 | 100.00 +| 2256 |[Minimum Average Difference](src/main/kotlin/g2201_2300/s2256_minimum_average_difference)| Medium | Array, Prefix_Sum | 527 | 100.00 +| 2255 |[Count Prefixes of a Given String](src/main/kotlin/g2201_2300/s2255_count_prefixes_of_a_given_string)| Easy | Array, String | 162 | 100.00 +| 2251 |[Number of Flowers in Full Bloom](src/main/kotlin/g2201_2300/s2251_number_of_flowers_in_full_bloom)| Hard | Array, Hash_Table, Sorting, Binary_Search, Prefix_Sum, Ordered_Set | 973 | 100.00 +| 2250 |[Count Number of Rectangles Containing Each Point](src/main/kotlin/g2201_2300/s2250_count_number_of_rectangles_containing_each_point)| Medium | Array, Sorting, Binary_Search, Binary_Indexed_Tree | 967 | 100.00 +| 2249 |[Count Lattice Points Inside a Circle](src/main/kotlin/g2201_2300/s2249_count_lattice_points_inside_a_circle)| Medium | Array, Hash_Table, Math, Enumeration, Geometry | 204 | 100.00 +| 2248 |[Intersection of Multiple Arrays](src/main/kotlin/g2201_2300/s2248_intersection_of_multiple_arrays)| Easy | Array, Hash_Table, Counting | 197 | 100.00 +| 2246 |[Longest Path With Different Adjacent Characters](src/main/kotlin/g2201_2300/s2246_longest_path_with_different_adjacent_characters)| Hard | Array, String, Depth_First_Search, Tree, Graph, Topological_Sort | 828 | 100.00 +| 2245 |[Maximum Trailing Zeros in a Cornered Path](src/main/kotlin/g2201_2300/s2245_maximum_trailing_zeros_in_a_cornered_path)| Medium | Array, Matrix, Prefix_Sum | 888 | 100.00 +| 2244 |[Minimum Rounds to Complete All Tasks](src/main/kotlin/g2201_2300/s2244_minimum_rounds_to_complete_all_tasks)| Medium | Array, Hash_Table, Greedy, Counting | 584 | 73.68 +| 2243 |[Calculate Digit Sum of a String](src/main/kotlin/g2201_2300/s2243_calculate_digit_sum_of_a_string)| Easy | String, Simulation | 141 | 100.00 +| 2242 |[Maximum Score of a Node Sequence](src/main/kotlin/g2201_2300/s2242_maximum_score_of_a_node_sequence)| Hard | Array, Sorting, Graph, Enumeration | 844 | 100.00 +| 2241 |[Design an ATM Machine](src/main/kotlin/g2201_2300/s2241_design_an_atm_machine)| Medium | Array, Greedy, Design | 764 | 100.00 +| 2240 |[Number of Ways to Buy Pens and Pencils](src/main/kotlin/g2201_2300/s2240_number_of_ways_to_buy_pens_and_pencils)| Medium | Math, Enumeration | 143 | 100.00 +| 2239 |[Find Closest Number to Zero](src/main/kotlin/g2201_2300/s2239_find_closest_number_to_zero)| Easy | Array | 245 | 66.67 +| 2236 |[Root Equals Sum of Children](src/main/kotlin/g2201_2300/s2236_root_equals_sum_of_children)| Easy | Tree, Binary_Tree | 141 | 86.73 +| 2235 |[Add Two Integers](src/main/kotlin/g2201_2300/s2235_add_two_integers)| Easy | Math | 131 | 65.81 +| 2234 |[Maximum Total Beauty of the Gardens](src/main/kotlin/g2201_2300/s2234_maximum_total_beauty_of_the_gardens)| Hard | Array, Sorting, Greedy, Binary_Search, Two_Pointers | 699 | 100.00 +| 2233 |[Maximum Product After K Increments](src/main/kotlin/g2201_2300/s2233_maximum_product_after_k_increments)| Medium | Array, Greedy, Heap_Priority_Queue | 766 | 100.00 +| 2232 |[Minimize Result by Adding Parentheses to Expression](src/main/kotlin/g2201_2300/s2232_minimize_result_by_adding_parentheses_to_expression)| Medium | String, Enumeration | 191 | 100.00 +| 2231 |[Largest Number After Digit Swaps by Parity](src/main/kotlin/g2201_2300/s2231_largest_number_after_digit_swaps_by_parity)| Easy | Sorting, Heap_Priority_Queue | 124 | 100.00 +| 2227 |[Encrypt and Decrypt Strings](src/main/kotlin/g2201_2300/s2227_encrypt_and_decrypt_strings)| Hard | Array, String, Hash_Table, Design, Trie | 483 | 75.00 +| 2226 |[Maximum Candies Allocated to K Children](src/main/kotlin/g2201_2300/s2226_maximum_candies_allocated_to_k_children)| Medium | Array, Binary_Search | 544 | 66.67 +| 2225 |[Find Players With Zero or One Losses](src/main/kotlin/g2201_2300/s2225_find_players_with_zero_or_one_losses)| Medium | Array, Hash_Table, Sorting, Counting | 1323 | 65.79 +| 2224 |[Minimum Number of Operations to Convert Time](src/main/kotlin/g2201_2300/s2224_minimum_number_of_operations_to_convert_time)| Easy | String, Greedy | 155 | 66.67 +| 2223 |[Sum of Scores of Built Strings](src/main/kotlin/g2201_2300/s2223_sum_of_scores_of_built_strings)| Hard | String, Binary_Search, Hash_Function, String_Matching, Rolling_Hash, Suffix_Array | 264 | 100.00 +| 2222 |[Number of Ways to Select Buildings](src/main/kotlin/g2201_2300/s2222_number_of_ways_to_select_buildings)| Medium | String, Dynamic_Programming, Prefix_Sum | 261 | 100.00 +| 2221 |[Find Triangular Sum of an Array](src/main/kotlin/g2201_2300/s2221_find_triangular_sum_of_an_array)| Medium | Array, Math, Simulation, Combinatorics | 257 | 100.00 +| 2220 |[Minimum Bit Flips to Convert Number](src/main/kotlin/g2201_2300/s2220_minimum_bit_flips_to_convert_number)| Easy | Bit_Manipulation | 131 | 70.59 +| 2218 |[Maximum Value of K Coins From Piles](src/main/kotlin/g2201_2300/s2218_maximum_value_of_k_coins_from_piles)| Hard | Array, Dynamic_Programming, Prefix_Sum | 313 | 100.00 +| 2217 |[Find Palindrome With Fixed Length](src/main/kotlin/g2201_2300/s2217_find_palindrome_with_fixed_length)| Medium | Array, Math | 541 | 100.00 +| 2216 |[Minimum Deletions to Make Array Beautiful](src/main/kotlin/g2201_2300/s2216_minimum_deletions_to_make_array_beautiful)| Medium | Array, Greedy, Stack | 567 | 66.67 +| 2215 |[Find the Difference of Two Arrays](src/main/kotlin/g2201_2300/s2215_find_the_difference_of_two_arrays)| Easy | Array, Hash_Table | 352 | 98.63 +| 2213 |[Longest Substring of One Repeating Character](src/main/kotlin/g2201_2300/s2213_longest_substring_of_one_repeating_character)| Hard | Array, String, Ordered_Set, Segment_Tree | 879 | 100.00 +| 2212 |[Maximum Points in an Archery Competition](src/main/kotlin/g2201_2300/s2212_maximum_points_in_an_archery_competition)| Medium | Array, Bit_Manipulation, Recursion, Enumeration | 210 | 100.00 +| 2211 |[Count Collisions on a Road](src/main/kotlin/g2201_2300/s2211_count_collisions_on_a_road)| Medium | String, Stack | 325 | 100.00 +| 2210 |[Count Hills and Valleys in an Array](src/main/kotlin/g2201_2300/s2210_count_hills_and_valleys_in_an_array)| Easy | Array | 153 | 80.00 +| 2209 |[Minimum White Tiles After Covering With Carpets](src/main/kotlin/g2201_2300/s2209_minimum_white_tiles_after_covering_with_carpets)| Hard | String, Dynamic_Programming, Prefix_Sum | 373 | 100.00 +| 2208 |[Minimum Operations to Halve Array Sum](src/main/kotlin/g2201_2300/s2208_minimum_operations_to_halve_array_sum)| Medium | Array, Greedy, Heap_Priority_Queue | 628 | 33.33 +| 2207 |[Maximize Number of Subsequences in a String](src/main/kotlin/g2201_2300/s2207_maximize_number_of_subsequences_in_a_string)| Medium | String, Greedy, Prefix_Sum | 295 | 100.00 +| 2206 |[Divide Array Into Equal Pairs](src/main/kotlin/g2201_2300/s2206_divide_array_into_equal_pairs)| Easy | Array, Hash_Table, Bit_Manipulation, Counting | 221 | 71.43 +| 2203 |[Minimum Weighted Subgraph With the Required Paths](src/main/kotlin/g2201_2300/s2203_minimum_weighted_subgraph_with_the_required_paths)| Hard | Graph, Shortest_Path | 1126 | 100.00 +| 2202 |[Maximize the Topmost Element After K Moves](src/main/kotlin/g2201_2300/s2202_maximize_the_topmost_element_after_k_moves)| Medium | Array, Greedy | 491 | 50.00 +| 2201 |[Count Artifacts That Can Be Extracted](src/main/kotlin/g2201_2300/s2201_count_artifacts_that_can_be_extracted)| Medium | Array, Hash_Table, Simulation | 1011 | 100.00 +| 2200 |[Find All K-Distant Indices in an Array](src/main/kotlin/g2101_2200/s2200_find_all_k_distant_indices_in_an_array)| Easy | Array | 200 | 100.00 +| 2197 |[Replace Non-Coprime Numbers in Array](src/main/kotlin/g2101_2200/s2197_replace_non_coprime_numbers_in_array)| Hard | Array, Math, Stack, Number_Theory | 917 | 100.00 +| 2196 |[Create Binary Tree From Descriptions](src/main/kotlin/g2101_2200/s2196_create_binary_tree_from_descriptions)| Medium | Array, Hash_Table, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 933 | 100.00 +| 2195 |[Append K Integers With Minimal Sum](src/main/kotlin/g2101_2200/s2195_append_k_integers_with_minimal_sum)| Medium | Array, Math, Sorting, Greedy | 542 | 100.00 +| 2194 |[Cells in a Range on an Excel Sheet](src/main/kotlin/g2101_2200/s2194_cells_in_a_range_on_an_excel_sheet)| Easy | String | 176 | 100.00 +| 2193 |[Minimum Number of Moves to Make Palindrome](src/main/kotlin/g2101_2200/s2193_minimum_number_of_moves_to_make_palindrome)| Hard | String, Greedy, Two_Pointers, Binary_Indexed_Tree | 176 | 100.00 +| 2192 |[All Ancestors of a Node in a Directed Acyclic Graph](src/main/kotlin/g2101_2200/s2192_all_ancestors_of_a_node_in_a_directed_acyclic_graph)| Medium | Depth_First_Search, Breadth_First_Search, Graph, Topological_Sort | 841 | 100.00 +| 2191 |[Sort the Jumbled Numbers](src/main/kotlin/g2101_2200/s2191_sort_the_jumbled_numbers)| Medium | Array, Sorting | 821 | 100.00 +| 2190 |[Most Frequent Number Following Key In an Array](src/main/kotlin/g2101_2200/s2190_most_frequent_number_following_key_in_an_array)| Easy | Array, Hash_Table, Counting | 188 | 100.00 +| 2188 |[Minimum Time to Finish the Race](src/main/kotlin/g2101_2200/s2188_minimum_time_to_finish_the_race)| Hard | Array, Dynamic_Programming | 1220 | 100.00 +| 2187 |[Minimum Time to Complete Trips](src/main/kotlin/g2101_2200/s2187_minimum_time_to_complete_trips)| Medium | Array, Binary_Search | 660 | 90.91 +| 2186 |[Minimum Number of Steps to Make Two Strings Anagram II](src/main/kotlin/g2101_2200/s2186_minimum_number_of_steps_to_make_two_strings_anagram_ii)| Medium | String, Hash_Table, Counting | 304 | 100.00 +| 2185 |[Counting Words With a Given Prefix](src/main/kotlin/g2101_2200/s2185_counting_words_with_a_given_prefix)| Easy | Array, String | 172 | 100.00 +| 2183 |[Count Array Pairs Divisible by K](src/main/kotlin/g2101_2200/s2183_count_array_pairs_divisible_by_k)| Hard | Array, Math, Number_Theory | 756 | 100.00 +| 2182 |[Construct String With Repeat Limit](src/main/kotlin/g2101_2200/s2182_construct_string_with_repeat_limit)| Medium | String, Greedy, Heap_Priority_Queue, Counting | 311 | 100.00 +| 2181 |[Merge Nodes in Between Zeros](src/main/kotlin/g2101_2200/s2181_merge_nodes_in_between_zeros)| Medium | Simulation, Linked_List | 980 | 25.00 +| 2180 |[Count Integers With Even Digit Sum](src/main/kotlin/g2101_2200/s2180_count_integers_with_even_digit_sum)| Easy | Math, Simulation | 126 | 100.00 +| 2179 |[Count Good Triplets in an Array](src/main/kotlin/g2101_2200/s2179_count_good_triplets_in_an_array)| Hard | Array, Binary_Search, Ordered_Set, Divide_and_Conquer, Segment_Tree, Binary_Indexed_Tree, Merge_Sort | 563 | 100.00 +| 2178 |[Maximum Split of Positive Even Integers](src/main/kotlin/g2101_2200/s2178_maximum_split_of_positive_even_integers)| Medium | Math, Greedy | 486 | 55.56 +| 2177 |[Find Three Consecutive Integers That Sum to a Given Number](src/main/kotlin/g2101_2200/s2177_find_three_consecutive_integers_that_sum_to_a_given_number)| Medium | Math, Simulation | 160 | 100.00 +| 2176 |[Count Equal and Divisible Pairs in an Array](src/main/kotlin/g2101_2200/s2176_count_equal_and_divisible_pairs_in_an_array)| Easy | Array | 179 | 69.23 +| 2172 |[Maximum AND Sum of Array](src/main/kotlin/g2101_2200/s2172_maximum_and_sum_of_array)| Hard | Array, Dynamic_Programming, Bit_Manipulation, Bitmask | 165 | 100.00 +| 2171 |[Removing Minimum Number of Magic Beans](src/main/kotlin/g2101_2200/s2171_removing_minimum_number_of_magic_beans)| Medium | Array, Sorting, Prefix_Sum | 728 | 100.00 +| 2170 |[Minimum Operations to Make the Array Alternating](src/main/kotlin/g2101_2200/s2170_minimum_operations_to_make_the_array_alternating)| Medium | Array, Hash_Table, Greedy, Counting | 531 | 100.00 +| 2169 |[Count Operations to Obtain Zero](src/main/kotlin/g2101_2200/s2169_count_operations_to_obtain_zero)| Easy | Math, Simulation | 127 | 77.78 +| 2167 |[Minimum Time to Remove All Cars Containing Illegal Goods](src/main/kotlin/g2101_2200/s2167_minimum_time_to_remove_all_cars_containing_illegal_goods)| Hard | String, Dynamic_Programming | 312 | 100.00 +| 2166 |[Design Bitset](src/main/kotlin/g2101_2200/s2166_design_bitset)| Medium | Array, Hash_Table, Design | 1036 | 100.00 +| 2165 |[Smallest Value of the Rearranged Number](src/main/kotlin/g2101_2200/s2165_smallest_value_of_the_rearranged_number)| Medium | Math, Sorting | 129 | 100.00 +| 2164 |[Sort Even and Odd Indices Independently](src/main/kotlin/g2101_2200/s2164_sort_even_and_odd_indices_independently)| Easy | Array, Sorting | 200 | 100.00 +| 2163 |[Minimum Difference in Sums After Removal of Elements](src/main/kotlin/g2101_2200/s2163_minimum_difference_in_sums_after_removal_of_elements)| Hard | Array, Dynamic_Programming, Heap_Priority_Queue | 854 | 100.00 +| 2162 |[Minimum Cost to Set Cooking Time](src/main/kotlin/g2101_2200/s2162_minimum_cost_to_set_cooking_time)| Medium | Math, Enumeration | 134 | 100.00 +| 2161 |[Partition Array According to Given Pivot](src/main/kotlin/g2101_2200/s2161_partition_array_according_to_given_pivot)| Medium | Array, Two_Pointers, Simulation | 859 | 46.15 +| 2160 |[Minimum Sum of Four Digit Number After Splitting Digits](src/main/kotlin/g2101_2200/s2160_minimum_sum_of_four_digit_number_after_splitting_digits)| Easy | Math, Sorting, Greedy | 133 | 88.24 +| 2157 |[Groups of Strings](src/main/kotlin/g2101_2200/s2157_groups_of_strings)| Hard | String, Bit_Manipulation, Union_Find | 930 | 100.00 +| 2156 |[Find Substring With Given Hash Value](src/main/kotlin/g2101_2200/s2156_find_substring_with_given_hash_value)| Hard | String, Sliding_Window, Hash_Function, Rolling_Hash | 248 | 100.00 +| 2155 |[All Divisions With the Highest Score of a Binary Array](src/main/kotlin/g2101_2200/s2155_all_divisions_with_the_highest_score_of_a_binary_array)| Medium | Array | 1171 | 100.00 +| 2154 |[Keep Multiplying Found Values by Two](src/main/kotlin/g2101_2200/s2154_keep_multiplying_found_values_by_two)| Easy | Array, Hash_Table, Sorting, Simulation | 183 | 85.71 +| 2151 |[Maximum Good People Based on Statements](src/main/kotlin/g2101_2200/s2151_maximum_good_people_based_on_statements)| Hard | Array, Bit_Manipulation, Backtracking, Enumeration | 308 | 100.00 +| 2150 |[Find All Lonely Numbers in the Array](src/main/kotlin/g2101_2200/s2150_find_all_lonely_numbers_in_the_array)| Medium | Array, Hash_Table, Counting | 1045 | 50.00 +| 2149 |[Rearrange Array Elements by Sign](src/main/kotlin/g2101_2200/s2149_rearrange_array_elements_by_sign)| Medium | Array, Two_Pointers, Simulation | 873 | 42.86 +| 2148 |[Count Elements With Strictly Smaller and Greater Elements](src/main/kotlin/g2101_2200/s2148_count_elements_with_strictly_smaller_and_greater_elements)| Easy | Array, Sorting | 148 | 83.33 +| 2147 |[Number of Ways to Divide a Long Corridor](src/main/kotlin/g2101_2200/s2147_number_of_ways_to_divide_a_long_corridor)| Hard | String, Dynamic_Programming, Math | 361 | 100.00 +| 2146 |[K Highest Ranked Items Within a Price Range](src/main/kotlin/g2101_2200/s2146_k_highest_ranked_items_within_a_price_range)| Medium | Array, Sorting, Breadth_First_Search, Matrix, Heap_Priority_Queue | 1373 | 100.00 +| 2145 |[Count the Hidden Sequences](src/main/kotlin/g2101_2200/s2145_count_the_hidden_sequences)| Medium | Array, Prefix_Sum | 641 | 100.00 +| 2144 |[Minimum Cost of Buying Candies With Discount](src/main/kotlin/g2101_2200/s2144_minimum_cost_of_buying_candies_with_discount)| Easy | Array, Sorting, Greedy | 169 | 75.00 +| 2141 |[Maximum Running Time of N Computers](src/main/kotlin/g2101_2200/s2141_maximum_running_time_of_n_computers)| Hard | Array, Sorting, Greedy | ch | ch +| 2140 |[Solving Questions With Brainpower](src/main/kotlin/g2101_2200/s2140_solving_questions_with_brainpower)| Medium | Array, Dynamic_Programming | 753 | 66.97 +| 2139 |[Minimum Moves to Reach Target Score](src/main/kotlin/g2101_2200/s2139_minimum_moves_to_reach_target_score)| Medium | Math, Greedy | 123 | 100.00 +| 2138 |[Divide a String Into Groups of Size k](src/main/kotlin/g2101_2200/s2138_divide_a_string_into_groups_of_size_k)| Easy | String, Simulation | 173 | 75.00 +| 2136 |[Earliest Possible Day of Full Bloom](src/main/kotlin/g2101_2200/s2136_earliest_possible_day_of_full_bloom)| Hard | Array, Sorting, Greedy | 968 | 100.00 +| 2135 |[Count Words Obtained After Adding a Letter](src/main/kotlin/g2101_2200/s2135_count_words_obtained_after_adding_a_letter)| Medium | Array, String, Hash_Table, Sorting, Bit_Manipulation | 556 | 100.00 +| 2134 |[Minimum Swaps to Group All 1's Together II](src/main/kotlin/g2101_2200/s2134_minimum_swaps_to_group_all_1s_together_ii)| Medium | Array, Sliding_Window | 465 | 33.33 +| 2133 |[Check if Every Row and Column Contains All Numbers](src/main/kotlin/g2101_2200/s2133_check_if_every_row_and_column_contains_all_numbers)| Easy | Array, Hash_Table, Matrix | 404 | 100.00 +| 2132 |[Stamping the Grid](src/main/kotlin/g2101_2200/s2132_stamping_the_grid)| Hard | Array, Greedy, Matrix, Prefix_Sum | 1158 | 100.00 +| 2131 |[Longest Palindrome by Concatenating Two Letter Words](src/main/kotlin/g2101_2200/s2131_longest_palindrome_by_concatenating_two_letter_words)| Medium | Array, String, Hash_Table, Greedy, Counting, Level_2_Day_5_Greedy | 607 | 90.00 +| 2130 |[Maximum Twin Sum of a Linked List](src/main/kotlin/g2101_2200/s2130_maximum_twin_sum_of_a_linked_list)| Medium | Two_Pointers, Stack, Linked_List | 534 | 16.77 +| 2129 |[Capitalize the Title](src/main/kotlin/g2101_2200/s2129_capitalize_the_title)| Easy | String | 140 | 100.00 +| 2127 |[Maximum Employees to Be Invited to a Meeting](src/main/kotlin/g2101_2200/s2127_maximum_employees_to_be_invited_to_a_meeting)| Hard | Depth_First_Search, Graph, Topological_Sort | 572 | 100.00 +| 2126 |[Destroying Asteroids](src/main/kotlin/g2101_2200/s2126_destroying_asteroids)| Medium | Array, Sorting, Greedy | 560 | 100.00 +| 2125 |[Number of Laser Beams in a Bank](src/main/kotlin/g2101_2200/s2125_number_of_laser_beams_in_a_bank)| Medium | Array, String, Math, Matrix | 297 | 100.00 +| 2124 |[Check if All A's Appears Before All B's](src/main/kotlin/g2101_2200/s2124_check_if_all_as_appears_before_all_bs)| Easy | String | 136 | 87.50 +| 2122 |[Recover the Original Array](src/main/kotlin/g2101_2200/s2122_recover_the_original_array)| Hard | Array, Hash_Table, Sorting, Enumeration | 299 | 100.00 +| 2121 |[Intervals Between Identical Elements](src/main/kotlin/g2101_2200/s2121_intervals_between_identical_elements)| Medium | Array, Hash_Table, Prefix_Sum | 1022 | 100.00 +| 2120 |[Execution of All Suffix Instructions Staying in a Grid](src/main/kotlin/g2101_2200/s2120_execution_of_all_suffix_instructions_staying_in_a_grid)| Medium | String, Simulation | 215 | 100.00 +| 2119 |[A Number After a Double Reversal](src/main/kotlin/g2101_2200/s2119_a_number_after_a_double_reversal)| Easy | Math | 127 | 89.47 +| 2117 |[Abbreviating the Product of a Range](src/main/kotlin/g2101_2200/s2117_abbreviating_the_product_of_a_range)| Hard | Math | 232 | 100.00 +| 2116 |[Check if a Parentheses String Can Be Valid](src/main/kotlin/g2101_2200/s2116_check_if_a_parentheses_string_can_be_valid)| Medium | String, Greedy, Stack | 315 | 42.86 +| 2115 |[Find All Possible Recipes from Given Supplies](src/main/kotlin/g2101_2200/s2115_find_all_possible_recipes_from_given_supplies)| Medium | Array, String, Hash_Table, Graph, Topological_Sort | 514 | 100.00 +| 2114 |[Maximum Number of Words Found in Sentences](src/main/kotlin/g2101_2200/s2114_maximum_number_of_words_found_in_sentences)| Easy | Array, String | 183 | 88.64 +| 2111 |[Minimum Operations to Make the Array K-Increasing](src/main/kotlin/g2101_2200/s2111_minimum_operations_to_make_the_array_k_increasing)| Hard | Array, Binary_Search | 558 | 100.00 +| 2110 |[Number of Smooth Descent Periods of a Stock](src/main/kotlin/g2101_2200/s2110_number_of_smooth_descent_periods_of_a_stock)| Medium | Array, Dynamic_Programming, Math | 582 | 100.00 +| 2109 |[Adding Spaces to a String](src/main/kotlin/g2101_2200/s2109_adding_spaces_to_a_string)| Medium | Array, String, Simulation | 624 | 100.00 +| 2108 |[Find First Palindromic String in the Array](src/main/kotlin/g2101_2200/s2108_find_first_palindromic_string_in_the_array)| Easy | Array, String, Two_Pointers | 242 | 100.00 +| 2106 |[Maximum Fruits Harvested After at Most K Steps](src/main/kotlin/g2101_2200/s2106_maximum_fruits_harvested_after_at_most_k_steps)| Hard | Array, Binary_Search, Prefix_Sum, Sliding_Window | 816 | 100.00 +| 2105 |[Watering Plants II](src/main/kotlin/g2101_2200/s2105_watering_plants_ii)| Medium | Array, Two_Pointers, Simulation | 531 | 50.00 +| 2104 |[Sum of Subarray Ranges](src/main/kotlin/g2101_2200/s2104_sum_of_subarray_ranges)| Medium | Array, Stack, Monotonic_Stack | 212 | 100.00 +| 2103 |[Rings and Rods](src/main/kotlin/g2101_2200/s2103_rings_and_rods)| Easy | String, Hash_Table | 131 | 89.47 +| 2102 |[Sequentially Ordinal Rank Tracker](src/main/kotlin/g2101_2200/s2102_sequentially_ordinal_rank_tracker)| Hard | Design, Heap_Priority_Queue, Ordered_Set, Data_Stream | 1208 | 100.00 +| 2101 |[Detonate the Maximum Bombs](src/main/kotlin/g2101_2200/s2101_detonate_the_maximum_bombs)| Medium | Array, Math, Depth_First_Search, Breadth_First_Search, Graph, Geometry | 262 | 98.96 +| 2100 |[Find Good Days to Rob the Bank](src/main/kotlin/g2001_2100/s2100_find_good_days_to_rob_the_bank)| Medium | Array, Dynamic_Programming, Prefix_Sum | 695 | 100.00 +| 2099 |[Find Subsequence of Length K With the Largest Sum](src/main/kotlin/g2001_2100/s2099_find_subsequence_of_length_k_with_the_largest_sum)| Easy | Array, Hash_Table, Sorting, Heap_Priority_Queue | 203 | 100.00 +| 2097 |[Valid Arrangement of Pairs](src/main/kotlin/g2001_2100/s2097_valid_arrangement_of_pairs)| Hard | Depth_First_Search, Graph, Eulerian_Circuit | 2120 | 100.00 +| 2096 |[Step-By-Step Directions From a Binary Tree Node to Another](src/main/kotlin/g2001_2100/s2096_step_by_step_directions_from_a_binary_tree_node_to_another)| Medium | String, Depth_First_Search, Tree, Binary_Tree | 690 | 93.33 +| 2095 |[Delete the Middle Node of a Linked List](src/main/kotlin/g2001_2100/s2095_delete_the_middle_node_of_a_linked_list)| Medium | Two_Pointers, Linked_List | 1115 | 50.00 +| 2094 |[Finding 3-Digit Even Numbers](src/main/kotlin/g2001_2100/s2094_finding_3_digit_even_numbers)| Easy | Array, Hash_Table, Sorting, Enumeration | 181 | 100.00 +| 2092 |[Find All People With Secret](src/main/kotlin/g2001_2100/s2092_find_all_people_with_secret)| Hard | Sorting, Depth_First_Search, Breadth_First_Search, Graph, Union_Find | 1086 | 100.00 +| 2091 |[Removing Minimum and Maximum From Array](src/main/kotlin/g2001_2100/s2091_removing_minimum_and_maximum_from_array)| Medium | Array, Greedy | 607 | 100.00 +| 2090 |[K Radius Subarray Averages](src/main/kotlin/g2001_2100/s2090_k_radius_subarray_averages)| Medium | Array, Sliding_Window | 874 | 85.63 +| 2089 |[Find Target Indices After Sorting Array](src/main/kotlin/g2001_2100/s2089_find_target_indices_after_sorting_array)| Easy | Array, Sorting, Binary_Search | 180 | 90.48 +| 2088 |[Count Fertile Pyramids in a Land](src/main/kotlin/g2001_2100/s2088_count_fertile_pyramids_in_a_land)| Hard | Array, Dynamic_Programming, Matrix | 489 | 100.00 +| 2087 |[Minimum Cost Homecoming of a Robot in a Grid](src/main/kotlin/g2001_2100/s2087_minimum_cost_homecoming_of_a_robot_in_a_grid)| Medium | Array, Greedy, Matrix | 672 | 100.00 +| 2086 |[Minimum Number of Buckets Required to Collect Rainwater from Houses](src/main/kotlin/g2001_2100/s2086_minimum_number_of_food_buckets_to_feed_the_hamsters)| Medium | String, Dynamic_Programming, Greedy | 208 | 100.00 +| 2085 |[Count Common Words With One Occurrence](src/main/kotlin/g2001_2100/s2085_count_common_words_with_one_occurrence)| Easy | Array, String, Hash_Table, Counting | 192 | 100.00 +| 2081 |[Sum of k-Mirror Numbers](src/main/kotlin/g2001_2100/s2081_sum_of_k_mirror_numbers)| Hard | Math, Enumeration | 455 | 100.00 +| 2080 |[Range Frequency Queries](src/main/kotlin/g2001_2100/s2080_range_frequency_queries)| Medium | Array, Hash_Table, Binary_Search, Design, Segment_Tree | 1102 | 100.00 +| 2079 |[Watering Plants](src/main/kotlin/g2001_2100/s2079_watering_plants)| Medium | Array | 157 | 100.00 +| 2078 |[Two Furthest Houses With Different Colors](src/main/kotlin/g2001_2100/s2078_two_furthest_houses_with_different_colors)| Easy | Array, Greedy | 131 | 100.00 +| 2076 |[Process Restricted Friend Requests](src/main/kotlin/g2001_2100/s2076_process_restricted_friend_requests)| Hard | Graph, Union_Find | 355 | 100.00 +| 2075 |[Decode the Slanted Ciphertext](src/main/kotlin/g2001_2100/s2075_decode_the_slanted_ciphertext)| Medium | String, Simulation | 418 | 100.00 +| 2074 |[Reverse Nodes in Even Length Groups](src/main/kotlin/g2001_2100/s2074_reverse_nodes_in_even_length_groups)| Medium | Linked_List | 1197 | 50.00 +| 2073 |[Time Needed to Buy Tickets](src/main/kotlin/g2001_2100/s2073_time_needed_to_buy_tickets)| Easy | Array, Simulation, Queue | 145 | 100.00 +| 2071 |[Maximum Number of Tasks You Can Assign](src/main/kotlin/g2001_2100/s2071_maximum_number_of_tasks_you_can_assign)| Hard | Array, Sorting, Greedy, Binary_Search, Queue, Monotonic_Queue | 747 | 100.00 +| 2070 |[Most Beautiful Item for Each Query](src/main/kotlin/g2001_2100/s2070_most_beautiful_item_for_each_query)| Medium | Array, Sorting, Binary_Search | 747 | 100.00 +| 2069 |[Walking Robot Simulation II](src/main/kotlin/g2001_2100/s2069_walking_robot_simulation_ii)| Medium | Design, Simulation | 636 | 100.00 +| 2068 |[Check Whether Two Strings are Almost Equivalent](src/main/kotlin/g2001_2100/s2068_check_whether_two_strings_are_almost_equivalent)| Easy | String, Hash_Table, Counting | 131 | 100.00 +| 2065 |[Maximum Path Quality of a Graph](src/main/kotlin/g2001_2100/s2065_maximum_path_quality_of_a_graph)| Hard | Array, Graph, Backtracking | 429 | 100.00 +| 2064 |[Minimized Maximum of Products Distributed to Any Store](src/main/kotlin/g2001_2100/s2064_minimized_maximum_of_products_distributed_to_any_store)| Medium | Array, Binary_Search | 609 | 100.00 +| 2063 |[Vowels of All Substrings](src/main/kotlin/g2001_2100/s2063_vowels_of_all_substrings)| Medium | String, Dynamic_Programming, Math, Combinatorics | 206 | 100.00 +| 2062 |[Count Vowel Substrings of a String](src/main/kotlin/g2001_2100/s2062_count_vowel_substrings_of_a_string)| Easy | String, Hash_Table | 216 | 60.00 +| 2060 |[Check if an Original String Exists Given Two Encoded Strings](src/main/kotlin/g2001_2100/s2060_check_if_an_original_string_exists_given_two_encoded_strings)| Hard | String, Dynamic_Programming | 1219 | 100.00 +| 2059 |[Minimum Operations to Convert Number](src/main/kotlin/g2001_2100/s2059_minimum_operations_to_convert_number)| Medium | Array, Breadth_First_Search | 285 | 66.67 +| 2058 |[Find the Minimum and Maximum Number of Nodes Between Critical Points](src/main/kotlin/g2001_2100/s2058_find_the_minimum_and_maximum_number_of_nodes_between_critical_points)| Medium | Linked_List | 602 | 50.00 +| 2057 |[Smallest Index With Equal Value](src/main/kotlin/g2001_2100/s2057_smallest_index_with_equal_value)| Easy | Array | 178 | 100.00 +| 2056 |[Number of Valid Move Combinations On Chessboard](src/main/kotlin/g2001_2100/s2056_number_of_valid_move_combinations_on_chessboard)| Hard | Array, String, Simulation, Backtracking | 600 | 100.00 +| 2055 |[Plates Between Candles](src/main/kotlin/g2001_2100/s2055_plates_between_candles)| Medium | Array, String, Binary_Search, Prefix_Sum | 831 | 100.00 +| 2054 |[Two Best Non-Overlapping Events](src/main/kotlin/g2001_2100/s2054_two_best_non_overlapping_events)| Medium | Array, Dynamic_Programming, Sorting, Binary_Search, Heap_Priority_Queue | 851 | 100.00 +| 2053 |[Kth Distinct String in an Array](src/main/kotlin/g2001_2100/s2053_kth_distinct_string_in_an_array)| Easy | Array, String, Hash_Table, Counting | 181 | 90.00 | 2050 |[Parallel Courses III](src/main/kotlin/g2001_2100/s2050_parallel_courses_iii)| Hard | Dynamic_Programming, Graph, Topological_Sort | 974 | 100.00 | 2049 |[Count Nodes With the Highest Score](src/main/kotlin/g2001_2100/s2049_count_nodes_with_the_highest_score)| Medium | Array, Depth_First_Search, Tree, Binary_Tree | 483 | 100.00 | 2048 |[Next Greater Numerically Balanced Number](src/main/kotlin/g2001_2100/s2048_next_greater_numerically_balanced_number)| Medium | Math, Backtracking, Enumeration | 138 | 100.00 @@ -1847,6 +2131,13 @@ | 2013 |[Detect Squares](src/main/kotlin/g2001_2100/s2013_detect_squares)| Medium | Array, Hash_Table, Design, Counting | 511 | 100.00 | 2012 |[Sum of Beauty in the Array](src/main/kotlin/g2001_2100/s2012_sum_of_beauty_in_the_array)| Medium | Array | 511 | 100.00 | 2011 |[Final Value of Variable After Performing Operations](src/main/kotlin/g2001_2100/s2011_final_value_of_variable_after_performing_operations)| Easy | Array, String, Simulation | 178 | 44.55 +| 2009 |[Minimum Number of Operations to Make Array Continuous](src/main/kotlin/g2001_2100/s2009_minimum_number_of_operations_to_make_array_continuous)| Hard | Array, Binary_Search | 603 | 100.00 +| 2008 |[Maximum Earnings From Taxi](src/main/kotlin/g2001_2100/s2008_maximum_earnings_from_taxi)| Medium | Array, Dynamic_Programming, Sorting, Binary_Search | 1008 | 100.00 +| 2007 |[Find Original Array From Doubled Array](src/main/kotlin/g2001_2100/s2007_find_original_array_from_doubled_array)| Medium | Array, Hash_Table, Sorting, Greedy | 753 | 100.00 +| 2006 |[Count Number of Pairs With Absolute Difference K](src/main/kotlin/g2001_2100/s2006_count_number_of_pairs_with_absolute_difference_k)| Easy | Array, Hash_Table, Counting | 186 | 100.00 +| 2003 |[Smallest Missing Genetic Value in Each Subtree](src/main/kotlin/g2001_2100/s2003_smallest_missing_genetic_value_in_each_subtree)| Hard | Dynamic_Programming, Depth_First_Search, Tree, Union_Find | 984 | 100.00 +| 2002 |[Maximum Product of the Length of Two Palindromic Subsequences](src/main/kotlin/g2001_2100/s2002_maximum_product_of_the_length_of_two_palindromic_subsequences)| Medium | String, Dynamic_Programming, Bit_Manipulation, Backtracking, Bitmask | 389 | 100.00 +| 2001 |[Number of Pairs of Interchangeable Rectangles](src/main/kotlin/g2001_2100/s2001_number_of_pairs_of_interchangeable_rectangles)| Medium | Array, Hash_Table, Math, Counting, Number_Theory | 797 | 100.00 | 2000 |[Reverse Prefix of Word](src/main/kotlin/g1901_2000/s2000_reverse_prefix_of_word)| Easy | String, Two_Pointers | 164 | 31.25 | 1998 |[GCD Sort of an Array](src/main/kotlin/g1901_2000/s1998_gcd_sort_of_an_array)| Hard | Array, Math, Sorting, Union_Find | 437 | 100.00 | 1997 |[First Day Where You Have Been in All the Rooms](src/main/kotlin/g1901_2000/s1997_first_day_where_you_have_been_in_all_the_rooms)| Medium | Array, Dynamic_Programming | 572 | 100.00 @@ -1864,6 +2155,7 @@ | 1981 |[Minimize the Difference Between Target and Chosen Elements](src/main/kotlin/g1901_2000/s1981_minimize_the_difference_between_target_and_chosen_elements)| Medium | Array, Dynamic_Programming, Matrix | 588 | 100.00 | 1980 |[Find Unique Binary String](src/main/kotlin/g1901_2000/s1980_find_unique_binary_string)| Medium | Array, String, Backtracking | 186 | 50.00 | 1979 |[Find Greatest Common Divisor of Array](src/main/kotlin/g1901_2000/s1979_find_greatest_common_divisor_of_array)| Easy | Array, Math, Number_Theory | 172 | 100.00 +| 1978 |[Employees Whose Manager Left the Company](src/main/kotlin/g1901_2000/s1978_employees_whose_manager_left_the_company)| Easy | Database | 686 | 64.74 | 1977 |[Number of Ways to Separate Numbers](src/main/kotlin/g1901_2000/s1977_number_of_ways_to_separate_numbers)| Hard | String, Dynamic_Programming, Suffix_Array | 199 | 100.00 | 1976 |[Number of Ways to Arrive at Destination](src/main/kotlin/g1901_2000/s1976_number_of_ways_to_arrive_at_destination)| Medium | Dynamic_Programming, Graph, Topological_Sort, Shortest_Path | 282 | 100.00 | 1975 |[Maximum Matrix Sum](src/main/kotlin/g1901_2000/s1975_maximum_matrix_sum)| Medium | Array, Greedy, Matrix | 535 | 100.00 diff --git a/src/main/kotlin/g1901_2000/s1978_employees_whose_manager_left_the_company/readme.md b/src/main/kotlin/g1901_2000/s1978_employees_whose_manager_left_the_company/readme.md new file mode 100644 index 00000000..84893d21 --- /dev/null +++ b/src/main/kotlin/g1901_2000/s1978_employees_whose_manager_left_the_company/readme.md @@ -0,0 +1,66 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 1978\. Employees Whose Manager Left the Company + +Easy + +SQL Schema + +Table: `Employees` + + +-------------+----------+ + | Column Name | Type | + +-------------+----------+ + | employee_id | int | + | name | varchar | + | manager_id | int | + | salary | int | + +-------------+----------+ + +employee_id is the primary key for this table. This table contains information about the employees, their salary, and the ID of their manager. Some employees do not have a manager (manager_id is null). + +Write an SQL query to report the IDs of the employees whose salary is strictly less than `$30000` and whose manager left the company. When a manager leaves the company, their information is deleted from the `Employees` table, but the reports still have their `manager_id` set to the manager that left. + +Return the result table ordered by `employee_id`. + +The query result format is in the following example. + +**Example 1:** + +**Input: ** Employees table: + + +-------------+-----------+------------+--------+ + | employee_id | name | manager_id | salary | + +-------------+-----------+------------+--------+ + | 3 | Mila | 9 | 60301 | + | 12 | Antonella | null | 31000 | + | 13 | Emery | null | 67084 | + | 1 | Kalel | 11 | 21241 | + | 9 | Mikaela | null | 50937 | + | 11 | Joziah | 6 | 28485 | + +-------------+-----------+------------+--------+ + +**Output:** + + +-------------+ + | employee_id | + +-------------+ + | 11 | + +-------------+ + +**Explanation:** + +The employees with a salary less than $30000 are 1 (Kalel) and 11 (Joziah). + +Kalel's manager is employee 11, who is still in the company (Joziah). + +Joziah's manager is employee 6, who left the company because there is no row for employee 6 as it was deleted. + +## Solution + +```sql +# Write your MySQL query statement below +select employee_id from employees where manager_id not in (select distinct (employee_id) from employees) +AND salary < 30000 order by employee_id +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2001_number_of_pairs_of_interchangeable_rectangles/readme.md b/src/main/kotlin/g2001_2100/s2001_number_of_pairs_of_interchangeable_rectangles/readme.md new file mode 100644 index 00000000..05f11736 --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2001_number_of_pairs_of_interchangeable_rectangles/readme.md @@ -0,0 +1,84 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2001\. Number of Pairs of Interchangeable Rectangles + +Medium + +You are given `n` rectangles represented by a **0-indexed** 2D integer array `rectangles`, where rectangles[i] = [widthi, heighti] denotes the width and height of the ith rectangle. + +Two rectangles `i` and `j` (`i < j`) are considered **interchangeable** if they have the **same** width-to-height ratio. More formally, two rectangles are **interchangeable** if widthi/heighti == widthj/heightj (using decimal division, not integer division). + +Return _the **number** of pairs of **interchangeable** rectangles in_ `rectangles`. + +**Example 1:** + +**Input:** rectangles = \[\[4,8],[3,6],[10,20],[15,30]] + +**Output:** 6 + +**Explanation:** The following are the interchangeable pairs of rectangles by index (0-indexed): + +- Rectangle 0 with rectangle 1: 4/8 == 3/6. + +- Rectangle 0 with rectangle 2: 4/8 == 10/20. + +- Rectangle 0 with rectangle 3: 4/8 == 15/30. + +- Rectangle 1 with rectangle 2: 3/6 == 10/20. + +- Rectangle 1 with rectangle 3: 3/6 == 15/30. + +- Rectangle 2 with rectangle 3: 10/20 == 15/30. + +**Example 2:** + +**Input:** rectangles = \[\[4,5],[7,8]] + +**Output:** 0 + +**Explanation:** There are no interchangeable pairs of rectangles. + +**Constraints:** + +* `n == rectangles.length` +* 1 <= n <= 105 +* `rectangles[i].length == 2` +* 1 <= widthi, heighti <= 105 + +## Solution + +```kotlin +@Suppress("NAME_SHADOWING") +class Solution { + private fun factorial(n: Long): Long { + var n = n + var m: Long = 0 + while (n > 0) { + m += n + n -= 1 + } + return m + } + + fun interchangeableRectangles(rec: Array): Long { + val ratio = DoubleArray(rec.size) + for (i in rec.indices) { + ratio[i] = rec[i][0].toDouble() / rec[i][1] + } + ratio.sort() + var res: Long = 0 + var k = 0 + for (j in 0 until ratio.size - 1) { + if (ratio[j] == ratio[j + 1]) { + k++ + } + if (ratio[j] != ratio[j + 1] || j + 2 == ratio.size) { + res += factorial(k.toLong()) + k = 0 + } + } + return res + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2002_maximum_product_of_the_length_of_two_palindromic_subsequences/readme.md b/src/main/kotlin/g2001_2100/s2002_maximum_product_of_the_length_of_two_palindromic_subsequences/readme.md new file mode 100644 index 00000000..21639f08 --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2002_maximum_product_of_the_length_of_two_palindromic_subsequences/readme.md @@ -0,0 +1,122 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2002\. Maximum Product of the Length of Two Palindromic Subsequences + +Medium + +Given a string `s`, find two **disjoint palindromic subsequences** of `s` such that the **product** of their lengths is **maximized**. The two subsequences are **disjoint** if they do not both pick a character at the same index. + +Return _the **maximum** possible **product** of the lengths of the two palindromic subsequences_. + +A **subsequence** is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters. A string is **palindromic** if it reads the same forward and backward. + +**Example 1:** + +![example-1](https://assets.leetcode.com/uploads/2021/08/24/two-palindromic-subsequences.png) + +**Input:** s = "leetcodecom" + +**Output:** 9 + +**Explanation:** An optimal solution is to choose "ete" for the 1st subsequence and "cdc" for the 2nd subsequence. + +The product of their lengths is: 3 \* 3 = 9. + +**Example 2:** + +**Input:** s = "bb" + +**Output:** 1 + +**Explanation:** An optimal solution is to choose "b" (the first character) for the 1st subsequence and "b" (the second character) for the 2nd subsequence. + +The product of their lengths is: 1 \* 1 = 1. + +**Example 3:** + +**Input:** s = "accbcaxxcxx" + +**Output:** 25 + +**Explanation:** An optimal solution is to choose "accca" for the 1st subsequence and "xxcxx" for the 2nd subsequence. + +The product of their lengths is: 5 \* 5 = 25. + +**Constraints:** + +* `2 <= s.length <= 12` +* `s` consists of lowercase English letters only. + +## Solution + +```kotlin +class Solution { + fun maxProduct(s: String): Int { + if (s.length == 2) { + return 1 + } + val list: MutableList = ArrayList() + val chars = s.toCharArray() + val visited: MutableSet = HashSet() + for (i in chars.indices) { + val mask = 1 shl i + recur(chars, State(i, i, 0, mask), list, visited) + recur(chars, State(i, i + 1, 0, mask), list, visited) + } + list.sortWith { a: State, b: State -> b.cnt - a.cnt } + var res = 1 + val explored: MutableSet = HashSet() + for (i in 0 until list.size - 1) { + if (explored.contains(i)) { + continue + } + val cur = list[i] + if (cur.cnt == 1) { + break + } + for (j in i + 1 until list.size) { + val cand = list[j] + if (cur.mask and cand.mask < 1) { + if (explored.add(j)) { + res = res.coerceAtLeast(cur.cnt * cand.cnt) + } + break + } + } + } + return res + } + + private fun recur(chars: CharArray, s: State, list: MutableList, visited: MutableSet) { + if (s.i < 0 || s.j >= chars.size) { + return + } + if (!visited.add(s)) { + return + } + if (chars[s.i] == chars[s.j]) { + val m = s.mask or (1 shl s.i) or (1 shl s.j) + val nextCnt = s.cnt + if (s.i < s.j) 2 else 1 + list.add(State(s.i, s.j, nextCnt, m)) + recur(chars, State(s.i - 1, s.j + 1, nextCnt, m), list, visited) + } + recur(chars, State(s.i - 1, s.j, s.cnt, s.mask), list, visited) + recur(chars, State(s.i, s.j + 1, s.cnt, s.mask), list, visited) + } + + private class State(var i: Int, var j: Int, var cnt: Int, var mask: Int) { + override fun equals(other: Any?): Boolean { + if (other == null || other.javaClass != this.javaClass) { + return false + } + val s = other as State + return i == s.i && j == s.j && mask == s.mask + } + + override fun hashCode(): Int { + return (i * 31 + j) * 31 + mask + } + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2003_smallest_missing_genetic_value_in_each_subtree/readme.md b/src/main/kotlin/g2001_2100/s2003_smallest_missing_genetic_value_in_each_subtree/readme.md new file mode 100644 index 00000000..b8854a34 --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2003_smallest_missing_genetic_value_in_each_subtree/readme.md @@ -0,0 +1,151 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2003\. Smallest Missing Genetic Value in Each Subtree + +Hard + +There is a **family tree** rooted at `0` consisting of `n` nodes numbered `0` to `n - 1`. You are given a **0-indexed** integer array `parents`, where `parents[i]` is the parent for node `i`. Since node `0` is the **root**, `parents[0] == -1`. + +There are 105 genetic values, each represented by an integer in the **inclusive** range [1, 105]. You are given a **0-indexed** integer array `nums`, where `nums[i]` is a **distinct** genetic value for node `i`. + +Return _an array_ `ans` _of length_ `n` _where_ `ans[i]` _is_ _the **smallest** genetic value that is **missing** from the subtree rooted at node_ `i`. + +The **subtree** rooted at a node `x` contains node `x` and all of its **descendant** nodes. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/08/23/case-1.png) + +**Input:** parents = [-1,0,0,2], nums = [1,2,3,4] + +**Output:** [5,1,1,1] + +**Explanation:** The answer for each subtree is calculated as follows: + +- 0: The subtree contains nodes [0,1,2,3] with values [1,2,3,4]. 5 is the smallest missing value. + +- 1: The subtree contains only node 1 with value 2. 1 is the smallest missing value. + +- 2: The subtree contains nodes [2,3] with values [3,4]. 1 is the smallest missing value. + +- 3: The subtree contains only node 3 with value 4. 1 is the smallest missing value. + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2021/08/23/case-2.png) + +**Input:** parents = [-1,0,1,0,3,3], nums = [5,4,6,2,1,3] + +**Output:** [7,1,1,4,2,1] + +**Explanation:** The answer for each subtree is calculated as follows: + +- 0: The subtree contains nodes [0,1,2,3,4,5] with values [5,4,6,2,1,3]. 7 is the smallest missing value. + +- 1: The subtree contains nodes [1,2] with values [4,6]. 1 is the smallest missing value. + +- 2: The subtree contains only node 2 with value 6. 1 is the smallest missing value. + +- 3: The subtree contains nodes [3,4,5] with values [2,1,3]. 4 is the smallest missing value. + +- 4: The subtree contains only node 4 with value 1. 2 is the smallest missing value. + +- 5: The subtree contains only node 5 with value 3. 1 is the smallest missing value. + +**Example 3:** + +**Input:** parents = [-1,2,3,0,2,4,1], nums = [2,3,4,5,6,7,8] + +**Output:** [1,1,1,1,1,1,1] + +**Explanation:** The value 1 is missing from all the subtrees. + +**Constraints:** + +* `n == parents.length == nums.length` +* 2 <= n <= 105 +* `0 <= parents[i] <= n - 1` for `i != 0` +* `parents[0] == -1` +* `parents` represents a valid tree. +* 1 <= nums[i] <= 105 +* Each `nums[i]` is distinct. + +## Solution + +```kotlin +@Suppress("NAME_SHADOWING") +class Solution { + fun smallestMissingValueSubtree(parents: IntArray, nums: IntArray): IntArray { + val ans = IntArray(parents.size) + val all = arrayOfNulls(parents.size) + var max = 0 + for (i in nums.indices) { + all[i] = Node(i, nums[i]) + max = max.coerceAtLeast(nums[i]) + } + for (i in 1 until parents.size) { + all[parents[i]]!!.nodes.add(all[i]) + } + solve(all[0], ans, UF(++max, nums)) + return ans + } + + private fun solve(root: Node?, ans: IntArray, uf: UF) { + var max = 1 + for (child in root!!.nodes) { + solve(child, ans, uf) + uf.union(root.`val`, child!!.`val`) + max = ans[child.idx].coerceAtLeast(max) + } + while (max <= ans.size && uf.isConnected(max, root.`val`)) { + ++max + } + ans[root.idx] = max + } + + private class Node internal constructor(var idx: Int, var `val`: Int) { + var nodes: MutableList = ArrayList() + } + + private class UF internal constructor(n: Int, nums: IntArray) { + var rank: IntArray + var parent: IntArray + + init { + rank = IntArray(n) + parent = IntArray(n) + for (m in nums) { + parent[m] = m + } + } + + private fun find(x: Int): Int { + if (x == parent[x]) { + return x + } + parent[x] = find(parent[x]) + return parent[x] + } + + fun union(x: Int, y: Int) { + var x = x + var y = y + x = find(x) + y = find(y) + if (rank[x] > rank[y]) { + parent[y] = x + } else { + parent[x] = y + if (rank[x] == rank[y]) { + rank[y]++ + } + } + } + + fun isConnected(x: Int, y: Int): Boolean { + return find(x) == find(y) + } + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2006_count_number_of_pairs_with_absolute_difference_k/readme.md b/src/main/kotlin/g2001_2100/s2006_count_number_of_pairs_with_absolute_difference_k/readme.md new file mode 100644 index 00000000..b798acb3 --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2006_count_number_of_pairs_with_absolute_difference_k/readme.md @@ -0,0 +1,77 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2006\. Count Number of Pairs With Absolute Difference K + +Easy + +Given an integer array `nums` and an integer `k`, return _the number of pairs_ `(i, j)` _where_ `i < j` _such that_ `|nums[i] - nums[j]| == k`. + +The value of `|x|` is defined as: + +* `x` if `x >= 0`. +* `-x` if `x < 0`. + +**Example 1:** + +**Input:** nums = [1,2,2,1], k = 1 + +**Output:** 4 + +**Explanation:** The pairs with an absolute difference of 1 are: + +- \[**1**,**2**,2,1] + +- \[**1**,2,**2**,1] + +- \[1,**2**,2,**1**] + +- \[1,2,**2**,**1**] + +**Example 2:** + +**Input:** nums = [1,3], k = 3 + +**Output:** 0 + +**Explanation:** There are no pairs with an absolute difference of 3. + +**Example 3:** + +**Input:** nums = [3,2,1,5,4], k = 2 + +**Output:** 3 + +**Explanation:** The pairs with an absolute difference of 2 are: + +- \[**3**,2,**1**,5,4] + +- \[**3**,2,1,**5**,4] + +- \[3,**2**,1,5,**4**] + +**Constraints:** + +* `1 <= nums.length <= 200` +* `1 <= nums[i] <= 100` +* `1 <= k <= 99` + +## Solution + +```kotlin +import kotlin.math.abs + +class Solution { + fun countKDifference(nums: IntArray, k: Int): Int { + var pairs = 0 + for (i in 0 until nums.size - 1) { + for (j in i + 1 until nums.size) { + if (abs(nums[i] - nums[j]) == k) { + pairs++ + } + } + } + return pairs + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2007_find_original_array_from_doubled_array/readme.md b/src/main/kotlin/g2001_2100/s2007_find_original_array_from_doubled_array/readme.md new file mode 100644 index 00000000..5f8fc02c --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2007_find_original_array_from_doubled_array/readme.md @@ -0,0 +1,96 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2007\. Find Original Array From Doubled Array + +Medium + +An integer array `original` is transformed into a **doubled** array `changed` by appending **twice the value** of every element in `original`, and then randomly **shuffling** the resulting array. + +Given an array `changed`, return `original` _if_ `changed` _is a **doubled** array. If_ `changed` _is not a **doubled** array, return an empty array. The elements in_ `original` _may be returned in **any** order_. + +**Example 1:** + +**Input:** changed = [1,3,4,2,6,8] + +**Output:** [1,3,4] + +**Explanation:** One possible original array could be [1,3,4]: + +- Twice the value of 1 is 1 \* 2 = 2. + +- Twice the value of 3 is 3 \* 2 = 6. + +- Twice the value of 4 is 4 \* 2 = 8. + +Other original arrays could be [4,3,1] or [3,1,4]. + +**Example 2:** + +**Input:** changed = [6,3,0,1] + +**Output:** [] + +**Explanation:** changed is not a doubled array. + +**Example 3:** + +**Input:** changed = [1] + +**Output:** [] + +**Explanation:** changed is not a doubled array. + +**Constraints:** + +* 1 <= changed.length <= 105 +* 0 <= changed[i] <= 105 + +## Solution + +```kotlin +class Solution { + fun findOriginalArray(changed: IntArray): IntArray { + if (changed.size % 2 == 1) { + return IntArray(0) + } + val a = IntArray(100001) + for (j in changed) { + a[j]++ + } + if (a[0] % 2 == 1) { + return IntArray(0) + } + val ans = IntArray(changed.size / 2) + var p = 0 + if (a[0] > 0) { + a[0] /= 2 + while (a[0] > 0) { + ans[p++] = 0 + a[0]-- + } + } + for (i in 1..100001 / 2) { + if (a[i] == 0) { + continue + } + val tmp = i * 2 + if (a[tmp] >= a[i]) { + a[tmp] = a[tmp] - a[i] + while (a[i] > 0) { + ans[p++] = i + a[i]-- + } + } else { + return IntArray(0) + } + } + for (i in 1 until a.size) { + if (a[i] != 0) { + return IntArray(0) + } + } + return ans + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2008_maximum_earnings_from_taxi/readme.md b/src/main/kotlin/g2001_2100/s2008_maximum_earnings_from_taxi/readme.md new file mode 100644 index 00000000..7965237e --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2008_maximum_earnings_from_taxi/readme.md @@ -0,0 +1,89 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2008\. Maximum Earnings From Taxi + +Medium + +There are `n` points on a road you are driving your taxi on. The `n` points on the road are labeled from `1` to `n` in the direction you are going, and you want to drive from point `1` to point `n` to make money by picking up passengers. You cannot change the direction of the taxi. + +The passengers are represented by a **0-indexed** 2D integer array `rides`, where rides[i] = [starti, endi, tipi] denotes the ith passenger requesting a ride from point starti to point endi who is willing to give a tipi dollar tip. + +For **each** passenger `i` you pick up, you **earn** endi - starti + tipi dollars. You may only drive **at most one** passenger at a time. + +Given `n` and `rides`, return _the **maximum** number of dollars you can earn by picking up the passengers optimally._ + +**Note:** You may drop off a passenger and pick up a different passenger at the same point. + +**Example 1:** + +**Input:** n = 5, rides = \[\[2,5,4],[1,5,1]] + +**Output:** 7 + +**Explanation:** We can pick up passenger 0 to earn 5 - 2 + 4 = 7 dollars. + +**Example 2:** + +**Input:** n = 20, rides = \[\[1,6,1],[3,10,2],[10,12,3],[11,12,2],[12,15,2],[13,18,1]] + +**Output:** 20 + +**Explanation:** We will pick up the following passengers: + +- Drive passenger 1 from point 3 to point 10 for a profit of 10 - 3 + 2 = 9 dollars. + +- Drive passenger 2 from point 10 to point 12 for a profit of 12 - 10 + 3 = 5 dollars. + +- Drive passenger 5 from point 13 to point 18 for a profit of 18 - 13 + 1 = 6 dollars. + +We earn 9 + 5 + 6 = 20 dollars in total. + +**Constraints:** + +* 1 <= n <= 105 +* 1 <= rides.length <= 3 * 104 +* `rides[i].length == 3` +* 1 <= starti < endi <= n +* 1 <= tipi <= 105 + +## Solution + +```kotlin +import java.util.Arrays +import java.util.PriorityQueue + +@Suppress("UNUSED_PARAMETER") +class Solution { + fun maxTaxiEarnings(n: Int, rides: Array): Long { + // Sort based on start time + Arrays.sort(rides) { a: IntArray, b: IntArray -> + a[0] - b[0] + } + var max: Long = 0 + + // Storing Long array instead of Int array, since max value is long. + // Sort based on end time + val myQueue = PriorityQueue { a: LongArray, b: LongArray -> + java.lang.Long.compare( + a[0], + b[0] + ) + } + for (i in rides.indices) { + val start = rides[i][0] + val end = rides[i][1] + val profit = end - start + java.lang.Long.valueOf(rides[i][2].toLong()) + while (myQueue.isNotEmpty() && start >= myQueue.peek()[0]) { + max = max.coerceAtLeast(myQueue.peek()[1]) + myQueue.poll() + } + myQueue.offer(longArrayOf(end.toLong(), profit + max)) + } + while (myQueue.isNotEmpty()) { + max = max.coerceAtLeast(myQueue.poll()[1]) + } + return max + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2009_minimum_number_of_operations_to_make_array_continuous/readme.md b/src/main/kotlin/g2001_2100/s2009_minimum_number_of_operations_to_make_array_continuous/readme.md new file mode 100644 index 00000000..3b280092 --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2009_minimum_number_of_operations_to_make_array_continuous/readme.md @@ -0,0 +1,83 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2009\. Minimum Number of Operations to Make Array Continuous + +Hard + +You are given an integer array `nums`. In one operation, you can replace **any** element in `nums` with **any** integer. + +`nums` is considered **continuous** if both of the following conditions are fulfilled: + +* All elements in `nums` are **unique**. +* The difference between the **maximum** element and the **minimum** element in `nums` equals `nums.length - 1`. + +For example, `nums = [4, 2, 5, 3]` is **continuous**, but `nums = [1, 2, 3, 5, 6]` is **not continuous**. + +Return _the **minimum** number of operations to make_ `nums` **_continuous_**. + +**Example 1:** + +**Input:** nums = [4,2,5,3] + +**Output:** 0 + +**Explanation:** nums is already continuous. + +**Example 2:** + +**Input:** nums = [1,2,3,5,6] + +**Output:** 1 + +**Explanation:** One possible solution is to change the last element to 4. The resulting array is [1,2,3,5,4], which is continuous. + +**Example 3:** + +**Input:** nums = [1,10,100,1000] + +**Output:** 3 + +**Explanation:** One possible solution is to: + +- Change the second element to 2. + +- Change the third element to 3. + +- Change the fourth element to 4. + +The resulting array is [1,2,3,4], which is continuous. + +**Constraints:** + +* 1 <= nums.length <= 105 +* 1 <= nums[i] <= 109 + +## Solution + +```kotlin +class Solution { + fun minOperations(nums: IntArray): Int { + nums.sort() + val n = nums.size + var duplicates = 0 + var maxContinuous = 0 + var start = 0 + var end = 0 + while (end < n) { + if (end > 0 && nums[end] == nums[end - 1]) { + duplicates++ + } + while (nums[start] + n <= nums[end]) { + start++ + if (nums[start] == nums[start - 1]) { + duplicates-- + } + } + maxContinuous = maxContinuous.coerceAtLeast(end - start + 1 - duplicates) + end++ + } + return n - maxContinuous + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2053_kth_distinct_string_in_an_array/readme.md b/src/main/kotlin/g2001_2100/s2053_kth_distinct_string_in_an_array/readme.md new file mode 100644 index 00000000..5dfb6670 --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2053_kth_distinct_string_in_an_array/readme.md @@ -0,0 +1,75 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2053\. Kth Distinct String in an Array + +Easy + +A **distinct string** is a string that is present only **once** in an array. + +Given an array of strings `arr`, and an integer `k`, return _the_ kth _**distinct string** present in_ `arr`. If there are **fewer** than `k` distinct strings, return _an **empty string**_ `""`. + +Note that the strings are considered in the **order in which they appear** in the array. + +**Example 1:** + +**Input:** arr = ["d","b","c","b","c","a"], k = 2 + +**Output:** "a" + +**Explanation:** + +The only distinct strings in arr are "d" and "a". + +"d" appears 1st, so it is the 1st distinct string. + +"a" appears 2nd, so it is the 2nd distinct string. + +Since k == 2, "a" is returned. + +**Example 2:** + +**Input:** arr = ["aaa","aa","a"], k = 1 + +**Output:** "aaa" + +**Explanation:** + +All strings in arr are distinct, so the 1st string "aaa" is returned. + +**Example 3:** + +**Input:** arr = ["a","b","a"], k = 3 + +**Output:** "" + +**Explanation:** The only distinct string is "b". Since there are fewer than 3 distinct strings, we return an empty string "". + +**Constraints:** + +* `1 <= k <= arr.length <= 1000` +* `1 <= arr[i].length <= 5` +* `arr[i]` consists of lowercase English letters. + +## Solution + +```kotlin +class Solution { + fun kthDistinct(arr: Array, k: Int): String { + val m: MutableMap = HashMap() + for (value in arr) { + m[value] = m.getOrDefault(value, 0) + 1 + } + var c = 0 + for (s in arr) { + if (m[s] == 1) { + ++c + if (c == k) { + return s + } + } + } + return "" + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2054_two_best_non_overlapping_events/readme.md b/src/main/kotlin/g2001_2100/s2054_two_best_non_overlapping_events/readme.md new file mode 100644 index 00000000..76c3e631 --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2054_two_best_non_overlapping_events/readme.md @@ -0,0 +1,89 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2054\. Two Best Non-Overlapping Events + +Medium + +You are given a **0-indexed** 2D integer array of `events` where events[i] = [startTimei, endTimei, valuei]. The ith event starts at startTimei and ends at endTimei, and if you attend this event, you will receive a value of valuei. You can choose **at most** **two** **non-overlapping** events to attend such that the sum of their values is **maximized**. + +Return _this **maximum** sum._ + +Note that the start time and end time is **inclusive**: that is, you cannot attend two events where one of them starts and the other ends at the same time. More specifically, if you attend an event with end time `t`, the next event must start at or after `t + 1`. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/09/21/picture5.png) + +**Input:** events = \[\[1,3,2],[4,5,2],[2,4,3]] + +**Output:** 4 + +**Explanation:** Choose the green events, 0 and 1 for a sum of 2 + 2 = 4. + +**Example 2:** + +![Example 1 Diagram](https://assets.leetcode.com/uploads/2021/09/21/picture1.png) + +**Input:** events = \[\[1,3,2],[4,5,2],[1,5,5]] + +**Output:** 5 + +**Explanation:** Choose event 2 for a sum of 5. + +**Example 3:** + +![](https://assets.leetcode.com/uploads/2021/09/21/picture3.png) + +**Input:** events = \[\[1,5,3],[1,5,1],[6,6,5]] + +**Output:** 8 + +**Explanation:** Choose events 0 and 2 for a sum of 3 + 5 = 8. + +**Constraints:** + +* 2 <= events.length <= 105 +* `events[i].length == 3` +* 1 <= startTimei <= endTimei <= 109 +* 1 <= valuei <= 106 + +## Solution + +```kotlin +import java.util.Arrays + +class Solution { + fun maxTwoEvents(events: Array): Int { + Arrays.sort(events) { a: IntArray, b: IntArray -> a[0] - b[0] } + val max = IntArray(events.size) + for (i in events.indices.reversed()) { + if (i == events.size - 1) { + max[i] = events[i][2] + } else { + max[i] = events[i][2].coerceAtLeast(max[i + 1]) + } + } + var ans = 0 + for (i in events.indices) { + val end = events[i][1] + var left = i + 1 + var right = events.size + while (left < right) { + val mid = left + (right - left) / 2 + if (events[mid][0] <= end) { + left = mid + 1 + } else { + right = mid + } + } + var value = events[i][2] + if (right < events.size) { + value += max[right] + } + ans = ans.coerceAtLeast(value) + } + return ans + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2055_plates_between_candles/readme.md b/src/main/kotlin/g2001_2100/s2055_plates_between_candles/readme.md new file mode 100644 index 00000000..41f4ca7d --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2055_plates_between_candles/readme.md @@ -0,0 +1,89 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2055\. Plates Between Candles + +Medium + +There is a long table with a line of plates and candles arranged on top of it. You are given a **0-indexed** string `s` consisting of characters `'*'` and `'|'` only, where a `'*'` represents a **plate** and a `'|'` represents a **candle**. + +You are also given a **0-indexed** 2D integer array `queries` where queries[i] = [lefti, righti] denotes the **substring** s[lefti...righti] (**inclusive**). For each query, you need to find the **number** of plates **between candles** that are **in the substring**. A plate is considered **between candles** if there is at least one candle to its left **and** at least one candle to its right **in the substring**. + +* For example, `s = "||**||**|*"`, and a query `[3, 8]` denotes the substring `"*||******|"`. The number of plates between candles in this substring is `2`, as each of the two plates has at least one candle **in the substring** to its left **and** right. + +Return _an integer array_ `answer` _where_ `answer[i]` _is the answer to the_ ith _query_. + +**Example 1:** + +![ex-1](https://assets.leetcode.com/uploads/2021/10/04/ex-1.png) + +**Input:** s = "\*\*\|\*\*\|\*\*\*\|", queries = \[\[2,5],[5,9]] + +**Output:** [2,3] + +**Explanation:** - queries[0] has two plates between candles. - queries[1] has three plates between candles. + +**Example 2:** + +![ex-2](https://assets.leetcode.com/uploads/2021/10/04/ex-2.png) + +**Input:** s = "\*\*\*\|\*\*\|\*\*\*\*\*\|\*\*\|\|\*\*\|\*", queries = \[\[1,17],[4,5],[14,17],[5,11],[15,16]] + +**Output:** [9,0,0,0,0] + +**Explanation:** - queries[0] has nine plates between candles. - The other queries have zero plates between candles. + +**Constraints:** + +* 3 <= s.length <= 105 +* `s` consists of `'*'` and `'|'` characters. +* 1 <= queries.length <= 105 +* `queries[i].length == 2` +* 0 <= lefti <= righti < s.length + +## Solution + +```kotlin +class Solution { + fun platesBetweenCandles(s: String, queries: Array): IntArray { + val sa = s.toCharArray() + val n = sa.size + val nextCandle = IntArray(n + 1) + nextCandle[n] = -1 + for (i in n - 1 downTo 0) { + nextCandle[i] = if (sa[i] == '|') i else nextCandle[i + 1] + } + val prevCandle = IntArray(n) + val prevPlates = IntArray(n) + var countPlate = 0 + if (sa[0] == '*') { + countPlate = 1 + prevCandle[0] = -1 + } + for (i in 1 until n) { + if (sa[i] == '|') { + prevCandle[i] = i + prevPlates[i] = countPlate + } else { + prevCandle[i] = prevCandle[i - 1] + countPlate++ + } + } + val len = queries.size + val res = IntArray(len) + for (i in 0 until len) { + val query = queries[i] + val start = query[0] + val end = query[1] + var curPlates = 0 + val endCandle = prevCandle[end] + if (endCandle >= start) { + val startCandle = nextCandle[start] + curPlates = prevPlates[endCandle] - prevPlates[startCandle] + } + res[i] = curPlates + } + return res + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2056_number_of_valid_move_combinations_on_chessboard/readme.md b/src/main/kotlin/g2001_2100/s2056_number_of_valid_move_combinations_on_chessboard/readme.md new file mode 100644 index 00000000..8cf2605a --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2056_number_of_valid_move_combinations_on_chessboard/readme.md @@ -0,0 +1,167 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2056\. Number of Valid Move Combinations On Chessboard + +Hard + +There is an `8 x 8` chessboard containing `n` pieces (rooks, queens, or bishops). You are given a string array `pieces` of length `n`, where `pieces[i]` describes the type (rook, queen, or bishop) of the ith piece. In addition, you are given a 2D integer array `positions` also of length `n`, where positions[i] = [ri, ci] indicates that the ith piece is currently at the **1-based** coordinate (ri, ci) on the chessboard. + +When making a **move** for a piece, you choose a **destination** square that the piece will travel toward and stop on. + +* A rook can only travel **horizontally or vertically** from `(r, c)` to the direction of `(r+1, c)`, `(r-1, c)`, `(r, c+1)`, or `(r, c-1)`. +* A queen can only travel **horizontally, vertically, or diagonally** from `(r, c)` to the direction of `(r+1, c)`, `(r-1, c)`, `(r, c+1)`, `(r, c-1)`, `(r+1, c+1)`, `(r+1, c-1)`, `(r-1, c+1)`, `(r-1, c-1)`. +* A bishop can only travel **diagonally** from `(r, c)` to the direction of `(r+1, c+1)`, `(r+1, c-1)`, `(r-1, c+1)`, `(r-1, c-1)`. + +You must make a **move** for every piece on the board simultaneously. A **move combination** consists of all the **moves** performed on all the given pieces. Every second, each piece will instantaneously travel **one square** towards their destination if they are not already at it. All pieces start traveling at the 0th second. A move combination is **invalid** if, at a given time, **two or more** pieces occupy the same square. + +Return _the number of **valid** move combinations_. + +**Notes:** + +* **No two pieces** will start in the **same** square. +* You may choose the square a piece is already on as its **destination**. +* If two pieces are **directly adjacent** to each other, it is valid for them to **move past each other** and swap positions in one second. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/09/23/a1.png) + +**Input:** pieces = ["rook"], positions = \[\[1,1]] + +**Output:** 15 + +**Explanation:** The image above shows the possible squares the piece can move to. + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2021/09/23/a2.png) + +**Input:** pieces = ["queen"], positions = \[\[1,1]] + +**Output:** 22 + +**Explanation:** The image above shows the possible squares the piece can move to. + +**Example 3:** + +![](https://assets.leetcode.com/uploads/2021/09/23/a3.png) + +**Input:** pieces = ["bishop"], positions = \[\[4,3]] + +**Output:** 12 + +**Explanation:** The image above shows the possible squares the piece can move to. + +**Constraints:** + +* `n == pieces.length` +* `n == positions.length` +* `1 <= n <= 4` +* `pieces` only contains the strings `"rook"`, `"queen"`, and `"bishop"`. +* There will be at most one queen on the chessboard. +* 1 <= xi, yi <= 8 +* Each `positions[i]` is distinct. + +## Solution + +```kotlin +class Solution { + // 0: rook, queen, bishop + private val dirs = arrayOf( + arrayOf(intArrayOf(-1, 0), intArrayOf(1, 0), intArrayOf(0, -1), intArrayOf(0, 1)), + arrayOf( + intArrayOf(-1, 0), + intArrayOf(1, 0), + intArrayOf(0, -1), + intArrayOf(0, 1), + intArrayOf(1, 1), + intArrayOf(-1, -1), + intArrayOf(-1, 1), + intArrayOf(1, -1) + ), + arrayOf(intArrayOf(1, 1), intArrayOf(-1, -1), intArrayOf(-1, 1), intArrayOf(1, -1)) + ) + + fun countCombinations(pieces: Array, positions: Array): Int { + val endPosition: Array?> = arrayOfNulls(pieces.size) + for (i in pieces.indices) { + endPosition[i] = ArrayList() + } + for (i in pieces.indices) { + positions[i][0]-- + positions[i][1]-- + endPosition[i]!!.add(positions[i]) + var dirIndex = 0 + when (pieces[i]) { + "rook" -> dirIndex = 0 + "queen" -> dirIndex = 1 + "bishop" -> dirIndex = 2 + } + for (d in dirs[dirIndex]) { + var r = positions[i][0] + var c = positions[i][1] + while (true) { + r += d[0] + c += d[1] + if (r < 0 || r >= 8 || c < 0 || c >= 8) { + break + } + endPosition[i]!!.add(intArrayOf(r, c)) + } + } + } + return dfs(positions, endPosition, IntArray(pieces.size), 0) + } + + private fun dfs(positions: Array, stop: Array?>, stopIndex: IntArray, cur: Int): Int { + if (cur == stopIndex.size) { + val p = Array(positions.size) { IntArray(2) } + for (i in p.indices) { + p[i] = intArrayOf(positions[i][0], positions[i][1]) + } + return check(p, stop, stopIndex) + } + var res = 0 + for (i in stop[cur]!!.indices) { + stopIndex[cur] = i + res += dfs(positions, stop, stopIndex, cur + 1) + } + return res + } + + private fun check(positions: Array, stop: Array?>, stopIndex: IntArray): Int { + var keepGoing = true + while (keepGoing) { + keepGoing = false + for (i in positions.indices) { + var diff = stop[i]!![stopIndex[i]][0] - positions[i][0] + if (diff > 0) { + keepGoing = true + positions[i][0]++ + } else if (diff < 0) { + keepGoing = true + positions[i][0]-- + } + diff = stop[i]!![stopIndex[i]][1] - positions[i][1] + if (diff > 0) { + keepGoing = true + positions[i][1]++ + } else if (diff < 0) { + keepGoing = true + positions[i][1]-- + } + } + val seen: MutableSet = HashSet() + for (position in positions) { + val key = position[0] * 100 + position[1] + if (seen.contains(key)) { + return 0 + } + seen.add(key) + } + } + return 1 + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2057_smallest_index_with_equal_value/readme.md b/src/main/kotlin/g2001_2100/s2057_smallest_index_with_equal_value/readme.md new file mode 100644 index 00000000..65f049be --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2057_smallest_index_with_equal_value/readme.md @@ -0,0 +1,72 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2057\. Smallest Index With Equal Value + +Easy + +Given a **0-indexed** integer array `nums`, return _the **smallest** index_ `i` _of_ `nums` _such that_ `i mod 10 == nums[i]`_, or_ `-1` _if such index does not exist_. + +`x mod y` denotes the **remainder** when `x` is divided by `y`. + +**Example 1:** + +**Input:** nums = [0,1,2] + +**Output:** 0 + +**Explanation:** + +i=0: 0 mod 10 = 0 == nums[0]. + +i=1: 1 mod 10 = 1 == nums[1]. + +i=2: 2 mod 10 = 2 == nums[2]. + +All indices have i mod 10 == nums[i], so we return the smallest index 0. + +**Example 2:** + +**Input:** nums = [4,3,2,1] + +**Output:** 2 + +**Explanation:** + +i=0: 0 mod 10 = 0 != nums[0]. + +i=1: 1 mod 10 = 1 != nums[1]. + +i=2: 2 mod 10 = 2 == nums[2]. + +i=3: 3 mod 10 = 3 != nums[3]. + +2 is the only index which has i mod 10 == nums[i]. + +**Example 3:** + +**Input:** nums = [1,2,3,4,5,6,7,8,9,0] + +**Output:** -1 + +**Explanation:** No index satisfies i mod 10 == nums[i]. + +**Constraints:** + +* `1 <= nums.length <= 100` +* `0 <= nums[i] <= 9` + +## Solution + +```kotlin +class Solution { + fun smallestEqual(nums: IntArray): Int { + for (i in nums.indices) { + if (i % 10 == nums[i]) { + return i + } + } + return -1 + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2058_find_the_minimum_and_maximum_number_of_nodes_between_critical_points/readme.md b/src/main/kotlin/g2001_2100/s2058_find_the_minimum_and_maximum_number_of_nodes_between_critical_points/readme.md new file mode 100644 index 00000000..ab0bd5df --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2058_find_the_minimum_and_maximum_number_of_nodes_between_critical_points/readme.md @@ -0,0 +1,122 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2058\. Find the Minimum and Maximum Number of Nodes Between Critical Points + +Medium + +A **critical point** in a linked list is defined as **either** a **local maxima** or a **local minima**. + +A node is a **local maxima** if the current node has a value **strictly greater** than the previous node and the next node. + +A node is a **local minima** if the current node has a value **strictly smaller** than the previous node and the next node. + +Note that a node can only be a local maxima/minima if there exists **both** a previous node and a next node. + +Given a linked list `head`, return _an array of length 2 containing_ `[minDistance, maxDistance]` _where_ `minDistance` _is the **minimum distance** between **any two distinct** critical points and_ `maxDistance` _is the **maximum distance** between **any two distinct** critical points. If there are **fewer** than two critical points, return_ `[-1, -1]`. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/10/13/a1.png) + +**Input:** head = [3,1] + +**Output:** [-1,-1] + +**Explanation:** There are no critical points in [3,1]. + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2021/10/13/a2.png) + +**Input:** head = [5,3,1,2,5,1,2] + +**Output:** [1,3] + +**Explanation:** There are three critical points: + +- \[5,3,**1**,2,5,1,2]: The third node is a local minima because 1 is less than 3 and 2. + +- \[5,3,1,2,**5**,1,2]: The fifth node is a local maxima because 5 is greater than 2 and 1. + +- \[5,3,1,2,5,**1**,2]: The sixth node is a local minima because 1 is less than 5 and 2. + +The minimum distance is between the fifth and the sixth node. minDistance = 6 - 5 = 1. + +The maximum distance is between the third and the sixth node. maxDistance = 6 - 3 = 3. + +**Example 3:** + +![](https://assets.leetcode.com/uploads/2021/10/14/a5.png) + +**Input:** head = [1,3,2,2,3,2,2,2,7] + +**Output:** [3,3] + +**Explanation:** There are two critical points: + +- \[1,**3**,2,2,3,2,2,2,7]: The second node is a local maxima because 3 is greater than 1 and 2. + +- \[1,3,2,2,**3**,2,2,2,7]: The fifth node is a local maxima because 3 is greater than 2 and 2. + +Both the minimum and maximum distances are between the second and the fifth node. + +Thus, minDistance and maxDistance is 5 - 2 = 3. + +Note that the last node is not considered a local maxima because it does not have a next node. + +**Constraints:** + +* The number of nodes in the list is in the range [2, 105]. +* 1 <= Node.val <= 105 + +## Solution + +```kotlin +import com_github_leetcode.ListNode + +class Solution { + fun nodesBetweenCriticalPoints(head: ListNode?): IntArray { + val arr = IntArray(2) + if (head?.next == null || head.next!!.next == null) { + arr[0] = -1 + arr[1] = -1 + return arr + } + var c1 = 0 + var c2 = 0 + var c3 = 0 + var prev = head + var curr = prev.next + var sec = curr!!.next + var count = 1 + var min = Int.MAX_VALUE + while (sec != null) { + count++ + if (curr!!.`val` > prev!!.`val` && curr.`val` > sec.`val` || + curr.`val` < prev.`val` && curr.`val` < sec.`val` + ) { + if (c1 == 0) { + c1 = count + c2 = count + } else { + c3 = count + min = (c3 - c2).coerceAtMost(min) + c2 = c3 + } + } + prev = prev.next + curr = curr.next + sec = sec.next + } + if (c3 == 0) { + arr[0] = -1 + arr[1] = -1 + } else { + arr[1] = c3 - c1 + arr[0] = min + } + return arr + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2059_minimum_operations_to_convert_number/readme.md b/src/main/kotlin/g2001_2100/s2059_minimum_operations_to_convert_number/readme.md new file mode 100644 index 00000000..c2ebeb34 --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2059_minimum_operations_to_convert_number/readme.md @@ -0,0 +1,92 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2059\. Minimum Operations to Convert Number + +Medium + +You are given a **0-indexed** integer array `nums` containing **distinct** numbers, an integer `start`, and an integer `goal`. There is an integer `x` that is initially set to `start`, and you want to perform operations on `x` such that it is converted to `goal`. You can perform the following operation repeatedly on the number `x`: + +If `0 <= x <= 1000`, then for any index `i` in the array (`0 <= i < nums.length`), you can set `x` to any of the following: + +* `x + nums[i]` +* `x - nums[i]` +* `x ^ nums[i]` (bitwise-XOR) + +Note that you can use each `nums[i]` any number of times in any order. Operations that set `x` to be out of the range `0 <= x <= 1000` are valid, but no more operations can be done afterward. + +Return _the **minimum** number of operations needed to convert_ `x = start` _into_ `goal`_, and_ `-1` _if it is not possible_. + +**Example 1:** + +**Input:** nums = [2,4,12], start = 2, goal = 12 + +**Output:** 2 + +**Explanation:** We can go from 2 → 14 → 12 with the following 2 operations. + +- 2 + 12 = 14 + +- 14 - 2 = 12 + +**Example 2:** + +**Input:** nums = [3,5,7], start = 0, goal = -4 + +**Output:** 2 + +**Explanation:** We can go from 0 → 3 → -4 with the following 2 operations. + +- 0 + 3 = 3 + +- 3 - 7 = -4 + +Note that the last operation sets x out of the range 0 <= x <= 1000, which is valid. + +**Example 3:** + +**Input:** nums = [2,8,16], start = 0, goal = 1 + +**Output:** -1 + +**Explanation:** +There is no way to convert 0 into 1. + +**Constraints:** + +* `1 <= nums.length <= 1000` +* -109 <= nums[i], goal <= 109 +* `0 <= start <= 1000` +* `start != goal` +* All the integers in `nums` are distinct. + +## Solution + +```kotlin +class Solution { + fun minimumOperations(nums: IntArray, start: Int, goal: Int): Int { + val seen = BooleanArray(1001) + var q = listOf(goal) + var cnt = 0 + while (q.isNotEmpty()) { + ++cnt + val q1: MutableList = ArrayList() + for (x in q) { + for (n in nums) { + for (xn in intArrayOf(x + n, x - n, x xor n)) { + if (xn in 0..1000 && !seen[xn]) { + if (xn == start) { + return cnt + } + seen[xn] = true + q1.add(xn) + } + } + } + q = q1 + } + } + return -1 + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2060_check_if_an_original_string_exists_given_two_encoded_strings/readme.md b/src/main/kotlin/g2001_2100/s2060_check_if_an_original_string_exists_given_two_encoded_strings/readme.md new file mode 100644 index 00000000..c6d05e4b --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2060_check_if_an_original_string_exists_given_two_encoded_strings/readme.md @@ -0,0 +1,196 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2060\. Check if an Original String Exists Given Two Encoded Strings + +Hard + +An original string, consisting of lowercase English letters, can be encoded by the following steps: + +* Arbitrarily **split** it into a **sequence** of some number of **non-empty** substrings. +* Arbitrarily choose some elements (possibly none) of the sequence, and **replace** each with **its length** (as a numeric string). +* **Concatenate** the sequence as the encoded string. + +For example, **one way** to encode an original string `"abcdefghijklmnop"` might be: + +* Split it as a sequence: `["ab", "cdefghijklmn", "o", "p"]`. +* Choose the second and third elements to be replaced by their lengths, respectively. The sequence becomes `["ab", "12", "1", "p"]`. +* Concatenate the elements of the sequence to get the encoded string: `"ab121p"`. + +Given two encoded strings `s1` and `s2`, consisting of lowercase English letters and digits `1-9` (inclusive), return `true` _if there exists an original string that could be encoded as **both**_ `s1` _and_ `s2`_. Otherwise, return_ `false`. + +**Note**: The test cases are generated such that the number of consecutive digits in `s1` and `s2` does not exceed `3`. + +**Example 1:** + +**Input:** s1 = "internationalization", s2 = "i18n" + +**Output:** true + +**Explanation:** It is possible that "internationalization" was the original string. + +- "internationalization" + + -> Split: ["internationalization"] + + -> Do not replace any element + + -> Concatenate: "internationalization", which is s1. + +- "internationalization" + + -> Split: ["i", "nternationalizatio", "n"] + + -> Replace: ["i", "18", "n"] + + -> Concatenate: "i18n", which is s2 + +**Example 2:** + +**Input:** s1 = "l123e", s2 = "44" + +**Output:** true + +**Explanation:** It is possible that "leetcode" was the original string. + +- "leetcode" + + -> Split: ["l", "e", "et", "cod", "e"] + + -> Replace: ["l", "1", "2", "3", "e"] + + -> Concatenate: "l123e", which is s1. + +- "leetcode" + + -> Split: ["leet", "code"] + + -> Replace: ["4", "4"] + + -> Concatenate: "44", which is s2. + +**Example 3:** + +**Input:** s1 = "a5b", s2 = "c5b" + +**Output:** false + +**Explanation:** It is impossible. + +- The original string encoded as s1 must start with the letter 'a'. + +- The original string encoded as s2 must start with the letter 'c'. + +**Constraints:** + +* `1 <= s1.length, s2.length <= 40` +* `s1` and `s2` consist of digits `1-9` (inclusive), and lowercase English letters only. +* The number of consecutive digits in `s1` and `s2` does not exceed `3`. + +## Solution + +```kotlin +class Solution { + private var stringMatched = false + private var s1: String? = null + private var s2: String? = null + private lateinit var memo: Array>> + + fun possiblyEquals(s1: String, s2: String): Boolean { + this.s1 = s1 + this.s2 = s2 + memo = Array(s1.length + 1) { Array>(s2.length + 1) { arrayOfNulls(2000) } } + dfs(0, 0, 0) + return stringMatched + } + + private fun dfs(i1: Int, i2: Int, diff: Int) { + if (stringMatched) { + return + } + if (i1 == s1!!.length && i2 == s2!!.length) { + if (diff == 0) { + stringMatched = true + } + return + } + if (i1 == s1!!.length && diff <= 0) { + return + } + if (i2 == s2!!.length && diff >= 0) { + return + } + if (memo[i1][i2][diff + 999] != null) { + stringMatched = memo[i1][i2][diff + 999]!! + return + } + val indexNums1: MutableList = ArrayList() + var num1 = 0 + var x1 = i1 + while (x1 < s1!!.length && Character.isDigit(s1!![x1])) { + num1 = num1 * 10 + (s1!![x1].code - '0'.code) + indexNums1.add(intArrayOf(x1, num1)) + x1++ + } + val indexNums2: MutableList = ArrayList() + var num2 = 0 + var x2 = i2 + while (x2 < s2!!.length && Character.isDigit(s2!![x2])) { + num2 = num2 * 10 + (s2!![x2].code - '0'.code) + indexNums2.add(intArrayOf(x2, num2)) + x2++ + } + if (diff == 0) { + if (extracted(i1, i2, diff, indexNums1, indexNums2)) { + return + } + } else if (diff > 0) { + if (Character.isLetter(s2!![i2])) { + dfs(i1, i2 + 1, diff - 1) + } else { + for (num2Item in indexNums2) { + dfs(i1, num2Item[0] + 1, diff - num2Item[1]) + } + } + } else { + if (Character.isLetter(s1!![i1])) { + dfs(i1 + 1, i2, diff + 1) + } else { + for (num1Item in indexNums1) { + dfs(num1Item[0] + 1, i2, diff + num1Item[1]) + } + } + } + memo[i1][i2][diff + 999] = stringMatched + } + + private fun extracted( + i1: Int, + i2: Int, + diff: Int, + indexNums1: List, + indexNums2: List + ): Boolean { + val c1 = s1!![i1] + val c2 = s2!![i2] + if (Character.isLetter(c1) && Character.isLetter(c2)) { + if (c1 != c2) { + return true + } + dfs(i1 + 1, i2 + 1, diff) + return true + } else { + if (indexNums1.isNotEmpty()) { + for (num1Item in indexNums1) { + dfs(num1Item[0] + 1, i2, diff + num1Item[1]) + } + } else { + for (num2Item in indexNums2) { + dfs(i1, num2Item[0] + 1, diff - num2Item[1]) + } + } + } + return false + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2062_count_vowel_substrings_of_a_string/readme.md b/src/main/kotlin/g2001_2100/s2062_count_vowel_substrings_of_a_string/readme.md new file mode 100644 index 00000000..2d6a69ce --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2062_count_vowel_substrings_of_a_string/readme.md @@ -0,0 +1,88 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2062\. Count Vowel Substrings of a String + +Easy + +A **substring** is a contiguous (non-empty) sequence of characters within a string. + +A **vowel substring** is a substring that **only** consists of vowels (`'a'`, `'e'`, `'i'`, `'o'`, and `'u'`) and has **all five** vowels present in it. + +Given a string `word`, return _the number of **vowel substrings** in_ `word`. + +**Example 1:** + +**Input:** word = "aeiouu" + +**Output:** 2 + +**Explanation:** The vowel substrings of word are as follows (underlined): + +- "**aeiou**u" + +- "**aeiouu**" + +**Example 2:** + +**Input:** word = "unicornarihan" + +**Output:** 0 + +**Explanation:** Not all 5 vowels are present, so there are no vowel substrings. + +**Example 3:** + +**Input:** word = "cuaieuouac" + +**Output:** 7 + +**Explanation:** The vowel substrings of word are as follows (underlined): + +- "c**uaieuo**uac" + +- "c**uaieuou**ac" + +- "c**uaieuoua**c" + +- "cu**aieuo**uac" + +- "cu**aieuou**ac" + +- "cu**aieuoua**c" + +- "cua**ieuoua**c" + +**Constraints:** + +* `1 <= word.length <= 100` +* `word` consists of lowercase English letters only. + +## Solution + +```kotlin +class Solution { + fun countVowelSubstrings(word: String): Int { + var count = 0 + val vowels: Set = HashSet(listOf('a', 'e', 'i', 'o', 'u')) + val window: MutableSet = HashSet() + for (i in word.indices) { + window.clear() + if (vowels.contains(word[i])) { + window.add(word[i]) + for (j in i + 1 until word.length) { + if (!vowels.contains(word[j])) { + break + } else { + window.add(word[j]) + if (window.size == 5) { + count++ + } + } + } + } + } + return count + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2063_vowels_of_all_substrings/readme.md b/src/main/kotlin/g2001_2100/s2063_vowels_of_all_substrings/readme.md new file mode 100644 index 00000000..49aa25f0 --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2063_vowels_of_all_substrings/readme.md @@ -0,0 +1,76 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2063\. Vowels of All Substrings + +Medium + +Given a string `word`, return _the **sum of the number of vowels** (_`'a'`, `'e'`_,_ `'i'`_,_ `'o'`_, and_ `'u'`_)_ _in every substring of_ `word`. + +A **substring** is a contiguous (non-empty) sequence of characters within a string. + +**Note:** Due to the large constraints, the answer may not fit in a signed 32-bit integer. Please be careful during the calculations. + +**Example 1:** + +**Input:** word = "aba" + +**Output:** 6 + +**Explanation:** All possible substrings are: "a", "ab", "aba", "b", "ba", and "a". + +- "b" has 0 vowels in it + +- "a", "ab", "ba", and "a" have 1 vowel each + +- "aba" has 2 vowels in it + +Hence, the total sum of vowels = 0 + 1 + 1 + 1 + 1 + 2 = 6. + +**Example 2:** + +**Input:** word = "abc" + +**Output:** 3 + +**Explanation:** All possible substrings are: "a", "ab", "abc", "b", "bc", and "c". + +- "a", "ab", and "abc" have 1 vowel each + +- "b", "bc", and "c" have 0 vowels each + +Hence, the total sum of vowels = 1 + 1 + 1 + 0 + 0 + 0 = 3. + +**Example 3:** + +**Input:** word = "ltcd" + +**Output:** 0 + +**Explanation:** There are no vowels in any substring of "ltcd". + +**Constraints:** + +* 1 <= word.length <= 105 +* `word` consists of lowercase English letters. + +## Solution + +```kotlin +class Solution { + fun countVowels(word: String): Long { + var ans: Long = 0 + for (i in word.indices) { + if (isVowel(word[i])) { + val right = word.length - i.toLong() - 1 + ans += (i.toLong() + 1) * (right + 1) + } + } + return ans + } + + private fun isVowel(ch: Char): Boolean { + return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2064_minimized_maximum_of_products_distributed_to_any_store/readme.md b/src/main/kotlin/g2001_2100/s2064_minimized_maximum_of_products_distributed_to_any_store/readme.md new file mode 100644 index 00000000..78a570f8 --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2064_minimized_maximum_of_products_distributed_to_any_store/readme.md @@ -0,0 +1,104 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2064\. Minimized Maximum of Products Distributed to Any Store + +Medium + +You are given an integer `n` indicating there are `n` specialty retail stores. There are `m` product types of varying amounts, which are given as a **0-indexed** integer array `quantities`, where `quantities[i]` represents the number of products of the ith product type. + +You need to distribute **all products** to the retail stores following these rules: + +* A store can only be given **at most one product type** but can be given **any** amount of it. +* After distribution, each store will have been given some number of products (possibly `0`). Let `x` represent the maximum number of products given to any store. You want `x` to be as small as possible, i.e., you want to **minimize** the **maximum** number of products that are given to any store. + +Return _the minimum possible_ `x`. + +**Example 1:** + +**Input:** n = 6, quantities = [11,6] + +**Output:** 3 + +**Explanation:** One optimal way is: + +- The 11 products of type 0 are distributed to the first four stores in these amounts: 2, 3, 3, 3 + +- The 6 products of type 1 are distributed to the other two stores in these amounts: 3, 3 + +The maximum number of products given to any store is max(2, 3, 3, 3, 3, 3) = 3. + +**Example 2:** + +**Input:** n = 7, quantities = [15,10,10] + +**Output:** 5 + +**Explanation:** One optimal way is: + +- The 15 products of type 0 are distributed to the first three stores in these amounts: 5, 5, 5 + +- The 10 products of type 1 are distributed to the next two stores in these amounts: 5, 5 + +- The 10 products of type 2 are distributed to the last two stores in these amounts: 5, 5 + +The maximum number of products given to any store is max(5, 5, 5, 5, 5, 5, 5) = 5. + +**Example 3:** + +**Input:** n = 1, quantities = [100000] + +**Output:** 100000 + +**Explanation:** The only optimal way is: + +- The 100000 products of type 0 are distributed to the only store. + +The maximum number of products given to any store is max(100000) = 100000. + +**Constraints:** + +* `m == quantities.length` +* 1 <= m <= n <= 105 +* 1 <= quantities[i] <= 105 + +## Solution + +```kotlin +class Solution { + fun minimizedMaximum(n: Int, q: IntArray): Int { + var min = 1 + var max = maxi(q) + var ans = 0 + while (min <= max) { + val mid = min + (max - min) / 2 + if (condition(q, mid, n)) { + ans = mid + max = mid - 1 + } else { + min = mid + 1 + } + } + return ans + } + + private fun condition(arr: IntArray, mid: Int, n: Int): Boolean { + var ans = 0 + for (num in arr) { + ans += num / mid + if (num % mid != 0) { + ans++ + } + } + return ans <= n + } + + private fun maxi(arr: IntArray): Int { + var ans = 0 + for (n in arr) { + ans = ans.coerceAtLeast(n) + } + return ans + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2065_maximum_path_quality_of_a_graph/readme.md b/src/main/kotlin/g2001_2100/s2065_maximum_path_quality_of_a_graph/readme.md new file mode 100644 index 00000000..42eb72e2 --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2065_maximum_path_quality_of_a_graph/readme.md @@ -0,0 +1,142 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2065\. Maximum Path Quality of a Graph + +Hard + +There is an **undirected** graph with `n` nodes numbered from `0` to `n - 1` (**inclusive**). You are given a **0-indexed** integer array `values` where `values[i]` is the **value** of the ith node. You are also given a **0-indexed** 2D integer array `edges`, where each edges[j] = [uj, vj, timej] indicates that there is an undirected edge between the nodes uj and vj, and it takes timej seconds to travel between the two nodes. Finally, you are given an integer `maxTime`. + +A **valid** **path** in the graph is any path that starts at node `0`, ends at node `0`, and takes **at most** `maxTime` seconds to complete. You may visit the same node multiple times. The **quality** of a valid path is the **sum** of the values of the **unique nodes** visited in the path (each node's value is added **at most once** to the sum). + +Return _the **maximum** quality of a valid path_. + +**Note:** There are **at most four** edges connected to each node. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/10/19/ex1drawio.png) + +**Input:** values = [0,32,10,43], edges = \[\[0,1,10],[1,2,15],[0,3,10]], maxTime = 49 + +**Output:** 75 + +**Explanation:** + +One possible path is 0 -> 1 -> 0 -> 3 -> 0. + +The total time taken is 10 + 10 + 10 + 10 = 40 <= 49. + +The nodes visited are 0, 1, and 3, giving a maximal path quality of 0 + 32 + 43 = 75. + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2021/10/19/ex2drawio.png) + +**Input:** values = [5,10,15,20], edges = \[\[0,1,10],[1,2,10],[0,3,10]], maxTime = 30 + +**Output:** 25 + +**Explanation:** + +One possible path is 0 -> 3 -> 0. + +The total time taken is 10 + 10 = 20 <= 30. + +The nodes visited are 0 and 3, giving a maximal path quality of 5 + 20 = 25. + +**Example 3:** + +![](https://assets.leetcode.com/uploads/2021/10/19/ex31drawio.png) + +**Input:** values = [1,2,3,4], edges = \[\[0,1,10],[1,2,11],[2,3,12],[1,3,13]], maxTime = 50 + +**Output:** 7 + +**Explanation:** + +One possible path is 0 -> 1 -> 3 -> 1 -> 0. + +The total time taken is 10 + 13 + 13 + 10 = 46 <= 50. + +The nodes visited are 0, 1, and 3, giving a maximal path quality of 1 + 2 + 4 = 7. + +**Constraints:** + +* `n == values.length` +* `1 <= n <= 1000` +* 0 <= values[i] <= 108 +* `0 <= edges.length <= 2000` +* `edges[j].length == 3` +* 0 <= uj < vj <= n - 1 +* 10 <= timej, maxTime <= 100 +* All the pairs [uj, vj] are **unique**. +* There are **at most four** edges connected to each node. +* The graph may not be connected. + +## Solution + +```kotlin +class Solution { + private var maxQuality = 0 + + internal class Node(var i: Int, var time: Int) + + fun maximalPathQuality(values: IntArray, edges: Array, maxTime: Int): Int { + val graph: MutableList> = ArrayList() + for (i in values.indices) { + graph.add(ArrayList()) + } + for (edge in edges) { + val u = edge[0] + val v = edge[1] + val time = edge[2] + val node1 = Node(u, time) + val node2 = Node(v, time) + graph[u].add(node2) + graph[v].add(node1) + } + maxQuality = 0 + dfs(graph, 0, 0, maxTime, values[0], values) + return maxQuality + } + + private fun dfs( + graph: List>, + start: Int, + curTime: Int, + maxTime: Int, + curValue: Int, + values: IntArray + ) { + if (curTime > maxTime) { + return + } + if (curTime == maxTime && start != 0) { + return + } + if (start == 0) { + maxQuality = maxQuality.coerceAtLeast(curValue) + } + val tmp = values[start] + if (tmp != 0) { + values[start] = 0 + } + for (node in graph[start]) { + val v = node.i + val time = node.time + val value = values[v] + if (value != 0) { + values[v] = 0 + } + dfs(graph, v, curTime + time, maxTime, curValue + value, values) + if (value != 0) { + values[v] = value + } + } + if (tmp != 0) { + values[start] = tmp + } + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2068_check_whether_two_strings_are_almost_equivalent/readme.md b/src/main/kotlin/g2001_2100/s2068_check_whether_two_strings_are_almost_equivalent/readme.md new file mode 100644 index 00000000..3048c01f --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2068_check_whether_two_strings_are_almost_equivalent/readme.md @@ -0,0 +1,86 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2068\. Check Whether Two Strings are Almost Equivalent + +Easy + +Two strings `word1` and `word2` are considered **almost equivalent** if the differences between the frequencies of each letter from `'a'` to `'z'` between `word1` and `word2` is **at most** `3`. + +Given two strings `word1` and `word2`, each of length `n`, return `true` _if_ `word1` _and_ `word2` _are **almost equivalent**, or_ `false` _otherwise_. + +The **frequency** of a letter `x` is the number of times it occurs in the string. + +**Example 1:** + +**Input:** word1 = "aaaa", word2 = "bccb" + +**Output:** false + +**Explanation:** There are 4 'a's in "aaaa" but 0 'a's in "bccb". + +The difference is 4, which is more than the allowed 3. + +**Example 2:** + +**Input:** word1 = "abcdeef", word2 = "abaaacc" + +**Output:** true + +**Explanation:** The differences between the frequencies of each letter in word1 and word2 are at most 3: + +- 'a' appears 1 time in word1 and 4 times in word2. The difference is 3. + +- 'b' appears 1 time in word1 and 1 time in word2. The difference is 0. + +- 'c' appears 1 time in word1 and 2 times in word2. The difference is 1. + +- 'd' appears 1 time in word1 and 0 times in word2. The difference is 1. + +- 'e' appears 2 times in word1 and 0 times in word2. The difference is 2. + +- 'f' appears 1 time in word1 and 0 times in word2. The difference is 1. + +**Example 3:** + +**Input:** word1 = "cccddabba", word2 = "babababab" + +**Output:** true + +**Explanation:** The differences between the frequencies of each letter in word1 and word2 are at most 3: + +- 'a' appears 2 times in word1 and 4 times in word2. The difference is 2. + +- 'b' appears 2 times in word1 and 5 times in word2. The difference is 3. + +- 'c' appears 3 times in word1 and 0 times in word2. The difference is 3. + +- 'd' appears 2 times in word1 and 0 times in word2. The difference is 2. + +**Constraints:** + +* `n == word1.length == word2.length` +* `1 <= n <= 100` +* `word1` and `word2` consist only of lowercase English letters. + +## Solution + +```kotlin +import kotlin.math.abs + +class Solution { + fun checkAlmostEquivalent(word1: String, word2: String): Boolean { + val freq = IntArray(26) + for (i in word1.indices) { + ++freq[word1[i].code - 'a'.code] + --freq[word2[i].code - 'a'.code] + } + for (i in freq) { + if (abs(i) > 3) { + return false + } + } + return true + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2069_walking_robot_simulation_ii/readme.md b/src/main/kotlin/g2001_2100/s2069_walking_robot_simulation_ii/readme.md new file mode 100644 index 00000000..96212813 --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2069_walking_robot_simulation_ii/readme.md @@ -0,0 +1,116 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2069\. Walking Robot Simulation II + +Medium + +A `width x height` grid is on an XY-plane with the **bottom-left** cell at `(0, 0)` and the **top-right** cell at `(width - 1, height - 1)`. The grid is aligned with the four cardinal directions (`"North"`, `"East"`, `"South"`, and `"West"`). A robot is **initially** at cell `(0, 0)` facing direction `"East"`. + +The robot can be instructed to move for a specific number of **steps**. For each step, it does the following. + +1. Attempts to move **forward one** cell in the direction it is facing. +2. If the cell the robot is **moving to** is **out of bounds**, the robot instead **turns** 90 degrees **counterclockwise** and retries the step. + +After the robot finishes moving the number of steps required, it stops and awaits the next instruction. + +Implement the `Robot` class: + +* `Robot(int width, int height)` Initializes the `width x height` grid with the robot at `(0, 0)` facing `"East"`. +* `void step(int num)` Instructs the robot to move forward `num` steps. +* `int[] getPos()` Returns the current cell the robot is at, as an array of length 2, `[x, y]`. +* `String getDir()` Returns the current direction of the robot, `"North"`, `"East"`, `"South"`, or `"West"`. + +**Example 1:** + +![example-1](https://assets.leetcode.com/uploads/2021/10/09/example-1.png) + +**Input** + +["Robot", "step", "step", "getPos", "getDir", "step", "step", "step", "getPos", "getDir"] + +[[6, 3], [2], [2], [], [], [2], [1], [4], [], []] + +**Output:** + +[null, null, null, [4, 0], "East", null, null, null, [1, 2], "West"] + +**Explanation:** + + Robot robot = new Robot(6, 3); // Initialize the grid and the robot at (0, 0) facing East. + robot.step(2); // It moves two steps East to (2, 0), and faces East. + robot.step(2); // It moves two steps East to (4, 0), and faces East. + robot.getPos(); // return [4, 0] + robot.getDir(); // return "East" + robot.step(2); // It moves one step East to (5, 0), and faces East. + // Moving the next step East would be out of bounds, so it turns and faces North. + // Then, it moves one step North to (5, 1), and faces North. + robot.step(1); // It moves one step North to (5, 2), and faces North (not West). + robot.step(4); // Moving the next step North would be out of bounds, so it turns and faces West. + // Then, it moves four steps West to (1, 2), and faces West. + robot.getPos(); // return [1, 2] + robot.getDir(); // return "West" + +**Constraints:** + +* `2 <= width, height <= 100` +* 1 <= num <= 105 +* At most 104 calls **in total** will be made to `step`, `getPos`, and `getDir`. + +## Solution + +```kotlin +class Robot(width: Int, height: Int) { + private var p: Int + private val w: Int + private val h: Int + + init { + w = width - 1 + h = height - 1 + p = 0 + } + + fun step(num: Int) { + p += num + } + + fun getPos(): IntArray { + var remain = p % (2 * (w + h)) + if (remain <= w) { + return intArrayOf(remain, 0) + } + remain -= w + if (remain <= h) { + return intArrayOf(w, remain) + } + remain -= h + if (remain <= w) { + return intArrayOf(w - remain, h) + } + remain -= w + return intArrayOf(0, h - remain) + } + + fun getDir(): String { + val pos = getPos() + return if (p == 0 || pos[1] == 0 && pos[0] > 0) { + "East" + } else if (pos[0] == w && pos[1] > 0) { + "North" + } else if (pos[1] == h && pos[0] < w) { + "West" + } else { + "South" + } + } +} + +/* + * Your Robot object will be instantiated and called as such: + * var obj = Robot(width, height) + * obj.step(num) + * var param_2 = obj.getPos() + * var param_3 = obj.getDir() + */ +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2070_most_beautiful_item_for_each_query/readme.md b/src/main/kotlin/g2001_2100/s2070_most_beautiful_item_for_each_query/readme.md new file mode 100644 index 00000000..3c823c18 --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2070_most_beautiful_item_for_each_query/readme.md @@ -0,0 +1,90 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2070\. Most Beautiful Item for Each Query + +Medium + +You are given a 2D integer array `items` where items[i] = [pricei, beautyi] denotes the **price** and **beauty** of an item respectively. + +You are also given a **0-indexed** integer array `queries`. For each `queries[j]`, you want to determine the **maximum beauty** of an item whose **price** is **less than or equal** to `queries[j]`. If no such item exists, then the answer to this query is `0`. + +Return _an array_ `answer` _of the same length as_ `queries` _where_ `answer[j]` _is the answer to the_ jth _query_. + +**Example 1:** + +**Input:** items = \[\[1,2],[3,2],[2,4],[5,6],[3,5]], queries = [1,2,3,4,5,6] + +**Output:** [2,4,5,5,6,6] + +**Explanation:** + +- For queries[0]=1, [1,2] is the only item which has price <= 1. Hence, the answer for this query is 2. + +- For queries[1]=2, the items which can be considered are [1,2] and [2,4]. + +The maximum beauty among them is 4. + +- For queries[2]=3 and queries[3]=4, the items which can be considered are [1,2], [3,2], [2,4], and [3,5]. + +The maximum beauty among them is 5. + +- For queries[4]=5 and queries[5]=6, all items can be considered. + +Hence, the answer for them is the maximum beauty of all items, i.e., 6. + +**Example 2:** + +**Input:** items = \[\[1,2],[1,2],[1,3],[1,4]], queries = [1] + +**Output:** [4] + +**Explanation:** + +The price of every item is equal to 1, so we choose the item with the maximum beauty 4. + +Note that multiple items can have the same price and/or beauty. + +**Example 3:** + +**Input:** items = \[\[10,1000]], queries = [5] + +**Output:** [0] + +**Explanation:** + +No item has a price less than or equal to 5, so no item can be chosen. + +Hence, the answer to the query is 0. + +**Constraints:** + +* 1 <= items.length, queries.length <= 105 +* `items[i].length == 2` +* 1 <= pricei, beautyi, queries[j] <= 109 + +## Solution + +```kotlin +class Solution { + fun maximumBeauty(items: Array, queries: IntArray): IntArray { + val res = IntArray(queries.size) + items.sortWith(compareBy { a: IntArray -> a[1] }) + for (i in res.indices) { + res[i] = maxBeauty(items, queries[i]) + } + return res + } + + private fun maxBeauty(items: Array, query: Int): Int { + for (i in items.indices.reversed()) { + val price = items[i][0] + val beauty = items[i][1] + if (price <= query) { + return beauty + } + } + return 0 + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2071_maximum_number_of_tasks_you_can_assign/readme.md b/src/main/kotlin/g2001_2100/s2071_maximum_number_of_tasks_you_can_assign/readme.md new file mode 100644 index 00000000..0ea9e2d2 --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2071_maximum_number_of_tasks_you_can_assign/readme.md @@ -0,0 +1,125 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2071\. Maximum Number of Tasks You Can Assign + +Hard + +You have `n` tasks and `m` workers. Each task has a strength requirement stored in a **0-indexed** integer array `tasks`, with the ith task requiring `tasks[i]` strength to complete. The strength of each worker is stored in a **0-indexed** integer array `workers`, with the jth worker having `workers[j]` strength. Each worker can only be assigned to a **single** task and must have a strength **greater than or equal** to the task's strength requirement (i.e., `workers[j] >= tasks[i]`). + +Additionally, you have `pills` magical pills that will **increase a worker's strength** by `strength`. You can decide which workers receive the magical pills, however, you may only give each worker **at most one** magical pill. + +Given the **0-indexed** integer arrays `tasks` and `workers` and the integers `pills` and `strength`, return _the **maximum** number of tasks that can be completed._ + +**Example 1:** + +**Input:** tasks = [**3**,**2**,**1**], workers = [**0**,**3**,**3**], pills = 1, strength = 1 + +**Output:** 3 + +**Explanation:** + +We can assign the magical pill and tasks as follows: + +- Give the magical pill to worker 0. + +- Assign worker 0 to task 2 (0 + 1 >= 1) + +- Assign worker 1 to task 1 (3 >= 2) + +- Assign worker 2 to task 0 (3 >= 3) + +**Example 2:** + +**Input:** tasks = [**5**,4], workers = [**0**,0,0], pills = 1, strength = 5 + +**Output:** 1 + +**Explanation:** + +We can assign the magical pill and tasks as follows: + +- Give the magical pill to worker 0. + +- Assign worker 0 to task 0 (0 + 5 >= 5) + +**Example 3:** + +**Input:** tasks = [**10**,**15**,30], workers = [**0**,**10**,10,10,10], pills = 3, strength = 10 + +**Output:** 2 + +**Explanation:** + +We can assign the magical pills and tasks as follows: + +- Give the magical pill to worker 0 and worker 1. + +- Assign worker 0 to task 0 (0 + 10 >= 10) + +- Assign worker 1 to task 1 (10 + 10 >= 15) + +The last pill is not given because it will not make any worker strong enough for the last task. + +**Constraints:** + +* `n == tasks.length` +* `m == workers.length` +* 1 <= n, m <= 5 * 104 +* `0 <= pills <= m` +* 0 <= tasks[i], workers[j], strength <= 109 + +## Solution + +```kotlin +import java.util.Deque +import java.util.LinkedList + +@Suppress("NAME_SHADOWING") +class Solution { + fun maxTaskAssign(tasks: IntArray, workers: IntArray, pills: Int, strength: Int): Int { + var left = 0 + var right = tasks.size.coerceAtMost(workers.size) + tasks.sort() + workers.sort() + while (left + 1 < right) { + val mid = left + (right - left) / 2 + if (canAssign(mid, tasks, workers, pills, strength)) { + left = mid + } else { + right = mid + } + } + return if (canAssign(right, tasks, workers, pills, strength)) { + right + } else { + left + } + } + + private fun canAssign(count: Int, tasks: IntArray, workers: IntArray, pills: Int, strength: Int): Boolean { + var pills = pills + val dq: Deque = LinkedList() + var ind = workers.size - 1 + for (i in count - 1 downTo 0) { + while (ind >= workers.size - count && workers[ind] + strength >= tasks[i]) { + dq.offerLast(workers[ind]) + ind-- + } + if (dq.isEmpty()) { + return false + } + if (dq.peekFirst() >= tasks[i]) { + dq.pollFirst() + } else { + dq.pollLast() + pills-- + if (pills < 0) { + return false + } + } + } + return true + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2073_time_needed_to_buy_tickets/readme.md b/src/main/kotlin/g2001_2100/s2073_time_needed_to_buy_tickets/readme.md new file mode 100644 index 00000000..42501350 --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2073_time_needed_to_buy_tickets/readme.md @@ -0,0 +1,67 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2073\. Time Needed to Buy Tickets + +Easy + +There are `n` people in a line queuing to buy tickets, where the 0th person is at the **front** of the line and the (n - 1)th person is at the **back** of the line. + +You are given a **0-indexed** integer array `tickets` of length `n` where the number of tickets that the ith person would like to buy is `tickets[i]`. + +Each person takes **exactly 1 second** to buy a ticket. A person can only buy **1 ticket at a time** and has to go back to **the end** of the line (which happens **instantaneously**) in order to buy more tickets. If a person does not have any tickets left to buy, the person will **leave** the line. + +Return _the **time taken** for the person at position_ `k`_**(0-indexed)** to finish buying tickets_. + +**Example 1:** + +**Input:** tickets = [2,3,2], k = 2 + +**Output:** 6 + +**Explanation:** + +- In the first pass, everyone in the line buys a ticket and the line becomes [1, 2, 1]. + +- In the second pass, everyone in the line buys a ticket and the line becomes [0, 1, 0]. + +The person at position 2 has successfully bought 2 tickets and it took 3 + 3 = 6 seconds. + +**Example 2:** + +**Input:** tickets = [5,1,1,1], k = 0 + +**Output:** 8 + +**Explanation:** + +- In the first pass, everyone in the line buys a ticket and the line becomes [4, 0, 0, 0]. + +- In the next 4 passes, only the person in position 0 is buying tickets. + +The person at position 0 has successfully bought 5 tickets and it took 4 + 1 + 1 + 1 + 1 = 8 seconds. + +**Constraints:** + +* `n == tickets.length` +* `1 <= n <= 100` +* `1 <= tickets[i] <= 100` +* `0 <= k < n` + +## Solution + +```kotlin +class Solution { + fun timeRequiredToBuy(tickets: IntArray, k: Int): Int { + var res = 0 + for (i in tickets.indices) { + res += if (i <= k) { + tickets[k].coerceAtMost(tickets[i]) + } else { + (tickets[k] - 1).coerceAtMost(tickets[i]) + } + } + return res + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2074_reverse_nodes_in_even_length_groups/readme.md b/src/main/kotlin/g2001_2100/s2074_reverse_nodes_in_even_length_groups/readme.md new file mode 100644 index 00000000..185878da --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2074_reverse_nodes_in_even_length_groups/readme.md @@ -0,0 +1,129 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2074\. Reverse Nodes in Even Length Groups + +Medium + +You are given the `head` of a linked list. + +The nodes in the linked list are **sequentially** assigned to **non-empty** groups whose lengths form the sequence of the natural numbers (`1, 2, 3, 4, ...`). The **length** of a group is the number of nodes assigned to it. In other words, + +* The 1st node is assigned to the first group. +* The 2nd and the 3rd nodes are assigned to the second group. +* The 4th, 5th, and 6th nodes are assigned to the third group, and so on. + +Note that the length of the last group may be less than or equal to `1 + the length of the second to last group`. + +**Reverse** the nodes in each group with an **even** length, and return _the_ `head` _of the modified linked list_. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/10/25/eg1.png) + +**Input:** head = [5,2,6,3,9,1,7,3,8,4] + +**Output:** [5,6,2,3,9,1,4,8,3,7] + +**Explanation:** + +- The length of the first group is 1, which is odd, hence no reversal occurs. + +- The length of the second group is 2, which is even, hence the nodes are reversed. + +- The length of the third group is 3, which is odd, hence no reversal occurs. + +- The length of the last group is 4, which is even, hence the nodes are reversed. + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2021/10/25/eg2.png) + +**Input:** head = [1,1,0,6] + +**Output:** [1,0,1,6] + +**Explanation:** + +- The length of the first group is 1. No reversal occurs. + +- The length of the second group is 2. The nodes are reversed. + +- The length of the last group is 1. No reversal occurs. + +**Example 3:** + +![](https://assets.leetcode.com/uploads/2021/11/17/ex3.png) + +**Input:** head = [1,1,0,6,5] + +**Output:** [1,0,1,5,6] + +**Explanation:** + +- The length of the first group is 1. No reversal occurs. + +- The length of the second group is 2. The nodes are reversed. + +- The length of the last group is 2. The nodes are reversed. + +**Constraints:** + +* The number of nodes in the list is in the range [1, 105]. +* 0 <= Node.val <= 105 + +## Solution + +```kotlin +import com_github_leetcode.ListNode + +/* + * Example: + * var li = ListNode(5) + * var v = li.`val` + * Definition for singly-linked list. + * class ListNode(var `val`: Int) { + * var next: ListNode? = null + * } + */ +class Solution { + fun reverseEvenLengthGroups(head: ListNode?): ListNode? { + var cnt = 1 + var currGroupCnt = 0 + var currNode = head + var s = currNode + while (currNode != null) { + while (currGroupCnt++ < cnt && currNode != null) { + val isEven = currGroupCnt % 2 == 0 + val isLastNodeInGroup = currGroupCnt == cnt || currNode.next == null + if (isEven && isLastNodeInGroup) { + val end = currNode.next + val afterStart = s?.next + currNode = afterStart + var prev = s?.next + var curr = prev?.next + // First node of the group should link to 'start' of the next group exclusive + afterStart?.next = end + // Reverse this group, prev - curr - temp algorithm: + // curr will point to prev, new prev is curr, while curr shifts forward via tmp (: + while (curr != null && curr != end) { + val tmp = curr.next + curr.next = prev + prev = curr + curr = tmp + } + // Last node of the prev group should link to new first node of this one + s?.next = prev + s = afterStart + } else if (!isEven && isLastNodeInGroup) { + s = currNode + } + currNode = currNode?.next + } + cnt++ + currGroupCnt = 0 + } + return head + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2075_decode_the_slanted_ciphertext/readme.md b/src/main/kotlin/g2001_2100/s2075_decode_the_slanted_ciphertext/readme.md new file mode 100644 index 00000000..bfc42b55 --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2075_decode_the_slanted_ciphertext/readme.md @@ -0,0 +1,106 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2075\. Decode the Slanted Ciphertext + +Medium + +A string `originalText` is encoded using a **slanted transposition cipher** to a string `encodedText` with the help of a matrix having a **fixed number of rows** `rows`. + +`originalText` is placed first in a top-left to bottom-right manner. + +![](https://assets.leetcode.com/uploads/2021/11/07/exa11.png) + +The blue cells are filled first, followed by the red cells, then the yellow cells, and so on, until we reach the end of `originalText`. The arrow indicates the order in which the cells are filled. All empty cells are filled with `' '`. The number of columns is chosen such that the rightmost column will **not be empty** after filling in `originalText`. + +`encodedText` is then formed by appending all characters of the matrix in a row-wise fashion. + +![](https://assets.leetcode.com/uploads/2021/11/07/exa12.png) + +The characters in the blue cells are appended first to `encodedText`, then the red cells, and so on, and finally the yellow cells. The arrow indicates the order in which the cells are accessed. + +For example, if `originalText = "cipher"` and `rows = 3`, then we encode it in the following manner: + +![](https://assets.leetcode.com/uploads/2021/10/25/desc2.png) + +The blue arrows depict how `originalText` is placed in the matrix, and the red arrows denote the order in which `encodedText` is formed. In the above example, `encodedText = "ch ie pr"`. + +Given the encoded string `encodedText` and number of rows `rows`, return _the original string_ `originalText`. + +**Note:** `originalText` **does not** have any trailing spaces `' '`. The test cases are generated such that there is only one possible `originalText`. + +**Example 1:** + +**Input:** encodedText = "ch ie pr", rows = 3 + +**Output:** "cipher" + +**Explanation:** This is the same example described in the problem description. + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2021/10/26/exam1.png) + +**Input:** encodedText = "iveo eed l te olc", rows = 4 + +**Output:** "i love leetcode" + +**Explanation:** The figure above denotes the matrix that was used to encode originalText. + +The blue arrows show how we can find originalText from encodedText. + +**Example 3:** + +![](https://assets.leetcode.com/uploads/2021/10/26/eg2.png) + +**Input:** encodedText = "coding", rows = 1 + +**Output:** "coding" + +**Explanation:** Since there is only 1 row, both originalText and encodedText are the same. + +**Constraints:** + +* 0 <= encodedText.length <= 106 +* `encodedText` consists of lowercase English letters and `' '` only. +* `encodedText` is a valid encoding of some `originalText` that **does not** have trailing spaces. +* `1 <= rows <= 1000` +* The testcases are generated such that there is **only one** possible `originalText`. + +## Solution + +```kotlin +class Solution { + fun decodeCiphertext(encodedText: String, rows: Int): String { + if (rows == 1) { + return encodedText + } + val total = encodedText.length + val cols = total / rows + val grid = Array(rows) { CharArray(cols) } + var index = 0 + for (i in 0 until rows) { + for (j in 0 until cols) { + grid[i][j] = encodedText[index++] + } + } + val sb = StringBuilder() + var colIndex = 0 + while (colIndex < cols) { + var j = colIndex + var i = 0 + while (j < cols && i < rows) { + sb.append(grid[i][j]) + j++ + i++ + } + colIndex++ + } + var i = sb.length - 1 + while (i >= 0 && sb[i] == ' ') { + i-- + } + return sb.substring(0, i + 1) + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2076_process_restricted_friend_requests/readme.md b/src/main/kotlin/g2001_2100/s2076_process_restricted_friend_requests/readme.md new file mode 100644 index 00000000..8e9f8cca --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2076_process_restricted_friend_requests/readme.md @@ -0,0 +1,126 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2076\. Process Restricted Friend Requests + +Hard + +You are given an integer `n` indicating the number of people in a network. Each person is labeled from `0` to `n - 1`. + +You are also given a **0-indexed** 2D integer array `restrictions`, where restrictions[i] = [xi, yi] means that person xi and person yi **cannot** become **friends**, either **directly** or **indirectly** through other people. + +Initially, no one is friends with each other. You are given a list of friend requests as a **0-indexed** 2D integer array `requests`, where requests[j] = [uj, vj] is a friend request between person uj and person vj. + +A friend request is **successful** if uj and vj can be **friends**. Each friend request is processed in the given order (i.e., `requests[j]` occurs before `requests[j + 1]`), and upon a successful request, uj and vj **become direct friends** for all future friend requests. + +Return _a **boolean array**_ `result`, _where each_ `result[j]` _is_ `true` _if the_ jth _friend request is **successful** or_ `false` _if it is not_. + +**Note:** If uj and vj are already direct friends, the request is still **successful**. + +**Example 1:** + +**Input:** n = 3, restrictions = \[\[0,1]], requests = \[\[0,2],[2,1]] + +**Output:** [true,false] + +**Explanation:** + +Request 0: Person 0 and person 2 can be friends, so they become direct friends. + +Request 1: Person 2 and person 1 cannot be friends since person 0 and person 1 would be indirect friends (1--2--0). + +**Example 2:** + +**Input:** n = 3, restrictions = \[\[0,1]], requests = \[\[1,2],[0,2]] + +**Output:** [true,false] + +**Explanation:** + +Request 0: Person 1 and person 2 can be friends, so they become direct friends. + +Request 1: Person 0 and person 2 cannot be friends since person 0 and person 1 would be indirect friends (0--2--1). + +**Example 3:** + +**Input:** n = 5, restrictions = \[\[0,1],[1,2],[2,3]], requests = \[\[0,4],[1,2],[3,1],[3,4]] + +**Output:** [true,false,true,false] + +**Explanation:** + +Request 0: Person 0 and person 4 can be friends, so they become direct friends. + +Request 1: Person 1 and person 2 cannot be friends since they are directly restricted. + +Request 2: Person 3 and person 1 can be friends, so they become direct friends. + +Request 3: Person 3 and person 4 cannot be friends since person 0 and person 1 would be indirect friends (0--4--3--1). + +**Constraints:** + +* `2 <= n <= 1000` +* `0 <= restrictions.length <= 1000` +* `restrictions[i].length == 2` +* 0 <= xi, yi <= n - 1 +* xi != yi +* `1 <= requests.length <= 1000` +* `requests[j].length == 2` +* 0 <= uj, vj <= n - 1 +* uj != vj + +## Solution + +```kotlin +@Suppress("NAME_SHADOWING") +class Solution { + fun friendRequests(n: Int, restrictions: Array, requests: Array): BooleanArray { + // Check for each request whether it can cause conflict or not + val uf = UnionFind(n) + val res = BooleanArray(requests.size) + for (i in requests.indices) { + val p1 = uf.findParent(requests[i][0]) + val p2 = uf.findParent(requests[i][1]) + if (p1 == p2) { + res[i] = true + continue + } + // Check whether the current request will violate any restriction or not + var flag = true + for (restrict in restrictions) { + val r1 = uf.findParent(restrict[0]) + val r2 = uf.findParent(restrict[1]) + if (r1 == p1 && r2 == p2 || r1 == p2 && r2 == p1) { + flag = false + break + } + } + if (flag) { + res[i] = true + // Union + uf.parent[p1] = p2 + } + } + return res + } + + private class UnionFind(n: Int) { + var parent: IntArray = IntArray(n) + + init { + for (i in 0 until n) { + parent[i] = i + } + } + + fun findParent(user: Int): Int { + var user = user + while (parent[user] != user) { + parent[user] = parent[parent[user]] + user = parent[user] + } + return user + } + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2078_two_furthest_houses_with_different_colors/readme.md b/src/main/kotlin/g2001_2100/s2078_two_furthest_houses_with_different_colors/readme.md new file mode 100644 index 00000000..905e0ee8 --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2078_two_furthest_houses_with_different_colors/readme.md @@ -0,0 +1,95 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2078\. Two Furthest Houses With Different Colors + +Easy + +There are `n` houses evenly lined up on the street, and each house is beautifully painted. You are given a **0-indexed** integer array `colors` of length `n`, where `colors[i]` represents the color of the ith house. + +Return _the **maximum** distance between **two** houses with **different** colors_. + +The distance between the ith and jth houses is `abs(i - j)`, where `abs(x)` is the **absolute value** of `x`. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/10/31/eg1.png) + +**Input:** colors = [**1**,1,1,**6**,1,1,1] + +**Output:** 3 + +**Explanation:** In the above image, color 1 is blue, and color 6 is red. + +The furthest two houses with different colors are house 0 and house 3. + +House 0 has color 1, and house 3 has color 6. + +The distance between them is abs(0 - 3) = 3. + +Note that houses 3 and 6 can also produce the optimal answer. + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2021/10/31/eg2.png) + +**Input:** colors = [**1**,8,3,8,**3**] + +**Output:** 4 + +**Explanation:** In the above image, color 1 is blue, color 8 is yellow, and color 3 is green. + +The furthest two houses with different colors are house 0 and house 4. + +House 0 has color 1, and house 4 has color 3. + +The distance between them is abs(0 - 4) = 4. + +**Example 3:** + +**Input:** colors = [**0**,**1**] + +**Output:** 1 + +**Explanation:** The furthest two houses with different colors are house 0 and house 1. + +House 0 has color 0, and house 1 has color 1. + +The distance between them is abs(0 - 1) = 1. + +**Constraints:** + +* `n == colors.length` +* `2 <= n <= 100` +* `0 <= colors[i] <= 100` +* Test data are generated such that **at least** two houses have different colors. + +## Solution + +```kotlin +class Solution { + fun maxDistance(colors: IntArray): Int { + var left = 0 + var right = colors.size - 1 + var max = 0 + while (left < right) { + if (colors[left] != colors[right]) { + max = max.coerceAtLeast(right - left) + break + } else { + left++ + } + } + left = 0 + while (left < right) { + if (colors[left] != colors[right]) { + max = max.coerceAtLeast(right - left) + break + } else { + right-- + } + } + return max + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2079_watering_plants/readme.md b/src/main/kotlin/g2001_2100/s2079_watering_plants/readme.md new file mode 100644 index 00000000..6200753f --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2079_watering_plants/readme.md @@ -0,0 +1,100 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2079\. Watering Plants + +Medium + +You want to water `n` plants in your garden with a watering can. The plants are arranged in a row and are labeled from `0` to `n - 1` from left to right where the ith plant is located at `x = i`. There is a river at `x = -1` that you can refill your watering can at. + +Each plant needs a specific amount of water. You will water the plants in the following way: + +* Water the plants in order from left to right. +* After watering the current plant, if you do not have enough water to **completely** water the next plant, return to the river to fully refill the watering can. +* You **cannot** refill the watering can early. + +You are initially at the river (i.e., `x = -1`). It takes **one step** to move **one unit** on the x-axis. + +Given a **0-indexed** integer array `plants` of `n` integers, where `plants[i]` is the amount of water the ith plant needs, and an integer `capacity` representing the watering can capacity, return _the **number of steps** needed to water all the plants_. + +**Example 1:** + +**Input:** plants = [2,2,3,3], capacity = 5 + +**Output:** 14 + +**Explanation:** Start at the river with a full watering can: + +- Walk to plant 0 (1 step) and water it. Watering can has 3 units of water. + +- Walk to plant 1 (1 step) and water it. Watering can has 1 unit of water. + +- Since you cannot completely water plant 2, walk back to the river to refill (2 steps). + +- Walk to plant 2 (3 steps) and water it. Watering can has 2 units of water. + +- Since you cannot completely water plant 3, walk back to the river to refill (3 steps). + +- Walk to plant 3 (4 steps) and water it. + +Steps needed = 1 + 1 + 2 + 3 + 3 + 4 = 14. + +**Example 2:** + +**Input:** plants = [1,1,1,4,2,3], capacity = 4 + +**Output:** 30 + +**Explanation:** Start at the river with a full watering can: + +- Water plants 0, 1, and 2 (3 steps). Return to river (3 steps). + +- Water plant 3 (4 steps). Return to river (4 steps). + +- Water plant 4 (5 steps). Return to river (5 steps). + +- Water plant 5 (6 steps). + +Steps needed = 3 + 3 + 4 + 4 + 5 + 5 + 6 = 30. + +**Example 3:** + +**Input:** plants = [7,7,7,7,7,7,7], capacity = 8 + +**Output:** 49 + +**Explanation:** You have to refill before watering each plant. + +Steps needed = 1 + 1 + 2 + 2 + 3 + 3 + 4 + 4 + 5 + 5 + 6 + 6 + 7 = 49. + +**Constraints:** + +* `n == plants.length` +* `1 <= n <= 1000` +* 1 <= plants[i] <= 106 +* max(plants[i]) <= capacity <= 109 + +## Solution + +```kotlin +@Suppress("NAME_SHADOWING") +class Solution { + fun wateringPlants(plants: IntArray, capacity: Int): Int { + var capacity = capacity + val initial = capacity + var ans = 0 + for (i in plants.indices) { + if (plants[i] <= capacity) { + ++ans + capacity -= plants[i] + } else { + ans += i + capacity = initial + ans += i + 1 + capacity -= plants[i] + } + } + return ans + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2080_range_frequency_queries/readme.md b/src/main/kotlin/g2001_2100/s2080_range_frequency_queries/readme.md new file mode 100644 index 00000000..72debafd --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2080_range_frequency_queries/readme.md @@ -0,0 +1,75 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2080\. Range Frequency Queries + +Medium + +Design a data structure to find the **frequency** of a given value in a given subarray. + +The **frequency** of a value in a subarray is the number of occurrences of that value in the subarray. + +Implement the `RangeFreqQuery` class: + +* `RangeFreqQuery(int[] arr)` Constructs an instance of the class with the given **0-indexed** integer array `arr`. +* `int query(int left, int right, int value)` Returns the **frequency** of `value` in the subarray `arr[left...right]`. + +A **subarray** is a contiguous sequence of elements within an array. `arr[left...right]` denotes the subarray that contains the elements of `nums` between indices `left` and `right` (**inclusive**). + +**Example 1:** + +**Input** + + ["RangeFreqQuery", "query", "query"] + [[[12, 33, 4, 56, 22, 2, 34, 33, 22, 12, 34, 56]], [1, 2, 4], [0, 11, 33]] + +**Output:** [null, 1, 2] + +**Explanation:** + + RangeFreqQuery rangeFreqQuery = new RangeFreqQuery([12, 33, 4, 56, 22, 2, 34, 33, 22, 12, 34, 56]); + rangeFreqQuery.query(1, 2, 4); // return 1. The value 4 occurs 1 time in the subarray [33, 4] + rangeFreqQuery.query(0, 11, 33); // return 2. The value 33 occurs 2 times in the whole array. + +**Constraints:** + +* 1 <= arr.length <= 105 +* 1 <= arr[i], value <= 104 +* `0 <= left <= right < arr.length` +* At most 105 calls will be made to `query` + +## Solution + +```kotlin +import java.util.Collections + +class RangeFreqQuery(arr: IntArray) { + private val map: MutableMap> + + init { + map = HashMap() + for (i in arr.indices) { + if (!map.containsKey(arr[i])) { + map[arr[i]] = ArrayList() + } + map[arr[i]]!!.add(i) + } + } + + fun query(left: Int, right: Int, value: Int): Int { + if (!map.containsKey(value)) { + return 0 + } + val list: List = map[value]!! + var s = Collections.binarySearch(list, left) + var e = Collections.binarySearch(list, right) + if (s < 0) { + s = (s + 1) * -1 + } + if (e < 0) { + e = (e + 2) * -1 + } + return e - s + 1 + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2081_sum_of_k_mirror_numbers/readme.md b/src/main/kotlin/g2001_2100/s2081_sum_of_k_mirror_numbers/readme.md new file mode 100644 index 00000000..3120f574 --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2081_sum_of_k_mirror_numbers/readme.md @@ -0,0 +1,123 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2081\. Sum of k-Mirror Numbers + +Hard + +A **k-mirror number** is a **positive** integer **without leading zeros** that reads the same both forward and backward in base-10 **as well as** in base-k. + +* For example, `9` is a 2-mirror number. The representation of `9` in base-10 and base-2 are `9` and `1001` respectively, which read the same both forward and backward. +* On the contrary, `4` is not a 2-mirror number. The representation of `4` in base-2 is `100`, which does not read the same both forward and backward. + +Given the base `k` and the number `n`, return _the **sum** of the_ `n` _**smallest** k-mirror numbers_. + +**Example 1:** + +**Input:** k = 2, n = 5 + +**Output:** 25 + +**Explanation:** + +The 5 smallest 2-mirror numbers and their representations in base-2 are listed as follows: + + base-10 base-2 + 1 1 + 3 11 + 5 101 + 7 111 + 9 1001 + Their sum = 1 + 3 + 5 + 7 + 9 = 25. + +**Example 2:** + +**Input:** k = 3, n = 7 + +**Output:** 499 + +**Explanation:** The 7 smallest 3-mirror numbers are and their representations in base-3 are listed as follows: + + base-10 base-3 + 1 1 + 2 2 + 4 11 + 8 22 + 121 11111 + 151 12121 + 212 21212 + Their sum = 1 + 2 + 4 + 8 + 121 + 151 + 212 = 499. + +**Example 3:** + +**Input:** k = 7, n = 17 + +**Output:** 20379000 + +**Explanation:** The 17 smallest 7-mirror numbers are: + +1, 2, 3, 4, 5, 6, 8, 121, 171, 242, 292, 16561, 65656, 2137312, 4602064, 6597956, 6958596 + +**Constraints:** + +* `2 <= k <= 9` +* `1 <= n <= 30` + +## Solution + +```kotlin +class Solution { + fun kMirror(k: Int, n: Int): Long { + val result: MutableList = ArrayList() + var len = 1 + while (result.size < n) { + backtrack(result, CharArray(len++), k, n, 0) + } + var sum: Long = 0 + for (num in result) { + sum += num + } + return sum + } + + private fun backtrack(result: MutableList, arr: CharArray, k: Int, n: Int, index: Int) { + if (result.size == n) { + return + } + if (index >= (arr.size + 1) / 2) { + // Number in base-10 + val number = String(arr).toLong(k) + if (isPalindrome(number)) { + result.add(number) + } + return + } + // Generate base-k palindrome number in arr.length without leading zeros + for (i in 0 until k) { + if (index == 0 && i == 0) { + // Leading zeros + continue + } + val c: Char = (i + '0'.code).toChar() + arr[index] = c + arr[arr.size - 1 - index] = c + backtrack(result, arr, k, n, index + 1) + } + } + + private fun isPalindrome(number: Long): Boolean { + val strNum = number.toString() + var left = 0 + var right = strNum.length - 1 + while (left < right) { + if (strNum[left] == strNum[right]) { + left++ + right-- + } else { + return false + } + } + return true + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2085_count_common_words_with_one_occurrence/readme.md b/src/main/kotlin/g2001_2100/s2085_count_common_words_with_one_occurrence/readme.md new file mode 100644 index 00000000..ccd1fdfe --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2085_count_common_words_with_one_occurrence/readme.md @@ -0,0 +1,85 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2085\. Count Common Words With One Occurrence + +Easy + +Given two string arrays `words1` and `words2`, return _the number of strings that appear **exactly once** in **each** of the two arrays._ + +**Example 1:** + +**Input:** words1 = ["leetcode","is","amazing","as","is"], words2 = ["amazing","leetcode","is"] + +**Output:** 2 + +**Explanation:** + +- "leetcode" appears exactly once in each of the two arrays. We count this string. + +- "amazing" appears exactly once in each of the two arrays. We count this string. + +- "is" appears in each of the two arrays, but there are 2 occurrences of it in words1. We do not count this string. + +- "as" appears once in words1, but does not appear in words2. We do not count this string. + +Thus, there are 2 strings that appear exactly once in each of the two arrays. + +**Example 2:** + +**Input:** words1 = ["b","bb","bbb"], words2 = ["a","aa","aaa"] + +**Output:** 0 + +**Explanation:** There are no strings that appear in each of the two arrays. + +**Example 3:** + +**Input:** words1 = ["a","ab"], words2 = ["a","a","a","ab"] + +**Output:** 1 + +**Explanation:** The only string that appears exactly once in each of the two arrays is "ab". + +**Constraints:** + +* `1 <= words1.length, words2.length <= 1000` +* `1 <= words1[i].length, words2[j].length <= 30` +* `words1[i]` and `words2[j]` consists only of lowercase English letters. + +## Solution + +```kotlin +class Solution { + fun countWords(words1: Array, words2: Array): Int { + var count = 0 + val map = HashMap() + val map1 = HashMap() + // Putting the "words1" array in the map + for (s in words1) { + if (!map.containsKey(s)) { + map[s] = 1 + } else { + map[s] = map[s]!! + 1 + } + } + // Putting "words2" array in another map + for (s in words2) { + if (!map1.containsKey(s)) { + map1[s] = 1 + } else { + map1[s] = map1[s]!! + 1 + } + } + // traversing through the "words1" array + for (s in words1) { + // Checking if the key is present and is matching in both maps + // and if the key has appeared just one time in "map1" map + if (map[s] == map1[s] && map1[s] == 1) { + count++ + } + } + return count + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2086_minimum_number_of_food_buckets_to_feed_the_hamsters/readme.md b/src/main/kotlin/g2001_2100/s2086_minimum_number_of_food_buckets_to_feed_the_hamsters/readme.md new file mode 100644 index 00000000..b2edf9dd --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2086_minimum_number_of_food_buckets_to_feed_the_hamsters/readme.md @@ -0,0 +1,103 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2086\. Minimum Number of Buckets Required to Collect Rainwater from Houses + +Medium + +You are given a **0-index****ed** string `street`. Each character in `street` is either `'H'` representing a house or `'.'` representing an empty space. + +You can place buckets on the **empty spaces** to collect rainwater that falls from the adjacent houses. The rainwater from a house at index `i` is collected if a bucket is placed at index `i - 1` **and/or** index `i + 1`. A single bucket, if placed adjacent to two houses, can collect the rainwater from **both** houses. + +Return _the **minimum** number of buckets needed so that for **every** house, there is **at least** one bucket collecting rainwater from it, or_ `-1` _if it is impossible._ + +**Example 1:** + +**Input:** street = "H..H" + +**Output:** 2 + +**Explanation:** + +We can put buckets at index 1 and index 2. + +"H..H" -> "HBBH" ('B' denotes where a bucket is placed). + +The house at index 0 has a bucket to its right, and the house at index 3 has a bucket to its left. + +Thus, for every house, there is at least one bucket collecting rainwater from it. + +**Example 2:** + +**Input:** street = ".H.H." + +**Output:** 1 + +**Explanation:** + +We can put a bucket at index 2. + +".H.H." -> ".HBH." ('B' denotes where a bucket is placed). + +The house at index 1 has a bucket to its right, and the house at index 3 has a bucket to its left. + +Thus, for every house, there is at least one bucket collecting rainwater from it. + +**Example 3:** + +**Input:** street = ".HHH." + +**Output:** -1 + +**Explanation:** + +There is no empty space to place a bucket to collect the rainwater from the house at index 2. + +Thus, it is impossible to collect the rainwater from all the houses. + +**Constraints:** + +* 1 <= street.length <= 105 +* `street[i]` is either`'H'` or `'.'`. + +## Solution + +```kotlin +class Solution { + fun minimumBuckets(street: String): Int { + // check if houses have space in between or not + // eg:".HHH." + // array formation + val arr = street.toCharArray() + for (i in arr.indices) { + if (arr[i] == '.') { + continue + } + if (i + 1 < arr.size && arr[i + 1] == '.') { + continue + } + // H is present before curr character + if (i - 1 >= 0 && arr[i - 1] == '.') { + continue + } + return -1 + } + var x = 0 + for (j in arr.indices) { + // point move next we only take care of H + if (arr[j] == 'H') { + if (j - 1 >= 0 && arr[j - 1] == 'X') { + continue + } + if (j + 1 < arr.size && arr[j + 1] == '.') { + arr[j + 1] = 'X' + } else { + arr[j - 1] = 'X' + } + x++ + } + } + return x + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2087_minimum_cost_homecoming_of_a_robot_in_a_grid/readme.md b/src/main/kotlin/g2001_2100/s2087_minimum_cost_homecoming_of_a_robot_in_a_grid/readme.md new file mode 100644 index 00000000..448b83e3 --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2087_minimum_cost_homecoming_of_a_robot_in_a_grid/readme.md @@ -0,0 +1,100 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2087\. Minimum Cost Homecoming of a Robot in a Grid + +Medium + +There is an `m x n` grid, where `(0, 0)` is the top-left cell and `(m - 1, n - 1)` is the bottom-right cell. You are given an integer array `startPos` where startPos = [startrow, startcol] indicates that **initially**, a **robot** is at the cell (startrow, startcol). You are also given an integer array `homePos` where homePos = [homerow, homecol] indicates that its **home** is at the cell (homerow, homecol). + +The robot needs to go to its home. It can move one cell in four directions: **left**, **right**, **up**, or **down**, and it can not move outside the boundary. Every move incurs some cost. You are further given two **0-indexed** integer arrays: `rowCosts` of length `m` and `colCosts` of length `n`. + +* If the robot moves **up** or **down** into a cell whose **row** is `r`, then this move costs `rowCosts[r]`. +* If the robot moves **left** or **right** into a cell whose **column** is `c`, then this move costs `colCosts[c]`. + +Return _the **minimum total cost** for this robot to return home_. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/10/11/eg-1.png) + +**Input:** startPos = [1, 0], homePos = [2, 3], rowCosts = [5, 4, 3], colCosts = [8, 2, 6, 7] + +**Output:** 18 + +**Explanation:** One optimal path is that: + +Starting from (1, 0) + +-> It goes down to (**2**, 0). This move costs rowCosts[2] = 3. + +-> It goes right to (2, **1**). This move costs colCosts[1] = 2. + +-> It goes right to (2, **2**). This move costs colCosts[2] = 6. + +-> It goes right to (2, **3**). This move costs colCosts[3] = 7. + +The total cost is 3 + 2 + 6 + 7 = 18 + +**Example 2:** + +**Input:** startPos = [0, 0], homePos = [0, 0], rowCosts = [5], colCosts = [26] + +**Output:** 0 + +**Explanation:** The robot is already at its home. Since no moves occur, the total cost is 0. + +**Constraints:** + +* `m == rowCosts.length` +* `n == colCosts.length` +* 1 <= m, n <= 105 +* 0 <= rowCosts[r], colCosts[c] <= 104 +* `startPos.length == 2` +* `homePos.length == 2` +* 0 <= startrow, homerow < m +* 0 <= startcol, homecol < n + +## Solution + +```kotlin +class Solution { + fun minCost(startPos: IntArray, homePos: IntArray, rowCosts: IntArray, colCosts: IntArray): Int { + val sx = startPos[0] + val sy = startPos[1] + val ex = homePos[0] + val ey = homePos[1] + if (sx == ex && sy == ey) { + return 0 + } + var total = 0 + if (sx < ex) { + var i = sx + while (i < ex) { + i++ + total += rowCosts[i] + } + } else { + var i = sx + while (i > ex) { + i-- + total += rowCosts[i] + } + } + if (sy < ey) { + var i = sy + while (i < ey) { + i++ + total += colCosts[i] + } + } else { + var i = sy + while (i > ey) { + i-- + total += colCosts[i] + } + } + return total + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2088_count_fertile_pyramids_in_a_land/readme.md b/src/main/kotlin/g2001_2100/s2088_count_fertile_pyramids_in_a_land/readme.md new file mode 100644 index 00000000..c10fe44a --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2088_count_fertile_pyramids_in_a_land/readme.md @@ -0,0 +1,110 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2088\. Count Fertile Pyramids in a Land + +Hard + +A farmer has a **rectangular grid** of land with `m` rows and `n` columns that can be divided into unit cells. Each cell is either **fertile** (represented by a `1`) or **barren** (represented by a `0`). All cells outside the grid are considered barren. + +A **pyramidal plot** of land can be defined as a set of cells with the following criteria: + +1. The number of cells in the set has to be **greater than** `1` and all cells must be **fertile**. +2. The **apex** of a pyramid is the **topmost** cell of the pyramid. The **height** of a pyramid is the number of rows it covers. Let `(r, c)` be the apex of the pyramid, and its height be `h`. Then, the plot comprises of cells `(i, j)` where `r <= i <= r + h - 1` **and** `c - (i - r) <= j <= c + (i - r)`. + +An **inverse pyramidal plot** of land can be defined as a set of cells with similar criteria: + +1. The number of cells in the set has to be **greater than** `1` and all cells must be **fertile**. +2. The **apex** of an inverse pyramid is the **bottommost** cell of the inverse pyramid. The **height** of an inverse pyramid is the number of rows it covers. Let `(r, c)` be the apex of the pyramid, and its height be `h`. Then, the plot comprises of cells `(i, j)` where `r - h + 1 <= i <= r` **and** `c - (r - i) <= j <= c + (r - i)`. + +Some examples of valid and invalid pyramidal (and inverse pyramidal) plots are shown below. Black cells indicate fertile cells. + +![](https://assets.leetcode.com/uploads/2021/11/08/image.png) + +Given a **0-indexed** `m x n` binary matrix `grid` representing the farmland, return _the **total number** of pyramidal and inverse pyramidal plots that can be found in_ `grid`. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/12/22/1.JPG) + +**Input:** grid = \[\[0,1,1,0],[1,1,1,1]] + +**Output:** 2 + +**Explanation:** The 2 possible pyramidal plots are shown in blue and red respectively. + +There are no inverse pyramidal plots in this grid. + +Hence total number of pyramidal and inverse pyramidal plots is 2 + 0 = 2. + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2021/12/22/2.JPG) + +**Input:** grid = \[\[1,1,1],[1,1,1]] + +**Output:** 2 + +**Explanation:** The pyramidal plot is shown in blue, and the inverse pyramidal plot is shown in red. + +Hence the total number of plots is 1 + 1 = 2. + +**Example 3:** + +![](https://assets.leetcode.com/uploads/2021/12/22/3.JPG) + +**Input:** grid = \[\[1,1,1,1,0],[1,1,1,1,1],[1,1,1,1,1],[0,1,0,0,1]] + +**Output:** 13 + +**Explanation:** There are 7 pyramidal plots, 3 of which are shown in the 2nd and 3rd figures. + +There are 6 inverse pyramidal plots, 2 of which are shown in the last figure. + +The total number of plots is 7 + 6 = 13. + +**Constraints:** + +* `m == grid.length` +* `n == grid[i].length` +* `1 <= m, n <= 1000` +* 1 <= m * n <= 105 +* `grid[i][j]` is either `0` or `1`. + +## Solution + +```kotlin +class Solution { + fun countPyramids(grid: Array): Int { + val m = grid.size + val n = grid[0].size + val rev = Array(m) { IntArray(n) } + for (i in 0 until m) { + System.arraycopy(grid[i], 0, rev[m - i - 1], 0, n) + } + return cal(grid) + cal(rev) + } + + private fun cal(grid: Array): Int { + val m = grid.size + val n = grid[0].size + var res = 0 + for (i in 1 until m) { + var cnt = 0 + for (j in 0 until n) { + if (0 != grid[i][j]) { + cnt++ + } else { + cnt = 0 + } + if (0 == cnt || 0 == j) { + continue + } + grid[i][j] = (grid[i - 1][j - 1] + 1).coerceAtMost(cnt + 1 shr 1) + res += grid[i][j] - 1 + } + } + return res + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2089_find_target_indices_after_sorting_array/readme.md b/src/main/kotlin/g2001_2100/s2089_find_target_indices_after_sorting_array/readme.md new file mode 100644 index 00000000..d3592da2 --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2089_find_target_indices_after_sorting_array/readme.md @@ -0,0 +1,71 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2089\. Find Target Indices After Sorting Array + +Easy + +You are given a **0-indexed** integer array `nums` and a target element `target`. + +A **target index** is an index `i` such that `nums[i] == target`. + +Return _a list of the target indices of_ `nums` after _sorting_ `nums` _in **non-decreasing** order_. If there are no target indices, return _an **empty** list_. The returned list must be sorted in **increasing** order. + +**Example 1:** + +**Input:** nums = [1,2,5,2,3], target = 2 + +**Output:** [1,2] + +**Explanation:** After sorting, nums is [1,**2**,**2**,3,5]. + +The indices where nums[i] == 2 are 1 and 2. + +**Example 2:** + +**Input:** nums = [1,2,5,2,3], target = 3 + +**Output:** [3] + +**Explanation:** After sorting, nums is [1,2,2,**3**,5]. + +The index where nums[i] == 3 is 3. + +**Example 3:** + +**Input:** nums = [1,2,5,2,3], target = 5 + +**Output:** [4] + +**Explanation:** After sorting, nums is [1,2,2,3,**5**]. + +The index where nums[i] == 5 is 4. + +**Constraints:** + +* `1 <= nums.length <= 100` +* `1 <= nums[i], target <= 100` + +## Solution + +```kotlin +class Solution { + fun targetIndices(nums: IntArray, target: Int): List { + var count = 0 + var lessthan = 0 + for (n in nums) { + if (n == target) { + count++ + } + if (n < target) { + lessthan++ + } + } + val result: MutableList = ArrayList() + for (i in 0 until count) { + result.add(lessthan++) + } + return result + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2090_k_radius_subarray_averages/readme.md b/src/main/kotlin/g2001_2100/s2090_k_radius_subarray_averages/readme.md new file mode 100644 index 00000000..1834cc74 --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2090_k_radius_subarray_averages/readme.md @@ -0,0 +1,96 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2090\. K Radius Subarray Averages + +Medium + +You are given a **0-indexed** array `nums` of `n` integers, and an integer `k`. + +The **k-radius average** for a subarray of `nums` **centered** at some index `i` with the **radius** `k` is the average of **all** elements in `nums` between the indices `i - k` and `i + k` (**inclusive**). If there are less than `k` elements before **or** after the index `i`, then the **k-radius average** is `-1`. + +Build and return _an array_ `avgs` _of length_ `n` _where_ `avgs[i]` _is the **k-radius average** for the subarray centered at index_ `i`. + +The **average** of `x` elements is the sum of the `x` elements divided by `x`, using **integer division**. The integer division truncates toward zero, which means losing its fractional part. + +* For example, the average of four elements `2`, `3`, `1`, and `5` is `(2 + 3 + 1 + 5) / 4 = 11 / 4 = 2.75`, which truncates to `2`. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/11/07/eg1.png) + +**Input:** nums = [7,4,3,9,1,8,5,2,6], k = 3 + +**Output:** [-1,-1,-1,5,4,4,-1,-1,-1] + +**Explanation:** + +- avg[0], avg[1], and avg[2] are -1 because there are less than k elements **before** each index. + +- The sum of the subarray centered at index 3 with radius 3 is: 7 + 4 + 3 + 9 + 1 + 8 + 5 = 37. + + Using **integer division**, avg[3] = 37 / 7 = 5. + +- For the subarray centered at index 4, avg[4] = (4 + 3 + 9 + 1 + 8 + 5 + 2) / 7 = 4. + +- For the subarray centered at index 5, avg[5] = (3 + 9 + 1 + 8 + 5 + 2 + 6) / 7 = 4. + +- avg[6], avg[7], and avg[8] are -1 because there are less than k elements **after** each index. + +**Example 2:** + +**Input:** nums = [100000], k = 0 + +**Output:** [100000] + +**Explanation:** + +- The sum of the subarray centered at index 0 with radius 0 is: 100000. + + avg[0] = 100000 / 1 = 100000. + +**Example 3:** + +**Input:** nums = [8], k = 100000 + +**Output:** [-1] + +**Explanation:** + +- avg[0] is -1 because there are less than k elements before and after index 0. + +**Constraints:** + +* `n == nums.length` +* 1 <= n <= 105 +* 0 <= nums[i], k <= 105 + +## Solution + +```kotlin +class Solution { + fun getAverages(nums: IntArray, k: Int): IntArray { + // initialize result array with -1 + val res = IntArray(nums.size) + res.fill(-1) + if (nums.size <= k * 2) { + // return if not enough elements + return res + } + var sum: Long = 0 + val range = 2 * k + 1L + // take sum of all elements from 0 to k*2 index + for (i in 0..2 * k) { + sum += nums[i].toLong() + } + // update first valid avg + res[k] = (sum / range).toInt() + // update other valid averages using sliding window + for (i in k + 1 until nums.size - k) { + sum = sum - nums[i - k - 1] + nums[i + k] + res[i] = (sum / range).toInt() + } + return res + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2091_removing_minimum_and_maximum_from_array/readme.md b/src/main/kotlin/g2001_2100/s2091_removing_minimum_and_maximum_from_array/readme.md new file mode 100644 index 00000000..18b69181 --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2091_removing_minimum_and_maximum_from_array/readme.md @@ -0,0 +1,101 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2091\. Removing Minimum and Maximum From Array + +Medium + +You are given a **0-indexed** array of **distinct** integers `nums`. + +There is an element in `nums` that has the **lowest** value and an element that has the **highest** value. We call them the **minimum** and **maximum** respectively. Your goal is to remove **both** these elements from the array. + +A **deletion** is defined as either removing an element from the **front** of the array or removing an element from the **back** of the array. + +Return _the **minimum** number of deletions it would take to remove **both** the minimum and maximum element from the array._ + +**Example 1:** + +**Input:** nums = [2,**10**,7,5,4,**1**,8,6] + +**Output:** 5 + +**Explanation:** + +The minimum element in the array is nums[5], which is 1. + +The maximum element in the array is nums[1], which is 10. + +We can remove both the minimum and maximum by removing 2 elements from the front and 3 elements from the back. + +This results in 2 + 3 = 5 deletions, which is the minimum number possible. + +**Example 2:** + +**Input:** nums = [0,**\-4**,**19**,1,8,-2,-3,5] + +**Output:** 3 + +**Explanation:** + +The minimum element in the array is nums[1], which is -4. + +The maximum element in the array is nums[2], which is 19. + +We can remove both the minimum and maximum by removing 3 elements from the front. + +This results in only 3 deletions, which is the minimum number possible. + +**Example 3:** + +**Input:** nums = [**101**] + +**Output:** 1 + +**Explanation:** + +There is only one element in the array, which makes it both the minimum and maximum element. + +We can remove it with 1 deletion. + +**Constraints:** + +* 1 <= nums.length <= 105 +* -105 <= nums[i] <= 105 +* The integers in `nums` are **distinct**. + +## Solution + +```kotlin +class Solution { + fun minimumDeletions(nums: IntArray): Int { + val n = nums.size + var min = Int.MAX_VALUE + var max = Int.MIN_VALUE + var minIndex = 0 + var maxIndex = 0 + for (i in nums.indices) { + if (nums[i] < min) { + min = nums[i] + minIndex = i + } + if (nums[i] > max) { + max = nums[i] + maxIndex = i + } + } + val firstCase: Int + val secondCase: Int + val thirdCase: Int + if (minIndex > maxIndex) { + firstCase = minIndex + 1 + secondCase = n - maxIndex + thirdCase = maxIndex + 1 + (n - minIndex) + } else { + firstCase = maxIndex + 1 + secondCase = n - minIndex + thirdCase = minIndex + 1 + (n - maxIndex) + } + return firstCase.coerceAtMost(secondCase.coerceAtMost(thirdCase)) + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2092_find_all_people_with_secret/readme.md b/src/main/kotlin/g2001_2100/s2092_find_all_people_with_secret/readme.md new file mode 100644 index 00000000..1363ca10 --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2092_find_all_people_with_secret/readme.md @@ -0,0 +1,167 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2092\. Find All People With Secret + +Hard + +You are given an integer `n` indicating there are `n` people numbered from `0` to `n - 1`. You are also given a **0-indexed** 2D integer array `meetings` where meetings[i] = [xi, yi, timei] indicates that person xi and person yi have a meeting at timei. A person may attend **multiple meetings** at the same time. Finally, you are given an integer `firstPerson`. + +Person `0` has a **secret** and initially shares the secret with a person `firstPerson` at time `0`. This secret is then shared every time a meeting takes place with a person that has the secret. More formally, for every meeting, if a person xi has the secret at timei, then they will share the secret with person yi, and vice versa. + +The secrets are shared **instantaneously**. That is, a person may receive the secret and share it with people in other meetings within the same time frame. + +Return _a list of all the people that have the secret after all the meetings have taken place._ You may return the answer in **any order**. + +**Example 1:** + +**Input:** n = 6, meetings = \[\[1,2,5],[2,3,8],[1,5,10]], firstPerson = 1 + +**Output:** [0,1,2,3,5] + +**Explanation:** + +At time 0, person 0 shares the secret with person 1. + +At time 5, person 1 shares the secret with person 2. + +At time 8, person 2 shares the secret with person 3. + +At time 10, person 1 shares the secret with person 5. + +Thus, people 0, 1, 2, 3, and 5 know the secret after all the meetings. + +**Example 2:** + +**Input:** n = 4, meetings = \[\[3,1,3],[1,2,2],[0,3,3]], firstPerson = 3 + +**Output:** [0,1,3] + +**Explanation:** + +At time 0, person 0 shares the secret with person 3. + +At time 2, neither person 1 nor person 2 know the secret. + +At time 3, person 3 shares the secret with person 0 and person 1. + +Thus, people 0, 1, and 3 know the secret after all the meetings. + +**Example 3:** + +**Input:** n = 5, meetings = \[\[3,4,2],[1,2,1],[2,3,1]], firstPerson = 1 + +**Output:** [0,1,2,3,4] + +**Explanation:** + +At time 0, person 0 shares the secret with person 1. + +At time 1, person 1 shares the secret with person 2, and person 2 shares the secret with person 3. + +Note that person 2 can share the secret at the same time as receiving it. + +At time 2, person 3 shares the secret with person 4. + +Thus, people 0, 1, 2, 3, and 4 know the secret after all the meetings. + +**Constraints:** + +* 2 <= n <= 105 +* 1 <= meetings.length <= 105 +* `meetings[i].length == 3` +* 0 <= xi, yi <= n - 1 +* xi != yi +* 1 <= timei <= 105 +* `1 <= firstPerson <= n - 1` + +## Solution + +```kotlin +import java.util.Arrays + +@Suppress("NAME_SHADOWING") +class Solution { + fun findAllPeople(n: Int, meetings: Array, firstPerson: Int): List { + Arrays.sort(meetings) { a: IntArray, b: IntArray -> a[2] - b[2] } + val uf = UF(n) + // base + uf.union(0, firstPerson) + // for every time we have a pool of people that talk to each other + // if someone knows a secret proir to this meeting - all pool will too + // if not - reset unions from this pool + var i = 0 + while (i < meetings.size) { + val curTime = meetings[i][2] + val pool: MutableSet = HashSet() + while (i < meetings.size && curTime == meetings[i][2]) { + val currentMeeting = meetings[i] + uf.union(currentMeeting[0], currentMeeting[1]) + pool.add(currentMeeting[0]) + pool.add(currentMeeting[1]) + i++ + } + // meeting that took place now should't affect future + // meetings if people don't know the secret + for (j in pool) { + if (!uf.connected(0, j)) { + uf.reset(j) + } + } + } + // if the person is conneted to 0 - they know a secret + val ans: MutableList = ArrayList() + for (j in 0 until n) { + if (uf.connected(j, 0)) { + ans.add(j) + } + } + return ans + } + + // regular union find + private class UF(n: Int) { + private val parent: IntArray + private val rank: IntArray + + init { + parent = IntArray(n) + rank = IntArray(n) + for (i in 0 until n) { + parent[i] = i + } + } + + fun union(p: Int, q: Int) { + val rootP = find(p) + val rootQ = find(q) + if (rootP == rootQ) { + return + } + if (rank[rootP] < rank[rootQ]) { + parent[rootP] = rootQ + } else { + parent[rootQ] = rootP + rank[rootP]++ + } + } + + fun find(p: Int): Int { + var p = p + while (parent[p] != p) { + p = parent[parent[p]] + } + return p + } + + fun connected(p: Int, q: Int): Boolean { + return find(p) == find(q) + } + + fun reset(p: Int) { + parent[p] = p + rank[p] = 0 + } + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2094_finding_3_digit_even_numbers/readme.md b/src/main/kotlin/g2001_2100/s2094_finding_3_digit_even_numbers/readme.md new file mode 100644 index 00000000..9b81b186 --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2094_finding_3_digit_even_numbers/readme.md @@ -0,0 +1,88 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2094\. Finding 3-Digit Even Numbers + +Easy + +You are given an integer array `digits`, where each element is a digit. The array may contain duplicates. + +You need to find **all** the **unique** integers that follow the given requirements: + +* The integer consists of the **concatenation** of **three** elements from `digits` in **any** arbitrary order. +* The integer does not have **leading zeros**. +* The integer is **even**. + +For example, if the given `digits` were `[1, 2, 3]`, integers `132` and `312` follow the requirements. + +Return _a **sorted** array of the unique integers._ + +**Example 1:** + +**Input:** digits = [2,1,3,0] + +**Output:** [102,120,130,132,210,230,302,310,312,320] + +**Explanation:** All the possible integers that follow the requirements are in the output array. + +Notice that there are no **odd** integers or integers with **leading zeros**. + +**Example 2:** + +**Input:** digits = [2,2,8,8,2] + +**Output:** [222,228,282,288,822,828,882] + +**Explanation:** The same digit can be used as many times as it appears in digits. + +In this example, the digit 8 is used twice each time in 288, 828, and 882. + +**Example 3:** + +**Input:** digits = [3,7,5] + +**Output:** [] + +**Explanation:** No **even** integers can be formed using the given digits. + +**Constraints:** + +* `3 <= digits.length <= 100` +* `0 <= digits[i] <= 9` + +## Solution + +```kotlin +@Suppress("NAME_SHADOWING") +class Solution { + fun findEvenNumbers(digits: IntArray): IntArray { + val idx = IntArray(1) + val result = IntArray(9 * 10 * 5) + val digitMap = IntArray(10) + for (digit in digits) { + digitMap[digit]++ + } + dfs(result, digitMap, idx, 0) + return result.copyOfRange(0, idx[0]) + } + + private fun dfs(result: IntArray, digitMap: IntArray, idx: IntArray, `val`: Int) { + var `val` = `val` + if (`val` > 99) { + result[idx[0]++] = `val` + return + } + `val` *= 10 + for (i in 0..9) { + if (digitMap[i] == 0 || `val` == 0 && i == 0 || `val` > 99 && i and 1 == 1) { + continue + } + digitMap[i]-- + `val` += i + dfs(result, digitMap, idx, `val`) + `val` -= i + digitMap[i]++ + } + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2095_delete_the_middle_node_of_a_linked_list/readme.md b/src/main/kotlin/g2001_2100/s2095_delete_the_middle_node_of_a_linked_list/readme.md new file mode 100644 index 00000000..8c5508be --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2095_delete_the_middle_node_of_a_linked_list/readme.md @@ -0,0 +1,97 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2095\. Delete the Middle Node of a Linked List + +Medium + +You are given the `head` of a linked list. **Delete** the **middle node**, and return _the_ `head` _of the modified linked list_. + +The **middle node** of a linked list of size `n` is the ⌊n / 2⌋th node from the **start** using **0-based indexing**, where `⌊x⌋` denotes the largest integer less than or equal to `x`. + +* For `n` = `1`, `2`, `3`, `4`, and `5`, the middle nodes are `0`, `1`, `1`, `2`, and `2`, respectively. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/11/16/eg1drawio.png) + +**Input:** head = [1,3,4,7,1,2,6] + +**Output:** [1,3,4,1,2,6] + +**Explanation:** + +The above figure represents the given linked list. + +The indices of the nodes are written below. Since n = 7, node 3 with value 7 is the middle node, which is marked in red. + +We return the new list after removing this node. + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2021/11/16/eg2drawio.png) + +**Input:** head = [1,2,3,4] + +**Output:** [1,2,4] + +**Explanation:** + +The above figure represents the given linked list. + +For n = 4, node 2 with value 3 is the middle node, which is marked in red. + +**Example 3:** + +![](https://assets.leetcode.com/uploads/2021/11/16/eg3drawio.png) + +**Input:** head = [2,1] + +**Output:** [2] + +**Explanation:** + +The above figure represents the given linked list. + +For n = 2, node 1 with value 1 is the middle node, which is marked in red. + +Node 0 with value 2 is the only node remaining after removing node 1. + +**Constraints:** + +* The number of nodes in the list is in the range [1, 105]. +* 1 <= Node.val <= 105 + +## Solution + +```kotlin +import com_github_leetcode.ListNode + +/* + * Example: + * var li = ListNode(5) + * var v = li.`val` + * Definition for singly-linked list. + * class ListNode(var `val`: Int) { + * var next: ListNode? = null + * } + */ +class Solution { + fun deleteMiddle(head: ListNode?): ListNode? { + var slow = head + var fast = head + var prev: ListNode? = null + while (fast?.next != null) { + prev = slow + + slow = slow?.next + fast = fast.next?.next + } + if (slow == head) { + return null + } + prev?.next = slow?.next + return head + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2096_step_by_step_directions_from_a_binary_tree_node_to_another/readme.md b/src/main/kotlin/g2001_2100/s2096_step_by_step_directions_from_a_binary_tree_node_to_another/readme.md new file mode 100644 index 00000000..e2e1a5e7 --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2096_step_by_step_directions_from_a_binary_tree_node_to_another/readme.md @@ -0,0 +1,93 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2096\. Step-By-Step Directions From a Binary Tree Node to Another + +Medium + +You are given the `root` of a **binary tree** with `n` nodes. Each node is uniquely assigned a value from `1` to `n`. You are also given an integer `startValue` representing the value of the start node `s`, and a different integer `destValue` representing the value of the destination node `t`. + +Find the **shortest path** starting from node `s` and ending at node `t`. Generate step-by-step directions of such path as a string consisting of only the **uppercase** letters `'L'`, `'R'`, and `'U'`. Each letter indicates a specific direction: + +* `'L'` means to go from a node to its **left child** node. +* `'R'` means to go from a node to its **right child** node. +* `'U'` means to go from a node to its **parent** node. + +Return _the step-by-step directions of the **shortest path** from node_ `s` _to node_ `t`. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/11/15/eg1.png) + +**Input:** root = [5,1,2,3,null,6,4], startValue = 3, destValue = 6 + +**Output:** "UURL" + +**Explanation:** The shortest path is: 3 → 1 → 5 → 2 → 6. + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2021/11/15/eg2.png) + +**Input:** root = [2,1], startValue = 2, destValue = 1 + +**Output:** "L" + +**Explanation:** The shortest path is: 2 → 1. + +**Constraints:** + +* The number of nodes in the tree is `n`. +* 2 <= n <= 105 +* `1 <= Node.val <= n` +* All the values in the tree are **unique**. +* `1 <= startValue, destValue <= n` +* `startValue != destValue` + +## Solution + +```kotlin +import com_github_leetcode.TreeNode + +/* + * Example: + * var ti = TreeNode(5) + * var v = ti.`val` + * Definition for a binary tree node. + * class TreeNode(var `val`: Int) { + * var left: TreeNode? = null + * var right: TreeNode? = null + * } + */ +class Solution { + private fun find(n: TreeNode?, `val`: Int, sb: StringBuilder): Boolean { + if (n!!.`val` == `val`) { + return true + } + if (n.left != null && find(n.left, `val`, sb)) { + sb.append("L") + } else if (n.right != null && find(n.right, `val`, sb)) { + sb.append("R") + } + return sb.isNotEmpty() + } + + fun getDirections(root: TreeNode?, startValue: Int, destValue: Int): String { + val s = StringBuilder() + val d = StringBuilder() + find(root, startValue, s) + find(root, destValue, d) + var i = 0 + val maxI = d.length.coerceAtMost(s.length) + while (i < maxI && s[s.length - i - 1] == d[d.length - i - 1]) { + ++i + } + val result = StringBuilder() + for (j in 0 until s.length - i) { + result.append("U") + } + result.append(d.reverse().substring(i)) + return result.toString() + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2097_valid_arrangement_of_pairs/readme.md b/src/main/kotlin/g2001_2100/s2097_valid_arrangement_of_pairs/readme.md new file mode 100644 index 00000000..1d371949 --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2097_valid_arrangement_of_pairs/readme.md @@ -0,0 +1,128 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2097\. Valid Arrangement of Pairs + +Hard + +You are given a **0-indexed** 2D integer array `pairs` where pairs[i] = [starti, endi]. An arrangement of `pairs` is **valid** if for every index `i` where `1 <= i < pairs.length`, we have endi-1 == starti. + +Return _**any** valid arrangement of_ `pairs`. + +**Note:** The inputs will be generated such that there exists a valid arrangement of `pairs`. + +**Example 1:** + +**Input:** pairs = \[\[5,1],[4,5],[11,9],[9,4]] + +**Output:** [[11,9],[9,4],[4,5],[5,1]] + +**Explanation:** + +This is a valid arrangement since endi-1 always equals starti. + +end0 = 9 == 9 = start1 + +end1 = 4 == 4 = start2 + +end2 = 5 == 5 = start3 + +**Example 2:** + +**Input:** pairs = \[\[1,3],[3,2],[2,1]] + +**Output:** [[1,3],[3,2],[2,1]] + +**Explanation:** + +This is a valid arrangement since endi-1 always equals starti. + +end0 = 3 == 3 = start1 + +end1 = 2 == 2 = start2 + +The arrangements [[2,1],[1,3],[3,2]] and [[3,2],[2,1],[1,3]] are also valid. + +**Example 3:** + +**Input:** pairs = \[\[1,2],[1,3],[2,1]] + +**Output:** [[1,2],[2,1],[1,3]] + +**Explanation:** + +This is a valid arrangement since endi-1 always equals starti. + +end0 = 2 == 2 = start1 + +end1 = 1 == 1 = start2 + +**Constraints:** + +* 1 <= pairs.length <= 105 +* `pairs[i].length == 2` +* 0 <= starti, endi <= 109 +* starti != endi +* No two pairs are exactly the same. +* There **exists** a valid arrangement of `pairs`. + +## Solution + +```kotlin +import java.util.LinkedList +import java.util.Queue + +@Suppress("NAME_SHADOWING") +class Solution { + fun validArrangement(pairs: Array): Array { + val inOutedge = HashMap() + val adList = getAdList(pairs, inOutedge) + val start = getStart(inOutedge) + val res = Array(pairs.size) { IntArray(2) } + getRes(start, adList, res, pairs.size - 1) + return res + } + + private fun getAdList( + pairs: Array, + inOutEdge: HashMap + ): HashMap> { + val adList = HashMap>() + for (pair in pairs) { + val s = pair[0] + val d = pair[1] + val set = adList.computeIfAbsent(s) { _: Int? -> LinkedList() } + set.add(d) + val sEdgeCnt = inOutEdge.computeIfAbsent(s) { _: Int? -> IntArray(2) } + val dEdgeCnt = inOutEdge.computeIfAbsent(d) { _: Int? -> IntArray(2) } + sEdgeCnt[1]++ + dEdgeCnt[0]++ + } + return adList + } + + private fun getRes(k: Int, adList: HashMap>, res: Array, idx: Int): Int { + var idx = idx + val edges = adList[k] ?: return idx + while (edges.isNotEmpty()) { + val edge = edges.poll() + idx = getRes(edge, adList, res, idx) + res[idx--] = intArrayOf(k, edge) + } + return idx + } + + private fun getStart(map: HashMap): Int { + var start = -1 + for ((k, value) in map) { + val inEdge = value[0] + val outEdge = value[1] + start = k + if (outEdge - inEdge == 1) { + return k + } + } + return start + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2099_find_subsequence_of_length_k_with_the_largest_sum/readme.md b/src/main/kotlin/g2001_2100/s2099_find_subsequence_of_length_k_with_the_largest_sum/readme.md new file mode 100644 index 00000000..46fd791f --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2099_find_subsequence_of_length_k_with_the_largest_sum/readme.md @@ -0,0 +1,87 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2099\. Find Subsequence of Length K With the Largest Sum + +Easy + +You are given an integer array `nums` and an integer `k`. You want to find a **subsequence** of `nums` of length `k` that has the **largest** sum. + +Return _**any** such subsequence as an integer array of length_ `k`. + +A **subsequence** is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements. + +**Example 1:** + +**Input:** nums = [2,1,3,3], k = 2 + +**Output:** [3,3] + +**Explanation:** The subsequence has the largest sum of 3 + 3 = 6. + +**Example 2:** + +**Input:** nums = [-1,-2,3,4], k = 3 + +**Output:** [-1,3,4] + +**Explanation:** The subsequence has the largest sum of -1 + 3 + 4 = 6. + +**Example 3:** + +**Input:** nums = [3,4,3,3], k = 2 + +**Output:** [3,4] + +**Explanation:** The subsequence has the largest sum of 3 + 4 = 7. + +Another possible subsequence is [4, 3]. + +**Constraints:** + +* `1 <= nums.length <= 1000` +* -105 <= nums[i] <= 105 +* `1 <= k <= nums.length` + +## Solution + +```kotlin +import java.util.PriorityQueue + +class Solution { + fun maxSubsequence(nums: IntArray, k: Int): IntArray { + // Create proirity queue with min priority queue so that min element will be removed first, + // with index + // Add those unique index in a set + // Loop from 0 to n-1 and add element in result if set contains those index + // For ex. set has index 3,5,6 Just add those element. Order will be maintained + // We are defining the min priority queue + val q = PriorityQueue { a: IntArray, b: IntArray -> a[0] - b[0] } + // Add element with index to priority queue + for (i in nums.indices) { + q.offer(intArrayOf(nums[i], i)) + if (q.size > k) { + q.poll() + } + } + // Set to keep index + val index: MutableSet = HashSet() + // At the index in the set since index are unique + while (q.isNotEmpty()) { + val top = q.poll() + index.add(top[1]) + } + // Final result add here + val result = IntArray(k) + // Just add the element in the result for those index present in SET + var p = 0 + for (i in nums.indices) { + if (index.contains(i)) { + result[p] = nums[i] + ++p + } + } + return result + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2001_2100/s2100_find_good_days_to_rob_the_bank/readme.md b/src/main/kotlin/g2001_2100/s2100_find_good_days_to_rob_the_bank/readme.md new file mode 100644 index 00000000..56fb7ead --- /dev/null +++ b/src/main/kotlin/g2001_2100/s2100_find_good_days_to_rob_the_bank/readme.md @@ -0,0 +1,90 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2100\. Find Good Days to Rob the Bank + +Medium + +You and a gang of thieves are planning on robbing a bank. You are given a **0-indexed** integer array `security`, where `security[i]` is the number of guards on duty on the ith day. The days are numbered starting from `0`. You are also given an integer `time`. + +The ith day is a good day to rob the bank if: + +* There are at least `time` days before and after the ith day, +* The number of guards at the bank for the `time` days **before** `i` are **non-increasing**, and +* The number of guards at the bank for the `time` days **after** `i` are **non-decreasing**. + +More formally, this means day `i` is a good day to rob the bank if and only if `security[i - time] >= security[i - time + 1] >= ... >= security[i] <= ... <= security[i + time - 1] <= security[i + time]`. + +Return _a list of **all** days **(0-indexed)** that are good days to rob the bank_. _The order that the days are returned in does **not** matter._ + +**Example 1:** + +**Input:** security = [5,3,3,3,5,6,2], time = 2 + +**Output:** [2,3] + +**Explanation:** + +On day 2, we have security[0] >= security[1] >= security[2] <= security[3] <= security[4]. + +On day 3, we have security[1] >= security[2] >= security[3] <= security[4] <= security[5]. + +No other days satisfy this condition, so days 2 and 3 are the only good days to rob the bank. + +**Example 2:** + +**Input:** security = [1,1,1,1,1], time = 0 + +**Output:** [0,1,2,3,4] + +**Explanation:** Since time equals 0, every day is a good day to rob the bank, so return every day. + +**Example 3:** + +**Input:** security = [1,2,3,4,5,6], time = 2 + +**Output:** [] + +**Explanation:** + +No day has 2 days before it that have a non-increasing number of guards. + +Thus, no day is a good day to rob the bank, so return an empty list. + +**Constraints:** + +* 1 <= security.length <= 105 +* 0 <= security[i], time <= 105 + +## Solution + +```kotlin +class Solution { + fun goodDaysToRobBank(security: IntArray, time: Int): List { + val n = security.size + // dec: # of non-increasing elements before [i] + // inc: # of non-decreasing elements after [i] + val dec = IntArray(n) + val inc = IntArray(n) + for (i in 1 until n) { + if (security[i] <= security[i - 1]) { + dec[i] = dec[i - 1] + 1 + } + // no need for else, because array elements are inited as 0 + } + for (i in n - 2 downTo 0) { + if (security[i] <= security[i + 1]) { + inc[i] = inc[i + 1] + 1 + } + // no need for else, because array elements are inited as 0 + } + val res: MutableList = ArrayList() + for (i in 0 until n) { + if (dec[i] >= time && inc[i] >= time) { + res.add(i) + } + } + return res + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2101_2200/s2101_detonate_the_maximum_bombs/readme.md b/src/main/kotlin/g2101_2200/s2101_detonate_the_maximum_bombs/readme.md new file mode 100644 index 00000000..e6106cee --- /dev/null +++ b/src/main/kotlin/g2101_2200/s2101_detonate_the_maximum_bombs/readme.md @@ -0,0 +1,117 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2101\. Detonate the Maximum Bombs + +Medium + +You are given a list of bombs. The **range** of a bomb is defined as the area where its effect can be felt. This area is in the shape of a **circle** with the center as the location of the bomb. + +The bombs are represented by a **0-indexed** 2D integer array `bombs` where bombs[i] = [xi, yi, ri]. xi and yi denote the X-coordinate and Y-coordinate of the location of the ith bomb, whereas ri denotes the **radius** of its range. + +You may choose to detonate a **single** bomb. When a bomb is detonated, it will detonate **all bombs** that lie in its range. These bombs will further detonate the bombs that lie in their ranges. + +Given the list of `bombs`, return _the **maximum** number of bombs that can be detonated if you are allowed to detonate **only one** bomb_. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/11/06/desmos-eg-3.png) + +**Input:** bombs = \[\[2,1,3],[6,1,4]] + +**Output:** 2 + +**Explanation:** + +The above figure shows the positions and ranges of the 2 bombs. + +If we detonate the left bomb, the right bomb will not be affected. + +But if we detonate the right bomb, both bombs will be detonated. + +So the maximum bombs that can be detonated is max(1, 2) = 2. + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2021/11/06/desmos-eg-2.png) + +**Input:** bombs = \[\[1,1,5],[10,10,5]] + +**Output:** 1 + +**Explanation:** Detonating either bomb will not detonate the other bomb, so the maximum number of bombs that can be detonated is 1. + +**Example 3:** + +![](https://assets.leetcode.com/uploads/2021/11/07/desmos-eg1.png) + +**Input:** bombs = \[\[1,2,3],[2,3,1],[3,4,2],[4,5,3],[5,6,4]] + +**Output:** 5 + +**Explanation:** The best bomb to detonate is bomb 0 because: + +- Bomb 0 detonates bombs 1 and 2. The red circle denotes the range of bomb 0. + +- Bomb 2 detonates bomb 3. The blue circle denotes the range of bomb 2. + +- Bomb 3 detonates bomb 4. The green circle denotes the range of bomb 3. + +Thus all 5 bombs are detonated. + +**Constraints:** + +* `1 <= bombs.length <= 100` +* `bombs[i].length == 3` +* 1 <= xi, yi, ri <= 105 + +## Solution + +```kotlin +class Solution { + fun maximumDetonation(bombs: Array): Int { + val n = bombs.size + val graph: Array?> = arrayOfNulls(n) + for (i in 0 until n) { + graph[i] = ArrayList() + } + for (i in 0 until n) { + for (j in i + 1 until n) { + val dx = bombs[i][0] - bombs[j][0].toDouble() + val dy = bombs[i][1] - bombs[j][1].toDouble() + val r1 = bombs[i][2].toDouble() + val r2 = bombs[j][2].toDouble() + val dist = dx * dx + dy * dy + if (dist <= r1 * r1) { + graph[i]?.add(j) + } + if (dist <= r2 * r2) { + graph[j]?.add(i) + } + } + } + val visited = BooleanArray(n) + var ans = 0 + for (i in 0 until n) { + ans = Math.max(ans, dfs(graph, i, visited)) + if (ans == n) { + return ans + } + visited.fill(false) + } + return ans + } + + private fun dfs(graph: Array?>, i: Int, visited: BooleanArray): Int { + var cc = 0 + if (visited[i]) { + return 0 + } + visited[i] = true + for (neigh in graph[i]!!) { + cc += dfs(graph, neigh, visited) + } + return cc + 1 + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2101_2200/s2102_sequentially_ordinal_rank_tracker/readme.md b/src/main/kotlin/g2101_2200/s2102_sequentially_ordinal_rank_tracker/readme.md new file mode 100644 index 00000000..f6832134 --- /dev/null +++ b/src/main/kotlin/g2101_2200/s2102_sequentially_ordinal_rank_tracker/readme.md @@ -0,0 +1,114 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2102\. Sequentially Ordinal Rank Tracker + +Hard + +A scenic location is represented by its `name` and attractiveness `score`, where `name` is a **unique** string among all locations and `score` is an integer. Locations can be ranked from the best to the worst. The **higher** the score, the better the location. If the scores of two locations are equal, then the location with the **lexicographically smaller** name is better. + +You are building a system that tracks the ranking of locations with the system initially starting with no locations. It supports: + +* **Adding** scenic locations, **one at a time**. +* **Querying** the ith **best** location of **all locations already added**, where `i` is the number of times the system has been queried (including the current query). + * For example, when the system is queried for the 4th time, it returns the 4th best location of all locations already added. + +Note that the test data are generated so that **at any time**, the number of queries **does not exceed** the number of locations added to the system. + +Implement the `SORTracker` class: + +* `SORTracker()` Initializes the tracker system. +* `void add(string name, int score)` Adds a scenic location with `name` and `score` to the system. +* `string get()` Queries and returns the ith best location, where `i` is the number of times this method has been invoked (including this invocation). + +**Example 1:** + +**Input** ["SORTracker", "add", "add", "get", "add", "get", "add", "get", "add", "get", "add", "get", "get"] [[], ["bradford", 2], ["branford", 3], [], ["alps", 2], [], ["orland", 2], [], ["orlando", 3], [], ["alpine", 2], [], []] + +**Output:** [null, null, null, "branford", null, "alps", null, "bradford", null, "bradford", null, "bradford", "orland"] + +**Explanation:** + + SORTracker tracker = new SORTracker(); // Initialize the tracker system. + tracker.add("bradford", 2); // Add location with name="bradford" and score=2 to the system. + tracker.add("branford", 3); // Add location with name="branford" and score=3 to the system. + tracker.get(); // The sorted locations, from best to worst, are: branford, bradford. + // Note that branford precedes bradford due to its **higher score** (3 > 2). + // This is the 1st time get() is called, so return the best location: "branford". + tracker.add("alps", 2); // Add location with name="alps" and score=2 to the system. + tracker.get(); // Sorted locations: branford, alps, bradford. + // Note that alps precedes bradford even though they have the same score (2). + // This is because "alps" is **lexicographically smaller** than "bradford". + // Return the 2nd best location "alps", as it is the 2nd time get() is called. + tracker.add("orland", 2); // Add location with name="orland" and score=2 to the system. + tracker.get(); // Sorted locations: branford, alps, bradford, orland. + // Return "bradford", as it is the 3rd time get() is called. + tracker.add("orlando", 3); // Add location with name="orlando" and score=3 to the system. + tracker.get(); // Sorted locations: branford, orlando, alps, bradford, orland. + // Return "bradford". + tracker.add("alpine", 2); // Add location with name="alpine" and score=2 to the system. + tracker.get(); // Sorted locations: branford, orlando, alpine, alps, bradford, orland. + // Return "bradford". + tracker.get(); + // Sorted locations: branford, orlando, alpine, alps, bradford, orland. + // Return "orland". + +**Constraints:** + +* `name` consists of lowercase English letters, and is unique among all locations. +* `1 <= name.length <= 10` +* 1 <= score <= 105 +* At any time, the number of calls to `get` does not exceed the number of calls to `add`. +* At most 4 * 104 calls **in total** will be made to `add` and `get`. + +## Solution + +```kotlin +import java.util.TreeSet + +class SORTracker { + class Location(var name: String, var score: Int) + + private var tSet1: TreeSet + private var tSet2: TreeSet + + init { + tSet1 = TreeSet( + Comparator { a: Location?, b: Location? -> + return@Comparator if (a!!.score != b!!.score) { + b.score - a.score + } else { + a.name.compareTo(b.name) + } + } + ) + tSet2 = TreeSet( + Comparator { a: Location?, b: Location? -> + return@Comparator if (a!!.score != b!!.score) { + b.score - a.score + } else { + a.name.compareTo(b.name) + } + } + ) + } + + fun add(name: String, score: Int) { + tSet1.add(Location(name, score)) + tSet2.add(tSet1.pollLast()) + } + + fun get(): String { + val res = tSet2.pollFirst() + tSet1.add(res) + assert(res != null) + return res!!.name + } +} +/* + * Your SORTracker object will be instantiated and called as such: + * var obj = SORTracker() + * obj.add(name,score) + * var param_2 = obj.get() + */ +``` \ No newline at end of file diff --git a/src/main/kotlin/g2101_2200/s2103_rings_and_rods/readme.md b/src/main/kotlin/g2101_2200/s2103_rings_and_rods/readme.md new file mode 100644 index 00000000..3ef86d37 --- /dev/null +++ b/src/main/kotlin/g2101_2200/s2103_rings_and_rods/readme.md @@ -0,0 +1,103 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2103\. Rings and Rods + +Easy + +There are `n` rings and each ring is either red, green, or blue. The rings are distributed **across ten rods** labeled from `0` to `9`. + +You are given a string `rings` of length `2n` that describes the `n` rings that are placed onto the rods. Every two characters in `rings` forms a **color-position pair** that is used to describe each ring where: + +* The **first** character of the ith pair denotes the ith ring's **color** (`'R'`, `'G'`, `'B'`). +* The **second** character of the ith pair denotes the **rod** that the ith ring is placed on (`'0'` to `'9'`). + +For example, `"R3G2B1"` describes `n == 3` rings: a red ring placed onto the rod labeled 3, a green ring placed onto the rod labeled 2, and a blue ring placed onto the rod labeled 1. + +Return _the number of rods that have **all three colors** of rings on them._ + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/11/23/ex1final.png) + +**Input:** rings = "B0B6G0R6R0R6G9" + +**Output:** 1 + +**Explanation:** + +- The rod labeled 0 holds 3 rings with all colors: red, green, and blue. + +- The rod labeled 6 holds 3 rings, but it only has red and blue. + +- The rod labeled 9 holds only a green ring. + +Thus, the number of rods with all three colors is 1. + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2021/11/23/ex2final.png) + +**Input:** rings = "B0R0G0R9R0B0G0" + +**Output:** 1 + +**Explanation:** + +- The rod labeled 0 holds 6 rings with all colors: red, green, and blue. + +- The rod labeled 9 holds only a red ring. + +Thus, the number of rods with all three colors is 1. + +**Example 3:** + +**Input:** rings = "G4" + +**Output:** 0 + +**Explanation:** Only one ring is given. Thus, no rods have all three colors. + +**Constraints:** + +* `rings.length == 2 * n` +* `1 <= n <= 100` +* `rings[i]` where `i` is **even** is either `'R'`, `'G'`, or `'B'` (**0-indexed**). +* `rings[i]` where `i` is **odd** is a digit from `'0'` to `'9'` (**0-indexed**). + +## Solution + +```kotlin +class Solution { + fun countPoints(rings: String): Int { + val redHashMap: MutableMap = HashMap() + val greenHashMap: MutableMap = HashMap() + val blueHashMap: MutableMap = HashMap() + run { + var i = 0 + while (i <= rings.length - 2) { + val charOne = rings[i] + val charTwo = rings[i + 1] + if (charOne == 'R') { + redHashMap[Character.getNumericValue(charTwo)] = 123 + } else if (charOne == 'G') { + greenHashMap[Character.getNumericValue(charTwo)] = 123 + } else { + blueHashMap[Character.getNumericValue(charTwo)] = 123 + } + i = i + 2 + } + } + var result = 0 + for (i in 0..9) { + if (redHashMap.containsKey(i) && + greenHashMap.containsKey(i) && + blueHashMap.containsKey(i) + ) { + result++ + } + } + return result + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2101_2200/s2104_sum_of_subarray_ranges/readme.md b/src/main/kotlin/g2101_2200/s2104_sum_of_subarray_ranges/readme.md new file mode 100644 index 00000000..c04cfdb8 --- /dev/null +++ b/src/main/kotlin/g2101_2200/s2104_sum_of_subarray_ranges/readme.md @@ -0,0 +1,106 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2104\. Sum of Subarray Ranges + +Medium + +You are given an integer array `nums`. The **range** of a subarray of `nums` is the difference between the largest and smallest element in the subarray. + +Return _the **sum of all** subarray ranges of_ `nums`_._ + +A subarray is a contiguous **non-empty** sequence of elements within an array. + +**Example 1:** + +**Input:** nums = [1,2,3] + +**Output:** 4 + +**Explanation:** The 6 subarrays of nums are the following: + +[1], range = largest - smallest = 1 - 1 = 0 + +[2], range = 2 - 2 = 0 + +[3], range = 3 - 3 = 0 + +[1,2], range = 2 - 1 = 1 + +[2,3], range = 3 - 2 = 1 + +[1,2,3], range = 3 - 1 = 2 + +So the sum of all ranges is 0 + 0 + 0 + 1 + 1 + 2 = 4. + +**Example 2:** + +**Input:** nums = [1,3,3] + +**Output:** 4 + +**Explanation:** The 6 subarrays of nums are the following: + +[1], range = largest - smallest = 1 - 1 = 0 + +[3], range = 3 - 3 = 0 + +[3], range = 3 - 3 = 0 + +[1,3], range = 3 - 1 = 2 + +[3,3], range = 3 - 3 = 0 + +[1,3,3], range = 3 - 1 = 2 + +So the sum of all ranges is 0 + 0 + 0 + 2 + 0 + 2 = 4. + +**Example 3:** + +**Input:** nums = [4,-2,-3,4,1] + +**Output:** 59 + +**Explanation:** The sum of all subarray ranges of nums is 59. + +**Constraints:** + +* `1 <= nums.length <= 1000` +* -109 <= nums[i] <= 109 + +**Follow-up:** Could you find a solution with `O(n)` time complexity? + +## Solution + +```kotlin +import java.util.ArrayDeque +import java.util.Deque + +class Solution { + fun subArrayRanges(nums: IntArray): Long { + val n = nums.size + var sum: Long = 0 + val q: Deque = ArrayDeque() + q.add(-1) + for (i in 0..n) { + while (q.peekLast() != -1 && (i == n || nums[q.peekLast()] <= nums[i])) { + val cur = q.removeLast() + val left = q.peekLast() + sum += 1L * (cur - left) * (i - cur) * nums[cur] + } + q.add(i) + } + q.clear() + q.add(-1) + for (i in 0..n) { + while (q.peekLast() != -1 && (i == n || nums[q.peekLast()] >= nums[i])) { + val cur = q.removeLast() + val left = q.peekLast() + sum -= 1L * (cur - left) * (i - cur) * nums[cur] + } + q.add(i) + } + return sum + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2101_2200/s2105_watering_plants_ii/readme.md b/src/main/kotlin/g2101_2200/s2105_watering_plants_ii/readme.md new file mode 100644 index 00000000..563ca667 --- /dev/null +++ b/src/main/kotlin/g2101_2200/s2105_watering_plants_ii/readme.md @@ -0,0 +1,117 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2105\. Watering Plants II + +Medium + +Alice and Bob want to water `n` plants in their garden. The plants are arranged in a row and are labeled from `0` to `n - 1` from left to right where the ith plant is located at `x = i`. + +Each plant needs a specific amount of water. Alice and Bob have a watering can each, **initially full**. They water the plants in the following way: + +* Alice waters the plants in order from **left to right**, starting from the 0th plant. Bob waters the plants in order from **right to left**, starting from the (n - 1)th plant. They begin watering the plants **simultaneously**. +* It takes the same amount of time to water each plant regardless of how much water it needs. +* Alice/Bob **must** water the plant if they have enough in their can to **fully** water it. Otherwise, they **first** refill their can (instantaneously) then water the plant. +* In case both Alice and Bob reach the same plant, the one with **more** water currently in his/her watering can should water this plant. If they have the same amount of water, then Alice should water this plant. + +Given a **0-indexed** integer array `plants` of `n` integers, where `plants[i]` is the amount of water the ith plant needs, and two integers `capacityA` and `capacityB` representing the capacities of Alice's and Bob's watering cans respectively, return _the **number of times** they have to refill to water all the plants_. + +**Example 1:** + +**Input:** plants = [2,2,3,3], capacityA = 5, capacityB = 5 + +**Output:** 1 + +**Explanation:** + +- Initially, Alice and Bob have 5 units of water each in their watering cans. + +- Alice waters plant 0, Bob waters plant 3. + +- Alice and Bob now have 3 units and 2 units of water respectively. + +- Alice has enough water for plant 1, so she waters it. Bob does not have enough water for plant 2, so he refills his can then waters it. + +So, the total number of times they have to refill to water all the plants is 0 + 0 + 1 + 0 = 1. + +**Example 2:** + +**Input:** plants = [2,2,3,3], capacityA = 3, capacityB = 4 + +**Output:** 2 + +**Explanation:** + +- Initially, Alice and Bob have 3 units and 4 units of water in their watering cans respectively. + +- Alice waters plant 0, Bob waters plant 3. + +- Alice and Bob now have 1 unit of water each, and need to water plants 1 and 2 respectively. + +- Since neither of them have enough water for their current plants, they refill their cans and then water the plants. + +So, the total number of times they have to refill to water all the plants is 0 + 1 + 1 + 0 = 2. + +**Example 3:** + +**Input:** plants = [5], capacityA = 10, capacityB = 8 + +**Output:** 0 + +**Explanation:** + +- There is only one plant. + +- Alice's watering can has 10 units of water, whereas Bob's can has 8 units. Since Alice has more water in her can, she waters this plant. + +So, the total number of times they have to refill is 0. + +**Constraints:** + +* `n == plants.length` +* 1 <= n <= 105 +* 1 <= plants[i] <= 106 +* max(plants[i]) <= capacityA, capacityB <= 109 + +## Solution + +```kotlin +@Suppress("NAME_SHADOWING") +class Solution { + fun minimumRefill(plants: IntArray, capacityA: Int, capacityB: Int): Int { + var capacityA = capacityA + var capacityB = capacityB + val n = plants.size + var i = 0 + var j = n - 1 + var aRefill = 0 + var bRefill = 0 + val initialCapacityA = capacityA + val initialCapacityB = capacityB + while (i <= j) { + if (i == j) { + if (!(capacityA >= plants[i] || capacityB >= plants[i])) { + aRefill++ + } + i++ + continue + } + capacityA = if (capacityA >= plants[i]) { + capacityA - plants[i] + } else { + aRefill++ + initialCapacityA - plants[i] + } + capacityB = if (capacityB >= plants[j]) { + capacityB - plants[j] + } else { + bRefill++ + initialCapacityB - plants[j] + } + i++ + j-- + } + return aRefill + bRefill + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2101_2200/s2106_maximum_fruits_harvested_after_at_most_k_steps/readme.md b/src/main/kotlin/g2101_2200/s2106_maximum_fruits_harvested_after_at_most_k_steps/readme.md new file mode 100644 index 00000000..0a0243c4 --- /dev/null +++ b/src/main/kotlin/g2101_2200/s2106_maximum_fruits_harvested_after_at_most_k_steps/readme.md @@ -0,0 +1,101 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2106\. Maximum Fruits Harvested After at Most K Steps + +Hard + +Fruits are available at some positions on an infinite x-axis. You are given a 2D integer array `fruits` where fruits[i] = [positioni, amounti] depicts amounti fruits at the position positioni. `fruits` is already **sorted** by positioni in **ascending order**, and each positioni is **unique**. + +You are also given an integer `startPos` and an integer `k`. Initially, you are at the position `startPos`. From any position, you can either walk to the **left or right**. It takes **one step** to move **one unit** on the x-axis, and you can walk **at most** `k` steps in total. For every position you reach, you harvest all the fruits at that position, and the fruits will disappear from that position. + +Return _the **maximum total number** of fruits you can harvest_. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/11/21/1.png) + +**Input:** fruits = \[\[2,8],[6,3],[8,6]], startPos = 5, k = 4 + +**Output:** 9 + +**Explanation:** The optimal way is to: + +- Move right to position 6 and harvest 3 fruits + +- Move right to position 8 and harvest 6 fruits + +You moved 3 steps and harvested 3 + 6 = 9 fruits in total. + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2021/11/21/2.png) + +**Input:** fruits = \[\[0,9],[4,1],[5,7],[6,2],[7,4],[10,9]], startPos = 5, k = 4 + +**Output:** 14 + +**Explanation:** You can move at most k = 4 steps, so you cannot reach position 0 nor 10. The optimal way is to: + +- Harvest the 7 fruits at the starting position 5 + +- Move left to position 4 and harvest 1 fruit + +- Move right to position 6 and harvest 2 fruits + +- Move right to position 7 and harvest 4 fruits + +You moved 1 + 3 = 4 steps and harvested 7 + 1 + 2 + 4 = 14 fruits in total. + +**Example 3:** + +![](https://assets.leetcode.com/uploads/2021/11/21/3.png) + +**Input:** fruits = \[\[0,3],[6,4],[8,5]], startPos = 3, k = 2 + +**Output:** 0 + +**Explanation:** You can move at most k = 2 steps and cannot reach any position with fruits. + +**Constraints:** + +* 1 <= fruits.length <= 105 +* `fruits[i].length == 2` +* 0 <= startPos, positioni <= 2 * 105 +* positioni-1 < positioni for any `i > 0` (**0-indexed**) +* 1 <= amounti <= 104 +* 0 <= k <= 2 * 105 + +## Solution + +```kotlin +class Solution { + fun maxTotalFruits(fruits: Array, startPos: Int, k: Int): Int { + var res = 0 + var sum = 0 + var left = 0 + for (right in fruits.indices) { + sum += fruits[right][1] + while (left <= right && !isValidRange(fruits[left][0], fruits[right][0], startPos, k)) { + sum -= fruits[left++][1] + } + res = Math.max(sum, res) + } + return res + } + + private fun isValidRange(leftPos: Int, rightPos: Int, startPos: Int, k: Int): Boolean { + val result: Boolean + result = if (rightPos <= startPos) { + startPos - leftPos <= k + } else if (leftPos >= startPos) { + rightPos - startPos <= k + } else { + val left = startPos - leftPos + val right = rightPos - startPos + if (left <= right) left * 2 + right <= k else right * 2 + left <= k + } + return result + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2101_2200/s2108_find_first_palindromic_string_in_the_array/readme.md b/src/main/kotlin/g2101_2200/s2108_find_first_palindromic_string_in_the_array/readme.md new file mode 100644 index 00000000..58471d9f --- /dev/null +++ b/src/main/kotlin/g2101_2200/s2108_find_first_palindromic_string_in_the_array/readme.md @@ -0,0 +1,71 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2108\. Find First Palindromic String in the Array + +Easy + +Given an array of strings `words`, return _the first **palindromic** string in the array_. If there is no such string, return _an **empty string**_ `""`. + +A string is **palindromic** if it reads the same forward and backward. + +**Example 1:** + +**Input:** words = ["abc","car","ada","racecar","cool"] + +**Output:** "ada" + +**Explanation:** The first string that is palindromic is "ada". Note that "racecar" is also palindromic, but it is not the first. + +**Example 2:** + +**Input:** words = ["notapalindrome","racecar"] + +**Output:** "racecar" + +**Explanation:** The first and only string that is palindromic is "racecar". + +**Example 3:** + +**Input:** words = ["def","ghi"] + +**Output:** "" + +**Explanation:** There are no palindromic strings, so the empty string is returned. + +**Constraints:** + +* `1 <= words.length <= 100` +* `1 <= words[i].length <= 100` +* `words[i]` consists only of lowercase English letters. + +## Solution + +```kotlin +class Solution { + fun firstPalindrome(words: Array): String { + for (word in words) { + if (isPalindrome(word)) { + return word + } + } + return "" + } + + companion object { + fun isPalindrome(s: String): Boolean { + val len = s.length + var i = 0 + var j = len - 1 + while (i <= len / 2 && j >= len / 2) { + if (s[i] != s[j]) { + return false + } + i++ + j-- + } + return true + } + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2101_2200/s2109_adding_spaces_to_a_string/readme.md b/src/main/kotlin/g2101_2200/s2109_adding_spaces_to_a_string/readme.md new file mode 100644 index 00000000..17e23833 --- /dev/null +++ b/src/main/kotlin/g2101_2200/s2109_adding_spaces_to_a_string/readme.md @@ -0,0 +1,77 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2109\. Adding Spaces to a String + +Medium + +You are given a **0-indexed** string `s` and a **0-indexed** integer array `spaces` that describes the indices in the original string where spaces will be added. Each space should be inserted **before** the character at the given index. + +* For example, given `s = "EnjoyYourCoffee"` and `spaces = [5, 9]`, we place spaces before `'Y'` and `'C'`, which are at indices `5` and `9` respectively. Thus, we obtain `"Enjoy **Y**our **C**offee"`. + +Return _the modified string **after** the spaces have been added._ + +**Example 1:** + +**Input:** s = "LeetcodeHelpsMeLearn", spaces = [8,13,15] + +**Output:** "Leetcode Helps Me Learn" + +**Explanation:** + +The indices 8, 13, and 15 correspond to the underlined characters in "Leetcode**H**elps**M**e**L**earn". + +We then place spaces before those characters. + +**Example 2:** + +**Input:** s = "icodeinpython", spaces = [1,5,7,9] + +**Output:** "i code in py thon" + +**Explanation:** + +The indices 1, 5, 7, and 9 correspond to the underlined characters in "i**c**ode**i**n**p**y**t**hon". + +We then place spaces before those characters. + +**Example 3:** + +**Input:** s = "spacing", spaces = [0,1,2,3,4,5,6] + +**Output:** " s p a c i n g" + +**Explanation:** We are also able to place spaces before the first character of the string. + +**Constraints:** + +* 1 <= s.length <= 3 * 105 +* `s` consists only of lowercase and uppercase English letters. +* 1 <= spaces.length <= 3 * 105 +* `0 <= spaces[i] <= s.length - 1` +* All the values of `spaces` are **strictly increasing**. + +## Solution + +```kotlin +class Solution { + fun addSpaces(s: String, spaces: IntArray): String { + val stringChars = CharArray(s.length + spaces.size) + for (i in spaces.indices) { + stringChars[spaces[i] + i] = ' ' + } + var equivalentIndex = -1 + var i = 0 + while (i < s.length) { + equivalentIndex++ + if (stringChars[equivalentIndex] == ' ') { + i-- + } else { + stringChars[equivalentIndex] = s[i] + } + i++ + } + return String(stringChars) + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2101_2200/s2110_number_of_smooth_descent_periods_of_a_stock/readme.md b/src/main/kotlin/g2101_2200/s2110_number_of_smooth_descent_periods_of_a_stock/readme.md new file mode 100644 index 00000000..4a785136 --- /dev/null +++ b/src/main/kotlin/g2101_2200/s2110_number_of_smooth_descent_periods_of_a_stock/readme.md @@ -0,0 +1,71 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2110\. Number of Smooth Descent Periods of a Stock + +Medium + +You are given an integer array `prices` representing the daily price history of a stock, where `prices[i]` is the stock price on the ith day. + +A **smooth descent period** of a stock consists of **one or more contiguous** days such that the price on each day is **lower** than the price on the **preceding day** by **exactly** `1`. The first day of the period is exempted from this rule. + +Return _the number of **smooth descent periods**_. + +**Example 1:** + +**Input:** prices = [3,2,1,4] + +**Output:** 7 + +**Explanation:** There are 7 smooth descent periods: + +[3], [2], [1], [4], [3,2], [2,1], and [3,2,1] + +Note that a period with one day is a smooth descent period by the definition. + +**Example 2:** + +**Input:** prices = [8,6,7,7] + +**Output:** 4 + +**Explanation:** There are 4 smooth descent periods: [8], [6], [7], and [7] + +Note that [8,6] is not a smooth descent period as 8 - 6 ≠ 1. + +**Example 3:** + +**Input:** prices = [1] + +**Output:** 1 + +**Explanation:** There is 1 smooth descent period: [1] + +**Constraints:** + +* 1 <= prices.length <= 105 +* 1 <= prices[i] <= 105 + +## Solution + +```kotlin +class Solution { + fun getDescentPeriods(prices: IntArray): Long { + var descendantCount: Long = 0 + var previousCounts = 0 + for (i in 0 until prices.size - 1) { + if (prices[i] - prices[i + 1] == 1) { + descendantCount++ + if (previousCounts > 0) { + descendantCount += previousCounts.toLong() + } + previousCounts++ + } else { + previousCounts = 0 + } + } + descendantCount += prices.size.toLong() + return descendantCount + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2101_2200/s2111_minimum_operations_to_make_the_array_k_increasing/readme.md b/src/main/kotlin/g2101_2200/s2111_minimum_operations_to_make_the_array_k_increasing/readme.md new file mode 100644 index 00000000..93350dae --- /dev/null +++ b/src/main/kotlin/g2101_2200/s2111_minimum_operations_to_make_the_array_k_increasing/readme.md @@ -0,0 +1,116 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2111\. Minimum Operations to Make the Array K-Increasing + +Hard + +You are given a **0-indexed** array `arr` consisting of `n` positive integers, and a positive integer `k`. + +The array `arr` is called **K-increasing** if `arr[i-k] <= arr[i]` holds for every index `i`, where `k <= i <= n-1`. + +* For example, `arr = [4, 1, 5, 2, 6, 2]` is K-increasing for `k = 2` because: + * `arr[0] <= arr[2] (4 <= 5)` + * `arr[1] <= arr[3] (1 <= 2)` + * `arr[2] <= arr[4] (5 <= 6)` + * `arr[3] <= arr[5] (2 <= 2)` +* However, the same `arr` is not K-increasing for `k = 1` (because `arr[0] > arr[1]`) or `k = 3` (because `arr[0] > arr[3]`). + +In one **operation**, you can choose an index `i` and **change** `arr[i]` into **any** positive integer. + +Return _the **minimum number of operations** required to make the array K-increasing for the given_ `k`. + +**Example 1:** + +**Input:** arr = [5,4,3,2,1], k = 1 + +**Output:** 4 + +**Explanation:** + +For k = 1, the resultant array has to be non-decreasing. + +Some of the K-increasing arrays that can be formed are [5,**6**,**7**,**8**,**9**], [**1**,**1**,**1**,**1**,1], [**2**,**2**,3,**4**,**4**]. All of them require 4 operations. + +It is suboptimal to change the array to, for example, [**6**,**7**,**8**,**9**,**10**] because it would take 5 operations. + +It can be shown that we cannot make the array K-increasing in less than 4 operations. + +**Example 2:** + +**Input:** arr = [4,1,5,2,6,2], k = 2 + +**Output:** 0 + +**Explanation:** + +This is the same example as the one in the problem description. + +Here, for every index i where 2 <= i <= 5, arr[i-2] <= arr[i]. + +Since the given array is already K-increasing, we do not need to perform any operations. + +**Example 3:** + +**Input:** arr = [4,1,5,2,6,2], k = 3 + +**Output:** 2 + +**Explanation:** + +Indices 3 and 5 are the only ones not satisfying arr[i-3] <= arr[i] for 3 <= i <= 5. + +One of the ways we can make the array K-increasing is by changing arr[3] to 4 and arr[5] to 5. + +The array will now be [4,1,5,**4**,6,**5**]. + +Note that there can be other ways to make the array K-increasing, but none of them require less than 2 operations. + +**Constraints:** + +* 1 <= arr.length <= 105 +* `1 <= arr[i], k <= arr.length` + +## Solution + +```kotlin +class Solution { + fun kIncreasing(a: IntArray, k: Int): Int { + val n = a.size + var res = 0 + for (s in 0 until k) { + val dp: MutableList = ArrayList() + var i = s + while (i < n) { + if (!bsearch(dp, a[i])) { + dp.add(a[i]) + } + i += k + } + res += dp.size + } + return n - res + } + + private fun bsearch(dp: MutableList, target: Int): Boolean { + if (dp.isEmpty()) { + return false + } + var lo = 0 + var hi = dp.size - 1 + while (lo < hi) { + val mid = lo + (hi - lo) / 2 + if (dp[mid] <= target) { + lo = mid + 1 + } else { + hi = mid + } + } + if (dp[lo] > target) { + dp[lo] = target + return true + } + return false + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2101_2200/s2114_maximum_number_of_words_found_in_sentences/readme.md b/src/main/kotlin/g2101_2200/s2114_maximum_number_of_words_found_in_sentences/readme.md new file mode 100644 index 00000000..37dc38ab --- /dev/null +++ b/src/main/kotlin/g2101_2200/s2114_maximum_number_of_words_found_in_sentences/readme.md @@ -0,0 +1,72 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2114\. Maximum Number of Words Found in Sentences + +Easy + +A **sentence** is a list of **words** that are separated by a single space with no leading or trailing spaces. + +You are given an array of strings `sentences`, where each `sentences[i]` represents a single **sentence**. + +Return _the **maximum number of words** that appear in a single sentence_. + +**Example 1:** + +**Input:** sentences = ["alice and bob love leetcode", "i think so too", "this is great thanks very much"] + +**Output:** 6 + +**Explanation:** + +- The first sentence, "alice and bob love leetcode", has 5 words in total. + +- The second sentence, "i think so too", has 4 words in total. + +- The third sentence, "this is great thanks very much", has 6 words in total. + +Thus, the maximum number of words in a single sentence comes from the third sentence, which has 6 words. + +**Example 2:** + +**Input:** sentences = ["please wait", "continue to fight", "continue to win"] + +**Output:** 3 + +**Explanation:** It is possible that multiple sentences contain the same number of words. In this example, the second and third sentences (underlined) have the same number of words. + +**Constraints:** + +* `1 <= sentences.length <= 100` +* `1 <= sentences[i].length <= 100` +* `sentences[i]` consists only of lowercase English letters and `' '` only. +* `sentences[i]` does not have leading or trailing spaces. +* All the words in `sentences[i]` are separated by a single space. + +## Solution + +```kotlin +class Solution { + fun mostWordsFound(sentences: Array): Int { + var max = 0 + for (sentence in sentences) { + max = Math.max(max, countWords(sentence)) + } + return max + } + + private fun countWords(s: String): Int { + var start = 0 + var wc = 0 + while (start < s.length) { + var end = start + while (end < s.length && Character.isLetter(s[end])) { + end++ + } + wc++ + start = ++end + } + return wc + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2101_2200/s2115_find_all_possible_recipes_from_given_supplies/readme.md b/src/main/kotlin/g2101_2200/s2115_find_all_possible_recipes_from_given_supplies/readme.md new file mode 100644 index 00000000..4cc073fc --- /dev/null +++ b/src/main/kotlin/g2101_2200/s2115_find_all_possible_recipes_from_given_supplies/readme.md @@ -0,0 +1,112 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2115\. Find All Possible Recipes from Given Supplies + +Medium + +You have information about `n` different recipes. You are given a string array `recipes` and a 2D string array `ingredients`. The ith recipe has the name `recipes[i]`, and you can **create** it if you have **all** the needed ingredients from `ingredients[i]`. Ingredients to a recipe may need to be created from **other** recipes, i.e., `ingredients[i]` may contain a string that is in `recipes`. + +You are also given a string array `supplies` containing all the ingredients that you initially have, and you have an infinite supply of all of them. + +Return _a list of all the recipes that you can create._ You may return the answer in **any order**. + +Note that two recipes may contain each other in their ingredients. + +**Example 1:** + +**Input:** recipes = ["bread"], ingredients = \[\["yeast","flour"]], supplies = ["yeast","flour","corn"] + +**Output:** ["bread"] + +**Explanation:** We can create "bread" since we have the ingredients "yeast" and "flour". + +**Example 2:** + +**Input:** recipes = ["bread","sandwich"], ingredients = \[\["yeast","flour"],["bread","meat"]], supplies = ["yeast","flour","meat"] + +**Output:** ["bread","sandwich"] + +**Explanation:** + +We can create "bread" since we have the ingredients "yeast" and "flour". + +We can create "sandwich" since we have the ingredient "meat" and can create the ingredient "bread". + +**Example 3:** + +**Input:** recipes = ["bread","sandwich","burger"], ingredients = \[\["yeast","flour"],["bread","meat"],["sandwich","meat","bread"]], supplies = ["yeast","flour","meat"] + +**Output:** ["bread","sandwich","burger"] + +**Explanation:** + +We can create "bread" since we have the ingredients "yeast" and "flour". + +We can create "sandwich" since we have the ingredient "meat" and can create the ingredient "bread". + +We can create "burger" since we have the ingredient "meat" and can create the ingredients "bread" and "sandwich". + +**Constraints:** + +* `n == recipes.length == ingredients.length` +* `1 <= n <= 100` +* `1 <= ingredients[i].length, supplies.length <= 100` +* `1 <= recipes[i].length, ingredients[i][j].length, supplies[k].length <= 10` +* `recipes[i], ingredients[i][j]`, and `supplies[k]` consist only of lowercase English letters. +* All the values of `recipes` and `supplies` combined are unique. +* Each `ingredients[i]` does not contain any duplicate values. + +## Solution + +```kotlin +import java.util.LinkedList +import java.util.Queue + +class Solution { + fun findAllRecipes( + recipes: Array, + ingredients: List>, + supplies: Array + ): List { + val indegree: MutableMap = HashMap() + val supplySet: MutableSet = HashSet() + val adj: MutableMap> = HashMap() + supplySet.addAll(supplies) + for (recipe in recipes) { + indegree[recipe] = 0 + } + for (i in recipes.indices) { + val recipe = recipes[i] + var numberOfDependencies = 0 + for (ingredient in ingredients[i]) { + if (!supplySet.contains(ingredient)) { + adj.computeIfAbsent(ingredient) { _: String? -> HashSet() }.add(recipe) + numberOfDependencies++ + } + } + indegree[recipe] = numberOfDependencies + } + val q: Queue = LinkedList() + for ((key, value) in indegree) { + if (value == 0) { + q.add(key) + } + } + val res: MutableList = ArrayList() + while (q.isNotEmpty()) { + val recipe = q.remove() + res.add(recipe) + if (adj.containsKey(recipe)) { + for (dep in adj[recipe]!!) { + indegree[dep] = indegree[dep]!! - 1 + if (indegree[dep] == 0) { + q.add(dep) + } + } + } + } + return res + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2101_2200/s2116_check_if_a_parentheses_string_can_be_valid/readme.md b/src/main/kotlin/g2101_2200/s2116_check_if_a_parentheses_string_can_be_valid/readme.md new file mode 100644 index 00000000..1b9016b2 --- /dev/null +++ b/src/main/kotlin/g2101_2200/s2116_check_if_a_parentheses_string_can_be_valid/readme.md @@ -0,0 +1,89 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2116\. Check if a Parentheses String Can Be Valid + +Medium + +A parentheses string is a **non-empty** string consisting only of `'('` and `')'`. It is valid if **any** of the following conditions is **true**: + +* It is `()`. +* It can be written as `AB` (`A` concatenated with `B`), where `A` and `B` are valid parentheses strings. +* It can be written as `(A)`, where `A` is a valid parentheses string. + +You are given a parentheses string `s` and a string `locked`, both of length `n`. `locked` is a binary string consisting only of `'0'`s and `'1'`s. For **each** index `i` of `locked`, + +* If `locked[i]` is `'1'`, you **cannot** change `s[i]`. +* But if `locked[i]` is `'0'`, you **can** change `s[i]` to either `'('` or `')'`. + +Return `true` _if you can make `s` a valid parentheses string_. Otherwise, return `false`. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/11/06/eg1.png) + +**Input:** s = "))()))", locked = "010100" + +**Output:** true + +**Explanation:** locked[1] == '1' and locked[3] == '1', so we cannot change s[1] or s[3]. We change s[0] and s[4] to '(' while leaving s[2] and s[5] unchanged to make s valid. + +**Example 2:** + +**Input:** s = "()()", locked = "0000" + +**Output:** true + +**Explanation:** We do not need to make any changes because s is already valid. + +**Example 3:** + +**Input:** s = ")", locked = "0" + +**Output:** false + +**Explanation:** locked permits us to change s[0]. Changing s[0] to either '(' or ')' will not make s valid. + +**Constraints:** + +* `n == s.length == locked.length` +* 1 <= n <= 105 +* `s[i]` is either `'('` or `')'`. +* `locked[i]` is either `'0'` or `'1'`. + +## Solution + +```kotlin +class Solution { + fun canBeValid(s: String, locked: String): Boolean { + if (s.isEmpty()) { + return true + } + if (s.length and 1 > 0) { + return false + } + if (locked.isEmpty()) { + return true + } + var numOfLockedClose = 0 + var numOfLockedOpen = 0 + for (i in s.indices) { + val countOfChars = i + 1 + if (s[i] == ')' && locked[i] == '1') { + numOfLockedClose++ + if (numOfLockedClose * 2 > countOfChars) { + return false + } + } + val j = s.length - 1 - i + if (s[j] == '(' && locked[j] == '1') { + numOfLockedOpen++ + if (numOfLockedOpen * 2 > countOfChars) { + return false + } + } + } + return true + } +} +``` \ No newline at end of file diff --git a/src/main/kotlin/g2101_2200/s2117_abbreviating_the_product_of_a_range/readme.md b/src/main/kotlin/g2101_2200/s2117_abbreviating_the_product_of_a_range/readme.md new file mode 100644 index 00000000..f541752d --- /dev/null +++ b/src/main/kotlin/g2101_2200/s2117_abbreviating_the_product_of_a_range/readme.md @@ -0,0 +1,111 @@ +[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin) +[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork) + +## 2117\. Abbreviating the Product of a Range + +Hard + +You are given two positive integers `left` and `right` with `left <= right`. Calculate the **product** of all integers in the **inclusive** range `[left, right]`. + +Since the product may be very large, you will **abbreviate** it following these steps: + +1. Count all **trailing** zeros in the product and **remove** them. Let us denote this count as `C`. + * For example, there are `3` trailing zeros in `1000`, and there are `0` trailing zeros in `546`. +2. Denote the remaining number of digits in the product as `d`. If `d > 10`, then express the product as `
...` where `
` denotes the **first** `5` digits of the product, and `` denotes the **last** `5` digits of the product **after** removing all trailing zeros. If `d <= 10`, we keep it unchanged.
+    *   For example, we express `1234567654321` as `12345...54321`, but `1234567` is represented as `1234567`.
+3.  Finally, represent the product as a **string** `"
...eC"`.
+    *   For example, `12345678987600000` will be represented as `"12345...89876e5"`.
+
+Return _a string denoting the **abbreviated product** of all integers in the **inclusive** range_ `[left, right]`.
+
+**Example 1:**
+
+**Input:** left = 1, right = 4
+
+**Output:** "24e0"
+
+**Explanation:** The product is 1 × 2 × 3 × 4 = 24. 
+
+There are no trailing zeros, so 24 remains the same. 
+
+The abbreviation will end with "e0". Since the number of digits is 2, which is less than 10, we do not have to abbreviate it further. 
+
+Thus, the final representation is "24e0".
+
+**Example 2:**
+
+**Input:** left = 2, right = 11
+
+**Output:** "399168e2"
+
+**Explanation:** The product is 39916800. 
+
+There are 2 trailing zeros, which we remove to get 399168. 
+
+The abbreviation will end with "e2". The number of digits after removing the trailing zeros is 6, so we do not abbreviate it further. 
+
+Hence, the abbreviated product is "399168e2".
+
+**Example 3:**
+
+**Input:** left = 371, right = 375
+
+**Output:** "7219856259e3"
+
+**Explanation:** The product is 7219856259000.
+
+**Constraints:**
+
+*   1 <= left <= right <= 104
+
+## Solution
+
+```kotlin
+class Solution {
+    fun abbreviateProduct(left: Int, right: Int): String {
+        val threshold0 = 100000000000000L
+        val threshold1 = 10000000000L
+        val threshold2: Long = 100000
+        var curr: Long = 1
+        var i: Int
+        var zerosCount = 0
+        i = left
+        while (i <= right && curr < threshold0) {
+            curr *= i.toLong()
+            while (curr % 10 == 0L) {
+                curr /= 10
+                zerosCount++
+            }
+            i++
+        }
+        if (curr < threshold1) {
+            return String.format("%de%d", curr, zerosCount)
+        }
+        var low = curr % threshold1
+        var high = curr.toDouble()
+        while (high > threshold1) {
+            high /= 10.0
+        }
+        while (i <= right) {
+            low *= i.toLong()
+            high *= i.toDouble()
+            while (low % 10 == 0L) {
+                low /= 10
+                zerosCount++
+            }
+            if (low >= threshold1) {
+                low %= threshold1
+            }
+            while (high > threshold1) {
+                high /= 10.0
+            }
+            i++
+        }
+        while (high >= threshold2) {
+            high /= 10.0
+        }
+        low %= threshold2
+        return String.format("%d...%05de%d", high.toInt(), low, zerosCount)
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2119_a_number_after_a_double_reversal/readme.md b/src/main/kotlin/g2101_2200/s2119_a_number_after_a_double_reversal/readme.md
new file mode 100644
index 00000000..a89a3f4f
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2119_a_number_after_a_double_reversal/readme.md
@@ -0,0 +1,52 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2119\. A Number After a Double Reversal
+
+Easy
+
+**Reversing** an integer means to reverse all its digits.
+
+*   For example, reversing `2021` gives `1202`. Reversing `12300` gives `321` as the **leading zeros are not retained**.
+
+Given an integer `num`, **reverse** `num` to get `reversed1`, **then reverse** `reversed1` to get `reversed2`. Return `true` _if_ `reversed2` _equals_ `num`. Otherwise return `false`.
+
+**Example 1:**
+
+**Input:** num = 526
+
+**Output:** true
+
+**Explanation:** Reverse num to get 625, then reverse 625 to get 526, which equals num.
+
+**Example 2:**
+
+**Input:** num = 1800
+
+**Output:** false
+
+**Explanation:** Reverse num to get 81, then reverse 81 to get 18, which does not equal num.
+
+**Example 3:**
+
+**Input:** num = 0
+
+**Output:** true
+
+**Explanation:** Reverse num to get 0, then reverse 0 to get 0, which equals num.
+
+**Constraints:**
+
+*   0 <= num <= 106
+
+## Solution
+
+```kotlin
+class Solution {
+    fun isSameAfterReversals(num: Int): Boolean {
+        return if (num == 0) {
+            true
+        } else num % 10 != 0
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2120_execution_of_all_suffix_instructions_staying_in_a_grid/readme.md b/src/main/kotlin/g2101_2200/s2120_execution_of_all_suffix_instructions_staying_in_a_grid/readme.md
new file mode 100644
index 00000000..0414cdfd
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2120_execution_of_all_suffix_instructions_staying_in_a_grid/readme.md
@@ -0,0 +1,117 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2120\. Execution of All Suffix Instructions Staying in a Grid
+
+Medium
+
+There is an `n x n` grid, with the top-left cell at `(0, 0)` and the bottom-right cell at `(n - 1, n - 1)`. You are given the integer `n` and an integer array `startPos` where startPos = [startrow, startcol] indicates that a robot is initially at cell (startrow, startcol).
+
+You are also given a **0-indexed** string `s` of length `m` where `s[i]` is the ith instruction for the robot: `'L'` (move left), `'R'` (move right), `'U'` (move up), and `'D'` (move down).
+
+The robot can begin executing from any ith instruction in `s`. It executes the instructions one by one towards the end of `s` but it stops if either of these conditions is met:
+
+*   The next instruction will move the robot off the grid.
+*   There are no more instructions left to execute.
+
+Return _an array_ `answer` _of length_ `m` _where_ `answer[i]` _is **the number of instructions** the robot can execute if the robot **begins executing from** the_ ith _instruction in_ `s`.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2021/12/09/1.png)
+
+**Input:** n = 3, startPos = [0,1], s = "RRDDLU"
+
+**Output:** [1,5,4,3,1,0]
+
+**Explanation:** Starting from startPos and beginning execution from the ith instruction: 
+
+- 0th: "**R**RDDLU". Only one instruction "R" can be executed before it moves off the grid. 
+
+- 1st: "**RDDLU**". All five instructions can be executed while it stays in the grid and ends at (1, 1). 
+
+- 2nd: "**DDLU**". All four instructions can be executed while it stays in the grid and ends at (1, 0).
+
+- 3rd: "**DLU**". All three instructions can be executed while it stays in the grid and ends at (0, 0). 
+
+- 4th: "**L**U". Only one instruction "L" can be executed before it moves off the grid. 
+
+- 5th: "U". If moving up, it would move off the grid.
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2021/12/09/2.png)
+
+**Input:** n = 2, startPos = [1,1], s = "LURD"
+
+**Output:** [4,1,0,0]
+
+**Explanation:** 
+
+- 0th: "**LURD**". 
+
+- 1st: "**U**RD". 
+
+- 2nd: "RD". 
+
+- 3rd: "D".
+
+**Example 3:**
+
+![](https://assets.leetcode.com/uploads/2021/12/09/3.png)
+
+**Input:** n = 1, startPos = [0,0], s = "LRUD"
+
+**Output:** [0,0,0,0]
+
+**Explanation:** No matter which instruction the robot begins execution from, it would move off the grid.
+
+**Constraints:**
+
+*   `m == s.length`
+*   `1 <= n, m <= 500`
+*   `startPos.length == 2`
+*   0 <= startrow, startcol < n
+*   `s` consists of `'L'`, `'R'`, `'U'`, and `'D'`.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun executeInstructions(n: Int, startPos: IntArray, s: String): IntArray {
+        val answer = IntArray(s.length)
+        for (i in 0 until s.length) {
+            var count = 0
+            var currX = startPos[0]
+            var currY = startPos[1]
+            for (j in i until s.length) {
+                val mv = s[j]
+                if (mv == 'R') {
+                    currY++
+                    if (currY > n - 1) {
+                        break
+                    }
+                } else if (mv == 'D') {
+                    currX++
+                    if (currX > n - 1) {
+                        break
+                    }
+                } else if (mv == 'L') {
+                    currY--
+                    if (currY < 0) {
+                        break
+                    }
+                } else if (mv == 'U') {
+                    currX--
+                    if (currX < 0) {
+                        break
+                    }
+                }
+                count++
+            }
+            answer[i] = count
+        }
+        return answer
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2121_intervals_between_identical_elements/readme.md b/src/main/kotlin/g2101_2200/s2121_intervals_between_identical_elements/readme.md
new file mode 100644
index 00000000..7bc22ef5
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2121_intervals_between_identical_elements/readme.md
@@ -0,0 +1,97 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2121\. Intervals Between Identical Elements
+
+Medium
+
+You are given a **0-indexed** array of `n` integers `arr`.
+
+The **interval** between two elements in `arr` is defined as the **absolute difference** between their indices. More formally, the **interval** between `arr[i]` and `arr[j]` is `|i - j|`.
+
+Return _an array_ `intervals` _of length_ `n` _where_ `intervals[i]` _is **the sum of intervals** between_ `arr[i]` _and each element in_ `arr` _with the same value as_ `arr[i]`_._
+
+**Note:** `|x|` is the absolute value of `x`.
+
+**Example 1:**
+
+**Input:** arr = [2,1,3,1,2,3,3]
+
+**Output:** [4,2,7,2,4,4,5]
+
+**Explanation:** 
+
+- Index 0: Another 2 is found at index 4. \|0 - 4\| = 4 
+
+- Index 1: Another 1 is found at index 3. \|1 - 3\| = 2 
+
+- Index 2: Two more 3s are found at indices 5 and 6. \|2 - 5\| + \|2 - 6\| = 7 
+
+- Index 3: Another 1 is found at index 1. \|3 - 1\| = 2 
+
+- Index 4: Another 2 is found at index 0. \|4 - 0\| = 4 
+
+- Index 5: Two more 3s are found at indices 2 and 6. \|5 - 2\| + \|5 - 6\| = 4 
+
+- Index 6: Two more 3s are found at indices 2 and 5. \|6 - 2\| + \|6 - 5\| = 5
+
+**Example 2:**
+
+**Input:** arr = [10,5,10,10]
+
+**Output:** [5,0,3,4]
+
+**Explanation:** 
+
+- Index 0: Two more 10s are found at indices 2 and 3. \|0 - 2\| + \|0 - 3\| = 5 
+
+- Index 1: There is only one 5 in the array, so its sum of intervals to identical elements is 0. 
+
+- Index 2: Two more 10s are found at indices 0 and 3. \|2 - 0\| + \|2 - 3\| = 3 
+
+- Index 3: Two more 10s are found at indices 0 and 2. \|3 - 0\| + \|3 - 2\| = 4
+
+**Constraints:**
+
+*   `n == arr.length`
+*   1 <= n <= 105
+*   1 <= arr[i] <= 105
+
+## Solution
+
+```kotlin
+class Solution {
+    fun getDistances(arr: IntArray): LongArray {
+        val n = arr.size
+        val map: MutableMap> = HashMap()
+        for (i in 0 until n) {
+            var list = map[arr[i]]
+            if (list == null) {
+                list = ArrayList()
+            }
+            list.add(i)
+            map[arr[i]] = list
+        }
+        val ans = LongArray(n)
+        ans.fill(0)
+        for (list in map.values) {
+            var sum: Long = 0
+            val first = list[0]
+            for (i in 1 until list.size) {
+                sum = sum + list[i] - first
+            }
+            ans[first] = sum
+            var prevElements = 0
+            var nextElements = list.size - 2
+            for (i in 1 until list.size) {
+                val diff = list[i] - list[i - 1]
+                sum = sum + diff.toLong() * (prevElements - nextElements)
+                ans[list[i]] = sum
+                prevElements++
+                nextElements--
+            }
+        }
+        return ans
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2122_recover_the_original_array/readme.md b/src/main/kotlin/g2101_2200/s2122_recover_the_original_array/readme.md
new file mode 100644
index 00000000..31a05d9c
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2122_recover_the_original_array/readme.md
@@ -0,0 +1,124 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2122\. Recover the Original Array
+
+Hard
+
+Alice had a **0-indexed** array `arr` consisting of `n` **positive** integers. She chose an arbitrary **positive integer** `k` and created two new **0-indexed** integer arrays `lower` and `higher` in the following manner:
+
+1.  `lower[i] = arr[i] - k`, for every index `i` where `0 <= i < n`
+2.  `higher[i] = arr[i] + k`, for every index `i` where `0 <= i < n`
+
+Unfortunately, Alice lost all three arrays. However, she remembers the integers that were present in the arrays `lower` and `higher`, but not the array each integer belonged to. Help Alice and recover the original array.
+
+Given an array `nums` consisting of `2n` integers, where **exactly** `n` of the integers were present in `lower` and the remaining in `higher`, return _the **original** array_ `arr`. In case the answer is not unique, return _**any** valid array_.
+
+**Note:** The test cases are generated such that there exists **at least one** valid array `arr`.
+
+**Example 1:**
+
+**Input:** nums = [2,10,6,4,8,12]
+
+**Output:** [3,7,11]
+
+**Explanation:** 
+
+If arr = [3,7,11] and k = 1, we get lower = [2,6,10] and higher = [4,8,12]. 
+
+Combining lower and higher gives us [2,6,10,4,8,12], which is a permutation of nums. 
+
+Another valid possibility is that arr = [5,7,9] and k = 3. In that case, lower = [2,4,6] and higher = [8,10,12].
+
+**Example 2:**
+
+**Input:** nums = [1,1,3,3]
+
+**Output:** [2,2]
+
+**Explanation:** 
+
+If arr = [2,2] and k = 1, we get lower = [1,1] and higher = [3,3]. 
+
+Combining lower and higher gives us [1,1,3,3], which is equal to nums. 
+
+Note that arr cannot be [1,3] because in that case, the only possible way to obtain [1,1,3,3] is with k = 0. 
+
+This is invalid since k must be positive.
+
+**Example 3:**
+
+**Input:** nums = [5,435]
+
+**Output:** [220]
+
+**Explanation:** The only possible combination is arr = [220] and k = 215. Using them, we get lower = [5] and higher = [435].
+
+**Constraints:**
+
+*   `2 * n == nums.length`
+*   `1 <= n <= 1000`
+*   1 <= nums[i] <= 109
+*   The test cases are generated such that there exists **at least one** valid array `arr`.
+
+## Solution
+
+```kotlin
+class Solution {
+    private lateinit var res: IntArray
+
+    fun recoverArray(nums: IntArray): IntArray {
+        val n = nums.size
+        nums.sort()
+        val diffs = ArrayList()
+        val smallest = nums[0]
+        for (i in 1 until n) {
+            val k = (nums[i] - smallest) / 2
+            if ((nums[i] - smallest) % 2 == 0 && k != 0) {
+                diffs.add(k)
+            }
+        }
+        for (k in diffs) {
+            if (check(n, k, nums)) {
+                break
+            }
+        }
+        return res
+    }
+
+    private fun check(n: Int, k: Int, nums: IntArray): Boolean {
+        res = IntArray(n / 2)
+        val visited = BooleanArray(n)
+        var lower = 0
+        var higher = 1
+        var count = 0
+        while (lower < n) {
+            if (visited[lower]) {
+                lower++
+                continue
+            }
+            val lowerVal = nums[lower]
+            val higherVal = lowerVal + 2 * k
+            while (higher < n) {
+                if (nums[higher] == higherVal && !visited[higher]) {
+                    break
+                }
+                higher++
+            }
+            if (higher == n) {
+                return false
+            }
+            visited[lower] = true
+            visited[higher] = true
+            res[count] = lowerVal + k
+            count++
+            if (count == n / 2) {
+                return true
+            }
+            lower++
+            higher++
+        }
+        return false
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2124_check_if_all_as_appears_before_all_bs/readme.md b/src/main/kotlin/g2101_2200/s2124_check_if_all_as_appears_before_all_bs/readme.md
new file mode 100644
index 00000000..94f5499e
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2124_check_if_all_as_appears_before_all_bs/readme.md
@@ -0,0 +1,74 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2124\. Check if All A's Appears Before All B's
+
+Easy
+
+Given a string `s` consisting of **only** the characters `'a'` and `'b'`, return `true` _if **every**_ `'a'` _appears before **every**_ `'b'` _in the string_. Otherwise, return `false`.
+
+**Example 1:**
+
+**Input:** s = "aaabbb"
+
+**Output:** true
+
+**Explanation:** 
+
+The 'a's are at indices 0, 1, and 2, while the 'b's are at indices 3, 4, and 5. 
+
+Hence, every 'a' appears before every 'b' and we return true.
+
+**Example 2:**
+
+**Input:** s = "abab"
+
+**Output:** false
+
+**Explanation:** 
+
+There is an 'a' at index 2 and a 'b' at index 1. 
+
+Hence, not every 'a' appears before every 'b' and we return false.
+
+**Example 3:**
+
+**Input:** s = "bbb"
+
+**Output:** true
+
+**Explanation:** There are no 'a's, hence, every 'a' appears before every 'b' and we return true.
+
+**Constraints:**
+
+*   `1 <= s.length <= 100`
+*   `s[i]` is either `'a'` or `'b'`.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun checkString(s: String): Boolean {
+        var aEndIndex = -1
+        var bStartIndex = -1
+        if (s.length == 1) {
+            return true
+        }
+        for (i in s.length - 1 downTo 0) {
+            if (s[i] == 'a') {
+                aEndIndex = i
+                break
+            }
+        }
+        for (i in 0..s.length - 1) {
+            if (s[i] == 'b') {
+                bStartIndex = i
+                break
+            }
+        }
+        return if (aEndIndex == -1 || bStartIndex == -1) {
+            true
+        } else bStartIndex > aEndIndex
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2125_number_of_laser_beams_in_a_bank/readme.md b/src/main/kotlin/g2101_2200/s2125_number_of_laser_beams_in_a_bank/readme.md
new file mode 100644
index 00000000..04718189
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2125_number_of_laser_beams_in_a_bank/readme.md
@@ -0,0 +1,92 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2125\. Number of Laser Beams in a Bank
+
+Medium
+
+Anti-theft security devices are activated inside a bank. You are given a **0-indexed** binary string array `bank` representing the floor plan of the bank, which is an `m x n` 2D matrix. `bank[i]` represents the ith row, consisting of `'0'`s and `'1'`s. `'0'` means the cell is empty, while`'1'` means the cell has a security device.
+
+There is **one** laser beam between any **two** security devices **if both** conditions are met:
+
+*   The two devices are located on two **different rows**: r1 and r2, where r1 < r2.
+*   For **each** row `i` where r1 < i < r2, there are **no security devices** in the ith row.
+
+Laser beams are independent, i.e., one beam does not interfere nor join with another.
+
+Return _the total number of laser beams in the bank_.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2021/12/24/laser1.jpg)
+
+**Input:** bank = ["011001","000000","010100","001000"]
+
+**Output:** 8
+
+**Explanation:** Between each of the following device pairs, there is one beam. In total, there are 8 beams: 
+
+* bank[0][1] -- bank[2][1] 
+
+* bank[0][1] -- bank[2][3] 
+
+* bank[0][2] -- bank[2][1] 
+
+* bank[0][2] -- bank[2][3] 
+
+* bank[0][5] -- bank[2][1] 
+
+* bank[0][5] -- bank[2][3] 
+
+* bank[2][1] -- bank[3][2] 
+
+* bank[2][3] -- bank[3][2] 
+  
+Note that there is no beam between any device on the 0th row with any on the 3rd row. 
+
+This is because the 2nd row contains security devices, which breaks the second condition.
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2021/12/24/laser2.jpg)
+
+**Input:** bank = ["000","111","000"]
+
+**Output:** 0
+
+**Explanation:** There does not exist two devices located on two different rows.
+
+**Constraints:**
+
+*   `m == bank.length`
+*   `n == bank[i].length`
+*   `1 <= m, n <= 500`
+*   `bank[i][j]` is either `'0'` or `'1'`.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun numberOfBeams(bank: Array): Int {
+        var beam = 0
+        var prev = 0
+        for (s in bank) {
+            var nos = 0
+            for (j in s.toCharArray()) {
+                if (j == '1') {
+                    nos++
+                }
+            }
+            if (nos > 0) {
+                if (prev == 0) {
+                    prev = nos
+                } else {
+                    beam += prev * nos
+                    prev = nos
+                }
+            }
+        }
+        return beam
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2126_destroying_asteroids/readme.md b/src/main/kotlin/g2101_2200/s2126_destroying_asteroids/readme.md
new file mode 100644
index 00000000..eb213137
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2126_destroying_asteroids/readme.md
@@ -0,0 +1,94 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2126\. Destroying Asteroids
+
+Medium
+
+You are given an integer `mass`, which represents the original mass of a planet. You are further given an integer array `asteroids`, where `asteroids[i]` is the mass of the ith asteroid.
+
+You can arrange for the planet to collide with the asteroids in **any arbitrary order**. If the mass of the planet is **greater than or equal to** the mass of the asteroid, the asteroid is **destroyed** and the planet **gains** the mass of the asteroid. Otherwise, the planet is destroyed.
+
+Return `true` _if **all** asteroids can be destroyed. Otherwise, return_ `false`_._
+
+**Example 1:**
+
+**Input:** mass = 10, asteroids = [3,9,19,5,21]
+
+**Output:** true
+
+**Explanation:** One way to order the asteroids is [9,19,5,3,21]: 
+
+- The planet collides with the asteroid with a mass of 9. New planet mass: 10 + 9 = 19 
+
+- The planet collides with the asteroid with a mass of 19. New planet mass: 19 + 19 = 38 
+
+- The planet collides with the asteroid with a mass of 5. New planet mass: 38 + 5 = 43 
+
+- The planet collides with the asteroid with a mass of 3. New planet mass: 43 + 3 = 46
+
+- The planet collides with the asteroid with a mass of 21. New planet mass: 46 + 21 = 67 
+  
+All asteroids are destroyed.
+
+**Example 2:**
+
+**Input:** mass = 5, asteroids = [4,9,23,4]
+
+**Output:** false
+
+**Explanation:** The planet cannot ever gain enough mass to destroy the asteroid with a mass of 23. 
+
+After the planet destroys the other asteroids, it will have a mass of 5 + 4 + 9 + 4 = 22. 
+
+This is less than 23, so a collision would not destroy the last asteroid.
+
+**Constraints:**
+
+*   1 <= mass <= 105
+*   1 <= asteroids.length <= 105
+*   1 <= asteroids[i] <= 105
+
+## Solution
+
+```kotlin
+@Suppress("NAME_SHADOWING")
+class Solution {
+    fun asteroidsDestroyed(mass: Int, asteroids: IntArray): Boolean {
+        return helper(mass.toLong(), 0, asteroids)
+    }
+
+    private fun helper(mass: Long, startIndex: Int, asteroids: IntArray): Boolean {
+        var mass = mass
+        var smallOrEqualIndex = partition(mass, startIndex, asteroids)
+        if (smallOrEqualIndex < startIndex) {
+            return false
+        }
+        if (smallOrEqualIndex >= asteroids.size - 1) {
+            return true
+        }
+        for (i in startIndex..smallOrEqualIndex) {
+            mass += asteroids[i].toLong()
+        }
+        return helper(mass, ++smallOrEqualIndex, asteroids)
+    }
+
+    private fun partition(mass: Long, startIndex: Int, asteroids: IntArray): Int {
+        val length = asteroids.size
+        var smallOrEqualIndex = startIndex - 1
+        for (i in startIndex until length) {
+            if (asteroids[i] <= mass) {
+                smallOrEqualIndex++
+                swap(asteroids, i, smallOrEqualIndex)
+            }
+        }
+        return smallOrEqualIndex
+    }
+
+    private fun swap(array: IntArray, i: Int, j: Int) {
+        val tmp = array[i]
+        array[i] = array[j]
+        array[j] = tmp
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2127_maximum_employees_to_be_invited_to_a_meeting/readme.md b/src/main/kotlin/g2101_2200/s2127_maximum_employees_to_be_invited_to_a_meeting/readme.md
new file mode 100644
index 00000000..ec5d19d3
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2127_maximum_employees_to_be_invited_to_a_meeting/readme.md
@@ -0,0 +1,131 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2127\. Maximum Employees to Be Invited to a Meeting
+
+Hard
+
+A company is organizing a meeting and has a list of `n` employees, waiting to be invited. They have arranged for a large **circular** table, capable of seating **any number** of employees.
+
+The employees are numbered from `0` to `n - 1`. Each employee has a **favorite** person and they will attend the meeting **only if** they can sit next to their favorite person at the table. The favorite person of an employee is **not** themself.
+
+Given a **0-indexed** integer array `favorite`, where `favorite[i]` denotes the favorite person of the ith employee, return _the **maximum number of employees** that can be invited to the meeting_.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2021/12/14/ex1.png)
+
+**Input:** favorite = [2,2,1,2]
+
+**Output:** 3
+
+**Explanation:** 
+
+The above figure shows how the company can invite employees 0, 1, and 2, and seat them at the round table. 
+
+All employees cannot be invited because employee 2 cannot sit beside employees 0, 1, and 3, simultaneously. 
+
+Note that the company can also invite employees 1, 2, and 3, and give them their desired seats. 
+
+The maximum number of employees that can be invited to the meeting is 3.
+
+**Example 2:**
+
+**Input:** favorite = [1,2,0]
+
+**Output:** 3
+
+**Explanation:** 
+
+Each employee is the favorite person of at least one other employee, and the only way the company can invite them is if they invite every employee. 
+
+The seating arrangement will be the same as that in the figure given in example 1: 
+
+- Employee 0 will sit between employees 2 and 1. 
+
+- Employee 1 will sit between employees 0 and 2. 
+
+- Employee 2 will sit between employees 1 and 0. 
+  
+The maximum number of employees that can be invited to the meeting is 3.
+
+**Example 3:**
+
+![](https://assets.leetcode.com/uploads/2021/12/14/ex2.png)
+
+**Input:** favorite = [3,0,1,4,1]
+
+**Output:** 4
+
+**Explanation:** 
+
+The above figure shows how the company will invite employees 0, 1, 3, and 4, and seat them at the round table. 
+
+Employee 2 cannot be invited because the two spots next to their favorite employee 1 are taken. 
+
+So the company leaves them out of the meeting. \
+
+The maximum number of employees that can be invited to the meeting is 4.
+
+**Constraints:**
+
+*   `n == favorite.length`
+*   2 <= n <= 105
+*   `0 <= favorite[i] <= n - 1`
+*   `favorite[i] != i`
+
+## Solution
+
+```kotlin
+import java.util.LinkedList
+import java.util.Queue
+
+class Solution {
+    fun maximumInvitations(favorite: IntArray): Int {
+        if (favorite.isEmpty()) return 0
+        val n = favorite.size
+        var cycle = 0
+        var cycleDepth = 0
+        val indegree = IntArray(n)
+        val depth = IntArray(n)
+        val visited = BooleanArray(n)
+        val q: Queue = LinkedList()
+        for (i in 0 until n) {
+            indegree[favorite[i]]++
+            depth[i] = 1
+        }
+        for (i in 0 until n) {
+            if (indegree[i] == 0) {
+                q.add(i)
+                visited[i] = true
+            }
+        }
+        while (q.isNotEmpty()) {
+            val curr = q.poll()
+            val next = favorite[curr]
+            indegree[next]--
+            if (indegree[next] == 0) {
+                q.add(next)
+                visited[next] = true
+            }
+            depth[next] = depth[curr] + 1
+        }
+        for (i in 0 until n) {
+            if (visited[i]) continue
+            var j = i
+            var count = 0
+            while (!visited[j]) {
+                visited[j] = true
+                j = favorite[j]
+                count++
+            }
+            if (count > 2) {
+                cycle = Math.max(cycle, count)
+            } else {
+                cycleDepth += depth[i] + depth[favorite[i]]
+            }
+        }
+        return Math.max(cycle, cycleDepth)
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2129_capitalize_the_title/readme.md b/src/main/kotlin/g2101_2200/s2129_capitalize_the_title/readme.md
new file mode 100644
index 00000000..c6c0c53f
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2129_capitalize_the_title/readme.md
@@ -0,0 +1,79 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2129\. Capitalize the Title
+
+Easy
+
+You are given a string `title` consisting of one or more words separated by a single space, where each word consists of English letters. **Capitalize** the string by changing the capitalization of each word such that:
+
+*   If the length of the word is `1` or `2` letters, change all letters to lowercase.
+*   Otherwise, change the first letter to uppercase and the remaining letters to lowercase.
+
+Return _the **capitalized**_ `title`.
+
+**Example 1:**
+
+**Input:** title = "capiTalIze tHe titLe"
+
+**Output:** "Capitalize The Title"
+
+**Explanation:** Since all the words have a length of at least 3, the first letter of each word is uppercase, and the remaining letters are lowercase.
+
+**Example 2:**
+
+**Input:** title = "First leTTeR of EACH Word"
+
+**Output:** "First Letter of Each Word"
+
+**Explanation:** 
+
+The word "of" has length 2, so it is all lowercase. 
+
+The remaining words have a length of at least 3, so the first letter of each remaining word is uppercase, and the remaining letters are lowercase.
+
+**Example 3:**
+
+**Input:** title = "i lOve leetcode"
+
+**Output:** "i Love Leetcode"
+
+**Explanation:** 
+
+The word "i" has length 1, so it is lowercase. 
+
+The remaining words have a length of at least 3, so the first letter of each remaining word is uppercase, and the remaining letters are lowercase.
+
+**Constraints:**
+
+*   `1 <= title.length <= 100`
+*   `title` consists of words separated by a single space without any leading or trailing spaces.
+*   Each word consists of uppercase and lowercase English letters and is **non-empty**.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun capitalizeTitle(title: String): String {
+        val sb = StringBuilder()
+        var i = 0
+        var j = 0
+        while (i < title.length) {
+            while (j < title.length && title[j] != ' ') {
+                sb.append(title[j].lowercaseChar())
+                j++
+            }
+            val len = j - i
+            if (len > 2) {
+                sb.setCharAt(i, title[i].uppercaseChar())
+            }
+            if (j == title.length) {
+                break
+            }
+            sb.append(title[j])
+            i = ++j
+        }
+        return sb.toString()
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2130_maximum_twin_sum_of_a_linked_list/readme.md b/src/main/kotlin/g2101_2200/s2130_maximum_twin_sum_of_a_linked_list/readme.md
new file mode 100644
index 00000000..cc6446c7
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2130_maximum_twin_sum_of_a_linked_list/readme.md
@@ -0,0 +1,118 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2130\. Maximum Twin Sum of a Linked List
+
+Medium
+
+In a linked list of size `n`, where `n` is **even**, the ith node (**0-indexed**) of the linked list is known as the **twin** of the (n-1-i)th node, if `0 <= i <= (n / 2) - 1`.
+
+*   For example, if `n = 4`, then node `0` is the twin of node `3`, and node `1` is the twin of node `2`. These are the only nodes with twins for `n = 4`.
+
+The **twin sum** is defined as the sum of a node and its twin.
+
+Given the `head` of a linked list with even length, return _the **maximum twin sum** of the linked list_.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2021/12/03/eg1drawio.png)
+
+**Input:** head = [5,4,2,1]
+
+**Output:** 6
+
+**Explanation:** 
+
+Nodes 0 and 1 are the twins of nodes 3 and 2, respectively. All have twin sum = 6. 
+
+There are no other nodes with twins in the linked list. 
+
+Thus, the maximum twin sum of the linked list is 6.
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2021/12/03/eg2drawio.png)
+
+**Input:** head = [4,2,2,3]
+
+**Output:** 7
+
+**Explanation:** 
+
+The nodes with twins present in this linked list are: 
+
+- Node 0 is the twin of node 3 having a twin sum of 4 + 3 = 7. 
+
+- Node 1 is the twin of node 2 having a twin sum of 2 + 2 = 4. 
+  
+Thus, the maximum twin sum of the linked list is max(7, 4) = 7.
+
+**Example 3:**
+
+![](https://assets.leetcode.com/uploads/2021/12/03/eg3drawio.png)
+
+**Input:** head = [1,100000]
+
+**Output:** 100001
+
+**Explanation:** 
+
+There is only one node with a twin in the linked list having twin sum of 1 + 100000 = 100001.
+
+**Constraints:**
+
+*   The number of nodes in the list is an **even** integer in the range [2, 105].
+*   1 <= Node.val <= 105
+
+## Solution
+
+```kotlin
+import com_github_leetcode.ListNode
+
+/*
+ * Example:
+ * var li = ListNode(5)
+ * var v = li.`val`
+ * Definition for singly-linked list.
+ * class ListNode(var `val`: Int) {
+ *     var next: ListNode? = null
+ * }
+ */
+class Solution {
+    fun pairSum(head: ListNode?): Int {
+        if (head == null) {
+            return 0
+        }
+        var maxSum = Int.MIN_VALUE
+        var slow = head
+        var fast = head
+        while (fast != null && fast.next != null) {
+            slow = slow!!.next
+            fast = fast.next!!.next
+        }
+        if (slow!!.next == null) {
+            return head.`val` + slow.`val`
+        }
+        var tail = head
+        var pivot = reverse(slow)
+        while (pivot != null) {
+            maxSum = Math.max(maxSum, tail!!.`val` + pivot.`val`)
+            tail = tail.next
+            pivot = pivot.next
+        }
+        return maxSum
+    }
+
+    private fun reverse(head: ListNode?): ListNode? {
+        var tail = head
+        var prev: ListNode? = null
+        while (tail != null) {
+            val temp = tail.next
+            tail.next = prev
+            prev = tail
+            tail = temp
+        }
+        return prev
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2131_longest_palindrome_by_concatenating_two_letter_words/readme.md b/src/main/kotlin/g2101_2200/s2131_longest_palindrome_by_concatenating_two_letter_words/readme.md
new file mode 100644
index 00000000..c58efccd
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2131_longest_palindrome_by_concatenating_two_letter_words/readme.md
@@ -0,0 +1,83 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2131\. Longest Palindrome by Concatenating Two Letter Words
+
+Medium
+
+You are given an array of strings `words`. Each element of `words` consists of **two** lowercase English letters.
+
+Create the **longest possible palindrome** by selecting some elements from `words` and concatenating them in **any order**. Each element can be selected **at most once**.
+
+Return _the **length** of the longest palindrome that you can create_. If it is impossible to create any palindrome, return `0`.
+
+A **palindrome** is a string that reads the same forward and backward.
+
+**Example 1:**
+
+**Input:** words = ["lc","cl","gg"]
+
+**Output:** 6
+
+**Explanation:** One longest palindrome is "lc" + "gg" + "cl" = "lcggcl", of length 6. Note that "clgglc" is another longest palindrome that can be created.
+
+**Example 2:**
+
+**Input:** words = ["ab","ty","yt","lc","cl","ab"]
+
+**Output:** 8
+
+**Explanation:** One longest palindrome is "ty" + "lc" + "cl" + "yt" = "tylcclyt", of length 8. Note that "lcyttycl" is another longest palindrome that can be created.
+
+**Example 3:**
+
+**Input:** words = ["cc","ll","xx"]
+
+**Output:** 2
+
+**Explanation:** One longest palindrome is "cc", of length 2. Note that "ll" is another longest palindrome that can be created, and so is "xx".
+
+**Constraints:**
+
+*   1 <= words.length <= 105
+*   `words[i].length == 2`
+*   `words[i]` consists of lowercase English letters.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun longestPalindrome(words: Array): Int {
+        val counter: MutableMap = HashMap()
+        for (word in words) {
+            counter[word] = counter.getOrDefault(word, 0) + 1
+        }
+        var pairPalindrome = 0
+        var selfPalindrome = 0
+        for ((key, count1) in counter) {
+            if (isPalindrome(key)) {
+                selfPalindrome += if (count1 % 2 == 1 && selfPalindrome % 2 == 0) {
+                    count1
+                } else {
+                    count1 - count1 % 2
+                }
+            } else {
+                val palindrome = palindrome(key)
+                val count = counter[palindrome]
+                if (count != null) {
+                    pairPalindrome += Math.min(count, count1)
+                }
+            }
+        }
+        return 2 * (selfPalindrome + pairPalindrome)
+    }
+
+    private fun isPalindrome(word: String): Boolean {
+        return word[1] == word[0]
+    }
+
+    private fun palindrome(word: String): String {
+        return java.lang.String.valueOf(charArrayOf(word[1], word[0]))
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2132_stamping_the_grid/readme.md b/src/main/kotlin/g2101_2200/s2132_stamping_the_grid/readme.md
new file mode 100644
index 00000000..cad0b688
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2132_stamping_the_grid/readme.md
@@ -0,0 +1,112 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2132\. Stamping the Grid
+
+Hard
+
+You are given an `m x n` binary matrix `grid` where each cell is either `0` (empty) or `1` (occupied).
+
+You are then given stamps of size `stampHeight x stampWidth`. We want to fit the stamps such that they follow the given **restrictions** and **requirements**:
+
+1.  Cover all the **empty** cells.
+2.  Do not cover any of the **occupied** cells.
+3.  We can put as **many** stamps as we want.
+4.  Stamps can **overlap** with each other.
+5.  Stamps are not allowed to be **rotated**.
+6.  Stamps must stay completely **inside** the grid.
+
+Return `true` _if it is possible to fit the stamps while following the given restrictions and requirements. Otherwise, return_ `false`.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2021/11/03/ex1.png)
+
+**Input:** grid = \[\[1,0,0,0],[1,0,0,0],[1,0,0,0],[1,0,0,0],[1,0,0,0]], stampHeight = 4, stampWidth = 3
+
+**Output:** true
+
+**Explanation:** We have two overlapping stamps (labeled 1 and 2 in the image) that are able to cover all the empty cells.
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2021/11/03/ex2.png)
+
+**Input:** grid = \[\[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]], stampHeight = 2, stampWidth = 2
+
+**Output:** false
+
+**Explanation:** There is no way to fit the stamps onto all the empty cells without the stamps going outside the grid.
+
+**Constraints:**
+
+*   `m == grid.length`
+*   `n == grid[r].length`
+*   1 <= m, n <= 105
+*   1 <= m * n <= 2 * 105
+*   `grid[r][c]` is either `0` or `1`.
+*   1 <= stampHeight, stampWidth <= 105
+
+## Solution
+
+```kotlin
+class Solution {
+    private fun canPaved(grid: Array, `is`: Int, js: Int, ie: Int, je: Int): Boolean {
+        for (i in `is`..ie) {
+            for (j in js..je) {
+                if (grid[i][j] == 1) {
+                    return true
+                }
+            }
+        }
+        return false
+    }
+
+    fun possibleToStamp(grid: Array, h: Int, w: Int): Boolean {
+        val rl = grid[0].size
+        for (i in grid.indices) {
+            val row = grid[i]
+            var prev = -1
+            for (j in row.indices) {
+                if (row[j] == 0) {
+                    if (j + 1 < rl && row[j + 1] == 1 && j - w + 1 >= 0 &&
+                        i + 1 < grid.size && grid[i + 1][j] == 1 && i - h + 1 >= 0 && canPaved(
+                                grid,
+                                i - h + 1,
+                                j - w + 1,
+                                i,
+                                j
+                            )
+                    ) {
+                        return false
+                    }
+                    continue
+                }
+                if (j - prev in 2..w) {
+                    return false
+                }
+                prev = j
+            }
+            if (row.size - prev in 2..w) {
+                return false
+            }
+        }
+        for (i in 0 until rl) {
+            var prev = -1
+            for (j in grid.indices) {
+                if (grid[j][i] == 0) {
+                    continue
+                }
+                if (j - prev in 2..h) {
+                    return false
+                }
+                prev = j
+            }
+            if (grid.size - prev in 2..h) {
+                return false
+            }
+        }
+        return true
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2133_check_if_every_row_and_column_contains_all_numbers/readme.md b/src/main/kotlin/g2101_2200/s2133_check_if_every_row_and_column_contains_all_numbers/readme.md
new file mode 100644
index 00000000..e8fe9b34
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2133_check_if_every_row_and_column_contains_all_numbers/readme.md
@@ -0,0 +1,66 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2133\. Check if Every Row and Column Contains All Numbers
+
+Easy
+
+An `n x n` matrix is **valid** if every row and every column contains **all** the integers from `1` to `n` (**inclusive**).
+
+Given an `n x n` integer matrix `matrix`, return `true` _if the matrix is **valid**._ Otherwise, return `false`.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2021/12/21/example1drawio.png)
+
+**Input:** matrix = \[\[1,2,3],[3,1,2],[2,3,1]]
+
+**Output:** true
+
+**Explanation:** In this case, n = 3, and every row and column contains the numbers 1, 2, and 3. Hence, we return true.
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2021/12/21/example2drawio.png)
+
+**Input:** matrix = \[\[1,1,1],[1,2,3],[1,2,3]]
+
+**Output:** false
+
+**Explanation:** In this case, n = 3, but the first row and the first column do not contain the numbers 2 or 3. Hence, we return false.
+
+**Constraints:**
+
+*   `n == matrix.length == matrix[i].length`
+*   `1 <= n <= 100`
+*   `1 <= matrix[i][j] <= n`
+
+## Solution
+
+```kotlin
+class Solution {
+    fun checkValid(matrix: Array): Boolean {
+        val n = matrix.size
+        val set: MutableSet = HashSet()
+        for (ints in matrix) {
+            for (anInt in ints) {
+                set.add(anInt)
+            }
+            if (set.size != n) {
+                return false
+            }
+            set.clear()
+        }
+        for (i in matrix[0].indices) {
+            for (ints in matrix) {
+                set.add(ints[i])
+            }
+            if (set.size != n) {
+                return false
+            }
+            set.clear()
+        }
+        return true
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2134_minimum_swaps_to_group_all_1s_together_ii/readme.md b/src/main/kotlin/g2101_2200/s2134_minimum_swaps_to_group_all_1s_together_ii/readme.md
new file mode 100644
index 00000000..a99f8c0a
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2134_minimum_swaps_to_group_all_1s_together_ii/readme.md
@@ -0,0 +1,102 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2134\. Minimum Swaps to Group All 1's Together II
+
+Medium
+
+A **swap** is defined as taking two **distinct** positions in an array and swapping the values in them.
+
+A **circular** array is defined as an array where we consider the **first** element and the **last** element to be **adjacent**.
+
+Given a **binary** **circular** array `nums`, return _the minimum number of swaps required to group all_ `1`_'s present in the array together at **any location**_.
+
+**Example 1:**
+
+**Input:** nums = [0,1,0,1,1,0,0]
+
+**Output:** 1
+
+**Explanation:** Here are a few of the ways to group all the 1's together: 
+
+[0,0,1,1,1,0,0] using 1 swap. 
+
+[0,1,1,1,0,0,0] using 1 swap. 
+
+[1,1,0,0,0,0,1] using 2 swaps (using the circular property of the array). 
+
+There is no way to group all 1's together with 0 swaps. 
+
+Thus, the minimum number of swaps required is 1.
+
+**Example 2:**
+
+**Input:** nums = [0,1,1,1,0,0,1,1,0]
+
+**Output:** 2
+
+**Explanation:** Here are a few of the ways to group all the 1's together: 
+
+[1,1,1,0,0,0,0,1,1] using 2 swaps (using the circular property of the array). 
+
+[1,1,1,1,1,0,0,0,0] using 2 swaps. 
+
+There is no way to group all 1's together with 0 or 1 swaps. 
+
+Thus, the minimum number of swaps required is 2.
+
+**Example 3:**
+
+**Input:** nums = [1,1,0,0,1]
+
+**Output:** 0
+
+**Explanation:** All the 1's are already grouped together due to the circular property of the array. 
+
+Thus, the minimum number of swaps required is 0.
+
+**Constraints:**
+
+*   1 <= nums.length <= 105
+*   `nums[i]` is either `0` or `1`.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun minSwaps(nums: IntArray): Int {
+        val l = nums.size
+        val ones = IntArray(l)
+        ones[0] = if (nums[0] == 1) 1 else 0
+        for (i in 1 until l) {
+            if (nums[i] == 1) {
+                ones[i] = ones[i - 1] + 1
+            } else {
+                ones[i] = ones[i - 1]
+            }
+        }
+        if (ones[l - 1] == l || ones[l - 1] == 0) {
+            return 0
+        }
+        val ws = ones[l - 1]
+        var minSwaps = Int.MAX_VALUE
+        var si = 0
+        var ei: Int
+        while (si < nums.size) {
+            ei = (si + ws - 1) % l
+            var totalones: Int
+            totalones = if (ei >= si) {
+                ones[ei] - if (si == 0) 0 else ones[si - 1]
+            } else {
+                ones[ei] + (ones[l - 1] - ones[si - 1])
+            }
+            val swapsreq = ws - totalones
+            if (swapsreq < minSwaps) {
+                minSwaps = swapsreq
+            }
+            si++
+        }
+        return minSwaps
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2135_count_words_obtained_after_adding_a_letter/readme.md b/src/main/kotlin/g2101_2200/s2135_count_words_obtained_after_adding_a_letter/readme.md
new file mode 100644
index 00000000..7a953ad5
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2135_count_words_obtained_after_adding_a_letter/readme.md
@@ -0,0 +1,125 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2135\. Count Words Obtained After Adding a Letter
+
+Medium
+
+You are given two **0-indexed** arrays of strings `startWords` and `targetWords`. Each string consists of **lowercase English letters** only.
+
+For each string in `targetWords`, check if it is possible to choose a string from `startWords` and perform a **conversion operation** on it to be equal to that from `targetWords`.
+
+The **conversion operation** is described in the following two steps:
+
+1.  **Append** any lowercase letter that is **not present** in the string to its end.
+    *   For example, if the string is `"abc"`, the letters `'d'`, `'e'`, or `'y'` can be added to it, but not `'a'`. If `'d'` is added, the resulting string will be `"abcd"`.
+2.  **Rearrange** the letters of the new string in **any** arbitrary order.
+    *   For example, `"abcd"` can be rearranged to `"acbd"`, `"bacd"`, `"cbda"`, and so on. Note that it can also be rearranged to `"abcd"` itself.
+
+Return _the **number of strings** in_ `targetWords` _that can be obtained by performing the operations on **any** string of_ `startWords`.
+
+**Note** that you will only be verifying if the string in `targetWords` can be obtained from a string in `startWords` by performing the operations. The strings in `startWords` **do not** actually change during this process.
+
+**Example 1:**
+
+**Input:** startWords = ["ant","act","tack"], targetWords = ["tack","act","acti"]
+
+**Output:** 2
+
+**Explanation:** 
+
+- In order to form targetWords[0] = "tack", we use startWords[1] = "act", append 'k' to it, and rearrange "actk" to "tack". 
+
+- There is no string in startWords that can be used to obtain targetWords[1] = "act". 
+  
+Note that "act" does exist in startWords, but we **must** append one letter to the string before rearranging it. 
+
+- In order to form targetWords[2] = "acti", we use startWords[1] = "act", append 'i' to it, and rearrange "acti" to "acti" itself.
+
+**Example 2:**
+
+**Input:** startWords = ["ab","a"], targetWords = ["abc","abcd"]
+
+**Output:** 1
+
+**Explanation:** 
+
+- In order to form targetWords[0] = "abc", we use startWords[0] = "ab", add 'c' to it, and rearrange it to "abc". 
+
+- There is no string in startWords that can be used to obtain targetWords[1] = "abcd".
+
+**Constraints:**
+
+*   1 <= startWords.length, targetWords.length <= 5 * 104
+*   `1 <= startWords[i].length, targetWords[j].length <= 26`
+*   Each string of `startWords` and `targetWords` consists of lowercase English letters only.
+*   No letter occurs more than once in any string of `startWords` or `targetWords`.
+
+## Solution
+
+```kotlin
+@Suppress("NAME_SHADOWING")
+class Solution {
+    private lateinit var set: MutableSet
+
+    private fun preprocess(words: Array) {
+        set = HashSet()
+        for (word in words) {
+            val bitMap = getBitMap(word)
+            set.add(bitMap)
+        }
+    }
+
+    private fun matches(bitMap: Int): Boolean {
+        return set.contains(bitMap)
+    }
+
+    private fun getBitMap(word: String): Int {
+        var result = 0
+        for (element in word) {
+            val position = element.code - 'a'.code
+            result = result or (1 shl position)
+        }
+        return result
+    }
+
+    private fun addBit(bitMap: Int, c: Char): Int {
+        var bitMap = bitMap
+        val position = c.code - 'a'.code
+        bitMap = bitMap or (1 shl position)
+        return bitMap
+    }
+
+    private fun removeBit(bitMap: Int, c: Char): Int {
+        var bitMap = bitMap
+        val position = c.code - 'a'.code
+        bitMap = bitMap and (1 shl position).inv()
+        return bitMap
+    }
+
+    fun wordCount(startWords: Array, targetWords: Array): Int {
+        if (startWords.isEmpty()) {
+            return 0
+        }
+        if (targetWords.isEmpty()) {
+            return 0
+        }
+        preprocess(startWords)
+        var count = 0
+        for (word in targetWords) {
+            var bitMap = getBitMap(word)
+            for (i in word.indices) {
+                bitMap = removeBit(bitMap, word[i])
+                if (i > 0) {
+                    bitMap = addBit(bitMap, word[i - 1])
+                }
+                if (matches(bitMap)) {
+                    count++
+                    break
+                }
+            }
+        }
+        return count
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2136_earliest_possible_day_of_full_bloom/readme.md b/src/main/kotlin/g2101_2200/s2136_earliest_possible_day_of_full_bloom/readme.md
new file mode 100644
index 00000000..c2e5ced2
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2136_earliest_possible_day_of_full_bloom/readme.md
@@ -0,0 +1,108 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2136\. Earliest Possible Day of Full Bloom
+
+Hard
+
+You have `n` flower seeds. Every seed must be planted first before it can begin to grow, then bloom. Planting a seed takes time and so does the growth of a seed. You are given two **0-indexed** integer arrays `plantTime` and `growTime`, of length `n` each:
+
+*   `plantTime[i]` is the number of **full days** it takes you to **plant** the ith seed. Every day, you can work on planting exactly one seed. You **do not** have to work on planting the same seed on consecutive days, but the planting of a seed is not complete **until** you have worked `plantTime[i]` days on planting it in total.
+*   `growTime[i]` is the number of **full days** it takes the ith seed to grow after being completely planted. **After** the last day of its growth, the flower **blooms** and stays bloomed forever.
+
+From the beginning of day `0`, you can plant the seeds in **any** order.
+
+Return _the **earliest** possible day where **all** seeds are blooming_.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2021/12/21/1.png)
+
+**Input:** plantTime = [1,4,3], growTime = [2,3,1]
+
+**Output:** 9
+
+**Explanation:** The grayed out pots represent planting days, colored pots represent growing days, and the flower represents the day it blooms. 
+
+One optimal way is: 
+
+On day 0, plant the 0th seed. The seed grows for 2 full days and blooms on day 3. 
+
+On days 1, 2, 3, and 4, plant the 1st seed. The seed grows for 3 full days and blooms on day 8.
+
+On days 5, 6, and 7, plant the 2nd seed. The seed grows for 1 full day and blooms on day 9. 
+
+Thus, on day 9, all the seeds are blooming.
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2021/12/21/2.png)
+
+**Input:** plantTime = [1,2,3,2], growTime = [2,1,2,1]
+
+**Output:** 9
+
+**Explanation:** The grayed out pots represent planting days, colored pots represent growing days, and the flower represents the day it blooms. 
+
+One optimal way is: 
+
+On day 1, plant the 0th seed. The seed grows for 2 full days and blooms on day 4. 
+
+On days 0 and 3, plant the 1st seed. The seed grows for 1 full day and blooms on day 5. 
+
+On days 2, 4, and 5, plant the 2nd seed. The seed grows for 2 full days and blooms on day 8. 
+
+On days 6 and 7, plant the 3rd seed. The seed grows for 1 full day and blooms on day 9. 
+
+Thus, on day 9, all the seeds are blooming.
+
+**Example 3:**
+
+**Input:** plantTime = [1], growTime = [1]
+
+**Output:** 2
+
+**Explanation:** On day 0, plant the 0th seed. The seed grows for 1 full day and blooms on day 2. 
+
+Thus, on day 2, all the seeds are blooming.
+
+**Constraints:**
+
+*   `n == plantTime.length == growTime.length`
+*   1 <= n <= 105
+*   1 <= plantTime[i], growTime[i] <= 104
+
+## Solution
+
+```kotlin
+import java.util.Arrays
+import java.util.Collections
+
+class Solution {
+    fun earliestFullBloom(plantTime: IntArray, growTime: IntArray): Int {
+        val n = plantTime.size
+        if (n == 1) {
+            return plantTime[0] + growTime[0]
+        }
+        val arr = arrayOfNulls(n)
+        for (i in 0 until n) {
+            arr[i] = Seed(plantTime[i], growTime[i])
+        }
+        Arrays.sort(arr, Collections.reverseOrder())
+        var ans = arr[0]!!.plantTime + arr[0]!!.growTime
+        var lastPlantDay = arr[0]!!.plantTime
+        for (i in 1 until n) {
+            val currBloomDay = lastPlantDay + arr[i]!!.plantTime + arr[i]!!.growTime
+            ans = Math.max(ans, currBloomDay)
+            lastPlantDay += arr[i]!!.plantTime
+        }
+        return ans
+    }
+
+    internal class Seed(var plantTime: Int, var growTime: Int) : Comparable {
+        override fun compareTo(other: Seed): Int {
+            return growTime - other.growTime
+        }
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2138_divide_a_string_into_groups_of_size_k/readme.md b/src/main/kotlin/g2101_2200/s2138_divide_a_string_into_groups_of_size_k/readme.md
new file mode 100644
index 00000000..7d9a4fe4
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2138_divide_a_string_into_groups_of_size_k/readme.md
@@ -0,0 +1,90 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2138\. Divide a String Into Groups of Size k
+
+Easy
+
+A string `s` can be partitioned into groups of size `k` using the following procedure:
+
+*   The first group consists of the first `k` characters of the string, the second group consists of the next `k` characters of the string, and so on. Each character can be a part of **exactly one** group.
+*   For the last group, if the string **does not** have `k` characters remaining, a character `fill` is used to complete the group.
+
+Note that the partition is done so that after removing the `fill` character from the last group (if it exists) and concatenating all the groups in order, the resultant string should be `s`.
+
+Given the string `s`, the size of each group `k` and the character `fill`, return _a string array denoting the **composition of every group**_ `s` _has been divided into, using the above procedure_.
+
+**Example 1:**
+
+**Input:** s = "abcdefghi", k = 3, fill = "x"
+
+**Output:** ["abc","def","ghi"]
+
+**Explanation:** 
+
+The first 3 characters "abc" form the first group. 
+
+The next 3 characters "def" form the second group. 
+
+The last 3 characters "ghi" form the third group. 
+
+Since all groups can be completely filled by characters from the string, we do not need to use fill. 
+
+Thus, the groups formed are "abc", "def", and "ghi".
+
+**Example 2:**
+
+**Input:** s = "abcdefghij", k = 3, fill = "x"
+
+**Output:** ["abc","def","ghi","jxx"]
+
+**Explanation:** 
+
+Similar to the previous example, we are forming the first three groups "abc", "def", and "ghi". 
+
+For the last group, we can only use the character 'j' from the string. 
+
+To complete this group, we add 'x' twice. Thus, the 4 groups formed are "abc", "def", "ghi", and "jxx".
+
+**Constraints:**
+
+*   `1 <= s.length <= 100`
+*   `s` consists of lowercase English letters only.
+*   `1 <= k <= 100`
+*   `fill` is a lowercase English letter.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun divideString(s: String, k: Int, fill: Char): Array {
+        val ans = arrayOfNulls(if (s.length % k != 0) s.length / k + 1 else s.length / k)
+        var t = k
+        val str: MutableList = ArrayList()
+        val sb = StringBuilder()
+        var i = 0
+        while (i < s.length) {
+            if (t > 0) {
+                sb.append(s[i])
+                t--
+            } else {
+                t = k
+                str.add(sb.toString())
+                sb.setLength(0)
+                i--
+            }
+            i++
+        }
+        if (t > 0) {
+            while (t-- > 0) {
+                sb.append(fill)
+            }
+        }
+        str.add(sb.toString())
+        for (j in str.indices) {
+            ans[j] = str[j]
+        }
+        return ans
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2139_minimum_moves_to_reach_target_score/readme.md b/src/main/kotlin/g2101_2200/s2139_minimum_moves_to_reach_target_score/readme.md
new file mode 100644
index 00000000..5e455b80
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2139_minimum_moves_to_reach_target_score/readme.md
@@ -0,0 +1,92 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2139\. Minimum Moves to Reach Target Score
+
+Medium
+
+You are playing a game with integers. You start with the integer `1` and you want to reach the integer `target`.
+
+In one move, you can either:
+
+*   **Increment** the current integer by one (i.e., `x = x + 1`).
+*   **Double** the current integer (i.e., `x = 2 * x`).
+
+You can use the **increment** operation **any** number of times, however, you can only use the **double** operation **at most** `maxDoubles` times.
+
+Given the two integers `target` and `maxDoubles`, return _the minimum number of moves needed to reach_ `target` _starting with_ `1`.
+
+**Example 1:**
+
+**Input:** target = 5, maxDoubles = 0
+
+**Output:** 4
+
+**Explanation:** Keep incrementing by 1 until you reach target.
+
+**Example 2:**
+
+**Input:** target = 19, maxDoubles = 2
+
+**Output:** 7
+
+**Explanation:** Initially, x = 1 
+
+Increment 3 times so x = 4 
+
+Double once so x = 8 
+
+Increment once so x = 9 
+
+Double again so x = 18 
+
+Increment once so x = 19
+
+**Example 3:**
+
+**Input:** target = 10, maxDoubles = 4
+
+**Output:** 4
+
+**Explanation:** Initially, x = 1 
+
+Increment once so x = 2 
+
+Double once so x = 4 
+
+Increment once so x = 5 
+
+Double again so x = 10
+
+**Constraints:**
+
+*   1 <= target <= 109
+*   `0 <= maxDoubles <= 100`
+
+## Solution
+
+```kotlin
+@Suppress("NAME_SHADOWING")
+class Solution {
+    fun minMoves(target: Int, maxDoubles: Int): Int {
+        var target = target
+        var maxDoubles = maxDoubles
+        var count = 0
+        while (target > 1) {
+            if (maxDoubles > 0 && target % 2 == 0) {
+                maxDoubles--
+                target /= 2
+            } else {
+                if (maxDoubles == 0) {
+                    count = count + target - 1
+                    return count
+                } else {
+                    target -= 1
+                }
+            }
+            count++
+        }
+        return count
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2140_solving_questions_with_brainpower/readme.md b/src/main/kotlin/g2101_2200/s2140_solving_questions_with_brainpower/readme.md
new file mode 100644
index 00000000..c17b6c8d
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2140_solving_questions_with_brainpower/readme.md
@@ -0,0 +1,76 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2140\. Solving Questions With Brainpower
+
+Medium
+
+You are given a **0-indexed** 2D integer array `questions` where questions[i] = [pointsi, brainpoweri].
+
+The array describes the questions of an exam, where you have to process the questions **in order** (i.e., starting from question `0`) and make a decision whether to **solve** or **skip** each question. Solving question `i` will **earn** you pointsi points but you will be **unable** to solve each of the next brainpoweri questions. If you skip question `i`, you get to make the decision on the next question.
+
+*   For example, given `questions = \[\[3, 2], [4, 3], [4, 4], [2, 5]]`:
+    *   If question `0` is solved, you will earn `3` points but you will be unable to solve questions `1` and `2`.
+    *   If instead, question `0` is skipped and question `1` is solved, you will earn `4` points but you will be unable to solve questions `2` and `3`.
+
+Return _the **maximum** points you can earn for the exam_.
+
+**Example 1:**
+
+**Input:** questions = \[\[3,2],[4,3],[4,4],[2,5]]
+
+**Output:** 5
+
+**Explanation:** The maximum points can be earned by solving questions 0 and 3. 
+
+- Solve question 0: Earn 3 points, will be unable to solve the next 2 questions 
+
+- Unable to solve questions 1 and 2 
+
+- Solve question 3: Earn 2 points 
+  
+Total points earned: 3 + 2 = 5. There is no other way to earn 5 or more points.
+
+**Example 2:**
+
+**Input:** questions = \[\[1,1],[2,2],[3,3],[4,4],[5,5]]
+
+**Output:** 7
+
+**Explanation:** The maximum points can be earned by solving questions 1 and 4. 
+
+- Skip question 0 
+
+- Solve question 1: Earn 2 points, will be unable to solve the next 2 questions 
+
+- Unable to solve questions 2 and 3 
+
+- Solve question 4: Earn 5 points 
+  
+Total points earned: 2 + 5 = 7. There is no other way to earn 7 or more points.
+
+**Constraints:**
+
+*   1 <= questions.length <= 105
+*   `questions[i].length == 2`
+*   1 <= pointsi, brainpoweri <= 105
+
+## Solution
+
+```kotlin
+class Solution {
+    fun mostPoints(questions: Array): Long {
+        val n = questions.size
+        val memo = LongArray(n)
+        memo[n - 1] = questions[n - 1][0].toLong()
+        for (i in n - 2 downTo 0) {
+            if (i + questions[i][1] + 1 < n) {
+                memo[i] = Math.max(memo[i + 1], questions[i][0] + memo[i + questions[i][1] + 1])
+            } else {
+                memo[i] = Math.max(memo[i + 1], questions[i][0].toLong())
+            }
+        }
+        return memo[0]
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2141_maximum_running_time_of_n_computers/readme.md b/src/main/kotlin/g2101_2200/s2141_maximum_running_time_of_n_computers/readme.md
new file mode 100644
index 00000000..b6b54b1a
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2141_maximum_running_time_of_n_computers/readme.md
@@ -0,0 +1,87 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2141\. Maximum Running Time of N Computers
+
+Hard
+
+You have `n` computers. You are given the integer `n` and a **0-indexed** integer array `batteries` where the ith battery can **run** a computer for `batteries[i]` minutes. You are interested in running **all** `n` computers **simultaneously** using the given batteries.
+
+Initially, you can insert **at most one battery** into each computer. After that and at any integer time moment, you can remove a battery from a computer and insert another battery **any number of times**. The inserted battery can be a totally new battery or a battery from another computer. You may assume that the removing and inserting processes take no time.
+
+Note that the batteries cannot be recharged.
+
+Return _the **maximum** number of minutes you can run all the_ `n` _computers simultaneously._
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/01/06/example1-fit.png)
+
+**Input:** n = 2, batteries = [3,3,3]
+
+**Output:** 4
+
+**Explanation:** 
+
+Initially, insert battery 0 into the first computer and battery 1 into the second computer. 
+
+After two minutes, remove battery 1 from the second computer and insert battery 2 instead. Note that battery 1 can still run for one minute.
+
+At the end of the third minute, battery 0 is drained, and you need to remove it from the first computer and insert battery 1 instead. 
+
+By the end of the fourth minute, battery 1 is also drained, and the first computer is no longer running. 
+
+We can run the two computers simultaneously for at most 4 minutes, so we return 4.
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2022/01/06/example2.png)
+
+**Input:** n = 2, batteries = [1,1,1,1]
+
+**Output:** 2
+
+**Explanation:** 
+
+Initially, insert battery 0 into the first computer and battery 2 into the second computer. 
+
+After one minute, battery 0 and battery 2 are drained so you need to remove them and insert battery 1 into the first computer and battery 3 into the second computer. 
+
+After another minute, battery 1 and battery 3 are also drained so the first and second computers are no longer running. 
+
+We can run the two computers simultaneously for at most 2 minutes, so we return 2.
+
+**Constraints:**
+
+*   1 <= n <= batteries.length <= 105
+*   1 <= batteries[i] <= 109
+
+## Solution
+
+```kotlin
+class Solution {
+    fun maxRunTime(n: Int, batteries: IntArray): Long {
+        var sumbatt: Long = 0
+        for (x in batteries) sumbatt += x.toLong()
+        var l: Long = 0
+        var r = sumbatt / n
+        var res = Long.MIN_VALUE
+        while (l <= r) {
+            val mid = (l + r) / 2
+            if (isPossible(mid, n, batteries)) {
+                res = mid
+                l = mid + 1
+            } else {
+                r = mid - 1
+            }
+        }
+        return res
+    }
+
+    private fun isPossible(mid: Long, n: Int, b: IntArray): Boolean {
+        var sum: Long = 0
+        for (x in b) sum += Math.min(x.toLong(), mid)
+        return n * mid <= sum
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2144_minimum_cost_of_buying_candies_with_discount/readme.md b/src/main/kotlin/g2101_2200/s2144_minimum_cost_of_buying_candies_with_discount/readme.md
new file mode 100644
index 00000000..41b241c2
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2144_minimum_cost_of_buying_candies_with_discount/readme.md
@@ -0,0 +1,80 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2144\. Minimum Cost of Buying Candies With Discount
+
+Easy
+
+A shop is selling candies at a discount. For **every two** candies sold, the shop gives a **third** candy for **free**.
+
+The customer can choose **any** candy to take away for free as long as the cost of the chosen candy is less than or equal to the **minimum** cost of the two candies bought.
+
+*   For example, if there are `4` candies with costs `1`, `2`, `3`, and `4`, and the customer buys candies with costs `2` and `3`, they can take the candy with cost `1` for free, but not the candy with cost `4`.
+
+Given a **0-indexed** integer array `cost`, where `cost[i]` denotes the cost of the ith candy, return _the **minimum cost** of buying **all** the candies_.
+
+**Example 1:**
+
+**Input:** cost = [1,2,3]
+
+**Output:** 5
+
+**Explanation:** We buy the candies with costs 2 and 3, and take the candy with cost 1 for free. 
+
+The total cost of buying all candies is 2 + 3 = 5. This is the **only** way we can buy the candies. 
+
+Note that we cannot buy candies with costs 1 and 3, and then take the candy with cost 2 for free. 
+
+The cost of the free candy has to be less than or equal to the minimum cost of the purchased candies.
+
+**Example 2:**
+
+**Input:** cost = [6,5,7,9,2,2]
+
+**Output:** 23
+
+**Explanation:** The way in which we can get the minimum cost is described below: 
+
+- Buy candies with costs 9 and 7 
+
+- Take the candy with cost 6 for free 
+
+- We buy candies with costs 5 and 2 
+
+- Take the last remaining candy with cost 2 for free 
+  
+Hence, the minimum cost to buy all candies is 9 + 7 + 5 + 2 = 23.
+
+**Example 3:**
+
+**Input:** cost = [5,5]
+
+**Output:** 10
+
+**Explanation:** Since there are only 2 candies, we buy both of them. There is not a third candy we can take for free. 
+
+Hence, the minimum cost to buy all candies is 5 + 5 = 10.
+
+**Constraints:**
+
+*   `1 <= cost.length <= 100`
+*   `1 <= cost[i] <= 100`
+
+## Solution
+
+```kotlin
+class Solution {
+    fun minimumCost(cost: IntArray): Int {
+        cost.sort()
+        var size = 0
+        var sum = 0
+        for (i in cost.indices.reversed()) {
+            size++
+            if (size % 3 != 0) {
+                sum += cost[i]
+            }
+        }
+        return sum
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2145_count_the_hidden_sequences/readme.md b/src/main/kotlin/g2101_2200/s2145_count_the_hidden_sequences/readme.md
new file mode 100644
index 00000000..b35f0436
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2145_count_the_hidden_sequences/readme.md
@@ -0,0 +1,101 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2145\. Count the Hidden Sequences
+
+Medium
+
+You are given a **0-indexed** array of `n` integers `differences`, which describes the **differences** between each pair of **consecutive** integers of a **hidden** sequence of length `(n + 1)`. More formally, call the hidden sequence `hidden`, then we have that `differences[i] = hidden[i + 1] - hidden[i]`.
+
+You are further given two integers `lower` and `upper` that describe the **inclusive** range of values `[lower, upper]` that the hidden sequence can contain.
+
+*   For example, given `differences = [1, -3, 4]`, `lower = 1`, `upper = 6`, the hidden sequence is a sequence of length `4` whose elements are in between `1` and `6` (**inclusive**).
+    *   `[3, 4, 1, 5]` and `[4, 5, 2, 6]` are possible hidden sequences.
+    *   `[5, 6, 3, 7]` is not possible since it contains an element greater than `6`.
+    *   `[1, 2, 3, 4]` is not possible since the differences are not correct.
+
+Return _the number of **possible** hidden sequences there are._ If there are no possible sequences, return `0`.
+
+**Example 1:**
+
+**Input:** differences = [1,-3,4], lower = 1, upper = 6
+
+**Output:** 2
+
+**Explanation:** The possible hidden sequences are: 
+
+- \[3, 4, 1, 5] 
+
+- \[4, 5, 2, 6] 
+  
+Thus, we return 2.
+
+**Example 2:**
+
+**Input:** differences = [3,-4,5,1,-2], lower = -4, upper = 5
+
+**Output:** 4
+
+**Explanation:** The possible hidden sequences are: 
+
+- \[-3, 0, -4, 1, 2, 0] 
+
+- \[-2, 1, -3, 2, 3, 1] 
+
+- \[-1, 2, -2, 3, 4, 2] 
+
+- \[0, 3, -1, 4, 5, 3] 
+  
+Thus, we return 4.
+
+**Example 3:**
+
+**Input:** differences = [4,-7,2], lower = 3, upper = 6
+
+**Output:** 0
+
+**Explanation:** There are no possible hidden sequences. Thus, we return 0.
+
+**Constraints:**
+
+*   `n == differences.length`
+*   1 <= n <= 105
+*   -105 <= differences[i] <= 105
+*   -105 <= lower <= upper <= 105
+
+## Solution
+
+```kotlin
+class Solution {
+    fun numberOfArrays(differences: IntArray, lower: Int, upper: Int): Int {
+        val n = differences.size
+        if (lower == upper) {
+            for (j in differences) {
+                if (j != 0) {
+                    return 0
+                }
+            }
+        }
+        var max = (-1e9).toInt()
+        var min = 1e9.toInt()
+        val hidden = IntArray(n + 1)
+        hidden[0] = 0
+        for (i in 1..n) {
+            hidden[i] = hidden[i - 1] + differences[i - 1]
+        }
+        for (i in 0..n) {
+            if (hidden[i] > max) {
+                max = hidden[i]
+            }
+            if (hidden[i] < min) {
+                min = hidden[i]
+            }
+        }
+        val low = lower - min
+        val high = upper - max
+        return if (low > high) {
+            0
+        } else high - low + 1
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2146_k_highest_ranked_items_within_a_price_range/readme.md b/src/main/kotlin/g2101_2200/s2146_k_highest_ranked_items_within_a_price_range/readme.md
new file mode 100644
index 00000000..d0248673
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2146_k_highest_ranked_items_within_a_price_range/readme.md
@@ -0,0 +1,166 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2146\. K Highest Ranked Items Within a Price Range
+
+Medium
+
+You are given a **0-indexed** 2D integer array `grid` of size `m x n` that represents a map of the items in a shop. The integers in the grid represent the following:
+
+*   `0` represents a wall that you cannot pass through.
+*   `1` represents an empty cell that you can freely move to and from.
+*   All other positive integers represent the price of an item in that cell. You may also freely move to and from these item cells.
+
+It takes `1` step to travel between adjacent grid cells.
+
+You are also given integer arrays `pricing` and `start` where `pricing = [low, high]` and `start = [row, col]` indicates that you start at the position `(row, col)` and are interested only in items with a price in the range of `[low, high]` (**inclusive**). You are further given an integer `k`.
+
+You are interested in the **positions** of the `k` **highest-ranked** items whose prices are **within** the given price range. The rank is determined by the **first** of these criteria that is different:
+
+1.  Distance, defined as the length of the shortest path from the `start` (**shorter** distance has a higher rank).
+2.  Price (**lower** price has a higher rank, but it must be **in the price range**).
+3.  The row number (**smaller** row number has a higher rank).
+4.  The column number (**smaller** column number has a higher rank).
+
+Return _the_ `k` _highest-ranked items within the price range **sorted** by their rank (highest to lowest)_. If there are fewer than `k` reachable items within the price range, return _**all** of them_.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2021/12/16/example1drawio.png)
+
+**Input:** grid = \[\[1,2,0,1],[1,3,0,1],[0,2,5,1]], pricing = [2,5], start = [0,0], k = 3
+
+**Output:** [[0,1],[1,1],[2,1]]
+
+**Explanation:** You start at (0,0). 
+
+With a price range of [2,5], we can take items from (0,1), (1,1), (2,1) and (2,2). 
+
+The ranks of these items are: 
+
+- (0,1) with distance 1 
+
+- (1,1) with distance 2 
+
+- (2,1) with distance 3 
+
+- (2,2) with distance 4 
+  
+Thus, the 3 highest ranked items in the price range are (0,1), (1,1), and (2,1).
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2021/12/16/example2drawio1.png)
+
+**Input:** grid = \[\[1,2,0,1],[1,3,3,1],[0,2,5,1]], pricing = [2,3], start = [2,3], k = 2
+
+**Output:** [[2,1],[1,2]]
+
+**Explanation:** You start at (2,3). 
+
+With a price range of [2,3], we can take items from (0,1), (1,1), (1,2) and (2,1). 
+
+The ranks of these items are: 
+
+- (2,1) with distance 2, price 2 
+
+- (1,2) with distance 2, price 3 
+
+- (1,1) with distance 3 
+
+- (0,1) with distance 4 
+  
+Thus, the 2 highest ranked items in the price range are (2,1) and (1,2).
+
+**Example 3:**
+
+![](https://assets.leetcode.com/uploads/2021/12/30/example3.png)
+
+**Input:** grid = \[\[1,1,1],[0,0,1],[2,3,4]], pricing = [2,3], start = [0,0], k = 3
+
+**Output:** [[2,1],[2,0]]
+
+**Explanation:** You start at (0,0). 
+
+With a price range of [2,3], we can take items from (2,0) and (2,1). 
+
+The ranks of these items are: 
+
+- (2,1) with distance 5 
+
+- (2,0) with distance 6 
+  
+Thus, the 2 highest ranked items in the price range are (2,1) and (2,0). 
+
+    Note that k = 3 but there are only 2 reachable items within the price range.
+
+**Constraints:**
+
+*   `m == grid.length`
+*   `n == grid[i].length`
+*   1 <= m, n <= 105
+*   1 <= m * n <= 105
+*   0 <= grid[i][j] <= 105
+*   `pricing.length == 2`
+*   2 <= low <= high <= 105
+*   `start.length == 2`
+*   `0 <= row <= m - 1`
+*   `0 <= col <= n - 1`
+*   `grid[row][col] > 0`
+*   `1 <= k <= m * n`
+
+## Solution
+
+```kotlin
+import java.util.ArrayDeque
+import java.util.Collections
+import java.util.Deque
+
+class Solution {
+    fun highestRankedKItems(grid: Array, pricing: IntArray, start: IntArray, k: Int): List> {
+        val m = grid.size
+        val n = grid[0].size
+        val row = start[0]
+        val col = start[1]
+        val low = pricing[0]
+        val high = pricing[1]
+        val items: MutableList = ArrayList()
+        if (grid[row][col] in low..high) items.add(intArrayOf(0, grid[row][col], row, col))
+        grid[row][col] = 0
+        val q: Deque = ArrayDeque()
+        q.offer(intArrayOf(row, col, 0))
+        val dirs = intArrayOf(-1, 0, 1, 0, -1)
+        while (q.isNotEmpty()) {
+            val p = q.poll()
+            val i = p[0]
+            val j = p[1]
+            val d = p[2]
+            for (l in 0..3) {
+                val x = i + dirs[l]
+                val y = j + dirs[l + 1]
+                if (x in 0 until m && y >= 0 && y < n && grid[x][y] > 0) {
+                    if (grid[x][y] in low..high) {
+                        items.add(intArrayOf(d + 1, grid[x][y], x, y))
+                    }
+                    grid[x][y] = 0
+                    q.offer(intArrayOf(x, y, d + 1))
+                }
+            }
+        }
+        Collections.sort(items) { a: IntArray, b: IntArray ->
+            if (a[0] != b[0]) return@sort a[0] - b[0]
+            if (a[1] != b[1]) return@sort a[1] - b[1]
+            if (a[2] != b[2]) return@sort a[2] - b[2]
+            a[3] - b[3]
+        }
+        val ans: MutableList> = ArrayList()
+        var i = 0
+        while (i < items.size && i < k) {
+            val p = items[i]
+            ans.add(listOf(p[2], p[3]))
+            ++i
+        }
+        return ans
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2147_number_of_ways_to_divide_a_long_corridor/readme.md b/src/main/kotlin/g2101_2200/s2147_number_of_ways_to_divide_a_long_corridor/readme.md
new file mode 100644
index 00000000..ee88590d
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2147_number_of_ways_to_divide_a_long_corridor/readme.md
@@ -0,0 +1,99 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2147\. Number of Ways to Divide a Long Corridor
+
+Hard
+
+Along a long library corridor, there is a line of seats and decorative plants. You are given a **0-indexed** string `corridor` of length `n` consisting of letters `'S'` and `'P'` where each `'S'` represents a seat and each `'P'` represents a plant.
+
+One room divider has **already** been installed to the left of index `0`, and **another** to the right of index `n - 1`. Additional room dividers can be installed. For each position between indices `i - 1` and `i` (`1 <= i <= n - 1`), at most one divider can be installed.
+
+Divide the corridor into non-overlapping sections, where each section has **exactly two seats** with any number of plants. There may be multiple ways to perform the division. Two ways are **different** if there is a position with a room divider installed in the first way but not in the second way.
+
+Return _the number of ways to divide the corridor_. Since the answer may be very large, return it **modulo** 109 + 7. If there is no way, return `0`.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2021/12/04/1.png)
+
+**Input:** corridor = "SSPPSPS"
+
+**Output:** 3
+
+**Explanation:** There are 3 different ways to divide the corridor. 
+
+The black bars in the above image indicate the two room dividers already installed. 
+
+Note that in each of the ways, **each** section has exactly **two** seats.
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2021/12/04/2.png)
+
+**Input:** corridor = "PPSPSP"
+
+**Output:** 1
+
+**Explanation:** There is only 1 way to divide the corridor, by not installing any additional dividers. 
+
+Installing any would create some section that does not have exactly two seats.
+
+**Example 3:**
+
+![](https://assets.leetcode.com/uploads/2021/12/12/3.png)
+
+**Input:** corridor = "S"
+
+**Output:** 0
+
+**Explanation:** There is no way to divide the corridor because there will always be a section that does not have exactly two seats.
+
+**Constraints:**
+
+*   `n == corridor.length`
+*   1 <= n <= 105
+*   `corridor[i]` is either `'S'` or `'P'`.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun numberOfWays(corridor: String): Int {
+        var seat = 0
+        val mod = 1e9.toInt() + 7
+        for (i in 0 until corridor.length) {
+            if (corridor[i] == 'S') {
+                seat++
+            }
+        }
+        if (seat == 0 || seat % 2 != 0) {
+            return 0
+        }
+        seat /= 2
+        var curr: Long = 0
+        var ans: Long = 1
+        var i = 0
+        while (corridor[i] != 'S') {
+            i++
+        }
+        i++
+        while (seat > 1) {
+            while (corridor[i] != 'S') {
+                i++
+            }
+            i++
+            while (corridor[i] != 'S') {
+                i++
+                curr++
+            }
+            curr++
+            ans = ans * curr % mod
+            curr = 0
+            seat--
+            i++
+        }
+        return ans.toInt()
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2148_count_elements_with_strictly_smaller_and_greater_elements/readme.md b/src/main/kotlin/g2101_2200/s2148_count_elements_with_strictly_smaller_and_greater_elements/readme.md
new file mode 100644
index 00000000..eeb6a305
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2148_count_elements_with_strictly_smaller_and_greater_elements/readme.md
@@ -0,0 +1,63 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2148\. Count Elements With Strictly Smaller and Greater Elements
+
+Easy
+
+Given an integer array `nums`, return _the number of elements that have **both** a strictly smaller and a strictly greater element appear in_ `nums`.
+
+**Example 1:**
+
+**Input:** nums = [11,7,2,15]
+
+**Output:** 2
+
+**Explanation:** The element 7 has the element 2 strictly smaller than it and the element 11 strictly greater than it. 
+
+Element 11 has element 7 strictly smaller than it and element 15 strictly greater than it. 
+
+In total there are 2 elements having both a strictly smaller and a strictly greater element appear in `nums`.
+
+**Example 2:**
+
+**Input:** nums = [-3,3,3,90]
+
+**Output:** 2
+
+**Explanation:** The element 3 has the element -3 strictly smaller than it and the element 90 strictly greater than it. 
+
+Since there are two elements with the value 3, in total there are 2 elements having both a strictly smaller and a strictly greater element appear in `nums`.
+
+**Constraints:**
+
+*   `1 <= nums.length <= 100`
+*   -105 <= nums[i] <= 105
+
+## Solution
+
+```kotlin
+class Solution {
+    fun countElements(nums: IntArray): Int {
+        var min = nums[0]
+        var max = nums[0]
+        var minocr = 1
+        var maxocr = 1
+        for (i in 1 until nums.size) {
+            if (nums[i] < min) {
+                min = nums[i]
+                minocr = 1
+            } else if (nums[i] == min) {
+                minocr++
+            }
+            if (nums[i] > max) {
+                max = nums[i]
+                maxocr = 1
+            } else if (nums[i] == max) {
+                maxocr++
+            }
+        }
+        return if (min == max) 0 else nums.size - minocr - maxocr
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2149_rearrange_array_elements_by_sign/readme.md b/src/main/kotlin/g2101_2200/s2149_rearrange_array_elements_by_sign/readme.md
new file mode 100644
index 00000000..5ae1569f
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2149_rearrange_array_elements_by_sign/readme.md
@@ -0,0 +1,76 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2149\. Rearrange Array Elements by Sign
+
+Medium
+
+You are given a **0-indexed** integer array `nums` of **even** length consisting of an **equal** number of positive and negative integers.
+
+You should **rearrange** the elements of `nums` such that the modified array follows the given conditions:
+
+1.  Every **consecutive pair** of integers have **opposite signs**.
+2.  For all integers with the same sign, the **order** in which they were present in `nums` is **preserved**.
+3.  The rearranged array begins with a positive integer.
+
+Return _the modified array after rearranging the elements to satisfy the aforementioned conditions_.
+
+**Example 1:**
+
+**Input:** nums = [3,1,-2,-5,2,-4]
+
+**Output:** [3,-2,1,-5,2,-4]
+
+**Explanation:** The positive integers in nums are [3,1,2]. 
+
+The negative integers are [-2,-5,-4]. 
+
+The only possible way to rearrange them such that they satisfy all conditions is [3,-2,1,-5,2,-4]. 
+
+Other ways such as [1,-2,2,-5,3,-4], [3,1,2,-2,-5,-4], [-2,3,-5,1,-4,2] are incorrect because they do not satisfy one or more conditions.
+
+**Example 2:**
+
+**Input:** nums = [-1,1]
+
+**Output:** [1,-1]
+
+**Explanation:** 1 is the only positive integer and -1 the only negative integer in nums. 
+
+So nums is rearranged to [1,-1].
+
+**Constraints:**
+
+*   2 <= nums.length <= 2 * 105
+*   `nums.length` is **even**
+*   1 <= |nums[i]| <= 105
+*   `nums` consists of **equal** number of positive and negative integers.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun rearrangeArray(nums: IntArray): IntArray {
+        val negatives = IntArray(nums.size / 2)
+        val positives = IntArray(nums.size / 2)
+        val result = IntArray(nums.size)
+        var pPtr = 0
+        var nPtr = 0
+        var rPtr = 0
+        for (num in nums) {
+            if (num > 0) {
+                positives[pPtr++] = num
+            } else {
+                negatives[nPtr++] = num
+            }
+        }
+        pPtr = 0
+        nPtr = 0
+        while (pPtr < positives.size && nPtr < negatives.size) {
+            result[rPtr++] = positives[pPtr++]
+            result[rPtr++] = negatives[nPtr++]
+        }
+        return result
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2150_find_all_lonely_numbers_in_the_array/readme.md b/src/main/kotlin/g2101_2200/s2150_find_all_lonely_numbers_in_the_array/readme.md
new file mode 100644
index 00000000..aa331e7d
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2150_find_all_lonely_numbers_in_the_array/readme.md
@@ -0,0 +1,71 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2150\. Find All Lonely Numbers in the Array
+
+Medium
+
+You are given an integer array `nums`. A number `x` is **lonely** when it appears only **once**, and no **adjacent** numbers (i.e. `x + 1` and `x - 1)` appear in the array.
+
+Return _**all** lonely numbers in_ `nums`. You may return the answer in **any order**.
+
+**Example 1:**
+
+**Input:** nums = [10,6,5,8]
+
+**Output:** [10,8]
+
+**Explanation:**
+
+- 10 is a lonely number since it appears exactly once and 9 and 11 does not appear in nums. 
+
+- 8 is a lonely number since it appears exactly once and 7 and 9 does not appear in nums. 
+
+- 5 is not a lonely number since 6 appears in nums and vice versa. 
+
+Hence, the lonely numbers in nums are [10, 8]. 
+
+Note that [8, 10] may also be returned. 
+
+**Example 2:**
+
+**Input:** nums = [1,3,5,3]
+
+**Output:** [1,5]
+
+**Explanation:**
+
+- 1 is a lonely number since it appears exactly once and 0 and 2 does not appear in nums. 
+
+- 5 is a lonely number since it appears exactly once and 4 and 6 does not appear in nums. 
+
+- 3 is not a lonely number since it appears twice. 
+
+Hence, the lonely numbers in nums are [1, 5]. 
+
+Note that [5, 1] may also be returned. 
+
+**Constraints:**
+
+*   1 <= nums.length <= 105
+*   0 <= nums[i] <= 106
+
+## Solution
+
+```kotlin
+class Solution {
+    fun findLonely(nums: IntArray): List {
+        val ans: MutableList = ArrayList()
+        val m = HashMap()
+        for (i in nums) {
+            m[i] = m.getOrDefault(i, 0) + 1
+        }
+        for (i in nums) {
+            if (m[i] == 1 && !m.containsKey(i - 1) && !m.containsKey(i + 1)) {
+                ans.add(i)
+            }
+        }
+        return ans
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2151_maximum_good_people_based_on_statements/readme.md b/src/main/kotlin/g2101_2200/s2151_maximum_good_people_based_on_statements/readme.md
new file mode 100644
index 00000000..2cf6cc35
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2151_maximum_good_people_based_on_statements/readme.md
@@ -0,0 +1,135 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2151\. Maximum Good People Based on Statements
+
+Hard
+
+There are two types of persons:
+
+*   The **good person**: The person who always tells the truth.
+*   The **bad person**: The person who might tell the truth and might lie.
+
+You are given a **0-indexed** 2D integer array `statements` of size `n x n` that represents the statements made by `n` people about each other. More specifically, `statements[i][j]` could be one of the following:
+
+*   `0` which represents a statement made by person `i` that person `j` is a **bad** person.
+*   `1` which represents a statement made by person `i` that person `j` is a **good** person.
+*   `2` represents that **no statement** is made by person `i` about person `j`.
+
+Additionally, no person ever makes a statement about themselves. Formally, we have that `statements[i][i] = 2` for all `0 <= i < n`.
+
+Return _the **maximum** number of people who can be **good** based on the statements made by the_ `n` _people_.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/01/15/logic1.jpg)
+
+**Input:** statements = \[\[2,1,2],[1,2,2],[2,0,2]]
+
+**Output:** 2
+
+**Explanation:**
+
+    Each person makes a single statement.
+    - Person 0 states that person 1 is good.
+    - Person 1 states that person 0 is good.
+    - Person 2 states that person 1 is bad.
+    Let's take person 2 as the key.
+    - Assuming that person 2 is a good person:
+        - Based on the statement made by person 2, person 1 is a bad person.
+        - Now we know for sure that person 1 is bad and person 2 is good.
+        - Based on the statement made by person 1, and since person 1 is bad, they could be:
+            - telling the truth. There will be a contradiction in this case and this assumption is invalid.
+            - lying. In this case, person 0 is also a bad person and lied in their statement.
+        - Following that person 2 is a good person, there will be only one good person in the group.
+    - Assuming that person 2 is a bad person:
+        - Based on the statement made by person 2, and since person 2 is bad, they could be:
+            - telling the truth. Following this scenario, person 0 and 1 are both bad as explained before.
+                - Following that person 2 is bad but told the truth, there will be no good persons in the group.
+            - lying. In this case person 1 is a good person.
+                - Since person 1 is a good person, person 0 is also a good person.
+                - Following that person 2 is bad and lied, there will be two good persons in the group.
+                
+    We can see that at most 2 persons are good in the best case, so we return 2.
+    Note that there is more than one way to arrive at this conclusion. 
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2022/01/15/logic2.jpg)
+
+**Input:** statements = \[\[2,0],[0,2]]
+
+**Output:** 1
+
+**Explanation:**
+
+    Each person makes a single statement.
+    - Person 0 states that person 1 is bad.
+    - Person 1 states that person 0 is bad.
+    Let's take person 0 as the key.
+    - Assuming that person 0 is a good person:
+        - Based on the statement made by person 0, person 1 is a bad person and was lying.
+        - Following that person 0 is a good person, there will be only one good person in the group.
+    - Assuming that person 0 is a bad person:
+        - Based on the statement made by person 0, and since person 0 is bad, they could be:
+            - telling the truth. Following this scenario, person 0 and 1 are both bad.
+                - Following that person 0 is bad but told the truth, there will be no good persons in the group.
+            - lying. In this case person 1 is a good person.
+                - Following that person 0 is bad and lied, there will be only one good person in the group.
+    We can see that at most, one person is good in the best case, so we return 1.
+    Note that there is more than one way to arrive at this conclusion. 
+
+**Constraints:**
+
+*   `n == statements.length == statements[i].length`
+*   `2 <= n <= 15`
+*   `statements[i][j]` is either `0`, `1`, or `2`.
+*   `statements[i][i] == 2`
+
+## Solution
+
+```kotlin
+class Solution {
+    fun maximumGood(statements: Array): Int {
+        val known = IntArray(statements.size)
+        known.fill(2)
+        return max(statements, known, 0)
+    }
+
+    private fun max(statements: Array, known: IntArray, position: Int): Int {
+        return if (position == statements.size) {
+            known.asSequence().filter { a: Int -> a == 1 }.count()
+        } else when (known[position]) {
+            0 -> assumeBad(statements, known, position)
+            1 -> assumeGood(statements, known, position)
+            else -> Math.max(
+                assumeBad(statements, known, position),
+                assumeGood(statements, known, position)
+            )
+        }
+    }
+
+    private fun assumeBad(statements: Array, known: IntArray, position: Int): Int {
+        val updatedKnown = known.clone()
+        updatedKnown[position] = 0
+        return max(statements, updatedKnown, position + 1)
+    }
+
+    private fun assumeGood(statements: Array, known: IntArray, position: Int): Int {
+        val updatedKnown = known.clone()
+        var conflictDetected = false
+        updatedKnown[position] = 1
+        for (i in statements[position].indices) {
+            val answer = statements[position][i]
+            if (answer != 2) {
+                if (known[i] != 2 && answer != known[i]) {
+                    conflictDetected = true
+                    break
+                }
+                updatedKnown[i] = answer
+            }
+        }
+        return if (conflictDetected) 0 else max(statements, updatedKnown, position + 1)
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2154_keep_multiplying_found_values_by_two/readme.md b/src/main/kotlin/g2101_2200/s2154_keep_multiplying_found_values_by_two/readme.md
new file mode 100644
index 00000000..b788936e
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2154_keep_multiplying_found_values_by_two/readme.md
@@ -0,0 +1,68 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2154\. Keep Multiplying Found Values by Two
+
+Easy
+
+You are given an array of integers `nums`. You are also given an integer `original` which is the first number that needs to be searched for in `nums`.
+
+You then do the following steps:
+
+1.  If `original` is found in `nums`, **multiply** it by two (i.e., set `original = 2 * original`).
+2.  Otherwise, **stop** the process.
+3.  **Repeat** this process with the new number as long as you keep finding the number.
+
+Return _the **final** value of_ `original`.
+
+**Example 1:**
+
+**Input:** nums = [5,3,6,1,12], original = 3
+
+**Output:** 24
+
+**Explanation:** 
+- 3 is found in nums. 3 is multiplied by 2 to obtain 6. 
+
+- 6 is found in nums. 6 is multiplied by 2 to obtain 12. 
+
+- 12 is found in nums. 12 is multiplied by 2 to obtain 24. 
+
+- 24 is not found in nums. 
+Thus, 24 is returned. 
+
+**Example 2:**
+
+**Input:** nums = [2,7,9], original = 4
+
+**Output:** 4
+
+**Explanation:** 
+- 4 is not found in nums. 
+
+Thus, 4 is returned. 
+
+**Constraints:**
+
+*   `1 <= nums.length <= 1000`
+*   `1 <= nums[i], original <= 1000`
+
+## Solution
+
+```kotlin
+@Suppress("NAME_SHADOWING")
+class Solution {
+    fun findFinalValue(nums: IntArray, original: Int): Int {
+        var original = original
+        var i = 0
+        while (i < nums.size) {
+            if (nums[i] == original) {
+                original = original * 2
+                i = -1
+            }
+            i++
+        }
+        return original
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2155_all_divisions_with_the_highest_score_of_a_binary_array/readme.md b/src/main/kotlin/g2101_2200/s2155_all_divisions_with_the_highest_score_of_a_binary_array/readme.md
new file mode 100644
index 00000000..37d01bf9
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2155_all_divisions_with_the_highest_score_of_a_binary_array/readme.md
@@ -0,0 +1,112 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2155\. All Divisions With the Highest Score of a Binary Array
+
+Medium
+
+You are given a **0-indexed** binary array `nums` of length `n`. `nums` can be divided at index `i` (where `0 <= i <= n)` into two arrays (possibly empty) numsleft and numsright:
+
+*   numsleft has all the elements of `nums` between index `0` and `i - 1` **(inclusive)**, while numsright has all the elements of nums between index `i` and `n - 1` **(inclusive)**.
+*   If `i == 0`, numsleft is **empty**, while numsright has all the elements of `nums`.
+*   If `i == n`, numsleft has all the elements of nums, while numsright is **empty**.
+
+The **division score** of an index `i` is the **sum** of the number of `0`'s in numsleft and the number of `1`'s in numsright.
+
+Return _**all distinct indices** that have the **highest** possible **division score**_. You may return the answer in **any order**.
+
+**Example 1:**
+
+**Input:** nums = [0,0,1,0]
+
+**Output:** [2,4]
+
+**Explanation:** Division at index 
+- 0: numsleft is []. numsright is [0,0,**1**,0]. The score is 0 + 1 = 1. 
+
+- 1: numsleft is [**0**]. numsright is [0,**1**,0]. The score is 1 + 1 = 2. 
+
+- 2: numsleft is [**0**,**0**]. numsright is [**1**,0]. The score is 2 + 1 = 3. 
+
+- 3: numsleft is [**0**,**0**,1]. numsright is [0]. The score is 2 + 0 = 2. 
+
+- 4: numsleft is [**0**,**0**,1,**0**]. numsright is []. The score is 3 + 0 = 3. 
+
+Indices 2 and 4 both have the highest possible division score 3. 
+
+Note the answer [4,2] would also be accepted.
+
+**Example 2:**
+
+**Input:** nums = [0,0,0]
+
+**Output:** [3]
+
+**Explanation:** Division at index 
+- 0: numsleft is []. numsright is [0,0,0]. The score is 0 + 0 = 0. 
+
+- 1: numsleft is [**0**]. numsright is [0,0]. The score is 1 + 0 = 1. 
+
+- 2: numsleft is [**0**,**0**]. numsright is [0]. The score is 2 + 0 = 2. 
+
+- 3: numsleft is [**0**,**0**,**0**]. numsright is []. The score is 3 + 0 = 3. 
+
+Only index 3 has the highest possible division score 3. 
+
+**Example 3:**
+
+**Input:** nums = [1,1]
+
+**Output:** [0]
+
+**Explanation:** Division at index 
+- 0: numsleft is []. numsright is [**1**,**1**]. The score is 0 + 2 = 2. 
+
+- 1: numsleft is [1]. numsright is [**1**]. The score is 0 + 1 = 1. 
+
+- 2: numsleft is [1,1]. numsright is []. The score is 0 + 0 = 0. 
+
+Only index 0 has the highest possible division score 2. 
+
+**Constraints:**
+
+*   `n == nums.length`
+*   1 <= n <= 105
+*   `nums[i]` is either `0` or `1`.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun maxScoreIndices(nums: IntArray): List {
+        var curone = 0
+        var curzero = 0
+        var max = 0
+        for (i in nums) {
+            curone += i
+        }
+        val list: MutableList = ArrayList()
+        for (i in nums.indices) {
+            if (curzero + curone > max) {
+                list.clear()
+                list.add(i)
+                max = curzero + curone
+            } else if (curzero + curone == max) {
+                list.add(i)
+            }
+            if (nums[i] == 1) {
+                curone--
+            } else {
+                curzero++
+            }
+        }
+        if (curzero > max) {
+            list.clear()
+            list.add(nums.size)
+        } else if (curzero == max) {
+            list.add(nums.size)
+        }
+        return list
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2156_find_substring_with_given_hash_value/readme.md b/src/main/kotlin/g2101_2200/s2156_find_substring_with_given_hash_value/readme.md
new file mode 100644
index 00000000..abff4872
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2156_find_substring_with_given_hash_value/readme.md
@@ -0,0 +1,75 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2156\. Find Substring With Given Hash Value
+
+Hard
+
+The hash of a **0-indexed** string `s` of length `k`, given integers `p` and `m`, is computed using the following function:
+
+*   hash(s, p, m) = (val(s[0]) * p0 + val(s[1]) * p1 + ... + val(s[k-1]) * pk-1) mod m.
+
+Where `val(s[i])` represents the index of `s[i]` in the alphabet from `val('a') = 1` to `val('z') = 26`.
+
+You are given a string `s` and the integers `power`, `modulo`, `k`, and `hashValue.` Return `sub`, _the **first** **substring** of_ `s` _of length_ `k` _such that_ `hash(sub, power, modulo) == hashValue`.
+
+The test cases will be generated such that an answer always **exists**.
+
+A **substring** is a contiguous non-empty sequence of characters within a string.
+
+**Example 1:**
+
+**Input:** s = "leetcode", power = 7, modulo = 20, k = 2, hashValue = 0
+
+**Output:** "ee"
+
+**Explanation:** The hash of "ee" can be computed to be hash("ee", 7, 20) = (5 \* 1 + 5 \* 7) mod 20 = 40 mod 20 = 0. "ee" is the first substring of length 2 with hashValue 0. Hence, we return "ee".
+
+**Example 2:**
+
+**Input:** s = "fbxzaad", power = 31, modulo = 100, k = 3, hashValue = 32
+
+**Output:** "fbx"
+
+**Explanation:** The hash of "fbx" can be computed to be hash("fbx", 31, 100) = (6 \* 1 + 2 \* 31 + 24 \* 312) mod 100 = 23132 mod 100 = 32. 
+
+The hash of "bxz" can be computed to be hash("bxz", 31, 100) = (2 \* 1 + 24 \* 31 + 26 \* 312) mod 100 = 25732 mod 100 = 32. "fbx" is the first substring of length 3 with hashValue 32. Hence, we return "fbx". 
+
+Note that "bxz" also has a hash of 32 but it appears later than "fbx".
+
+**Constraints:**
+
+*   1 <= k <= s.length <= 2 * 104
+*   1 <= power, modulo <= 109
+*   `0 <= hashValue < modulo`
+*   `s` consists of lowercase English letters only.
+*   The test cases are generated such that an answer always **exists**.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun subStrHash(s: String, power: Int, modulo: Int, k: Int, hashValue: Int): String {
+        var mul1: Long = 1
+        var times = k - 1
+        while (times-- > 0) {
+            mul1 = mul1 * power % modulo
+        }
+        var index = -1
+        var hash: Long = 0
+        var end = s.length - 1
+        for (i in s.length - 1 downTo 0) {
+            val `val` = s[i].code - 96
+            hash = (hash * power % modulo + `val`) % modulo
+            if (end - i + 1 == k) {
+                if (hash == hashValue.toLong()) {
+                    index = i
+                }
+                hash = (hash - (s[end].code - 96) * mul1 % modulo + modulo) % modulo
+                end--
+            }
+        }
+        return s.substring(index, index + k)
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2157_groups_of_strings/readme.md b/src/main/kotlin/g2101_2200/s2157_groups_of_strings/readme.md
new file mode 100644
index 00000000..f2e4ede8
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2157_groups_of_strings/readme.md
@@ -0,0 +1,122 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2157\. Groups of Strings
+
+Hard
+
+You are given a **0-indexed** array of strings `words`. Each string consists of **lowercase English letters** only. No letter occurs more than once in any string of `words`.
+
+Two strings `s1` and `s2` are said to be **connected** if the set of letters of `s2` can be obtained from the set of letters of `s1` by any **one** of the following operations:
+
+*   Adding exactly one letter to the set of the letters of `s1`.
+*   Deleting exactly one letter from the set of the letters of `s1`.
+*   Replacing exactly one letter from the set of the letters of `s1` with any letter, **including** itself.
+
+The array `words` can be divided into one or more non-intersecting **groups**. A string belongs to a group if any **one** of the following is true:
+
+*   It is connected to **at least one** other string of the group.
+*   It is the **only** string present in the group.
+
+Note that the strings in `words` should be grouped in such a manner that a string belonging to a group cannot be connected to a string present in any other group. It can be proved that such an arrangement is always unique.
+
+Return _an array_ `ans` _of size_ `2` _where:_
+
+*   `ans[0]` _is the **maximum number** of groups_ `words` _can be divided into, and_
+*   `ans[1]` _is the **size of the largest** group_.
+
+**Example 1:**
+
+**Input:** words = ["a","b","ab","cde"]
+
+**Output:** [2,3]
+
+**Explanation:** 
+
+- words[0] can be used to obtain words[1] (by replacing 'a' with 'b'), and words[2] (by adding 'b'). So words[0] is connected to words[1] and words[2]. 
+
+- words[1] can be used to obtain words[0] (by replacing 'b' with 'a'), and words[2] (by adding 'a'). So words[1] is connected to words[0] and words[2]. 
+
+- words[2] can be used to obtain words[0] (by deleting 'b'), and words[1] (by deleting 'a'). So words[2] is connected to words[0] and words[1]. 
+
+- words[3] is not connected to any string in words. 
+  
+Thus, words can be divided into 2 groups ["a","b","ab"] and ["cde"]. The size of the largest group is 3.
+
+**Example 2:**
+
+**Input:** words = ["a","ab","abc"]
+
+**Output:** [1,3]
+
+**Explanation:** 
+
+- words[0] is connected to words[1]. 
+
+- words[1] is connected to words[0] and words[2].
+
+- words[2] is connected to words[1]. 
+  
+Since all strings are connected to each other, they should be grouped together. 
+
+Thus, the size of the largest group is 3.
+
+**Constraints:**
+
+*   1 <= words.length <= 2 * 104
+*   `1 <= words[i].length <= 26`
+*   `words[i]` consists of lowercase English letters only.
+*   No letter occurs more than once in `words[i]`.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun groupStrings(words: Array): IntArray {
+        val map = HashMap()
+        for (word in words) {
+            var bitmask = 0
+            for (ch in word.toCharArray()) {
+                bitmask = bitmask or (1 shl ch.code - 'a'.code)
+            }
+            map[bitmask] = map.getOrDefault(bitmask, 0) + 1
+        }
+        val keyset: MutableList = ArrayList()
+        for (key in map.keys) {
+            keyset.add(key)
+        }
+        var totalGroups = 0
+        var maxSize = 0
+        for (key in keyset) {
+            if (!map.containsKey(key)) {
+                continue
+            }
+            totalGroups++
+            val size = dfs(key, map)
+            maxSize = Math.max(size, maxSize)
+        }
+        return intArrayOf(totalGroups, maxSize)
+    }
+
+    private fun dfs(key: Int, map: HashMap): Int {
+        if (!map.containsKey(key)) {
+            return 0
+        }
+        var size = map[key]!!
+        map.remove(key)
+        for (i in 0..25) {
+            size += dfs(key xor (1 shl i), map)
+        }
+        for (i in 0..25) {
+            if (key and (1 shl i) > 0) {
+                for (j in 0..25) {
+                    if (key and (1 shl j) == 0) {
+                        size += dfs(key xor (1 shl i) xor (1 shl j), map)
+                    }
+                }
+            }
+        }
+        return size
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2160_minimum_sum_of_four_digit_number_after_splitting_digits/readme.md b/src/main/kotlin/g2101_2200/s2160_minimum_sum_of_four_digit_number_after_splitting_digits/readme.md
new file mode 100644
index 00000000..51ab17c1
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2160_minimum_sum_of_four_digit_number_after_splitting_digits/readme.md
@@ -0,0 +1,57 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2160\. Minimum Sum of Four Digit Number After Splitting Digits
+
+Easy
+
+You are given a **positive** integer `num` consisting of exactly four digits. Split `num` into two new integers `new1` and `new2` by using the **digits** found in `num`. **Leading zeros** are allowed in `new1` and `new2`, and **all** the digits found in `num` must be used.
+
+*   For example, given `num = 2932`, you have the following digits: two `2`'s, one `9` and one `3`. Some of the possible pairs `[new1, new2]` are `[22, 93]`, `[23, 92]`, `[223, 9]` and `[2, 329]`.
+
+Return _the **minimum** possible sum of_ `new1` _and_ `new2`.
+
+**Example 1:**
+
+**Input:** num = 2932
+
+**Output:** 52
+
+**Explanation:** Some possible pairs [new1, new2] are [29, 23], [223, 9], etc. 
+
+The minimum sum can be obtained by the pair [29, 23]: 29 + 23 = 52. 
+
+**Example 2:**
+
+**Input:** num = 4009
+
+**Output:** 13
+
+**Explanation:** Some possible pairs [new1, new2] are [0, 49], [490, 0], etc. 
+
+The minimum sum can be obtained by the pair [4, 9]: 4 + 9 = 13. 
+
+**Constraints:**
+
+*   `1000 <= num <= 9999`
+
+## Solution
+
+```kotlin
+@Suppress("NAME_SHADOWING")
+class Solution {
+    fun minimumSum(num: Int): Int {
+        var num = num
+        val digit = IntArray(4)
+        var cur = 0
+        while (num > 0) {
+            digit[cur++] = num % 10
+            num /= 10
+        }
+        digit.sort()
+        val num1 = digit[0] * 10 + digit[2]
+        val num2 = digit[1] * 10 + digit[3]
+        return num1 + num2
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2161_partition_array_according_to_given_pivot/readme.md b/src/main/kotlin/g2101_2200/s2161_partition_array_according_to_given_pivot/readme.md
new file mode 100644
index 00000000..7ffdc261
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2161_partition_array_according_to_given_pivot/readme.md
@@ -0,0 +1,81 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2161\. Partition Array According to Given Pivot
+
+Medium
+
+You are given a **0-indexed** integer array `nums` and an integer `pivot`. Rearrange `nums` such that the following conditions are satisfied:
+
+*   Every element less than `pivot` appears **before** every element greater than `pivot`.
+*   Every element equal to `pivot` appears **in between** the elements less than and greater than `pivot`.
+*   The **relative order** of the elements less than `pivot` and the elements greater than `pivot` is maintained.
+    *   More formally, consider every pi, pj where pi is the new position of the ith element and pj is the new position of the jth element. For elements less than `pivot`, if `i < j` and `nums[i] < pivot` and `nums[j] < pivot`, then pi < pj. Similarly for elements greater than `pivot`, if `i < j` and `nums[i] > pivot` and `nums[j] > pivot`, then pi < pj.
+
+Return `nums` _after the rearrangement._
+
+**Example 1:**
+
+**Input:** nums = [9,12,5,10,14,3,10], pivot = 10
+
+**Output:** [9,5,3,10,10,12,14]
+
+**Explanation:** The elements 9, 5, and 3 are less than the pivot so they are on the left side of the array. 
+
+The elements 12 and 14 are greater than the pivot so they are on the right side of the array. 
+
+The relative ordering of the elements less than and greater than pivot is also maintained. 
+
+[9, 5, 3] and [12, 14] are the respective orderings. 
+
+**Example 2:**
+
+**Input:** nums = [-3,4,3,2], pivot = 2
+
+**Output:** [-3,2,4,3]
+
+**Explanation:** The element -3 is less than the pivot so it is on the left side of the array. 
+
+elements 4 and 3 are greater than the pivot so they are on the right side of the array. 
+
+The relative ordering of the elements less than and greater than pivot is also maintained. 
+
+[-3] and [4, 3] are the respective orderings. 
+
+**Constraints:**
+
+*   1 <= nums.length <= 105
+*   -106 <= nums[i] <= 106
+*   `pivot` equals to an element of `nums`.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun pivotArray(nums: IntArray, pivot: Int): IntArray {
+        val ans = IntArray(nums.size)
+        var point = 0
+        var equal = 0
+        for (i in nums) {
+            if (i < pivot) {
+                ans[point] = i
+                ++point
+            } else if (i == pivot) {
+                ++equal
+            }
+        }
+        while (equal > 0) {
+            ans[point] = pivot
+            ++point
+            --equal
+        }
+        for (i in nums) {
+            if (i > pivot) {
+                ans[point] = i
+                ++point
+            }
+        }
+        return ans
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2162_minimum_cost_to_set_cooking_time/readme.md b/src/main/kotlin/g2101_2200/s2162_minimum_cost_to_set_cooking_time/readme.md
new file mode 100644
index 00000000..4c97afcb
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2162_minimum_cost_to_set_cooking_time/readme.md
@@ -0,0 +1,109 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2162\. Minimum Cost to Set Cooking Time
+
+Medium
+
+A generic microwave supports cooking times for:
+
+*   at least `1` second.
+*   at most `99` minutes and `99` seconds.
+
+To set the cooking time, you push **at most four digits**. The microwave normalizes what you push as four digits by **prepending zeroes**. It interprets the **first** two digits as the minutes and the **last** two digits as the seconds. It then **adds** them up as the cooking time. For example,
+
+*   You push `9` `5` `4` (three digits). It is normalized as `0954` and interpreted as `9` minutes and `54` seconds.
+*   You push `0` `0` `0` `8` (four digits). It is interpreted as `0` minutes and `8` seconds.
+*   You push `8` `0` `9` `0`. It is interpreted as `80` minutes and `90` seconds.
+*   You push `8` `1` `3` `0`. It is interpreted as `81` minutes and `30` seconds.
+
+You are given integers `startAt`, `moveCost`, `pushCost`, and `targetSeconds`. **Initially**, your finger is on the digit `startAt`. Moving the finger above **any specific digit** costs `moveCost` units of fatigue. Pushing the digit below the finger **once** costs `pushCost` units of fatigue.
+
+There can be multiple ways to set the microwave to cook for `targetSeconds` seconds but you are interested in the way with the minimum cost.
+
+Return _the **minimum cost** to set_ `targetSeconds` _seconds of cooking time_.
+
+Remember that one minute consists of `60` seconds.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2021/12/30/1.png)
+
+**Input:** startAt = 1, moveCost = 2, pushCost = 1, targetSeconds = 600
+
+**Output:** 6
+
+**Explanation:** The following are the possible ways to set the cooking time. 
+
+- 1 0 0 0, interpreted as 10 minutes and 0 seconds. 
+
+The finger is already on digit 1, pushes 1 (with cost 1), moves to 0 (with cost 2), pushes 0 (with cost 1), pushes 0 (with cost 1), and pushes 0 (with cost 1). 
+
+The cost is: 1 + 2 + 1 + 1 + 1 = 6. This is the minimum cost. 
+
+- 0 9 6 0, interpreted as 9 minutes and 60 seconds. That is also 600 seconds. 
+
+The finger moves to 0 (with cost 2), pushes 0 (with cost 1), moves to 9 (with cost 2), pushes 9 (with cost 1), moves to 6 (with cost 2), pushes 6 (with cost 1), moves to 0 (with cost 2), and pushes 0 (with cost 1). 
+
+The cost is: 2 + 1 + 2 + 1 + 2 + 1 + 2 + 1 = 12. 
+
+- 9 6 0, normalized as 0960 and interpreted as 9 minutes and 60 seconds. 
+
+The finger moves to 9 (with cost 2), pushes 9 (with cost 1), moves to 6 (with cost 2), pushes 6 (with cost 1), moves to 0 (with cost 2), and pushes 0 (with cost 1). 
+
+The cost is: 2 + 1 + 2 + 1 + 2 + 1 = 9. 
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2021/12/30/2.png)
+
+**Input:** startAt = 0, moveCost = 1, pushCost = 2, targetSeconds = 76
+
+**Output:** 6
+
+**Explanation:** The optimal way is to push two digits: 7 6, interpreted as 76 seconds. 
+
+The finger moves to 7 (with cost 1), pushes 7 (with cost 2), moves to 6 (with cost 1), and pushes 6 (with cost 2). 
+
+The total cost is: 1 + 2 + 1 + 2 = 6 
+
+Note other possible ways are 0076, 076, 0116, and 116, but none of them produces the minimum cost. 
+
+**Constraints:**
+
+*   `0 <= startAt <= 9`
+*   1 <= moveCost, pushCost <= 105
+*   `1 <= targetSeconds <= 6039`
+
+## Solution
+
+```kotlin
+class Solution {
+    fun minCostSetTime(startAt: Int, moveCost: Int, pushCost: Int, targetSeconds: Int): Int {
+        val mins = targetSeconds / 60
+        val secs = targetSeconds % 60
+        return Math.min(
+            cost(mins, secs, startAt, moveCost, pushCost),
+            cost(mins - 1, secs + 60, startAt, moveCost, pushCost)
+        )
+    }
+
+    private fun cost(mins: Int, secs: Int, startAt: Int, moveCost: Int, pushCost: Int): Int {
+        if (mins > 99 || secs > 99 || mins < 0 || secs < 0) {
+            return Int.MAX_VALUE
+        }
+        val s = Integer.toString(mins * 100 + secs)
+        var curr = (startAt + '0'.code).toChar()
+        var res = 0
+        for (i in 0 until s.length) {
+            if (s[i] == curr) {
+                res += pushCost
+            } else {
+                res += pushCost + moveCost
+                curr = s[i]
+            }
+        }
+        return res
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2163_minimum_difference_in_sums_after_removal_of_elements/readme.md b/src/main/kotlin/g2101_2200/s2163_minimum_difference_in_sums_after_removal_of_elements/readme.md
new file mode 100644
index 00000000..3e1b9b05
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2163_minimum_difference_in_sums_after_removal_of_elements/readme.md
@@ -0,0 +1,104 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2163\. Minimum Difference in Sums After Removal of Elements
+
+Hard
+
+You are given a **0-indexed** integer array `nums` consisting of `3 * n` elements.
+
+You are allowed to remove any **subsequence** of elements of size **exactly** `n` from `nums`. The remaining `2 * n` elements will be divided into two **equal** parts:
+
+*   The first `n` elements belonging to the first part and their sum is sumfirst.
+*   The next `n` elements belonging to the second part and their sum is sumsecond.
+
+The **difference in sums** of the two parts is denoted as sumfirst - sumsecond.
+
+*   For example, if sumfirst = 3 and sumsecond = 2, their difference is `1`.
+*   Similarly, if sumfirst = 2 and sumsecond = 3, their difference is `-1`.
+
+Return _the **minimum difference** possible between the sums of the two parts after the removal of_ `n` _elements_.
+
+**Example 1:**
+
+**Input:** nums = [3,1,2]
+
+**Output:** -1
+
+**Explanation:** Here, nums has 3 elements, so n = 1.
+
+Thus we have to remove 1 element from nums and divide the array into two equal parts.
+
+- If we remove nums[0] = 3, the array will be [1,2]. The difference in sums of the two parts will be 1 - 2 = -1.
+
+- If we remove nums[1] = 1, the array will be [3,2]. The difference in sums of the two parts will be 3 - 2 = 1.
+
+- If we remove nums[2] = 2, the array will be [3,1]. The difference in sums of the two parts will be 3 - 1 = 2.
+
+The minimum difference between sums of the two parts is min(-1,1,2) = -1. 
+
+**Example 2:**
+
+**Input:** nums = [7,9,5,8,1,3]
+
+**Output:** 1
+
+**Explanation:** Here n = 2. So we must remove 2 elements and divide the remaining array into two parts containing two elements each.
+
+If we remove nums[2] = 5 and nums[3] = 8, the resultant array will be [7,9,1,3]. The difference in sums will be (7+9) - (1+3) = 12.
+
+To obtain the minimum difference, we should remove nums[1] = 9 and nums[4] = 1. The resultant array becomes [7,5,8,3]. The difference in sums of the two parts is (7+5) - (8+3) = 1.
+
+It can be shown that it is not possible to obtain a difference smaller than 1. 
+
+**Constraints:**
+
+*   `nums.length == 3 * n`
+*   1 <= n <= 105
+*   1 <= nums[i] <= 105
+
+## Solution
+
+```kotlin
+import java.util.PriorityQueue
+
+class Solution {
+    fun minimumDifference(nums: IntArray): Long {
+        val n = nums.size / 3
+        val minHeap = PriorityQueue()
+        val maxHeap = PriorityQueue { a: Int, b: Int -> b - a }
+        val leftMemo = LongArray(nums.size)
+        val rightMemo = LongArray(nums.size)
+        var current = 0L
+        for (i in 0..2 * n - 1) {
+            current += nums[i].toLong()
+            maxHeap.add(nums[i])
+            if (maxHeap.size > n) {
+                val removed = maxHeap.poll()
+                current -= removed.toLong()
+                leftMemo[i] = current
+            }
+            if (maxHeap.size == n) {
+                leftMemo[i] = current
+            }
+        }
+        current = 0
+        for (i in nums.size - 1 downTo n) {
+            current += nums[i].toLong()
+            minHeap.add(nums[i])
+            if (minHeap.size > n) {
+                val removed = minHeap.poll()
+                current -= removed.toLong()
+            }
+            if (minHeap.size == n) {
+                rightMemo[i] = current
+            }
+        }
+        var min = Long.MAX_VALUE
+        for (i in n - 1..2 * n - 1) {
+            min = Math.min(min, leftMemo[i] - rightMemo[i + 1])
+        }
+        return min
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2164_sort_even_and_odd_indices_independently/readme.md b/src/main/kotlin/g2101_2200/s2164_sort_even_and_odd_indices_independently/readme.md
new file mode 100644
index 00000000..07df313c
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2164_sort_even_and_odd_indices_independently/readme.md
@@ -0,0 +1,82 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2164\. Sort Even and Odd Indices Independently
+
+Easy
+
+You are given a **0-indexed** integer array `nums`. Rearrange the values of `nums` according to the following rules:
+
+1.  Sort the values at **odd indices** of `nums` in **non-increasing** order.
+    *   For example, if nums = [4,**1**,2,**3**] before this step, it becomes [4,**3**,2,**1**] after. The values at odd indices `1` and `3` are sorted in non-increasing order.
+2.  Sort the values at **even indices** of `nums` in **non-decreasing** order.
+    *   For example, if nums = [**4**,1,**2**,3] before this step, it becomes [**2**,1,**4**,3] after. The values at even indices `0` and `2` are sorted in non-decreasing order.
+
+Return _the array formed after rearranging the values of_ `nums`.
+
+**Example 1:**
+
+**Input:** nums = [4,1,2,3]
+
+**Output:** [2,3,4,1]
+
+**Explanation:** 
+
+First, we sort the values present at odd indices (1 and 3) in non-increasing order. 
+
+So, nums changes from [4,**1**,2,**3**] to [4,**3**,2,**1**]. 
+
+Next, we sort the values present at even indices (0 and 2) in non-decreasing order. So, nums changes from [**4**,1,**2**,3] to [**2**,3,**4**,1]. 
+
+Thus, the array formed after rearranging the values is [2,3,4,1]. 
+
+**Example 2:**
+
+**Input:** nums = [2,1]
+
+**Output:** [2,1]
+
+**Explanation:** Since there is exactly one odd index and one even index, no rearrangement of values takes place. 
+
+The resultant array formed is [2,1], which is the same as the initial array. 
+
+**Constraints:**
+
+*   `1 <= nums.length <= 100`
+*   `1 <= nums[i] <= 100`
+
+## Solution
+
+```kotlin
+class Solution {
+    fun sortEvenOdd(nums: IntArray): IntArray {
+        val odd = IntArray(nums.size / 2)
+        val even = IntArray((nums.size + 1) / 2)
+        var o = 0
+        var e = 0
+        for (i in nums.indices) {
+            if (i % 2 == 0) {
+                even[e] = nums[i]
+                ++e
+            } else {
+                odd[o] = nums[i]
+                ++o
+            }
+        }
+        odd.sort()
+        even.sort()
+        e = 0
+        o = odd.size - 1
+        for (i in nums.indices) {
+            if (i % 2 == 0) {
+                nums[i] = even[e]
+                ++e
+            } else {
+                nums[i] = odd[o]
+                --o
+            }
+        }
+        return nums
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2165_smallest_value_of_the_rearranged_number/readme.md b/src/main/kotlin/g2101_2200/s2165_smallest_value_of_the_rearranged_number/readme.md
new file mode 100644
index 00000000..52756138
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2165_smallest_value_of_the_rearranged_number/readme.md
@@ -0,0 +1,79 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2165\. Smallest Value of the Rearranged Number
+
+Medium
+
+You are given an integer `num.` **Rearrange** the digits of `num` such that its value is **minimized** and it does not contain **any** leading zeros.
+
+Return _the rearranged number with minimal value_.
+
+Note that the sign of the number does not change after rearranging the digits.
+
+**Example 1:**
+
+**Input:** num = 310
+
+**Output:** 103
+
+**Explanation:** The possible arrangements for the digits of 310 are 013, 031, 103, 130, 301, 310. 
+
+The arrangement with the smallest value that does not contain any leading zeros is 103. 
+
+**Example 2:**
+
+**Input:** num = -7605
+
+**Output:** -7650
+
+**Explanation:** Some possible arrangements for the digits of -7605 are -7650, -6705, -5076, -0567. 
+
+The arrangement with the smallest value that does not contain any leading zeros is -7650. 
+
+**Constraints:**
+
+*   -1015 <= num <= 1015
+
+## Solution
+
+```kotlin
+class Solution {
+    fun smallestNumber(num: Long): Long {
+        val count = IntArray(10)
+        var tempNum: Long
+        tempNum = if (num > 0) {
+            num
+        } else {
+            num * -1
+        }
+        var min = 10
+        while (tempNum > 0) {
+            val rem = (tempNum % 10).toInt()
+            if (rem != 0) {
+                min = Math.min(min, rem)
+            }
+            count[rem]++
+            tempNum = tempNum / 10
+        }
+        var output: Long = 0
+        if (num > 0) {
+            output = output * 10 + min
+            count[min]--
+            for (i in 0..9) {
+                for (j in 0 until count[i]) {
+                    output = output * 10 + i
+                }
+            }
+        } else {
+            for (i in 9 downTo 0) {
+                for (j in 0 until count[i]) {
+                    output = output * 10 + i
+                }
+            }
+            output = output * -1
+        }
+        return output
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2166_design_bitset/readme.md b/src/main/kotlin/g2101_2200/s2166_design_bitset/readme.md
new file mode 100644
index 00000000..366cdabc
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2166_design_bitset/readme.md
@@ -0,0 +1,121 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2166\. Design Bitset
+
+Medium
+
+A **Bitset** is a data structure that compactly stores bits.
+
+Implement the `Bitset` class:
+
+*   `Bitset(int size)` Initializes the Bitset with `size` bits, all of which are `0`.
+*   `void fix(int idx)` Updates the value of the bit at the index `idx` to `1`. If the value was already `1`, no change occurs.
+*   `void unfix(int idx)` Updates the value of the bit at the index `idx` to `0`. If the value was already `0`, no change occurs.
+*   `void flip()` Flips the values of each bit in the Bitset. In other words, all bits with value `0` will now have value `1` and vice versa.
+*   `boolean all()` Checks if the value of **each** bit in the Bitset is `1`. Returns `true` if it satisfies the condition, `false` otherwise.
+*   `boolean one()` Checks if there is **at least one** bit in the Bitset with value `1`. Returns `true` if it satisfies the condition, `false` otherwise.
+*   `int count()` Returns the **total number** of bits in the Bitset which have value `1`.
+*   `String toString()` Returns the current composition of the Bitset. Note that in the resultant string, the character at the ith index should coincide with the value at the ith bit of the Bitset.
+
+**Example 1:**
+
+**Input**
+
+["Bitset", "fix", "fix", "flip", "all", "unfix", "flip", "one", "unfix", "count", "toString"]
+
+[[5], [3], [1], [], [], [0], [], [], [0], [], []]
+
+**Output:** [null, null, null, null, false, null, null, true, null, 2, "01010"]
+
+**Explanation:**
+
+    Bitset bs = new Bitset(5); // bitset = "00000".
+    bs.fix(3); // the value at idx = 3 is updated to 1, so bitset = "00010".
+    bs.fix(1); // the value at idx = 1 is updated to 1, so bitset = "01010".
+    bs.flip(); // the value of each bit is flipped, so bitset = "10101".
+    bs.all(); // return False, as not all values of the bitset are 1.
+    bs.unfix(0); // the value at idx = 0 is updated to 0, so bitset = "00101".
+    bs.flip(); // the value of each bit is flipped, so bitset = "11010".
+    bs.one(); // return True, as there is at least 1 index with value 1.
+    bs.unfix(0); // the value at idx = 0 is updated to 0, so bitset = "01010".
+    bs.count(); // return 2, as there are 2 bits with value 1.
+    bs.toString(); // return "01010", which is the composition of bitset. 
+
+**Constraints:**
+
+*   1 <= size <= 105
+*   `0 <= idx <= size - 1`
+*   At most 105 calls will be made **in total** to `fix`, `unfix`, `flip`, `all`, `one`, `count`, and `toString`.
+*   At least one call will be made to `all`, `one`, `count`, or `toString`.
+*   At most `5` calls will be made to `toString`.
+
+## Solution
+
+```kotlin
+class Bitset(private val sz: Int) {
+    private var bits: BooleanArray
+    private var flipped: BooleanArray
+    private var cnt = 0
+
+    init {
+        bits = BooleanArray(sz)
+        flipped = BooleanArray(sz)
+        flipped.fill(true)
+    }
+
+    fun fix(idx: Int) {
+        if (!bits[idx]) {
+            bits[idx] = bits[idx] xor true
+            flipped[idx] = flipped[idx] xor true
+            cnt += 1
+        }
+    }
+
+    fun unfix(idx: Int) {
+        if (bits[idx]) {
+            bits[idx] = bits[idx] xor true
+            flipped[idx] = flipped[idx] xor true
+            cnt -= 1
+        }
+    }
+
+    fun flip() {
+        val tmp = bits
+        bits = flipped
+        flipped = tmp
+        cnt = sz - cnt
+    }
+
+    fun all(): Boolean {
+        return cnt == sz
+    }
+
+    fun one(): Boolean {
+        return cnt > 0
+    }
+
+    fun count(): Int {
+        return cnt
+    }
+
+    override fun toString(): String {
+        val sb = StringBuilder()
+        for (b in bits) {
+            sb.append(if (b) '1' else '0')
+        }
+        return sb.toString()
+    }
+}
+/*
+ * Your Bitset object will be instantiated and called as such:
+ * var obj = Bitset(size)
+ * obj.fix(idx)
+ * obj.unfix(idx)
+ * obj.flip()
+ * var param_4 = obj.all()
+ * var param_5 = obj.one()
+ * var param_6 = obj.count()
+ * var param_7 = obj.toString()
+ */
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2167_minimum_time_to_remove_all_cars_containing_illegal_goods/readme.md b/src/main/kotlin/g2101_2200/s2167_minimum_time_to_remove_all_cars_containing_illegal_goods/readme.md
new file mode 100644
index 00000000..595765e8
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2167_minimum_time_to_remove_all_cars_containing_illegal_goods/readme.md
@@ -0,0 +1,95 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2167\. Minimum Time to Remove All Cars Containing Illegal Goods
+
+Hard
+
+You are given a **0-indexed** binary string `s` which represents a sequence of train cars. `s[i] = '0'` denotes that the ith car does **not** contain illegal goods and `s[i] = '1'` denotes that the ith car does contain illegal goods.
+
+As the train conductor, you would like to get rid of all the cars containing illegal goods. You can do any of the following three operations **any** number of times:
+
+1.  Remove a train car from the **left** end (i.e., remove `s[0]`) which takes 1 unit of time.
+2.  Remove a train car from the **right** end (i.e., remove `s[s.length - 1]`) which takes 1 unit of time.
+3.  Remove a train car from **anywhere** in the sequence which takes 2 units of time.
+
+Return _the **minimum** time to remove all the cars containing illegal goods_.
+
+Note that an empty sequence of cars is considered to have no cars containing illegal goods.
+
+**Example 1:**
+
+**Input:** s = "**11**00**1**0**1**"
+
+**Output:** 5
+
+**Explanation:** 
+
+One way to remove all the cars containing illegal goods from the sequence is to 
+
+- remove a car from the left end 2 times. Time taken is 2 \* 1 = 2. 
+
+- remove a car from the right end. Time taken is 1. 
+
+- remove the car containing illegal goods found in the middle. Time taken is 2. This obtains a total time of 2 + 1 + 2 = 5. An alternative way is to 
+
+- remove a car from the left end 2 times. Time taken is 2 \* 1 = 2. 
+
+- remove a car from the right end 3 times. Time taken is 3 \* 1 = 3. This also obtains a total time of 2 + 3 = 5. 
+  
+5 is the minimum time taken to remove all the cars containing illegal goods. There are no other ways to remove them with less time.
+
+**Example 2:**
+
+**Input:** s = "00**1**0"
+
+**Output:** 2
+
+**Explanation:** One way to remove all the cars containing illegal goods from the sequence is to 
+
+- remove a car from the left end 3 times. Time taken is 3 \* 1 = 3. 
+  
+This obtains a total time of 3.
+
+Another way to remove all the cars containing illegal goods from the sequence is to 
+
+- remove the car containing illegal goods found in the middle. Time taken is 2. This obtains a total time of 2. 
+  
+Another way to remove all the cars containing illegal goods from the sequence is to 
+
+- remove a car from the right end 2 times. Time taken is 2 \* 1 = 2. 
+  
+This obtains a total time of 2. 
+
+2 is the minimum time taken to remove all the cars containing illegal goods. 
+
+There are no other ways to remove them with less time.
+
+**Constraints:**
+
+*   1 <= s.length <= 2 * 105
+*   `s[i]` is either `'0'` or `'1'`.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun minimumTime(s: String): Int {
+        val n = s.length
+        val sum = IntArray(n + 1)
+        for (i in 0 until n) {
+            sum[i + 1] = sum[i] + (s[i].code - '0'.code)
+        }
+        if (sum[n] == 0) {
+            return 0
+        }
+        var res = s.length
+        var min = Int.MAX_VALUE
+        for (end in 0 until n) {
+            min = Math.min(min, end - 2 * sum[end] + n - 1)
+            res = Math.min(res, min + 2 * sum[end + 1] - end)
+        }
+        return res
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2169_count_operations_to_obtain_zero/readme.md b/src/main/kotlin/g2101_2200/s2169_count_operations_to_obtain_zero/readme.md
new file mode 100644
index 00000000..813decba
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2169_count_operations_to_obtain_zero/readme.md
@@ -0,0 +1,73 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2169\. Count Operations to Obtain Zero
+
+Easy
+
+You are given two **non-negative** integers `num1` and `num2`.
+
+In one **operation**, if `num1 >= num2`, you must subtract `num2` from `num1`, otherwise subtract `num1` from `num2`.
+
+*   For example, if `num1 = 5` and `num2 = 4`, subtract `num2` from `num1`, thus obtaining `num1 = 1` and `num2 = 4`. However, if `num1 = 4` and `num2 = 5`, after one operation, `num1 = 4` and `num2 = 1`.
+
+Return _the **number of operations** required to make either_ `num1 = 0` _or_ `num2 = 0`.
+
+**Example 1:**
+
+**Input:** num1 = 2, num2 = 3
+
+**Output:** 3
+
+**Explanation:** 
+
+- Operation 1: num1 = 2, num2 = 3. Since num1 < num2, we subtract num1 from num2 and get num1 = 2, num2 = 3 - 2 = 1. 
+
+- Operation 2: num1 = 2, num2 = 1. Since num1 > num2, we subtract num2 from num1. 
+
+- Operation 3: num1 = 1, num2 = 1. Since num1 == num2, we subtract num2 from num1. 
+
+Now num1 = 0 and num2 = 1. Since num1 == 0, we do not need to perform any further operations. 
+
+So the total number of operations required is 3. 
+
+**Example 2:**
+
+**Input:** num1 = 10, num2 = 10
+
+**Output:** 1
+
+**Explanation:** 
+
+- Operation 1: num1 = 10, num2 = 10. Since num1 == num2, we subtract num2 from num1 and get num1 = 10 - 10 = 0. 
+
+Now num1 = 0 and num2 = 10. Since num1 == 0, we are done. 
+
+So the total number of operations required is 1. 
+
+**Constraints:**
+
+*   0 <= num1, num2 <= 105
+
+## Solution
+
+```kotlin
+@Suppress("NAME_SHADOWING")
+class Solution {
+    fun countOperations(num1: Int, num2: Int): Int {
+        var num1 = num1
+        var num2 = num2
+        var ans = 0
+        while (num1 * num2 != 0) {
+            if (num1 >= num2) {
+                ans += num1 / num2
+                num1 = num1 % num2
+            } else {
+                ans += num2 / num1
+                num2 = num2 % num1
+            }
+        }
+        return ans
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2170_minimum_operations_to_make_the_array_alternating/readme.md b/src/main/kotlin/g2101_2200/s2170_minimum_operations_to_make_the_array_alternating/readme.md
new file mode 100644
index 00000000..63625837
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2170_minimum_operations_to_make_the_array_alternating/readme.md
@@ -0,0 +1,107 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2170\. Minimum Operations to Make the Array Alternating
+
+Medium
+
+You are given a **0-indexed** array `nums` consisting of `n` positive integers.
+
+The array `nums` is called **alternating** if:
+
+*   `nums[i - 2] == nums[i]`, where `2 <= i <= n - 1`.
+*   `nums[i - 1] != nums[i]`, where `1 <= i <= n - 1`.
+
+In one **operation**, you can choose an index `i` and **change** `nums[i]` into **any** positive integer.
+
+Return _the **minimum number of operations** required to make the array alternating_.
+
+**Example 1:**
+
+**Input:** nums = [3,1,3,2,4,3]
+
+**Output:** 3
+
+**Explanation:**
+
+One way to make the array alternating is by converting it to [3,1,3,**1**,**3**,**1**].
+
+The number of operations required in this case is 3.
+
+It can be proven that it is not possible to make the array alternating in less than 3 operations. 
+
+**Example 2:**
+
+**Input:** nums = [1,2,2,2,2]
+
+**Output:** 2
+
+**Explanation:**
+
+One way to make the array alternating is by converting it to [1,2,**1**,2,**1**].
+
+The number of operations required in this case is 2.
+
+Note that the array cannot be converted to [**2**,2,2,2,2] because in this case nums[0] == nums[1] which violates the conditions of an alternating array. 
+
+**Constraints:**
+
+*   1 <= nums.length <= 105
+*   1 <= nums[i] <= 105
+
+## Solution
+
+```kotlin
+class Solution {
+    fun minimumOperations(nums: IntArray): Int {
+        var maxOdd = 0
+        var maxEven = 0
+        var max = 0
+        val n = nums.size
+        for (num in nums) {
+            max = Math.max(max, num)
+        }
+        val even = IntArray(max + 1)
+        val odd = IntArray(max + 1)
+        for (i in 0 until n) {
+            if (i % 2 == 0) {
+                even[nums[i]]++
+            } else {
+                odd[nums[i]]++
+            }
+        }
+        var t1 = 0
+        var t2 = 0
+        for (i in 0 until max + 1) {
+            if (even[i] > maxEven) {
+                maxEven = even[i]
+                t1 = i
+            }
+            if (odd[i] > maxOdd) {
+                maxOdd = odd[i]
+                t2 = i
+            }
+        }
+        val ans: Int
+        if (t1 == t2) {
+            var secondEven = 0
+            var secondOdd = 0
+            for (i in 0 until max + 1) {
+                if (i != t1 && even[i] > secondEven) {
+                    secondEven = even[i]
+                }
+                if (i != t2 && odd[i] > secondOdd) {
+                    secondOdd = odd[i]
+                }
+            }
+            ans = Math.min(
+                n / 2 + n % 2 - maxEven + (n / 2 - secondOdd),
+                n / 2 + n % 2 - secondEven + (n / 2 - maxOdd)
+            )
+        } else {
+            ans = n / 2 + n % 2 - maxEven + n / 2 - maxOdd
+        }
+        return ans
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2171_removing_minimum_number_of_magic_beans/readme.md b/src/main/kotlin/g2101_2200/s2171_removing_minimum_number_of_magic_beans/readme.md
new file mode 100644
index 00000000..40138925
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2171_removing_minimum_number_of_magic_beans/readme.md
@@ -0,0 +1,93 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2171\. Removing Minimum Number of Magic Beans
+
+Medium
+
+You are given an array of **positive** integers `beans`, where each integer represents the number of magic beans found in a particular magic bag.
+
+**Remove** any number of beans (**possibly none**) from each bag such that the number of beans in each remaining **non-empty** bag (still containing **at least one** bean) is **equal**. Once a bean has been removed from a bag, you are **not** allowed to return it to any of the bags.
+
+Return _the **minimum** number of magic beans that you have to remove_.
+
+**Example 1:**
+
+**Input:** beans = [4,**1**,6,5]
+
+**Output:** 4
+
+**Explanation:**
+
+- We remove 1 bean from the bag with only 1 bean.
+
+  This results in the remaining bags: [4,**0**,6,5]
+  
+- Then we remove 2 beans from the bag with 6 beans.
+
+  This results in the remaining bags: [4,0,**4**,5]
+
+- Then we remove 1 bean from the bag with 5 beans.
+
+  This results in the remaining bags: [4,0,4,**4**]
+  
+We removed a total of 1 + 2 + 1 = 4 beans to make the remaining non-empty bags have an equal number of beans.
+
+There are no other solutions that remove 4 beans or fewer. 
+
+**Example 2:**
+
+**Input:** beans = [**2**,10,**3**,**2**]
+
+**Output:** 7
+
+**Explanation:**
+
+- We remove 2 beans from one of the bags with 2 beans.
+
+  This results in the remaining bags: [**0**,10,3,2]
+  
+- Then we remove 2 beans from the other bag with 2 beans.
+
+  This results in the remaining bags: [0,10,3,**0**]
+  
+- Then we remove 3 beans from the bag with 3 beans.
+
+  This results in the remaining bags: [0,10,**0**,0]
+  
+We removed a total of 2 + 2 + 3 = 7 beans to make the remaining non-empty bags have an equal number of beans.
+
+There are no other solutions that removes 7 beans or fewer. 
+
+**Constraints:**
+
+*   1 <= beans.length <= 105
+*   1 <= beans[i] <= 105
+
+## Solution
+
+```kotlin
+class Solution {
+    fun minimumRemoval(beans: IntArray): Long {
+        beans.sort()
+        val n = beans.size
+        var sum: Long = 0
+        for (bean in beans) {
+            sum += bean.toLong()
+        }
+        var minbeans = Long.MAX_VALUE
+        var prefix: Long = 0
+        var suffix: Long
+        var count: Long
+        for (i in 0 until n) {
+            prefix += beans[i].toLong()
+            suffix = sum - prefix
+            count = prefix - beans[i] + (suffix - beans[i] * (n - i - 1L))
+            if (count < minbeans) {
+                minbeans = count
+            }
+        }
+        return minbeans
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2172_maximum_and_sum_of_array/readme.md b/src/main/kotlin/g2101_2200/s2172_maximum_and_sum_of_array/readme.md
new file mode 100644
index 00000000..26b3e4bd
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2172_maximum_and_sum_of_array/readme.md
@@ -0,0 +1,77 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2172\. Maximum AND Sum of Array
+
+Hard
+
+You are given an integer array `nums` of length `n` and an integer `numSlots` such that `2 * numSlots >= n`. There are `numSlots` slots numbered from `1` to `numSlots`.
+
+You have to place all `n` integers into the slots such that each slot contains at **most** two numbers. The **AND sum** of a given placement is the sum of the **bitwise** `AND` of every number with its respective slot number.
+
+*   For example, the **AND sum** of placing the numbers `[1, 3]` into slot `1` and `[4, 6]` into slot `2` is equal to `(1 AND 1) + (3 AND 1) + (4 AND 2) + (6 AND 2) = 1 + 1 + 0 + 2 = 4`.
+
+Return _the maximum possible **AND sum** of_ `nums` _given_ `numSlots` _slots._
+
+**Example 1:**
+
+**Input:** nums = [1,2,3,4,5,6], numSlots = 3
+
+**Output:** 9
+
+**Explanation:** One possible placement is [1, 4] into slot 1, [2, 6] into slot 2, and [3, 5] into slot 3.
+
+This gives the maximum AND sum of (1 AND 1) + (4 AND 1) + (2 AND 2) + (6 AND 2) + (3 AND 3) + (5 AND 3) = 1 + 0 + 2 + 2 + 3 + 1 = 9.
+
+**Example 2:**
+
+**Input:** nums = [1,3,10,4,7,1], numSlots = 9
+
+**Output:** 24
+
+**Explanation:** One possible placement is [1, 1] into slot 1, [3] into slot 3, [4] into slot 4, [7] into slot 7, and [10] into slot 9.
+
+This gives the maximum AND sum of (1 AND 1) + (1 AND 1) + (3 AND 3) + (4 AND 4) + (7 AND 7) + (10 AND 9) = 1 + 1 + 3 + 4 + 7 + 8 = 24.
+
+Note that slots 2, 5, 6, and 8 are empty which is permitted.
+
+**Constraints:**
+
+*   `n == nums.length`
+*   `1 <= numSlots <= 9`
+*   `1 <= n <= 2 * numSlots`
+*   `1 <= nums[i] <= 15`
+
+## Solution
+
+```kotlin
+class Solution {
+    fun maximumANDSum(nums: IntArray, numSlots: Int): Int {
+        val mask = Math.pow(3.0, numSlots.toDouble()).toInt() - 1
+        val memo = IntArray(mask + 1)
+        return dp(nums.size - 1, mask, numSlots, memo, nums)
+    }
+
+    private fun dp(i: Int, mask: Int, numSlots: Int, memo: IntArray, ints: IntArray): Int {
+        if (memo[mask] > 0) {
+            return memo[mask]
+        }
+        if (i < 0) {
+            return 0
+        }
+        var slot = 1
+        var bit = 1
+        while (slot <= numSlots) {
+            if (mask / bit % 3 > 0) {
+                memo[mask] = Math.max(
+                    memo[mask],
+                    (ints[i] and slot) + dp(i - 1, mask - bit, numSlots, memo, ints)
+                )
+            }
+            ++slot
+            bit *= 3
+        }
+        return memo[mask]
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2176_count_equal_and_divisible_pairs_in_an_array/readme.md b/src/main/kotlin/g2101_2200/s2176_count_equal_and_divisible_pairs_in_an_array/readme.md
new file mode 100644
index 00000000..618b4fd0
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2176_count_equal_and_divisible_pairs_in_an_array/readme.md
@@ -0,0 +1,55 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2176\. Count Equal and Divisible Pairs in an Array
+
+Easy
+
+Given a **0-indexed** integer array `nums` of length `n` and an integer `k`, return _the **number of pairs**_ `(i, j)` _where_ `0 <= i < j < n`, _such that_ `nums[i] == nums[j]` _and_ `(i * j)` _is divisible by_ `k`.
+
+**Example 1:**
+
+**Input:** nums = [3,1,2,2,2,1,3], k = 2
+
+**Output:** 4
+
+**Explanation:** There are 4 pairs that meet all the requirements: 
+
+- nums[0] == nums[6], and 0 \* 6 == 0, which is divisible by 2. 
+
+- nums[2] == nums[3], and 2 \* 3 == 6, which is divisible by 2. 
+
+- nums[2] == nums[4], and 2 \* 4 == 8, which is divisible by 2. 
+
+- nums[3] == nums[4], and 3 \* 4 == 12, which is divisible by 2. 
+
+**Example 2:**
+
+**Input:** nums = [1,2,3,4], k = 1
+
+**Output:** 0
+
+**Explanation:** Since no value in nums is repeated, there are no pairs (i,j) that meet all the requirements. 
+
+**Constraints:**
+
+*   `1 <= nums.length <= 100`
+*   `1 <= nums[i], k <= 100`
+
+## Solution
+
+```kotlin
+class Solution {
+    fun countPairs(nums: IntArray, k: Int): Int {
+        var ans = 0
+        for (i in nums.indices) {
+            for (j in i + 1 until nums.size) {
+                if (nums[i] == nums[j] && i * j % k == 0) {
+                    ++ans
+                }
+            }
+        }
+        return ans
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2177_find_three_consecutive_integers_that_sum_to_a_given_number/readme.md b/src/main/kotlin/g2101_2200/s2177_find_three_consecutive_integers_that_sum_to_a_given_number/readme.md
new file mode 100644
index 00000000..e105b610
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2177_find_three_consecutive_integers_that_sum_to_a_given_number/readme.md
@@ -0,0 +1,42 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2177\. Find Three Consecutive Integers That Sum to a Given Number
+
+Medium
+
+Given an integer `num`, return _three consecutive integers (as a sorted array)_ _that **sum** to_ `num`. If `num` cannot be expressed as the sum of three consecutive integers, return _an **empty** array._
+
+**Example 1:**
+
+**Input:** num = 33
+
+**Output:** [10,11,12]
+
+**Explanation:** 33 can be expressed as 10 + 11 + 12 = 33. 
+
+10, 11, 12 are 3 consecutive integers, so we return [10, 11, 12]. 
+
+**Example 2:**
+
+**Input:** num = 4
+
+**Output:** []
+
+**Explanation:** There is no way to express 4 as the sum of 3 consecutive integers. 
+
+**Constraints:**
+
+*   0 <= num <= 1015
+
+## Solution
+
+```kotlin
+class Solution {
+    fun sumOfThree(num: Long): LongArray {
+        return if (num % 3 == 0L) {
+            longArrayOf(num / 3 - 1, num / 3, num / 3 + 1)
+        } else LongArray(0)
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2178_maximum_split_of_positive_even_integers/readme.md b/src/main/kotlin/g2101_2200/s2178_maximum_split_of_positive_even_integers/readme.md
new file mode 100644
index 00000000..3c95ce99
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2178_maximum_split_of_positive_even_integers/readme.md
@@ -0,0 +1,81 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2178\. Maximum Split of Positive Even Integers
+
+Medium
+
+You are given an integer `finalSum`. Split it into a sum of a **maximum** number of **unique** positive even integers.
+
+*   For example, given `finalSum = 12`, the following splits are **valid** (unique positive even integers summing up to `finalSum`): `(12)`, `(2 + 10)`, `(2 + 4 + 6)`, and `(4 + 8)`. Among them, `(2 + 4 + 6)` contains the maximum number of integers. Note that `finalSum` cannot be split into `(2 + 2 + 4 + 4)` as all the numbers should be unique.
+
+Return _a list of integers that represent a valid split containing a **maximum** number of integers_. If no valid split exists for `finalSum`, return _an **empty** list_. You may return the integers in **any** order.
+
+**Example 1:**
+
+**Input:** finalSum = 12
+
+**Output:** [2,4,6]
+
+**Explanation:** The following are valid splits: `(12)`, `(2 + 10)`, `(2 + 4 + 6)`, and `(4 + 8)`.
+
+(2 + 4 + 6) has the maximum number of integers, which is 3. Thus, we return [2,4,6].
+
+Note that [2,6,4], [6,2,4], etc. are also accepted. 
+
+**Example 2:**
+
+**Input:** finalSum = 7
+
+**Output:** []
+
+**Explanation:** There are no valid splits for the given finalSum. Thus, we return an empty array. 
+
+**Example 3:**
+
+**Input:** finalSum = 28
+
+**Output:** [6,8,2,12]
+
+**Explanation:** The following are valid splits: `(2 + 26)`, `(6 + 8 + 2 + 12)`, and `(4 + 24)`.
+
+`(6 + 8 + 2 + 12)` has the maximum number of integers, which is 4. Thus, we return [6,8,2,12].
+
+Note that [10,2,4,12], [6,2,4,16], etc. are also accepted. 
+
+**Constraints:**
+
+*   1 <= finalSum <= 1010
+
+## Solution
+
+```kotlin
+class Solution {
+    fun maximumEvenSplit(finalSum: Long): List {
+        var curr: Long = 2
+        var remainingSum = finalSum
+        val result: MutableList = ArrayList()
+        if (finalSum % 2 != 0L) {
+            return result
+        }
+        while (remainingSum >= curr) {
+            result.add(curr)
+            remainingSum -= curr
+            curr += 2
+        }
+        /*
+        go greedily by starting from smallest even number
+        for target = 16 after the while loop
+        remainingSum = 4
+        curr = 8 (if we add 8 it exceeds the target 16)
+        result = [2,4,6]
+        so remove 6 from list and add it to remainigSum and insert to list
+        result = [2,4,10]
+        */
+        val lastSum = result[result.size - 1]
+        result.removeAt(result.size - 1)
+        result.add(lastSum + remainingSum)
+        return result
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2179_count_good_triplets_in_an_array/readme.md b/src/main/kotlin/g2101_2200/s2179_count_good_triplets_in_an_array/readme.md
new file mode 100644
index 00000000..e3521730
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2179_count_good_triplets_in_an_array/readme.md
@@ -0,0 +1,99 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2179\. Count Good Triplets in an Array
+
+Hard
+
+You are given two **0-indexed** arrays `nums1` and `nums2` of length `n`, both of which are **permutations** of `[0, 1, ..., n - 1]`.
+
+A **good triplet** is a set of `3` **distinct** values which are present in **increasing order** by position both in `nums1` and `nums2`. In other words, if we consider pos1v as the index of the value `v` in `nums1` and pos2v as the index of the value `v` in `nums2`, then a good triplet will be a set `(x, y, z)` where `0 <= x, y, z <= n - 1`, such that pos1x < pos1y < pos1z and pos2x < pos2y < pos2z.
+
+Return _the **total number** of good triplets_.
+
+**Example 1:**
+
+**Input:** nums1 = [2,0,1,3], nums2 = [0,1,2,3]
+
+**Output:** 1
+
+**Explanation:**
+
+There are 4 triplets (x,y,z) such that pos1x < pos1y < pos1z. They are (2,0,1), (2,0,3), (2,1,3), and (0,1,3).
+
+Out of those triplets, only the triplet (0,1,3) satisfies pos2x < pos2y < pos2z.
+
+Hence, there is only 1 good triplet.
+
+**Example 2:**
+
+**Input:** nums1 = [4,0,1,3,2], nums2 = [4,1,0,2,3]
+
+**Output:** 4
+
+**Explanation:** The 4 good triplets are (4,0,3), (4,0,2), (4,1,3), and (4,1,2).
+
+**Constraints:**
+
+*   `n == nums1.length == nums2.length`
+*   3 <= n <= 105
+*   `0 <= nums1[i], nums2[i] <= n - 1`
+*   `nums1` and `nums2` are permutations of `[0, 1, ..., n - 1]`.
+
+## Solution
+
+```kotlin
+@Suppress("NAME_SHADOWING")
+class Solution {
+    fun goodTriplets(nums1: IntArray, nums2: IntArray): Long {
+        val n = nums1.size
+        val idx = IntArray(n)
+        val arr = IntArray(n)
+        for (i in 0 until n) {
+            idx[nums2[i]] = i
+        }
+        for (i in 0 until n) {
+            arr[i] = idx[nums1[i]]
+        }
+        val tree = Tree(n)
+        var res = 0L
+        for (i in 0 until n) {
+            val smaller = tree.query(arr[i])
+            val bigger = n - (arr[i] + 1) - (i - smaller)
+            res += smaller.toLong() * bigger
+            tree.update(arr[i] + 1, 1)
+        }
+        return res
+    }
+
+    private class Tree(var n: Int) {
+        var array: IntArray
+
+        init {
+            array = IntArray(n + 1)
+        }
+
+        fun lowbit(x: Int): Int {
+            return x and -x
+        }
+
+        fun update(i: Int, delta: Int) {
+            var i = i
+            while (i <= n) {
+                array[i] += delta
+                i += lowbit(i)
+            }
+        }
+
+        fun query(k: Int): Int {
+            var k = k
+            var ans = 0
+            while (k > 0) {
+                ans += array[k]
+                k -= lowbit(k)
+            }
+            return ans
+        }
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2180_count_integers_with_even_digit_sum/readme.md b/src/main/kotlin/g2101_2200/s2180_count_integers_with_even_digit_sum/readme.md
new file mode 100644
index 00000000..d1811d67
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2180_count_integers_with_even_digit_sum/readme.md
@@ -0,0 +1,50 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2180\. Count Integers With Even Digit Sum
+
+Easy
+
+Given a positive integer `num`, return _the number of positive integers **less than or equal to**_ `num` _whose digit sums are **even**_.
+
+The **digit sum** of a positive integer is the sum of all its digits.
+
+**Example 1:**
+
+**Input:** num = 4
+
+**Output:** 2
+
+**Explanation:** 
+
+The only integers less than or equal to 4 whose digit sums are even are 2 and 4.
+
+**Example 2:**
+
+**Input:** num = 30
+
+**Output:** 14
+
+**Explanation:** 
+
+The 14 integers less than or equal to 30 whose digit sums are even are 
+
+2, 4, 6, 8, 11, 13, 15, 17, 19, 20, 22, 24, 26, and 28.
+
+**Constraints:**
+
+* `1 <= num <= 1000`
+
+## Solution
+
+```kotlin
+class Solution {
+    fun countEven(num: Int): Int {
+        // Digit sum of the last number, we can get each digit this way sicne the range is [1, 1000]
+        val sum = num % 10 + num / 10 % 10 + num / 100 % 10 + num / 1000 % 10
+
+        // Check the parity of the digit sum of the last number
+        return (num - (sum and 1)) / 2
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2181_merge_nodes_in_between_zeros/readme.md b/src/main/kotlin/g2101_2200/s2181_merge_nodes_in_between_zeros/readme.md
new file mode 100644
index 00000000..db34cbf9
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2181_merge_nodes_in_between_zeros/readme.md
@@ -0,0 +1,91 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2181\. Merge Nodes in Between Zeros
+
+Medium
+
+You are given the `head` of a linked list, which contains a series of integers **separated** by `0`'s. The **beginning** and **end** of the linked list will have `Node.val == 0`.
+
+For **every** two consecutive `0`'s, **merge** all the nodes lying in between them into a single node whose value is the **sum** of all the merged nodes. The modified list should not contain any `0`'s.
+
+Return _the_ `head` _of the modified linked list_.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/02/02/ex1-1.png)
+
+**Input:** head = [0,3,1,0,4,5,2,0]
+
+**Output:** [4,11]
+
+**Explanation:**
+
+The above figure represents the given linked list. The modified list contains
+
+- The sum of the nodes marked in green: 3 + 1 = 4.
+
+- The sum of the nodes marked in red: 4 + 5 + 2 = 11. 
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2022/02/02/ex2-1.png)
+
+**Input:** head = [0,1,0,3,0,2,2,0]
+
+**Output:** [1,3,4]
+
+**Explanation:**
+
+The above figure represents the given linked list. The modified list contains
+
+- The sum of the nodes marked in green: 1 = 1.
+
+- The sum of the nodes marked in red: 3 = 3.
+
+- The sum of the nodes marked in yellow: 2 + 2 = 4. 
+
+**Constraints:**
+
+*   The number of nodes in the list is in the range [3, 2 * 105].
+*   `0 <= Node.val <= 1000`
+*   There are **no** two consecutive nodes with `Node.val == 0`.
+*   The **beginning** and **end** of the linked list have `Node.val == 0`.
+
+## Solution
+
+```kotlin
+import com_github_leetcode.ListNode
+
+/*
+ * Example:
+ * var li = ListNode(5)
+ * var v = li.`val`
+ * Definition for singly-linked list.
+ * class ListNode(var `val`: Int) {
+ *     var next: ListNode? = null
+ * }
+ */
+class Solution {
+    fun mergeNodes(head: ListNode): ListNode? {
+        var temp = head.next
+        var slow = head
+        var sum = 0
+        var fast = temp
+        while (temp != null) {
+            if (temp.`val` == 0) {
+                temp.`val` = sum
+                sum = 0
+                slow.next = fast!!.next
+                slow = temp
+                fast = fast.next
+            } else {
+                sum += temp.`val`
+                fast = temp
+            }
+            temp = temp.next
+        }
+        return head.next
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2182_construct_string_with_repeat_limit/readme.md b/src/main/kotlin/g2101_2200/s2182_construct_string_with_repeat_limit/readme.md
new file mode 100644
index 00000000..119f733d
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2182_construct_string_with_repeat_limit/readme.md
@@ -0,0 +1,97 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2182\. Construct String With Repeat Limit
+
+Medium
+
+You are given a string `s` and an integer `repeatLimit`. Construct a new string `repeatLimitedString` using the characters of `s` such that no letter appears **more than** `repeatLimit` times **in a row**. You do **not** have to use all characters from `s`.
+
+Return _the **lexicographically largest**_ `repeatLimitedString` _possible_.
+
+A string `a` is **lexicographically larger** than a string `b` if in the first position where `a` and `b` differ, string `a` has a letter that appears later in the alphabet than the corresponding letter in `b`. If the first `min(a.length, b.length)` characters do not differ, then the longer string is the lexicographically larger one.
+
+**Example 1:**
+
+**Input:** s = "cczazcc", repeatLimit = 3
+
+**Output:** "zzcccac"
+
+**Explanation:** We use all of the characters from s to construct the repeatLimitedString "zzcccac".
+
+The letter 'a' appears at most 1 time in a row.
+
+The letter 'c' appears at most 3 times in a row.
+
+The letter 'z' appears at most 2 times in a row.
+
+Hence, no letter appears more than repeatLimit times in a row and the string is a valid repeatLimitedString.
+
+The string is the lexicographically largest repeatLimitedString possible so we return "zzcccac".
+
+Note that the string "zzcccca" is lexicographically larger but the letter 'c' appears more than 3 times in a row, so it is not a valid repeatLimitedString. 
+
+**Example 2:**
+
+**Input:** s = "aababab", repeatLimit = 2
+
+**Output:** "bbabaa"
+
+**Explanation:** We use only some of the characters from s to construct the repeatLimitedString "bbabaa".
+
+The letter 'a' appears at most 2 times in a row. The letter 'b' appears at most 2 times in a row.
+
+Hence, no letter appears more than repeatLimit times in a row and the string is a valid repeatLimitedString.
+
+The string is the lexicographically largest repeatLimitedString possible so we return "bbabaa".
+
+Note that the string "bbabaaa" is lexicographically larger but the letter 'a' appears more than 2 times in a row, so it is not a valid repeatLimitedString. 
+
+**Constraints:**
+
+*   1 <= repeatLimit <= s.length <= 105
+*   `s` consists of lowercase English letters.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun repeatLimitedString(s: String, repeatLimit: Int): String {
+        val result = CharArray(s.length)
+        val freq = IntArray(128)
+        var index = 0
+        for (c in s.toCharArray()) {
+            freq[c.code]++
+        }
+        var max = 'z'
+        var second = 'y'
+        while (true) {
+            while (max >= 'a' && freq[max.code] == 0) {
+                max--
+            }
+            if (max < 'a') {
+                break
+            }
+            second = Math.min(max.code - 1, second.code).toChar()
+            var count = Math.min(freq[max.code], repeatLimit)
+            freq[max.code] -= count
+            while (count-- > 0) {
+                result[index++] = max
+            }
+            if (freq[max.code] == 0) {
+                max = second--
+                continue
+            }
+            while (second >= 'a' && freq[second.code] == 0) {
+                second--
+            }
+            if (second < 'a') {
+                break
+            }
+            result[index++] = second
+            freq[second.code]--
+        }
+        return String(result, 0, index)
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2183_count_array_pairs_divisible_by_k/readme.md b/src/main/kotlin/g2101_2200/s2183_count_array_pairs_divisible_by_k/readme.md
new file mode 100644
index 00000000..f98ab428
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2183_count_array_pairs_divisible_by_k/readme.md
@@ -0,0 +1,71 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2183\. Count Array Pairs Divisible by K
+
+Hard
+
+Given a **0-indexed** integer array `nums` of length `n` and an integer `k`, return _the **number of pairs**_ `(i, j)` _such that:_
+
+*   `0 <= i < j <= n - 1` _and_
+*   `nums[i] * nums[j]` _is divisible by_ `k`.
+
+**Example 1:**
+
+**Input:** nums = [1,2,3,4,5], k = 2
+
+**Output:** 7
+
+**Explanation:**
+
+The 7 pairs of indices whose corresponding products are divisible by 2 are
+
+(0, 1), (0, 3), (1, 2), (1, 3), (1, 4), (2, 3), and (3, 4).
+
+Their products are 2, 4, 6, 8, 10, 12, and 20 respectively.
+
+Other pairs such as (0, 2) and (2, 4) have products 3 and 15 respectively, which are not divisible by 2. 
+
+**Example 2:**
+
+**Input:** nums = [1,2,3,4], k = 5
+
+**Output:** 0
+
+**Explanation:** There does not exist any pair of indices whose corresponding product is divisible by 5. 
+
+**Constraints:**
+
+*   1 <= nums.length <= 105
+*   1 <= nums[i], k <= 105
+
+## Solution
+
+```kotlin
+class Solution {
+    fun countPairs(nums: IntArray, k: Int): Long {
+        var count = 0L
+        val map: MutableMap = HashMap()
+        for (num in nums) {
+            val gd = gcd(num, k)
+            val want = k / gd
+            for ((key, value) in map) {
+                if (key % want == 0) {
+                    count += value
+                }
+            }
+            map[gd] = map.getOrDefault(gd, 0L) + 1L
+        }
+        return count
+    }
+
+    private fun gcd(a: Int, b: Int): Int {
+        if (a > b) {
+            return gcd(b, a)
+        }
+        return if (a == 0) {
+            b
+        } else gcd(a, b % a)
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2185_counting_words_with_a_given_prefix/readme.md b/src/main/kotlin/g2101_2200/s2185_counting_words_with_a_given_prefix/readme.md
new file mode 100644
index 00000000..8db6f6d7
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2185_counting_words_with_a_given_prefix/readme.md
@@ -0,0 +1,50 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2185\. Counting Words With a Given Prefix
+
+Easy
+
+You are given an array of strings `words` and a string `pref`.
+
+Return _the number of strings in_ `words` _that contain_ `pref` _as a **prefix**_.
+
+A **prefix** of a string `s` is any leading contiguous substring of `s`.
+
+**Example 1:**
+
+**Input:** words = ["pay","**at**tention","practice","**at**tend"], `pref` \= "at"
+
+**Output:** 2
+
+**Explanation:** The 2 strings that contain "at" as a prefix are: "**at**tention" and "**at**tend". 
+
+**Example 2:**
+
+**Input:** words = ["leetcode","win","loops","success"], `pref` \= "code"
+
+**Output:** 0
+
+**Explanation:** There are no strings that contain "code" as a prefix. 
+
+**Constraints:**
+
+*   `1 <= words.length <= 100`
+*   `1 <= words[i].length, pref.length <= 100`
+*   `words[i]` and `pref` consist of lowercase English letters.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun prefixCount(words: Array, pref: String?): Int {
+        var count = 0
+        for (s in words) {
+            if (s.startsWith(pref!!)) {
+                count++
+            }
+        }
+        return count
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2186_minimum_number_of_steps_to_make_two_strings_anagram_ii/readme.md b/src/main/kotlin/g2101_2200/s2186_minimum_number_of_steps_to_make_two_strings_anagram_ii/readme.md
new file mode 100644
index 00000000..66e069bb
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2186_minimum_number_of_steps_to_make_two_strings_anagram_ii/readme.md
@@ -0,0 +1,64 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2186\. Minimum Number of Steps to Make Two Strings Anagram II
+
+Medium
+
+You are given two strings `s` and `t`. In one step, you can append **any character** to either `s` or `t`.
+
+Return _the minimum number of steps to make_ `s` _and_ `t` _**anagrams** of each other._
+
+An **anagram** of a string is a string that contains the same characters with a different (or the same) ordering.
+
+**Example 1:**
+
+**Input:** s = "**lee**tco**de**", t = "co**a**t**s**"
+
+**Output:** 7
+
+**Explanation:**
+
+- In 2 steps, we can append the letters in "as" onto s = "leetcode", forming s = "leetcode**as**".
+
+- In 5 steps, we can append the letters in "leede" onto t = "coats", forming t = "coats**leede**".
+
+"leetcodeas" and "coatsleede" are now anagrams of each other.
+
+We used a total of 2 + 5 = 7 steps.
+
+It can be shown that there is no way to make them anagrams of each other with less than 7 steps. 
+
+**Example 2:**
+
+**Input:** s = "night", t = "thing"
+
+**Output:** 0
+
+**Explanation:** The given strings are already anagrams of each other. Thus, we do not need any further steps. 
+
+**Constraints:**
+
+*   1 <= s.length, t.length <= 2 * 105
+*   `s` and `t` consist of lowercase English letters.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun minSteps(s: String, t: String): Int {
+        val a = IntArray(26)
+        for (i in 0 until s.length) {
+            a[s[i].code - 'a'.code]++
+        }
+        for (i in 0 until t.length) {
+            a[t[i].code - 'a'.code]--
+        }
+        var sum = 0
+        for (j in a) {
+            sum += Math.abs(j)
+        }
+        return sum
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2187_minimum_time_to_complete_trips/readme.md b/src/main/kotlin/g2101_2200/s2187_minimum_time_to_complete_trips/readme.md
new file mode 100644
index 00000000..b11f9902
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2187_minimum_time_to_complete_trips/readme.md
@@ -0,0 +1,83 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2187\. Minimum Time to Complete Trips
+
+Medium
+
+You are given an array `time` where `time[i]` denotes the time taken by the ith bus to complete **one trip**.
+
+Each bus can make multiple trips **successively**; that is, the next trip can start **immediately after** completing the current trip. Also, each bus operates **independently**; that is, the trips of one bus do not influence the trips of any other bus.
+
+You are also given an integer `totalTrips`, which denotes the number of trips all buses should make **in total**. Return _the **minimum time** required for all buses to complete **at least**_ `totalTrips` _trips_.
+
+**Example 1:**
+
+**Input:** time = [1,2,3], totalTrips = 5
+
+**Output:** 3
+
+**Explanation:**
+
+- At time t = 1, the number of trips completed by each bus are [1,0,0].
+
+The total number of trips completed is 1 + 0 + 0 = 1.
+
+- At time t = 2, the number of trips completed by each bus are [2,1,0].
+
+The total number of trips completed is 2 + 1 + 0 = 3.
+
+- At time t = 3, the number of trips completed by each bus are [3,1,1].
+
+The total number of trips completed is 3 + 1 + 1 = 5.
+
+So the minimum time needed for all buses to complete at least 5 trips is 3. 
+
+**Example 2:**
+
+**Input:** time = [2], totalTrips = 1
+
+**Output:** 2
+
+**Explanation:**
+
+There is only one bus, and it will complete its first trip at t = 2.
+
+So the minimum time needed to complete 1 trip is 2. 
+
+**Constraints:**
+
+*   1 <= time.length <= 105
+*   1 <= time[i], totalTrips <= 107
+
+## Solution
+
+```kotlin
+class Solution {
+    fun minimumTime(time: IntArray, totalTrips: Int): Long {
+        return bs(0, Long.MAX_VALUE, time, totalTrips.toLong())
+    }
+
+    private fun bs(left: Long, right: Long, time: IntArray, totalTrips: Long): Long {
+        if (left > right) {
+            return Long.MAX_VALUE
+        }
+        val mid = left + right shr 1
+        return if (isPossible(time, mid, totalTrips)) Math.min(
+            mid,
+            bs(left, mid - 1, time, totalTrips)
+        ) else bs(mid + 1, right, time, totalTrips)
+    }
+
+    private fun isPossible(time: IntArray, mid: Long, totalTrips: Long): Boolean {
+        var count: Long = 0
+        for (i in time) {
+            count += mid / i
+            if (count >= totalTrips) {
+                return true
+            }
+        }
+        return false
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2188_minimum_time_to_finish_the_race/readme.md b/src/main/kotlin/g2101_2200/s2188_minimum_time_to_finish_the_race/readme.md
new file mode 100644
index 00000000..25b44bad
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2188_minimum_time_to_finish_the_race/readme.md
@@ -0,0 +1,117 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2188\. Minimum Time to Finish the Race
+
+Hard
+
+You are given a **0-indexed** 2D integer array `tires` where tires[i] = [fi, ri] indicates that the ith tire can finish its xth successive lap in fi * ri(x-1) seconds.
+
+*   For example, if fi = 3 and ri = 2, then the tire would finish its 1st lap in `3` seconds, its 2nd lap in `3 * 2 = 6` seconds, its 3rd lap in 3 * 22 = 12 seconds, etc.
+
+You are also given an integer `changeTime` and an integer `numLaps`.
+
+The race consists of `numLaps` laps and you may start the race with **any** tire. You have an **unlimited** supply of each tire and after every lap, you may **change** to any given tire (including the current tire type) if you wait `changeTime` seconds.
+
+Return _the **minimum** time to finish the race._
+
+**Example 1:**
+
+**Input:** tires = \[\[2,3],[3,4]], changeTime = 5, numLaps = 4
+
+**Output:** 21
+
+**Explanation:**
+
+Lap 1: Start with tire 0 and finish the lap in 2 seconds.
+
+Lap 2: Continue with tire 0 and finish the lap in 2 \* 3 = 6 seconds.
+
+Lap 3: Change tires to a new tire 0 for 5 seconds and then finish the lap in another 2 seconds.
+
+Lap 4: Continue with tire 0 and finish the lap in 2 \* 3 = 6 seconds.
+
+Total time = 2 + 6 + 5 + 2 + 6 = 21 seconds.
+
+The minimum time to complete the race is 21 seconds. 
+
+**Example 2:**
+
+**Input:** tires = \[\[1,10],[2,2],[3,4]], changeTime = 6, numLaps = 5
+
+**Output:** 25
+
+**Explanation:**
+
+Lap 1: Start with tire 1 and finish the lap in 2 seconds.
+
+Lap 2: Continue with tire 1 and finish the lap in 2 \* 2 = 4 seconds.
+
+Lap 3: Change tires to a new tire 1 for 6 seconds and then finish the lap in another 2 seconds.
+
+Lap 4: Continue with tire 1 and finish the lap in 2 \* 2 = 4 seconds.
+
+Lap 5: Change tires to tire 0 for 6 seconds then finish the lap in another 1 second.
+
+Total time = 2 + 4 + 6 + 2 + 4 + 6 + 1 = 25 seconds.
+
+The minimum time to complete the race is 25 seconds. 
+
+**Constraints:**
+
+*   1 <= tires.length <= 105
+*   `tires[i].length == 2`
+*   1 <= fi, changeTime <= 105
+*   2 <= ri <= 105
+*   `1 <= numLaps <= 1000`
+
+## Solution
+
+```kotlin
+class Solution {
+    fun minimumFinishTime(tires: Array, changeTime: Int, numLaps: Int): Int {
+        var minf = Int.MAX_VALUE
+        // find the minimum of f, to deal with special case and stronger constraints later.
+        for (tire in tires) {
+            minf = Math.min(minf, tire[0])
+        }
+        // if min-f >= changeTime, we can return early
+        if (minf >= changeTime) {
+            return minf * numLaps + changeTime * (numLaps - 1)
+        }
+        // shortest[i] record shortest time that one single tire is worth to go the i-th laps
+        // worth to go means the i-th lap time is shorter than changeTime + f
+        val shortest = IntArray(numLaps + 1)
+        shortest.fill(Int.MAX_VALUE)
+        var len = 0
+        // traverse all tires, and update the shortest[i]
+        // this shortest time is available from [1, len] in the array
+        // len is updated in the traverse
+        for (tire in tires) {
+            val f = tire[0]
+            val r = tire[1]
+            // index start from 1 to be consistent with numLaps
+            var index = 1
+            var t = f
+            var sum = t
+            // use changeTime + minf here, which is a strong constraints than changeTime + f
+            while (t <= changeTime + minf && index <= numLaps) {
+                shortest[index] = Math.min(shortest[index], sum)
+                t = t * r
+                sum += t
+                index++
+            }
+            len = Math.max(len, index - 1)
+        }
+        for (i in 2..numLaps) {
+            // for j > Math.min(i/2, len), it's simply recombination of the values of shortest
+            // [1:len]
+            // it's ok to go furthur for the loop, just repeat the Math.min computation
+            for (j in 1..Math.min(i / 2, len)) {
+                shortest[i] = Math.min(shortest[i], shortest[j] + shortest[i - j] + changeTime)
+            }
+        }
+        return shortest[numLaps]
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2190_most_frequent_number_following_key_in_an_array/readme.md b/src/main/kotlin/g2101_2200/s2190_most_frequent_number_following_key_in_an_array/readme.md
new file mode 100644
index 00000000..1deafbf5
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2190_most_frequent_number_following_key_in_an_array/readme.md
@@ -0,0 +1,68 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2190\. Most Frequent Number Following Key In an Array
+
+Easy
+
+You are given a **0-indexed** integer array `nums`. You are also given an integer `key`, which is present in `nums`.
+
+For every unique integer `target` in `nums`, **count** the number of times `target` immediately follows an occurrence of `key` in `nums`. In other words, count the number of indices `i` such that:
+
+*   `0 <= i <= nums.length - 2`,
+*   `nums[i] == key` and,
+*   `nums[i + 1] == target`.
+
+Return _the_ `target` _with the **maximum** count_. The test cases will be generated such that the `target` with maximum count is unique.
+
+**Example 1:**
+
+**Input:** nums = [1,100,200,1,100], key = 1
+
+**Output:** 100
+
+**Explanation:** For target = 100, there are 2 occurrences at indices 1 and 4 which follow an occurrence of key.
+
+No other integers follow an occurrence of key, so we return 100. 
+
+**Example 2:**
+
+**Input:** nums = [2,2,2,2,3], key = 2
+
+**Output:** 2
+
+**Explanation:** For target = 2, there are 3 occurrences at indices 1, 2, and 3 which follow an occurrence of key.
+
+For target = 3, there is only one occurrence at index 4 which follows an occurrence of key.
+
+target = 2 has the maximum number of occurrences following an occurrence of key, so we return 2. 
+
+**Constraints:**
+
+*   `2 <= nums.length <= 1000`
+*   `1 <= nums[i] <= 1000`
+*   The test cases will be generated such that the answer is unique.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun mostFrequent(nums: IntArray, key: Int): Int {
+        val store = IntArray(1001)
+        for (i in 0 until nums.size - 1) {
+            if (nums[i] == key) {
+                store[nums[i + 1]]++
+            }
+        }
+        var res = 0
+        var count = store[0]
+        for (i in 1..1000) {
+            if (count < store[i]) {
+                count = store[i]
+                res = i
+            }
+        }
+        return res
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2191_sort_the_jumbled_numbers/readme.md b/src/main/kotlin/g2101_2200/s2191_sort_the_jumbled_numbers/readme.md
new file mode 100644
index 00000000..db1f75b8
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2191_sort_the_jumbled_numbers/readme.md
@@ -0,0 +1,110 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2191\. Sort the Jumbled Numbers
+
+Medium
+
+You are given a **0-indexed** integer array `mapping` which represents the mapping rule of a shuffled decimal system. `mapping[i] = j` means digit `i` should be mapped to digit `j` in this system.
+
+The **mapped value** of an integer is the new integer obtained by replacing each occurrence of digit `i` in the integer with `mapping[i]` for all `0 <= i <= 9`.
+
+You are also given another integer array `nums`. Return _the array_ `nums` _sorted in **non-decreasing** order based on the **mapped values** of its elements._
+
+**Notes:**
+
+*   Elements with the same mapped values should appear in the **same relative order** as in the input.
+*   The elements of `nums` should only be sorted based on their mapped values and **not be replaced** by them.
+
+**Example 1:**
+
+**Input:** mapping = [8,9,4,0,2,1,3,5,7,6], nums = [991,338,38]
+
+**Output:** [338,38,991]
+
+**Explanation:**
+
+Map the number 991 as follows:
+
+1. mapping[9] = 6, so all occurrences of the digit 9 will become 6.
+
+2. mapping[1] = 9, so all occurrences of the digit 1 will become 9.
+
+Therefore, the mapped value of 991 is 669.
+
+338 maps to 007, or 7 after removing the leading zeros.
+
+38 maps to 07, which is also 7 after removing leading zeros.
+
+Since 338 and 38 share the same mapped value, they should remain in the same relative order, so 338 comes before 38.
+
+Thus, the sorted array is [338,38,991]. 
+
+**Example 2:**
+
+**Input:** mapping = [0,1,2,3,4,5,6,7,8,9], nums = [789,456,123]
+
+**Output:** [123,456,789]
+
+**Explanation:** 789 maps to 789, 456 maps to 456, and 123 maps to 123. Thus, the sorted array is [123,456,789]. 
+
+**Constraints:**
+
+*   `mapping.length == 10`
+*   `0 <= mapping[i] <= 9`
+*   All the values of `mapping[i]` are **unique**.
+*   1 <= nums.length <= 3 * 104
+*   0 <= nums[i] < 109
+
+## Solution
+
+```kotlin
+import java.util.Collections
+
+class Solution {
+    @Suppress("NAME_SHADOWING")
+    private class RealNum(mapping: IntArray, orig: Int, index: Int) {
+        var index: Int
+        var orig: Int
+        var real = 0
+
+        init {
+            var orig = orig
+            this.orig = orig
+            this.index = index
+            var mult = 1
+            if (orig == 0) {
+                real = mapping[0]
+            } else {
+                while (orig > 0) {
+                    val mod = orig % 10
+                    orig = orig / 10
+                    real += mapping[mod] * mult
+                    mult *= 10
+                }
+            }
+        }
+    }
+
+    fun sortJumbled(mapping: IntArray, nums: IntArray): IntArray {
+        val realNums: MutableList = ArrayList()
+        for (i in nums.indices) {
+            val num = nums[i]
+            val realNum = RealNum(mapping, num, i)
+            realNums.add(realNum)
+        }
+        Collections.sort(realNums) { a: RealNum, b: RealNum ->
+            val retval = a.real - b.real
+            if (retval != 0) {
+                return@sort retval
+            }
+            a.index - b.index
+        }
+        val retval = IntArray(nums.size)
+        for (i in nums.indices) {
+            retval[i] = realNums[i].orig
+        }
+        return retval
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2192_all_ancestors_of_a_node_in_a_directed_acyclic_graph/readme.md b/src/main/kotlin/g2101_2200/s2192_all_ancestors_of_a_node_in_a_directed_acyclic_graph/readme.md
new file mode 100644
index 00000000..cc255430
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2192_all_ancestors_of_a_node_in_a_directed_acyclic_graph/readme.md
@@ -0,0 +1,122 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2192\. All Ancestors of a Node in a Directed Acyclic Graph
+
+Medium
+
+You are given a positive integer `n` representing the number of nodes of a **Directed Acyclic Graph** (DAG). The nodes are numbered from `0` to `n - 1` (**inclusive**).
+
+You are also given a 2D integer array `edges`, where edges[i] = [fromi, toi] denotes that there is a **unidirectional** edge from fromi to toi in the graph.
+
+Return _a list_ `answer`_, where_ `answer[i]` _is the **list of ancestors** of the_ ith _node, sorted in **ascending order**_.
+
+A node `u` is an **ancestor** of another node `v` if `u` can reach `v` via a set of edges.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2019/12/12/e1.png)
+
+**Input:** n = 8, edgeList = \[\[0,3],[0,4],[1,3],[2,4],[2,7],[3,5],[3,6],[3,7],[4,6]]
+
+**Output:** [[],[],[],[0,1],[0,2],[0,1,3],[0,1,2,3,4],[0,1,2,3]]
+
+**Explanation:**
+
+The above diagram represents the input graph.
+
+- Nodes 0, 1, and 2 do not have any ancestors.
+
+- Node 3 has two ancestors 0 and 1.
+
+- Node 4 has two ancestors 0 and 2.
+
+- Node 5 has three ancestors 0, 1, and 3.
+
+- Node 6 has five ancestors 0, 1, 2, 3, and 4.
+
+- Node 7 has four ancestors 0, 1, 2, and 3. 
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2019/12/12/e2.png)
+
+**Input:** n = 5, edgeList = \[\[0,1],[0,2],[0,3],[0,4],[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]
+
+**Output:** [[],[0],[0,1],[0,1,2],[0,1,2,3]]
+
+**Explanation:**
+
+The above diagram represents the input graph.
+
+- Node 0 does not have any ancestor.
+
+- Node 1 has one ancestor 0.
+
+- Node 2 has two ancestors 0 and 1.
+
+- Node 3 has three ancestors 0, 1, and 2.
+
+- Node 4 has four ancestors 0, 1, 2, and 3. 
+
+**Constraints:**
+
+*   `1 <= n <= 1000`
+*   `0 <= edges.length <= min(2000, n * (n - 1) / 2)`
+*   `edges[i].length == 2`
+*   0 <= fromi, toi <= n - 1
+*   fromi != toi
+*   There are no duplicate edges.
+*   The graph is **directed** and **acyclic**.
+
+## Solution
+
+```kotlin
+class Solution {
+    private lateinit var adjList: MutableList>
+    private lateinit var result: MutableList>
+
+    fun getAncestors(n: Int, edges: Array): List> {
+        adjList = ArrayList()
+        result = ArrayList()
+        for (i in 0 until n) {
+            adjList.add(ArrayList())
+            result.add(ArrayList())
+        }
+        for (edge in edges) {
+            val start = edge[0]
+            val end = edge[1]
+            adjList[start].add(end)
+        }
+        //  DFS for each node from 0 --> n , and add that node as root/parent into each reachable
+        // node and their child
+        //  Use visited[] to identify if any of the child or their childs are already visited for
+        // that perticular root/parent,
+        //  so will not add the root to avoid duplicacy and call reduction .
+        for (i in 0 until n) {
+            val visited = BooleanArray(n)
+            val childList: List = adjList[i]
+            for (child in childList) {
+                if (!visited[child]) {
+                    dfs(i, child, visited)
+                }
+            }
+        }
+        return result
+    }
+
+    private fun dfs(root: Int, node: Int, visited: BooleanArray) {
+        if (visited[node]) {
+            return
+        }
+        visited[node] = true
+        result[node].add(root)
+        val childList: List = adjList[node]
+        for (child in childList) {
+            if (!visited[child]) {
+                dfs(root, child, visited)
+            }
+        }
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2193_minimum_number_of_moves_to_make_palindrome/readme.md b/src/main/kotlin/g2101_2200/s2193_minimum_number_of_moves_to_make_palindrome/readme.md
new file mode 100644
index 00000000..018b024f
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2193_minimum_number_of_moves_to_make_palindrome/readme.md
@@ -0,0 +1,91 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2193\. Minimum Number of Moves to Make Palindrome
+
+Hard
+
+You are given a string `s` consisting only of lowercase English letters.
+
+In one **move**, you can select any two **adjacent** characters of `s` and swap them.
+
+Return _the **minimum number of moves** needed to make_ `s` _a palindrome_.
+
+**Note** that the input will be generated such that `s` can always be converted to a palindrome.
+
+**Example 1:**
+
+**Input:** s = "aabb"
+
+**Output:** 2
+
+**Explanation:**
+
+We can obtain two palindromes from s, "abba" and "baab".
+
+- We can obtain "abba" from s in 2 moves: "a**ab**b" -> "ab**ab**" -> "abba".
+
+- We can obtain "baab" from s in 2 moves: "a**ab**b" -> "**ab**ab" -> "baab".
+
+Thus, the minimum number of moves needed to make s a palindrome is 2. 
+
+**Example 2:**
+
+**Input:** s = "letelt"
+
+**Output:** 2
+
+**Explanation:**
+
+One of the palindromes we can obtain from s in 2 moves is "lettel".
+
+One of the ways we can obtain it is "lete**lt**" -> "let**et**l" -> "lettel".
+
+Other palindromes such as "tleelt" can also be obtained in 2 moves.
+
+It can be shown that it is not possible to obtain a palindrome in less than 2 moves. 
+
+**Constraints:**
+
+*   `1 <= s.length <= 2000`
+*   `s` consists only of lowercase English letters.
+*   `s` can be converted to a palindrome using a finite number of moves.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun minMovesToMakePalindrome(s: String): Int {
+        var l = 0
+        var r = s.length - 1
+        val charArray = s.toCharArray()
+        var output = 0
+        while (l < r) {
+            if (charArray[l] != charArray[r]) {
+                val prev = charArray[l]
+                var k = r
+                while (charArray[k] != prev) {
+                    k--
+                }
+                // middle element
+                if (k == l) {
+                    val temp = charArray[l]
+                    charArray[l] = charArray[l + 1]
+                    charArray[l + 1] = temp
+                    output++
+                    continue
+                }
+                for (i in k until r) {
+                    val temp = charArray[i]
+                    charArray[i] = charArray[i + 1]
+                    charArray[i + 1] = temp
+                    output++
+                }
+            }
+            l++
+            r--
+        }
+        return output
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2194_cells_in_a_range_on_an_excel_sheet/readme.md b/src/main/kotlin/g2101_2200/s2194_cells_in_a_range_on_an_excel_sheet/readme.md
new file mode 100644
index 00000000..9acf7381
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2194_cells_in_a_range_on_an_excel_sheet/readme.md
@@ -0,0 +1,72 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2194\. Cells in a Range on an Excel Sheet
+
+Easy
+
+A cell `(r, c)` of an excel sheet is represented as a string `""` where:
+
+*   `` denotes the column number `c` of the cell. It is represented by **alphabetical letters**.
+    *   For example, the 1st column is denoted by `'A'`, the 2nd by `'B'`, the 3rd by `'C'`, and so on.
+*   `` is the row number `r` of the cell. The rth row is represented by the **integer** `r`.
+
+You are given a string `s` in the format `":"`, where `` represents the column `c1`, `` represents the row `r1`, `` represents the column `c2`, and `` represents the row `r2`, such that `r1 <= r2` and `c1 <= c2`.
+
+Return _the **list of cells**_ `(x, y)` _such that_ `r1 <= x <= r2` _and_ `c1 <= y <= c2`. The cells should be represented as **strings** in the format mentioned above and be sorted in **non-decreasing** order first by columns and then by rows.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/02/08/ex1drawio.png)
+
+**Input:** s = "K1:L2"
+
+**Output:** ["K1","K2","L1","L2"]
+
+**Explanation:**
+
+The above diagram shows the cells which should be present in the list.
+
+The red arrows denote the order in which the cells should be presented. 
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2022/02/09/exam2drawio.png)
+
+**Input:** s = "A1:F1"
+
+**Output:** ["A1","B1","C1","D1","E1","F1"]
+
+**Explanation:**
+
+The above diagram shows the cells which should be present in the list.
+
+The red arrow denotes the order in which the cells should be presented. 
+
+**Constraints:**
+
+*   `s.length == 5`
+*   `'A' <= s[0] <= s[3] <= 'Z'`
+*   `'1' <= s[1] <= s[4] <= '9'`
+*   `s` consists of uppercase English letters, digits and `':'`.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun cellsInRange(s: String): List {
+        val c = s.toCharArray()
+        val strings: MutableList = ArrayList()
+        var i = c[0]
+        while (i <= c[3]) {
+            var j = c[1]
+            while (j <= c[4]) {
+                strings.add(String(charArrayOf(i, j)))
+                j++
+            }
+            i++
+        }
+        return strings
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2195_append_k_integers_with_minimal_sum/readme.md b/src/main/kotlin/g2101_2200/s2195_append_k_integers_with_minimal_sum/readme.md
new file mode 100644
index 00000000..6d6f347b
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2195_append_k_integers_with_minimal_sum/readme.md
@@ -0,0 +1,63 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2195\. Append K Integers With Minimal Sum
+
+Medium
+
+You are given an integer array `nums` and an integer `k`. Append `k` **unique positive** integers that do **not** appear in `nums` to `nums` such that the resulting total sum is **minimum**.
+
+Return _the sum of the_ `k` _integers appended to_ `nums`.
+
+**Example 1:**
+
+**Input:** nums = [1,4,25,10,25], k = 2
+
+**Output:** 5
+
+**Explanation:** The two unique positive integers that do not appear in nums which we append are 2 and 3.
+
+The resulting sum of nums is 1 + 4 + 25 + 10 + 25 + 2 + 3 = 70, which is the minimum.
+
+The sum of the two integers appended is 2 + 3 = 5, so we return 5.
+
+**Example 2:**
+
+**Input:** nums = [5,6], k = 6
+
+**Output:** 25
+
+**Explanation:** The six unique positive integers that do not appear in nums which we append are 1, 2, 3, 4, 7, and 8.
+
+The resulting sum of nums is 5 + 6 + 1 + 2 + 3 + 4 + 7 + 8 = 36, which is the minimum.
+
+The sum of the six integers appended is 1 + 2 + 3 + 4 + 7 + 8 = 25, so we return 25. 
+
+**Constraints:**
+
+*   1 <= nums.length <= 105
+*   1 <= nums[i] <= 109
+*   1 <= k <= 108
+
+## Solution
+
+```kotlin
+class Solution {
+    fun minimalKSum(nums: IntArray, k: Int): Long {
+        nums.sort()
+        var sum: Long = 0
+        var n = 0
+        for (i in nums.indices) {
+            if (i == 0 || nums[i] != nums[i - 1]) {
+                if (nums[i] - n > k) {
+                    break
+                }
+                sum += nums[i].toLong()
+                n++
+            }
+        }
+        val t = n + k.toLong()
+        return (1 + t) * t / 2 - sum
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2196_create_binary_tree_from_descriptions/readme.md b/src/main/kotlin/g2101_2200/s2196_create_binary_tree_from_descriptions/readme.md
new file mode 100644
index 00000000..e5fd2702
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2196_create_binary_tree_from_descriptions/readme.md
@@ -0,0 +1,101 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2196\. Create Binary Tree From Descriptions
+
+Medium
+
+You are given a 2D integer array `descriptions` where descriptions[i] = [parenti, childi, isLefti] indicates that parenti is the **parent** of childi in a **binary** tree of **unique** values. Furthermore,
+
+*   If isLefti == 1, then childi is the left child of parenti.
+*   If isLefti == 0, then childi is the right child of parenti.
+
+Construct the binary tree described by `descriptions` and return _its **root**_.
+
+The test cases will be generated such that the binary tree is **valid**.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/02/09/example1drawio.png)
+
+**Input:** descriptions = \[\[20,15,1],[20,17,0],[50,20,1],[50,80,0],[80,19,1]]
+
+**Output:** [50,20,80,15,17,19]
+
+**Explanation:** The root node is the node with value 50 since it has no parent.
+
+The resulting binary tree is shown in the diagram. 
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2022/02/09/example2drawio.png)
+
+**Input:** descriptions = \[\[1,2,1],[2,3,0],[3,4,1]]
+
+**Output:** [1,2,null,null,3,4]
+
+**Explanation:** The root node is the node with value 1 since it has no parent.
+
+The resulting binary tree is shown in the diagram. 
+
+**Constraints:**
+
+*   1 <= descriptions.length <= 104
+*   `descriptions[i].length == 3`
+*   1 <= parenti, childi <= 105
+*   0 <= isLefti <= 1
+*   The binary tree described by `descriptions` is valid.
+
+## Solution
+
+```kotlin
+import com_github_leetcode.TreeNode
+
+/*
+ * Example:
+ * var ti = TreeNode(5)
+ * var v = ti.`val`
+ * Definition for a binary tree node.
+ * class TreeNode(var `val`: Int) {
+ *     var left: TreeNode? = null
+ *     var right: TreeNode? = null
+ * }
+ */
+class Solution {
+    fun createBinaryTree(descriptions: Array): TreeNode? {
+        val map: MutableMap = HashMap()
+        for (description in descriptions) {
+            var data = map[description[0]]
+            if (data == null) {
+                data = Data()
+                data.node = TreeNode(description[0])
+                data.isHead = true
+                map[description[0]] = data
+            }
+            var childData = map[description[1]]
+            if (childData == null) {
+                childData = Data()
+                childData.node = TreeNode(description[1])
+                map[childData.node!!.`val`] = childData
+            }
+            childData.isHead = false
+            if (description[2] == 1) {
+                data.node!!.left = childData.node
+            } else {
+                data.node!!.right = childData.node
+            }
+        }
+        for ((_, value) in map) {
+            if (value.isHead) {
+                return value.node
+            }
+        }
+        return null
+    }
+
+    private class Data {
+        var node: TreeNode? = null
+        var isHead = false
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2197_replace_non_coprime_numbers_in_array/readme.md b/src/main/kotlin/g2101_2200/s2197_replace_non_coprime_numbers_in_array/readme.md
new file mode 100644
index 00000000..3b94caed
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2197_replace_non_coprime_numbers_in_array/readme.md
@@ -0,0 +1,122 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2197\. Replace Non-Coprime Numbers in Array
+
+Hard
+
+You are given an array of integers `nums`. Perform the following steps:
+
+1.  Find **any** two **adjacent** numbers in `nums` that are **non-coprime**.
+2.  If no such numbers are found, **stop** the process.
+3.  Otherwise, delete the two numbers and **replace** them with their **LCM (Least Common Multiple)**.
+4.  **Repeat** this process as long as you keep finding two adjacent non-coprime numbers.
+
+Return _the **final** modified array._ It can be shown that replacing adjacent non-coprime numbers in **any** arbitrary order will lead to the same result.
+
+The test cases are generated such that the values in the final array are **less than or equal** to 108.
+
+Two values `x` and `y` are **non-coprime** if `GCD(x, y) > 1` where `GCD(x, y)` is the **Greatest Common Divisor** of `x` and `y`.
+
+**Example 1:**
+
+**Input:** nums = [6,4,3,2,7,6,2]
+
+**Output:** [12,7,6]
+
+**Explanation:**
+
+- (6, 4) are non-coprime with LCM(6, 4) = 12. Now, nums = [**12**,3,2,7,6,2].
+
+- (12, 3) are non-coprime with LCM(12, 3) = 12. Now, nums = [**12**,2,7,6,2].
+
+- (12, 2) are non-coprime with LCM(12, 2) = 12. Now, nums = [**12**,7,6,2].
+
+- (6, 2) are non-coprime with LCM(6, 2) = 6. Now, nums = [12,7,**6**].
+
+There are no more adjacent non-coprime numbers in nums.
+
+Thus, the final modified array is [12,7,6].
+
+Note that there are other ways to obtain the same resultant array. 
+
+**Example 2:**
+
+**Input:** nums = [2,2,1,1,3,3,3]
+
+**Output:** [2,1,1,3]
+
+**Explanation:**
+
+- (3, 3) are non-coprime with LCM(3, 3) = 3. Now, nums = [2,2,1,1,**3**,3].
+
+- (3, 3) are non-coprime with LCM(3, 3) = 3. Now, nums = [2,2,1,1,**3**].
+
+- (2, 2) are non-coprime with LCM(2, 2) = 2. Now, nums = [**2**,1,1,3].
+
+There are no more adjacent non-coprime numbers in nums.
+
+Thus, the final modified array is [2,1,1,3].
+
+Note that there are other ways to obtain the same resultant array. 
+
+**Constraints:**
+
+*   1 <= nums.length <= 105
+*   1 <= nums[i] <= 105
+*   The test cases are generated such that the values in the final array are **less than or equal** to 108.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun replaceNonCoprimes(nums: IntArray): List {
+        val res = ArrayList()
+        var i = 1
+        res.add(nums[0])
+        while (i < nums.size) {
+            val first = res[res.size - 1]
+            val second = nums[i]
+            val gcd = gcd(first, second)
+            if (gcd > 1) {
+                val lcm = first.toLong() * second.toLong() / gcd
+                if (res.isNotEmpty()) {
+                    res.removeAt(res.size - 1)
+                }
+                res.add(lcm.toInt())
+                recursivelyCheck(res)
+            } else {
+                res.add(second)
+            }
+            i++
+        }
+        return res
+    }
+
+    private fun gcd(a: Int, b: Int): Int {
+        if (a > b) {
+            return gcd(b, a)
+        }
+        return if (b % a == 0) {
+            a
+        } else gcd(b % a, a)
+    }
+
+    private fun recursivelyCheck(list: ArrayList) {
+        if (list.size < 2) {
+            return
+        }
+        val a = list.removeAt(list.size - 1)
+        val b = list.removeAt(list.size - 1)
+        val gcd = gcd(a, b)
+        if (gcd > 1) {
+            val lcm = a.toLong() * b.toLong() / gcd
+            list.add(lcm.toInt())
+            recursivelyCheck(list)
+        } else {
+            list.add(b)
+            list.add(a)
+        }
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2101_2200/s2200_find_all_k_distant_indices_in_an_array/readme.md b/src/main/kotlin/g2101_2200/s2200_find_all_k_distant_indices_in_an_array/readme.md
new file mode 100644
index 00000000..53a826b3
--- /dev/null
+++ b/src/main/kotlin/g2101_2200/s2200_find_all_k_distant_indices_in_an_array/readme.md
@@ -0,0 +1,73 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2200\. Find All K-Distant Indices in an Array
+
+Easy
+
+You are given a **0-indexed** integer array `nums` and two integers `key` and `k`. A **k-distant index** is an index `i` of `nums` for which there exists at least one index `j` such that `|i - j| <= k` and `nums[j] == key`.
+
+Return _a list of all k-distant indices sorted in **increasing order**_.
+
+**Example 1:**
+
+**Input:** nums = [3,4,9,1,3,9,5], key = 9, k = 1
+
+**Output:** [1,2,3,4,5,6]
+
+**Explanation:** Here, nums[2] == key and nums[5] == key.
+
+- For index 0, \|0 - 2\| > k and \|0 - 5\| > k, so there is no j where \|0 - j\| <= k and nums[j] == key. Thus, 0 is not a k-distant index.
+
+- For index 1, \|1 - 2\| <= k and nums[2] == key, so 1 is a k-distant index.
+
+- For index 2, \|2 - 2\| <= k and nums[2] == key, so 2 is a k-distant index.
+
+- For index 3, \|3 - 2\| <= k and nums[2] == key, so 3 is a k-distant index.
+
+- For index 4, \|4 - 5\| <= k and nums[5] == key, so 4 is a k-distant index.
+
+- For index 5, \|5 - 5\| <= k and nums[5] == key, so 5 is a k-distant index.
+
+- For index 6, \|6 - 5\| <= k and nums[5] == key, so 6 is a k-distant index.
+
+Thus, we return [1,2,3,4,5,6] which is sorted in increasing order. 
+
+**Example 2:**
+
+**Input:** nums = [2,2,2,2,2], key = 2, k = 2
+
+**Output:** [0,1,2,3,4]
+
+**Explanation:** For all indices i in nums, there exists some index j such that \|i - j\| <= k and nums[j] == key, so every index is a k-distant index.
+
+Hence, we return [0,1,2,3,4]. 
+
+**Constraints:**
+
+*   `1 <= nums.length <= 1000`
+*   `1 <= nums[i] <= 1000`
+*   `key` is an integer from the array `nums`.
+*   `1 <= k <= nums.length`
+
+## Solution
+
+```kotlin
+class Solution {
+    fun findKDistantIndices(nums: IntArray, key: Int, k: Int): List {
+        val ans: MutableList = ArrayList()
+        var start = 0
+        val n = nums.size
+        for (i in 0 until n) {
+            if (nums[i] == key) {
+                start = Math.max(i - k, start)
+                val end = Math.min(i + k, n - 1)
+                while (start <= end) {
+                    ans.add(start++)
+                }
+            }
+        }
+        return ans
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2201_count_artifacts_that_can_be_extracted/readme.md b/src/main/kotlin/g2201_2300/s2201_count_artifacts_that_can_be_extracted/readme.md
new file mode 100644
index 00000000..1cd998e5
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2201_count_artifacts_that_can_be_extracted/readme.md
@@ -0,0 +1,95 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2201\. Count Artifacts That Can Be Extracted
+
+Medium
+
+There is an `n x n` **0-indexed** grid with some artifacts buried in it. You are given the integer `n` and a **0-indexed** 2D integer array `artifacts` describing the positions of the rectangular artifacts where artifacts[i] = [r1i, c1i, r2i, c2i] denotes that the ith artifact is buried in the subgrid where:
+
+*   (r1i, c1i) is the coordinate of the **top-left** cell of the ith artifact and
+*   (r2i, c2i) is the coordinate of the **bottom-right** cell of the ith artifact.
+
+You will excavate some cells of the grid and remove all the mud from them. If the cell has a part of an artifact buried underneath, it will be uncovered. If all the parts of an artifact are uncovered, you can extract it.
+
+Given a **0-indexed** 2D integer array `dig` where dig[i] = [ri, ci] indicates that you will excavate the cell (ri, ci), return _the number of artifacts that you can extract_.
+
+The test cases are generated such that:
+
+*   No two artifacts overlap.
+*   Each artifact only covers at most `4` cells.
+*   The entries of `dig` are unique.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2019/09/16/untitled-diagram.jpg)
+
+**Input:** n = 2, artifacts = \[\[0,0,0,0],[0,1,1,1]], dig = \[\[0,0],[0,1]]
+
+**Output:** 1
+
+**Explanation:** The different colors represent different artifacts. Excavated cells are labeled with a 'D' in the grid. There is 1 artifact that can be extracted, namely the red artifact. The blue artifact has one part in cell (1,1) which remains uncovered, so we cannot extract it. Thus, we return 1.
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2019/09/16/untitled-diagram-1.jpg)
+
+**Input:** n = 2, artifacts = \[\[0,0,0,0],[0,1,1,1]], dig = \[\[0,0],[0,1],[1,1]]
+
+**Output:** 2
+
+**Explanation:** Both the red and blue artifacts have all parts uncovered (labeled with a 'D') and can be extracted, so we return 2.
+
+**Constraints:**
+
+*   `1 <= n <= 1000`
+*   1 <= artifacts.length, dig.length <= min(n2, 105)
+*   `artifacts[i].length == 4`
+*   `dig[i].length == 2`
+*   0 <= r1i, c1i, r2i, c2i, ri, ci <= n - 1
+*   r1i <= r2i
+*   c1i <= c2i
+*   No two artifacts will overlap.
+*   The number of cells covered by an artifact is **at most** `4`.
+*   The entries of `dig` are unique.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun digArtifacts(n: Int, artifacts: Array, dig: Array): Int {
+        val ar = Array(n) { IntArray(n) }
+        for (ints in dig) {
+            ar[ints[0]][ints[1]] = 1
+        }
+        var ans = 0
+        for (artifact in artifacts) {
+            val x1 = artifact[0]
+            val y1 = artifact[1]
+            val x2 = artifact[2]
+            val y2 = artifact[3]
+            var flag = 0
+            var a = x1
+            var b = y1
+            while (a <= x2) {
+                b = y1
+                while (b <= y2) {
+                    if (ar[a][b] != 1) {
+                        flag = 1
+                        break
+                    }
+                    b++
+                }
+                if (flag == 1) {
+                    break
+                }
+                a++
+            }
+            if (a == x2 + 1 && b == y2 + 1) {
+                ans++
+            }
+        }
+        return ans
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2202_maximize_the_topmost_element_after_k_moves/readme.md b/src/main/kotlin/g2201_2300/s2202_maximize_the_topmost_element_after_k_moves/readme.md
new file mode 100644
index 00000000..3db6f5a0
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2202_maximize_the_topmost_element_after_k_moves/readme.md
@@ -0,0 +1,78 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2202\. Maximize the Topmost Element After K Moves
+
+Medium
+
+You are given a **0-indexed** integer array `nums` representing the contents of a **pile**, where `nums[0]` is the topmost element of the pile.
+
+In one move, you can perform **either** of the following:
+
+*   If the pile is not empty, **remove** the topmost element of the pile.
+*   If there are one or more removed elements, **add** any one of them back onto the pile. This element becomes the new topmost element.
+
+You are also given an integer `k`, which denotes the total number of moves to be made.
+
+Return _the **maximum value** of the topmost element of the pile possible after **exactly**_ `k` _moves_. In case it is not possible to obtain a non-empty pile after `k` moves, return `-1`.
+
+**Example 1:**
+
+**Input:** nums = [5,2,2,4,0,6], k = 4
+
+**Output:** 5
+
+**Explanation:**
+
+One of the ways we can end with 5 at the top of the pile after 4 moves is as follows:
+
+- Step 1: Remove the topmost element = 5. The pile becomes [2,2,4,0,6].
+
+- Step 2: Remove the topmost element = 2. The pile becomes [2,4,0,6].
+
+- Step 3: Remove the topmost element = 2. The pile becomes [4,0,6].
+
+- Step 4: Add 5 back onto the pile. The pile becomes [5,4,0,6].
+
+Note that this is not the only way to end with 5 at the top of the pile. It can be shown that 5 is the largest answer possible after 4 moves. 
+
+**Example 2:**
+
+**Input:** nums = [2], k = 1
+
+**Output:** -1
+
+**Explanation:**
+
+In the first move, our only option is to pop the topmost element of the pile.
+
+Since it is not possible to obtain a non-empty pile after one move, we return -1. 
+
+**Constraints:**
+
+*   1 <= nums.length <= 105
+*   0 <= nums[i], k <= 109
+
+## Solution
+
+```kotlin
+class Solution {
+    fun maximumTop(nums: IntArray, k: Int): Int {
+        var max = -1
+        val maxTravers = Math.min(k + 1, nums.size)
+        if (nums.size == 1) {
+            return if (k % 2 == 0) {
+                nums[0]
+            } else {
+                max
+            }
+        }
+        for (i in 0 until maxTravers) {
+            if (nums[i] > max && i != k - 1) {
+                max = nums[i]
+            }
+        }
+        return max
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2203_minimum_weighted_subgraph_with_the_required_paths/readme.md b/src/main/kotlin/g2201_2300/s2203_minimum_weighted_subgraph_with_the_required_paths/readme.md
new file mode 100644
index 00000000..597a6723
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2203_minimum_weighted_subgraph_with_the_required_paths/readme.md
@@ -0,0 +1,99 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2203\. Minimum Weighted Subgraph With the Required Paths
+
+Hard
+
+You are given an integer `n` denoting the number of nodes of a **weighted directed** graph. The nodes are numbered from `0` to `n - 1`.
+
+You are also given a 2D integer array `edges` where edges[i] = [fromi, toi, weighti] denotes that there exists a **directed** edge from fromi to toi with weight weighti.
+
+Lastly, you are given three **distinct** integers `src1`, `src2`, and `dest` denoting three distinct nodes of the graph.
+
+Return _the **minimum weight** of a subgraph of the graph such that it is **possible** to reach_ `dest` _from both_ `src1` _and_ `src2` _via a set of edges of this subgraph_. In case such a subgraph does not exist, return `-1`.
+
+A **subgraph** is a graph whose vertices and edges are subsets of the original graph. The **weight** of a subgraph is the sum of weights of its constituent edges.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/02/17/example1drawio.png)
+
+**Input:** n = 6, edges = \[\[0,2,2],[0,5,6],[1,0,3],[1,4,5],[2,1,1],[2,3,3],[2,3,4],[3,4,2],[4,5,1]], src1 = 0, src2 = 1, dest = 5
+
+**Output:** 9
+
+**Explanation:** The above figure represents the input graph. The blue edges represent one of the subgraphs that yield the optimal answer. Note that the subgraph [[1,0,3],[0,5,6]] also yields the optimal answer. It is not possible to get a subgraph with less weight satisfying all the constraints.
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2022/02/17/example2-1drawio.png)
+
+**Input:** n = 3, edges = \[\[0,1,1],[2,1,1]], src1 = 0, src2 = 1, dest = 2
+
+**Output:** -1
+
+**Explanation:** The above figure represents the input graph. It can be seen that there does not exist any path from node 1 to node 2, hence there are no subgraphs satisfying all the constraints.
+
+**Constraints:**
+
+*   3 <= n <= 105
+*   0 <= edges.length <= 105
+*   `edges[i].length == 3`
+*   0 <= fromi, toi, src1, src2, dest <= n - 1
+*   fromi != toi
+*   `src1`, `src2`, and `dest` are pairwise distinct.
+*   1 <= weight[i] <= 105
+
+## Solution
+
+```kotlin
+import java.util.PriorityQueue
+import java.util.Queue
+
+class Solution {
+    fun minimumWeight(n: Int, edges: Array, src1: Int, src2: Int, dest: Int): Long {
+        val graph: Array?> = arrayOfNulls(n)
+        val weight = Array(3) { LongArray(n) }
+        for (i in 0 until n) {
+            for (j in 0..2) {
+                weight[j][i] = Long.MAX_VALUE
+            }
+            graph[i] = ArrayList()
+        }
+        for (e in edges) {
+            graph[e[0]]?.add(intArrayOf(e[1], e[2]))
+        }
+        val queue: Queue = PriorityQueue({ node1: Node, node2: Node -> node1.weight.compareTo(node2.weight) })
+        queue.offer(Node(0, src1, 0))
+        weight[0][src1] = 0
+        queue.offer(Node(1, src2, 0))
+        weight[1][src2] = 0
+        while (queue.isNotEmpty()) {
+            val curr = queue.poll()
+            if (curr.vertex == dest && curr.index == 2) {
+                return curr.weight
+            }
+            for (next in graph[curr.vertex]!!) {
+                if (curr.index == 2 && weight[curr.index][next[0]] > curr.weight + next[1]) {
+                    weight[curr.index][next[0]] = curr.weight + next[1]
+                    queue.offer(Node(curr.index, next[0], weight[curr.index][next[0]]))
+                } else if (weight[curr.index][next[0]] > curr.weight + next[1]) {
+                    weight[curr.index][next[0]] = curr.weight + next[1]
+                    queue.offer(Node(curr.index, next[0], weight[curr.index][next[0]]))
+                    if (weight[curr.index xor 1][next[0]] != Long.MAX_VALUE &&
+                        weight[curr.index][next[0]] + weight[curr.index xor 1][next[0]]
+                        < weight[2][next[0]]
+                    ) {
+                        weight[2][next[0]] = weight[curr.index][next[0]] + weight[curr.index xor 1][next[0]]
+                        queue.offer(Node(2, next[0], weight[2][next[0]]))
+                    }
+                }
+            }
+        }
+        return -1
+    }
+
+    private class Node(var index: Int, var vertex: Int, var weight: Long)
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2206_divide_array_into_equal_pairs/readme.md b/src/main/kotlin/g2201_2300/s2206_divide_array_into_equal_pairs/readme.md
new file mode 100644
index 00000000..f5bdba3e
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2206_divide_array_into_equal_pairs/readme.md
@@ -0,0 +1,62 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2206\. Divide Array Into Equal Pairs
+
+Easy
+
+You are given an integer array `nums` consisting of `2 * n` integers.
+
+You need to divide `nums` into `n` pairs such that:
+
+*   Each element belongs to **exactly one** pair.
+*   The elements present in a pair are **equal**.
+
+Return `true` _if nums can be divided into_ `n` _pairs, otherwise return_ `false`.
+
+**Example 1:**
+
+**Input:** nums = [3,2,3,2,2,2]
+
+**Output:** true
+
+**Explanation:**
+
+There are 6 elements in nums, so they should be divided into 6 / 2 = 3 pairs.
+
+If nums is divided into the pairs (2, 2), (3, 3), and (2, 2), it will satisfy all the conditions.
+
+**Example 2:**
+
+**Input:** nums = [1,2,3,4]
+
+**Output:** false
+
+**Explanation:**
+
+There is no way to divide nums into 4 / 2 = 2 pairs such that the pairs satisfy every condition.
+
+**Constraints:**
+
+*   `nums.length == 2 * n`
+*   `1 <= n <= 500`
+*   `1 <= nums[i] <= 500`
+
+## Solution
+
+```kotlin
+class Solution {
+    fun divideArray(nums: IntArray): Boolean {
+        val freq = IntArray(501)
+        for (num in nums) {
+            ++freq[num]
+        }
+        for (f in freq) {
+            if (f % 2 != 0) {
+                return false
+            }
+        }
+        return true
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2207_maximize_number_of_subsequences_in_a_string/readme.md b/src/main/kotlin/g2201_2300/s2207_maximize_number_of_subsequences_in_a_string/readme.md
new file mode 100644
index 00000000..efba5ca1
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2207_maximize_number_of_subsequences_in_a_string/readme.md
@@ -0,0 +1,78 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2207\. Maximize Number of Subsequences in a String
+
+Medium
+
+You are given a **0-indexed** string `text` and another **0-indexed** string `pattern` of length `2`, both of which consist of only lowercase English letters.
+
+You can add **either** `pattern[0]` **or** `pattern[1]` anywhere in `text` **exactly once**. Note that the character can be added even at the beginning or at the end of `text`.
+
+Return _the **maximum** number of times_ `pattern` _can occur as a **subsequence** of the modified_ `text`.
+
+A **subsequence** is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.
+
+**Example 1:**
+
+**Input:** text = "abdcdbc", pattern = "ac"
+
+**Output:** 4
+
+**Explanation:**
+
+If we add pattern[0] = 'a' in between text[1] and text[2], we get "ab**a**dcdbc". Now, the number of times "ac" occurs as a subsequence is 4.
+
+Some other strings which have 4 subsequences "ac" after adding a character to text are "**a**abdcdbc" and "abd**a**cdbc".
+
+However, strings such as "abdc**a**dbc", "abd**c**cdbc", and "abdcdbc**c**", although obtainable, have only 3 subsequences "ac" and are thus suboptimal.
+
+It can be shown that it is not possible to get more than 4 subsequences "ac" by adding only one character.
+
+**Example 2:**
+
+**Input:** text = "aabb", pattern = "ab"
+
+**Output:** 6
+
+**Explanation:**
+
+Some of the strings which can be obtained from text and have 6 subsequences "ab" are "**a**aabb", "aa**a**bb", and "aab**b**b".
+
+**Constraints:**
+
+*   1 <= text.length <= 105
+*   `pattern.length == 2`
+*   `text` and `pattern` consist only of lowercase English letters.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun maximumSubsequenceCount(text: String, pattern: String): Long {
+        val first = pattern[0]
+        val second = pattern[1]
+        if (first == second) {
+            var res: Long = 0
+            for (c in text.toCharArray()) {
+                if (c == first) {
+                    res++
+                }
+            }
+            return res * (res + 1) / 2
+        }
+        var res: Long = 0
+        var firstCount = 0
+        var secondCount = 0
+        for (c in text.toCharArray()) {
+            if (c == first) {
+                firstCount++
+            } else if (c == second) {
+                secondCount++
+                res += firstCount.toLong()
+            }
+        }
+        return Math.max(res + secondCount, res + firstCount)
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2208_minimum_operations_to_halve_array_sum/readme.md b/src/main/kotlin/g2201_2300/s2208_minimum_operations_to_halve_array_sum/readme.md
new file mode 100644
index 00000000..37356c68
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2208_minimum_operations_to_halve_array_sum/readme.md
@@ -0,0 +1,91 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2208\. Minimum Operations to Halve Array Sum
+
+Medium
+
+You are given an array `nums` of positive integers. In one operation, you can choose **any** number from `nums` and reduce it to **exactly** half the number. (Note that you may choose this reduced number in future operations.)
+
+Return _the **minimum** number of operations to reduce the sum of_ `nums` _by **at least** half._
+
+**Example 1:**
+
+**Input:** nums = [5,19,8,1]
+
+**Output:** 3
+
+**Explanation:** The initial sum of nums is equal to 5 + 19 + 8 + 1 = 33.
+
+The following is one of the ways to reduce the sum by at least half:
+
+Pick the number 19 and reduce it to 9.5.
+
+Pick the number 9.5 and reduce it to 4.75.
+
+Pick the number 8 and reduce it to 4.
+
+The final array is [5, 4.75, 4, 1] with a total sum of 5 + 4.75 + 4 + 1 = 14.75.
+
+The sum of nums has been reduced by 33 - 14.75 = 18.25, which is at least half of the initial sum, 18.25 >= 33/2 = 16.5.
+
+Overall, 3 operations were used so we return 3.
+
+It can be shown that we cannot reduce the sum by at least half in less than 3 operations. 
+
+**Example 2:**
+
+**Input:** nums = [3,8,20]
+
+**Output:** 3
+
+**Explanation:** The initial sum of nums is equal to 3 + 8 + 20 = 31.
+
+The following is one of the ways to reduce the sum by at least half:
+
+Pick the number 20 and reduce it to 10.
+
+Pick the number 10 and reduce it to 5.
+
+Pick the number 3 and reduce it to 1.5.
+
+The final array is [1.5, 8, 5] with a total sum of 1.5 + 8 + 5 = 14.5.
+
+The sum of nums has been reduced by 31 - 14.5 = 16.5, which is at least half of the initial sum, 16.5 >= 31/2 = 16.5.
+
+Overall, 3 operations were used so we return 3.
+
+It can be shown that we cannot reduce the sum by at least half in less than 3 operations. 
+
+**Constraints:**
+
+*   1 <= nums.length <= 105
+*   1 <= nums[i] <= 107
+
+## Solution
+
+```kotlin
+import java.util.Collections
+import java.util.PriorityQueue
+
+class Solution {
+    fun halveArray(nums: IntArray): Int {
+        val queue = PriorityQueue(nums.size, Collections.reverseOrder())
+        var sum = 0.0
+        var count = 0
+        for (num in nums) {
+            queue.add(num.toDouble())
+            sum += num
+        }
+        var hsum = sum
+        while (hsum > sum / 2) {
+            var maxElement = queue.poll()
+            maxElement /= 2
+            count++
+            hsum -= maxElement
+            queue.add(maxElement)
+        }
+        return count
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2209_minimum_white_tiles_after_covering_with_carpets/readme.md b/src/main/kotlin/g2201_2300/s2209_minimum_white_tiles_after_covering_with_carpets/readme.md
new file mode 100644
index 00000000..0da6b876
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2209_minimum_white_tiles_after_covering_with_carpets/readme.md
@@ -0,0 +1,86 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2209\. Minimum White Tiles After Covering With Carpets
+
+Hard
+
+You are given a **0-indexed binary** string `floor`, which represents the colors of tiles on a floor:
+
+*   `floor[i] = '0'` denotes that the ith tile of the floor is colored **black**.
+*   On the other hand, `floor[i] = '1'` denotes that the ith tile of the floor is colored **white**.
+
+You are also given `numCarpets` and `carpetLen`. You have `numCarpets` **black** carpets, each of length `carpetLen` tiles. Cover the tiles with the given carpets such that the number of **white** tiles still visible is **minimum**. Carpets may overlap one another.
+
+Return _the **minimum** number of white tiles still visible._
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/02/10/ex1-1.png)
+
+**Input:** floor = "10110101", numCarpets = 2, carpetLen = 2
+
+**Output:** 2
+
+**Explanation:**
+
+The figure above shows one way of covering the tiles with the carpets such that only 2 white tiles are visible.
+
+No other way of covering the tiles with the carpets can leave less than 2 white tiles visible. 
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2022/02/10/ex2.png)
+
+**Input:** floor = "11111", numCarpets = 2, carpetLen = 3
+
+**Output:** 0
+
+**Explanation:**
+
+The figure above shows one way of covering the tiles with the carpets such that no white tiles are visible.
+
+Note that the carpets are able to overlap one another. 
+
+**Constraints:**
+
+*   `1 <= carpetLen <= floor.length <= 1000`
+*   `floor[i]` is either `'0'` or `'1'`.
+*   `1 <= numCarpets <= 1000`
+
+## Solution
+
+```kotlin
+class Solution {
+    fun minimumWhiteTiles(floor: String, numCarpets: Int, carpetLen: Int): Int {
+        val len = floor.length
+        val dp = Array(numCarpets + 1) { IntArray(len + 1) }
+        val prefix = IntArray(len)
+        var tiles = 0
+        var total = 0
+        for (i in 0 until len) {
+            // calculate total no of Tiles within the Carpet Length Window
+            tiles += floor[i].code - '0'.code
+            // start excluding tiles which are not in the Range anymore of the Carpet Length given
+            if (i - carpetLen >= 0) {
+                tiles -= floor[i - carpetLen].code - '0'.code
+            }
+            // the total no of tiles covered within the Carpet Length range for current index
+            prefix[i] = tiles
+            total += floor[i].code - '0'.code
+        }
+        for (i in 1..numCarpets) {
+            for (j in 0 until len) {
+                // if we do not wish to cover current Tile
+                val doNot = dp[i][j]
+                // if we do wish to cover current tile
+                val doTake = dp[i - 1][Math.max(0, j - carpetLen + 1)] + prefix[j]
+                // we should go back the Carpet length & check for tiles not covered before j -
+                // carpet Length distance
+                dp[i][j + 1] = Math.max(doTake, doNot)
+            }
+        }
+        return total - dp[numCarpets][len]
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2210_count_hills_and_valleys_in_an_array/readme.md b/src/main/kotlin/g2201_2300/s2210_count_hills_and_valleys_in_an_array/readme.md
new file mode 100644
index 00000000..6914fe02
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2210_count_hills_and_valleys_in_an_array/readme.md
@@ -0,0 +1,73 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2210\. Count Hills and Valleys in an Array
+
+Easy
+
+You are given a **0-indexed** integer array `nums`. An index `i` is part of a **hill** in `nums` if the closest non-equal neighbors of `i` are smaller than `nums[i]`. Similarly, an index `i` is part of a **valley** in `nums` if the closest non-equal neighbors of `i` are larger than `nums[i]`. Adjacent indices `i` and `j` are part of the **same** hill or valley if `nums[i] == nums[j]`.
+
+Note that for an index to be part of a hill or valley, it must have a non-equal neighbor on **both** the left and right of the index.
+
+Return _the number of hills and valleys in_ `nums`.
+
+**Example 1:**
+
+**Input:** nums = [2,4,1,1,6,5]
+
+**Output:** 3
+
+**Explanation:** 
+
+At index 0: There is no non-equal neighbor of 2 on the left, so index 0 is neither a hill nor a valley. 
+
+At index 1: The closest non-equal neighbors of 4 are 2 and 1. Since 4 > 2 and 4 > 1, index 1 is a hill. 
+
+At index 2: The closest non-equal neighbors of 1 are 4 and 6. Since 1 < 4 and 1 < 6, index 2 is a valley. 
+
+At index 3: The closest non-equal neighbors of 1 are 4 and 6. Since 1 < 4 and 1 < 6, index 3 is a valley, but note that it is part of the same valley as index 2. At index 4: The closest non-equal neighbors of 6 are 1 and 5. Since 6 > 1 and 6 > 5, index 4 is a hill. 
+
+At index 5: There is no non-equal neighbor of 5 on the right, so index 5 is neither a hill nor a valley. There are 3 hills and valleys so we return 3.
+
+**Example 2:**
+
+**Input:** nums = [6,6,5,5,4,1]
+
+**Output:** 0
+
+**Explanation:** 
+
+At index 0: There is no non-equal neighbor of 6 on the left, so index 0 is neither a hill nor a valley. 
+
+At index 1: There is no non-equal neighbor of 6 on the left, so index 1 is neither a hill nor a valley. 
+
+At index 2: The closest non-equal neighbors of 5 are 6 and 4. Since 5 < 6 and 5 > 4, index 2 is neither a hill nor a valley. 
+
+At index 3: The closest non-equal neighbors of 5 are 6 and 4. Since 5 < 6 and 5 > 4, index 3 is neither a hill nor a valley. 
+
+At index 4: The closest non-equal neighbors of 4 are 5 and 1. Since 4 < 5 and 4 > 1, index 4 is neither a hill nor a valley. 
+
+At index 5: There is no non-equal neighbor of 1 on the right, so index 5 is neither a hill nor a valley. There are 0 hills and valleys so we return 0.
+
+**Constraints:**
+
+*   `3 <= nums.length <= 100`
+*   `1 <= nums[i] <= 100`
+
+## Solution
+
+```kotlin
+class Solution {
+    fun countHillValley(nums: IntArray): Int {
+        var left = nums[0]
+        var count = 0
+        for (i in 1 until nums.size - 1) {
+            if (left > nums[i] && nums[i + 1] > nums[i] || left < nums[i] && nums[i + 1] < nums[i]) {
+                count++
+                left = nums[i]
+            }
+        }
+        return count
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2211_count_collisions_on_a_road/readme.md b/src/main/kotlin/g2201_2300/s2211_count_collisions_on_a_road/readme.md
new file mode 100644
index 00000000..205efb21
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2211_count_collisions_on_a_road/readme.md
@@ -0,0 +1,101 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2211\. Count Collisions on a Road
+
+Medium
+
+There are `n` cars on an infinitely long road. The cars are numbered from `0` to `n - 1` from left to right and each car is present at a **unique** point.
+
+You are given a **0-indexed** string `directions` of length `n`. `directions[i]` can be either `'L'`, `'R'`, or `'S'` denoting whether the ith car is moving towards the **left**, towards the **right**, or **staying** at its current point respectively. Each moving car has the **same speed**.
+
+The number of collisions can be calculated as follows:
+
+*   When two cars moving in **opposite** directions collide with each other, the number of collisions increases by `2`.
+*   When a moving car collides with a stationary car, the number of collisions increases by `1`.
+
+After a collision, the cars involved can no longer move and will stay at the point where they collided. Other than that, cars cannot change their state or direction of motion.
+
+Return _the **total number of collisions** that will happen on the road_.
+
+**Example 1:**
+
+**Input:** directions = "RLRSLL"
+
+**Output:** 5
+
+**Explanation:** The collisions that will happen on the road are: 
+
+- Cars 0 and 1 will collide with each other. Since they are moving in opposite directions, the number of collisions becomes 0 + 2 = 2. 
+
+- Cars 2 and 3 will collide with each other. Since car 3 is stationary, the number of collisions becomes 2 + 1 = 3. 
+
+- Cars 3 and 4 will collide with each other. Since car 3 is stationary, the number of collisions becomes 3 + 1 = 4. 
+
+- Cars 4 and 5 will collide with each other. After car 4 collides with car 3, it will stay at the point of collision and get hit by car 5. The number of collisions becomes 4 + 1 = 5. 
+  
+Thus, the total number of collisions that will happen on the road is 5.
+
+**Example 2:**
+
+**Input:** directions = "LLRR"
+
+**Output:** 0
+
+**Explanation:** No cars will collide with each other. Thus, the total number of collisions that will happen on the road is 0.
+
+**Constraints:**
+
+*   1 <= directions.length <= 105
+*   `directions[i]` is either `'L'`, `'R'`, or `'S'`.
+
+## Solution
+
+```kotlin
+import java.util.ArrayDeque
+import java.util.Deque
+
+class Solution {
+    fun countCollisions(directions: String?): Int {
+        if (directions == null || directions.length == 1) {
+            return 0
+        }
+        val stack: Deque = ArrayDeque()
+        val direction = directions.toCharArray()
+        var prevc = '0'
+        var collision = 0
+        for (i in direction.indices) {
+            if (direction[i] == 'R') {
+                stack.push(direction[i])
+            } else {
+                if (direction[i] == 'S' && prevc == 'R') {
+                    if (stack.isNotEmpty()) {
+                        stack.pop()
+                    }
+                    collision += 1
+                    direction[i] = 'S'
+                    while (stack.isNotEmpty()) {
+                        collision++
+                        stack.pop()
+                    }
+                }
+                if (direction[i] == 'L' && prevc == 'R') {
+                    stack.pop()
+                    collision += 2
+                    direction[i] = 'S'
+                    while (stack.isNotEmpty()) {
+                        collision++
+                        stack.pop()
+                    }
+                }
+                if (direction[i] == 'L' && prevc == 'S') {
+                    collision++
+                    direction[i] = 'S'
+                }
+            }
+            prevc = direction[i]
+        }
+        return collision
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2212_maximum_points_in_an_archery_competition/readme.md b/src/main/kotlin/g2201_2300/s2212_maximum_points_in_an_archery_competition/readme.md
new file mode 100644
index 00000000..92419240
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2212_maximum_points_in_an_archery_competition/readme.md
@@ -0,0 +1,81 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2212\. Maximum Points in an Archery Competition
+
+Medium
+
+Alice and Bob are opponents in an archery competition. The competition has set the following rules:
+
+1.  Alice first shoots `numArrows` arrows and then Bob shoots `numArrows` arrows.
+2.  The points are then calculated as follows:
+    1.  The target has integer scoring sections ranging from `0` to `11` **inclusive**.
+    2.  For **each** section of the target with score `k` (in between `0` to `11`), say Alice and Bob have shot ak and bk arrows on that section respectively. If ak >= bk, then Alice takes `k` points. If ak < bk, then Bob takes `k` points.
+    3.  However, if ak == bk == 0, then **nobody** takes `k` points.
+
+*   For example, if Alice and Bob both shot `2` arrows on the section with score `11`, then Alice takes `11` points. On the other hand, if Alice shot `0` arrows on the section with score `11` and Bob shot `2` arrows on that same section, then Bob takes `11` points.
+
+
+You are given the integer `numArrows` and an integer array `aliceArrows` of size `12`, which represents the number of arrows Alice shot on each scoring section from `0` to `11`. Now, Bob wants to **maximize** the total number of points he can obtain.
+
+Return _the array_ `bobArrows` _which represents the number of arrows Bob shot on **each** scoring section from_ `0` _to_ `11`. The sum of the values in `bobArrows` should equal `numArrows`.
+
+If there are multiple ways for Bob to earn the maximum total points, return **any** one of them.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/02/24/ex1.jpg)
+
+**Input:** numArrows = 9, aliceArrows = [1,1,0,1,0,0,2,1,0,1,2,0]
+
+**Output:** [0,0,0,0,1,1,0,0,1,2,3,1]
+
+**Explanation:** The table above shows how the competition is scored. Bob earns a total point of 4 + 5 + 8 + 9 + 10 + 11 = 47. It can be shown that Bob cannot obtain a score higher than 47 points.
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2022/02/24/ex2new.jpg)
+
+**Input:** numArrows = 3, aliceArrows = [0,0,1,0,0,0,0,0,0,0,0,2]
+
+**Output:** [0,0,0,0,0,0,0,0,1,1,1,0]
+
+**Explanation:** The table above shows how the competition is scored. Bob earns a total point of 8 + 9 + 10 = 27. It can be shown that Bob cannot obtain a score higher than 27 points.
+
+**Constraints:**
+
+*   1 <= numArrows <= 105
+*   `aliceArrows.length == bobArrows.length == 12`
+*   `0 <= aliceArrows[i], bobArrows[i] <= numArrows`
+*   `sum(aliceArrows[i]) == numArrows`
+
+## Solution
+
+```kotlin
+class Solution {
+    private val ans = IntArray(12)
+    private val ans1 = IntArray(12)
+    private var max = 0
+    fun maximumBobPoints(numArrows: Int, aliceArrows: IntArray): IntArray {
+        solve(numArrows, aliceArrows, 11, 0)
+        return ans1
+    }
+
+    private fun solve(numArrows: Int, aliceArrows: IntArray, index: Int, sum: Int) {
+        if (numArrows <= 0 || index < 0) {
+            if (max < sum) {
+                max = sum
+                ans1[0] = Math.max(ans[0], ans[0] + numArrows)
+                System.arraycopy(ans, 1, ans1, 1, 11)
+            }
+            return
+        }
+        if (aliceArrows[index] + 1 <= numArrows) {
+            ans[index] = aliceArrows[index] + 1
+            solve(numArrows - (aliceArrows[index] + 1), aliceArrows, index - 1, sum + index)
+            ans[index] = 0
+        }
+        solve(numArrows, aliceArrows, index - 1, sum)
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2213_longest_substring_of_one_repeating_character/readme.md b/src/main/kotlin/g2201_2300/s2213_longest_substring_of_one_repeating_character/readme.md
new file mode 100644
index 00000000..11033f20
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2213_longest_substring_of_one_repeating_character/readme.md
@@ -0,0 +1,136 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2213\. Longest Substring of One Repeating Character
+
+Hard
+
+You are given a **0-indexed** string `s`. You are also given a **0-indexed** string `queryCharacters` of length `k` and a **0-indexed** array of integer **indices** `queryIndices` of length `k`, both of which are used to describe `k` queries.
+
+The ith query updates the character in `s` at index `queryIndices[i]` to the character `queryCharacters[i]`.
+
+Return _an array_ `lengths` _of length_ `k` _where_ `lengths[i]` _is the **length** of the **longest substring** of_ `s` _consisting of **only one repeating** character **after** the_ ith _query_ _is performed._
+
+**Example 1:**
+
+**Input:** s = "babacc", queryCharacters = "bcb", queryIndices = [1,3,3]
+
+**Output:** [3,3,4]
+
+**Explanation:** - 1st query updates s = "b**b**bacc". The longest substring consisting of one repeating character is "bbb" with length 3. 
+
+- 2nd query updates s = "bbb**c**cc". The longest substring consisting of one repeating character can be "bbb" or "ccc" with length 3. 
+
+- 3rd query updates s = "bbb**b**cc". The longest substring consisting of one repeating character is "bbbb" with length 4. 
+  
+Thus, we return [3,3,4].
+
+**Example 2:**
+
+**Input:** s = "abyzz", queryCharacters = "aa", queryIndices = [2,1]
+
+**Output:** [2,3]
+
+**Explanation:** - 1st query updates s = "ab**a**zz". The longest substring consisting of one repeating character is "zz" with length 2. 
+
+- 2nd query updates s = "a**a**azz". The longest substring consisting of one repeating character is "aaa" with length 3. 
+  
+Thus, we return [2,3].
+
+**Constraints:**
+
+*   1 <= s.length <= 105
+*   `s` consists of lowercase English letters.
+*   `k == queryCharacters.length == queryIndices.length`
+*   1 <= k <= 105
+*   `queryCharacters` consists of lowercase English letters.
+*   `0 <= queryIndices[i] < s.length`
+
+## Solution
+
+```kotlin
+class Solution {
+    internal class TreeNode(var start: Int, var end: Int) {
+        var leftChar = 0.toChar()
+        var leftCharLen = 0
+        var rightChar = 0.toChar()
+        var rightCharLen = 0
+        var max = 0
+        var left: TreeNode? = null
+        var right: TreeNode? = null
+    }
+
+    fun longestRepeating(s: String, queryCharacters: String, queryIndices: IntArray): IntArray {
+        val sChar = s.toCharArray()
+        val qChar = queryCharacters.toCharArray()
+        val root = buildTree(sChar, 0, sChar.size - 1)
+        val result = IntArray(qChar.size)
+        for (i in qChar.indices) {
+            updateTree(root, queryIndices[i], qChar[i])
+            if (root != null) {
+                result[i] = root.max
+            }
+        }
+        return result
+    }
+
+    private fun buildTree(s: CharArray, from: Int, to: Int): TreeNode? {
+        if (from > to) {
+            return null
+        }
+        val root = TreeNode(from, to)
+        if (from == to) {
+            root.max = 1
+            root.leftChar = s[from]
+            root.rightChar = root.leftChar
+            root.rightCharLen = 1
+            root.leftCharLen = root.rightCharLen
+            return root
+        }
+        val middle = from + (to - from) / 2
+        root.left = buildTree(s, from, middle)
+        root.right = buildTree(s, middle + 1, to)
+        updateNode(root)
+        return root
+    }
+
+    private fun updateTree(root: TreeNode?, index: Int, c: Char) {
+        if (root == null || root.start > index || root.end < index) {
+            return
+        }
+        if (root.start == index && root.end == index) {
+            root.rightChar = c
+            root.leftChar = root.rightChar
+            return
+        }
+        updateTree(root.left, index, c)
+        updateTree(root.right, index, c)
+        updateNode(root)
+    }
+
+    private fun updateNode(root: TreeNode?) {
+        if (root == null) {
+            return
+        }
+        root.leftChar = root.left!!.leftChar
+        root.leftCharLen = root.left!!.leftCharLen
+        root.rightChar = root.right!!.rightChar
+        root.rightCharLen = root.right!!.rightCharLen
+        root.max = Math.max(root.left!!.max, root.right!!.max)
+        if (root.left!!.rightChar == root.right!!.leftChar) {
+            val len = root.left!!.rightCharLen + root.right!!.leftCharLen
+            if (root.left!!.leftChar == root.left!!.rightChar &&
+                root.left!!.leftCharLen == root.left!!.end - root.left!!.start + 1
+            ) {
+                root.leftCharLen = len
+            }
+            if (root.right!!.leftChar == root.right!!.rightChar &&
+                root.right!!.leftCharLen == root.right!!.end - root.right!!.start + 1
+            ) {
+                root.rightCharLen = len
+            }
+            root.max = Math.max(root.max, len)
+        }
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2215_find_the_difference_of_two_arrays/readme.md b/src/main/kotlin/g2201_2300/s2215_find_the_difference_of_two_arrays/readme.md
new file mode 100644
index 00000000..8bdab0a1
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2215_find_the_difference_of_two_arrays/readme.md
@@ -0,0 +1,72 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2215\. Find the Difference of Two Arrays
+
+Easy
+
+Given two **0-indexed** integer arrays `nums1` and `nums2`, return _a list_ `answer` _of size_ `2` _where:_
+
+*   `answer[0]` _is a list of all **distinct** integers in_ `nums1` _which are **not** present in_ `nums2`_._
+*   `answer[1]` _is a list of all **distinct** integers in_ `nums2` _which are **not** present in_ `nums1`.
+
+**Note** that the integers in the lists may be returned in **any** order.
+
+**Example 1:**
+
+**Input:** nums1 = [1,2,3], nums2 = [2,4,6]
+
+**Output:** [[1,3],[4,6]]
+
+**Explanation:**
+
+For nums1, nums1[1] = 2 is present at index 0 of nums2, whereas nums1[0] = 1 and nums1[2] = 3 are not present in nums2. Therefore, answer[0] = [1,3].
+
+For nums2, nums2[0] = 2 is present at index 1 of nums1, whereas nums2[1] = 4 and nums2[2] = 6 are not present in nums2. Therefore, answer[1] = [4,6].
+
+**Example 2:**
+
+**Input:** nums1 = [1,2,3,3], nums2 = [1,1,2,2]
+
+**Output:** [[3],[]]
+
+**Explanation:**
+
+For nums1, nums1[2] and nums1[3] are not present in nums2. Since nums1[2] == nums1[3], their value is only included once and answer[0] = [3].
+
+Every integer in nums2 is present in nums1. Therefore, answer[1] = []. 
+
+**Constraints:**
+
+*   `1 <= nums1.length, nums2.length <= 1000`
+*   `-1000 <= nums1[i], nums2[i] <= 1000`
+
+## Solution
+
+```kotlin
+class Solution {
+    fun findDifference(nums1: IntArray, nums2: IntArray): List> {
+        val set1 = createSet(nums1)
+        val set2 = createSet(nums2)
+        return listOf(getMissing(set1, set2), getMissing(set2, set1))
+    }
+
+    private fun createSet(array: IntArray): Set {
+        val set: MutableSet = HashSet()
+        for (x in array) {
+            set.add(x)
+        }
+        return set
+    }
+
+    private fun getMissing(first: Set, second: Set): List {
+        val list: MutableList = ArrayList()
+        for (x in first) {
+            if (!second.contains(x)) {
+                list.add(x)
+            }
+        }
+        return list
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2216_minimum_deletions_to_make_array_beautiful/readme.md b/src/main/kotlin/g2201_2300/s2216_minimum_deletions_to_make_array_beautiful/readme.md
new file mode 100644
index 00000000..659985c8
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2216_minimum_deletions_to_make_array_beautiful/readme.md
@@ -0,0 +1,63 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2216\. Minimum Deletions to Make Array Beautiful
+
+Medium
+
+You are given a **0-indexed** integer array `nums`. The array `nums` is **beautiful** if:
+
+*   `nums.length` is even.
+*   `nums[i] != nums[i + 1]` for all `i % 2 == 0`.
+
+Note that an empty array is considered beautiful.
+
+You can delete any number of elements from `nums`. When you delete an element, all the elements to the right of the deleted element will be **shifted one unit to the left** to fill the gap created and all the elements to the left of the deleted element will remain **unchanged**.
+
+Return _the **minimum** number of elements to delete from_ `nums` _to make it_ _beautiful._
+
+**Example 1:**
+
+**Input:** nums = [1,1,2,3,5]
+
+**Output:** 1
+
+**Explanation:** You can delete either `nums[0]` or `nums[1]` to make `nums` = [1,2,3,5] which is beautiful. It can be proven you need at least 1 deletion to make `nums` beautiful.
+
+**Example 2:**
+
+**Input:** nums = [1,1,2,2,3,3]
+
+**Output:** 2
+
+**Explanation:** You can delete `nums[0]` and `nums[5]` to make nums = [1,2,2,3] which is beautiful. It can be proven you need at least 2 deletions to make nums beautiful.
+
+**Constraints:**
+
+*   1 <= nums.length <= 105
+*   0 <= nums[i] <= 105
+
+## Solution
+
+```kotlin
+class Solution {
+    fun minDeletion(nums: IntArray): Int {
+        var offset = 0
+        var res = 0
+        var i = 0
+        while (i < nums.size) {
+            var j = i
+            while (j < nums.size - 1 && nums[j + 1] == nums[j] && (j - offset) % 2 == 0) {
+                offset++
+                res++
+                j++
+            }
+            i = j + 2
+        }
+        if ((nums.size - offset) % 2 != 0) {
+            res++
+        }
+        return res
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2217_find_palindrome_with_fixed_length/readme.md b/src/main/kotlin/g2201_2300/s2217_find_palindrome_with_fixed_length/readme.md
new file mode 100644
index 00000000..4eb4359f
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2217_find_palindrome_with_fixed_length/readme.md
@@ -0,0 +1,72 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2217\. Find Palindrome With Fixed Length
+
+Medium
+
+Given an integer array `queries` and a **positive** integer `intLength`, return _an array_ `answer` _where_ `answer[i]` _is either the_ queries[i]th _smallest **positive palindrome** of length_ `intLength` _or_ `-1` _if no such palindrome exists_.
+
+A **palindrome** is a number that reads the same backwards and forwards. Palindromes cannot have leading zeros.
+
+**Example 1:**
+
+**Input:** queries = [1,2,3,4,5,90], intLength = 3
+
+**Output:** [101,111,121,131,141,999]
+
+**Explanation:** 
+
+The first few palindromes of length 3 are: 
+
+101, 111, 121, 131, 141, 151, 161, 171, 181, 191, 202, ... 
+
+The 90th palindrome of length 3 is 999.
+
+**Example 2:**
+
+**Input:** queries = [2,4,6], intLength = 4
+
+**Output:** [1111,1331,1551]
+
+**Explanation:** 
+
+The first six palindromes of length 4 are: 
+
+1001, 1111, 1221, 1331, 1441, and 1551.
+
+**Constraints:**
+
+*   1 <= queries.length <= 5 * 104
+*   1 <= queries[i] <= 109
+*   `1 <= intLength <= 15`
+
+## Solution
+
+```kotlin
+class Solution {
+    fun kthPalindrome(queries: IntArray, intLength: Int): LongArray {
+        val minHalf = Math.pow(10.0, ((intLength - 1) / 2).toDouble()).toLong()
+        val maxIndex = Math.pow(10.0, ((intLength + 1) / 2).toDouble()).toLong() - minHalf
+        val isOdd = intLength % 2 == 1
+        val res = LongArray(queries.size)
+        for (i in res.indices) {
+            res[i] = if (queries[i] > maxIndex) -1 else helper(queries[i].toLong(), minHalf, isOdd)
+        }
+        return res
+    }
+
+    private fun helper(index: Long, minHalf: Long, isOdd: Boolean): Long {
+        var half = minHalf + index - 1
+        var res = half
+        if (isOdd) {
+            res /= 10
+        }
+        while (half != 0L) {
+            res = res * 10 + half % 10
+            half /= 10
+        }
+        return res
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2218_maximum_value_of_k_coins_from_piles/readme.md b/src/main/kotlin/g2201_2300/s2218_maximum_value_of_k_coins_from_piles/readme.md
new file mode 100644
index 00000000..145a1a3c
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2218_maximum_value_of_k_coins_from_piles/readme.md
@@ -0,0 +1,66 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2218\. Maximum Value of K Coins From Piles
+
+Hard
+
+There are `n` **piles** of coins on a table. Each pile consists of a **positive number** of coins of assorted denominations.
+
+In one move, you can choose any coin on **top** of any pile, remove it, and add it to your wallet.
+
+Given a list `piles`, where `piles[i]` is a list of integers denoting the composition of the ith pile from **top to bottom**, and a positive integer `k`, return _the **maximum total value** of coins you can have in your wallet if you choose **exactly**_ `k` _coins optimally_.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2019/11/09/e1.png)
+
+**Input:** piles = \[\[1,100,3],[7,8,9]], k = 2
+
+**Output:** 101
+
+**Explanation:** The above diagram shows the different ways we can choose k coins. 
+
+The maximum total we can obtain is 101.
+
+**Example 2:**
+
+**Input:** piles = \[\[100],[100],[100],[100],[100],[100],[1,1,1,1,1,1,700]], k = 7
+
+**Output:** 706
+
+**Explanation:** The maximum total can be obtained if we choose all coins from the last pile.
+
+**Constraints:**
+
+*   `n == piles.length`
+*   `1 <= n <= 1000`
+*   1 <= piles[i][j] <= 105
+*   `1 <= k <= sum(piles[i].length) <= 2000`
+
+## Solution
+
+```kotlin
+class Solution {
+    fun maxValueOfCoins(piles: List>, k: Int): Int {
+        var dp = IntArray(k + 1)
+        for (pile in piles) {
+            val m = pile.size
+            val cum = IntArray(m + 1)
+            for (i in 0 until m) {
+                cum[i + 1] = cum[i] + pile[i]
+            }
+            val curdp = IntArray(k + 1)
+            for (i in 0..k) {
+                var j = 0
+                while (j <= m && i + j <= k) {
+                    curdp[i + j] = Math.max(curdp[i + j], dp[i] + cum[j])
+                    j++
+                }
+            }
+            dp = curdp
+        }
+        return dp[k]
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2220_minimum_bit_flips_to_convert_number/readme.md b/src/main/kotlin/g2201_2300/s2220_minimum_bit_flips_to_convert_number/readme.md
new file mode 100644
index 00000000..4e81f111
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2220_minimum_bit_flips_to_convert_number/readme.md
@@ -0,0 +1,78 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2220\. Minimum Bit Flips to Convert Number
+
+Easy
+
+A **bit flip** of a number `x` is choosing a bit in the binary representation of `x` and **flipping** it from either `0` to `1` or `1` to `0`.
+
+*   For example, for `x = 7`, the binary representation is `111` and we may choose any bit (including any leading zeros not shown) and flip it. We can flip the first bit from the right to get `110`, flip the second bit from the right to get `101`, flip the fifth bit from the right (a leading zero) to get `10111`, etc.
+
+Given two integers `start` and `goal`, return _the **minimum** number of **bit flips** to convert_ `start` _to_ `goal`.
+
+**Example 1:**
+
+**Input:** start = 10, goal = 7
+
+**Output:** 3
+
+**Explanation:** The binary representation of 10 and 7 are 1010 and 0111 respectively. We can convert 10 to 7 in 3 steps: 
+
+- Flip the first bit from the right: 1010 -> 1011. 
+
+- Flip the third bit from the right: 1011 -> 1111\. 
+
+- Flip the fourth bit from the right: 1111 -> 0111\. 
+  
+It can be shown we cannot convert 10 to 7 in less than 3 steps. Hence, we return 3.
+
+**Example 2:**
+
+**Input:** start = 3, goal = 4
+
+**Output:** 3
+
+**Explanation:** The binary representation of 3 and 4 are 011 and 100 respectively. We can convert 3 to 4 in 3 steps: 
+
+- Flip the first bit from the right: 011 -> 010. 
+
+- Flip the second bit from the right: 010 -> 000\. 
+
+- Flip the third bit from the right: 000 -> 100\. 
+  
+It can be shown we cannot convert 3 to 4 in less than 3 steps. Hence, we return 3.
+
+**Constraints:**
+
+*   0 <= start, goal <= 109
+
+## Solution
+
+```kotlin
+@Suppress("NAME_SHADOWING")
+class Solution {
+    private fun decToBinary(n: Int): Int {
+        var n = n
+        val binaryNum = IntArray(32)
+        var i = 0
+        while (n > 0) {
+            binaryNum[i] = n % 2
+            n = n / 2
+            i++
+        }
+        var answer = 0
+        for (j in i - 1 downTo 0) {
+            if (binaryNum[j] == 1) {
+                answer++
+            }
+        }
+        return answer
+    }
+
+    fun minBitFlips(start: Int, goal: Int): Int {
+        val answer = start xor goal
+        return decToBinary(answer)
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2221_find_triangular_sum_of_an_array/readme.md b/src/main/kotlin/g2201_2300/s2221_find_triangular_sum_of_an_array/readme.md
new file mode 100644
index 00000000..7668edec
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2221_find_triangular_sum_of_an_array/readme.md
@@ -0,0 +1,57 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2221\. Find Triangular Sum of an Array
+
+Medium
+
+You are given a **0-indexed** integer array `nums`, where `nums[i]` is a digit between `0` and `9` (**inclusive**).
+
+The **triangular sum** of `nums` is the value of the only element present in `nums` after the following process terminates:
+
+1.  Let `nums` comprise of `n` elements. If `n == 1`, **end** the process. Otherwise, **create** a new **0-indexed** integer array `newNums` of length `n - 1`.
+2.  For each index `i`, where `0 <= i < n - 1`, **assign** the value of `newNums[i]` as `(nums[i] + nums[i+1]) % 10`, where `%` denotes modulo operator.
+3.  **Replace** the array `nums` with `newNums`.
+4.  **Repeat** the entire process starting from step 1.
+
+Return _the triangular sum of_ `nums`.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/02/22/ex1drawio.png)
+
+**Input:** nums = [1,2,3,4,5]
+
+**Output:** 8
+
+**Explanation:** The above diagram depicts the process from which we obtain the triangular sum of the array.
+
+**Example 2:**
+
+**Input:** nums = [5]
+
+**Output:** 5
+
+**Explanation:** Since there is only one element in nums, the triangular sum is the value of that element itself.
+
+**Constraints:**
+
+*   `1 <= nums.length <= 1000`
+*   `0 <= nums[i] <= 9`
+
+## Solution
+
+```kotlin
+class Solution {
+    fun triangularSum(nums: IntArray): Int {
+        var len = nums.size
+        while (len-- > 1) {
+            for (i in 0 until len) {
+                nums[i] += nums[i + 1]
+                nums[i] %= 10
+            }
+        }
+        return nums[0]
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2222_number_of_ways_to_select_buildings/readme.md b/src/main/kotlin/g2201_2300/s2222_number_of_ways_to_select_buildings/readme.md
new file mode 100644
index 00000000..a10e8c67
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2222_number_of_ways_to_select_buildings/readme.md
@@ -0,0 +1,79 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2222\. Number of Ways to Select Buildings
+
+Medium
+
+You are given a **0-indexed** binary string `s` which represents the types of buildings along a street where:
+
+*   `s[i] = '0'` denotes that the ith building is an office and
+*   `s[i] = '1'` denotes that the ith building is a restaurant.
+
+As a city official, you would like to **select** 3 buildings for random inspection. However, to ensure variety, **no two consecutive** buildings out of the **selected** buildings can be of the same type.
+
+*   For example, given `s = "0**0**1**1**0**1**"`, we cannot select the 1st, 3rd, and 5th buildings as that would form `"0**11**"` which is **not** allowed due to having two consecutive buildings of the same type.
+
+Return _the **number of valid ways** to select 3 buildings._
+
+**Example 1:**
+
+**Input:** s = "001101"
+
+**Output:** 6
+
+**Explanation:** The following sets of indices selected are valid: 
+
+- \[0,2,4] from "**0**0**1**1**0**1" forms "010" 
+
+- \[0,3,4] from "**0**01**10**1" forms "010" 
+
+- \[1,2,4] from "0**01**1**0**1" forms "010" 
+
+- \[1,3,4] from "0**0**1**10**1" forms "010" 
+
+- \[2,4,5] from "00**1**1**01**" forms "101" 
+
+- \[3,4,5] from "001**101**" forms "101" 
+  
+No other selection is valid. Thus, there are 6 total ways.
+
+**Example 2:**
+
+**Input:** s = "11100"
+
+**Output:** 0
+
+**Explanation:** It can be shown that there are no valid selections.
+
+**Constraints:**
+
+*   3 <= s.length <= 105
+*   `s[i]` is either `'0'` or `'1'`.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun numberOfWays(s: String): Long {
+        var z: Long = 0
+        var o: Long = 0
+        var zo: Long = 0
+        var oz: Long = 0
+        var zoz: Long = 0
+        var ozo: Long = 0
+        for (c in s.toCharArray()) {
+            if (c == '0') {
+                zoz += zo
+                oz += o
+                z++
+            } else {
+                ozo += oz
+                zo += z
+                o++
+            }
+        }
+        return zoz + ozo
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2223_sum_of_scores_of_built_strings/readme.md b/src/main/kotlin/g2201_2300/s2223_sum_of_scores_of_built_strings/readme.md
new file mode 100644
index 00000000..448c48f9
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2223_sum_of_scores_of_built_strings/readme.md
@@ -0,0 +1,86 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2223\. Sum of Scores of Built Strings
+
+Hard
+
+You are **building** a string `s` of length `n` **one** character at a time, **prepending** each new character to the **front** of the string. The strings are labeled from `1` to `n`, where the string with length `i` is labeled si.
+
+*   For example, for `s = "abaca"`, s1 == "a", s2 == "ca", s3 == "aca", etc.
+
+The **score** of si is the length of the **longest common prefix** between si and sn (Note that s == sn).
+
+Given the final string `s`, return _the **sum** of the **score** of every_ si.
+
+**Example 1:**
+
+**Input:** s = "babab"
+
+**Output:** 9
+
+**Explanation:** For s1 == "b", the longest common prefix is "b" which has a score of 1. 
+
+For s2 == "ab", there is no common prefix so the score is 0. 
+
+For s3 == "bab", the longest common prefix is "bab" which has a score of 3. 
+
+For s4 == "abab", there is no common prefix so the score is 0. 
+
+For s5 == "babab", the longest common prefix is "babab" which has a score of 5. 
+
+The sum of the scores is 1 + 0 + 3 + 0 + 5 = 9, so we return 9.
+
+**Example 2:**
+
+**Input:** s = "azbazbzaz"
+
+**Output:** 14
+
+**Explanation:** 
+
+For s2 == "az", the longest common prefix is "az" which has a score of 2. 
+
+For s6 == "azbzaz", the longest common prefix is "azb" which has a score of 3. 
+
+For s9 == "azbazbzaz", the longest common prefix is "azbazbzaz" which has a score of 9. 
+
+For all other si, the score is 0. 
+
+The sum of the scores is 2 + 3 + 9 = 14, so we return 14.
+
+**Constraints:**
+
+*   1 <= s.length <= 105
+*   `s` consists of lowercase English letters.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun sumScores(s: String): Long {
+        val n = s.length
+        val ss = s.toCharArray()
+        val z = IntArray(n)
+        var l = 0
+        var r = 0
+        for (i in 1 until n) {
+            if (i <= r) {
+                z[i] = Math.min(z[i - l], r - i + 1)
+            }
+            while (i + z[i] < n && ss[z[i]] == ss[i + z[i]]) {
+                z[i]++
+            }
+            if (i + z[i] - 1 > r) {
+                l = i
+                r = i + z[i] - 1
+            }
+        }
+        var sum = n.toLong()
+        for (i in 0 until n) {
+            sum += z[i].toLong()
+        }
+        return sum
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2224_minimum_number_of_operations_to_convert_time/readme.md b/src/main/kotlin/g2201_2300/s2224_minimum_number_of_operations_to_convert_time/readme.md
new file mode 100644
index 00000000..e83c7ec3
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2224_minimum_number_of_operations_to_convert_time/readme.md
@@ -0,0 +1,77 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2224\. Minimum Number of Operations to Convert Time
+
+Easy
+
+You are given two strings `current` and `correct` representing two **24-hour times**.
+
+24-hour times are formatted as `"HH:MM"`, where `HH` is between `00` and `23`, and `MM` is between `00` and `59`. The earliest 24-hour time is `00:00`, and the latest is `23:59`.
+
+In one operation you can increase the time `current` by `1`, `5`, `15`, or `60` minutes. You can perform this operation **any** number of times.
+
+Return _the **minimum number of operations** needed to convert_ `current` _to_ `correct`.
+
+**Example 1:**
+
+**Input:** current = "02:30", correct = "04:35"
+
+**Output:** 3
+
+**Explanation:** 
+
+We can convert current to correct in 3 operations as follows: 
+
+- Add 60 minutes to current. current becomes "03:30". 
+
+- Add 60 minutes to current. current becomes "04:30". 
+
+- Add 5 minutes to current. current becomes "04:35". 
+  
+It can be proven that it is not possible to convert current to correct in fewer than 3 operations.
+
+**Example 2:**
+
+**Input:** current = "11:00", correct = "11:01"
+
+**Output:** 1
+
+**Explanation:** We only have to add one minute to current, so the minimum number of operations needed is 1.
+
+**Constraints:**
+
+*   `current` and `correct` are in the format `"HH:MM"`
+*   `current <= correct`
+
+## Solution
+
+```kotlin
+class Solution {
+    private val duration = intArrayOf(60, 15, 5, 1)
+    private var c = 0
+
+    fun convertTime(current: String, correct: String): Int {
+        val dmin = correct.substring(3).toInt() - current.substring(3).toInt()
+        val dhour = correct.substring(0, 2).toInt() - current.substring(0, 2).toInt()
+        val min = dhour * 60 + dmin
+        dfs(0, min)
+        return c
+    }
+
+    private fun dfs(i: Int, amount: Int) {
+        if (i == 4) {
+            return
+        }
+        if (amount == 0) {
+            return
+        }
+        if (amount - duration[i] >= 0) {
+            c++
+            dfs(i, amount - duration[i])
+        } else {
+            dfs(i + 1, amount)
+        }
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2225_find_players_with_zero_or_one_losses/readme.md b/src/main/kotlin/g2201_2300/s2225_find_players_with_zero_or_one_losses/readme.md
new file mode 100644
index 00000000..27fa2c02
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2225_find_players_with_zero_or_one_losses/readme.md
@@ -0,0 +1,76 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2225\. Find Players With Zero or One Losses
+
+Medium
+
+You are given an integer array `matches` where matches[i] = [winneri, loseri] indicates that the player winneri defeated player loseri in a match.
+
+Return _a list_ `answer` _of size_ `2` _where:_
+
+*   `answer[0]` is a list of all players that have **not** lost any matches.
+*   `answer[1]` is a list of all players that have lost exactly **one** match.
+
+The values in the two lists should be returned in **increasing** order.
+
+**Note:**
+
+*   You should only consider the players that have played **at least one** match.
+*   The testcases will be generated such that **no** two matches will have the **same** outcome.
+
+**Example 1:**
+
+**Input:** matches = \[\[1,3],[2,3],[3,6],[5,6],[5,7],[4,5],[4,8],[4,9],[10,4],[10,9]]
+
+**Output:** [[1,2,10],[4,5,7,8]]
+
+**Explanation:** Players 1, 2, and 10 have not lost any matches. Players 4, 5, 7, and 8 each have lost one match. Players 3, 6, and 9 each have lost two matches. Thus, answer[0] = [1,2,10] and answer[1] = [4,5,7,8].
+
+**Example 2:**
+
+**Input:** matches = \[\[2,3],[1,3],[5,4],[6,4]]
+
+**Output:** [[1,2,5,6],[]]
+
+**Explanation:** Players 1, 2, 5, and 6 have not lost any matches. Players 3 and 4 each have lost two matches. Thus, answer[0] = [1,2,5,6] and answer[1] = [].
+
+**Constraints:**
+
+*   1 <= matches.length <= 105
+*   `matches[i].length == 2`
+*   1 <= winneri, loseri <= 105
+*   winneri != loseri
+*   All `matches[i]` are **unique**.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun findWinners(matches: Array): List> {
+        val map: MutableMap = HashMap()
+        val list1: MutableList = ArrayList()
+        val list2: MutableList = ArrayList()
+        val res: MutableList> = ArrayList()
+        for (match in matches) {
+            val winner = match[0]
+            val loser = match[1]
+            map.putIfAbsent(winner, 0)
+            map[loser] = map.getOrDefault(loser, 0) + 1
+        }
+        for ((key, value) in map) {
+            if (value == 0) {
+                list1.add(key)
+            }
+            if (value == 1) {
+                list2.add(key)
+            }
+        }
+        list1.sort()
+        list2.sort()
+        res.add(list1)
+        res.add(list2)
+        return res
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2226_maximum_candies_allocated_to_k_children/readme.md b/src/main/kotlin/g2201_2300/s2226_maximum_candies_allocated_to_k_children/readme.md
new file mode 100644
index 00000000..9c6baf8a
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2226_maximum_candies_allocated_to_k_children/readme.md
@@ -0,0 +1,78 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2226\. Maximum Candies Allocated to K Children
+
+Medium
+
+You are given a **0-indexed** integer array `candies`. Each element in the array denotes a pile of candies of size `candies[i]`. You can divide each pile into any number of **sub piles**, but you **cannot** merge two piles together.
+
+You are also given an integer `k`. You should allocate piles of candies to `k` children such that each child gets the **same** number of candies. Each child can take **at most one** pile of candies and some piles of candies may go unused.
+
+Return _the **maximum number of candies** each child can get._
+
+**Example 1:**
+
+**Input:** candies = [5,8,6], k = 3
+
+**Output:** 5
+
+**Explanation:** We can divide candies[1] into 2 piles of size 5 and 3, and candies[2] into 2 piles of size 5 and 1. We now have five piles of candies of sizes 5, 5, 3, 5, and 1. We can allocate the 3 piles of size 5 to 3 children. It can be proven that each child cannot receive more than 5 candies. 
+
+**Example 2:**
+
+**Input:** candies = [2,5], k = 11
+
+**Output:** 0
+
+**Explanation:** There are 11 children but only 7 candies in total, so it is impossible to ensure each child receives at least one candy. Thus, each child gets no candy and the answer is 0. 
+
+**Constraints:**
+
+*   1 <= candies.length <= 105
+*   1 <= candies[i] <= 107
+*   1 <= k <= 1012
+
+## Solution
+
+```kotlin
+@Suppress("NAME_SHADOWING")
+class Solution {
+    fun maximumCandies(candies: IntArray, k: Long): Int {
+        var max = Int.MIN_VALUE
+        var sum: Long = 0
+        for (num in candies) {
+            max = Math.max(max, num)
+            sum += num.toLong()
+        }
+        if (sum < k) {
+            return 0
+        }
+        var left = 1
+        var right = max
+        while (left < right) {
+            val mid = left + (right - left) / 2
+            if (canBeDistributed(mid, candies, k)) {
+                left = if (!canBeDistributed(mid + 1, candies, k)) {
+                    return mid
+                } else {
+                    mid + 1
+                }
+            } else {
+                right = mid - 1
+            }
+        }
+        return left
+    }
+
+    private fun canBeDistributed(num: Int, candies: IntArray, k: Long): Boolean {
+        var k = k
+        var i = 0
+        while (i < candies.size && k > 0) {
+            k -= (candies[i] / num).toLong()
+            ++i
+        }
+        return k <= 0
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2227_encrypt_and_decrypt_strings/readme.md b/src/main/kotlin/g2201_2300/s2227_encrypt_and_decrypt_strings/readme.md
new file mode 100644
index 00000000..81ec4879
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2227_encrypt_and_decrypt_strings/readme.md
@@ -0,0 +1,97 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2227\. Encrypt and Decrypt Strings
+
+Hard
+
+You are given a character array `keys` containing **unique** characters and a string array `values` containing strings of length 2. You are also given another string array `dictionary` that contains all permitted original strings after decryption. You should implement a data structure that can encrypt or decrypt a **0-indexed** string.
+
+A string is **encrypted** with the following process:
+
+1.  For each character `c` in the string, we find the index `i` satisfying `keys[i] == c` in `keys`.
+2.  Replace `c` with `values[i]` in the string.
+
+Note that in case a character of the string is **not present** in `keys`, the encryption process cannot be carried out, and an empty string `""` is returned.
+
+A string is **decrypted** with the following process:
+
+1.  For each substring `s` of length 2 occurring at an even index in the string, we find an `i` such that `values[i] == s`. If there are multiple valid `i`, we choose **any** one of them. This means a string could have multiple possible strings it can decrypt to.
+2.  Replace `s` with `keys[i]` in the string.
+
+Implement the `Encrypter` class:
+
+*   `Encrypter(char[] keys, String[] values, String[] dictionary)` Initializes the `Encrypter` class with `keys, values`, and `dictionary`.
+*   `String encrypt(String word1)` Encrypts `word1` with the encryption process described above and returns the encrypted string.
+*   `int decrypt(String word2)` Returns the number of possible strings `word2` could decrypt to that also appear in `dictionary`.
+
+**Example 1:**
+
+**Input** ["Encrypter", "encrypt", "decrypt"] [[['a', 'b', 'c', 'd'], ["ei", "zf", "ei", "am"], ["abcd", "acbd", "adbc", "badc", "dacb", "cadb", "cbda", "abad"]], ["abcd"], ["eizfeiam"]]
+
+**Output:** [null, "eizfeiam", 2]
+
+**Explanation:** Encrypter encrypter = new Encrypter([['a', 'b', 'c', 'd'], ["ei", "zf", "ei", "am"], ["abcd", "acbd", "adbc", "badc", "dacb", "cadb", "cbda", "abad"]); 
+
+encrypter.encrypt("abcd"); // return "eizfeiam". 
+                            // 'a' maps to "ei", 'b' maps to "zf", 'c' maps to "ei", and 'd' maps to "am". 
+
+encrypter.decrypt("eizfeiam"); // return 2. 
+                                // "ei" can map to 'a' or 'c', "zf" maps to 'b', and "am" maps to 'd'. 
+                                // Thus, the possible strings after decryption are "abad", "cbad", "abcd", and "cbcd". 
+                                // 2 of those strings, "abad" and "abcd", appear in dictionary, so the answer is 2.
+
+**Constraints:**
+
+*   `1 <= keys.length == values.length <= 26`
+*   `values[i].length == 2`
+*   `1 <= dictionary.length <= 100`
+*   `1 <= dictionary[i].length <= 100`
+*   All `keys[i]` and `dictionary[i]` are **unique**.
+*   `1 <= word1.length <= 2000`
+*   `1 <= word2.length <= 200`
+*   All `word1[i]` appear in `keys`.
+*   `word2.length` is even.
+*   `keys`, `values[i]`, `dictionary[i]`, `word1`, and `word2` only contain lowercase English letters.
+*   At most `200` calls will be made to `encrypt` and `decrypt` **in total**.
+
+## Solution
+
+```kotlin
+class Encrypter(keys: CharArray, values: Array, dictionary: Array) {
+    private val eMap: MutableMap
+    private val dMap: MutableMap
+
+    init {
+        eMap = HashMap()
+        dMap = HashMap()
+        for (i in keys.indices) {
+            eMap[keys[i]] = values[i]
+        }
+        for (s in dictionary) {
+            val str = encrypt(s)
+            if (str != "" && str != "null") {
+                dMap[str] = dMap.getOrDefault(str, 0) + 1
+            }
+        }
+    }
+
+    fun encrypt(word1: String): String {
+        val sb = StringBuilder()
+        for (c in word1.toCharArray()) {
+            sb.append(eMap[c])
+        }
+        return sb.toString()
+    }
+
+    fun decrypt(word2: String): Int {
+        return dMap.getOrDefault(word2, 0)
+    }
+}
+/*
+ * Your Encrypter object will be instantiated and called as such:
+ * var obj = Encrypter(keys, values, dictionary)
+ * var param_1 = obj.encrypt(word1)
+ * var param_2 = obj.decrypt(word2)
+ */
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2231_largest_number_after_digit_swaps_by_parity/readme.md b/src/main/kotlin/g2201_2300/s2231_largest_number_after_digit_swaps_by_parity/readme.md
new file mode 100644
index 00000000..5b36bea3
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2231_largest_number_after_digit_swaps_by_parity/readme.md
@@ -0,0 +1,78 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2231\. Largest Number After Digit Swaps by Parity
+
+Easy
+
+You are given a positive integer `num`. You may swap any two digits of `num` that have the same **parity** (i.e. both odd digits or both even digits).
+
+Return _the **largest** possible value of_ `num` _after **any** number of swaps._
+
+**Example 1:**
+
+**Input:** num = 1234
+
+**Output:** 3412
+
+**Explanation:** Swap the digit 3 with the digit 1, this results in the number 3214.
+
+Swap the digit 2 with the digit 4, this results in the number 3412.
+
+Note that there may be other sequences of swaps but it can be shown that 3412 is the largest possible number.
+
+Also note that we may not swap the digit 4 with the digit 1 since they are of different parities. 
+
+**Example 2:**
+
+**Input:** num = 65875
+
+**Output:** 87655
+
+**Explanation:** Swap the digit 8 with the digit 6, this results in the number 85675.
+
+Swap the first digit 5 with the digit 7, this results in the number 87655.
+
+Note that there may be other sequences of swaps but it can be shown that 87655 is the largest possible number. 
+
+**Constraints:**
+
+*   1 <= num <= 109
+
+## Solution
+
+```kotlin
+class Solution {
+    fun largestInteger(num: Int): Int {
+        val str = num.toString().toCharArray()
+        var temp: Char
+        for (i in str.indices) {
+            temp = str[i]
+            var swapIndex = i
+            val even = str[i].code % 2 == 0
+            var max = Int.MIN_VALUE
+            if (even) {
+                for (j in i + 1 until str.size) {
+                    if (str[j].code % 2 == 0 && str[j] > str[i] && str[j].code > max) {
+                        max = str[j].code
+                        temp = str[j]
+                        swapIndex = j
+                    }
+                }
+            } else {
+                for (j in i + 1 until str.size) {
+                    if (str[j].code % 2 != 0 && str[j] > str[i] && str[j].code > max) {
+                        max = str[j].code
+                        temp = str[j]
+                        swapIndex = j
+                    }
+                }
+            }
+            val tempStr = str[i]
+            str[i] = temp
+            str[swapIndex] = tempStr
+        }
+        return Integer.valueOf(String(str))
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2232_minimize_result_by_adding_parentheses_to_expression/readme.md b/src/main/kotlin/g2201_2300/s2232_minimize_result_by_adding_parentheses_to_expression/readme.md
new file mode 100644
index 00000000..547e367a
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2232_minimize_result_by_adding_parentheses_to_expression/readme.md
@@ -0,0 +1,136 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2232\. Minimize Result by Adding Parentheses to Expression
+
+Medium
+
+You are given a **0-indexed** string `expression` of the form `"+"` where `` and `` represent positive integers.
+
+Add a pair of parentheses to `expression` such that after the addition of parentheses, `expression` is a **valid** mathematical expression and evaluates to the **smallest** possible value. The left parenthesis **must** be added to the left of `'+'` and the right parenthesis **must** be added to the right of `'+'`.
+
+Return `expression` _after adding a pair of parentheses such that_ `expression` _evaluates to the **smallest** possible value._ If there are multiple answers that yield the same result, return any of them.
+
+The input has been generated such that the original value of `expression`, and the value of `expression` after adding any pair of parentheses that meets the requirements fits within a signed 32-bit integer.
+
+**Example 1:**
+
+**Input:** expression = "247+38"
+
+**Output:** "2(47+38)"
+
+**Explanation:** The `expression` evaluates to 2 \* (47 + 38) = 2 \* 85 = 170.
+
+Note that "2(4)7+38" is invalid because the right parenthesis must be to the right of the `'+'`.
+
+It can be shown that 170 is the smallest possible value. 
+
+**Example 2:**
+
+**Input:** expression = "12+34"
+
+**Output:** "1(2+3)4"
+
+**Explanation:** The expression evaluates to 1 \* (2 + 3) \* 4 = 1 \* 5 \* 4 = 20. 
+
+**Example 3:**
+
+**Input:** expression = "999+999"
+
+**Output:** "(999+999)"
+
+**Explanation:** The `expression` evaluates to 999 + 999 = 1998. 
+
+**Constraints:**
+
+*   `3 <= expression.length <= 10`
+*   `expression` consists of digits from `'1'` to `'9'` and `'+'`.
+*   `expression` starts and ends with digits.
+*   `expression` contains exactly one `'+'`.
+*   The original value of `expression`, and the value of `expression` after adding any pair of parentheses that meets the requirements fits within a signed 32-bit integer.
+
+## Solution
+
+```kotlin
+class Solution {
+    // Variables for final solution, to avoid create combination Strings
+    private var currentLeft = 0
+    private var currentRight = 0
+    private var currentMin = Int.MAX_VALUE
+    fun minimizeResult(expression: String): String {
+        // Identify our starting point, to apply the expansion technique
+        val plusIndex = expression.indexOf("+")
+        // We start expanding from the first values to the left and right of the center (plus sign).
+        expand(plusIndex - 1, plusIndex + 1, expression)
+        // Build the final String. We add the parentheses to our expression in the already
+        // calculated indices, defined as global variables.
+        val stringBuilder = StringBuilder()
+        for (i in 0 until expression.length) {
+            if (i == currentLeft) {
+                stringBuilder.append('(')
+            }
+            stringBuilder.append(expression[i])
+            if (i == currentRight) {
+                stringBuilder.append(')')
+            }
+        }
+        return stringBuilder.toString()
+    }
+
+    // With this function, we calculate all possible combinations of parentheses from two pointers,
+    // left and right.
+    private fun expand(left: Int, right: Int, expression: String) {
+        if (left < 0 || right >= expression.length) {
+            return
+        }
+        // from zero to first parentheses
+        val a = evaluate(0, left, expression)
+        // from first parentheses to right parentheses (+1 means inclusive)
+        val b = evaluate(left, right + 1, expression)
+        // from right parentheses to the end of expression (+1 means inclusive)
+        val c = evaluate(right + 1, expression.length, expression)
+        // If the expression a * b * c is less than our current minimum
+        // this is our solution, we replace the variables with these new values.
+        if (a * b * c < currentMin) {
+            currentMin = a * b * c
+            currentLeft = left
+            currentRight = right
+        }
+        // Move parentheses left only
+        expand(left - 1, right, expression)
+        // Move parentheses right only
+        expand(left, right + 1, expression)
+        // Move parentheses left and right
+        expand(left - 1, right + 1, expression)
+    }
+
+    /* This function is responsible for calculating the expressions of each variable.
+
+    a = (0, left) // from the start of the expression to the first parentheses
+    b = (left, right) // between parentheses, include plus sign
+    c = (right, end of expression) // from the last parentheses to the end
+    */
+    private fun evaluate(left: Int, right: Int, expression: String): Int {
+        // This means that the parentheses are at the beginning or end of the expression and are
+        // equal to the range of the expression to be evaluated. Return 1 to avoid zero factors in
+        // equation (a * b * c).
+        if (left == right) {
+            return 1
+        }
+        var number = 0
+        for (i in left until right) {
+            // If we find a sign, we must add both parts, therefore, we convert the expression to (a
+            // + b).
+            // We return the variable (a) wich is (number) and add to what follows after the sign (i
+            // + 1).
+            // We call the same function to calculate the b value.
+            number = if (expression[i] == '+') {
+                return number + evaluate(i + 1, right, expression)
+            } else {
+                number * 10 + (expression[i].code - '0'.code)
+            }
+        }
+        return number
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2233_maximum_product_after_k_increments/readme.md b/src/main/kotlin/g2201_2300/s2233_maximum_product_after_k_increments/readme.md
new file mode 100644
index 00000000..7f70441b
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2233_maximum_product_after_k_increments/readme.md
@@ -0,0 +1,69 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2233\. Maximum Product After K Increments
+
+Medium
+
+You are given an array of non-negative integers `nums` and an integer `k`. In one operation, you may choose **any** element from `nums` and **increment** it by `1`.
+
+Return _the **maximum** **product** of_ `nums` _after **at most**_ `k` _operations._ Since the answer may be very large, return it **modulo** 109 + 7. Note that you should maximize the product before taking the modulo.
+
+**Example 1:**
+
+**Input:** nums = [0,4], k = 5
+
+**Output:** 20
+
+**Explanation:** Increment the first number 5 times.
+
+Now nums = [5, 4], with a product of 5 \* 4 = 20.
+
+It can be shown that 20 is maximum product possible, so we return 20.
+
+Note that there may be other ways to increment nums to have the maximum product.
+
+**Example 2:**
+
+**Input:** nums = [6,3,3,2], k = 2
+
+**Output:** 216
+
+**Explanation:** Increment the second number 1 time and increment the fourth number 1 time.
+
+Now nums = [6, 4, 3, 3], with a product of 6 \* 4 \* 3 \* 3 = 216.
+
+It can be shown that 216 is maximum product possible, so we return 216.
+
+Note that there may be other ways to increment nums to have the maximum product.
+
+**Constraints:**
+
+*   1 <= nums.length, k <= 105
+*   0 <= nums[i] <= 106
+
+## Solution
+
+```kotlin
+import java.util.PriorityQueue
+
+@Suppress("NAME_SHADOWING")
+class Solution {
+    fun maximumProduct(nums: IntArray, k: Int): Int {
+        var k = k
+        val pq = PriorityQueue()
+        for (num in nums) {
+            pq.add(num)
+        }
+        while (k-- > 0) {
+            pq.add(pq.poll() + 1)
+        }
+        var ans: Long = 1
+        val mod = 1000000007
+        while (pq.isNotEmpty()) {
+            ans = ans * pq.poll() % mod
+        }
+        return ans.toInt()
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2234_maximum_total_beauty_of_the_gardens/readme.md b/src/main/kotlin/g2201_2300/s2234_maximum_total_beauty_of_the_gardens/readme.md
new file mode 100644
index 00000000..9e5ccba3
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2234_maximum_total_beauty_of_the_gardens/readme.md
@@ -0,0 +1,120 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2234\. Maximum Total Beauty of the Gardens
+
+Hard
+
+Alice is a caretaker of `n` gardens and she wants to plant flowers to maximize the total beauty of all her gardens.
+
+You are given a **0-indexed** integer array `flowers` of size `n`, where `flowers[i]` is the number of flowers already planted in the ith garden. Flowers that are already planted **cannot** be removed. You are then given another integer `newFlowers`, which is the **maximum** number of flowers that Alice can additionally plant. You are also given the integers `target`, `full`, and `partial`.
+
+A garden is considered **complete** if it has **at least** `target` flowers. The **total beauty** of the gardens is then determined as the **sum** of the following:
+
+*   The number of **complete** gardens multiplied by `full`.
+*   The **minimum** number of flowers in any of the **incomplete** gardens multiplied by `partial`. If there are no incomplete gardens, then this value will be `0`.
+
+Return _the **maximum** total beauty that Alice can obtain after planting at most_ `newFlowers` _flowers._
+
+**Example 1:**
+
+**Input:** flowers = [1,3,1,1], newFlowers = 7, target = 6, full = 12, partial = 1
+
+**Output:** 14
+
+**Explanation:** Alice can plant
+
+- 2 flowers in the 0th garden
+
+- 3 flowers in the 1st garden
+
+- 1 flower in the 2nd garden
+
+- 1 flower in the 3rd garden
+
+The gardens will then be [3,6,2,2]. She planted a total of 2 + 3 + 1 + 1 = 7 flowers.
+
+There is 1 garden that is complete.
+
+The minimum number of flowers in the incomplete gardens is 2.
+
+Thus, the total beauty is 1 \* 12 + 2 \* 1 = 12 + 2 = 14.
+
+No other way of planting flowers can obtain a total beauty higher than 14. 
+
+**Example 2:**
+
+**Input:** flowers = [2,4,5,3], newFlowers = 10, target = 5, full = 2, partial = 6
+
+**Output:** 30
+
+**Explanation:** Alice can plant
+
+- 3 flowers in the 0th garden
+
+- 0 flowers in the 1st garden
+
+- 0 flowers in the 2nd garden
+
+- 2 flowers in the 3rd garden
+
+The gardens will then be [5,4,5,5]. She planted a total of 3 + 0 + 0 + 2 = 5 flowers.
+
+There are 3 gardens that are complete.
+
+The minimum number of flowers in the incomplete gardens is 4.
+
+Thus, the total beauty is 3 \* 2 + 4 \* 6 = 6 + 24 = 30.
+
+No other way of planting flowers can obtain a total beauty higher than 30.
+
+Note that Alice could make all the gardens complete but in this case, she would obtain a lower total beauty. 
+
+**Constraints:**
+
+*   1 <= flowers.length <= 105
+*   1 <= flowers[i], target <= 105
+*   1 <= newFlowers <= 1010
+*   1 <= full, partial <= 105
+
+## Solution
+
+```kotlin
+class Solution {
+    fun maximumBeauty(flowers: IntArray, newFlowers: Long, target: Int, full: Int, partial: Int): Long {
+        val n = flowers.size
+        val prefix = LongArray(n + 1)
+        flowers.sort()
+        for (i in 0 until n) {
+            prefix[i + 1] = prefix[i] + Math.min(flowers[i], target)
+        }
+        var res: Long = 0
+        var i = n - 1
+        for (c in 0..n) {
+            val remain = prefix[n] - prefix[n - c] + newFlowers - c * target.toLong()
+            var min: Long = 0
+            if (0 > remain) {
+                break
+            }
+            i = Math.min(i, n - c - 1)
+            while (0 <= i &&
+                (
+                    target <= flowers[i] ||
+                        flowers[i] * (i + 1).toLong() - prefix[i + 1] > remain
+                    )
+            ) {
+                i--
+            }
+            if (0 <= i) {
+                val dif = flowers[i] * (i + 1).toLong() - prefix[i + 1]
+                min = Math.min(target - 1L, flowers[i] + (remain - dif) / (i + 1))
+                if (i + 1 < n - c) {
+                    min = Math.min(min, flowers[i + 1].toLong())
+                }
+            }
+            res = Math.max(res, c * full.toLong() + min * partial)
+        }
+        return res
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2235_add_two_integers/readme.md b/src/main/kotlin/g2201_2300/s2235_add_two_integers/readme.md
new file mode 100644
index 00000000..9dadd9a4
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2235_add_two_integers/readme.md
@@ -0,0 +1,38 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2235\. Add Two Integers
+
+Easy
+
+Given two integers `num1` and `num2`, return _the **sum** of the two integers_.
+
+**Example 1:**
+
+**Input:** num1 = 12, num2 = 5
+
+**Output:** 17
+
+**Explanation:** num1 is 12, num2 is 5, and their sum is 12 + 5 = 17, so 17 is returned.
+
+**Example 2:**
+
+**Input:** num1 = -10, num2 = 4
+
+**Output:** -6
+
+**Explanation:** num1 + num2 = -6, so -6 is returned.
+
+**Constraints:**
+
+* `-100 <= num1, num2 <= 100`
+
+## Solution
+
+```kotlin
+class Solution {
+    fun sum(num1: Int, num2: Int): Int {
+        return num1 + num2
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2236_root_equals_sum_of_children/readme.md b/src/main/kotlin/g2201_2300/s2236_root_equals_sum_of_children/readme.md
new file mode 100644
index 00000000..a97e4de7
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2236_root_equals_sum_of_children/readme.md
@@ -0,0 +1,61 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2236\. Root Equals Sum of Children
+
+Easy
+
+You are given the `root` of a **binary tree** that consists of exactly `3` nodes: the root, its left child, and its right child.
+
+Return `true` _if the value of the root is equal to the **sum** of the values of its two children, or_ `false` _otherwise_.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/04/08/graph3drawio.png)
+
+**Input:** root = [10,4,6]
+
+**Output:** true
+
+**Explanation:** The values of the root, its left child, and its right child are 10, 4, and 6, respectively. 
+
+10 is equal to 4 + 6, so we return true.
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2022/04/08/graph3drawio-1.png)
+
+**Input:** root = [5,3,1]
+
+**Output:** false
+
+**Explanation:** The values of the root, its left child, and its right child are 5, 3, and 1, respectively. 
+
+5 is not equal to 3 + 1, so we return false.
+
+**Constraints:**
+
+* The tree consists only of the root, its left child, and its right child.
+* `-100 <= Node.val <= 100`
+
+## Solution
+
+```kotlin
+import com_github_leetcode.TreeNode
+
+/*
+ * Example:
+ * var ti = TreeNode(5)
+ * var v = ti.`val`
+ * Definition for a binary tree node.
+ * class TreeNode(var `val`: Int) {
+ *     var left: TreeNode? = null
+ *     var right: TreeNode? = null
+ * }
+ */
+class Solution {
+    fun checkTree(root: TreeNode): Boolean {
+        return root.left!!.`val` + root.right!!.`val` == root.`val`
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2239_find_closest_number_to_zero/readme.md b/src/main/kotlin/g2201_2300/s2239_find_closest_number_to_zero/readme.md
new file mode 100644
index 00000000..b1c8de02
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2239_find_closest_number_to_zero/readme.md
@@ -0,0 +1,59 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2239\. Find Closest Number to Zero
+
+Easy
+
+Given an integer array `nums` of size `n`, return _the number with the value **closest** to_ `0` _in_ `nums`. If there are multiple answers, return _the number with the **largest** value_.
+
+**Example 1:**
+
+**Input:** nums = [-4,-2,1,4,8]
+
+**Output:** 1
+
+**Explanation:** 
+
+The distance from -4 to 0 is \|-4\| = 4. 
+
+The distance from -2 to 0 is \|-2\| = 2. 
+
+The distance from 1 to 0 is \|1\| = 1. The distance from 4 to 0 is \|4\| = 4. 
+
+The distance from 8 to 0 is \|8\| = 8. 
+
+Thus, the closest number to 0 in the array is 1. 
+
+**Example 2:**
+
+**Input:** nums = [2,-1,1]
+
+**Output:** 1
+
+**Explanation:** 1 and -1 are both the closest numbers to 0, so 1 being larger is returned. 
+
+**Constraints:**
+
+*   `1 <= n <= 1000`
+*   -105 <= nums[i] <= 105
+
+## Solution
+
+```kotlin
+class Solution {
+    fun findClosestNumber(nums: IntArray): Int {
+        var mini = Int.MAX_VALUE
+        var closestNum = 0
+        for (n in nums) {
+            if (mini > Math.abs(n)) {
+                mini = Math.abs(n)
+                closestNum = n
+            } else if (mini == Math.abs(n) && closestNum < n) {
+                closestNum = n
+            }
+        }
+        return closestNum
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2240_number_of_ways_to_buy_pens_and_pencils/readme.md b/src/main/kotlin/g2201_2300/s2240_number_of_ways_to_buy_pens_and_pencils/readme.md
new file mode 100644
index 00000000..2d4a14d2
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2240_number_of_ways_to_buy_pens_and_pencils/readme.md
@@ -0,0 +1,55 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2240\. Number of Ways to Buy Pens and Pencils
+
+Medium
+
+You are given an integer `total` indicating the amount of money you have. You are also given two integers `cost1` and `cost2` indicating the price of a pen and pencil respectively. You can spend **part or all** of your money to buy multiple quantities (or none) of each kind of writing utensil.
+
+Return _the **number of distinct ways** you can buy some number of pens and pencils._
+
+**Example 1:**
+
+**Input:** total = 20, cost1 = 10, cost2 = 5
+
+**Output:** 9
+
+**Explanation:** The price of a pen is 10 and the price of a pencil is 5. 
+
+- If you buy 0 pens, you can buy 0, 1, 2, 3, or 4 pencils. 
+
+- If you buy 1 pen, you can buy 0, 1, or 2 pencils. 
+
+- If you buy 2 pens, you cannot buy any pencils. 
+  
+The total number of ways to buy pens and pencils is 5 + 3 + 1 = 9.
+
+**Example 2:**
+
+**Input:** total = 5, cost1 = 10, cost2 = 10
+
+**Output:** 1
+
+**Explanation:** The price of both pens and pencils are 10, which cost more than total, so you cannot buy any writing utensils. Therefore, there is only 1 way: buy 0 pens and 0 pencils.
+
+**Constraints:**
+
+*   1 <= total, cost1, cost2 <= 106
+
+## Solution
+
+```kotlin
+class Solution {
+    fun waysToBuyPensPencils(total: Int, cost1: Int, cost2: Int): Long {
+        var ways: Long = 0
+        var cntPen = 0
+        while (cntPen * cost1 <= total) {
+            val remMoney = total - cntPen * cost1
+            ways += (remMoney / cost2 + 1).toLong()
+            cntPen++
+        }
+        return ways
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2241_design_an_atm_machine/readme.md b/src/main/kotlin/g2201_2300/s2241_design_an_atm_machine/readme.md
new file mode 100644
index 00000000..52947831
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2241_design_an_atm_machine/readme.md
@@ -0,0 +1,99 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2241\. Design an ATM Machine
+
+Medium
+
+There is an ATM machine that stores banknotes of `5` denominations: `20`, `50`, `100`, `200`, and `500` dollars. Initially the ATM is empty. The user can use the machine to deposit or withdraw any amount of money.
+
+When withdrawing, the machine prioritizes using banknotes of **larger** values.
+
+*   For example, if you want to withdraw `$300` and there are `2` `$50` banknotes, `1` `$100` banknote, and `1` `$200` banknote, then the machine will use the `$100` and `$200` banknotes.
+*   However, if you try to withdraw `$600` and there are `3` `$200` banknotes and `1` `$500` banknote, then the withdraw request will be rejected because the machine will first try to use the `$500` banknote and then be unable to use banknotes to complete the remaining `$100`. Note that the machine is **not** allowed to use the `$200` banknotes instead of the `$500` banknote.
+
+Implement the ATM class:
+
+*   `ATM()` Initializes the ATM object.
+*   `void deposit(int[] banknotesCount)` Deposits new banknotes in the order `$20`, `$50`, `$100`, `$200`, and `$500`.
+*   `int[] withdraw(int amount)` Returns an array of length `5` of the number of banknotes that will be handed to the user in the order `$20`, `$50`, `$100`, `$200`, and `$500`, and update the number of banknotes in the ATM after withdrawing. Returns `[-1]` if it is not possible (do **not** withdraw any banknotes in this case).
+
+**Example 1:**
+
+**Input**
+
+["ATM", "deposit", "withdraw", "deposit", "withdraw", "withdraw"]
+
+[[], [[0,0,1,2,1]], [600], [[0,1,0,1,1]], [600], [550]]
+
+**Output:** [null, null, [0,0,1,0,1], null, [-1], [0,1,0,0,1]]
+
+**Explanation:**
+
+    ATM atm = new ATM();
+    atm.deposit([0,0,1,2,1]); // Deposits 1 $100 banknote, 2 $200 banknotes,
+                              // and 1 $500 banknote.
+    atm.withdraw(600);        // Returns [0,0,1,0,1]. The machine uses 1 $100 banknote
+                              // and 1 $500 banknote. The banknotes left over in the
+                              // machine are [0,0,0,2,0].
+    atm.deposit([0,1,0,1,1]); // Deposits 1 $50, $200, and $500 banknote.
+                              // The banknotes in the machine are now [0,1,0,3,1].
+    atm.withdraw(600);        // Returns [-1]. The machine will try to use a $500 banknote
+                              // and then be unable to complete the remaining $100,
+                              // so the withdraw request will be rejected.
+                              // Since the request is rejected, the number of banknotes
+                              // in the machine is not modified.
+    atm.withdraw(550);        // Returns [0,1,0,0,1]. The machine uses 1 $50 banknote
+                              // and 1 $500 banknote.
+
+**Constraints:**
+
+*   `banknotesCount.length == 5`
+*   0 <= banknotesCount[i] <= 109
+*   1 <= amount <= 109
+*   At most `5000` calls **in total** will be made to `withdraw` and `deposit`.
+*   At least **one** call will be made to each function `withdraw` and `deposit`.
+
+## Solution
+
+```kotlin
+class ATM {
+    private val nominals: IntArray = intArrayOf(20, 50, 100, 200, 500)
+    private val counts: LongArray = LongArray(5)
+
+    fun deposit(banknotesCount: IntArray) {
+        for (i in 0..4) {
+            counts[i] += banknotesCount[i].toLong()
+        }
+    }
+
+    fun withdraw(amount: Int): IntArray {
+        val delivery = IntArray(5)
+        var currentAmount = amount.toLong()
+        for (i in 4 downTo 0) {
+            if (currentAmount > nominals[i] * counts[i]) {
+                delivery[i] = counts[i].toInt()
+            } else {
+                delivery[i] = currentAmount.toInt() / nominals[i]
+            }
+            currentAmount += -nominals[i].toLong() * delivery[i]
+            if (currentAmount == 0L) {
+                break
+            }
+        }
+        if (currentAmount > 0) {
+            return intArrayOf(-1)
+        }
+        for (i in 0..4) {
+            counts[i] += -delivery[i].toLong()
+        }
+        return delivery
+    }
+}
+/*
+ * Your ATM object will be instantiated and called as such:
+ * var obj = ATM()
+ * obj.deposit(banknotesCount)
+ * var param_2 = obj.withdraw(amount)
+ */
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2242_maximum_score_of_a_node_sequence/readme.md b/src/main/kotlin/g2201_2300/s2242_maximum_score_of_a_node_sequence/readme.md
new file mode 100644
index 00000000..d183c199
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2242_maximum_score_of_a_node_sequence/readme.md
@@ -0,0 +1,132 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2242\. Maximum Score of a Node Sequence
+
+Hard
+
+There is an **undirected** graph with `n` nodes, numbered from `0` to `n - 1`.
+
+You are given a **0-indexed** integer array `scores` of length `n` where `scores[i]` denotes the score of node `i`. You are also given a 2D integer array `edges` where edges[i] = [ai, bi] denotes that there exists an **undirected** edge connecting nodes ai and bi.
+
+A node sequence is **valid** if it meets the following conditions:
+
+*   There is an edge connecting every pair of **adjacent** nodes in the sequence.
+*   No node appears more than once in the sequence.
+
+The score of a node sequence is defined as the **sum** of the scores of the nodes in the sequence.
+
+Return _the **maximum score** of a valid node sequence with a length of_ `4`_._ If no such sequence exists, return `-1`.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/04/15/ex1new3.png)
+
+**Input:** scores = [5,2,9,8,4], edges = \[\[0,1],[1,2],[2,3],[0,2],[1,3],[2,4]]
+
+**Output:** 24
+
+**Explanation:** The figure above shows the graph and the chosen node sequence [0,1,2,3].
+
+The score of the node sequence is 5 + 2 + 9 + 8 = 24.
+
+It can be shown that no other node sequence has a score of more than 24.
+
+Note that the sequences [3,1,2,0] and [1,0,2,3] are also valid and have a score of 24.
+
+The sequence [0,3,2,4] is not valid since no edge connects nodes 0 and 3. 
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2022/03/17/ex2.png)
+
+**Input:** scores = [9,20,6,4,11,12], edges = \[\[0,3],[5,3],[2,4],[1,3]]
+
+**Output:** -1
+
+**Explanation:** The figure above shows the graph.
+
+There are no valid node sequences of length 4, so we return -1. 
+
+**Constraints:**
+
+*   `n == scores.length`
+*   4 <= n <= 5 * 104
+*   1 <= scores[i] <= 108
+*   0 <= edges.length <= 5 * 104
+*   `edges[i].length == 2`
+*   0 <= ai, bi <= n - 1
+*   ai != bi
+*   There are no duplicate edges.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun maximumScore(scores: IntArray, edges: Array): Int {
+        // store only top 3 nodes (having highest scores)
+        val graph = Array(scores.size) { IntArray(3) }
+        for (a in graph) {
+            a.fill(-1)
+        }
+        for (edge in edges) {
+            insert(edge[0], graph[edge[1]], scores)
+            insert(edge[1], graph[edge[0]], scores)
+        }
+        var maxScore = -1
+        for (edge in edges) {
+            val u = edge[0]
+            val v = edge[1]
+            val score = scores[u] + scores[v]
+            for (i in 0..2) {
+                // if neighbour is current node, skip
+                if (graph[u][i] == -1 || graph[u][i] == v) {
+                    continue
+                }
+                for (j in 0..2) {
+                    // if neighbour is current node or already choosen node, skip
+                    if (graph[v][j] == -1 || graph[v][j] == u) {
+                        continue
+                    }
+                    if (graph[v][j] == graph[u][i]) {
+                        continue
+                    }
+                    maxScore = Math.max(maxScore, score + scores[graph[u][i]] + scores[graph[v][j]])
+                }
+            }
+        }
+        return maxScore
+    }
+
+    private fun insert(n: Int, arr: IntArray, scores: IntArray) {
+        if (arr[0] == -1) {
+            arr[0] = n
+        } else if (arr[1] == -1) {
+            if (scores[arr[0]] < scores[n]) {
+                arr[1] = arr[0]
+                arr[0] = n
+            } else {
+                arr[1] = n
+            }
+        } else if (arr[2] == -1) {
+            if (scores[arr[0]] < scores[n]) {
+                arr[2] = arr[1]
+                arr[1] = arr[0]
+                arr[0] = n
+            } else if (scores[arr[1]] < scores[n]) {
+                arr[2] = arr[1]
+                arr[1] = n
+            } else {
+                arr[2] = n
+            }
+        } else {
+            if (scores[arr[1]] < scores[n]) {
+                arr[2] = arr[1]
+                arr[1] = n
+            } else if (scores[arr[2]] < scores[n]) {
+                arr[2] = n
+            }
+        }
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2243_calculate_digit_sum_of_a_string/readme.md b/src/main/kotlin/g2201_2300/s2243_calculate_digit_sum_of_a_string/readme.md
new file mode 100644
index 00000000..516fa2ca
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2243_calculate_digit_sum_of_a_string/readme.md
@@ -0,0 +1,87 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2243\. Calculate Digit Sum of a String
+
+Easy
+
+You are given a string `s` consisting of digits and an integer `k`.
+
+A **round** can be completed if the length of `s` is greater than `k`. In one round, do the following:
+
+1.  **Divide** `s` into **consecutive groups** of size `k` such that the first `k` characters are in the first group, the next `k` characters are in the second group, and so on. **Note** that the size of the last group can be smaller than `k`.
+2.  **Replace** each group of `s` with a string representing the sum of all its digits. For example, `"346"` is replaced with `"13"` because `3 + 4 + 6 = 13`.
+3.  **Merge** consecutive groups together to form a new string. If the length of the string is greater than `k`, repeat from step `1`.
+
+Return `s` _after all rounds have been completed_.
+
+**Example 1:**
+
+**Input:** s = "11111222223", k = 3
+
+**Output:** "135"
+
+**Explanation:**
+
+- For the first round, we divide s into groups of size 3: "111", "112", "222", and "23".
+
+Then we calculate the digit sum of each group: 1 + 1 + 1 = 3, 1 + 1 + 2 = 4, 2 + 2 + 2 = 6, and 2 + 3 = 5.
+
+So, s becomes "3" + "4" + "6" + "5" = "3465" after the first round.
+
+- For the second round, we divide s into "346" and "5".
+
+Then we calculate the digit sum of each group: 3 + 4 + 6 = 13, 5 = 5.
+
+So, s becomes "13" + "5" = "135" after second round.
+
+Now, s.length <= k, so we return "135" as the answer. 
+
+**Example 2:**
+
+**Input:** s = "00000000", k = 3
+
+**Output:** "000"
+
+**Explanation:**
+
+We divide s into "000", "000", and "00".
+
+Then we calculate the digit sum of each group: 0 + 0 + 0 = 0, 0 + 0 + 0 = 0, and 0 + 0 = 0.
+
+s becomes "0" + "0" + "0" = "000", whose length is equal to k, so we return "000". 
+
+**Constraints:**
+
+*   `1 <= s.length <= 100`
+*   `2 <= k <= 100`
+*   `s` consists of digits only.
+
+## Solution
+
+```kotlin
+@Suppress("NAME_SHADOWING")
+class Solution {
+    fun digitSum(s: String, k: Int): String {
+        var s = s
+        while (s.length > k) {
+            val n = s.length
+            var count = 0
+            var sum = 0
+            val sb = StringBuilder()
+            for (i in 0 until n) {
+                if (count == k) {
+                    sb.append(sum)
+                    sum = 0
+                    count = 0
+                }
+                sum += s[i].code - '0'.code
+                count++
+            }
+            sb.append(sum)
+            s = sb.toString()
+        }
+        return s
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2244_minimum_rounds_to_complete_all_tasks/readme.md b/src/main/kotlin/g2201_2300/s2244_minimum_rounds_to_complete_all_tasks/readme.md
new file mode 100644
index 00000000..fb4a1d6b
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2244_minimum_rounds_to_complete_all_tasks/readme.md
@@ -0,0 +1,79 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2244\. Minimum Rounds to Complete All Tasks
+
+Medium
+
+You are given a **0-indexed** integer array `tasks`, where `tasks[i]` represents the difficulty level of a task. In each round, you can complete either 2 or 3 tasks of the **same difficulty level**.
+
+Return _the **minimum** rounds required to complete all the tasks, or_ `-1` _if it is not possible to complete all the tasks._
+
+**Example 1:**
+
+**Input:** tasks = [2,2,3,3,2,4,4,4,4,4]
+
+**Output:** 4
+
+**Explanation:** To complete all the tasks, a possible plan is:
+
+- In the first round, you complete 3 tasks of difficulty level 2.
+
+- In the second round, you complete 2 tasks of difficulty level 3.
+
+- In the third round, you complete 3 tasks of difficulty level 4.
+
+- In the fourth round, you complete 2 tasks of difficulty level 4.
+
+It can be shown that all the tasks cannot be completed in fewer than 4 rounds, so the answer is 4. 
+
+**Example 2:**
+
+**Input:** tasks = [2,3,3]
+
+**Output:** -1
+
+**Explanation:** There is only 1 task of difficulty level 2, but in each round, you can only complete either 2 or 3 tasks of the same difficulty level. Hence, you cannot complete all the tasks, and the answer is -1. 
+
+**Constraints:**
+
+*   1 <= tasks.length <= 105
+*   1 <= tasks[i] <= 109
+
+## Solution
+
+```kotlin
+class Solution {
+    fun minimumRounds(tasks: IntArray): Int {
+        tasks.sort()
+        var rounds = 0
+        var c = 1
+        for (i in 0 until tasks.size - 1) {
+            if (tasks[i] == tasks[i + 1]) {
+                c++
+            } else {
+                if (c == 1) {
+                    return -1
+                }
+                if (c % 3 == 0) {
+                    rounds += c / 3
+                }
+                if (c % 3 >= 1) {
+                    rounds += c / 3 + 1
+                }
+                c = 1
+            }
+        }
+        if (c == 1) {
+            return -1
+        }
+        if (c % 3 == 0) {
+            rounds += c / 3
+        }
+        if (c % 3 >= 1) {
+            rounds += c / 3 + 1
+        }
+        return rounds
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2245_maximum_trailing_zeros_in_a_cornered_path/readme.md b/src/main/kotlin/g2201_2300/s2245_maximum_trailing_zeros_in_a_cornered_path/readme.md
new file mode 100644
index 00000000..7bfe79ec
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2245_maximum_trailing_zeros_in_a_cornered_path/readme.md
@@ -0,0 +1,118 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2245\. Maximum Trailing Zeros in a Cornered Path
+
+Medium
+
+You are given a 2D integer array `grid` of size `m x n`, where each cell contains a positive integer.
+
+A **cornered path** is defined as a set of adjacent cells with **at most** one turn. More specifically, the path should exclusively move either **horizontally** or **vertically** up to the turn (if there is one), without returning to a previously visited cell. After the turn, the path will then move exclusively in the **alternate** direction: move vertically if it moved horizontally, and vice versa, also without returning to a previously visited cell.
+
+The **product** of a path is defined as the product of all the values in the path.
+
+Return _the **maximum** number of **trailing zeros** in the product of a cornered path found in_ `grid`.
+
+Note:
+
+*   **Horizontal** movement means moving in either the left or right direction.
+*   **Vertical** movement means moving in either the up or down direction.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/03/23/ex1new2.jpg)
+
+**Input:** grid = \[\[23,17,15,3,20],[8,1,20,27,11],[9,4,6,2,21],[40,9,1,10,6],[22,7,4,5,3]]
+
+**Output:** 3
+
+**Explanation:** The grid on the left shows a valid cornered path.
+
+It has a product of 15 \* 20 \* 6 \* 1 \* 10 = 18000 which has 3 trailing zeros.
+
+It can be shown that this is the maximum trailing zeros in the product of a cornered path.
+
+
+The grid in the middle is not a cornered path as it has more than one turn.
+
+The grid on the right is not a cornered path as it requires a return to a previously visited cell. 
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2022/03/25/ex2.jpg)
+
+**Input:** grid = \[\[4,3,2],[7,6,1],[8,8,8]]
+
+**Output:** 0
+
+**Explanation:** The grid is shown in the figure above.
+
+There are no cornered paths in the grid that result in a product with a trailing zero. 
+
+**Constraints:**
+
+*   `m == grid.length`
+*   `n == grid[i].length`
+*   1 <= m, n <= 105
+*   1 <= m * n <= 105
+*   `1 <= grid[i][j] <= 1000`
+
+## Solution
+
+```kotlin
+@Suppress("NAME_SHADOWING")
+class Solution {
+    fun maxTrailingZeros(grid: Array): Int {
+        val m = grid.size
+        val n = grid[0].size
+        var max = 0
+        val row2 = Array(m + 1) { IntArray(n + 1) }
+        val row5 = Array(m + 1) { IntArray(n + 1) }
+        val col2 = Array(m + 1) { IntArray(n + 1) }
+        val col5 = Array(m + 1) { IntArray(n + 1) }
+        val factor2 = Array(m) { IntArray(n) }
+        val factor5 = Array(m) { IntArray(n) }
+        for (r in 0 until m) {
+            for (c in 0 until n) {
+                val factorTwo = findFactor(grid[r][c], 2)
+                val factorFive = findFactor(grid[r][c], 5)
+                row2[r + 1][c + 1] = row2[r + 1][c] + factorTwo
+                row5[r + 1][c + 1] = row5[r + 1][c] + factorFive
+                col2[r + 1][c + 1] = col2[r][c + 1] + factorTwo
+                col5[r + 1][c + 1] = col5[r][c + 1] + factorFive
+                factor2[r][c] = factorTwo
+                factor5[r][c] = factorFive
+            }
+        }
+        for (r in 0 until m) {
+            for (c in 0 until n) {
+                val cur2 = factor2[r][c]
+                val cur5 = factor5[r][c]
+                val up2 = col2[r + 1][c + 1]
+                val up5 = col5[r + 1][c + 1]
+                val down2 = col2[m][c + 1] - col2[r][c + 1]
+                val down5 = col5[m][c + 1] - col5[r][c + 1]
+                val left2 = row2[r + 1][c + 1]
+                val left5 = row5[r + 1][c + 1]
+                val right2 = row2[r + 1][n] - row2[r + 1][c]
+                val right5 = row5[r + 1][n] - row5[r + 1][c]
+                max = Math.max(max, Math.min(left2 + up2 - cur2, left5 + up5 - cur5))
+                max = Math.max(max, Math.min(right2 + up2 - cur2, right5 + up5 - cur5))
+                max = Math.max(max, Math.min(left2 + down2 - cur2, left5 + down5 - cur5))
+                max = Math.max(max, Math.min(right2 + down2 - cur2, right5 + down5 - cur5))
+            }
+        }
+        return max
+    }
+
+    private fun findFactor(a: Int, b: Int): Int {
+        var a = a
+        var factors = 0
+        while (a % b == 0) {
+            a /= b
+            factors++
+        }
+        return factors
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2246_longest_path_with_different_adjacent_characters/readme.md b/src/main/kotlin/g2201_2300/s2246_longest_path_with_different_adjacent_characters/readme.md
new file mode 100644
index 00000000..f313960a
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2246_longest_path_with_different_adjacent_characters/readme.md
@@ -0,0 +1,107 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2246\. Longest Path With Different Adjacent Characters
+
+Hard
+
+You are given a **tree** (i.e. a connected, undirected graph that has no cycles) **rooted** at node `0` consisting of `n` nodes numbered from `0` to `n - 1`. The tree is represented by a **0-indexed** array `parent` of size `n`, where `parent[i]` is the parent of node `i`. Since node `0` is the root, `parent[0] == -1`.
+
+You are also given a string `s` of length `n`, where `s[i]` is the character assigned to node `i`.
+
+Return _the length of the **longest path** in the tree such that no pair of **adjacent** nodes on the path have the same character assigned to them._
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/03/25/testingdrawio.png)
+
+**Input:** parent = [-1,0,0,1,1,2], s = "abacbe"
+
+**Output:** 3
+
+**Explanation:** The longest path where each two adjacent nodes have different characters in the tree is the path: 0 -> 1 -> 3. The length of this path is 3, so 3 is returned.
+
+It can be proven that there is no longer path that satisfies the conditions. 
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2022/03/25/graph2drawio.png)
+
+**Input:** parent = [-1,0,0,0], s = "aabc"
+
+**Output:** 3
+
+**Explanation:** The longest path where each two adjacent nodes have different characters is the path: 2 -> 0 -> 3. The length of this path is 3, so 3 is returned. 
+
+**Constraints:**
+
+*   `n == parent.length == s.length`
+*   1 <= n <= 105
+*   `0 <= parent[i] <= n - 1` for all `i >= 1`
+*   `parent[0] == -1`
+*   `parent` represents a valid tree.
+*   `s` consists of only lowercase English letters.
+
+## Solution
+
+```kotlin
+import java.util.LinkedList
+
+class Solution {
+    fun longestPath(parent: IntArray, s: String): Int {
+        // for first max length
+        val first = IntArray(s.length)
+        first.fill(0)
+        // for second max length
+        val second = IntArray(s.length)
+        second.fill(0)
+        // for number of children for this node
+        val children = IntArray(s.length)
+        children.fill(0)
+        for (i in 1 until s.length) {
+            // calculate all children for each node
+            children[parent[i]]++
+        }
+        // for traversal from leafs to root
+        val st = LinkedList()
+        // put all leafs
+        for (i in 1 until s.length) {
+            if (children[i] == 0) {
+                st.add(i)
+            }
+        }
+        // traversal from leafs to root
+        while (st.isNotEmpty()) {
+            // fetch current node
+            val i = st.pollLast()
+            // if we in root - ignore it
+            if (i == 0) {
+                continue
+            }
+            if (--children[parent[i]] == 0) {
+                // decrease number of children by parent node and if number of children
+                st.add(parent[i])
+            }
+            // is equal 0 - our parent became a leaf
+            // if letters isn't equal
+            if (s[parent[i]] != s[i]) {
+                // fetch maximal path from node
+                val maxi = 1 + Math.max(first[i], second[i])
+                // and update maximal first and second path from parent
+                if (maxi >= first[parent[i]]) {
+                    second[parent[i]] = first[parent[i]]
+                    first[parent[i]] = maxi
+                } else if (second[parent[i]] < maxi) {
+                    second[parent[i]] = maxi
+                }
+            }
+        }
+        // fetch answer
+        var ans = 0
+        for (i in 0 until s.length) {
+            ans = Math.max(ans, first[i] + second[i])
+        }
+        return ans + 1
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2248_intersection_of_multiple_arrays/readme.md b/src/main/kotlin/g2201_2300/s2248_intersection_of_multiple_arrays/readme.md
new file mode 100644
index 00000000..01390121
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2248_intersection_of_multiple_arrays/readme.md
@@ -0,0 +1,57 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2248\. Intersection of Multiple Arrays
+
+Easy
+
+Given a 2D integer array `nums` where `nums[i]` is a non-empty array of **distinct** positive integers, return _the list of integers that are present in **each array** of_ `nums` _sorted in **ascending order**_.
+
+**Example 1:**
+
+**Input:** nums = \[\[**3**,1,2,**4**,5],[1,2,**3**,**4**],[**3**,**4**,5,6]]
+
+**Output:** [3,4]
+
+**Explanation:** 
+
+The only integers present in each of nums[0] = [**3**,1,2,**4**,5], nums[1] = [1,2,**3**,**4**], and nums[2] = [**3**,**4**,5,6] are 3 and 4, so we return [3,4].
+
+**Example 2:**
+
+**Input:** nums = \[\[1,2,3],[4,5,6]]
+
+**Output:** []
+
+**Explanation:** 
+
+There does not exist any integer present both in nums[0] and nums[1], so we return an empty list [].
+
+**Constraints:**
+
+* `1 <= nums.length <= 1000`
+* `1 <= sum(nums[i].length) <= 1000`
+* `1 <= nums[i][j] <= 1000`
+* All the values of `nums[i]` are **unique**.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun intersection(nums: Array): List {
+        val ans: MutableList = ArrayList()
+        val count = IntArray(1001)
+        for (arr in nums) {
+            for (i in arr) {
+                ++count[i]
+            }
+        }
+        for (i in count.indices) {
+            if (count[i] == nums.size) {
+                ans.add(i)
+            }
+        }
+        return ans
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2249_count_lattice_points_inside_a_circle/readme.md b/src/main/kotlin/g2201_2300/s2249_count_lattice_points_inside_a_circle/readme.md
new file mode 100644
index 00000000..f3edd41c
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2249_count_lattice_points_inside_a_circle/readme.md
@@ -0,0 +1,85 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2249\. Count Lattice Points Inside a Circle
+
+Medium
+
+Given a 2D integer array `circles` where circles[i] = [xi, yi, ri] represents the center (xi, yi) and radius ri of the ith circle drawn on a grid, return _the **number of lattice points**_ _that are present inside **at least one** circle_.
+
+**Note:**
+
+*   A **lattice point** is a point with integer coordinates.
+*   Points that lie **on the circumference of a circle** are also considered to be inside it.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/03/02/exa-11.png)
+
+**Input:** circles = \[\[2,2,1]]
+
+**Output:** 5
+
+**Explanation:** 
+
+The figure above shows the given circle. 
+
+The lattice points present inside the circle are (1, 2), (2, 1), (2, 2), (2, 3), and (3, 2) and are shown in green. 
+
+Other points such as (1, 1) and (1, 3), which are shown in red, are not considered inside the circle. 
+
+Hence, the number of lattice points present inside at least one circle is 5.
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2022/03/02/exa-22.png)
+
+**Input:** circles = \[\[2,2,2],[3,4,1]]
+
+**Output:** 16
+
+**Explanation:** 
+
+The figure above shows the given circles. 
+
+There are exactly 16 lattice points which are present inside at least one circle. 
+
+Some of them are (0, 2), (2, 0), (2, 4), (3, 2), and (4, 4).
+
+**Constraints:**
+
+*   `1 <= circles.length <= 200`
+*   `circles[i].length == 3`
+*   1 <= xi, yi <= 100
+*   1 <= ri <= min(xi, yi)
+
+## Solution
+
+```kotlin
+class Solution {
+    fun countLatticePoints(circles: Array): Int {
+        var xMin = 200
+        var xMax = -1
+        var yMin = 200
+        var yMax = -1
+        for (c in circles) {
+            xMin = Math.min(xMin, c[0] - c[2])
+            xMax = Math.max(xMax, c[0] + c[2])
+            yMin = Math.min(yMin, c[1] - c[2])
+            yMax = Math.max(yMax, c[1] + c[2])
+        }
+        var ans = 0
+        for (x in xMin..xMax) {
+            for (y in yMin..yMax) {
+                for (c in circles) {
+                    if ((c[0] - x) * (c[0] - x) + (c[1] - y) * (c[1] - y) <= c[2] * c[2]) {
+                        ans++
+                        break
+                    }
+                }
+            }
+        }
+        return ans
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2250_count_number_of_rectangles_containing_each_point/readme.md b/src/main/kotlin/g2201_2300/s2250_count_number_of_rectangles_containing_each_point/readme.md
new file mode 100644
index 00000000..6f44d5a6
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2250_count_number_of_rectangles_containing_each_point/readme.md
@@ -0,0 +1,98 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2250\. Count Number of Rectangles Containing Each Point
+
+Medium
+
+You are given a 2D integer array `rectangles` where rectangles[i] = [li, hi] indicates that ith rectangle has a length of li and a height of hi. You are also given a 2D integer array `points` where points[j] = [xj, yj] is a point with coordinates (xj, yj).
+
+The ith rectangle has its **bottom-left corner** point at the coordinates `(0, 0)` and its **top-right corner** point at (li, hi).
+
+Return _an integer array_ `count` _of length_ `points.length` _where_ `count[j]` _is the number of rectangles that **contain** the_ jth _point._
+
+The ith rectangle **contains** the jth point if 0 <= xj <= li and 0 <= yj <= hi. Note that points that lie on the **edges** of a rectangle are also considered to be contained by that rectangle.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/03/02/example1.png)
+
+**Input:** rectangles = \[\[1,2],[2,3],[2,5]], points = \[\[2,1],[1,4]]
+
+**Output:** [2,1]
+
+**Explanation:** 
+
+The first rectangle contains no points. 
+
+The second rectangle contains only the point (2, 1). 
+
+The third rectangle contains the points (2, 1) and (1, 4). 
+
+The number of rectangles that contain the point (2, 1) is 2. 
+
+The number of rectangles that contain the point (1, 4) is 1. 
+
+Therefore, we return [2, 1].
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2022/03/02/example2.png)
+
+**Input:** rectangles = \[\[1,1],[2,2],[3,3]], points = \[\[1,3],[1,1]]
+
+**Output:** [1,3]
+
+**Explanation:** 
+
+The first rectangle contains only the point (1, 1). 
+
+The second rectangle contains only the point (1, 1). 
+
+The third rectangle contains the points (1, 3) and (1, 1). 
+
+The number of rectangles that contain the point (1, 3) is 1. 
+
+The number of rectangles that contain the point (1, 1) is 3.
+
+Therefore, we return [1, 3].
+
+**Constraints:**
+
+*   1 <= rectangles.length, points.length <= 5 * 104
+*   `rectangles[i].length == points[j].length == 2`
+*   1 <= li, xj <= 109
+*   1 <= hi, yj <= 100
+*   All the `rectangles` are **unique**.
+*   All the `points` are **unique**.
+
+## Solution
+
+```kotlin
+import java.util.Arrays
+
+class Solution {
+    fun countRectangles(rectangles: Array, points: Array): IntArray {
+        val n = rectangles.size
+        val q = points.size
+        val es = arrayOfNulls(n + q)
+        System.arraycopy(rectangles, 0, es, 0, n)
+        for (i in 0 until q) {
+            es[n + i] = intArrayOf(points[i][0], points[i][1], i)
+        }
+        Arrays.sort(es) { x: IntArray?, y: IntArray? -> if (x!![0] != y!![0]) -(x[0] - y[0]) else x.size - y.size }
+        val ct = IntArray(101)
+        val ans = IntArray(q)
+        for (e in es) {
+            if (e!!.size == 2) {
+                for (i in 0..e[1]) {
+                    ct[i]++
+                }
+            } else {
+                ans[e[2]] = ct[e[1]]
+            }
+        }
+        return ans
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2251_number_of_flowers_in_full_bloom/readme.md b/src/main/kotlin/g2201_2300/s2251_number_of_flowers_in_full_bloom/readme.md
new file mode 100644
index 00000000..ccfb1ed6
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2251_number_of_flowers_in_full_bloom/readme.md
@@ -0,0 +1,85 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2251\. Number of Flowers in Full Bloom
+
+Hard
+
+You are given a **0-indexed** 2D integer array `flowers`, where flowers[i] = [starti, endi] means the ith flower will be in **full bloom** from starti to endi (**inclusive**). You are also given a **0-indexed** integer array `persons` of size `n`, where `persons[i]` is the time that the ith person will arrive to see the flowers.
+
+Return _an integer array_ `answer` _of size_ `n`_, where_ `answer[i]` _is the **number** of flowers that are in full bloom when the_ ith _person arrives._
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/03/02/ex1new.jpg)
+
+**Input:** flowers = \[\[1,6],[3,7],[9,12],[4,13]], persons = [2,3,7,11]
+
+**Output:** [1,2,2,2]
+
+**Explanation:** The figure above shows the times when the flowers are in full bloom and when the people arrive. For each person, we return the number of flowers in full bloom during their arrival.
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2022/03/02/ex2new.jpg)
+
+**Input:** flowers = \[\[1,10],[3,3]], persons = [3,3,2]
+
+**Output:** [2,2,1]
+
+**Explanation:** The figure above shows the times when the flowers are in full bloom and when the people arrive. For each person, we return the number of flowers in full bloom during their arrival.
+
+**Constraints:**
+
+*   1 <= flowers.length <= 5 * 104
+*   `flowers[i].length == 2`
+*   1 <= starti <= endi <= 109
+*   1 <= persons.length <= 5 * 104
+*   1 <= persons[i] <= 109
+
+## Solution
+
+```kotlin
+import java.util.Arrays
+import java.util.PriorityQueue
+
+class Solution {
+    fun fullBloomFlowers(flowers: Array, persons: IntArray): IntArray {
+        Arrays.sort(flowers, { a: IntArray, b: IntArray -> a[0].compareTo(b[0]) })
+        val ans = IntArray(persons.size)
+        val pq = PriorityQueue({ a: Pair, b: Pair -> a.j.compareTo(b.j) })
+        var j = 0
+        val t = Array(persons.size) { IntArray(2) }
+        for (i in persons.indices) {
+            t[i][0] = persons[i]
+            t[i][1] = i
+        }
+        Arrays.sort(t, { a: IntArray, b: IntArray -> a[0].compareTo(b[0]) })
+        for (ints in t) {
+            while (pq.isNotEmpty()) {
+                if (pq.peek().j < ints[0]) {
+                    pq.poll()
+                } else {
+                    break
+                }
+            }
+            while (j < flowers.size) {
+                if (flowers[j][0] <= ints[0] && flowers[j][1] >= ints[0]) {
+                    pq.add(Pair(flowers[j][0], flowers[j][1]))
+                    j++
+                    continue
+                }
+                if (flowers[j][1] < ints[0]) {
+                    j++
+                    continue
+                }
+                break
+            }
+            ans[ints[1]] = pq.size
+        }
+        return ans
+    }
+
+    private class Pair(var i: Int, var j: Int)
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2255_count_prefixes_of_a_given_string/readme.md b/src/main/kotlin/g2201_2300/s2255_count_prefixes_of_a_given_string/readme.md
new file mode 100644
index 00000000..6f03415f
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2255_count_prefixes_of_a_given_string/readme.md
@@ -0,0 +1,60 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2255\. Count Prefixes of a Given String
+
+Easy
+
+You are given a string array `words` and a string `s`, where `words[i]` and `s` comprise only of **lowercase English letters**.
+
+Return _the **number of strings** in_ `words` _that are a **prefix** of_ `s`.
+
+A **prefix** of a string is a substring that occurs at the beginning of the string. A **substring** is a contiguous sequence of characters within a string.
+
+**Example 1:**
+
+**Input:** words = ["a","b","c","ab","bc","abc"], s = "abc"
+
+**Output:** 3
+
+**Explanation:**
+
+The strings in words which are a prefix of s = "abc" are:
+
+"a", "ab", and "abc".
+
+Thus the number of strings in words which are a prefix of s is 3.
+
+**Example 2:**
+
+**Input:** words = ["a","a"], s = "aa"
+
+**Output:** 2
+
+**Explanation:**
+
+Both of the strings are a prefix of s.
+
+Note that the same string can occur multiple times in words, and it should be counted each time.
+
+**Constraints:**
+
+*   `1 <= words.length <= 1000`
+*   `1 <= words[i].length, s.length <= 10`
+*   `words[i]` and `s` consist of lowercase English letters **only**.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun countPrefixes(words: Array, s: String): Int {
+        var count = 0
+        for (str in words) {
+            if (s.indexOf(str) == 0) {
+                ++count
+            }
+        }
+        return count
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2256_minimum_average_difference/readme.md b/src/main/kotlin/g2201_2300/s2256_minimum_average_difference/readme.md
new file mode 100644
index 00000000..37087930
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2256_minimum_average_difference/readme.md
@@ -0,0 +1,86 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2256\. Minimum Average Difference
+
+Medium
+
+You are given a **0-indexed** integer array `nums` of length `n`.
+
+The **average difference** of the index `i` is the **absolute** **difference** between the average of the **first** `i + 1` elements of `nums` and the average of the **last** `n - i - 1` elements. Both averages should be **rounded down** to the nearest integer.
+
+Return _the index with the **minimum average difference**_. If there are multiple such indices, return the **smallest** one.
+
+**Note:**
+
+*   The **absolute difference** of two numbers is the absolute value of their difference.
+*   The **average** of `n` elements is the **sum** of the `n` elements divided (**integer division**) by `n`.
+*   The average of `0` elements is considered to be `0`.
+
+**Example 1:**
+
+**Input:** nums = [2,5,3,9,5,3]
+
+**Output:** 3
+
+**Explanation:** 
+
+- The average difference of index 0 is: \|2 / 1 - (5 + 3 + 9 + 5 + 3) / 5\| = \|2 / 1 - 25 / 5\| = \|2 - 5\| = 3. 
+
+- The average difference of index 1 is: \|(2 + 5) / 2 - (3 + 9 + 5 + 3) / 4\| = \|7 / 2 - 20 / 4\| = \|3 - 5\| = 2. 
+ 
+- The average difference of index 2 is: \|(2 + 5 + 3) / 3 - (9 + 5 + 3) / 3\| = \|10 / 3 - 17 / 3\| = \|3 - 5\| = 2. 
+ 
+- The average difference of index 3 is: \|(2 + 5 + 3 + 9) / 4 - (5 + 3) / 2\| = \|19 / 4 - 8 / 2\| = \|4 - 4\| = 0. 
+ 
+- The average difference of index 4 is: \|(2 + 5 + 3 + 9 + 5) / 5 - 3 / 1\| = \|24 / 5 - 3 / 1\| = \|4 - 3\| = 1. 
+ 
+- The average difference of index 5 is: \|(2 + 5 + 3 + 9 + 5 + 3) / 6 - 0\| = \|27 / 6 - 0\| = \|4 - 0\| = 4. 
+ 
+The average difference of index 3 is the minimum average difference so return 3. 
+
+**Example 2:**
+
+**Input:** nums = [0]
+
+**Output:** 0
+
+**Explanation:** 
+
+The only index is 0 so return 0. 
+
+The average difference of index 0 is: \|0 / 1 - 0\| = \|0 - 0\| = 0. 
+
+**Constraints:**
+
+*   1 <= nums.length <= 105
+*   0 <= nums[i] <= 105
+
+## Solution
+
+```kotlin
+class Solution {
+    fun minimumAverageDifference(nums: IntArray): Int {
+        var numsSum: Long = 0
+        for (num in nums) {
+            numsSum += num.toLong()
+        }
+        var minAverageDiff = Long.MAX_VALUE
+        var sumFromFront: Long = 0
+        var index = 0
+        for (i in nums.indices) {
+            sumFromFront += nums[i].toLong()
+            val numbersRight = if (i == nums.size - 1) 1 else nums.size - i - 1
+            val averageDiff = Math.abs(sumFromFront / (i + 1) - (numsSum - sumFromFront) / numbersRight)
+            if (minAverageDiff > averageDiff) {
+                minAverageDiff = averageDiff
+                index = i
+            }
+            if (averageDiff == 0L) {
+                break
+            }
+        }
+        return index
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2257_count_unguarded_cells_in_the_grid/readme.md b/src/main/kotlin/g2201_2300/s2257_count_unguarded_cells_in_the_grid/readme.md
new file mode 100644
index 00000000..a3107ce3
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2257_count_unguarded_cells_in_the_grid/readme.md
@@ -0,0 +1,135 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2257\. Count Unguarded Cells in the Grid
+
+Medium
+
+You are given two integers `m` and `n` representing a **0-indexed** `m x n` grid. You are also given two 2D integer arrays `guards` and `walls` where guards[i] = [rowi, coli] and walls[j] = [rowj, colj] represent the positions of the ith guard and jth wall respectively.
+
+A guard can see **every** cell in the four cardinal directions (north, east, south, or west) starting from their position unless **obstructed** by a wall or another guard. A cell is **guarded** if there is **at least** one guard that can see it.
+
+Return _the number of unoccupied cells that are **not** **guarded**._
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/03/10/example1drawio2.png)
+
+**Input:** m = 4, n = 6, guards = \[\[0,0],[1,1],[2,3]], walls = \[\[0,1],[2,2],[1,4]]
+
+**Output:** 7
+
+**Explanation:** The guarded and unguarded cells are shown in red and green respectively in the above diagram. There are a total of 7 unguarded cells, so we return 7.
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2022/03/10/example2drawio.png)
+
+**Input:** m = 3, n = 3, guards = \[\[1,1]], walls = \[\[0,1],[1,0],[2,1],[1,2]]
+
+**Output:** 4
+
+**Explanation:** The unguarded cells are shown in green in the above diagram. There are a total of 4 unguarded cells, so we return 4.
+
+**Constraints:**
+
+*   1 <= m, n <= 105
+*   2 <= m * n <= 105
+*   1 <= guards.length, walls.length <= 5 * 104
+*   `2 <= guards.length + walls.length <= m * n`
+*   `guards[i].length == walls[j].length == 2`
+*   0 <= rowi, rowj < m
+*   0 <= coli, colj < n
+*   All the positions in `guards` and `walls` are **unique**.
+
+## Solution
+
+```kotlin
+@Suppress("NAME_SHADOWING")
+class Solution {
+    fun countUnguarded(m: Int, n: Int, guards: Array, walls: Array): Int {
+        val matrix = Array(m) { CharArray(n) }
+        var result = 0
+        for (i in guards.indices) {
+            val guardRow = guards[i][0]
+            val guardCol = guards[i][1]
+            matrix[guardRow][guardCol] = 'G'
+        }
+        for (i in walls.indices) {
+            val wallRow = walls[i][0]
+            val wallCol = walls[i][1]
+            matrix[wallRow][wallCol] = 'W'
+        }
+        for (i in guards.indices) {
+            var currentRow = guards[i][0]
+            var currentCol = guards[i][1] - 1
+            extracted(matrix, currentRow, currentCol)
+            currentRow = guards[i][0]
+            currentCol = guards[i][1] + 1
+            extracted(n, matrix, currentRow, currentCol)
+            currentRow = guards[i][0] - 1
+            currentCol = guards[i][1]
+            extracted1(matrix, currentRow, currentCol)
+            currentRow = guards[i][0] + 1
+            currentCol = guards[i][1]
+            extracted1(m, matrix, currentRow, currentCol)
+        }
+        for (i in 0 until m) {
+            for (j in 0 until n) {
+                if (matrix[i][j] != 'R' && matrix[i][j] != 'G' && matrix[i][j] != 'W') {
+                    result++
+                }
+            }
+        }
+        return result
+    }
+
+    private fun extracted1(m: Int, matrix: Array, currentRow: Int, currentCol: Int) {
+        var currentRow = currentRow
+        while (currentRow <= m - 1) {
+            if (matrix[currentRow][currentCol] != 'W' && matrix[currentRow][currentCol] != 'G') {
+                matrix[currentRow][currentCol] = 'R'
+            } else {
+                break
+            }
+            currentRow++
+        }
+    }
+
+    private fun extracted1(matrix: Array, currentRow: Int, currentCol: Int) {
+        var currentRow = currentRow
+        while (currentRow >= 0) {
+            if (matrix[currentRow][currentCol] != 'W' && matrix[currentRow][currentCol] != 'G') {
+                matrix[currentRow][currentCol] = 'R'
+            } else {
+                break
+            }
+            currentRow--
+        }
+    }
+
+    private fun extracted(n: Int, matrix: Array, currentRow: Int, currentCol: Int) {
+        var currentCol = currentCol
+        while (currentCol <= n - 1) {
+            if (matrix[currentRow][currentCol] != 'W' && matrix[currentRow][currentCol] != 'G') {
+                matrix[currentRow][currentCol] = 'R'
+            } else {
+                break
+            }
+            currentCol++
+        }
+    }
+
+    private fun extracted(matrix: Array, currentRow: Int, currentCol: Int) {
+        var currentCol = currentCol
+        while (currentCol >= 0) {
+            if (matrix[currentRow][currentCol] != 'W' && matrix[currentRow][currentCol] != 'G') {
+                matrix[currentRow][currentCol] = 'R'
+            } else {
+                break
+            }
+            currentCol--
+        }
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2258_escape_the_spreading_fire/readme.md b/src/main/kotlin/g2201_2300/s2258_escape_the_spreading_fire/readme.md
new file mode 100644
index 00000000..67a70c3e
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2258_escape_the_spreading_fire/readme.md
@@ -0,0 +1,166 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2258\. Escape the Spreading Fire
+
+Hard
+
+You are given a **0-indexed** 2D integer array `grid` of size `m x n` which represents a field. Each cell has one of three values:
+
+*   `0` represents grass,
+*   `1` represents fire,
+*   `2` represents a wall that you and fire cannot pass through.
+
+You are situated in the top-left cell, `(0, 0)`, and you want to travel to the safehouse at the bottom-right cell, `(m - 1, n - 1)`. Every minute, you may move to an **adjacent** grass cell. **After** your move, every fire cell will spread to all **adjacent** cells that are not walls.
+
+Return _the **maximum** number of minutes that you can stay in your initial position before moving while still safely reaching the safehouse_. If this is impossible, return `-1`. If you can **always** reach the safehouse regardless of the minutes stayed, return 109.
+
+Note that even if the fire spreads to the safehouse immediately after you have reached it, it will be counted as safely reaching the safehouse.
+
+A cell is **adjacent** to another cell if the former is directly north, east, south, or west of the latter (i.e., their sides are touching).
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/03/10/ex1new.jpg)
+
+**Input:** grid = \[\[0,2,0,0,0,0,0],[0,0,0,2,2,1,0],[0,2,0,0,1,2,0],[0,0,2,2,2,0,2],[0,0,0,0,0,0,0]]
+
+**Output:** 3
+
+**Explanation:** The figure above shows the scenario where you stay in the initial position for 3 minutes.
+
+You will still be able to safely reach the safehouse.
+
+Staying for more than 3 minutes will not allow you to safely reach the safehouse.
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2022/03/10/ex2new2.jpg)
+
+**Input:** grid = \[\[0,0,0,0],[0,1,2,0],[0,2,0,0]]
+
+**Output:** -1
+
+**Explanation:** The figure above shows the scenario where you immediately move towards the safehouse.
+
+Fire will spread to any cell you move towards and it is impossible to safely reach the safehouse.
+
+Thus, -1 is returned.
+
+**Example 3:**
+
+![](https://assets.leetcode.com/uploads/2022/03/10/ex3new.jpg)
+
+**Input:** grid = \[\[0,0,0],[2,2,0],[1,2,0]]
+
+**Output:** 1000000000
+
+**Explanation:** The figure above shows the initial grid. Notice that the fire is contained by walls and you will always be able to safely reach the safehouse. Thus, 109 is returned. 
+
+**Constraints:**
+
+*   `m == grid.length`
+*   `n == grid[i].length`
+*   `2 <= m, n <= 300`
+*   4 <= m * n <= 2 * 104
+*   `grid[i][j]` is either `0`, `1`, or `2`.
+*   `grid[0][0] == grid[m - 1][n - 1] == 0`
+
+## Solution
+
+```kotlin
+@Suppress("NAME_SHADOWING")
+class Solution {
+    private fun setFire(grid: Array, dir: Array): Array {
+        val n = grid.size
+        val m = grid[0].size
+        val bfs = ArrayDeque()
+        val fire = Array(n) { IntArray(m) }
+        for (i in 0 until n) {
+            for (j in 0 until m) {
+                fire[i][j] = Int.MAX_VALUE
+                if (grid[i][j] == 1) {
+                    fire[i][j] = 0
+                    bfs.add(i * m + j)
+                }
+                if (grid[i][j] == 2) {
+                    fire[i][j] = 0
+                }
+            }
+        }
+        while (bfs.isNotEmpty()) {
+            val rm = bfs.removeFirst()
+            val x = rm / m
+            val y = rm % m
+            for (d in 0..3) {
+                val nx = x + dir[d][0]
+                val ny = y + dir[d][1]
+                if (nx >= 0 && ny >= 0 && nx < n && ny < m && fire[nx][ny] == Int.MAX_VALUE) {
+                    fire[nx][ny] = fire[x][y] + 1
+                    bfs.add(nx * m + ny)
+                }
+            }
+        }
+        return fire
+    }
+
+    private fun isPoss(fire: Array, dir: Array, time: Int): Boolean {
+        var time = time
+        if (time >= fire[0][0]) {
+            return false
+        }
+        val n = fire.size
+        val m = fire[0].size
+        val bfs = ArrayDeque()
+        bfs.add(0)
+        val isVis = Array(n) { BooleanArray(m) }
+        isVis[0][0] = true
+        while (bfs.isNotEmpty()) {
+            var size = bfs.size
+            while (size-- > 0) {
+                val rm = bfs.removeFirst()
+                val x = rm / m
+                val y = rm % m
+                if (x == n - 1 && y == m - 1) {
+                    return true
+                }
+                for (d in 0..3) {
+                    val nx = x + dir[d][0]
+                    val ny = y + dir[d][1]
+                    if (nx >= 0 && ny >= 0 && nx < n && ny < m && !isVis[nx][ny]) {
+                        if (nx == n - 1 && ny == m - 1) {
+                            if (time + 1 <= fire[nx][ny]) {
+                                isVis[nx][ny] = true
+                                bfs.add(nx * m + ny)
+                            }
+                        } else {
+                            if (time + 1 < fire[nx][ny]) {
+                                isVis[nx][ny] = true
+                                bfs.add(nx * m + ny)
+                            }
+                        }
+                    }
+                }
+            }
+            time++
+        }
+        return false
+    }
+
+    fun maximumMinutes(grid: Array): Int {
+        val dir = arrayOf(intArrayOf(0, 1), intArrayOf(1, 0), intArrayOf(-1, 0), intArrayOf(0, -1))
+        val fire = setFire(grid, dir)
+        var lo = 0
+        var hi = 1e9.toInt()
+        while (lo <= hi) {
+            val mid = (hi - lo shr 1) + lo
+            if (isPoss(fire, dir, mid)) {
+                lo = mid + 1
+            } else {
+                hi = mid - 1
+            }
+        }
+        return hi
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2259_remove_digit_from_number_to_maximize_result/readme.md b/src/main/kotlin/g2201_2300/s2259_remove_digit_from_number_to_maximize_result/readme.md
new file mode 100644
index 00000000..1a20fd58
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2259_remove_digit_from_number_to_maximize_result/readme.md
@@ -0,0 +1,68 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2259\. Remove Digit From Number to Maximize Result
+
+Easy
+
+You are given a string `number` representing a **positive integer** and a character `digit`.
+
+Return _the resulting string after removing **exactly one occurrence** of_ `digit` _from_ `number` _such that the value of the resulting string in **decimal** form is **maximized**_. The test cases are generated such that `digit` occurs at least once in `number`.
+
+**Example 1:**
+
+**Input:** number = "123", digit = "3"
+
+**Output:** "12"
+
+**Explanation:** There is only one '3' in "123". After removing '3', the result is "12".
+
+**Example 2:**
+
+**Input:** number = "1231", digit = "1"
+
+**Output:** "231"
+
+**Explanation:** We can remove the first '1' to get "231" or remove the second '1' to get "123".
+
+Since 231 > 123, we return "231".
+
+**Example 3:**
+
+**Input:** number = "551", digit = "5"
+
+**Output:** "51"
+
+**Explanation:** We can remove either the first or second '5' from "551".
+
+Both result in the string "51".
+
+**Constraints:**
+
+*   `2 <= number.length <= 100`
+*   `number` consists of digits from `'1'` to `'9'`.
+*   `digit` is a digit from `'1'` to `'9'`.
+*   `digit` occurs at least once in `number`.
+
+## Solution
+
+```kotlin
+@Suppress("NAME_SHADOWING")
+class Solution {
+    fun removeDigit(number: String, digit: Char): String {
+        var number = number
+        var index = 0
+        val n = number.length
+        for (i in 0 until n) {
+            if (number[i] == digit) {
+                index = i
+                if (i < n - 1 && digit < number[i + 1]) {
+                    break
+                }
+            }
+        }
+        number = number.substring(0, index) + number.substring(index + 1)
+        return number
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2260_minimum_consecutive_cards_to_pick_up/readme.md b/src/main/kotlin/g2201_2300/s2260_minimum_consecutive_cards_to_pick_up/readme.md
new file mode 100644
index 00000000..9ae41537
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2260_minimum_consecutive_cards_to_pick_up/readme.md
@@ -0,0 +1,55 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2260\. Minimum Consecutive Cards to Pick Up
+
+Medium
+
+You are given an integer array `cards` where `cards[i]` represents the **value** of the ith card. A pair of cards are **matching** if the cards have the **same** value.
+
+Return _the **minimum** number of **consecutive** cards you have to pick up to have a pair of **matching** cards among the picked cards._ If it is impossible to have matching cards, return `-1`.
+
+**Example 1:**
+
+**Input:** cards = [3,4,2,3,4,7]
+
+**Output:** 4
+
+**Explanation:** We can pick up the cards [3,4,2,3] which contain a matching pair of cards with value 3.
+
+Note that picking up the cards [4,2,3,4] is also optimal.
+
+**Example 2:**
+
+**Input:** cards = [1,0,5,3]
+
+**Output:** -1
+
+**Explanation:** There is no way to pick up a set of consecutive cards that contain a pair of matching cards. 
+
+**Constraints:**
+
+*   1 <= cards.length <= 105
+*   0 <= cards[i] <= 106
+
+## Solution
+
+```kotlin
+class Solution {
+    fun minimumCardPickup(cards: IntArray): Int {
+        var mindiff = Int.MAX_VALUE
+        val map: MutableMap = HashMap()
+        val n = cards.size
+        for (i in 0 until n) {
+            if (map.containsKey(cards[i])) {
+                val j = map[cards[i]]!!
+                mindiff = Math.min(mindiff, i - j + 1)
+            }
+            map[cards[i]] = i
+        }
+        return if (mindiff == Int.MAX_VALUE) {
+            -1
+        } else mindiff
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2261_k_divisible_elements_subarrays/readme.md b/src/main/kotlin/g2201_2300/s2261_k_divisible_elements_subarrays/readme.md
new file mode 100644
index 00000000..6e30e813
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2261_k_divisible_elements_subarrays/readme.md
@@ -0,0 +1,79 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2261\. K Divisible Elements Subarrays
+
+Medium
+
+Given an integer array `nums` and two integers `k` and `p`, return _the number of **distinct subarrays** which have **at most**_ `k` _elements divisible by_ `p`.
+
+Two arrays `nums1` and `nums2` are said to be **distinct** if:
+
+*   They are of **different** lengths, or
+*   There exists **at least** one index `i` where `nums1[i] != nums2[i]`.
+
+A **subarray** is defined as a **non-empty** contiguous sequence of elements in an array.
+
+**Example 1:**
+
+**Input:** nums = [**2**,3,3,**2**,**2**], k = 2, p = 2
+
+**Output:** 11
+
+**Explanation:**
+
+The elements at indices 0, 3, and 4 are divisible by p = 2.
+
+The 11 distinct subarrays which have at most k = 2 elements divisible by 2 are:
+
+[2], [2,3], [2,3,3], [2,3,3,2], [3], [3,3], [3,3,2], [3,3,2,2], [3,2], [3,2,2], and [2,2].
+
+Note that the subarrays [2] and [3] occur more than once in nums, but they should each be counted only once.
+
+The subarray [2,3,3,2,2] should not be counted because it has 3 elements that are divisible by 2.
+
+**Example 2:**
+
+**Input:** nums = [1,2,3,4], k = 4, p = 1
+
+**Output:** 10
+
+**Explanation:**
+
+All element of nums are divisible by p = 1.
+
+Also, every subarray of nums will have at most 4 elements that are divisible by 1.
+
+Since all subarrays are distinct, the total number of subarrays satisfying all the constraints is 10.
+
+**Constraints:**
+
+*   `1 <= nums.length <= 200`
+*   `1 <= nums[i], p <= 200`
+*   `1 <= k <= nums.length`
+
+## Solution
+
+```kotlin
+class Solution {
+    fun countDistinct(nums: IntArray, k: Int, p: Int): Int {
+        val numSubarray = HashSet()
+        for (i in nums.indices) {
+            var countDiv = 0
+            var hashCode: Long = 1
+            for (j in i until nums.size) {
+                hashCode = 199L * hashCode + nums[j]
+                if (nums[j] % p == 0) {
+                    countDiv++
+                }
+                if (countDiv <= k) {
+                    numSubarray.add(hashCode)
+                } else {
+                    break
+                }
+            }
+        }
+        return numSubarray.size
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2262_total_appeal_of_a_string/readme.md b/src/main/kotlin/g2201_2300/s2262_total_appeal_of_a_string/readme.md
new file mode 100644
index 00000000..a05a7ec9
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2262_total_appeal_of_a_string/readme.md
@@ -0,0 +1,76 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2262\. Total Appeal of A String
+
+Hard
+
+The **appeal** of a string is the number of **distinct** characters found in the string.
+
+*   For example, the appeal of `"abbca"` is `3` because it has `3` distinct characters: `'a'`, `'b'`, and `'c'`.
+
+Given a string `s`, return _the **total appeal of all of its **substrings**.**_
+
+A **substring** is a contiguous sequence of characters within a string.
+
+**Example 1:**
+
+**Input:** s = "abbca"
+
+**Output:** 28
+
+**Explanation:** The following are the substrings of "abbca":
+
+- Substrings of length 1: "a", "b", "b", "c", "a" have an appeal of 1, 1, 1, 1, and 1 respectively. The sum is 5.
+
+- Substrings of length 2: "ab", "bb", "bc", "ca" have an appeal of 2, 1, 2, and 2 respectively. The sum is 7.
+
+- Substrings of length 3: "abb", "bbc", "bca" have an appeal of 2, 2, and 3 respectively. The sum is 7.
+
+- Substrings of length 4: "abbc", "bbca" have an appeal of 3 and 3 respectively. The sum is 6.
+
+- Substrings of length 5: "abbca" has an appeal of 3. The sum is 3.
+
+The total sum is 5 + 7 + 7 + 6 + 3 = 28. 
+
+**Example 2:**
+
+**Input:** s = "code"
+
+**Output:** 20
+
+**Explanation:** The following are the substrings of "code":
+
+- Substrings of length 1: "c", "o", "d", "e" have an appeal of 1, 1, 1, and 1 respectively. The sum is 4.
+
+- Substrings of length 2: "co", "od", "de" have an appeal of 2, 2, and 2 respectively. The sum is 6.
+
+- Substrings of length 3: "cod", "ode" have an appeal of 3 and 3 respectively. The sum is 6.
+
+- Substrings of length 4: "code" has an appeal of 4. The sum is 4.
+
+The total sum is 4 + 6 + 6 + 4 = 20. 
+
+**Constraints:**
+
+*   1 <= s.length <= 105
+*   `s` consists of lowercase English letters.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun appealSum(s: String): Long {
+        val len = s.length
+        val lastPos = IntArray(26)
+        lastPos.fill(-1)
+        var res: Long = 0
+        for (i in 0 until len) {
+            val idx = s[i].code - 'a'.code
+            res += ((i - lastPos[idx]) * (len - i)).toLong()
+            lastPos[idx] = i
+        }
+        return res
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2264_largest_3_same_digit_number_in_string/readme.md b/src/main/kotlin/g2201_2300/s2264_largest_3_same_digit_number_in_string/readme.md
new file mode 100644
index 00000000..9531e107
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2264_largest_3_same_digit_number_in_string/readme.md
@@ -0,0 +1,72 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2264\. Largest 3-Same-Digit Number in String
+
+Easy
+
+You are given a string `num` representing a large integer. An integer is **good** if it meets the following conditions:
+
+*   It is a **substring** of `num` with length `3`.
+*   It consists of only one unique digit.
+
+Return _the **maximum good** integer as a **string** or an empty string_ `""` _if no such integer exists_.
+
+Note:
+
+*   A **substring** is a contiguous sequence of characters within a string.
+*   There may be **leading zeroes** in `num` or a good integer.
+
+**Example 1:**
+
+**Input:** num = "6**777**133339"
+
+**Output:** "777"
+
+**Explanation:** There are two distinct good integers: "777" and "333".
+
+"777" is the largest, so we return "777". 
+
+**Example 2:**
+
+**Input:** num = "23**000**19"
+
+**Output:** "000"
+
+**Explanation:** "000" is the only good integer.
+
+**Example 3:**
+
+**Input:** num = "42352338"
+
+**Output:** ""
+
+**Explanation:** No substring of length 3 consists of only one unique digit. Therefore, there are no good integers.
+
+**Constraints:**
+
+*   `3 <= num.length <= 1000`
+*   `num` only consists of digits.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun largestGoodInteger(num: String): String {
+        var maxi = "000"
+        var c = 0
+        for (i in 0 until num.length - 2) {
+            val s = num.substring(i, i + 3)
+            if (s[0] == s[1] && s[1] == s[2]) {
+                if (s.compareTo(maxi) >= 0) {
+                    maxi = s
+                }
+                ++c
+            }
+        }
+        return if (c == 0) {
+            ""
+        } else maxi
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2265_count_nodes_equal_to_average_of_subtree/readme.md b/src/main/kotlin/g2201_2300/s2265_count_nodes_equal_to_average_of_subtree/readme.md
new file mode 100644
index 00000000..07668955
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2265_count_nodes_equal_to_average_of_subtree/readme.md
@@ -0,0 +1,86 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2265\. Count Nodes Equal to Average of Subtree
+
+Medium
+
+Given the `root` of a binary tree, return _the number of nodes where the value of the node is equal to the **average** of the values in its **subtree**_.
+
+**Note:**
+
+*   The **average** of `n` elements is the **sum** of the `n` elements divided by `n` and **rounded down** to the nearest integer.
+*   A **subtree** of `root` is a tree consisting of `root` and all of its descendants.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/03/15/image-20220315203925-1.png)
+
+**Input:** root = [4,8,5,0,1,null,6]
+
+**Output:** 5
+
+**Explanation:**
+
+For the node with value 4: The average of its subtree is (4 + 8 + 5 + 0 + 1 + 6) / 6 = 24 / 6 = 4.
+
+For the node with value 5: The average of its subtree is (5 + 6) / 2 = 11 / 2 = 5.
+
+For the node with value 0: The average of its subtree is 0 / 1 = 0.
+
+For the node with value 1: The average of its subtree is 1 / 1 = 1.
+
+For the node with value 6: The average of its subtree is 6 / 1 = 6.
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2022/03/26/image-20220326133920-1.png)
+
+**Input:** root = [1]
+
+**Output:** 1
+
+**Explanation:** For the node with value 1: The average of its subtree is 1 / 1 = 1.
+
+**Constraints:**
+
+*   The number of nodes in the tree is in the range `[1, 1000]`.
+*   `0 <= Node.val <= 1000`
+
+## Solution
+
+```kotlin
+import com_github_leetcode.TreeNode
+
+/*
+ * Example:
+ * var ti = TreeNode(5)
+ * var v = ti.`val`
+ * Definition for a binary tree node.
+ * class TreeNode(var `val`: Int) {
+ *     var left: TreeNode? = null
+ *     var right: TreeNode? = null
+ * }
+ */
+class Solution {
+    private var ans = 0
+    fun averageOfSubtree(root: TreeNode?): Int {
+        dfs(root)
+        return ans
+    }
+
+    private fun dfs(node: TreeNode?): IntArray {
+        if (node == null) {
+            return intArrayOf(0, 0)
+        }
+        val left = dfs(node.left)
+        val right = dfs(node.right)
+        val currsum = left[0] + right[0] + node.`val`
+        val currcount = left[1] + right[1] + 1
+        if (currsum / currcount == node.`val`) {
+            ++ans
+        }
+        return intArrayOf(currsum, currcount)
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2266_count_number_of_texts/readme.md b/src/main/kotlin/g2201_2300/s2266_count_number_of_texts/readme.md
new file mode 100644
index 00000000..b91ee499
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2266_count_number_of_texts/readme.md
@@ -0,0 +1,93 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2266\. Count Number of Texts
+
+Medium
+
+Alice is texting Bob using her phone. The **mapping** of digits to letters is shown in the figure below.
+
+![](https://assets.leetcode.com/uploads/2022/03/15/1200px-telephone-keypad2svg.png)
+
+In order to **add** a letter, Alice has to **press** the key of the corresponding digit `i` times, where `i` is the position of the letter in the key.
+
+*   For example, to add the letter `'s'`, Alice has to press `'7'` four times. Similarly, to add the letter `'k'`, Alice has to press `'5'` twice.
+*   Note that the digits `'0'` and `'1'` do not map to any letters, so Alice **does not** use them.
+
+However, due to an error in transmission, Bob did not receive Alice's text message but received a **string of pressed keys** instead.
+
+*   For example, when Alice sent the message `"bob"`, Bob received the string `"2266622"`.
+
+Given a string `pressedKeys` representing the string received by Bob, return _the **total number of possible text messages** Alice could have sent_.
+
+Since the answer may be very large, return it **modulo** 109 + 7.
+
+**Example 1:**
+
+**Input:** pressedKeys = "22233"
+
+**Output:** 8
+
+**Explanation:** 
+
+The possible text messages Alice could have sent are: 
+
+"aaadd", "abdd", "badd", "cdd", "aaae", "abe", "bae", and "ce". 
+
+Since there are 8 possible messages, we return 8.
+
+**Example 2:**
+
+**Input:** pressedKeys = "222222222222222222222222222222222222"
+
+**Output:** 82876089
+
+**Explanation:** There are 2082876103 possible text messages Alice could have sent. 
+
+Since we need to return the answer modulo 109 + 7, we return 2082876103 % (109 + 7) = 82876089.
+
+**Constraints:**
+
+*   1 <= pressedKeys.length <= 105
+*   `pressedKeys` only consists of digits from `'2'` - `'9'`.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun countTexts(pressedKeys: String): Int {
+        val len = pressedKeys.length
+        var dp0 = 1L
+        var dp1: Long = 0
+        var dp2: Long = 0
+        var dp3: Long = 0
+        var dp4: Long
+        val keys = pressedKeys.toCharArray()
+        val base = 1000000007
+        for (i in 1 until len) {
+            val r = keys[i].code - '0'.code
+            dp4 = dp3
+            dp3 = dp2
+            dp2 = dp1
+            dp1 = dp0 % base
+            dp0 = dp1
+            dp0 += (if (i - 1 == 0 && keys[i] == keys[i - 1]) 1 else 0).toLong()
+            if (i - 1 <= 0 || keys[i] != keys[i - 1]) {
+                continue
+            }
+            dp0 += dp2
+            dp0 += (if (i - 2 == 0 && keys[i] == keys[i - 2]) 1 else 0).toLong()
+            if (i - 2 <= 0 || keys[i] != keys[i - 2]) {
+                continue
+            }
+            dp0 += dp3
+            dp0 += (if (i - 3 == 0 && keys[i] == keys[i - 3] && (r == 7 || r == 9)) 1 else 0).toLong()
+            if (i - 3 <= 0 || keys[i] != keys[i - 3] || r != 7 && r != 9) {
+                continue
+            }
+            dp0 += dp4
+        }
+        return (dp0 % base).toInt()
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2267_check_if_there_is_a_valid_parentheses_string_path/readme.md b/src/main/kotlin/g2201_2300/s2267_check_if_there_is_a_valid_parentheses_string_path/readme.md
new file mode 100644
index 00000000..11a6c093
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2267_check_if_there_is_a_valid_parentheses_string_path/readme.md
@@ -0,0 +1,119 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2267\. Check if There Is a Valid Parentheses String Path
+
+Hard
+
+A parentheses string is a **non-empty** string consisting only of `'('` and `')'`. It is **valid** if **any** of the following conditions is **true**:
+
+*   It is `()`.
+*   It can be written as `AB` (`A` concatenated with `B`), where `A` and `B` are valid parentheses strings.
+*   It can be written as `(A)`, where `A` is a valid parentheses string.
+
+You are given an `m x n` matrix of parentheses `grid`. A **valid parentheses string path** in the grid is a path satisfying **all** of the following conditions:
+
+*   The path starts from the upper left cell `(0, 0)`.
+*   The path ends at the bottom-right cell `(m - 1, n - 1)`.
+*   The path only ever moves **down** or **right**.
+*   The resulting parentheses string formed by the path is **valid**.
+
+Return `true` _if there exists a **valid parentheses string path** in the grid._ Otherwise, return `false`.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/03/15/example1drawio.png)
+
+**Input:** grid = \[\["(","(","("],[")","(",")"],["(","(",")"],["(","(",")"]]
+
+**Output:** true
+
+**Explanation:** The above diagram shows two possible paths that form valid parentheses strings. 
+
+The first path shown results in the valid parentheses string "()(())". 
+
+The second path shown results in the valid parentheses string "((()))". 
+
+Note that there may be other valid parentheses string paths.
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2022/03/15/example2drawio.png)
+
+**Input:** grid = \[\[")",")"],["(","("]]
+
+**Output:** false
+
+**Explanation:** The two possible paths form the parentheses strings "))(" and ")((". Since neither of them are valid parentheses strings, we return false.
+
+**Constraints:**
+
+*   `m == grid.length`
+*   `n == grid[i].length`
+*   `1 <= m, n <= 100`
+*   `grid[i][j]` is either `'('` or `')'`.
+
+## Solution
+
+```kotlin
+@Suppress("NAME_SHADOWING")
+class Solution {
+    private lateinit var grid: Array
+    private var m = 0
+    private var n = 0
+
+    fun hasValidPath(grid: Array): Boolean {
+        this.grid = grid
+        m = grid.size
+        n = grid[0].size
+        val dp = Array(m) { Array(n) { arrayOfNulls(m + n + 1) } }
+        if (grid[0][0] == RGTPAR) {
+            return false
+        }
+        return if ((m + n) % 2 == 0) {
+            false
+        } else dfs(0, 0, 0, 0, dp)
+    }
+
+    private fun dfs(u: Int, v: Int, open: Int, close: Int, dp: Array>>): Boolean {
+        var open = open
+        var close = close
+        if (grid[u][v] == LFTPAR) {
+            open++
+        } else {
+            close++
+        }
+        if (u == m - 1 && v == n - 1) {
+            return open == close
+        }
+        if (open < close) {
+            return false
+        }
+        if (dp[u][v][open - close] != null) {
+            return dp[u][v][open - close]!!
+        }
+        if (u == m - 1) {
+            val result = dfs(u, v + 1, open, close, dp)
+            dp[u][v][open - close] = result
+            return result
+        }
+        if (v == n - 1) {
+            return dfs(u + 1, v, open, close, dp)
+        }
+        val rslt: Boolean
+        rslt =
+            if (grid[u][v] == LFTPAR) {
+                dfs(u + 1, v, open, close, dp) || dfs(u, v + 1, open, close, dp)
+            } else {
+                dfs(u, v + 1, open, close, dp) || dfs(u + 1, v, open, close, dp)
+            }
+        dp[u][v][open - close] = rslt
+        return rslt
+    }
+
+    companion object {
+        private const val LFTPAR = '('
+        private const val RGTPAR = ')'
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2269_find_the_k_beauty_of_a_number/readme.md b/src/main/kotlin/g2201_2300/s2269_find_the_k_beauty_of_a_number/readme.md
new file mode 100644
index 00000000..4b57ce6f
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2269_find_the_k_beauty_of_a_number/readme.md
@@ -0,0 +1,88 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2269\. Find the K-Beauty of a Number
+
+Easy
+
+The **k-beauty** of an integer `num` is defined as the number of **substrings** of `num` when it is read as a string that meet the following conditions:
+
+*   It has a length of `k`.
+*   It is a divisor of `num`.
+
+Given integers `num` and `k`, return _the k-beauty of_ `num`.
+
+Note:
+
+*   **Leading zeros** are allowed.
+*   `0` is not a divisor of any value.
+
+A **substring** is a contiguous sequence of characters in a string.
+
+**Example 1:**
+
+**Input:** num = 240, k = 2
+
+**Output:** 2
+
+**Explanation:** The following are the substrings of num of length k:
+
+- "24" from "**24**0": 24 is a divisor of 240.
+
+- "40" from "2**40**": 40 is a divisor of 240.
+
+Therefore, the k-beauty is 2. 
+
+**Example 2:**
+
+**Input:** num = 430043, k = 2
+
+**Output:** 2
+
+**Explanation:** The following are the substrings of num of length k:
+
+- "43" from "**43**0043": 43 is a divisor of 430043.
+
+- "30" from "4**30**043": 30 is not a divisor of 430043.
+
+- "00" from "43**00**43": 0 is not a divisor of 430043.
+
+- "04" from "430**04**3": 4 is not a divisor of 430043.
+
+- "43" from "4300**43**": 43 is a divisor of 430043.
+
+Therefore, the k-beauty is 2. 
+
+**Constraints:**
+
+*   1 <= num <= 109
+*   `1 <= k <= num.length` (taking `num` as a string)
+
+## Solution
+
+```kotlin
+class Solution {
+    fun divisorSubstrings(num: Int, k: Int): Int {
+        var i = 0
+        var j = 0
+        var count = 0
+        val s = num.toString()
+        val sb = StringBuilder()
+        while (i < s.length && j < s.length) {
+            sb.append(s[j].code - '0'.code)
+            val `val` = sb.toString().toInt()
+            if (j - i + 1 == k) {
+                if (`val` != 0 && num % `val` == 0) {
+                    count++
+                }
+                sb.deleteCharAt(0)
+                i++
+                j++
+            } else {
+                j++
+            }
+        }
+        return count
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2270_number_of_ways_to_split_array/readme.md b/src/main/kotlin/g2201_2300/s2270_number_of_ways_to_split_array/readme.md
new file mode 100644
index 00000000..7286d2cb
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2270_number_of_ways_to_split_array/readme.md
@@ -0,0 +1,69 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2270\. Number of Ways to Split Array
+
+Medium
+
+You are given a **0-indexed** integer array `nums` of length `n`.
+
+`nums` contains a **valid split** at index `i` if the following are true:
+
+*   The sum of the first `i + 1` elements is **greater than or equal to** the sum of the last `n - i - 1` elements.
+*   There is **at least one** element to the right of `i`. That is, `0 <= i < n - 1`.
+
+Return _the number of **valid splits** in_ `nums`.
+
+**Example 1:**
+
+**Input:** nums = [10,4,-8,7]
+
+**Output:** 2
+
+**Explanation:** There are three ways of splitting nums into two non-empty parts: 
+
+- Split nums at index 0. Then, the first part is [10], and its sum is 10. The second part is [4,-8,7], and its sum is 3. Since 10 >= 3, i = 0 is a valid split. 
+
+- Split nums at index 1. Then, the first part is [10,4], and its sum is 14. The second part is [-8,7], and its sum is -1. Since 14 >= -1, i = 1 is a valid split. 
+
+- Split nums at index 2. Then, the first part is [10,4,-8], and its sum is 6. The second part is [7], and its sum is 7. Since 6 < 7, i = 2 is not a valid split. Thus, the number of valid splits in nums is 2.
+
+**Example 2:**
+
+**Input:** nums = [2,3,1,0]
+
+**Output:** 2
+
+**Explanation:** There are two valid splits in nums:
+
+- Split nums at index 1. Then, the first part is [2,3], and its sum is 5. The second part is [1,0], and its sum is 1. Since 5 >= 1, i = 1 is a valid split. 
+
+- Split nums at index 2. Then, the first part is [2,3,1], and its sum is 6. The second part is [0], and its sum is 0. Since 6 >= 0, i = 2 is a valid split.
+
+**Constraints:**
+
+*   2 <= nums.length <= 105
+*   -105 <= nums[i] <= 105
+
+## Solution
+
+```kotlin
+class Solution {
+    fun waysToSplitArray(nums: IntArray): Int {
+        var leftSum: Long = 0
+        var rightSum: Long = 0
+        for (i in nums) {
+            rightSum += i.toLong()
+        }
+        var count = 0
+        for (i in 0 until nums.size - 1) {
+            rightSum -= nums[i].toLong()
+            leftSum += nums[i].toLong()
+            if (leftSum >= rightSum) {
+                count++
+            }
+        }
+        return count
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2271_maximum_white_tiles_covered_by_a_carpet/readme.md b/src/main/kotlin/g2201_2300/s2271_maximum_white_tiles_covered_by_a_carpet/readme.md
new file mode 100644
index 00000000..2fc022b8
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2271_maximum_white_tiles_covered_by_a_carpet/readme.md
@@ -0,0 +1,77 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2271\. Maximum White Tiles Covered by a Carpet
+
+Medium
+
+You are given a 2D integer array `tiles` where tiles[i] = [li, ri] represents that every tile `j` in the range li <= j <= ri is colored white.
+
+You are also given an integer `carpetLen`, the length of a single carpet that can be placed **anywhere**.
+
+Return _the **maximum** number of white tiles that can be covered by the carpet_.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/03/25/example1drawio3.png)
+
+**Input:** tiles = \[\[1,5],[10,11],[12,18],[20,25],[30,32]], carpetLen = 10
+
+**Output:** 9
+
+**Explanation:** Place the carpet starting on tile 10. 
+
+It covers 9 white tiles, so we return 9. 
+
+Note that there may be other places where the carpet covers 9 white tiles. 
+
+It can be shown that the carpet cannot cover more than 9 white tiles.
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2022/03/24/example2drawio.png)
+
+**Input:** tiles = \[\[10,11],[1,1]], carpetLen = 2
+
+**Output:** 2
+
+**Explanation:** Place the carpet starting on tile 10. 
+
+It covers 2 white tiles, so we return 2.
+
+**Constraints:**
+
+*   1 <= tiles.length <= 5 * 104
+*   `tiles[i].length == 2`
+*   1 <= li <= ri <= 109
+*   1 <= carpetLen <= 109
+*   The `tiles` are **non-overlapping**.
+
+## Solution
+
+```kotlin
+import java.util.Arrays
+
+class Solution {
+    fun maximumWhiteTiles(tiles: Array, carpetLength: Int): Int {
+        Arrays.sort(tiles, { x: IntArray, y: IntArray -> x[0].compareTo(y[0]) })
+        var currentCover = Math.min(tiles[0][1] - tiles[0][0] + 1, carpetLength)
+        var maxCover = currentCover
+        var head = 1
+        var tail = 0
+        while (tail < tiles.size && head < tiles.size && maxCover < carpetLength) {
+            if (tiles[head][1] - tiles[tail][0] + 1 <= carpetLength) {
+                currentCover += tiles[head][1] - tiles[head][0] + 1
+                maxCover = Math.max(maxCover, currentCover)
+                ++head
+            } else {
+                val possiblePartialCoverOverCurrentHead = carpetLength - (tiles[head][0] - tiles[tail][0])
+                maxCover = Math.max(maxCover, currentCover + possiblePartialCoverOverCurrentHead)
+                currentCover = currentCover - (tiles[tail][1] - tiles[tail][0] + 1)
+                ++tail
+            }
+        }
+        return maxCover
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2272_substring_with_largest_variance/readme.md b/src/main/kotlin/g2201_2300/s2272_substring_with_largest_variance/readme.md
new file mode 100644
index 00000000..91b1b7fc
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2272_substring_with_largest_variance/readme.md
@@ -0,0 +1,86 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2272\. Substring With Largest Variance
+
+Hard
+
+The **variance** of a string is defined as the largest difference between the number of occurrences of **any** `2` characters present in the string. Note the two characters may or may not be the same.
+
+Given a string `s` consisting of lowercase English letters only, return _the **largest variance** possible among all **substrings** of_ `s`.
+
+A **substring** is a contiguous sequence of characters within a string.
+
+**Example 1:**
+
+**Input:** s = "aababbb"
+
+**Output:** 3
+
+**Explanation:** All possible variances along with their respective substrings are listed below: 
+
+- Variance 0 for substrings "a", "aa", "ab", "abab", "aababb", "ba", "b", "bb", and "bbb". 
+
+- Variance 1 for substrings "aab", "aba", "abb", "aabab", "ababb", "aababbb", and "bab". 
+
+- Variance 2 for substrings "aaba", "ababbb", "abbb", and "babb". 
+
+- Variance 3 for substring "babbb". 
+  
+Since the largest possible variance is 3, we return it.
+
+**Example 2:**
+
+**Input:** s = "abcde"
+
+**Output:** 0
+
+**Explanation:** No letter occurs more than once in s, so the variance of every substring is 0.
+
+**Constraints:**
+
+*   1 <= s.length <= 104
+*   `s` consists of lowercase English letters.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun largestVariance(s: String): Int {
+        val freq = IntArray(26)
+        for (i in 0 until s.length) {
+            freq[s[i].code - 'a'.code]++
+        }
+        var maxVariance = 0
+        for (a in 0..25) {
+            for (b in 0..25) {
+                var remainingA = freq[a]
+                val remainingB = freq[b]
+                if (a == b || remainingA == 0 || remainingB == 0) {
+                    continue
+                }
+                var currBFreq = 0
+                var currAFreq = 0
+                for (i in 0 until s.length) {
+                    val c = s[i].code - 'a'.code
+                    if (c == b) {
+                        currBFreq++
+                    }
+                    if (c == a) {
+                        currAFreq++
+                        remainingA--
+                    }
+                    if (currAFreq > 0) {
+                        maxVariance = Math.max(maxVariance, currBFreq - currAFreq)
+                    }
+                    if (currBFreq < currAFreq && remainingA >= 1) {
+                        currBFreq = 0
+                        currAFreq = 0
+                    }
+                }
+            }
+        }
+        return maxVariance
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2273_find_resultant_array_after_removing_anagrams/readme.md b/src/main/kotlin/g2201_2300/s2273_find_resultant_array_after_removing_anagrams/readme.md
new file mode 100644
index 00000000..18de49e1
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2273_find_resultant_array_after_removing_anagrams/readme.md
@@ -0,0 +1,89 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2273\. Find Resultant Array After Removing Anagrams
+
+Easy
+
+You are given a **0-indexed** string array `words`, where `words[i]` consists of lowercase English letters.
+
+In one operation, select any index `i` such that `0 < i < words.length` and `words[i - 1]` and `words[i]` are **anagrams**, and **delete** `words[i]` from `words`. Keep performing this operation as long as you can select an index that satisfies the conditions.
+
+Return `words` _after performing all operations_. It can be shown that selecting the indices for each operation in **any** arbitrary order will lead to the same result.
+
+An **Anagram** is a word or phrase formed by rearranging the letters of a different word or phrase using all the original letters exactly once. For example, `"dacb"` is an anagram of `"abdc"`.
+
+**Example 1:**
+
+**Input:** words = ["abba","baba","bbaa","cd","cd"]
+
+**Output:** ["abba","cd"]
+
+**Explanation:** One of the ways we can obtain the resultant array is by using the following operations: 
+
+- Since words[2] = "bbaa" and words[1] = "baba" are anagrams, we choose index 2 and delete words[2]. Now words = ["abba","baba","cd","cd"]. 
+
+- Since words[1] = "baba" and words[0] = "abba" are anagrams, we choose index 1 and delete words[1]. Now words = ["abba","cd","cd"]. 
+
+- Since words[2] = "cd" and words[1] = "cd" are anagrams, we choose index 2 and delete words[2]. Now words = ["abba","cd"]. 
+  
+We can no longer perform any operations, so ["abba","cd"] is the final answer.
+
+**Example 2:**
+
+**Input:** words = ["a","b","c","d","e"]
+
+**Output:** ["a","b","c","d","e"]
+
+**Explanation:** No two adjacent strings in words are anagrams of each other, so no operations are performed.
+
+**Constraints:**
+
+*   `1 <= words.length <= 100`
+*   `1 <= words[i].length <= 10`
+*   `words[i]` consists of lowercase English letters.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun removeAnagrams(words: Array): List {
+        val result: MutableList = ArrayList()
+        if (words.isEmpty()) {
+            return result
+        }
+        var uniqueWordIdx = 0
+        var currIdx = 1
+        result.add(words[uniqueWordIdx])
+        while (currIdx < words.size) {
+            if (!isAnagram(words[currIdx], words[uniqueWordIdx])) {
+                uniqueWordIdx = currIdx
+                result.add(words[uniqueWordIdx])
+            }
+            currIdx++
+        }
+        return result
+    }
+
+    /*
+    Utility to check if the 2 words are anagrams or not
+    */
+    private fun isAnagram(word1: String, word2: String): Boolean {
+        val charMap = IntArray(26)
+        val word1Arr = word1.toCharArray()
+        val word2Arr = word2.toCharArray()
+        for (a in word1Arr) {
+            charMap[a.code - 'a'.code]++
+        }
+        for (a in word2Arr) {
+            charMap[a.code - 'a'.code]--
+        }
+        for (a in charMap) {
+            if (a != 0) {
+                return false
+            }
+        }
+        return true
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2274_maximum_consecutive_floors_without_special_floors/readme.md b/src/main/kotlin/g2201_2300/s2274_maximum_consecutive_floors_without_special_floors/readme.md
new file mode 100644
index 00000000..83c0bace
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2274_maximum_consecutive_floors_without_special_floors/readme.md
@@ -0,0 +1,66 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2274\. Maximum Consecutive Floors Without Special Floors
+
+Medium
+
+Alice manages a company and has rented some floors of a building as office space. Alice has decided some of these floors should be **special floors**, used for relaxation only.
+
+You are given two integers `bottom` and `top`, which denote that Alice has rented all the floors from `bottom` to `top` (**inclusive**). You are also given the integer array `special`, where `special[i]` denotes a special floor that Alice has designated for relaxation.
+
+Return _the **maximum** number of consecutive floors without a special floor_.
+
+**Example 1:**
+
+**Input:** bottom = 2, top = 9, special = [4,6]
+
+**Output:** 3
+
+**Explanation:** The following are the ranges (inclusive) of consecutive floors without a special floor:
+
+- (2, 3) with a total amount of 2 floors.
+
+- (5, 5) with a total amount of 1 floor.
+
+- (7, 9) with a total amount of 3 floors.
+
+Therefore, we return the maximum number which is 3 floors. 
+
+**Example 2:**
+
+**Input:** bottom = 6, top = 8, special = [7,6,8]
+
+**Output:** 0
+
+**Explanation:** Every floor rented is a special floor, so we return 0. 
+
+**Constraints:**
+
+*   1 <= special.length <= 105
+*   1 <= bottom <= special[i] <= top <= 109
+*   All the values of `special` are **unique**.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun maxConsecutive(bottom: Int, top: Int, special: IntArray): Int {
+        special.sort()
+        var start = bottom
+        var ans = 0
+        for (j in special) {
+            if (j - start > ans) {
+                ans = j - start
+                start = j + 1
+            } else {
+                start = j + 1
+            }
+        }
+        if (ans < top - special[special.size - 1]) {
+            ans = top - special[special.size - 1]
+        }
+        return ans
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2275_largest_combination_with_bitwise_and_greater_than_zero/readme.md b/src/main/kotlin/g2201_2300/s2275_largest_combination_with_bitwise_and_greater_than_zero/readme.md
new file mode 100644
index 00000000..9610971d
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2275_largest_combination_with_bitwise_and_greater_than_zero/readme.md
@@ -0,0 +1,70 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2275\. Largest Combination With Bitwise AND Greater Than Zero
+
+Medium
+
+The **bitwise AND** of an array `nums` is the bitwise AND of all integers in `nums`.
+
+*   For example, for `nums = [1, 5, 3]`, the bitwise AND is equal to `1 & 5 & 3 = 1`.
+*   Also, for `nums = [7]`, the bitwise AND is `7`.
+
+You are given an array of positive integers `candidates`. Evaluate the **bitwise AND** of every **combination** of numbers of `candidates`. Each number in `candidates` may only be used **once** in each combination.
+
+Return _the size of the **largest** combination of_ `candidates` _with a bitwise AND **greater** than_ `0`.
+
+**Example 1:**
+
+**Input:** candidates = [16,17,71,62,12,24,14]
+
+**Output:** 4
+
+**Explanation:** The combination [16,17,62,24] has a bitwise AND of 16 & 17 & 62 & 24 = 16 > 0. 
+
+The size of the combination is 4. 
+
+It can be shown that no combination with a size greater than 4 has a bitwise AND greater than 0.
+
+Note that more than one combination may have the largest size. 
+
+For example, the combination [62,12,24,14] has a bitwise AND of 62 & 12 & 24 & 14 = 8 > 0.
+
+**Example 2:**
+
+**Input:** candidates = [8,8]
+
+**Output:** 2
+
+**Explanation:** The largest combination [8,8] has a bitwise AND of 8 & 8 = 8 > 0. 
+
+The size of the combination is 2, so we return 2.
+
+**Constraints:**
+
+*   1 <= candidates.length <= 105
+*   1 <= candidates[i] <= 107
+
+## Solution
+
+```kotlin
+class Solution {
+    fun largestCombination(candidates: IntArray): Int {
+        val bits = IntArray(32)
+        for (x in candidates) {
+            var i = 0
+            var localX = x
+            while (localX != 0) {
+                bits[i] += localX and 1
+                i++
+                localX = localX shr 1
+            }
+        }
+        var ans = 0
+        for (b in bits) {
+            ans = Math.max(ans, b)
+        }
+        return ans
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2276_count_integers_in_intervals/readme.md b/src/main/kotlin/g2201_2300/s2276_count_integers_in_intervals/readme.md
new file mode 100644
index 00000000..4de09ff4
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2276_count_integers_in_intervals/readme.md
@@ -0,0 +1,93 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2276\. Count Integers in Intervals
+
+Hard
+
+Given an **empty** set of intervals, implement a data structure that can:
+
+*   **Add** an interval to the set of intervals.
+*   **Count** the number of integers that are present in **at least one** interval.
+
+Implement the `CountIntervals` class:
+
+*   `CountIntervals()` Initializes the object with an empty set of intervals.
+*   `void add(int left, int right)` Adds the interval `[left, right]` to the set of intervals.
+*   `int count()` Returns the number of integers that are present in **at least one** interval.
+
+**Note** that an interval `[left, right]` denotes all the integers `x` where `left <= x <= right`.
+
+**Example 1:**
+
+**Input**
+
+["CountIntervals", "add", "add", "count", "add", "count"]
+
+[[], [2, 3], [7, 10], [], [5, 8], []]
+
+**Output:** [null, null, null, 6, null, 8]
+
+**Explanation:**
+
+    CountIntervals countIntervals = new CountIntervals(); // initialize the object with an empty set of intervals.
+    countIntervals.add(2, 3);  // add [2, 3] to the set of intervals.
+    countIntervals.add(7, 10); // add [7, 10] to the set of intervals.
+    countIntervals.count();    // return 6
+                               // the integers 2 and 3 are present in the interval [2, 3].
+                               // the integers 7, 8, 9, and 10 are present in the interval [7, 10].
+    countIntervals.add(5, 8);  // add [5, 8] to the set of intervals.
+    countIntervals.count();    // return 8
+                               // the integers 2 and 3 are present in the interval [2, 3].
+                               // the integers 5 and 6 are present in the interval [5, 8].
+                               // the integers 7 and 8 are present in the intervals [5, 8] and [7, 10].
+                               // the integers 9 and 10 are present in the interval [7, 10].
+
+**Constraints:**
+
+*   1 <= left <= right <= 109
+*   At most 105 calls **in total** will be made to `add` and `count`.
+*   At least **one** call will be made to `count`.
+
+## Solution
+
+```kotlin
+import java.util.TreeMap
+
+@Suppress("NAME_SHADOWING")
+class CountIntervals {
+    private val map: TreeMap = TreeMap()
+    private var count: Int
+
+    init {
+        map[-1] = -1
+        map[1000000001] = 1000000001
+        count = 0
+    }
+
+    fun add(left: Int, right: Int) {
+        var left = left
+        var right = right
+        var item = if (map.floorEntry(left).value < left) map.ceilingEntry(left) else map.floorEntry(left)
+        while (item.key <= right) {
+            left = Math.min(left, item.key)
+            right = Math.max(right, item.value)
+            count -= item.value - item.key + 1
+            map.remove(item.key)
+            item = map.ceilingEntry(item.key)
+        }
+        map[left] = right
+        count += right - left + 1
+    }
+
+    fun count(): Int {
+        return count
+    }
+}
+/*
+ * Your CountIntervals object will be instantiated and called as such:
+ * var obj = CountIntervals()
+ * obj.add(left,right)
+ * var param_2 = obj.count()
+ */
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2278_percentage_of_letter_in_string/readme.md b/src/main/kotlin/g2201_2300/s2278_percentage_of_letter_in_string/readme.md
new file mode 100644
index 00000000..9f042d06
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2278_percentage_of_letter_in_string/readme.md
@@ -0,0 +1,51 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2278\. Percentage of Letter in String
+
+Easy
+
+Given a string `s` and a character `letter`, return _the **percentage** of characters in_ `s` _that equal_ `letter` _**rounded down** to the nearest whole percent._
+
+**Example 1:**
+
+**Input:** s = "foobar", letter = "o"
+
+**Output:** 33
+
+**Explanation:**
+
+The percentage of characters in s that equal the letter 'o' is 2 / 6 \* 100% = 33% when rounded down, so we return 33.
+
+**Example 2:**
+
+**Input:** s = "jjjj", letter = "k"
+
+**Output:** 0
+
+**Explanation:**
+
+The percentage of characters in s that equal the letter 'k' is 0%, so we return 0.
+
+**Constraints:**
+
+*   `1 <= s.length <= 100`
+*   `s` consists of lowercase English letters.
+*   `letter` is a lowercase English letter.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun percentageLetter(s: String, letter: Char): Int {
+        var count = 0
+        val n = s.length
+        for (i in 0 until n) {
+            if (s[i] == letter) {
+                ++count
+            }
+        }
+        return count * 100 / n
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2279_maximum_bags_with_full_capacity_of_rocks/readme.md b/src/main/kotlin/g2201_2300/s2279_maximum_bags_with_full_capacity_of_rocks/readme.md
new file mode 100644
index 00000000..eccd589f
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2279_maximum_bags_with_full_capacity_of_rocks/readme.md
@@ -0,0 +1,84 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2279\. Maximum Bags With Full Capacity of Rocks
+
+Medium
+
+You have `n` bags numbered from `0` to `n - 1`. You are given two **0-indexed** integer arrays `capacity` and `rocks`. The ith bag can hold a maximum of `capacity[i]` rocks and currently contains `rocks[i]` rocks. You are also given an integer `additionalRocks`, the number of additional rocks you can place in **any** of the bags.
+
+Return _the **maximum** number of bags that could have full capacity after placing the additional rocks in some bags._
+
+**Example 1:**
+
+**Input:** capacity = [2,3,4,5], rocks = [1,2,4,4], additionalRocks = 2
+
+**Output:** 3
+
+**Explanation:**
+
+Place 1 rock in bag 0 and 1 rock in bag 1.
+
+The number of rocks in each bag are now [2,3,4,4].
+
+Bags 0, 1, and 2 have full capacity.
+
+There are 3 bags at full capacity, so we return 3.
+
+It can be shown that it is not possible to have more than 3 bags at full capacity.
+
+Note that there may be other ways of placing the rocks that result in an answer of 3. 
+
+**Example 2:**
+
+**Input:** capacity = [10,2,2], rocks = [2,2,0], additionalRocks = 100
+
+**Output:** 3
+
+**Explanation:**
+
+Place 8 rocks in bag 0 and 2 rocks in bag 2.
+
+The number of rocks in each bag are now [10,2,2].
+
+Bags 0, 1, and 2 have full capacity.
+
+There are 3 bags at full capacity, so we return 3.
+
+It can be shown that it is not possible to have more than 3 bags at full capacity.
+
+Note that we did not use all of the additional rocks. 
+
+**Constraints:**
+
+*   `n == capacity.length == rocks.length`
+*   1 <= n <= 5 * 104
+*   1 <= capacity[i] <= 109
+*   `0 <= rocks[i] <= capacity[i]`
+*   1 <= additionalRocks <= 109
+
+## Solution
+
+```kotlin
+@Suppress("NAME_SHADOWING")
+class Solution {
+    fun maximumBags(capacity: IntArray, rocks: IntArray, additionalRocks: Int): Int {
+        var additionalRocks = additionalRocks
+        val len = capacity.size
+        for (i in 0 until len) {
+            capacity[i] -= rocks[i]
+        }
+        capacity.sort()
+        var total = 0
+        var i = 0
+        while (i < len && additionalRocks > 0) {
+            if (capacity[i] <= additionalRocks) {
+                additionalRocks -= capacity[i]
+                total++
+            }
+            i++
+        }
+        return total
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2280_minimum_lines_to_represent_a_line_chart/readme.md b/src/main/kotlin/g2201_2300/s2280_minimum_lines_to_represent_a_line_chart/readme.md
new file mode 100644
index 00000000..b99e14d8
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2280_minimum_lines_to_represent_a_line_chart/readme.md
@@ -0,0 +1,87 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2280\. Minimum Lines to Represent a Line Chart
+
+Medium
+
+You are given a 2D integer array `stockPrices` where stockPrices[i] = [dayi, pricei] indicates the price of the stock on day dayi is pricei. A **line chart** is created from the array by plotting the points on an XY plane with the X-axis representing the day and the Y-axis representing the price and connecting adjacent points. One such example is shown below:
+
+![](https://assets.leetcode.com/uploads/2022/03/30/1920px-pushkin_population_historysvg.png)
+
+Return _the **minimum number of lines** needed to represent the line chart_.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/03/30/ex0.png)
+
+**Input:** stockPrices = \[\[1,7],[2,6],[3,5],[4,4],[5,4],[6,3],[7,2],[8,1]]
+
+**Output:** 3
+
+**Explanation:**
+
+The diagram above represents the input, with the X-axis representing the day and Y-axis representing the price.
+
+The following 3 lines can be drawn to represent the line chart:
+
+- Line 1 (in red) from (1,7) to (4,4) passing through (1,7), (2,6), (3,5), and (4,4).
+
+- Line 2 (in blue) from (4,4) to (5,4).
+
+- Line 3 (in green) from (5,4) to (8,1) passing through (5,4), (6,3), (7,2), and (8,1).
+
+It can be shown that it is not possible to represent the line chart using less than 3 lines. 
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2022/03/30/ex1.png)
+
+**Input:** stockPrices = \[\[3,4],[1,2],[7,8],[2,3]]
+
+**Output:** 1
+
+**Explanation:** As shown in the diagram above, the line chart can be represented with a single line. 
+
+**Constraints:**
+
+*   1 <= stockPrices.length <= 105
+*   `stockPrices[i].length == 2`
+*   1 <= dayi, pricei <= 109
+*   All dayi are **distinct**.
+
+## Solution
+
+```kotlin
+import java.util.Arrays
+
+class Solution {
+    fun minimumLines(stockPrices: Array): Int {
+        if (stockPrices.size == 1) {
+            return 0
+        }
+        Arrays.sort(stockPrices) { a: IntArray, b: IntArray -> a[0] - b[0] }
+        // multiply with 1.0 to make it double and multiply with 100 for making it big so that
+        // difference won't come out to be very less and after division it become 0.
+        // failing for one of the case without multiply 100
+        var lastSlope = (
+            (stockPrices[1][1] - stockPrices[0][1]) *
+                100 /
+                ((stockPrices[1][0] - stockPrices[0][0]) * 1.0)
+            )
+        var ans = 1
+        for (i in 2 until stockPrices.size) {
+            val curSlope = (
+                (stockPrices[i][1] - stockPrices[i - 1][1]) *
+                    100 /
+                    ((stockPrices[i][0] - stockPrices[i - 1][0]) * 1.0)
+                )
+            if (lastSlope != curSlope) {
+                lastSlope = curSlope
+                ans++
+            }
+        }
+        return ans
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2281_sum_of_total_strength_of_wizards/readme.md b/src/main/kotlin/g2201_2300/s2281_sum_of_total_strength_of_wizards/readme.md
new file mode 100644
index 00000000..7ba60779
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2281_sum_of_total_strength_of_wizards/readme.md
@@ -0,0 +1,182 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2281\. Sum of Total Strength of Wizards
+
+Hard
+
+As the ruler of a kingdom, you have an army of wizards at your command.
+
+You are given a **0-indexed** integer array `strength`, where `strength[i]` denotes the strength of the ith wizard. For a **contiguous** group of wizards (i.e. the wizards' strengths form a **subarray** of `strength`), the **total strength** is defined as the **product** of the following two values:
+
+*   The strength of the **weakest** wizard in the group.
+*   The **total** of all the individual strengths of the wizards in the group.
+
+Return _the **sum** of the total strengths of **all** contiguous groups of wizards_. Since the answer may be very large, return it **modulo** 109 + 7.
+
+A **subarray** is a contiguous **non-empty** sequence of elements within an array.
+
+**Example 1:**
+
+**Input:** strength = [1,3,1,2]
+
+**Output:** 44
+
+**Explanation:** The following are all the contiguous groups of wizards:
+
+- \[1] from [**1**,3,1,2] has a total strength of min([1]) \* sum([1]) = 1 \* 1 = 1
+
+- \[3] from [1,**3**,1,2] has a total strength of min([3]) \* sum([3]) = 3 \* 3 = 9
+
+- \[1] from [1,3,**1**,2] has a total strength of min([1]) \* sum([1]) = 1 \* 1 = 1
+
+- \[2] from [1,3,1,**2**] has a total strength of min([2]) \* sum([2]) = 2 \* 2 = 4
+
+- \[1,3] from [**1,3**,1,2] has a total strength of min([1,3]) \* sum([1,3]) = 1 \* 4 = 4
+
+- \[3,1] from [1,**3,1**,2] has a total strength of min([3,1]) \* sum([3,1]) = 1 \* 4 = 4
+
+- \[1,2] from [1,3,**1,2**] has a total strength of min([1,2]) \* sum([1,2]) = 1 \* 3 = 3
+
+- \[1,3,1] from [**1,3,1**,2] has a total strength of min([1,3,1]) \* sum([1,3,1]) = 1 \* 5 = 5
+
+- \[3,1,2] from [1,**3,1,2**] has a total strength of min([3,1,2]) \* sum([3,1,2]) = 1 \* 6 = 6
+
+- \[1,3,1,2] from [**1,3,1,2**] has a total strength of min([1,3,1,2]) \* sum([1,3,1,2]) = 1 \* 7 = 7
+
+The sum of all the total strengths is 1 + 9 + 1 + 4 + 4 + 4 + 3 + 5 + 6 + 7 = 44.
+
+**Example 2:**
+
+**Input:** strength = [5,4,6]
+
+**Output:** 213
+
+**Explanation:** The following are all the contiguous groups of wizards:
+
+- \[5] from [**5**,4,6] has a total strength of min([5]) \* sum([5]) = 5 \* 5 = 25
+
+- \[4] from [5,**4**,6] has a total strength of min([4]) \* sum([4]) = 4 \* 4 = 16
+
+- \[6] from [5,4,**6**] has a total strength of min([6]) \* sum([6]) = 6 \* 6 = 36
+
+- \[5,4] from [**5,4**,6] has a total strength of min([5,4]) \* sum([5,4]) = 4 \* 9 = 36
+
+- \[4,6] from [5,**4,6**] has a total strength of min([4,6]) \* sum([4,6]) = 4 \* 10 = 40
+
+- \[5,4,6] from [**5,4,6**] has a total strength of min([5,4,6]) \* sum([5,4,6]) = 4 \* 15 = 60
+
+The sum of all the total strengths is 25 + 16 + 36 + 36 + 40 + 60 = 213.
+
+**Constraints:**
+
+*   1 <= strength.length <= 105
+*   1 <= strength[i] <= 109
+
+## Solution
+
+```kotlin
+import java.util.Deque
+import java.util.LinkedList
+
+@Suppress("kotlin:S107")
+class Solution {
+    fun totalStrength(nums: IntArray): Int {
+        val n = nums.size
+        val forward = LongArray(n)
+        val backward = LongArray(n)
+        val prefix = LongArray(n + 1)
+        val suffix = LongArray(n + 1)
+        prefix[1] = nums[0].toLong()
+        forward[0] = prefix[1]
+        suffix[n - 1] = nums[n - 1].toLong()
+        backward[n - 1] = suffix[n - 1]
+        for (i in 1 until n) {
+            forward[i] = nums[i] + forward[i - 1]
+            prefix[i + 1] = prefix[i] + forward[i]
+        }
+        run {
+            var i = n - 2
+            while (0 <= i) {
+                backward[i] = nums[i] + backward[i + 1]
+                suffix[i] = suffix[i + 1] + backward[i]
+                --i
+            }
+        }
+        var res: Long = 0
+        val dq: Deque = LinkedList()
+        for (i in 0 until n) {
+            while (dq.isNotEmpty() && nums[dq.peekLast()] >= nums[i]) {
+                val cur = dq.pollLast()
+                val prev = if (dq.isEmpty()) -1 else dq.peekLast()
+                res = (
+                    (
+                        res +
+                            getSum(
+                                nums, forward, prefix, backward, suffix,
+                                prev, cur, i
+                            ) *
+                                nums[cur]
+                        ) %
+                        mod
+                    )
+            }
+            dq.add(i)
+        }
+        while (dq.isNotEmpty()) {
+            val cur = dq.pollLast()
+            val prev = if (dq.isEmpty()) -1 else dq.peekLast()
+            res = (
+                (
+                    res +
+                        getSum(nums, forward, prefix, backward, suffix, prev, cur, n) *
+                            nums[cur]
+                    ) %
+                    mod
+                )
+        }
+        return res.toInt()
+    }
+
+    private fun getSum(
+        nums: IntArray,
+        forward: LongArray,
+        prefix: LongArray,
+        backward: LongArray,
+        suffix: LongArray,
+        prev: Int,
+        cur: Int,
+        next: Int
+    ): Long {
+        val sum = (cur - prev) * nums[cur].toLong() % mod * (next - cur) % mod
+        val preSum = getPresum(backward, suffix, prev + 1, cur - 1, next - cur)
+        val postSum = getPostsum(forward, prefix, cur + 1, next - 1, cur - prev)
+        return (sum + preSum + postSum) % mod
+    }
+
+    private fun getPresum(backward: LongArray, suffix: LongArray, from: Int, to: Int, m: Int): Long {
+        val n = backward.size
+        val cnt = to - from + 1L
+        return (
+            (suffix[from] - suffix[to + 1] - cnt * (if (to + 1 == n) 0 else backward[to + 1]) % mod) %
+                mod
+                * m %
+                mod
+            )
+    }
+
+    private fun getPostsum(forward: LongArray, prefix: LongArray, from: Int, to: Int, m: Int): Long {
+        val cnt = to - from + 1L
+        return (
+            (prefix[to + 1] - prefix[from] - cnt * (if (0 == from) 0 else forward[from - 1]) % mod) %
+                mod
+                * m %
+                mod
+            )
+    }
+
+    companion object {
+        private const val mod = 1e9.toInt() + 7
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2283_check_if_number_has_equal_digit_count_and_digit_value/readme.md b/src/main/kotlin/g2201_2300/s2283_check_if_number_has_equal_digit_count_and_digit_value/readme.md
new file mode 100644
index 00000000..6506caa2
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2283_check_if_number_has_equal_digit_count_and_digit_value/readme.md
@@ -0,0 +1,70 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2283\. Check if Number Has Equal Digit Count and Digit Value
+
+Easy
+
+You are given a **0-indexed** string `num` of length `n` consisting of digits.
+
+Return `true` _if for **every** index_ `i` _in the range_ `0 <= i < n`_, the digit_ `i` _occurs_ `num[i]` _times in_ `num`_, otherwise return_ `false`.
+
+**Example 1:**
+
+**Input:** num = "1210"
+
+**Output:** true
+
+**Explanation:**
+
+num[0] = '1'. The digit 0 occurs once in num.
+
+num[1] = '2'. The digit 1 occurs twice in num.
+
+num[2] = '1'. The digit 2 occurs once in num.
+
+num[3] = '0'. The digit 3 occurs zero times in num.
+
+The condition holds true for every index in "1210", so return true.
+
+**Example 2:**
+
+**Input:** num = "030"
+
+**Output:** false
+
+**Explanation:**
+
+num[0] = '0'. The digit 0 should occur zero times, but actually occurs twice in num.
+
+num[1] = '3'. The digit 1 should occur three times, but actually occurs zero times in num.
+
+num[2] = '0'. The digit 2 occurs zero times in num.
+
+The indices 0 and 1 both violate the condition, so return false.
+
+**Constraints:**
+
+*   `n == num.length`
+*   `1 <= n <= 10`
+*   `num` consists of digits.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun digitCount(num: String): Boolean {
+        val cnt = IntArray(11)
+        val arr = num.toCharArray()
+        for (d in arr) {
+            ++cnt[d.code - '0'.code]
+        }
+        for (i in arr.indices) {
+            if (cnt[i] != arr[i].code - '0'.code) {
+                return false
+            }
+        }
+        return true
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2284_sender_with_largest_word_count/readme.md b/src/main/kotlin/g2201_2300/s2284_sender_with_largest_word_count/readme.md
new file mode 100644
index 00000000..aed6bcd6
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2284_sender_with_largest_word_count/readme.md
@@ -0,0 +1,83 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2284\. Sender With Largest Word Count
+
+Medium
+
+You have a chat log of `n` messages. You are given two string arrays `messages` and `senders` where `messages[i]` is a **message** sent by `senders[i]`.
+
+A **message** is list of **words** that are separated by a single space with no leading or trailing spaces. The **word count** of a sender is the total number of **words** sent by the sender. Note that a sender may send more than one message.
+
+Return _the sender with the **largest** word count_. If there is more than one sender with the largest word count, return _the one with the **lexicographically largest** name_.
+
+**Note:**
+
+*   Uppercase letters come before lowercase letters in lexicographical order.
+*   `"Alice"` and `"alice"` are distinct.
+
+**Example 1:**
+
+**Input:** messages = ["Hello userTwooo","Hi userThree","Wonderful day Alice","Nice day userThree"], senders = ["Alice","userTwo","userThree","Alice"]
+
+**Output:** "Alice"
+
+**Explanation:** Alice sends a total of 2 + 3 = 5 words.
+
+userTwo sends a total of 2 words.
+
+userThree sends a total of 3 words.
+
+Since Alice has the largest word count, we return "Alice".
+
+**Example 2:**
+
+**Input:** messages = ["How is leetcode for everyone","Leetcode is useful for practice"], senders = ["Bob","Charlie"]
+
+**Output:** "Charlie"
+
+**Explanation:** Bob sends a total of 5 words.
+
+Charlie sends a total of 5 words.
+
+Since there is a tie for the largest word count, we return the sender with the lexicographically larger name, Charlie.
+
+**Constraints:**
+
+*   `n == messages.length == senders.length`
+*   1 <= n <= 104
+*   `1 <= messages[i].length <= 100`
+*   `1 <= senders[i].length <= 10`
+*   `messages[i]` consists of uppercase and lowercase English letters and `' '`.
+*   All the words in `messages[i]` are separated by **a single space**.
+*   `messages[i]` does not have leading or trailing spaces.
+*   `senders[i]` consists of uppercase and lowercase English letters only.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun largestWordCount(messages: Array, senders: Array): String {
+        val x = HashMap()
+        for (i in messages.indices) {
+            val words = messages[i].length - messages[i].replace(" ", "").length + 1
+            if (x.containsKey(senders[i])) {
+                x[senders[i]] = x[senders[i]]!! + words
+            } else {
+                x[senders[i]] = words
+            }
+        }
+        var result = ""
+        var max = 0
+        for ((key, value) in x) {
+            if (value > max ||
+                value == max && result.compareTo(key) < 0
+            ) {
+                max = value
+                result = key
+            }
+        }
+        return result
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2285_maximum_total_importance_of_roads/readme.md b/src/main/kotlin/g2201_2300/s2285_maximum_total_importance_of_roads/readme.md
new file mode 100644
index 00000000..c77de18d
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2285_maximum_total_importance_of_roads/readme.md
@@ -0,0 +1,104 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2285\. Maximum Total Importance of Roads
+
+Medium
+
+You are given an integer `n` denoting the number of cities in a country. The cities are numbered from `0` to `n - 1`.
+
+You are also given a 2D integer array `roads` where roads[i] = [ai, bi] denotes that there exists a **bidirectional** road connecting cities ai and bi.
+
+You need to assign each city with an integer value from `1` to `n`, where each value can only be used **once**. The **importance** of a road is then defined as the **sum** of the values of the two cities it connects.
+
+Return _the **maximum total importance** of all roads possible after assigning the values optimally._
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/04/07/ex1drawio.png)
+
+**Input:** n = 5, roads = \[\[0,1],[1,2],[2,3],[0,2],[1,3],[2,4]]
+
+**Output:** 43
+
+**Explanation:** The figure above shows the country and the assigned values of [2,4,5,3,1].
+
+- The road (0,1) has an importance of 2 + 4 = 6.
+
+- The road (1,2) has an importance of 4 + 5 = 9.
+
+- The road (2,3) has an importance of 5 + 3 = 8.
+
+- The road (0,2) has an importance of 2 + 5 = 7.
+
+- The road (1,3) has an importance of 4 + 3 = 7.
+
+- The road (2,4) has an importance of 5 + 1 = 6.
+
+The total importance of all roads is 6 + 9 + 8 + 7 + 7 + 6 = 43.
+
+It can be shown that we cannot obtain a greater total importance than 43.
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2022/04/07/ex2drawio.png)
+
+**Input:** n = 5, roads = \[\[0,3],[2,4],[1,3]]
+
+**Output:** 20
+
+**Explanation:** The figure above shows the country and the assigned values of [4,3,2,5,1].
+
+- The road (0,3) has an importance of 4 + 5 = 9.
+
+- The road (2,4) has an importance of 2 + 1 = 3.
+
+- The road (1,3) has an importance of 3 + 5 = 8.
+
+The total importance of all roads is 9 + 3 + 8 = 20.
+
+It can be shown that we cannot obtain a greater total importance than 20.
+
+**Constraints:**
+
+*   2 <= n <= 5 * 104
+*   1 <= roads.length <= 5 * 104
+*   `roads[i].length == 2`
+*   0 <= ai, bi <= n - 1
+*   ai != bi
+*   There are no duplicate roads.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun maximumImportance(n: Int, roads: Array): Long {
+        val degree = IntArray(n)
+        var maxdegree = 0
+        for (r in roads) {
+            degree[r[0]]++
+            degree[r[1]]++
+            maxdegree = Math.max(maxdegree, Math.max(degree[r[0]], degree[r[1]]))
+        }
+        val rank: MutableMap = HashMap()
+        var i = n
+        while (i > 0) {
+            for (j in 0 until n) {
+                if (degree[j] == maxdegree) {
+                    rank[j] = i--
+                    degree[j] = Int.MIN_VALUE
+                }
+            }
+            maxdegree = 0
+            for (d in degree) {
+                maxdegree = Math.max(maxdegree, d)
+            }
+        }
+        var res: Long = 0
+        for (r in roads) {
+            res += (rank[r[0]]!! + rank[r[1]]!!).toLong()
+        }
+        return res
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2286_booking_concert_tickets_in_groups/readme.md b/src/main/kotlin/g2201_2300/s2286_booking_concert_tickets_in_groups/readme.md
new file mode 100644
index 00000000..9e08ef1a
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2286_booking_concert_tickets_in_groups/readme.md
@@ -0,0 +1,211 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2286\. Booking Concert Tickets in Groups
+
+Hard
+
+A concert hall has `n` rows numbered from `0` to `n - 1`, each with `m` seats, numbered from `0` to `m - 1`. You need to design a ticketing system that can allocate seats in the following cases:
+
+*   If a group of `k` spectators can sit **together** in a row.
+*   If **every** member of a group of `k` spectators can get a seat. They may or **may not** sit together.
+
+Note that the spectators are very picky. Hence:
+
+*   They will book seats only if each member of their group can get a seat with row number **less than or equal** to `maxRow`. `maxRow` can **vary** from group to group.
+*   In case there are multiple rows to choose from, the row with the **smallest** number is chosen. If there are multiple seats to choose in the same row, the seat with the **smallest** number is chosen.
+
+Implement the `BookMyShow` class:
+
+*   `BookMyShow(int n, int m)` Initializes the object with `n` as number of rows and `m` as number of seats per row.
+*   `int[] gather(int k, int maxRow)` Returns an array of length `2` denoting the row and seat number (respectively) of the **first seat** being allocated to the `k` members of the group, who must sit **together**. In other words, it returns the smallest possible `r` and `c` such that all `[c, c + k - 1]` seats are valid and empty in row `r`, and `r <= maxRow`. Returns `[]` in case it is **not possible** to allocate seats to the group.
+*   `boolean scatter(int k, int maxRow)` Returns `true` if all `k` members of the group can be allocated seats in rows `0` to `maxRow`, who may or **may not** sit together. If the seats can be allocated, it allocates `k` seats to the group with the **smallest** row numbers, and the smallest possible seat numbers in each row. Otherwise, returns `false`.
+
+**Example 1:**
+
+**Input**
+
+["BookMyShow", "gather", "gather", "scatter", "scatter"]
+
+[[2, 5], [4, 0], [2, 0], [5, 1], [5, 1]]
+
+**Output:** [null, [0, 0], [], true, false]
+
+**Explanation:**
+
+    BookMyShow bms = new BookMyShow(2, 5); // There are 2 rows with 5 seats each
+    bms.gather(4, 0); // return [0, 0]
+                      // The group books seats [0, 3] of row 0.
+    bms.gather(2, 0); // return []
+                      // There is only 1 seat left in row 0,
+                      // so it is not possible to book 2 consecutive seats.
+    bms.scatter(5, 1); // return True
+                       // The group books seat 4 of row 0 and seats [0, 3] of row 1.
+    bms.scatter(5, 1); // return False
+                       // There is only one seat left in the hall. 
+
+**Constraints:**
+
+*   1 <= n <= 5 * 104
+*   1 <= m, k <= 109
+*   `0 <= maxRow <= n - 1`
+*   At most 5 * 104 calls **in total** will be made to `gather` and `scatter`.
+
+## Solution
+
+```kotlin
+import java.util.ArrayDeque
+import java.util.Arrays
+import java.util.Deque
+
+@Suppress("NAME_SHADOWING")
+class BookMyShow(n: Int, private val m: Int) {
+    private val n: Int
+
+    // max number of seats in a row for some segment of the rows
+    private val max: IntArray
+
+    // total number of seats for some segment of the rows
+    private val total: LongArray
+
+    // number of rows with zero free places on the left and on the right
+    // using this to quickly skip already zero rows
+    // actual nodes are placed in [1,this.n], the first and last element only shows there the first
+    // non-zero row
+    private val numZerosRight: IntArray
+    private val numZerosLeft: IntArray
+
+    init {
+        // make n to be a power of 2 (for simplicity)
+        this.n = nextPow2(n)
+        // segment tree for max number of seats in a row
+        max = IntArray(this.n * 2 - 1)
+        // total number of seats for a segment of the rows
+        total = LongArray(this.n * 2 - 1)
+        numZerosRight = IntArray(this.n + 2)
+        numZerosLeft = IntArray(this.n + 2)
+        // initialize max and total, for max we firstly set values to m
+        // segments of size 1 are placed starting from this.n - 1
+        Arrays.fill(max, this.n - 1, this.n + n - 1, m)
+        Arrays.fill(total, this.n - 1, this.n + n - 1, m.toLong())
+        // calculate values of max and total for segments based on values of their children
+        var i = this.n - 2
+        var i1 = i * 2 + 1
+        var i2 = i * 2 + 2
+        while (i >= 0) {
+            max[i] = Math.max(max[i1], max[i2])
+            total[i] = total[i1] + total[i2]
+            i--
+            i1 -= 2
+            i2 -= 2
+        }
+    }
+
+    fun gather(k: Int, maxRow: Int): IntArray {
+        // find most left row with enough free places
+        val mostLeft = mostLeft(0, 0, n, k, maxRow + 1)
+        if (mostLeft == -1) {
+            return IntArray(0)
+        }
+        // get corresponding segment tree node
+        var v = n - 1 + mostLeft
+        val ans = intArrayOf(mostLeft, m - max[v])
+        // update max and total for this node
+        max[v] -= k
+        total[v] -= k.toLong()
+        // until this is a root of segment tree we update its parent
+        while (v != 0) {
+            v = (v - 1) / 2
+            max[v] = Math.max(max[v * 2 + 1], max[v * 2 + 2])
+            total[v] = total[v * 2 + 1] + total[v * 2 + 2]
+        }
+        return ans
+    }
+
+    private fun mostLeft(v: Int, l: Int, r: Int, k: Int, qr: Int): Int {
+        if (l >= qr || max[v] < k) {
+            return -1
+        }
+        if (l == r - 1) {
+            return l
+        }
+        val mid = (l + r) / 2
+        val left = mostLeft(v * 2 + 1, l, mid, k, qr)
+        return if (left != -1) {
+            left
+        } else mostLeft(v * 2 + 2, mid, r, k, qr)
+    }
+
+    fun scatter(k: Int, maxRow: Int): Boolean {
+        // find total number of free places in the rows [0; maxRow+1)
+        var k = k
+        val sum = total(0, 0, n, maxRow + 1)
+        if (sum < k) {
+            return false
+        }
+        var i = 0
+        // to don't update parent for both of its children we use a queue
+        val deque: Deque = ArrayDeque()
+        while (k != 0) {
+            i += numZerosRight[i] + 1
+            var v = n - 1 + i - 1
+            val spent = Math.min(k, max[v])
+            k -= spent
+            max[v] -= spent
+            total[v] -= spent.toLong()
+            if (max[v] == 0) {
+                // update numZerosRight and numZerosLeft
+                numZerosRight[i - numZerosLeft[i] - 1] += numZerosRight[i] + 1
+                numZerosLeft[i + numZerosRight[i] + 1] += numZerosLeft[i] + 1
+            }
+            if (v != 0) {
+                v = (v - 1) / 2
+                // if we already have the parent node in the queue we don't need to update it
+                if (deque.isEmpty() || deque.peekLast() != v) {
+                    deque.addLast(v)
+                }
+            }
+        }
+        // update max and total
+        while (deque.isNotEmpty()) {
+            var v = deque.pollFirst()
+            max[v] = Math.max(max[v * 2 + 1], max[v * 2 + 2])
+            total[v] = total[v * 2 + 1] + total[v * 2 + 2]
+            if (v != 0) {
+                v = (v - 1) / 2
+                // if we already have the parent node in the queue we don't need to update it
+                if (deque.isEmpty() || deque.peekLast() != v) {
+                    deque.addLast(v)
+                }
+            }
+        }
+        return true
+    }
+
+    // find sum of [ql, qr)
+    private fun total(v: Int, l: Int, r: Int, qr: Int): Long {
+        if (l >= qr) {
+            return 0
+        }
+        if (r <= qr) {
+            return total[v]
+        }
+        val mid = (l + r) / 2
+        return total(v * 2 + 1, l, mid, qr) + total(v * 2 + 2, mid, r, qr)
+    }
+
+    companion object {
+        private fun nextPow2(n: Int): Int {
+            return if (n and n - 1 == 0) {
+                n
+            } else Integer.highestOneBit(n) shl 1
+        }
+    }
+}
+/*
+ * Your BookMyShow object will be instantiated and called as such:
+ * var obj = BookMyShow(n, m)
+ * var param_1 = obj.gather(k,maxRow)
+ * var param_2 = obj.scatter(k,maxRow)
+ */
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2287_rearrange_characters_to_make_target_string/readme.md b/src/main/kotlin/g2201_2300/s2287_rearrange_characters_to_make_target_string/readme.md
new file mode 100644
index 00000000..bffaef79
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2287_rearrange_characters_to_make_target_string/readme.md
@@ -0,0 +1,85 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2287\. Rearrange Characters to Make Target String
+
+Easy
+
+You are given two **0-indexed** strings `s` and `target`. You can take some letters from `s` and rearrange them to form new strings.
+
+Return _the **maximum** number of copies of_ `target` _that can be formed by taking letters from_ `s` _and rearranging them._
+
+**Example 1:**
+
+**Input:** s = "ilovecodingonleetcode", target = "code"
+
+**Output:** 2
+
+**Explanation:**
+
+For the first copy of "code", take the letters at indices 4, 5, 6, and 7.
+
+For the second copy of "code", take the letters at indices 17, 18, 19, and 20.
+
+The strings that are formed are "ecod" and "code" which can both be rearranged into "code".
+
+We can make at most two copies of "code", so we return 2. 
+
+**Example 2:**
+
+**Input:** s = "abcba", target = "abc"
+
+**Output:** 1
+
+**Explanation:**
+
+We can make one copy of "abc" by taking the letters at indices 0, 1, and 2.
+
+We can make at most one copy of "abc", so we return 1.
+
+Note that while there is an extra 'a' and 'b' at indices 3 and 4, we cannot reuse the letter 'c' at index 2, so we cannot make a second copy of "abc". 
+
+**Example 3:**
+
+**Input:** s = "abbaccaddaeea", target = "aaaaa"
+
+**Output:** 1
+
+**Explanation:**
+
+We can make one copy of "aaaaa" by taking the letters at indices 0, 3, 6, 9, and 12.
+
+We can make at most one copy of "aaaaa", so we return 1. 
+
+**Constraints:**
+
+*   `1 <= s.length <= 100`
+*   `1 <= target.length <= 10`
+*   `s` and `target` consist of lowercase English letters.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun rearrangeCharacters(s: String, target: String): Int {
+        return getMaxCopies(target, getCharCount(s), getCharCount(target))
+    }
+
+    private fun getCharCount(str: String): IntArray {
+        val charToCount = IntArray(26)
+        for (i in 0 until str.length) {
+            charToCount[str[i].code - 'a'.code]++
+        }
+        return charToCount
+    }
+
+    private fun getMaxCopies(target: String, sCount: IntArray, tCount: IntArray): Int {
+        var copies = Int.MAX_VALUE
+        for (i in 0 until target.length) {
+            val ch = target[i].code - 'a'.code
+            copies = Math.min(copies, sCount[ch] / tCount[ch])
+        }
+        return copies
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2288_apply_discount_to_prices/readme.md b/src/main/kotlin/g2201_2300/s2288_apply_discount_to_prices/readme.md
new file mode 100644
index 00000000..740856de
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2288_apply_discount_to_prices/readme.md
@@ -0,0 +1,98 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2288\. Apply Discount to Prices
+
+Medium
+
+A **sentence** is a string of single-space separated words where each word can contain digits, lowercase letters, and the dollar sign `'$'`. A word represents a **price** if it is a sequence of digits preceded by a dollar sign.
+
+*   For example, `"$100"`, `"$23"`, and `"$6"` represent prices while `"100"`, `"$"`, and `"$1e5"` do not.
+
+You are given a string `sentence` representing a sentence and an integer `discount`. For each word representing a price, apply a discount of `discount%` on the price and **update** the word in the sentence. All updated prices should be represented with **exactly two** decimal places.
+
+Return _a string representing the modified sentence_.
+
+Note that all prices will contain **at most** `10` digits.
+
+**Example 1:**
+
+**Input:** sentence = "there are $1 $2 and 5$ candies in the shop", discount = 50
+
+**Output:** "there are $0.50 $1.00 and 5$ candies in the shop"
+
+**Explanation:**
+
+The words which represent prices are "$1" and "$2".
+
+- A 50% discount on "$1" yields "$0.50", so "$1" is replaced by "$0.50".
+
+- A 50% discount on "$2" yields "$1". Since we need to have exactly 2 decimal places after a price, we replace "$2" with "$1.00". 
+
+**Example 2:**
+
+**Input:** sentence = "1 2 $3 4 $5 $6 7 8$ $9 $10$", discount = 100
+
+**Output:** "1 2 $0.00 4 $0.00 $0.00 7 8$ $0.00 $10$"
+
+**Explanation:**
+
+Applying a 100% discount on any price will result in 0.
+
+The words representing prices are "$3", "$5", "$6", and "$9".
+
+Each of them is replaced by "$0.00". 
+
+**Constraints:**
+
+*   1 <= sentence.length <= 105
+*   `sentence` consists of lowercase English letters, digits, `' '`, and `'$'`.
+*   `sentence` does not have leading or trailing spaces.
+*   All words in `sentence` are separated by a single space.
+*   All prices will be **positive** numbers without leading zeros.
+*   All prices will have **at most** `10` digits.
+*   `0 <= discount <= 100`
+
+## Solution
+
+```kotlin
+class Solution {
+    fun discountPrices(sentence: String, discount: Int): String {
+        val words = sentence.split(" ").dropLastWhile { it.isEmpty() }.toTypedArray()
+        val sb = StringBuilder()
+        for (word in words) {
+            sb.append(applyDiscount(word, discount))
+            sb.append(" ")
+        }
+        sb.deleteCharAt(sb.length - 1)
+        return sb.toString()
+    }
+
+    private fun applyDiscount(s: String, discount: Int): String {
+        if (s[0] == '$' && s.length > 1) {
+            var price: Long = 0
+            for (i in 1 until s.length) {
+                if (!Character.isDigit(s[i])) {
+                    // Error case. We could also use Long.parseLong() here.
+                    return s
+                }
+                price *= 10
+                price += ((s[i].code - '0'.code) * (100 - discount)).toLong()
+            }
+            val stringPrice = price.toString()
+            if (price < 10) {
+                return "$0.0$stringPrice"
+            }
+            return if (price < 100) {
+                "$0.$stringPrice"
+            } else (
+                "$" +
+                    stringPrice.substring(0, stringPrice.length - 2) +
+                    "." +
+                    stringPrice.substring(stringPrice.length - 2)
+                )
+        }
+        return s
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2289_steps_to_make_array_non_decreasing/readme.md b/src/main/kotlin/g2201_2300/s2289_steps_to_make_array_non_decreasing/readme.md
new file mode 100644
index 00000000..cafc24ce
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2289_steps_to_make_array_non_decreasing/readme.md
@@ -0,0 +1,64 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2289\. Steps to Make Array Non-decreasing
+
+Medium
+
+You are given a **0-indexed** integer array `nums`. In one step, **remove** all elements `nums[i]` where `nums[i - 1] > nums[i]` for all `0 < i < nums.length`.
+
+Return _the number of steps performed until_ `nums` _becomes a **non-decreasing** array_.
+
+**Example 1:**
+
+**Input:** nums = [5,3,4,4,7,3,6,11,8,5,11]
+
+**Output:** 3
+
+**Explanation:** The following are the steps performed:
+
+- Step 1: [5,**3**,4,4,7,**3**,6,11,**8**,**5**,11] becomes [5,4,4,7,6,11,11]
+
+- Step 2: [5,**4**,4,7,**6**,11,11] becomes [5,4,7,11,11]
+
+- Step 3: [5,**4**,7,11,11] becomes [5,7,11,11]
+
+[5,7,11,11] is a non-decreasing array. Therefore, we return 3. 
+
+**Example 2:**
+
+**Input:** nums = [4,5,7,7,13]
+
+**Output:** 0
+
+**Explanation:** nums is already a non-decreasing array. Therefore, we return 0. 
+
+**Constraints:**
+
+*   1 <= nums.length <= 105
+*   1 <= nums[i] <= 109
+
+## Solution
+
+```kotlin
+class Solution {
+    fun totalSteps(nums: IntArray): Int {
+        var max = 0
+        val pos = IntArray(nums.size + 1)
+        val steps = IntArray(nums.size + 1)
+        var top = -1
+        for (i in 0..nums.size) {
+            val `val` = if (i == nums.size) Int.MAX_VALUE else nums[i]
+            while (top >= 0 && nums[pos[top]] <= `val`) {
+                if (top == 0) {
+                    max = Math.max(max, steps[pos[top--]])
+                } else {
+                    steps[pos[--top]] = Math.max(steps[pos[top]] + 1, steps[pos[top + 1]])
+                }
+            }
+            pos[++top] = i
+        }
+        return max
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2290_minimum_obstacle_removal_to_reach_corner/readme.md b/src/main/kotlin/g2201_2300/s2290_minimum_obstacle_removal_to_reach_corner/readme.md
new file mode 100644
index 00000000..b16dd0df
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2290_minimum_obstacle_removal_to_reach_corner/readme.md
@@ -0,0 +1,89 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2290\. Minimum Obstacle Removal to Reach Corner
+
+Hard
+
+You are given a **0-indexed** 2D integer array `grid` of size `m x n`. Each cell has one of two values:
+
+*   `0` represents an **empty** cell,
+*   `1` represents an **obstacle** that may be removed.
+
+You can move up, down, left, or right from and to an empty cell.
+
+Return _the **minimum** number of **obstacles** to **remove** so you can move from the upper left corner_ `(0, 0)` _to the lower right corner_ `(m - 1, n - 1)`.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/04/06/example1drawio-1.png)
+
+**Input:** grid = \[\[0,1,1],[1,1,0],[1,1,0]]
+
+**Output:** 2
+
+**Explanation:** We can remove the obstacles at (0, 1) and (0, 2) to create a path from (0, 0) to (2, 2).
+
+It can be shown that we need to remove at least 2 obstacles, so we return 2.
+
+Note that there may be other ways to remove 2 obstacles to create a path. 
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2022/04/06/example1drawio.png)
+
+**Input:** grid = \[\[0,1,0,0,0],[0,1,0,1,0],[0,0,0,1,0]]
+
+**Output:** 0
+
+**Explanation:** We can move from (0, 0) to (2, 4) without removing any obstacles, so we return 0. 
+
+**Constraints:**
+
+*   `m == grid.length`
+*   `n == grid[i].length`
+*   1 <= m, n <= 105
+*   2 <= m * n <= 105
+*   `grid[i][j]` is either `0` **or** `1`.
+*   `grid[0][0] == grid[m - 1][n - 1] == 0`
+
+## Solution
+
+```kotlin
+import java.util.PriorityQueue
+import java.util.Queue
+
+class Solution {
+    fun minimumObstacles(grid: Array): Int {
+        val n = grid.size
+        val m = grid[0].size
+        val dirs = arrayOf(intArrayOf(0, 1), intArrayOf(1, 0), intArrayOf(0, -1), intArrayOf(-1, 0))
+        val q: Queue = PriorityQueue { a: State, b: State -> a.removed - b.removed }
+        q.add(State(0, 0, 0))
+        val visited = Array(n) { BooleanArray(m) }
+        visited[0][0] = true
+        while (q.isNotEmpty()) {
+            val state = q.poll()
+            if (state.r == n - 1 && state.c == m - 1) {
+                return state.removed
+            }
+            for (d in dirs) {
+                val nr = state.r + d[0]
+                val nc = state.c + d[1]
+                if (nr < 0 || nc < 0 || nr == n || nc == m || visited[nr][nc]) {
+                    continue
+                }
+                visited[nr][nc] = true
+                val next = State(nr, nc, state.removed)
+                if (grid[nr][nc] == 1) {
+                    next.removed++
+                }
+                q.add(next)
+            }
+        }
+        return -1
+    }
+
+    private class State(var r: Int, var c: Int, var removed: Int)
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2293_min_max_game/readme.md b/src/main/kotlin/g2201_2300/s2293_min_max_game/readme.md
new file mode 100644
index 00000000..3e98a9a8
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2293_min_max_game/readme.md
@@ -0,0 +1,72 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2293\. Min Max Game
+
+Easy
+
+You are given a **0-indexed** integer array `nums` whose length is a power of `2`.
+
+Apply the following algorithm on `nums`:
+
+1.  Let `n` be the length of `nums`. If `n == 1`, **end** the process. Otherwise, **create** a new **0-indexed** integer array `newNums` of length `n / 2`.
+2.  For every **even** index `i` where `0 <= i < n / 2`, **assign** the value of `newNums[i]` as `min(nums[2 * i], nums[2 * i + 1])`.
+3.  For every **odd** index `i` where `0 <= i < n / 2`, **assign** the value of `newNums[i]` as `max(nums[2 * i], nums[2 * i + 1])`.
+4.  **Replace** the array `nums` with `newNums`.
+5.  **Repeat** the entire process starting from step 1.
+
+Return _the last number that remains in_ `nums` _after applying the algorithm._
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/04/13/example1drawio-1.png)
+
+**Input:** nums = [1,3,5,2,4,8,2,2]
+
+**Output:** 1
+
+**Explanation:** The following arrays are the results of applying the algorithm repeatedly.
+
+First: nums = [1,5,4,2]
+
+Second: nums = [1,4]
+
+Third: nums = [1]
+
+1 is the last remaining number, so we return 1. 
+
+**Example 2:**
+
+**Input:** nums = [3]
+
+**Output:** 3
+
+**Explanation:** 3 is already the last remaining number, so we return 3. 
+
+**Constraints:**
+
+*   `1 <= nums.length <= 1024`
+*   1 <= nums[i] <= 109
+*   `nums.length` is a power of `2`.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun minMaxGame(nums: IntArray): Int {
+        val n = nums.size
+        if (n == 1) {
+            return nums[0]
+        }
+        val newNums = IntArray(n / 2)
+        for (i in 0 until n / 2) {
+            if (i % 2 == 0) {
+                newNums[i] = Math.min(nums[2 * i], nums[2 * i + 1])
+            } else {
+                newNums[i] = Math.max(nums[2 * i], nums[2 * i + 1])
+            }
+        }
+        return minMaxGame(newNums)
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2294_partition_array_such_that_maximum_difference_is_k/readme.md b/src/main/kotlin/g2201_2300/s2294_partition_array_such_that_maximum_difference_is_k/readme.md
new file mode 100644
index 00000000..e9a3f4a9
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2294_partition_array_such_that_maximum_difference_is_k/readme.md
@@ -0,0 +1,87 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2294\. Partition Array Such That Maximum Difference Is K
+
+Medium
+
+You are given an integer array `nums` and an integer `k`. You may partition `nums` into one or more **subsequences** such that each element in `nums` appears in **exactly** one of the subsequences.
+
+Return _the **minimum** number of subsequences needed such that the difference between the maximum and minimum values in each subsequence is **at most**_ `k`_._
+
+A **subsequence** is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.
+
+**Example 1:**
+
+**Input:** nums = [3,6,1,2,5], k = 2
+
+**Output:** 2
+
+**Explanation:**
+
+We can partition nums into the two subsequences [3,1,2] and [6,5].
+
+The difference between the maximum and minimum value in the first subsequence is 3 - 1 = 2.
+
+The difference between the maximum and minimum value in the second subsequence is 6 - 5 = 1.
+
+Since two subsequences were created, we return 2. It can be shown that 2 is the minimum number of subsequences needed. 
+
+**Example 2:**
+
+**Input:** nums = [1,2,3], k = 1
+
+**Output:** 2
+
+**Explanation:**
+
+We can partition nums into the two subsequences [1,2] and [3].
+
+The difference between the maximum and minimum value in the first subsequence is 2 - 1 = 1.
+
+The difference between the maximum and minimum value in the second subsequence is 3 - 3 = 0.
+
+Since two subsequences were created, we return 2. Note that another optimal solution is to partition nums into the two subsequences [1] and [2,3]. 
+
+**Example 3:**
+
+**Input:** nums = [2,2,4,5], k = 0
+
+**Output:** 3
+
+**Explanation:**
+
+We can partition nums into the three subsequences [2,2], [4], and [5].
+
+The difference between the maximum and minimum value in the first subsequences is 2 - 2 = 0.
+
+The difference between the maximum and minimum value in the second subsequences is 4 - 4 = 0.
+
+The difference between the maximum and minimum value in the third subsequences is 5 - 5 = 0.
+
+Since three subsequences were created, we return 3. It can be shown that 3 is the minimum number of subsequences needed. 
+
+**Constraints:**
+
+*   1 <= nums.length <= 105
+*   0 <= nums[i] <= 105
+*   0 <= k <= 105
+
+## Solution
+
+```kotlin
+class Solution {
+    fun partitionArray(nums: IntArray, k: Int): Int {
+        nums.sort()
+        var partitions = 1
+        var j = 0
+        for (i in 1 until nums.size) {
+            if (nums[i] - nums[j] > k) {
+                partitions++
+                j = i
+            }
+        }
+        return partitions
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2295_replace_elements_in_an_array/readme.md b/src/main/kotlin/g2201_2300/s2295_replace_elements_in_an_array/readme.md
new file mode 100644
index 00000000..bfddc57f
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2295_replace_elements_in_an_array/readme.md
@@ -0,0 +1,81 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2295\. Replace Elements in an Array
+
+Medium
+
+You are given a **0-indexed** array `nums` that consists of `n` **distinct** positive integers. Apply `m` operations to this array, where in the ith operation you replace the number `operations[i][0]` with `operations[i][1]`.
+
+It is guaranteed that in the ith operation:
+
+*   `operations[i][0]` **exists** in `nums`.
+*   `operations[i][1]` does **not** exist in `nums`.
+
+Return _the array obtained after applying all the operations_.
+
+**Example 1:**
+
+**Input:** nums = [1,2,4,6], operations = \[\[1,3],[4,7],[6,1]]
+
+**Output:** [3,2,7,1]
+
+**Explanation:**
+
+We perform the following operations on nums: 
+
+- Replace the number 1 with 3. nums becomes [**3**,2,4,6]. 
+
+- Replace the number 4 with 7. nums becomes [3,2,**7**,6]. 
+
+- Replace the number 6 with 1. nums becomes [3,2,7,**1**]. 
+
+We return the final array [3,2,7,1]. 
+
+**Example 2:**
+
+**Input:** nums = [1,2], operations = \[\[1,3],[2,1],[3,2]]
+
+**Output:** [2,1]
+
+**Explanation:**
+
+We perform the following operations to nums: 
+
+- Replace the number 1 with 3. nums becomes [**3**,2]. 
+ 
+- Replace the number 2 with 1. nums becomes [3,**1**]. 
+
+- Replace the number 3 with 2. nums becomes [**2**,1]. 
+
+We return the array [2,1]. 
+
+**Constraints:**
+
+*   `n == nums.length`
+*   `m == operations.length`
+*   1 <= n, m <= 105
+*   All the values of `nums` are **distinct**.
+*   `operations[i].length == 2`
+*   1 <= nums[i], operations[i][0], operations[i][1] <= 106
+*   `operations[i][0]` will exist in `nums` when applying the ith operation.
+*   `operations[i][1]` will not exist in `nums` when applying the ith operation.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun arrayChange(nums: IntArray, operations: Array): IntArray {
+        val map = HashMap()
+        for (i in nums.indices) {
+            map[nums[i]] = i
+        }
+        for (operation in operations) {
+            val index = map[operation[0]]!!
+            nums[index] = operation[1]
+            map[operation[1]] = index
+        }
+        return nums
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2296_design_a_text_editor/readme.md b/src/main/kotlin/g2201_2300/s2296_design_a_text_editor/readme.md
new file mode 100644
index 00000000..d7a22cd7
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2296_design_a_text_editor/readme.md
@@ -0,0 +1,106 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2296\. Design a Text Editor
+
+Hard
+
+Design a text editor with a cursor that can do the following:
+
+*   **Add** text to where the cursor is.
+*   **Delete** text from where the cursor is (simulating the backspace key).
+*   **Move** the cursor either left or right.
+
+When deleting text, only characters to the left of the cursor will be deleted. The cursor will also remain within the actual text and cannot be moved beyond it. More formally, we have that `0 <= cursor.position <= currentText.length` always holds.
+
+Implement the `TextEditor` class:
+
+*   `TextEditor()` Initializes the object with empty text.
+*   `void addText(string text)` Appends `text` to where the cursor is. The cursor ends to the right of `text`.
+*   `int deleteText(int k)` Deletes `k` characters to the left of the cursor. Returns the number of characters actually deleted.
+*   `string cursorLeft(int k)` Moves the cursor to the left `k` times. Returns the last `min(10, len)` characters to the left of the cursor, where `len` is the number of characters to the left of the cursor.
+*   `string cursorRight(int k)` Moves the cursor to the right `k` times. Returns the last `min(10, len)` characters to the left of the cursor, where `len` is the number of characters to the left of the cursor.
+
+**Example 1:**
+
+**Input** ["TextEditor", "addText", "deleteText", "addText", "cursorRight", "cursorLeft", "deleteText", "cursorLeft", "cursorRight"] [[], ["leetcode"], [4], ["practice"], [3], [8], [10], [2], [6]]
+
+**Output:** [null, null, 4, null, "etpractice", "leet", 4, "", "practi"]
+
+**Explanation:**
+
+    TextEditor textEditor = new TextEditor(); // The current text is "|". (The '|' character represents the cursor)
+    textEditor.addText("leetcode"); // The current text is "leetcode|".
+    textEditor.deleteText(4); // return 4
+                              // The current text is "leet|".
+                              // 4 characters were deleted.
+    textEditor.addText("practice"); // The current text is "leetpractice|".
+    textEditor.cursorRight(3); // return "etpractice"
+                               // The current text is "leetpractice|".
+                               // The cursor cannot be moved beyond the actual text and thus did not move.
+                               // "etpractice" is the last 10 characters to the left of the cursor.
+     textEditor.cursorLeft(8); // return "leet"
+                               // The current text is "leet|practice".
+                               // "leet" is the last min(10, 4) = 4 characters to the left of the cursor.
+     textEditor.deleteText(10); // return 4
+                                // The current text is "|practice".
+                                // Only 4 characters were deleted.
+     textEditor.cursorLeft(2); // return ""
+                               // The current text is "|practice".
+                               // The cursor cannot be moved beyond the actual text and thus did not move.
+                               // "" is the last min(10, 0) = 0 characters to the left of the cursor.
+     textEditor.cursorRight(6); // return "practi"
+                                // The current text is "practi|ce".
+                                // "practi" is the last min(10, 6) = 6 characters to the left of the cursor. 
+
+**Constraints:**
+
+*   `1 <= text.length, k <= 40`
+*   `text` consists of lowercase English letters.
+*   At most 2 * 104 calls **in total** will be made to `addText`, `deleteText`, `cursorLeft` and `cursorRight`.
+
+**Follow-up:** Could you find a solution with time complexity of `O(k)` per call?
+
+## Solution
+
+```kotlin
+class TextEditor {
+    private val sb: StringBuilder = StringBuilder()
+    private var cursor = 0
+
+    fun addText(text: String) {
+        sb.insert(cursor, text)
+        cursor += text.length
+    }
+
+    fun deleteText(k: Int): Int {
+        val prevPos = cursor
+        if (cursor - k >= 0) {
+            cursor -= k
+            sb.delete(cursor, cursor + k)
+        } else {
+            sb.delete(0, cursor)
+            cursor = 0
+        }
+        return prevPos - cursor
+    }
+
+    fun cursorLeft(k: Int): String {
+        cursor = Math.max(cursor - k, 0)
+        return sb.substring(Math.max(cursor - 10, 0), cursor)
+    }
+
+    fun cursorRight(k: Int): String {
+        cursor = Math.min(cursor + k, sb.length)
+        return sb.substring(Math.max(cursor - 10, 0), cursor)
+    }
+}
+/*
+ * Your TextEditor object will be instantiated and called as such:
+ * var obj = TextEditor()
+ * obj.addText(text)
+ * var param_2 = obj.deleteText(k)
+ * var param_3 = obj.cursorLeft(k)
+ * var param_4 = obj.cursorRight(k)
+ */
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2299_strong_password_checker_ii/readme.md b/src/main/kotlin/g2201_2300/s2299_strong_password_checker_ii/readme.md
new file mode 100644
index 00000000..3e262f56
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2299_strong_password_checker_ii/readme.md
@@ -0,0 +1,81 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2299\. Strong Password Checker II
+
+Easy
+
+A password is said to be **strong** if it satisfies all the following criteria:
+
+*   It has at least `8` characters.
+*   It contains at least **one lowercase** letter.
+*   It contains at least **one uppercase** letter.
+*   It contains at least **one digit**.
+*   It contains at least **one special character**. The special characters are the characters in the following string: `"!@#$%^&*()-+"`.
+*   It does **not** contain `2` of the same character in adjacent positions (i.e., `"aab"` violates this condition, but `"aba"` does not).
+
+Given a string `password`, return `true` _if it is a **strong** password_. Otherwise, return `false`.
+
+**Example 1:**
+
+**Input:** password = "IloveLe3tcode!"
+
+**Output:** true
+
+**Explanation:** The password meets all the requirements. Therefore, we return true. 
+
+**Example 2:**
+
+**Input:** password = "Me+You--IsMyDream"
+
+**Output:** false
+
+**Explanation:** The password does not contain a digit and also contains 2 of the same character in adjacent positions. Therefore, we return false. 
+
+**Example 3:**
+
+**Input:** password = "1aB!"
+
+**Output:** false
+
+**Explanation:** The password does not meet the length requirement. Therefore, we return false.
+
+**Constraints:**
+
+*   `1 <= password.length <= 100`
+*   `password` consists of letters, digits, and special characters: `"!@#$%^&*()-+"`.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun strongPasswordCheckerII(password: String): Boolean {
+        if (password.length < 8) {
+            return false
+        }
+        var l = false
+        var u = false
+        var d = false
+        var s = false
+        val special = "!@#$%^&*()-+"
+        var previous = '.'
+        for (i in 0 until password.length) {
+            val ch = password[i]
+            if (ch == previous) {
+                return false
+            }
+            previous = ch
+            if (ch >= 'A' && ch <= 'Z') {
+                u = true
+            } else if (ch >= 'a' && ch <= 'z') {
+                l = true
+            } else if (ch >= '0' && ch <= '9') {
+                d = true
+            } else if (special.indexOf(ch) != -1) {
+                s = true
+            }
+        }
+        return l && u && d && s
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2201_2300/s2300_successful_pairs_of_spells_and_potions/readme.md b/src/main/kotlin/g2201_2300/s2300_successful_pairs_of_spells_and_potions/readme.md
new file mode 100644
index 00000000..3a45435c
--- /dev/null
+++ b/src/main/kotlin/g2201_2300/s2300_successful_pairs_of_spells_and_potions/readme.md
@@ -0,0 +1,76 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2300\. Successful Pairs of Spells and Potions
+
+Medium
+
+You are given two positive integer arrays `spells` and `potions`, of length `n` and `m` respectively, where `spells[i]` represents the strength of the ith spell and `potions[j]` represents the strength of the jth potion.
+
+You are also given an integer `success`. A spell and potion pair is considered **successful** if the **product** of their strengths is **at least** `success`.
+
+Return _an integer array_ `pairs` _of length_ `n` _where_ `pairs[i]` _is the number of **potions** that will form a successful pair with the_ ith _spell._
+
+**Example 1:**
+
+**Input:** spells = [5,1,3], potions = [1,2,3,4,5], success = 7
+
+**Output:** [4,0,3]
+
+**Explanation:**
+
+- 0th spell: 5 \* [1,2,3,4,5] = [5,**10**,**15**,**20**,**25**]. 4 pairs are successful.
+
+- 1st spell: 1 \* [1,2,3,4,5] = [1,2,3,4,5]. 0 pairs are successful.
+
+- 2nd spell: 3 \* [1,2,3,4,5] = [3,6,**9**,**12**,**15**]. 3 pairs are successful.
+
+Thus, [4,0,3] is returned. 
+
+**Example 2:**
+
+**Input:** spells = [3,1,2], potions = [8,5,8], success = 16
+
+**Output:** [2,0,2]
+
+**Explanation:**
+
+- 0th spell: 3 \* [8,5,8] = [**24**,15,**24**]. 2 pairs are successful.
+
+- 1st spell: 1 \* [8,5,8] = [8,5,8]. 0 pairs are successful.
+
+- 2nd spell: 2 \* [8,5,8] = [**16**,10,**16**]. 2 pairs are successful.
+
+Thus, [2,0,2] is returned. 
+
+**Constraints:**
+
+*   `n == spells.length`
+*   `m == potions.length`
+*   1 <= n, m <= 105
+*   1 <= spells[i], potions[i] <= 105
+*   1 <= success <= 1010
+
+## Solution
+
+```kotlin
+class Solution {
+    fun successfulPairs(spells: IntArray, potions: IntArray, success: Long): IntArray {
+        potions.sort()
+        for (i in spells.indices) {
+            var l = 0
+            var r = potions.size
+            while (l < r) {
+                val m = l + (r - l) / 2
+                if (spells[i].toLong() * potions[m] >= success) {
+                    r = m
+                } else {
+                    l = m + 1
+                }
+            }
+            spells[i] = potions.size - l
+        }
+        return spells
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2301_match_substring_after_replacement/readme.md b/src/main/kotlin/g2301_2400/s2301_match_substring_after_replacement/readme.md
new file mode 100644
index 00000000..30e1e20e
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2301_match_substring_after_replacement/readme.md
@@ -0,0 +1,96 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2301\. Match Substring After Replacement
+
+Hard
+
+You are given two strings `s` and `sub`. You are also given a 2D character array `mappings` where mappings[i] = [oldi, newi] indicates that you may **replace** any number of oldi characters of `sub` with newi. Each character in `sub` **cannot** be replaced more than once.
+
+Return `true` _if it is possible to make_ `sub` _a substring of_ `s` _by replacing zero or more characters according to_ `mappings`. Otherwise, return `false`.
+
+A **substring** is a contiguous non-empty sequence of characters within a string.
+
+**Example 1:**
+
+**Input:** s = "fool3e7bar", sub = "leet", mappings = \[\["e","3"],["t","7"],["t","8"]]
+
+**Output:** true
+
+**Explanation:** Replace the first 'e' in sub with '3' and 't' in sub with '7'.
+
+Now sub = "l3e7" is a substring of s, so we return true.
+
+**Example 2:**
+
+**Input:** s = "fooleetbar", sub = "f00l", mappings = \[\["o","0"]]
+
+**Output:** false
+
+**Explanation:** The string "f00l" is not a substring of s and no replacements can be made.
+
+Note that we cannot replace '0' with 'o'. 
+
+**Example 3:**
+
+**Input:** s = "Fool33tbaR", sub = "leetd", mappings = \[\["e","3"],["t","7"],["t","8"],["d","b"],["p","b"]]
+
+**Output:** true
+
+**Explanation:** Replace the first and second 'e' in sub with '3' and 'd' in sub with 'b'.
+
+Now sub = "l33tb" is a substring of s, so we return true. 
+
+**Constraints:**
+
+*   `1 <= sub.length <= s.length <= 5000`
+*   `0 <= mappings.length <= 1000`
+*   `mappings[i].length == 2`
+*   oldi != newi
+*   `s` and `sub` consist of uppercase and lowercase English letters and digits.
+*   oldi and newi are either uppercase or lowercase English letters or digits.
+
+## Solution
+
+```kotlin
+@Suppress("NAME_SHADOWING")
+class Solution {
+    private lateinit var c1: CharArray
+    private lateinit var c2: CharArray
+    private lateinit var al: Array?>
+    fun matchReplacement(s: String, sub: String, mappings: Array): Boolean {
+        c1 = s.toCharArray()
+        c2 = sub.toCharArray()
+        al = arrayOfNulls(75)
+        for (i in 0..74) {
+            val temp: MutableSet = HashSet()
+            al[i] = temp
+        }
+        for (mapping in mappings) {
+            al[mapping[0].code - '0'.code]!!.add(mapping[1])
+        }
+        return ans(c1.size, c2.size) == 1
+    }
+
+    private fun ans(m: Int, n: Int): Int {
+        var m = m
+        var n = n
+        if (m == 0) {
+            return 0
+        }
+        if (ans(m - 1, n) == 1) {
+            return 1
+        }
+        if (m >= n && (c1[m - 1] == c2[n - 1] || al[c2[n - 1].code - '0'.code]!!.contains(c1[m - 1]))) {
+            while (n >= 1 && (c1[m - 1] == c2[n - 1] || al[c2[n - 1].code - '0'.code]!!.contains(c1[m - 1]))) {
+                n--
+                m--
+            }
+            if (n == 0) {
+                return 1
+            }
+        }
+        return 0
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2302_count_subarrays_with_score_less_than_k/readme.md b/src/main/kotlin/g2301_2400/s2302_count_subarrays_with_score_less_than_k/readme.md
new file mode 100644
index 00000000..e1ef76b1
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2302_count_subarrays_with_score_less_than_k/readme.md
@@ -0,0 +1,79 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2302\. Count Subarrays With Score Less Than K
+
+Hard
+
+The **score** of an array is defined as the **product** of its sum and its length.
+
+*   For example, the score of `[1, 2, 3, 4, 5]` is `(1 + 2 + 3 + 4 + 5) * 5 = 75`.
+
+Given a positive integer array `nums` and an integer `k`, return _the **number of non-empty subarrays** of_ `nums` _whose score is **strictly less** than_ `k`.
+
+A **subarray** is a contiguous sequence of elements within an array.
+
+**Example 1:**
+
+**Input:** nums = [2,1,4,3,5], k = 10
+
+**Output:** 6
+
+**Explanation:**
+
+The 6 subarrays having scores less than 10 are:
+
+- \[2] with score 2 \* 1 = 2.
+
+- \[1] with score 1 \* 1 = 1.
+
+- \[4] with score 4 \* 1 = 4.
+
+- \[3] with score 3 \* 1 = 3.
+
+- \[5] with score 5 \* 1 = 5.
+
+- \[2,1] with score (2 + 1) \* 2 = 6.
+
+Note that subarrays such as [1,4] and [4,3,5] are not considered because their scores are 10 and 36 respectively, while we need scores strictly less than 10.
+
+**Example 2:**
+
+**Input:** nums = [1,1,1], k = 5
+
+**Output:** 5
+
+**Explanation:**
+
+Every subarray except [1,1,1] has a score less than 5.
+
+[1,1,1] has a score (1 + 1 + 1) \* 3 = 9, which is greater than 5.
+
+Thus, there are 5 subarrays having scores less than 5. 
+
+**Constraints:**
+
+*   1 <= nums.length <= 105
+*   1 <= nums[i] <= 105
+*   1 <= k <= 1015
+
+## Solution
+
+```kotlin
+class Solution {
+    fun countSubarrays(nums: IntArray, k: Long): Long {
+        var sum: Long = 0
+        var count: Long = 0
+        var i = 0
+        var j = 0
+        while (i < nums.size) {
+            sum += nums[i].toLong()
+            while (sum * (i - j + 1) >= k) {
+                sum -= nums[j++].toLong()
+            }
+            count += (i++ - j + 1).toLong()
+        }
+        return count
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2303_calculate_amount_paid_in_taxes/readme.md b/src/main/kotlin/g2301_2400/s2303_calculate_amount_paid_in_taxes/readme.md
new file mode 100644
index 00000000..15979471
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2303_calculate_amount_paid_in_taxes/readme.md
@@ -0,0 +1,85 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2303\. Calculate Amount Paid in Taxes
+
+Easy
+
+You are given a **0-indexed** 2D integer array `brackets` where brackets[i] = [upperi, percenti] means that the ith tax bracket has an upper bound of upperi and is taxed at a rate of percenti. The brackets are **sorted** by upper bound (i.e. upperi-1 < upperi for `0 < i < brackets.length`).
+
+Tax is calculated as follows:
+
+*   The first upper0 dollars earned are taxed at a rate of percent0.
+*   The next upper1 - upper0 dollars earned are taxed at a rate of percent1.
+*   The next upper2 - upper1 dollars earned are taxed at a rate of percent2.
+*   And so on.
+
+You are given an integer `income` representing the amount of money you earned. Return _the amount of money that you have to pay in taxes._ Answers within 10-5 of the actual answer will be accepted.
+
+**Example 1:**
+
+**Input:** brackets = \[\[3,50],[7,10],[12,25]], income = 10
+
+**Output:** 2.65000
+
+**Explanation:**
+
+The first 3 dollars you earn are taxed at 50%. You have to pay $3 \* 50% = $1.50 dollars in taxes.
+
+The next 7 - 3 = 4 dollars you earn are taxed at 10%. You have to pay $4 \* 10% = $0.40 dollars in taxes.
+
+The final 10 - 7 = 3 dollars you earn are taxed at 25%. You have to pay $3 \* 25% = $0.75 dollars in taxes. You have to pay a total of $1.50 + $0.40 + $0.75 = $2.65 dollars in taxes. 
+
+**Example 2:**
+
+**Input:** brackets = \[\[1,0],[4,25],[5,50]], income = 2
+
+**Output:** 0.25000
+
+**Explanation:**
+
+The first dollar you earn is taxed at 0%. You have to pay $1 \* 0% = $0 dollars in taxes.
+
+The second dollar you earn is taxed at 25%. You have to pay $1 \* 25% = $0.25 dollars in taxes.
+
+You have to pay a total of $0 + $0.25 = $0.25 dollars in taxes. 
+
+**Example 3:**
+
+**Input:** brackets = \[\[2,50]], income = 0
+
+**Output:** 0.00000
+
+**Explanation:** You have no income to tax, so you have to pay a total of $0 dollars in taxes. 
+
+**Constraints:**
+
+*   `1 <= brackets.length <= 100`
+*   1 <= upperi <= 1000
+*   0 <= percenti <= 100
+*   `0 <= income <= 1000`
+*   upperi is sorted in ascending order.
+*   All the values of upperi are **unique**.
+*   The upper bound of the last tax bracket is greater than or equal to `income`.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun calculateTax(brackets: Array, income: Int): Double {
+        // you can remove this line
+        if (income == 0) {
+            return 0.0
+        }
+        var sum = 0.0
+        var prev = 0.0
+        for (bracket in brackets) {
+            val salary = bracket[0].coerceAtMost(income).toDouble()
+            val tax = bracket[1].toDouble()
+            sum += (salary - prev) * tax
+            prev = salary
+        }
+        return sum / 100
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2304_minimum_path_cost_in_a_grid/readme.md b/src/main/kotlin/g2301_2400/s2304_minimum_path_cost_in_a_grid/readme.md
new file mode 100644
index 00000000..2514b998
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2304_minimum_path_cost_in_a_grid/readme.md
@@ -0,0 +1,81 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2304\. Minimum Path Cost in a Grid
+
+Medium
+
+You are given a **0-indexed** `m x n` integer matrix `grid` consisting of **distinct** integers from `0` to `m * n - 1`. You can move in this matrix from a cell to any other cell in the **next** row. That is, if you are in cell `(x, y)` such that `x < m - 1`, you can move to any of the cells `(x + 1, 0)`, `(x + 1, 1)`, ..., `(x + 1, n - 1)`. **Note** that it is not possible to move from cells in the last row.
+
+Each possible move has a cost given by a **0-indexed** 2D array `moveCost` of size `(m * n) x n`, where `moveCost[i][j]` is the cost of moving from a cell with value `i` to a cell in column `j` of the next row. The cost of moving from cells in the last row of `grid` can be ignored.
+
+The cost of a path in `grid` is the **sum** of all values of cells visited plus the **sum** of costs of all the moves made. Return _the **minimum** cost of a path that starts from any cell in the **first** row and ends at any cell in the **last** row._
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/04/28/griddrawio-2.png)
+
+**Input:** grid = \[\[5,3],[4,0],[2,1]], moveCost = \[\[9,8],[1,5],[10,12],[18,6],[2,4],[14,3]]
+
+**Output:** 17
+
+**Explanation:** The path with the minimum possible cost is the path 5 -> 0 -> 1.
+
+- The sum of the values of cells visited is 5 + 0 + 1 = 6.
+
+- The cost of moving from 5 to 0 is 3.
+
+- The cost of moving from 0 to 1 is 8.
+
+So the total cost of the path is 6 + 3 + 8 = 17.
+
+**Example 2:**
+
+**Input:** grid = \[\[5,1,2],[4,0,3]], moveCost = \[\[12,10,15],[20,23,8],[21,7,1],[8,1,13],[9,10,25],[5,3,2]]
+
+**Output:** 6
+
+**Explanation:** The path with the minimum possible cost is the path 2 -> 3.
+
+- The sum of the values of cells visited is 2 + 3 = 5.
+
+- The cost of moving from 2 to 3 is 1.
+
+So the total cost of this path is 5 + 1 = 6.
+
+**Constraints:**
+
+*   `m == grid.length`
+*   `n == grid[i].length`
+*   `2 <= m, n <= 50`
+*   `grid` consists of distinct integers from `0` to `m * n - 1`.
+*   `moveCost.length == m * n`
+*   `moveCost[i].length == n`
+*   `1 <= moveCost[i][j] <= 100`
+
+## Solution
+
+```kotlin
+class Solution {
+    fun minPathCost(grid: Array, moveCost: Array): Int {
+        val m = grid.size
+        val n = grid[0].size
+        val dp = Array(m) { IntArray(n) }
+        System.arraycopy(grid[m - 1], 0, dp[m - 1], 0, n)
+        for (i in m - 2 downTo 0) {
+            for (j in 0 until n) {
+                var min = Int.MAX_VALUE
+                for (k in 0 until n) {
+                    min = min.coerceAtMost(grid[i][j] + moveCost[grid[i][j]][k] + dp[i + 1][k])
+                }
+                dp[i][j] = min
+            }
+        }
+        var min = Int.MAX_VALUE
+        for (s in dp[0]) {
+            min = min.coerceAtMost(s)
+        }
+        return min
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2305_fair_distribution_of_cookies/readme.md b/src/main/kotlin/g2301_2400/s2305_fair_distribution_of_cookies/readme.md
new file mode 100644
index 00000000..12eac6c9
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2305_fair_distribution_of_cookies/readme.md
@@ -0,0 +1,84 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2305\. Fair Distribution of Cookies
+
+Medium
+
+You are given an integer array `cookies`, where `cookies[i]` denotes the number of cookies in the ith bag. You are also given an integer `k` that denotes the number of children to distribute **all** the bags of cookies to. All the cookies in the same bag must go to the same child and cannot be split up.
+
+The **unfairness** of a distribution is defined as the **maximum** **total** cookies obtained by a single child in the distribution.
+
+Return _the **minimum** unfairness of all distributions_.
+
+**Example 1:**
+
+**Input:** cookies = [8,15,10,20,8], k = 2
+
+**Output:** 31
+
+**Explanation:** One optimal distribution is [8,15,8] and [10,20]
+
+- The 1st child receives [8,15,8] which has a total of 8 + 15 + 8 = 31 cookies.
+
+- The 2nd child receives [10,20] which has a total of 10 + 20 = 30 cookies.
+
+The unfairness of the distribution is max(31,30) = 31.
+
+It can be shown that there is no distribution with an unfairness less than 31. 
+
+**Example 2:**
+
+**Input:** cookies = [6,1,3,2,2,4,1,2], k = 3
+
+**Output:** 7
+
+**Explanation:** One optimal distribution is [6,1], [3,2,2], and [4,1,2]
+
+- The 1st child receives [6,1] which has a total of 6 + 1 = 7 cookies.
+
+- The 2nd child receives [3,2,2] which has a total of 3 + 2 + 2 = 7 cookies.
+
+- The 3rd child receives [4,1,2] which has a total of 4 + 1 + 2 = 7 cookies.
+
+The unfairness of the distribution is max(7,7,7) = 7.
+
+It can be shown that there is no distribution with an unfairness less than 7. 
+
+**Constraints:**
+
+*   `2 <= cookies.length <= 8`
+*   1 <= cookies[i] <= 105
+*   `2 <= k <= cookies.length`
+
+## Solution
+
+```kotlin
+class Solution {
+    private var res = Int.MAX_VALUE
+    fun distributeCookies(c: IntArray, k: Int): Int {
+        val nums = IntArray(k)
+        dfs(c, nums, 0)
+        return res
+    }
+
+    private fun dfs(c: IntArray, nums: IntArray, cur: Int) {
+        if (cur == c.size) {
+            var r = 0
+            for (num in nums) {
+                r = r.coerceAtLeast(num)
+            }
+            res = res.coerceAtMost(r)
+            return
+        }
+        for (i in nums.indices) {
+            if (nums[i] + c[cur] > res) {
+                continue
+            }
+            nums[i] += c[cur]
+            dfs(c, nums, cur + 1)
+            nums[i] -= c[cur]
+        }
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2306_naming_a_company/readme.md b/src/main/kotlin/g2301_2400/s2306_naming_a_company/readme.md
new file mode 100644
index 00000000..f437152a
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2306_naming_a_company/readme.md
@@ -0,0 +1,107 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2306\. Naming a Company
+
+Hard
+
+You are given an array of strings `ideas` that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:
+
+1.  Choose 2 **distinct** names from `ideas`, call them ideaA and ideaB.
+2.  Swap the first letters of ideaA and ideaB with each other.
+3.  If **both** of the new names are not found in the original `ideas`, then the name ideaA ideaB (the **concatenation** of ideaA and ideaB, separated by a space) is a valid company name.
+4.  Otherwise, it is not a valid name.
+
+Return _the number of **distinct** valid names for the company_.
+
+**Example 1:**
+
+**Input:** ideas = ["coffee","donuts","time","toffee"]
+
+**Output:** 6
+
+**Explanation:** The following selections are valid:
+
+- ("coffee", "donuts"): The company name created is "doffee conuts".
+
+- ("donuts", "coffee"): The company name created is "conuts doffee".
+
+- ("donuts", "time"): The company name created is "tonuts dime".
+
+- ("donuts", "toffee"): The company name created is "tonuts doffee".
+
+- ("time", "donuts"): The company name created is "dime tonuts".
+
+- ("toffee", "donuts"): The company name created is "doffee tonuts".
+
+Therefore, there are a total of 6 distinct company names.
+
+
+The following are some examples of invalid selections:
+
+- ("coffee", "time"): The name "toffee" formed after swapping already exists in the original array.
+
+- ("time", "toffee"): Both names are still the same after swapping and exist in the original array.
+
+- ("coffee", "toffee"): Both names formed after swapping already exist in the original array. 
+
+**Example 2:**
+
+**Input:** ideas = ["lack","back"]
+
+**Output:** 0
+
+**Explanation:** There are no valid selections. Therefore, 0 is returned. 
+
+**Constraints:**
+
+*   2 <= ideas.length <= 5 * 104
+*   `1 <= ideas[i].length <= 10`
+*   `ideas[i]` consists of lowercase English letters.
+*   All the strings in `ideas` are **unique**.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun distinctNames(a: Array): Long {
+        val m = Array>(26) { mutableSetOf() }
+        for (s in a) {
+            val i = s[0].code - 97
+            m[i].add(s.substring(1))
+        }
+
+        var res = 0L
+        for (i in m.indices) {
+            val b1 = m[i]
+            if (b1.isEmpty()) {
+                continue
+            }
+            for (y in i + 1 until m.size) {
+                val b2 = m[y]
+                if (b2.isEmpty()) {
+                    continue
+                }
+                res += compare(b1, b2)
+            }
+        }
+
+        return res
+    }
+
+    fun compare(b1: MutableSet, b2: MutableSet): Long {
+        val set1 = if (b1.size > b2.size) b1 else b2
+        val set2 = if (b1.size > b2.size) b2 else b1
+        var n1 = set1.size
+        var n2 = set2.size
+        for (s in set1) {
+            if (set2.contains(s)) {
+                n1--
+                n2--
+            }
+        }
+
+        return (n1 * n2) * 2L
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2309_greatest_english_letter_in_upper_and_lower_case/readme.md b/src/main/kotlin/g2301_2400/s2309_greatest_english_letter_in_upper_and_lower_case/readme.md
new file mode 100644
index 00000000..0940f2be
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2309_greatest_english_letter_in_upper_and_lower_case/readme.md
@@ -0,0 +1,71 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2309\. Greatest English Letter in Upper and Lower Case
+
+Easy
+
+Given a string of English letters `s`, return _the **greatest** English letter which occurs as **both** a lowercase and uppercase letter in_ `s`. The returned letter should be in **uppercase**. If no such letter exists, return _an empty string_.
+
+An English letter `b` is **greater** than another letter `a` if `b` appears **after** `a` in the English alphabet.
+
+**Example 1:**
+
+**Input:** s = "l**Ee**TcOd**E**"
+
+**Output:** "E"
+
+**Explanation:**
+
+The letter 'E' is the only letter to appear in both lower and upper case.
+
+**Example 2:**
+
+**Input:** s = "a**rR**AzFif"
+
+**Output:** "R"
+
+**Explanation:**
+
+The letter 'R' is the greatest letter to appear in both lower and upper case.
+
+Note that 'A' and 'F' also appear in both lower and upper case, but 'R' is greater than 'F' or 'A'.
+
+**Example 3:**
+
+**Input:** s = "AbCdEfGhIjK"
+
+**Output:** ""
+
+**Explanation:** There is no letter that appears in both lower and upper case. 
+
+**Constraints:**
+
+*   `1 <= s.length <= 1000`
+*   `s` consists of lowercase and uppercase English letters.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun greatestLetter(s: String): String {
+        var gt = ' '
+        val sA = BooleanArray(26)
+        val uA = BooleanArray(26)
+        for (ch in s.toCharArray()) {
+            var i: Int
+            if (ch in 'A'..'Z') {
+                i = ch.code - 'A'.code
+                uA[i] = true
+            } else {
+                i = ch.code - 'a'.code
+                sA[i] = true
+            }
+            if (uA[i] == sA[i] && gt.code < 'A'.code + i) {
+                gt = ('A'.code + i).toChar()
+            }
+        }
+        return if (gt == ' ') "" else gt.toString() + ""
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2310_sum_of_numbers_with_units_digit_k/readme.md b/src/main/kotlin/g2301_2400/s2310_sum_of_numbers_with_units_digit_k/readme.md
new file mode 100644
index 00000000..2da1e96e
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2310_sum_of_numbers_with_units_digit_k/readme.md
@@ -0,0 +1,75 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2310\. Sum of Numbers With Units Digit K
+
+Medium
+
+Given two integers `num` and `k`, consider a set of positive integers with the following properties:
+
+*   The units digit of each integer is `k`.
+*   The sum of the integers is `num`.
+
+Return _the **minimum** possible size of such a set, or_ `-1` _if no such set exists._
+
+Note:
+
+*   The set can contain multiple instances of the same integer, and the sum of an empty set is considered `0`.
+*   The **units digit** of a number is the rightmost digit of the number.
+
+**Example 1:**
+
+**Input:** num = 58, k = 9
+
+**Output:** 2
+
+**Explanation:**
+
+One valid set is [9,49], as the sum is 58 and each integer has a units digit of 9.
+
+Another valid set is [19,39].
+
+It can be shown that 2 is the minimum possible size of a valid set. 
+
+**Example 2:**
+
+**Input:** num = 37, k = 2
+
+**Output:** -1
+
+**Explanation:** It is not possible to obtain a sum of 37 using only integers that have a units digit of 2. 
+
+**Example 3:**
+
+**Input:** num = 0, k = 7
+
+**Output:** 0
+
+**Explanation:** The sum of an empty set is considered 0. 
+
+**Constraints:**
+
+*   `0 <= num <= 3000`
+*   `0 <= k <= 9`
+
+## Solution
+
+```kotlin
+class Solution {
+    fun minimumNumbers(nums: Int, k: Int): Int {
+        // Base Case Check
+        if (nums == 0) {
+            return 0
+        }
+        val x = nums % 10
+        for (i in 1..10) {
+            // check if the unit digits are equal for any case and if n>k*i
+            if (k * i % 10 == x && nums >= k * i) {
+                return i
+            }
+        }
+        // in case nothing matches
+        return -1
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2311_longest_binary_subsequence_less_than_or_equal_to_k/readme.md b/src/main/kotlin/g2301_2400/s2311_longest_binary_subsequence_less_than_or_equal_to_k/readme.md
new file mode 100644
index 00000000..fcbdf4f9
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2311_longest_binary_subsequence_less_than_or_equal_to_k/readme.md
@@ -0,0 +1,68 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2311\. Longest Binary Subsequence Less Than or Equal to K
+
+Medium
+
+You are given a binary string `s` and a positive integer `k`.
+
+Return _the length of the **longest** subsequence of_ `s` _that makes up a **binary** number less than or equal to_ `k`.
+
+Note:
+
+*   The subsequence can contain **leading zeroes**.
+*   The empty string is considered to be equal to `0`.
+*   A **subsequence** is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.
+
+**Example 1:**
+
+**Input:** s = "1001010", k = 5
+
+**Output:** 5
+
+**Explanation:** The longest subsequence of s that makes up a binary number less than or equal to 5 is "00010", as this number is equal to 2 in decimal.
+
+Note that "00100" and "00101" are also possible, which are equal to 4 and 5 in decimal, respectively.
+
+The length of this subsequence is 5, so 5 is returned.
+
+**Example 2:**
+
+**Input:** s = "00101001", k = 1
+
+**Output:** 6
+
+**Explanation:** "000001" is the longest subsequence of s that makes up a binary number less than or equal to 1, as this number is equal to 1 in decimal.
+
+The length of this subsequence is 6, so 6 is returned.
+
+**Constraints:**
+
+*   `1 <= s.length <= 1000`
+*   `s[i]` is either `'0'` or `'1'`.
+*   1 <= k <= 109
+
+## Solution
+
+```kotlin
+@Suppress("NAME_SHADOWING")
+class Solution {
+    fun longestSubsequence(s: String, k: Int): Int {
+        var k = k
+        var res = 0
+        var cost = 1
+        val n = s.length
+        for (i in n - 1 downTo 0) {
+            if (s[i] == '0' || cost <= k) {
+                k -= cost * (s[i].code - '0'.code)
+                ++res
+            }
+            if (cost <= k) {
+                cost *= 2
+            }
+        }
+        return res
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2312_selling_pieces_of_wood/readme.md b/src/main/kotlin/g2301_2400/s2312_selling_pieces_of_wood/readme.md
new file mode 100644
index 00000000..535ae5d5
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2312_selling_pieces_of_wood/readme.md
@@ -0,0 +1,91 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2312\. Selling Pieces of Wood
+
+Hard
+
+You are given two integers `m` and `n` that represent the height and width of a rectangular piece of wood. You are also given a 2D integer array `prices`, where prices[i] = [hi, wi, pricei] indicates you can sell a rectangular piece of wood of height hi and width wi for pricei dollars.
+
+To cut a piece of wood, you must make a vertical or horizontal cut across the **entire** height or width of the piece to split it into two smaller pieces. After cutting a piece of wood into some number of smaller pieces, you can sell pieces according to `prices`. You may sell multiple pieces of the same shape, and you do not have to sell all the shapes. The grain of the wood makes a difference, so you **cannot** rotate a piece to swap its height and width.
+
+Return _the **maximum** money you can earn after cutting an_ `m x n` _piece of wood_.
+
+Note that you can cut the piece of wood as many times as you want.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/04/27/ex1.png)
+
+**Input:** m = 3, n = 5, prices = \[\[1,4,2],[2,2,7],[2,1,3]]
+
+**Output:** 19
+
+**Explanation:** The diagram above shows a possible scenario. It consists of:
+
+- 2 pieces of wood shaped 2 x 2, selling for a price of 2 \* 7 = 14.
+
+- 1 piece of wood shaped 2 x 1, selling for a price of 1 \* 3 = 3.
+
+- 1 piece of wood shaped 1 x 4, selling for a price of 1 \* 2 = 2.
+
+This obtains a total of 14 + 3 + 2 = 19 money earned.
+
+It can be shown that 19 is the maximum amount of money that can be earned.
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2022/04/27/ex2new.png)
+
+**Input:** m = 4, n = 6, prices = \[\[3,2,10],[1,4,2],[4,1,3]]
+
+**Output:** 32
+
+**Explanation:** The diagram above shows a possible scenario. It consists of:
+
+- 3 pieces of wood shaped 3 x 2, selling for a price of 3 \* 10 = 30.
+
+- 1 piece of wood shaped 1 x 4, selling for a price of 1 \* 2 = 2.
+
+This obtains a total of 30 + 2 = 32 money earned.
+
+It can be shown that 32 is the maximum amount of money that can be earned.
+
+Notice that we cannot rotate the 1 x 4 piece of wood to obtain a 4 x 1 piece of wood.
+
+**Constraints:**
+
+*   `1 <= m, n <= 200`
+*   1 <= prices.length <= 2 * 104
+*   `prices[i].length == 3`
+*   1 <= hi <= m
+*   1 <= wi <= n
+*   1 <= pricei <= 106
+*   All the shapes of wood (hi, wi) are pairwise **distinct**.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun sellingWood(m: Int, n: Int, prices: Array): Long {
+        // dp[i][j] = Maximum profit selling wood of size i*j
+        val dp = Array(m) { LongArray(n) }
+        for (price in prices) {
+            dp[price[0] - 1][price[1] - 1] = dp[price[0] - 1][price[1] - 1].coerceAtLeast(price[2].toLong())
+        }
+        for (i in 0 until m) {
+            for (j in 0 until n) {
+                // Cut Vertically
+                for (k in 0 until j) {
+                    dp[i][j] = dp[i][j].coerceAtLeast(dp[i][k] + dp[i][j - k - 1])
+                }
+                // Cut Horizontally
+                for (k in 0 until i) {
+                    dp[i][j] = dp[i][j].coerceAtLeast(dp[k][j] + dp[i - k - 1][j])
+                }
+            }
+        }
+        return dp[m - 1][n - 1]
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2315_count_asterisks/readme.md b/src/main/kotlin/g2301_2400/s2315_count_asterisks/readme.md
new file mode 100644
index 00000000..0a68b721
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2315_count_asterisks/readme.md
@@ -0,0 +1,73 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2315\. Count Asterisks
+
+Easy
+
+You are given a string `s`, where every **two** consecutive vertical bars `'|'` are grouped into a **pair**. In other words, the 1st and 2nd `'|'` make a pair, the 3rd and 4th `'|'` make a pair, and so forth.
+
+Return _the number of_ `'*'` _in_ `s`_, **excluding** the_ `'*'` _between each pair of_ `'|'`.
+
+**Note** that each `'|'` will belong to **exactly** one pair.
+
+**Example 1:**
+
+**Input:** s = "l\|\*e\*et\|c\*\*o\|\*de\|"
+
+**Output:** 2
+
+**Explanation:** The considered characters are underlined: "l\|\*e\*et\|c\*\*o\|\*de\|".
+
+The characters between the first and second '\|' are excluded from the answer.
+
+Also, the characters between the third and fourth '\|' are excluded from the answer. There are 2 asterisks considered. Therefore, we return 2.
+
+**Example 2:**
+
+**Input:** s = "iamprogrammer"
+
+**Output:** 0
+
+**Explanation:** In this example, there are no asterisks in s. Therefore, we return 0. 
+
+**Example 3:**
+
+**Input:** s = "yo\|uar\|e\*\*\|b\|e\*\*\*au\|tifu\|l"
+
+**Output:** 5
+
+**Explanation:** The considered characters are underlined: "yo\|uar\|e\*\*\|b\|e\*\*\*au\|tifu\|l".
+
+There are 5 asterisks considered. Therefore, we return 5.
+
+**Constraints:**
+
+*   `1 <= s.length <= 1000`
+*   `s` consists of lowercase English letters, vertical bars `'|'`, and asterisks `'*'`.
+*   `s` contains an **even** number of vertical bars `'|'`.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun countAsterisks(s: String): Int {
+        var c = 0
+        val n = s.length
+        var i = 0
+        while (i < n) {
+            if (s[i] == '|') {
+                i++
+                while (s[i] != '|') {
+                    i++
+                }
+            }
+            if (s[i] == '*') {
+                c++
+            }
+            i++
+        }
+        return c
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2316_count_unreachable_pairs_of_nodes_in_an_undirected_graph/readme.md b/src/main/kotlin/g2301_2400/s2316_count_unreachable_pairs_of_nodes_in_an_undirected_graph/readme.md
new file mode 100644
index 00000000..623f9db2
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2316_count_unreachable_pairs_of_nodes_in_an_undirected_graph/readme.md
@@ -0,0 +1,101 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2316\. Count Unreachable Pairs of Nodes in an Undirected Graph
+
+Medium
+
+You are given an integer `n`. There is an **undirected** graph with `n` nodes, numbered from `0` to `n - 1`. You are given a 2D integer array `edges` where edges[i] = [ai, bi] denotes that there exists an **undirected** edge connecting nodes ai and bi.
+
+Return _the **number of pairs** of different nodes that are **unreachable** from each other_.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/05/05/tc-3.png)
+
+**Input:** n = 3, edges = \[\[0,1],[0,2],[1,2]]
+
+**Output:** 0
+
+**Explanation:** There are no pairs of nodes that are unreachable from each other.
+
+Therefore, we return 0.
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2022/05/05/tc-2.png)
+
+**Input:** n = 7, edges = \[\[0,2],[0,5],[2,4],[1,6],[5,4]]
+
+**Output:** 14
+
+**Explanation:** There are 14 pairs of nodes that are unreachable from each other: [[0,1],[0,3],[0,6],[1,2],[1,3],[1,4],[1,5],[2,3],[2,6],[3,4],[3,5],[3,6],[4,6],[5,6]].
+
+Therefore, we return 14.
+
+**Constraints:**
+
+*   1 <= n <= 105
+*   0 <= edges.length <= 2 * 105
+*   `edges[i].length == 2`
+*   0 <= ai, bi < n
+*   ai != bi
+*   There are no repeated edges.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun countPairs(n: Int, edges: Array): Long {
+        val d = DSU(n)
+        val map = HashMap()
+        for (e in edges) {
+            d.union(e[0], e[1])
+        }
+        var ans: Long = 0
+        for (i in 0 until n) {
+            val p = d.findParent(i)
+            val cnt = if (map.containsKey(p)) map[p]!! else 0
+            ans += (i - cnt).toLong()
+            map[p] = map.getOrDefault(p, 0) + 1
+        }
+        return ans
+    }
+
+    private class DSU internal constructor(n: Int) {
+        var rank: IntArray
+        var parent: IntArray
+
+        init {
+            rank = IntArray(n + 1)
+            parent = IntArray(n + 1)
+            for (i in 1..n) {
+                parent[i] = i
+            }
+        }
+
+        fun findParent(node: Int): Int {
+            if (parent[node] == node) {
+                return node
+            }
+            parent[node] = findParent(parent[node])
+            return findParent(parent[node])
+        }
+
+        fun union(x: Int, y: Int): Boolean {
+            val px = findParent(x)
+            val py = findParent(y)
+            if (px == py) {
+                return false
+            }
+            if (rank[px] > rank[py]) {
+                parent[py] = px
+            } else {
+                parent[px] = py
+                rank[py]++
+            }
+            return true
+        }
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2317_maximum_xor_after_operations/readme.md b/src/main/kotlin/g2301_2400/s2317_maximum_xor_after_operations/readme.md
new file mode 100644
index 00000000..2424a4d2
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2317_maximum_xor_after_operations/readme.md
@@ -0,0 +1,57 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2317\. Maximum XOR After Operations
+
+Medium
+
+You are given a **0-indexed** integer array `nums`. In one operation, select **any** non-negative integer `x` and an index `i`, then **update** `nums[i]` to be equal to `nums[i] AND (nums[i] XOR x)`.
+
+Note that `AND` is the bitwise AND operation and `XOR` is the bitwise XOR operation.
+
+Return _the **maximum** possible bitwise XOR of all elements of_ `nums` _after applying the operation **any number** of times_.
+
+**Example 1:**
+
+**Input:** nums = [3,2,4,6]
+
+**Output:** 7
+
+**Explanation:** Apply the operation with x = 4 and i = 3, num[3] = 6 AND (6 XOR 4) = 6 AND 2 = 2.
+
+Now, nums = [3, 2, 4, 2] and the bitwise XOR of all the elements = 3 XOR 2 XOR 4 XOR 2 = 7.
+
+It can be shown that 7 is the maximum possible bitwise XOR.
+
+Note that other operations may be used to achieve a bitwise XOR of 7.
+
+**Example 2:**
+
+**Input:** nums = [1,2,3,9,2]
+
+**Output:** 11
+
+**Explanation:** Apply the operation zero times.
+
+The bitwise XOR of all the elements = 1 XOR 2 XOR 3 XOR 9 XOR 2 = 11.
+
+It can be shown that 11 is the maximum possible bitwise XOR.
+
+**Constraints:**
+
+*   1 <= nums.length <= 105
+*   0 <= nums[i] <= 108
+
+## Solution
+
+```kotlin
+class Solution {
+    fun maximumXOR(nums: IntArray): Int {
+        var max = 0
+        for (n in nums) {
+            max = max or n
+        }
+        return max
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2318_number_of_distinct_roll_sequences/readme.md b/src/main/kotlin/g2301_2400/s2318_number_of_distinct_roll_sequences/readme.md
new file mode 100644
index 00000000..ed09ef8a
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2318_number_of_distinct_roll_sequences/readme.md
@@ -0,0 +1,86 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2318\. Number of Distinct Roll Sequences
+
+Hard
+
+You are given an integer `n`. You roll a fair 6-sided dice `n` times. Determine the total number of **distinct** sequences of rolls possible such that the following conditions are satisfied:
+
+1.  The **greatest common divisor** of any **adjacent** values in the sequence is equal to `1`.
+2.  There is **at least** a gap of `2` rolls between **equal** valued rolls. More formally, if the value of the ith roll is **equal** to the value of the jth roll, then `abs(i - j) > 2`.
+
+Return _the **total number** of distinct sequences possible_. Since the answer may be very large, return it **modulo** 109 + 7.
+
+Two sequences are considered distinct if at least one element is different.
+
+**Example 1:**
+
+**Input:** n = 4
+
+**Output:** 184
+
+**Explanation:** Some of the possible sequences are (1, 2, 3, 4), (6, 1, 2, 3), (1, 2, 3, 1), etc.
+
+Some invalid sequences are (1, 2, 1, 3), (1, 2, 3, 6).
+
+(1, 2, 1, 3) is invalid since the first and third roll have an equal value and abs(1 - 3) = 2 (i and j are 1-indexed).
+
+(1, 2, 3, 6) is invalid since the greatest common divisor of 3 and 6 = 3.
+
+There are a total of 184 distinct sequences possible, so we return 184.
+
+**Example 2:**
+
+**Input:** n = 2
+
+**Output:** 22
+
+**Explanation:** Some of the possible sequences are (1, 2), (2, 1), (3, 2).
+
+Some invalid sequences are (3, 6), (2, 4) since the greatest common divisor is not equal to 1.
+
+There are a total of 22 distinct sequences possible, so we return 22. 
+
+**Constraints:**
+
+*   1 <= n <= 104
+
+## Solution
+
+```kotlin
+class Solution {
+    private val memo = Array(10001) { Array(7) { IntArray(7) } }
+    private val mod = 1000000007
+    private val m = arrayOf(
+        intArrayOf(1, 2, 3, 4, 5, 6),
+        intArrayOf(2, 3, 4, 5, 6),
+        intArrayOf(1, 3, 5),
+        intArrayOf(1, 2, 4, 5),
+        intArrayOf(1, 3, 5),
+        intArrayOf(1, 2, 3, 4, 6),
+        intArrayOf(1, 5)
+    )
+
+    fun distinctSequences(n: Int): Int {
+        return dp(n, 0, 0)
+    }
+
+    private fun dp(n: Int, prev: Int, pprev: Int): Int {
+        if (n == 0) {
+            return 1
+        }
+        if (memo[n][prev][pprev] != 0) {
+            return memo[n][prev][pprev]
+        }
+        var ans = 0
+        for (x in m[prev]) {
+            if (x != pprev) {
+                ans = (ans + dp(n - 1, x, prev)) % mod
+            }
+        }
+        memo[n][prev][pprev] = ans
+        return ans
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2319_check_if_matrix_is_x_matrix/readme.md b/src/main/kotlin/g2301_2400/s2319_check_if_matrix_is_x_matrix/readme.md
new file mode 100644
index 00000000..1f934aa5
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2319_check_if_matrix_is_x_matrix/readme.md
@@ -0,0 +1,70 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2319\. Check if Matrix Is X-Matrix
+
+Easy
+
+A square matrix is said to be an **X-Matrix** if **both** of the following conditions hold:
+
+1.  All the elements in the diagonals of the matrix are **non-zero**.
+2.  All other elements are 0.
+
+Given a 2D integer array `grid` of size `n x n` representing a square matrix, return `true` _if_ `grid` _is an X-Matrix_. Otherwise, return `false`.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/05/03/ex1.jpg)
+
+**Input:** grid = \[\[2,0,0,1],[0,3,1,0],[0,5,2,0],[4,0,0,2]]
+
+**Output:** true
+
+**Explanation:** Refer to the diagram above.
+
+An X-Matrix should have the green elements (diagonals) be non-zero and the red elements be 0.
+
+Thus, grid is an X-Matrix.
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2022/05/03/ex2.jpg)
+
+**Input:** grid = \[\[5,7,0],[0,3,1],[0,5,0]]
+
+**Output:** false
+
+**Explanation:** Refer to the diagram above.
+
+An X-Matrix should have the green elements (diagonals) be non-zero and the red elements be 0.
+
+Thus, grid is not an X-Matrix.
+
+**Constraints:**
+
+*   `n == grid.length == grid[i].length`
+*   `3 <= n <= 100`
+*   0 <= grid[i][j] <= 105
+
+## Solution
+
+```kotlin
+class Solution {
+    fun checkXMatrix(grid: Array): Boolean {
+        for (i in grid.indices) {
+            for (j in grid[0].indices) {
+                if (i == j || i + j == grid.size - 1) {
+                    if (grid[i][j] == 0) {
+                        return false
+                    }
+                } else {
+                    if (grid[i][j] != 0) {
+                        return false
+                    }
+                }
+            }
+        }
+        return true
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2320_count_number_of_ways_to_place_houses/readme.md b/src/main/kotlin/g2301_2400/s2320_count_number_of_ways_to_place_houses/readme.md
new file mode 100644
index 00000000..10d21d16
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2320_count_number_of_ways_to_place_houses/readme.md
@@ -0,0 +1,73 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2320\. Count Number of Ways to Place Houses
+
+Medium
+
+There is a street with `n * 2` **plots**, where there are `n` plots on each side of the street. The plots on each side are numbered from `1` to `n`. On each plot, a house can be placed.
+
+Return _the number of ways houses can be placed such that no two houses are adjacent to each other on the same side of the street_. Since the answer may be very large, return it **modulo** 109 + 7.
+
+Note that if a house is placed on the ith plot on one side of the street, a house can also be placed on the ith plot on the other side of the street.
+
+**Example 1:**
+
+**Input:** n = 1
+
+**Output:** 4
+
+**Explanation:**
+
+Possible arrangements:
+
+1. All plots are empty.
+
+2. A house is placed on one side of the street.
+
+3. A house is placed on the other side of the street.
+
+4. Two houses are placed, one on each side of the street.
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2022/05/12/arrangements.png)
+
+**Input:** n = 2
+
+**Output:** 9
+
+**Explanation:** The 9 possible arrangements are shown in the diagram above.
+
+**Constraints:**
+
+*   1 <= n <= 104
+
+## Solution
+
+```kotlin
+@Suppress("NAME_SHADOWING")
+class Solution {
+    fun countHousePlacements(n: Int): Int {
+        // algo - 1st solve one side  of the street
+        // think 0 - space , 1 - house
+        // if n = 1 then we can take one 0 and one 1 (total ways = 2)
+        // if n = 2 then 00 , 01 , 10 , 11 but we cant take 11 as two house cant be adjacent.
+        // so the 1 ended string will be only 1 which is same as previous 0 ended string and 0 ended
+        // string are 2 which is previous sum(total ways)
+        // apply this formula for n no's
+        var n = n
+        val mod: Long = 1000000007
+        var space: Long = 1
+        var house: Long = 1
+        var sum = space + house
+        while (--n > 0) {
+            house = space
+            space = sum
+            sum = (house + space) % mod
+        }
+        // as street has two side
+        return (sum * sum % mod).toInt()
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2321_maximum_score_of_spliced_array/readme.md b/src/main/kotlin/g2301_2400/s2321_maximum_score_of_spliced_array/readme.md
new file mode 100644
index 00000000..56afad4d
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2321_maximum_score_of_spliced_array/readme.md
@@ -0,0 +1,114 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2321\. Maximum Score Of Spliced Array
+
+Hard
+
+You are given two **0-indexed** integer arrays `nums1` and `nums2`, both of length `n`.
+
+You can choose two integers `left` and `right` where `0 <= left <= right < n` and **swap** the subarray `nums1[left...right]` with the subarray `nums2[left...right]`.
+
+*   For example, if `nums1 = [1,2,3,4,5]` and `nums2 = [11,12,13,14,15]` and you choose `left = 1` and `right = 2`, `nums1` becomes `[1,**12,13**,4,5]` and `nums2` becomes `[11,**2,3**,14,15]`.
+
+You may choose to apply the mentioned operation **once** or not do anything.
+
+The **score** of the arrays is the **maximum** of `sum(nums1)` and `sum(nums2)`, where `sum(arr)` is the sum of all the elements in the array `arr`.
+
+Return _the **maximum possible score**_.
+
+A **subarray** is a contiguous sequence of elements within an array. `arr[left...right]` denotes the subarray that contains the elements of `nums` between indices `left` and `right` (**inclusive**).
+
+**Example 1:**
+
+**Input:** nums1 = [60,60,60], nums2 = [10,90,10]
+
+**Output:** 210
+
+**Explanation:** Choosing left = 1 and right = 1, we have nums1 = [60,**90**,60] and nums2 = [10,**60**,10].
+
+The score is max(sum(nums1), sum(nums2)) = max(210, 80) = 210.
+
+**Example 2:**
+
+**Input:** nums1 = [20,40,20,70,30], nums2 = [50,20,50,40,20]
+
+**Output:** 220
+
+**Explanation:** Choosing left = 3, right = 4, we have nums1 = [20,40,20,**40,20**] and nums2 = [50,20,50,**70,30**].
+
+The score is max(sum(nums1), sum(nums2)) = max(140, 220) = 220. 
+
+**Example 3:**
+
+**Input:** nums1 = [7,11,13], nums2 = [1,1,1]
+
+**Output:** 31
+
+**Explanation:** We choose not to swap any subarray.
+
+The score is max(sum(nums1), sum(nums2)) = max(31, 3) = 31. 
+
+**Constraints:**
+
+*   `n == nums1.length == nums2.length`
+*   1 <= n <= 105
+*   1 <= nums1[i], nums2[i] <= 104
+
+## Solution
+
+```kotlin
+@Suppress("NAME_SHADOWING")
+class Solution {
+    fun maximumsSplicedArray(nums1: IntArray, nums2: IntArray): Int {
+        var nums1 = nums1
+        var nums2 = nums2
+        var sum1 = 0
+        var sum2 = 0
+        val n = nums1.size
+        for (num in nums1) {
+            sum1 += num
+        }
+        for (num in nums2) {
+            sum2 += num
+        }
+        if (sum2 > sum1) {
+            val temp = sum2
+            sum2 = sum1
+            sum1 = temp
+            val temparr = nums2
+            nums2 = nums1
+            nums1 = temparr
+        }
+        // now sum1>=sum2
+        // maxEndingHere denotes the maximum sum subarray ending at current index(ie. element at
+        // current index has to be included)
+        // minEndingHere denotes the minimum sum subarray ending at current index
+        var maxEndingHere: Int
+        var minEndingHere: Int
+        var maxSoFar: Int
+        var minSoFar: Int
+        var currEle: Int
+        minSoFar = nums2[0] - nums1[0]
+        maxSoFar = minSoFar
+        minEndingHere = maxSoFar
+        maxEndingHere = minEndingHere
+        for (i in 1 until n) {
+            currEle = nums2[i] - nums1[i]
+            minEndingHere += currEle
+            maxEndingHere += currEle
+            if (maxEndingHere < currEle) {
+                maxEndingHere = currEle
+            }
+            if (minEndingHere > currEle) {
+                minEndingHere = currEle
+            }
+            maxSoFar = maxEndingHere.coerceAtLeast(maxSoFar)
+            minSoFar = minEndingHere.coerceAtMost(minSoFar)
+        }
+        // return the maximum of the 2 possibilities dicussed
+        // also keep care that maxSoFar>=0 and maxSoFar<=0
+        return (sum1 + maxSoFar.coerceAtLeast(0)).coerceAtLeast(sum2 - 0.coerceAtMost(minSoFar))
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2322_minimum_score_after_removals_on_a_tree/readme.md b/src/main/kotlin/g2301_2400/s2322_minimum_score_after_removals_on_a_tree/readme.md
new file mode 100644
index 00000000..aa7d241b
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2322_minimum_score_after_removals_on_a_tree/readme.md
@@ -0,0 +1,157 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2322\. Minimum Score After Removals on a Tree
+
+Hard
+
+There is an undirected connected tree with `n` nodes labeled from `0` to `n - 1` and `n - 1` edges.
+
+You are given a **0-indexed** integer array `nums` of length `n` where `nums[i]` represents the value of the ith node. You are also given a 2D integer array `edges` of length `n - 1` where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.
+
+Remove two **distinct** edges of the tree to form three connected components. For a pair of removed edges, the following steps are defined:
+
+1.  Get the XOR of all the values of the nodes for **each** of the three components respectively.
+2.  The **difference** between the **largest** XOR value and the **smallest** XOR value is the **score** of the pair.
+
+*   For example, say the three components have the node values: `[4,5,7]`, `[1,9]`, and `[3,3,3]`. The three XOR values are 4 ^ 5 ^ 7 = **6**, 1 ^ 9 = **8**, and 3 ^ 3 ^ 3 = **3**. The largest XOR value is `8` and the smallest XOR value is `3`. The score is then `8 - 3 = 5`.
+
+Return _the **minimum** score of any possible pair of edge removals on the given tree_.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/05/03/ex1drawio.png)
+
+**Input:** nums = [1,5,5,4,11], edges = \[\[0,1],[1,2],[1,3],[3,4]]
+
+**Output:** 9
+
+**Explanation:** The diagram above shows a way to make a pair of removals.
+
+- The 1st component has nodes [1,3,4] with values [5,4,11]. Its XOR value is 5 ^ 4 ^ 11 = 10.
+
+- The 2nd component has node [0] with value [1]. Its XOR value is 1 = 1.
+
+- The 3rd component has node [2] with value [5]. Its XOR value is 5 = 5.
+
+The score is the difference between the largest and smallest XOR value which is 10 - 1 = 9.
+
+It can be shown that no other pair of removals will obtain a smaller score than 9. 
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2022/05/03/ex2drawio.png)
+
+**Input:** nums = [5,5,2,4,4,2], edges = \[\[0,1],[1,2],[5,2],[4,3],[1,3]]
+
+**Output:** 0
+
+**Explanation:** The diagram above shows a way to make a pair of removals.
+
+- The 1st component has nodes [3,4] with values [4,4]. Its XOR value is 4 ^ 4 = 0.
+
+- The 2nd component has nodes [1,0] with values [5,5]. Its XOR value is 5 ^ 5 = 0.
+
+- The 3rd component has nodes [2,5] with values [2,2]. Its XOR value is 2 ^ 2 = 0.
+
+The score is the difference between the largest and smallest XOR value which is 0 - 0 = 0.
+
+We cannot obtain a smaller score than 0. 
+
+**Constraints:**
+
+*   `n == nums.length`
+*   `3 <= n <= 1000`
+*   1 <= nums[i] <= 108
+*   `edges.length == n - 1`
+*   `edges[i].length == 2`
+*   0 <= ai, bi < n
+*   ai != bi
+*   `edges` represents a valid tree.
+
+## Solution
+
+```kotlin
+class Solution {
+    private var ans = Int.MAX_VALUE
+
+    // function to travel 2nd time on the tree and find the second edge to be removed
+    private fun helper(
+        src: Int,
+        graph: Array?>,
+        arr: IntArray,
+        par: Int,
+        block: Int,
+        xor1: Int,
+        tot: Int
+    ): Int {
+        // Setting the value for the current subtree's XOR value
+        var myXOR = arr[src]
+        for (nbr in graph[src]!!) {
+            // If the current nbr is niether the parent of this node nor the blocked node  , then
+            // only we'll proceed
+            if (nbr != par && nbr != block) {
+                val nbrXOR = helper(nbr, graph, arr, src, block, xor1, tot)
+                // 'src <----> nbr' is the second edge to be removed
+                // Getting the XOR value of the current neighbor
+                // The XOR of the remaining component
+                val xor3 = tot xor xor1 xor nbrXOR
+                // Getting the minimum of the three values
+                val max = xor1.coerceAtLeast(nbrXOR.coerceAtLeast(xor3))
+                // Getting the maximum of the three value
+                val min = xor1.coerceAtMost(nbrXOR.coerceAtMost(xor3))
+                ans = ans.coerceAtMost(max - min)
+                // Including the neighbour subtree's XOR value in the XOR value of the subtree
+                // rooted at src node
+                myXOR = myXOR xor nbrXOR
+            }
+        }
+        // Returing the XOR value of the current subtree rooted at the src node
+        return myXOR
+    }
+
+    // function to travel 1st time on the tree and find the first edge to be removed and
+    // then block the node at which the edge ends to avoid selecting the same node again
+    private fun dfs(src: Int, graph: Array?>, arr: IntArray, par: Int, tot: Int): Int {
+        // Setting the value for the current subtree's XOR value
+        var myXOR = arr[src]
+        for (nbr in graph[src]!!) {
+            // If the current nbr is not the parent of this node, then only we'll proceed
+            if (nbr != par) {
+                // After selecting 'src <----> nbr' as the first edge, we block 'nbr' node and then
+                // make a call to try all the second edges
+                val nbrXOR = dfs(nbr, graph, arr, src, tot)
+                // Calling the helper to find the try all the second edges after blocking the
+                // current node
+                helper(0, graph, arr, -1, nbr, nbrXOR, tot)
+                // Including the neighbour subtree's XOR value in the XOR value of the subtree
+                // rooted at src node
+                myXOR = myXOR xor nbrXOR
+            }
+        }
+        // Returing the XOR value of the current subtree rooted at the src node
+        return myXOR
+    }
+
+    fun minimumScore(arr: IntArray, edges: Array): Int {
+        val n = arr.size
+        val graph: Array?> = arrayOfNulls(n)
+        var tot = 0
+        for (i in 0 until n) {
+            // Initializing the graph and finding the total XOR
+            graph[i] = ArrayList()
+            tot = tot xor arr[i]
+        }
+        for (edge in edges) {
+            // adding the edges
+            val u = edge[0]
+            val v = edge[1]
+            graph[u]!!.add(v)
+            graph[v]!!.add(u)
+        }
+        ans = Int.MAX_VALUE
+        dfs(0, graph, arr, -1, tot)
+        return ans
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2325_decode_the_message/readme.md b/src/main/kotlin/g2301_2400/s2325_decode_the_message/readme.md
new file mode 100644
index 00000000..59b15429
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2325_decode_the_message/readme.md
@@ -0,0 +1,81 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2325\. Decode the Message
+
+Easy
+
+You are given the strings `key` and `message`, which represent a cipher key and a secret message, respectively. The steps to decode `message` are as follows:
+
+1.  Use the **first** appearance of all 26 lowercase English letters in `key` as the **order** of the substitution table.
+2.  Align the substitution table with the regular English alphabet.
+3.  Each letter in `message` is then **substituted** using the table.
+4.  Spaces `' '` are transformed to themselves.
+
+*   For example, given key = "**hap**p**y** **bo**y" (actual key would have **at least one** instance of each letter in the alphabet), we have the partial substitution table of (`'h' -> 'a'`, `'a' -> 'b'`, `'p' -> 'c'`, `'y' -> 'd'`, `'b' -> 'e'`, `'o' -> 'f'`).
+
+Return _the decoded message_.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/05/08/ex1new4.jpg)
+
+**Input:** key = "the quick brown fox jumps over the lazy dog", message = "vkbs bs t suepuv"
+
+**Output:** "this is a secret"
+
+**Explanation:** The diagram above shows the substitution table.
+
+It is obtained by taking the first appearance of each letter in "**the** **quick** **brown** **f**o**x** **j**u**mps** o**v**er the **lazy** **d**o**g**".
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2022/05/08/ex2new.jpg)
+
+**Input:** key = "eljuxhpwnyrdgtqkviszcfmabo", message = "zwx hnfx lqantp mnoeius ycgk vcnjrdb"
+
+**Output:** "the five boxing wizards jump quickly"
+
+**Explanation:** The diagram above shows the substitution table.
+
+It is obtained by taking the first appearance of each letter in "**eljuxhpwnyrdgtqkviszcfmabo**".
+
+**Constraints:**
+
+*   `26 <= key.length <= 2000`
+*   `key` consists of lowercase English letters and `' '`.
+*   `key` contains every letter in the English alphabet (`'a'` to `'z'`) **at least once**.
+*   `1 <= message.length <= 2000`
+*   `message` consists of lowercase English letters and `' '`.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun decodeMessage(key: String, message: String): String {
+        val sb = StringBuilder()
+        val temp: MutableMap = HashMap()
+        val alphabet = CharArray(26)
+        var itr = 0
+        var c = 'a'
+        while (c <= 'z') {
+            alphabet[c.code - 'a'.code] = c
+            ++c
+        }
+        for (i in key.indices) {
+            if (!temp.containsKey(key[i]) && key[i] != ' ') {
+                temp[key[i]] = alphabet[itr++]
+            }
+        }
+        for (j in message.indices) {
+            if (message[j] == ' ') {
+                sb.append(' ')
+            } else {
+                val result = temp[message[j]]!!
+                sb.append(result)
+            }
+        }
+        return sb.toString()
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2326_spiral_matrix_iv/readme.md b/src/main/kotlin/g2301_2400/s2326_spiral_matrix_iv/readme.md
new file mode 100644
index 00000000..93a8abde
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2326_spiral_matrix_iv/readme.md
@@ -0,0 +1,126 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2326\. Spiral Matrix IV
+
+Medium
+
+You are given two integers `m` and `n`, which represent the dimensions of a matrix.
+
+You are also given the `head` of a linked list of integers.
+
+Generate an `m x n` matrix that contains the integers in the linked list presented in **spiral** order **(clockwise)**, starting from the **top-left** of the matrix. If there are remaining empty spaces, fill them with `-1`.
+
+Return _the generated matrix_.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/05/09/ex1new.jpg)
+
+**Input:** m = 3, n = 5, head = [3,0,2,6,8,1,7,9,4,2,5,5,0]
+
+**Output:** [[3,0,2,6,8],[5,0,-1,-1,1],[5,2,4,9,7]]
+
+**Explanation:** The diagram above shows how the values are printed in the matrix.
+
+Note that the remaining spaces in the matrix are filled with -1.
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2022/05/11/ex2.jpg)
+
+**Input:** m = 1, n = 4, head = [0,1,2]
+
+**Output:** [[0,1,2,-1]]
+
+**Explanation:** The diagram above shows how the values are printed from left to right in the matrix.
+
+The last space in the matrix is set to -1.
+
+**Constraints:**
+
+*   1 <= m, n <= 105
+*   1 <= m * n <= 105
+*   The number of nodes in the list is in the range `[1, m * n]`.
+*   `0 <= Node.val <= 1000`
+
+## Solution
+
+```kotlin
+import com_github_leetcode.ListNode
+
+/*
+ * Example:
+ * var li = ListNode(5)
+ * var v = li.`val`
+ * Definition for singly-linked list.
+ * class ListNode(var `val`: Int) {
+ *     var next: ListNode? = null
+ * }
+ */
+@Suppress("NAME_SHADOWING")
+class Solution {
+    private enum class Direction {
+        RIGHT, DOWN, LEFT, UP
+    }
+
+    fun spiralMatrix(m: Int, n: Int, head: ListNode?): Array {
+        var head = head
+        val arr = Array(m) { IntArray(n) }
+        var i = 0
+        var j = -1
+        var direction = Direction.RIGHT
+        // Boundaries
+        // ++ after Left to right Horizontal traversed
+        var a = 0
+        // -- after Down to Up vertical traversed
+        var b = n - 1
+        // -- after Right to Left horizontal teversed
+        var c = m - 1
+        // ++ after Down to Up vertical traversed
+        var d = 0
+        for (k in 0 until m * n) {
+            var `val` = -1
+            if (head != null) {
+                `val` = head.`val`
+                head = head.next
+            }
+            when (direction) {
+                Direction.RIGHT -> {
+                    ++j
+                    if (j == b) {
+                        direction = Direction.DOWN
+                        ++a
+                    }
+                }
+
+                Direction.DOWN -> {
+                    ++i
+                    if (i == c) {
+                        direction = Direction.LEFT
+                    }
+                }
+
+                Direction.LEFT -> {
+                    --j
+                    if (j == d) {
+                        --c
+                        direction = Direction.UP
+                    }
+                }
+
+                Direction.UP -> {
+                    --i
+                    if (i == a) {
+                        --b
+                        ++d
+                        direction = Direction.RIGHT
+                    }
+                }
+            }
+            arr[i][j] = `val`
+        }
+        return arr
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2327_number_of_people_aware_of_a_secret/readme.md b/src/main/kotlin/g2301_2400/s2327_number_of_people_aware_of_a_secret/readme.md
new file mode 100644
index 00000000..2b2b67f6
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2327_number_of_people_aware_of_a_secret/readme.md
@@ -0,0 +1,81 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2327\. Number of People Aware of a Secret
+
+Medium
+
+On day `1`, one person discovers a secret.
+
+You are given an integer `delay`, which means that each person will **share** the secret with a new person **every day**, starting from `delay` days after discovering the secret. You are also given an integer `forget`, which means that each person will **forget** the secret `forget` days after discovering it. A person **cannot** share the secret on the same day they forgot it, or on any day afterwards.
+
+Given an integer `n`, return _the number of people who know the secret at the end of day_ `n`. Since the answer may be very large, return it **modulo** 109 + 7.
+
+**Example 1:**
+
+**Input:** n = 6, delay = 2, forget = 4
+
+**Output:** 5
+
+**Explanation:**
+
+Day 1: Suppose the first person is named A. (1 person)
+
+Day 2: A is the only person who knows the secret. (1 person)
+
+Day 3: A shares the secret with a new person, B. (2 people)
+
+Day 4: A shares the secret with a new person, C. (3 people)
+
+Day 5: A forgets the secret, and B shares the secret with a new person, D. (3 people)
+
+Day 6: B shares the secret with E, and C shares the secret with F. (5 people) 
+
+**Example 2:**
+
+**Input:** n = 4, delay = 1, forget = 3
+
+**Output:** 6
+
+**Explanation:**
+
+Day 1: The first person is named A. (1 person)
+
+Day 2: A shares the secret with B. (2 people)
+
+Day 3: A and B share the secret with 2 new people, C and D. (4 people)
+
+Day 4: A forgets the secret. B, C, and D share the secret with 3 new people. (6 people) 
+
+**Constraints:**
+
+*   `2 <= n <= 1000`
+*   `1 <= delay < forget <= n`
+
+## Solution
+
+```kotlin
+class Solution {
+    fun peopleAwareOfSecret(n: Int, delay: Int, forget: Int): Int {
+        val dp = Array(n + forget) { LongArray(3) }
+        // 0: people who currently know the secret (includes [1] below)
+        // 1: people who start sharing the secret on this day
+        // 2: people who forget on this day
+        val mod = 1e9.toLong() + 7
+        dp[forget][2] = 1
+        dp[delay][1] = dp[forget][2]
+        dp[0][0] = dp[delay][1]
+        for (i in 1 until n) {
+            // dp[i][1] was originally just the i - delay newcomers
+            dp[i][1] = (dp[i][1] + dp[i - 1][1] - dp[i][2] + mod) % mod
+            // these people forget on i + forget day
+            dp[i + forget][2] = dp[i][1]
+            // these people start sharing on i + delay day
+            dp[i + delay][1] = dp[i][1]
+            // today's total people who know the secret
+            dp[i][0] = (dp[i - 1][0] + dp[i][1] - dp[i][2] + mod) % mod
+        }
+        return dp[n - 1][0].toInt()
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2328_number_of_increasing_paths_in_a_grid/readme.md b/src/main/kotlin/g2301_2400/s2328_number_of_increasing_paths_in_a_grid/readme.md
new file mode 100644
index 00000000..57646d87
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2328_number_of_increasing_paths_in_a_grid/readme.md
@@ -0,0 +1,96 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2328\. Number of Increasing Paths in a Grid
+
+Hard
+
+You are given an `m x n` integer matrix `grid`, where you can move from a cell to any adjacent cell in all `4` directions.
+
+Return _the number of **strictly** **increasing** paths in the grid such that you can start from **any** cell and end at **any** cell._ Since the answer may be very large, return it **modulo** 109 + 7.
+
+Two paths are considered different if they do not have exactly the same sequence of visited cells.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/05/10/griddrawio-4.png)
+
+**Input:** grid = \[\[1,1],[3,4]]
+
+**Output:** 8
+
+**Explanation:** The strictly increasing paths are:
+
+- Paths with length 1: [1], [1], [3], [4].
+
+- Paths with length 2: [1 -> 3], [1 -> 4], [3 -> 4].
+
+- Paths with length 3: [1 -> 3 -> 4].
+
+The total number of paths is 4 + 3 + 1 = 8.
+
+**Example 2:**
+
+**Input:** grid = \[\[1],[2]]
+
+**Output:** 3
+
+**Explanation:** The strictly increasing paths are:
+
+- Paths with length 1: [1], [2].
+
+- Paths with length 2: [1 -> 2].
+
+The total number of paths is 2 + 1 = 3.
+
+**Constraints:**
+
+*   `m == grid.length`
+*   `n == grid[i].length`
+*   `1 <= m, n <= 1000`
+*   1 <= m * n <= 105
+*   1 <= grid[i][j] <= 105
+
+## Solution
+
+```kotlin
+class Solution {
+    private fun help(a: Array, i: Int, j: Int, n: Int, m: Int, dp: Array): Int {
+        if (i < 0 || i >= n || j >= m || j < 0) {
+            return 0
+        }
+        if (dp[i][j] != 0) {
+            return dp[i][j]
+        }
+        var res: Long = 0
+        if (i < n - 1 && a[i + 1][j] > a[i][j]) {
+            res += (1 + help(a, i + 1, j, n, m, dp)).toLong()
+        }
+        if (i > 0 && a[i - 1][j] > a[i][j]) {
+            res += (1 + help(a, i - 1, j, n, m, dp)).toLong()
+        }
+        if (j > 0 && a[i][j - 1] > a[i][j]) {
+            res += (1 + help(a, i, j - 1, n, m, dp)).toLong()
+        }
+        if (j < m - 1 && a[i][j + 1] > a[i][j]) {
+            res += (1 + help(a, i, j + 1, n, m, dp)).toLong()
+        }
+        dp[i][j] = res.toInt() % 1000000007
+        return dp[i][j]
+    }
+
+    fun countPaths(grid: Array): Int {
+        val n = grid.size
+        val m = grid[0].size
+        var ans = n.toLong() * m
+        val dp = Array(n) { IntArray(m) }
+        for (i in 0 until n) {
+            for (j in 0 until m) {
+                ans += (help(grid, i, j, n, m, dp) % 1000000007).toLong()
+            }
+        }
+        ans %= 1000000007
+        return ans.toInt()
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2331_evaluate_boolean_binary_tree/readme.md b/src/main/kotlin/g2301_2400/s2331_evaluate_boolean_binary_tree/readme.md
new file mode 100644
index 00000000..f071b860
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2331_evaluate_boolean_binary_tree/readme.md
@@ -0,0 +1,74 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2331\. Evaluate Boolean Binary Tree
+
+Easy
+
+You are given the `root` of a **full binary tree** with the following properties:
+
+*   **Leaf nodes** have either the value `0` or `1`, where `0` represents `False` and `1` represents `True`.
+*   **Non-leaf nodes** have either the value `2` or `3`, where `2` represents the boolean `OR` and `3` represents the boolean `AND`.
+
+The **evaluation** of a node is as follows:
+
+*   If the node is a leaf node, the evaluation is the **value** of the node, i.e. `True` or `False`.
+*   Otherwise, **evaluate** the node's two children and **apply** the boolean operation of its value with the children's evaluations.
+
+Return _the boolean result of **evaluating** the_ `root` _node._
+
+A **full binary tree** is a binary tree where each node has either `0` or `2` children.
+
+A **leaf node** is a node that has zero children.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/05/16/example1drawio1.png)
+
+**Input:** root = [2,1,3,null,null,0,1]
+
+**Output:** true
+
+**Explanation:** The above diagram illustrates the evaluation process.
+
+The AND node evaluates to False AND True = False.
+
+The OR node evaluates to True OR False = True.
+
+The root node evaluates to True, so we return true.
+
+**Example 2:**
+
+**Input:** root = [0]
+
+**Output:** false
+
+**Explanation:** The root node is a leaf node and it evaluates to false, so we return false. 
+
+**Constraints:**
+
+*   The number of nodes in the tree is in the range `[1, 1000]`.
+*   `0 <= Node.val <= 3`
+*   Every node has either `0` or `2` children.
+*   Leaf nodes have a value of `0` or `1`.
+*   Non-leaf nodes have a value of `2` or `3`.
+
+## Solution
+
+```kotlin
+import com_github_leetcode.TreeNode
+
+class Solution {
+    fun evaluateTree(root: TreeNode?): Boolean {
+        return if (root!!.left == null) {
+            root.`val` == 1
+        } else {
+            if (root.`val` == 2) {
+                evaluateTree(root.left) || evaluateTree(root.right)
+            } else {
+                evaluateTree(root.left) && evaluateTree(root.right)
+            }
+        }
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2332_the_latest_time_to_catch_a_bus/readme.md b/src/main/kotlin/g2301_2400/s2332_the_latest_time_to_catch_a_bus/readme.md
new file mode 100644
index 00000000..79f64830
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2332_the_latest_time_to_catch_a_bus/readme.md
@@ -0,0 +1,101 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2332\. The Latest Time to Catch a Bus
+
+Medium
+
+You are given a **0-indexed** integer array `buses` of length `n`, where `buses[i]` represents the departure time of the ith bus. You are also given a **0-indexed** integer array `passengers` of length `m`, where `passengers[j]` represents the arrival time of the jth passenger. All bus departure times are unique. All passenger arrival times are unique.
+
+You are given an integer `capacity`, which represents the **maximum** number of passengers that can get on each bus.
+
+The passengers will get on the next available bus. You can get on a bus that will depart at `x` minutes if you arrive at `y` minutes where `y <= x`, and the bus is not full. Passengers with the **earliest** arrival times get on the bus first.
+
+Return _the latest time you may arrive at the bus station to catch a bus_. You **cannot** arrive at the same time as another passenger.
+
+**Note:** The arrays `buses` and `passengers` are not necessarily sorted.
+
+**Example 1:**
+
+**Input:** buses = [10,20], passengers = [2,17,18,19], capacity = 2
+
+**Output:** 16
+
+**Explanation:**
+
+The 1st bus departs with the 1st passenger.
+
+The 2nd bus departs with you and the 2nd passenger.
+
+Note that you must not arrive at the same time as the passengers, which is why you must arrive before the 2nd passenger to catch the bus.
+
+**Example 2:**
+
+**Input:** buses = [20,30,10], passengers = [19,13,26,4,25,11,21], capacity = 2
+
+**Output:** 20
+
+**Explanation:**
+
+The 1st bus departs with the 4th passenger.
+
+The 2nd bus departs with the 6th and 2nd passengers.
+
+The 3rd bus departs with the 1st passenger and you. 
+
+**Constraints:**
+
+*   `n == buses.length`
+*   `m == passengers.length`
+*   1 <= n, m, capacity <= 105
+*   2 <= buses[i], passengers[i] <= 109
+*   Each element in `buses` is **unique**.
+*   Each element in `passengers` is **unique**.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun latestTimeCatchTheBus(buses: IntArray, passengers: IntArray, capacity: Int): Int {
+        // sort arrays and move in arrays from left to right and find capacity in last bus
+        // if capcity is full in last bus then find time last passenger might have boarded then go
+        // backward till find a slot to replace last passenger
+        // if capacity is not full in last bus then start with last bus departure time and check if
+        // can board on last moment and go backward till find a available time slot
+        buses.sort()
+        passengers.sort()
+        val blen = buses.size
+        val plen = passengers.size
+        var b = 0
+        var p = 0
+        var c = 0
+        // find capacity in last bus
+        while (b < blen && p < plen) {
+            if (passengers[p] <= buses[b] && c < capacity) {
+                c++
+                p++
+            }
+            if (c == capacity || p < plen && passengers[p] > buses[b]) {
+                if (b < blen - 1) {
+                    c = 0
+                }
+                b++
+            }
+        }
+        var start: Int = if (c == capacity) {
+            // capcity is full in last bus, find time last passenger might have boarded
+            passengers[p - 1].coerceAtMost(buses[blen - 1])
+        } else {
+            // capacity is not full in last bus, start with last bus departure time and check if can
+            // board on last moment
+            buses[blen - 1]
+        }
+        // go backward till find a slot
+        while (p > 0 && start == passengers[p - 1]) {
+            start--
+            p--
+        }
+        return start
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2333_minimum_sum_of_squared_difference/readme.md b/src/main/kotlin/g2301_2400/s2333_minimum_sum_of_squared_difference/readme.md
new file mode 100644
index 00000000..b37ec930
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2333_minimum_sum_of_squared_difference/readme.md
@@ -0,0 +1,110 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2333\. Minimum Sum of Squared Difference
+
+Medium
+
+You are given two positive **0-indexed** integer arrays `nums1` and `nums2`, both of length `n`.
+
+The **sum of squared difference** of arrays `nums1` and `nums2` is defined as the **sum** of (nums1[i] - nums2[i])2 for each `0 <= i < n`.
+
+You are also given two positive integers `k1` and `k2`. You can modify any of the elements of `nums1` by `+1` or `-1` at most `k1` times. Similarly, you can modify any of the elements of `nums2` by `+1` or `-1` at most `k2` times.
+
+Return _the minimum **sum of squared difference** after modifying array_ `nums1` _at most_ `k1` _times and modifying array_ `nums2` _at most_ `k2` _times_.
+
+**Note**: You are allowed to modify the array elements to become **negative** integers.
+
+**Example 1:**
+
+**Input:** nums1 = [1,2,3,4], nums2 = [2,10,20,19], k1 = 0, k2 = 0
+
+**Output:** 579
+
+**Explanation:** The elements in nums1 and nums2 cannot be modified because k1 = 0 and k2 = 0.
+
+The sum of square difference will be: (1 - 2)2 \+ (2 - 10)2 \+ (3 - 20)2 \+ (4 - 19)2 = 579. 
+
+**Example 2:**
+
+**Input:** nums1 = [1,4,10,12], nums2 = [5,8,6,9], k1 = 1, k2 = 1
+
+**Output:** 43
+
+**Explanation:** One way to obtain the minimum sum of square difference is:
+
+- Increase nums1[0] once.
+
+- Increase nums2[2] once.
+
+The minimum of the sum of square difference will be: (2 - 5)2 \+ (4 - 8)2 \+ (10 - 7)2 \+ (12 - 9)2 = 43.
+
+Note that, there are other ways to obtain the minimum of the sum of square difference, but there is no way to obtain a sum smaller than 43.
+
+**Constraints:**
+
+*   `n == nums1.length == nums2.length`
+*   1 <= n <= 105
+*   0 <= nums1[i], nums2[i] <= 105
+*   0 <= k1, k2 <= 109
+
+## Solution
+
+```kotlin
+import kotlin.math.abs
+import kotlin.math.pow
+
+class Solution {
+    fun minSumSquareDiff(nums1: IntArray, nums2: IntArray, k1: Int, k2: Int): Long {
+        var minSumSquare: Long = 0
+        val diffs = IntArray(100001)
+        var totalDiff: Long = 0
+        var kSum = k1.toLong() + k2
+        var currentDiff: Int
+        var maxDiff = 0
+        for (i in nums1.indices) {
+            // get current diff.
+            currentDiff = abs(nums1[i] - nums2[i])
+            // if current diff > 0, count/store it. If not,then ignore it.
+            if (currentDiff > 0) {
+                totalDiff += currentDiff.toLong()
+                diffs[currentDiff]++
+                maxDiff = maxDiff.coerceAtLeast(currentDiff)
+            }
+        }
+        // if kSum (k1 + k2) < totalDifferences, it means we can make all numbers/differences 0s
+        if (totalDiff <= kSum) {
+            return 0
+        }
+        // starting from the back, from the highest difference, lower that group one by one to the
+        // previous group.
+        // we need to make all n diffs to n-1, then n-2, as long as kSum allows it.
+        run {
+            var i = maxDiff
+            while (i > 0 && kSum > 0) {
+                if (diffs[i] > 0) {
+                    // if current group has more differences than the totalK, we can only move k of them
+                    // to the lower level.
+                    if (diffs[i] >= kSum) {
+                        diffs[i] -= kSum.toInt()
+                        diffs[i - 1] += kSum.toInt()
+                        kSum = 0
+                    } else {
+                        // else, we can make this whole group one level lower.
+                        diffs[i - 1] += diffs[i]
+                        kSum -= diffs[i].toLong()
+                        diffs[i] = 0
+                    }
+                }
+                i--
+            }
+        }
+        for (i in 0..maxDiff) {
+            if (diffs[i] > 0) {
+                minSumSquare += i.toDouble().pow(2.0).toLong() * diffs[i]
+            }
+        }
+        return minSumSquare
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2334_subarray_with_elements_greater_than_varying_threshold/readme.md b/src/main/kotlin/g2301_2400/s2334_subarray_with_elements_greater_than_varying_threshold/readme.md
new file mode 100644
index 00000000..e3f894e5
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2334_subarray_with_elements_greater_than_varying_threshold/readme.md
@@ -0,0 +1,80 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2334\. Subarray With Elements Greater Than Varying Threshold
+
+Hard
+
+You are given an integer array `nums` and an integer `threshold`.
+
+Find any subarray of `nums` of length `k` such that **every** element in the subarray is **greater** than `threshold / k`.
+
+Return _the **size** of **any** such subarray_. If there is no such subarray, return `-1`.
+
+A **subarray** is a contiguous non-empty sequence of elements within an array.
+
+**Example 1:**
+
+**Input:** nums = [1,3,4,3,1], threshold = 6
+
+**Output:** 3
+
+**Explanation:** The subarray [3,4,3] has a size of 3, and every element is greater than 6 / 3 = 2.
+
+Note that this is the only valid subarray. 
+
+**Example 2:**
+
+**Input:** nums = [6,5,6,5,8], threshold = 7
+
+**Output:** 1
+
+**Explanation:** The subarray [8] has a size of 1, and 8 > 7 / 1 = 7. So 1 is returned.
+
+Note that the subarray [6,5] has a size of 2, and every element is greater than 7 / 2 = 3.5.
+
+Similarly, the subarrays [6,5,6], [6,5,6,5], [6,5,6,5,8] also satisfy the given conditions.
+
+Therefore, 2, 3, 4, or 5 may also be returned.
+
+**Constraints:**
+
+*   1 <= nums.length <= 105
+*   1 <= nums[i], threshold <= 109
+
+## Solution
+
+```kotlin
+import java.util.PriorityQueue
+import java.util.TreeSet
+
+class Solution {
+    fun validSubarraySize(nums: IntArray, threshold: Int): Int {
+        val n = nums.size
+        val min = IntArray(n)
+        // base case
+        val dead = TreeSet(listOf(n, -1))
+        val maxheap = PriorityQueue(compareBy { o: Int -> -min[o] })
+        for (i in 0 until n) {
+            min[i] = threshold / nums[i] + 1
+            if (min[i] > nums.size) {
+                // dead, this element should never appear in the answer
+                dead.add(i)
+            } else {
+                maxheap.offer(i)
+            }
+        }
+        while (maxheap.isNotEmpty()) {
+            val cur = maxheap.poll()
+            if (dead.higher(cur)!! - dead.lower(cur)!! - 1 < min[cur]) {
+                // widest open range < minimum required length, this index is also bad.
+                dead.add(cur)
+            } else {
+                // otherwise we've found it!
+                return min[cur]
+            }
+        }
+        return -1
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2335_minimum_amount_of_time_to_fill_cups/readme.md b/src/main/kotlin/g2301_2400/s2335_minimum_amount_of_time_to_fill_cups/readme.md
new file mode 100644
index 00000000..94e872d6
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2335_minimum_amount_of_time_to_fill_cups/readme.md
@@ -0,0 +1,75 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2335\. Minimum Amount of Time to Fill Cups
+
+Easy
+
+You have a water dispenser that can dispense cold, warm, and hot water. Every second, you can either fill up `2` cups with **different** types of water, or `1` cup of any type of water.
+
+You are given a **0-indexed** integer array `amount` of length `3` where `amount[0]`, `amount[1]`, and `amount[2]` denote the number of cold, warm, and hot water cups you need to fill respectively. Return _the **minimum** number of seconds needed to fill up all the cups_.
+
+**Example 1:**
+
+**Input:** amount = [1,4,2]
+
+**Output:** 4
+
+**Explanation:** One way to fill up the cups is:
+
+Second 1: Fill up a cold cup and a warm cup.
+
+Second 2: Fill up a warm cup and a hot cup.
+
+Second 3: Fill up a warm cup and a hot cup.
+
+Second 4: Fill up a warm cup.
+
+It can be proven that 4 is the minimum number of seconds needed.
+
+**Example 2:**
+
+**Input:** amount = [5,4,4]
+
+**Output:** 7
+
+**Explanation:** One way to fill up the cups is:
+
+Second 1: Fill up a cold cup, and a hot cup.
+
+Second 2: Fill up a cold cup, and a warm cup.
+
+Second 3: Fill up a cold cup, and a warm cup.
+
+Second 4: Fill up a warm cup, and a hot cup.
+
+Second 5: Fill up a cold cup, and a hot cup.
+
+Second 6: Fill up a cold cup, and a warm cup.
+
+Second 7: Fill up a hot cup.
+
+**Example 3:**
+
+**Input:** amount = [5,0,0]
+
+**Output:** 5
+
+**Explanation:** Every second, we fill up a cold cup.
+
+**Constraints:**
+
+*   `amount.length == 3`
+*   `0 <= amount[i] <= 100`
+
+## Solution
+
+```kotlin
+class Solution {
+    fun fillCups(amount: IntArray): Int {
+        amount.sort()
+        val sum = amount[0] + amount[1] + amount[2]
+        return if (amount[0] + amount[1] < amount[2]) amount[2] else (sum + 1) / 2
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2336_smallest_number_in_infinite_set/readme.md b/src/main/kotlin/g2301_2400/s2336_smallest_number_in_infinite_set/readme.md
new file mode 100644
index 00000000..b3909e88
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2336_smallest_number_in_infinite_set/readme.md
@@ -0,0 +1,80 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2336\. Smallest Number in Infinite Set
+
+Medium
+
+You have a set which contains all positive integers `[1, 2, 3, 4, 5, ...]`.
+
+Implement the `SmallestInfiniteSet` class:
+
+*   `SmallestInfiniteSet()` Initializes the **SmallestInfiniteSet** object to contain **all** positive integers.
+*   `int popSmallest()` **Removes** and returns the smallest integer contained in the infinite set.
+*   `void addBack(int num)` **Adds** a positive integer `num` back into the infinite set, if it is **not** already in the infinite set.
+
+**Example 1:**
+
+**Input**
+
+["SmallestInfiniteSet", "addBack", "popSmallest", "popSmallest", "popSmallest", "addBack", "popSmallest", "popSmallest", "popSmallest"]
+
+[[], [2], [], [], [], [1], [], [], []]
+
+**Output:**
+
+[null, null, 1, 2, 3, null, 1, 4, 5]
+
+**Explanation:**
+
+    SmallestInfiniteSet smallestInfiniteSet = new SmallestInfiniteSet();
+    smallestInfiniteSet.addBack(2); // 2 is already in the set, so no change is made.
+    smallestInfiniteSet.popSmallest(); // return 1, since 1 is the smallest number, and remove it from the set.
+    smallestInfiniteSet.popSmallest(); // return 2, and remove it from the set.
+    smallestInfiniteSet.popSmallest(); // return 3, and remove it from the set.
+    smallestInfiniteSet.addBack(1); // 1 is added back to the set.
+    smallestInfiniteSet.popSmallest(); // return 1, since 1 was added back to the set and
+                                       // is the smallest number, and remove it from the set.
+    smallestInfiniteSet.popSmallest(); // return 4, and remove it from the set.
+    smallestInfiniteSet.popSmallest(); // return 5, and remove it from the set. 
+
+**Constraints:**
+
+*   `1 <= num <= 1000`
+*   At most `1000` calls will be made **in total** to `popSmallest` and `addBack`.
+
+## Solution
+
+```kotlin
+class SmallestInfiniteSet {
+    private val set = IntArray(1001)
+    private var ptr = 1
+
+    init {
+        for (i in 1..1000) {
+            set[i] = 1
+        }
+    }
+
+    fun popSmallest(): Int {
+        var `val` = -1
+        if (ptr in 1..1000) {
+            set[ptr] = 0
+            `val` = ptr++
+            while (ptr <= 1000 && set[ptr] == 0) {
+                ptr++
+            }
+        }
+        return `val`
+    }
+
+    fun addBack(num: Int) {
+        if (set[num] == 0) {
+            set[num] = 1
+            if (num < ptr) {
+                ptr = num
+            }
+        }
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2337_move_pieces_to_obtain_a_string/readme.md b/src/main/kotlin/g2301_2400/s2337_move_pieces_to_obtain_a_string/readme.md
new file mode 100644
index 00000000..4d0704a7
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2337_move_pieces_to_obtain_a_string/readme.md
@@ -0,0 +1,85 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2337\. Move Pieces to Obtain a String
+
+Medium
+
+You are given two strings `start` and `target`, both of length `n`. Each string consists **only** of the characters `'L'`, `'R'`, and `'_'` where:
+
+*   The characters `'L'` and `'R'` represent pieces, where a piece `'L'` can move to the **left** only if there is a **blank** space directly to its left, and a piece `'R'` can move to the **right** only if there is a **blank** space directly to its right.
+*   The character `'_'` represents a blank space that can be occupied by **any** of the `'L'` or `'R'` pieces.
+
+Return `true` _if it is possible to obtain the string_ `target` _by moving the pieces of the string_ `start` _**any** number of times_. Otherwise, return `false`.
+
+**Example 1:**
+
+**Input:** start = "\_L\_\_R\_\_R\_", target = "L\_\_\_\_\_\_RR"
+
+**Output:** true
+
+**Explanation:** We can obtain the string target from start by doing the following moves:
+
+- Move the first piece one step to the left, start becomes equal to "**L**\_\_\_R\_\_R\_".
+
+- Move the last piece one step to the right, start becomes equal to "L\_\_\_R\_\_\_**R**".
+
+- Move the second piece three steps to the right, start becomes equal to "L\_\_\_\_\_\_**R**R".
+
+Since it is possible to get the string target from start, we return true. 
+
+**Example 2:**
+
+**Input:** start = "R\_L\_", target = "\_\_LR"
+
+**Output:** false
+
+**Explanation:** The 'R' piece in the string start can move one step to the right to obtain "\_**R**L\_".
+
+After that, no pieces can move anymore, so it is impossible to obtain the string target from start. 
+
+**Example 3:**
+
+**Input:** start = "\_R", target = "R\_"
+
+**Output:** false
+
+**Explanation:** The piece in the string start can move only to the right, so it is impossible to obtain the string target from start.
+
+**Constraints:**
+
+*   `n == start.length == target.length`
+*   1 <= n <= 105
+*   `start` and `target` consist of the characters `'L'`, `'R'`, and `'_'`.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun canChange(start: String, target: String): Boolean {
+        var i = -1
+        var j = -1
+        while (true) {
+            while (true) {
+                if (++i >= start.length || start[i] != '_') {
+                    break
+                }
+            }
+            while (true) {
+                if (++j >= target.length || target[j] != '_') {
+                    break
+                }
+            }
+            if (i == start.length && j == target.length) {
+                return true
+            }
+            if (i == start.length || j == target.length) {
+                return false
+            }
+            if (start[i] != target[j] || (if (start[i] == 'L') j > i else i > j)) {
+                return false
+            }
+        }
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2338_count_the_number_of_ideal_arrays/readme.md b/src/main/kotlin/g2301_2400/s2338_count_the_number_of_ideal_arrays/readme.md
new file mode 100644
index 00000000..99abb859
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2338_count_the_number_of_ideal_arrays/readme.md
@@ -0,0 +1,108 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2338\. Count the Number of Ideal Arrays
+
+Hard
+
+You are given two integers `n` and `maxValue`, which are used to describe an **ideal** array.
+
+A **0-indexed** integer array `arr` of length `n` is considered **ideal** if the following conditions hold:
+
+*   Every `arr[i]` is a value from `1` to `maxValue`, for `0 <= i < n`.
+*   Every `arr[i]` is divisible by `arr[i - 1]`, for `0 < i < n`.
+
+Return _the number of **distinct** ideal arrays of length_ `n`. Since the answer may be very large, return it modulo 109 + 7.
+
+**Example 1:**
+
+**Input:** n = 2, maxValue = 5
+
+**Output:** 10
+
+**Explanation:** The following are the possible ideal arrays:
+
+- Arrays starting with the value 1 (5 arrays): [1,1], [1,2], [1,3], [1,4], [1,5]
+
+- Arrays starting with the value 2 (2 arrays): [2,2], [2,4]
+
+- Arrays starting with the value 3 (1 array): [3,3]
+
+- Arrays starting with the value 4 (1 array): [4,4]
+
+- Arrays starting with the value 5 (1 array): [5,5]
+
+There are a total of 5 + 2 + 1 + 1 + 1 = 10 distinct ideal arrays. 
+
+**Example 2:**
+
+**Input:** n = 5, maxValue = 3
+
+**Output:** 11
+
+**Explanation:** The following are the possible ideal arrays:
+
+- Arrays starting with the value 1 (9 arrays):
+
+   - With no other distinct values (1 array): [1,1,1,1,1]
+
+   - With 2nd distinct value 2 (4 arrays): [1,1,1,1,2], [1,1,1,2,2], [1,1,2,2,2], [1,2,2,2,2]
+   
+   - With 2nd distinct value 3 (4 arrays): [1,1,1,1,3], [1,1,1,3,3], [1,1,3,3,3], [1,3,3,3,3]
+   
+- Arrays starting with the value 2 (1 array): [2,2,2,2,2]
+
+- Arrays starting with the value 3 (1 array): [3,3,3,3,3]
+
+There are a total of 9 + 1 + 1 = 11 distinct ideal arrays. 
+
+**Constraints:**
+
+*   2 <= n <= 104
+*   1 <= maxValue <= 104
+
+## Solution
+
+```kotlin
+import kotlin.math.ln
+
+class Solution {
+    fun idealArrays(n: Int, maxValue: Int): Int {
+        val mod = (1e9 + 7).toInt()
+        val maxDistinct = (ln(maxValue.toDouble()) / ln(2.0)).toInt() + 1
+        val dp = Array(maxDistinct + 1) { IntArray(maxValue + 1) }
+        dp[1].fill(1)
+        dp[1][0] = 0
+        for (i in 2..maxDistinct) {
+            for (j in 1..maxValue) {
+                var k = 2
+                while (j * k <= maxValue && dp[i - 1][j * k] != 0) {
+                    dp[i][j] += dp[i - 1][j * k]
+                    k++
+                }
+            }
+        }
+        val sum = IntArray(maxDistinct + 1)
+        for (i in 1..maxDistinct) {
+            sum[i] = dp[i].sum()
+        }
+        val invs = LongArray(n.coerceAtMost(maxDistinct) + 1)
+        invs[1] = 1
+        for (i in 2 until invs.size) {
+            invs[i] = mod - mod / i * invs[mod % i] % mod
+        }
+        var result = maxValue.toLong()
+        var comb = n.toLong() - 1
+        var i = 2
+        while (i <= maxDistinct && i <= n) {
+            result += sum[i] * comb % mod
+            comb *= (n - i).toLong()
+            comb %= mod.toLong()
+            comb *= invs[i]
+            comb %= mod.toLong()
+            i++
+        }
+        return (result % mod).toInt()
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2341_maximum_number_of_pairs_in_array/readme.md b/src/main/kotlin/g2301_2400/s2341_maximum_number_of_pairs_in_array/readme.md
new file mode 100644
index 00000000..f93166db
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2341_maximum_number_of_pairs_in_array/readme.md
@@ -0,0 +1,73 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2341\. Maximum Number of Pairs in Array
+
+Easy
+
+You are given a **0-indexed** integer array `nums`. In one operation, you may do the following:
+
+*   Choose **two** integers in `nums` that are **equal**.
+*   Remove both integers from `nums`, forming a **pair**.
+
+The operation is done on `nums` as many times as possible.
+
+Return _a **0-indexed** integer array_ `answer` _of size_ `2` _where_ `answer[0]` _is the number of pairs that are formed and_ `answer[1]` _is the number of leftover integers in_ `nums` _after doing the operation as many times as possible_.
+
+**Example 1:**
+
+**Input:** nums = [1,3,2,1,3,2,2]
+
+**Output:** [3,1]
+
+**Explanation:**
+
+Form a pair with nums[0] and nums[3] and remove them from nums. Now, nums = [3,2,3,2,2].
+
+Form a pair with nums[0] and nums[2] and remove them from nums. Now, nums = [2,2,2].
+
+Form a pair with nums[0] and nums[1] and remove them from nums. Now, nums = [2].
+
+No more pairs can be formed. A total of 3 pairs have been formed, and there is 1 number leftover in nums.
+
+**Example 2:**
+
+**Input:** nums = [1,1]
+
+**Output:** [1,0]
+
+**Explanation:** Form a pair with nums[0] and nums[1] and remove them from nums. Now, nums = [].
+
+No more pairs can be formed. A total of 1 pair has been formed, and there are 0 numbers leftover in nums.
+
+**Example 3:**
+
+**Input:** nums = [0]
+
+**Output:** [0,1]
+
+**Explanation:** No pairs can be formed, and there is 1 number leftover in nums. 
+
+**Constraints:**
+
+*   `1 <= nums.length <= 100`
+*   `0 <= nums[i] <= 100`
+
+## Solution
+
+```kotlin
+class Solution {
+    fun numberOfPairs(nums: IntArray): IntArray {
+        nums.sort()
+        var pairs = 0
+        for (i in nums.indices) {
+            if (i > 0 && nums[i] == nums[i - 1]) {
+                nums[i] = -1
+                nums[i - 1] = -1
+                pairs++
+            }
+        }
+        return intArrayOf(pairs, nums.size - 2 * pairs)
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2342_max_sum_of_a_pair_with_equal_sum_of_digits/readme.md b/src/main/kotlin/g2301_2400/s2342_max_sum_of_a_pair_with_equal_sum_of_digits/readme.md
new file mode 100644
index 00000000..a4e4f96d
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2342_max_sum_of_a_pair_with_equal_sum_of_digits/readme.md
@@ -0,0 +1,61 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2342\. Max Sum of a Pair With Equal Sum of Digits
+
+Medium
+
+You are given a **0-indexed** array `nums` consisting of **positive** integers. You can choose two indices `i` and `j`, such that `i != j`, and the sum of digits of the number `nums[i]` is equal to that of `nums[j]`.
+
+Return _the **maximum** value of_ `nums[i] + nums[j]` _that you can obtain over all possible indices_ `i` _and_ `j` _that satisfy the conditions._
+
+**Example 1:**
+
+**Input:** nums = [18,43,36,13,7]
+
+**Output:** 54
+
+**Explanation:** The pairs (i, j) that satisfy the conditions are:
+
+- (0, 2), both numbers have a sum of digits equal to 9, and their sum is 18 + 36 = 54.
+
+- (1, 4), both numbers have a sum of digits equal to 7, and their sum is 43 + 7 = 50.
+
+So the maximum sum that we can obtain is 54. 
+
+**Example 2:**
+
+**Input:** nums = [10,12,19,14]
+
+**Output:** -1
+
+**Explanation:** There are no two numbers that satisfy the conditions, so we return -1. 
+
+**Constraints:**
+
+*   1 <= nums.length <= 105
+*   1 <= nums[i] <= 109
+
+## Solution
+
+```kotlin
+class Solution {
+    fun maximumSum(nums: IntArray): Int {
+        val map: MutableMap = HashMap()
+        var res = -1
+        for (num in nums) {
+            var s = 0
+            for (digit in num.toString().toCharArray()) {
+                s += Integer.valueOf(digit.code - '0'.code)
+            }
+            if (!map.containsKey(s)) {
+                map[s] = num
+            } else {
+                res = Math.max(res, map[s]!! + num)
+                map[s] = Math.max(map[s]!!, num)
+            }
+        }
+        return res
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2343_query_kth_smallest_trimmed_number/readme.md b/src/main/kotlin/g2301_2400/s2343_query_kth_smallest_trimmed_number/readme.md
new file mode 100644
index 00000000..b398cb71
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2343_query_kth_smallest_trimmed_number/readme.md
@@ -0,0 +1,125 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2343\. Query Kth Smallest Trimmed Number
+
+Medium
+
+You are given a **0-indexed** array of strings `nums`, where each string is of **equal length** and consists of only digits.
+
+You are also given a **0-indexed** 2D integer array `queries` where queries[i] = [ki, trimi]. For each `queries[i]`, you need to:
+
+*   **Trim** each number in `nums` to its **rightmost** trimi digits.
+*   Determine the **index** of the kith smallest trimmed number in `nums`. If two trimmed numbers are equal, the number with the **lower** index is considered to be smaller.
+*   Reset each number in `nums` to its original length.
+
+Return _an array_ `answer` _of the same length as_ `queries`, _where_ `answer[i]` _is the answer to the_ ith _query._
+
+**Note**:
+
+*   To trim to the rightmost `x` digits means to keep removing the leftmost digit, until only `x` digits remain.
+*   Strings in `nums` may contain leading zeros.
+
+**Example 1:**
+
+**Input:** nums = ["102","473","251","814"], queries = \[\[1,1],[2,3],[4,2],[1,2]]
+
+**Output:** [2,2,1,0]
+
+**Explanation:**
+
+1. After trimming to the last digit, nums = ["2","3","1","4"]. The smallest number is 1 at index 2.
+
+2. Trimmed to the last 3 digits, nums is unchanged. The 2nd smallest number is 251 at index 2.
+
+3. Trimmed to the last 2 digits, nums = ["02","73","51","14"]. The 4th smallest number is 73.
+
+4. Trimmed to the last 2 digits, the smallest number is 2 at index 0.
+
+   Note that the trimmed number "02" is evaluated as 2. 
+
+**Example 2:**
+
+**Input:** nums = ["24","37","96","04"], queries = \[\[2,1],[2,2]]
+
+**Output:** [3,0]
+
+**Explanation:**
+
+1. Trimmed to the last digit, nums = ["4","7","6","4"]. The 2nd smallest number is 4 at index 3.
+
+   There are two occurrences of 4, but the one at index 0 is considered smaller than the one at index 3.
+   
+2. Trimmed to the last 2 digits, nums is unchanged. The 2nd smallest number is 24. 
+
+**Constraints:**
+
+*   `1 <= nums.length <= 100`
+*   `1 <= nums[i].length <= 100`
+*   `nums[i]` consists of only digits.
+*   All `nums[i].length` are **equal**.
+*   `1 <= queries.length <= 100`
+*   `queries[i].length == 2`
+*   1 <= ki <= nums.length
+*   1 <= trimi <= nums[i].length
+
+**Follow up:** Could you use the **Radix Sort Algorithm** to solve this problem? What will be the complexity of that solution?
+
+## Solution
+
+```kotlin
+class Solution {
+    fun smallestTrimmedNumbers(nums: Array, queries: Array): IntArray {
+        val numberOfDigits = nums[0].length
+        var placeValue = numberOfDigits
+        val list: MutableList = ArrayList(numberOfDigits)
+        while (--placeValue >= 0) {
+            countSort(nums, placeValue, numberOfDigits, list)
+        }
+        val op = IntArray(queries.size)
+        var i = 0
+        for (query in queries) {
+            val listIndex = query[1] - 1
+            val place = query[0] - 1
+            op[i++] = list[listIndex][place]
+        }
+        return op
+    }
+
+    private fun countSort(arr: Array, exp: Int, numberOfDigits: Int, list: MutableList) {
+        val n = arr.size
+        val output = arrayOfNulls(n)
+        val count = IntArray(10)
+        count.fill(0)
+        // Store count of occurrences in count[]
+        var i = 0
+        while (i < n) {
+            val digit = arr[i][exp].code - '0'.code
+            count[digit]++
+            i++
+        }
+        i = 1
+        while (i < 10) {
+            count[i] += count[i - 1]
+            i++
+        }
+        // Build the output array
+        val op = IntArray(n)
+        i = n - 1
+        while (i >= 0) {
+            val digit = arr[i][exp].code - '0'.code
+            val place = count[digit] - 1
+            output[place] = arr[i]
+            if (exp == numberOfDigits - 1) {
+                op[place] = i
+            } else {
+                op[place] = list[list.size - 1][i]
+            }
+            count[digit]--
+            i--
+        }
+        list.add(op)
+        System.arraycopy(output, 0, arr, 0, n)
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2344_minimum_deletions_to_make_array_divisible/readme.md b/src/main/kotlin/g2301_2400/s2344_minimum_deletions_to_make_array_divisible/readme.md
new file mode 100644
index 00000000..c03b2f1d
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2344_minimum_deletions_to_make_array_divisible/readme.md
@@ -0,0 +1,83 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2344\. Minimum Deletions to Make Array Divisible
+
+Hard
+
+You are given two positive integer arrays `nums` and `numsDivide`. You can delete any number of elements from `nums`.
+
+Return _the **minimum** number of deletions such that the **smallest** element in_ `nums` _**divides** all the elements of_ `numsDivide`. If this is not possible, return `-1`.
+
+Note that an integer `x` divides `y` if `y % x == 0`.
+
+**Example 1:**
+
+**Input:** nums = [2,3,2,4,3], numsDivide = [9,6,9,3,15]
+
+**Output:** 2
+
+**Explanation:**
+
+The smallest element in [2,3,2,4,3] is 2, which does not divide all the elements of numsDivide.
+
+We use 2 deletions to delete the elements in nums that are equal to 2 which makes nums = [3,4,3].
+
+The smallest element in [3,4,3] is 3, which divides all the elements of numsDivide.
+
+It can be shown that 2 is the minimum number of deletions needed. 
+
+**Example 2:**
+
+**Input:** nums = [4,3,6], numsDivide = [8,2,6,10]
+
+**Output:** -1
+
+**Explanation:**
+
+We want the smallest element in nums to divide all the elements of numsDivide.
+
+There is no way to delete elements from nums to allow this.
+
+**Constraints:**
+
+*   1 <= nums.length, numsDivide.length <= 105
+*   1 <= nums[i], numsDivide[i] <= 109
+
+## Solution
+
+```kotlin
+@Suppress("NAME_SHADOWING")
+class Solution {
+    fun minOperations(nums: IntArray, numsDivide: IntArray): Int {
+        var g = numsDivide[0]
+        for (i in numsDivide) {
+            g = gcd(g, i)
+        }
+        var minOp = 0
+        var smallest = Int.MAX_VALUE
+        for (num in nums) {
+            if (g % num == 0) {
+                smallest = Math.min(smallest, num)
+            }
+        }
+        for (num in nums) {
+            if (num < smallest) {
+                ++minOp
+            }
+        }
+        return if (smallest == Int.MAX_VALUE) -1 else minOp
+    }
+
+    private fun gcd(a: Int, b: Int): Int {
+        var a = a
+        var b = b
+        while (b > 0) {
+            val tmp = a
+            a = b
+            b = tmp % b
+        }
+        return a
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2347_best_poker_hand/readme.md b/src/main/kotlin/g2301_2400/s2347_best_poker_hand/readme.md
new file mode 100644
index 00000000..bc62049e
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2347_best_poker_hand/readme.md
@@ -0,0 +1,92 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2347\. Best Poker Hand
+
+Easy
+
+You are given an integer array `ranks` and a character array `suits`. You have `5` cards where the ith card has a rank of `ranks[i]` and a suit of `suits[i]`.
+
+The following are the types of **poker hands** you can make from best to worst:
+
+1.  `"Flush"`: Five cards of the same suit.
+2.  `"Three of a Kind"`: Three cards of the same rank.
+3.  `"Pair"`: Two cards of the same rank.
+4.  `"High Card"`: Any single card.
+
+Return _a string representing the **best** type of **poker hand** you can make with the given cards._
+
+**Note** that the return values are **case-sensitive**.
+
+**Example 1:**
+
+**Input:** ranks = [13,2,3,1,9], suits = ["a","a","a","a","a"]
+
+**Output:** "Flush"
+
+**Explanation:** The hand with all the cards consists of 5 cards with the same suit, so we have a "Flush". 
+
+**Example 2:**
+
+**Input:** ranks = [4,4,2,4,4], suits = ["d","a","a","b","c"]
+
+**Output:** "Three of a Kind"
+
+**Explanation:** The hand with the first, second, and fourth card consists of 3 cards with the same rank, so we have a "Three of a Kind".
+
+Note that we could also make a "Pair" hand but "Three of a Kind" is a better hand.
+
+Also note that other cards could be used to make the "Three of a Kind" hand.
+
+**Example 3:**
+
+**Input:** ranks = [10,10,2,12,9], suits = ["a","b","c","a","d"]
+
+**Output:** "Pair"
+
+**Explanation:** The hand with the first and second card consists of 2 cards with the same rank, so we have a "Pair".
+
+Note that we cannot make a "Flush" or a "Three of a Kind". 
+
+**Constraints:**
+
+*   `ranks.length == suits.length == 5`
+*   `1 <= ranks[i] <= 13`
+*   `'a' <= suits[i] <= 'd'`
+*   No two cards have the same rank and suit.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun bestHand(ranks: IntArray, suits: CharArray): String {
+        val map = HashMap()
+        for (suit in suits) {
+            if (map.containsKey(suit)) {
+                map[suit] = map[suit]!! + 1
+                if (map[suit] == 5) {
+                    return "Flush"
+                }
+            } else {
+                map[suit] = 1
+            }
+        }
+        var s = ""
+        val map2 = HashMap()
+        for (rank in ranks) {
+            if (map2.containsKey(rank)) {
+                map2[rank] = map2[rank]!! + 1
+                if (map2[rank] == 2) {
+                    s = "Pair"
+                } else if (map2[rank] == 3) {
+                    s = "Three of a Kind"
+                    return s
+                }
+            } else {
+                map2[rank] = 1
+            }
+        }
+        return if (s.isEmpty()) "High Card" else s
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2348_number_of_zero_filled_subarrays/readme.md b/src/main/kotlin/g2301_2400/s2348_number_of_zero_filled_subarrays/readme.md
new file mode 100644
index 00000000..88452008
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2348_number_of_zero_filled_subarrays/readme.md
@@ -0,0 +1,72 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2348\. Number of Zero-Filled Subarrays
+
+Medium
+
+Given an integer array `nums`, return _the number of **subarrays** filled with_ `0`.
+
+A **subarray** is a contiguous non-empty sequence of elements within an array.
+
+**Example 1:**
+
+**Input:** nums = [1,3,0,0,2,0,0,4]
+
+**Output:** 6
+
+**Explanation:**
+
+There are 4 occurrences of [0] as a subarray.
+
+There are 2 occurrences of [0,0] as a subarray.
+
+There is no occurrence of a subarray with a size more than 2 filled with 0. Therefore, we return 6.
+
+**Example 2:**
+
+**Input:** nums = [0,0,0,2,0,0]
+
+**Output:** 9
+
+**Explanation:**
+
+There are 5 occurrences of [0] as a subarray.
+
+There are 3 occurrences of [0,0] as a subarray.
+
+There is 1 occurrence of [0,0,0] as a subarray.
+
+There is no occurrence of a subarray with a size more than 3 filled with 0. Therefore, we return 9. 
+
+**Example 3:**
+
+**Input:** nums = [2,10,2019]
+
+**Output:** 0
+
+**Explanation:** There is no subarray filled with 0. Therefore, we return 0. 
+
+**Constraints:**
+
+*   1 <= nums.length <= 105
+*   -109 <= nums[i] <= 109
+
+## Solution
+
+```kotlin
+class Solution {
+    fun zeroFilledSubarray(nums: IntArray): Long {
+        var cnt = 0L
+        var local = 0L
+        for (n in nums) {
+            if (n == 0) {
+                cnt += ++local
+            } else {
+                local = 0
+            }
+        }
+        return cnt
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2349_design_a_number_container_system/readme.md b/src/main/kotlin/g2301_2400/s2349_design_a_number_container_system/readme.md
new file mode 100644
index 00000000..42e1dbfa
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2349_design_a_number_container_system/readme.md
@@ -0,0 +1,78 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2349\. Design a Number Container System
+
+Medium
+
+Design a number container system that can do the following:
+
+*   **Insert** or **Replace** a number at the given index in the system.
+*   **Return** the smallest index for the given number in the system.
+
+Implement the `NumberContainers` class:
+
+*   `NumberContainers()` Initializes the number container system.
+*   `void change(int index, int number)` Fills the container at `index` with the `number`. If there is already a number at that `index`, replace it.
+*   `int find(int number)` Returns the smallest index for the given `number`, or `-1` if there is no index that is filled by `number` in the system.
+
+**Example 1:**
+
+**Input**
+
+["NumberContainers", "find", "change", "change", "change", "change", "find", "change", "find"]
+
+[[], [10], [2, 10], [1, 10], [3, 10], [5, 10], [10], [1, 20], [10]]
+
+**Output:** [null, -1, null, null, null, null, 1, null, 2]
+
+**Explanation:**
+
+    NumberContainers nc = new NumberContainers();
+    nc.find(10); // There is no index that is filled with number 10. Therefore, we return -1.
+    nc.change(2, 10); // Your container at index 2 will be filled with number 10.
+    nc.change(1, 10); // Your container at index 1 will be filled with number 10.
+    nc.change(3, 10); // Your container at index 3 will be filled with number 10.
+    nc.change(5, 10); // Your container at index 5 will be filled with number 10.
+    nc.find(10); // Number 10 is at the indices 1, 2, 3, and 5. Since the smallest index that is filled with 10 is 1, we return 1.
+    nc.change(1, 20); // Your container at index 1 will be filled with number 20. Note that index 1 was filled with 10 and then replaced with 20.
+    nc.find(10); // Number 10 is at the indices 2, 3, and 5. The smallest index that is filled with 10 is 2. Therefore, we return 2. 
+
+**Constraints:**
+
+*   1 <= index, number <= 109
+*   At most 105 calls will be made **in total** to `change` and `find`.
+
+## Solution
+
+```kotlin
+import java.util.TreeSet
+
+class NumberContainers {
+    private val indices: MutableMap> = HashMap()
+    private val vals: MutableMap = HashMap()
+    fun change(index: Int, number: Int) {
+        if (vals.containsKey(index)) {
+            val old = vals[index]!!
+            indices[old]!!.remove(index)
+            if (indices[old]!!.isEmpty()) {
+                indices.remove(old)
+            }
+        }
+        vals[index] = number
+        indices.computeIfAbsent(number) { _: Int? -> TreeSet() }.add(index)
+    }
+
+    fun find(number: Int): Int {
+        return if (indices.containsKey(number)) {
+            indices[number]!!.first()
+        } else -1
+    }
+}
+/*
+ * Your NumberContainers object will be instantiated and called as such:
+ * var obj = NumberContainers()
+ * obj.change(index,number)
+ * var param_2 = obj.find(number)
+ */
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2350_shortest_impossible_sequence_of_rolls/readme.md b/src/main/kotlin/g2301_2400/s2350_shortest_impossible_sequence_of_rolls/readme.md
new file mode 100644
index 00000000..f47b55ba
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2350_shortest_impossible_sequence_of_rolls/readme.md
@@ -0,0 +1,80 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2350\. Shortest Impossible Sequence of Rolls
+
+Hard
+
+You are given an integer array `rolls` of length `n` and an integer `k`. You roll a `k` sided dice numbered from `1` to `k`, `n` times, where the result of the ith roll is `rolls[i]`.
+
+Return _the length of the **shortest** sequence of rolls that **cannot** be taken from_ `rolls`.
+
+A **sequence of rolls** of length `len` is the result of rolling a `k` sided dice `len` times.
+
+**Note** that the sequence taken does not have to be consecutive as long as it is in order.
+
+**Example 1:**
+
+**Input:** rolls = [4,2,1,2,3,3,2,4,1], k = 4
+
+**Output:** 3
+
+**Explanation:** Every sequence of rolls of length 1, [1], [2], [3], [4], can be taken from rolls.
+
+Every sequence of rolls of length 2, [1, 1], [1, 2], ..., [4, 4], can be taken from rolls.
+
+The sequence [1, 4, 2] cannot be taken from rolls, so we return 3.
+
+Note that there are other sequences that cannot be taken from rolls.
+
+**Example 2:**
+
+**Input:** rolls = [1,1,2,2], k = 2
+
+**Output:** 2
+
+**Explanation:** Every sequence of rolls of length 1, [1], [2], can be taken from rolls.
+
+The sequence [2, 1] cannot be taken from rolls, so we return 2.
+
+Note that there are other sequences that cannot be taken from rolls but [2, 1] is the shortest. 
+
+**Example 3:**
+
+**Input:** rolls = [1,1,3,2,2,2,3,3], k = 4
+
+**Output:** 1
+
+**Explanation:** The sequence [4] cannot be taken from rolls, so we return 1. Note that there are other sequences that cannot be taken from rolls but [4] is the shortest. 
+
+**Constraints:**
+
+*   `n == rolls.length`
+*   1 <= n <= 105
+*   1 <= rolls[i] <= k <= 105
+
+## Solution
+
+```kotlin
+import java.util.BitSet
+
+class Solution {
+    fun shortestSequence(rolls: IntArray, k: Int): Int {
+        val bitSet = BitSet(k + 1)
+        var cnt = 0
+        var res = 1
+        for (roll in rolls) {
+            if (!bitSet[roll]) {
+                bitSet.set(roll)
+                cnt++
+            }
+            if (cnt == k) {
+                res++
+                cnt = 0
+                bitSet.clear()
+            }
+        }
+        return res
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2351_first_letter_to_appear_twice/readme.md b/src/main/kotlin/g2301_2400/s2351_first_letter_to_appear_twice/readme.md
new file mode 100644
index 00000000..00d8ee8c
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2351_first_letter_to_appear_twice/readme.md
@@ -0,0 +1,66 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2351\. First Letter to Appear Twice
+
+Easy
+
+Given a string `s` consisting of lowercase English letters, return _the first letter to appear **twice**_.
+
+**Note**:
+
+*   A letter `a` appears twice before another letter `b` if the **second** occurrence of `a` is before the **second** occurrence of `b`.
+*   `s` will contain at least one letter that appears twice.
+
+**Example 1:**
+
+**Input:** s = "abccbaacz"
+
+**Output:** "c"
+
+**Explanation:**
+
+The letter 'a' appears on the indexes 0, 5 and 6.
+
+The letter 'b' appears on the indexes 1 and 4.
+
+The letter 'c' appears on the indexes 2, 3 and 7.
+
+The letter 'z' appears on the index 8.
+
+The letter 'c' is the first letter to appear twice, because out of all the letters the index of its second occurrence is the smallest.
+
+**Example 2:**
+
+**Input:** s = "abcdd"
+
+**Output:** "d"
+
+**Explanation:**
+
+The only letter that appears twice is 'd' so we return 'd'. 
+
+**Constraints:**
+
+*   `2 <= s.length <= 100`
+*   `s` consists of lowercase English letters.
+*   `s` has at least one repeated letter.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun repeatedCharacter(s: String): Char {
+        val n = s.length
+        val hm = IntArray(26)
+        for (i in 0 until n) {
+            val c = s[i]
+            hm[c.code - 'a'.code]++
+            if (hm[c.code - 'a'.code] > 1) {
+                return c
+            }
+        }
+        return '0'
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2352_equal_row_and_column_pairs/readme.md b/src/main/kotlin/g2301_2400/s2352_equal_row_and_column_pairs/readme.md
new file mode 100644
index 00000000..c1ab78ab
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2352_equal_row_and_column_pairs/readme.md
@@ -0,0 +1,78 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2352\. Equal Row and Column Pairs
+
+Medium
+
+Given a **0-indexed** `n x n` integer matrix `grid`, _return the number of pairs_ (Ri, Cj) _such that row_ Ri _and column_ Cj _are equal_.
+
+A row and column pair is considered equal if they contain the same elements in the same order (i.e. an equal array).
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/06/01/ex1.jpg)
+
+**Input:** grid = \[\[3,2,1],[1,7,6],[2,7,7]]
+
+**Output:** 1
+
+**Explanation:** There is 1 equal row and column pair:
+
+- (Row 2, Column 1): [2,7,7] 
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2022/06/01/ex2.jpg)
+
+**Input:** grid = \[\[3,1,2,2],[1,4,4,5],[2,4,2,2],[2,4,2,2]]
+
+**Output:** 3
+
+**Explanation:** There are 3 equal row and column pairs:
+
+- (Row 0, Column 0): [3,1,2,2]
+
+- (Row 2, Column 2): [2,4,2,2]
+
+- (Row 3, Column 2): [2,4,2,2]
+
+**Constraints:**
+
+*   `n == grid.length == grid[i].length`
+*   `1 <= n <= 200`
+*   1 <= grid[i][j] <= 105
+
+## Solution
+
+```kotlin
+class Solution {
+    fun equalPairs(grid: Array): Int {
+        val rows: MutableMap = HashMap()
+        for (i in grid.indices) {
+            val hash = getRowHash(grid[i])
+            rows[hash] = rows.getOrDefault(hash, 0) + 1
+        }
+        var count = 0
+        for (i in grid.indices) {
+            val hash = getColHash(grid, i)
+            count += rows.getOrDefault(hash, 0)
+        }
+        return count
+    }
+
+    private fun getRowHash(grid: IntArray): Int {
+        var res = 11
+        for (i in grid) res = res * 11 + i
+        return res
+    }
+
+    private fun getColHash(grid: Array, index: Int): Int {
+        var res = 11
+        for (i in grid.indices) {
+            res = res * 11 + grid[i][index]
+        }
+        return res
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2353_design_a_food_rating_system/readme.md b/src/main/kotlin/g2301_2400/s2353_design_a_food_rating_system/readme.md
new file mode 100644
index 00000000..49295fe0
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2353_design_a_food_rating_system/readme.md
@@ -0,0 +1,114 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2353\. Design a Food Rating System
+
+Medium
+
+Design a food rating system that can do the following:
+
+*   **Modify** the rating of a food item listed in the system.
+*   Return the highest-rated food item for a type of cuisine in the system.
+
+Implement the `FoodRatings` class:
+
+*   `FoodRatings(String[] foods, String[] cuisines, int[] ratings)` Initializes the system. The food items are described by `foods`, `cuisines` and `ratings`, all of which have a length of `n`.
+    *   `foods[i]` is the name of the ith food,
+    *   `cuisines[i]` is the type of cuisine of the ith food, and
+    *   `ratings[i]` is the initial rating of the ith food.
+*   `void changeRating(String food, int newRating)` Changes the rating of the food item with the name `food`.
+*   `String highestRated(String cuisine)` Returns the name of the food item that has the highest rating for the given type of `cuisine`. If there is a tie, return the item with the **lexicographically smaller** name.
+
+Note that a string `x` is lexicographically smaller than string `y` if `x` comes before `y` in dictionary order, that is, either `x` is a prefix of `y`, or if `i` is the first position such that `x[i] != y[i]`, then `x[i]` comes before `y[i]` in alphabetic order.
+
+**Example 1:**
+
+**Input**
+
+["FoodRatings", "highestRated", "highestRated", "changeRating", "highestRated", "changeRating", "highestRated"]
+
+[[["kimchi", "miso", "sushi", "moussaka", "ramen", "bulgogi"], ["korean", "japanese", "japanese", "greek", "japanese", "korean"], [9, 12, 8, 15, 14, 7]], ["korean"], ["japanese"], ["sushi", 16], ["japanese"], ["ramen", 16], ["japanese"]]
+
+**Output:**
+
+[null, "kimchi", "ramen", null, "sushi", null, "ramen"]
+
+**Explanation:**
+
+    FoodRatings foodRatings = new FoodRatings(["kimchi", "miso", "sushi", "moussaka", "ramen", "bulgogi"], ["korean", "japanese", "japanese", "greek", "japanese", "korean"], [9, 12, 8, 15, 14, 7]);
+    foodRatings.highestRated("korean"); // return "kimchi"
+                                        // "kimchi" is the highest rated korean food with a rating of 9.
+    foodRatings.highestRated("japanese"); // return "ramen"
+                                          // "ramen" is the highest rated japanese food with a rating of 14.
+    foodRatings.changeRating("sushi", 16); // "sushi" now has a rating of 16.
+    foodRatings.highestRated("japanese"); // return "sushi"
+                                          // "sushi" is the highest rated japanese food with a rating of 16.
+    foodRatings.changeRating("ramen", 16); // "ramen" now has a rating of 16.
+    foodRatings.highestRated("japanese"); // return "ramen"
+                                          // Both "sushi" and "ramen" have a rating of 16.
+                                          // However, "ramen" is lexicographically smaller than "sushi". 
+
+**Constraints:**
+
+*   1 <= n <= 2 * 104
+*   `n == foods.length == cuisines.length == ratings.length`
+*   `1 <= foods[i].length, cuisines[i].length <= 10`
+*   `foods[i]`, `cuisines[i]` consist of lowercase English letters.
+*   1 <= ratings[i] <= 108
+*   All the strings in `foods` are **distinct**.
+*   `food` will be the name of a food item in the system across all calls to `changeRating`.
+*   `cuisine` will be a type of cuisine of **at least one** food item in the system across all calls to `highestRated`.
+*   At most 2 * 104 calls **in total** will be made to `changeRating` and `highestRated`.
+
+## Solution
+
+```kotlin
+import java.util.TreeSet
+
+class FoodRatings(foods: Array, cuisines: Array, ratings: IntArray) {
+    private val cus = HashMap>()
+    private val foodHashMap = HashMap()
+
+    init {
+        for (i in foods.indices) {
+            val food = Food(foods[i], ratings[i], cuisines[i])
+            foodHashMap[foods[i]] = food
+            if (cus.containsKey(cuisines[i])) {
+                cus[cuisines[i]]!!.add(food)
+            } else {
+                val pq = TreeSet(Comp())
+                pq.add(food)
+                cus[cuisines[i]] = pq
+            }
+        }
+    }
+
+    fun changeRating(food: String, newRating: Int) {
+        val dish = foodHashMap[food]
+        val pq = cus[dish!!.cus]!!
+        pq.remove(dish)
+        dish.rating = newRating
+        pq.add(dish)
+    }
+
+    fun highestRated(cuisine: String): String {
+        return cus[cuisine]!!.first()!!.foodItem
+    }
+
+    private class Comp : Comparator {
+        override fun compare(f1: Food, f2: Food): Int {
+            return if (f1.rating == f2.rating) {
+                f1.foodItem.compareTo(f2.foodItem)
+            } else Integer.compare(f2.rating, f1.rating)
+        }
+    }
+
+    private class Food internal constructor(val foodItem: String, var rating: Int, val cus: String)
+}
+/*
+ * Your FoodRatings object will be instantiated and called as such:
+ * var obj = FoodRatings(foods, cuisines, ratings)
+ * obj.changeRating(food,newRating)
+ * var param_2 = obj.highestRated(cuisine)
+ */
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2354_number_of_excellent_pairs/readme.md b/src/main/kotlin/g2301_2400/s2354_number_of_excellent_pairs/readme.md
new file mode 100644
index 00000000..1a7f190c
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2354_number_of_excellent_pairs/readme.md
@@ -0,0 +1,75 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2354\. Number of Excellent Pairs
+
+Hard
+
+You are given a **0-indexed** positive integer array `nums` and a positive integer `k`.
+
+A pair of numbers `(num1, num2)` is called **excellent** if the following conditions are satisfied:
+
+*   **Both** the numbers `num1` and `num2` exist in the array `nums`.
+*   The sum of the number of set bits in `num1 OR num2` and `num1 AND num2` is greater than or equal to `k`, where `OR` is the bitwise **OR** operation and `AND` is the bitwise **AND** operation.
+
+Return _the number of **distinct** excellent pairs_.
+
+Two pairs `(a, b)` and `(c, d)` are considered distinct if either `a != c` or `b != d`. For example, `(1, 2)` and `(2, 1)` are distinct.
+
+**Note** that a pair `(num1, num2)` such that `num1 == num2` can also be excellent if you have at least **one** occurrence of `num1` in the array.
+
+**Example 1:**
+
+**Input:** nums = [1,2,3,1], k = 3
+
+**Output:** 5
+
+**Explanation:** The excellent pairs are the following:
+
+- (3, 3). (3 AND 3) and (3 OR 3) are both equal to (11) in binary. The total number of set bits is 2 + 2 = 4, which is greater than or equal to k = 3.
+
+- (2, 3) and (3, 2). (2 AND 3) is equal to (10) in binary, and (2 OR 3) is equal to (11) in binary. The total number of set bits is 1 + 2 = 3.
+
+- (1, 3) and (3, 1). (1 AND 3) is equal to (01) in binary, and (1 OR 3) is equal to (11) in binary. The total number of set bits is 1 + 2 = 3.
+
+So the number of excellent pairs is 5.
+
+**Example 2:**
+
+**Input:** nums = [5,1,1], k = 10
+
+**Output:** 0
+
+**Explanation:** There are no excellent pairs for this array. 
+
+**Constraints:**
+
+*   1 <= nums.length <= 105
+*   1 <= nums[i] <= 109
+*   `1 <= k <= 60`
+
+## Solution
+
+```kotlin
+class Solution {
+    fun countExcellentPairs(nums: IntArray, k: Int): Long {
+        val cnt = LongArray(30)
+        var res = 0L
+        val set: MutableSet = HashSet()
+        for (a in nums) {
+            set.add(a)
+        }
+        for (a in set) {
+            cnt[Integer.bitCount(a)]++
+        }
+        for (i in 1..29) {
+            for (j in 1..29) {
+                if (i + j >= k) {
+                    res += cnt[i] * cnt[j]
+                }
+            }
+        }
+        return res
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2356_number_of_unique_subjects_taught_by_each_teacher/readme.md b/src/main/kotlin/g2301_2400/s2356_number_of_unique_subjects_taught_by_each_teacher/readme.md
new file mode 100644
index 00000000..40343714
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2356_number_of_unique_subjects_taught_by_each_teacher/readme.md
@@ -0,0 +1,79 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2356\. Number of Unique Subjects Taught by Each Teacher
+
+Easy
+
+SQL Schema
+
+Table: `Teacher`
+
+    +-------------+------+
+    | Column Name | Type |
+    +-------------+------+
+    | teacher_id  | int  |
+    | subject_id  | int  |
+    | dept_id     | int  |
+    +-------------+------+
+    (subject_id, dept_id) is the primary key for this table.
+    Each row in this table indicates that the teacher with teacher_id teaches the subject subject_id in the department dept_id. 
+
+Write an SQL query to report the number of unique subjects each teacher teaches in the university.
+
+Return the result table in **any order**.
+
+The query result format is shown in the following example.
+
+**Example 1:**
+
+**Input:**
+
+Teacher table:
+
+    +------------+------------+---------+
+    | teacher_id | subject_id | dept_id |
+    +------------+------------+---------+
+    | 1          | 2          | 3       |
+    | 1          | 2          | 4       |
+    | 1          | 3          | 3       |
+    | 2          | 1          | 1       |
+    | 2          | 2          | 1       |
+    | 2          | 3          | 1       |
+    | 2          | 4          | 1       |
+    +------------+------------+---------+
+
+**Output:**
+
+    +------------+-----+
+    | teacher_id | cnt |
+    +------------+-----+
+    | 1          | 2   |
+    | 2          | 4   |
+    +------------+-----+
+
+**Explanation:**
+
+Teacher 1:
+
+- They teach subject 2 in departments 3 and 4.
+
+- They teach subject 3 in department 3.
+
+Teacher 2:
+
+- They teach subject 1 in department 1.
+
+- They teach subject 2 in department 1.
+
+- They teach subject 3 in department 1.
+
+- They teach subject 4 in department 1.
+
+## Solution
+
+```sql
+# Write your MySQL query statement below
+SELECT teacher_id,COUNT(DISTINCT subject_id) as cnt FROM Teacher
+GROUP BY teacher_id;
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2357_make_array_zero_by_subtracting_equal_amounts/readme.md b/src/main/kotlin/g2301_2400/s2357_make_array_zero_by_subtracting_equal_amounts/readme.md
new file mode 100644
index 00000000..e0576739
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2357_make_array_zero_by_subtracting_equal_amounts/readme.md
@@ -0,0 +1,56 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2357\. Make Array Zero by Subtracting Equal Amounts
+
+Easy
+
+You are given a non-negative integer array `nums`. In one operation, you must:
+
+*   Choose a positive integer `x` such that `x` is less than or equal to the **smallest non-zero** element in `nums`.
+*   Subtract `x` from every **positive** element in `nums`.
+
+Return _the **minimum** number of operations to make every element in_ `nums` _equal to_ `0`.
+
+**Example 1:**
+
+**Input:** nums = [1,5,0,3,5]
+
+**Output:** 3
+
+**Explanation:**
+
+In the first operation, choose x = 1. Now, nums = [0,4,0,2,4].
+
+In the second operation, choose x = 2. Now, nums = [0,2,0,0,2].
+
+In the third operation, choose x = 2. Now, nums = [0,0,0,0,0]. 
+
+**Example 2:**
+
+**Input:** nums = [0]
+
+**Output:** 0
+
+**Explanation:** Each element in nums is already 0 so no operations are needed. 
+
+**Constraints:**
+
+*   `1 <= nums.length <= 100`
+*   `0 <= nums[i] <= 100`
+
+## Solution
+
+```kotlin
+class Solution {
+    fun minimumOperations(nums: IntArray): Int {
+        val set: MutableSet = HashSet()
+        for (a in nums) {
+            if (a > 0) {
+                set.add(a)
+            }
+        }
+        return set.size
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2358_maximum_number_of_groups_entering_a_competition/readme.md b/src/main/kotlin/g2301_2400/s2358_maximum_number_of_groups_entering_a_competition/readme.md
new file mode 100644
index 00000000..1e52bb57
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2358_maximum_number_of_groups_entering_a_competition/readme.md
@@ -0,0 +1,53 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2358\. Maximum Number of Groups Entering a Competition
+
+Medium
+
+You are given a positive integer array `grades` which represents the grades of students in a university. You would like to enter **all** these students into a competition in **ordered** non-empty groups, such that the ordering meets the following conditions:
+
+*   The sum of the grades of students in the ith group is **less than** the sum of the grades of students in the (i + 1)th group, for all groups (except the last).
+*   The total number of students in the ith group is **less than** the total number of students in the (i + 1)th group, for all groups (except the last).
+
+Return _the **maximum** number of groups that can be formed_.
+
+**Example 1:**
+
+**Input:** grades = [10,6,12,7,3,5]
+
+**Output:** 3
+
+**Explanation:** The following is a possible way to form 3 groups of students:
+
+- 1st group has the students with grades = [12]. Sum of grades: 12. Student count: 1
+
+- 2nd group has the students with grades = [6,7]. Sum of grades: 6 + 7 = 13. Student count: 2
+
+- 3rd group has the students with grades = [10,3,5]. Sum of grades: 10 + 3 + 5 = 18. Student count: 3
+
+It can be shown that it is not possible to form more than 3 groups. 
+
+**Example 2:**
+
+**Input:** grades = [8,8]
+
+**Output:** 1
+
+**Explanation:** We can only form 1 group, since forming 2 groups would lead to an equal number of students in both groups. 
+
+**Constraints:**
+
+*   1 <= grades.length <= 105
+*   1 <= grades[i] <= 105
+
+## Solution
+
+```kotlin
+class Solution {
+    fun maximumGroups(grades: IntArray): Int {
+        val len = grades.size
+        return (-1 + Math.sqrt(1.0 + 8 * len)).toInt() / 2
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2359_find_closest_node_to_given_two_nodes/readme.md b/src/main/kotlin/g2301_2400/s2359_find_closest_node_to_given_two_nodes/readme.md
new file mode 100644
index 00000000..5ae56ffc
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2359_find_closest_node_to_given_two_nodes/readme.md
@@ -0,0 +1,81 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2359\. Find Closest Node to Given Two Nodes
+
+Medium
+
+You are given a **directed** graph of `n` nodes numbered from `0` to `n - 1`, where each node has **at most one** outgoing edge.
+
+The graph is represented with a given **0-indexed** array `edges` of size `n`, indicating that there is a directed edge from node `i` to node `edges[i]`. If there is no outgoing edge from `i`, then `edges[i] == -1`.
+
+You are also given two integers `node1` and `node2`.
+
+Return _the **index** of the node that can be reached from both_ `node1` _and_ `node2`_, such that the **maximum** between the distance from_ `node1` _to that node, and from_ `node2` _to that node is **minimized**_. If there are multiple answers, return the node with the **smallest** index, and if no possible answer exists, return `-1`.
+
+Note that `edges` may contain cycles.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/06/07/graph4drawio-2.png)
+
+**Input:** edges = [2,2,3,-1], node1 = 0, node2 = 1
+
+**Output:** 2
+
+**Explanation:** The distance from node 0 to node 2 is 1, and the distance from node 1 to node 2 is 1.
+
+The maximum of those two distances is 1. It can be proven that we cannot get a node with a smaller maximum distance than 1, so we return node 2.
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2022/06/07/graph4drawio-4.png)
+
+**Input:** edges = [1,2,-1], node1 = 0, node2 = 2
+
+**Output:** 2
+
+**Explanation:** The distance from node 0 to node 2 is 2, and the distance from node 2 to itself is 0.
+
+The maximum of those two distances is 2. It can be proven that we cannot get a node with a smaller maximum distance than 2, so we return node 2.
+
+**Constraints:**
+
+*   `n == edges.length`
+*   2 <= n <= 105
+*   `-1 <= edges[i] < n`
+*   `edges[i] != i`
+*   `0 <= node1, node2 < n`
+
+## Solution
+
+```kotlin
+@Suppress("NAME_SHADOWING")
+class Solution {
+    fun closestMeetingNode(edges: IntArray, node1: Int, node2: Int): Int {
+        val n = edges.size
+        val m1 = arrayOfNulls(n)
+        val m2 = arrayOfNulls(n)
+        dfs(edges, m1, node1)
+        dfs(edges, m2, node2)
+        var index = -1
+        var dist = Int.MAX_VALUE
+        for (i in 0 until n) {
+            if (m1[i] != null && m2[i] != null && dist > Math.max(m1[i]!!, m2[i]!!)) {
+                dist = Math.max(m1[i]!!, m2[i]!!)
+                index = i
+            }
+        }
+        return index
+    }
+
+    private fun dfs(edges: IntArray, memo: Array, node: Int) {
+        var node = node
+        var dist = 0
+        while (node != -1 && memo[node] == null) {
+            memo[node] = dist++
+            node = edges[node]
+        }
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2360_longest_cycle_in_a_graph/readme.md b/src/main/kotlin/g2301_2400/s2360_longest_cycle_in_a_graph/readme.md
new file mode 100644
index 00000000..867720f0
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2360_longest_cycle_in_a_graph/readme.md
@@ -0,0 +1,85 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2360\. Longest Cycle in a Graph
+
+Hard
+
+You are given a **directed** graph of `n` nodes numbered from `0` to `n - 1`, where each node has **at most one** outgoing edge.
+
+The graph is represented with a given **0-indexed** array `edges` of size `n`, indicating that there is a directed edge from node `i` to node `edges[i]`. If there is no outgoing edge from node `i`, then `edges[i] == -1`.
+
+Return _the length of the **longest** cycle in the graph_. If no cycle exists, return `-1`.
+
+A cycle is a path that starts and ends at the **same** node.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/06/08/graph4drawio-5.png)
+
+**Input:** edges = [3,3,4,2,3]
+
+**Output:** 3
+
+**Explanation:** The longest cycle in the graph is the cycle: 2 -> 4 -> 3 -> 2.
+
+The length of this cycle is 3, so 3 is returned. 
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2022/06/07/graph4drawio-1.png)
+
+**Input:** edges = [2,-1,3,1]
+
+**Output:** -1
+
+**Explanation:** There are no cycles in this graph. 
+
+**Constraints:**
+
+*   `n == edges.length`
+*   2 <= n <= 105
+*   `-1 <= edges[i] < n`
+*   `edges[i] != i`
+
+## Solution
+
+```kotlin
+class Solution {
+    fun longestCycle(edges: IntArray): Int {
+        val n = edges.size
+        val vis = BooleanArray(n)
+        val dfsvis = BooleanArray(n)
+        val path = IntArray(n)
+        var maxLength = -1
+        for (i in 0 until n) {
+            if (!vis[i]) {
+                path[i] = 1
+                maxLength = Math.max(maxLength, dfs(i, 1, path, vis, dfsvis, edges))
+            }
+        }
+        return maxLength
+    }
+
+    private fun dfs(
+        node: Int,
+        pathLength: Int,
+        path: IntArray,
+        vis: BooleanArray,
+        dfsvis: BooleanArray,
+        edges: IntArray
+    ): Int {
+        vis[node] = true
+        dfsvis[node] = true
+        var length = -1
+        if (edges[node] != -1 && !vis[edges[node]]) {
+            path[edges[node]] = pathLength + 1
+            length = dfs(edges[node], pathLength + 1, path, vis, dfsvis, edges)
+        } else if (edges[node] != -1 && dfsvis[edges[node]]) {
+            length = pathLength - path[edges[node]] + 1
+        }
+        dfsvis[node] = false
+        return length
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2363_merge_similar_items/readme.md b/src/main/kotlin/g2301_2400/s2363_merge_similar_items/readme.md
new file mode 100644
index 00000000..1624292a
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2363_merge_similar_items/readme.md
@@ -0,0 +1,91 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2363\. Merge Similar Items
+
+Easy
+
+You are given two 2D integer arrays, `items1` and `items2`, representing two sets of items. Each array `items` has the following properties:
+
+*   items[i] = [valuei, weighti] where valuei represents the **value** and weighti represents the **weight** of the ith item.
+*   The value of each item in `items` is **unique**.
+
+Return _a 2D integer array_ `ret` _where_ ret[i] = [valuei, weighti]_,_ _with_ weighti _being the **sum of weights** of all items with value_ valuei.
+
+**Note:** `ret` should be returned in **ascending** order by value.
+
+**Example 1:**
+
+**Input:** items1 = \[\[1,1],[4,5],[3,8]], items2 = \[\[3,1],[1,5]]
+
+**Output:** [[1,6],[3,9],[4,5]]
+
+**Explanation:** 
+The item with value = 1 occurs in items1 with weight = 1 and in items2 with weight = 5, total weight = 1 + 5 = 6. 
+
+The item with value = 3 occurs in items1 with weight = 8 and in items2 with weight = 1, total weight = 8 + 1 = 9. 
+
+The item with value = 4 occurs in items1 with weight = 5, total weight = 5. 
+
+Therefore, we return [[1,6],[3,9],[4,5]].
+
+**Example 2:**
+
+**Input:** items1 = \[\[1,1],[3,2],[2,3]], items2 = \[\[2,1],[3,2],[1,3]]
+
+**Output:** [[1,4],[2,4],[3,4]]
+
+**Explanation:** 
+The item with value = 1 occurs in items1 with weight = 1 and in items2 with weight = 3, total weight = 1 + 3 = 4. 
+
+The item with value = 2 occurs in items1 with weight = 3 and in items2 with weight = 1, total weight = 3 + 1 = 4. 
+
+The item with value = 3 occurs in items1 with weight = 2 and in items2 with weight = 2, total weight = 2 + 2 = 4. Therefore, we return [[1,4],[2,4],[3,4]].
+
+**Example 3:**
+
+**Input:** items1 = \[\[1,3],[2,2]], items2 = \[\[7,1],[2,2],[1,4]]
+
+**Output:** [[1,7],[2,4],[7,1]]
+
+**Explanation:** 
+
+The item with value = 1 occurs in items1 with weight = 3 and in items2 with weight = 4, total weight = 3 + 4 = 7. 
+
+The item with value = 2 occurs in items1 with weight = 2 and in items2 with weight = 2, total weight = 2 + 2 = 4. 
+
+The item with value = 7 occurs in items2 with weight = 1, total weight = 1. 
+
+Therefore, we return [[1,7],[2,4],[7,1]].
+
+**Constraints:**
+
+*   `1 <= items1.length, items2.length <= 1000`
+*   `items1[i].length == items2[i].length == 2`
+*   1 <= valuei, weighti <= 1000
+*   Each valuei in `items1` is **unique**.
+*   Each valuei in `items2` is **unique**.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun mergeSimilarItems(items1: Array, items2: Array): List> {
+        val cache = IntArray(1001)
+        for (num in items1) {
+            cache[num[0]] += num[1]
+        }
+        for (num in items2) {
+            cache[num[0]] += num[1]
+        }
+        val result: MutableList> = ArrayList()
+        for (i in cache.indices) {
+            val weight = cache[i]
+            if (weight > 0) {
+                result.add(listOf(i, weight))
+            }
+        }
+        return result
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2364_count_number_of_bad_pairs/readme.md b/src/main/kotlin/g2301_2400/s2364_count_number_of_bad_pairs/readme.md
new file mode 100644
index 00000000..0e7c5a40
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2364_count_number_of_bad_pairs/readme.md
@@ -0,0 +1,64 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2364\. Count Number of Bad Pairs
+
+Medium
+
+You are given a **0-indexed** integer array `nums`. A pair of indices `(i, j)` is a **bad pair** if `i < j` and `j - i != nums[j] - nums[i]`.
+
+Return _the total number of **bad pairs** in_ `nums`.
+
+**Example 1:**
+
+**Input:** nums = [4,1,3,3]
+
+**Output:** 5
+
+**Explanation:** 
+
+The pair (0, 1) is a bad pair since 1 - 0 != 1 - 4.
+
+The pair (0, 2) is a bad pair since 2 - 0 != 3 - 4, 2 != -1. 
+
+The pair (0, 3) is a bad pair since 3 - 0 != 3 - 4, 3 != -1. 
+
+The pair (1, 2) is a bad pair since 2 - 1 != 3 - 1, 1 != 2. 
+
+The pair (2, 3) is a bad pair since 3 - 2 != 3 - 3, 1 != 0. 
+
+There are a total of 5 bad pairs, so we return 5.
+
+**Example 2:**
+
+**Input:** nums = [1,2,3,4,5]
+
+**Output:** 0
+
+**Explanation:** There are no bad pairs.
+
+**Constraints:**
+
+*   1 <= nums.length <= 105
+*   1 <= nums[i] <= 109
+
+## Solution
+
+```kotlin
+class Solution {
+    fun countBadPairs(nums: IntArray): Long {
+        val seen = HashMap()
+        var count: Long = 0
+        for (i in nums.indices) {
+            val diff = i - nums[i]
+            count += if (seen.containsKey(diff)) {
+                (i - seen[diff]!!).toLong()
+            } else {
+                i.toLong()
+            }
+            seen[diff] = seen.getOrDefault(diff, 0) + 1
+        }
+        return count
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2365_task_scheduler_ii/readme.md b/src/main/kotlin/g2301_2400/s2365_task_scheduler_ii/readme.md
new file mode 100644
index 00000000..024f00d5
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2365_task_scheduler_ii/readme.md
@@ -0,0 +1,103 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2365\. Task Scheduler II
+
+Medium
+
+You are given a **0-indexed** array of positive integers `tasks`, representing tasks that need to be completed **in order**, where `tasks[i]` represents the **type** of the ith task.
+
+You are also given a positive integer `space`, which represents the **minimum** number of days that must pass **after** the completion of a task before another task of the **same** type can be performed.
+
+Each day, until all tasks have been completed, you must either:
+
+*   Complete the next task from `tasks`, or
+*   Take a break.
+
+Return _the **minimum** number of days needed to complete all tasks_.
+
+**Example 1:**
+
+**Input:** tasks = [1,2,1,2,3,1], space = 3
+
+**Output:** 9
+
+**Explanation:** 
+
+One way to complete all tasks in 9 days is as follows: 
+
+Day 1: Complete the 0th task. 
+
+Day 2: Complete the 1st task.
+
+Day 3: Take a break.
+
+Day 4: Take a break. 
+
+Day 5: Complete the 2nd task. 
+
+Day 6: Complete the 3rd task.
+
+Day 7: Take a break. 
+
+Day 8: Complete the 4th task. 
+
+Day 9: Complete the 5th task. 
+
+It can be shown that the tasks cannot be completed in less than 9 days.
+
+**Example 2:**
+
+**Input:** tasks = [5,8,8,5], space = 2
+
+**Output:** 6
+
+**Explanation:** 
+
+One way to complete all tasks in 6 days is as follows:
+
+Day 1: Complete the 0th task.
+
+Day 2: Complete the 1st task. 
+
+Day 3: Take a break.
+
+Day 4: Take a break.
+
+Day 5: Complete the 2nd task.
+
+Day 6: Complete the 3rd task. 
+
+It can be shown that the tasks cannot be completed in less than 6 days.
+
+**Constraints:**
+
+*   1 <= tasks.length <= 105
+*   1 <= tasks[i] <= 109
+*   `1 <= space <= tasks.length`
+
+## Solution
+
+```kotlin
+@Suppress("NAME_SHADOWING")
+class Solution {
+    fun taskSchedulerII(tasks: IntArray, space: Int): Long {
+        var space = space
+        var days: Long = 0
+        space++
+        val lastOccurence = HashMap()
+        for (i in tasks.indices) {
+            if (lastOccurence.containsKey(tasks[i])) {
+                val lastTimeOccurred = lastOccurence[tasks[i]]!!
+                val daysDifference = days - lastTimeOccurred
+                if (daysDifference < space) {
+                    days += space - daysDifference
+                }
+            }
+            lastOccurence[tasks[i]] = days
+            days++
+        }
+        return days
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2366_minimum_replacements_to_sort_the_array/readme.md b/src/main/kotlin/g2301_2400/s2366_minimum_replacements_to_sort_the_array/readme.md
new file mode 100644
index 00000000..f7187977
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2366_minimum_replacements_to_sort_the_array/readme.md
@@ -0,0 +1,59 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2366\. Minimum Replacements to Sort the Array
+
+Hard
+
+You are given a **0-indexed** integer array `nums`. In one operation you can replace any element of the array with **any two** elements that **sum** to it.
+
+*   For example, consider `nums = [5,6,7]`. In one operation, we can replace `nums[1]` with `2` and `4` and convert `nums` to `[5,2,4,7]`.
+
+Return _the minimum number of operations to make an array that is sorted in **non-decreasing** order_.
+
+**Example 1:**
+
+**Input:** nums = [3,9,3]
+
+**Output:** 2
+
+**Explanation:** Here are the steps to sort the array in non-decreasing order: 
+
+- From [3,9,3], replace the 9 with 3 and 6 so the array becomes [3,3,6,3] 
+
+- From [3,3,6,3], replace the 6 with 3 and 3 so the array becomes [3,3,3,3,3] 
+  
+There are 2 steps to sort the array in non-decreasing order. Therefore, we return 2.
+
+**Example 2:**
+
+**Input:** nums = [1,2,3,4,5]
+
+**Output:** 0
+
+**Explanation:** The array is already in non-decreasing order. Therefore, we return 0.
+
+**Constraints:**
+
+*   1 <= nums.length <= 105
+*   1 <= nums[i] <= 109
+
+## Solution
+
+```kotlin
+class Solution {
+    fun minimumReplacement(nums: IntArray): Long {
+        var limit = nums[nums.size - 1]
+        var ans: Long = 0
+        for (i in nums.size - 2 downTo 0) {
+            var replacements = nums[i] / limit - 1
+            if (nums[i] % limit != 0) {
+                replacements++
+            }
+            ans += replacements.toLong()
+            limit = nums[i] / (replacements + 1)
+        }
+        return ans
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2367_number_of_arithmetic_triplets/readme.md b/src/main/kotlin/g2301_2400/s2367_number_of_arithmetic_triplets/readme.md
new file mode 100644
index 00000000..93a6b26c
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2367_number_of_arithmetic_triplets/readme.md
@@ -0,0 +1,65 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2367\. Number of Arithmetic Triplets
+
+Easy
+
+You are given a **0-indexed**, **strictly increasing** integer array `nums` and a positive integer `diff`. A triplet `(i, j, k)` is an **arithmetic triplet** if the following conditions are met:
+
+*   `i < j < k`,
+*   `nums[j] - nums[i] == diff`, and
+*   `nums[k] - nums[j] == diff`.
+
+Return _the number of unique **arithmetic triplets**._
+
+**Example 1:**
+
+**Input:** nums = [0,1,4,6,7,10], diff = 3
+
+**Output:** 2
+
+**Explanation:** 
+
+(1, 2, 4) is an arithmetic triplet because both 7 - 4 == 3 and 4 - 1 == 3. 
+
+(2, 4, 5) is an arithmetic triplet because both 10 - 7 == 3 and 7 - 4 == 3.
+
+**Example 2:**
+
+**Input:** nums = [4,5,6,7,8,9], diff = 2
+
+**Output:** 2
+
+**Explanation:** 
+
+(0, 2, 4) is an arithmetic triplet because both 8 - 6 == 2 and 6 - 4 == 2. 
+
+(1, 3, 5) is an arithmetic triplet because both 9 - 7 == 2 and 7 - 5 == 2.
+
+**Constraints:**
+
+*   `3 <= nums.length <= 200`
+*   `0 <= nums[i] <= 200`
+*   `1 <= diff <= 50`
+*   `nums` is **strictly** increasing.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun arithmeticTriplets(nums: IntArray, diff: Int): Int {
+        val set: MutableSet = HashSet()
+        for (x in nums) {
+            set.add(x)
+        }
+        var ans = 0
+        for (x in nums) {
+            if (set.contains(x - diff) && set.contains(x + diff)) {
+                ans++
+            }
+        }
+        return ans
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2368_reachable_nodes_with_restrictions/readme.md b/src/main/kotlin/g2301_2400/s2368_reachable_nodes_with_restrictions/readme.md
new file mode 100644
index 00000000..6f20067e
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2368_reachable_nodes_with_restrictions/readme.md
@@ -0,0 +1,87 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2368\. Reachable Nodes With Restrictions
+
+Medium
+
+There is an undirected tree with `n` nodes labeled from `0` to `n - 1` and `n - 1` edges.
+
+You are given a 2D integer array `edges` of length `n - 1` where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree. You are also given an integer array `restricted` which represents **restricted** nodes.
+
+Return _the **maximum** number of nodes you can reach from node_ `0` _without visiting a restricted node._
+
+Note that node `0` will **not** be a restricted node.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/06/15/ex1drawio.png)
+
+**Input:** n = 7, edges = \[\[0,1],[1,2],[3,1],[4,0],[0,5],[5,6]], restricted = [4,5]
+
+**Output:** 4
+
+**Explanation:** The diagram above shows the tree. We have that [0,1,2,3] are the only nodes that can be reached from node 0 without visiting a restricted node.
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2022/06/15/ex2drawio.png)
+
+**Input:** n = 7, edges = \[\[0,1],[0,2],[0,5],[0,4],[3,2],[6,5]], restricted = [4,2,1]
+
+**Output:** 3
+
+**Explanation:** The diagram above shows the tree. We have that [0,5,6] are the only nodes that can be reached from node 0 without visiting a restricted node.
+
+**Constraints:**
+
+*   2 <= n <= 105
+*   `edges.length == n - 1`
+*   `edges[i].length == 2`
+*   0 <= ai, bi < n
+*   ai != bi
+*   `edges` represents a valid tree.
+*   `1 <= restricted.length < n`
+*   `1 <= restricted[i] < n`
+*   All the values of `restricted` are **unique**.
+
+## Solution
+
+```kotlin
+import java.util.ArrayDeque
+import java.util.Queue
+
+class Solution {
+    fun reachableNodes(n: Int, edges: Array, restricted: IntArray): Int {
+        val graph: Array?> = arrayOfNulls(n)
+        for (i in 0 until n) {
+            graph[i] = ArrayList()
+        }
+        for (edge in edges) {
+            val src = edge[0]
+            val dest = edge[1]
+            graph[src]?.add(dest)
+            graph[dest]?.add(src)
+        }
+        val q: Queue = ArrayDeque()
+        val visited = BooleanArray(n)
+        q.offer(0)
+        visited[0] = true
+        for (node in restricted) {
+            visited[node] = true
+        }
+        var ans = 0
+        while (q.isNotEmpty()) {
+            val vertex = q.poll()
+            ans++
+            for (neighbour in graph[vertex]!!) {
+                if (!visited[neighbour]) {
+                    q.offer(neighbour)
+                    visited[neighbour] = true
+                }
+            }
+        }
+        return ans
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2369_check_if_there_is_a_valid_partition_for_the_array/readme.md b/src/main/kotlin/g2301_2400/s2369_check_if_there_is_a_valid_partition_for_the_array/readme.md
new file mode 100644
index 00000000..9f465acc
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2369_check_if_there_is_a_valid_partition_for_the_array/readme.md
@@ -0,0 +1,65 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2369\. Check if There is a Valid Partition For The Array
+
+Medium
+
+You are given a **0-indexed** integer array `nums`. You have to partition the array into one or more **contiguous** subarrays.
+
+We call a partition of the array **valid** if each of the obtained subarrays satisfies **one** of the following conditions:
+
+1.  The subarray consists of **exactly** `2` equal elements. For example, the subarray `[2,2]` is good.
+2.  The subarray consists of **exactly** `3` equal elements. For example, the subarray `[4,4,4]` is good.
+3.  The subarray consists of **exactly** `3` consecutive increasing elements, that is, the difference between adjacent elements is `1`. For example, the subarray `[3,4,5]` is good, but the subarray `[1,3,5]` is not.
+
+Return `true` _if the array has **at least** one valid partition_. Otherwise, return `false`.
+
+**Example 1:**
+
+**Input:** nums = [4,4,4,5,6]
+
+**Output:** true
+
+**Explanation:** The array can be partitioned into the subarrays [4,4] and [4,5,6]. This partition is valid, so we return true.
+
+**Example 2:**
+
+**Input:** nums = [1,1,1,2]
+
+**Output:** false
+
+**Explanation:** There is no valid partition for this array.
+
+**Constraints:**
+
+*   2 <= nums.length <= 105
+*   1 <= nums[i] <= 106
+
+## Solution
+
+```kotlin
+class Solution {
+    fun validPartition(nums: IntArray): Boolean {
+        val canPartition = BooleanArray(nums.size + 1)
+        canPartition[0] = true
+        var diff = nums[1] - nums[0]
+        var equal = diff == 0
+        var incOne = diff == 1
+        canPartition[2] = equal
+        for (i in 3 until canPartition.size) {
+            diff = nums[i - 1] - nums[i - 2]
+            if (diff == 0) {
+                canPartition[i] = canPartition[i - 2] || equal && canPartition[i - 3]
+                equal = true
+                incOne = false
+            } else if (diff == 1) {
+                canPartition[i] = incOne && canPartition[i - 3]
+                equal = false
+                incOne = true
+            }
+        }
+        return canPartition[nums.size]
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2370_longest_ideal_subsequence/readme.md b/src/main/kotlin/g2301_2400/s2370_longest_ideal_subsequence/readme.md
new file mode 100644
index 00000000..38111732
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2370_longest_ideal_subsequence/readme.md
@@ -0,0 +1,84 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2370\. Longest Ideal Subsequence
+
+Medium
+
+You are given a string `s` consisting of lowercase letters and an integer `k`. We call a string `t` **ideal** if the following conditions are satisfied:
+
+*   `t` is a **subsequence** of the string `s`.
+*   The absolute difference in the alphabet order of every two **adjacent** letters in `t` is less than or equal to `k`.
+
+Return _the length of the **longest** ideal string_.
+
+A **subsequence** is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.
+
+**Note** that the alphabet order is not cyclic. For example, the absolute difference in the alphabet order of `'a'` and `'z'` is `25`, not `1`.
+
+**Example 1:**
+
+**Input:** s = "acfgbd", k = 2
+
+**Output:** 4
+
+**Explanation:** The longest ideal string is "acbd". The length of this string is 4, so 4 is returned. Note that "acfgbd" is not ideal because 'c' and 'f' have a difference of 3 in alphabet order.
+
+**Example 2:**
+
+**Input:** s = "abcd", k = 3
+
+**Output:** 4
+
+**Explanation:** The longest ideal string is "abcd". The length of this string is 4, so 4 is returned.
+
+**Constraints:**
+
+*   1 <= s.length <= 105
+*   `0 <= k <= 25`
+*   `s` consists of lowercase English letters.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun longestIdealString(s: String, k: Int): Int {
+        var ans = 1
+        val array = IntArray(26)
+        for (i in 0 until s.length) {
+            val curr = s[i].code - 'a'.code
+            var currans = 1
+            var temp = k
+            array[curr] += 1
+            var j = curr - 1
+            while (temp > 0) {
+                if (j == -1) {
+                    break
+                }
+                currans = Math.max(currans, array[j] + 1)
+                temp--
+                if (j == 0) {
+                    break
+                }
+                j--
+            }
+            temp = k
+            j = curr + 1
+            while (temp > 0) {
+                if (j == 26) {
+                    break
+                }
+                currans = Math.max(currans, array[j] + 1)
+                temp--
+                if (j == 25) {
+                    break
+                }
+                j++
+            }
+            array[curr] = Math.max(currans, array[curr])
+            ans = Math.max(ans, array[curr])
+        }
+        return ans
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2373_largest_local_values_in_a_matrix/readme.md b/src/main/kotlin/g2301_2400/s2373_largest_local_values_in_a_matrix/readme.md
new file mode 100644
index 00000000..915f340e
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2373_largest_local_values_in_a_matrix/readme.md
@@ -0,0 +1,65 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2373\. Largest Local Values in a Matrix
+
+Easy
+
+You are given an `n x n` integer matrix `grid`.
+
+Generate an integer matrix `maxLocal` of size `(n - 2) x (n - 2)` such that:
+
+*   `maxLocal[i][j]` is equal to the **largest** value of the `3 x 3` matrix in `grid` centered around row `i + 1` and column `j + 1`.
+
+In other words, we want to find the largest value in every contiguous `3 x 3` matrix in `grid`.
+
+Return _the generated matrix_.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/06/21/ex1.png)
+
+**Input:** grid = \[\[9,9,8,1],[5,6,2,6],[8,2,6,4],[6,2,2,2]]
+
+**Output:** [[9,9],[8,6]]
+
+**Explanation:** The diagram above shows the original matrix and the generated matrix.
+
+Notice that each value in the generated matrix corresponds to the largest value of a contiguous 3 x 3 matrix in grid.
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2022/07/02/ex2new2.png)
+
+**Input:** grid = \[\[1,1,1,1,1],[1,1,1,1,1],[1,1,2,1,1],[1,1,1,1,1],[1,1,1,1,1]]
+
+**Output:** [[2,2,2],[2,2,2],[2,2,2]]
+
+**Explanation:** Notice that the 2 is contained within every contiguous 3 x 3 matrix in grid. 
+
+**Constraints:**
+
+*   `n == grid.length == grid[i].length`
+*   `3 <= n <= 100`
+*   `1 <= grid[i][j] <= 100`
+
+## Solution
+
+```kotlin
+class Solution {
+    fun largestLocal(grid: Array): Array {
+        val n = grid.size
+        val res = Array(n - 2) { IntArray(n - 2) }
+        for (i in 0 until n - 2) {
+            for (j in 0 until n - 2) {
+                for (p in i until i + 3) {
+                    for (q in j until j + 3) {
+                        res[i][j] = Math.max(res[i][j], grid[p][q])
+                    }
+                }
+            }
+        }
+        return res
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2374_node_with_highest_edge_score/readme.md b/src/main/kotlin/g2301_2400/s2374_node_with_highest_edge_score/readme.md
new file mode 100644
index 00000000..1c01e949
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2374_node_with_highest_edge_score/readme.md
@@ -0,0 +1,74 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2374\. Node With Highest Edge Score
+
+Medium
+
+You are given a directed graph with `n` nodes labeled from `0` to `n - 1`, where each node has **exactly one** outgoing edge.
+
+The graph is represented by a given **0-indexed** integer array `edges` of length `n`, where `edges[i]` indicates that there is a **directed** edge from node `i` to node `edges[i]`.
+
+The **edge score** of a node `i` is defined as the sum of the **labels** of all the nodes that have an edge pointing to `i`.
+
+Return _the node with the highest **edge score**_. If multiple nodes have the same **edge score**, return the node with the **smallest** index.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/06/20/image-20220620195403-1.png)
+
+**Input:** edges = [1,0,0,0,0,7,7,5]
+
+**Output:** 7
+
+**Explanation:**
+
+- The nodes 1, 2, 3 and 4 have an edge pointing to node 0. The edge score of node 0 is 1 + 2 + 3 + 4 = 10.
+
+- The node 0 has an edge pointing to node 1. The edge score of node 1 is 0.
+
+- The node 7 has an edge pointing to node 5. The edge score of node 5 is 7.
+
+- The nodes 5 and 6 have an edge pointing to node 7. The edge score of node 7 is 5 + 6 = 11.
+
+Node 7 has the highest edge score so return 7. 
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2022/06/20/image-20220620200212-3.png)
+
+**Input:** edges = [2,0,0,2]
+
+**Output:** 0
+
+**Explanation:**
+
+- The nodes 1 and 2 have an edge pointing to node 0. The edge score of node 0 is 1 + 2 = 3.
+
+- The nodes 0 and 3 have an edge pointing to node 2. The edge score of node 2 is 0 + 3 = 3.
+
+Nodes 0 and 2 both have an edge score of 3. Since node 0 has a smaller index, we return 0. 
+
+**Constraints:**
+
+*   `n == edges.length`
+*   2 <= n <= 105
+*   `0 <= edges[i] < n`
+*   `edges[i] != i`
+
+## Solution
+
+```kotlin
+class Solution {
+    fun edgeScore(edges: IntArray): Int {
+        val a = LongArray(edges.size)
+        var max = 0
+        for (i in edges.indices) {
+            a[edges[i]] += i.toLong()
+            if (a[edges[i]] > a[max]) max = edges[i]
+            else if (a[edges[i]] == a[max] && edges[i] < max) max = edges[i]
+        }
+        return max
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2375_construct_smallest_number_from_di_string/readme.md b/src/main/kotlin/g2301_2400/s2375_construct_smallest_number_from_di_string/readme.md
new file mode 100644
index 00000000..ec3cc353
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2375_construct_smallest_number_from_di_string/readme.md
@@ -0,0 +1,80 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2375\. Construct Smallest Number From DI String
+
+Medium
+
+You are given a **0-indexed** string `pattern` of length `n` consisting of the characters `'I'` meaning **increasing** and `'D'` meaning **decreasing**.
+
+A **0-indexed** string `num` of length `n + 1` is created using the following conditions:
+
+*   `num` consists of the digits `'1'` to `'9'`, where each digit is used **at most** once.
+*   If `pattern[i] == 'I'`, then `num[i] < num[i + 1]`.
+*   If `pattern[i] == 'D'`, then `num[i] > num[i + 1]`.
+
+Return _the lexicographically **smallest** possible string_ `num` _that meets the conditions._
+
+**Example 1:**
+
+**Input:** pattern = "IIIDIDDD"
+
+**Output:** "123549876"
+
+**Explanation:**
+
+At indices 0, 1, 2, and 4 we must have that num[i] < num[i+1].
+
+At indices 3, 5, 6, and 7 we must have that num[i] > num[i+1].
+
+Some possible values of num are "245639871", "135749862", and "123849765".
+
+It can be proven that "123549876" is the smallest possible num that meets the conditions.
+
+Note that "123414321" is not possible because the digit '1' is used more than once.
+
+**Example 2:**
+
+**Input:** pattern = "DDD"
+
+**Output:** "4321"
+
+**Explanation:**
+
+Some possible values of num are "9876", "7321", and "8742".
+
+It can be proven that "4321" is the smallest possible num that meets the conditions. 
+
+**Constraints:**
+
+*   `1 <= pattern.length <= 8`
+*   `pattern` consists of only the letters `'I'` and `'D'`.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun smallestNumber(pattern: String): String {
+        val ret = IntArray(pattern.length + 1)
+        ret[0] = 1
+        var max = 2
+        var lastI = 0
+        for (i in pattern.indices) {
+            if (pattern[i] == 'I') {
+                ret[i + 1] = max++
+                lastI = i + 1
+            } else {
+                for (j in i downTo lastI) {
+                    ret[j + 1] = ret[j]
+                }
+                ret[lastI] = max++
+            }
+        }
+        val sb = StringBuilder()
+        for (i in ret) {
+            sb.append(i)
+        }
+        return sb.toString()
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2376_count_special_integers/readme.md b/src/main/kotlin/g2301_2400/s2376_count_special_integers/readme.md
new file mode 100644
index 00000000..a45b8fc1
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2376_count_special_integers/readme.md
@@ -0,0 +1,104 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2376\. Count Special Integers
+
+Hard
+
+We call a positive integer **special** if all of its digits are **distinct**.
+
+Given a **positive** integer `n`, return _the number of special integers that belong to the interval_ `[1, n]`.
+
+**Example 1:**
+
+**Input:** n = 20
+
+**Output:** 19
+
+**Explanation:** All the integers from 1 to 20, except 11, are special. Thus, there are 19 special integers. 
+
+**Example 2:**
+
+**Input:** n = 5
+
+**Output:** 5
+
+**Explanation:** All the integers from 1 to 5 are special. 
+
+**Example 3:**
+
+**Input:** n = 135
+
+**Output:** 110
+
+**Explanation:** There are 110 integers from 1 to 135 that are special.
+
+Some of the integers that are not special are: 22, 114, and 131.
+
+**Constraints:**
+
+*   1 <= n <= 2 * 109
+
+## Solution
+
+```kotlin
+@Suppress("NAME_SHADOWING")
+class Solution {
+    private lateinit var cntMap: IntArray
+    // number n as an array, splitted by each digit
+    private lateinit var digits: IntArray
+
+    fun countSpecialNumbers(n: Int): Int {
+        var n = n
+        if (n < 10) {
+            return n
+        }
+        val len = Math.log10(n.toDouble()).toInt() + 1
+        cntMap = IntArray(len - 1)
+        val res = countUnbounded(len)
+        digits = IntArray(len)
+        var i = len - 1
+        while (i >= 0) {
+            digits[i] = n % 10
+            i--
+            n /= 10
+        }
+        return res + dfs(0, 0)
+    }
+
+    private fun dfs(i: Int, mask: Int): Int {
+        if (i == digits.size) {
+            return 1
+        }
+        var res = 0
+        val startJ = if (i == 0) 1 else 0
+        for (j in startJ until digits[i]) {
+            if (mask and (1 shl j) == 0) {
+                // unbounded lens left
+                val unbounded = digits.size - 2 - i
+                res += if (unbounded >= 0) count(unbounded, 9 - i) else 1
+            }
+        }
+        if (mask and (1 shl digits[i]) == 0) {
+            res += dfs(i + 1, mask or (1 shl digits[i]))
+        }
+        return res
+    }
+
+    private fun count(i: Int, max: Int): Int {
+        return if (i == 0) {
+            max
+        } else (max - i) * count(i - 1, max)
+    }
+
+    private fun countUnbounded(len: Int): Int {
+        var res = 9
+        cntMap[0] = 9
+        for (i in 0 until len - 2) {
+            cntMap[i + 1] = cntMap[i] * (9 - i)
+            res += cntMap[i + 1]
+        }
+        return res
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2379_minimum_recolors_to_get_k_consecutive_black_blocks/readme.md b/src/main/kotlin/g2301_2400/s2379_minimum_recolors_to_get_k_consecutive_black_blocks/readme.md
new file mode 100644
index 00000000..d8fb398a
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2379_minimum_recolors_to_get_k_consecutive_black_blocks/readme.md
@@ -0,0 +1,80 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2379\. Minimum Recolors to Get K Consecutive Black Blocks
+
+Easy
+
+You are given a **0-indexed** string `blocks` of length `n`, where `blocks[i]` is either `'W'` or `'B'`, representing the color of the ith block. The characters `'W'` and `'B'` denote the colors white and black, respectively.
+
+You are also given an integer `k`, which is the desired number of **consecutive** black blocks.
+
+In one operation, you can **recolor** a white block such that it becomes a black block.
+
+Return _the **minimum** number of operations needed such that there is at least **one** occurrence of_ `k` _consecutive black blocks._
+
+**Example 1:**
+
+**Input:** blocks = "WBBWWBBWBW", k = 7
+
+**Output:** 3
+
+**Explanation:**
+
+One way to achieve 7 consecutive black blocks is to recolor the 0th, 3rd, and 4th blocks so that blocks = "BBBBBBBWBW".
+
+It can be shown that there is no way to achieve 7 consecutive black blocks in less than 3 operations.
+
+Therefore, we return 3.
+
+**Example 2:**
+
+**Input:** blocks = "WBWBBBW", k = 2
+
+**Output:** 0
+
+**Explanation:**
+
+No changes need to be made, since 2 consecutive black blocks already exist.
+
+Therefore, we return 0. 
+
+**Constraints:**
+
+*   `n == blocks.length`
+*   `1 <= n <= 100`
+*   `blocks[i]` is either `'W'` or `'B'`.
+*   `1 <= k <= n`
+
+## Solution
+
+```kotlin
+class Solution {
+    fun minimumRecolors(blocks: String, k: Int): Int {
+        val n = blocks.length
+        var ans: Int
+        var i: Int
+        var cur = 0
+        i = 0
+        while (i < k) {
+            if (blocks[i] == 'W') {
+                cur++
+            }
+            i++
+        }
+        ans = cur
+        i = k
+        while (i < n) {
+            if (blocks[i] == 'W') {
+                cur++
+            }
+            if (blocks[i - k] == 'W') {
+                cur--
+            }
+            ans = Math.min(ans, cur)
+            i++
+        }
+        return ans
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2380_time_needed_to_rearrange_a_binary_string/readme.md b/src/main/kotlin/g2301_2400/s2380_time_needed_to_rearrange_a_binary_string/readme.md
new file mode 100644
index 00000000..4bb7eb01
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2380_time_needed_to_rearrange_a_binary_string/readme.md
@@ -0,0 +1,84 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2380\. Time Needed to Rearrange a Binary String
+
+Medium
+
+You are given a binary string `s`. In one second, **all** occurrences of `"01"` are **simultaneously** replaced with `"10"`. This process **repeats** until no occurrences of `"01"` exist.
+
+Return _the number of seconds needed to complete this process._
+
+**Example 1:**
+
+**Input:** s = "0110101"
+
+**Output:** 4
+
+**Explanation:**
+
+After one second, s becomes "1011010".
+
+After another second, s becomes "1101100".
+
+After the third second, s becomes "1110100".
+
+After the fourth second, s becomes "1111000".
+
+No occurrence of "01" exists any longer, and the process needed 4 seconds to complete, so we return 4.
+
+**Example 2:**
+
+**Input:** s = "11100"
+
+**Output:** 0
+
+**Explanation:** No occurrence of "01" exists in s, and the processes needed 0 seconds to complete, so we return 0.
+
+**Constraints:**
+
+*   `1 <= s.length <= 1000`
+*   `s[i]` is either `'0'` or `'1'`.
+
+**Follow up:**
+
+Can you solve this problem in O(n) time complexity?
+
+## Solution
+
+```kotlin
+class Solution {
+    fun secondsToRemoveOccurrences(s: String): Int {
+        var lastOne = -1
+        var result = 0
+        var prevResult: Int
+        var curResult = 0
+        var countOne = 0
+        var countZero = 0
+        var diff: Int
+        var pTarget: Int
+        var pWait: Int
+        var cTarget: Int
+        for (i in 0 until s.length) {
+            if (s[i] == '0') {
+                ++countZero
+                continue
+            }
+            ++countOne
+            diff = i - lastOne - 1
+            prevResult = curResult
+            cTarget = countOne - 1
+            pTarget = cTarget - 1
+            pWait = prevResult - (lastOne - pTarget)
+            curResult = if (diff > pWait) {
+                countZero
+            } else {
+                if (countZero == 0) 0 else pWait - diff + 1 + countZero
+            }
+            result = curResult
+            lastOne = i
+        }
+        return result
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2381_shifting_letters_ii/readme.md b/src/main/kotlin/g2301_2400/s2381_shifting_letters_ii/readme.md
new file mode 100644
index 00000000..2b38c820
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2381_shifting_letters_ii/readme.md
@@ -0,0 +1,80 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2381\. Shifting Letters II
+
+Medium
+
+You are given a string `s` of lowercase English letters and a 2D integer array `shifts` where shifts[i] = [starti, endi, directioni]. For every `i`, **shift** the characters in `s` from the index starti to the index endi (**inclusive**) forward if directioni = 1, or shift the characters backward if directioni = 0.
+
+Shifting a character **forward** means replacing it with the **next** letter in the alphabet (wrapping around so that `'z'` becomes `'a'`). Similarly, shifting a character **backward** means replacing it with the **previous** letter in the alphabet (wrapping around so that `'a'` becomes `'z'`).
+
+Return _the final string after all such shifts to_ `s` _are applied_.
+
+**Example 1:**
+
+**Input:** s = "abc", shifts = \[\[0,1,0],[1,2,1],[0,2,1]]
+
+**Output:** "ace"
+
+**Explanation:** Firstly, shift the characters from index 0 to index 1 backward. Now s = "zac".
+
+Secondly, shift the characters from index 1 to index 2 forward. Now s = "zbd".
+
+Finally, shift the characters from index 0 to index 2 forward. Now s = "ace".
+
+**Example 2:**
+
+**Input:** s = "dztz", shifts = \[\[0,0,0],[1,1,1]]
+
+**Output:** "catz"
+
+**Explanation:** Firstly, shift the characters from index 0 to index 0 backward. Now s = "cztz".
+
+Finally, shift the characters from index 1 to index 1 forward. Now s = "catz".
+
+**Constraints:**
+
+*   1 <= s.length, shifts.length <= 5 * 104
+*   `shifts[i].length == 3`
+*   0 <= starti <= endi < s.length
+*   0 <= directioni <= 1
+*   `s` consists of lowercase English letters.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun shiftingLetters(s: String, shifts: Array): String {
+        val diff = IntArray(s.length + 1)
+        var l: Int
+        var r: Int
+        for (shift in shifts) {
+            l = shift[0]
+            r = shift[1] + 1
+            diff[l] += 26
+            diff[r] += 26
+            if (shift[2] == 0) {
+                diff[l]--
+                diff[r]++
+            } else {
+                diff[l]++
+                diff[r]--
+            }
+            diff[l] %= 26
+            diff[r] %= 26
+        }
+        val sb = StringBuilder()
+        var current = 0
+        var `val`: Int
+        for (i in 0 until s.length) {
+            current += diff[i]
+            `val` = s[i].code - 'a'.code
+            `val` += current
+            `val` %= 26
+            sb.append(('a'.code + `val`).toChar())
+        }
+        return sb.toString()
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2382_maximum_segment_sum_after_removals/readme.md b/src/main/kotlin/g2301_2400/s2382_maximum_segment_sum_after_removals/readme.md
new file mode 100644
index 00000000..bd1d39a6
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2382_maximum_segment_sum_after_removals/readme.md
@@ -0,0 +1,133 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2382\. Maximum Segment Sum After Removals
+
+Hard
+
+You are given two **0-indexed** integer arrays `nums` and `removeQueries`, both of length `n`. For the ith query, the element in `nums` at the index `removeQueries[i]` is removed, splitting `nums` into different segments.
+
+A **segment** is a contiguous sequence of **positive** integers in `nums`. A **segment sum** is the sum of every element in a segment.
+
+Return _an integer array_ `answer`_, of length_ `n`_, where_ `answer[i]` _is the **maximum** segment sum after applying the_ ith _removal._
+
+**Note:** The same index will **not** be removed more than once.
+
+**Example 1:**
+
+**Input:** nums = [1,2,5,6,1], removeQueries = [0,3,2,4,1]
+
+**Output:** [14,7,2,2,0]
+
+**Explanation:** Using 0 to indicate a removed element, the answer is as follows:
+
+Query 1: Remove the 0th element, nums becomes [0,2,5,6,1] and the maximum segment sum is 14 for segment [2,5,6,1].
+
+Query 2: Remove the 3rd element, nums becomes [0,2,5,0,1] and the maximum segment sum is 7 for segment [2,5].
+
+Query 3: Remove the 2nd element, nums becomes [0,2,0,0,1] and the maximum segment sum is 2 for segment [2].
+
+Query 4: Remove the 4th element, nums becomes [0,2,0,0,0] and the maximum segment sum is 2 for segment [2].
+
+Query 5: Remove the 1st element, nums becomes [0,0,0,0,0] and the maximum segment sum is 0, since there are no segments.
+
+Finally, we return [14,7,2,2,0].
+
+**Example 2:**
+
+**Input:** nums = [3,2,11,1], removeQueries = [3,2,1,0]
+
+**Output:** [16,5,3,0]
+
+**Explanation:** Using 0 to indicate a removed element, the answer is as follows:
+
+Query 1: Remove the 3rd element, nums becomes [3,2,11,0] and the maximum segment sum is 16 for segment [3,2,11].
+
+Query 2: Remove the 2nd element, nums becomes [3,2,0,0] and the maximum segment sum is 5 for segment [3,2].
+
+Query 3: Remove the 1st element, nums becomes [3,0,0,0] and the maximum segment sum is 3 for segment [3].
+
+Query 4: Remove the 0th element, nums becomes [0,0,0,0] and the maximum segment sum is 0, since there are no segments.
+
+Finally, we return [16,5,3,0].
+
+**Constraints:**
+
+*   `n == nums.length == removeQueries.length`
+*   1 <= n <= 105
+*   1 <= nums[i] <= 109
+*   `0 <= removeQueries[i] < n`
+*   All the values of `removeQueries` are **unique**.
+
+## Solution
+
+```kotlin
+@Suppress("NAME_SHADOWING")
+class Solution {
+    private class UF(n: Int) {
+        var root: IntArray
+        var sum: LongArray
+
+        init {
+            this.root = IntArray(n)
+            this.root.fill(-1)
+            sum = LongArray(n)
+        }
+
+        fun insert(x: Int, value: Int) {
+            if (root[x] != -1 || sum[x] != 0L) {
+                return
+            }
+            this.root[x] = x
+            sum[x] = value.toLong()
+        }
+
+        fun find(x: Int): Int {
+            var x = x
+            while (root[x] != x) {
+                val fa = root[x]
+                val ga = root[fa]
+                root[x] = ga
+                x = fa
+            }
+            return x
+        }
+
+        fun union(x: Int, y: Int) {
+            val rx = find(x)
+            val ry = find(y)
+            if (x == y) {
+                return
+            }
+            root[rx] = ry
+            sum[ry] += sum[rx]
+        }
+
+        fun has(x: Int): Boolean {
+            return root[x] != -1 || sum[x] != 0L
+        }
+    }
+
+    fun maximumSegmentSum(nums: IntArray, removeQueries: IntArray): LongArray {
+        val n = removeQueries.size
+        val ret = LongArray(n)
+        var max = 0L
+        val uf = UF(n)
+        for (i in n - 1 downTo 0) {
+            val u = removeQueries[i]
+            uf.insert(u, nums[u])
+            var v = u - 1
+            while (v <= u + 1) {
+                if (v >= 0 && v < n && uf.has(v)) {
+                    uf.union(v, u)
+                }
+                v += 2
+            }
+            ret[i] = max
+            val ru = uf.find(u)
+            max = Math.max(max, uf.sum[ru])
+        }
+        return ret
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2383_minimum_hours_of_training_to_win_a_competition/readme.md b/src/main/kotlin/g2301_2400/s2383_minimum_hours_of_training_to_win_a_competition/readme.md
new file mode 100644
index 00000000..42952c13
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2383_minimum_hours_of_training_to_win_a_competition/readme.md
@@ -0,0 +1,96 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2383\. Minimum Hours of Training to Win a Competition
+
+Easy
+
+You are entering a competition, and are given two **positive** integers `initialEnergy` and `initialExperience` denoting your initial energy and initial experience respectively.
+
+You are also given two **0-indexed** integer arrays `energy` and `experience`, both of length `n`.
+
+You will face `n` opponents **in order**. The energy and experience of the ith opponent is denoted by `energy[i]` and `experience[i]` respectively. When you face an opponent, you need to have both **strictly** greater experience and energy to defeat them and move to the next opponent if available.
+
+Defeating the ith opponent **increases** your experience by `experience[i]`, but **decreases** your energy by `energy[i]`.
+
+Before starting the competition, you can train for some number of hours. After each hour of training, you can **either** choose to increase your initial experience by one, or increase your initial energy by one.
+
+Return _the **minimum** number of training hours required to defeat all_ `n` _opponents_.
+
+**Example 1:**
+
+**Input:** initialEnergy = 5, initialExperience = 3, energy = [1,4,3,2], experience = [2,6,3,1]
+
+**Output:** 8
+
+**Explanation:** You can increase your energy to 11 after 6 hours of training, and your experience to 5 after 2 hours of training.
+
+You face the opponents in the following order:
+
+- You have more energy and experience than the 0th opponent so you win.
+
+  Your energy becomes 11 - 1 = 10, and your experience becomes 5 + 2 = 7.
+  
+- You have more energy and experience than the 1st opponent so you win.
+
+  Your energy becomes 10 - 4 = 6, and your experience becomes 7 + 6 = 13.
+  
+- You have more energy and experience than the 2nd opponent so you win.
+
+  Your energy becomes 6 - 3 = 3, and your experience becomes 13 + 3 = 16.
+  
+- You have more energy and experience than the 3rd opponent so you win.
+
+  Your energy becomes 3 - 2 = 1, and your experience becomes 16 + 1 = 17.
+  
+You did a total of 6 + 2 = 8 hours of training before the competition, so we return 8.
+
+It can be proven that no smaller answer exists. 
+
+**Example 2:**
+
+**Input:** initialEnergy = 2, initialExperience = 4, energy = [1], experience = [3]
+
+**Output:** 0
+
+**Explanation:** You do not need any additional energy or experience to win the competition, so we return 0. 
+
+**Constraints:**
+
+*   `n == energy.length == experience.length`
+*   `1 <= n <= 100`
+*   `1 <= initialEnergy, initialExperience, energy[i], experience[i] <= 100`
+
+## Solution
+
+```kotlin
+class Solution {
+    fun minNumberOfHours(
+        initialEnergy: Int,
+        initialExperience: Int,
+        energy: IntArray,
+        experience: IntArray
+    ): Int {
+        var totalEnergy = 0
+        for (e in energy) {
+            totalEnergy += e
+        }
+        var result = Math.max(0, totalEnergy - initialEnergy + 1)
+        var currentExp = initialExperience
+        var exp: Int
+        for (i in 0 until experience.size - 1) {
+            exp = experience[i]
+            if (currentExp <= exp) {
+                result += exp - currentExp + 1
+                currentExp = exp + 1
+            }
+            currentExp += exp
+        }
+        val last = experience[experience.size - 1]
+        if (currentExp <= last) {
+            result += last - currentExp + 1
+        }
+        return result
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2384_largest_palindromic_number/readme.md b/src/main/kotlin/g2301_2400/s2384_largest_palindromic_number/readme.md
new file mode 100644
index 00000000..299c630a
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2384_largest_palindromic_number/readme.md
@@ -0,0 +1,79 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2384\. Largest Palindromic Number
+
+Medium
+
+You are given a string `num` consisting of digits only.
+
+Return _the **largest palindromic** integer (in the form of a string) that can be formed using digits taken from_ `num`. It should not contain **leading zeroes**.
+
+**Notes:**
+
+*   You do **not** need to use all the digits of `num`, but you must use **at least** one digit.
+*   The digits can be reordered.
+
+**Example 1:**
+
+**Input:** num = "444947137"
+
+**Output:** "7449447"
+
+**Explanation:**
+
+Use the digits "4449477" from "**44494****7**13**7**" to form the palindromic integer "7449447".
+
+It can be shown that "7449447" is the largest palindromic integer that can be formed.
+
+**Example 2:**
+
+**Input:** num = "00009"
+
+**Output:** "9"
+
+**Explanation:**
+
+It can be shown that "9" is the largest palindromic integer that can be formed.
+
+Note that the integer returned should not contain leading zeroes.
+
+**Constraints:**
+
+*   1 <= num.length <= 105
+*   `num` consists of digits.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun largestPalindromic(num: String): String {
+        val count = IntArray(10)
+        var center = -1
+        val first = StringBuilder()
+        for (c in num.toCharArray()) {
+            count[c.code - '0'.code]++
+        }
+        var c: Int
+        for (i in 9 downTo 0) {
+            c = 0
+            if (count[i] % 2 == 1 && center == -1) {
+                center = i
+            }
+            if (first.length == 0 && i == 0) {
+                continue
+            }
+            while (c < count[i] / 2) {
+                first.append(i.toString())
+                c++
+            }
+        }
+        val second: StringBuilder = StringBuilder(first.toString())
+        if (center != -1) {
+            first.append(center)
+        }
+        first.append(second.reverse().toString())
+        return if (first.length == 0) "0" else first.toString()
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2385_amount_of_time_for_binary_tree_to_be_infected/readme.md b/src/main/kotlin/g2301_2400/s2385_amount_of_time_for_binary_tree_to_be_infected/readme.md
new file mode 100644
index 00000000..74a460b9
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2385_amount_of_time_for_binary_tree_to_be_infected/readme.md
@@ -0,0 +1,102 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2385\. Amount of Time for Binary Tree to Be Infected
+
+Medium
+
+You are given the `root` of a binary tree with **unique** values, and an integer `start`. At minute `0`, an **infection** starts from the node with value `start`.
+
+Each minute, a node becomes infected if:
+
+*   The node is currently uninfected.
+*   The node is adjacent to an infected node.
+
+Return _the number of minutes needed for the entire tree to be infected._
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/06/25/image-20220625231744-1.png)
+
+**Input:** root = [1,5,3,null,4,10,6,9,2], start = 3
+
+**Output:** 4
+
+**Explanation:** The following nodes are infected during:
+
+- Minute 0: Node 3
+
+- Minute 1: Nodes 1, 10 and 6
+
+- Minute 2: Node 5
+
+- Minute 3: Node 4
+
+- Minute 4: Nodes 9 and 2
+
+It takes 4 minutes for the whole tree to be infected so we return 4. 
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2022/06/25/image-20220625231812-2.png)
+
+**Input:** root = [1], start = 1
+
+**Output:** 0
+
+**Explanation:** At minute 0, the only node in the tree is infected so we return 0. 
+
+**Constraints:**
+
+*   The number of nodes in the tree is in the range [1, 105].
+*   1 <= Node.val <= 105
+*   Each node has a **unique** value.
+*   A node with a value of `start` exists in the tree.
+
+## Solution
+
+```kotlin
+import com_github_leetcode.TreeNode
+
+/*
+ * Example:
+ * var ti = TreeNode(5)
+ * var v = ti.`val`
+ * Definition for a binary tree node.
+ * class TreeNode(var `val`: Int) {
+ *     var left: TreeNode? = null
+ *     var right: TreeNode? = null
+ * }
+ */
+class Solution {
+    private var max = 0
+    fun amountOfTime(root: TreeNode?, start: Int): Int {
+        dfs(root, start, Distance(-1))
+        return max
+    }
+
+    private fun dfs(root: TreeNode?, start: Int, l: Distance): Int {
+        if (root == null) {
+            return 0
+        }
+        val ld = Distance(-1)
+        val rd = Distance(-1)
+        val left = dfs(root.left, start, ld)
+        val right = dfs(root.right, start, rd)
+        if (l.`val` == -1 && start == root.`val`) {
+            max = Math.max(left, right)
+            l.`val` = 1
+        }
+        if (ld.`val` != -1) {
+            max = Math.max(max, ld.`val` + right)
+            l.`val` = ld.`val` + 1
+        } else if (rd.`val` != -1) {
+            max = Math.max(max, rd.`val` + left)
+            l.`val` = rd.`val` + 1
+        }
+        return Math.max(left, right) + 1
+    }
+
+    private class Distance internal constructor(var `val`: Int)
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2386_find_the_k_sum_of_an_array/readme.md b/src/main/kotlin/g2301_2400/s2386_find_the_k_sum_of_an_array/readme.md
new file mode 100644
index 00000000..c1f8f0d0
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2386_find_the_k_sum_of_an_array/readme.md
@@ -0,0 +1,83 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2386\. Find the K-Sum of an Array
+
+Hard
+
+You are given an integer array `nums` and a **positive** integer `k`. You can choose any **subsequence** of the array and sum all of its elements together.
+
+We define the **K-Sum** of the array as the kth **largest** subsequence sum that can be obtained (**not** necessarily distinct).
+
+Return _the K-Sum of the array_.
+
+A **subsequence** is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.
+
+**Note** that the empty subsequence is considered to have a sum of `0`.
+
+**Example 1:**
+
+**Input:** nums = [2,4,-2], k = 5
+
+**Output:** 2
+
+**Explanation:** All the possible subsequence sums that we can obtain are the following sorted in decreasing order:
+
+- 6, 4, 4, 2, 2, 0, 0, -2.
+
+The 5-Sum of the array is 2. 
+
+**Example 2:**
+
+**Input:** nums = [1,-2,3,4,-10,12], k = 16
+
+**Output:** 10
+
+**Explanation:** The 16-Sum of the array is 10. 
+
+**Constraints:**
+
+*   `n == nums.length`
+*   1 <= n <= 105
+*   -109 <= nums[i] <= 109
+*   1 <= k <= min(2000, 2n)
+
+## Solution
+
+```kotlin
+import java.util.PriorityQueue
+
+@Suppress("NAME_SHADOWING")
+class Solution {
+    fun kSum(nums: IntArray, k: Int): Long {
+        var k = k
+        var sum = 0L
+        for (i in nums.indices) {
+            if (nums[i] > 0) {
+                sum += nums[i].toLong()
+            } else {
+                nums[i] = -nums[i]
+            }
+        }
+        nums.sort()
+        val pq = PriorityQueue { a: Pair, b: Pair ->
+            b.key.compareTo(a.key)
+        }
+        pq.offer(Pair(sum, 0))
+        while (k-- > 1) {
+            val top = pq.poll()
+            val s: Long = top.key
+            val i: Int = top.value
+            if (i < nums.size) {
+                pq.offer(Pair(s - nums[i], i + 1))
+                if (i > 0) {
+                    pq.offer(Pair(s - nums[i] + nums[i - 1], i + 1))
+                }
+            }
+        }
+        return pq.peek().key
+    }
+
+    private class Pair(var key: K, var value: V)
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2389_longest_subsequence_with_limited_sum/readme.md b/src/main/kotlin/g2301_2400/s2389_longest_subsequence_with_limited_sum/readme.md
new file mode 100644
index 00000000..e7f8a96d
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2389_longest_subsequence_with_limited_sum/readme.md
@@ -0,0 +1,63 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2389\. Longest Subsequence With Limited Sum
+
+Easy
+
+You are given an integer array `nums` of length `n`, and an integer array `queries` of length `m`.
+
+Return _an array_ `answer` _of length_ `m` _where_ `answer[i]` _is the **maximum** size of a **subsequence** that you can take from_ `nums` _such that the **sum** of its elements is less than or equal to_ `queries[i]`.
+
+A **subsequence** is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.
+
+**Example 1:**
+
+**Input:** nums = [4,5,2,1], queries = [3,10,21]
+
+**Output:** [2,3,4]
+
+**Explanation:** We answer the queries as follows:
+
+- The subsequence [2,1] has a sum less than or equal to 3. It can be proven that 2 is the maximum size of such a subsequence, so answer[0] = 2.
+
+- The subsequence [4,5,1] has a sum less than or equal to 10. It can be proven that 3 is the maximum size of such a subsequence, so answer[1] = 3.
+
+- The subsequence [4,5,2,1] has a sum less than or equal to 21. It can be proven that 4 is the maximum size of such a subsequence, so answer[2] = 4. 
+
+**Example 2:**
+
+**Input:** nums = [2,3,4,5], queries = [1]
+
+**Output:** [0]
+
+**Explanation:** The empty subsequence is the only subsequence that has a sum less than or equal to 1, so answer[0] = 0.
+
+**Constraints:**
+
+*   `n == nums.length`
+*   `m == queries.length`
+*   `1 <= n, m <= 1000`
+*   1 <= nums[i], queries[i] <= 106
+
+## Solution
+
+```kotlin
+class Solution {
+    fun answerQueries(nums: IntArray, queries: IntArray): IntArray {
+        // we can sort the nums because the order of the subsequence does not matter
+        nums.sort()
+        for (i in 1 until nums.size) {
+            nums[i] = nums[i] + nums[i - 1]
+        }
+        for (i in queries.indices) {
+            var j = nums.binarySearch(queries[i])
+            if (j < 0) {
+                j = -j - 2
+            }
+            queries[i] = j + 1
+        }
+        return queries
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2390_removing_stars_from_a_string/readme.md b/src/main/kotlin/g2301_2400/s2390_removing_stars_from_a_string/readme.md
new file mode 100644
index 00000000..e6d90e7f
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2390_removing_stars_from_a_string/readme.md
@@ -0,0 +1,71 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2390\. Removing Stars From a String
+
+Medium
+
+You are given a string `s`, which contains stars `*`.
+
+In one operation, you can:
+
+*   Choose a star in `s`.
+*   Remove the closest **non-star** character to its **left**, as well as remove the star itself.
+
+Return _the string after **all** stars have been removed_.
+
+**Note:**
+
+*   The input will be generated such that the operation is always possible.
+*   It can be shown that the resulting string will always be unique.
+
+**Example 1:**
+
+**Input:** s = "leet\*\*cod\*e"
+
+**Output:** "lecoe"
+
+**Explanation:** Performing the removals from left to right:
+
+- The closest character to the 1st star is 't' in "lee**t**\*\*cod\*e". s becomes "lee\*cod\*e".
+
+- The closest character to the 2nd star is 'e' in "le**e**\*cod\*e". s becomes "lecod\*e".
+
+- The closest character to the 3rd star is 'd' in "leco**d**\*e". s becomes "lecoe".
+
+There are no more stars, so we return "lecoe".
+
+**Example 2:**
+
+**Input:** s = "erase\*\*\*\*\*"
+
+**Output:** ""
+
+**Explanation:** The entire string is removed, so we return an empty string. 
+
+**Constraints:**
+
+*   1 <= s.length <= 105
+*   `s` consists of lowercase English letters and stars `*`.
+*   The operation above can be performed on `s`.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun removeStars(s: String): String {
+        val sb = StringBuilder()
+        var stars = 0
+        for (i in s.length - 1 downTo 0) {
+            if (s[i] == '*') {
+                ++stars
+            } else if (stars > 0) {
+                --stars
+            } else {
+                sb.append(s[i])
+            }
+        }
+        return sb.reverse().toString()
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2391_minimum_amount_of_time_to_collect_garbage/readme.md b/src/main/kotlin/g2301_2400/s2391_minimum_amount_of_time_to_collect_garbage/readme.md
new file mode 100644
index 00000000..9901dfc2
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2391_minimum_amount_of_time_to_collect_garbage/readme.md
@@ -0,0 +1,113 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2391\. Minimum Amount of Time to Collect Garbage
+
+Medium
+
+You are given a **0-indexed** array of strings `garbage` where `garbage[i]` represents the assortment of garbage at the ith house. `garbage[i]` consists only of the characters `'M'`, `'P'` and `'G'` representing one unit of metal, paper and glass garbage respectively. Picking up **one** unit of any type of garbage takes `1` minute.
+
+You are also given a **0-indexed** integer array `travel` where `travel[i]` is the number of minutes needed to go from house `i` to house `i + 1`.
+
+There are three garbage trucks in the city, each responsible for picking up one type of garbage. Each garbage truck starts at house `0` and must visit each house **in order**; however, they do **not** need to visit every house.
+
+Only **one** garbage truck may be used at any given moment. While one truck is driving or picking up garbage, the other two trucks **cannot** do anything.
+
+Return _the **minimum** number of minutes needed to pick up all the garbage._
+
+**Example 1:**
+
+**Input:** garbage = ["G","P","GP","GG"], travel = [2,4,3]
+
+**Output:** 21
+
+**Explanation:**
+
+The paper garbage truck:
+
+1. Travels from house 0 to house 1
+
+2. Collects the paper garbage at house 1
+
+3. Travels from house 1 to house 2
+
+4. Collects the paper garbage at house 2 Altogether, it takes 8 minutes to pick up all the paper garbage.
+
+The glass garbage truck:
+
+1. Collects the glass garbage at house 0
+
+2. Travels from house 0 to house 1
+
+3. Travels from house 1 to house 2
+
+4. Collects the glass garbage at house 2
+
+5. Travels from house 2 to house 3
+
+6. Collects the glass garbage at house 3
+
+Altogether, it takes 13 minutes to pick up all the glass garbage.
+
+Since there is no metal garbage, we do not need to consider the metal garbage truck.
+
+Therefore, it takes a total of 8 + 13 = 21 minutes to collect all the garbage. 
+
+**Example 2:**
+
+**Input:** garbage = ["MMM","PGM","GP"], travel = [3,10]
+
+**Output:** 37
+
+**Explanation:**
+
+The metal garbage truck takes 7 minutes to pick up all the metal garbage.
+
+The paper garbage truck takes 15 minutes to pick up all the paper garbage.
+
+The glass garbage truck takes 15 minutes to pick up all the glass garbage.
+
+It takes a total of 7 + 15 + 15 = 37 minutes to collect all the garbage. 
+
+**Constraints:**
+
+*   2 <= garbage.length <= 105
+*   `garbage[i]` consists of only the letters `'M'`, `'P'`, and `'G'`.
+*   `1 <= garbage[i].length <= 10`
+*   `travel.length == garbage.length - 1`
+*   `1 <= travel[i] <= 100`
+
+## Solution
+
+```kotlin
+class Solution {
+    fun garbageCollection(garbage: Array, travel: IntArray): Int {
+        var cTime = 0
+        for (str in garbage) {
+            cTime += str.length
+        }
+        val n = travel.size
+        for (i in 1 until n) {
+            travel[i] += travel[i - 1]
+        }
+        val mT = getMostTra(garbage, 'M')
+        val pT = getMostTra(garbage, 'P')
+        val gT = getMostTra(garbage, 'G')
+        val m = if (mT <= 0) 0 else travel[mT - 1]
+        val p = if (pT <= 0) 0 else travel[pT - 1]
+        val g = if (gT <= 0) 0 else travel[gT - 1]
+        val tTime = m + p + g
+        return cTime + tTime
+    }
+
+    private fun getMostTra(garbage: Array, c: Char): Int {
+        val n = garbage.size
+        for (i in n - 1 downTo 0) {
+            if (garbage[i].indexOf(c) != -1) {
+                return i
+            }
+        }
+        return -1
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2392_build_a_matrix_with_conditions/readme.md b/src/main/kotlin/g2301_2400/s2392_build_a_matrix_with_conditions/readme.md
new file mode 100644
index 00000000..4375475d
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2392_build_a_matrix_with_conditions/readme.md
@@ -0,0 +1,143 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2392\. Build a Matrix With Conditions
+
+Hard
+
+You are given a **positive** integer `k`. You are also given:
+
+*   a 2D integer array `rowConditions` of size `n` where rowConditions[i] = [abovei, belowi], and
+*   a 2D integer array `colConditions` of size `m` where colConditions[i] = [lefti, righti].
+
+The two arrays contain integers from `1` to `k`.
+
+You have to build a `k x k` matrix that contains each of the numbers from `1` to `k` **exactly once**. The remaining cells should have the value `0`.
+
+The matrix should also satisfy the following conditions:
+
+*   The number abovei should appear in a **row** that is strictly **above** the row at which the number belowi appears for all `i` from `0` to `n - 1`.
+*   The number lefti should appear in a **column** that is strictly **left** of the column at which the number righti appears for all `i` from `0` to `m - 1`.
+
+Return _**any** matrix that satisfies the conditions_. If no answer exists, return an empty matrix.
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/07/06/gridosdrawio.png)
+
+**Input:** k = 3, rowConditions = \[\[1,2],[3,2]], colConditions = \[\[2,1],[3,2]]
+
+**Output:** [[3,0,0],[0,0,1],[0,2,0]]
+
+**Explanation:** The diagram above shows a valid example of a matrix that satisfies all the conditions.
+
+The row conditions are the following:
+
+- Number 1 is in row 1, and number 2 is in row 2, so 1 is above 2 in the matrix.
+
+- Number 3 is in row 0, and number 2 is in row 2, so 3 is above 2 in the matrix.
+
+The column conditions are the following:
+
+- Number 2 is in column 1, and number 1 is in column 2, so 2 is left of 1 in the matrix.
+
+- Number 3 is in column 0, and number 2 is in column 1, so 3 is left of 2 in the matrix.
+
+Note that there may be multiple correct answers. 
+
+**Example 2:**
+
+**Input:** k = 3, rowConditions = \[\[1,2],[2,3],[3,1],[2,3]], colConditions = \[\[2,1]]
+
+**Output:** []
+
+**Explanation:** From the first two conditions, 3 has to be below 1 but the third conditions needs 3 to be above 1 to be satisfied.
+
+No matrix can satisfy all the conditions, so we return the empty matrix. 
+
+**Constraints:**
+
+*   `2 <= k <= 400`
+*   1 <= rowConditions.length, colConditions.length <= 104
+*   `rowConditions[i].length == colConditions[i].length == 2`
+*   1 <= abovei, belowi, lefti, righti <= k
+*   abovei != belowi
+*   lefti != righti
+
+## Solution
+
+```kotlin
+import java.util.LinkedList
+import java.util.Queue
+
+class Solution {
+    // Using topological sort to solve this problem
+    fun buildMatrix(k: Int, rowConditions: Array, colConditions: Array): Array {
+        // First, get the topo-sorted of row and col
+        val row = toposort(k, rowConditions)
+        val col = toposort(k, colConditions)
+        // base case: when the length of row or col is less than k, return empty.
+        // That is: there is a loop in established graph
+        if (row.size < k || col.size < k) {
+            return Array(0) { IntArray(0) }
+        }
+        val res = Array(k) { IntArray(k) }
+        val map: MutableMap = HashMap()
+        for (i in 0 until k) {
+            // we record the number corresbonding to each column:
+            // [number, column index]
+            map[col[i]] = i
+        }
+        // col: 3 2 1
+        // row: 1 3 2
+        for (i in 0 until k) {
+            // For each row: we have number row.get(i). And we need to know
+            // which column we need to assign, which is from map.get(row.get(i))
+            // known by map.get()
+            res[i][map[row[i]]!!] = row[i]
+        }
+        return res
+    }
+
+    private fun toposort(k: Int, matrix: Array): List {
+        // need a int[] to record the indegree of each number [1, k]
+        val deg = IntArray(k + 1)
+        // need a list to record the order of each number, then return this list
+        val res: MutableList = ArrayList()
+        // need a 2-D list to be the graph, and fill the graph
+        val graph: MutableList> = ArrayList()
+        for (i in 0 until k) {
+            graph.add(ArrayList())
+        }
+        // need a queue to do the BFS
+        val queue: Queue = LinkedList()
+        // First, we need to establish the graph, following the given matrix
+        for (a in matrix) {
+            val from = a[0]
+            val to = a[1]
+            graph[from - 1].add(to)
+            deg[to]++
+        }
+        // Second, after building a graph, we start the bfs,
+        // that is, traverse the node with 0 degree
+        for (i in 1..k) {
+            if (deg[i] == 0) {
+                queue.offer(i)
+                res.add(i)
+            }
+        }
+        // Third, start the topo sort
+        while (queue.isNotEmpty()) {
+            val node = queue.poll()
+            val list: List = graph[node - 1]
+            for (i in list) {
+                if (--deg[i] == 0) {
+                    queue.offer(i)
+                    res.add(i)
+                }
+            }
+        }
+        return res
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2395_find_subarrays_with_equal_sum/readme.md b/src/main/kotlin/g2301_2400/s2395_find_subarrays_with_equal_sum/readme.md
new file mode 100644
index 00000000..251071c6
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2395_find_subarrays_with_equal_sum/readme.md
@@ -0,0 +1,59 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2395\. Find Subarrays With Equal Sum
+
+Easy
+
+Given a **0-indexed** integer array `nums`, determine whether there exist **two** subarrays of length `2` with **equal** sum. Note that the two subarrays must begin at **different** indices.
+
+Return `true` _if these subarrays exist, and_ `false` _otherwise._
+
+A **subarray** is a contiguous non-empty sequence of elements within an array.
+
+**Example 1:**
+
+**Input:** nums = [4,2,4]
+
+**Output:** true
+
+**Explanation:** The subarrays with elements [4,2] and [2,4] have the same sum of 6. 
+
+**Example 2:**
+
+**Input:** nums = [1,2,3,4,5]
+
+**Output:** false
+
+**Explanation:** No two subarrays of size 2 have the same sum. 
+
+**Example 3:**
+
+**Input:** nums = [0,0,0]
+
+**Output:** true
+
+**Explanation:** The subarrays [nums[0],nums[1]] and [nums[1],nums[2]] have the same sum of 0.
+
+Note that even though the subarrays have the same content, the two subarrays are considered different because they are in different positions in the original array. 
+
+**Constraints:**
+
+*   `2 <= nums.length <= 1000`
+*   -109 <= nums[i] <= 109
+
+## Solution
+
+```kotlin
+class Solution {
+    fun findSubarrays(nums: IntArray): Boolean {
+        val set: MutableSet = HashSet()
+        for (i in 1 until nums.size) {
+            if (!set.add(nums[i] + nums[i - 1])) {
+                return true
+            }
+        }
+        return false
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2396_strictly_palindromic_number/readme.md b/src/main/kotlin/g2301_2400/s2396_strictly_palindromic_number/readme.md
new file mode 100644
index 00000000..fac6a684
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2396_strictly_palindromic_number/readme.md
@@ -0,0 +1,76 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2396\. Strictly Palindromic Number
+
+Medium
+
+An integer `n` is **strictly palindromic** if, for **every** base `b` between `2` and `n - 2` (**inclusive**), the string representation of the integer `n` in base `b` is **palindromic**.
+
+Given an integer `n`, return `true` _if_ `n` _is **strictly palindromic** and_ `false` _otherwise_.
+
+A string is **palindromic** if it reads the same forward and backward.
+
+**Example 1:**
+
+**Input:** n = 9
+
+**Output:** false
+
+**Explanation:** In base 2: 9 = 1001 (base 2), which is palindromic.
+
+In base 3: 9 = 100 (base 3), which is not palindromic.
+
+Therefore, 9 is not strictly palindromic so we return false.
+
+Note that in bases 4, 5, 6, and 7, n = 9 is also not palindromic. 
+
+**Example 2:**
+
+**Input:** n = 4
+
+**Output:** false
+
+**Explanation:** We only consider base 2: 4 = 100 (base 2), which is not palindromic.
+
+Therefore, we return false. 
+
+**Constraints:**
+
+*   4 <= n <= 105
+
+## Solution
+
+```kotlin
+class Solution {
+    fun isStrictlyPalindromic(n: Int): Boolean {
+        for (i in 2..n - 2) {
+            val num = Integer.toString(i)
+            val s = baseConversion(num, 10, i)
+            if (!checkPalindrome(s)) {
+                return false
+            }
+        }
+        return true
+    }
+
+    private fun baseConversion(number: String, sBase: Int, dBase: Int): String {
+        // Parse the number with source radix
+        // and return in specified radix(base)
+        return Integer.toString(number.toInt(sBase), dBase)
+    }
+
+    private fun checkPalindrome(s: String): Boolean {
+        var start = 0
+        var end = s.length - 1
+        while (start <= end) {
+            if (s[start] != s[end]) {
+                return false
+            }
+            start++
+            end--
+        }
+        return true
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2397_maximum_rows_covered_by_columns/readme.md b/src/main/kotlin/g2301_2400/s2397_maximum_rows_covered_by_columns/readme.md
new file mode 100644
index 00000000..62b32fab
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2397_maximum_rows_covered_by_columns/readme.md
@@ -0,0 +1,104 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2397\. Maximum Rows Covered by Columns
+
+Medium
+
+You are given a **0-indexed** `m x n` binary matrix `matrix` and an integer `numSelect`, which denotes the number of **distinct** columns you must select from `matrix`.
+
+Let us consider s = {c1, c2, ...., cnumSelect} as the set of columns selected by you. A row `row` is **covered** by `s` if:
+
+*   For each cell `matrix[row][col]` (`0 <= col <= n - 1`) where `matrix[row][col] == 1`, `col` is present in `s` or,
+*   **No cell** in `row` has a value of `1`.
+
+You need to choose `numSelect` columns such that the number of rows that are covered is **maximized**.
+
+Return _the **maximum** number of rows that can be **covered** by a set of_ `numSelect` _columns._
+
+**Example 1:**
+
+![](https://assets.leetcode.com/uploads/2022/07/14/rowscovered.png)
+
+**Input:** matrix = \[\[0,0,0],[1,0,1],[0,1,1],[0,0,1]], numSelect = 2
+
+**Output:** 3
+
+**Explanation:** One possible way to cover 3 rows is shown in the diagram above.
+
+We choose s = {0, 2}.
+
+- Row 0 is covered because it has no occurrences of 1.
+
+- Row 1 is covered because the columns with value 1, i.e. 0 and 2 are present in s.
+
+- Row 2 is not covered because matrix[2][1] == 1 but 1 is not present in s.
+
+- Row 3 is covered because matrix[2][2] == 1 and 2 is present in s.
+
+Thus, we can cover three rows.
+
+Note that s = {1, 2} will also cover 3 rows, but it can be shown that no more than three rows can be covered. 
+
+**Example 2:**
+
+![](https://assets.leetcode.com/uploads/2022/07/14/rowscovered2.png)
+
+**Input:** matrix = \[\[1],[0]], numSelect = 1
+
+**Output:** 2
+
+**Explanation:** Selecting the only column will result in both rows being covered since the entire matrix is selected.
+
+Therefore, we return 2. 
+
+**Constraints:**
+
+*   `m == matrix.length`
+*   `n == matrix[i].length`
+*   `1 <= m, n <= 12`
+*   `matrix[i][j]` is either `0` or `1`.
+*   `1 <= numSelect <= n`
+
+## Solution
+
+```kotlin
+class Solution {
+    private var ans = 0
+    fun maximumRows(matrix: Array, numSelect: Int): Int {
+        dfs(matrix, /*colIndex=*/0, numSelect, /*mask=*/0)
+        return ans
+    }
+
+    private fun dfs(matrix: Array, colIndex: Int, leftColsCount: Int, mask: Int) {
+        if (leftColsCount == 0) {
+            ans = Math.max(ans, getAllZerosRowCount(matrix, mask))
+            return
+        }
+        if (colIndex == matrix[0].size) {
+            return
+        }
+        // choose this column
+        dfs(matrix, colIndex + 1, leftColsCount - 1, mask or (1 shl colIndex))
+        // not choose this column
+        dfs(matrix, colIndex + 1, leftColsCount, mask)
+    }
+
+    private fun getAllZerosRowCount(matrix: Array, mask: Int): Int {
+        var count = 0
+        for (row in matrix) {
+            var isAllZeros = true
+            for (i in row.indices) {
+                if (row[i] == 1 && mask shr i and 1 == 0) {
+                    isAllZeros = false
+                    break
+                }
+            }
+            if (isAllZeros) {
+                ++count
+            }
+        }
+        return count
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2398_maximum_number_of_robots_within_budget/readme.md b/src/main/kotlin/g2301_2400/s2398_maximum_number_of_robots_within_budget/readme.md
new file mode 100644
index 00000000..6245e644
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2398_maximum_number_of_robots_within_budget/readme.md
@@ -0,0 +1,88 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2398\. Maximum Number of Robots Within Budget
+
+Hard
+
+You have `n` robots. You are given two **0-indexed** integer arrays, `chargeTimes` and `runningCosts`, both of length `n`. The ith robot costs `chargeTimes[i]` units to charge and costs `runningCosts[i]` units to run. You are also given an integer `budget`.
+
+The **total cost** of running `k` chosen robots is equal to `max(chargeTimes) + k * sum(runningCosts)`, where `max(chargeTimes)` is the largest charge cost among the `k` robots and `sum(runningCosts)` is the sum of running costs among the `k` robots.
+
+Return _the **maximum** number of **consecutive** robots you can run such that the total cost **does not** exceed_ `budget`.
+
+**Example 1:**
+
+**Input:** chargeTimes = [3,6,1,3,4], runningCosts = [2,1,3,4,5], budget = 25
+
+**Output:** 3
+
+**Explanation:**
+
+It is possible to run all individual and consecutive pairs of robots within budget.
+
+To obtain answer 3, consider the first 3 robots. The total cost will be max(3,6,1) + 3 \* sum(2,1,3) = 6 + 3 \* 6 = 24 which is less than 25.
+
+It can be shown that it is not possible to run more than 3 consecutive robots within budget, so we return 3. 
+
+**Example 2:**
+
+**Input:** chargeTimes = [11,12,19], runningCosts = [10,8,7], budget = 19
+
+**Output:** 0
+
+**Explanation:** No robot can be run that does not exceed the budget, so we return 0. 
+
+**Constraints:**
+
+*   `chargeTimes.length == runningCosts.length == n`
+*   1 <= n <= 5 * 104
+*   1 <= chargeTimes[i], runningCosts[i] <= 105
+*   1 <= budget <= 1015
+
+## Solution
+
+```kotlin
+class Solution {
+    // use sliding window to track the largest in a way that the sliding window only grows.
+    //   then the maximum size is the size of the sliding window at the end.
+    // if condition is met, we just grow the sliding window.
+    // if condition is not met, we shift the sliding window with the same size to the next position.
+    // e.g., if [0,3] is valid, next time we will try [0,4].
+    //       if [0,3] is invalid, next time we will try [1,4],
+    //         by adjusting the window to [1,3] first in the current round.
+    fun maximumRobots(chargeTimes: IntArray, runningCosts: IntArray, budget: Long): Int {
+        val n = chargeTimes.size
+        // [front, end).
+        val deque = IntArray(n)
+        var front = 0
+        var end = 0
+        var sum: Long = 0
+        var left = 0
+        var right = 0
+        while (right < n) {
+
+            // add right into the sliding window, so the window becomes [left, right].
+            // update sliding window max and window sum.
+            while (end - front > 0 && chargeTimes[deque[end - 1]] <= chargeTimes[right]) {
+                --end
+            }
+            deque[end++] = right
+            sum += runningCosts[right].toLong()
+            // if the condition is met in the window, do nothing,
+            // so the next window size will become one larger.
+            // if the condition is not met in the window, shrink one from the front,
+            // so the next window size will stay the same.
+            if (chargeTimes[deque[front]] + (right - left + 1) * sum > budget) {
+                while (end - front > 0 && deque[front] <= left) {
+                    ++front
+                }
+                sum -= runningCosts[left].toLong()
+                ++left
+            }
+            ++right
+        }
+        return right - left
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2399_check_distances_between_same_letters/readme.md b/src/main/kotlin/g2301_2400/s2399_check_distances_between_same_letters/readme.md
new file mode 100644
index 00000000..9e4aaabe
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2399_check_distances_between_same_letters/readme.md
@@ -0,0 +1,75 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2399\. Check Distances Between Same Letters
+
+Easy
+
+You are given a **0-indexed** string `s` consisting of only lowercase English letters, where each letter in `s` appears **exactly** **twice**. You are also given a **0-indexed** integer array `distance` of length `26`.
+
+Each letter in the alphabet is numbered from `0` to `25` (i.e. `'a' -> 0`, `'b' -> 1`, `'c' -> 2`, ... , `'z' -> 25`).
+
+In a **well-spaced** string, the number of letters between the two occurrences of the ith letter is `distance[i]`. If the ith letter does not appear in `s`, then `distance[i]` can be **ignored**.
+
+Return `true` _if_ `s` _is a **well-spaced** string, otherwise return_ `false`.
+
+**Example 1:**
+
+**Input:** s = "abaccb", distance = [1,3,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
+
+**Output:** true
+
+**Explanation:**
+
+- 'a' appears at indices 0 and 2 so it satisfies distance[0] = 1.
+
+- 'b' appears at indices 1 and 5 so it satisfies distance[1] = 3.
+
+- 'c' appears at indices 3 and 4 so it satisfies distance[2] = 0.
+
+Note that distance[3] = 5, but since 'd' does not appear in s, it can be ignored.
+
+Return true because s is a well-spaced string. 
+
+**Example 2:**
+
+**Input:** s = "aa", distance = [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
+
+**Output:** false
+
+**Explanation:**
+
+- 'a' appears at indices 0 and 1 so there are zero letters between them. Because distance[0] = 1, s is not a well-spaced string. 
+
+**Constraints:**
+
+*   `2 <= s.length <= 52`
+*   `s` consists only of lowercase English letters.
+*   Each letter appears in `s` exactly twice.
+*   `distance.length == 26`
+*   `0 <= distance[i] <= 50`
+
+## Solution
+
+```kotlin
+class Solution {
+    fun checkDistances(s: String, distance: IntArray): Boolean {
+        val seenFirstIndexYet = BooleanArray(26)
+        for (idxIntoS in 0 until s.length) {
+            val c = s[idxIntoS]
+            if (!seenFirstIndexYet[c.code - 'a'.code]) {
+                seenFirstIndexYet[c.code - 'a'.code] = true
+                distance[c.code - 'a'.code] += idxIntoS
+            } else {
+                // seenFirstIndexYet[c - 'a']
+                distance[c.code - 'a'.code] -= idxIntoS
+                if (distance[c.code - 'a'.code] != -1) {
+                    // early return
+                    return false
+                }
+            }
+        }
+        return true
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2301_2400/s2400_number_of_ways_to_reach_a_position_after_exactly_k_steps/readme.md b/src/main/kotlin/g2301_2400/s2400_number_of_ways_to_reach_a_position_after_exactly_k_steps/readme.md
new file mode 100644
index 00000000..84991848
--- /dev/null
+++ b/src/main/kotlin/g2301_2400/s2400_number_of_ways_to_reach_a_position_after_exactly_k_steps/readme.md
@@ -0,0 +1,74 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2400\. Number of Ways to Reach a Position After Exactly k Steps
+
+Medium
+
+You are given two **positive** integers `startPos` and `endPos`. Initially, you are standing at position `startPos` on an **infinite** number line. With one step, you can move either one position to the left, or one position to the right.
+
+Given a positive integer `k`, return _the number of **different** ways to reach the position_ `endPos` _starting from_ `startPos`_, such that you perform **exactly**_ `k` _steps_. Since the answer may be very large, return it **modulo** 109 + 7.
+
+Two ways are considered different if the order of the steps made is not exactly the same.
+
+**Note** that the number line includes negative integers.
+
+**Example 1:**
+
+**Input:** startPos = 1, endPos = 2, k = 3
+
+**Output:** 3
+
+**Explanation:** We can reach position 2 from 1 in exactly 3 steps in three ways:
+
+- 1 -> 2 -> 3 -> 2.
+
+- 1 -> 2 -> 1 -> 2.
+
+- 1 -> 0 -> 1 -> 2.
+
+It can be proven that no other way is possible, so we return 3.
+
+**Example 2:**
+
+**Input:** startPos = 2, endPos = 5, k = 10
+
+**Output:** 0
+
+**Explanation:** It is impossible to reach position 5 from position 2 in exactly 10 steps. 
+
+**Constraints:**
+
+*   `1 <= startPos, endPos, k <= 1000`
+
+## Solution
+
+```kotlin
+class Solution {
+    private val mod = 1000000007
+
+    fun numberOfWays(startPos: Int, endPos: Int, k: Int): Int {
+        if (Math.abs(endPos - startPos) > k) {
+            return 0
+        }
+        if (Math.abs(endPos - startPos + k) % 2 != 0) {
+            return 0
+        }
+        val t = endPos - startPos
+        val right = (k + t) / 2
+        val min = Math.min(right, k - right)
+        if (min == 0) {
+            return 1
+        }
+        val rev = IntArray(min + 1)
+        rev[1] = 1
+        var ans = k
+        for (i in 2..min) {
+            rev[i] = ((mod - mod / i).toLong() * rev[mod % i].toLong() % mod).toInt()
+            ans = (ans.toLong() * (k - i + 1).toLong() % mod).toInt()
+            ans = (ans.toLong() * rev[i].toLong() % mod).toInt()
+        }
+        return ans
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2401_2500/s2401_longest_nice_subarray/readme.md b/src/main/kotlin/g2401_2500/s2401_longest_nice_subarray/readme.md
new file mode 100644
index 00000000..b602c4b7
--- /dev/null
+++ b/src/main/kotlin/g2401_2500/s2401_longest_nice_subarray/readme.md
@@ -0,0 +1,70 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2401\. Longest Nice Subarray
+
+Medium
+
+You are given an array `nums` consisting of **positive** integers.
+
+We call a subarray of `nums` **nice** if the bitwise **AND** of every pair of elements that are in **different** positions in the subarray is equal to `0`.
+
+Return _the length of the **longest** nice subarray_.
+
+A **subarray** is a **contiguous** part of an array.
+
+**Note** that subarrays of length `1` are always considered nice.
+
+**Example 1:**
+
+**Input:** nums = [1,3,8,48,10]
+
+**Output:** 3
+
+**Explanation:** The longest nice subarray is [3,8,48]. This subarray satisfies the conditions:
+
+- 3 AND 8 = 0.
+
+- 3 AND 48 = 0.
+
+- 8 AND 48 = 0.
+
+It can be proven that no longer nice subarray can be obtained, so we return 3.
+
+**Example 2:**
+
+**Input:** nums = [3,1,5,11,13]
+
+**Output:** 1
+
+**Explanation:** The length of the longest nice subarray is 1. Any subarray of length 1 can be chosen. 
+
+**Constraints:**
+
+*   1 <= nums.length <= 105
+*   1 <= nums[i] <= 109
+
+## Solution
+
+```kotlin
+class Solution {
+    fun longestNiceSubarray(nums: IntArray): Int {
+        var ans = 1
+        var left = 0
+        var right = 0
+        while (right < nums.size) {
+            for (i in right - 1 downTo left) {
+                if (nums[i] and nums[right] != 0) {
+                    left = i + 1
+                    break
+                }
+                if (i == left) {
+                    ans = ans.coerceAtLeast(right - left + 1)
+                }
+            }
+            right++
+        }
+        return ans
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2401_2500/s2402_meeting_rooms_iii/readme.md b/src/main/kotlin/g2401_2500/s2402_meeting_rooms_iii/readme.md
new file mode 100644
index 00000000..4a562070
--- /dev/null
+++ b/src/main/kotlin/g2401_2500/s2402_meeting_rooms_iii/readme.md
@@ -0,0 +1,122 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2402\. Meeting Rooms III
+
+Hard
+
+You are given an integer `n`. There are `n` rooms numbered from `0` to `n - 1`.
+
+You are given a 2D integer array `meetings` where meetings[i] = [starti, endi] means that a meeting will be held during the **half-closed** time interval [starti, endi). All the values of starti are **unique**.
+
+Meetings are allocated to rooms in the following manner:
+
+1.  Each meeting will take place in the unused room with the **lowest** number.
+2.  If there are no available rooms, the meeting will be delayed until a room becomes free. The delayed meeting should have the **same** duration as the original meeting.
+3.  When a room becomes unused, meetings that have an earlier original **start** time should be given the room.
+
+Return _the **number** of the room that held the most meetings._ If there are multiple rooms, return _the room with the **lowest** number._
+
+A **half-closed interval** `[a, b)` is the interval between `a` and `b` **including** `a` and **not including** `b`.
+
+**Example 1:**
+
+**Input:** n = 2, meetings = \[\[0,10],[1,5],[2,7],[3,4]]
+
+**Output:** 0
+
+**Explanation:**
+
+- At time 0, both rooms are not being used. The first meeting starts in room 0.
+
+- At time 1, only room 1 is not being used. The second meeting starts in room 1.
+
+- At time 2, both rooms are being used. The third meeting is delayed.
+
+- At time 3, both rooms are being used. The fourth meeting is delayed.
+
+- At time 5, the meeting in room 1 finishes. The third meeting starts in room 1 for the time period [5,10).
+
+- At time 10, the meetings in both rooms finish. The fourth meeting starts in room 0 for the time period [10,11).
+
+Both rooms 0 and 1 held 2 meetings, so we return 0. 
+
+**Example 2:**
+
+**Input:** n = 3, meetings = \[\[1,20],[2,10],[3,5],[4,9],[6,8]]
+
+**Output:** 1
+
+**Explanation:**
+
+- At time 1, all three rooms are not being used. The first meeting starts in room 0.
+
+- At time 2, rooms 1 and 2 are not being used. The second meeting starts in room 1.
+
+- At time 3, only room 2 is not being used. The third meeting starts in room 2.
+
+- At time 4, all three rooms are being used. The fourth meeting is delayed.
+
+- At time 5, the meeting in room 2 finishes. The fourth meeting starts in room 2 for the time period [5,10).
+
+- At time 6, all three rooms are being used. The fifth meeting is delayed.
+
+- At time 10, the meetings in rooms 1 and 2 finish. The fifth meeting starts in room 1 for the time period [10,12).
+
+Room 0 held 1 meeting while rooms 1 and 2 each held 2 meetings, so we return 1. 
+
+**Constraints:**
+
+*   `1 <= n <= 100`
+*   1 <= meetings.length <= 105
+*   `meetings[i].length == 2`
+*   0 <= starti < endi <= 5 * 105
+*   All the values of starti are **unique**.
+
+## Solution
+
+```kotlin
+import java.util.Arrays
+
+class Solution {
+    fun mostBooked(n: Int, meetings: Array): Int {
+        val counts = IntArray(n)
+        val endTimes = LongArray(n)
+        Arrays.sort(meetings) { a: IntArray, b: IntArray -> Integer.compare(a[0], b[0]) }
+        for (meeting in meetings) {
+            val id = findRoomId(endTimes, meeting[0])
+            counts[id]++
+            endTimes[id] = endTimes[id].coerceAtLeast(meeting[0].toLong()) + meeting[1] - meeting[0]
+        }
+        var res = 0
+        var count: Long = 0
+        for (i in 0 until n) {
+            if (counts[i] > count) {
+                count = counts[i].toLong()
+                res = i
+            }
+        }
+        return res
+    }
+
+    private fun findRoomId(endTimes: LongArray, start: Int): Int {
+        val n = endTimes.size
+        // Find the first one
+        for (i in 0 until n) {
+            if (endTimes[i] <= start) {
+                return i
+            }
+        }
+        // Only when non is not delayed, then we find the smallest one
+        var id = 0
+        var min = Long.MAX_VALUE
+        for (i in 0 until n) {
+            if (endTimes[i] < min) {
+                min = endTimes[i]
+                id = i
+            }
+        }
+        return id
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2401_2500/s2404_most_frequent_even_element/readme.md b/src/main/kotlin/g2401_2500/s2404_most_frequent_even_element/readme.md
new file mode 100644
index 00000000..3a112854
--- /dev/null
+++ b/src/main/kotlin/g2401_2500/s2404_most_frequent_even_element/readme.md
@@ -0,0 +1,77 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2404\. Most Frequent Even Element
+
+Easy
+
+Given an integer array `nums`, return _the most frequent even element_.
+
+If there is a tie, return the **smallest** one. If there is no such element, return `-1`.
+
+**Example 1:**
+
+**Input:** nums = [0,1,2,2,4,4,1]
+
+**Output:** 2
+
+**Explanation:**
+
+The even elements are 0, 2, and 4. Of these, 2 and 4 appear the most.
+
+We return the smallest one, which is 2.
+
+**Example 2:**
+
+**Input:** nums = [4,4,4,9,2,4]
+
+**Output:** 4
+
+**Explanation:** 4 is the even element appears the most. 
+
+**Example 3:**
+
+**Input:** nums = [29,47,21,41,13,37,25,7]
+
+**Output:** -1
+
+**Explanation:** There is no even element. 
+
+**Constraints:**
+
+*   `1 <= nums.length <= 2000`
+*   0 <= nums[i] <= 105
+
+## Solution
+
+```kotlin
+class Solution {
+    fun mostFrequentEven(nums: IntArray): Int {
+        val hm = HashMap()
+        var max = 0
+        var small = Int.MAX_VALUE
+
+        if (nums.size == 1) {
+            return if (nums[0] % 2 == 0) nums[0]
+            else -1
+        }
+
+        for (i in nums.indices) {
+            if (nums[i] % 2 == 0) {
+                hm[nums[i]] = hm.getOrDefault(nums[i], 0) + 1
+                if (hm[nums[i]]!! > max) {
+                    max = hm[nums[i]]!!
+                }
+            }
+        }
+
+        for ((key, value) in hm) {
+            if (value == max && key < small) {
+                small = key
+            }
+        }
+
+        return if (small == Int.MAX_VALUE) -1 else small
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2401_2500/s2405_optimal_partition_of_string/readme.md b/src/main/kotlin/g2401_2500/s2405_optimal_partition_of_string/readme.md
new file mode 100644
index 00000000..db4dd099
--- /dev/null
+++ b/src/main/kotlin/g2401_2500/s2405_optimal_partition_of_string/readme.md
@@ -0,0 +1,58 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2405\. Optimal Partition of String
+
+Medium
+
+Given a string `s`, partition the string into one or more **substrings** such that the characters in each substring are **unique**. That is, no letter appears in a single substring more than **once**.
+
+Return _the **minimum** number of substrings in such a partition._
+
+Note that each character should belong to exactly one substring in a partition.
+
+**Example 1:**
+
+**Input:** s = "abacaba"
+
+**Output:** 4
+
+**Explanation:**
+
+Two possible partitions are ("a","ba","cab","a") and ("ab","a","ca","ba").
+
+It can be shown that 4 is the minimum number of substrings needed. 
+
+**Example 2:**
+
+**Input:** s = "ssssss"
+
+**Output:** 6
+
+**Explanation:**
+
+The only valid partition is ("s","s","s","s","s","s"). 
+
+**Constraints:**
+
+*   1 <= s.length <= 105
+*   `s` consists of only English lowercase letters.
+
+## Solution
+
+```kotlin
+class Solution {
+    fun partitionString(s: String): Int {
+        var count = 1
+        var arr = BooleanArray(26)
+        for (c in s.toCharArray()) {
+            if (arr[c.code - 'a'.code]) {
+                count++
+                arr = BooleanArray(26)
+            }
+            arr[c.code - 'a'.code] = true
+        }
+        return count
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2401_2500/s2406_divide_intervals_into_minimum_number_of_groups/readme.md b/src/main/kotlin/g2401_2500/s2406_divide_intervals_into_minimum_number_of_groups/readme.md
new file mode 100644
index 00000000..523b9add
--- /dev/null
+++ b/src/main/kotlin/g2401_2500/s2406_divide_intervals_into_minimum_number_of_groups/readme.md
@@ -0,0 +1,69 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2406\. Divide Intervals Into Minimum Number of Groups
+
+Medium
+
+You are given a 2D integer array `intervals` where intervals[i] = [lefti, righti] represents the **inclusive** interval [lefti, righti].
+
+You have to divide the intervals into one or more **groups** such that each interval is in **exactly** one group, and no two intervals that are in the same group **intersect** each other.
+
+Return _the **minimum** number of groups you need to make_.
+
+Two intervals **intersect** if there is at least one common number between them. For example, the intervals `[1, 5]` and `[5, 8]` intersect.
+
+**Example 1:**
+
+**Input:** intervals = \[\[5,10],[6,8],[1,5],[2,3],[1,10]]
+
+**Output:** 3
+
+**Explanation:** We can divide the intervals into the following groups:
+
+- Group 1: [1, 5], [6, 8].
+
+- Group 2: [2, 3], [5, 10].
+
+- Group 3: [1, 10].
+
+It can be proven that it is not possible to divide the intervals into fewer than 3 groups. 
+
+**Example 2:**
+
+**Input:** intervals = \[\[1,3],[5,6],[8,10],[11,13]]
+
+**Output:** 1
+
+**Explanation:** None of the intervals overlap, so we can put all of them in one group. 
+
+**Constraints:**
+
+*   1 <= intervals.length <= 105
+*   `intervals[i].length == 2`
+*   1 <= lefti <= righti <= 106
+
+## Solution
+
+```kotlin
+class Solution {
+    fun minGroups(intervals: Array): Int {
+        var maxElement = 0
+        for (i in intervals) {
+            maxElement = maxElement.coerceAtLeast(i[0])
+            maxElement = maxElement.coerceAtLeast(i[1])
+        }
+        val prefixSum = LongArray(maxElement + 2)
+        for (i in intervals) {
+            prefixSum[i[0]] = prefixSum[i[0]] + 1
+            prefixSum[i[1] + 1] = prefixSum[i[1] + 1] - 1
+        }
+        var ans: Long = 0
+        for (i in 1..maxElement + 1) {
+            prefixSum[i] += prefixSum[i - 1]
+            ans = ans.coerceAtLeast(prefixSum[i])
+        }
+        return ans.toInt()
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2401_2500/s2407_longest_increasing_subsequence_ii/readme.md b/src/main/kotlin/g2401_2500/s2407_longest_increasing_subsequence_ii/readme.md
new file mode 100644
index 00000000..82e92d22
--- /dev/null
+++ b/src/main/kotlin/g2401_2500/s2407_longest_increasing_subsequence_ii/readme.md
@@ -0,0 +1,117 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2407\. Longest Increasing Subsequence II
+
+Hard
+
+You are given an integer array `nums` and an integer `k`.
+
+Find the longest subsequence of `nums` that meets the following requirements:
+
+*   The subsequence is **strictly increasing** and
+*   The difference between adjacent elements in the subsequence is **at most** `k`.
+
+Return _the length of the **longest** **subsequence** that meets the requirements._
+
+A **subsequence** is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.
+
+**Example 1:**
+
+**Input:** nums = [4,2,1,4,3,4,5,8,15], k = 3
+
+**Output:** 5
+
+**Explanation:**
+
+The longest subsequence that meets the requirements is [1,3,4,5,8].
+
+The subsequence has a length of 5, so we return 5.
+
+Note that the subsequence [1,3,4,5,8,15] does not meet the requirements because 15 - 8 = 7 is larger than 3. 
+
+**Example 2:**
+
+**Input:** nums = [7,4,5,1,8,12,4,7], k = 5
+
+**Output:** 4
+
+**Explanation:**
+
+The longest subsequence that meets the requirements is [4,5,8,12].
+
+The subsequence has a length of 4, so we return 4. 
+
+**Example 3:**
+
+**Input:** nums = [1,5], k = 1
+
+**Output:** 1
+
+**Explanation:** The longest subsequence that meets the requirements is [1]. The subsequence has a length of 1, so we return 1. 
+
+**Constraints:**
+
+*   1 <= nums.length <= 105
+*   1 <= nums[i], k <= 105
+
+## Solution
+
+```kotlin
+@Suppress("NAME_SHADOWING")
+class Solution {
+    private class SegTree(private val n: Int) {
+        private val arr: IntArray = IntArray(2 * n)
+
+        fun query(l: Int, r: Int): Int {
+            var l = l
+            var r = r
+            l += n
+            r += n
+            var ans = 0
+            while (l < r) {
+                if (l and 1 == 1) {
+                    ans = ans.coerceAtLeast(arr[l])
+                    l += 1
+                }
+                if (r and 1 == 1) {
+                    r -= 1
+                    ans = ans.coerceAtLeast(arr[r])
+                }
+                l = l shr 1
+                r = r shr 1
+            }
+            return ans
+        }
+
+        fun update(i: Int, `val`: Int) {
+            var i = i
+            i += n
+            arr[i] = `val`
+            while (i > 0) {
+                i = i shr 1
+                arr[i] = arr[2 * i].coerceAtLeast(arr[2 * i + 1])
+            }
+        }
+    }
+
+    fun lengthOfLIS(nums: IntArray, k: Int): Int {
+        var max = 0
+        for (n in nums) {
+            max = max.coerceAtLeast(n)
+        }
+        val seg = SegTree(max)
+        var ans = 0
+        var i = 0
+        while (i < nums.size) {
+            var n = nums[i]
+            n -= 1
+            val temp = seg.query(0.coerceAtLeast(n - k), n) + 1
+            ans = ans.coerceAtLeast(temp)
+            seg.update(n, temp)
+            i++
+        }
+        return ans
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2401_2500/s2409_count_days_spent_together/readme.md b/src/main/kotlin/g2401_2500/s2409_count_days_spent_together/readme.md
new file mode 100644
index 00000000..2c657e79
--- /dev/null
+++ b/src/main/kotlin/g2401_2500/s2409_count_days_spent_together/readme.md
@@ -0,0 +1,74 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2409\. Count Days Spent Together
+
+Easy
+
+Alice and Bob are traveling to Rome for separate business meetings.
+
+You are given 4 strings `arriveAlice`, `leaveAlice`, `arriveBob`, and `leaveBob`. Alice will be in the city from the dates `arriveAlice` to `leaveAlice` (**inclusive**), while Bob will be in the city from the dates `arriveBob` to `leaveBob` (**inclusive**). Each will be a 5-character string in the format `"MM-DD"`, corresponding to the month and day of the date.
+
+Return _the total number of days that Alice and Bob are in Rome together._
+
+You can assume that all dates occur in the **same** calendar year, which is **not** a leap year. Note that the number of days per month can be represented as: `[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]`.
+
+**Example 1:**
+
+**Input:** arriveAlice = "08-15", leaveAlice = "08-18", arriveBob = "08-16", leaveBob = "08-19"
+
+**Output:** 3
+
+**Explanation:** Alice will be in Rome from August 15 to August 18. Bob will be in Rome from August 16 to August 19. They are both in Rome together on August 16th, 17th, and 18th, so the answer is 3. 
+
+**Example 2:**
+
+**Input:** arriveAlice = "10-01", leaveAlice = "10-31", arriveBob = "11-01", leaveBob = "12-31"
+
+**Output:** 0
+
+**Explanation:** There is no day when Alice and Bob are in Rome together, so we return 0. 
+
+**Constraints:**
+
+*   All dates are provided in the format `"MM-DD"`.
+*   Alice and Bob's arrival dates are **earlier than or equal to** their leaving dates.
+*   The given dates are valid dates of a **non-leap** year.
+
+## Solution
+
+```kotlin
+class Solution {
+    private val dates = intArrayOf(0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
+
+    fun countDaysTogether(
+        arriveAlice: String,
+        leaveAlice: String,
+        arriveBob: String,
+        leaveBob: String
+    ): Int {
+        if (leaveAlice < arriveBob || leaveBob < arriveAlice) {
+            return 0
+        }
+        val end = if (leaveAlice <= leaveBob) leaveAlice else leaveBob
+        val start = if (arriveAlice <= arriveBob) arriveBob else arriveAlice
+        val starts = start.split("-".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
+        val ends = end.split("-".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
+        val startMonth = Integer.valueOf(starts[0])
+        val endMonth = Integer.valueOf(ends[0])
+        var res = 0
+        if (startMonth == endMonth) {
+            res += Integer.valueOf(ends[1]) - Integer.valueOf(starts[1]) + 1
+            return res
+        }
+        for (i in startMonth..endMonth) {
+            res += when (i) {
+                endMonth -> Integer.valueOf(ends[1])
+                startMonth -> dates[i] - Integer.valueOf(starts[1]) + 1
+                else -> dates[i]
+            }
+        }
+        return res
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2401_2500/s2410_maximum_matching_of_players_with_trainers/readme.md b/src/main/kotlin/g2401_2500/s2410_maximum_matching_of_players_with_trainers/readme.md
new file mode 100644
index 00000000..83bf396c
--- /dev/null
+++ b/src/main/kotlin/g2401_2500/s2410_maximum_matching_of_players_with_trainers/readme.md
@@ -0,0 +1,79 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2410\. Maximum Matching of Players With Trainers
+
+Medium
+
+You are given a **0-indexed** integer array `players`, where `players[i]` represents the **ability** of the ith player. You are also given a **0-indexed** integer array `trainers`, where `trainers[j]` represents the **training capacity** of the jth trainer.
+
+The ith player can **match** with the jth trainer if the player's ability is **less than or equal to** the trainer's training capacity. Additionally, the ith player can be matched with at most one trainer, and the jth trainer can be matched with at most one player.
+
+Return _the **maximum** number of matchings between_ `players` _and_ `trainers` _that satisfy these conditions._
+
+**Example 1:**
+
+**Input:** players = [4,7,9], trainers = [8,2,5,8]
+
+**Output:** 2
+
+**Explanation:**
+
+One of the ways we can form two matchings is as follows:
+
+- players[0] can be matched with trainers[0] since 4 <= 8.
+
+- players[1] can be matched with trainers[3] since 7 <= 8.
+
+It can be proven that 2 is the maximum number of matchings that can be formed. 
+
+**Example 2:**
+
+**Input:** players = [1,1,1], trainers = [10]
+
+**Output:** 1
+
+**Explanation:**
+
+The trainer can be matched with any of the 3 players.
+
+Each player can only be matched with one trainer, so the maximum answer is 1. 
+
+**Constraints:**
+
+*   1 <= players.length, trainers.length <= 105
+*   1 <= players[i], trainers[j] <= 109
+
+## Solution
+
+```kotlin
+class Solution {
+    fun matchPlayersAndTrainers(players: IntArray, trainers: IntArray): Int {
+        players.sort()
+        trainers.sort()
+        var j = 0
+        var count = 0
+        var i = 0
+        while (i < players.size) {
+            while (trainers[j] < players[i]) {
+                j++
+                if (j >= trainers.size) {
+                    break
+                }
+            }
+            if (j >= trainers.size) {
+                break
+            }
+            if (trainers[j] >= players[i]) {
+                count++
+            }
+            i++
+            j++
+            if (j >= trainers.size || i >= players.size) {
+                break
+            }
+        }
+        return count
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2401_2500/s2411_smallest_subarrays_with_maximum_bitwise_or/readme.md b/src/main/kotlin/g2401_2500/s2411_smallest_subarrays_with_maximum_bitwise_or/readme.md
new file mode 100644
index 00000000..5438b195
--- /dev/null
+++ b/src/main/kotlin/g2401_2500/s2411_smallest_subarrays_with_maximum_bitwise_or/readme.md
@@ -0,0 +1,79 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2411\. Smallest Subarrays With Maximum Bitwise OR
+
+Medium
+
+You are given a **0-indexed** array `nums` of length `n`, consisting of non-negative integers. For each index `i` from `0` to `n - 1`, you must determine the size of the **minimum sized** non-empty subarray of `nums` starting at `i` (**inclusive**) that has the **maximum** possible **bitwise OR**.
+
+*   In other words, let Bij be the bitwise OR of the subarray `nums[i...j]`. You need to find the smallest subarray starting at `i`, such that bitwise OR of this subarray is equal to max(Bik) where `i <= k <= n - 1`.
+
+The bitwise OR of an array is the bitwise OR of all the numbers in it.
+
+Return _an integer array_ `answer` _of size_ `n` _where_ `answer[i]` _is the length of the **minimum** sized subarray starting at_ `i` _with **maximum** bitwise OR._
+
+A **subarray** is a contiguous non-empty sequence of elements within an array.
+
+**Example 1:**
+
+**Input:** nums = [1,0,2,1,3]
+
+**Output:** [3,3,2,2,1]
+
+**Explanation:**
+
+The maximum possible bitwise OR starting at any index is 3.
+
+- Starting at index 0, the shortest subarray that yields it is [1,0,2].
+
+- Starting at index 1, the shortest subarray that yields the maximum bitwise OR is [0,2,1].
+
+- Starting at index 2, the shortest subarray that yields the maximum bitwise OR is [2,1].
+
+- Starting at index 3, the shortest subarray that yields the maximum bitwise OR is [1,3].
+
+- Starting at index 4, the shortest subarray that yields the maximum bitwise OR is [3].
+
+Therefore, we return [3,3,2,2,1]. 
+
+**Example 2:**
+
+**Input:** nums = [1,2]
+
+**Output:** [2,1]
+
+**Explanation:**
+
+Starting at index 0, the shortest subarray that yields the maximum bitwise OR is of length 2.
+
+Starting at index 1, the shortest subarray that yields the maximum bitwise OR is of length 1.
+
+Therefore, we return [2,1]. 
+
+**Constraints:**
+
+*   `n == nums.length`
+*   1 <= n <= 105
+*   0 <= nums[i] <= 109
+
+## Solution
+
+```kotlin
+class Solution {
+    fun smallestSubarrays(nums: IntArray): IntArray {
+        val res = IntArray(nums.size)
+        val bitPosition = IntArray(30)
+        for (i in nums.indices.reversed()) {
+            res[i] = 1
+            for (j in 0..29) {
+                if (nums[i] and (1 shl j) > 0) {
+                    bitPosition[j] = i
+                }
+                res[i] = res[i].coerceAtLeast(bitPosition[j] - i + 1)
+            }
+        }
+        return res
+    }
+}
+```
\ No newline at end of file
diff --git a/src/main/kotlin/g2401_2500/s2412_minimum_money_required_before_transactions/readme.md b/src/main/kotlin/g2401_2500/s2412_minimum_money_required_before_transactions/readme.md
new file mode 100644
index 00000000..8ac4e37c
--- /dev/null
+++ b/src/main/kotlin/g2401_2500/s2412_minimum_money_required_before_transactions/readme.md
@@ -0,0 +1,64 @@
+[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
+[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
+
+## 2412\. Minimum Money Required Before Transactions
+
+Hard
+
+You are given a **0-indexed** 2D integer array `transactions`, where transactions[i] = [costi, cashbacki].
+
+The array describes transactions, where each transaction must be completed exactly once in **some order**. At any given moment, you have a certain amount of `money`. In order to complete transaction `i`, money >= costi must hold true. After performing a transaction, `money` becomes money - costi + cashbacki.
+
+Return _the minimum amount of_ `money` _required before any transaction so that all of the transactions can be completed **regardless of the order** of the transactions._
+
+**Example 1:**
+
+**Input:** transactions = \[\[2,1],[5,0],[4,2]]
+
+**Output:** 10
+
+**Explanation:**
+
+Starting with money = 10, the transactions can be performed in any order.
+
+It can be shown that starting with money < 10 will fail to complete all transactions in some order. 
+
+**Example 2:**
+
+**Input:** transactions = \[\[3,0],[0,3]]
+
+**Output:** 3
+
+**Explanation:**
+
+- If transactions are in the order [[3,0],[0,3]], the minimum money required to complete the transactions is 3.
+
+- If transactions are in the order [[0,3],[3,0]], the minimum money required to complete the transactions is 0.
+
+Thus, starting with money = 3, the transactions can be performed in any order. 
+
+**Constraints:**
+
+*   1 <= transactions.length <= 105
+*   `transactions[i].length == 2`
+*   0 <= costi, cashbacki <= 109
+
+## Solution
+
+```kotlin
+class Solution {
+    fun minimumMoney(transactions: Array): Long {
+        var max = 0
+        var sum: Long = 0
+        for (transaction in transactions) {
+            val diff = transaction[1] - transaction[0]
+            if (diff < 0) {
+                sum -= diff.toLong()
+                transaction[0] += diff
+            }
+            max = max.coerceAtLeast(transaction[0])
+        }
+        return max + sum
+    }
+}
+```
\ No newline at end of file