From 06c1ddca8fed8678f08c928b589af62d8abbe673 Mon Sep 17 00:00:00 2001 From: sumanth_botlagunta <86908741+sumanth-botlagunta@users.noreply.github.com> Date: Tue, 11 Apr 2023 13:11:03 +0530 Subject: [PATCH 001/280] solves clone graph (#133) in python --- python/clone_graph.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 python/clone_graph.py diff --git a/python/clone_graph.py b/python/clone_graph.py new file mode 100644 index 0000000..35fd538 --- /dev/null +++ b/python/clone_graph.py @@ -0,0 +1,19 @@ +# https://leetcode.com/problems/clone-graph/description/ +# T: O(n) where n is the number of nodes in the graph +# S: O(n) where n is the number of nodes in the graph + +class Solution: + def cloneGraph(self, node: 'Node') -> 'Node': + if not node: + return node + d = {node.val: Node(node.val, [])} + q = deque([node]) + while q: + cur_node = q.pop() + cur_res = d[cur_node.val] + for n in cur_node.neighbors: + if n.val not in d: + q.append(n) + d[n.val] = Node(n.val, []) + cur_res.neighbors.append(d[n.val]) + return d[node.val] From 4f2227d8030c7aa68354ae9fc578d897c2103fbd Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 4 May 2023 22:34:14 +0200 Subject: [PATCH 002/280] updates readme status --- README.md | 4 ++-- src/GameOfLife.java | 55 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 src/GameOfLife.java diff --git a/README.md b/README.md index 1a83c86..044a74c 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # LeetCode Algorithms ![problems-solved](https://img.shields.io/badge/Problems%20Solved-542/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-542/2081-1abc9c.svg) -![problems-solved-python](https://img.shields.io/badge/Python-185/2081-1abc9c.svg) +![problems-solved-java](https://img.shields.io/badge/Java-556/2081-1abc9c.svg) +![problems-solved-python](https://img.shields.io/badge/Python-205/2081-1abc9c.svg) ![problems-solved-javascript](https://img.shields.io/badge/JavaScript-4/2081-1abc9c.svg) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md) [![cp](https://img.shields.io/badge/also%20see-Competitve%20Programming-1f72ff.svg)](https://github.com/anishLearnsToCode/competitive-programming) diff --git a/src/GameOfLife.java b/src/GameOfLife.java new file mode 100644 index 0000000..ebeb019 --- /dev/null +++ b/src/GameOfLife.java @@ -0,0 +1,55 @@ +// https://leetcode.com/problems/game-of-life + +import java.util.Arrays; + +public class GameOfLife { + private static int rows, columns; + + public static void gameOfLife(int[][] board) { + rows = board.length; + columns = board[0].length; + final int[][] adjacentLiveSquares = getAdjacentLiveSquares(board); + System.out.println(Arrays.deepToString(adjacentLiveSquares)); + + for (int row = 0 ; row < rows ; row++) { + for (int column = 0 ; column < columns ; column++) { + if (board[row][column] == 1) { + if (adjacentLiveSquares[row][column] < 2 || adjacentLiveSquares[row][column] > 3) { + board[row][column] = 0; + } + } else { + if (adjacentLiveSquares[row][column] == 3) { + board[row][column] = 1; + } + } + } + } + } + + private static int[][] getAdjacentLiveSquares(int[][] board) { + final int[][] result = new int[rows][columns]; + + for (int row = 0 ; row < rows ; row++) { + for (int column = 0 ; column < columns ; column++) { + result[row][column] = (row > 0 ? getRowSum(board, row - 1, column) : 0) + + (row + 1 < rows ? getRowSum(board, row + 1, column) : 0) + + (column > 0 ? board[row][column - 1] : 0) + + (column + 1 < columns ? board[row][column + 1] : 0); + } + } + + return result; + } + + private static int getRowSum(int[][] board, int row, int column) { + return board[row][column] + + (column - 1 >= 0 ? board[row][column - 1] : 0) + + (column + 1 < columns ? board[row][column + 1] : 0); + } + + public static void main(String[] args) { + int[][] result = new int[][] {{0,1,0},{0,0,1},{1,1,1},{0,0,0}}; + gameOfLife(result); + System.out.println(Arrays.deepToString(result)); + } +} From 5fd736f6ea67440ccbb356c158849c69124ba893 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 13 May 2023 20:52:07 +0200 Subject: [PATCH 003/280] updates status --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 044a74c..dba4922 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-542/2081-1f425f.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-570/2081-1f425f.svg) ![problems-solved-java](https://img.shields.io/badge/Java-556/2081-1abc9c.svg) ![problems-solved-python](https://img.shields.io/badge/Python-205/2081-1abc9c.svg) ![problems-solved-javascript](https://img.shields.io/badge/JavaScript-4/2081-1abc9c.svg) From 737e6d09b5f5a285d0f039d0cfd02e464591bf06 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 13 May 2023 21:29:17 +0200 Subject: [PATCH 004/280] updates links --- README.md | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index dba4922..fd4d57a 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ | 61 | [Rotate List](https://leetcode.com/problems/rotate-list) | [![Java](assets/java.png)](src/RotateList.java) | | | 62 | [Unique Paths](https://leetcode.com/problems/unique-paths) | [![Java](assets/java.png)](src/UniquePaths.java) | | | 63 | [Unique Paths II](https://leetcode.com/problems/unique-paths-ii) | [![Java](assets/java.png)](src/UniquePathII.java) | | -| 64 | [Minimum Path Sum](https://leetcode.com/problems/minimum-path-sum) | [![Java](assets/java.png)](src/MinimumPathSum.java) | | +| 64 | [Minimum Path Sum](https://leetcode.com/problems/minimum-path-sum) | [![Java](assets/java.png)](src/MinimumPathSum.java) [![Python](assets/python.png)](python/minimum_path_sum.py) | | | 66 | [Plus One](https://leetcode.com/problems/plus-one) | [![Java](assets/java.png)](src/PlusOne.java) [![Python](assets/python.png)](python/plus_one.py) | | | 67 | [Add Binary](https://leetcode.com/problems/add-binary) | [![Java](assets/java.png)](src/AddBinary.java) [![Python](assets/python.png)](python/add_binary.py) | | | 69 | [Sqrt(x)](https://leetcode.com/problems/sqrtx) | [![Java](assets/java.png)](src/Sqrtx.java) [![Python](assets/python.png)](python/sqrt.py) | | @@ -81,6 +81,7 @@ | 82 | [Remove Duplicates from Sorted List II](https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii) | [![Java](assets/java.png)](src/RemoveDuplicatesFromSortedListII.java) | | | 83 | [Remove Duplicates from Sorted List](https://leetcode.com/problems/remove-duplicates-from-sorted-list) | [![Java](assets/java.png)](src/RemoveDuplicatesFromSortedList.java) [![Python](assets/python.png)](python/remove_duplicates_from_linked_list.py) | | | 86 | [Partition List](https://leetcode.com/problems/partition-list) | [![Java](assets/java.png)](src/PartitionList.java) | | +| 87 | [Scramble String](https://leetcode.com/problems/scramble-string) | [![Python](assets/python.png)](python/scramble_strings.py) | | | 88 | [Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array) | [![Java](assets/java.png)](src/MergeSortedArray.java) [![Python](assets/python.png)](python/merge_sorted_array.py) | | | 89 | [Gray Code](https://leetcode.com/problems/gray-code) | [![Java](assets/java.png)](src/GrayCode.java) | | | 90 | [Subsets II](https://leetcode.com/problems/subsets-ii) | [![Java](assets/java.png)](src/SubsetsII.java) | | @@ -120,7 +121,7 @@ | 129 | [Sum Root to Leaf Numbers](https://leetcode.com/problems/sum-root-to-leaf-numbers) | [![Java](assets/java.png)](src/SumRootToLeafNumbers.java) | | | 130 | [Surrounded Regions](https://leetcode.com/problems/surrounded-regions) | [![Java](assets/java.png)](src/SurroundedRegions.java) | | | 131 | [Palindrome Partitioning](https://leetcode.com/problems/palindrome-partitioning) | [![Java](assets/java.png)](src/PalindromePartitioning.java) | | -| 133 | [Clone Graph](https://leetcode.com/problems/clone-graph) | [![Java](assets/java.png)](src/CloneGraph.java) | | +| 133 | [Clone Graph](https://leetcode.com/problems/clone-graph) | [![Java](assets/java.png)](src/CloneGraph.java) [![Python](assets/python.png)](python/clone_graph.py) | | | 134 | [Gas Station](https://leetcode.com/problems/gas-station) | [![Java](assets/java.png)](src/GasStation.java) | | | 136 | [Single Number](https://leetcode.com/problems/single-number) | [![Java](assets/java.png)](src/SingleNumber.java) [![Python](assets/python.png)](python/single_number.py) | | | 137 | [Single Number II](https://leetcode.com/problems/single-number-ii) | [![Java](assets/java.png)](src/SingleNumberII.java) | | @@ -161,7 +162,7 @@ | 191 | [Number of One Bits](https://leetcode.com/problems/number-of-1-bits) | [![Java](assets/java.png)](src/NumberOf1Bit.java) [![Python](assets/python.png)](python/number_of_1_bits.py) | | | 198 | [House Robber](https://leetcode.com/problems/house-robber) | [![Java](assets/java.png)](src/HouseRobber.java) [![Python](assets/python.png)](python/house_robber.py) | | | 199 | [Binary Tree Right Side View](https://leetcode.com/problems/binary-tree-right-side-view) | [![Java](assets/java.png)](src/BinaryTreeRightSideView.java) | | -| 200 | [Number of Islands](https://leetcode.com/problems/number-of-islands) | [![Java](assets/java.png)](src/NumberOfIslands.java) | | +| 200 | [Number of Islands](https://leetcode.com/problems/number-of-islands) | [![Java](assets/java.png)](src/NumberOfIslands.java) [![Python](assets/python.png)](python/number_of_islands.py) | | | 201 | [Bitwise AND of Numbers Range](https://leetcode.com/problems/bitwise-and-of-numbers-range) | [![Java](assets/java.png)](src/BitwiseANDOfNumbersRange.java) | | | 202 | [Happy Number](https://leetcode.com/problems/happy-number) | [![Java](assets/java.png)](src/HappyNumber.java) [![Python](assets/python.png)](python/happy_number.py) | | | 203 | [Remove Linked List Elements](https://leetcode.com/problems/remove-linked-list-elements) | [![Java](assets/java.png)](src/RemoveLinkedListElements.java) [![Python](assets/python.png)](python/remove_linked_list_elements.py) | | @@ -169,7 +170,7 @@ | 205 | [Isomorphic Strings](https://leetcode.com/problems/isomorphic-strings) | [![Java](assets/java.png)](src/IsomorphicStrings.java) [![Python](assets/python.png)](python/isomorphic_strings.py) | | | 206 | [Reverse Linked List](https://leetcode.com/problems/reverse-linked-list) | [![Java](assets/java.png)](src/ReverseLinkedList.java) [![Python](assets/python.png)](python/reverse_linked_list.py) | | | 207 | [Course Schedule](https://leetcode.com/problems/course-schedule) | [![Java](assets/java.png)](src/CourseSchedule.java) | | -| 208 | [Implement Trie (Prefix Tree)](https://leetcode.com/problems/implement-trie-prefix-tree) | [![Java](assets/java.png)](src/Trie.java) | | +| 208 | [Implement Trie (Prefix Tree)](https://leetcode.com/problems/implement-trie-prefix-tree) | [![Java](assets/java.png)](src/Trie.java) [![Python](assets/python.png)](python/trie.py) | | | 209 | [Minimum Size Subarray Sum](https://leetcode.com/problems/minimum-size-subarray-sum) | [![Java](assets/java.png)](src/MinimumSizeSubarraySum.java) | | | 210 | [Course Schedule II](https://leetcode.com/problems/course-schedule-ii) | [![Java](assets/java.png)](src/CourseScheduleII.java) | | | 211 | [Design Add and Search Words Data Structure](https://leetcode.com/problems/design-add-and-search-words-data-structure) | [![Java](assets/java.png)](src/DesignAddAndSearchWordsDataStructure.java) | | @@ -177,6 +178,7 @@ | 215 | [Kth Largest Element in an Array](https://leetcode.com/problems/kth-largest-element-in-an-array) | [![Java](assets/java.png)](src/KthLargestElementInAnArray.java) | | | 216 | [Combination Sum III](https://leetcode.com/problems/combination-sum-iii) | [![Java](assets/java.png)](src/CombinationSumIII.java) | | | 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate) | [![Java](assets/java.png)](src/ContainsDuplicate.java) [![Python](assets/python.png)](python/contains_duplicate.py) | | +| 218 | [The Skyline Problem](https://leetcode.com/problems/the-skyline-problem) | [![Python](assets/python.png)](python/the_skyline_problem.py) | | | 219 | [Contains Duplicate II](https://leetcode.com/problems/contains-duplicate-ii) | [![Java](assets/java.png)](src/ContainsDuplicateII.java) [![Python](assets/python.png)](python/contains_duplicate_ii.py) | | | 220 | [Contains Duplicate III](https://leetcode.com/problems/contains-duplicate-iii) | [![Java](assets/java.png)](src/ContainsDuplicateIII.java) | | | 221 | [Maximal Square](https://leetcode.com/problems/maximal-square) | [![Java](assets/java.png)](src/MaximalSquare.java) | | @@ -420,6 +422,7 @@ | 872 | [Leaf-Similar Trees](https://leetcode.com/problems/leaf-similar-trees) | [![Java](assets/java.png)](src/LeafSimilarTrees.java) | | | 874 | [Walking Robot Simulation](https://leetcode.com/problems/walking-robot-simulation) | | | | 876 | [Middle of the Linked List](https://leetcode.com/problems/middle-of-the-linked-list) | [![Java](assets/java.png)](src/MiddleOfTheLinkedList.java) | | +| 881 | [Boats to Save People](https://leetcode.com/problems/boats-to-save-people) | [![Python](assets/python.png)](python/boats_to_save_people.py) | | | 883 | [Projection Area of 3D Shapes](https://leetcode.com/problems/projection-area-of-3d-shapes) | [![Java](assets/java.png)](src/ProjectionAreaOf3DShapes.java) | | | 884 | [Uncommon Words from 2 Sentences](https://leetcode.com/problems/uncommon-words-from-two-sentences) | [![Java](assets/java.png)](src/UncommonWordsFromTwoSentences.java) | | | 888 | [Fair Candy Swap](https://leetcode.com/problems/fair-candy-swap) | [![Java](assets/java.png)](src/FairCandySwap.java) | | @@ -447,6 +450,7 @@ | 970 | [Powerful Integers](https://leetcode.com/problems/powerful-integers) | | | | 976 | [Largest Perimeter Triangle](https://leetcode.com/problems/largest-perimeter-triangle) | [![Java](assets/java.png)](src/LargestPerimeterTriangle.java) | | | 977 | [Squares of a Sorted Array](https://leetcode.com/problems/squares-of-a-sorted-array) | | | +| 983 | [Minimum Cost For Tickets](https://leetcode.com/problems/minimum-cost-for-tickets) | [![Python](assets/python.png)](python/minimum_cost_for_tickets.py) | | | 985 | [Sum of Even Numbers after Queries](https://leetcode.com/problems/sum-of-even-numbers-after-queries) | | | | 989 | [Add to Array Form of Integer](https://leetcode.com/problems/add-to-array-form-of-integer) | [![Java](assets/java.png)](src/AddToArrayFormOfInteger.java) | | | 993 | [Cousins in Binary Tree](https://leetcode.com/problems/cousins-in-binary-tree) | [![Java](assets/java.png)](src/CousinsInBinaryTree.java) | | @@ -459,6 +463,7 @@ | 1010 | [Pairs of Songs With Total Durations Divisible by 60](https://leetcode.com/problems/pairs-of-songs-with-total-durations-divisible-by-60) | [![Java](assets/java.png)](src/PartitionArrayIntoThreePartsWithEqualSum.java) | | | 1013 | [Partition Array into Three Parts with equal Sum](https://leetcode.com/problems/partition-array-into-three-parts-with-equal-sum) | | | | 1018 | [Binary Prefix Divisible by 5](https://leetcode.com/problems/binary-prefix-divisible-by-5) | [![Java](assets/java.png)](src/BinaryPrefixDivisibleBy5.java) | | +| 1020 | [Number of Enclaves](https://leetcode.com/problems/number-of-enclaves) | [![Python](assets/python.png)](python/number_of_enclaves.py) | | | 1021 | [Remove Outermost Parenthesis](https://leetcode.com/problems/remove-outermost-parentheses) | [![Java](assets/java.png)](src/RemoveOutermostParentheses.java) | | | 1022 | [Sum of Root to Leaf Binary Numbers](https://leetcode.com/problems/sum-of-root-to-leaf-binary-numbers) | [![Java](assets/java.png)](src/SumOfRootToLeafBinaryNumbers.java) | | | 1025 | [Divisor Game](https://leetcode.com/problems/divisor-game) | [![Java](assets/java.png)](src/DivisorGame.java) | | @@ -513,6 +518,7 @@ | 1243 | 🔒 [Array Transformation](https://leetcode.com/problems/array-transformation) | | | | 1249 | [Minimum Remove to Make Valid Parentheses](https://leetcode.com/problems/minimum-remove-to-make-valid-parentheses) | [![Java](assets/java.png)](src/MinimumRemoveToMakeValidParentheses.java) | | | 1252 | [Cells With Odd Values In Matrix](https://leetcode.com/problems/cells-with-odd-values-in-a-matrix) | [![Java](assets/java.png)](src/CellsWithOddValuesInMatrix.java) | | +| 1254 | [Number of Closed Islands](https://leetcode.com/problems/number-of-closed-islands) | [![Python](assets/python.png)](python/number_of_closed_islands.py) | | | 1260 | [Shift 2D Grid](https://leetcode.com/problems/shift-2d-grid) | [![Java](assets/java.png)](src/Shift2DGrid.java) | | | 1266 | [Minimum Time Visiting All Points](https://leetcode.com/problems/minimum-time-visiting-all-points) | [![Java](assets/java.png)](src/MinimumTimeVisitingAllPoints.java) | | | 1271 | 🔒 [Hexspeak](https://leetcode.com/problems/hexspeak) | | | @@ -526,6 +532,7 @@ | 1309 | [Decrypt String From Alphabet To Integer Mapping](https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping) | [![Java](assets/java.png)](src/DecryptStringFromAlphabetToIntegerMapping.java) | | | 1313 | [Decompress Run-Length Encoded Strings](https://leetcode.com/problems/decompress-run-length-encoded-list) | [![Java](assets/java.png)](src/DecompressRunLengthEncodedList.java) | | | 1317 | [Convert Integer to Sum Of Two Non-Zero Integers](https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers) | [![Java](assets/java.png)](src/ConvertIntegerToTheSumOfTwoNoZeroIntegers.java) | | +| 1319 | [Number of Operations to Make Network Connected](https://leetcode.com/problems/number-of-operations-to-make-network-connected) | [![Python](assets/python.png)](python/no_of_operations_to_make_network_connected.py) | | | 1323 | [Maximum 69 Number](https://leetcode.com/problems/maximum-69-number) | [![Java](assets/java.png)](src/Maximum69Number.java) | | | 1331 | [Rank Transform of An Array](https://leetcode.com/problems/rank-transform-of-an-array) | [![Java](assets/java.png)](src/RankTransformOfArray.java) | | | 1332 | [Remove Palindromic Subsequences](https://leetcode.com/problems/remove-palindromic-subsequences) | [![Java](assets/java.png)](src/RemovePalindromicSubSequences.java) | | @@ -544,6 +551,7 @@ | 1389 | [Create Target Array in Given Order](https://leetcode.com/problems/create-target-array-in-the-given-order) | [![Java](assets/java.png)](src/CreateTargetArrayInGivenOrder.java) | | | 1394 | [Find Lucky Integer In An Array](https://leetcode.com/problems/find-lucky-integer-in-an-array) | [![Java](assets/java.png)](src/FindTheLuckyIntegerInAnArray.java) | | | 1399 | [Count Largest Group](https://leetcode.com/problems/count-largest-group) | [![Java](assets/java.png)](src/CountLargestGroup.java) | | +| 1402 | [Reducing Dishes](https://leetcode.com/problems/reducing-dishes) | [![Python](assets/python.png)](python/reducing_dishes.py) | | | 1403 | [Minimum Subsequence in Non-Increasing Order](https://leetcode.com/problems/minimum-subsequence-in-non-increasing-order) | [![Java](assets/java.png)](src/MinimumSubSequenceInNonIncreasingOrder.java) | | | 1408 | [String Matching In An Array](https://leetcode.com/problems/string-matching-in-an-array) | [![Java](assets/java.png)](src/StringMatchingInAnArray.java) | | | 1413 | [Minimum Value To Get Positive Step By Step Sum](https://leetcode.com/problems/minimum-value-to-get-positive-step-by-step-sum) | [![Java](assets/java.png)](src/MinimumValueToGetPositiveStepByStepSum.java) | | @@ -555,12 +563,14 @@ | 1436 | [Destination City](https://leetcode.com/problems/destination-city) | [![Java](assets/java.png)](src/DestinationCity.java) | | | 1437 | [Check If All 1's Are at Least Length K Places Away](https://leetcode.com/problems/check-if-all-1s-are-at-least-length-k-places-away) | [![Java](assets/java.png)](src/CheckIfAll1sAreAtLeastKPlacesAway.java) | | | 1441 | [Build An Array With Stack Operation](https://leetcode.com/problems/build-an-array-with-stack-operations) | [![Java](assets/java.png)](src/BuildAnArrayWithStackOperations.java) | | +| 1444 | [Number of Ways of Cutting a Pizza](https://leetcode.com/problems/number-of-ways-of-cutting-a-pizza) | [![Python](assets/python.png)](python/number_of_ways_of_cutting_pizza.py) | | | 1446 | [Consecutive Characters](https://leetcode.com/problems/consecutive-characters) | [![Java](assets/java.png)](src/ConsecutiveCharacters.java) | | | 1450 | [Number of Students Doing Homework at Given Time](https://leetcode.com/problems/number-of-students-doing-homework-at-a-given-time) | [![Java](assets/java.png)](src/NumberOfStudentsDoingHomeworkAtGivenTime.java) | | | 1455 | [Check If Word Occurs as Prefix of any Word in Sentence](https://leetcode.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence) | [![Java](assets/java.png)](src/CheckIfAWordOccursAsAPrefixOfAnyWordInASentence.java) | | | 1460 | [Make 2 Arrays Equal by Reversing Sub Arrays](https://leetcode.com/problems/make-two-arrays-equal-by-reversing-sub-arrays) | [![Java](assets/java.png)](src/MakeTwoArraysEqualByReversingSubArrays.java) | | | 1464 | [Maximum Product of 2 Elements in Array](https://leetcode.com/problems/maximum-product-of-two-elements-in-an-array) | [![Java](assets/java.png)](src/MaximumProductOfTwoElementsInArray.java) | | -| 1469 | 🔒 [Find All Lonely Nodes](https://leetcode.com/problems/find-all-the-lonely-nodes) | | | +| 1466 | [Reorder Routes to Make All Paths Lead to the City Zero](https://leetcode.com/problems/reorder-routes-to-make-all-paths-lead-to-the-city-zero) | [![Java](assets/java.png)](src/MaximumProductOfTwoElementsInArray.java) | | +| 1469 | 🔒 [Find All Lonely Nodes](https://leetcode.com/problems/find-all-the-lonely-nodes) | [![Python](assets/python.png)](python/reorder_routes_to_make_all_paths_lead_to_city_zero.py) | | | 1470 | [Shuffle The Array](https://leetcode.com/problems/shuffle-the-array) | [![Java](assets/java.png)](src/ShuffleTheArray.java) | | | 1474 | [Delete N Nodes After M Nodes In A Linked List](https://leetcode.com/problems/delete-n-nodes-after-m-nodes-of-a-linked-list) | | | | 1475 | [Final Prices With Special Discount in a Shop](https://leetcode.com/problems/final-prices-with-a-special-discount-in-a-shop) | [![Java](assets/java.png)](src/FinalPricesWithASpecialDiscountInAShop.java) | | @@ -689,3 +699,9 @@ | 2099 | [Find Subsequence of Length K With the Largest Sum](https://leetcode.com/problems/find-subsequence-of-length-k-with-the-largest-sum) | [![Java](assets/java.png)](src/FindSubsequenceOfLengthKWithTheLargestSum.java) | | | 2103 | [Rings and Rods](https://leetcode.com/problems/rings-and-rods) | [![Java](assets/java.png)](src/RingsAndRods.java) | | | 2108 | [Find First Palindromic String in the Array](https://leetcode.com/problems/find-first-palindromic-string-in-the-array) | [![Java](assets/java.png)](src/FindFirstPalindromicStringInArray.java) | | +| 2300 | [Successful Pairs of Spells and Potions](https://leetcode.com/problems/successful-pairs-of-spells-and-potions) | [![Python](assets/python.png)](python/successfull_pairs_of_spells_and_potions.py) | | +| 2316 | [Count Unreachable Pairs of Nodes in an Undirected Graph](https://leetcode.com/problems/count-unreachable-pairs-of-nodes-in-an-undirected-graph) | [![Python](assets/python.png)](python/count_unreachable_pair_of_node_in_an_undirectable_graph.py) | | +| 2360 | [Longest Cycle in a Graph](https://leetcode.com/problems/longest-cycle-in-a-graph) | [![Python](assets/python.png)](python/longest_cycle_in_graph.py) | | +| 2348 | [Number of Zero-Filled Subarrays](https://leetcode.com/problems/number-of-zero-filled-subarrays) | [![Python](assets/python.png)](python/number_of_zero_filled_subarrays.py) | | +| 2439 | [Minimize Maximum of Array](https://leetcode.com/problems/minimize-maximum-of-array) | [![Python](assets/python.png)](python/minimize_maximum_of_array.py) | | +| 2492 | [Minimum Score of a Path Between Two Cities](https://leetcode.com/problems/minimum-score-of-a-path-between-two-cities) | [![Python](assets/python.png)](python/minimum_score_of_a_path_between_two_cities.py) | | From 504ced6974b3343d01a5c81339e5fa0f7d1919be Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 13 May 2023 21:35:06 +0200 Subject: [PATCH 005/280] updates links --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fd4d57a..f2583b8 100644 --- a/README.md +++ b/README.md @@ -173,7 +173,7 @@ | 208 | [Implement Trie (Prefix Tree)](https://leetcode.com/problems/implement-trie-prefix-tree) | [![Java](assets/java.png)](src/Trie.java) [![Python](assets/python.png)](python/trie.py) | | | 209 | [Minimum Size Subarray Sum](https://leetcode.com/problems/minimum-size-subarray-sum) | [![Java](assets/java.png)](src/MinimumSizeSubarraySum.java) | | | 210 | [Course Schedule II](https://leetcode.com/problems/course-schedule-ii) | [![Java](assets/java.png)](src/CourseScheduleII.java) | | -| 211 | [Design Add and Search Words Data Structure](https://leetcode.com/problems/design-add-and-search-words-data-structure) | [![Java](assets/java.png)](src/DesignAddAndSearchWordsDataStructure.java) | | +| 211 | [Design Add and Search Words Data Structure](https://leetcode.com/problems/design-add-and-search-words-data-structure) | [![Java](assets/java.png)](src/DesignAddAndSearchWordsDataStructure.java) [![Python](assets/python.png)](python/design_add_and_search_words_data_structure.py) | | | 213 | [House Robber II](https://leetcode.com/problems/house-robber-ii) | [![Java](assets/java.png)](src/HouseRobberII.java) | | | 215 | [Kth Largest Element in an Array](https://leetcode.com/problems/kth-largest-element-in-an-array) | [![Java](assets/java.png)](src/KthLargestElementInAnArray.java) | | | 216 | [Combination Sum III](https://leetcode.com/problems/combination-sum-iii) | [![Java](assets/java.png)](src/CombinationSumIII.java) | | @@ -572,6 +572,7 @@ | 1466 | [Reorder Routes to Make All Paths Lead to the City Zero](https://leetcode.com/problems/reorder-routes-to-make-all-paths-lead-to-the-city-zero) | [![Java](assets/java.png)](src/MaximumProductOfTwoElementsInArray.java) | | | 1469 | 🔒 [Find All Lonely Nodes](https://leetcode.com/problems/find-all-the-lonely-nodes) | [![Python](assets/python.png)](python/reorder_routes_to_make_all_paths_lead_to_city_zero.py) | | | 1470 | [Shuffle The Array](https://leetcode.com/problems/shuffle-the-array) | [![Java](assets/java.png)](src/ShuffleTheArray.java) | | +| 1472 | [Design Browser History](https://leetcode.com/problems/design-browser-history) | [![Java](assets/java.png)](src/DesignBrowserHistory.java) [![Python](assets/python.png)](python/design_browser_history.py) | | | 1474 | [Delete N Nodes After M Nodes In A Linked List](https://leetcode.com/problems/delete-n-nodes-after-m-nodes-of-a-linked-list) | | | | 1475 | [Final Prices With Special Discount in a Shop](https://leetcode.com/problems/final-prices-with-a-special-discount-in-a-shop) | [![Java](assets/java.png)](src/FinalPricesWithASpecialDiscountInAShop.java) | | | 1480 | [Running Sum of 1D Array](https://leetcode.com/problems/running-sum-of-1d-array) | [![Java](assets/java.png)](src/RunningSumOf1DArray.java) | | From 5b382a51f3135f2c17d8245af0496f2ae03edfd2 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 13 May 2023 22:53:49 +0200 Subject: [PATCH 006/280] solve Find a Corresponding Node of a Binary Tree in a Clone of That Tree (#1379) in java --- README.md | 1507 +++++++++-------- ...ngNodeOfABinaryTreeInACloneOfThatTree.java | 19 + 2 files changed, 830 insertions(+), 696 deletions(-) create mode 100644 src/FindACorrespondingNodeOfABinaryTreeInACloneOfThatTree.java diff --git a/README.md b/README.md index f2583b8..9d202d5 100644 --- a/README.md +++ b/README.md @@ -10,699 +10,814 @@ 🔒 = Subscription Content ## Problems -| # | Name | Solution | Youtube | -|:----:|-----------------------------------------------------------------------------------------------------------------------------------------------------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:---------------------------------------------------------------------------------------------------------------------------------:| -| 1 | [Two Sum](https://leetcode.com/problems/two-sum) | [![Java](assets/java.png)](src/TwoSum.java) [![Python](assets/python.png)](python/two_sum.py) | [![java-yt](assets/java-yt.png)](https://youtu.be/9wSL_7NN-A8) [![python-yt](assets/python-yt.png)](https://youtu.be/N5FXCTg0TDE) | -| 2 | [Add Two Numbers](https://leetcode.com/problems/add-two-numbers) | [![Java](assets/java.png)](src/AddTwoNumbers.java) [![js](assets/javascript.png)](javascript/AddTwoNumbers.js) | | -| 3 | [Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters) | [![Java](assets/java.png)](src/LongestSubstringWithoutRepeatingCharacters.java) | | -| 5 | [Longest Palindromic Substring](https://leetcode.com/problems/longest-palindromic-substring) | [![Java](assets/java.png)](src/LongestPalindromicSubstring.java) | | -| 6 | [Zigzag Conversion](https://leetcode.com/problems/zigzag-conversion) | [![Java](assets/java.png)](src/ZigZagConversion.java) | | -| 7 | [Reverse Integer](https://leetcode.com/problems/reverse-integer) | [![Java](assets/java.png)](src/ReverseInteger.java) [![Python](assets/python.png)](python/reverse_integer.py) [![js](assets/javascript.png)](javascript/ReverseInteger.js) | [![java-yt](assets/java-yt.png)](https://youtu.be/7bOhyl5lWjI) [![python-yt](assets/python-yt.png)](https://youtu.be/lmLG30TLcSg) | -| 8 | [String to Integer (atoi)](https://leetcode.com/problems/string-to-integer-atoi) | [![Java](assets/java.png)](src/StringToIntegerAtoi.java) | | -| 9 | [Palindrome Number](https://leetcode.com/problems/palindrome-number) | [![Java](assets/java.png)](src/PalindromeNumber.java) [![Python](assets/python.png)](python/palindrome_number.py) [![js](assets/javascript.png)](javascript/PalindromeNumber.js) | | -| 11 | [Container With Most Water](https://leetcode.com/problems/container-with-most-water) | [![Java](assets/java.png)](src/ContainerWitMostWater.java) | | -| 12 | [Integer to Roman](https://leetcode.com/problems/integer-to-roman) | [![Java](assets/java.png)](src/IntegerToRoman.java) | | -| 13 | [Roman To Integer](https://leetcode.com/problems/roman-to-integer/) | [![Java](assets/java.png)](src/RomanToInteger.java) [![Python](assets/python.png)](python/roman_to_integer.py) | [![java-yt](assets/java-yt.png)](https://youtu.be/BCue_mO_81A) [![python-yt](assets/python-yt.png)](https://youtu.be/8h_yGTNvKMA) | -| 14 | [Longest Common Prefix](https://leetcode.com/problems/longest-common-prefix/) | [![Java](assets/java.png)](src/LongestCommonPrefix.java) [![Python](assets/python.png)](python/longest_common_prefix.py) | | -| 15 | [3Sum](https://leetcode.com/problems/3sum) | [![Java](assets/java.png)](src/ThreeSum.java) | | -| 16 | [3Sum Closest](https://leetcode.com/problems/3sum-closest) | [![Java](assets/java.png)](src/ThreeSumClosest.java) | | -| 17 | [Letter Combinations of a Phone Number](https://leetcode.com/problems/letter-combinations-of-a-phone-number) | [![Java](assets/java.png)](src/LetterCombinationsOfAPhoneNumber.java) | | -| 18 | [4Sum](https://leetcode.com/problems/4sum) | [![Java](assets/java.png)](src/FourSum.java) | | -| 19 | [Remove Nth Node From End of List](https://leetcode.com/problems/remove-nth-node-from-end-of-list) | [![Java](assets/java.png)](src/RemoveNthNodeFromEndOfList.java) | | -| 20 | [ValidParentheses](https://leetcode.com/problems/valid-parentheses/) | [![Java](assets/java.png)](src/ValidParentheses.java) [![Python](assets/python.png)](python/valid_parentheses.py) | | -| 21 | [Merge 2 Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/) | [![Java](assets/java.png)](src/Merge2SortedLists.java) [![Python](assets/python.png)](python/merge_2_sorted_lists.py) | | -| 22 | [Generate Parentheses](https://leetcode.com/problems/generate-parentheses) | [![Java](assets/java.png)](src/GenerateParentheses.java) | | -| 24 | [Swap Nodes in Pairs](https://leetcode.com/problems/swap-nodes-in-pairs) | [![Java](assets/java.png)](src/SwapNodesInPairs.java) | | -| 26 | [Remove Duplicates From Sorted Array](https://leetcode.com/problems/remove-duplicates-from-sorted-array) | [![Java](assets/java.png)](src/RemoveDuplicatesFromSortedArray.java) [![Python](assets/python.png)](python/remove_duplicates_from_sorted_array.py) [![js](assets/javascript.png)](javascript/RemoveDuplicatesFromSortedArray.js) | | -| 27 | [Remove Element](https://leetcode.com/problems/remove-element/) | [![Java](assets/java.png)](src/RemoveElement.java) [![Python](assets/python.png)](python/remove_element.py) | | -| 28 | [Needle in Haystack](https://leetcode.com/problems/implement-strstr) | [![Java](assets/java.png)](src/NeedleInHaystack.java) [![Python](assets/python.png)](python/needle_in_haystack.py) | | -| 29 | [Divide Two Integers](https://leetcode.com/problems/divide-two-integers) | [![Java](assets/java.png)](src/DivideTwoIntegers.java) | | -| 31 | [Next Permutation](https://leetcode.com/problems/next-permutation) | [![Java](assets/java.png)](src/NextPermutation.java) | | -| 33 | [Search in Rotated Sorted Array](https://leetcode.com/problems/search-in-rotated-sorted-array) | [![Java](assets/java.png)](src/SearchInRotatedSortedArray.java) | | -| 34 | [Find First and Last Position of Element in Sorted Array](https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array) | [![Java](assets/java.png)](src/FindFirstAndLastPositionOfElementInSortedArray.java) | | -| 35 | [Search Inserted Position](https://leetcode.com/problems/search-insert-position/) | [![Java](assets/java.png)](src/SearchInsertPosition.java) [![Python](assets/python.png)](python/search_insert_position.py) | | -| 36 | [Valid Sudoku](https://leetcode.com/problems/valid-sudoku) | [![Java](assets/java.png)](src/ValidSudoku.java) | | -| 37 | [Sudoku Solver](https://leetcode.com/problems/sudoku-solver) | [![Java](assets/java.png)](src/SudokuSolver.java) | | -| 38 | [Count and Say](https://leetcode.com/problems/count-and-say) | [![Java](assets/java.png)](src/CountAndSay.java) [![Python](assets/python.png)](python/count_and_say.py) | | -| 39 | [Combination Sum](https://leetcode.com/problems/combination-sum) | [![Java](assets/java.png)](src/CombinationSum.java) | | -| 40 | [Combination Sum II](https://leetcode.com/problems/combination-sum-ii) | [![Java](assets/java.png)](src/CombinationSumII.java) | | -| 42 | [Trapping Rain Water](https://leetcode.com/problems/trapping-rain-water) | [![Java](assets/java.png)](src/TrappingRainwater.java) | | -| 43 | [Multiply Strings](https://leetcode.com/problems/multiply-strings) | [![Java](assets/java.png)](src/MultiplyStrings.java) | | -| 45 | [Jump Game II](https://leetcode.com/problems/jump-game-ii) | [![Java](assets/java.png)](src/JumpGameII.java) | | -| 46 | [Permutations](https://leetcode.com/problems/permutations) | [![Java](assets/java.png)](src/Permutations.java) | | -| 47 | [Permutations II](https://leetcode.com/problems/permutations-ii) | [![Java](assets/java.png)](src/PermutationsII.java) | | -| 48 | [Rotate Image](https://leetcode.com/problems/rotate-image) | [![Java](assets/java.png)](src/RotateImage.java) | | -| 49 | [Group Anagrams](https://leetcode.com/problems/group-anagrams) | [![Java](assets/java.png)](src/GroupAnagrams.java) | | -| 50 | [Pow(x,n)](https://leetcode.com/problems/powx-n) | [![Java](assets/java.png)](src/Powxn.java) | | -| 53 | [Maximum SubArray](https://leetcode.com/problems/maximum-subarray) | [![Java](assets/java.png)](src/MaximumSubArray.java) [![Python](assets/python.png)](python/maximum_sum_subarray.py) | | -| 54 | [Spiral Matrix](https://leetcode.com/problems/spiral-matrix) | [![Java](assets/java.png)](src/SpiralMatrix.java) | | -| 55 | [Jump Game](https://leetcode.com/problems/jump-game) | [![Java](assets/java.png)](src/JumpGame.java) | | -| 56 | [Merge Intervals](https://leetcode.com/problems/merge-intervals) | [![Java](assets/java.png)](src/MergeIntervals.java) | | -| 57 | [Insert Interval](https://leetcode.com/problems/insert-interval) | [![Java](assets/java.png)](src/InsertInterval.java) | | -| 58 | [Length of Last Word](https://leetcode.com/problems/length-of-last-word) | [![Java](assets/java.png)](src/LengthOfLastWord.java) [![Python](assets/python.png)](python/length_of_last_word.py) | | -| 59 | [Spiral Matrix II](https://leetcode.com/problems/spiral-matrix-ii) | [![Java](assets/java.png)](src/SpiralMatrixII.java) | | -| 61 | [Rotate List](https://leetcode.com/problems/rotate-list) | [![Java](assets/java.png)](src/RotateList.java) | | -| 62 | [Unique Paths](https://leetcode.com/problems/unique-paths) | [![Java](assets/java.png)](src/UniquePaths.java) | | -| 63 | [Unique Paths II](https://leetcode.com/problems/unique-paths-ii) | [![Java](assets/java.png)](src/UniquePathII.java) | | -| 64 | [Minimum Path Sum](https://leetcode.com/problems/minimum-path-sum) | [![Java](assets/java.png)](src/MinimumPathSum.java) [![Python](assets/python.png)](python/minimum_path_sum.py) | | -| 66 | [Plus One](https://leetcode.com/problems/plus-one) | [![Java](assets/java.png)](src/PlusOne.java) [![Python](assets/python.png)](python/plus_one.py) | | -| 67 | [Add Binary](https://leetcode.com/problems/add-binary) | [![Java](assets/java.png)](src/AddBinary.java) [![Python](assets/python.png)](python/add_binary.py) | | -| 69 | [Sqrt(x)](https://leetcode.com/problems/sqrtx) | [![Java](assets/java.png)](src/Sqrtx.java) [![Python](assets/python.png)](python/sqrt.py) | | -| 70 | [Climbing Stairs](https://leetcode.com/problems/climbing-stairs) | [![Java](assets/java.png)](src/ClimbingStairs.java) [![Python](assets/python.png)](python/climbing_stairs.py) | | -| 71 | [Simplify Path](https://leetcode.com/problems/simplify-path) | [![Java](assets/java.png)](src/SimplifyPath.java) | | -| 73 | [Set Matrix Zeroes](https://leetcode.com/problems/set-matrix-zeroes) | [![Java](assets/java.png)](src/SetMatrixZeroes.java) | | -| 74 | [Search a 2D Matrix](https://leetcode.com/problems/search-a-2d-matrix) | [![Java](assets/java.png)](src/SearchA2DMatrix.java) | | -| 75 | [Sort Colors](https://leetcode.com/problems/sort-colors) | [![Java](assets/java.png)](src/SortColors.java) | | -| 77 | [Combinations](https://leetcode.com/problems/combinations) | [![Java](assets/java.png)](src/Combinations.java) | | -| 78 | [Subsets](https://leetcode.com/problems/subsets) | [![Java](assets/java.png)](src/Subsets.java) | | -| 79 | [Word Search](https://leetcode.com/problems/word-search) | [![Java](assets/java.png)](src/WordSearch.java) | | -| 80 | [Remove Duplicates from Sorted Array II](https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii) | [![Java](assets/java.png)](src/RemoveDuplicatesFromSortedArrayII.java) | | -| 81 | [Search in Rotated Sorted Array II](https://leetcode.com/problems/search-in-rotated-sorted-array-ii) | [![Java](assets/java.png)](src/SearchInRotatedSortedArrayII.java) | | -| 82 | [Remove Duplicates from Sorted List II](https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii) | [![Java](assets/java.png)](src/RemoveDuplicatesFromSortedListII.java) | | -| 83 | [Remove Duplicates from Sorted List](https://leetcode.com/problems/remove-duplicates-from-sorted-list) | [![Java](assets/java.png)](src/RemoveDuplicatesFromSortedList.java) [![Python](assets/python.png)](python/remove_duplicates_from_linked_list.py) | | -| 86 | [Partition List](https://leetcode.com/problems/partition-list) | [![Java](assets/java.png)](src/PartitionList.java) | | -| 87 | [Scramble String](https://leetcode.com/problems/scramble-string) | [![Python](assets/python.png)](python/scramble_strings.py) | | -| 88 | [Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array) | [![Java](assets/java.png)](src/MergeSortedArray.java) [![Python](assets/python.png)](python/merge_sorted_array.py) | | -| 89 | [Gray Code](https://leetcode.com/problems/gray-code) | [![Java](assets/java.png)](src/GrayCode.java) | | -| 90 | [Subsets II](https://leetcode.com/problems/subsets-ii) | [![Java](assets/java.png)](src/SubsetsII.java) | | -| 91 | [Decode Ways](https://leetcode.com/problems/decode-ways) | [![Java](assets/java.png)](src/DecodeWays.java) | | -| 92 | [Reverse Linked List II](https://leetcode.com/problems/reverse-linked-list-ii) | [![Java](assets/java.png)](src/ReverseLinkedListII.java) | | -| 93 | [Restore IP Addresses](https://leetcode.com/problems/restore-ip-addresses) | [![Java](assets/java.png)](src/RestoreIPAddresses.java) | | -| 94 | [Binary Tree Inorder Traversal](https://leetcode.com/problems/binary-tree-inorder-traversal) | [![Java](assets/java.png)](src/BinaryTreeInorderTraversal.java) [![Python](assets/python.png)](python/binary_tree_inorder_traversal.py) | | -| 95 | [Unique Binary Search Trees II](https://leetcode.com/problems/unique-binary-search-trees-ii) | [![Java](assets/java.png)](src/UniqueBinarySearchTreesII.java) | | -| 96 | [Unique Binary Search Trees](https://leetcode.com/problems/unique-binary-search-trees) | [![Java](assets/java.png)](src/UniqueBinarySearchTrees.java) | | -| 97 | [Interleaving String](https://leetcode.com/problems/interleaving-string) | [![Java](assets/java.png)](src/InterleavingString.java) | | -| 98 | [Validate Binary Search Tree](https://leetcode.com/problems/validate-binary-search-tree) | [![Java](assets/java.png)](src/ValidateBinarySearchTree.java) | | -| 99 | [Recover Binary Search Tree](https://leetcode.com/problems/recover-binary-search-tree) | [![Java](assets/java.png)](src/RecoverBinarySearchTree.java) | | -| 100 | [Same Tree](https://leetcode.com/problems/same-tree) | [![Java](assets/java.png)](src/SameTree.java) [![Python](assets/python.png)](python/same_tree.py) | | -| 101 | [Symmetric Tree](https://leetcode.com/problems/symmetric-tree) | [![Java](assets/java.png)](src/SymmetricTree.java) [![Python](assets/python.png)](python/symmetric_tree.py) | | -| 102 | [Binary Tree Level Order Traversal](https://leetcode.com/problems/binary-tree-level-order-traversal) | [![Java](assets/java.png)](src/BinaryTreeLevelOrderTraversal.java) | | -| 103 | [Binary Tree Zigzag Level Order Traversal](https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal) | [![Java](assets/java.png)](src/BinaryTreeZigzagLevelOrderTraversal.java) | | -| 104 | [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree) | [![Java](assets/java.png)](src/MaximumDepthOfBinaryTree.java) [![Python](assets/python.png)](python/maximum_depth_of_binary_tree.py) | | -| 105 | [Construct Binary Tree from Preorder and Inorder Traversal](https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal) | [![Java](assets/java.png)](src/ConstructBinaryTreeFromPreorderAndInorderTraversal.java) | | -| 106 | [Construct Binary Tree from Inorder and Postorder Traversal](https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal) | [![Java](assets/java.png)](src/ConstructBinaryTreeFromInorderAndPostorderTraversal.java) | | -| 107 | [Binary Tree Level Order Traversal II](https://leetcode.com/problems/binary-tree-level-order-traversal-ii) | [![Java](assets/java.png)](src/BinaryTreeLevelOrderTraversalII.java) [![Python](assets/python.png)](python/binary_tree_level_order_traversal_ii.py) | | -| 108 | [Convert Sorted Array To Binary Search Tree](https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree) | [![Java](assets/java.png)](src/ConvertSortedArrayToBinarySearchTree.java) [![Python](assets/python.png)](python/converted_sorted_array_to_binary_search_tree.py) | | -| 109 | [Convert Sorted List to Binary Search Tree](https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree) | [![Java](assets/java.png)](src/ConvertSortedListToBinarySearchTree.java) | | -| 110 | [Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree) | [![Java](assets/java.png)](src/BalancedBinaryTree.java) [![Python](assets/python.png)](python/balanced_binary_tree.py) | | -| 111 | [Minimum Depth of Binary Tree](https://leetcode.com/problems/minimum-depth-of-binary-tree) | [![Java](assets/java.png)](src/MinimumDepthOfBinaryTree.java) [![Python](assets/python.png)](python/minimum_depth_of_binary_tree.py) | | -| 112 | [Path Sum](https://leetcode.com/problems/path-sum) | [![Java](assets/java.png)](src/PathSum.java) [![Python](assets/python.png)](python/path_sum.py) | | -| 113 | [Path Sum II](https://leetcode.com/problems/path-sum-ii) | [![Java](assets/java.png)](src/PathSumII.java) | | -| 114 | [Flatten Binary Tree to Linked List](https://leetcode.com/problems/flatten-binary-tree-to-linked-list) | [![Java](assets/java.png)](src/FlattenBinaryTreeToLinkedList.java) | | -| 116 | [Populating Next Right Pointers in Each Node](https://leetcode.com/problems/populating-next-right-pointers-in-each-node) | [![Java](assets/java.png)](src/PopulatingNextRightPointersInEachNode.java) | | -| 117 | [Populating Next Right Pointers in Each Node II](https://leetcode.com/problems/populating-next-right-pointers-in-each-node-ii) | [![Java](assets/java.png)](src/PopulatingNextRightPointersInEachNodeII.java) | | -| 118 | [Pascal's Triangle](https://leetcode.com/problems/pascals-triangle) | [![Java](assets/java.png)](src/PascalsTriangle.java) [![Python](assets/python.png)](python/pascals_triangle.py) | | -| 119 | [Pascal's Triangle II](https://leetcode.com/problems/pascals-triangle-ii) | [![Java](assets/java.png)](src/PascalsTriangleII.java) [![Python](assets/python.png)](python/pascals_triangle_ii.py) | | -| 120 | [Triangle](https://leetcode.com/problems/triangle) | [![Java](assets/java.png)](src/Triangle.java) | | -| 121 | [Best Time to Buy and Sell Stocks](https://leetcode.com/problems/best-time-to-buy-and-sell-stock) | [![Java](assets/java.png)](src/BestTimeToBuyAndSellStock.java) [![Python](assets/python.png)](python/best_time_to_buy_and_sell_stock.py) | | -| 122 | [Best Time to Buy and Sell Stocks II](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii) | [![Java](assets/java.png)](src/BestTimeToBuyAndSellStockII.java) [![Python](assets/python.png)](python/best_time_to_buy_and_sell_stock_ii.py) | | -| 125 | [Valid Palindrome](https://leetcode.com/problems/valid-palindrome) | [![Java](assets/java.png)](src/ValidPalindrome.java) [![Python](assets/python.png)](python/valid_palindrome.py) | | -| 128 | [Longest Consecutive Sequence](https://leetcode.com/problems/longest-consecutive-sequence) | [![Java](assets/java.png)](src/LongestConsecutiveSequence.java) | | -| 129 | [Sum Root to Leaf Numbers](https://leetcode.com/problems/sum-root-to-leaf-numbers) | [![Java](assets/java.png)](src/SumRootToLeafNumbers.java) | | -| 130 | [Surrounded Regions](https://leetcode.com/problems/surrounded-regions) | [![Java](assets/java.png)](src/SurroundedRegions.java) | | -| 131 | [Palindrome Partitioning](https://leetcode.com/problems/palindrome-partitioning) | [![Java](assets/java.png)](src/PalindromePartitioning.java) | | -| 133 | [Clone Graph](https://leetcode.com/problems/clone-graph) | [![Java](assets/java.png)](src/CloneGraph.java) [![Python](assets/python.png)](python/clone_graph.py) | | -| 134 | [Gas Station](https://leetcode.com/problems/gas-station) | [![Java](assets/java.png)](src/GasStation.java) | | -| 136 | [Single Number](https://leetcode.com/problems/single-number) | [![Java](assets/java.png)](src/SingleNumber.java) [![Python](assets/python.png)](python/single_number.py) | | -| 137 | [Single Number II](https://leetcode.com/problems/single-number-ii) | [![Java](assets/java.png)](src/SingleNumberII.java) | | -| 138 | [Copy List with Random Pointer](https://leetcode.com/problems/copy-list-with-random-pointer) | [![Java](assets/java.png)](src/CopyListWithRandomPointer.java) | | -| 139 | [Word Break](https://leetcode.com/problems/word-break) | [![Java](assets/java.png)](src/WordBreak.java) | | -| 141 | [Linked List Cycle](https://leetcode.com/problems/linked-list-cycle) | [![Java](assets/java.png)](src/LinkedListCycle.java) [![Python](assets/python.png)](python/linked_list_cycle.py) | | -| 142 | [Linked List Cycle II](https://leetcode.com/problems/linked-list-cycle-ii) | [![Java](assets/java.png)](src/LinkedListCycleII.java) | | -| 143 | [Reorder List](https://leetcode.com/problems/reorder-list) | [![Java](assets/java.png)](src/ReorderList.java) | | -| 144 | [Binary Tree Preorder Traversal](https://leetcode.com/problems/binary-tree-preorder-traversal) | [![Java](assets/java.png)](src/BinaryTreePreOrderTraversal.java) [![Python](assets/python.png)](python/binary_tree_preorder_traversal.py) | | -| 145 | [Binary Tree Postorder Traversal](https://leetcode.com/problems/binary-tree-postorder-traversal) | [![Java](assets/java.png)](src/BinaryTreePostorderTraversal.java) [![Python](assets/python.png)](python/binary_tree_postorder_traversal.py) | | -| 146 | [LRU Cache](https://leetcode.com/problems/lru-cache) | [![Java](assets/java.png)](src/LRUCache.java) | | -| 147 | [Insertion Sort List](https://leetcode.com/problems/insertion-sort-list) | [![Java](assets/java.png)](src/InsertionSortList.java) | | -| 148 | [Sort List](https://leetcode.com/problems/sort-list) | [![Java](assets/java.png)](src/SortList.java) | | -| 150 | [Evaluate Reverse Polish Notation](https://leetcode.com/problems/evaluate-reverse-polish-notation) | [![Java](assets/java.png)](src/EvaluateReversePolishNotation.java) | | -| 151 | [Reverse Words in a String](https://leetcode.com/problems/reverse-words-in-a-string) | [![Java](assets/java.png)](src/ReverseWordsInAString.java) | | -| 152 | [Maximum Product Subarray](https://leetcode.com/problems/maximum-product-subarray) | [![Java](assets/java.png)](src/MaximumProductSubarray.java) | | -| 153 | [Find Minimum in Rotated Sorted Array](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array) | [![Java](assets/java.png)](src/FindMinimumInRotatedSortedArray.java) | | -| 155 | [Min Stack](https://leetcode.com/problems/min-stack) | [![Java](assets/java.png)](src/MinStack.java) [![Python](assets/python.png)](python/min_stack.py) | | -| 156 | 🔒 [Binary Tree Upside Down](https://leetcode.com/problems/binary-tree-upside-down) | | | -| 157 | [Read N Characters Given Read4](https://leetcode.com/problems/read-n-characters-given-read4) | | | -| 159 | 🔒 [Longest Substring With At Most Two Distinct Characters](https://leetcode.com/problems/longest-substring-with-at-most-two-distinct-characters) | | | -| 160 | [Intersection of Two Linked Lists](https://leetcode.com/problems/intersection-of-two-linked-lists) | [![Java](assets/java.png)](src/IntersectionOf2LinkedLists.java) [![Python](assets/python.png)](python/intersecction_of_two_linked_lists.py) | | -| 161 | 🔒 [One Edit Distance](https://leetcode.com/problems/one-edit-distance) | | | -| 162 | [Find Peak Element](https://leetcode.com/problems/find-peak-element) | [![Java](assets/java.png)](src/FindPeakElement.java) | | -| 165 | [Compare Version Numbers](https://leetcode.com/problems/compare-version-numbers) | [![Java](assets/java.png)](src/CompareVersionNumbers.java) | | -| 166 | [Fraction to Recurring Decimal](https://leetcode.com/problems/fraction-to-recurring-decimal) | [![Java](assets/java.png)](src/FractionToRecurringDecimal.java) | | -| 167 | [Two Sum II - Input Array is Sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted) | [![Java](assets/java.png)](src/TwoSumIIInputArrayIsSorted.java) [![Python](assets/python.png)](python/two_sum_ii.py) | | -| 168 | [Excel Sheet Column Title](https://leetcode.com/problems/excel-sheet-column-title) | [![Java](assets/java.png)](src/ExcelSheetColumnTitle.java) [![Python](assets/python.png)](python/excel_sheet_column_title.py) | | -| 169 | [Majority Element](https://leetcode.com/problems/majority-element) | [![Java](assets/java.png)](src/MajorityElement.java) [![Python](assets/python.png)](python/majority_element.py) | | -| 170 | 🔒 [Two Sum III - Data Structure Design](https://leetcode.com/problems/two-sum-iii-data-structure-design) | | | -| 171 | [Excel Sheet Column Number](https://leetcode.com/problems/excel-sheet-column-number) | [![Java](assets/java.png)](src/ExcelSheetColumnNumber.java) [![Python](assets/python.png)](python/excel_sheet_column_number.py) | | -| 172 | [Factoring Trailing Zeroes](https://leetcode.com/problems/factorial-trailing-zeroes) | [![Java](assets/java.png)](src/FactorialTrailingZeros.java) [![Python](assets/python.png)](python/factorial_trailing_zeroes.py) | | -| 173 | [Binary Search Tree Iterator](https://leetcode.com/problems/binary-search-tree-iterator) | [![Java](assets/java.png)](src/BinarySearchTreeIterator.java) | | -| 179 | [Largest Number](https://leetcode.com/problems/largest-number) | [![Java](assets/java.png)](src/LargestNumber.java) | | -| 187 | [Repeated DNA Sequences](https://leetcode.com/problems/repeated-dna-sequences) | [![Java](assets/java.png)](src/RepeatedDNASequences.java) | | -| 189 | [Rotate Array](https://leetcode.com/problems/rotate-array) | [![Java](assets/java.png)](src/RotateArray.java) [![Python](assets/python.png)](python/rotate_array.py) | | -| 190 | [Reverse Bits](https://leetcode.com/problems/reverse-bits) | [![Java](assets/java.png)](src/ReverseBits.java) [![Python](assets/python.png)](python/reverse_bits.py) | | -| 191 | [Number of One Bits](https://leetcode.com/problems/number-of-1-bits) | [![Java](assets/java.png)](src/NumberOf1Bit.java) [![Python](assets/python.png)](python/number_of_1_bits.py) | | -| 198 | [House Robber](https://leetcode.com/problems/house-robber) | [![Java](assets/java.png)](src/HouseRobber.java) [![Python](assets/python.png)](python/house_robber.py) | | -| 199 | [Binary Tree Right Side View](https://leetcode.com/problems/binary-tree-right-side-view) | [![Java](assets/java.png)](src/BinaryTreeRightSideView.java) | | -| 200 | [Number of Islands](https://leetcode.com/problems/number-of-islands) | [![Java](assets/java.png)](src/NumberOfIslands.java) [![Python](assets/python.png)](python/number_of_islands.py) | | -| 201 | [Bitwise AND of Numbers Range](https://leetcode.com/problems/bitwise-and-of-numbers-range) | [![Java](assets/java.png)](src/BitwiseANDOfNumbersRange.java) | | -| 202 | [Happy Number](https://leetcode.com/problems/happy-number) | [![Java](assets/java.png)](src/HappyNumber.java) [![Python](assets/python.png)](python/happy_number.py) | | -| 203 | [Remove Linked List Elements](https://leetcode.com/problems/remove-linked-list-elements) | [![Java](assets/java.png)](src/RemoveLinkedListElements.java) [![Python](assets/python.png)](python/remove_linked_list_elements.py) | | -| 204 | [Count Primes](https://leetcode.com/problems/count-primes) | [![Java](assets/java.png)](src/CountPrimes.java) [![Python](assets/python.png)](python/count_primes.py) | | -| 205 | [Isomorphic Strings](https://leetcode.com/problems/isomorphic-strings) | [![Java](assets/java.png)](src/IsomorphicStrings.java) [![Python](assets/python.png)](python/isomorphic_strings.py) | | -| 206 | [Reverse Linked List](https://leetcode.com/problems/reverse-linked-list) | [![Java](assets/java.png)](src/ReverseLinkedList.java) [![Python](assets/python.png)](python/reverse_linked_list.py) | | -| 207 | [Course Schedule](https://leetcode.com/problems/course-schedule) | [![Java](assets/java.png)](src/CourseSchedule.java) | | -| 208 | [Implement Trie (Prefix Tree)](https://leetcode.com/problems/implement-trie-prefix-tree) | [![Java](assets/java.png)](src/Trie.java) [![Python](assets/python.png)](python/trie.py) | | -| 209 | [Minimum Size Subarray Sum](https://leetcode.com/problems/minimum-size-subarray-sum) | [![Java](assets/java.png)](src/MinimumSizeSubarraySum.java) | | -| 210 | [Course Schedule II](https://leetcode.com/problems/course-schedule-ii) | [![Java](assets/java.png)](src/CourseScheduleII.java) | | -| 211 | [Design Add and Search Words Data Structure](https://leetcode.com/problems/design-add-and-search-words-data-structure) | [![Java](assets/java.png)](src/DesignAddAndSearchWordsDataStructure.java) [![Python](assets/python.png)](python/design_add_and_search_words_data_structure.py) | | -| 213 | [House Robber II](https://leetcode.com/problems/house-robber-ii) | [![Java](assets/java.png)](src/HouseRobberII.java) | | -| 215 | [Kth Largest Element in an Array](https://leetcode.com/problems/kth-largest-element-in-an-array) | [![Java](assets/java.png)](src/KthLargestElementInAnArray.java) | | -| 216 | [Combination Sum III](https://leetcode.com/problems/combination-sum-iii) | [![Java](assets/java.png)](src/CombinationSumIII.java) | | -| 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate) | [![Java](assets/java.png)](src/ContainsDuplicate.java) [![Python](assets/python.png)](python/contains_duplicate.py) | | -| 218 | [The Skyline Problem](https://leetcode.com/problems/the-skyline-problem) | [![Python](assets/python.png)](python/the_skyline_problem.py) | | -| 219 | [Contains Duplicate II](https://leetcode.com/problems/contains-duplicate-ii) | [![Java](assets/java.png)](src/ContainsDuplicateII.java) [![Python](assets/python.png)](python/contains_duplicate_ii.py) | | -| 220 | [Contains Duplicate III](https://leetcode.com/problems/contains-duplicate-iii) | [![Java](assets/java.png)](src/ContainsDuplicateIII.java) | | -| 221 | [Maximal Square](https://leetcode.com/problems/maximal-square) | [![Java](assets/java.png)](src/MaximalSquare.java) | | -| 222 | [Count Complete Tree Nodes](https://leetcode.com/problems/count-complete-tree-nodes) | [![Java](assets/java.png)](src/CountCompleteTreeNodes.java) | | -| 223 | [Rectangle Area](https://leetcode.com/problems/rectangle-area) | [![Java](assets/java.png)](src/RectangleArea.java) | | -| 225 | [Implement Stack using Queues](https://leetcode.com/problems/implement-stack-using-queues) | [![Java](assets/java.png)](src/MyStack.java) [![Python](assets/python.png)](python/implement_stack_using_queues.py) | | -| 226 | [Invert Binary Tree](https://leetcode.com/problems/invert-binary-tree) | [![Java](assets/java.png)](src/InvertBinaryTree.java) [![Python](assets/python.png)](python/invert_binary_tree.py) | | -| 227 | [Basic Calculator II](https://leetcode.com/problems/basic-calculator-ii) | [![Java](assets/java.png)](src/BasicCalculatorII.java) | | -| 229 | [Majority Element II](https://leetcode.com/problems/majority-element-ii) | [![Java](assets/java.png)](src/MajorityElementII.java) | | -| 230 | [Kth Smallest Element in a BST](https://leetcode.com/problems/kth-smallest-element-in-a-bst) | [![Java](assets/java.png)](src/KthSmallestElementInABST.java) | | -| 231 | [Power of Two](https://leetcode.com/problems/power-of-two) | [![Java](assets/java.png)](src/PowerOf2.java) [![Python](assets/python.png)](python/is_power_of_2.py) | | -| 232 | [Implement Queue Using Stacks](https://leetcode.com/problems/implement-queue-using-stacks) | [![Java](assets/java.png)](src/MyQueue.java) [![Python](assets/python.png)](python/implement_queue_using_stacks.py) | | -| 234 | [Palindrome Linked Lists](https://leetcode.com/problems/palindrome-linked-list) | [![Java](assets/java.png)](src/PalindromeLinkedList.java) [![Python](assets/python.png)](python/palindrome_linked_list.py) | | -| 235 | [Lowest Common Ancestor of a Binary Search Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree) | [![Java](assets/java.png)](src/LowestCommonAncestorOfBinarySearchTree.java) [![Python](assets/python.png)](python/lowest_common_ancestor_of_bst.py) | | -| 236 | [Lowest Common Ancestor of a Binary Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree) | [![Java](assets/java.png)](src/LowestCommonAncestorOfBinaryTree.java) | | -| 237 | [Delete a Node In A Linked List](https://leetcode.com/problems/delete-node-in-a-linked-list) | [![Java](assets/java.png)](src/DeleteANodeInLinkedList.java) [![Python](assets/python.png)](python/delete_node_in_linked_list.py) | | -| 238 | [Product of Array Except Self](https://leetcode.com/problems/product-of-array-except-self) | [![Java](assets/java.png)](src/ProductOfArrayExceptItself.java) | | -| 240 | [Search a 2D Matrix II](https://leetcode.com/problems/search-a-2d-matrix-ii) | [![Java](assets/java.png)](src/SearchA2DMatrixII.java) | | -| 241 | [Different Ways to Add Parentheses](https://leetcode.com/problems/different-ways-to-add-parentheses) | | | -| 242 | [Valid Anagram](https://leetcode.com/problems/valid-anagram) | [![Java](assets/java.png)](src/ValidAnagram.java) [![Python](assets/python.png)](python/delete_node_in_linked_list.py) | | -| 243 | 🔒 [Shortest Word Distance](https://leetcode.com/problems/shortest-word-distance) | | | -| 244 | 🔒 [Shortest Word Distance II](https://leetcode.com/problems/shortest-word-distance-ii) | | | -| 245 | 🔒 [Shortest Word Distance III](https://leetcode.com/problems/shortest-word-distance-iii) | | | -| 246 | 🔒 [Strobogramatic Number](https://leetcode.com/problems/strobogrammatic-number) | | | -| 247 | 🔒 [Strobogramatic Number II](https://leetcode.com/problems/strobogrammatic-number-ii) | | | -| 249 | 🔒 [Group Shifted Strings](https://leetcode.com/problems/group-shifted-strings) | | | -| 250 | 🔒 [Count Univalue Subtrees](https://leetcode.com/problems/count-univalue-subtrees) | | | -| 251 | 🔒 [Flatten 2D Vector](https://leetcode.com/problems/flatten-2d-vector) | | | -| 252 | 🔒 [Meeting Rooms](https://leetcode.com/problems/meeting-rooms) | | | -| 253 | 🔒 [Meeting Rooms II](https://leetcode.com/problems/meeting-rooms-ii) | | | -| 254 | 🔒 [Factor Combinations](https://leetcode.com/problems/factor-combinations) | | | -| 255 | 🔒 [Verify Preorder Sequence In Binary Search Tree](https://leetcode.com/problems/verify-preorder-sequence-in-binary-search-tree) | | | -| 256 | 🔒 [Paint House](https://leetcode.com/problems/paint-house) | | | -| 257 | [Binary Tree Paths](https://leetcode.com/problems/binary-tree-paths) | [![Java](assets/java.png)](src/BinaryTreePaths.java) [![Python](assets/python.png)](python/binary_tree_paths.py) | | -| 258 | [Add Digits](https://leetcode.com/problems/add-digits) | [![Java](assets/java.png)](src/AddDigits.java) [![Python](assets/python.png)](python/add_digits.py) | | -| 259 | 🔒 [3Sum Smaller](https://leetcode.com/problems/3sum-smaller) | | | -| 260 | [Single Number III](https://leetcode.com/problems/single-number-iii) | [![Java](assets/java.png)](src/SingleNumberIII.java) | | -| 261 | 🔒 [Graph Valid Tree](https://leetcode.com/problems/graph-valid-tree) | | | -| 263 | [Ugly Number](https://leetcode.com/problems/ugly-number) | [![Java](assets/java.png)](src/UglyNumber.java) [![Python](assets/python.png)](python/ugly_number.py) | | -| 264 | [Ugly Number II](https://leetcode.com/problems/ugly-number-ii) | [![Java](assets/java.png)](src/UglyNumberII.java) | | -| 266 | 🔒 [Palindrome Permutation](https://leetcode.com/problems/palindrome-permutation) | | | -| 267 | 🔒 [Palindrome Permutation II](https://leetcode.com/problems/palindrome-permutation-ii) | | | -| 268 | [Missing Number](https://leetcode.com/problems/missing-number) | [![Java](assets/java.png)](src/MissingNumber.java) [![Python](assets/python.png)](python/missing_number.py) | | -| 270 | 🔒 [Closest Binary Search Tree Value](https://leetcode.com/problems/closest-binary-search-tree-value) | | | -| 271 | 🔒 [Encode and Decode Strings](https://leetcode.com/problems/encode-and-decode-strings) | | | -| 274 | [H-Index](https://leetcode.com/problems/h-index) | [![Java](assets/java.png)](src/HIndex.java) | | -| 275 | [H-Index II](https://leetcode.com/problems/h-index-ii) | [![Java](assets/java.png)](src/HIndexII.java) | | -| 276 | 🔒 [Paint Fence](https://leetcode.com/problems/paint-fence) | | | -| 277 | 🔒 [Find The Celebrity](https://leetcode.com/problems/find-the-celebrity) | | | -| 278 | [First Bad Version](https://leetcode.com/problems/first-bad-version) | [![Java](assets/java.png)](src/FirstBadVersion.java) [![Python](assets/python.png)](python/first_bad_version.py) | | -| 279 | [Perfect Squares](https://leetcode.com/problems/perfect-squares) | [![Java](assets/java.png)](src/PerfectSquares.java) | | -| 280 | 🔒 [Wiggle Sort](https://leetcode.com/problems/wiggle-sort) | | | -| 281 | 🔒 [Zigzag Iterator](https://leetcode.com/problems/zigzag-iterator) | | | -| 283 | [Move Zeroes](https://leetcode.com/problems/move-zeroes) | [![Java](assets/java.png)](src/MoveZeros.java) [![Python](assets/python.png)](python/move_zeroes.py) | | -| 284 | [Peeking Iterator](https://leetcode.com/problems/peeking-iterator) | [![Java](assets/java.png)](src/PeekingIterator.java) | | -| 285 | 🔒 [Inorder Successor in BST](https://leetcode.com/problems/inorder-successor-in-bst) | | | -| 286 | 🔒 [Walls and Gates](https://leetcode.com/problems/walls-and-gates) | | | -| 287 | [Find the Duplicate Number](https://leetcode.com/problems/find-the-duplicate-number) | [![Java](assets/java.png)](src/FindTheDuplicateNumber.java) | | -| 288 | 🔒 [Unique Word Abbreviation](https://leetcode.com/problems/unique-word-abbreviation) | | | -| 289 | [Game of Life](https://leetcode.com/problems/game-of-life) | | | -| 290 | [Word Pattern](https://leetcode.com/problems/word-pattern) | [![Java](assets/java.png)](src/WordPattern.java) [![Python](assets/python.png)](python/word_pattern.py) | | -| 291 | 🔒 [Word Pattern II](https://leetcode.com/problems/word-pattern-ii) | | | -| 292 | [Nim Game](https://leetcode.com/problems/nim-game) | [![Java](assets/java.png)](src/NimGame.java) [![Python](assets/python.png)](python/nim_game.py) | | -| 293 | 🔒 [Flip Game](https://leetcode.com/problems/flip-game) | | | -| 294 | 🔒 [Flip Game II](https://leetcode.com/problems/flip-game-ii) | | | -| 298 | 🔒 [Binary Tree Longest Consecutive Sequence](https://leetcode.com/problems/binary-tree-longest-consecutive-sequence) | | | -| 299 | [Bulls and Cows](https://leetcode.com/problems/bulls-and-cows) | [![Java](assets/java.png)](src/BullsAndCows.java) [![Python](assets/python.png)](python/bulls_and_cows.py) | | -| 300 | [Longest Increasing Subsequence](https://leetcode.com/problems/longest-increasing-subsequence) | | | -| 303 | [Range Sum Query - Immutable](https://leetcode.com/problems/range-sum-query-immutable) | [![Java](assets/java.png)](src/RangeSumQueryImmutable.java) [![Python](assets/python.png)](python/range_sum_query_immutable.py) | | -| 304 | [Range Sum Query 2D - Immutable](https://leetcode.com/problems/range-sum-query-2d-immutable) | | | -| 306 | [Additive Number](https://leetcode.com/problems/additive-number) | | | -| 307 | [Range Sum Query - Mutable](https://leetcode.com/problems/range-sum-query-mutable) | | | -| 309 | [Best Time to Buy and Sell Stock with Cooldown](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown) | | | -| 310 | [Minimum Height Trees](https://leetcode.com/problems/minimum-height-trees) | | | -| 311 | 🔒 [Sparse Matrix Multiplication](https://leetcode.com/problems/sparse-matrix-multiplication) | | | -| 313 | [Super Ugly Number](https://leetcode.com/problems/super-ugly-number) | | | -| 314 | 🔒 [Binary Tree Vertical Order Traversal](https://leetcode.com/problems/binary-tree-vertical-order-traversal) | | | -| 316 | [Remove Duplicate Letters](https://leetcode.com/problems/remove-duplicate-letters) | | | -| 318 | [Maximum Product of Word Lengths](https://leetcode.com/problems/maximum-product-of-word-lengths) | | | -| 319 | [Bulb Switcher](https://leetcode.com/problems/bulb-switcher) | | | -| 320 | 🔒 [Generalized Abbreviation](https://leetcode.com/problems/generalized-abbreviation) | | | -| 322 | [Coin Change](https://leetcode.com/problems/coin-change) | | | -| 323 | 🔒 [Number of Connected Components in Undirected Graph](https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph) | | | -| 324 | [Wiggle Sort II](https://leetcode.com/problems/wiggle-sort-ii) | | | -| 325 | 🔒 [Maximum Size Subarray Sum Equals K](https://leetcode.com/problems/maximum-size-subarray-sum-equals-k) | | | -| 326 | [Power of Three](https://leetcode.com/problems/power-of-three) | [![Java](assets/java.png)](src/PowerOfThree.java) [![Python](assets/python.png)](python/power_of_three.py) | | -| 328 | [Odd Even Linked List](https://leetcode.com/problems/odd-even-linked-list) | | | -| 331 | [Verify Preorder Serialization of a Binary Tree](https://leetcode.com/problems/verify-preorder-serialization-of-a-binary-tree) | | | -| 331 | 🔒 [Largest BST Subtree](https://leetcode.com/problems/largest-bst-subtree) | | | -| 334 | [Increasing Triplet Subsequence](https://leetcode.com/problems/increasing-triplet-subsequence) | | | -| 337 | [House Robber III](https://leetcode.com/problems/increasing-triplet-subsequence) | | | -| 338 | [Counting Bits](https://leetcode.com/problems/counting-bits/) | [![Java](assets/java.png)](src/CountingBits.java) [![Python](assets/python.png)](python/counting_bits.py) | | -| 339 | 🔒 [Nested List Weight Sum](https://leetcode.com/problems/nested-list-weight-sum) | | | -| 340 | 🔒 [Longest Substring with At Most K Distinct Characters](https://leetcode.com/problems/longest-substring-with-at-most-k-distinct-characters) | | | -| 341 | [Flatten Nested List Iterator](https://leetcode.com/problems/flatten-nested-list-iterator) | | | -| 342 | [Power of Four](https://leetcode.com/problems/power-of-four) | [![Java](assets/java.png)](src/PowerOf4.java) [![Python](assets/python.png)](python/power_of_four.py) | | -| 343 | [Integer Break](https://leetcode.com/problems/integer-break) | | | -| 344 | [Reverse A String](https://leetcode.com/problems/reverse-string) | [![Java](assets/java.png)](src/ReverseString.java) [![Python](assets/python.png)](python/reverse_a_string.py) | | -| 345 | [Reverse Vowels of A String](https://leetcode.com/problems/reverse-vowels-of-a-string) | [![Java](assets/java.png)](src/ReverseVowelsOfString.java) [![Python](assets/python.png)](python/reverse_vowels_of_a_string.py) | | -| 346 | 🔒 [Moving Average From Data Stream](https://leetcode.com/problems/moving-average-from-data-stream) | | | -| 347 | [Top K frequent Elements](https://leetcode.com/problems/top-k-frequent-elements) | | | -| 348 | 🔒 [Design Tic-Tac-Toe](https://leetcode.com/problems/design-tic-tac-toe) | | | -| 349 | [Intersection of 2 Arrays](https://leetcode.com/problems/intersection-of-two-arrays) | [![Java](assets/java.png)](src/IntersectionOfTwoArrays.java) [![Python](assets/python.png)](python/intersection_of_2_array.py) | | -| 350 | [Intersection of 2 Arrays II](https://leetcode.com/problems/intersection-of-two-arrays-ii) | [![Java](assets/java.png)](src/IntersectionOfTwoArraysII.java) [![Python](assets/python.png)](python/intersection_of_2_arrays_II.py) | | -| 351 | 🔒 [Android Unlock Patterns](https://leetcode.com/problems/android-unlock-patterns) | | | -| 355 | [Design Twitter](https://leetcode.com/problems/design-twitter) | | | -| 357 | [Count Numbers with Unique Digits](https://leetcode.com/problems/count-numbers-with-unique-digits) | | | -| 359 | 🔒 [Logger Rate Limiter](https://leetcode.com/problems/logger-rate-limiter) | | | -| 367 | [Valid Perfect Square](https://leetcode.com/problems/valid-perfect-square) | [![Java](assets/java.png)](src/IsPerfectSquare.java) [![Python](assets/python.png)](python/valid_perfect_square.py) | | -| 374 | [Guess Number Higher or Lower](https://leetcode.com/problems/guess-number-higher-or-lower) | [![Java](assets/java.png)](src/GuessNumberHigherOrLower.java) [![Python](assets/python.png)](python/guess_number_higher_or_lower.py) | | -| 383 | [Ransom Note](https://leetcode.com/problems/ransom-note) | [![Java](assets/java.png)](src/RansomNote.java) [![Python](assets/python.png)](python/ransom_note.py) | | -| 387 | [First Unique Character in String](https://leetcode.com/problems/first-unique-character-in-a-string) | [![Java](assets/java.png)](src/FirstUniqueCharacter.java) [![Python](assets/python.png)](python/first_unique_character_in_string.py) | | -| 389 | [Find the Difference](https://leetcode.com/problems/find-the-difference) | [![Java](assets/java.png)](src/FindTheDifference.java) [![Python](assets/python.png)](python/find_the_difference.py) | | -| 392 | [Is Subsequence](https://leetcode.com/problems/is-subsequence) | [![Java](assets/java.png)](src/IsSubsequence.java) [![Python](assets/python.png)](python/is_subsequence.py) | | -| 401 | [Binary Watch](https://leetcode.com/problems/binary-watch) | [![Java](assets/java.png)](src/BinaryWatch.java) [![Python](assets/python.png)](python/binary_watch.py) | | -| 404 | [Sum of Left Leaves](https://leetcode.com/problems/sum-of-left-leaves) | [![Java](assets/java.png)](src/SumOfLeftLeaves.java) [![Python](assets/python.png)](python/sum_of_left_leaves.py) | | -| 405 | [Convert a Number to Hexadecimal](https://leetcode.com/problems/convert-a-number-to-hexadecimal) | [![Java](assets/java.png)](src/ConvertNumberToHexadecimal.java) [![Python](assets/python.png)](python/convert_a_number_to_hexadecimal.py) | | -| 408 | 🔒 [Valid Word Abbreviation](https://leetcode.com/problems/valid-word-abbreviation) | | | -| 409 | [Longest Palindrome](https://leetcode.com/problems/longest-palindrome) | [![Java](assets/java.png)](src/LongestPalindrome.java) [![Python](assets/python.png)](python/longest_palindrome.py) | | -| 412 | [Fizz Buzz](https://leetcode.com/problems/fizz-buzz) | [![Java](assets/java.png)](src/FizzBuzz.java) [![Python](assets/python.png)](python/fizz_buzz.py) | | -| 414 | [Third Maximum Number](https://leetcode.com/problems/third-maximum-number) | [![Java](assets/java.png)](src/ThirdMaximumNumber.java) [![Python](assets/python.png)](python/fizz_buzz.py) | | -| 415 | [Add Strings](https://leetcode.com/problems/add-strings) | [![Java](assets/java.png)](src/AddString.java) [![Python](assets/python.png)](python/add_strings.py) | | -| 422 | 🔒 [Valid Word Square](https://leetcode.com/problems/valid-word-square) | | | -| 430 | [Flatten a Multilevel Doubly Linked List](https://leetcode.com/problems/flatten-a-multilevel-doubly-linked-list) | [![Java](assets/java.png)](src/FlattenAMultiLevelDoublyLinkedList.java) | | -| 434 | [Number of Segments in a String](https://leetcode.com/problems/number-of-segments-in-a-string) | [![Java](assets/java.png)](src/NumberOfSegmentsInString.java) [![Python](assets/python.png)](python/number_of_segments_in_a_string.py) | | -| 441 | [Arranging Coins](https://leetcode.com/problems/arranging-coins) | [![Java](assets/java.png)](src/ArrangingCoins.java) [![Python](assets/python.png)](python/arranging_coins.py) | | -| 443 | [String Compression](https://leetcode.com/problems/string-compression) | [![Java](assets/java.png)](src/StringCompression.java) [![Python](assets/python.png)](python/string_compression.py) | | -| 447 | [Number of Boomerangs](https://leetcode.com/problems/number-of-boomerangs) | [![Java](assets/java.png)](src/NumberOfBoomerangs.java) [![Python](assets/python.png)](python/number_of_boomerangs.py) | | -| 448 | [Find All Numbers Disappeared in an Array](https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array) | [![Java](assets/java.png)](src/FindAllNumbersDisappearedInAnArray.java) [![Python](assets/python.png)](python/find_all_numbers_disappeared_in_an_array.py) | | -| 453 | [Minimum Moves to Equal Array Elements](https://leetcode.com/problems/minimum-moves-to-equal-array-elements) | [![Java](assets/java.png)](src/MinimumMovesToEqualArrayElements.java) [![Python](assets/python.png)](python/minimum_moves_to_equal_array_element.py) | | -| 455 | [Assign Cookies](https://leetcode.com/problems/assign-cookies) | [![Java](assets/java.png)](src/AssignCookies.java) [![Python](assets/python.png)](python/assign_cookies.py) | | -| 459 | [Repeated Substring Pattern](https://leetcode.com/problems/repeated-substring-pattern) | [![Java](assets/java.png)](src/RepeatedSubstringPattern.java) [![Python](assets/python.png)](python/repeated_substring_pattern.py) | | -| 461 | [Hamming Distance](https://leetcode.com/problems/hamming-distance) | [![Java](assets/java.png)](src/HammingDistance.java) [![Python](assets/python.png)](python/hamming_distance.py) | | -| 463 | [Island Perimeter](https://leetcode.com/problems/island-perimeter) | [![Java](assets/java.png)](src/IslandPerimeter.java) [![Python](assets/python.png)](python/island_perimeter.py) | | -| 475 | [Heaters](https://leetcode.com/problems/heaters) | [![Java](assets/java.png)](src/Heaters.java) [![Python](assets/python.png)](python/heaters.py) | | -| 476 | [Number Complement](https://leetcode.com/problems/number-complement) | [![Java](assets/java.png)](src/NumberComplement.java) [![Python](assets/python.png)](python/number_complement.py) | | -| 482 | [License Key Formatting](https://leetcode.com/problems/license-key-formatting) | [![Java](assets/java.png)](src/LicenseKeyFormatting.java) [![Python](assets/python.png)](python/license_key_formatting.py) | | -| 485 | [Max Consecutive Ones](https://leetcode.com/problems/max-consecutive-ones) | [![Java](assets/java.png)](src/MaxConsecutiveOnes.java) [![Python](assets/python.png)](python/max_consecutive_ones.py) | | -| 492 | [Construct the Rectangle](https://leetcode.com/problems/construct-the-rectangle) | [![Java](assets/java.png)](src/ConstructTheRectangle.java) [![Python](assets/python.png)](python/construct_the_rectangle.py) | | -| 495 | [Teemo Attacking](https://leetcode.com/problems/teemo-attacking/) | [![Java](assets/java.png)](src/TeemoAttacking.java) [![Python](assets/python.png)](python/teemo_attacking.py) | | -| 496 | [Next Greater Element I](https://leetcode.com/problems/next-greater-element-i) | [![Java](assets/java.png)](src/NextGreaterElementI.java) [![Python](assets/python.png)](python/next_greater_element_i.py) | | -| 500 | [Keyboard Row](https://leetcode.com/problems/keyboard-row) | [![Java](assets/java.png)](src/KeyBoardRow.java) [![Python](assets/python.png)](python/keyboard_row.py) | | -| 501 | [Find Mode in Binary Search Tree](https://leetcode.com/problems/find-mode-in-binary-search-tree) | [![Java](assets/java.png)](src/FindModeInBinarySearchTree.java) [![Python](assets/python.png)](python/find_mode_in_binary_search_tree.py) | | -| 504 | [Base 7](https://leetcode.com/problems/base-7) | [![Java](assets/java.png)](src/Base7.java) [![Python](assets/python.png)](python/base_7.py) | | -| 506 | [Relative Ranks](https://leetcode.com/problems/relative-ranks) | [![Java](assets/java.png)](src/RelativeRanks.java) [![Python](assets/python.png)](python/relative_ranks.py) | | -| 507 | [Perfect Number](https://leetcode.com/problems/perfect-number) | [![Java](assets/java.png)](src/CheckPerfectNumber.java) [![Python](assets/python.png)](python/check_perfect_number.py) | | -| 509 | [Fibonacci Number](https://leetcode.com/problems/fibonacci-number) | [![Java](assets/java.png)](src/FibonacciNumber.java) [![Python](assets/python.png)](python/fibonacci_number.py) | | -| 520 | [Detect Capital](https://leetcode.com/problems/detect-capital) | [![Java](assets/java.png)](src/DetectCapital.java) [![Python](assets/python.png)](python/detect_capital.py) | | -| 521 | [Longest Uncommon Subsequence I](https://leetcode.com/problems/longest-uncommon-subsequence-i) | [![Java](assets/java.png)](src/LongestUncommonSubsequenceI.java) [![Python](assets/python.png)](python/longest_uncommon_subsequence_I.py) | | -| 530 | [Minimum Absolute Difference in BST](https://leetcode.com/problems/minimum-absolute-difference-in-bst) | [![Java](assets/java.png)](src/MinimumAbsoluteDifferenceInBST.java) [![Python](assets/python.png)](python/minimum_absolute_difference_in_bst.py) | | -| 532 | [K - Diff Pairs in Array](https://leetcode.com/problems/k-diff-pairs-in-an-array) | [![Java](assets/java.png)](src/KDiffPairsInAnArray.java) [![Python](assets/python.png)](python/k_dif_pairs_in_an_array.py) | | -| 538 | [Convert BST to Greater Tree](https://leetcode.com/problems/convert-bst-to-greater-tree) | [![Java](assets/java.png)](src/ConvertBSTToGreaterTree.java) [![Python](assets/python.png)](python/convert_bst_to_greater_tree.py) | | -| 541 | [Reverse String II](https://leetcode.com/problems/reverse-string-ii) | [![Java](assets/java.png)](src/ReverseStringII.java) [![Python](assets/python.png)](python/reverse_string_ii.py) | | -| 543 | [Diameter of Binary Tree](https://leetcode.com/problems/diameter-of-binary-tree) | [![Java](assets/java.png)](src/DiameterOfBinaryTree.java) [![Python](assets/python.png)](python/diameter_of_binary_tree.py) | | -| 551 | [Student Attendance Record I](https://leetcode.com/problems/student-attendance-record-i) | [![Java](assets/java.png)](src/StudentAttendanceRecordI.java) [![Python](assets/python.png)](python/student_attendance_record_I.py) | | -| 557 | [Reverse Words in a String III](https://leetcode.com/problems/reverse-words-in-a-string-iii) | [![Java](assets/java.png)](src/ReverseWordsInStringIII.java) [![Python](assets/python.png)](python/reverse_words_in_string_iii.py) | | -| 559 | [Maximum Depth of N-Ary Tree](https://leetcode.com/problems/maximum-depth-of-n-ary-tree) | [![Java](assets/java.png)](src/MaximumDepthOfNAryTree.java) [![Python](assets/python.png)](python/maximum_depth_of_n_ary_tree.py) | | -| 561 | [Array Partition I](https://leetcode.com/problems/array-partition-i) | [![Java](assets/java.png)](src/ArrayPartitionI.java) [![Python](assets/python.png)](python/array_partiton_I.py) | | -| 563 | [Binary Tree Tilt](https://leetcode.com/problems/binary-tree-tilt) | [![Java](assets/java.png)](src/BinaryTreeTilt.java) [![Python](assets/python.png)](python/binary_tree_tilt.py) | | -| 566 | [Reshape The Matrix](https://leetcode.com/problems/reshape-the-matrix) | [![Java](assets/java.png)](src/ReshapeTheMatrix.java) [![Python](assets/python.png)](python/reshape_the_matrix.py) | | -| 572 | [Subtree of Another Tree](https://leetcode.com/problems/subtree-of-another-tree) | [![Java](assets/java.png)](src/SubtreeOfAnotherTree.java) [![Python](assets/python.png)](python/subtree_of_another_tree.py) | | -| 575 | [Distribute Candies](https://leetcode.com/problems/distribute-candies) | [![Java](assets/java.png)](src/DistributeCandies.java) [![Python](assets/python.png)](python/distribute_candies.py) | | -| 581 | [Shortest Unsorted Continuous Subarray](https://leetcode.com/problems/shortest-unsorted-continuous-subarray) | [![Java](assets/java.png)](src/ShortestUnsortedContinuousSubarray.java) [![Python](assets/python.png)](python/shortest_continuous_unsorted_subarray.py) | | -| 589 | [N-Ary Tree Preorder Traversal](https://leetcode.com/problems/n-ary-tree-preorder-traversal) | [![Java](assets/java.png)](src/NArayTreePreOrderTraversal.java) [![Python](assets/python.png)](python/n_ary_tree_preorder_traversal.py) | | -| 590 | [N-Ary Tree Postorder Traversal](https://leetcode.com/problems/n-ary-tree-postorder-traversal) | [![Java](assets/java.png)](src/NAryTreePostorderTraversal.java) [![Python](assets/python.png)](python/n_ary_tree_postorder_traversal.py) | | -| 594 | [Longest Harmonious Subsequence](https://leetcode.com/problems/longest-harmonious-subsequence) | [![Java](assets/java.png)](src/LongestHarmoniousSubsequence.java) [![Python](assets/python.png)](python/longest_harmonious_subequence.py) | | -| 598 | [Range Addition II](https://leetcode.com/problems/range-addition-ii) | [![Java](assets/java.png)](src/RangeAdditionII.java) [![Python](assets/python.png)](python/range_addition_ii.py) | | -| 599 | [Minimum Index Sum of 2 Lists](https://leetcode.com/problems/minimum-index-sum-of-two-lists) | [![Java](assets/java.png)](src/MinimumIndexSumOfTwoLists.java) [![Python](assets/python.png)](python/minimum_index_sum_of_two_lists.py) | | -| 604 | 🔒 [Design Compressed String Iterator](https://leetcode.com/problems/design-compressed-string-iterator) | | | -| 605 | [Can Place Flowers](https://leetcode.com/problems/can-place-flowers) | [![Java](assets/java.png)](src/CanPlaceFlowers.java) [![Python](assets/python.png)](python/can_place_flowers.py) | | -| 606 | [Construct String from Binary Tree](https://leetcode.com/problems/construct-string-from-binary-tree) | [![Java](assets/java.png)](src/ConstructStringFromBinaryTree.java) [![Python](assets/python.png)](python/construct_string_from_binary_tree.py) | | -| 617 | [Merge Two Binary Trees](https://leetcode.com/problems/merge-two-binary-trees) | [![Java](assets/java.png)](src/MergeTwoBinaryTrees.java) [![Python](assets/python.png)](python/merge_two_binary_trees.py) | | -| 624 | 🔒 [Maximum Distance in Arrays](https://leetcode.com/problems/maximum-distance-in-arrays) | | | -| 628 | [Maximum Product of Three Numbers](https://leetcode.com/problems/maximum-product-of-three-numbers) | [![Java](assets/java.png)](src/MaximumProductOfThreeNumbers.java) [![Python](assets/python.png)](python/maximum_product_of_three_numbers.py) | | -| 633 | [Sum Square Numbers](https://leetcode.com/problems/sum-of-square-numbers) | [![Java](assets/java.png)](src/SumOfSquareNumbers.java) [![Python](assets/python.png)](python/sum_of_squares_numbers.py) | | -| 637 | [Average of Levels in Binary Tree](https://leetcode.com/problems/average-of-levels-in-binary-tree) | [![Java](assets/java.png)](src/AverageLevelsOfBinaryTree.java) [![Python](assets/python.png)](python/average_levels_of_binary_tree.py) | | -| 643 | [Maximum Average SubArray I](https://leetcode.com/problems/maximum-average-subarray-i) | [![Java](assets/java.png)](src/MaximumAverageSubArrayI.java) [![Python](assets/python.png)](python/maximum_average_subarray_I.py) | | -| 645 | [Set Mismatch](https://leetcode.com/problems/set-mismatch) | [![Java](assets/java.png)](src/SetMismatch.java) [![Python](assets/python.png)](python/set_mismatch.py) | | -| 653 | [Two Sum IV - Input is a BST](https://leetcode.com/problems/two-sum-iv-input-is-a-bst) | [![Java](assets/java.png)](src/TwoSumIVInputIsABST.java) [![Python](assets/python.png)](python/two_sum_iv.py) | | -| 657 | [Robot Return to Origin](https://leetcode.com/problems/robot-return-to-origin) | [![Java](assets/java.png)](src/RobotReturnToOrigin.java) [![Python](assets/python.png)](python/robot_return_to_origin.py) | | -| 661 | [Image Smoother](https://leetcode.com/problems/image-smoother) | [![Java](assets/java.png)](src/ImageSmoother.java) [![Python](assets/python.png)](python/image_smoother.py) | | -| 665 | [Non Deceasing Array](https://leetcode.com/problems/non-decreasing-array) | [![Java](assets/java.png)](src/NonDecreasingArray.java) [![Python](assets/python.png)](python/non_decreasing_array.py) | | -| 669 | [Trim a Binary Search Tree](https://leetcode.com/problems/trim-a-binary-search-tree) | [![Java](assets/java.png)](src/TrimABinarySearchTree.java) [![Python](assets/python.png)](python/trim_a_binary_search_tree.py) | | -| 671 | [Second Minimum Node in Binary Tree](https://leetcode.com/problems/second-minimum-node-in-a-binary-tree) | [![Java](assets/java.png)](src/SecondMinimumNodeInBinaryTree.java) [![Python](assets/python.png)](python/second_minimum_node_in_binary_tree.py) | | -| 674 | [Longest Continuous Increasing Subsequence](https://leetcode.com/problems/longest-continuous-increasing-subsequence) | [![Java](assets/java.png)](src/LongestContinuousIncreasingSubsequence.java) [![Python](assets/python.png)](python/longest_continuous_increasing_subsequence.py) | | -| 680 | [Valid Palindrome II](https://leetcode.com/problems/valid-palindrome-ii) | [![Java](assets/java.png)](src/ValidPalindromeII.java) [![Python](assets/python.png)](python/valid_pallindrome_ii.py) | | -| 682 | [Baseball Game](https://leetcode.com/problems/baseball-game) | [![Java](assets/java.png)](src/BaseballGame.java) [![Python](assets/python.png)](python/baseball_game.py) | | -| 686 | [Repeated String Match](https://leetcode.com/problems/repeated-string-match) | | | -| 687 | [Longest Univalue Path](https://leetcode.com/problems/longest-univalue-path) | | | -| 688 | [Knight Probability in Chessboard](https://leetcode.com/problems/knight-probability-in-chessboard) | [![Java](assets/java.png)](src/KnightProbabilityInChessboard.java) | | -| 690 | [Employee Importance](https://leetcode.com/problems/employee-importance) | | | -| 693 | [Binary Number with Alternating Bits](https://leetcode.com/problems/binary-number-with-alternating-bits) | [![Java](assets/java.png)](src/BinaryNumberWithAlternatingBits.java) [![Python](assets/python.png)](python/binary_number_with_alternating_bits.py) | | -| 696 | [Count Binary Substrings](https://leetcode.com/problems/count-binary-substrings) | [![Java](assets/java.png)](src/CountBinarySubstrings.java) [![Python](assets/python.png)](python/count_binary_substrings.py) | | -| 697 | [Degree of an Array](https://leetcode.com/problems/degree-of-an-array) | [![Java](assets/java.png)](src/DegreeOfAnArray.java) [![Python](assets/python.png)](python/degree_of_an_array.py) | | -| 700 | [Search in a Binary Search Tree](https://leetcode.com/problems/search-in-a-binary-search-tree) | [![Java](assets/java.png)](src/SearchInBinarySearchTree.java) [![Python](assets/python.png)](python/search_in_binary_search_tree.py) | | -| 703 | [Kth Largest Element in a Stream](https://leetcode.com/problems/kth-largest-element-in-a-stream) | [![Java](assets/java.png)](src/KthLargestElementInAStream.java) [![Python](assets/python.png)](python/k_th_largest_element_in_a_stream.py) | | -| 704 | [Binary Search](https://leetcode.com/problems/binary-search) | [![Java](assets/java.png)](src/BinarySearch.java) [![Python](assets/python.png)](python/binary_search.py) | | -| 705 | [Design HashSet](https://leetcode.com/problems/design-hashset) | [![Java](assets/java.png)](src/DesignHashSet.java) [![Python](assets/python.png)](python/design_hash_set.py) | | -| 706 | [Design HashMap](https://leetcode.com/problems/design-hashmap) | [![Java](assets/java.png)](src/DesignHashMap.java) [![Python](assets/python.png)](python/design_hash_map.py) | | -| 709 | [To Lower Case](https://leetcode.com/problems/to-lower-case) | [![Java](assets/java.png)](src/ToLowerCase.java) [![Python](assets/python.png)](python/to_lower_case.py) | | -| 716 | 🔒 [Max Stack](https://leetcode.com/problems/max-stack) | | | -| 717 | [1-bit and 2-bit Characters](https://leetcode.com/problems/1-bit-and-2-bit-characters) | [![Java](assets/java.png)](src/OneBitAndTwoBitCharacters.java) [![Python](assets/python.png)](python/one_bit_and_two_bit_characters.py) | | -| 718 | [Maximum Length of Repeated Subarray](https://leetcode.com/problems/maximum-length-of-repeated-subarray) | [![Java](assets/java.png)](src/MaximumLengthOfRepeatedSubArray.java) | | -| 720 | [Longest Word in Dictionary](https://leetcode.com/problems/longest-word-in-dictionary) | | | -| 724 | [Find Pivot Index](https://leetcode.com/problems/find-pivot-index) | [![Java](assets/java.png)](src/FindPivotIndex.java) [![Python](assets/python.png)](python/find_pivot_index.py) | | -| 728 | [Self Dividing Numbers](https://leetcode.com/problems/self-dividing-numbers) | [![Java](assets/java.png)](src/SelfDividingNumbers.java) [![Python](assets/python.png)](python/self_dividing_number.py) | | -| 733 | [Flood Fill](https://leetcode.com/problems/flood-fill) | [![Java](assets/java.png)](src/FloodFill.java) [![Python](assets/python.png)](python/flood_fill.py) | | -| 743 | [Network Delay Time](https://leetcode.com/problems/network-delay-time) | [![Java](assets/java.png)](src/NetworkDelayTime.java) | | -| 734 | [Sentence Similarity](https://leetcode.com/problems/sentence-similarity) | | | -| 744 | [Find Smallest Letter Greater Than Target](https://leetcode.com/problems/find-smallest-letter-greater-than-target) | [![Java](assets/java.png)](src/FindSmallestLetterGreaterThanTarget.java) [![Python](assets/python.png)](python/find_smallest_letter_greater_than.py) | | -| 746 | [Min Cost Climbing Stairs](https://leetcode.com/problems/min-cost-climbing-stairs) | [![Java](assets/java.png)](src/MinCostClimbingStairs.java) [![Python](assets/python.png)](python/min_cost_climbing_stairs.py) | | -| 747 | [Largest Number at least Twice of Others](https://leetcode.com/problems/largest-number-at-least-twice-of-others) | [![Java](assets/java.png)](src/LargestNumberAtLeastTwiceOfOthers.java) [![Python](assets/python.png)](python/largest_number_at_least_twice_of_others.py) | | -| 748 | [Shortest Completing Word](https://leetcode.com/problems/shortest-completing-word) | [![Java](assets/java.png)](src/ShortestCompletingWord.java) [![Python](assets/python.png)](python/shortest_completing_word.py) | | -| 758 | [Bold Words in String](https://leetcode.com/problems/bold-words-in-string) | | | -| 760 | [Find Anagram Mappings](https://leetcode.com/problems/find-anagram-mappings) | | | -| 762 | [Prime Number of Set Bits in Primary Representation](https://leetcode.com/problems/prime-number-of-set-bits-in-binary-representation) | [![Java](assets/java.png)](src/PrimeNumberOfSetBitsInBinaryRepresentation.java) [![Python](assets/python.png)](python/prime_number_of_set_bits_in_binary_representation.py) | | -| 766 | [Toeplitz Matrix](https://leetcode.com/problems/toeplitz-matrix) | [![Java](assets/java.png)](src/ToeplitzMatrix.java) [![Python](assets/python.png)](python/toeplitz_matrix.py) | | -| 771 | [Jewels and Stones](https://leetcode.com/problems/jewels-and-stones) | [![Java](assets/java.png)](src/JewelsAndStones.java) [![Python](assets/python.png)](python/jewels_and_stones.py) | | -| 783 | [Minimum Distance Between BST Nodes](https://leetcode.com/problems/minimum-distance-between-bst-nodes) | [![Java](assets/java.png)](src/MinimumAbsoluteDifferenceInBST.java) [![Python](assets/python.png)](python/minimum_distance_between_bst_nodes.py) | | -| 788 | [Rotated Digits](https://leetcode.com/problems/rotated-digits) | | | -| 796 | [Rotate String](https://leetcode.com/problems/rotate-string) | [![Java](assets/java.png)](src/RotateString.java) | | -| 800 | [Similar RGB Color](https://leetcode.com/problems/similar-rgb-color) | | | -| 804 | [Unique Morse Code Words](https://leetcode.com/problems/unique-morse-code-words) | [![Java](assets/java.png)](src/UniqueMorseCodeWords.java) | | -| 806 | [Number of Lines to Write String](https://leetcode.com/problems/number-of-lines-to-write-string) | [![Java](assets/java.png)](src/NumberOfLinesToWriteInString.java) | | -| 811 | [Subdomain Visit Count](https://leetcode.com/problems/subdomain-visit-count) | | | -| 812 | [Largest Triangle Area](https://leetcode.com/problems/largest-triangle-area) | [![Java](assets/java.png)](src/LargestTriangleArea.java) | | -| 819 | [Most Common Word](https://leetcode.com/problems/most-common-word) | [![Java](assets/java.png)](src/MostCommonWord.java) | | -| 821 | [Shortest Distance to Character](https://leetcode.com/problems/shortest-distance-to-a-character) | [![Java](assets/java.png)](src/ShortestDistanceToACharacter.java) | | -| 824 | [Goat Latin](https://leetcode.com/problems/goat-latin) | [![Java](assets/java.png)](src/GoatLatin.java) | | -| 830 | [Positions of Large Groups](https://leetcode.com/problems/positions-of-large-groups) | [![Java](assets/java.png)](src/PositionsOfLargeGroups.java) | | -| 832 | [Flipping an Image](https://leetcode.com/problems/flipping-an-image) | [![Java](assets/java.png)](src/FlippingAnImage.java) | | -| 836 | [Rectangle Overlap](https://leetcode.com/problems/rectangle-overlap) | [![Java](assets/java.png)](src/RectangleOverlap.java) | | -| 840 | [Magic Squares in Grid](https://leetcode.com/problems/magic-squares-in-grid) | | | -| 844 | [Backspace String Compare](https://leetcode.com/problems/backspace-string-compare) | [![Java](assets/java.png)](src/BackspaceStringCompare.java) | | -| 849 | [Maximize Distance to Closest Person](https://leetcode.com/problems/maximize-distance-to-closest-person) | | | -| 852 | [Peak Index in Mountain Array](https://leetcode.com/problems/peak-index-in-a-mountain-array) | [![Java](assets/java.png)](src/PeakIndexInMountainArray.java) | | -| 859 | [Buddy Strings](https://leetcode.com/problems/buddy-strings) | [![Java](assets/java.png)](src/BuddyStrings.java) | | -| 860 | [Lemonade Change](https://leetcode.com/problems/lemonade-change) | [![Java](assets/java.png)](src/LemonadeChange.java) | | -| 867 | [Transpose Matrix](https://leetcode.com/problems/transpose-matrix) | [![Java](assets/java.png)](src/TransposeMatrix.java) | | -| 868 | [Binary Gap](https://leetcode.com/problems/binary-gap) | [![Java](assets/java.png)](src/BinaryGap.java) | | -| 872 | [Leaf-Similar Trees](https://leetcode.com/problems/leaf-similar-trees) | [![Java](assets/java.png)](src/LeafSimilarTrees.java) | | -| 874 | [Walking Robot Simulation](https://leetcode.com/problems/walking-robot-simulation) | | | -| 876 | [Middle of the Linked List](https://leetcode.com/problems/middle-of-the-linked-list) | [![Java](assets/java.png)](src/MiddleOfTheLinkedList.java) | | -| 881 | [Boats to Save People](https://leetcode.com/problems/boats-to-save-people) | [![Python](assets/python.png)](python/boats_to_save_people.py) | | -| 883 | [Projection Area of 3D Shapes](https://leetcode.com/problems/projection-area-of-3d-shapes) | [![Java](assets/java.png)](src/ProjectionAreaOf3DShapes.java) | | -| 884 | [Uncommon Words from 2 Sentences](https://leetcode.com/problems/uncommon-words-from-two-sentences) | [![Java](assets/java.png)](src/UncommonWordsFromTwoSentences.java) | | -| 888 | [Fair Candy Swap](https://leetcode.com/problems/fair-candy-swap) | [![Java](assets/java.png)](src/FairCandySwap.java) | | -| 892 | [Surface Area of 3D Shapes](https://leetcode.com/problems/surface-area-of-3d-shapes) | [![Java](assets/java.png)](src/SurfaceAreaOf3DShapes.java) | | -| 893 | [Groups of Special Equivalent Strings](https://leetcode.com/problems/groups-of-special-equivalent-strings) | | | -| 896 | [Monotonic Array](https://leetcode.com/problems/monotonic-array) | [![Java](assets/java.png)](src/MonotonicArray.java) | | -| 897 | [Increasing Order Search Tree](https://leetcode.com/problems/increasing-order-search-tree) | [![Java](assets/java.png)](src/IncreasingOrderSearchTree.java) | | -| 905 | [Sort Array by Parity](https://leetcode.com/problems/sort-array-by-parity) | | | -| 908 | [Smallest Range I](https://leetcode.com/problems/smallest-range-i) | [![Java](assets/java.png)](src/SmallestRangeI.java) | | -| 914 | [X of a kind in a Deck of Cards](https://leetcode.com/problems/x-of-a-kind-in-a-deck-of-cards) | [![Java](assets/java.png)](src/XOfAKindInADeckOfCards.java) | | -| 917 | [Reverse Only Letters](https://leetcode.com/problems/reverse-only-letters) | [![Java](assets/java.png)](src/ReverseOnlyLetters.java) | | -| 922 | [Sort Array by Parity II](https://leetcode.com/problems/sort-array-by-parity-ii) | [![Java](assets/java.png)](src/SortArrayByParityII.java) | | -| 925 | [Long Pressed Name](https://leetcode.com/problems/long-pressed-name) | [![Java](assets/java.png)](src/LongPressedName.java) | | -| 929 | [Unique Email Addresses](https://leetcode.com/problems/unique-email-addresses) | [![Java](assets/java.png)](src/UniqueEmailAddresses.java) | | -| 933 | [Number of Recent Calls](https://leetcode.com/problems/number-of-recent-calls) | [![Java](assets/java.png)](src/NumberOfRecentCalls.java) | | -| 937 | [Reorder Data In Log Files](https://leetcode.com/problems/reorder-data-in-log-files) | [![Java](assets/java.png)](src/ReorderDataInLogFiles.java) | | -| 938 | [Range Sum of BST](https://leetcode.com/problems/range-sum-of-bst) | [![Java](assets/java.png)](src/RangeSumOfBST.java) | | -| 941 | [Valid Mountain Array](https://leetcode.com/problems/valid-mountain-array) | [![Java](assets/java.png)](src/ValidMountainArray.java) [![Python](assets/python.png)](python/valid_mountain_array.py) | | -| 942 | [DI String Match](https://leetcode.com/problems/di-string-match) | [![Java](assets/java.png)](src/DIStringMatch.java) | | -| 944 | [Delete Columns to Make Sorted](https://leetcode.com/problems/delete-columns-to-make-sorted) | [![Java](assets/java.png)](src/DeleteColumnsToMakeSorted.java) | | -| 949 | [Largest Time for Given Digits](https://leetcode.com/problems/largest-time-for-given-digits) | | | -| 953 | [Verifying an Alien Dictionary](https://leetcode.com/problems/verifying-an-alien-dictionary) | [![Java](assets/java.png)](src/VerifyAnAlienDictionary.java) | | -| 961 | [N-Repeated Elements in Size 2N Array](https://leetcode.com/problems/n-repeated-element-in-size-2n-array) | [![Java](assets/java.png)](src/NRepeatedElementInSizeNArray.java) | | -| 965 | [Univalued Binary Tree](https://leetcode.com/problems/univalued-binary-tree) | [![Java](assets/java.png)](src/UnivaluedBinaryTree.java) | | -| 970 | [Powerful Integers](https://leetcode.com/problems/powerful-integers) | | | -| 976 | [Largest Perimeter Triangle](https://leetcode.com/problems/largest-perimeter-triangle) | [![Java](assets/java.png)](src/LargestPerimeterTriangle.java) | | -| 977 | [Squares of a Sorted Array](https://leetcode.com/problems/squares-of-a-sorted-array) | | | -| 983 | [Minimum Cost For Tickets](https://leetcode.com/problems/minimum-cost-for-tickets) | [![Python](assets/python.png)](python/minimum_cost_for_tickets.py) | | -| 985 | [Sum of Even Numbers after Queries](https://leetcode.com/problems/sum-of-even-numbers-after-queries) | | | -| 989 | [Add to Array Form of Integer](https://leetcode.com/problems/add-to-array-form-of-integer) | [![Java](assets/java.png)](src/AddToArrayFormOfInteger.java) | | -| 993 | [Cousins in Binary Tree](https://leetcode.com/problems/cousins-in-binary-tree) | [![Java](assets/java.png)](src/CousinsInBinaryTree.java) | | -| 994 | [Rotting Oranges](https://leetcode.com/problems/rotting-oranges) | [![Java](assets/java.png)](src/RottingOranges.java) | | -| 997 | [Find the Town Judge](https://leetcode.com/problems/find-the-town-judge) | [![Java](assets/java.png)](src/FindTheTownJudge.java) | | -| 999 | [Available Captures for Rook](https://leetcode.com/problems/available-captures-for-rook) | [![Java](assets/java.png)](src/AvailableCapturesForRook.java) | | -| 1002 | [Find Common Characters](https://leetcode.com/problems/find-common-characters) | [![Java](assets/java.png)](src/FindCommonCharacters.java) | | -| 1005 | [Maximize Sum of Array After K Negations](https://leetcode.com/problems/maximize-sum-of-array-after-k-negations) | [![Java](assets/java.png)](src/MaximizeSumOfArrayAfterKNegations.java) | | -| 1009 | [Complement of Base 10 Integer](https://leetcode.com/problems/complement-of-base-10-integer) | [![Java](assets/java.png)](src/NumberComplement.java) | | -| 1010 | [Pairs of Songs With Total Durations Divisible by 60](https://leetcode.com/problems/pairs-of-songs-with-total-durations-divisible-by-60) | [![Java](assets/java.png)](src/PartitionArrayIntoThreePartsWithEqualSum.java) | | -| 1013 | [Partition Array into Three Parts with equal Sum](https://leetcode.com/problems/partition-array-into-three-parts-with-equal-sum) | | | -| 1018 | [Binary Prefix Divisible by 5](https://leetcode.com/problems/binary-prefix-divisible-by-5) | [![Java](assets/java.png)](src/BinaryPrefixDivisibleBy5.java) | | -| 1020 | [Number of Enclaves](https://leetcode.com/problems/number-of-enclaves) | [![Python](assets/python.png)](python/number_of_enclaves.py) | | -| 1021 | [Remove Outermost Parenthesis](https://leetcode.com/problems/remove-outermost-parentheses) | [![Java](assets/java.png)](src/RemoveOutermostParentheses.java) | | -| 1022 | [Sum of Root to Leaf Binary Numbers](https://leetcode.com/problems/sum-of-root-to-leaf-binary-numbers) | [![Java](assets/java.png)](src/SumOfRootToLeafBinaryNumbers.java) | | -| 1025 | [Divisor Game](https://leetcode.com/problems/divisor-game) | [![Java](assets/java.png)](src/DivisorGame.java) | | -| 1029 | [Two City Scheduling](https://leetcode.com/problems/two-city-scheduling) | | | -| 1030 | [Matrix Cells in Distance Order](https://leetcode.com/problems/matrix-cells-in-distance-order) | [![Java](assets/java.png)](src/MatrixCellsInDistanceOrder.java) | | -| 1033 | [Moving Stones Until Consecutive](https://leetcode.com/problems/moving-stones-until-consecutive) | | | -| 1037 | [Valid Boomerang](https://leetcode.com/problems/valid-boomerang) | [![Java](assets/java.png)](src/ValidBoomerang.java) | | -| 1042 | [Flower Planting with no Adjacent](https://leetcode.com/problems/flower-planting-with-no-adjacent) | | | -| 1046 | [Last Stone Weight](https://leetcode.com/problems/last-stone-weight) | [![Java](assets/java.png)](src/LastStoneWeight.java) | | -| 1047 | [Remove All adjacent Duplicates in String](https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string) | [![Java](assets/java.png)](src/RemoveAllAdjacentDuplicatesInAString.java) | | -| 1051 | [Height Checker](https://leetcode.com/problems/height-checker) | | | -| 1056 | 🔒 [Confusing Number](https://leetcode.com/problems/confusing-number) | | | -| 1064 | 🔒 [Fixed Point](https://leetcode.com/problems/fixed-point) | | | -| 1065 | 🔒 [Index Pairs of a String](https://leetcode.com/problems/index-pairs-of-a-string) | | | -| 1071 | [Greatest Common Divisors of Strings](https://leetcode.com/problems/greatest-common-divisor-of-strings) | [![Java](assets/java.png)](src/GreatestCommonDivisorOfStrings.java) | | -| 1078 | [Occurrence After Bigram](https://leetcode.com/problems/occurrences-after-bigram) | [![Java](assets/java.png)](src/OccurrencesAfterBigram.java) | | -| 1085 | 🔒 [Sum of Digits in Minimum Number](https://leetcode.com/problems/sum-of-digits-in-the-minimum-number) | | | -| 1086 | 🔒 [High Five](https://leetcode.com/problems/high-five) | | | -| 1089 | [Duplicate Zeroes](https://leetcode.com/problems/duplicate-zeros) | [![Java](assets/java.png)](src/DuplicateZeros.java) | | -| 1099 | 🔒 [Two Sum Less Than K](https://leetcode.com/problems/two-sum-less-than-k) | | | -| 1103 | [Distribute Candies to People](https://leetcode.com/problems/distribute-candies-to-people) | [![Java](assets/java.png)](src/DistributeCandiesToPeople.java) | | -| 1108 | [Defanging an IP Address](https://leetcode.com/problems/defanging-an-ip-address) | [![Java](assets/java.png)](src/DefangingAnIPAddress.java) | | -| 1118 | 🔒 [Number of Days in a Month](https://leetcode.com/problems/number-of-days-in-a-month) | | | -| 1119 | 🔒 [Remove Vowels From String](https://leetcode.com/problems/remove-vowels-from-a-string) | | | -| 1122 | [Relative Sort Array](https://leetcode.com/problems/relative-sort-array) | [![Java](assets/java.png)](src/RelativeSortArray.java) | | -| 1128 | [Number of Equivalent Domino Pairs](https://leetcode.com/problems/number-of-equivalent-domino-pairs) | [![Java](assets/java.png)](src/NumberOfEquivalentDominoPairs.java) | | -| 1133 | 🔒 [Largest Unique Number](https://leetcode.com/problems/largest-unique-number) | | | -| 1134 | 🔒 [Armstrong Number](https://leetcode.com/problems/armstrong-number) | | | -| 1137 | [Nth Tribonacci Number](https://leetcode.com/problems/n-th-tribonacci-number) | [![Java](assets/java.png)](src/NthTribonacciNumber.java) | | -| 1143 | [Longest Common Subsequence](https://leetcode.com/problems/longest-common-subsequence) | [![Java](assets/java.png)](src/LongestCommonSubsequence.java) | | -| 1150 | [Check if Number is Majority Element in Sorted Array](https://leetcode.com/problems/check-if-a-number-is-majority-element-in-a-sorted-array) | | | -| 1154 | [Day of The Year](https://leetcode.com/problems/day-of-the-year) | [![Java](assets/java.png)](src/DayOfTheYear.java) | | -| 1160 | [Find Words That Can Be Formed By Characters](https://leetcode.com/problems/find-words-that-can-be-formed-by-characters) | | | -| 1165 | [Single Row Keyboard](https://leetcode.com/problems/single-row-keyboard) | [![Java](assets/java.png)](src/FindWordsThatCanBeFormedByCharacters.java) | | -| 1170 | [Compare Strings By Frequency of the Smallest Character](https://leetcode.com/problems/compare-strings-by-frequency-of-the-smallest-character) | | | -| 1175 | [Prime Arrangements](https://leetcode.com/problems/prime-arrangements) | [![Java](assets/java.png)](src/PrimeArrangements.java) | | -| 1176 | 🔒 [Diet Plan Performance](https://leetcode.com/problems/diet-plan-performance) | | | -| 1180 | 🔒 [Count Substrings with only one Distinct Letter](https://leetcode.com/problems/count-substrings-with-only-one-distinct-letter) | | | -| 1184 | [Distance Between Bus Stops](https://leetcode.com/problems/distance-between-bus-stops) | [![Java](assets/java.png)](src/DistanceBetweenBusStops.java) | | -| 1185 | [Day of the Week](https://leetcode.com/problems/day-of-the-week) | [![Java](assets/java.png)](src/DayOfWeek.java) | | -| 1189 | [Maximum Number of Balloons](https://leetcode.com/problems/maximum-number-of-balloons) | [![Java](assets/java.png)](src/MaximumNumberOfBalloons.java) | | -| 1196 | 🔒 [How Many Apples Can You Put into the Basket](https://leetcode.com/problems/how-many-apples-can-you-put-into-the-basket) | | | -| 1200 | [Minimum Absolute Difference](https://leetcode.com/problems/minimum-absolute-difference) | [![Java](assets/java.png)](src/MinimumAbsoluteDifference.java) | | -| 1201 | [Ugly Number III](https://leetcode.com/problems/ugly-number-iii) | [![Java](assets/java.png)](src/UglyNumberIII.java) | | -| 1207 | [Unique Number of Occurrences](https://leetcode.com/problems/unique-number-of-occurrences) | [![Java](assets/java.png)](src/UniqueNumberOfOccurrences.java) | | -| 1213 | 🔒 [Intersection of Three Sorted Arrays](https://leetcode.com/problems/intersection-of-three-sorted-arrays) | | | -| 1217 | [Minimum Cost to Move Chips to The Same Position](https://leetcode.com/problems/minimum-cost-to-move-chips-to-the-same-position) | [![Java](assets/java.png)](src/MinimumCostToMoveChipsToTheSamePosition.java) | | -| 1221 | [Split A String In Balanced Strings](https://leetcode.com/problems/split-a-string-in-balanced-strings) | [![Java](assets/java.png)](src/SplitAStringInBalancedStrings.java) | | -| 1228 | 🔒 [Missing A Number In Arithmetic Progression](https://leetcode.com/problems/missing-number-in-arithmetic-progression) | | | -| 1232 | [Check If It Is A Straight Line](https://leetcode.com/problems/check-if-it-is-a-straight-line) | [![Java](assets/java.png)](src/CheckIfItIsASStraightLine.java) | | -| 1237 | [Find Positive Integer Solutions for a Given Equation](https://leetcode.com/problems/find-positive-integer-solution-for-a-given-equation) | | | -| 1243 | 🔒 [Array Transformation](https://leetcode.com/problems/array-transformation) | | | -| 1249 | [Minimum Remove to Make Valid Parentheses](https://leetcode.com/problems/minimum-remove-to-make-valid-parentheses) | [![Java](assets/java.png)](src/MinimumRemoveToMakeValidParentheses.java) | | -| 1252 | [Cells With Odd Values In Matrix](https://leetcode.com/problems/cells-with-odd-values-in-a-matrix) | [![Java](assets/java.png)](src/CellsWithOddValuesInMatrix.java) | | -| 1254 | [Number of Closed Islands](https://leetcode.com/problems/number-of-closed-islands) | [![Python](assets/python.png)](python/number_of_closed_islands.py) | | -| 1260 | [Shift 2D Grid](https://leetcode.com/problems/shift-2d-grid) | [![Java](assets/java.png)](src/Shift2DGrid.java) | | -| 1266 | [Minimum Time Visiting All Points](https://leetcode.com/problems/minimum-time-visiting-all-points) | [![Java](assets/java.png)](src/MinimumTimeVisitingAllPoints.java) | | -| 1271 | 🔒 [Hexspeak](https://leetcode.com/problems/hexspeak) | | | -| 1275 | [Find Winner On a Tic Tac Toe Game](https://leetcode.com/problems/find-winner-on-a-tic-tac-toe-game) | [![Java](assets/java.png)](src/FindWinnerOnATicTacToeGame.java) | | -| 1281 | [Subtract the Product and Sum of Digits of a Integer](https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer) | [![Java](assets/java.png)](src/SubtractTheProductAndSumOfDigitsOfAnInteger.java) | | -| 1287 | [Element Appearing More Than 25% in Sorted Array](https://leetcode.com/problems/element-appearing-more-than-25-in-sorted-array) | [![Java](assets/java.png)](src/ElementAppearingMoreThan25PercentInSortedArray.java) | | -| 1290 | [Convert Binary Number In A Linked List to Integer](https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer) | [![Java](assets/java.png)](src/ConvertBinaryNumberInLinkedListToInteger.java) | | -| 1295 | [Find Numbers With Even Numbers of Digits](https://leetcode.com/problems/find-numbers-with-even-number-of-digits) | [![Java](assets/java.png)](src/FindNumbersWithEvenNumbersOfDigits.java) [![Python](assets/python.png)](python/find_numbers_with_even_number_of_digits.py) | | -| 1299 | [Replace Elements With Greatest Element on Right Side](https://leetcode.com/problems/replace-elements-with-greatest-element-on-right-side) | [![Java](assets/java.png)](src/ReplaceElementWithGreatestElementOnRightSide.java) [![Python](assets/python.png)](python/replace_element_with_greatest_element_on_right_hand_side.py) | | -| 1304 | [Find N Unique Integers Sum Up To Zero](https://leetcode.com/problems/find-n-unique-integers-sum-up-to-zero) | [![Java](assets/java.png)](src/FindNUniqueIntegersSumUpToZero.java) | | -| 1309 | [Decrypt String From Alphabet To Integer Mapping](https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping) | [![Java](assets/java.png)](src/DecryptStringFromAlphabetToIntegerMapping.java) | | -| 1313 | [Decompress Run-Length Encoded Strings](https://leetcode.com/problems/decompress-run-length-encoded-list) | [![Java](assets/java.png)](src/DecompressRunLengthEncodedList.java) | | -| 1317 | [Convert Integer to Sum Of Two Non-Zero Integers](https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers) | [![Java](assets/java.png)](src/ConvertIntegerToTheSumOfTwoNoZeroIntegers.java) | | -| 1319 | [Number of Operations to Make Network Connected](https://leetcode.com/problems/number-of-operations-to-make-network-connected) | [![Python](assets/python.png)](python/no_of_operations_to_make_network_connected.py) | | -| 1323 | [Maximum 69 Number](https://leetcode.com/problems/maximum-69-number) | [![Java](assets/java.png)](src/Maximum69Number.java) | | -| 1331 | [Rank Transform of An Array](https://leetcode.com/problems/rank-transform-of-an-array) | [![Java](assets/java.png)](src/RankTransformOfArray.java) | | -| 1332 | [Remove Palindromic Subsequences](https://leetcode.com/problems/remove-palindromic-subsequences) | [![Java](assets/java.png)](src/RemovePalindromicSubSequences.java) | | -| 1337 | [The K Weakest Rows In A Matrix](https://leetcode.com/problems/the-k-weakest-rows-in-a-matrix) | [![Java](assets/java.png)](src/TheKWeakestRowsInAMatrix.java) | | -| 1342 | [Number of Steps to Reduce a Number to Zero](https://leetcode.com/problems/number-of-steps-to-reduce-a-number-to-zero) | [![Java](assets/java.png)](src/NumberOfStepsToReduceANumberToZero.java) | | -| 1346 | [Check if N and It's Double Exist](https://leetcode.com/problems/check-if-n-and-its-double-exist) | [![Java](assets/java.png)](src/CheckIfNAndItsDoubleExist.java) [![Python](assets/python.png)](python/check_if_n_and_its_double_exist.py) | | -| 1351 | [Count Negative Numbers In A Sorted Matrix](https://leetcode.com/problems/count-negative-numbers-in-a-sorted-matrix) | [![Java](assets/java.png)](src/CountNegativeNumbersInSortedMatrix.java) | | -| 1356 | [Sort Integers by Number of 1 Bits](https://leetcode.com/problems/sort-integers-by-the-number-of-1-bits) | [![Java](assets/java.png)](src/SortIntegersByTheNumberOf1Bits.java) | | -| 1360 | [Number of Days Between Two Dates](https://leetcode.com/problems/number-of-days-between-two-dates) | [![Java](assets/java.png)](src/NumberOfDaysBetweenTwoDates.java) | | -| 1365 | [How Many Numbers Are Smaller Than Current Number](https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number) | [![Java](assets/java.png)](src/HowManyNumbersAreSmallerThanCurrentNumber.java) | | -| 1370 | [Increasing Decreasing String](https://leetcode.com/problems/increasing-decreasing-string) | [![Java](assets/java.png)](src/IncreasingDecreasingString.java) | | -| 1374 | [Generate A String With Characters That Have Odd Count](https://leetcode.com/problems/generate-a-string-with-characters-that-have-odd-counts) | [![Java](assets/java.png)](src/GenerateAStringWithCharactersThatHaveOddCounts.java) | | -| 1376 | [Time Needed to Inform All Employees](https://leetcode.com/problems/time-needed-to-inform-all-employees) | [![Java](assets/java.png)](src/TimeNeededToInformAllEmployees.java) | | -| 1380 | [Lucky Numbers In A Matrix](https://leetcode.com/problems/lucky-numbers-in-a-matrix) | [![Java](assets/java.png)](src/LuckyNumbersInAMatrix.java) | | -| 1385 | [Find The Distance Value Between 2 Arrays](https://leetcode.com/problems/find-the-distance-value-between-two-arrays) | [![Java](assets/java.png)](src/FindTheDistanceValuesBetweenTwoArrays.java) | | -| 1389 | [Create Target Array in Given Order](https://leetcode.com/problems/create-target-array-in-the-given-order) | [![Java](assets/java.png)](src/CreateTargetArrayInGivenOrder.java) | | -| 1394 | [Find Lucky Integer In An Array](https://leetcode.com/problems/find-lucky-integer-in-an-array) | [![Java](assets/java.png)](src/FindTheLuckyIntegerInAnArray.java) | | -| 1399 | [Count Largest Group](https://leetcode.com/problems/count-largest-group) | [![Java](assets/java.png)](src/CountLargestGroup.java) | | -| 1402 | [Reducing Dishes](https://leetcode.com/problems/reducing-dishes) | [![Python](assets/python.png)](python/reducing_dishes.py) | | -| 1403 | [Minimum Subsequence in Non-Increasing Order](https://leetcode.com/problems/minimum-subsequence-in-non-increasing-order) | [![Java](assets/java.png)](src/MinimumSubSequenceInNonIncreasingOrder.java) | | -| 1408 | [String Matching In An Array](https://leetcode.com/problems/string-matching-in-an-array) | [![Java](assets/java.png)](src/StringMatchingInAnArray.java) | | -| 1413 | [Minimum Value To Get Positive Step By Step Sum](https://leetcode.com/problems/minimum-value-to-get-positive-step-by-step-sum) | [![Java](assets/java.png)](src/MinimumValueToGetPositiveStepByStepSum.java) | | -| 1417 | [Reformat The String](https://leetcode.com/problems/reformat-the-string) | [![Java](assets/java.png)](src/ReformatTheString.java) | | -| 1422 | [Maximum Score After Splitting A String](https://leetcode.com/problems/maximum-score-after-splitting-a-string) | [![Java](assets/java.png)](src/MaximumScoreAfterSplittingAString.java) | | -| 1426 | 🔒 [Counting Elements](https://leetcode.com/problems/counting-elements) | | | -| 1427 | 🔒 [Performing String Shifts](https://leetcode.com/problems/perform-string-shifts) | | | -| 1431 | [Kids With The Greatest Number Of Candies](https://leetcode.com/problems/kids-with-the-greatest-number-of-candies) | [![Java](assets/java.png)](src/KidsWithTheGreatestNumberOfCandies.java) | | -| 1436 | [Destination City](https://leetcode.com/problems/destination-city) | [![Java](assets/java.png)](src/DestinationCity.java) | | -| 1437 | [Check If All 1's Are at Least Length K Places Away](https://leetcode.com/problems/check-if-all-1s-are-at-least-length-k-places-away) | [![Java](assets/java.png)](src/CheckIfAll1sAreAtLeastKPlacesAway.java) | | -| 1441 | [Build An Array With Stack Operation](https://leetcode.com/problems/build-an-array-with-stack-operations) | [![Java](assets/java.png)](src/BuildAnArrayWithStackOperations.java) | | -| 1444 | [Number of Ways of Cutting a Pizza](https://leetcode.com/problems/number-of-ways-of-cutting-a-pizza) | [![Python](assets/python.png)](python/number_of_ways_of_cutting_pizza.py) | | -| 1446 | [Consecutive Characters](https://leetcode.com/problems/consecutive-characters) | [![Java](assets/java.png)](src/ConsecutiveCharacters.java) | | -| 1450 | [Number of Students Doing Homework at Given Time](https://leetcode.com/problems/number-of-students-doing-homework-at-a-given-time) | [![Java](assets/java.png)](src/NumberOfStudentsDoingHomeworkAtGivenTime.java) | | -| 1455 | [Check If Word Occurs as Prefix of any Word in Sentence](https://leetcode.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence) | [![Java](assets/java.png)](src/CheckIfAWordOccursAsAPrefixOfAnyWordInASentence.java) | | -| 1460 | [Make 2 Arrays Equal by Reversing Sub Arrays](https://leetcode.com/problems/make-two-arrays-equal-by-reversing-sub-arrays) | [![Java](assets/java.png)](src/MakeTwoArraysEqualByReversingSubArrays.java) | | -| 1464 | [Maximum Product of 2 Elements in Array](https://leetcode.com/problems/maximum-product-of-two-elements-in-an-array) | [![Java](assets/java.png)](src/MaximumProductOfTwoElementsInArray.java) | | -| 1466 | [Reorder Routes to Make All Paths Lead to the City Zero](https://leetcode.com/problems/reorder-routes-to-make-all-paths-lead-to-the-city-zero) | [![Java](assets/java.png)](src/MaximumProductOfTwoElementsInArray.java) | | -| 1469 | 🔒 [Find All Lonely Nodes](https://leetcode.com/problems/find-all-the-lonely-nodes) | [![Python](assets/python.png)](python/reorder_routes_to_make_all_paths_lead_to_city_zero.py) | | -| 1470 | [Shuffle The Array](https://leetcode.com/problems/shuffle-the-array) | [![Java](assets/java.png)](src/ShuffleTheArray.java) | | -| 1472 | [Design Browser History](https://leetcode.com/problems/design-browser-history) | [![Java](assets/java.png)](src/DesignBrowserHistory.java) [![Python](assets/python.png)](python/design_browser_history.py) | | -| 1474 | [Delete N Nodes After M Nodes In A Linked List](https://leetcode.com/problems/delete-n-nodes-after-m-nodes-of-a-linked-list) | | | -| 1475 | [Final Prices With Special Discount in a Shop](https://leetcode.com/problems/final-prices-with-a-special-discount-in-a-shop) | [![Java](assets/java.png)](src/FinalPricesWithASpecialDiscountInAShop.java) | | -| 1480 | [Running Sum of 1D Array](https://leetcode.com/problems/running-sum-of-1d-array) | [![Java](assets/java.png)](src/RunningSumOf1DArray.java) | | -| 1486 | [XOR Operations in An Array](https://leetcode.com/problems/xor-operation-in-an-array) | [![Java](assets/java.png)](src/XOROperationInAnArray.java) | | -| 1491 | [Average Salary Excluding the Minimum and Maximum Salary](https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary) | [![Java](assets/java.png)](src/AverageSalaryExcludingTheMinimumAndMaximumSalary.java) | | -| 1496 | [Path Crossing](https://leetcode.com/problems/path-crossing) | [![Java](assets/java.png)](src/PathCrossing.java) | | -| 1502 | [Can Make Arithmetic Progression From Sequence](https://leetcode.com/problems/can-make-arithmetic-progression-from-sequence) | [![Java](assets/java.png)](src/CanMakeArithmeticProgressionFromSequence.java) | | -| 1507 | [Reformat Date](https://leetcode.com/problems/reformat-date) | [![Java](assets/java.png)](src/ReformatDate.java) | | -| 1512 | [Number of Good Pairs](https://leetcode.com/problems/number-of-good-pairs) | [![Java](assets/java.png)](src/NumberOfGoodPairs.java) | | -| 1518 | [Water Bottles](https://leetcode.com/problems/water-bottles) | [![Java](assets/java.png)](src/WaterBottles.java) | | -| 1523 | [Count Odd Numbers In Interval Range](https://leetcode.com/problems/count-odd-numbers-in-an-interval-range) | [![Java](assets/java.png)](src/CountOddNumbersInIntervalRange.java) | | -| 1528 | [Shuffle Strings](https://leetcode.com/problems/shuffle-string) | [![Java](assets/java.png)](src/ShuffleString.java) | | -| 1534 | [Count Good Triplets](https://leetcode.com/problems/count-good-triplets) | [![Java](assets/java.png)](src/CountGoodTriplets.java) | | -| 1539 | [Kth Missing Positive Number](https://leetcode.com/problems/kth-missing-positive-number) | [![Java](assets/java.png)](src/KthMissingPositiveNumber.java) | | -| 1544 | [Make The String Great](https://leetcode.com/problems/make-the-string-great) | [![Java](assets/java.png)](src/MakeTheStringGreat.java) | | -| 1550 | [Three Consecutive Odds](https://leetcode.com/problems/three-consecutive-odds) | [![Java](assets/java.png)](src/ThreeConsecutiveOdds.java) | | -| 1556 | [Thousand Separator](https://leetcode.com/problems/thousand-separator) | [![Java](assets/java.png)](src/ThousandSeparator.java) | | -| 1560 | [Most Visited Sector in a Circular Track](https://leetcode.com/problems/most-visited-sector-in-a-circular-track) | [![Java](assets/java.png)](src/MostVisitedSectorInACircularTrack.java) | | -| 1566 | [Detect Pattern of Length M Repeated K or More Times](https://leetcode.com/problems/detect-pattern-of-length-m-repeated-k-or-more-times) | [![Java](assets/java.png)](src/DetectPatternOfLengthMRepeatedKOrMoreTimes.java) | | -| 1572 | [Matrix Diagonal Sum](https://leetcode.com/problems/matrix-diagonal-sum) | [![Java](assets/java.png)](src/MatrixDiagonalSum.java) | | -| 1576 | [Replace All ?'s to Avoid Consecutive Repeating Characters](https://leetcode.com/problems/replace-all-s-to-avoid-consecutive-repeating-characters) | [![Java](assets/java.png)](src/ReplaceAllToAvoidConsecutiveRepeatingCharacters.java) | | -| 1582 | [Special Positions in a Binary Matrix](https://leetcode.com/problems/special-positions-in-a-binary-matrix) | [![Java](assets/java.png)](src/SpecialPositionInABinaryMatrix.java) | | -| 1588 | [Sum of All Odd Length Subarrays](https://leetcode.com/problems/sum-of-all-odd-length-subarrays) | [![Java](assets/java.png)](src/SumOfAllOddLengthSubArrays.java) | | -| 1592 | [Rearrange Spaces Between Words](https://leetcode.com/problems/rearrange-spaces-between-words) | [![Java](assets/java.png)](src/RearrangeSpacesBetweenWords.java) | | -| 1598 | [Crawler Log Folder](https://leetcode.com/problems/crawler-log-folder) | [![Java](assets/java.png)](src/CrawlerLogFolder.java) | | -| 1600 | [Throne Inheritance](https://leetcode.com/problems/throne-inheritance) | [![Java](assets/java.png)](src/ThroneInheritance.java) | | -| 1603 | [Design Parking System](https://leetcode.com/problems/design-parking-system) | [![Java](assets/java.png)](src/DesignParkingSystem.java) | | -| 1608 | [Special Array With X Elements Greater Than or Equal X](https://leetcode.com/problems/special-array-with-x-elements-greater-than-or-equal-x) | [![Java](assets/java.png)](src/SpecialArrayWithXElementsGreaterThanEqualToX.java) | | -| 1614 | [Maximum Nesting Depth of the Parentheses](https://leetcode.com/problems/maximum-nesting-depth-of-the-parentheses) | [![Java](assets/java.png)](src/MaximumNestingDepthOfTheParentheses.java) | | -| 1619 | [Mean of Array After Removing Some Elements](https://leetcode.com/problems/mean-of-array-after-removing-some-elements) | [![Java](assets/java.png)](src/MeanOfArrayAfterRemovingSomeElements.java) | | -| 1624 | [Largest Substring Between Two Equal Characters](https://leetcode.com/problems/largest-substring-between-two-equal-characters) | [![Java](assets/java.png)](src/LargestSubStringBetweenTwoEqualCharacters.java) | | -| 1629 | [Slowest Key](https://leetcode.com/problems/slowest-key) | [![Java](assets/java.png)](src/SlowestKey.java) | | -| 1636 | [Sort Array by Increasing Frequency](https://leetcode.com/problems/sort-array-by-increasing-frequency) | [![Java](assets/java.png)](src/SortArrayByIncreasingFrequency.java) | | -| 1640 | [Check Array Formation Through Concatenation](https://leetcode.com/problems/check-array-formation-through-concatenation) | [![Java](assets/java.png)](src/CheckArrayFormationThroughConcatenation.java) | | -| 1646 | [Get Maximum in Generated Array](https://leetcode.com/problems/get-maximum-in-generated-array) | [![Java](assets/java.png)](src/GetMaximumInGeneratedArray.java) | | -| 1652 | [Defuse the Bomb](https://leetcode.com/problems/defuse-the-bomb) | [![Java](assets/java.png)](src/DefuseTheBomb.java) | | -| 1656 | [Design an Ordered Stream](https://leetcode.com/problems/design-an-ordered-stream) | [![Java](assets/java.png)](src/DesignAnOrderedStream.java) | | -| 1662 | [Check If Two String Arrays are Equivalent](https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent) | [![Java](assets/java.png)](src/CheckIfTwoStringArraysAreEquivalent.java) | | -| 1668 | [Maximum Repeating Substring](https://leetcode.com/problems/maximum-repeating-substring) | [![Java](assets/java.png)](src/MaximumRepeatingSubString.java) | | -| 1672 | [Richest Customer Wealth](https://leetcode.com/problems/richest-customer-wealth) | [![Java](assets/java.png)](src/RichestCustomerWealth.java) | | -| 1678 | [Goal Parser Interpretation](https://leetcode.com/problems/goal-parser-interpretation) | [![Java](assets/java.png)](src/GoalParserInterpretation.java) | | -| 1684 | [Count the Number of Consistent Strings](https://leetcode.com/problems/count-the-number-of-consistent-strings) | [![Java](assets/java.png)](src/CountTheNumberOfConsistentStrings.java) | | -| 1688 | [Count of Matches in Tournament](https://leetcode.com/problems/count-of-matches-in-tournament) | [![Java](assets/java.png)](src/CountOfMatchesInTournament.java) | | -| 1694 | [Reformat Phone Number](https://leetcode.com/problems/reformat-phone-number) | [![Java](assets/java.png)](src/ReformatPhoneNumber.java) | | -| 1700 | [Number of Students Unable to Eat Lunch](https://leetcode.com/problems/number-of-students-unable-to-eat-lunch) | [![Java](assets/java.png)](src/NumberOfStudentsUnableToEatLunch.java) | | -| 1704 | [Determine if String Halves Are Alike](https://leetcode.com/problems/determine-if-string-halves-are-alike) | [![Java](assets/java.png)](src/DetermineIfStringHalvesAreAlike.java) | | -| 1708 | 🔒 [Largest Subarray Length K](https://leetcode.com/problems/largest-subarray-length-k/) | | | -| 1710 | [Maximum Units on a Truck](https://leetcode.com/problems/maximum-units-on-a-truck/) | [![Java](assets/java.png)](src/MaximumUnitsOnATruck.java) | | -| 1716 | [Calculate Money in Leetcode Bank](https://leetcode.com/problems/calculate-money-in-leetcode-bank) | [![Java](assets/java.png)](src/CalculateMoneyInLeetCodeBank.java) | | -| 1720 | [Decode XORed Array](https://leetcode.com/problems/decode-xored-array) | [![Java](assets/java.png)](src/DecodeXORedArray.java) | | -| 1725 | [Number Of Rectangles That Can Form The Largest Square](https://leetcode.com/problems/number-of-rectangles-that-can-form-the-largest-square) | [![Java](assets/java.png)](src/NumberOfRectanglesThatCanFormTheLargestSquare.java) | | -| 1732 | [Find the Highest Altitude](https://leetcode.com/problems/find-the-highest-altitude) | [![Java](assets/java.png)](src/FindTheHighestAltitude.java) | | -| 1736 | [Latest Time by Replacing Hidden Digits](https://leetcode.com/problems/latest-time-by-replacing-hidden-digits) | [![Java](assets/java.png)](src/LatestTimeByReplacingHiddenDigits.java) | | -| 1742 | [Maximum Number of Balls in a Box](https://leetcode.com/problems/maximum-number-of-balls-in-a-box) | [![Java](assets/java.png)](src/MaximumNumberOfBallsInABox.java) | | -| 1748 | [Sum of Unique Elements](https://leetcode.com/problems/sum-of-unique-elements) | [![Java](assets/java.png)](src/SumOfUniqueElements.java) | | -| 1752 | [Check if Array Is Sorted and Rotated](https://leetcode.com/problems/check-if-array-is-sorted-and-rotated) | [![Java](assets/java.png)](src/CheckIfArrayIsSortedAndRotated.java) | | -| 1758 | [Minimum Changes To Make Alternating Binary String](https://leetcode.com/problems/minimum-changes-to-make-alternating-binary-string) | [![Java](assets/java.png)](src/MinimumChangesToMakeAlternatingBinaryString.java) | | -| 1763 | [Longest Nice Substring](https://leetcode.com/problems/longest-nice-substring) | [![Java](assets/java.png)](src/LongestNiceSubstring.java) | | -| 1768 | [Merge Strings Alternately](https://leetcode.com/problems/merge-strings-alternately) | [![Java](assets/java.png)](src/MergeStringsAlternately.java) | | -| 1773 | [Count Items Matching a Rule](https://leetcode.com/problems/count-items-matching-a-rule) | [![Java](assets/java.png)](src/CountItemsMatchingARule.java) | | -| 1779 | [Find Nearest Point That Has the Same X or Y Coordinate](https://leetcode.com/problems/find-nearest-point-that-has-the-same-x-or-y-coordinate) | [![Java](assets/java.png)](src/FindNearestPointThatHasTheSameXOrYCoordinate.java) | | -| 1784 | [Check if Binary String Has at Most One Segment of Ones](https://leetcode.com/problems/check-if-binary-string-has-at-most-one-segment-of-ones) | [![Java](assets/java.png)](src/CheckIfBinaryStringHasAtMostOneSegmentOfOnes.java) | | -| 1790 | [Check if One String Swap Can Make Strings Equal](https://leetcode.com/problems/check-if-one-string-swap-can-make-strings-equal) | [![Java](assets/java.png)](src/CheckIfOneStringSwapCanMakeStringsEqual.java) | | -| 1791 | [Find Center of Star Graph](https://leetcode.com/problems/find-center-of-star-graph) | [![Java](assets/java.png)](src/FindCenterOfStarGraph.java) | | -| 1796 | [Second Largest Digit in a String](https://leetcode.com/problems/second-largest-digit-in-a-string) | [![Java](assets/java.png)](src/SecondLargestDigitInAString.java) | | -| 1800 | [Maximum Ascending Subarray Sum](https://leetcode.com/problems/maximum-ascending-subarray-sum) | [![Java](assets/java.png)](src/MaximumAscendingSubArraySum.java) | | -| 1805 | [Number of Different Integers in a String](https://leetcode.com/problems/number-of-different-integers-in-a-string) | [![Java](assets/java.png)](src/NumberOfDifferentIntegersInString.java) | | -| 1812 | [Determine Color of a Chessboard Square](https://leetcode.com/problems/determine-color-of-a-chessboard-square) | [![Java](assets/java.png)](src/DetermineColorOfChessboardSquare.java) | | -| 1816 | [Truncate Sentence](https://leetcode.com/problems/truncate-sentence) | [![Java](assets/java.png)](src/TruncateSentences.java) | | -| 1822 | [Sign of the Product of an Array](https://leetcode.com/problems/sign-of-the-product-of-an-array) | [![Java](assets/java.png)](src/SignOfTheProductOfAnArray.java) | | -| 1826 | 🔒 [Faulty Sensor](https://leetcode.com/problems/faulty-sensor) | | | -| 1827 | [Minimum Operations to Make the Array Increasing](https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing) | [![Java](assets/java.png)](src/MinimumOperationsToMakeTheArrayIncreasing.java) | | -| 1832 | [Check if the Sentence Is Pangram](https://leetcode.com/problems/check-if-the-sentence-is-pangram) | [![Java](assets/java.png)](src/CheckIfSentenceIsPangram.java) | | -| 1837 | [Sum of Digits in Base K](https://leetcode.com/problems/sum-of-digits-in-base-k) | [![Java](assets/java.png)](src/SumOfDigitsInBaseK.java) | | -| 1844 | [Replace All Digits with Characters](https://leetcode.com/problems/replace-all-digits-with-characters) | [![Java](assets/java.png)](src/ReplaceAllDigitsWithCharacters.java) | | -| 1848 | [Minimum Distance to the Target Element](https://leetcode.com/problems/minimum-distance-to-the-target-element) | [![Java](assets/java.png)](src/MinimumDistanceToTheTargetElement.java) | | -| 1854 | [Maximum Population Year](https://leetcode.com/problems/maximum-population-year) | [![Java](assets/java.png)](src/MaximumPopulationYear.java) | | -| 1859 | [Sorting the Sentence](https://leetcode.com/problems/sorting-the-sentence) | [![Java](assets/java.png)](src/SortingTheSentence.java) | | -| 1863 | [Sum of All Subset XOR Totals](https://leetcode.com/problems/sum-of-all-subset-xor-totals) | [![Java](assets/java.png)](src/SumOfAllSubsetXORTotals.java) | | -| 1869 | [Longer Contiguous Segments of Ones than Zeros](https://leetcode.com/problems/longer-contiguous-segments-of-ones-than-zeros) | [![Java](assets/java.png)](src/LongerContiguousSegmentOfOnesThanZeros.java) | | -| 1876 | [Substrings of Size Three with Distinct Characters](https://leetcode.com/problems/substrings-of-size-three-with-distinct-characters) | [![Java](assets/java.png)](src/SubstringsOfSizeThreeWithDistinctCharacters.java) | | -| 1880 | [Check if Word Equals Summation of Two Words](https://leetcode.com/problems/check-if-word-equals-summation-of-two-words) | [![Java](assets/java.png)](src/CheckIfWordEqualsSummationOfTwoWords.java) | | -| 1886 | [Determine Whether Matrix Can Be Obtained By Rotation](https://leetcode.com/problems/determine-whether-matrix-can-be-obtained-by-rotation) | [![Java](assets/java.png)](src/DetermineWhetherMatrixCanBeObtainedByRotation.java) | | -| 1893 | [Check if All the Integers in a Range Are Covered](https://leetcode.com/problems/check-if-all-the-integers-in-a-range-are-covered) | [![Java](assets/java.png)](src/CheckIfAllTheIntegersInARangeAreCovered.java) | | -| 1897 | [Redistribute Characters to Make All Strings Equal](https://leetcode.com/problems/redistribute-characters-to-make-all-strings-equal) | [![Java](assets/java.png)](src/RedistributeCharactersToMakeAllStringsEqual.java) | | -| 1903 | [Largest Odd Number in String](https://leetcode.com/problems/largest-odd-number-in-string) | [![Java](assets/java.png)](src/LargestOddNumberInString.java) | | -| 1909 | [Remove One Element to Make the Array Strictly Increasing](https://leetcode.com/problems/remove-one-element-to-make-the-array-strictly-increasing) | [![Java](assets/java.png)](src/RemoveOneElementToMakeTheArrayStrictlyIncreasing.java) | | -| 1913 | [Maximum Product Difference Between Two Pairs](https://leetcode.com/problems/maximum-product-difference-between-two-pairs) | [![Java](assets/java.png)](src/MaximumProductDifferenceBetweenTwoPairs.java) | | -| 1920 | [Build Array from Permutation](https://leetcode.com/problems/build-array-from-permutation) | [![Java](assets/java.png)](src/BuildArrayFromPermutation.java) | | -| 1925 | [Count Square Sum Triples](https://leetcode.com/problems/count-square-sum-triples) | [![Java](assets/java.png)](src/CountSquareSumTriplets.java) | | -| 1929 | [Concatenation of Array](https://leetcode.com/problems/concatenation-of-array) | [![Java](assets/java.png)](src/ConcatenationOfArray.java) | | -| 1933 | 🔒 [Check If String Is Decomposable Into Value EqualSubstrings](https://leetcode.com/problems/check-if-string-is-decomposable-into-value-equal-substring) | | | -| 1935 | [Maximum Number of Words You Can Type](https://leetcode.com/problems/maximum-number-of-words-you-can-type) | [![Java](assets/java.png)](src/MaximumNumberOfWordsYouCanType.java) | | -| 1941 | [Check if All Characters Have Equal Number of Occurrences](https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences) | [![Java](assets/java.png)](src/CheckIfAllCharactersHaveEqualNumberOfOccurrences.java) | | -| 1945 | [Sum of Digits of String After Convert](https://leetcode.com/problems/sum-of-digits-of-string-after-convert) | [![Java](assets/java.png)](src/SumOfDigitsOfStringAfterConvert.java) | | -| 1952 | [Three Divisors](https://leetcode.com/problems/three-divisors) | [![Java](assets/java.png)](src/ThreeDivisors.java) | | -| 1957 | [Delete Characters to Make Fancy String](https://leetcode.com/problems/delete-characters-to-make-fancy-string) | [![Java](assets/java.png)](src/DeleteCharactersToMakeFancyString.java) | | -| 1961 | [Check If String Is a Prefix of Array](https://leetcode.com/problems/check-if-string-is-a-prefix-of-array) | [![Java](assets/java.png)](src/CheckIfStringIsAPrefixOfArray.java) | | -| 1967 | [Number of Strings That Appear as Substrings in Word](https://leetcode.com/problems/number-of-strings-that-appear-as-substrings-in-word) | [![Java](assets/java.png)](src/NumberOfStringsThatAppearAsSubstringsInWord.java) | | -| 1971 | [Find if Path Exists in Graph](https://leetcode.com/problems/find-if-path-exists-in-graph) | [![Java](assets/java.png)](src/FindIfPathExistsInGraph.java) | | -| 1974 | [Minimum Time to Type Word Using Special Typewriter](https://leetcode.com/problems/minimum-time-to-type-word-using-special-typewriter) | [![Java](assets/java.png)](src/MinimumTimeToTypeWordUsingSpecialTypewriter.java) | | -| 1979 | [Find Greatest Common Divisor of Array](https://leetcode.com/problems/find-greatest-common-divisor-of-array) | [![Java](assets/java.png)](src/FindGreatestCommonDivisorOfArray.java) | | -| 1984 | [Minimum Difference Between Highest and Lowest of K Scores](https://leetcode.com/problems/minimum-difference-between-highest-and-lowest-of-k-scores) | [![Java](assets/java.png)](src/MinimumDifferenceBetweenHighestAndLowestOfKScores.java) | | -| 1991 | [Find the Middle Index in Array](https://leetcode.com/problems/find-the-middle-index-in-array) | [![Java](assets/java.png)](src/FindTheMiddleIndexInArray.java) | | -| 1995 | [Count Special Quadruplets](https://leetcode.com/problems/count-special-quadruplets) | [![Java](assets/java.png)](src/CountSpecialQuadruplets.java) | | -| 2000 | [Reverse Prefix of Word](https://leetcode.com/problems/reverse-prefix-of-word) | [![Java](assets/java.png)](src/ReversePrefixOfWord.java) | | -| 2006 | [Count Number of Pairs With Absolute Difference K](https://leetcode.com/problems/count-number-of-pairs-with-absolute-difference-k) | [![Java](assets/java.png)](src/CountNumberOfPairsWithAbsoluteDifferenceK.java) | | -| 2011 | [Final Value of Variable After Performing Operations](https://leetcode.com/problems/final-value-of-variable-after-performing-operations) | [![Java](assets/java.png)](src/FinalValueOfVariableAfterPerformingOperations.java) | | -| 2016 | [Maximum Difference Between Increasing Elements](https://leetcode.com/problems/maximum-difference-between-increasing-elements) | [![Java](assets/java.png)](src/MaximumDifferenceBetweenIncreasingElements.java) | | -| 2022 | [Convert 1D Array Into 2D Array](https://leetcode.com/problems/convert-1d-array-into-2d-array) | [![Java](assets/java.png)](src/Convert1DArrayInto2DArray.java) | | -| 2027 | [Minimum Moves to Convert String](https://leetcode.com/problems/minimum-moves-to-convert-string) | [![Java](assets/java.png)](src/MinimumMovesToConvertString.java) | | -| 2032 | [Two Out of Three](https://leetcode.com/problems/two-out-of-three) | [![Java](assets/java.png)](src/TwoOutOfThree.java) | | -| 2037 | [Minimum Number of Moves to Seat Everyone](https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone) | [![Java](assets/java.png)](src/MinimumNumberOfMovesToSeatEveryone.java) | | -| 2042 | [Check if Numbers Are Ascending in a Sentence](https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence) | [![Java](assets/java.png)](src/CheckIfNumbersAreAscendingInASentence.java) | | -| 2047 | [Number of Valid Words in a Sentence](https://leetcode.com/problems/number-of-valid-words-in-a-sentence) | [![Java](assets/java.png)](src/NumberOfValidWordsInASentence.java) | | -| 2053 | [Kth Distinct String in an Array](https://leetcode.com/problems/kth-distinct-string-in-an-array) | [![Java](assets/java.png)](src/KthDistinctStringInAnArray.java) | | -| 2057 | [Smallest Index With Equal Value](https://leetcode.com/problems/smallest-index-with-equal-value) | [![Java](assets/java.png)](src/SmallestIndexWithEqualValue.java) | | -| 2062 | [Count Vowel Substrings of a String](https://leetcode.com/problems/count-vowel-substrings-of-a-string) | [![Java](assets/java.png)](src/CountVowelSubstringsOfAString.java) | | -| 2068 | [Check Whether Two Strings are Almost Equivalent](https://leetcode.com/problems/check-whether-two-strings-are-almost-equivalent) | [![Java](assets/java.png)](src/CheckWhetherTwoStringsAreAlmostEquivalent.java) | | -| 2073 | [Time Needed to Buy Tickets](https://leetcode.com/problems/time-needed-to-buy-tickets) | [![Java](assets/java.png)](src/TimeNeededToBuyTickets.java) | | -| 2078 | [Two Furthest Houses With Different Colors](https://leetcode.com/problems/two-furthest-houses-with-different-colors) | [![Java](assets/java.png)](src/TwoFurthestHousesWithDifferentColors.java) | | -| 2085 | [Count Common Words With One Occurrence](https://leetcode.com/problems/count-common-words-with-one-occurrence) | [![Java](assets/java.png)](src/CountCommonWordsWithOneOccurrence.java) | | -| 2089 | [Find Target Indices After Sorting Array](https://leetcode.com/problems/find-target-indices-after-sorting-array) | [![Java](assets/java.png)](src/FindTargetIndicesAfterSortingArray.java) | | -| 2094 | [Finding 3-Digit Even Numbers](https://leetcode.com/problems/finding-3-digit-even-numbers) | [![Java](assets/java.png)](src/Finding3DigitEvenNumbers.java) | | -| 2099 | [Find Subsequence of Length K With the Largest Sum](https://leetcode.com/problems/find-subsequence-of-length-k-with-the-largest-sum) | [![Java](assets/java.png)](src/FindSubsequenceOfLengthKWithTheLargestSum.java) | | -| 2103 | [Rings and Rods](https://leetcode.com/problems/rings-and-rods) | [![Java](assets/java.png)](src/RingsAndRods.java) | | -| 2108 | [Find First Palindromic String in the Array](https://leetcode.com/problems/find-first-palindromic-string-in-the-array) | [![Java](assets/java.png)](src/FindFirstPalindromicStringInArray.java) | | -| 2300 | [Successful Pairs of Spells and Potions](https://leetcode.com/problems/successful-pairs-of-spells-and-potions) | [![Python](assets/python.png)](python/successfull_pairs_of_spells_and_potions.py) | | -| 2316 | [Count Unreachable Pairs of Nodes in an Undirected Graph](https://leetcode.com/problems/count-unreachable-pairs-of-nodes-in-an-undirected-graph) | [![Python](assets/python.png)](python/count_unreachable_pair_of_node_in_an_undirectable_graph.py) | | -| 2360 | [Longest Cycle in a Graph](https://leetcode.com/problems/longest-cycle-in-a-graph) | [![Python](assets/python.png)](python/longest_cycle_in_graph.py) | | -| 2348 | [Number of Zero-Filled Subarrays](https://leetcode.com/problems/number-of-zero-filled-subarrays) | [![Python](assets/python.png)](python/number_of_zero_filled_subarrays.py) | | -| 2439 | [Minimize Maximum of Array](https://leetcode.com/problems/minimize-maximum-of-array) | [![Python](assets/python.png)](python/minimize_maximum_of_array.py) | | -| 2492 | [Minimum Score of a Path Between Two Cities](https://leetcode.com/problems/minimum-score-of-a-path-between-two-cities) | [![Python](assets/python.png)](python/minimum_score_of_a_path_between_two_cities.py) | | +| # | Name | Solution | Youtube | +|:----:|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:---------------------------------------------------------------------------------------------------------------------------------:| +| 1 | [Two Sum](https://leetcode.com/problems/two-sum) | [![Java](assets/java.png)](src/TwoSum.java) [![Python](assets/python.png)](python/two_sum.py) | [![java-yt](assets/java-yt.png)](https://youtu.be/9wSL_7NN-A8) [![python-yt](assets/python-yt.png)](https://youtu.be/N5FXCTg0TDE) | +| 2 | [Add Two Numbers](https://leetcode.com/problems/add-two-numbers) | [![Java](assets/java.png)](src/AddTwoNumbers.java) [![js](assets/javascript.png)](javascript/AddTwoNumbers.js) | | +| 3 | [Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters) | [![Java](assets/java.png)](src/LongestSubstringWithoutRepeatingCharacters.java) | | +| 5 | [Longest Palindromic Substring](https://leetcode.com/problems/longest-palindromic-substring) | [![Java](assets/java.png)](src/LongestPalindromicSubstring.java) | | +| 6 | [Zigzag Conversion](https://leetcode.com/problems/zigzag-conversion) | [![Java](assets/java.png)](src/ZigZagConversion.java) | | +| 7 | [Reverse Integer](https://leetcode.com/problems/reverse-integer) | [![Java](assets/java.png)](src/ReverseInteger.java) [![Python](assets/python.png)](python/reverse_integer.py) [![js](assets/javascript.png)](javascript/ReverseInteger.js) | [![java-yt](assets/java-yt.png)](https://youtu.be/7bOhyl5lWjI) [![python-yt](assets/python-yt.png)](https://youtu.be/lmLG30TLcSg) | +| 8 | [String to Integer (atoi)](https://leetcode.com/problems/string-to-integer-atoi) | [![Java](assets/java.png)](src/StringToIntegerAtoi.java) | | +| 9 | [Palindrome Number](https://leetcode.com/problems/palindrome-number) | [![Java](assets/java.png)](src/PalindromeNumber.java) [![Python](assets/python.png)](python/palindrome_number.py) [![js](assets/javascript.png)](javascript/PalindromeNumber.js) | | +| 11 | [Container With Most Water](https://leetcode.com/problems/container-with-most-water) | [![Java](assets/java.png)](src/ContainerWitMostWater.java) | | +| 12 | [Integer to Roman](https://leetcode.com/problems/integer-to-roman) | [![Java](assets/java.png)](src/IntegerToRoman.java) | | +| 13 | [Roman To Integer](https://leetcode.com/problems/roman-to-integer/) | [![Java](assets/java.png)](src/RomanToInteger.java) [![Python](assets/python.png)](python/roman_to_integer.py) | [![java-yt](assets/java-yt.png)](https://youtu.be/BCue_mO_81A) [![python-yt](assets/python-yt.png)](https://youtu.be/8h_yGTNvKMA) | +| 14 | [Longest Common Prefix](https://leetcode.com/problems/longest-common-prefix/) | [![Java](assets/java.png)](src/LongestCommonPrefix.java) [![Python](assets/python.png)](python/longest_common_prefix.py) | | +| 15 | [3Sum](https://leetcode.com/problems/3sum) | [![Java](assets/java.png)](src/ThreeSum.java) | | +| 16 | [3Sum Closest](https://leetcode.com/problems/3sum-closest) | [![Java](assets/java.png)](src/ThreeSumClosest.java) | | +| 17 | [Letter Combinations of a Phone Number](https://leetcode.com/problems/letter-combinations-of-a-phone-number) | [![Java](assets/java.png)](src/LetterCombinationsOfAPhoneNumber.java) | | +| 18 | [4Sum](https://leetcode.com/problems/4sum) | [![Java](assets/java.png)](src/FourSum.java) | | +| 19 | [Remove Nth Node From End of List](https://leetcode.com/problems/remove-nth-node-from-end-of-list) | [![Java](assets/java.png)](src/RemoveNthNodeFromEndOfList.java) | | +| 20 | [ValidParentheses](https://leetcode.com/problems/valid-parentheses/) | [![Java](assets/java.png)](src/ValidParentheses.java) [![Python](assets/python.png)](python/valid_parentheses.py) | | +| 21 | [Merge 2 Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/) | [![Java](assets/java.png)](src/Merge2SortedLists.java) [![Python](assets/python.png)](python/merge_2_sorted_lists.py) | | +| 22 | [Generate Parentheses](https://leetcode.com/problems/generate-parentheses) | [![Java](assets/java.png)](src/GenerateParentheses.java) | | +| 24 | [Swap Nodes in Pairs](https://leetcode.com/problems/swap-nodes-in-pairs) | [![Java](assets/java.png)](src/SwapNodesInPairs.java) | | +| 26 | [Remove Duplicates From Sorted Array](https://leetcode.com/problems/remove-duplicates-from-sorted-array) | [![Java](assets/java.png)](src/RemoveDuplicatesFromSortedArray.java) [![Python](assets/python.png)](python/remove_duplicates_from_sorted_array.py) [![js](assets/javascript.png)](javascript/RemoveDuplicatesFromSortedArray.js) | | +| 27 | [Remove Element](https://leetcode.com/problems/remove-element/) | [![Java](assets/java.png)](src/RemoveElement.java) [![Python](assets/python.png)](python/remove_element.py) | | +| 28 | [Needle in Haystack](https://leetcode.com/problems/implement-strstr) | [![Java](assets/java.png)](src/NeedleInHaystack.java) [![Python](assets/python.png)](python/needle_in_haystack.py) | | +| 29 | [Divide Two Integers](https://leetcode.com/problems/divide-two-integers) | [![Java](assets/java.png)](src/DivideTwoIntegers.java) | | +| 31 | [Next Permutation](https://leetcode.com/problems/next-permutation) | [![Java](assets/java.png)](src/NextPermutation.java) | | +| 33 | [Search in Rotated Sorted Array](https://leetcode.com/problems/search-in-rotated-sorted-array) | [![Java](assets/java.png)](src/SearchInRotatedSortedArray.java) | | +| 34 | [Find First and Last Position of Element in Sorted Array](https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array) | [![Java](assets/java.png)](src/FindFirstAndLastPositionOfElementInSortedArray.java) | | +| 35 | [Search Inserted Position](https://leetcode.com/problems/search-insert-position/) | [![Java](assets/java.png)](src/SearchInsertPosition.java) [![Python](assets/python.png)](python/search_insert_position.py) | | +| 36 | [Valid Sudoku](https://leetcode.com/problems/valid-sudoku) | [![Java](assets/java.png)](src/ValidSudoku.java) | | +| 37 | [Sudoku Solver](https://leetcode.com/problems/sudoku-solver) | [![Java](assets/java.png)](src/SudokuSolver.java) | | +| 38 | [Count and Say](https://leetcode.com/problems/count-and-say) | [![Java](assets/java.png)](src/CountAndSay.java) [![Python](assets/python.png)](python/count_and_say.py) | | +| 39 | [Combination Sum](https://leetcode.com/problems/combination-sum) | [![Java](assets/java.png)](src/CombinationSum.java) | | +| 40 | [Combination Sum II](https://leetcode.com/problems/combination-sum-ii) | [![Java](assets/java.png)](src/CombinationSumII.java) | | +| 42 | [Trapping Rain Water](https://leetcode.com/problems/trapping-rain-water) | [![Java](assets/java.png)](src/TrappingRainwater.java) | | +| 43 | [Multiply Strings](https://leetcode.com/problems/multiply-strings) | [![Java](assets/java.png)](src/MultiplyStrings.java) | | +| 45 | [Jump Game II](https://leetcode.com/problems/jump-game-ii) | [![Java](assets/java.png)](src/JumpGameII.java) | | +| 46 | [Permutations](https://leetcode.com/problems/permutations) | [![Java](assets/java.png)](src/Permutations.java) | | +| 47 | [Permutations II](https://leetcode.com/problems/permutations-ii) | [![Java](assets/java.png)](src/PermutationsII.java) | | +| 48 | [Rotate Image](https://leetcode.com/problems/rotate-image) | [![Java](assets/java.png)](src/RotateImage.java) | | +| 49 | [Group Anagrams](https://leetcode.com/problems/group-anagrams) | [![Java](assets/java.png)](src/GroupAnagrams.java) | | +| 50 | [Pow(x,n)](https://leetcode.com/problems/powx-n) | [![Java](assets/java.png)](src/Powxn.java) | | +| 53 | [Maximum SubArray](https://leetcode.com/problems/maximum-subarray) | [![Java](assets/java.png)](src/MaximumSubArray.java) [![Python](assets/python.png)](python/maximum_sum_subarray.py) | | +| 54 | [Spiral Matrix](https://leetcode.com/problems/spiral-matrix) | [![Java](assets/java.png)](src/SpiralMatrix.java) | | +| 55 | [Jump Game](https://leetcode.com/problems/jump-game) | [![Java](assets/java.png)](src/JumpGame.java) | | +| 56 | [Merge Intervals](https://leetcode.com/problems/merge-intervals) | [![Java](assets/java.png)](src/MergeIntervals.java) | | +| 57 | [Insert Interval](https://leetcode.com/problems/insert-interval) | [![Java](assets/java.png)](src/InsertInterval.java) | | +| 58 | [Length of Last Word](https://leetcode.com/problems/length-of-last-word) | [![Java](assets/java.png)](src/LengthOfLastWord.java) [![Python](assets/python.png)](python/length_of_last_word.py) | | +| 59 | [Spiral Matrix II](https://leetcode.com/problems/spiral-matrix-ii) | [![Java](assets/java.png)](src/SpiralMatrixII.java) | | +| 61 | [Rotate List](https://leetcode.com/problems/rotate-list) | [![Java](assets/java.png)](src/RotateList.java) | | +| 62 | [Unique Paths](https://leetcode.com/problems/unique-paths) | [![Java](assets/java.png)](src/UniquePaths.java) | | +| 63 | [Unique Paths II](https://leetcode.com/problems/unique-paths-ii) | [![Java](assets/java.png)](src/UniquePathII.java) | | +| 64 | [Minimum Path Sum](https://leetcode.com/problems/minimum-path-sum) | [![Java](assets/java.png)](src/MinimumPathSum.java) [![Python](assets/python.png)](python/minimum_path_sum.py) | | +| 66 | [Plus One](https://leetcode.com/problems/plus-one) | [![Java](assets/java.png)](src/PlusOne.java) [![Python](assets/python.png)](python/plus_one.py) | | +| 67 | [Add Binary](https://leetcode.com/problems/add-binary) | [![Java](assets/java.png)](src/AddBinary.java) [![Python](assets/python.png)](python/add_binary.py) | | +| 69 | [Sqrt(x)](https://leetcode.com/problems/sqrtx) | [![Java](assets/java.png)](src/Sqrtx.java) [![Python](assets/python.png)](python/sqrt.py) | | +| 70 | [Climbing Stairs](https://leetcode.com/problems/climbing-stairs) | [![Java](assets/java.png)](src/ClimbingStairs.java) [![Python](assets/python.png)](python/climbing_stairs.py) | | +| 71 | [Simplify Path](https://leetcode.com/problems/simplify-path) | [![Java](assets/java.png)](src/SimplifyPath.java) | | +| 73 | [Set Matrix Zeroes](https://leetcode.com/problems/set-matrix-zeroes) | [![Java](assets/java.png)](src/SetMatrixZeroes.java) | | +| 74 | [Search a 2D Matrix](https://leetcode.com/problems/search-a-2d-matrix) | [![Java](assets/java.png)](src/SearchA2DMatrix.java) | | +| 75 | [Sort Colors](https://leetcode.com/problems/sort-colors) | [![Java](assets/java.png)](src/SortColors.java) | | +| 77 | [Combinations](https://leetcode.com/problems/combinations) | [![Java](assets/java.png)](src/Combinations.java) | | +| 78 | [Subsets](https://leetcode.com/problems/subsets) | [![Java](assets/java.png)](src/Subsets.java) | | +| 79 | [Word Search](https://leetcode.com/problems/word-search) | [![Java](assets/java.png)](src/WordSearch.java) | | +| 80 | [Remove Duplicates from Sorted Array II](https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii) | [![Java](assets/java.png)](src/RemoveDuplicatesFromSortedArrayII.java) | | +| 81 | [Search in Rotated Sorted Array II](https://leetcode.com/problems/search-in-rotated-sorted-array-ii) | [![Java](assets/java.png)](src/SearchInRotatedSortedArrayII.java) | | +| 82 | [Remove Duplicates from Sorted List II](https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii) | [![Java](assets/java.png)](src/RemoveDuplicatesFromSortedListII.java) | | +| 83 | [Remove Duplicates from Sorted List](https://leetcode.com/problems/remove-duplicates-from-sorted-list) | [![Java](assets/java.png)](src/RemoveDuplicatesFromSortedList.java) [![Python](assets/python.png)](python/remove_duplicates_from_linked_list.py) | | +| 86 | [Partition List](https://leetcode.com/problems/partition-list) | [![Java](assets/java.png)](src/PartitionList.java) | | +| 87 | [Scramble String](https://leetcode.com/problems/scramble-string) | [![Python](assets/python.png)](python/scramble_strings.py) | | +| 88 | [Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array) | [![Java](assets/java.png)](src/MergeSortedArray.java) [![Python](assets/python.png)](python/merge_sorted_array.py) | | +| 89 | [Gray Code](https://leetcode.com/problems/gray-code) | [![Java](assets/java.png)](src/GrayCode.java) | | +| 90 | [Subsets II](https://leetcode.com/problems/subsets-ii) | [![Java](assets/java.png)](src/SubsetsII.java) | | +| 91 | [Decode Ways](https://leetcode.com/problems/decode-ways) | [![Java](assets/java.png)](src/DecodeWays.java) | | +| 92 | [Reverse Linked List II](https://leetcode.com/problems/reverse-linked-list-ii) | [![Java](assets/java.png)](src/ReverseLinkedListII.java) | | +| 93 | [Restore IP Addresses](https://leetcode.com/problems/restore-ip-addresses) | [![Java](assets/java.png)](src/RestoreIPAddresses.java) | | +| 94 | [Binary Tree Inorder Traversal](https://leetcode.com/problems/binary-tree-inorder-traversal) | [![Java](assets/java.png)](src/BinaryTreeInorderTraversal.java) [![Python](assets/python.png)](python/binary_tree_inorder_traversal.py) | | +| 95 | [Unique Binary Search Trees II](https://leetcode.com/problems/unique-binary-search-trees-ii) | [![Java](assets/java.png)](src/UniqueBinarySearchTreesII.java) | | +| 96 | [Unique Binary Search Trees](https://leetcode.com/problems/unique-binary-search-trees) | [![Java](assets/java.png)](src/UniqueBinarySearchTrees.java) | | +| 97 | [Interleaving String](https://leetcode.com/problems/interleaving-string) | [![Java](assets/java.png)](src/InterleavingString.java) | | +| 98 | [Validate Binary Search Tree](https://leetcode.com/problems/validate-binary-search-tree) | [![Java](assets/java.png)](src/ValidateBinarySearchTree.java) | | +| 99 | [Recover Binary Search Tree](https://leetcode.com/problems/recover-binary-search-tree) | [![Java](assets/java.png)](src/RecoverBinarySearchTree.java) | | +| 100 | [Same Tree](https://leetcode.com/problems/same-tree) | [![Java](assets/java.png)](src/SameTree.java) [![Python](assets/python.png)](python/same_tree.py) | | +| 101 | [Symmetric Tree](https://leetcode.com/problems/symmetric-tree) | [![Java](assets/java.png)](src/SymmetricTree.java) [![Python](assets/python.png)](python/symmetric_tree.py) | | +| 102 | [Binary Tree Level Order Traversal](https://leetcode.com/problems/binary-tree-level-order-traversal) | [![Java](assets/java.png)](src/BinaryTreeLevelOrderTraversal.java) | | +| 103 | [Binary Tree Zigzag Level Order Traversal](https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal) | [![Java](assets/java.png)](src/BinaryTreeZigzagLevelOrderTraversal.java) | | +| 104 | [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree) | [![Java](assets/java.png)](src/MaximumDepthOfBinaryTree.java) [![Python](assets/python.png)](python/maximum_depth_of_binary_tree.py) | | +| 105 | [Construct Binary Tree from Preorder and Inorder Traversal](https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal) | [![Java](assets/java.png)](src/ConstructBinaryTreeFromPreorderAndInorderTraversal.java) | | +| 106 | [Construct Binary Tree from Inorder and Postorder Traversal](https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal) | [![Java](assets/java.png)](src/ConstructBinaryTreeFromInorderAndPostorderTraversal.java) | | +| 107 | [Binary Tree Level Order Traversal II](https://leetcode.com/problems/binary-tree-level-order-traversal-ii) | [![Java](assets/java.png)](src/BinaryTreeLevelOrderTraversalII.java) [![Python](assets/python.png)](python/binary_tree_level_order_traversal_ii.py) | | +| 108 | [Convert Sorted Array To Binary Search Tree](https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree) | [![Java](assets/java.png)](src/ConvertSortedArrayToBinarySearchTree.java) [![Python](assets/python.png)](python/converted_sorted_array_to_binary_search_tree.py) | | +| 109 | [Convert Sorted List to Binary Search Tree](https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree) | [![Java](assets/java.png)](src/ConvertSortedListToBinarySearchTree.java) | | +| 110 | [Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree) | [![Java](assets/java.png)](src/BalancedBinaryTree.java) [![Python](assets/python.png)](python/balanced_binary_tree.py) | | +| 111 | [Minimum Depth of Binary Tree](https://leetcode.com/problems/minimum-depth-of-binary-tree) | [![Java](assets/java.png)](src/MinimumDepthOfBinaryTree.java) [![Python](assets/python.png)](python/minimum_depth_of_binary_tree.py) | | +| 112 | [Path Sum](https://leetcode.com/problems/path-sum) | [![Java](assets/java.png)](src/PathSum.java) [![Python](assets/python.png)](python/path_sum.py) | | +| 113 | [Path Sum II](https://leetcode.com/problems/path-sum-ii) | [![Java](assets/java.png)](src/PathSumII.java) | | +| 114 | [Flatten Binary Tree to Linked List](https://leetcode.com/problems/flatten-binary-tree-to-linked-list) | [![Java](assets/java.png)](src/FlattenBinaryTreeToLinkedList.java) | | +| 116 | [Populating Next Right Pointers in Each Node](https://leetcode.com/problems/populating-next-right-pointers-in-each-node) | [![Java](assets/java.png)](src/PopulatingNextRightPointersInEachNode.java) | | +| 117 | [Populating Next Right Pointers in Each Node II](https://leetcode.com/problems/populating-next-right-pointers-in-each-node-ii) | [![Java](assets/java.png)](src/PopulatingNextRightPointersInEachNodeII.java) | | +| 118 | [Pascal's Triangle](https://leetcode.com/problems/pascals-triangle) | [![Java](assets/java.png)](src/PascalsTriangle.java) [![Python](assets/python.png)](python/pascals_triangle.py) | | +| 119 | [Pascal's Triangle II](https://leetcode.com/problems/pascals-triangle-ii) | [![Java](assets/java.png)](src/PascalsTriangleII.java) [![Python](assets/python.png)](python/pascals_triangle_ii.py) | | +| 120 | [Triangle](https://leetcode.com/problems/triangle) | [![Java](assets/java.png)](src/Triangle.java) | | +| 121 | [Best Time to Buy and Sell Stocks](https://leetcode.com/problems/best-time-to-buy-and-sell-stock) | [![Java](assets/java.png)](src/BestTimeToBuyAndSellStock.java) [![Python](assets/python.png)](python/best_time_to_buy_and_sell_stock.py) | | +| 122 | [Best Time to Buy and Sell Stocks II](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii) | [![Java](assets/java.png)](src/BestTimeToBuyAndSellStockII.java) [![Python](assets/python.png)](python/best_time_to_buy_and_sell_stock_ii.py) | | +| 125 | [Valid Palindrome](https://leetcode.com/problems/valid-palindrome) | [![Java](assets/java.png)](src/ValidPalindrome.java) [![Python](assets/python.png)](python/valid_palindrome.py) | | +| 128 | [Longest Consecutive Sequence](https://leetcode.com/problems/longest-consecutive-sequence) | [![Java](assets/java.png)](src/LongestConsecutiveSequence.java) | | +| 129 | [Sum Root to Leaf Numbers](https://leetcode.com/problems/sum-root-to-leaf-numbers) | [![Java](assets/java.png)](src/SumRootToLeafNumbers.java) | | +| 130 | [Surrounded Regions](https://leetcode.com/problems/surrounded-regions) | [![Java](assets/java.png)](src/SurroundedRegions.java) | | +| 131 | [Palindrome Partitioning](https://leetcode.com/problems/palindrome-partitioning) | [![Java](assets/java.png)](src/PalindromePartitioning.java) | | +| 133 | [Clone Graph](https://leetcode.com/problems/clone-graph) | [![Java](assets/java.png)](src/CloneGraph.java) [![Python](assets/python.png)](python/clone_graph.py) | | +| 134 | [Gas Station](https://leetcode.com/problems/gas-station) | [![Java](assets/java.png)](src/GasStation.java) | | +| 136 | [Single Number](https://leetcode.com/problems/single-number) | [![Java](assets/java.png)](src/SingleNumber.java) [![Python](assets/python.png)](python/single_number.py) | | +| 137 | [Single Number II](https://leetcode.com/problems/single-number-ii) | [![Java](assets/java.png)](src/SingleNumberII.java) | | +| 138 | [Copy List with Random Pointer](https://leetcode.com/problems/copy-list-with-random-pointer) | [![Java](assets/java.png)](src/CopyListWithRandomPointer.java) | | +| 139 | [Word Break](https://leetcode.com/problems/word-break) | [![Java](assets/java.png)](src/WordBreak.java) | | +| 141 | [Linked List Cycle](https://leetcode.com/problems/linked-list-cycle) | [![Java](assets/java.png)](src/LinkedListCycle.java) [![Python](assets/python.png)](python/linked_list_cycle.py) | | +| 142 | [Linked List Cycle II](https://leetcode.com/problems/linked-list-cycle-ii) | [![Java](assets/java.png)](src/LinkedListCycleII.java) | | +| 143 | [Reorder List](https://leetcode.com/problems/reorder-list) | [![Java](assets/java.png)](src/ReorderList.java) | | +| 144 | [Binary Tree Preorder Traversal](https://leetcode.com/problems/binary-tree-preorder-traversal) | [![Java](assets/java.png)](src/BinaryTreePreOrderTraversal.java) [![Python](assets/python.png)](python/binary_tree_preorder_traversal.py) | | +| 145 | [Binary Tree Postorder Traversal](https://leetcode.com/problems/binary-tree-postorder-traversal) | [![Java](assets/java.png)](src/BinaryTreePostorderTraversal.java) [![Python](assets/python.png)](python/binary_tree_postorder_traversal.py) | | +| 146 | [LRU Cache](https://leetcode.com/problems/lru-cache) | [![Java](assets/java.png)](src/LRUCache.java) | | +| 147 | [Insertion Sort List](https://leetcode.com/problems/insertion-sort-list) | [![Java](assets/java.png)](src/InsertionSortList.java) | | +| 148 | [Sort List](https://leetcode.com/problems/sort-list) | [![Java](assets/java.png)](src/SortList.java) | | +| 150 | [Evaluate Reverse Polish Notation](https://leetcode.com/problems/evaluate-reverse-polish-notation) | [![Java](assets/java.png)](src/EvaluateReversePolishNotation.java) | | +| 151 | [Reverse Words in a String](https://leetcode.com/problems/reverse-words-in-a-string) | [![Java](assets/java.png)](src/ReverseWordsInAString.java) | | +| 152 | [Maximum Product Subarray](https://leetcode.com/problems/maximum-product-subarray) | [![Java](assets/java.png)](src/MaximumProductSubarray.java) | | +| 153 | [Find Minimum in Rotated Sorted Array](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array) | [![Java](assets/java.png)](src/FindMinimumInRotatedSortedArray.java) | | +| 155 | [Min Stack](https://leetcode.com/problems/min-stack) | [![Java](assets/java.png)](src/MinStack.java) [![Python](assets/python.png)](python/min_stack.py) | | +| 156 | 🔒 [Binary Tree Upside Down](https://leetcode.com/problems/binary-tree-upside-down) | | | +| 157 | [Read N Characters Given Read4](https://leetcode.com/problems/read-n-characters-given-read4) | | | +| 159 | 🔒 [Longest Substring With At Most Two Distinct Characters](https://leetcode.com/problems/longest-substring-with-at-most-two-distinct-characters) | | | +| 160 | [Intersection of Two Linked Lists](https://leetcode.com/problems/intersection-of-two-linked-lists) | [![Java](assets/java.png)](src/IntersectionOf2LinkedLists.java) [![Python](assets/python.png)](python/intersecction_of_two_linked_lists.py) | | +| 161 | 🔒 [One Edit Distance](https://leetcode.com/problems/one-edit-distance) | | | +| 162 | [Find Peak Element](https://leetcode.com/problems/find-peak-element) | [![Java](assets/java.png)](src/FindPeakElement.java) | | +| 165 | [Compare Version Numbers](https://leetcode.com/problems/compare-version-numbers) | [![Java](assets/java.png)](src/CompareVersionNumbers.java) | | +| 166 | [Fraction to Recurring Decimal](https://leetcode.com/problems/fraction-to-recurring-decimal) | [![Java](assets/java.png)](src/FractionToRecurringDecimal.java) | | +| 167 | [Two Sum II - Input Array is Sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted) | [![Java](assets/java.png)](src/TwoSumIIInputArrayIsSorted.java) [![Python](assets/python.png)](python/two_sum_ii.py) | | +| 168 | [Excel Sheet Column Title](https://leetcode.com/problems/excel-sheet-column-title) | [![Java](assets/java.png)](src/ExcelSheetColumnTitle.java) [![Python](assets/python.png)](python/excel_sheet_column_title.py) | | +| 169 | [Majority Element](https://leetcode.com/problems/majority-element) | [![Java](assets/java.png)](src/MajorityElement.java) [![Python](assets/python.png)](python/majority_element.py) | | +| 170 | 🔒 [Two Sum III - Data Structure Design](https://leetcode.com/problems/two-sum-iii-data-structure-design) | | | +| 171 | [Excel Sheet Column Number](https://leetcode.com/problems/excel-sheet-column-number) | [![Java](assets/java.png)](src/ExcelSheetColumnNumber.java) [![Python](assets/python.png)](python/excel_sheet_column_number.py) | | +| 172 | [Factoring Trailing Zeroes](https://leetcode.com/problems/factorial-trailing-zeroes) | [![Java](assets/java.png)](src/FactorialTrailingZeros.java) [![Python](assets/python.png)](python/factorial_trailing_zeroes.py) | | +| 173 | [Binary Search Tree Iterator](https://leetcode.com/problems/binary-search-tree-iterator) | [![Java](assets/java.png)](src/BinarySearchTreeIterator.java) | | +| 179 | [Largest Number](https://leetcode.com/problems/largest-number) | [![Java](assets/java.png)](src/LargestNumber.java) | | +| 187 | [Repeated DNA Sequences](https://leetcode.com/problems/repeated-dna-sequences) | [![Java](assets/java.png)](src/RepeatedDNASequences.java) | | +| 189 | [Rotate Array](https://leetcode.com/problems/rotate-array) | [![Java](assets/java.png)](src/RotateArray.java) [![Python](assets/python.png)](python/rotate_array.py) | | +| 190 | [Reverse Bits](https://leetcode.com/problems/reverse-bits) | [![Java](assets/java.png)](src/ReverseBits.java) [![Python](assets/python.png)](python/reverse_bits.py) | | +| 191 | [Number of One Bits](https://leetcode.com/problems/number-of-1-bits) | [![Java](assets/java.png)](src/NumberOf1Bit.java) [![Python](assets/python.png)](python/number_of_1_bits.py) | | +| 198 | [House Robber](https://leetcode.com/problems/house-robber) | [![Java](assets/java.png)](src/HouseRobber.java) [![Python](assets/python.png)](python/house_robber.py) | | +| 199 | [Binary Tree Right Side View](https://leetcode.com/problems/binary-tree-right-side-view) | [![Java](assets/java.png)](src/BinaryTreeRightSideView.java) | | +| 200 | [Number of Islands](https://leetcode.com/problems/number-of-islands) | [![Java](assets/java.png)](src/NumberOfIslands.java) [![Python](assets/python.png)](python/number_of_islands.py) | | +| 201 | [Bitwise AND of Numbers Range](https://leetcode.com/problems/bitwise-and-of-numbers-range) | [![Java](assets/java.png)](src/BitwiseANDOfNumbersRange.java) | | +| 202 | [Happy Number](https://leetcode.com/problems/happy-number) | [![Java](assets/java.png)](src/HappyNumber.java) [![Python](assets/python.png)](python/happy_number.py) | | +| 203 | [Remove Linked List Elements](https://leetcode.com/problems/remove-linked-list-elements) | [![Java](assets/java.png)](src/RemoveLinkedListElements.java) [![Python](assets/python.png)](python/remove_linked_list_elements.py) | | +| 204 | [Count Primes](https://leetcode.com/problems/count-primes) | [![Java](assets/java.png)](src/CountPrimes.java) [![Python](assets/python.png)](python/count_primes.py) | | +| 205 | [Isomorphic Strings](https://leetcode.com/problems/isomorphic-strings) | [![Java](assets/java.png)](src/IsomorphicStrings.java) [![Python](assets/python.png)](python/isomorphic_strings.py) | | +| 206 | [Reverse Linked List](https://leetcode.com/problems/reverse-linked-list) | [![Java](assets/java.png)](src/ReverseLinkedList.java) [![Python](assets/python.png)](python/reverse_linked_list.py) | | +| 207 | [Course Schedule](https://leetcode.com/problems/course-schedule) | [![Java](assets/java.png)](src/CourseSchedule.java) | | +| 208 | [Implement Trie (Prefix Tree)](https://leetcode.com/problems/implement-trie-prefix-tree) | [![Java](assets/java.png)](src/Trie.java) [![Python](assets/python.png)](python/trie.py) | | +| 209 | [Minimum Size Subarray Sum](https://leetcode.com/problems/minimum-size-subarray-sum) | [![Java](assets/java.png)](src/MinimumSizeSubarraySum.java) | | +| 210 | [Course Schedule II](https://leetcode.com/problems/course-schedule-ii) | [![Java](assets/java.png)](src/CourseScheduleII.java) | | +| 211 | [Design Add and Search Words Data Structure](https://leetcode.com/problems/design-add-and-search-words-data-structure) | [![Java](assets/java.png)](src/DesignAddAndSearchWordsDataStructure.java) [![Python](assets/python.png)](python/design_add_and_search_words_data_structure.py) | | +| 213 | [House Robber II](https://leetcode.com/problems/house-robber-ii) | [![Java](assets/java.png)](src/HouseRobberII.java) | | +| 215 | [Kth Largest Element in an Array](https://leetcode.com/problems/kth-largest-element-in-an-array) | [![Java](assets/java.png)](src/KthLargestElementInAnArray.java) | | +| 216 | [Combination Sum III](https://leetcode.com/problems/combination-sum-iii) | [![Java](assets/java.png)](src/CombinationSumIII.java) | | +| 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate) | [![Java](assets/java.png)](src/ContainsDuplicate.java) [![Python](assets/python.png)](python/contains_duplicate.py) | | +| 218 | [The Skyline Problem](https://leetcode.com/problems/the-skyline-problem) | [![Python](assets/python.png)](python/the_skyline_problem.py) | | +| 219 | [Contains Duplicate II](https://leetcode.com/problems/contains-duplicate-ii) | [![Java](assets/java.png)](src/ContainsDuplicateII.java) [![Python](assets/python.png)](python/contains_duplicate_ii.py) | | +| 220 | [Contains Duplicate III](https://leetcode.com/problems/contains-duplicate-iii) | [![Java](assets/java.png)](src/ContainsDuplicateIII.java) | | +| 221 | [Maximal Square](https://leetcode.com/problems/maximal-square) | [![Java](assets/java.png)](src/MaximalSquare.java) | | +| 222 | [Count Complete Tree Nodes](https://leetcode.com/problems/count-complete-tree-nodes) | [![Java](assets/java.png)](src/CountCompleteTreeNodes.java) | | +| 223 | [Rectangle Area](https://leetcode.com/problems/rectangle-area) | [![Java](assets/java.png)](src/RectangleArea.java) | | +| 225 | [Implement Stack using Queues](https://leetcode.com/problems/implement-stack-using-queues) | [![Java](assets/java.png)](src/MyStack.java) [![Python](assets/python.png)](python/implement_stack_using_queues.py) | | +| 226 | [Invert Binary Tree](https://leetcode.com/problems/invert-binary-tree) | [![Java](assets/java.png)](src/InvertBinaryTree.java) [![Python](assets/python.png)](python/invert_binary_tree.py) | | +| 227 | [Basic Calculator II](https://leetcode.com/problems/basic-calculator-ii) | [![Java](assets/java.png)](src/BasicCalculatorII.java) | | +| 229 | [Majority Element II](https://leetcode.com/problems/majority-element-ii) | [![Java](assets/java.png)](src/MajorityElementII.java) | | +| 230 | [Kth Smallest Element in a BST](https://leetcode.com/problems/kth-smallest-element-in-a-bst) | [![Java](assets/java.png)](src/KthSmallestElementInABST.java) | | +| 231 | [Power of Two](https://leetcode.com/problems/power-of-two) | [![Java](assets/java.png)](src/PowerOf2.java) [![Python](assets/python.png)](python/is_power_of_2.py) | | +| 232 | [Implement Queue Using Stacks](https://leetcode.com/problems/implement-queue-using-stacks) | [![Java](assets/java.png)](src/MyQueue.java) [![Python](assets/python.png)](python/implement_queue_using_stacks.py) | | +| 234 | [Palindrome Linked Lists](https://leetcode.com/problems/palindrome-linked-list) | [![Java](assets/java.png)](src/PalindromeLinkedList.java) [![Python](assets/python.png)](python/palindrome_linked_list.py) | | +| 235 | [Lowest Common Ancestor of a Binary Search Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree) | [![Java](assets/java.png)](src/LowestCommonAncestorOfBinarySearchTree.java) [![Python](assets/python.png)](python/lowest_common_ancestor_of_bst.py) | | +| 236 | [Lowest Common Ancestor of a Binary Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree) | [![Java](assets/java.png)](src/LowestCommonAncestorOfBinaryTree.java) | | +| 237 | [Delete a Node In A Linked List](https://leetcode.com/problems/delete-node-in-a-linked-list) | [![Java](assets/java.png)](src/DeleteANodeInLinkedList.java) [![Python](assets/python.png)](python/delete_node_in_linked_list.py) | | +| 238 | [Product of Array Except Self](https://leetcode.com/problems/product-of-array-except-self) | [![Java](assets/java.png)](src/ProductOfArrayExceptItself.java) | | +| 240 | [Search a 2D Matrix II](https://leetcode.com/problems/search-a-2d-matrix-ii) | [![Java](assets/java.png)](src/SearchA2DMatrixII.java) | | +| 241 | [Different Ways to Add Parentheses](https://leetcode.com/problems/different-ways-to-add-parentheses) | | | +| 242 | [Valid Anagram](https://leetcode.com/problems/valid-anagram) | [![Java](assets/java.png)](src/ValidAnagram.java) [![Python](assets/python.png)](python/delete_node_in_linked_list.py) | | +| 243 | 🔒 [Shortest Word Distance](https://leetcode.com/problems/shortest-word-distance) | | | +| 244 | 🔒 [Shortest Word Distance II](https://leetcode.com/problems/shortest-word-distance-ii) | | | +| 245 | 🔒 [Shortest Word Distance III](https://leetcode.com/problems/shortest-word-distance-iii) | | | +| 246 | 🔒 [Strobogramatic Number](https://leetcode.com/problems/strobogrammatic-number) | | | +| 247 | 🔒 [Strobogramatic Number II](https://leetcode.com/problems/strobogrammatic-number-ii) | | | +| 249 | 🔒 [Group Shifted Strings](https://leetcode.com/problems/group-shifted-strings) | | | +| 250 | 🔒 [Count Univalue Subtrees](https://leetcode.com/problems/count-univalue-subtrees) | | | +| 251 | 🔒 [Flatten 2D Vector](https://leetcode.com/problems/flatten-2d-vector) | | | +| 252 | 🔒 [Meeting Rooms](https://leetcode.com/problems/meeting-rooms) | | | +| 253 | 🔒 [Meeting Rooms II](https://leetcode.com/problems/meeting-rooms-ii) | | | +| 254 | 🔒 [Factor Combinations](https://leetcode.com/problems/factor-combinations) | | | +| 255 | 🔒 [Verify Preorder Sequence In Binary Search Tree](https://leetcode.com/problems/verify-preorder-sequence-in-binary-search-tree) | | | +| 256 | 🔒 [Paint House](https://leetcode.com/problems/paint-house) | | | +| 257 | [Binary Tree Paths](https://leetcode.com/problems/binary-tree-paths) | [![Java](assets/java.png)](src/BinaryTreePaths.java) [![Python](assets/python.png)](python/binary_tree_paths.py) | | +| 258 | [Add Digits](https://leetcode.com/problems/add-digits) | [![Java](assets/java.png)](src/AddDigits.java) [![Python](assets/python.png)](python/add_digits.py) | | +| 259 | 🔒 [3Sum Smaller](https://leetcode.com/problems/3sum-smaller) | | | +| 260 | [Single Number III](https://leetcode.com/problems/single-number-iii) | [![Java](assets/java.png)](src/SingleNumberIII.java) | | +| 261 | 🔒 [Graph Valid Tree](https://leetcode.com/problems/graph-valid-tree) | | | +| 263 | [Ugly Number](https://leetcode.com/problems/ugly-number) | [![Java](assets/java.png)](src/UglyNumber.java) [![Python](assets/python.png)](python/ugly_number.py) | | +| 264 | [Ugly Number II](https://leetcode.com/problems/ugly-number-ii) | [![Java](assets/java.png)](src/UglyNumberII.java) | | +| 266 | 🔒 [Palindrome Permutation](https://leetcode.com/problems/palindrome-permutation) | | | +| 267 | 🔒 [Palindrome Permutation II](https://leetcode.com/problems/palindrome-permutation-ii) | | | +| 268 | [Missing Number](https://leetcode.com/problems/missing-number) | [![Java](assets/java.png)](src/MissingNumber.java) [![Python](assets/python.png)](python/missing_number.py) | | +| 270 | 🔒 [Closest Binary Search Tree Value](https://leetcode.com/problems/closest-binary-search-tree-value) | | | +| 271 | 🔒 [Encode and Decode Strings](https://leetcode.com/problems/encode-and-decode-strings) | | | +| 274 | [H-Index](https://leetcode.com/problems/h-index) | [![Java](assets/java.png)](src/HIndex.java) | | +| 275 | [H-Index II](https://leetcode.com/problems/h-index-ii) | [![Java](assets/java.png)](src/HIndexII.java) | | +| 276 | 🔒 [Paint Fence](https://leetcode.com/problems/paint-fence) | | | +| 277 | 🔒 [Find The Celebrity](https://leetcode.com/problems/find-the-celebrity) | | | +| 278 | [First Bad Version](https://leetcode.com/problems/first-bad-version) | [![Java](assets/java.png)](src/FirstBadVersion.java) [![Python](assets/python.png)](python/first_bad_version.py) | | +| 279 | [Perfect Squares](https://leetcode.com/problems/perfect-squares) | [![Java](assets/java.png)](src/PerfectSquares.java) | | +| 280 | 🔒 [Wiggle Sort](https://leetcode.com/problems/wiggle-sort) | | | +| 281 | 🔒 [Zigzag Iterator](https://leetcode.com/problems/zigzag-iterator) | | | +| 283 | [Move Zeroes](https://leetcode.com/problems/move-zeroes) | [![Java](assets/java.png)](src/MoveZeros.java) [![Python](assets/python.png)](python/move_zeroes.py) | | +| 284 | [Peeking Iterator](https://leetcode.com/problems/peeking-iterator) | [![Java](assets/java.png)](src/PeekingIterator.java) | | +| 285 | 🔒 [Inorder Successor in BST](https://leetcode.com/problems/inorder-successor-in-bst) | | | +| 286 | 🔒 [Walls and Gates](https://leetcode.com/problems/walls-and-gates) | | | +| 287 | [Find the Duplicate Number](https://leetcode.com/problems/find-the-duplicate-number) | [![Java](assets/java.png)](src/FindTheDuplicateNumber.java) | | +| 288 | 🔒 [Unique Word Abbreviation](https://leetcode.com/problems/unique-word-abbreviation) | | | +| 289 | [Game of Life](https://leetcode.com/problems/game-of-life) | | | +| 290 | [Word Pattern](https://leetcode.com/problems/word-pattern) | [![Java](assets/java.png)](src/WordPattern.java) [![Python](assets/python.png)](python/word_pattern.py) | | +| 291 | 🔒 [Word Pattern II](https://leetcode.com/problems/word-pattern-ii) | | | +| 292 | [Nim Game](https://leetcode.com/problems/nim-game) | [![Java](assets/java.png)](src/NimGame.java) [![Python](assets/python.png)](python/nim_game.py) | | +| 293 | 🔒 [Flip Game](https://leetcode.com/problems/flip-game) | | | +| 294 | 🔒 [Flip Game II](https://leetcode.com/problems/flip-game-ii) | | | +| 298 | 🔒 [Binary Tree Longest Consecutive Sequence](https://leetcode.com/problems/binary-tree-longest-consecutive-sequence) | | | +| 299 | [Bulls and Cows](https://leetcode.com/problems/bulls-and-cows) | [![Java](assets/java.png)](src/BullsAndCows.java) [![Python](assets/python.png)](python/bulls_and_cows.py) | | +| 300 | [Longest Increasing Subsequence](https://leetcode.com/problems/longest-increasing-subsequence) | | | +| 303 | [Range Sum Query - Immutable](https://leetcode.com/problems/range-sum-query-immutable) | [![Java](assets/java.png)](src/RangeSumQueryImmutable.java) [![Python](assets/python.png)](python/range_sum_query_immutable.py) | | +| 304 | [Range Sum Query 2D - Immutable](https://leetcode.com/problems/range-sum-query-2d-immutable) | | | +| 306 | [Additive Number](https://leetcode.com/problems/additive-number) | | | +| 307 | [Range Sum Query - Mutable](https://leetcode.com/problems/range-sum-query-mutable) | | | +| 309 | [Best Time to Buy and Sell Stock with Cooldown](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown) | | | +| 310 | [Minimum Height Trees](https://leetcode.com/problems/minimum-height-trees) | | | +| 311 | 🔒 [Sparse Matrix Multiplication](https://leetcode.com/problems/sparse-matrix-multiplication) | | | +| 313 | [Super Ugly Number](https://leetcode.com/problems/super-ugly-number) | | | +| 314 | 🔒 [Binary Tree Vertical Order Traversal](https://leetcode.com/problems/binary-tree-vertical-order-traversal) | | | +| 316 | [Remove Duplicate Letters](https://leetcode.com/problems/remove-duplicate-letters) | | | +| 318 | [Maximum Product of Word Lengths](https://leetcode.com/problems/maximum-product-of-word-lengths) | | | +| 319 | [Bulb Switcher](https://leetcode.com/problems/bulb-switcher) | | | +| 320 | 🔒 [Generalized Abbreviation](https://leetcode.com/problems/generalized-abbreviation) | | | +| 322 | [Coin Change](https://leetcode.com/problems/coin-change) | | | +| 323 | 🔒 [Number of Connected Components in Undirected Graph](https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph) | | | +| 324 | [Wiggle Sort II](https://leetcode.com/problems/wiggle-sort-ii) | | | +| 325 | 🔒 [Maximum Size Subarray Sum Equals K](https://leetcode.com/problems/maximum-size-subarray-sum-equals-k) | | | +| 326 | [Power of Three](https://leetcode.com/problems/power-of-three) | [![Java](assets/java.png)](src/PowerOfThree.java) [![Python](assets/python.png)](python/power_of_three.py) | | +| 328 | [Odd Even Linked List](https://leetcode.com/problems/odd-even-linked-list) | | | +| 331 | [Verify Preorder Serialization of a Binary Tree](https://leetcode.com/problems/verify-preorder-serialization-of-a-binary-tree) | | | +| 331 | 🔒 [Largest BST Subtree](https://leetcode.com/problems/largest-bst-subtree) | | | +| 334 | [Increasing Triplet Subsequence](https://leetcode.com/problems/increasing-triplet-subsequence) | | | +| 337 | [House Robber III](https://leetcode.com/problems/increasing-triplet-subsequence) | | | +| 338 | [Counting Bits](https://leetcode.com/problems/counting-bits/) | [![Java](assets/java.png)](src/CountingBits.java) [![Python](assets/python.png)](python/counting_bits.py) | | +| 339 | 🔒 [Nested List Weight Sum](https://leetcode.com/problems/nested-list-weight-sum) | | | +| 340 | 🔒 [Longest Substring with At Most K Distinct Characters](https://leetcode.com/problems/longest-substring-with-at-most-k-distinct-characters) | | | +| 341 | [Flatten Nested List Iterator](https://leetcode.com/problems/flatten-nested-list-iterator) | | | +| 342 | [Power of Four](https://leetcode.com/problems/power-of-four) | [![Java](assets/java.png)](src/PowerOf4.java) [![Python](assets/python.png)](python/power_of_four.py) | | +| 343 | [Integer Break](https://leetcode.com/problems/integer-break) | | | +| 344 | [Reverse A String](https://leetcode.com/problems/reverse-string) | [![Java](assets/java.png)](src/ReverseString.java) [![Python](assets/python.png)](python/reverse_a_string.py) | | +| 345 | [Reverse Vowels of A String](https://leetcode.com/problems/reverse-vowels-of-a-string) | [![Java](assets/java.png)](src/ReverseVowelsOfString.java) [![Python](assets/python.png)](python/reverse_vowels_of_a_string.py) | | +| 346 | 🔒 [Moving Average From Data Stream](https://leetcode.com/problems/moving-average-from-data-stream) | | | +| 347 | [Top K frequent Elements](https://leetcode.com/problems/top-k-frequent-elements) | | | +| 348 | 🔒 [Design Tic-Tac-Toe](https://leetcode.com/problems/design-tic-tac-toe) | | | +| 349 | [Intersection of 2 Arrays](https://leetcode.com/problems/intersection-of-two-arrays) | [![Java](assets/java.png)](src/IntersectionOfTwoArrays.java) [![Python](assets/python.png)](python/intersection_of_2_array.py) | | +| 350 | [Intersection of 2 Arrays II](https://leetcode.com/problems/intersection-of-two-arrays-ii) | [![Java](assets/java.png)](src/IntersectionOfTwoArraysII.java) [![Python](assets/python.png)](python/intersection_of_2_arrays_II.py) | | +| 351 | 🔒 [Android Unlock Patterns](https://leetcode.com/problems/android-unlock-patterns) | | | +| 355 | [Design Twitter](https://leetcode.com/problems/design-twitter) | | | +| 357 | [Count Numbers with Unique Digits](https://leetcode.com/problems/count-numbers-with-unique-digits) | | | +| 359 | 🔒 [Logger Rate Limiter](https://leetcode.com/problems/logger-rate-limiter) | | | +| 367 | [Valid Perfect Square](https://leetcode.com/problems/valid-perfect-square) | [![Java](assets/java.png)](src/IsPerfectSquare.java) [![Python](assets/python.png)](python/valid_perfect_square.py) | | +| 374 | [Guess Number Higher or Lower](https://leetcode.com/problems/guess-number-higher-or-lower) | [![Java](assets/java.png)](src/GuessNumberHigherOrLower.java) [![Python](assets/python.png)](python/guess_number_higher_or_lower.py) | | +| 383 | [Ransom Note](https://leetcode.com/problems/ransom-note) | [![Java](assets/java.png)](src/RansomNote.java) [![Python](assets/python.png)](python/ransom_note.py) | | +| 387 | [First Unique Character in String](https://leetcode.com/problems/first-unique-character-in-a-string) | [![Java](assets/java.png)](src/FirstUniqueCharacter.java) [![Python](assets/python.png)](python/first_unique_character_in_string.py) | | +| 389 | [Find the Difference](https://leetcode.com/problems/find-the-difference) | [![Java](assets/java.png)](src/FindTheDifference.java) [![Python](assets/python.png)](python/find_the_difference.py) | | +| 392 | [Is Subsequence](https://leetcode.com/problems/is-subsequence) | [![Java](assets/java.png)](src/IsSubsequence.java) [![Python](assets/python.png)](python/is_subsequence.py) | | +| 401 | [Binary Watch](https://leetcode.com/problems/binary-watch) | [![Java](assets/java.png)](src/BinaryWatch.java) [![Python](assets/python.png)](python/binary_watch.py) | | +| 404 | [Sum of Left Leaves](https://leetcode.com/problems/sum-of-left-leaves) | [![Java](assets/java.png)](src/SumOfLeftLeaves.java) [![Python](assets/python.png)](python/sum_of_left_leaves.py) | | +| 405 | [Convert a Number to Hexadecimal](https://leetcode.com/problems/convert-a-number-to-hexadecimal) | [![Java](assets/java.png)](src/ConvertNumberToHexadecimal.java) [![Python](assets/python.png)](python/convert_a_number_to_hexadecimal.py) | | +| 408 | 🔒 [Valid Word Abbreviation](https://leetcode.com/problems/valid-word-abbreviation) | | | +| 409 | [Longest Palindrome](https://leetcode.com/problems/longest-palindrome) | [![Java](assets/java.png)](src/LongestPalindrome.java) [![Python](assets/python.png)](python/longest_palindrome.py) | | +| 412 | [Fizz Buzz](https://leetcode.com/problems/fizz-buzz) | [![Java](assets/java.png)](src/FizzBuzz.java) [![Python](assets/python.png)](python/fizz_buzz.py) | | +| 414 | [Third Maximum Number](https://leetcode.com/problems/third-maximum-number) | [![Java](assets/java.png)](src/ThirdMaximumNumber.java) [![Python](assets/python.png)](python/fizz_buzz.py) | | +| 415 | [Add Strings](https://leetcode.com/problems/add-strings) | [![Java](assets/java.png)](src/AddString.java) [![Python](assets/python.png)](python/add_strings.py) | | +| 422 | 🔒 [Valid Word Square](https://leetcode.com/problems/valid-word-square) | | | +| 430 | [Flatten a Multilevel Doubly Linked List](https://leetcode.com/problems/flatten-a-multilevel-doubly-linked-list) | [![Java](assets/java.png)](src/FlattenAMultiLevelDoublyLinkedList.java) | | +| 434 | [Number of Segments in a String](https://leetcode.com/problems/number-of-segments-in-a-string) | [![Java](assets/java.png)](src/NumberOfSegmentsInString.java) [![Python](assets/python.png)](python/number_of_segments_in_a_string.py) | | +| 441 | [Arranging Coins](https://leetcode.com/problems/arranging-coins) | [![Java](assets/java.png)](src/ArrangingCoins.java) [![Python](assets/python.png)](python/arranging_coins.py) | | +| 443 | [String Compression](https://leetcode.com/problems/string-compression) | [![Java](assets/java.png)](src/StringCompression.java) [![Python](assets/python.png)](python/string_compression.py) | | +| 447 | [Number of Boomerangs](https://leetcode.com/problems/number-of-boomerangs) | [![Java](assets/java.png)](src/NumberOfBoomerangs.java) [![Python](assets/python.png)](python/number_of_boomerangs.py) | | +| 448 | [Find All Numbers Disappeared in an Array](https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array) | [![Java](assets/java.png)](src/FindAllNumbersDisappearedInAnArray.java) [![Python](assets/python.png)](python/find_all_numbers_disappeared_in_an_array.py) | | +| 453 | [Minimum Moves to Equal Array Elements](https://leetcode.com/problems/minimum-moves-to-equal-array-elements) | [![Java](assets/java.png)](src/MinimumMovesToEqualArrayElements.java) [![Python](assets/python.png)](python/minimum_moves_to_equal_array_element.py) | | +| 455 | [Assign Cookies](https://leetcode.com/problems/assign-cookies) | [![Java](assets/java.png)](src/AssignCookies.java) [![Python](assets/python.png)](python/assign_cookies.py) | | +| 459 | [Repeated Substring Pattern](https://leetcode.com/problems/repeated-substring-pattern) | [![Java](assets/java.png)](src/RepeatedSubstringPattern.java) [![Python](assets/python.png)](python/repeated_substring_pattern.py) | | +| 461 | [Hamming Distance](https://leetcode.com/problems/hamming-distance) | [![Java](assets/java.png)](src/HammingDistance.java) [![Python](assets/python.png)](python/hamming_distance.py) | | +| 463 | [Island Perimeter](https://leetcode.com/problems/island-perimeter) | [![Java](assets/java.png)](src/IslandPerimeter.java) [![Python](assets/python.png)](python/island_perimeter.py) | | +| 475 | [Heaters](https://leetcode.com/problems/heaters) | [![Java](assets/java.png)](src/Heaters.java) [![Python](assets/python.png)](python/heaters.py) | | +| 476 | [Number Complement](https://leetcode.com/problems/number-complement) | [![Java](assets/java.png)](src/NumberComplement.java) [![Python](assets/python.png)](python/number_complement.py) | | +| 482 | [License Key Formatting](https://leetcode.com/problems/license-key-formatting) | [![Java](assets/java.png)](src/LicenseKeyFormatting.java) [![Python](assets/python.png)](python/license_key_formatting.py) | | +| 485 | [Max Consecutive Ones](https://leetcode.com/problems/max-consecutive-ones) | [![Java](assets/java.png)](src/MaxConsecutiveOnes.java) [![Python](assets/python.png)](python/max_consecutive_ones.py) | | +| 492 | [Construct the Rectangle](https://leetcode.com/problems/construct-the-rectangle) | [![Java](assets/java.png)](src/ConstructTheRectangle.java) [![Python](assets/python.png)](python/construct_the_rectangle.py) | | +| 495 | [Teemo Attacking](https://leetcode.com/problems/teemo-attacking/) | [![Java](assets/java.png)](src/TeemoAttacking.java) [![Python](assets/python.png)](python/teemo_attacking.py) | | +| 496 | [Next Greater Element I](https://leetcode.com/problems/next-greater-element-i) | [![Java](assets/java.png)](src/NextGreaterElementI.java) [![Python](assets/python.png)](python/next_greater_element_i.py) | | +| 500 | [Keyboard Row](https://leetcode.com/problems/keyboard-row) | [![Java](assets/java.png)](src/KeyBoardRow.java) [![Python](assets/python.png)](python/keyboard_row.py) | | +| 501 | [Find Mode in Binary Search Tree](https://leetcode.com/problems/find-mode-in-binary-search-tree) | [![Java](assets/java.png)](src/FindModeInBinarySearchTree.java) [![Python](assets/python.png)](python/find_mode_in_binary_search_tree.py) | | +| 504 | [Base 7](https://leetcode.com/problems/base-7) | [![Java](assets/java.png)](src/Base7.java) [![Python](assets/python.png)](python/base_7.py) | | +| 506 | [Relative Ranks](https://leetcode.com/problems/relative-ranks) | [![Java](assets/java.png)](src/RelativeRanks.java) [![Python](assets/python.png)](python/relative_ranks.py) | | +| 507 | [Perfect Number](https://leetcode.com/problems/perfect-number) | [![Java](assets/java.png)](src/CheckPerfectNumber.java) [![Python](assets/python.png)](python/check_perfect_number.py) | | +| 509 | [Fibonacci Number](https://leetcode.com/problems/fibonacci-number) | [![Java](assets/java.png)](src/FibonacciNumber.java) [![Python](assets/python.png)](python/fibonacci_number.py) | | +| 520 | [Detect Capital](https://leetcode.com/problems/detect-capital) | [![Java](assets/java.png)](src/DetectCapital.java) [![Python](assets/python.png)](python/detect_capital.py) | | +| 521 | [Longest Uncommon Subsequence I](https://leetcode.com/problems/longest-uncommon-subsequence-i) | [![Java](assets/java.png)](src/LongestUncommonSubsequenceI.java) [![Python](assets/python.png)](python/longest_uncommon_subsequence_I.py) | | +| 530 | [Minimum Absolute Difference in BST](https://leetcode.com/problems/minimum-absolute-difference-in-bst) | [![Java](assets/java.png)](src/MinimumAbsoluteDifferenceInBST.java) [![Python](assets/python.png)](python/minimum_absolute_difference_in_bst.py) | | +| 532 | [K - Diff Pairs in Array](https://leetcode.com/problems/k-diff-pairs-in-an-array) | [![Java](assets/java.png)](src/KDiffPairsInAnArray.java) [![Python](assets/python.png)](python/k_dif_pairs_in_an_array.py) | | +| 538 | [Convert BST to Greater Tree](https://leetcode.com/problems/convert-bst-to-greater-tree) | [![Java](assets/java.png)](src/ConvertBSTToGreaterTree.java) [![Python](assets/python.png)](python/convert_bst_to_greater_tree.py) | | +| 541 | [Reverse String II](https://leetcode.com/problems/reverse-string-ii) | [![Java](assets/java.png)](src/ReverseStringII.java) [![Python](assets/python.png)](python/reverse_string_ii.py) | | +| 543 | [Diameter of Binary Tree](https://leetcode.com/problems/diameter-of-binary-tree) | [![Java](assets/java.png)](src/DiameterOfBinaryTree.java) [![Python](assets/python.png)](python/diameter_of_binary_tree.py) | | +| 551 | [Student Attendance Record I](https://leetcode.com/problems/student-attendance-record-i) | [![Java](assets/java.png)](src/StudentAttendanceRecordI.java) [![Python](assets/python.png)](python/student_attendance_record_I.py) | | +| 557 | [Reverse Words in a String III](https://leetcode.com/problems/reverse-words-in-a-string-iii) | [![Java](assets/java.png)](src/ReverseWordsInStringIII.java) [![Python](assets/python.png)](python/reverse_words_in_string_iii.py) | | +| 559 | [Maximum Depth of N-Ary Tree](https://leetcode.com/problems/maximum-depth-of-n-ary-tree) | [![Java](assets/java.png)](src/MaximumDepthOfNAryTree.java) [![Python](assets/python.png)](python/maximum_depth_of_n_ary_tree.py) | | +| 561 | [Array Partition I](https://leetcode.com/problems/array-partition-i) | [![Java](assets/java.png)](src/ArrayPartitionI.java) [![Python](assets/python.png)](python/array_partiton_I.py) | | +| 563 | [Binary Tree Tilt](https://leetcode.com/problems/binary-tree-tilt) | [![Java](assets/java.png)](src/BinaryTreeTilt.java) [![Python](assets/python.png)](python/binary_tree_tilt.py) | | +| 566 | [Reshape The Matrix](https://leetcode.com/problems/reshape-the-matrix) | [![Java](assets/java.png)](src/ReshapeTheMatrix.java) [![Python](assets/python.png)](python/reshape_the_matrix.py) | | +| 572 | [Subtree of Another Tree](https://leetcode.com/problems/subtree-of-another-tree) | [![Java](assets/java.png)](src/SubtreeOfAnotherTree.java) [![Python](assets/python.png)](python/subtree_of_another_tree.py) | | +| 575 | [Distribute Candies](https://leetcode.com/problems/distribute-candies) | [![Java](assets/java.png)](src/DistributeCandies.java) [![Python](assets/python.png)](python/distribute_candies.py) | | +| 581 | [Shortest Unsorted Continuous Subarray](https://leetcode.com/problems/shortest-unsorted-continuous-subarray) | [![Java](assets/java.png)](src/ShortestUnsortedContinuousSubarray.java) [![Python](assets/python.png)](python/shortest_continuous_unsorted_subarray.py) | | +| 589 | [N-Ary Tree Preorder Traversal](https://leetcode.com/problems/n-ary-tree-preorder-traversal) | [![Java](assets/java.png)](src/NArayTreePreOrderTraversal.java) [![Python](assets/python.png)](python/n_ary_tree_preorder_traversal.py) | | +| 590 | [N-Ary Tree Postorder Traversal](https://leetcode.com/problems/n-ary-tree-postorder-traversal) | [![Java](assets/java.png)](src/NAryTreePostorderTraversal.java) [![Python](assets/python.png)](python/n_ary_tree_postorder_traversal.py) | | +| 594 | [Longest Harmonious Subsequence](https://leetcode.com/problems/longest-harmonious-subsequence) | [![Java](assets/java.png)](src/LongestHarmoniousSubsequence.java) [![Python](assets/python.png)](python/longest_harmonious_subequence.py) | | +| 598 | [Range Addition II](https://leetcode.com/problems/range-addition-ii) | [![Java](assets/java.png)](src/RangeAdditionII.java) [![Python](assets/python.png)](python/range_addition_ii.py) | | +| 599 | [Minimum Index Sum of 2 Lists](https://leetcode.com/problems/minimum-index-sum-of-two-lists) | [![Java](assets/java.png)](src/MinimumIndexSumOfTwoLists.java) [![Python](assets/python.png)](python/minimum_index_sum_of_two_lists.py) | | +| 604 | 🔒 [Design Compressed String Iterator](https://leetcode.com/problems/design-compressed-string-iterator) | | | +| 605 | [Can Place Flowers](https://leetcode.com/problems/can-place-flowers) | [![Java](assets/java.png)](src/CanPlaceFlowers.java) [![Python](assets/python.png)](python/can_place_flowers.py) | | +| 606 | [Construct String from Binary Tree](https://leetcode.com/problems/construct-string-from-binary-tree) | [![Java](assets/java.png)](src/ConstructStringFromBinaryTree.java) [![Python](assets/python.png)](python/construct_string_from_binary_tree.py) | | +| 617 | [Merge Two Binary Trees](https://leetcode.com/problems/merge-two-binary-trees) | [![Java](assets/java.png)](src/MergeTwoBinaryTrees.java) [![Python](assets/python.png)](python/merge_two_binary_trees.py) | | +| 624 | 🔒 [Maximum Distance in Arrays](https://leetcode.com/problems/maximum-distance-in-arrays) | | | +| 628 | [Maximum Product of Three Numbers](https://leetcode.com/problems/maximum-product-of-three-numbers) | [![Java](assets/java.png)](src/MaximumProductOfThreeNumbers.java) [![Python](assets/python.png)](python/maximum_product_of_three_numbers.py) | | +| 633 | [Sum Square Numbers](https://leetcode.com/problems/sum-of-square-numbers) | [![Java](assets/java.png)](src/SumOfSquareNumbers.java) [![Python](assets/python.png)](python/sum_of_squares_numbers.py) | | +| 637 | [Average of Levels in Binary Tree](https://leetcode.com/problems/average-of-levels-in-binary-tree) | [![Java](assets/java.png)](src/AverageLevelsOfBinaryTree.java) [![Python](assets/python.png)](python/average_levels_of_binary_tree.py) | | +| 643 | [Maximum Average SubArray I](https://leetcode.com/problems/maximum-average-subarray-i) | [![Java](assets/java.png)](src/MaximumAverageSubArrayI.java) [![Python](assets/python.png)](python/maximum_average_subarray_I.py) | | +| 645 | [Set Mismatch](https://leetcode.com/problems/set-mismatch) | [![Java](assets/java.png)](src/SetMismatch.java) [![Python](assets/python.png)](python/set_mismatch.py) | | +| 653 | [Two Sum IV - Input is a BST](https://leetcode.com/problems/two-sum-iv-input-is-a-bst) | [![Java](assets/java.png)](src/TwoSumIVInputIsABST.java) [![Python](assets/python.png)](python/two_sum_iv.py) | | +| 657 | [Robot Return to Origin](https://leetcode.com/problems/robot-return-to-origin) | [![Java](assets/java.png)](src/RobotReturnToOrigin.java) [![Python](assets/python.png)](python/robot_return_to_origin.py) | | +| 661 | [Image Smoother](https://leetcode.com/problems/image-smoother) | [![Java](assets/java.png)](src/ImageSmoother.java) [![Python](assets/python.png)](python/image_smoother.py) | | +| 665 | [Non Deceasing Array](https://leetcode.com/problems/non-decreasing-array) | [![Java](assets/java.png)](src/NonDecreasingArray.java) [![Python](assets/python.png)](python/non_decreasing_array.py) | | +| 669 | [Trim a Binary Search Tree](https://leetcode.com/problems/trim-a-binary-search-tree) | [![Java](assets/java.png)](src/TrimABinarySearchTree.java) [![Python](assets/python.png)](python/trim_a_binary_search_tree.py) | | +| 671 | [Second Minimum Node in Binary Tree](https://leetcode.com/problems/second-minimum-node-in-a-binary-tree) | [![Java](assets/java.png)](src/SecondMinimumNodeInBinaryTree.java) [![Python](assets/python.png)](python/second_minimum_node_in_binary_tree.py) | | +| 674 | [Longest Continuous Increasing Subsequence](https://leetcode.com/problems/longest-continuous-increasing-subsequence) | [![Java](assets/java.png)](src/LongestContinuousIncreasingSubsequence.java) [![Python](assets/python.png)](python/longest_continuous_increasing_subsequence.py) | | +| 680 | [Valid Palindrome II](https://leetcode.com/problems/valid-palindrome-ii) | [![Java](assets/java.png)](src/ValidPalindromeII.java) [![Python](assets/python.png)](python/valid_pallindrome_ii.py) | | +| 682 | [Baseball Game](https://leetcode.com/problems/baseball-game) | [![Java](assets/java.png)](src/BaseballGame.java) [![Python](assets/python.png)](python/baseball_game.py) | | +| 686 | [Repeated String Match](https://leetcode.com/problems/repeated-string-match) | | | +| 687 | [Longest Univalue Path](https://leetcode.com/problems/longest-univalue-path) | | | +| 688 | [Knight Probability in Chessboard](https://leetcode.com/problems/knight-probability-in-chessboard) | [![Java](assets/java.png)](src/KnightProbabilityInChessboard.java) | | +| 690 | [Employee Importance](https://leetcode.com/problems/employee-importance) | | | +| 693 | [Binary Number with Alternating Bits](https://leetcode.com/problems/binary-number-with-alternating-bits) | [![Java](assets/java.png)](src/BinaryNumberWithAlternatingBits.java) [![Python](assets/python.png)](python/binary_number_with_alternating_bits.py) | | +| 696 | [Count Binary Substrings](https://leetcode.com/problems/count-binary-substrings) | [![Java](assets/java.png)](src/CountBinarySubstrings.java) [![Python](assets/python.png)](python/count_binary_substrings.py) | | +| 697 | [Degree of an Array](https://leetcode.com/problems/degree-of-an-array) | [![Java](assets/java.png)](src/DegreeOfAnArray.java) [![Python](assets/python.png)](python/degree_of_an_array.py) | | +| 700 | [Search in a Binary Search Tree](https://leetcode.com/problems/search-in-a-binary-search-tree) | [![Java](assets/java.png)](src/SearchInBinarySearchTree.java) [![Python](assets/python.png)](python/search_in_binary_search_tree.py) | | +| 703 | [Kth Largest Element in a Stream](https://leetcode.com/problems/kth-largest-element-in-a-stream) | [![Java](assets/java.png)](src/KthLargestElementInAStream.java) [![Python](assets/python.png)](python/k_th_largest_element_in_a_stream.py) | | +| 704 | [Binary Search](https://leetcode.com/problems/binary-search) | [![Java](assets/java.png)](src/BinarySearch.java) [![Python](assets/python.png)](python/binary_search.py) | | +| 705 | [Design HashSet](https://leetcode.com/problems/design-hashset) | [![Java](assets/java.png)](src/DesignHashSet.java) [![Python](assets/python.png)](python/design_hash_set.py) | | +| 706 | [Design HashMap](https://leetcode.com/problems/design-hashmap) | [![Java](assets/java.png)](src/DesignHashMap.java) [![Python](assets/python.png)](python/design_hash_map.py) | | +| 709 | [To Lower Case](https://leetcode.com/problems/to-lower-case) | [![Java](assets/java.png)](src/ToLowerCase.java) [![Python](assets/python.png)](python/to_lower_case.py) | | +| 716 | 🔒 [Max Stack](https://leetcode.com/problems/max-stack) | | | +| 717 | [1-bit and 2-bit Characters](https://leetcode.com/problems/1-bit-and-2-bit-characters) | [![Java](assets/java.png)](src/OneBitAndTwoBitCharacters.java) [![Python](assets/python.png)](python/one_bit_and_two_bit_characters.py) | | +| 718 | [Maximum Length of Repeated Subarray](https://leetcode.com/problems/maximum-length-of-repeated-subarray) | [![Java](assets/java.png)](src/MaximumLengthOfRepeatedSubArray.java) | | +| 720 | [Longest Word in Dictionary](https://leetcode.com/problems/longest-word-in-dictionary) | | | +| 724 | [Find Pivot Index](https://leetcode.com/problems/find-pivot-index) | [![Java](assets/java.png)](src/FindPivotIndex.java) [![Python](assets/python.png)](python/find_pivot_index.py) | | +| 728 | [Self Dividing Numbers](https://leetcode.com/problems/self-dividing-numbers) | [![Java](assets/java.png)](src/SelfDividingNumbers.java) [![Python](assets/python.png)](python/self_dividing_number.py) | | +| 733 | [Flood Fill](https://leetcode.com/problems/flood-fill) | [![Java](assets/java.png)](src/FloodFill.java) [![Python](assets/python.png)](python/flood_fill.py) | | +| 743 | [Network Delay Time](https://leetcode.com/problems/network-delay-time) | [![Java](assets/java.png)](src/NetworkDelayTime.java) | | +| 734 | [Sentence Similarity](https://leetcode.com/problems/sentence-similarity) | | | +| 744 | [Find Smallest Letter Greater Than Target](https://leetcode.com/problems/find-smallest-letter-greater-than-target) | [![Java](assets/java.png)](src/FindSmallestLetterGreaterThanTarget.java) [![Python](assets/python.png)](python/find_smallest_letter_greater_than.py) | | +| 746 | [Min Cost Climbing Stairs](https://leetcode.com/problems/min-cost-climbing-stairs) | [![Java](assets/java.png)](src/MinCostClimbingStairs.java) [![Python](assets/python.png)](python/min_cost_climbing_stairs.py) | | +| 747 | [Largest Number at least Twice of Others](https://leetcode.com/problems/largest-number-at-least-twice-of-others) | [![Java](assets/java.png)](src/LargestNumberAtLeastTwiceOfOthers.java) [![Python](assets/python.png)](python/largest_number_at_least_twice_of_others.py) | | +| 748 | [Shortest Completing Word](https://leetcode.com/problems/shortest-completing-word) | [![Java](assets/java.png)](src/ShortestCompletingWord.java) [![Python](assets/python.png)](python/shortest_completing_word.py) | | +| 758 | [Bold Words in String](https://leetcode.com/problems/bold-words-in-string) | | | +| 760 | [Find Anagram Mappings](https://leetcode.com/problems/find-anagram-mappings) | | | +| 762 | [Prime Number of Set Bits in Primary Representation](https://leetcode.com/problems/prime-number-of-set-bits-in-binary-representation) | [![Java](assets/java.png)](src/PrimeNumberOfSetBitsInBinaryRepresentation.java) [![Python](assets/python.png)](python/prime_number_of_set_bits_in_binary_representation.py) | | +| 766 | [Toeplitz Matrix](https://leetcode.com/problems/toeplitz-matrix) | [![Java](assets/java.png)](src/ToeplitzMatrix.java) [![Python](assets/python.png)](python/toeplitz_matrix.py) | | +| 771 | [Jewels and Stones](https://leetcode.com/problems/jewels-and-stones) | [![Java](assets/java.png)](src/JewelsAndStones.java) [![Python](assets/python.png)](python/jewels_and_stones.py) | | +| 783 | [Minimum Distance Between BST Nodes](https://leetcode.com/problems/minimum-distance-between-bst-nodes) | [![Java](assets/java.png)](src/MinimumAbsoluteDifferenceInBST.java) [![Python](assets/python.png)](python/minimum_distance_between_bst_nodes.py) | | +| 788 | [Rotated Digits](https://leetcode.com/problems/rotated-digits) | | | +| 796 | [Rotate String](https://leetcode.com/problems/rotate-string) | [![Java](assets/java.png)](src/RotateString.java) | | +| 800 | [Similar RGB Color](https://leetcode.com/problems/similar-rgb-color) | | | +| 804 | [Unique Morse Code Words](https://leetcode.com/problems/unique-morse-code-words) | [![Java](assets/java.png)](src/UniqueMorseCodeWords.java) | | +| 806 | [Number of Lines to Write String](https://leetcode.com/problems/number-of-lines-to-write-string) | [![Java](assets/java.png)](src/NumberOfLinesToWriteInString.java) | | +| 811 | [Subdomain Visit Count](https://leetcode.com/problems/subdomain-visit-count) | | | +| 812 | [Largest Triangle Area](https://leetcode.com/problems/largest-triangle-area) | [![Java](assets/java.png)](src/LargestTriangleArea.java) | | +| 819 | [Most Common Word](https://leetcode.com/problems/most-common-word) | [![Java](assets/java.png)](src/MostCommonWord.java) | | +| 821 | [Shortest Distance to Character](https://leetcode.com/problems/shortest-distance-to-a-character) | [![Java](assets/java.png)](src/ShortestDistanceToACharacter.java) | | +| 824 | [Goat Latin](https://leetcode.com/problems/goat-latin) | [![Java](assets/java.png)](src/GoatLatin.java) | | +| 830 | [Positions of Large Groups](https://leetcode.com/problems/positions-of-large-groups) | [![Java](assets/java.png)](src/PositionsOfLargeGroups.java) | | +| 832 | [Flipping an Image](https://leetcode.com/problems/flipping-an-image) | [![Java](assets/java.png)](src/FlippingAnImage.java) | | +| 836 | [Rectangle Overlap](https://leetcode.com/problems/rectangle-overlap) | [![Java](assets/java.png)](src/RectangleOverlap.java) | | +| 840 | [Magic Squares in Grid](https://leetcode.com/problems/magic-squares-in-grid) | | | +| 844 | [Backspace String Compare](https://leetcode.com/problems/backspace-string-compare) | [![Java](assets/java.png)](src/BackspaceStringCompare.java) | | +| 849 | [Maximize Distance to Closest Person](https://leetcode.com/problems/maximize-distance-to-closest-person) | | | +| 852 | [Peak Index in Mountain Array](https://leetcode.com/problems/peak-index-in-a-mountain-array) | [![Java](assets/java.png)](src/PeakIndexInMountainArray.java) | | +| 859 | [Buddy Strings](https://leetcode.com/problems/buddy-strings) | [![Java](assets/java.png)](src/BuddyStrings.java) | | +| 860 | [Lemonade Change](https://leetcode.com/problems/lemonade-change) | [![Java](assets/java.png)](src/LemonadeChange.java) | | +| 867 | [Transpose Matrix](https://leetcode.com/problems/transpose-matrix) | [![Java](assets/java.png)](src/TransposeMatrix.java) | | +| 868 | [Binary Gap](https://leetcode.com/problems/binary-gap) | [![Java](assets/java.png)](src/BinaryGap.java) | | +| 872 | [Leaf-Similar Trees](https://leetcode.com/problems/leaf-similar-trees) | [![Java](assets/java.png)](src/LeafSimilarTrees.java) | | +| 874 | [Walking Robot Simulation](https://leetcode.com/problems/walking-robot-simulation) | | | +| 876 | [Middle of the Linked List](https://leetcode.com/problems/middle-of-the-linked-list) | [![Java](assets/java.png)](src/MiddleOfTheLinkedList.java) | | +| 881 | [Boats to Save People](https://leetcode.com/problems/boats-to-save-people) | [![Python](assets/python.png)](python/boats_to_save_people.py) | | +| 883 | [Projection Area of 3D Shapes](https://leetcode.com/problems/projection-area-of-3d-shapes) | [![Java](assets/java.png)](src/ProjectionAreaOf3DShapes.java) | | +| 884 | [Uncommon Words from 2 Sentences](https://leetcode.com/problems/uncommon-words-from-two-sentences) | [![Java](assets/java.png)](src/UncommonWordsFromTwoSentences.java) | | +| 888 | [Fair Candy Swap](https://leetcode.com/problems/fair-candy-swap) | [![Java](assets/java.png)](src/FairCandySwap.java) | | +| 892 | [Surface Area of 3D Shapes](https://leetcode.com/problems/surface-area-of-3d-shapes) | [![Java](assets/java.png)](src/SurfaceAreaOf3DShapes.java) | | +| 893 | [Groups of Special Equivalent Strings](https://leetcode.com/problems/groups-of-special-equivalent-strings) | | | +| 896 | [Monotonic Array](https://leetcode.com/problems/monotonic-array) | [![Java](assets/java.png)](src/MonotonicArray.java) | | +| 897 | [Increasing Order Search Tree](https://leetcode.com/problems/increasing-order-search-tree) | [![Java](assets/java.png)](src/IncreasingOrderSearchTree.java) | | +| 905 | [Sort Array by Parity](https://leetcode.com/problems/sort-array-by-parity) | | | +| 908 | [Smallest Range I](https://leetcode.com/problems/smallest-range-i) | [![Java](assets/java.png)](src/SmallestRangeI.java) | | +| 914 | [X of a kind in a Deck of Cards](https://leetcode.com/problems/x-of-a-kind-in-a-deck-of-cards) | [![Java](assets/java.png)](src/XOfAKindInADeckOfCards.java) | | +| 917 | [Reverse Only Letters](https://leetcode.com/problems/reverse-only-letters) | [![Java](assets/java.png)](src/ReverseOnlyLetters.java) | | +| 922 | [Sort Array by Parity II](https://leetcode.com/problems/sort-array-by-parity-ii) | [![Java](assets/java.png)](src/SortArrayByParityII.java) | | +| 925 | [Long Pressed Name](https://leetcode.com/problems/long-pressed-name) | [![Java](assets/java.png)](src/LongPressedName.java) | | +| 929 | [Unique Email Addresses](https://leetcode.com/problems/unique-email-addresses) | [![Java](assets/java.png)](src/UniqueEmailAddresses.java) | | +| 933 | [Number of Recent Calls](https://leetcode.com/problems/number-of-recent-calls) | [![Java](assets/java.png)](src/NumberOfRecentCalls.java) | | +| 937 | [Reorder Data In Log Files](https://leetcode.com/problems/reorder-data-in-log-files) | [![Java](assets/java.png)](src/ReorderDataInLogFiles.java) | | +| 938 | [Range Sum of BST](https://leetcode.com/problems/range-sum-of-bst) | [![Java](assets/java.png)](src/RangeSumOfBST.java) | | +| 941 | [Valid Mountain Array](https://leetcode.com/problems/valid-mountain-array) | [![Java](assets/java.png)](src/ValidMountainArray.java) [![Python](assets/python.png)](python/valid_mountain_array.py) | | +| 942 | [DI String Match](https://leetcode.com/problems/di-string-match) | [![Java](assets/java.png)](src/DIStringMatch.java) | | +| 944 | [Delete Columns to Make Sorted](https://leetcode.com/problems/delete-columns-to-make-sorted) | [![Java](assets/java.png)](src/DeleteColumnsToMakeSorted.java) | | +| 949 | [Largest Time for Given Digits](https://leetcode.com/problems/largest-time-for-given-digits) | | | +| 953 | [Verifying an Alien Dictionary](https://leetcode.com/problems/verifying-an-alien-dictionary) | [![Java](assets/java.png)](src/VerifyAnAlienDictionary.java) | | +| 961 | [N-Repeated Elements in Size 2N Array](https://leetcode.com/problems/n-repeated-element-in-size-2n-array) | [![Java](assets/java.png)](src/NRepeatedElementInSizeNArray.java) | | +| 965 | [Univalued Binary Tree](https://leetcode.com/problems/univalued-binary-tree) | [![Java](assets/java.png)](src/UnivaluedBinaryTree.java) | | +| 970 | [Powerful Integers](https://leetcode.com/problems/powerful-integers) | | | +| 976 | [Largest Perimeter Triangle](https://leetcode.com/problems/largest-perimeter-triangle) | [![Java](assets/java.png)](src/LargestPerimeterTriangle.java) | | +| 977 | [Squares of a Sorted Array](https://leetcode.com/problems/squares-of-a-sorted-array) | | | +| 983 | [Minimum Cost For Tickets](https://leetcode.com/problems/minimum-cost-for-tickets) | [![Python](assets/python.png)](python/minimum_cost_for_tickets.py) | | +| 985 | [Sum of Even Numbers after Queries](https://leetcode.com/problems/sum-of-even-numbers-after-queries) | | | +| 989 | [Add to Array Form of Integer](https://leetcode.com/problems/add-to-array-form-of-integer) | [![Java](assets/java.png)](src/AddToArrayFormOfInteger.java) | | +| 993 | [Cousins in Binary Tree](https://leetcode.com/problems/cousins-in-binary-tree) | [![Java](assets/java.png)](src/CousinsInBinaryTree.java) | | +| 994 | [Rotting Oranges](https://leetcode.com/problems/rotting-oranges) | [![Java](assets/java.png)](src/RottingOranges.java) | | +| 997 | [Find the Town Judge](https://leetcode.com/problems/find-the-town-judge) | [![Java](assets/java.png)](src/FindTheTownJudge.java) | | +| 999 | [Available Captures for Rook](https://leetcode.com/problems/available-captures-for-rook) | [![Java](assets/java.png)](src/AvailableCapturesForRook.java) | | +| 1002 | [Find Common Characters](https://leetcode.com/problems/find-common-characters) | [![Java](assets/java.png)](src/FindCommonCharacters.java) | | +| 1005 | [Maximize Sum of Array After K Negations](https://leetcode.com/problems/maximize-sum-of-array-after-k-negations) | [![Java](assets/java.png)](src/MaximizeSumOfArrayAfterKNegations.java) | | +| 1009 | [Complement of Base 10 Integer](https://leetcode.com/problems/complement-of-base-10-integer) | [![Java](assets/java.png)](src/NumberComplement.java) | | +| 1010 | [Pairs of Songs With Total Durations Divisible by 60](https://leetcode.com/problems/pairs-of-songs-with-total-durations-divisible-by-60) | [![Java](assets/java.png)](src/PartitionArrayIntoThreePartsWithEqualSum.java) | | +| 1013 | [Partition Array into Three Parts with equal Sum](https://leetcode.com/problems/partition-array-into-three-parts-with-equal-sum) | | | +| 1018 | [Binary Prefix Divisible by 5](https://leetcode.com/problems/binary-prefix-divisible-by-5) | [![Java](assets/java.png)](src/BinaryPrefixDivisibleBy5.java) | | +| 1020 | [Number of Enclaves](https://leetcode.com/problems/number-of-enclaves) | [![Python](assets/python.png)](python/number_of_enclaves.py) | | +| 1021 | [Remove Outermost Parenthesis](https://leetcode.com/problems/remove-outermost-parentheses) | [![Java](assets/java.png)](src/RemoveOutermostParentheses.java) | | +| 1022 | [Sum of Root to Leaf Binary Numbers](https://leetcode.com/problems/sum-of-root-to-leaf-binary-numbers) | [![Java](assets/java.png)](src/SumOfRootToLeafBinaryNumbers.java) | | +| 1025 | [Divisor Game](https://leetcode.com/problems/divisor-game) | [![Java](assets/java.png)](src/DivisorGame.java) | | +| 1029 | [Two City Scheduling](https://leetcode.com/problems/two-city-scheduling) | | | +| 1030 | [Matrix Cells in Distance Order](https://leetcode.com/problems/matrix-cells-in-distance-order) | [![Java](assets/java.png)](src/MatrixCellsInDistanceOrder.java) | | +| 1033 | [Moving Stones Until Consecutive](https://leetcode.com/problems/moving-stones-until-consecutive) | | | +| 1037 | [Valid Boomerang](https://leetcode.com/problems/valid-boomerang) | [![Java](assets/java.png)](src/ValidBoomerang.java) | | +| 1042 | [Flower Planting with no Adjacent](https://leetcode.com/problems/flower-planting-with-no-adjacent) | | | +| 1046 | [Last Stone Weight](https://leetcode.com/problems/last-stone-weight) | [![Java](assets/java.png)](src/LastStoneWeight.java) | | +| 1047 | [Remove All adjacent Duplicates in String](https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string) | [![Java](assets/java.png)](src/RemoveAllAdjacentDuplicatesInAString.java) | | +| 1051 | [Height Checker](https://leetcode.com/problems/height-checker) | | | +| 1056 | 🔒 [Confusing Number](https://leetcode.com/problems/confusing-number) | | | +| 1064 | 🔒 [Fixed Point](https://leetcode.com/problems/fixed-point) | | | +| 1065 | 🔒 [Index Pairs of a String](https://leetcode.com/problems/index-pairs-of-a-string) | | | +| 1071 | [Greatest Common Divisors of Strings](https://leetcode.com/problems/greatest-common-divisor-of-strings) | [![Java](assets/java.png)](src/GreatestCommonDivisorOfStrings.java) | | +| 1078 | [Occurrence After Bigram](https://leetcode.com/problems/occurrences-after-bigram) | [![Java](assets/java.png)](src/OccurrencesAfterBigram.java) | | +| 1085 | 🔒 [Sum of Digits in Minimum Number](https://leetcode.com/problems/sum-of-digits-in-the-minimum-number) | | | +| 1086 | 🔒 [High Five](https://leetcode.com/problems/high-five) | | | +| 1089 | [Duplicate Zeroes](https://leetcode.com/problems/duplicate-zeros) | [![Java](assets/java.png)](src/DuplicateZeros.java) | | +| 1099 | 🔒 [Two Sum Less Than K](https://leetcode.com/problems/two-sum-less-than-k) | | | +| 1103 | [Distribute Candies to People](https://leetcode.com/problems/distribute-candies-to-people) | [![Java](assets/java.png)](src/DistributeCandiesToPeople.java) | | +| 1108 | [Defanging an IP Address](https://leetcode.com/problems/defanging-an-ip-address) | [![Java](assets/java.png)](src/DefangingAnIPAddress.java) | | +| 1118 | 🔒 [Number of Days in a Month](https://leetcode.com/problems/number-of-days-in-a-month) | | | +| 1119 | 🔒 [Remove Vowels From String](https://leetcode.com/problems/remove-vowels-from-a-string) | | | +| 1122 | [Relative Sort Array](https://leetcode.com/problems/relative-sort-array) | [![Java](assets/java.png)](src/RelativeSortArray.java) | | +| 1128 | [Number of Equivalent Domino Pairs](https://leetcode.com/problems/number-of-equivalent-domino-pairs) | [![Java](assets/java.png)](src/NumberOfEquivalentDominoPairs.java) | | +| 1133 | 🔒 [Largest Unique Number](https://leetcode.com/problems/largest-unique-number) | | | +| 1134 | 🔒 [Armstrong Number](https://leetcode.com/problems/armstrong-number) | | | +| 1137 | [Nth Tribonacci Number](https://leetcode.com/problems/n-th-tribonacci-number) | [![Java](assets/java.png)](src/NthTribonacciNumber.java) | | +| 1143 | [Longest Common Subsequence](https://leetcode.com/problems/longest-common-subsequence) | [![Java](assets/java.png)](src/LongestCommonSubsequence.java) | | +| 1150 | [Check if Number is Majority Element in Sorted Array](https://leetcode.com/problems/check-if-a-number-is-majority-element-in-a-sorted-array) | | | +| 1154 | [Day of The Year](https://leetcode.com/problems/day-of-the-year) | [![Java](assets/java.png)](src/DayOfTheYear.java) | | +| 1160 | [Find Words That Can Be Formed By Characters](https://leetcode.com/problems/find-words-that-can-be-formed-by-characters) | | | +| 1165 | [Single Row Keyboard](https://leetcode.com/problems/single-row-keyboard) | [![Java](assets/java.png)](src/FindWordsThatCanBeFormedByCharacters.java) | | +| 1170 | [Compare Strings By Frequency of the Smallest Character](https://leetcode.com/problems/compare-strings-by-frequency-of-the-smallest-character) | | | +| 1175 | [Prime Arrangements](https://leetcode.com/problems/prime-arrangements) | [![Java](assets/java.png)](src/PrimeArrangements.java) | | +| 1176 | 🔒 [Diet Plan Performance](https://leetcode.com/problems/diet-plan-performance) | | | +| 1180 | 🔒 [Count Substrings with only one Distinct Letter](https://leetcode.com/problems/count-substrings-with-only-one-distinct-letter) | | | +| 1184 | [Distance Between Bus Stops](https://leetcode.com/problems/distance-between-bus-stops) | [![Java](assets/java.png)](src/DistanceBetweenBusStops.java) | | +| 1185 | [Day of the Week](https://leetcode.com/problems/day-of-the-week) | [![Java](assets/java.png)](src/DayOfWeek.java) | | +| 1189 | [Maximum Number of Balloons](https://leetcode.com/problems/maximum-number-of-balloons) | [![Java](assets/java.png)](src/MaximumNumberOfBalloons.java) | | +| 1196 | 🔒 [How Many Apples Can You Put into the Basket](https://leetcode.com/problems/how-many-apples-can-you-put-into-the-basket) | | | +| 1200 | [Minimum Absolute Difference](https://leetcode.com/problems/minimum-absolute-difference) | [![Java](assets/java.png)](src/MinimumAbsoluteDifference.java) | | +| 1201 | [Ugly Number III](https://leetcode.com/problems/ugly-number-iii) | [![Java](assets/java.png)](src/UglyNumberIII.java) | | +| 1207 | [Unique Number of Occurrences](https://leetcode.com/problems/unique-number-of-occurrences) | [![Java](assets/java.png)](src/UniqueNumberOfOccurrences.java) | | +| 1213 | 🔒 [Intersection of Three Sorted Arrays](https://leetcode.com/problems/intersection-of-three-sorted-arrays) | | | +| 1217 | [Minimum Cost to Move Chips to The Same Position](https://leetcode.com/problems/minimum-cost-to-move-chips-to-the-same-position) | [![Java](assets/java.png)](src/MinimumCostToMoveChipsToTheSamePosition.java) | | +| 1221 | [Split A String In Balanced Strings](https://leetcode.com/problems/split-a-string-in-balanced-strings) | [![Java](assets/java.png)](src/SplitAStringInBalancedStrings.java) | | +| 1228 | 🔒 [Missing A Number In Arithmetic Progression](https://leetcode.com/problems/missing-number-in-arithmetic-progression) | | | +| 1232 | [Check If It Is A Straight Line](https://leetcode.com/problems/check-if-it-is-a-straight-line) | [![Java](assets/java.png)](src/CheckIfItIsASStraightLine.java) | | +| 1237 | [Find Positive Integer Solutions for a Given Equation](https://leetcode.com/problems/find-positive-integer-solution-for-a-given-equation) | | | +| 1243 | 🔒 [Array Transformation](https://leetcode.com/problems/array-transformation) | | | +| 1249 | [Minimum Remove to Make Valid Parentheses](https://leetcode.com/problems/minimum-remove-to-make-valid-parentheses) | [![Java](assets/java.png)](src/MinimumRemoveToMakeValidParentheses.java) | | +| 1252 | [Cells With Odd Values In Matrix](https://leetcode.com/problems/cells-with-odd-values-in-a-matrix) | [![Java](assets/java.png)](src/CellsWithOddValuesInMatrix.java) | | +| 1254 | [Number of Closed Islands](https://leetcode.com/problems/number-of-closed-islands) | [![Python](assets/python.png)](python/number_of_closed_islands.py) | | +| 1260 | [Shift 2D Grid](https://leetcode.com/problems/shift-2d-grid) | [![Java](assets/java.png)](src/Shift2DGrid.java) | | +| 1266 | [Minimum Time Visiting All Points](https://leetcode.com/problems/minimum-time-visiting-all-points) | [![Java](assets/java.png)](src/MinimumTimeVisitingAllPoints.java) | | +| 1271 | 🔒 [Hexspeak](https://leetcode.com/problems/hexspeak) | | | +| 1275 | [Find Winner On a Tic Tac Toe Game](https://leetcode.com/problems/find-winner-on-a-tic-tac-toe-game) | [![Java](assets/java.png)](src/FindWinnerOnATicTacToeGame.java) | | +| 1281 | [Subtract the Product and Sum of Digits of a Integer](https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer) | [![Java](assets/java.png)](src/SubtractTheProductAndSumOfDigitsOfAnInteger.java) | | +| 1287 | [Element Appearing More Than 25% in Sorted Array](https://leetcode.com/problems/element-appearing-more-than-25-in-sorted-array) | [![Java](assets/java.png)](src/ElementAppearingMoreThan25PercentInSortedArray.java) | | +| 1290 | [Convert Binary Number In A Linked List to Integer](https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer) | [![Java](assets/java.png)](src/ConvertBinaryNumberInLinkedListToInteger.java) | | +| 1295 | [Find Numbers With Even Numbers of Digits](https://leetcode.com/problems/find-numbers-with-even-number-of-digits) | [![Java](assets/java.png)](src/FindNumbersWithEvenNumbersOfDigits.java) [![Python](assets/python.png)](python/find_numbers_with_even_number_of_digits.py) | | +| 1299 | [Replace Elements With Greatest Element on Right Side](https://leetcode.com/problems/replace-elements-with-greatest-element-on-right-side) | [![Java](assets/java.png)](src/ReplaceElementWithGreatestElementOnRightSide.java) [![Python](assets/python.png)](python/replace_element_with_greatest_element_on_right_hand_side.py) | | +| 1304 | [Find N Unique Integers Sum Up To Zero](https://leetcode.com/problems/find-n-unique-integers-sum-up-to-zero) | [![Java](assets/java.png)](src/FindNUniqueIntegersSumUpToZero.java) | | +| 1309 | [Decrypt String From Alphabet To Integer Mapping](https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping) | [![Java](assets/java.png)](src/DecryptStringFromAlphabetToIntegerMapping.java) | | +| 1313 | [Decompress Run-Length Encoded Strings](https://leetcode.com/problems/decompress-run-length-encoded-list) | [![Java](assets/java.png)](src/DecompressRunLengthEncodedList.java) | | +| 1317 | [Convert Integer to Sum Of Two Non-Zero Integers](https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers) | [![Java](assets/java.png)](src/ConvertIntegerToTheSumOfTwoNoZeroIntegers.java) | | +| 1319 | [Number of Operations to Make Network Connected](https://leetcode.com/problems/number-of-operations-to-make-network-connected) | [![Python](assets/python.png)](python/no_of_operations_to_make_network_connected.py) | | +| 1323 | [Maximum 69 Number](https://leetcode.com/problems/maximum-69-number) | [![Java](assets/java.png)](src/Maximum69Number.java) | | +| 1331 | [Rank Transform of An Array](https://leetcode.com/problems/rank-transform-of-an-array) | [![Java](assets/java.png)](src/RankTransformOfArray.java) | | +| 1332 | [Remove Palindromic Subsequences](https://leetcode.com/problems/remove-palindromic-subsequences) | [![Java](assets/java.png)](src/RemovePalindromicSubSequences.java) | | +| 1337 | [The K Weakest Rows In A Matrix](https://leetcode.com/problems/the-k-weakest-rows-in-a-matrix) | [![Java](assets/java.png)](src/TheKWeakestRowsInAMatrix.java) | | +| 1342 | [Number of Steps to Reduce a Number to Zero](https://leetcode.com/problems/number-of-steps-to-reduce-a-number-to-zero) | [![Java](assets/java.png)](src/NumberOfStepsToReduceANumberToZero.java) | | +| 1346 | [Check if N and It's Double Exist](https://leetcode.com/problems/check-if-n-and-its-double-exist) | [![Java](assets/java.png)](src/CheckIfNAndItsDoubleExist.java) [![Python](assets/python.png)](python/check_if_n_and_its_double_exist.py) | | +| 1351 | [Count Negative Numbers In A Sorted Matrix](https://leetcode.com/problems/count-negative-numbers-in-a-sorted-matrix) | [![Java](assets/java.png)](src/CountNegativeNumbersInSortedMatrix.java) | | +| 1356 | [Sort Integers by Number of 1 Bits](https://leetcode.com/problems/sort-integers-by-the-number-of-1-bits) | [![Java](assets/java.png)](src/SortIntegersByTheNumberOf1Bits.java) | | +| 1360 | [Number of Days Between Two Dates](https://leetcode.com/problems/number-of-days-between-two-dates) | [![Java](assets/java.png)](src/NumberOfDaysBetweenTwoDates.java) | | +| 1365 | [How Many Numbers Are Smaller Than Current Number](https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number) | [![Java](assets/java.png)](src/HowManyNumbersAreSmallerThanCurrentNumber.java) | | +| 1370 | [Increasing Decreasing String](https://leetcode.com/problems/increasing-decreasing-string) | [![Java](assets/java.png)](src/IncreasingDecreasingString.java) | | +| 1374 | [Generate A String With Characters That Have Odd Count](https://leetcode.com/problems/generate-a-string-with-characters-that-have-odd-counts) | [![Java](assets/java.png)](src/GenerateAStringWithCharactersThatHaveOddCounts.java) | | +| 1376 | [Time Needed to Inform All Employees](https://leetcode.com/problems/time-needed-to-inform-all-employees) | [![Java](assets/java.png)](src/TimeNeededToInformAllEmployees.java) | | +| 1379 | [Find a Corresponding Node of a Binary Tree in a Clone of That Tree](https://leetcode.com/problems/find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree) | [![Java](assets/java.png)](src/FindACorrespondingNodeOfABinaryTreeInACloneOfThatTree.java) | | +| 1380 | [Lucky Numbers In A Matrix](https://leetcode.com/problems/lucky-numbers-in-a-matrix) | [![Java](assets/java.png)](src/LuckyNumbersInAMatrix.java) | | +| 1385 | [Find The Distance Value Between 2 Arrays](https://leetcode.com/problems/find-the-distance-value-between-two-arrays) | [![Java](assets/java.png)](src/FindTheDistanceValuesBetweenTwoArrays.java) | | +| 1389 | [Create Target Array in Given Order](https://leetcode.com/problems/create-target-array-in-the-given-order) | [![Java](assets/java.png)](src/CreateTargetArrayInGivenOrder.java) | | +| 1394 | [Find Lucky Integer In An Array](https://leetcode.com/problems/find-lucky-integer-in-an-array) | [![Java](assets/java.png)](src/FindTheLuckyIntegerInAnArray.java) | | +| 1399 | [Count Largest Group](https://leetcode.com/problems/count-largest-group) | [![Java](assets/java.png)](src/CountLargestGroup.java) | | +| 1402 | [Reducing Dishes](https://leetcode.com/problems/reducing-dishes) | [![Python](assets/python.png)](python/reducing_dishes.py) | | +| 1403 | [Minimum Subsequence in Non-Increasing Order](https://leetcode.com/problems/minimum-subsequence-in-non-increasing-order) | [![Java](assets/java.png)](src/MinimumSubSequenceInNonIncreasingOrder.java) | | +| 1408 | [String Matching In An Array](https://leetcode.com/problems/string-matching-in-an-array) | [![Java](assets/java.png)](src/StringMatchingInAnArray.java) | | +| 1413 | [Minimum Value To Get Positive Step By Step Sum](https://leetcode.com/problems/minimum-value-to-get-positive-step-by-step-sum) | [![Java](assets/java.png)](src/MinimumValueToGetPositiveStepByStepSum.java) | | +| 1417 | [Reformat The String](https://leetcode.com/problems/reformat-the-string) | [![Java](assets/java.png)](src/ReformatTheString.java) | | +| 1422 | [Maximum Score After Splitting A String](https://leetcode.com/problems/maximum-score-after-splitting-a-string) | [![Java](assets/java.png)](src/MaximumScoreAfterSplittingAString.java) | | +| 1426 | 🔒 [Counting Elements](https://leetcode.com/problems/counting-elements) | | | +| 1427 | 🔒 [Performing String Shifts](https://leetcode.com/problems/perform-string-shifts) | | | +| 1431 | [Kids With The Greatest Number Of Candies](https://leetcode.com/problems/kids-with-the-greatest-number-of-candies) | [![Java](assets/java.png)](src/KidsWithTheGreatestNumberOfCandies.java) | | +| 1436 | [Destination City](https://leetcode.com/problems/destination-city) | [![Java](assets/java.png)](src/DestinationCity.java) | | +| 1437 | [Check If All 1's Are at Least Length K Places Away](https://leetcode.com/problems/check-if-all-1s-are-at-least-length-k-places-away) | [![Java](assets/java.png)](src/CheckIfAll1sAreAtLeastKPlacesAway.java) | | +| 1441 | [Build An Array With Stack Operation](https://leetcode.com/problems/build-an-array-with-stack-operations) | [![Java](assets/java.png)](src/BuildAnArrayWithStackOperations.java) | | +| 1444 | [Number of Ways of Cutting a Pizza](https://leetcode.com/problems/number-of-ways-of-cutting-a-pizza) | [![Python](assets/python.png)](python/number_of_ways_of_cutting_pizza.py) | | +| 1446 | [Consecutive Characters](https://leetcode.com/problems/consecutive-characters) | [![Java](assets/java.png)](src/ConsecutiveCharacters.java) | | +| 1450 | [Number of Students Doing Homework at Given Time](https://leetcode.com/problems/number-of-students-doing-homework-at-a-given-time) | [![Java](assets/java.png)](src/NumberOfStudentsDoingHomeworkAtGivenTime.java) | | +| 1455 | [Check If Word Occurs as Prefix of any Word in Sentence](https://leetcode.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence) | [![Java](assets/java.png)](src/CheckIfAWordOccursAsAPrefixOfAnyWordInASentence.java) | | +| 1460 | [Make 2 Arrays Equal by Reversing Sub Arrays](https://leetcode.com/problems/make-two-arrays-equal-by-reversing-sub-arrays) | [![Java](assets/java.png)](src/MakeTwoArraysEqualByReversingSubArrays.java) | | +| 1464 | [Maximum Product of 2 Elements in Array](https://leetcode.com/problems/maximum-product-of-two-elements-in-an-array) | [![Java](assets/java.png)](src/MaximumProductOfTwoElementsInArray.java) | | +| 1466 | [Reorder Routes to Make All Paths Lead to the City Zero](https://leetcode.com/problems/reorder-routes-to-make-all-paths-lead-to-the-city-zero) | [![Java](assets/java.png)](src/MaximumProductOfTwoElementsInArray.java) | | +| 1469 | 🔒 [Find All Lonely Nodes](https://leetcode.com/problems/find-all-the-lonely-nodes) | [![Python](assets/python.png)](python/reorder_routes_to_make_all_paths_lead_to_city_zero.py) | | +| 1470 | [Shuffle The Array](https://leetcode.com/problems/shuffle-the-array) | [![Java](assets/java.png)](src/ShuffleTheArray.java) | | +| 1472 | [Design Browser History](https://leetcode.com/problems/design-browser-history) | [![Java](assets/java.png)](src/DesignBrowserHistory.java) [![Python](assets/python.png)](python/design_browser_history.py) | | +| 1474 | [Delete N Nodes After M Nodes In A Linked List](https://leetcode.com/problems/delete-n-nodes-after-m-nodes-of-a-linked-list) | | | +| 1475 | [Final Prices With Special Discount in a Shop](https://leetcode.com/problems/final-prices-with-a-special-discount-in-a-shop) | [![Java](assets/java.png)](src/FinalPricesWithASpecialDiscountInAShop.java) | | +| 1480 | [Running Sum of 1D Array](https://leetcode.com/problems/running-sum-of-1d-array) | [![Java](assets/java.png)](src/RunningSumOf1DArray.java) | | +| 1486 | [XOR Operations in An Array](https://leetcode.com/problems/xor-operation-in-an-array) | [![Java](assets/java.png)](src/XOROperationInAnArray.java) | | +| 1491 | [Average Salary Excluding the Minimum and Maximum Salary](https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary) | [![Java](assets/java.png)](src/AverageSalaryExcludingTheMinimumAndMaximumSalary.java) | | +| 1496 | [Path Crossing](https://leetcode.com/problems/path-crossing) | [![Java](assets/java.png)](src/PathCrossing.java) | | +| 1502 | [Can Make Arithmetic Progression From Sequence](https://leetcode.com/problems/can-make-arithmetic-progression-from-sequence) | [![Java](assets/java.png)](src/CanMakeArithmeticProgressionFromSequence.java) | | +| 1507 | [Reformat Date](https://leetcode.com/problems/reformat-date) | [![Java](assets/java.png)](src/ReformatDate.java) | | +| 1512 | [Number of Good Pairs](https://leetcode.com/problems/number-of-good-pairs) | [![Java](assets/java.png)](src/NumberOfGoodPairs.java) | | +| 1518 | [Water Bottles](https://leetcode.com/problems/water-bottles) | [![Java](assets/java.png)](src/WaterBottles.java) | | +| 1523 | [Count Odd Numbers In Interval Range](https://leetcode.com/problems/count-odd-numbers-in-an-interval-range) | [![Java](assets/java.png)](src/CountOddNumbersInIntervalRange.java) | | +| 1528 | [Shuffle Strings](https://leetcode.com/problems/shuffle-string) | [![Java](assets/java.png)](src/ShuffleString.java) | | +| 1534 | [Count Good Triplets](https://leetcode.com/problems/count-good-triplets) | [![Java](assets/java.png)](src/CountGoodTriplets.java) | | +| 1539 | [Kth Missing Positive Number](https://leetcode.com/problems/kth-missing-positive-number) | [![Java](assets/java.png)](src/KthMissingPositiveNumber.java) | | +| 1544 | [Make The String Great](https://leetcode.com/problems/make-the-string-great) | [![Java](assets/java.png)](src/MakeTheStringGreat.java) | | +| 1550 | [Three Consecutive Odds](https://leetcode.com/problems/three-consecutive-odds) | [![Java](assets/java.png)](src/ThreeConsecutiveOdds.java) | | +| 1556 | [Thousand Separator](https://leetcode.com/problems/thousand-separator) | [![Java](assets/java.png)](src/ThousandSeparator.java) | | +| 1560 | [Most Visited Sector in a Circular Track](https://leetcode.com/problems/most-visited-sector-in-a-circular-track) | [![Java](assets/java.png)](src/MostVisitedSectorInACircularTrack.java) | | +| 1566 | [Detect Pattern of Length M Repeated K or More Times](https://leetcode.com/problems/detect-pattern-of-length-m-repeated-k-or-more-times) | [![Java](assets/java.png)](src/DetectPatternOfLengthMRepeatedKOrMoreTimes.java) | | +| 1572 | [Matrix Diagonal Sum](https://leetcode.com/problems/matrix-diagonal-sum) | [![Java](assets/java.png)](src/MatrixDiagonalSum.java) | | +| 1576 | [Replace All ?'s to Avoid Consecutive Repeating Characters](https://leetcode.com/problems/replace-all-s-to-avoid-consecutive-repeating-characters) | [![Java](assets/java.png)](src/ReplaceAllToAvoidConsecutiveRepeatingCharacters.java) | | +| 1582 | [Special Positions in a Binary Matrix](https://leetcode.com/problems/special-positions-in-a-binary-matrix) | [![Java](assets/java.png)](src/SpecialPositionInABinaryMatrix.java) | | +| 1588 | [Sum of All Odd Length Subarrays](https://leetcode.com/problems/sum-of-all-odd-length-subarrays) | [![Java](assets/java.png)](src/SumOfAllOddLengthSubArrays.java) | | +| 1592 | [Rearrange Spaces Between Words](https://leetcode.com/problems/rearrange-spaces-between-words) | [![Java](assets/java.png)](src/RearrangeSpacesBetweenWords.java) | | +| 1598 | [Crawler Log Folder](https://leetcode.com/problems/crawler-log-folder) | [![Java](assets/java.png)](src/CrawlerLogFolder.java) | | +| 1600 | [Throne Inheritance](https://leetcode.com/problems/throne-inheritance) | [![Java](assets/java.png)](src/ThroneInheritance.java) | | +| 1603 | [Design Parking System](https://leetcode.com/problems/design-parking-system) | [![Java](assets/java.png)](src/DesignParkingSystem.java) | | +| 1608 | [Special Array With X Elements Greater Than or Equal X](https://leetcode.com/problems/special-array-with-x-elements-greater-than-or-equal-x) | [![Java](assets/java.png)](src/SpecialArrayWithXElementsGreaterThanEqualToX.java) | | +| 1614 | [Maximum Nesting Depth of the Parentheses](https://leetcode.com/problems/maximum-nesting-depth-of-the-parentheses) | [![Java](assets/java.png)](src/MaximumNestingDepthOfTheParentheses.java) | | +| 1619 | [Mean of Array After Removing Some Elements](https://leetcode.com/problems/mean-of-array-after-removing-some-elements) | [![Java](assets/java.png)](src/MeanOfArrayAfterRemovingSomeElements.java) | | +| 1624 | [Largest Substring Between Two Equal Characters](https://leetcode.com/problems/largest-substring-between-two-equal-characters) | [![Java](assets/java.png)](src/LargestSubStringBetweenTwoEqualCharacters.java) | | +| 1629 | [Slowest Key](https://leetcode.com/problems/slowest-key) | [![Java](assets/java.png)](src/SlowestKey.java) | | +| 1636 | [Sort Array by Increasing Frequency](https://leetcode.com/problems/sort-array-by-increasing-frequency) | [![Java](assets/java.png)](src/SortArrayByIncreasingFrequency.java) | | +| 1640 | [Check Array Formation Through Concatenation](https://leetcode.com/problems/check-array-formation-through-concatenation) | [![Java](assets/java.png)](src/CheckArrayFormationThroughConcatenation.java) | | +| 1646 | [Get Maximum in Generated Array](https://leetcode.com/problems/get-maximum-in-generated-array) | [![Java](assets/java.png)](src/GetMaximumInGeneratedArray.java) | | +| 1652 | [Defuse the Bomb](https://leetcode.com/problems/defuse-the-bomb) | [![Java](assets/java.png)](src/DefuseTheBomb.java) | | +| 1656 | [Design an Ordered Stream](https://leetcode.com/problems/design-an-ordered-stream) | [![Java](assets/java.png)](src/DesignAnOrderedStream.java) | | +| 1662 | [Check If Two String Arrays are Equivalent](https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent) | [![Java](assets/java.png)](src/CheckIfTwoStringArraysAreEquivalent.java) | | +| 1668 | [Maximum Repeating Substring](https://leetcode.com/problems/maximum-repeating-substring) | [![Java](assets/java.png)](src/MaximumRepeatingSubString.java) | | +| 1672 | [Richest Customer Wealth](https://leetcode.com/problems/richest-customer-wealth) | [![Java](assets/java.png)](src/RichestCustomerWealth.java) | | +| 1678 | [Goal Parser Interpretation](https://leetcode.com/problems/goal-parser-interpretation) | [![Java](assets/java.png)](src/GoalParserInterpretation.java) | | +| 1684 | [Count the Number of Consistent Strings](https://leetcode.com/problems/count-the-number-of-consistent-strings) | [![Java](assets/java.png)](src/CountTheNumberOfConsistentStrings.java) | | +| 1688 | [Count of Matches in Tournament](https://leetcode.com/problems/count-of-matches-in-tournament) | [![Java](assets/java.png)](src/CountOfMatchesInTournament.java) | | +| 1694 | [Reformat Phone Number](https://leetcode.com/problems/reformat-phone-number) | [![Java](assets/java.png)](src/ReformatPhoneNumber.java) | | +| 1700 | [Number of Students Unable to Eat Lunch](https://leetcode.com/problems/number-of-students-unable-to-eat-lunch) | [![Java](assets/java.png)](src/NumberOfStudentsUnableToEatLunch.java) | | +| 1704 | [Determine if String Halves Are Alike](https://leetcode.com/problems/determine-if-string-halves-are-alike) | [![Java](assets/java.png)](src/DetermineIfStringHalvesAreAlike.java) | | +| 1708 | 🔒 [Largest Subarray Length K](https://leetcode.com/problems/largest-subarray-length-k/) | | | +| 1710 | [Maximum Units on a Truck](https://leetcode.com/problems/maximum-units-on-a-truck/) | [![Java](assets/java.png)](src/MaximumUnitsOnATruck.java) | | +| 1716 | [Calculate Money in Leetcode Bank](https://leetcode.com/problems/calculate-money-in-leetcode-bank) | [![Java](assets/java.png)](src/CalculateMoneyInLeetCodeBank.java) | | +| 1720 | [Decode XORed Array](https://leetcode.com/problems/decode-xored-array) | [![Java](assets/java.png)](src/DecodeXORedArray.java) | | +| 1725 | [Number Of Rectangles That Can Form The Largest Square](https://leetcode.com/problems/number-of-rectangles-that-can-form-the-largest-square) | [![Java](assets/java.png)](src/NumberOfRectanglesThatCanFormTheLargestSquare.java) | | +| 1732 | [Find the Highest Altitude](https://leetcode.com/problems/find-the-highest-altitude) | [![Java](assets/java.png)](src/FindTheHighestAltitude.java) | | +| 1736 | [Latest Time by Replacing Hidden Digits](https://leetcode.com/problems/latest-time-by-replacing-hidden-digits) | [![Java](assets/java.png)](src/LatestTimeByReplacingHiddenDigits.java) | | +| 1742 | [Maximum Number of Balls in a Box](https://leetcode.com/problems/maximum-number-of-balls-in-a-box) | [![Java](assets/java.png)](src/MaximumNumberOfBallsInABox.java) | | +| 1748 | [Sum of Unique Elements](https://leetcode.com/problems/sum-of-unique-elements) | [![Java](assets/java.png)](src/SumOfUniqueElements.java) | | +| 1752 | [Check if Array Is Sorted and Rotated](https://leetcode.com/problems/check-if-array-is-sorted-and-rotated) | [![Java](assets/java.png)](src/CheckIfArrayIsSortedAndRotated.java) | | +| 1758 | [Minimum Changes To Make Alternating Binary String](https://leetcode.com/problems/minimum-changes-to-make-alternating-binary-string) | [![Java](assets/java.png)](src/MinimumChangesToMakeAlternatingBinaryString.java) | | +| 1763 | [Longest Nice Substring](https://leetcode.com/problems/longest-nice-substring) | [![Java](assets/java.png)](src/LongestNiceSubstring.java) | | +| 1768 | [Merge Strings Alternately](https://leetcode.com/problems/merge-strings-alternately) | [![Java](assets/java.png)](src/MergeStringsAlternately.java) | | +| 1773 | [Count Items Matching a Rule](https://leetcode.com/problems/count-items-matching-a-rule) | [![Java](assets/java.png)](src/CountItemsMatchingARule.java) | | +| 1779 | [Find Nearest Point That Has the Same X or Y Coordinate](https://leetcode.com/problems/find-nearest-point-that-has-the-same-x-or-y-coordinate) | [![Java](assets/java.png)](src/FindNearestPointThatHasTheSameXOrYCoordinate.java) | | +| 1784 | [Check if Binary String Has at Most One Segment of Ones](https://leetcode.com/problems/check-if-binary-string-has-at-most-one-segment-of-ones) | [![Java](assets/java.png)](src/CheckIfBinaryStringHasAtMostOneSegmentOfOnes.java) | | +| 1790 | [Check if One String Swap Can Make Strings Equal](https://leetcode.com/problems/check-if-one-string-swap-can-make-strings-equal) | [![Java](assets/java.png)](src/CheckIfOneStringSwapCanMakeStringsEqual.java) | | +| 1791 | [Find Center of Star Graph](https://leetcode.com/problems/find-center-of-star-graph) | [![Java](assets/java.png)](src/FindCenterOfStarGraph.java) | | +| 1796 | [Second Largest Digit in a String](https://leetcode.com/problems/second-largest-digit-in-a-string) | [![Java](assets/java.png)](src/SecondLargestDigitInAString.java) | | +| 1800 | [Maximum Ascending Subarray Sum](https://leetcode.com/problems/maximum-ascending-subarray-sum) | [![Java](assets/java.png)](src/MaximumAscendingSubArraySum.java) | | +| 1805 | [Number of Different Integers in a String](https://leetcode.com/problems/number-of-different-integers-in-a-string) | [![Java](assets/java.png)](src/NumberOfDifferentIntegersInString.java) | | +| 1812 | [Determine Color of a Chessboard Square](https://leetcode.com/problems/determine-color-of-a-chessboard-square) | [![Java](assets/java.png)](src/DetermineColorOfChessboardSquare.java) | | +| 1816 | [Truncate Sentence](https://leetcode.com/problems/truncate-sentence) | [![Java](assets/java.png)](src/TruncateSentences.java) | | +| 1822 | [Sign of the Product of an Array](https://leetcode.com/problems/sign-of-the-product-of-an-array) | [![Java](assets/java.png)](src/SignOfTheProductOfAnArray.java) | | +| 1826 | 🔒 [Faulty Sensor](https://leetcode.com/problems/faulty-sensor) | | | +| 1827 | [Minimum Operations to Make the Array Increasing](https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing) | [![Java](assets/java.png)](src/MinimumOperationsToMakeTheArrayIncreasing.java) | | +| 1832 | [Check if the Sentence Is Pangram](https://leetcode.com/problems/check-if-the-sentence-is-pangram) | [![Java](assets/java.png)](src/CheckIfSentenceIsPangram.java) | | +| 1837 | [Sum of Digits in Base K](https://leetcode.com/problems/sum-of-digits-in-base-k) | [![Java](assets/java.png)](src/SumOfDigitsInBaseK.java) | | +| 1844 | [Replace All Digits with Characters](https://leetcode.com/problems/replace-all-digits-with-characters) | [![Java](assets/java.png)](src/ReplaceAllDigitsWithCharacters.java) | | +| 1848 | [Minimum Distance to the Target Element](https://leetcode.com/problems/minimum-distance-to-the-target-element) | [![Java](assets/java.png)](src/MinimumDistanceToTheTargetElement.java) | | +| 1854 | [Maximum Population Year](https://leetcode.com/problems/maximum-population-year) | [![Java](assets/java.png)](src/MaximumPopulationYear.java) | | +| 1859 | [Sorting the Sentence](https://leetcode.com/problems/sorting-the-sentence) | [![Java](assets/java.png)](src/SortingTheSentence.java) | | +| 1863 | [Sum of All Subset XOR Totals](https://leetcode.com/problems/sum-of-all-subset-xor-totals) | [![Java](assets/java.png)](src/SumOfAllSubsetXORTotals.java) | | +| 1869 | [Longer Contiguous Segments of Ones than Zeros](https://leetcode.com/problems/longer-contiguous-segments-of-ones-than-zeros) | [![Java](assets/java.png)](src/LongerContiguousSegmentOfOnesThanZeros.java) | | +| 1876 | [Substrings of Size Three with Distinct Characters](https://leetcode.com/problems/substrings-of-size-three-with-distinct-characters) | [![Java](assets/java.png)](src/SubstringsOfSizeThreeWithDistinctCharacters.java) | | +| 1880 | [Check if Word Equals Summation of Two Words](https://leetcode.com/problems/check-if-word-equals-summation-of-two-words) | [![Java](assets/java.png)](src/CheckIfWordEqualsSummationOfTwoWords.java) | | +| 1886 | [Determine Whether Matrix Can Be Obtained By Rotation](https://leetcode.com/problems/determine-whether-matrix-can-be-obtained-by-rotation) | [![Java](assets/java.png)](src/DetermineWhetherMatrixCanBeObtainedByRotation.java) | | +| 1893 | [Check if All the Integers in a Range Are Covered](https://leetcode.com/problems/check-if-all-the-integers-in-a-range-are-covered) | [![Java](assets/java.png)](src/CheckIfAllTheIntegersInARangeAreCovered.java) | | +| 1897 | [Redistribute Characters to Make All Strings Equal](https://leetcode.com/problems/redistribute-characters-to-make-all-strings-equal) | [![Java](assets/java.png)](src/RedistributeCharactersToMakeAllStringsEqual.java) | | +| 1903 | [Largest Odd Number in String](https://leetcode.com/problems/largest-odd-number-in-string) | [![Java](assets/java.png)](src/LargestOddNumberInString.java) | | +| 1909 | [Remove One Element to Make the Array Strictly Increasing](https://leetcode.com/problems/remove-one-element-to-make-the-array-strictly-increasing) | [![Java](assets/java.png)](src/RemoveOneElementToMakeTheArrayStrictlyIncreasing.java) | | +| 1913 | [Maximum Product Difference Between Two Pairs](https://leetcode.com/problems/maximum-product-difference-between-two-pairs) | [![Java](assets/java.png)](src/MaximumProductDifferenceBetweenTwoPairs.java) | | +| 1920 | [Build Array from Permutation](https://leetcode.com/problems/build-array-from-permutation) | [![Java](assets/java.png)](src/BuildArrayFromPermutation.java) | | +| 1925 | [Count Square Sum Triples](https://leetcode.com/problems/count-square-sum-triples) | [![Java](assets/java.png)](src/CountSquareSumTriplets.java) | | +| 1929 | [Concatenation of Array](https://leetcode.com/problems/concatenation-of-array) | [![Java](assets/java.png)](src/ConcatenationOfArray.java) | | +| 1933 | 🔒 [Check If String Is Decomposable Into Value EqualSubstrings](https://leetcode.com/problems/check-if-string-is-decomposable-into-value-equal-substring) | | | +| 1935 | [Maximum Number of Words You Can Type](https://leetcode.com/problems/maximum-number-of-words-you-can-type) | [![Java](assets/java.png)](src/MaximumNumberOfWordsYouCanType.java) | | +| 1941 | [Check if All Characters Have Equal Number of Occurrences](https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences) | [![Java](assets/java.png)](src/CheckIfAllCharactersHaveEqualNumberOfOccurrences.java) | | +| 1945 | [Sum of Digits of String After Convert](https://leetcode.com/problems/sum-of-digits-of-string-after-convert) | [![Java](assets/java.png)](src/SumOfDigitsOfStringAfterConvert.java) | | +| 1952 | [Three Divisors](https://leetcode.com/problems/three-divisors) | [![Java](assets/java.png)](src/ThreeDivisors.java) | | +| 1957 | [Delete Characters to Make Fancy String](https://leetcode.com/problems/delete-characters-to-make-fancy-string) | [![Java](assets/java.png)](src/DeleteCharactersToMakeFancyString.java) | | +| 1961 | [Check If String Is a Prefix of Array](https://leetcode.com/problems/check-if-string-is-a-prefix-of-array) | [![Java](assets/java.png)](src/CheckIfStringIsAPrefixOfArray.java) | | +| 1967 | [Number of Strings That Appear as Substrings in Word](https://leetcode.com/problems/number-of-strings-that-appear-as-substrings-in-word) | [![Java](assets/java.png)](src/NumberOfStringsThatAppearAsSubstringsInWord.java) | | +| 1971 | [Find if Path Exists in Graph](https://leetcode.com/problems/find-if-path-exists-in-graph) | [![Java](assets/java.png)](src/FindIfPathExistsInGraph.java) | | +| 1974 | [Minimum Time to Type Word Using Special Typewriter](https://leetcode.com/problems/minimum-time-to-type-word-using-special-typewriter) | [![Java](assets/java.png)](src/MinimumTimeToTypeWordUsingSpecialTypewriter.java) | | +| 1979 | [Find Greatest Common Divisor of Array](https://leetcode.com/problems/find-greatest-common-divisor-of-array) | [![Java](assets/java.png)](src/FindGreatestCommonDivisorOfArray.java) | | +| 1984 | [Minimum Difference Between Highest and Lowest of K Scores](https://leetcode.com/problems/minimum-difference-between-highest-and-lowest-of-k-scores) | [![Java](assets/java.png)](src/MinimumDifferenceBetweenHighestAndLowestOfKScores.java) | | +| 1991 | [Find the Middle Index in Array](https://leetcode.com/problems/find-the-middle-index-in-array) | [![Java](assets/java.png)](src/FindTheMiddleIndexInArray.java) | | +| 1995 | [Count Special Quadruplets](https://leetcode.com/problems/count-special-quadruplets) | [![Java](assets/java.png)](src/CountSpecialQuadruplets.java) | | +| 2000 | [Reverse Prefix of Word](https://leetcode.com/problems/reverse-prefix-of-word) | [![Java](assets/java.png)](src/ReversePrefixOfWord.java) | | +| 2006 | [Count Number of Pairs With Absolute Difference K](https://leetcode.com/problems/count-number-of-pairs-with-absolute-difference-k) | [![Java](assets/java.png)](src/CountNumberOfPairsWithAbsoluteDifferenceK.java) | | +| 2011 | [Final Value of Variable After Performing Operations](https://leetcode.com/problems/final-value-of-variable-after-performing-operations) | [![Java](assets/java.png)](src/FinalValueOfVariableAfterPerformingOperations.java) | | +| 2016 | [Maximum Difference Between Increasing Elements](https://leetcode.com/problems/maximum-difference-between-increasing-elements) | [![Java](assets/java.png)](src/MaximumDifferenceBetweenIncreasingElements.java) | | +| 2022 | [Convert 1D Array Into 2D Array](https://leetcode.com/problems/convert-1d-array-into-2d-array) | [![Java](assets/java.png)](src/Convert1DArrayInto2DArray.java) | | +| 2027 | [Minimum Moves to Convert String](https://leetcode.com/problems/minimum-moves-to-convert-string) | [![Java](assets/java.png)](src/MinimumMovesToConvertString.java) | | +| 2032 | [Two Out of Three](https://leetcode.com/problems/two-out-of-three) | [![Java](assets/java.png)](src/TwoOutOfThree.java) | | +| 2037 | [Minimum Number of Moves to Seat Everyone](https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone) | [![Java](assets/java.png)](src/MinimumNumberOfMovesToSeatEveryone.java) | | +| 2042 | [Check if Numbers Are Ascending in a Sentence](https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence) | [![Java](assets/java.png)](src/CheckIfNumbersAreAscendingInASentence.java) | | +| 2047 | [Number of Valid Words in a Sentence](https://leetcode.com/problems/number-of-valid-words-in-a-sentence) | [![Java](assets/java.png)](src/NumberOfValidWordsInASentence.java) | | +| 2053 | [Kth Distinct String in an Array](https://leetcode.com/problems/kth-distinct-string-in-an-array) | [![Java](assets/java.png)](src/KthDistinctStringInAnArray.java) | | +| 2057 | [Smallest Index With Equal Value](https://leetcode.com/problems/smallest-index-with-equal-value) | [![Java](assets/java.png)](src/SmallestIndexWithEqualValue.java) | | +| 2062 | [Count Vowel Substrings of a String](https://leetcode.com/problems/count-vowel-substrings-of-a-string) | [![Java](assets/java.png)](src/CountVowelSubstringsOfAString.java) | | +| 2068 | [Check Whether Two Strings are Almost Equivalent](https://leetcode.com/problems/check-whether-two-strings-are-almost-equivalent) | [![Java](assets/java.png)](src/CheckWhetherTwoStringsAreAlmostEquivalent.java) | | +| 2073 | [Time Needed to Buy Tickets](https://leetcode.com/problems/time-needed-to-buy-tickets) | [![Java](assets/java.png)](src/TimeNeededToBuyTickets.java) | | +| 2078 | [Two Furthest Houses With Different Colors](https://leetcode.com/problems/two-furthest-houses-with-different-colors) | [![Java](assets/java.png)](src/TwoFurthestHousesWithDifferentColors.java) | | +| 2085 | [Count Common Words With One Occurrence](https://leetcode.com/problems/count-common-words-with-one-occurrence) | [![Java](assets/java.png)](src/CountCommonWordsWithOneOccurrence.java) | | +| 2089 | [Find Target Indices After Sorting Array](https://leetcode.com/problems/find-target-indices-after-sorting-array) | [![Java](assets/java.png)](src/FindTargetIndicesAfterSortingArray.java) | | +| 2094 | [Finding 3-Digit Even Numbers](https://leetcode.com/problems/finding-3-digit-even-numbers) | [![Java](assets/java.png)](src/Finding3DigitEvenNumbers.java) | | +| 2099 | [Find Subsequence of Length K With the Largest Sum](https://leetcode.com/problems/find-subsequence-of-length-k-with-the-largest-sum) | [![Java](assets/java.png)](src/FindSubsequenceOfLengthKWithTheLargestSum.java) | | +| 2103 | [Rings and Rods](https://leetcode.com/problems/rings-and-rods) | [![Java](assets/java.png)](src/RingsAndRods.java) | | +| 2108 | [Find First Palindromic String in the Array](https://leetcode.com/problems/find-first-palindromic-string-in-the-array) | [![Java](assets/java.png)](src/FindFirstPalindromicStringInArray.java) | | +| 2114 | [Maximum Number of Words Found in Sentences](https://leetcode.com/problems/maximum-number-of-words-found-in-sentences) | | | +| 2119 | [A Number After a Double Reversal](https://leetcode.com/problems/a-number-after-a-double-reversal) | | | +| 2124 | [Check if All A's Appears Before All B's](https://leetcode.com/problems/check-if-all-as-appears-before-all-bs) | | | +| 2129 | [Capitalize the Title](https://leetcode.com/problems/capitalize-the-title) | | | +| 2133 | [Check if Every Row and Column Contains All Numbers](https://leetcode.com/problems/check-if-every-row-and-column-contains-all-numbers) | | | +| 2138 | [Divide a String Into Groups of Size k](https://leetcode.com/problems/divide-a-string-into-groups-of-size-k) | | | +| 2144 | [Minimum Cost of Buying Candies With Discount](https://leetcode.com/problems/minimum-cost-of-buying-candies-with-discount) | | | +| 2148 | [Count Elements With Strictly Smaller and Greater Elements](https://leetcode.com/problems/count-elements-with-strictly-smaller-and-greater-elements) | | | +| 2154 | [Keep Multiplying Found Values by Two](https://leetcode.com/problems/keep-multiplying-found-values-by-two) | | | +| 2160 | [Minimum Sum of Four Digit Number After Splitting Digits](https://leetcode.com/problems/minimum-sum-of-four-digit-number-after-splitting-digits) | | | +| 2164 | [Sort Even and Odd Indices Independently](https://leetcode.com/problems/sort-even-and-odd-indices-independently) | | | +| 2169 | [Count Operations to Obtain Zero](https://leetcode.com/problems/count-operations-to-obtain-zero) | | | +| 2176 | [Count Equal and Divisible Pairs in an Array](https://leetcode.com/problems/count-equal-and-divisible-pairs-in-an-array) | | | +| 2180 | [Count Integers With Even Digit Sum](https://leetcode.com/problems/count-integers-with-even-digit-sum) | | | +| 2185 | [Counting Words With a Given Prefix](https://leetcode.com/problems/counting-words-with-a-given-prefix) | | | +| 2190 | [Most Frequent Number Following Key In an Array](https://leetcode.com/problems/most-frequent-number-following-key-in-an-array) | | | +| 2194 | [Cells in a Range on an Excel Sheet](https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet) | | | +| 2200 | [Find All K-Distant Indices in an Array](https://leetcode.com/problems/find-all-k-distant-indices-in-an-array) | | | +| 2206 | [Divide Array Into Equal Pairs](https://leetcode.com/problems/divide-array-into-equal-pairs) | | | +| 2210 | [Count Hills and Valleys in an Array](https://leetcode.com/problems/count-hills-and-valleys-in-an-array) | | | +| 2215 | [Find the Difference of Two Arrays](https://leetcode.com/problems/find-the-difference-of-two-arrays) | | | +| 2220 | [Minimum Bit Flips to Convert Number](https://leetcode.com/problems/minimum-bit-flips-to-convert-number) | | | +| 2224 | [Minimum Number of Operations to Convert Time](https://leetcode.com/problems/minimum-number-of-operations-to-convert-time) | | | +| 2229 | 🔒 [Check if an array is consecutive](https://leetcode.com/problems/check-if-an-array-is-consecutive) | | | +| 2231 | [Largest Number After Digit Swaps by Parity](https://leetcode.com/problems/largest-number-after-digit-swaps-by-parity) | | | +| 2235 | [Add Two Integers](https://leetcode.com/problems/add-two-integers) | | | +| 2236 | [Root Equals Sum of Children](https://leetcode.com/problems/root-equals-sum-of-children) | | | +| 2239 | [Find Closest Number to Zero](https://leetcode.com/problems/find-closest-number-to-zero) | | | +| 2243 | [Calculate Digit Sum of a String](https://leetcode.com/problems/calculate-digit-sum-of-a-string) | | | +| 2248 | [Intersection of Multiple Arrays](https://leetcode.com/problems/intersection-of-multiple-arrays) | | | +| 2255 | [Count Prefixes of a Given String](https://leetcode.com/problems/count-prefixes-of-a-given-string) | | | +| 2259 | [Remove Digit From Number to Maximize Result](https://leetcode.com/problems/remove-digit-from-number-to-maximize-result) | | | +| 2264 | [Largest 3-Same-Digit Number in String](https://leetcode.com/problems/largest-3-same-digit-number-in-string) | | | +| 2269 | [Find the K-Beauty of a Number](https://leetcode.com/problems/find-the-k-beauty-of-a-number) | | | +| 2273 | [Find Resultant Array After Removing Anagrams](https://leetcode.com/problems/find-resultant-array-after-removing-anagrams) | | | +| 2278 | [Percentage of Letter in String](https://leetcode.com/problems/percentage-of-letter-in-string) | | | +| 2283 | [Check if Number Has Equal Digit Count and Digit Value](https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value) | | | +| 2287 | [Rearrange Characters to Make Target String](https://leetcode.com/problems/rearrange-characters-to-make-target-string) | | | +| 2293 | [Min Max Game](https://leetcode.com/problems/min-max-game) | | | +| 2299 | [Strong Password Checker II](https://leetcode.com/problems/strong-password-checker-ii) | | | +| 2300 | [Successful Pairs of Spells and Potions](https://leetcode.com/problems/successful-pairs-of-spells-and-potions) | [![Python](assets/python.png)](python/successfull_pairs_of_spells_and_potions.py) | | +| 2303 | [Calculate Amount Paid in Taxes](https://leetcode.com/problems/calculate-amount-paid-in-taxes) | [![Python](assets/python.png)](python/successfull_pairs_of_spells_and_potions.py) | | +| 2315 | [Count Asterisks](https://leetcode.com/problems/count-asterisks) | [![Python](assets/python.png)](python/successfull_pairs_of_spells_and_potions.py) | | +| 2316 | [Count Unreachable Pairs of Nodes in an Undirected Graph](https://leetcode.com/problems/count-unreachable-pairs-of-nodes-in-an-undirected-graph) | [![Python](assets/python.png)](python/count_unreachable_pair_of_node_in_an_undirectable_graph.py) | | +| 2319 | [Check if Matrix Is X-Matrix](https://leetcode.com/problems/check-if-matrix-is-x-matrix) | [![Python](assets/python.png)](python/count_unreachable_pair_of_node_in_an_undirectable_graph.py) | | +| 2325 | [Decode the Message](https://leetcode.com/problems/decode-the-message) | [![Python](assets/python.png)](python/count_unreachable_pair_of_node_in_an_undirectable_graph.py) | | +| 2331 | [Evaluate Boolean Binary Tree](https://leetcode.com/problems/evaluate-boolean-binary-tree) | [![Python](assets/python.png)](python/count_unreachable_pair_of_node_in_an_undirectable_graph.py) | | +| 2335 | [Minimum Amount of Time to Fill Cups](https://leetcode.com/problems/minimum-amount-of-time-to-fill-cups) | [![Python](assets/python.png)](python/count_unreachable_pair_of_node_in_an_undirectable_graph.py) | | +| 2439 | [Minimize Maximum of Array](https://leetcode.com/problems/minimize-maximum-of-array) | [![Python](assets/python.png)](python/minimize_maximum_of_array.py) | | +| 2341 | [Maximum Number of Pairs in Array](https://leetcode.com/problems/maximum-number-of-pairs-in-array) | [![Python](assets/python.png)](python/count_unreachable_pair_of_node_in_an_undirectable_graph.py) | | +| 2347 | [Best Poker Hand](https://leetcode.com/problems/best-poker-hand) | [![Python](assets/python.png)](python/count_unreachable_pair_of_node_in_an_undirectable_graph.py) | | +| 2348 | [Number of Zero-Filled Subarrays](https://leetcode.com/problems/number-of-zero-filled-subarrays) | [![Python](assets/python.png)](python/number_of_zero_filled_subarrays.py) | | +| 2351 | [First Letter to Appear Twice](https://leetcode.com/problems/first-letter-to-appear-twice) | [![Python](assets/python.png)](python/count_unreachable_pair_of_node_in_an_undirectable_graph.py) | | +| 2357 | [Make Array Zero by Subtracting Equal Amounts](https://leetcode.com/problems/make-array-zero-by-subtracting-equal-amounts) | [![Python](assets/python.png)](python/count_unreachable_pair_of_node_in_an_undirectable_graph.py) | | +| 2360 | [Longest Cycle in a Graph](https://leetcode.com/problems/longest-cycle-in-a-graph) | [![Python](assets/python.png)](python/longest_cycle_in_graph.py) | | +| 2363 | [Merge Similar Items](https://leetcode.com/problems/merge-similar-items) | | | +| 2367 | [Number of Arithmetic Triplets](https://leetcode.com/problems/number-of-arithmetic-triplets) | | | +| 2373 | [Largest Local Values in a Matrix](https://leetcode.com/problems/largest-local-values-in-a-matrix) | | | +| 2379 | [Minimum Recolors to Get K Consecutive Black Blocks](https://leetcode.com/problems/minimum-recolors-to-get-k-consecutive-black-blocks) | | | +| 2383 | [Minimum Hours of Training to Win a Competition](https://leetcode.com/problems/minimum-hours-of-training-to-win-a-competition) | | | +| 2389 | [Longest Subsequence With Limited Sum](https://leetcode.com/problems/longest-subsequence-with-limited-sum) | | | +| 2395 | [Find Subarrays With Equal Sum](https://leetcode.com/problems/find-subarrays-with-equal-sum) | | | +| 2399 | [Check Distances Between Same Letters](https://leetcode.com/problems/check-distances-between-same-letters) | | | +| 2404 | [Most Frequent Even Element](https://leetcode.com/problems/most-frequent-even-element) | | | +| 2409 | [Count Days Spent Together](https://leetcode.com/problems/count-days-spent-together) | | | +| 2413 | [Smallest Even Multiple](https://leetcode.com/problems/smallest-even-multiple) | | | +| 2418 | [Sort the People](https://leetcode.com/problems/sort-the-people) | | | +| 2423 | [Remove Letter To Equalize Frequency](https://leetcode.com/problems/remove-letter-to-equalize-frequency) | | | +| 2427 | [Number of Common Factors](https://leetcode.com/problems/number-of-common-factors) | | | +| 2432 | [The Employee That Worked on the Longest Task](https://leetcode.com/problems/the-employee-that-worked-on-the-longest-task) | | | +| 2437 | [Number of Valid Clock Times](https://leetcode.com/problems/number-of-valid-clock-times) | | | +| 2441 | [Largest Positive Integer That Exists With Its Negative](https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative) | | | +| 2446 | [Determine if Two Events Have Conflict](https://leetcode.com/problems/determine-if-two-events-have-conflict) | | | +| 2451 | [Odd String Difference](https://leetcode.com/problems/odd-string-difference) | | | +| 2455 | [Average Value of Even Numbers That Are Divisible by Three](https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three) | | | +| 2460 | [Apply Operations to an Array](https://leetcode.com/problems/apply-operations-to-an-array) | | | +| 2465 | [Number of Distinct Averages](https://leetcode.com/problems/number-of-distinct-averages) | | | +| 2466 | [Count Ways To Build Good Strings](https://leetcode.com/problems/count-ways-to-build-good-strings) | | | +| 2475 | [Number of Unequal Triplets in Array](https://leetcode.com/problems/number-of-unequal-triplets-in-array) | | | +| 2481 | [Minimum Cuts to Divide a Circle](https://leetcode.com/problems/minimum-cuts-to-divide-a-circle) | | | +| 2485 | [Find the Pivot Integer](https://leetcode.com/problems/find-the-pivot-integer) | | | +| 2490 | [Circular Sentence](https://leetcode.com/problems/circular-sentence) | | | +| 2492 | [Minimum Score of a Path Between Two Cities](https://leetcode.com/problems/minimum-score-of-a-path-between-two-cities) | [![Python](assets/python.png)](python/minimum_score_of_a_path_between_two_cities.py) | | +| 2496 | [Maximum Value of a String in an Array](https://leetcode.com/problems/maximum-value-of-a-string-in-an-array) | | | +| 2500 | [Delete Greatest Value in Each Row](https://leetcode.com/problems/delete-greatest-value-in-each-row) | | | +| 2506 | [Count Pairs Of Similar Strings](https://leetcode.com/problems/count-pairs-of-similar-strings) | | | +| 2511 | [Maximum Enemy Forts That Can Be Captured](https://leetcode.com/problems/maximum-enemy-forts-that-can-be-captured) | | | +| 2515 | [Shortest Distance to Target String in a Circular Array](https://leetcode.com/problems/shortest-distance-to-target-string-in-a-circular-array) | | | +| 2520 | [Count the Digits That Divide a Number](https://leetcode.com/problems/count-the-digits-that-divide-a-number) | | | +| 2525 | [Categorize Box According to Criteria](https://leetcode.com/problems/categorize-box-according-to-criteria) | | | +| 2529 | [Maximum Count of Positive Integer and Negative Integer](https://leetcode.com/problems/maximum-count-of-positive-integer-and-negative-integer) | | | +| 2535 | [Difference Between Element Sum and Digit Sum of an Array](https://leetcode.com/problems/difference-between-element-sum-and-digit-sum-of-an-array) | | | +| 2540 | [Minimum Common Value](https://leetcode.com/problems/minimum-common-value) | | | +| 2544 | [Alternating Digit Sum](https://leetcode.com/problems/alternating-digit-sum) | | | +| 2549 | [Count Distinct Numbers on Board](https://leetcode.com/problems/count-distinct-numbers-on-board) | | | +| 2553 | [Separate the Digits in an Array](https://leetcode.com/problems/separate-the-digits-in-an-array) | | | +| 2558 | [Take Gifts From the Richest Pile](https://leetcode.com/problems/take-gifts-from-the-richest-pile) | | | +| 2562 | [Find the Array Concatenation Value](https://leetcode.com/problems/find-the-array-concatenation-value) | | | +| 2566 | [Maximum Difference by Remapping a Digit](https://leetcode.com/problems/maximum-difference-by-remapping-a-digit) | | | +| 2570 | [Merge Two 2D Arrays by Summing Values](https://leetcode.com/problems/merge-two-2d-arrays-by-summing-values) | | | +| 2574 | [Left and Right Sum Differences](https://leetcode.com/problems/left-and-right-sum-differences) | | | +| 2578 | [Split With Minimum Sum](https://leetcode.com/problems/split-with-minimum-sum) | | | +| 2582 | [Pass the Pillow](https://leetcode.com/problems/pass-the-pillow) | | | +| 2586 | [Count the Number of Vowel Strings in Range](https://leetcode.com/problems/count-the-number-of-vowel-strings-in-range) | | | +| 2591 | [Distribute Money to Maximum Children](https://leetcode.com/problems/distribute-money-to-maximum-children) | | | +| 2595 | [Number of Even and Odd Bits](https://leetcode.com/problems/number-of-even-and-odd-bits) | | | +| 2600 | [K Items With the Maximum Sum](https://leetcode.com/problems/k-items-with-the-maximum-sum) | | | +| 2605 | [Form Smallest Number From Two Digit Arrays](https://leetcode.com/problems/form-smallest-number-from-two-digit-arrays) | | | +| 2605 | [Form Smallest Number From Two Digit Arrays](https://leetcode.com/problems/form-smallest-number-from-two-digit-arrays) | | | +| 2609 | [Find the Longest Balanced Substring of a Binary String](https://leetcode.com/problems/find-the-longest-balanced-substring-of-a-binary-string) | | | +| 2614 | [Prime In Diagonal](https://leetcode.com/problems/prime-in-diagonal) | | | +| 2639 | [Find the Width of Columns of a Grid](https://leetcode.com/problems/find-the-width-of-columns-of-a-grid) | | | +| 2643 | [Row With Maximum Ones](https://leetcode.com/problems/row-with-maximum-ones) | | | +| 2644 | [Find the Maximum Divisibility Score](https://leetcode.com/problems/find-the-maximum-divisibility-score) | | | +| 2651 | [Calculate Delayed Arrival Time](https://leetcode.com/problems/calculate-delayed-arrival-time) | | | +| 2652 | [Sum Multiples](https://leetcode.com/problems/sum-multiples) | | | +| 2656 | [Maximum Sum With Exactly K Elements](https://leetcode.com/problems/maximum-sum-with-exactly-k-elements) | | | +| 2660 | [Determine the Winner of a Bowling Game](https://leetcode.com/problems/determine-the-winner-of-a-bowling-game) | | | +| 2670 | [Find the Distinct Difference Array](https://leetcode.com/problems/find-the-distinct-difference-array) | | | +| 2678 | [Number of Senior Citizens](https://leetcode.com/problems/number-of-senior-citizens) | | | diff --git a/src/FindACorrespondingNodeOfABinaryTreeInACloneOfThatTree.java b/src/FindACorrespondingNodeOfABinaryTreeInACloneOfThatTree.java new file mode 100644 index 0000000..7a55bd4 --- /dev/null +++ b/src/FindACorrespondingNodeOfABinaryTreeInACloneOfThatTree.java @@ -0,0 +1,19 @@ +// https://leetcode.com/problems/find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree +// T: O(N) +// S: O(log(n)) + +public class FindACorrespondingNodeOfABinaryTreeInACloneOfThatTree { + public final TreeNode getTargetCopy(final TreeNode original, final TreeNode cloned, final TreeNode target) { + if (original == null) { + return null; + } + + if (original == target) return cloned; + + TreeNode leftAnswer = getTargetCopy(original.left, cloned.left, target); + TreeNode rightAnswer = getTargetCopy(original.right, cloned.right, target); + + if (leftAnswer != null) return leftAnswer; + return rightAnswer; + } +} From 7320d8c743061d64655f71afdb943ec2f2fa50fb Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 13 May 2023 23:02:00 +0200 Subject: [PATCH 007/280] solves #2114: MaximumNumberOfWordsFoundInSentences in java --- README.md | 2 +- src/MaximumNumberOfWordsFoundInSentences.java | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/MaximumNumberOfWordsFoundInSentences.java diff --git a/README.md b/README.md index 9d202d5..6da2472 100644 --- a/README.md +++ b/README.md @@ -701,7 +701,7 @@ | 2099 | [Find Subsequence of Length K With the Largest Sum](https://leetcode.com/problems/find-subsequence-of-length-k-with-the-largest-sum) | [![Java](assets/java.png)](src/FindSubsequenceOfLengthKWithTheLargestSum.java) | | | 2103 | [Rings and Rods](https://leetcode.com/problems/rings-and-rods) | [![Java](assets/java.png)](src/RingsAndRods.java) | | | 2108 | [Find First Palindromic String in the Array](https://leetcode.com/problems/find-first-palindromic-string-in-the-array) | [![Java](assets/java.png)](src/FindFirstPalindromicStringInArray.java) | | -| 2114 | [Maximum Number of Words Found in Sentences](https://leetcode.com/problems/maximum-number-of-words-found-in-sentences) | | | +| 2114 | [Maximum Number of Words Found in Sentences](https://leetcode.com/problems/maximum-number-of-words-found-in-sentences) | [![Java](assets/java.png)](src/MaximumNumberOfWordsFoundInSentences.java) | | | 2119 | [A Number After a Double Reversal](https://leetcode.com/problems/a-number-after-a-double-reversal) | | | | 2124 | [Check if All A's Appears Before All B's](https://leetcode.com/problems/check-if-all-as-appears-before-all-bs) | | | | 2129 | [Capitalize the Title](https://leetcode.com/problems/capitalize-the-title) | | | diff --git a/src/MaximumNumberOfWordsFoundInSentences.java b/src/MaximumNumberOfWordsFoundInSentences.java new file mode 100644 index 0000000..20af616 --- /dev/null +++ b/src/MaximumNumberOfWordsFoundInSentences.java @@ -0,0 +1,22 @@ +// https://leetcode.com/problems/maximum-number-of-words-found-in-sentences +// T: O(s * |s|) +// S: O(1) +// s = no. of sentences and |s| length of sentence + +public class MaximumNumberOfWordsFoundInSentences { + public int mostWordsFound(String[] sentences) { + int maxWords = 0; + for (String sentence : sentences) { + maxWords = Math.max(maxWords, totalWords(sentence)); + } + return maxWords; + } + + private int totalWords(String string) { + int count = 0; + for (int i = 0 ; i < string.length() ; i++) { + if (string.charAt(i) == ' ') count++; + } + return count + 1; + } +} From 2e25401b12a5f74356b3ef2f8d1c6677b04f90e7 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 13 May 2023 23:05:11 +0200 Subject: [PATCH 008/280] solves #2119: A Number After a Double Reversal in java --- README.md | 2 +- src/ANumberAfterADoubleReversal.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 src/ANumberAfterADoubleReversal.java diff --git a/README.md b/README.md index 6da2472..cd1367f 100644 --- a/README.md +++ b/README.md @@ -702,7 +702,7 @@ | 2103 | [Rings and Rods](https://leetcode.com/problems/rings-and-rods) | [![Java](assets/java.png)](src/RingsAndRods.java) | | | 2108 | [Find First Palindromic String in the Array](https://leetcode.com/problems/find-first-palindromic-string-in-the-array) | [![Java](assets/java.png)](src/FindFirstPalindromicStringInArray.java) | | | 2114 | [Maximum Number of Words Found in Sentences](https://leetcode.com/problems/maximum-number-of-words-found-in-sentences) | [![Java](assets/java.png)](src/MaximumNumberOfWordsFoundInSentences.java) | | -| 2119 | [A Number After a Double Reversal](https://leetcode.com/problems/a-number-after-a-double-reversal) | | | +| 2119 | [A Number After a Double Reversal](https://leetcode.com/problems/a-number-after-a-double-reversal) | [![Java](assets/java.png)](src/ANumberAfterADoubleReversal.java) | | | 2124 | [Check if All A's Appears Before All B's](https://leetcode.com/problems/check-if-all-as-appears-before-all-bs) | | | | 2129 | [Capitalize the Title](https://leetcode.com/problems/capitalize-the-title) | | | | 2133 | [Check if Every Row and Column Contains All Numbers](https://leetcode.com/problems/check-if-every-row-and-column-contains-all-numbers) | | | diff --git a/src/ANumberAfterADoubleReversal.java b/src/ANumberAfterADoubleReversal.java new file mode 100644 index 0000000..830cd56 --- /dev/null +++ b/src/ANumberAfterADoubleReversal.java @@ -0,0 +1,10 @@ +// https://leetcode.com/problems/a-number-after-a-double-reversal +// T: O(1) +// S: O(1) + +public class ANumberAfterADoubleReversal { + public boolean isSameAfterReversals(int num) { + if (num == 0) return true; + return num % 10 != 0; + } +} From cabc3193be96ae6e0130595f40595799162c4f88 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 13 May 2023 23:08:14 +0200 Subject: [PATCH 009/280] solves #2124: Check if All A's Appears Before All B's in java --- README.md | 2 +- src/CheckIfAllTheAsAppearBeforeAllTheBs.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/CheckIfAllTheAsAppearBeforeAllTheBs.java diff --git a/README.md b/README.md index cd1367f..9f030c1 100644 --- a/README.md +++ b/README.md @@ -703,7 +703,7 @@ | 2108 | [Find First Palindromic String in the Array](https://leetcode.com/problems/find-first-palindromic-string-in-the-array) | [![Java](assets/java.png)](src/FindFirstPalindromicStringInArray.java) | | | 2114 | [Maximum Number of Words Found in Sentences](https://leetcode.com/problems/maximum-number-of-words-found-in-sentences) | [![Java](assets/java.png)](src/MaximumNumberOfWordsFoundInSentences.java) | | | 2119 | [A Number After a Double Reversal](https://leetcode.com/problems/a-number-after-a-double-reversal) | [![Java](assets/java.png)](src/ANumberAfterADoubleReversal.java) | | -| 2124 | [Check if All A's Appears Before All B's](https://leetcode.com/problems/check-if-all-as-appears-before-all-bs) | | | +| 2124 | [Check if All A's Appears Before All B's](https://leetcode.com/problems/check-if-all-as-appears-before-all-bs) | [![Java](assets/java.png)](src/CheckIfAllTheAsAppearBeforeAllTheBs.java) | | | 2129 | [Capitalize the Title](https://leetcode.com/problems/capitalize-the-title) | | | | 2133 | [Check if Every Row and Column Contains All Numbers](https://leetcode.com/problems/check-if-every-row-and-column-contains-all-numbers) | | | | 2138 | [Divide a String Into Groups of Size k](https://leetcode.com/problems/divide-a-string-into-groups-of-size-k) | | | diff --git a/src/CheckIfAllTheAsAppearBeforeAllTheBs.java b/src/CheckIfAllTheAsAppearBeforeAllTheBs.java new file mode 100644 index 0000000..49ce502 --- /dev/null +++ b/src/CheckIfAllTheAsAppearBeforeAllTheBs.java @@ -0,0 +1,14 @@ +// https://leetcode.com/problems/check-if-all-as-appears-before-all-bs +// T: O(|s|) +// S: O(1) + +public class CheckIfAllTheAsAppearBeforeAllTheBs { + public boolean checkString(String s) { + boolean seenB = false; + for (int index = 0 ; index < s.length() ; index++) { + if (s.charAt(index) == 'b') seenB = true; + if (s.charAt(index) == 'a' && seenB) return false; + } + return true; + } +} From 7a244e9da9b6f055a58a5952a291ee26017d9be7 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 13 May 2023 23:15:50 +0200 Subject: [PATCH 010/280] solve #2129: Capitalize the Title in java --- README.md | 2 +- src/CapitalizeTheTitle.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/CapitalizeTheTitle.java diff --git a/README.md b/README.md index 9f030c1..ab435a3 100644 --- a/README.md +++ b/README.md @@ -704,7 +704,7 @@ | 2114 | [Maximum Number of Words Found in Sentences](https://leetcode.com/problems/maximum-number-of-words-found-in-sentences) | [![Java](assets/java.png)](src/MaximumNumberOfWordsFoundInSentences.java) | | | 2119 | [A Number After a Double Reversal](https://leetcode.com/problems/a-number-after-a-double-reversal) | [![Java](assets/java.png)](src/ANumberAfterADoubleReversal.java) | | | 2124 | [Check if All A's Appears Before All B's](https://leetcode.com/problems/check-if-all-as-appears-before-all-bs) | [![Java](assets/java.png)](src/CheckIfAllTheAsAppearBeforeAllTheBs.java) | | -| 2129 | [Capitalize the Title](https://leetcode.com/problems/capitalize-the-title) | | | +| 2129 | [Capitalize the Title](https://leetcode.com/problems/capitalize-the-title) | [![Java](assets/java.png)](src/CapitalizeTheTitle.java) | | | 2133 | [Check if Every Row and Column Contains All Numbers](https://leetcode.com/problems/check-if-every-row-and-column-contains-all-numbers) | | | | 2138 | [Divide a String Into Groups of Size k](https://leetcode.com/problems/divide-a-string-into-groups-of-size-k) | | | | 2144 | [Minimum Cost of Buying Candies With Discount](https://leetcode.com/problems/minimum-cost-of-buying-candies-with-discount) | | | diff --git a/src/CapitalizeTheTitle.java b/src/CapitalizeTheTitle.java new file mode 100644 index 0000000..3ec3e3b --- /dev/null +++ b/src/CapitalizeTheTitle.java @@ -0,0 +1,15 @@ +// https://leetcode.com/problems/capitalize-the-title +// T: O(|s|) +// S: O(|s|) + +public class CapitalizeTheTitle { + public String capitalizeTitle(String title) { + final StringBuilder result = new StringBuilder(); + final String[] words = title.split(" "); + for (String word : words) { + if (word.length() <= 2) result.append(word.toLowerCase()).append(' '); + else result.append(word.substring(0, 1).toUpperCase()).append(word.substring(1).toLowerCase()).append(' '); + } + return result.delete(result.length() - 1, result.length()).toString(); + } +} From 61be0392a7578b30fcd58da522f28ae3adafc675 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 13 May 2023 23:24:43 +0200 Subject: [PATCH 011/280] solves #2133: Check if Every Row and Column Contains All Numbers in java --- README.md | 2 +- ...eryRowAndEveryColumnContainAllNumbers.java | 41 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/CheckIfEveryRowAndEveryColumnContainAllNumbers.java diff --git a/README.md b/README.md index ab435a3..66726bf 100644 --- a/README.md +++ b/README.md @@ -705,7 +705,7 @@ | 2119 | [A Number After a Double Reversal](https://leetcode.com/problems/a-number-after-a-double-reversal) | [![Java](assets/java.png)](src/ANumberAfterADoubleReversal.java) | | | 2124 | [Check if All A's Appears Before All B's](https://leetcode.com/problems/check-if-all-as-appears-before-all-bs) | [![Java](assets/java.png)](src/CheckIfAllTheAsAppearBeforeAllTheBs.java) | | | 2129 | [Capitalize the Title](https://leetcode.com/problems/capitalize-the-title) | [![Java](assets/java.png)](src/CapitalizeTheTitle.java) | | -| 2133 | [Check if Every Row and Column Contains All Numbers](https://leetcode.com/problems/check-if-every-row-and-column-contains-all-numbers) | | | +| 2133 | [Check if Every Row and Column Contains All Numbers](https://leetcode.com/problems/check-if-every-row-and-column-contains-all-numbers) | [![Java](assets/java.png)](src/CheckIfEveryRowAndEveryColumnContainAllNumbers.java) | | | 2138 | [Divide a String Into Groups of Size k](https://leetcode.com/problems/divide-a-string-into-groups-of-size-k) | | | | 2144 | [Minimum Cost of Buying Candies With Discount](https://leetcode.com/problems/minimum-cost-of-buying-candies-with-discount) | | | | 2148 | [Count Elements With Strictly Smaller and Greater Elements](https://leetcode.com/problems/count-elements-with-strictly-smaller-and-greater-elements) | | | diff --git a/src/CheckIfEveryRowAndEveryColumnContainAllNumbers.java b/src/CheckIfEveryRowAndEveryColumnContainAllNumbers.java new file mode 100644 index 0000000..f7cbd82 --- /dev/null +++ b/src/CheckIfEveryRowAndEveryColumnContainAllNumbers.java @@ -0,0 +1,41 @@ +import java.util.HashSet; +import java.util.Set; + +public class CheckIfEveryRowAndEveryColumnContainAllNumbers { + private int n; + + public boolean checkValid(int[][] matrix) { + this.n = matrix.length; + return checkAllRows(matrix) && checkAllColumns(matrix); + } + + private boolean checkAllRows(int[][] matrix) { + for (int[] row : matrix) { + if (!isRowValid(row)) return false; + } + return true; + } + + private boolean isRowValid(int[] row) { + final Set numbers = new HashSet<>(); + for (int element: row) { + if (element <= 0 || element > n) return false; + if (numbers.contains(element)) return false; + numbers.add(element); + } + return true; + } + + private boolean checkAllColumns(int[][] matrix) { + for (int column = 0 ; column < n ; column++) { + final Set numbers = new HashSet<>(); + for (int row = 0 ; row < n ; row++) { + int element = matrix[row][column]; + if (element < 0 || element > n) return false; + if (numbers.contains(element)) return false; + numbers.add(element); + } + } + return true; + } +} From d7fde377bb2c2b42f00d30b71f06e7b6065e4924 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 13 May 2023 23:38:52 +0200 Subject: [PATCH 012/280] solves #2138: Divide a String Into Groups of Size k in java --- README.md | 2 +- src/DesignBrowserHistory.java | 3 +++ src/DivideTheStringIntoGroupsOfSizeK.java | 22 ++++++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/DivideTheStringIntoGroupsOfSizeK.java diff --git a/README.md b/README.md index 66726bf..944fac3 100644 --- a/README.md +++ b/README.md @@ -706,7 +706,7 @@ | 2124 | [Check if All A's Appears Before All B's](https://leetcode.com/problems/check-if-all-as-appears-before-all-bs) | [![Java](assets/java.png)](src/CheckIfAllTheAsAppearBeforeAllTheBs.java) | | | 2129 | [Capitalize the Title](https://leetcode.com/problems/capitalize-the-title) | [![Java](assets/java.png)](src/CapitalizeTheTitle.java) | | | 2133 | [Check if Every Row and Column Contains All Numbers](https://leetcode.com/problems/check-if-every-row-and-column-contains-all-numbers) | [![Java](assets/java.png)](src/CheckIfEveryRowAndEveryColumnContainAllNumbers.java) | | -| 2138 | [Divide a String Into Groups of Size k](https://leetcode.com/problems/divide-a-string-into-groups-of-size-k) | | | +| 2138 | [Divide a String Into Groups of Size k](https://leetcode.com/problems/divide-a-string-into-groups-of-size-k) | [![Java](assets/java.png)](src/DivideTheStringIntoGroupsOfSizeK.java) | | | 2144 | [Minimum Cost of Buying Candies With Discount](https://leetcode.com/problems/minimum-cost-of-buying-candies-with-discount) | | | | 2148 | [Count Elements With Strictly Smaller and Greater Elements](https://leetcode.com/problems/count-elements-with-strictly-smaller-and-greater-elements) | | | | 2154 | [Keep Multiplying Found Values by Two](https://leetcode.com/problems/keep-multiplying-found-values-by-two) | | | diff --git a/src/DesignBrowserHistory.java b/src/DesignBrowserHistory.java index ded6e65..4e1c946 100644 --- a/src/DesignBrowserHistory.java +++ b/src/DesignBrowserHistory.java @@ -1,3 +1,6 @@ +import java.util.ArrayList; +import java.util.List; + class BrowserHistory { private List history; private int ptr; diff --git a/src/DivideTheStringIntoGroupsOfSizeK.java b/src/DivideTheStringIntoGroupsOfSizeK.java new file mode 100644 index 0000000..9e4ee5a --- /dev/null +++ b/src/DivideTheStringIntoGroupsOfSizeK.java @@ -0,0 +1,22 @@ +// https://leetcode.com/problems/divide-a-string-into-groups-of-size-k +// T: O(s) +// S: O(s) + +public class DivideTheStringIntoGroupsOfSizeK { + public String[] divideString(String s, int k, char fill) { + final String filler = fill + ""; + final int groups = (int) Math.ceil((double) s.length() / k); + final String[] result = new String[groups]; + + for (int i = 0 ; i < groups ; i++) { + if (i == result.length - 1) { + if (s.length() - k * i < k) result[i] = s.substring(k * i) + filler.repeat(k - s.length() + k * i); + else result[i] = s.substring(k * i); + } else { + result[i] = s.substring(k * i, k * i + k); + } + } + + return result; + } +} From 0ee8b5aa1d12b69f8fcd8801a127865bd97753d6 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sun, 14 May 2023 00:08:40 +0200 Subject: [PATCH 013/280] solves #2180: Count Integers With Even Digit Sum in java --- README.md | 2 +- src/CountIntegersWithEvenDigitSum.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/CountIntegersWithEvenDigitSum.java diff --git a/README.md b/README.md index 944fac3..2b5d3e4 100644 --- a/README.md +++ b/README.md @@ -707,7 +707,7 @@ | 2129 | [Capitalize the Title](https://leetcode.com/problems/capitalize-the-title) | [![Java](assets/java.png)](src/CapitalizeTheTitle.java) | | | 2133 | [Check if Every Row and Column Contains All Numbers](https://leetcode.com/problems/check-if-every-row-and-column-contains-all-numbers) | [![Java](assets/java.png)](src/CheckIfEveryRowAndEveryColumnContainAllNumbers.java) | | | 2138 | [Divide a String Into Groups of Size k](https://leetcode.com/problems/divide-a-string-into-groups-of-size-k) | [![Java](assets/java.png)](src/DivideTheStringIntoGroupsOfSizeK.java) | | -| 2144 | [Minimum Cost of Buying Candies With Discount](https://leetcode.com/problems/minimum-cost-of-buying-candies-with-discount) | | | +| 2144 | [Minimum Cost of Buying Candies With Discount](https://leetcode.com/problems/minimum-cost-of-buying-candies-with-discount) | [![Java](assets/java.png)](src/CountIntegersWithEvenDigitSum.java) | | | 2148 | [Count Elements With Strictly Smaller and Greater Elements](https://leetcode.com/problems/count-elements-with-strictly-smaller-and-greater-elements) | | | | 2154 | [Keep Multiplying Found Values by Two](https://leetcode.com/problems/keep-multiplying-found-values-by-two) | | | | 2160 | [Minimum Sum of Four Digit Number After Splitting Digits](https://leetcode.com/problems/minimum-sum-of-four-digit-number-after-splitting-digits) | | | diff --git a/src/CountIntegersWithEvenDigitSum.java b/src/CountIntegersWithEvenDigitSum.java new file mode 100644 index 0000000..fd33346 --- /dev/null +++ b/src/CountIntegersWithEvenDigitSum.java @@ -0,0 +1,14 @@ +// https://leetcode.com/problems/count-integers-with-even-digit-sum +// T: O(1) +// S: O(1) + +public class CountIntegersWithEvenDigitSum { + public int countEven(int num) { + final int group = num / 10; + return 5 * group - 1 + (num % 10 + 1 + series(group)) / 2; + } + + private int series(int group) { + return (group % 10 + (group % 100) / 10 + (group % 1000) / 100 + 1) % 2; + } +} From b3ea3b0ac5569ae1c8b4b3e5de19033c9c02ef6e Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sun, 14 May 2023 15:28:13 +0200 Subject: [PATCH 014/280] solves #2180 Count Integers With Even Digit Sum in java --- README.md | 4 ++-- src/MinimumCostOfBuyingCandiesWithDiscount.java | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 src/MinimumCostOfBuyingCandiesWithDiscount.java diff --git a/README.md b/README.md index 2b5d3e4..c9d25ea 100644 --- a/README.md +++ b/README.md @@ -707,14 +707,14 @@ | 2129 | [Capitalize the Title](https://leetcode.com/problems/capitalize-the-title) | [![Java](assets/java.png)](src/CapitalizeTheTitle.java) | | | 2133 | [Check if Every Row and Column Contains All Numbers](https://leetcode.com/problems/check-if-every-row-and-column-contains-all-numbers) | [![Java](assets/java.png)](src/CheckIfEveryRowAndEveryColumnContainAllNumbers.java) | | | 2138 | [Divide a String Into Groups of Size k](https://leetcode.com/problems/divide-a-string-into-groups-of-size-k) | [![Java](assets/java.png)](src/DivideTheStringIntoGroupsOfSizeK.java) | | -| 2144 | [Minimum Cost of Buying Candies With Discount](https://leetcode.com/problems/minimum-cost-of-buying-candies-with-discount) | [![Java](assets/java.png)](src/CountIntegersWithEvenDigitSum.java) | | +| 2144 | [Minimum Cost of Buying Candies With Discount](https://leetcode.com/problems/minimum-cost-of-buying-candies-with-discount) | [![Java](assets/java.png)](src/MinimumCostOfBuyingCandiesWithDiscount.java) | | | 2148 | [Count Elements With Strictly Smaller and Greater Elements](https://leetcode.com/problems/count-elements-with-strictly-smaller-and-greater-elements) | | | | 2154 | [Keep Multiplying Found Values by Two](https://leetcode.com/problems/keep-multiplying-found-values-by-two) | | | | 2160 | [Minimum Sum of Four Digit Number After Splitting Digits](https://leetcode.com/problems/minimum-sum-of-four-digit-number-after-splitting-digits) | | | | 2164 | [Sort Even and Odd Indices Independently](https://leetcode.com/problems/sort-even-and-odd-indices-independently) | | | | 2169 | [Count Operations to Obtain Zero](https://leetcode.com/problems/count-operations-to-obtain-zero) | | | | 2176 | [Count Equal and Divisible Pairs in an Array](https://leetcode.com/problems/count-equal-and-divisible-pairs-in-an-array) | | | -| 2180 | [Count Integers With Even Digit Sum](https://leetcode.com/problems/count-integers-with-even-digit-sum) | | | +| 2180 | [Count Integers With Even Digit Sum](https://leetcode.com/problems/count-integers-with-even-digit-sum) | [![Java](assets/java.png)](src/CountIntegersWithEvenDigitSum.java) | | | 2185 | [Counting Words With a Given Prefix](https://leetcode.com/problems/counting-words-with-a-given-prefix) | | | | 2190 | [Most Frequent Number Following Key In an Array](https://leetcode.com/problems/most-frequent-number-following-key-in-an-array) | | | | 2194 | [Cells in a Range on an Excel Sheet](https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet) | | | diff --git a/src/MinimumCostOfBuyingCandiesWithDiscount.java b/src/MinimumCostOfBuyingCandiesWithDiscount.java new file mode 100644 index 0000000..61036ca --- /dev/null +++ b/src/MinimumCostOfBuyingCandiesWithDiscount.java @@ -0,0 +1,16 @@ +// https://leetcode.com/problems/minimum-cost-of-buying-candies-with-discount +// T: O(n log(n)) +// S: O(log(n)) + +import java.util.Arrays; + +public class MinimumCostOfBuyingCandiesWithDiscount { + public int minimumCost(int[] cost) { + Arrays.sort(cost); + int totalCost = 0; + for (int index = cost.length - 1 ; index >= 0 ; index -= 3) { + totalCost += cost[index] + (index - 1 >= 0 ? cost[index - 1] : 0); + } + return totalCost; + } +} From 5ac25c0170ddb8602feb260154b27406a82e2460 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sun, 14 May 2023 15:48:51 +0200 Subject: [PATCH 015/280] solves #2154: Keep Multiplying Found Values by Two in java --- README.md | 4 ++-- ...WithStrictlySmallerAndGreaterElements.java | 16 +++++++++++++ src/KeepMultiplyingFoundValuesByTwo.java | 24 +++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 src/CountElementsWithStrictlySmallerAndGreaterElements.java create mode 100644 src/KeepMultiplyingFoundValuesByTwo.java diff --git a/README.md b/README.md index c9d25ea..0acf8d9 100644 --- a/README.md +++ b/README.md @@ -708,8 +708,8 @@ | 2133 | [Check if Every Row and Column Contains All Numbers](https://leetcode.com/problems/check-if-every-row-and-column-contains-all-numbers) | [![Java](assets/java.png)](src/CheckIfEveryRowAndEveryColumnContainAllNumbers.java) | | | 2138 | [Divide a String Into Groups of Size k](https://leetcode.com/problems/divide-a-string-into-groups-of-size-k) | [![Java](assets/java.png)](src/DivideTheStringIntoGroupsOfSizeK.java) | | | 2144 | [Minimum Cost of Buying Candies With Discount](https://leetcode.com/problems/minimum-cost-of-buying-candies-with-discount) | [![Java](assets/java.png)](src/MinimumCostOfBuyingCandiesWithDiscount.java) | | -| 2148 | [Count Elements With Strictly Smaller and Greater Elements](https://leetcode.com/problems/count-elements-with-strictly-smaller-and-greater-elements) | | | -| 2154 | [Keep Multiplying Found Values by Two](https://leetcode.com/problems/keep-multiplying-found-values-by-two) | | | +| 2148 | [Count Elements With Strictly Smaller and Greater Elements](https://leetcode.com/problems/count-elements-with-strictly-smaller-and-greater-elements) | [![Java](assets/java.png)](src/CountElementsWithStrictlySmallerAndGreaterElements.java) | | +| 2154 | [Keep Multiplying Found Values by Two](https://leetcode.com/problems/keep-multiplying-found-values-by-two) | [![Java](assets/java.png)](src/KeepMultiplyingFoundValuesByTwo.java) | | | 2160 | [Minimum Sum of Four Digit Number After Splitting Digits](https://leetcode.com/problems/minimum-sum-of-four-digit-number-after-splitting-digits) | | | | 2164 | [Sort Even and Odd Indices Independently](https://leetcode.com/problems/sort-even-and-odd-indices-independently) | | | | 2169 | [Count Operations to Obtain Zero](https://leetcode.com/problems/count-operations-to-obtain-zero) | | | diff --git a/src/CountElementsWithStrictlySmallerAndGreaterElements.java b/src/CountElementsWithStrictlySmallerAndGreaterElements.java new file mode 100644 index 0000000..da0300f --- /dev/null +++ b/src/CountElementsWithStrictlySmallerAndGreaterElements.java @@ -0,0 +1,16 @@ +// https://leetcode.com/problems/count-elements-with-strictly-smaller-and-greater-elements +// T: O(n log(n)) +// S: O(log(n)) + +import java.util.Arrays; + +public class CountElementsWithStrictlySmallerAndGreaterElements { + public int countElements(int[] nums) { + Arrays.sort(nums); + int count = 0; + for (int index = 1 ; index < nums.length - 1 ; index++) { + if (nums[0] != nums[index] && nums[index] != nums[nums.length - 1]) count++; + } + return count; + } +} diff --git a/src/KeepMultiplyingFoundValuesByTwo.java b/src/KeepMultiplyingFoundValuesByTwo.java new file mode 100644 index 0000000..7bfd19b --- /dev/null +++ b/src/KeepMultiplyingFoundValuesByTwo.java @@ -0,0 +1,24 @@ +// https://leetcode.com/problems/keep-multiplying-found-values-by-two +// T: O(N) +// S: O(N) + +import java.util.HashSet; +import java.util.Set; + +public class KeepMultiplyingFoundValuesByTwo { + public int findFinalValue(int[] nums, int original) { + final Set numbers = setFrom(nums); + while (numbers.contains(original)) { + original *= 2; + } + return original; + } + + private Set setFrom(int[] numbers) { + final Set set = new HashSet<>(); + for (int element : numbers) { + set.add(element); + } + return set; + } +} From 8604837d0c4e70ca487991df92cb6a935c7014a1 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sun, 14 May 2023 16:29:59 +0200 Subject: [PATCH 016/280] solves #2164: Sort Even and Odd Indices Independently in java --- README.md | 4 +-- ...OfFourDigitNumberAfterSplittingDigits.java | 23 +++++++++++++++ src/SortEvenAndOddIndicesIndependently.java | 28 +++++++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 src/MinimumSumOfFourDigitNumberAfterSplittingDigits.java create mode 100644 src/SortEvenAndOddIndicesIndependently.java diff --git a/README.md b/README.md index 0acf8d9..f0eb9af 100644 --- a/README.md +++ b/README.md @@ -710,8 +710,8 @@ | 2144 | [Minimum Cost of Buying Candies With Discount](https://leetcode.com/problems/minimum-cost-of-buying-candies-with-discount) | [![Java](assets/java.png)](src/MinimumCostOfBuyingCandiesWithDiscount.java) | | | 2148 | [Count Elements With Strictly Smaller and Greater Elements](https://leetcode.com/problems/count-elements-with-strictly-smaller-and-greater-elements) | [![Java](assets/java.png)](src/CountElementsWithStrictlySmallerAndGreaterElements.java) | | | 2154 | [Keep Multiplying Found Values by Two](https://leetcode.com/problems/keep-multiplying-found-values-by-two) | [![Java](assets/java.png)](src/KeepMultiplyingFoundValuesByTwo.java) | | -| 2160 | [Minimum Sum of Four Digit Number After Splitting Digits](https://leetcode.com/problems/minimum-sum-of-four-digit-number-after-splitting-digits) | | | -| 2164 | [Sort Even and Odd Indices Independently](https://leetcode.com/problems/sort-even-and-odd-indices-independently) | | | +| 2160 | [Minimum Sum of Four Digit Number After Splitting Digits](https://leetcode.com/problems/minimum-sum-of-four-digit-number-after-splitting-digits) | [![Java](assets/java.png)](src/MinimumSumOfFourDigitNumberAfterSplittingDigits.java) | | +| 2164 | [Sort Even and Odd Indices Independently](https://leetcode.com/problems/sort-even-and-odd-indices-independently) | [![Java](assets/java.png)](src/SortEvenAndOddIndicesIndependently.java) | | | 2169 | [Count Operations to Obtain Zero](https://leetcode.com/problems/count-operations-to-obtain-zero) | | | | 2176 | [Count Equal and Divisible Pairs in an Array](https://leetcode.com/problems/count-equal-and-divisible-pairs-in-an-array) | | | | 2180 | [Count Integers With Even Digit Sum](https://leetcode.com/problems/count-integers-with-even-digit-sum) | [![Java](assets/java.png)](src/CountIntegersWithEvenDigitSum.java) | | diff --git a/src/MinimumSumOfFourDigitNumberAfterSplittingDigits.java b/src/MinimumSumOfFourDigitNumberAfterSplittingDigits.java new file mode 100644 index 0000000..faaef89 --- /dev/null +++ b/src/MinimumSumOfFourDigitNumberAfterSplittingDigits.java @@ -0,0 +1,23 @@ +// https://leetcode.com/problems/minimum-sum-of-four-digit-number-after-splitting-digits +// T: O(1) +// S: O(1) + +import java.util.Arrays; + +public class MinimumSumOfFourDigitNumberAfterSplittingDigits { + public int minimumSum(int num) { + final int digit1 = num / 1000; + final int digit2 = (num / 100) % 10; + final int digit3 = (num / 10) % 10; + final int digit4 = num % 10; + + final int[] digits = { digit1, digit2, digit3, digit4 }; + Arrays.sort(digits); + + return toNumber(digits[0], digits[2]) + toNumber(digits[1], digits[3]); + } + + private int toNumber(int a, int b) { + return 10 * a + b; + } +} diff --git a/src/SortEvenAndOddIndicesIndependently.java b/src/SortEvenAndOddIndicesIndependently.java new file mode 100644 index 0000000..a0a695a --- /dev/null +++ b/src/SortEvenAndOddIndicesIndependently.java @@ -0,0 +1,28 @@ +// https://leetcode.com/problems/sort-even-and-odd-indices-independently +// T: O(n log(n)) +// S: O(n) + +import java.util.Arrays; +import java.util.Comparator; + +public class SortEvenAndOddIndicesIndependently { + public int[] sortEvenOdd(int[] nums) { + final int[] even = new int[(nums.length + 1) / 2]; + final Integer[] odd = new Integer[nums.length / 2]; + + for (int i = 0 ; i < nums.length ; i++) { + if (i % 2 == 0) even[i / 2] = nums[i]; + else odd[i / 2] = nums[i]; + } + + Arrays.sort(even); + Arrays.sort(odd, Comparator.reverseOrder()); + + for (int i = 0 ; i < nums.length ; i++) { + if (i % 2 == 0) nums[i] = even[i / 2]; + else nums[i] = odd[i / 2]; + } + + return nums; + } +} From 66cfb13c9d9d086ef9231e68a8ad24ac241ae968 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sun, 14 May 2023 16:44:26 +0200 Subject: [PATCH 017/280] solves #2169: Count Operations to Obtain Zero in java --- README.md | 2 +- src/CountOperationsToObtainZero.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/CountOperationsToObtainZero.java diff --git a/README.md b/README.md index f0eb9af..5ad6e8f 100644 --- a/README.md +++ b/README.md @@ -712,7 +712,7 @@ | 2154 | [Keep Multiplying Found Values by Two](https://leetcode.com/problems/keep-multiplying-found-values-by-two) | [![Java](assets/java.png)](src/KeepMultiplyingFoundValuesByTwo.java) | | | 2160 | [Minimum Sum of Four Digit Number After Splitting Digits](https://leetcode.com/problems/minimum-sum-of-four-digit-number-after-splitting-digits) | [![Java](assets/java.png)](src/MinimumSumOfFourDigitNumberAfterSplittingDigits.java) | | | 2164 | [Sort Even and Odd Indices Independently](https://leetcode.com/problems/sort-even-and-odd-indices-independently) | [![Java](assets/java.png)](src/SortEvenAndOddIndicesIndependently.java) | | -| 2169 | [Count Operations to Obtain Zero](https://leetcode.com/problems/count-operations-to-obtain-zero) | | | +| 2169 | [Count Operations to Obtain Zero](https://leetcode.com/problems/count-operations-to-obtain-zero) | [![Java](assets/java.png)](src/CountOperationsToObtainZero.java) | | | 2176 | [Count Equal and Divisible Pairs in an Array](https://leetcode.com/problems/count-equal-and-divisible-pairs-in-an-array) | | | | 2180 | [Count Integers With Even Digit Sum](https://leetcode.com/problems/count-integers-with-even-digit-sum) | [![Java](assets/java.png)](src/CountIntegersWithEvenDigitSum.java) | | | 2185 | [Counting Words With a Given Prefix](https://leetcode.com/problems/counting-words-with-a-given-prefix) | | | diff --git a/src/CountOperationsToObtainZero.java b/src/CountOperationsToObtainZero.java new file mode 100644 index 0000000..9d0109c --- /dev/null +++ b/src/CountOperationsToObtainZero.java @@ -0,0 +1,16 @@ +// https://leetcode.com/problems/count-operations-to-obtain-zero +// T: O(max(a, b)) +// S: O(1) + +public class CountOperationsToObtainZero { + public int countOperations(int num1, int num2) { + int operations = 0; + while (num1 != 0 && num2 != 0) { + operations++; + if (num1 >= num2) { + num1 -= num2; + } else num2 -= num1; + } + return operations; + } +} From 0c3b8945d738c79a0b2db28bca2f31cdfd73ed67 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sun, 14 May 2023 16:52:36 +0200 Subject: [PATCH 018/280] solves #2176: Count Equal and Divisible Pairs in an Array in java --- README.md | 2 +- src/CountEqualAndDivisiblePairsInAnArray.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/CountEqualAndDivisiblePairsInAnArray.java diff --git a/README.md b/README.md index 5ad6e8f..ea4c138 100644 --- a/README.md +++ b/README.md @@ -713,7 +713,7 @@ | 2160 | [Minimum Sum of Four Digit Number After Splitting Digits](https://leetcode.com/problems/minimum-sum-of-four-digit-number-after-splitting-digits) | [![Java](assets/java.png)](src/MinimumSumOfFourDigitNumberAfterSplittingDigits.java) | | | 2164 | [Sort Even and Odd Indices Independently](https://leetcode.com/problems/sort-even-and-odd-indices-independently) | [![Java](assets/java.png)](src/SortEvenAndOddIndicesIndependently.java) | | | 2169 | [Count Operations to Obtain Zero](https://leetcode.com/problems/count-operations-to-obtain-zero) | [![Java](assets/java.png)](src/CountOperationsToObtainZero.java) | | -| 2176 | [Count Equal and Divisible Pairs in an Array](https://leetcode.com/problems/count-equal-and-divisible-pairs-in-an-array) | | | +| 2176 | [Count Equal and Divisible Pairs in an Array](https://leetcode.com/problems/count-equal-and-divisible-pairs-in-an-array) | [![Java](assets/java.png)](src/CountEqualAndDivisiblePairsInAnArray.java) | | | 2180 | [Count Integers With Even Digit Sum](https://leetcode.com/problems/count-integers-with-even-digit-sum) | [![Java](assets/java.png)](src/CountIntegersWithEvenDigitSum.java) | | | 2185 | [Counting Words With a Given Prefix](https://leetcode.com/problems/counting-words-with-a-given-prefix) | | | | 2190 | [Most Frequent Number Following Key In an Array](https://leetcode.com/problems/most-frequent-number-following-key-in-an-array) | | | diff --git a/src/CountEqualAndDivisiblePairsInAnArray.java b/src/CountEqualAndDivisiblePairsInAnArray.java new file mode 100644 index 0000000..37cd998 --- /dev/null +++ b/src/CountEqualAndDivisiblePairsInAnArray.java @@ -0,0 +1,15 @@ +// https://leetcode.com/problems/count-equal-and-divisible-pairs-in-an-array +// T: O(n^2) +// S: O(1) + +public class CountEqualAndDivisiblePairsInAnArray { + public int countPairs(int[] nums, int k) { + int pairs = 0; + for (int i = 0 ; i < nums.length ; i ++) { + for (int j = i + 1 ; j < nums.length ; j++) { + if (nums[i] == nums[j] && (i * j) % k == 0) pairs++; + } + } + return pairs; + } +} From 2f7e84802c66d1f181fb4722473a5748e5a0db67 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sun, 14 May 2023 16:54:57 +0200 Subject: [PATCH 019/280] solves #2185: Counting Words With a Given Prefix in java --- README.md | 2 +- src/CountingWordsWithAGivenPrefix.java | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/CountingWordsWithAGivenPrefix.java diff --git a/README.md b/README.md index ea4c138..936a41c 100644 --- a/README.md +++ b/README.md @@ -715,7 +715,7 @@ | 2169 | [Count Operations to Obtain Zero](https://leetcode.com/problems/count-operations-to-obtain-zero) | [![Java](assets/java.png)](src/CountOperationsToObtainZero.java) | | | 2176 | [Count Equal and Divisible Pairs in an Array](https://leetcode.com/problems/count-equal-and-divisible-pairs-in-an-array) | [![Java](assets/java.png)](src/CountEqualAndDivisiblePairsInAnArray.java) | | | 2180 | [Count Integers With Even Digit Sum](https://leetcode.com/problems/count-integers-with-even-digit-sum) | [![Java](assets/java.png)](src/CountIntegersWithEvenDigitSum.java) | | -| 2185 | [Counting Words With a Given Prefix](https://leetcode.com/problems/counting-words-with-a-given-prefix) | | | +| 2185 | [Counting Words With a Given Prefix](https://leetcode.com/problems/counting-words-with-a-given-prefix) | [![Java](assets/java.png)](src/CountingWordsWithAGivenPrefix.java) | | | 2190 | [Most Frequent Number Following Key In an Array](https://leetcode.com/problems/most-frequent-number-following-key-in-an-array) | | | | 2194 | [Cells in a Range on an Excel Sheet](https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet) | | | | 2200 | [Find All K-Distant Indices in an Array](https://leetcode.com/problems/find-all-k-distant-indices-in-an-array) | | | diff --git a/src/CountingWordsWithAGivenPrefix.java b/src/CountingWordsWithAGivenPrefix.java new file mode 100644 index 0000000..613d1dc --- /dev/null +++ b/src/CountingWordsWithAGivenPrefix.java @@ -0,0 +1,9 @@ +public class CountingWordsWithAGivenPrefix { + public int prefixCount(String[] words, String prefix) { + int count = 0; + for (String word : words) { + if (word.startsWith(prefix)) count++; + } + return count; + } +} From 1cdbba7444b64a53fbe6026d4520a159ab705009 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sun, 14 May 2023 17:13:03 +0200 Subject: [PATCH 020/280] solves #2190: Most Frequent Number Following Key In an Array in java --- README.md | 2 +- ...stFrequentNumberFollowingKeyInAnArray.java | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/MostFrequentNumberFollowingKeyInAnArray.java diff --git a/README.md b/README.md index 936a41c..7b1d0c9 100644 --- a/README.md +++ b/README.md @@ -716,7 +716,7 @@ | 2176 | [Count Equal and Divisible Pairs in an Array](https://leetcode.com/problems/count-equal-and-divisible-pairs-in-an-array) | [![Java](assets/java.png)](src/CountEqualAndDivisiblePairsInAnArray.java) | | | 2180 | [Count Integers With Even Digit Sum](https://leetcode.com/problems/count-integers-with-even-digit-sum) | [![Java](assets/java.png)](src/CountIntegersWithEvenDigitSum.java) | | | 2185 | [Counting Words With a Given Prefix](https://leetcode.com/problems/counting-words-with-a-given-prefix) | [![Java](assets/java.png)](src/CountingWordsWithAGivenPrefix.java) | | -| 2190 | [Most Frequent Number Following Key In an Array](https://leetcode.com/problems/most-frequent-number-following-key-in-an-array) | | | +| 2190 | [Most Frequent Number Following Key In an Array](https://leetcode.com/problems/most-frequent-number-following-key-in-an-array) | [![Java](assets/java.png)](src/MostFrequentNumberFollowingKeyInAnArray.java) | | | 2194 | [Cells in a Range on an Excel Sheet](https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet) | | | | 2200 | [Find All K-Distant Indices in an Array](https://leetcode.com/problems/find-all-k-distant-indices-in-an-array) | | | | 2206 | [Divide Array Into Equal Pairs](https://leetcode.com/problems/divide-array-into-equal-pairs) | | | diff --git a/src/MostFrequentNumberFollowingKeyInAnArray.java b/src/MostFrequentNumberFollowingKeyInAnArray.java new file mode 100644 index 0000000..040dbfd --- /dev/null +++ b/src/MostFrequentNumberFollowingKeyInAnArray.java @@ -0,0 +1,35 @@ +// https://leetcode.com/problems/most-frequent-number-following-key-in-an-array +// T: O(N) +// S: O(N) + +import java.util.HashMap; +import java.util.Map; + +public class MostFrequentNumberFollowingKeyInAnArray { + public int mostFrequent(int[] nums, int key) { + final Map targetToFrequency = getTargetFrequencies(nums, key); + return mostFrequentTarget(targetToFrequency); + } + + private Map getTargetFrequencies(int[] array, int key) { + final Map result = new HashMap<>(); + for (int index = 0 ; index < array.length - 1 ; index++) { + if (array[index] == key) { + int target = array[index + 1]; + result.put(target, result.getOrDefault(target, 0) + 1); + } + } + return result; + } + + private int mostFrequentTarget(final Map frequencies) { + int target = -1, maxFrequency = -1; + for (Map.Entry entry : frequencies.entrySet()) { + if (entry.getValue() > maxFrequency) { + maxFrequency = entry.getValue(); + target = entry.getKey(); + } + } + return target; + } +} From 4ee89162b029b7a71bbd498f20d9159d0283d3b9 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sun, 14 May 2023 17:19:58 +0200 Subject: [PATCH 021/280] solves #2194: Cells in a Range on an Excel Sheet in java --- README.md | 2 +- src/CellsInARangeOnAnExcelSheet.java | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/CellsInARangeOnAnExcelSheet.java diff --git a/README.md b/README.md index 7b1d0c9..a91e716 100644 --- a/README.md +++ b/README.md @@ -717,7 +717,7 @@ | 2180 | [Count Integers With Even Digit Sum](https://leetcode.com/problems/count-integers-with-even-digit-sum) | [![Java](assets/java.png)](src/CountIntegersWithEvenDigitSum.java) | | | 2185 | [Counting Words With a Given Prefix](https://leetcode.com/problems/counting-words-with-a-given-prefix) | [![Java](assets/java.png)](src/CountingWordsWithAGivenPrefix.java) | | | 2190 | [Most Frequent Number Following Key In an Array](https://leetcode.com/problems/most-frequent-number-following-key-in-an-array) | [![Java](assets/java.png)](src/MostFrequentNumberFollowingKeyInAnArray.java) | | -| 2194 | [Cells in a Range on an Excel Sheet](https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet) | | | +| 2194 | [Cells in a Range on an Excel Sheet](https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet) | [![Java](assets/java.png)](src/CellsInARangeOnAnExcelSheet.java) | | | 2200 | [Find All K-Distant Indices in an Array](https://leetcode.com/problems/find-all-k-distant-indices-in-an-array) | | | | 2206 | [Divide Array Into Equal Pairs](https://leetcode.com/problems/divide-array-into-equal-pairs) | | | | 2210 | [Count Hills and Valleys in an Array](https://leetcode.com/problems/count-hills-and-valleys-in-an-array) | | | diff --git a/src/CellsInARangeOnAnExcelSheet.java b/src/CellsInARangeOnAnExcelSheet.java new file mode 100644 index 0000000..cd7f813 --- /dev/null +++ b/src/CellsInARangeOnAnExcelSheet.java @@ -0,0 +1,25 @@ +// https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet +// T: O(1) +// S: O(1) + +import java.util.ArrayList; +import java.util.List; + +public class CellsInARangeOnAnExcelSheet { + public List cellsInRange(String s) { + final char column1 = s.charAt(0); + final char column2 = s.charAt(3); + final int row1 = s.charAt(1) - '0'; + final int row2 = s.charAt(4) - '0'; + + final List result = new ArrayList<>(); + + for (char column = column1 ; column <= column2 ; column++) { + for (int row = row1 ; row <= row2 ; row++) { + result.add((column + "") + row); + } + } + + return result; + } +} From c137d69e0d99edb9e47f695a5ef39b26dce604f0 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sun, 14 May 2023 17:27:50 +0200 Subject: [PATCH 022/280] solves #2200: Find All K-Distant Indices in an Array in java --- README.md | 2 +- src/FindAllKDistantIndicesInAnArray.java | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/FindAllKDistantIndicesInAnArray.java diff --git a/README.md b/README.md index a91e716..e91239b 100644 --- a/README.md +++ b/README.md @@ -718,7 +718,7 @@ | 2185 | [Counting Words With a Given Prefix](https://leetcode.com/problems/counting-words-with-a-given-prefix) | [![Java](assets/java.png)](src/CountingWordsWithAGivenPrefix.java) | | | 2190 | [Most Frequent Number Following Key In an Array](https://leetcode.com/problems/most-frequent-number-following-key-in-an-array) | [![Java](assets/java.png)](src/MostFrequentNumberFollowingKeyInAnArray.java) | | | 2194 | [Cells in a Range on an Excel Sheet](https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet) | [![Java](assets/java.png)](src/CellsInARangeOnAnExcelSheet.java) | | -| 2200 | [Find All K-Distant Indices in an Array](https://leetcode.com/problems/find-all-k-distant-indices-in-an-array) | | | +| 2200 | [Find All K-Distant Indices in an Array](https://leetcode.com/problems/find-all-k-distant-indices-in-an-array) | [![Java](assets/java.png)](src/FindAllKDistantIndicesInAnArray.java) | | | 2206 | [Divide Array Into Equal Pairs](https://leetcode.com/problems/divide-array-into-equal-pairs) | | | | 2210 | [Count Hills and Valleys in an Array](https://leetcode.com/problems/count-hills-and-valleys-in-an-array) | | | | 2215 | [Find the Difference of Two Arrays](https://leetcode.com/problems/find-the-difference-of-two-arrays) | | | diff --git a/src/FindAllKDistantIndicesInAnArray.java b/src/FindAllKDistantIndicesInAnArray.java new file mode 100644 index 0000000..360df96 --- /dev/null +++ b/src/FindAllKDistantIndicesInAnArray.java @@ -0,0 +1,24 @@ +// https://leetcode.com/problems/find-all-k-distant-indices-in-an-array +// T: O(N) +// S: O(N) + +import java.util.ArrayList; +import java.util.List; + +public class FindAllKDistantIndicesInAnArray { + public List findKDistantIndices(int[] array, int key, int k) { + final List result = new ArrayList<>(); + + for (int index = 0 ; index < array.length ; index++) { + if (array[index] == key) { + int startIndex = Math.max(result.isEmpty() ? 0 : result.get(result.size() - 1) + 1, index - k); + int endIndex = Math.min(index + k, array.length - 1); + for (int i = startIndex ; i <= endIndex ; i++) { + result.add(i); + } + } + } + + return result; + } +} From a5916d1ad1bd976bcf28e78fb2753cb6b3e40fa5 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sun, 14 May 2023 17:36:47 +0200 Subject: [PATCH 023/280] solves #2206: Divide Array Into Equal Pairs in java --- README.md | 2 +- src/DivideArrayIntoEqualPairs.java | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/DivideArrayIntoEqualPairs.java diff --git a/README.md b/README.md index e91239b..14722f9 100644 --- a/README.md +++ b/README.md @@ -719,7 +719,7 @@ | 2190 | [Most Frequent Number Following Key In an Array](https://leetcode.com/problems/most-frequent-number-following-key-in-an-array) | [![Java](assets/java.png)](src/MostFrequentNumberFollowingKeyInAnArray.java) | | | 2194 | [Cells in a Range on an Excel Sheet](https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet) | [![Java](assets/java.png)](src/CellsInARangeOnAnExcelSheet.java) | | | 2200 | [Find All K-Distant Indices in an Array](https://leetcode.com/problems/find-all-k-distant-indices-in-an-array) | [![Java](assets/java.png)](src/FindAllKDistantIndicesInAnArray.java) | | -| 2206 | [Divide Array Into Equal Pairs](https://leetcode.com/problems/divide-array-into-equal-pairs) | | | +| 2206 | [Divide Array Into Equal Pairs](https://leetcode.com/problems/divide-array-into-equal-pairs) | [![Java](assets/java.png)](src/DivideArrayIntoEqualPairs.java) | | | 2210 | [Count Hills and Valleys in an Array](https://leetcode.com/problems/count-hills-and-valleys-in-an-array) | | | | 2215 | [Find the Difference of Two Arrays](https://leetcode.com/problems/find-the-difference-of-two-arrays) | | | | 2220 | [Minimum Bit Flips to Convert Number](https://leetcode.com/problems/minimum-bit-flips-to-convert-number) | | | diff --git a/src/DivideArrayIntoEqualPairs.java b/src/DivideArrayIntoEqualPairs.java new file mode 100644 index 0000000..0d75bfa --- /dev/null +++ b/src/DivideArrayIntoEqualPairs.java @@ -0,0 +1,28 @@ +// https://leetcode.com/problems/divide-array-into-equal-pairs +// T: O(N) +// S: O(N) + +import java.util.HashMap; +import java.util.Map; + +public class DivideArrayIntoEqualPairs { + public static boolean divideArray(int[] array) { + final Map frequencies = getFrequencies(array); + return allFrequenciesAreEven(frequencies); + } + + private static boolean allFrequenciesAreEven(Map frequencies) { + for (int frequency : frequencies.values()) { + if (frequency % 2 == 1) return false; + } + return true; + } + + private static Map getFrequencies(int[] array) { + final Map result = new HashMap<>(); + for (int element : array) { + result.put(element, result.getOrDefault(element, 0) + 1); + } + return result; + } +} From 655e0e6edabba8c3cc61c5cd7f78e1ed664a6a36 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sun, 14 May 2023 17:59:08 +0200 Subject: [PATCH 024/280] solves #2210: Count Hills and Valleys in an Array in java --- README.md | 2 +- src/CountHillsAndValleysInAnArray.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/CountHillsAndValleysInAnArray.java diff --git a/README.md b/README.md index 14722f9..dcf7b32 100644 --- a/README.md +++ b/README.md @@ -720,7 +720,7 @@ | 2194 | [Cells in a Range on an Excel Sheet](https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet) | [![Java](assets/java.png)](src/CellsInARangeOnAnExcelSheet.java) | | | 2200 | [Find All K-Distant Indices in an Array](https://leetcode.com/problems/find-all-k-distant-indices-in-an-array) | [![Java](assets/java.png)](src/FindAllKDistantIndicesInAnArray.java) | | | 2206 | [Divide Array Into Equal Pairs](https://leetcode.com/problems/divide-array-into-equal-pairs) | [![Java](assets/java.png)](src/DivideArrayIntoEqualPairs.java) | | -| 2210 | [Count Hills and Valleys in an Array](https://leetcode.com/problems/count-hills-and-valleys-in-an-array) | | | +| 2210 | [Count Hills and Valleys in an Array](https://leetcode.com/problems/count-hills-and-valleys-in-an-array) | [![Java](assets/java.png)](src/CountHillsAndValleysInAnArray.java) | | | 2215 | [Find the Difference of Two Arrays](https://leetcode.com/problems/find-the-difference-of-two-arrays) | | | | 2220 | [Minimum Bit Flips to Convert Number](https://leetcode.com/problems/minimum-bit-flips-to-convert-number) | | | | 2224 | [Minimum Number of Operations to Convert Time](https://leetcode.com/problems/minimum-number-of-operations-to-convert-time) | | | diff --git a/src/CountHillsAndValleysInAnArray.java b/src/CountHillsAndValleysInAnArray.java new file mode 100644 index 0000000..7744a5e --- /dev/null +++ b/src/CountHillsAndValleysInAnArray.java @@ -0,0 +1,14 @@ +// https://leetcode.com/problems/count-hills-and-valleys-in-an-array + +public class CountHillsAndValleysInAnArray { + public int countHillValley(int[] array) { + int result = 0, left = array[0]; + for (int index = 1 ; index < array.length - 1; index++) { + if ((left < array[index] && array[index] > array[index + 1]) || (left > array[index] && array[index] < array[index + 1])) { + result++; + left = array[index]; + } + } + return result; + } +} From 653593fa1bc4ad5040621d3ea1707bcd184a88d4 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sun, 14 May 2023 18:06:47 +0200 Subject: [PATCH 025/280] solves #2215: Find the Difference of Two Arrays in java --- README.md | 2 +- src/FindTheDifferenceOfTwoArrays.java | 35 +++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/FindTheDifferenceOfTwoArrays.java diff --git a/README.md b/README.md index dcf7b32..b2f3f2d 100644 --- a/README.md +++ b/README.md @@ -721,7 +721,7 @@ | 2200 | [Find All K-Distant Indices in an Array](https://leetcode.com/problems/find-all-k-distant-indices-in-an-array) | [![Java](assets/java.png)](src/FindAllKDistantIndicesInAnArray.java) | | | 2206 | [Divide Array Into Equal Pairs](https://leetcode.com/problems/divide-array-into-equal-pairs) | [![Java](assets/java.png)](src/DivideArrayIntoEqualPairs.java) | | | 2210 | [Count Hills and Valleys in an Array](https://leetcode.com/problems/count-hills-and-valleys-in-an-array) | [![Java](assets/java.png)](src/CountHillsAndValleysInAnArray.java) | | -| 2215 | [Find the Difference of Two Arrays](https://leetcode.com/problems/find-the-difference-of-two-arrays) | | | +| 2215 | [Find the Difference of Two Arrays](https://leetcode.com/problems/find-the-difference-of-two-arrays) | [![Java](assets/java.png)](src/FindTheDifferenceOfTwoArrays.java) | | | 2220 | [Minimum Bit Flips to Convert Number](https://leetcode.com/problems/minimum-bit-flips-to-convert-number) | | | | 2224 | [Minimum Number of Operations to Convert Time](https://leetcode.com/problems/minimum-number-of-operations-to-convert-time) | | | | 2229 | 🔒 [Check if an array is consecutive](https://leetcode.com/problems/check-if-an-array-is-consecutive) | | | diff --git a/src/FindTheDifferenceOfTwoArrays.java b/src/FindTheDifferenceOfTwoArrays.java new file mode 100644 index 0000000..7508702 --- /dev/null +++ b/src/FindTheDifferenceOfTwoArrays.java @@ -0,0 +1,35 @@ +// https://leetcode.com/problems/find-the-difference-of-two-arrays +// T: O(N + M) +// S: O(N + M) + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class FindTheDifferenceOfTwoArrays { + public List> findDifference(int[] nums1, int[] nums2) { + final Set numbers1 = getSetFrom(nums1); + final Set numbers2 = getSetFrom(nums2); + final List distinctElementsInNums1 = difference(numbers1, numbers2); + final List distinctElementsInNums2 = difference(numbers2, numbers1); + + return List.of(distinctElementsInNums1, distinctElementsInNums2); + } + + private Set getSetFrom(int[] array) { + final Set set = new HashSet<>(); + for (int element : array) { + set.add(element); + } + return set; + } + + private List difference(Set set1, Set set2) { + final List result = new ArrayList<>(); + for (int element : set1) { + if (!set2.contains(element)) result.add(element); + } + return result; + } +} From 108da7c5abe85e43198e33cae23d79c9d473b0aa Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sun, 14 May 2023 18:23:19 +0200 Subject: [PATCH 026/280] solves #2220: Minimum Bit Flips to Convert Number in java --- README.md | 2 +- src/MinimumBitFlipsToConvertNumber.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/MinimumBitFlipsToConvertNumber.java diff --git a/README.md b/README.md index b2f3f2d..9956c86 100644 --- a/README.md +++ b/README.md @@ -722,7 +722,7 @@ | 2206 | [Divide Array Into Equal Pairs](https://leetcode.com/problems/divide-array-into-equal-pairs) | [![Java](assets/java.png)](src/DivideArrayIntoEqualPairs.java) | | | 2210 | [Count Hills and Valleys in an Array](https://leetcode.com/problems/count-hills-and-valleys-in-an-array) | [![Java](assets/java.png)](src/CountHillsAndValleysInAnArray.java) | | | 2215 | [Find the Difference of Two Arrays](https://leetcode.com/problems/find-the-difference-of-two-arrays) | [![Java](assets/java.png)](src/FindTheDifferenceOfTwoArrays.java) | | -| 2220 | [Minimum Bit Flips to Convert Number](https://leetcode.com/problems/minimum-bit-flips-to-convert-number) | | | +| 2220 | [Minimum Bit Flips to Convert Number](https://leetcode.com/problems/minimum-bit-flips-to-convert-number) | [![Java](assets/java.png)](src/MinimumBitFlipsToConvertNumber.java) | | | 2224 | [Minimum Number of Operations to Convert Time](https://leetcode.com/problems/minimum-number-of-operations-to-convert-time) | | | | 2229 | 🔒 [Check if an array is consecutive](https://leetcode.com/problems/check-if-an-array-is-consecutive) | | | | 2231 | [Largest Number After Digit Swaps by Parity](https://leetcode.com/problems/largest-number-after-digit-swaps-by-parity) | | | diff --git a/src/MinimumBitFlipsToConvertNumber.java b/src/MinimumBitFlipsToConvertNumber.java new file mode 100644 index 0000000..2d89594 --- /dev/null +++ b/src/MinimumBitFlipsToConvertNumber.java @@ -0,0 +1,18 @@ +// https://leetcode.com/problems/minimum-bit-flips-to-convert-number +// T: O(log(n)) +// S: O(1) + +public class MinimumBitFlipsToConvertNumber { + public int minBitFlips(int start, int goal) { + return hammingWeight(start ^ goal); + } + + private int hammingWeight(int x) { + int result = 0; + while (x > 0) { + x = x & (x - 1); + result++; + } + return result; + } +} From 57d6a820f857c3324e5b388f793ce109499b14f0 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sun, 14 May 2023 18:37:11 +0200 Subject: [PATCH 027/280] solves #2224: Minimum Number of Operations to Convert Time in java --- README.md | 2 +- ...inimumNumberOfOperationsToConvertTime.java | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 src/MinimumNumberOfOperationsToConvertTime.java diff --git a/README.md b/README.md index 9956c86..e73da7e 100644 --- a/README.md +++ b/README.md @@ -723,7 +723,7 @@ | 2210 | [Count Hills and Valleys in an Array](https://leetcode.com/problems/count-hills-and-valleys-in-an-array) | [![Java](assets/java.png)](src/CountHillsAndValleysInAnArray.java) | | | 2215 | [Find the Difference of Two Arrays](https://leetcode.com/problems/find-the-difference-of-two-arrays) | [![Java](assets/java.png)](src/FindTheDifferenceOfTwoArrays.java) | | | 2220 | [Minimum Bit Flips to Convert Number](https://leetcode.com/problems/minimum-bit-flips-to-convert-number) | [![Java](assets/java.png)](src/MinimumBitFlipsToConvertNumber.java) | | -| 2224 | [Minimum Number of Operations to Convert Time](https://leetcode.com/problems/minimum-number-of-operations-to-convert-time) | | | +| 2224 | [Minimum Number of Operations to Convert Time](https://leetcode.com/problems/minimum-number-of-operations-to-convert-time) | [![Java](assets/java.png)](src/MinimumNumberOfOperationsToConvertTime.java) | | | 2229 | 🔒 [Check if an array is consecutive](https://leetcode.com/problems/check-if-an-array-is-consecutive) | | | | 2231 | [Largest Number After Digit Swaps by Parity](https://leetcode.com/problems/largest-number-after-digit-swaps-by-parity) | | | | 2235 | [Add Two Integers](https://leetcode.com/problems/add-two-integers) | | | diff --git a/src/MinimumNumberOfOperationsToConvertTime.java b/src/MinimumNumberOfOperationsToConvertTime.java new file mode 100644 index 0000000..24878b4 --- /dev/null +++ b/src/MinimumNumberOfOperationsToConvertTime.java @@ -0,0 +1,23 @@ +// https://leetcode.com/problems/minimum-number-of-operations-to-convert-time +// T: O(1) +// S: O(1) + +public class MinimumNumberOfOperationsToConvertTime { + private final static int[] MINUTE_INCREMENTS = {60, 15, 5, 1}; + + public int convertTime(String current, String correct) { + final int hour1 = Integer.parseInt(current.substring(0, 2)), hour2 = Integer.parseInt(correct.substring(0, 2)); + final int minutes1 = Integer.parseInt(current.substring(3)), minutes2 = Integer.parseInt(correct.substring(3)); + final int totalMinutes1 = hour1 * 60 + minutes1, totalMinutes2 = hour2 * 60 + minutes2; + + int operations = 0; + int difference = totalMinutes2 - totalMinutes1; + + for (int i = 0 ; i < MINUTE_INCREMENTS.length && difference > 0; i++) { + operations += difference / MINUTE_INCREMENTS[i]; + difference -= (difference / MINUTE_INCREMENTS[i]) * MINUTE_INCREMENTS[i]; + } + + return operations; + } +} From 52dc19eebde704aae1ca8a77b7b2cc957cd26b37 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sun, 14 May 2023 19:32:33 +0200 Subject: [PATCH 028/280] solves #2231: Largest Number After Digit Swaps by Parity in java --- README.md | 4 +- src/LargestNumberAfterDigitSwapsByParity.java | 49 +++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 src/LargestNumberAfterDigitSwapsByParity.java diff --git a/README.md b/README.md index e73da7e..057da66 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-570/2081-1f425f.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-593/2081-1f425f.svg) ![problems-solved-java](https://img.shields.io/badge/Java-556/2081-1abc9c.svg) ![problems-solved-python](https://img.shields.io/badge/Python-205/2081-1abc9c.svg) ![problems-solved-javascript](https://img.shields.io/badge/JavaScript-4/2081-1abc9c.svg) @@ -725,7 +725,7 @@ | 2220 | [Minimum Bit Flips to Convert Number](https://leetcode.com/problems/minimum-bit-flips-to-convert-number) | [![Java](assets/java.png)](src/MinimumBitFlipsToConvertNumber.java) | | | 2224 | [Minimum Number of Operations to Convert Time](https://leetcode.com/problems/minimum-number-of-operations-to-convert-time) | [![Java](assets/java.png)](src/MinimumNumberOfOperationsToConvertTime.java) | | | 2229 | 🔒 [Check if an array is consecutive](https://leetcode.com/problems/check-if-an-array-is-consecutive) | | | -| 2231 | [Largest Number After Digit Swaps by Parity](https://leetcode.com/problems/largest-number-after-digit-swaps-by-parity) | | | +| 2231 | [Largest Number After Digit Swaps by Parity](https://leetcode.com/problems/largest-number-after-digit-swaps-by-parity) | [![Java](assets/java.png)](src/LargestNumberAfterDigitSwapsByParity.java) | | | 2235 | [Add Two Integers](https://leetcode.com/problems/add-two-integers) | | | | 2236 | [Root Equals Sum of Children](https://leetcode.com/problems/root-equals-sum-of-children) | | | | 2239 | [Find Closest Number to Zero](https://leetcode.com/problems/find-closest-number-to-zero) | | | diff --git a/src/LargestNumberAfterDigitSwapsByParity.java b/src/LargestNumberAfterDigitSwapsByParity.java new file mode 100644 index 0000000..0d898b9 --- /dev/null +++ b/src/LargestNumberAfterDigitSwapsByParity.java @@ -0,0 +1,49 @@ +// https://leetcode.com/problems/largest-number-after-digit-swaps-by-parity +// T: O(log(n) log(log(n))) +// S: O(log(n)) + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; + +public class LargestNumberAfterDigitSwapsByParity { + public int largestInteger(int num) { + final String number = num + ""; + final List evenDigits = getEvenDigits(number); + final List oddDigits = getOddDigits(number); + + evenDigits.sort(Comparator.reverseOrder()); + oddDigits.sort(Comparator.reverseOrder()); + + final StringBuilder result = new StringBuilder(); + for (int i = 0, evenIndex = 0, oddIndex = 0; i < number.length() ; i++) { + if (isOddDigit(number, i)) { + result.append(oddDigits.get(oddIndex++)); + } else { + result.append(evenDigits.get(evenIndex++)); + } + } + + return Integer.parseInt(result.toString()); + } + + private boolean isOddDigit(String number, int index) { + return (number.charAt(index) - '0') % 2 == 1; + } + + private List getEvenDigits(String string) { + final List result = new ArrayList<>(); + for (int index = 0 ; index < string.length() ; index++) { + if (!isOddDigit(string, index)) result.add(string.charAt(index) - '0'); + } + return result; + } + + private List getOddDigits(String string) { + final List result = new ArrayList<>(); + for (int index = 0 ; index < string.length() ; index++) { + if (isOddDigit(string, index)) result.add(string.charAt(index) - '0'); + } + return result; + } +} From d831362b0efe28d64c94c14636977ae08d704a8a Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sun, 14 May 2023 19:34:56 +0200 Subject: [PATCH 029/280] solves #2235: Add Two Integers in java --- README.md | 2 +- src/AddTwoIntegers.java | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/AddTwoIntegers.java diff --git a/README.md b/README.md index 057da66..b1bdf2a 100644 --- a/README.md +++ b/README.md @@ -726,7 +726,7 @@ | 2224 | [Minimum Number of Operations to Convert Time](https://leetcode.com/problems/minimum-number-of-operations-to-convert-time) | [![Java](assets/java.png)](src/MinimumNumberOfOperationsToConvertTime.java) | | | 2229 | 🔒 [Check if an array is consecutive](https://leetcode.com/problems/check-if-an-array-is-consecutive) | | | | 2231 | [Largest Number After Digit Swaps by Parity](https://leetcode.com/problems/largest-number-after-digit-swaps-by-parity) | [![Java](assets/java.png)](src/LargestNumberAfterDigitSwapsByParity.java) | | -| 2235 | [Add Two Integers](https://leetcode.com/problems/add-two-integers) | | | +| 2235 | [Add Two Integers](https://leetcode.com/problems/add-two-integers) | [![Java](assets/java.png)](src/AddTwoIntegers.java) | | | 2236 | [Root Equals Sum of Children](https://leetcode.com/problems/root-equals-sum-of-children) | | | | 2239 | [Find Closest Number to Zero](https://leetcode.com/problems/find-closest-number-to-zero) | | | | 2243 | [Calculate Digit Sum of a String](https://leetcode.com/problems/calculate-digit-sum-of-a-string) | | | diff --git a/src/AddTwoIntegers.java b/src/AddTwoIntegers.java new file mode 100644 index 0000000..db38d42 --- /dev/null +++ b/src/AddTwoIntegers.java @@ -0,0 +1,9 @@ +// https://leetcode.com/problems/add-two-integers +// T: O(1) +// S: O(1) + +public class AddTwoIntegers { + public int sum(int num1, int num2) { + return num1 + num2; + } +} From d9d4ec60a1d8fe29eae34223b44cd77a1624f446 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 16 May 2023 08:36:59 +0200 Subject: [PATCH 030/280] solves #2236: Root Equals Sum of Children in java --- .gitignore | 1 + README.md | 2 +- src/RootEqualsSumOfChildren.java | 9 +++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 src/RootEqualsSumOfChildren.java diff --git a/.gitignore b/.gitignore index 7b8c768..ce3bd8a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ out venv *.iml +.DS_Store diff --git a/README.md b/README.md index b1bdf2a..b16486b 100644 --- a/README.md +++ b/README.md @@ -727,7 +727,7 @@ | 2229 | 🔒 [Check if an array is consecutive](https://leetcode.com/problems/check-if-an-array-is-consecutive) | | | | 2231 | [Largest Number After Digit Swaps by Parity](https://leetcode.com/problems/largest-number-after-digit-swaps-by-parity) | [![Java](assets/java.png)](src/LargestNumberAfterDigitSwapsByParity.java) | | | 2235 | [Add Two Integers](https://leetcode.com/problems/add-two-integers) | [![Java](assets/java.png)](src/AddTwoIntegers.java) | | -| 2236 | [Root Equals Sum of Children](https://leetcode.com/problems/root-equals-sum-of-children) | | | +| 2236 | [Root Equals Sum of Children](https://leetcode.com/problems/root-equals-sum-of-children) | [![Java](assets/java.png)](src/RootEqualsSumOfChildren.java) | | | 2239 | [Find Closest Number to Zero](https://leetcode.com/problems/find-closest-number-to-zero) | | | | 2243 | [Calculate Digit Sum of a String](https://leetcode.com/problems/calculate-digit-sum-of-a-string) | | | | 2248 | [Intersection of Multiple Arrays](https://leetcode.com/problems/intersection-of-multiple-arrays) | | | diff --git a/src/RootEqualsSumOfChildren.java b/src/RootEqualsSumOfChildren.java new file mode 100644 index 0000000..52ee7c3 --- /dev/null +++ b/src/RootEqualsSumOfChildren.java @@ -0,0 +1,9 @@ +// https://leetcode.com/problems/root-equals-sum-of-children +// T: O(1) +// S: O(1) + +public class RootEqualsSumOfChildren { + public boolean checkTree(TreeNode root) { + return root.val == root.left.val + root.right.val; + } +} From 076f0863133da460f99d64b71842463e172b1f57 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 16 May 2023 08:44:24 +0200 Subject: [PATCH 031/280] solves #2239: Find Closest Number to Zero in java --- README.md | 2 +- src/FindClosestNumberToZero.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/FindClosestNumberToZero.java diff --git a/README.md b/README.md index b16486b..ad05066 100644 --- a/README.md +++ b/README.md @@ -728,7 +728,7 @@ | 2231 | [Largest Number After Digit Swaps by Parity](https://leetcode.com/problems/largest-number-after-digit-swaps-by-parity) | [![Java](assets/java.png)](src/LargestNumberAfterDigitSwapsByParity.java) | | | 2235 | [Add Two Integers](https://leetcode.com/problems/add-two-integers) | [![Java](assets/java.png)](src/AddTwoIntegers.java) | | | 2236 | [Root Equals Sum of Children](https://leetcode.com/problems/root-equals-sum-of-children) | [![Java](assets/java.png)](src/RootEqualsSumOfChildren.java) | | -| 2239 | [Find Closest Number to Zero](https://leetcode.com/problems/find-closest-number-to-zero) | | | +| 2239 | [Find Closest Number to Zero](https://leetcode.com/problems/find-closest-number-to-zero) | [![Java](assets/java.png)](src/FindClosestNumberToZero.java) | | | 2243 | [Calculate Digit Sum of a String](https://leetcode.com/problems/calculate-digit-sum-of-a-string) | | | | 2248 | [Intersection of Multiple Arrays](https://leetcode.com/problems/intersection-of-multiple-arrays) | | | | 2255 | [Count Prefixes of a Given String](https://leetcode.com/problems/count-prefixes-of-a-given-string) | | | diff --git a/src/FindClosestNumberToZero.java b/src/FindClosestNumberToZero.java new file mode 100644 index 0000000..62a59fe --- /dev/null +++ b/src/FindClosestNumberToZero.java @@ -0,0 +1,18 @@ +// https://leetcode.com/problems/find-closest-number-to-zero +// T: O(N) +// S: O(1) + +public class FindClosestNumberToZero { + public int findClosestNumber(int[] array) { + int nearest = Integer.MAX_VALUE; + for (int element : array) { + if (Math.abs(element) < Math.abs(nearest)) { + nearest = element; + } else if (Math.abs(element) == Math.abs(nearest)) { + nearest = Math.max(nearest, element); + } + } + + return nearest; + } +} From f7d24ca6e90a2e825d8ff679ca30a4ad19e2afc8 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 16 May 2023 08:51:39 +0200 Subject: [PATCH 032/280] solves #2243: Calculate Digit Sum of a String in java --- README.md | 2 +- src/CalculateDigitSumOfAString.java | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/CalculateDigitSumOfAString.java diff --git a/README.md b/README.md index ad05066..719cbd4 100644 --- a/README.md +++ b/README.md @@ -729,7 +729,7 @@ | 2235 | [Add Two Integers](https://leetcode.com/problems/add-two-integers) | [![Java](assets/java.png)](src/AddTwoIntegers.java) | | | 2236 | [Root Equals Sum of Children](https://leetcode.com/problems/root-equals-sum-of-children) | [![Java](assets/java.png)](src/RootEqualsSumOfChildren.java) | | | 2239 | [Find Closest Number to Zero](https://leetcode.com/problems/find-closest-number-to-zero) | [![Java](assets/java.png)](src/FindClosestNumberToZero.java) | | -| 2243 | [Calculate Digit Sum of a String](https://leetcode.com/problems/calculate-digit-sum-of-a-string) | | | +| 2243 | [Calculate Digit Sum of a String](https://leetcode.com/problems/calculate-digit-sum-of-a-string) | [![Java](assets/java.png)](src/CalculateDigitSumOfAString.java) | | | 2248 | [Intersection of Multiple Arrays](https://leetcode.com/problems/intersection-of-multiple-arrays) | | | | 2255 | [Count Prefixes of a Given String](https://leetcode.com/problems/count-prefixes-of-a-given-string) | | | | 2259 | [Remove Digit From Number to Maximize Result](https://leetcode.com/problems/remove-digit-from-number-to-maximize-result) | | | diff --git a/src/CalculateDigitSumOfAString.java b/src/CalculateDigitSumOfAString.java new file mode 100644 index 0000000..020a06f --- /dev/null +++ b/src/CalculateDigitSumOfAString.java @@ -0,0 +1,28 @@ +// https://leetcode.com/problems/calculate-digit-sum-of-a-string +// T: O(log(n)) +// S: O(log(n)) + +public class CalculateDigitSumOfAString { + public String digitSum(String s, int k) { + if (s.length() <= k) return s; + final StringBuilder result = new StringBuilder(); + for (int i = 0 ; i < s.length() ; i += k) { + final String group = s.substring(i, Math.min(i + k, s.length())); + final int groupSum = digitSum(group); + result.append(groupSum); + } + return digitSum(result.toString(), k); + } + + private int digitSum(String number) { + int sum = 0; + for (int index = 0 ; index < number.length() ; index++) { + sum += toInt(number.charAt(index)); + } + return sum; + } + + private int toInt(char x) { + return x - '0'; + } +} From 1870f7a41554b61ef0b2390f39ab059d34b3272d Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 27 May 2023 14:56:01 +0200 Subject: [PATCH 033/280] solves #2248: Intersection of Multiple Arrays in java --- README.md | 2 +- src/IntersectionOfMultipleArrays.java | 41 +++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/IntersectionOfMultipleArrays.java diff --git a/README.md b/README.md index 719cbd4..a988683 100644 --- a/README.md +++ b/README.md @@ -730,7 +730,7 @@ | 2236 | [Root Equals Sum of Children](https://leetcode.com/problems/root-equals-sum-of-children) | [![Java](assets/java.png)](src/RootEqualsSumOfChildren.java) | | | 2239 | [Find Closest Number to Zero](https://leetcode.com/problems/find-closest-number-to-zero) | [![Java](assets/java.png)](src/FindClosestNumberToZero.java) | | | 2243 | [Calculate Digit Sum of a String](https://leetcode.com/problems/calculate-digit-sum-of-a-string) | [![Java](assets/java.png)](src/CalculateDigitSumOfAString.java) | | -| 2248 | [Intersection of Multiple Arrays](https://leetcode.com/problems/intersection-of-multiple-arrays) | | | +| 2248 | [Intersection of Multiple Arrays](https://leetcode.com/problems/intersection-of-multiple-arrays) | [![Java](assets/java.png)](src/IntersectionOfMultipleArrays.java) | | | 2255 | [Count Prefixes of a Given String](https://leetcode.com/problems/count-prefixes-of-a-given-string) | | | | 2259 | [Remove Digit From Number to Maximize Result](https://leetcode.com/problems/remove-digit-from-number-to-maximize-result) | | | | 2264 | [Largest 3-Same-Digit Number in String](https://leetcode.com/problems/largest-3-same-digit-number-in-string) | | | diff --git a/src/IntersectionOfMultipleArrays.java b/src/IntersectionOfMultipleArrays.java new file mode 100644 index 0000000..9efff3d --- /dev/null +++ b/src/IntersectionOfMultipleArrays.java @@ -0,0 +1,41 @@ +// https://leetcode.com/problems/intersection-of-multiple-arrays +// T: O() +// S: O() + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class IntersectionOfMultipleArrays { + public List intersection(int[][] nums) { + Set set = setFrom(nums[0]); + for (int index = 1 ; index < nums.length ; index++) { + final Set other = setFrom(nums[index]); + set = intersection(set, other); + } + final List list = toList(set); + list.sort(Integer::compareTo); + return list; + } + + private Set setFrom(int[] array) { + final Set set = new HashSet<>(); + for (int element : array) { + set.add(element); + } + return set; + } + + private List toList(final Set set) { + return new ArrayList<>(set); + } + + private Set intersection(Set set1, Set set2) { + final Set result = new HashSet<>(); + for (int element : set1) { + if (set2.contains(element)) result.add(element); + } + return result; + } +} From 18b6658dd7d6f89f7aa1415269e31a4dbfb16938 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 27 May 2023 15:00:47 +0200 Subject: [PATCH 034/280] solves #2255: Count Prefixes of a Given String in java --- README.md | 4 ++-- src/CountPrefixesOfAGivenString.java | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 src/CountPrefixesOfAGivenString.java diff --git a/README.md b/README.md index a988683..e7fc0d2 100644 --- a/README.md +++ b/README.md @@ -730,8 +730,8 @@ | 2236 | [Root Equals Sum of Children](https://leetcode.com/problems/root-equals-sum-of-children) | [![Java](assets/java.png)](src/RootEqualsSumOfChildren.java) | | | 2239 | [Find Closest Number to Zero](https://leetcode.com/problems/find-closest-number-to-zero) | [![Java](assets/java.png)](src/FindClosestNumberToZero.java) | | | 2243 | [Calculate Digit Sum of a String](https://leetcode.com/problems/calculate-digit-sum-of-a-string) | [![Java](assets/java.png)](src/CalculateDigitSumOfAString.java) | | -| 2248 | [Intersection of Multiple Arrays](https://leetcode.com/problems/intersection-of-multiple-arrays) | [![Java](assets/java.png)](src/IntersectionOfMultipleArrays.java) | | -| 2255 | [Count Prefixes of a Given String](https://leetcode.com/problems/count-prefixes-of-a-given-string) | | | +| 2248 | [Intersection of Multiple Arrays](https://leetcode.com/problems/intersection-of-multiple-arrays) | [![Java](assets/java.png)](src/IntersectionOfMultipleArrays.java) | | +| 2255 | [Count Prefixes of a Given String](https://leetcode.com/problems/count-prefixes-of-a-given-string) | [![Java](assets/java.png)](src/CountPrefixesOfAGivenString.java) | | | 2259 | [Remove Digit From Number to Maximize Result](https://leetcode.com/problems/remove-digit-from-number-to-maximize-result) | | | | 2264 | [Largest 3-Same-Digit Number in String](https://leetcode.com/problems/largest-3-same-digit-number-in-string) | | | | 2269 | [Find the K-Beauty of a Number](https://leetcode.com/problems/find-the-k-beauty-of-a-number) | | | diff --git a/src/CountPrefixesOfAGivenString.java b/src/CountPrefixesOfAGivenString.java new file mode 100644 index 0000000..7c20c35 --- /dev/null +++ b/src/CountPrefixesOfAGivenString.java @@ -0,0 +1,13 @@ +// https://leetcode.com/problems/count-prefixes-of-a-given-string +// T: O(|words| * |s|) +// S: O(1) + +public class CountPrefixesOfAGivenString { + public int countPrefixes(String[] words, String s) { + int result = 0; + for (String word : words) { + if (s.startsWith(word)) result++; + } + return result; + } +} From ffa1ff1d470da1bb08b9f31f1556f0339a04a103 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 27 May 2023 15:10:56 +0200 Subject: [PATCH 035/280] solves #2259: Remove Digit From Number to Maximize Result in java --- README.md | 2 +- ...RemoveDigitFromNumberToMaximizeResult.java | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/RemoveDigitFromNumberToMaximizeResult.java diff --git a/README.md b/README.md index e7fc0d2..2be3d88 100644 --- a/README.md +++ b/README.md @@ -732,7 +732,7 @@ | 2243 | [Calculate Digit Sum of a String](https://leetcode.com/problems/calculate-digit-sum-of-a-string) | [![Java](assets/java.png)](src/CalculateDigitSumOfAString.java) | | | 2248 | [Intersection of Multiple Arrays](https://leetcode.com/problems/intersection-of-multiple-arrays) | [![Java](assets/java.png)](src/IntersectionOfMultipleArrays.java) | | | 2255 | [Count Prefixes of a Given String](https://leetcode.com/problems/count-prefixes-of-a-given-string) | [![Java](assets/java.png)](src/CountPrefixesOfAGivenString.java) | | -| 2259 | [Remove Digit From Number to Maximize Result](https://leetcode.com/problems/remove-digit-from-number-to-maximize-result) | | | +| 2259 | [Remove Digit From Number to Maximize Result](https://leetcode.com/problems/remove-digit-from-number-to-maximize-result) | [![Java](assets/java.png)](src/RemoveDigitFromNumberToMaximizeResult.java) | | | 2264 | [Largest 3-Same-Digit Number in String](https://leetcode.com/problems/largest-3-same-digit-number-in-string) | | | | 2269 | [Find the K-Beauty of a Number](https://leetcode.com/problems/find-the-k-beauty-of-a-number) | | | | 2273 | [Find Resultant Array After Removing Anagrams](https://leetcode.com/problems/find-resultant-array-after-removing-anagrams) | | | diff --git a/src/RemoveDigitFromNumberToMaximizeResult.java b/src/RemoveDigitFromNumberToMaximizeResult.java new file mode 100644 index 0000000..e04feab --- /dev/null +++ b/src/RemoveDigitFromNumberToMaximizeResult.java @@ -0,0 +1,29 @@ +// https://leetcode.com/problems/remove-digit-from-number-to-maximize-result +// T: O(|number|) +// S: O(|number|) + +import java.util.ArrayList; +import java.util.List; + +public class RemoveDigitFromNumberToMaximizeResult { + public String removeDigit(String number, char digit) { + final List digitIndices = getIndices(number, digit); + for (int index : digitIndices) { + if (index + 1 < number.length() && number.charAt(index) < number.charAt(index + 1)) { + return number.substring(0, index) + number.substring(index + 1); + } + } + int lastIndex = digitIndices.get(digitIndices.size() - 1); + return number.substring(0, lastIndex) + number.substring(lastIndex + 1); + } + + private List getIndices(String number, char digit) { + final List result = new ArrayList<>(); + for (int index = 0 ; index < number.length() ; index++) { + if (number.charAt(index) == digit) { + result.add(index); + } + } + return result; + } +} From edb017214f1fae3fa3e9cb030ffe824a7a5e3b99 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 27 May 2023 15:27:14 +0200 Subject: [PATCH 036/280] solves #2264: Largest 3-Same-Digit Number in String in java --- README.md | 2 +- src/Largest3SameDigitNumberInString.java | 25 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/Largest3SameDigitNumberInString.java diff --git a/README.md b/README.md index 2be3d88..ff4fcfb 100644 --- a/README.md +++ b/README.md @@ -733,7 +733,7 @@ | 2248 | [Intersection of Multiple Arrays](https://leetcode.com/problems/intersection-of-multiple-arrays) | [![Java](assets/java.png)](src/IntersectionOfMultipleArrays.java) | | | 2255 | [Count Prefixes of a Given String](https://leetcode.com/problems/count-prefixes-of-a-given-string) | [![Java](assets/java.png)](src/CountPrefixesOfAGivenString.java) | | | 2259 | [Remove Digit From Number to Maximize Result](https://leetcode.com/problems/remove-digit-from-number-to-maximize-result) | [![Java](assets/java.png)](src/RemoveDigitFromNumberToMaximizeResult.java) | | -| 2264 | [Largest 3-Same-Digit Number in String](https://leetcode.com/problems/largest-3-same-digit-number-in-string) | | | +| 2264 | [Largest 3-Same-Digit Number in String](https://leetcode.com/problems/largest-3-same-digit-number-in-string) | [![Java](assets/java.png)](src/Largest3SameDigitNumberInString.java) | | | 2269 | [Find the K-Beauty of a Number](https://leetcode.com/problems/find-the-k-beauty-of-a-number) | | | | 2273 | [Find Resultant Array After Removing Anagrams](https://leetcode.com/problems/find-resultant-array-after-removing-anagrams) | | | | 2278 | [Percentage of Letter in String](https://leetcode.com/problems/percentage-of-letter-in-string) | | | diff --git a/src/Largest3SameDigitNumberInString.java b/src/Largest3SameDigitNumberInString.java new file mode 100644 index 0000000..902ab77 --- /dev/null +++ b/src/Largest3SameDigitNumberInString.java @@ -0,0 +1,25 @@ +// https://leetcode.com/problems/largest-3-same-digit-number-in-string +// T: O(|s|) +// S: O(1) + +public class Largest3SameDigitNumberInString { + public String largestGoodInteger(String num) { + char current = num.charAt(0), result = '0' - 1; + for (int index = 1, count = 1 ; index < num.length() ; index++) { + if (num.charAt(index) == current) { + count++; + } else { + current = num.charAt(index); + count = 1; + } + + if (count >= 3 && current > result) { + result = current; + } + } + + if (result >= '0') { + return (result + "").repeat(3); + } else return ""; + } +} From 1e5817ebf6783d8dcca502957bfcb98847d55baf Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 27 May 2023 15:57:13 +0200 Subject: [PATCH 037/280] solves #2269: Find the K-Beauty of a Number in java --- README.md | 4 ++-- src/FindTheKBeautyOfANumber.java | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 src/FindTheKBeautyOfANumber.java diff --git a/README.md b/README.md index ff4fcfb..539ac47 100644 --- a/README.md +++ b/README.md @@ -733,8 +733,8 @@ | 2248 | [Intersection of Multiple Arrays](https://leetcode.com/problems/intersection-of-multiple-arrays) | [![Java](assets/java.png)](src/IntersectionOfMultipleArrays.java) | | | 2255 | [Count Prefixes of a Given String](https://leetcode.com/problems/count-prefixes-of-a-given-string) | [![Java](assets/java.png)](src/CountPrefixesOfAGivenString.java) | | | 2259 | [Remove Digit From Number to Maximize Result](https://leetcode.com/problems/remove-digit-from-number-to-maximize-result) | [![Java](assets/java.png)](src/RemoveDigitFromNumberToMaximizeResult.java) | | -| 2264 | [Largest 3-Same-Digit Number in String](https://leetcode.com/problems/largest-3-same-digit-number-in-string) | [![Java](assets/java.png)](src/Largest3SameDigitNumberInString.java) | | -| 2269 | [Find the K-Beauty of a Number](https://leetcode.com/problems/find-the-k-beauty-of-a-number) | | | +| 2264 | [Largest 3-Same-Digit Number in String](https://leetcode.com/problems/largest-3-same-digit-number-in-string) | [![Java](assets/java.png)](src/Largest3SameDigitNumberInString.java) | | +| 2269 | [Find the K-Beauty of a Number](https://leetcode.com/problems/find-the-k-beauty-of-a-number) | [![Java](assets/java.png)](src/FindTheKBeautyOfANumber.java) | | | 2273 | [Find Resultant Array After Removing Anagrams](https://leetcode.com/problems/find-resultant-array-after-removing-anagrams) | | | | 2278 | [Percentage of Letter in String](https://leetcode.com/problems/percentage-of-letter-in-string) | | | | 2283 | [Check if Number Has Equal Digit Count and Digit Value](https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value) | | | diff --git a/src/FindTheKBeautyOfANumber.java b/src/FindTheKBeautyOfANumber.java new file mode 100644 index 0000000..113653d --- /dev/null +++ b/src/FindTheKBeautyOfANumber.java @@ -0,0 +1,24 @@ +// https://leetcode.com/problems/find-the-k-beauty-of-a-number +// T: O(|num|) +// S: O(|num|) + +public class FindTheKBeautyOfANumber { + public int divisorSubstrings(int num, int k) { + int kBeauty = 0; + final String number = num + ""; + for (int index = 0 ; index < number.length() - k + 1 ; index++) { + final String substring = number.substring(index, index + k); + final int divisor = toNumber(substring); + if (divisor != 0 && num % divisor == 0) kBeauty++; + } + return kBeauty; + } + + private int toNumber(String string) { + int result = 0; + for (int i = 0; i < string.length() ; i++) { + result = 10 * result + (string.charAt(i) - '0'); + } + return result; + } +} From 685093698eb8bdcfa5503905f3ad5b80e635e8f3 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 27 May 2023 16:12:21 +0200 Subject: [PATCH 038/280] solves #2273: Find Resultant Array After Removing Anagrams in java --- README.md | 2 +- ...ndResultantArrayAfterRemovingAnagrams.java | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/FindResultantArrayAfterRemovingAnagrams.java diff --git a/README.md b/README.md index 539ac47..3bc5517 100644 --- a/README.md +++ b/README.md @@ -735,7 +735,7 @@ | 2259 | [Remove Digit From Number to Maximize Result](https://leetcode.com/problems/remove-digit-from-number-to-maximize-result) | [![Java](assets/java.png)](src/RemoveDigitFromNumberToMaximizeResult.java) | | | 2264 | [Largest 3-Same-Digit Number in String](https://leetcode.com/problems/largest-3-same-digit-number-in-string) | [![Java](assets/java.png)](src/Largest3SameDigitNumberInString.java) | | | 2269 | [Find the K-Beauty of a Number](https://leetcode.com/problems/find-the-k-beauty-of-a-number) | [![Java](assets/java.png)](src/FindTheKBeautyOfANumber.java) | | -| 2273 | [Find Resultant Array After Removing Anagrams](https://leetcode.com/problems/find-resultant-array-after-removing-anagrams) | | | +| 2273 | [Find Resultant Array After Removing Anagrams](https://leetcode.com/problems/find-resultant-array-after-removing-anagrams) | [![Java](assets/java.png)](src/FindResultantArrayAfterRemovingAnagrams.java) | | | 2278 | [Percentage of Letter in String](https://leetcode.com/problems/percentage-of-letter-in-string) | | | | 2283 | [Check if Number Has Equal Digit Count and Digit Value](https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value) | | | | 2287 | [Rearrange Characters to Make Target String](https://leetcode.com/problems/rearrange-characters-to-make-target-string) | | | diff --git a/src/FindResultantArrayAfterRemovingAnagrams.java b/src/FindResultantArrayAfterRemovingAnagrams.java new file mode 100644 index 0000000..c96803b --- /dev/null +++ b/src/FindResultantArrayAfterRemovingAnagrams.java @@ -0,0 +1,33 @@ +// https://leetcode.com/problems/find-resultant-array-after-removing-anagrams +// T: O(|words| * |words[i]|) +// S: O(|words[i]|) + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class FindResultantArrayAfterRemovingAnagrams { + public List removeAnagrams(String[] words) { + final List result = new ArrayList<>(); + result.add(words[0]); + Map wordSignature = getCharacterFrequencies(words[0]); + for (int index = 1 ; index < words.length ; index++) { + final String word = words[index]; + final Map wordCharFrequencies = getCharacterFrequencies(word); + if (!wordCharFrequencies.equals(wordSignature)) { + result.add(word); + wordSignature = wordCharFrequencies; + } + } + return result; + } + + private Map getCharacterFrequencies(String string) { + final Map result = new HashMap<>(); + for (int index = 0 ; index < string.length() ; index++) { + result.put(string.charAt(index), result.getOrDefault(string.charAt(index), 0) + 1); + } + return result; + } +} From f19f981305b0886d318edf8562119620526ea69a Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 27 May 2023 16:15:55 +0200 Subject: [PATCH 039/280] solves #2278: Percentage of Letter in String in java --- README.md | 2 +- src/PercentageOfLetterInString.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/PercentageOfLetterInString.java diff --git a/README.md b/README.md index 3bc5517..19742a8 100644 --- a/README.md +++ b/README.md @@ -736,7 +736,7 @@ | 2264 | [Largest 3-Same-Digit Number in String](https://leetcode.com/problems/largest-3-same-digit-number-in-string) | [![Java](assets/java.png)](src/Largest3SameDigitNumberInString.java) | | | 2269 | [Find the K-Beauty of a Number](https://leetcode.com/problems/find-the-k-beauty-of-a-number) | [![Java](assets/java.png)](src/FindTheKBeautyOfANumber.java) | | | 2273 | [Find Resultant Array After Removing Anagrams](https://leetcode.com/problems/find-resultant-array-after-removing-anagrams) | [![Java](assets/java.png)](src/FindResultantArrayAfterRemovingAnagrams.java) | | -| 2278 | [Percentage of Letter in String](https://leetcode.com/problems/percentage-of-letter-in-string) | | | +| 2278 | [Percentage of Letter in String](https://leetcode.com/problems/percentage-of-letter-in-string) | [![Java](assets/java.png)](src/PercentageOfLetterInString.java) | | | 2283 | [Check if Number Has Equal Digit Count and Digit Value](https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value) | | | | 2287 | [Rearrange Characters to Make Target String](https://leetcode.com/problems/rearrange-characters-to-make-target-string) | | | | 2293 | [Min Max Game](https://leetcode.com/problems/min-max-game) | | | diff --git a/src/PercentageOfLetterInString.java b/src/PercentageOfLetterInString.java new file mode 100644 index 0000000..d474b65 --- /dev/null +++ b/src/PercentageOfLetterInString.java @@ -0,0 +1,15 @@ +// https://leetcode.com/problems/percentage-of-letter-in-string +// T: O(|s|) +// S: O(1) + +public class PercentageOfLetterInString { + public int percentageLetter(String s, char letter) { + int count = 0; + for (int index = 0 ; index < s.length() ; index++) { + if (letter == s.charAt(index)) { + count++; + } + } + return (int) (((double) count / s.length()) * 100); + } +} From c9ec8a8600a686ed8e8579a751d6e4ea2eaf735b Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 27 May 2023 16:30:17 +0200 Subject: [PATCH 040/280] solves #2283: Check if Number Has Equal Digit Count and Digit Value in java --- README.md | 2 +- ...NumberHasEqualDigitCountAndDigitValue.java | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/CheckIfNumberHasEqualDigitCountAndDigitValue.java diff --git a/README.md b/README.md index 19742a8..0c9362e 100644 --- a/README.md +++ b/README.md @@ -737,7 +737,7 @@ | 2269 | [Find the K-Beauty of a Number](https://leetcode.com/problems/find-the-k-beauty-of-a-number) | [![Java](assets/java.png)](src/FindTheKBeautyOfANumber.java) | | | 2273 | [Find Resultant Array After Removing Anagrams](https://leetcode.com/problems/find-resultant-array-after-removing-anagrams) | [![Java](assets/java.png)](src/FindResultantArrayAfterRemovingAnagrams.java) | | | 2278 | [Percentage of Letter in String](https://leetcode.com/problems/percentage-of-letter-in-string) | [![Java](assets/java.png)](src/PercentageOfLetterInString.java) | | -| 2283 | [Check if Number Has Equal Digit Count and Digit Value](https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value) | | | +| 2283 | [Check if Number Has Equal Digit Count and Digit Value](https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value) | [![Java](assets/java.png)](src/CheckIfNumberHasEqualDigitCountAndDigitValue.java) | | | 2287 | [Rearrange Characters to Make Target String](https://leetcode.com/problems/rearrange-characters-to-make-target-string) | | | | 2293 | [Min Max Game](https://leetcode.com/problems/min-max-game) | | | | 2299 | [Strong Password Checker II](https://leetcode.com/problems/strong-password-checker-ii) | | | diff --git a/src/CheckIfNumberHasEqualDigitCountAndDigitValue.java b/src/CheckIfNumberHasEqualDigitCountAndDigitValue.java new file mode 100644 index 0000000..9d07c85 --- /dev/null +++ b/src/CheckIfNumberHasEqualDigitCountAndDigitValue.java @@ -0,0 +1,27 @@ +// https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value +// T: O(|num|) +// S: O(1) + +import java.util.HashMap; +import java.util.Map; + +public class CheckIfNumberHasEqualDigitCountAndDigitValue { + public boolean digitCount(String num) { + final Map digitFrequencies = getDigitFrequencies(num); + for (int index = 0 ; index < num.length() ; index++) { + if ((num.charAt(index) - '0') != digitFrequencies.getOrDefault(index, 0)) { + return false; + } + } + return true; + } + + private Map getDigitFrequencies(String number) { + final Map frequencies = new HashMap<>(); + for (int i = 0 ; i < number.length() ; i++) { + final int digit = number.charAt(i) - '0'; + frequencies.put(digit, frequencies.getOrDefault(digit, 0) + 1); + } + return frequencies; + } +} From 42be577eff8fe128632a8ca931954f0d605d61d9 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 27 May 2023 16:37:45 +0200 Subject: [PATCH 041/280] solves #2287: Rearrange Characters to Make Target String in java --- README.md | 2 +- ...RearrangeCharactersToMakeTargetString.java | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/RearrangeCharactersToMakeTargetString.java diff --git a/README.md b/README.md index 0c9362e..aa2323b 100644 --- a/README.md +++ b/README.md @@ -738,7 +738,7 @@ | 2273 | [Find Resultant Array After Removing Anagrams](https://leetcode.com/problems/find-resultant-array-after-removing-anagrams) | [![Java](assets/java.png)](src/FindResultantArrayAfterRemovingAnagrams.java) | | | 2278 | [Percentage of Letter in String](https://leetcode.com/problems/percentage-of-letter-in-string) | [![Java](assets/java.png)](src/PercentageOfLetterInString.java) | | | 2283 | [Check if Number Has Equal Digit Count and Digit Value](https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value) | [![Java](assets/java.png)](src/CheckIfNumberHasEqualDigitCountAndDigitValue.java) | | -| 2287 | [Rearrange Characters to Make Target String](https://leetcode.com/problems/rearrange-characters-to-make-target-string) | | | +| 2287 | [Rearrange Characters to Make Target String](https://leetcode.com/problems/rearrange-characters-to-make-target-string) | [![Java](assets/java.png)](src/RearrangeCharactersToMakeTargetString.java) | | | 2293 | [Min Max Game](https://leetcode.com/problems/min-max-game) | | | | 2299 | [Strong Password Checker II](https://leetcode.com/problems/strong-password-checker-ii) | | | | 2300 | [Successful Pairs of Spells and Potions](https://leetcode.com/problems/successful-pairs-of-spells-and-potions) | [![Python](assets/python.png)](python/successfull_pairs_of_spells_and_potions.py) | | diff --git a/src/RearrangeCharactersToMakeTargetString.java b/src/RearrangeCharactersToMakeTargetString.java new file mode 100644 index 0000000..5479f4a --- /dev/null +++ b/src/RearrangeCharactersToMakeTargetString.java @@ -0,0 +1,27 @@ +// https://leetcode.com/problems/rearrange-characters-to-make-target-string +// T: O(|s| + |target|) +// S: O(1) + +import java.util.HashMap; +import java.util.Map; + +public class RearrangeCharactersToMakeTargetString { + public int rearrangeCharacters(String s, String target) { + final Map sCharFrequencies = getCharFrequencies(s); + final Map targetCharFrequencies = getCharFrequencies(target); + + int maxCopies = Integer.MAX_VALUE; + for (char targetChar : targetCharFrequencies.keySet()) { + maxCopies = Math.min(maxCopies, sCharFrequencies.getOrDefault(targetChar, 0) / targetCharFrequencies.get(targetChar)); + } + return maxCopies; + } + + private Map getCharFrequencies(String string) { + final Map result = new HashMap<>(); + for (int i = 0 ; i < string.length() ; i++) { + result.put(string.charAt(i), result.getOrDefault(string.charAt(i), 0) + 1); + } + return result; + } +} From b71e7e45ddc5b04509984ac94b2d172603b27c9d Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 27 May 2023 16:51:50 +0200 Subject: [PATCH 042/280] solves #2293: Min Max Game in java --- README.md | 2 +- src/MinMaxGame.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/MinMaxGame.java diff --git a/README.md b/README.md index aa2323b..e5cc027 100644 --- a/README.md +++ b/README.md @@ -739,7 +739,7 @@ | 2278 | [Percentage of Letter in String](https://leetcode.com/problems/percentage-of-letter-in-string) | [![Java](assets/java.png)](src/PercentageOfLetterInString.java) | | | 2283 | [Check if Number Has Equal Digit Count and Digit Value](https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value) | [![Java](assets/java.png)](src/CheckIfNumberHasEqualDigitCountAndDigitValue.java) | | | 2287 | [Rearrange Characters to Make Target String](https://leetcode.com/problems/rearrange-characters-to-make-target-string) | [![Java](assets/java.png)](src/RearrangeCharactersToMakeTargetString.java) | | -| 2293 | [Min Max Game](https://leetcode.com/problems/min-max-game) | | | +| 2293 | [Min Max Game](https://leetcode.com/problems/min-max-game) | [![Java](assets/java.png)](src/MinMaxGame.java) | | | 2299 | [Strong Password Checker II](https://leetcode.com/problems/strong-password-checker-ii) | | | | 2300 | [Successful Pairs of Spells and Potions](https://leetcode.com/problems/successful-pairs-of-spells-and-potions) | [![Python](assets/python.png)](python/successfull_pairs_of_spells_and_potions.py) | | | 2303 | [Calculate Amount Paid in Taxes](https://leetcode.com/problems/calculate-amount-paid-in-taxes) | [![Python](assets/python.png)](python/successfull_pairs_of_spells_and_potions.py) | | diff --git a/src/MinMaxGame.java b/src/MinMaxGame.java new file mode 100644 index 0000000..526d7c1 --- /dev/null +++ b/src/MinMaxGame.java @@ -0,0 +1,14 @@ +// https://leetcode.com/problems/min-max-game +// T: O(N) +// S: O(1) + +public class MinMaxGame { + public int minMaxGame(int[] array) { + for (int len = array.length / 2 ; len > 1 ; len /= 2) { + for (int i = 0 ; i < len ; i++) { + array[i] = i % 2 == 0 ? Math.min(array[2 * i], array[2 * i + 1]) : Math.max(array[2 * i], array[2 * i + 1]); + } + } + return array[0]; + } +} From 4c93e45cc204734237bebe1c2f795fb660714ba8 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 27 May 2023 17:01:51 +0200 Subject: [PATCH 043/280] solves #2299: Strong Password Checker II in java --- README.md | 2 +- src/StrongPasswordCheckerII.java | 77 ++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 src/StrongPasswordCheckerII.java diff --git a/README.md b/README.md index e5cc027..5a9ec67 100644 --- a/README.md +++ b/README.md @@ -740,7 +740,7 @@ | 2283 | [Check if Number Has Equal Digit Count and Digit Value](https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value) | [![Java](assets/java.png)](src/CheckIfNumberHasEqualDigitCountAndDigitValue.java) | | | 2287 | [Rearrange Characters to Make Target String](https://leetcode.com/problems/rearrange-characters-to-make-target-string) | [![Java](assets/java.png)](src/RearrangeCharactersToMakeTargetString.java) | | | 2293 | [Min Max Game](https://leetcode.com/problems/min-max-game) | [![Java](assets/java.png)](src/MinMaxGame.java) | | -| 2299 | [Strong Password Checker II](https://leetcode.com/problems/strong-password-checker-ii) | | | +| 2299 | [Strong Password Checker II](https://leetcode.com/problems/strong-password-checker-ii) | [![Java](assets/java.png)](src/StrongPasswordCheckerII.java) | | | 2300 | [Successful Pairs of Spells and Potions](https://leetcode.com/problems/successful-pairs-of-spells-and-potions) | [![Python](assets/python.png)](python/successfull_pairs_of_spells_and_potions.py) | | | 2303 | [Calculate Amount Paid in Taxes](https://leetcode.com/problems/calculate-amount-paid-in-taxes) | [![Python](assets/python.png)](python/successfull_pairs_of_spells_and_potions.py) | | | 2315 | [Count Asterisks](https://leetcode.com/problems/count-asterisks) | [![Python](assets/python.png)](python/successfull_pairs_of_spells_and_potions.py) | | diff --git a/src/StrongPasswordCheckerII.java b/src/StrongPasswordCheckerII.java new file mode 100644 index 0000000..81de45f --- /dev/null +++ b/src/StrongPasswordCheckerII.java @@ -0,0 +1,77 @@ +// https://leetcode.com/problems/strong-password-checker-ii +// T: O(|password|) +// S: O(1) + +import java.util.HashSet; +import java.util.Set; + +public class StrongPasswordCheckerII { + private static final String SPECIAL_CHARACTERS = "!@#$%^&*()-+"; + + public boolean strongPasswordCheckerII(String password) { + return atLeastLen8(password) + && atLeast1LowercaseLetter(password) + && atLeast1UppercaseLetter(password) + && atLeast1Digit(password) + && atLeast1SpecialCharacter(password) + && noAdjacentSameCharacters(password); + } + + private boolean noAdjacentSameCharacters(String password) { + for (int i = 1 ; i < password.length() ; i++) { + if (password.charAt(i - 1) == password.charAt(i)) { + return false; + } + } + return true; + } + + private boolean atLeast1SpecialCharacter(String password) { + final Set characters = charactersOf(password); + for (int i = 0 ; i < SPECIAL_CHARACTERS.length() ; i++) { + if (characters.contains(SPECIAL_CHARACTERS.charAt(i))) { + return true; + } + } + return false; + } + + private Set charactersOf(String password) { + final Set set = new HashSet<>(); + for (int i = 0 ; i < password.length() ; i++) { + set.add(password.charAt(i)); + } + return set; + } + + private boolean atLeast1Digit(String password) { + for (int i = 0 ; i < password.length() ; i++) { + if (password.charAt(i) >= '0' && password.charAt(i) <= '9') { + return true; + } + } + return false; + } + + private boolean atLeast1UppercaseLetter(String password) { + for (int i = 0 ; i < password.length() ; i++) { + if (password.charAt(i) >= 'A' && password.charAt(i) <= 'Z') { + return true; + } + } + return false; + } + + private boolean atLeast1LowercaseLetter(String password) { + for (int i = 0 ; i < password.length() ; i++) { + if (password.charAt(i) >= 'a' && password.charAt(i) <= 'z') { + return true; + } + } + return false; + } + + private boolean atLeastLen8(String password) { + return password.length() >= 8; + } +} From 9566fadc5c71076aad9f384ef696c9e34069b92c Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 27 May 2023 17:36:30 +0200 Subject: [PATCH 044/280] solves #2303: Calculate Amount Paid in Taxes n java --- README.md | 2 +- src/CalculateAmountPaidInTaxes.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/CalculateAmountPaidInTaxes.java diff --git a/README.md b/README.md index 5a9ec67..be85343 100644 --- a/README.md +++ b/README.md @@ -742,7 +742,7 @@ | 2293 | [Min Max Game](https://leetcode.com/problems/min-max-game) | [![Java](assets/java.png)](src/MinMaxGame.java) | | | 2299 | [Strong Password Checker II](https://leetcode.com/problems/strong-password-checker-ii) | [![Java](assets/java.png)](src/StrongPasswordCheckerII.java) | | | 2300 | [Successful Pairs of Spells and Potions](https://leetcode.com/problems/successful-pairs-of-spells-and-potions) | [![Python](assets/python.png)](python/successfull_pairs_of_spells_and_potions.py) | | -| 2303 | [Calculate Amount Paid in Taxes](https://leetcode.com/problems/calculate-amount-paid-in-taxes) | [![Python](assets/python.png)](python/successfull_pairs_of_spells_and_potions.py) | | +| 2303 | [Calculate Amount Paid in Taxes](https://leetcode.com/problems/calculate-amount-paid-in-taxes) | [![Java](assets/java.png)](src/CalculateAmountPaidInTaxes.java) [![Python](assets/python.png)](python/successfull_pairs_of_spells_and_potions.py) | | | 2315 | [Count Asterisks](https://leetcode.com/problems/count-asterisks) | [![Python](assets/python.png)](python/successfull_pairs_of_spells_and_potions.py) | | | 2316 | [Count Unreachable Pairs of Nodes in an Undirected Graph](https://leetcode.com/problems/count-unreachable-pairs-of-nodes-in-an-undirected-graph) | [![Python](assets/python.png)](python/count_unreachable_pair_of_node_in_an_undirectable_graph.py) | | | 2319 | [Check if Matrix Is X-Matrix](https://leetcode.com/problems/check-if-matrix-is-x-matrix) | [![Python](assets/python.png)](python/count_unreachable_pair_of_node_in_an_undirectable_graph.py) | | diff --git a/src/CalculateAmountPaidInTaxes.java b/src/CalculateAmountPaidInTaxes.java new file mode 100644 index 0000000..9f16980 --- /dev/null +++ b/src/CalculateAmountPaidInTaxes.java @@ -0,0 +1,17 @@ +// https://leetcode.com/problems/calculate-amount-paid-in-taxes +// T: O(|brackets|) +// S: O(1) + +public class CalculateAmountPaidInTaxes { + public double calculateTax(int[][] brackets, int income) { + double tax = 0; + int ceiling = 0; + for (int i = 0 ; i < brackets.length && income > 0 ; i++) { + final int taxableIncome = Math.min(brackets[i][0] - ceiling, income); + income -= taxableIncome; + ceiling = brackets[i][0]; + tax += taxableIncome * ((double) brackets[i][1] / 100); + } + return tax; + } +} From 7270c6c8d2b48c967b9145ee3359d4807cb643dc Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 27 May 2023 17:47:14 +0200 Subject: [PATCH 045/280] solves #2309: Greatest English Letter in Upper and Lower Case in java --- README.md | 3 +- ...atestEnglishLetterInUpperAndLowerCase.java | 42 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 src/GreatestEnglishLetterInUpperAndLowerCase.java diff --git a/README.md b/README.md index be85343..bec5ac2 100644 --- a/README.md +++ b/README.md @@ -742,7 +742,8 @@ | 2293 | [Min Max Game](https://leetcode.com/problems/min-max-game) | [![Java](assets/java.png)](src/MinMaxGame.java) | | | 2299 | [Strong Password Checker II](https://leetcode.com/problems/strong-password-checker-ii) | [![Java](assets/java.png)](src/StrongPasswordCheckerII.java) | | | 2300 | [Successful Pairs of Spells and Potions](https://leetcode.com/problems/successful-pairs-of-spells-and-potions) | [![Python](assets/python.png)](python/successfull_pairs_of_spells_and_potions.py) | | -| 2303 | [Calculate Amount Paid in Taxes](https://leetcode.com/problems/calculate-amount-paid-in-taxes) | [![Java](assets/java.png)](src/CalculateAmountPaidInTaxes.java) [![Python](assets/python.png)](python/successfull_pairs_of_spells_and_potions.py) | | +| 2303 | [Calculate Amount Paid in Taxes](https://leetcode.com/problems/calculate-amount-paid-in-taxes) | [![Java](assets/java.png)](src/CalculateAmountPaidInTaxes.java) | | +| 2309 | [Greatest English Letter in Upper and Lower Case](https://leetcode.com/problems/greatest-english-letter-in-upper-and-lower-case) | [![Java](assets/java.png)](src/GreatestEnglishLetterInUpperAndLowerCase.java) | | | 2315 | [Count Asterisks](https://leetcode.com/problems/count-asterisks) | [![Python](assets/python.png)](python/successfull_pairs_of_spells_and_potions.py) | | | 2316 | [Count Unreachable Pairs of Nodes in an Undirected Graph](https://leetcode.com/problems/count-unreachable-pairs-of-nodes-in-an-undirected-graph) | [![Python](assets/python.png)](python/count_unreachable_pair_of_node_in_an_undirectable_graph.py) | | | 2319 | [Check if Matrix Is X-Matrix](https://leetcode.com/problems/check-if-matrix-is-x-matrix) | [![Python](assets/python.png)](python/count_unreachable_pair_of_node_in_an_undirectable_graph.py) | | diff --git a/src/GreatestEnglishLetterInUpperAndLowerCase.java b/src/GreatestEnglishLetterInUpperAndLowerCase.java new file mode 100644 index 0000000..b8c55ae --- /dev/null +++ b/src/GreatestEnglishLetterInUpperAndLowerCase.java @@ -0,0 +1,42 @@ +// https://leetcode.com/problems/greatest-english-letter-in-upper-and-lower-case +// T: O(|s|) +// S: O(1) + +import java.util.HashSet; +import java.util.Set; + +public class GreatestEnglishLetterInUpperAndLowerCase { + public String greatestLetter(String s) { + final Set lowercaseLetters = getLowercaseLetters(s); + final Set uppercaseLetters = getUppercaseLetters(s); + char maxLetter = 'a' - 1; + + for (char letter : lowercaseLetters) { + if (uppercaseLetters.contains(Character.toUpperCase(letter)) && letter > maxLetter) { + maxLetter = letter; + } + } + + return maxLetter >= 'a' ? (Character.toUpperCase(maxLetter) + "") : ""; + } + + private Set getUppercaseLetters(String string) { + final Set set = new HashSet<>(); + for (int i = 0 ; i < string.length() ; i++) { + if (Character.isUpperCase(string.charAt(i))) { + set.add(string.charAt(i)); + } + } + return set; + } + + private Set getLowercaseLetters(String string) { + final Set set = new HashSet<>(); + for (int i = 0 ; i < string.length() ; i++) { + if (Character.isLowerCase(string.charAt(i))) { + set.add(string.charAt(i)); + } + } + return set; + } +} From f7decc8cf82300585fe6a78832c38de2f71e1bbc Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 27 May 2023 17:54:48 +0200 Subject: [PATCH 046/280] solves #2315: Count Asterisks in java --- README.md | 2 +- src/CountAsterisks.java | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/CountAsterisks.java diff --git a/README.md b/README.md index bec5ac2..57ce40e 100644 --- a/README.md +++ b/README.md @@ -744,7 +744,7 @@ | 2300 | [Successful Pairs of Spells and Potions](https://leetcode.com/problems/successful-pairs-of-spells-and-potions) | [![Python](assets/python.png)](python/successfull_pairs_of_spells_and_potions.py) | | | 2303 | [Calculate Amount Paid in Taxes](https://leetcode.com/problems/calculate-amount-paid-in-taxes) | [![Java](assets/java.png)](src/CalculateAmountPaidInTaxes.java) | | | 2309 | [Greatest English Letter in Upper and Lower Case](https://leetcode.com/problems/greatest-english-letter-in-upper-and-lower-case) | [![Java](assets/java.png)](src/GreatestEnglishLetterInUpperAndLowerCase.java) | | -| 2315 | [Count Asterisks](https://leetcode.com/problems/count-asterisks) | [![Python](assets/python.png)](python/successfull_pairs_of_spells_and_potions.py) | | +| 2315 | [Count Asterisks](https://leetcode.com/problems/count-asterisks) | [![Java](assets/java.png)](src/CountAsterisks.java) [![Python](assets/python.png)](python/successfull_pairs_of_spells_and_potions.py) | | | 2316 | [Count Unreachable Pairs of Nodes in an Undirected Graph](https://leetcode.com/problems/count-unreachable-pairs-of-nodes-in-an-undirected-graph) | [![Python](assets/python.png)](python/count_unreachable_pair_of_node_in_an_undirectable_graph.py) | | | 2319 | [Check if Matrix Is X-Matrix](https://leetcode.com/problems/check-if-matrix-is-x-matrix) | [![Python](assets/python.png)](python/count_unreachable_pair_of_node_in_an_undirectable_graph.py) | | | 2325 | [Decode the Message](https://leetcode.com/problems/decode-the-message) | [![Python](assets/python.png)](python/count_unreachable_pair_of_node_in_an_undirectable_graph.py) | | diff --git a/src/CountAsterisks.java b/src/CountAsterisks.java new file mode 100644 index 0000000..f164cfa --- /dev/null +++ b/src/CountAsterisks.java @@ -0,0 +1,26 @@ +// https://leetcode.com/problems/count-asterisks +// T: O(|s|) +// S: O(1) + +public class CountAsterisks { + public int countAsterisks(String s) { + boolean seenPipe = false; + int count = 0, pipeBuffer = 0; + + for (int index = 0 ; index < s.length() ; index++) { + if (s.charAt(index) == '|') { + if (seenPipe) { + pipeBuffer = 0; + } + seenPipe = !seenPipe; + } + + if (s.charAt(index) == '*') { + if (seenPipe) pipeBuffer++; + else count++; + } + } + + return count + pipeBuffer; + } +} From 3f7f66d0f5777bc87def46bedb6faee079b16f03 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 27 May 2023 18:06:03 +0200 Subject: [PATCH 047/280] solves #2319: Check if Matrix Is X-Matrix in java --- README.md | 4 ++-- src/CheckIfMatrixIsXMatrix.java | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 src/CheckIfMatrixIsXMatrix.java diff --git a/README.md b/README.md index 57ce40e..a6feba1 100644 --- a/README.md +++ b/README.md @@ -744,9 +744,9 @@ | 2300 | [Successful Pairs of Spells and Potions](https://leetcode.com/problems/successful-pairs-of-spells-and-potions) | [![Python](assets/python.png)](python/successfull_pairs_of_spells_and_potions.py) | | | 2303 | [Calculate Amount Paid in Taxes](https://leetcode.com/problems/calculate-amount-paid-in-taxes) | [![Java](assets/java.png)](src/CalculateAmountPaidInTaxes.java) | | | 2309 | [Greatest English Letter in Upper and Lower Case](https://leetcode.com/problems/greatest-english-letter-in-upper-and-lower-case) | [![Java](assets/java.png)](src/GreatestEnglishLetterInUpperAndLowerCase.java) | | -| 2315 | [Count Asterisks](https://leetcode.com/problems/count-asterisks) | [![Java](assets/java.png)](src/CountAsterisks.java) [![Python](assets/python.png)](python/successfull_pairs_of_spells_and_potions.py) | | +| 2315 | [Count Asterisks](https://leetcode.com/problems/count-asterisks) | [![Java](assets/java.png)](src/CountAsterisks.java) [![Python](assets/python.png)](python/successfull_pairs_of_spells_and_potions.py) | | | 2316 | [Count Unreachable Pairs of Nodes in an Undirected Graph](https://leetcode.com/problems/count-unreachable-pairs-of-nodes-in-an-undirected-graph) | [![Python](assets/python.png)](python/count_unreachable_pair_of_node_in_an_undirectable_graph.py) | | -| 2319 | [Check if Matrix Is X-Matrix](https://leetcode.com/problems/check-if-matrix-is-x-matrix) | [![Python](assets/python.png)](python/count_unreachable_pair_of_node_in_an_undirectable_graph.py) | | +| 2319 | [Check if Matrix Is X-Matrix](https://leetcode.com/problems/check-if-matrix-is-x-matrix) | [![Java](assets/java.png)](src/CountAsterisks.java) | | | 2325 | [Decode the Message](https://leetcode.com/problems/decode-the-message) | [![Python](assets/python.png)](python/count_unreachable_pair_of_node_in_an_undirectable_graph.py) | | | 2331 | [Evaluate Boolean Binary Tree](https://leetcode.com/problems/evaluate-boolean-binary-tree) | [![Python](assets/python.png)](python/count_unreachable_pair_of_node_in_an_undirectable_graph.py) | | | 2335 | [Minimum Amount of Time to Fill Cups](https://leetcode.com/problems/minimum-amount-of-time-to-fill-cups) | [![Python](assets/python.png)](python/count_unreachable_pair_of_node_in_an_undirectable_graph.py) | | diff --git a/src/CheckIfMatrixIsXMatrix.java b/src/CheckIfMatrixIsXMatrix.java new file mode 100644 index 0000000..bf5fd5a --- /dev/null +++ b/src/CheckIfMatrixIsXMatrix.java @@ -0,0 +1,20 @@ +// https://leetcode.com/problems/check-if-matrix-is-x-matrix +// T: O(n * n) +// S: O(1) + +public class CheckIfMatrixIsXMatrix { + public boolean checkXMatrix(int[][] grid) { + for (int row = 0 ; row < grid.length ; row++) { + for (int column = 0 ; column < grid.length ; column++) { + if (isDiagonalCell(row, column, grid.length)) { + if (grid[row][column] == 0) return false; + } else if (grid[row][column] != 0) return false; + } + } + return true; + } + + private boolean isDiagonalCell(int row, int column, int length) { + return row == column || column == length - row - 1; + } +} From 9bc7dfa1d4ae3bc220d8d838a3e3ecb5b912a94f Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 27 May 2023 18:15:47 +0200 Subject: [PATCH 048/280] solves #2325: Decode the Message in java --- README.md | 14 +++++++------- src/DecodeTheMessage.java | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 src/DecodeTheMessage.java diff --git a/README.md b/README.md index a6feba1..2ac86dc 100644 --- a/README.md +++ b/README.md @@ -747,15 +747,15 @@ | 2315 | [Count Asterisks](https://leetcode.com/problems/count-asterisks) | [![Java](assets/java.png)](src/CountAsterisks.java) [![Python](assets/python.png)](python/successfull_pairs_of_spells_and_potions.py) | | | 2316 | [Count Unreachable Pairs of Nodes in an Undirected Graph](https://leetcode.com/problems/count-unreachable-pairs-of-nodes-in-an-undirected-graph) | [![Python](assets/python.png)](python/count_unreachable_pair_of_node_in_an_undirectable_graph.py) | | | 2319 | [Check if Matrix Is X-Matrix](https://leetcode.com/problems/check-if-matrix-is-x-matrix) | [![Java](assets/java.png)](src/CountAsterisks.java) | | -| 2325 | [Decode the Message](https://leetcode.com/problems/decode-the-message) | [![Python](assets/python.png)](python/count_unreachable_pair_of_node_in_an_undirectable_graph.py) | | -| 2331 | [Evaluate Boolean Binary Tree](https://leetcode.com/problems/evaluate-boolean-binary-tree) | [![Python](assets/python.png)](python/count_unreachable_pair_of_node_in_an_undirectable_graph.py) | | -| 2335 | [Minimum Amount of Time to Fill Cups](https://leetcode.com/problems/minimum-amount-of-time-to-fill-cups) | [![Python](assets/python.png)](python/count_unreachable_pair_of_node_in_an_undirectable_graph.py) | | +| 2325 | [Decode the Message](https://leetcode.com/problems/decode-the-message) | [![Java](assets/java.png)](src/DecodeTheMessage.java) | | +| 2331 | [Evaluate Boolean Binary Tree](https://leetcode.com/problems/evaluate-boolean-binary-tree) | | | +| 2335 | [Minimum Amount of Time to Fill Cups](https://leetcode.com/problems/minimum-amount-of-time-to-fill-cups) | | | | 2439 | [Minimize Maximum of Array](https://leetcode.com/problems/minimize-maximum-of-array) | [![Python](assets/python.png)](python/minimize_maximum_of_array.py) | | -| 2341 | [Maximum Number of Pairs in Array](https://leetcode.com/problems/maximum-number-of-pairs-in-array) | [![Python](assets/python.png)](python/count_unreachable_pair_of_node_in_an_undirectable_graph.py) | | -| 2347 | [Best Poker Hand](https://leetcode.com/problems/best-poker-hand) | [![Python](assets/python.png)](python/count_unreachable_pair_of_node_in_an_undirectable_graph.py) | | +| 2341 | [Maximum Number of Pairs in Array](https://leetcode.com/problems/maximum-number-of-pairs-in-array) | | | +| 2347 | [Best Poker Hand](https://leetcode.com/problems/best-poker-hand) | | | | 2348 | [Number of Zero-Filled Subarrays](https://leetcode.com/problems/number-of-zero-filled-subarrays) | [![Python](assets/python.png)](python/number_of_zero_filled_subarrays.py) | | -| 2351 | [First Letter to Appear Twice](https://leetcode.com/problems/first-letter-to-appear-twice) | [![Python](assets/python.png)](python/count_unreachable_pair_of_node_in_an_undirectable_graph.py) | | -| 2357 | [Make Array Zero by Subtracting Equal Amounts](https://leetcode.com/problems/make-array-zero-by-subtracting-equal-amounts) | [![Python](assets/python.png)](python/count_unreachable_pair_of_node_in_an_undirectable_graph.py) | | +| 2351 | [First Letter to Appear Twice](https://leetcode.com/problems/first-letter-to-appear-twice) | | | +| 2357 | [Make Array Zero by Subtracting Equal Amounts](https://leetcode.com/problems/make-array-zero-by-subtracting-equal-amounts) | | | | 2360 | [Longest Cycle in a Graph](https://leetcode.com/problems/longest-cycle-in-a-graph) | [![Python](assets/python.png)](python/longest_cycle_in_graph.py) | | | 2363 | [Merge Similar Items](https://leetcode.com/problems/merge-similar-items) | | | | 2367 | [Number of Arithmetic Triplets](https://leetcode.com/problems/number-of-arithmetic-triplets) | | | diff --git a/src/DecodeTheMessage.java b/src/DecodeTheMessage.java new file mode 100644 index 0000000..f8efdb2 --- /dev/null +++ b/src/DecodeTheMessage.java @@ -0,0 +1,35 @@ +// https://leetcode.com/problems/decode-the-message +// T: O(|key| + |message|) +// S: O(1) + +import java.util.HashMap; +import java.util.Map; + +public class DecodeTheMessage { + public String decodeMessage(String key, String message) { + final Map mapping = getSubstitutionMap(key); + final StringBuilder result = new StringBuilder(); + System.out.println(mapping); + + for (int index = 0 ; index < message.length() ; index++) { + if (message.charAt(index) == ' ') { + result.append(' '); + } else { + result.append(mapping.get(message.charAt(index))); + } + } + + return result.toString(); + } + + private Map getSubstitutionMap(String key) { + final Map result = new HashMap<>(); + char letter = 'a'; + for (int index = 0 ; index < key.length() ; index++) { + if (!result.containsKey(key.charAt(index)) && key.charAt(index) != ' ') { + result.put(key.charAt(index), letter++); + } + } + return result; + } +} From 36b6ee6f865f47a4a7bd750854d394db3acd83a4 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 27 May 2023 18:20:09 +0200 Subject: [PATCH 049/280] solves #2331: Evaluate Boolean Binary Tree in java --- README.md | 2 +- src/EvaluateBooleanBinaryTree.java | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 src/EvaluateBooleanBinaryTree.java diff --git a/README.md b/README.md index 2ac86dc..37de201 100644 --- a/README.md +++ b/README.md @@ -748,7 +748,7 @@ | 2316 | [Count Unreachable Pairs of Nodes in an Undirected Graph](https://leetcode.com/problems/count-unreachable-pairs-of-nodes-in-an-undirected-graph) | [![Python](assets/python.png)](python/count_unreachable_pair_of_node_in_an_undirectable_graph.py) | | | 2319 | [Check if Matrix Is X-Matrix](https://leetcode.com/problems/check-if-matrix-is-x-matrix) | [![Java](assets/java.png)](src/CountAsterisks.java) | | | 2325 | [Decode the Message](https://leetcode.com/problems/decode-the-message) | [![Java](assets/java.png)](src/DecodeTheMessage.java) | | -| 2331 | [Evaluate Boolean Binary Tree](https://leetcode.com/problems/evaluate-boolean-binary-tree) | | | +| 2331 | [Evaluate Boolean Binary Tree](https://leetcode.com/problems/evaluate-boolean-binary-tree) | [![Java](assets/java.png)](src/EvaluateBooleanBinaryTree.java) | | | 2335 | [Minimum Amount of Time to Fill Cups](https://leetcode.com/problems/minimum-amount-of-time-to-fill-cups) | | | | 2439 | [Minimize Maximum of Array](https://leetcode.com/problems/minimize-maximum-of-array) | [![Python](assets/python.png)](python/minimize_maximum_of_array.py) | | | 2341 | [Maximum Number of Pairs in Array](https://leetcode.com/problems/maximum-number-of-pairs-in-array) | | | diff --git a/src/EvaluateBooleanBinaryTree.java b/src/EvaluateBooleanBinaryTree.java new file mode 100644 index 0000000..474702e --- /dev/null +++ b/src/EvaluateBooleanBinaryTree.java @@ -0,0 +1,21 @@ +// https://leetcode.com/problems/evaluate-boolean-binary-tree +// T: O(N) +// S: O(log(N)) + +public class EvaluateBooleanBinaryTree { + public boolean evaluateTree(TreeNode root) { + if (isLeafNode(root)) { + return root.val == 1; + } + + if (root.val == 2) { + return evaluateTree(root.left) || evaluateTree(root.right); + } + + return evaluateTree(root.left) && evaluateTree(root.right); + } + + private boolean isLeafNode(TreeNode root) { + return root.left == null && root.right == null; + } +} From 187a7fbdfe6bf796bf19b834cccf990dbecef1a4 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 27 May 2023 18:33:41 +0200 Subject: [PATCH 050/280] solves #2335: Minimum Amount of Time to Fill Cups in java --- README.md | 2 +- src/MinimumAmountOfTimeToFillCups.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/MinimumAmountOfTimeToFillCups.java diff --git a/README.md b/README.md index 37de201..265a8ad 100644 --- a/README.md +++ b/README.md @@ -749,7 +749,7 @@ | 2319 | [Check if Matrix Is X-Matrix](https://leetcode.com/problems/check-if-matrix-is-x-matrix) | [![Java](assets/java.png)](src/CountAsterisks.java) | | | 2325 | [Decode the Message](https://leetcode.com/problems/decode-the-message) | [![Java](assets/java.png)](src/DecodeTheMessage.java) | | | 2331 | [Evaluate Boolean Binary Tree](https://leetcode.com/problems/evaluate-boolean-binary-tree) | [![Java](assets/java.png)](src/EvaluateBooleanBinaryTree.java) | | -| 2335 | [Minimum Amount of Time to Fill Cups](https://leetcode.com/problems/minimum-amount-of-time-to-fill-cups) | | | +| 2335 | [Minimum Amount of Time to Fill Cups](https://leetcode.com/problems/minimum-amount-of-time-to-fill-cups) | [![Java](assets/java.png)](src/MinimumAmountOfTimeToFillCups.java) | | | 2439 | [Minimize Maximum of Array](https://leetcode.com/problems/minimize-maximum-of-array) | [![Python](assets/python.png)](python/minimize_maximum_of_array.py) | | | 2341 | [Maximum Number of Pairs in Array](https://leetcode.com/problems/maximum-number-of-pairs-in-array) | | | | 2347 | [Best Poker Hand](https://leetcode.com/problems/best-poker-hand) | | | diff --git a/src/MinimumAmountOfTimeToFillCups.java b/src/MinimumAmountOfTimeToFillCups.java new file mode 100644 index 0000000..3d94c30 --- /dev/null +++ b/src/MinimumAmountOfTimeToFillCups.java @@ -0,0 +1,14 @@ +// https://leetcode.com/problems/minimum-amount-of-time-to-fill-cups +// T: O(1) +// S: O(1) + +import java.util.Arrays; + +public class MinimumAmountOfTimeToFillCups { + public int fillCups(int[] amount) { + return Math.max( + Arrays.stream(amount).max().getAsInt(), + (Arrays.stream(amount).sum() + 1) / 2 + ); + } +} From 5a7ad7fcc8cef51790f19691915a88624ad509df Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 27 May 2023 19:04:13 +0200 Subject: [PATCH 051/280] solves #2341: Maximum Number of Pairs in Array in java --- README.md | 2 +- src/MaximumNumberOfPairsInArray.java | 30 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/MaximumNumberOfPairsInArray.java diff --git a/README.md b/README.md index 265a8ad..2b51a00 100644 --- a/README.md +++ b/README.md @@ -751,7 +751,7 @@ | 2331 | [Evaluate Boolean Binary Tree](https://leetcode.com/problems/evaluate-boolean-binary-tree) | [![Java](assets/java.png)](src/EvaluateBooleanBinaryTree.java) | | | 2335 | [Minimum Amount of Time to Fill Cups](https://leetcode.com/problems/minimum-amount-of-time-to-fill-cups) | [![Java](assets/java.png)](src/MinimumAmountOfTimeToFillCups.java) | | | 2439 | [Minimize Maximum of Array](https://leetcode.com/problems/minimize-maximum-of-array) | [![Python](assets/python.png)](python/minimize_maximum_of_array.py) | | -| 2341 | [Maximum Number of Pairs in Array](https://leetcode.com/problems/maximum-number-of-pairs-in-array) | | | +| 2341 | [Maximum Number of Pairs in Array](https://leetcode.com/problems/maximum-number-of-pairs-in-array) | [![Java](assets/java.png)](src/MaximumNumberOfPairsInArray.java) | | | 2347 | [Best Poker Hand](https://leetcode.com/problems/best-poker-hand) | | | | 2348 | [Number of Zero-Filled Subarrays](https://leetcode.com/problems/number-of-zero-filled-subarrays) | [![Python](assets/python.png)](python/number_of_zero_filled_subarrays.py) | | | 2351 | [First Letter to Appear Twice](https://leetcode.com/problems/first-letter-to-appear-twice) | | | diff --git a/src/MaximumNumberOfPairsInArray.java b/src/MaximumNumberOfPairsInArray.java new file mode 100644 index 0000000..aa96fe1 --- /dev/null +++ b/src/MaximumNumberOfPairsInArray.java @@ -0,0 +1,30 @@ +// https://leetcode.com/problems/maximum-number-of-pairs-in-array +// T: O(N) +// S: O(N) + +import java.util.HashMap; +import java.util.Map; + +public class MaximumNumberOfPairsInArray { + public int[] numberOfPairs(int[] nums) { + final Map digitFrequencies = getFrequencies(nums); + final int numberOfPairs = getNumberOfPairs(digitFrequencies); + return new int[] { numberOfPairs, nums.length - 2 * numberOfPairs }; + } + + private int getNumberOfPairs(Map frequencies) { + int result = 0; + for (int frequency : frequencies.values()) { + result += frequency / 2; + } + return result; + } + + private Map getFrequencies(int[] array) { + final Map result = new HashMap<>(); + for (int element : array) { + result.put(element, result.getOrDefault(element, 0) + 1); + } + return result; + } +} From bd38977039a14540ebbc32251247e63f973d334c Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 27 May 2023 19:40:16 +0200 Subject: [PATCH 052/280] solves #2347: Best Poker Hand in jav a --- README.md | 2 +- src/BestPokerHand.java | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 src/BestPokerHand.java diff --git a/README.md b/README.md index 2b51a00..e84f81e 100644 --- a/README.md +++ b/README.md @@ -752,7 +752,7 @@ | 2335 | [Minimum Amount of Time to Fill Cups](https://leetcode.com/problems/minimum-amount-of-time-to-fill-cups) | [![Java](assets/java.png)](src/MinimumAmountOfTimeToFillCups.java) | | | 2439 | [Minimize Maximum of Array](https://leetcode.com/problems/minimize-maximum-of-array) | [![Python](assets/python.png)](python/minimize_maximum_of_array.py) | | | 2341 | [Maximum Number of Pairs in Array](https://leetcode.com/problems/maximum-number-of-pairs-in-array) | [![Java](assets/java.png)](src/MaximumNumberOfPairsInArray.java) | | -| 2347 | [Best Poker Hand](https://leetcode.com/problems/best-poker-hand) | | | +| 2347 | [Best Poker Hand](https://leetcode.com/problems/best-poker-hand) | [![Java](assets/java.png)](src/BestPokerHand.java) | | | 2348 | [Number of Zero-Filled Subarrays](https://leetcode.com/problems/number-of-zero-filled-subarrays) | [![Python](assets/python.png)](python/number_of_zero_filled_subarrays.py) | | | 2351 | [First Letter to Appear Twice](https://leetcode.com/problems/first-letter-to-appear-twice) | | | | 2357 | [Make Array Zero by Subtracting Equal Amounts](https://leetcode.com/problems/make-array-zero-by-subtracting-equal-amounts) | | | diff --git a/src/BestPokerHand.java b/src/BestPokerHand.java new file mode 100644 index 0000000..0388bac --- /dev/null +++ b/src/BestPokerHand.java @@ -0,0 +1,42 @@ +// https://leetcode.com/problems/best-poker-hand +// T: O(1) +// S: O(1) + +import java.util.HashMap; +import java.util.Map; + +public class BestPokerHand { + public String bestHand(int[] ranks, char[] suits) { + if (sameSuit(suits)) { + return "Flush"; + } + + final Map frequencies = getFrequencies(ranks); + final int maxFrequency = frequencies.values().stream().max(Integer::compare).get(); + + if (maxFrequency >= 3) { + return "Three of a Kind"; + } + if (maxFrequency == 2) { + return "Pair"; + } + + return "High Card"; + } + + private Map getFrequencies(int[] ranks) { + final Map frequencies = new HashMap<>(); + for (int rank : ranks) { + frequencies.put(rank, frequencies.getOrDefault(rank, 0) + 1); + } + return frequencies; + } + + private boolean sameSuit(char[] suits) { + char first = suits[0]; + for (char suit : suits) { + if (suit != first) return false; + } + return true; + } +} From a08df919f07d2f9ea06f79ed49dbb4d241a66ce8 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 27 May 2023 19:45:14 +0200 Subject: [PATCH 053/280] solves #2351: First Letter to Appear Twice in java --- README.md | 2 +- src/FirstLetterToAppearTwice.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/FirstLetterToAppearTwice.java diff --git a/README.md b/README.md index e84f81e..0b9d062 100644 --- a/README.md +++ b/README.md @@ -754,7 +754,7 @@ | 2341 | [Maximum Number of Pairs in Array](https://leetcode.com/problems/maximum-number-of-pairs-in-array) | [![Java](assets/java.png)](src/MaximumNumberOfPairsInArray.java) | | | 2347 | [Best Poker Hand](https://leetcode.com/problems/best-poker-hand) | [![Java](assets/java.png)](src/BestPokerHand.java) | | | 2348 | [Number of Zero-Filled Subarrays](https://leetcode.com/problems/number-of-zero-filled-subarrays) | [![Python](assets/python.png)](python/number_of_zero_filled_subarrays.py) | | -| 2351 | [First Letter to Appear Twice](https://leetcode.com/problems/first-letter-to-appear-twice) | | | +| 2351 | [First Letter to Appear Twice](https://leetcode.com/problems/first-letter-to-appear-twice) | [![Java](assets/java.png)](src/FirstLetterToAppearTwice.java) | | | 2357 | [Make Array Zero by Subtracting Equal Amounts](https://leetcode.com/problems/make-array-zero-by-subtracting-equal-amounts) | | | | 2360 | [Longest Cycle in a Graph](https://leetcode.com/problems/longest-cycle-in-a-graph) | [![Python](assets/python.png)](python/longest_cycle_in_graph.py) | | | 2363 | [Merge Similar Items](https://leetcode.com/problems/merge-similar-items) | | | diff --git a/src/FirstLetterToAppearTwice.java b/src/FirstLetterToAppearTwice.java new file mode 100644 index 0000000..7843b26 --- /dev/null +++ b/src/FirstLetterToAppearTwice.java @@ -0,0 +1,19 @@ +// https://leetcode.com/problems/first-letter-to-appear-twice +// T: O(1) +// S: O(1) + +import java.util.HashSet; +import java.util.Set; + +public class FirstLetterToAppearTwice { + public char repeatedCharacter(String s) { + final Set characters = new HashSet<>(); + for (int index = 0 ; index < s.length() ; index++) { + if (characters.contains(s.charAt(index))) { + return s.charAt(index); + } + characters.add(s.charAt(index)); + } + return 'a'; + } +} From fe3950af70a3929b97bebc739409468015470283 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 27 May 2023 19:51:58 +0200 Subject: [PATCH 054/280] solves #2357: Make Array Zero by Subtracting Equal Amounts in java --- README.md | 2 +- ...MakeArrayZeroBySubtractingEqualAmounts.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/MakeArrayZeroBySubtractingEqualAmounts.java diff --git a/README.md b/README.md index 0b9d062..858c7df 100644 --- a/README.md +++ b/README.md @@ -755,7 +755,7 @@ | 2347 | [Best Poker Hand](https://leetcode.com/problems/best-poker-hand) | [![Java](assets/java.png)](src/BestPokerHand.java) | | | 2348 | [Number of Zero-Filled Subarrays](https://leetcode.com/problems/number-of-zero-filled-subarrays) | [![Python](assets/python.png)](python/number_of_zero_filled_subarrays.py) | | | 2351 | [First Letter to Appear Twice](https://leetcode.com/problems/first-letter-to-appear-twice) | [![Java](assets/java.png)](src/FirstLetterToAppearTwice.java) | | -| 2357 | [Make Array Zero by Subtracting Equal Amounts](https://leetcode.com/problems/make-array-zero-by-subtracting-equal-amounts) | | | +| 2357 | [Make Array Zero by Subtracting Equal Amounts](https://leetcode.com/problems/make-array-zero-by-subtracting-equal-amounts) | [![Java](assets/java.png)](src/MakeArrayZeroBySubtractingEqualAmounts.java) | | | 2360 | [Longest Cycle in a Graph](https://leetcode.com/problems/longest-cycle-in-a-graph) | [![Python](assets/python.png)](python/longest_cycle_in_graph.py) | | | 2363 | [Merge Similar Items](https://leetcode.com/problems/merge-similar-items) | | | | 2367 | [Number of Arithmetic Triplets](https://leetcode.com/problems/number-of-arithmetic-triplets) | | | diff --git a/src/MakeArrayZeroBySubtractingEqualAmounts.java b/src/MakeArrayZeroBySubtractingEqualAmounts.java new file mode 100644 index 0000000..65ff7c8 --- /dev/null +++ b/src/MakeArrayZeroBySubtractingEqualAmounts.java @@ -0,0 +1,18 @@ +// https://leetcode.com/problems/make-array-zero-by-subtracting-equal-amounts +// T: O(|nums|) +// S: O(|nums|) + +import java.util.HashSet; +import java.util.Set; + +public class MakeArrayZeroBySubtractingEqualAmounts { + public int minimumOperations(int[] nums) { + final Set set = new HashSet<>(); + for (int element : nums) { + if (element != 0) { + set.add(element); + } + } + return set.size(); + } +} From a2ffa093a7183e5e7b98126bbbd5f70052174c03 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 29 May 2023 14:57:49 +0200 Subject: [PATCH 055/280] solves #2363: Merge Similar Items in java --- README.md | 2 +- src/MergeSimilarItems.java | 42 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 src/MergeSimilarItems.java diff --git a/README.md b/README.md index 858c7df..6481d75 100644 --- a/README.md +++ b/README.md @@ -757,7 +757,7 @@ | 2351 | [First Letter to Appear Twice](https://leetcode.com/problems/first-letter-to-appear-twice) | [![Java](assets/java.png)](src/FirstLetterToAppearTwice.java) | | | 2357 | [Make Array Zero by Subtracting Equal Amounts](https://leetcode.com/problems/make-array-zero-by-subtracting-equal-amounts) | [![Java](assets/java.png)](src/MakeArrayZeroBySubtractingEqualAmounts.java) | | | 2360 | [Longest Cycle in a Graph](https://leetcode.com/problems/longest-cycle-in-a-graph) | [![Python](assets/python.png)](python/longest_cycle_in_graph.py) | | -| 2363 | [Merge Similar Items](https://leetcode.com/problems/merge-similar-items) | | | +| 2363 | [Merge Similar Items](https://leetcode.com/problems/merge-similar-items) | [![Java](assets/java.png)](src/MergeSimilarItems.java) | | | 2367 | [Number of Arithmetic Triplets](https://leetcode.com/problems/number-of-arithmetic-triplets) | | | | 2373 | [Largest Local Values in a Matrix](https://leetcode.com/problems/largest-local-values-in-a-matrix) | | | | 2379 | [Minimum Recolors to Get K Consecutive Black Blocks](https://leetcode.com/problems/minimum-recolors-to-get-k-consecutive-black-blocks) | | | diff --git a/src/MergeSimilarItems.java b/src/MergeSimilarItems.java new file mode 100644 index 0000000..d899e34 --- /dev/null +++ b/src/MergeSimilarItems.java @@ -0,0 +1,42 @@ +// https://leetcode.com/problems/merge-similar-items +// T: O(Nlog(N)) +// S: O(N) + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class MergeSimilarItems { + public List> mergeSimilarItems(int[][] items1, int[][] items2) { + final Map valueToWeight = getValueToWeightMapping(items1); + for (int[] row : items2) { + if (valueToWeight.containsKey(row[0])) { + valueToWeight.put(row[0], valueToWeight.get(row[0]) + row[1]); + } else { + valueToWeight.put(row[0], row[1]); + } + } + + final List> list = toList(valueToWeight); + list.sort(Comparator.comparingInt(a -> a.get(0))); + return list; + } + + private List> toList(Map mapping) { + final List> result = new ArrayList<>(); + for (Map.Entry entry : mapping.entrySet()) { + result.add(List.of(entry.getKey(), entry.getValue())); + } + return result; + } + + private Map getValueToWeightMapping(int[][] array) { + final Map result = new HashMap<>(); + for (int[] row : array) { + result.put(row[0], row[1]); + } + return result; + } +} From 15af33ed1e51ab264d78995aa664ec768247c9fb Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 29 May 2023 15:09:27 +0200 Subject: [PATCH 056/280] solves #2367: Number of Arithmetic Triplets in jav a --- README.md | 2 +- src/NumberOfArithmeticTriplets.java | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/NumberOfArithmeticTriplets.java diff --git a/README.md b/README.md index 6481d75..9133cd5 100644 --- a/README.md +++ b/README.md @@ -758,7 +758,7 @@ | 2357 | [Make Array Zero by Subtracting Equal Amounts](https://leetcode.com/problems/make-array-zero-by-subtracting-equal-amounts) | [![Java](assets/java.png)](src/MakeArrayZeroBySubtractingEqualAmounts.java) | | | 2360 | [Longest Cycle in a Graph](https://leetcode.com/problems/longest-cycle-in-a-graph) | [![Python](assets/python.png)](python/longest_cycle_in_graph.py) | | | 2363 | [Merge Similar Items](https://leetcode.com/problems/merge-similar-items) | [![Java](assets/java.png)](src/MergeSimilarItems.java) | | -| 2367 | [Number of Arithmetic Triplets](https://leetcode.com/problems/number-of-arithmetic-triplets) | | | +| 2367 | [Number of Arithmetic Triplets](https://leetcode.com/problems/number-of-arithmetic-triplets) | [![Java](assets/java.png)](src/NumberOfArithmeticTriplets.java) | | | 2373 | [Largest Local Values in a Matrix](https://leetcode.com/problems/largest-local-values-in-a-matrix) | | | | 2379 | [Minimum Recolors to Get K Consecutive Black Blocks](https://leetcode.com/problems/minimum-recolors-to-get-k-consecutive-black-blocks) | | | | 2383 | [Minimum Hours of Training to Win a Competition](https://leetcode.com/problems/minimum-hours-of-training-to-win-a-competition) | | | diff --git a/src/NumberOfArithmeticTriplets.java b/src/NumberOfArithmeticTriplets.java new file mode 100644 index 0000000..08db058 --- /dev/null +++ b/src/NumberOfArithmeticTriplets.java @@ -0,0 +1,22 @@ +// https://leetcode.com/problems/number-of-arithmetic-triplets +// T: O(N) +// S: O(N) + +import java.util.HashSet; +import java.util.Set; + +public class NumberOfArithmeticTriplets { + public int arithmeticTriplets(int[] array, int diff) { + final Set elements = new HashSet<>(); + int triplets = 0; + + for (int number : array) { + if (elements.contains(number - diff) && elements.contains(number - 2 * diff)) { + triplets++; + } + elements.add(number); + } + + return triplets; + } +} From 45f1041458640cfb6952c2766078f9016690ac05 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 29 May 2023 15:19:43 +0200 Subject: [PATCH 057/280] solves #2373: Largest Local Values in a Matrix in java --- README.md | 2 +- src/LargestLocalValuesInAMatrix.java | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/LargestLocalValuesInAMatrix.java diff --git a/README.md b/README.md index 9133cd5..000f1ae 100644 --- a/README.md +++ b/README.md @@ -759,7 +759,7 @@ | 2360 | [Longest Cycle in a Graph](https://leetcode.com/problems/longest-cycle-in-a-graph) | [![Python](assets/python.png)](python/longest_cycle_in_graph.py) | | | 2363 | [Merge Similar Items](https://leetcode.com/problems/merge-similar-items) | [![Java](assets/java.png)](src/MergeSimilarItems.java) | | | 2367 | [Number of Arithmetic Triplets](https://leetcode.com/problems/number-of-arithmetic-triplets) | [![Java](assets/java.png)](src/NumberOfArithmeticTriplets.java) | | -| 2373 | [Largest Local Values in a Matrix](https://leetcode.com/problems/largest-local-values-in-a-matrix) | | | +| 2373 | [Largest Local Values in a Matrix](https://leetcode.com/problems/largest-local-values-in-a-matrix) | [![Java](assets/java.png)](src/LargestLocalValuesInAMatrix.java) | | | 2379 | [Minimum Recolors to Get K Consecutive Black Blocks](https://leetcode.com/problems/minimum-recolors-to-get-k-consecutive-black-blocks) | | | | 2383 | [Minimum Hours of Training to Win a Competition](https://leetcode.com/problems/minimum-hours-of-training-to-win-a-competition) | | | | 2389 | [Longest Subsequence With Limited Sum](https://leetcode.com/problems/longest-subsequence-with-limited-sum) | | | diff --git a/src/LargestLocalValuesInAMatrix.java b/src/LargestLocalValuesInAMatrix.java new file mode 100644 index 0000000..3fbc63e --- /dev/null +++ b/src/LargestLocalValuesInAMatrix.java @@ -0,0 +1,28 @@ +// https://leetcode.com/problems/largest-local-values-in-a-matrix +// T: O(n ^ 2) +// S: O(n ^ 2) + +public class LargestLocalValuesInAMatrix { + public int[][] largestLocal(int[][] grid) { + final int n = grid.length; + final int[][] result = new int[n - 2][n - 2]; + + for (int row = 1 ; row < n - 1 ; row++) { + for (int column = 1 ; column < n - 1 ; column++) { + result[row - 1][column - 1] = localMax(grid, row, column); + } + } + + return result; + } + + private int localMax(int[][] grid, int row, int column) { + int max = Integer.MIN_VALUE; + for (int i = row - 1 ; i <= row + 1 ; i++) { + for (int j = column - 1 ; j <= column + 1 ; j++) { + max = Math.max(max, grid[i][j]); + } + } + return max; + } +} From 4dd8f75e957a9d95baa3e2d328f33d0832110774 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 29 May 2023 15:36:49 +0200 Subject: [PATCH 058/280] solves #2379: Minimum Recolors to Get K Consecutive Black Blocks in java --- README.md | 2 +- ...mRecolorsToGetKConsecutiveBlackBlocks.java | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/MinimumRecolorsToGetKConsecutiveBlackBlocks.java diff --git a/README.md b/README.md index 000f1ae..1acbc12 100644 --- a/README.md +++ b/README.md @@ -760,7 +760,7 @@ | 2363 | [Merge Similar Items](https://leetcode.com/problems/merge-similar-items) | [![Java](assets/java.png)](src/MergeSimilarItems.java) | | | 2367 | [Number of Arithmetic Triplets](https://leetcode.com/problems/number-of-arithmetic-triplets) | [![Java](assets/java.png)](src/NumberOfArithmeticTriplets.java) | | | 2373 | [Largest Local Values in a Matrix](https://leetcode.com/problems/largest-local-values-in-a-matrix) | [![Java](assets/java.png)](src/LargestLocalValuesInAMatrix.java) | | -| 2379 | [Minimum Recolors to Get K Consecutive Black Blocks](https://leetcode.com/problems/minimum-recolors-to-get-k-consecutive-black-blocks) | | | +| 2379 | [Minimum Recolors to Get K Consecutive Black Blocks](https://leetcode.com/problems/minimum-recolors-to-get-k-consecutive-black-blocks) | [![Java](assets/java.png)](src/MinimumRecolorsToGetKConsecutiveBlackBlocks.java) | | | 2383 | [Minimum Hours of Training to Win a Competition](https://leetcode.com/problems/minimum-hours-of-training-to-win-a-competition) | | | | 2389 | [Longest Subsequence With Limited Sum](https://leetcode.com/problems/longest-subsequence-with-limited-sum) | | | | 2395 | [Find Subarrays With Equal Sum](https://leetcode.com/problems/find-subarrays-with-equal-sum) | | | diff --git a/src/MinimumRecolorsToGetKConsecutiveBlackBlocks.java b/src/MinimumRecolorsToGetKConsecutiveBlackBlocks.java new file mode 100644 index 0000000..0ddab6f --- /dev/null +++ b/src/MinimumRecolorsToGetKConsecutiveBlackBlocks.java @@ -0,0 +1,26 @@ +// https://leetcode.com/problems/minimum-recolors-to-get-k-consecutive-black-blocks +// T: O(N) +// S: O(1) + +public class MinimumRecolorsToGetKConsecutiveBlackBlocks { + public int minimumRecolors(String blocks, int k) { + int numberOfWhites = numberOfWhitesInFirst(blocks, k); + int minRecolors = numberOfWhites; + + for (int index = k ; index < blocks.length() ; index++) { + if (blocks.charAt(index - k)== 'W') numberOfWhites--; + if (blocks.charAt(index) == 'W') numberOfWhites++; + minRecolors = Math.min(minRecolors, numberOfWhites); + } + + return minRecolors; + } + + private int numberOfWhitesInFirst(String blocks, int k) { + int result = 0; + for (int index = 0 ; index < k ; index++) { + if (blocks.charAt(index) == 'W') result++; + } + return result; + } +} From acf2c2b455bbd55a67c81cc143abb0130c087e7e Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 29 May 2023 15:59:34 +0200 Subject: [PATCH 059/280] solves #2383: Minimum Hours of Training to Win a Competition in java --- README.md | 2 +- ...nimumHoursOfTrainingToWinACompetition.java | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/MinimumHoursOfTrainingToWinACompetition.java diff --git a/README.md b/README.md index 1acbc12..69ff97c 100644 --- a/README.md +++ b/README.md @@ -761,7 +761,7 @@ | 2367 | [Number of Arithmetic Triplets](https://leetcode.com/problems/number-of-arithmetic-triplets) | [![Java](assets/java.png)](src/NumberOfArithmeticTriplets.java) | | | 2373 | [Largest Local Values in a Matrix](https://leetcode.com/problems/largest-local-values-in-a-matrix) | [![Java](assets/java.png)](src/LargestLocalValuesInAMatrix.java) | | | 2379 | [Minimum Recolors to Get K Consecutive Black Blocks](https://leetcode.com/problems/minimum-recolors-to-get-k-consecutive-black-blocks) | [![Java](assets/java.png)](src/MinimumRecolorsToGetKConsecutiveBlackBlocks.java) | | -| 2383 | [Minimum Hours of Training to Win a Competition](https://leetcode.com/problems/minimum-hours-of-training-to-win-a-competition) | | | +| 2383 | [Minimum Hours of Training to Win a Competition](https://leetcode.com/problems/minimum-hours-of-training-to-win-a-competition) | [![Java](assets/java.png)](src/MinimumHoursOfTrainingToWinACompetition.java) | | | 2389 | [Longest Subsequence With Limited Sum](https://leetcode.com/problems/longest-subsequence-with-limited-sum) | | | | 2395 | [Find Subarrays With Equal Sum](https://leetcode.com/problems/find-subarrays-with-equal-sum) | | | | 2399 | [Check Distances Between Same Letters](https://leetcode.com/problems/check-distances-between-same-letters) | | | diff --git a/src/MinimumHoursOfTrainingToWinACompetition.java b/src/MinimumHoursOfTrainingToWinACompetition.java new file mode 100644 index 0000000..248e75b --- /dev/null +++ b/src/MinimumHoursOfTrainingToWinACompetition.java @@ -0,0 +1,24 @@ +// https://leetcode.com/problems/minimum-hours-of-training-to-win-a-competition +// T: O(N) +// S: O(1) + +public class MinimumHoursOfTrainingToWinACompetition { + public static int minNumberOfHours(int initialEnergy, int initialExperience, int[] energy, int[] experience) { + int trainingRequired = 0; + + for (int index = 0 ; index < energy.length ; index++) { + if (energy[index] >= initialEnergy) { + trainingRequired += energy[index] - initialEnergy + 1; + initialEnergy += energy[index] - initialEnergy + 1; + } + if (experience[index] >= initialExperience) { + trainingRequired += experience[index] - initialExperience + 1; + initialExperience += experience[index] - initialExperience + 1; + } + initialEnergy -= energy[index]; + initialExperience += experience[index]; + } + + return trainingRequired; + } +} From 45187e130dc6cec142c2c718c1497a036950a31e Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 29 May 2023 16:28:01 +0200 Subject: [PATCH 060/280] solves #2389: Longest Subsequence With Limited Sum in java --- README.md | 2 +- src/HelloWorld.java | 38 ++++--------------- src/LongestSubsequenceWithLimitedSum.java | 46 +++++++++++++++++++++++ 3 files changed, 55 insertions(+), 31 deletions(-) create mode 100644 src/LongestSubsequenceWithLimitedSum.java diff --git a/README.md b/README.md index 69ff97c..b8832eb 100644 --- a/README.md +++ b/README.md @@ -762,7 +762,7 @@ | 2373 | [Largest Local Values in a Matrix](https://leetcode.com/problems/largest-local-values-in-a-matrix) | [![Java](assets/java.png)](src/LargestLocalValuesInAMatrix.java) | | | 2379 | [Minimum Recolors to Get K Consecutive Black Blocks](https://leetcode.com/problems/minimum-recolors-to-get-k-consecutive-black-blocks) | [![Java](assets/java.png)](src/MinimumRecolorsToGetKConsecutiveBlackBlocks.java) | | | 2383 | [Minimum Hours of Training to Win a Competition](https://leetcode.com/problems/minimum-hours-of-training-to-win-a-competition) | [![Java](assets/java.png)](src/MinimumHoursOfTrainingToWinACompetition.java) | | -| 2389 | [Longest Subsequence With Limited Sum](https://leetcode.com/problems/longest-subsequence-with-limited-sum) | | | +| 2389 | [Longest Subsequence With Limited Sum](https://leetcode.com/problems/longest-subsequence-with-limited-sum) | [![Java](assets/java.png)](src/LongestSubsequenceWithLimitedSum.java) | | | 2395 | [Find Subarrays With Equal Sum](https://leetcode.com/problems/find-subarrays-with-equal-sum) | | | | 2399 | [Check Distances Between Same Letters](https://leetcode.com/problems/check-distances-between-same-letters) | | | | 2404 | [Most Frequent Even Element](https://leetcode.com/problems/most-frequent-even-element) | | | diff --git a/src/HelloWorld.java b/src/HelloWorld.java index 6987410..fce5a54 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -1,35 +1,13 @@ +import java.util.PriorityQueue; +import java.util.Queue; + public class HelloWorld { public static void main(String[] args) { - System.out.println( - LargestNumber.largestNumber(new int[] {1, 2, 3}) - ); - - System.out.println( - LargestNumber.largestNumber(new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9}) - ); - - System.out.println( - LargestNumber.largestNumber(new int[] {10, 2}) - ); - - System.out.println( - LargestNumber.largestNumber(new int[] {1}) - ); - - System.out.println( - LargestNumber.largestNumber(new int[] {1, 10, 11, 12}) - ); - - System.out.println( - LargestNumber.largestNumber(new int[] {1, 10, 11, 12, 16, 15, 14, 13, 19, 18, 17}) - ); - - System.out.println( - LargestNumber.largestNumber(new int[] {3, 30, 34, 5, 9}) - ); + final Queue queue = new PriorityQueue<>(); + queue.add(10); + queue.add(4); + queue.add(-2); - System.out.println( - LargestNumber.largestNumber(new int[] {432, 43243}) - ); + System.out.println(queue.peek()); } } diff --git a/src/LongestSubsequenceWithLimitedSum.java b/src/LongestSubsequenceWithLimitedSum.java new file mode 100644 index 0000000..b4412d1 --- /dev/null +++ b/src/LongestSubsequenceWithLimitedSum.java @@ -0,0 +1,46 @@ +// https://leetcode.com/problems/longest-subsequence-with-limited-sum +// T: O((n + m) log(n)) +// S: O(n) + +import java.util.PriorityQueue; +import java.util.Queue; + +public class LongestSubsequenceWithLimitedSum { + public int[] answerQueries(int[] nums, int[] queries) { + final int[] result = new int[queries.length]; + final int[] prefixSumArray = getMinSumArray(nums); + + for (int index = 0 ; index < queries.length ; index++) { + int maxLen = binarySearch(prefixSumArray, queries[index]); + if (maxLen < prefixSumArray.length && prefixSumArray[maxLen] == queries[index]) { + result[index] = maxLen + 1; + } else result[index] = maxLen; + } + + return result; + } + + private int binarySearch(int[] array, int x) { + int left = 0, right = array.length - 1, index = 0; + while (left <= right) { + index = left + (right - left) / 2; + if (array[index] == x) return index; + else if (array[index] > x) right = index - 1; + else left = index + 1; + } + return left; + } + + private int[] getMinSumArray(int[] array) { + final Queue minHeap = new PriorityQueue<>(); + final int[] result = new int[array.length]; + for (int element : array) { + minHeap.add(element); + } + result[0] = minHeap.poll(); + for (int index = 1 ; index < result.length ; index++) { + result[index] = result[index - 1] + minHeap.poll(); + } + return result; + } +} From 907bb3e746efb83605300123e6ba8cbb5d242e9f Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 29 May 2023 16:32:01 +0200 Subject: [PATCH 061/280] solves #2395: Find Subarrays With Equal Sum in java --- README.md | 2 +- src/FindSubarraysWithEqualSum.java | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/FindSubarraysWithEqualSum.java diff --git a/README.md b/README.md index b8832eb..f6eddd7 100644 --- a/README.md +++ b/README.md @@ -763,7 +763,7 @@ | 2379 | [Minimum Recolors to Get K Consecutive Black Blocks](https://leetcode.com/problems/minimum-recolors-to-get-k-consecutive-black-blocks) | [![Java](assets/java.png)](src/MinimumRecolorsToGetKConsecutiveBlackBlocks.java) | | | 2383 | [Minimum Hours of Training to Win a Competition](https://leetcode.com/problems/minimum-hours-of-training-to-win-a-competition) | [![Java](assets/java.png)](src/MinimumHoursOfTrainingToWinACompetition.java) | | | 2389 | [Longest Subsequence With Limited Sum](https://leetcode.com/problems/longest-subsequence-with-limited-sum) | [![Java](assets/java.png)](src/LongestSubsequenceWithLimitedSum.java) | | -| 2395 | [Find Subarrays With Equal Sum](https://leetcode.com/problems/find-subarrays-with-equal-sum) | | | +| 2395 | [Find Subarrays With Equal Sum](https://leetcode.com/problems/find-subarrays-with-equal-sum) | [![Java](assets/java.png)](src/FindSubarraysWithEqualSum.java) | | | 2399 | [Check Distances Between Same Letters](https://leetcode.com/problems/check-distances-between-same-letters) | | | | 2404 | [Most Frequent Even Element](https://leetcode.com/problems/most-frequent-even-element) | | | | 2409 | [Count Days Spent Together](https://leetcode.com/problems/count-days-spent-together) | | | diff --git a/src/FindSubarraysWithEqualSum.java b/src/FindSubarraysWithEqualSum.java new file mode 100644 index 0000000..4db4790 --- /dev/null +++ b/src/FindSubarraysWithEqualSum.java @@ -0,0 +1,20 @@ +// https://leetcode.com/problems/find-subarrays-with-equal-sum +// T: O(N) +// S: O(N) + +import java.util.HashSet; +import java.util.Set; + +public class FindSubarraysWithEqualSum { + public boolean findSubarrays(int[] array) { + final Set subarraySum = new HashSet<>(); + for (int i = 0 ; i < array.length - 1 ; i++) { + int sum = array[i] + array[i + 1]; + if (subarraySum.contains(sum)) { + return true; + } + subarraySum.add(sum); + } + return false; + } +} From d5774fd8e3fe98ed7af23fbbee553ccc0beae612 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 29 May 2023 16:37:24 +0200 Subject: [PATCH 062/280] solves #2399: Check Distances Between Same Letters in java --- README.md | 2 +- src/CheckDistancesBetweenSameLetters.java | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/CheckDistancesBetweenSameLetters.java diff --git a/README.md b/README.md index f6eddd7..b88a0ca 100644 --- a/README.md +++ b/README.md @@ -764,7 +764,7 @@ | 2383 | [Minimum Hours of Training to Win a Competition](https://leetcode.com/problems/minimum-hours-of-training-to-win-a-competition) | [![Java](assets/java.png)](src/MinimumHoursOfTrainingToWinACompetition.java) | | | 2389 | [Longest Subsequence With Limited Sum](https://leetcode.com/problems/longest-subsequence-with-limited-sum) | [![Java](assets/java.png)](src/LongestSubsequenceWithLimitedSum.java) | | | 2395 | [Find Subarrays With Equal Sum](https://leetcode.com/problems/find-subarrays-with-equal-sum) | [![Java](assets/java.png)](src/FindSubarraysWithEqualSum.java) | | -| 2399 | [Check Distances Between Same Letters](https://leetcode.com/problems/check-distances-between-same-letters) | | | +| 2399 | [Check Distances Between Same Letters](https://leetcode.com/problems/check-distances-between-same-letters) | [![Java](assets/java.png)](src/CheckDistancesBetweenSameLetters.java) | | | 2404 | [Most Frequent Even Element](https://leetcode.com/problems/most-frequent-even-element) | | | | 2409 | [Count Days Spent Together](https://leetcode.com/problems/count-days-spent-together) | | | | 2413 | [Smallest Even Multiple](https://leetcode.com/problems/smallest-even-multiple) | | | diff --git a/src/CheckDistancesBetweenSameLetters.java b/src/CheckDistancesBetweenSameLetters.java new file mode 100644 index 0000000..349109e --- /dev/null +++ b/src/CheckDistancesBetweenSameLetters.java @@ -0,0 +1,22 @@ +// https://leetcode.com/problems/check-distances-between-same-letters +// T: O(N) +// S: O(1) + +import java.util.HashMap; +import java.util.Map; + +public class CheckDistancesBetweenSameLetters { + public boolean checkDistances(String s, int[] distances) { + final Map firstOccurrenceIndex = new HashMap<>(); + for (int index = 0 ; index < s.length() ; index++) { + char letter = s.charAt(index); + if (firstOccurrenceIndex.containsKey(letter)) { + int distance = index - firstOccurrenceIndex.get(letter) - 1; + if (distance != distances[letter - 'a']) { + return false; + } + } else firstOccurrenceIndex.put(letter, index); + } + return true; + } +} From 1983d4a2e7ce5a0d2ec2a68efd4f6db1cbf3f03f Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 29 May 2023 16:48:57 +0200 Subject: [PATCH 063/280] solves #2404: Most Frequent Even Element in java --- README.md | 2 +- src/MostFrequentEvenElement.java | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/MostFrequentEvenElement.java diff --git a/README.md b/README.md index b88a0ca..eb8fd3b 100644 --- a/README.md +++ b/README.md @@ -765,7 +765,7 @@ | 2389 | [Longest Subsequence With Limited Sum](https://leetcode.com/problems/longest-subsequence-with-limited-sum) | [![Java](assets/java.png)](src/LongestSubsequenceWithLimitedSum.java) | | | 2395 | [Find Subarrays With Equal Sum](https://leetcode.com/problems/find-subarrays-with-equal-sum) | [![Java](assets/java.png)](src/FindSubarraysWithEqualSum.java) | | | 2399 | [Check Distances Between Same Letters](https://leetcode.com/problems/check-distances-between-same-letters) | [![Java](assets/java.png)](src/CheckDistancesBetweenSameLetters.java) | | -| 2404 | [Most Frequent Even Element](https://leetcode.com/problems/most-frequent-even-element) | | | +| 2404 | [Most Frequent Even Element](https://leetcode.com/problems/most-frequent-even-element) | [![Java](assets/java.png)](src/MostFrequentEvenElement.java) | | | 2409 | [Count Days Spent Together](https://leetcode.com/problems/count-days-spent-together) | | | | 2413 | [Smallest Even Multiple](https://leetcode.com/problems/smallest-even-multiple) | | | | 2418 | [Sort the People](https://leetcode.com/problems/sort-the-people) | | | diff --git a/src/MostFrequentEvenElement.java b/src/MostFrequentEvenElement.java new file mode 100644 index 0000000..3a81c9b --- /dev/null +++ b/src/MostFrequentEvenElement.java @@ -0,0 +1,29 @@ +// https://leetcode.com/problems/most-frequent-even-element +// T: O(N) +// S: O(N) + +import java.util.HashMap; +import java.util.Map; + +public class MostFrequentEvenElement { + public int mostFrequentEven(int[] nums) { + final Map evenFrequencies = new HashMap<>(); + int maxFrequency = 0, smallestEvenNumber = -1; + + for (int element : nums) { + if (element % 2 == 1) { + continue; + } + + evenFrequencies.put(element, evenFrequencies.getOrDefault(element, 0) + 1); + if (evenFrequencies.get(element) > maxFrequency) { + maxFrequency = evenFrequencies.get(element); + smallestEvenNumber = element; + } else if (evenFrequencies.get(element) == maxFrequency) { + smallestEvenNumber = Math.min(smallestEvenNumber, element); + } + } + + return smallestEvenNumber; + } +} From 2e7bf77e4247287e4745bf5b5d4d978e92a3a889 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 1 Jun 2023 16:56:35 +0200 Subject: [PATCH 064/280] solves #2409: Count Days Spent Together in java --- README.md | 2 +- src/CountDaysSpentTogether.java | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 src/CountDaysSpentTogether.java diff --git a/README.md b/README.md index eb8fd3b..8ddf178 100644 --- a/README.md +++ b/README.md @@ -766,7 +766,7 @@ | 2395 | [Find Subarrays With Equal Sum](https://leetcode.com/problems/find-subarrays-with-equal-sum) | [![Java](assets/java.png)](src/FindSubarraysWithEqualSum.java) | | | 2399 | [Check Distances Between Same Letters](https://leetcode.com/problems/check-distances-between-same-letters) | [![Java](assets/java.png)](src/CheckDistancesBetweenSameLetters.java) | | | 2404 | [Most Frequent Even Element](https://leetcode.com/problems/most-frequent-even-element) | [![Java](assets/java.png)](src/MostFrequentEvenElement.java) | | -| 2409 | [Count Days Spent Together](https://leetcode.com/problems/count-days-spent-together) | | | +| 2409 | [Count Days Spent Together](https://leetcode.com/problems/count-days-spent-together) | [![Java](assets/java.png)](src/CountDaysSpentTogether.java) | | | 2413 | [Smallest Even Multiple](https://leetcode.com/problems/smallest-even-multiple) | | | | 2418 | [Sort the People](https://leetcode.com/problems/sort-the-people) | | | | 2423 | [Remove Letter To Equalize Frequency](https://leetcode.com/problems/remove-letter-to-equalize-frequency) | | | diff --git a/src/CountDaysSpentTogether.java b/src/CountDaysSpentTogether.java new file mode 100644 index 0000000..9c018d4 --- /dev/null +++ b/src/CountDaysSpentTogether.java @@ -0,0 +1,23 @@ +// https://leetcode.com/problems/count-days-spent-together +// T: O(1) +// S: O(1) + +import java.time.LocalDate; + +public class CountDaysSpentTogether { + public int countDaysTogether(String arriveAlice, String leaveAlice, String arriveBob, String leaveBob){ + final long aliceArrive = getEpochDay(arriveAlice); + final long aliceLeave = getEpochDay(leaveAlice); + final long bobArrive = getEpochDay(arriveBob); + final long bobLeave = getEpochDay(leaveBob); + + //No intersection of days + if(aliceLeave < bobArrive || bobLeave < aliceArrive) return 0; + + return (int) ((Math.min(aliceLeave, bobLeave) - Math.max(aliceArrive, bobArrive)) + 1); + } + + private long getEpochDay(String mmDD) { + return LocalDate.of(2021,Integer.parseInt(mmDD.substring(0,2)),Integer.parseInt(mmDD.substring(3,5))).toEpochDay(); + } +} From 6d80d729a3f7b7254e2524b2d4c284451a02375a Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 1 Jun 2023 16:59:22 +0200 Subject: [PATCH 065/280] solves #2413: Smallest Even Multiple in java --- README.md | 2 +- src/SmallestEvenMultiple.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 src/SmallestEvenMultiple.java diff --git a/README.md b/README.md index 8ddf178..ac82453 100644 --- a/README.md +++ b/README.md @@ -767,7 +767,7 @@ | 2399 | [Check Distances Between Same Letters](https://leetcode.com/problems/check-distances-between-same-letters) | [![Java](assets/java.png)](src/CheckDistancesBetweenSameLetters.java) | | | 2404 | [Most Frequent Even Element](https://leetcode.com/problems/most-frequent-even-element) | [![Java](assets/java.png)](src/MostFrequentEvenElement.java) | | | 2409 | [Count Days Spent Together](https://leetcode.com/problems/count-days-spent-together) | [![Java](assets/java.png)](src/CountDaysSpentTogether.java) | | -| 2413 | [Smallest Even Multiple](https://leetcode.com/problems/smallest-even-multiple) | | | +| 2413 | [Smallest Even Multiple](https://leetcode.com/problems/smallest-even-multiple) | [![Java](assets/java.png)](src/SmallestEvenMultiple.java) | | | 2418 | [Sort the People](https://leetcode.com/problems/sort-the-people) | | | | 2423 | [Remove Letter To Equalize Frequency](https://leetcode.com/problems/remove-letter-to-equalize-frequency) | | | | 2427 | [Number of Common Factors](https://leetcode.com/problems/number-of-common-factors) | | | diff --git a/src/SmallestEvenMultiple.java b/src/SmallestEvenMultiple.java new file mode 100644 index 0000000..e1964f4 --- /dev/null +++ b/src/SmallestEvenMultiple.java @@ -0,0 +1,10 @@ +// https://leetcode.com/problems/smallest-even-multiple +// T: O(1) +// S: O(1) + +public class SmallestEvenMultiple { + public int smallestEvenMultiple(int n) { + if (n % 2 == 0) return n; + return n * 2; + } +} From fa30e45b2957136ef3a6ec4008866dc5dbf85090 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 1 Jun 2023 17:07:56 +0200 Subject: [PATCH 066/280] solves #2418: Sort the People in java --- README.md | 2 +- src/SortThePeople.java | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/SortThePeople.java diff --git a/README.md b/README.md index ac82453..485940d 100644 --- a/README.md +++ b/README.md @@ -768,7 +768,7 @@ | 2404 | [Most Frequent Even Element](https://leetcode.com/problems/most-frequent-even-element) | [![Java](assets/java.png)](src/MostFrequentEvenElement.java) | | | 2409 | [Count Days Spent Together](https://leetcode.com/problems/count-days-spent-together) | [![Java](assets/java.png)](src/CountDaysSpentTogether.java) | | | 2413 | [Smallest Even Multiple](https://leetcode.com/problems/smallest-even-multiple) | [![Java](assets/java.png)](src/SmallestEvenMultiple.java) | | -| 2418 | [Sort the People](https://leetcode.com/problems/sort-the-people) | | | +| 2418 | [Sort the People](https://leetcode.com/problems/sort-the-people) | [![Java](assets/java.png)](src/SortThePeople.java) | | | 2423 | [Remove Letter To Equalize Frequency](https://leetcode.com/problems/remove-letter-to-equalize-frequency) | | | | 2427 | [Number of Common Factors](https://leetcode.com/problems/number-of-common-factors) | | | | 2432 | [The Employee That Worked on the Longest Task](https://leetcode.com/problems/the-employee-that-worked-on-the-longest-task) | | | diff --git a/src/SortThePeople.java b/src/SortThePeople.java new file mode 100644 index 0000000..9d04187 --- /dev/null +++ b/src/SortThePeople.java @@ -0,0 +1,33 @@ +// https://leetcode.com/problems/sort-the-people +// T: O(n + nlogn) +// S: O(n) + +import java.util.ArrayList; +import java.util.List; + +public class SortThePeople { + private record Person(String name, int height) {} + + public String[] sortPeople(String[] names, int[] heights) { + final List people = getPeople(names, heights); + people.sort((a, b) -> Integer.compare(b.height, a.height)); + return toNameArray(people); + } + + private String[] toNameArray(List people) { + final String[] names = new String[people.size()]; + int k = 0; + for (Person person : people) { + names[k++] = person.name; + } + return names; + } + + private List getPeople(String[] names, int[] heights) { + final List people = new ArrayList<>(); + for (int i = 0 ; i < names.length ; i++) { + people.add(new Person(names[i], heights[i])); + } + return people; + } +} From 217c315c558b6115ae8493f3dc3e03ffecfafe68 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 1 Jun 2023 17:41:11 +0200 Subject: [PATCH 067/280] solves #2423: Remove Letter To Equalize Frequency in java --- README.md | 2 +- src/RemoveLetterToEqualizeFrequency.java | 52 ++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/RemoveLetterToEqualizeFrequency.java diff --git a/README.md b/README.md index 485940d..887394c 100644 --- a/README.md +++ b/README.md @@ -769,7 +769,7 @@ | 2409 | [Count Days Spent Together](https://leetcode.com/problems/count-days-spent-together) | [![Java](assets/java.png)](src/CountDaysSpentTogether.java) | | | 2413 | [Smallest Even Multiple](https://leetcode.com/problems/smallest-even-multiple) | [![Java](assets/java.png)](src/SmallestEvenMultiple.java) | | | 2418 | [Sort the People](https://leetcode.com/problems/sort-the-people) | [![Java](assets/java.png)](src/SortThePeople.java) | | -| 2423 | [Remove Letter To Equalize Frequency](https://leetcode.com/problems/remove-letter-to-equalize-frequency) | | | +| 2423 | [Remove Letter To Equalize Frequency](https://leetcode.com/problems/remove-letter-to-equalize-frequency) | [![Java](assets/java.png)](src/RemoveLetterToEqualizeFrequency.java) | | | 2427 | [Number of Common Factors](https://leetcode.com/problems/number-of-common-factors) | | | | 2432 | [The Employee That Worked on the Longest Task](https://leetcode.com/problems/the-employee-that-worked-on-the-longest-task) | | | | 2437 | [Number of Valid Clock Times](https://leetcode.com/problems/number-of-valid-clock-times) | | | diff --git a/src/RemoveLetterToEqualizeFrequency.java b/src/RemoveLetterToEqualizeFrequency.java new file mode 100644 index 0000000..9936398 --- /dev/null +++ b/src/RemoveLetterToEqualizeFrequency.java @@ -0,0 +1,52 @@ +// https://leetcode.com/problems/remove-letter-to-equalize-frequency +// T: O(|word|) +// S: O(1) + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +public class RemoveLetterToEqualizeFrequency { + public boolean equalFrequency(String word) { + final Map letterFrequency = getFrequencies(word); + final Map numberFrequency = getFrequencies(letterFrequency.values()); + + if (letterFrequency.size() == 1) { + return true; + } + + if (numberFrequency.size() == 1 && numberFrequency.keySet().iterator().next() == 1) { + return true; + } + + if (numberFrequency.size() == 1 || numberFrequency.size() > 2) { + return false; + } + + final Iterator iterator = numberFrequency.keySet().iterator(); + final int first = iterator.next(), second = iterator.next(); + final int smallerNum = Math.min(first, second); + final int largerNum = Math.max(first, second); + final int smallerNumFreq = numberFrequency.get(smallerNum); + final int largerNumFreq = numberFrequency.get(largerNum); + + return ((largerNum - smallerNum == 1) && largerNumFreq == 1) || (smallerNum == 1 && smallerNumFreq == 1); + } + + private Map getFrequencies(String string) { + final Map result = new HashMap<>(); + for (int index = 0 ; index < string.length() ; index++) { + char letter = string.charAt(index); + result.put(letter, result.getOrDefault(letter, 0) + 1); + } + return result; + } + + private Map getFrequencies(Iterable iterable) { + final Map result = new HashMap<>(); + for (int value : iterable) { + result.put(value, result.getOrDefault(value, 0) + 1); + } + return result; + } +} From c4ae3d2af6c657240a1e63618562a369fe46ec84 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 1 Jun 2023 17:45:59 +0200 Subject: [PATCH 068/280] solves number of common factors --- README.md | 2 +- src/NumberOfCommonFactors.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/NumberOfCommonFactors.java diff --git a/README.md b/README.md index 887394c..e1aff9a 100644 --- a/README.md +++ b/README.md @@ -770,7 +770,7 @@ | 2413 | [Smallest Even Multiple](https://leetcode.com/problems/smallest-even-multiple) | [![Java](assets/java.png)](src/SmallestEvenMultiple.java) | | | 2418 | [Sort the People](https://leetcode.com/problems/sort-the-people) | [![Java](assets/java.png)](src/SortThePeople.java) | | | 2423 | [Remove Letter To Equalize Frequency](https://leetcode.com/problems/remove-letter-to-equalize-frequency) | [![Java](assets/java.png)](src/RemoveLetterToEqualizeFrequency.java) | | -| 2427 | [Number of Common Factors](https://leetcode.com/problems/number-of-common-factors) | | | +| 2427 | [Number of Common Factors](https://leetcode.com/problems/number-of-common-factors) | [![Java](assets/java.png)](src/NumberOfCommonFactors.java) | | | 2432 | [The Employee That Worked on the Longest Task](https://leetcode.com/problems/the-employee-that-worked-on-the-longest-task) | | | | 2437 | [Number of Valid Clock Times](https://leetcode.com/problems/number-of-valid-clock-times) | | | | 2441 | [Largest Positive Integer That Exists With Its Negative](https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative) | | | diff --git a/src/NumberOfCommonFactors.java b/src/NumberOfCommonFactors.java new file mode 100644 index 0000000..f3409ed --- /dev/null +++ b/src/NumberOfCommonFactors.java @@ -0,0 +1,17 @@ +// https://leetcode.com/problems/number-of-common-factors +// T: O(min(a, b)) +// S: O(1) + +public class NumberOfCommonFactors { + public int commonFactors(int a, int b) { + final int min = Math.min(a, b); + int commonFactors = 1; + + for (int factor = 2 ; factor <= min ; factor++) { + if (a % factor == 0 & b % factor == 0) { + commonFactors++; + } + } + return commonFactors; + } +} From 879fc2e70dbbe54545d439d5430482978293f7c6 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 1 Jun 2023 17:54:28 +0200 Subject: [PATCH 069/280] solves #2432: The Employee That Worked on the Longest Task in java --- README.md | 2 +- ...TheEmployeeThatWorkedOnTheLongestTask.java | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/TheEmployeeThatWorkedOnTheLongestTask.java diff --git a/README.md b/README.md index e1aff9a..ebce36a 100644 --- a/README.md +++ b/README.md @@ -771,7 +771,7 @@ | 2418 | [Sort the People](https://leetcode.com/problems/sort-the-people) | [![Java](assets/java.png)](src/SortThePeople.java) | | | 2423 | [Remove Letter To Equalize Frequency](https://leetcode.com/problems/remove-letter-to-equalize-frequency) | [![Java](assets/java.png)](src/RemoveLetterToEqualizeFrequency.java) | | | 2427 | [Number of Common Factors](https://leetcode.com/problems/number-of-common-factors) | [![Java](assets/java.png)](src/NumberOfCommonFactors.java) | | -| 2432 | [The Employee That Worked on the Longest Task](https://leetcode.com/problems/the-employee-that-worked-on-the-longest-task) | | | +| 2432 | [The Employee That Worked on the Longest Task](https://leetcode.com/problems/the-employee-that-worked-on-the-longest-task) | [![Java](assets/java.png)](src/TheEmployeeThatWorkedOnTheLongestTask.java) | | | 2437 | [Number of Valid Clock Times](https://leetcode.com/problems/number-of-valid-clock-times) | | | | 2441 | [Largest Positive Integer That Exists With Its Negative](https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative) | | | | 2446 | [Determine if Two Events Have Conflict](https://leetcode.com/problems/determine-if-two-events-have-conflict) | | | diff --git a/src/TheEmployeeThatWorkedOnTheLongestTask.java b/src/TheEmployeeThatWorkedOnTheLongestTask.java new file mode 100644 index 0000000..a8d673f --- /dev/null +++ b/src/TheEmployeeThatWorkedOnTheLongestTask.java @@ -0,0 +1,20 @@ +// https://leetcode.com/problems/the-employee-that-worked-on-the-longest-task +// T: O(|logs|) +// S: O(1) + +public class TheEmployeeThatWorkedOnTheLongestTask { + public int hardestWorker(int n, int[][] logs) { + int longestTime = -1, employeeId = -1, previousTime = 0; + for (int[] log : logs) { + int time = log[1] - previousTime; + previousTime = log[1]; + if (time > longestTime) { + longestTime = time; + employeeId = log[0]; + } else if (time == longestTime && log[0] < employeeId) { + employeeId = log[0]; + } + } + return employeeId; + } +} From 6329d0d9ddd0da69ae03be7ce6d6dc888bca13a4 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 1 Jun 2023 18:08:16 +0200 Subject: [PATCH 070/280] solves #2437: Number of Valid Clock Times in java --- README.md | 2 +- src/NumberOfValidClockTimes.java | 35 ++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/NumberOfValidClockTimes.java diff --git a/README.md b/README.md index ebce36a..68b7a93 100644 --- a/README.md +++ b/README.md @@ -772,7 +772,7 @@ | 2423 | [Remove Letter To Equalize Frequency](https://leetcode.com/problems/remove-letter-to-equalize-frequency) | [![Java](assets/java.png)](src/RemoveLetterToEqualizeFrequency.java) | | | 2427 | [Number of Common Factors](https://leetcode.com/problems/number-of-common-factors) | [![Java](assets/java.png)](src/NumberOfCommonFactors.java) | | | 2432 | [The Employee That Worked on the Longest Task](https://leetcode.com/problems/the-employee-that-worked-on-the-longest-task) | [![Java](assets/java.png)](src/TheEmployeeThatWorkedOnTheLongestTask.java) | | -| 2437 | [Number of Valid Clock Times](https://leetcode.com/problems/number-of-valid-clock-times) | | | +| 2437 | [Number of Valid Clock Times](https://leetcode.com/problems/number-of-valid-clock-times) | [![Java](assets/java.png)](src/NumberOfValidClockTimes.java) | | | 2441 | [Largest Positive Integer That Exists With Its Negative](https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative) | | | | 2446 | [Determine if Two Events Have Conflict](https://leetcode.com/problems/determine-if-two-events-have-conflict) | | | | 2451 | [Odd String Difference](https://leetcode.com/problems/odd-string-difference) | | | diff --git a/src/NumberOfValidClockTimes.java b/src/NumberOfValidClockTimes.java new file mode 100644 index 0000000..a4114b5 --- /dev/null +++ b/src/NumberOfValidClockTimes.java @@ -0,0 +1,35 @@ +// https://leetcode.com/problems/number-of-valid-clock-times +// T: O(1) +// S: O(1) + +public class NumberOfValidClockTimes { + private static final char QUESTION = '?'; + + public int countTime(String time) { + return numberOfValidHourStrings(time.substring(0, 2)) * numberOfValidMinuteStrings(time.substring(3)); + } + + private int numberOfValidMinuteStrings(String mm) { + final char first = mm.charAt(0), second = mm.charAt(1); + + if (first == QUESTION && second == QUESTION) return 60; + if (first != QUESTION && second != QUESTION) return 1; + if (first != QUESTION) return 10; + return 6; + } + + private int numberOfValidHourStrings(String hh) { + final char first = hh.charAt(0), second = hh.charAt(1); + + if (first == QUESTION && second == QUESTION) return 24; + if (first != QUESTION && second != QUESTION) return 1; + + if (first != QUESTION) { + if (first == '2') return 4; + return 10; + } + + if (second > '3') return 2; + return 3; + } +} From a35c8dc7c88772d96841789d0afdf798686e437d Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 1 Jun 2023 18:13:42 +0200 Subject: [PATCH 071/280] solves #2441: Largest Positive Integer That Exists With Its Negative in java --- README.md | 2 +- ...itiveIntegerThatExistsWithItsNegative.java | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/LargestPositiveIntegerThatExistsWithItsNegative.java diff --git a/README.md b/README.md index 68b7a93..14427df 100644 --- a/README.md +++ b/README.md @@ -773,7 +773,7 @@ | 2427 | [Number of Common Factors](https://leetcode.com/problems/number-of-common-factors) | [![Java](assets/java.png)](src/NumberOfCommonFactors.java) | | | 2432 | [The Employee That Worked on the Longest Task](https://leetcode.com/problems/the-employee-that-worked-on-the-longest-task) | [![Java](assets/java.png)](src/TheEmployeeThatWorkedOnTheLongestTask.java) | | | 2437 | [Number of Valid Clock Times](https://leetcode.com/problems/number-of-valid-clock-times) | [![Java](assets/java.png)](src/NumberOfValidClockTimes.java) | | -| 2441 | [Largest Positive Integer That Exists With Its Negative](https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative) | | | +| 2441 | [Largest Positive Integer That Exists With Its Negative](https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative) | [![Java](assets/java.png)](src/LargestPositiveIntegerThatExistsWithItsNegative.java) | | | 2446 | [Determine if Two Events Have Conflict](https://leetcode.com/problems/determine-if-two-events-have-conflict) | | | | 2451 | [Odd String Difference](https://leetcode.com/problems/odd-string-difference) | | | | 2455 | [Average Value of Even Numbers That Are Divisible by Three](https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three) | | | diff --git a/src/LargestPositiveIntegerThatExistsWithItsNegative.java b/src/LargestPositiveIntegerThatExistsWithItsNegative.java new file mode 100644 index 0000000..03f284e --- /dev/null +++ b/src/LargestPositiveIntegerThatExistsWithItsNegative.java @@ -0,0 +1,22 @@ +// https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative +// T: O(N) +// S: O(N) + +import java.util.HashSet; +import java.util.Set; + +public class LargestPositiveIntegerThatExistsWithItsNegative { + public int findMaxK(int[] array) { + int largest = -1; + final Set numbers = new HashSet<>(); + + for (int element : array) { + if (Math.abs(element) > largest && numbers.contains(-element)) { + largest = Math.abs(element); + } + numbers.add(element); + } + + return largest; + } +} From 2c45527a0e670534eee94ed55a45dbb089bf3d96 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 1 Jun 2023 18:21:13 +0200 Subject: [PATCH 072/280] solves #2446: Determine if Two Events Have Conflict in java --- README.md | 2 +- src/DetermineIfTwoEventsHaveConflict.java | 32 +++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/DetermineIfTwoEventsHaveConflict.java diff --git a/README.md b/README.md index 14427df..82dde14 100644 --- a/README.md +++ b/README.md @@ -774,7 +774,7 @@ | 2432 | [The Employee That Worked on the Longest Task](https://leetcode.com/problems/the-employee-that-worked-on-the-longest-task) | [![Java](assets/java.png)](src/TheEmployeeThatWorkedOnTheLongestTask.java) | | | 2437 | [Number of Valid Clock Times](https://leetcode.com/problems/number-of-valid-clock-times) | [![Java](assets/java.png)](src/NumberOfValidClockTimes.java) | | | 2441 | [Largest Positive Integer That Exists With Its Negative](https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative) | [![Java](assets/java.png)](src/LargestPositiveIntegerThatExistsWithItsNegative.java) | | -| 2446 | [Determine if Two Events Have Conflict](https://leetcode.com/problems/determine-if-two-events-have-conflict) | | | +| 2446 | [Determine if Two Events Have Conflict](https://leetcode.com/problems/determine-if-two-events-have-conflict) | [![Java](assets/java.png)](src/DetermineIfTwoEventsHaveConflict.java) | | | 2451 | [Odd String Difference](https://leetcode.com/problems/odd-string-difference) | | | | 2455 | [Average Value of Even Numbers That Are Divisible by Three](https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three) | | | | 2460 | [Apply Operations to an Array](https://leetcode.com/problems/apply-operations-to-an-array) | | | diff --git a/src/DetermineIfTwoEventsHaveConflict.java b/src/DetermineIfTwoEventsHaveConflict.java new file mode 100644 index 0000000..3f71f0c --- /dev/null +++ b/src/DetermineIfTwoEventsHaveConflict.java @@ -0,0 +1,32 @@ +// https://leetcode.com/problems/determine-if-two-events-have-conflict +// T: O(1) +// S: O(1) + +public class DetermineIfTwoEventsHaveConflict { + public boolean haveConflict(String[] event1, String[] event2) { + final int[] event1EpochMinutes = getEpochMinutes(event1); + final int[] event2EpochMinutes = getEpochMinutes(event2); + return isIntersecting(event1EpochMinutes, event2EpochMinutes); + } + + private boolean isIntersecting(int[] event1, int[] event2) { + return Math.min(event1[1], event2[1]) >= Math.max(event1[0], event2[0]); + } + + private int[] getEpochMinutes(String[] event) { + return new int[] { getEpochMinutes(event[0]), getEpochMinutes(event[1])}; + } + + private int getEpochMinutes(String event) { + final String hh = event.substring(0, 2), mm = event.substring(3); + return toInt(hh) * 60 + toInt(mm); + } + + private int toInt(String string) { + int result = 0; + for (int index = 0 ; index < string.length() ; index++) { + result = 10 * result + (string.charAt(index) - '0'); + } + return result; + } +} From 9e81a0e8954ccd672ad0aa3e6ff8ce26f0198b76 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 1 Jun 2023 18:34:28 +0200 Subject: [PATCH 073/280] solves #2451: Odd String Difference in java --- README.md | 2 +- src/OddStringDifference.java | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/OddStringDifference.java diff --git a/README.md b/README.md index 82dde14..004f40f 100644 --- a/README.md +++ b/README.md @@ -775,7 +775,7 @@ | 2437 | [Number of Valid Clock Times](https://leetcode.com/problems/number-of-valid-clock-times) | [![Java](assets/java.png)](src/NumberOfValidClockTimes.java) | | | 2441 | [Largest Positive Integer That Exists With Its Negative](https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative) | [![Java](assets/java.png)](src/LargestPositiveIntegerThatExistsWithItsNegative.java) | | | 2446 | [Determine if Two Events Have Conflict](https://leetcode.com/problems/determine-if-two-events-have-conflict) | [![Java](assets/java.png)](src/DetermineIfTwoEventsHaveConflict.java) | | -| 2451 | [Odd String Difference](https://leetcode.com/problems/odd-string-difference) | | | +| 2451 | [Odd String Difference](https://leetcode.com/problems/odd-string-difference) | [![Java](assets/java.png)](src/OddStringDifference.java) | | | 2455 | [Average Value of Even Numbers That Are Divisible by Three](https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three) | | | | 2460 | [Apply Operations to an Array](https://leetcode.com/problems/apply-operations-to-an-array) | | | | 2465 | [Number of Distinct Averages](https://leetcode.com/problems/number-of-distinct-averages) | | | diff --git a/src/OddStringDifference.java b/src/OddStringDifference.java new file mode 100644 index 0000000..af3219c --- /dev/null +++ b/src/OddStringDifference.java @@ -0,0 +1,33 @@ +// https://leetcode.com/problems/odd-string-difference +// T: O(|words| * |words[i]|) +// S: O(|words[i]|) + +import java.util.Arrays; + +public class OddStringDifference { + public String oddString(String[] words) { + final int[] diff1 = stringDiffArray(words[0]); + final int[] diff2 = stringDiffArray(words[1]); + + if (Arrays.equals(diff1, diff2)) { + for (int index = 2 ; index < words.length ; index++) { + final int[] diff = stringDiffArray(words[index]); + if (!Arrays.equals(diff1, diff)) return words[index]; + } + } else { + final int[] diff3 = stringDiffArray(words[2]); + if (Arrays.equals(diff1, diff3)) return words[1]; + return words[0]; + } + + return words[0]; + } + + private int[] stringDiffArray(String word) { + final int[] array = new int[word.length() - 1]; + for (int index = 0 ; index < word.length() - 1 ; index++) { + array[index] = word.charAt(index) - word.charAt(index + 1); + } + return array; + } +} From f932595379800658a7a62ad9b62394015b3e5fa7 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 3 Jun 2023 15:00:46 +0200 Subject: [PATCH 074/280] solves #2455: Average Value of Even Numbers That Are Divisible by Three in java --- README.md | 2 +- ...alueOfEvenNumbersThatAreDivisibleByThree.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/AverageValueOfEvenNumbersThatAreDivisibleByThree.java diff --git a/README.md b/README.md index 004f40f..6538e56 100644 --- a/README.md +++ b/README.md @@ -776,7 +776,7 @@ | 2441 | [Largest Positive Integer That Exists With Its Negative](https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative) | [![Java](assets/java.png)](src/LargestPositiveIntegerThatExistsWithItsNegative.java) | | | 2446 | [Determine if Two Events Have Conflict](https://leetcode.com/problems/determine-if-two-events-have-conflict) | [![Java](assets/java.png)](src/DetermineIfTwoEventsHaveConflict.java) | | | 2451 | [Odd String Difference](https://leetcode.com/problems/odd-string-difference) | [![Java](assets/java.png)](src/OddStringDifference.java) | | -| 2455 | [Average Value of Even Numbers That Are Divisible by Three](https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three) | | | +| 2455 | [Average Value of Even Numbers That Are Divisible by Three](https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three) | [![Java](assets/java.png)](src/AverageValueOfEvenNumbersThatAreDivisibleByThree.java) | | | 2460 | [Apply Operations to an Array](https://leetcode.com/problems/apply-operations-to-an-array) | | | | 2465 | [Number of Distinct Averages](https://leetcode.com/problems/number-of-distinct-averages) | | | | 2466 | [Count Ways To Build Good Strings](https://leetcode.com/problems/count-ways-to-build-good-strings) | | | diff --git a/src/AverageValueOfEvenNumbersThatAreDivisibleByThree.java b/src/AverageValueOfEvenNumbersThatAreDivisibleByThree.java new file mode 100644 index 0000000..cb3beab --- /dev/null +++ b/src/AverageValueOfEvenNumbersThatAreDivisibleByThree.java @@ -0,0 +1,16 @@ +// https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three +// T: O(N) +// S: O(1) + +public class AverageValueOfEvenNumbersThatAreDivisibleByThree { + public int averageValue(int[] array) { + int sum = 0, count = 0; + for (int element : array) { + if (element % 6 == 0) { + sum += element; + count++; + } + } + return count == 0 ? 0 : sum / count; + } +} From 189e88679ff7ef6a7dcb854a91162082d8490aeb Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 3 Jun 2023 15:16:01 +0200 Subject: [PATCH 075/280] solves #2460: Apply Operations to an Array in java --- README.md | 2 +- src/ApplyOperationsToAnArray.java | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/ApplyOperationsToAnArray.java diff --git a/README.md b/README.md index 6538e56..0fc1a78 100644 --- a/README.md +++ b/README.md @@ -777,7 +777,7 @@ | 2446 | [Determine if Two Events Have Conflict](https://leetcode.com/problems/determine-if-two-events-have-conflict) | [![Java](assets/java.png)](src/DetermineIfTwoEventsHaveConflict.java) | | | 2451 | [Odd String Difference](https://leetcode.com/problems/odd-string-difference) | [![Java](assets/java.png)](src/OddStringDifference.java) | | | 2455 | [Average Value of Even Numbers That Are Divisible by Three](https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three) | [![Java](assets/java.png)](src/AverageValueOfEvenNumbersThatAreDivisibleByThree.java) | | -| 2460 | [Apply Operations to an Array](https://leetcode.com/problems/apply-operations-to-an-array) | | | +| 2460 | [Apply Operations to an Array](https://leetcode.com/problems/apply-operations-to-an-array) | [![Java](assets/java.png)](src/ApplyOperationsToAnArray.java) | | | 2465 | [Number of Distinct Averages](https://leetcode.com/problems/number-of-distinct-averages) | | | | 2466 | [Count Ways To Build Good Strings](https://leetcode.com/problems/count-ways-to-build-good-strings) | | | | 2475 | [Number of Unequal Triplets in Array](https://leetcode.com/problems/number-of-unequal-triplets-in-array) | | | diff --git a/src/ApplyOperationsToAnArray.java b/src/ApplyOperationsToAnArray.java new file mode 100644 index 0000000..5b73b7f --- /dev/null +++ b/src/ApplyOperationsToAnArray.java @@ -0,0 +1,31 @@ +// https://leetcode.com/problems/apply-operations-to-an-array +// T: O(N) +// S: O(N) + +public class ApplyOperationsToAnArray { + public int[] applyOperations(int[] array) { + final int[] result = new int[array.length]; + int j = 0; + for (int i = 0, previous = array[0] ; i < array.length - 1 ; i++) { + if (previous == 0) { + previous = array[i + 1]; + continue; + } + + if (previous == array[i + 1]) { + result[j++] = 2 * array[i]; + previous = 0; + continue; + } + + result[j++] = array[i]; + previous = array[i + 1]; + } + + if (array[array.length - 2] != array[array.length - 1]) { + result[j] = array[array.length - 1]; + } + + return result; + } +} From 0b25c2011b78e6a85268e8e7777d07227f6629b5 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 3 Jun 2023 15:20:52 +0200 Subject: [PATCH 076/280] solves #2465: Number of Distinct Averages in java --- README.md | 2 +- src/NumberOfDistinctAverages.java | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 src/NumberOfDistinctAverages.java diff --git a/README.md b/README.md index 0fc1a78..04465d3 100644 --- a/README.md +++ b/README.md @@ -778,7 +778,7 @@ | 2451 | [Odd String Difference](https://leetcode.com/problems/odd-string-difference) | [![Java](assets/java.png)](src/OddStringDifference.java) | | | 2455 | [Average Value of Even Numbers That Are Divisible by Three](https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three) | [![Java](assets/java.png)](src/AverageValueOfEvenNumbersThatAreDivisibleByThree.java) | | | 2460 | [Apply Operations to an Array](https://leetcode.com/problems/apply-operations-to-an-array) | [![Java](assets/java.png)](src/ApplyOperationsToAnArray.java) | | -| 2465 | [Number of Distinct Averages](https://leetcode.com/problems/number-of-distinct-averages) | | | +| 2465 | [Number of Distinct Averages](https://leetcode.com/problems/number-of-distinct-averages) | [![Java](assets/java.png)](src/NumberOfDistinctAverages.java) | | | 2466 | [Count Ways To Build Good Strings](https://leetcode.com/problems/count-ways-to-build-good-strings) | | | | 2475 | [Number of Unequal Triplets in Array](https://leetcode.com/problems/number-of-unequal-triplets-in-array) | | | | 2481 | [Minimum Cuts to Divide a Circle](https://leetcode.com/problems/minimum-cuts-to-divide-a-circle) | | | diff --git a/src/NumberOfDistinctAverages.java b/src/NumberOfDistinctAverages.java new file mode 100644 index 0000000..26e4e04 --- /dev/null +++ b/src/NumberOfDistinctAverages.java @@ -0,0 +1,21 @@ +// https://leetcode.com/problems/number-of-distinct-averages +// T: O(Nlog(N)) +// S: O(N) + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +public class NumberOfDistinctAverages { + public int distinctAverages(int[] nums) { + final Set set = new HashSet<>(); + Arrays.sort(nums); + + for (int i = 0 ; i < nums.length / 2 ; i++) { + int sum = nums[i] + nums[nums.length - 1 - i]; + set.add(sum); + } + + return set.size(); + } +} From 96d65c4ec8a9fd3ce2c226d85300bbbff960284f Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 3 Jun 2023 15:26:06 +0200 Subject: [PATCH 077/280] solves #2469: Convert the Temperature in java --- README.md | 1 + src/ConvertTheTemperature.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 src/ConvertTheTemperature.java diff --git a/README.md b/README.md index 04465d3..b844529 100644 --- a/README.md +++ b/README.md @@ -780,6 +780,7 @@ | 2460 | [Apply Operations to an Array](https://leetcode.com/problems/apply-operations-to-an-array) | [![Java](assets/java.png)](src/ApplyOperationsToAnArray.java) | | | 2465 | [Number of Distinct Averages](https://leetcode.com/problems/number-of-distinct-averages) | [![Java](assets/java.png)](src/NumberOfDistinctAverages.java) | | | 2466 | [Count Ways To Build Good Strings](https://leetcode.com/problems/count-ways-to-build-good-strings) | | | +| 2469 | [Convert the Temperature](https://leetcode.com/problems/convert-the-temperature) | [![Java](assets/java.png)](src/ConvertTheTemperature.java) | | | 2475 | [Number of Unequal Triplets in Array](https://leetcode.com/problems/number-of-unequal-triplets-in-array) | | | | 2481 | [Minimum Cuts to Divide a Circle](https://leetcode.com/problems/minimum-cuts-to-divide-a-circle) | | | | 2485 | [Find the Pivot Integer](https://leetcode.com/problems/find-the-pivot-integer) | | | diff --git a/src/ConvertTheTemperature.java b/src/ConvertTheTemperature.java new file mode 100644 index 0000000..bed0850 --- /dev/null +++ b/src/ConvertTheTemperature.java @@ -0,0 +1,17 @@ +// https://leetcode.com/problems/convert-the-temperature +// T: O(1) +// S: O(1) + +public class ConvertTheTemperature { + public double[] convertTemperature(double celsius) { + return new double[] { celsiusToKelvin(celsius), celsiusToFahrenheit(celsius) }; + } + + private double celsiusToFahrenheit(double celsius) { + return celsius * 1.8 + 32.00; + } + + private double celsiusToKelvin(double celsius) { + return celsius + 273.15; + } +} From 00cced96e3cee3b9a8e9a6fe60934df7f52bf18f Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 3 Jun 2023 15:56:16 +0200 Subject: [PATCH 078/280] solves #2475: Number of Unequal Triplets in Array in java --- README.md | 2 +- src/NumberOfUnequalTripletsInArray.java | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 src/NumberOfUnequalTripletsInArray.java diff --git a/README.md b/README.md index b844529..7eb6eaf 100644 --- a/README.md +++ b/README.md @@ -781,7 +781,7 @@ | 2465 | [Number of Distinct Averages](https://leetcode.com/problems/number-of-distinct-averages) | [![Java](assets/java.png)](src/NumberOfDistinctAverages.java) | | | 2466 | [Count Ways To Build Good Strings](https://leetcode.com/problems/count-ways-to-build-good-strings) | | | | 2469 | [Convert the Temperature](https://leetcode.com/problems/convert-the-temperature) | [![Java](assets/java.png)](src/ConvertTheTemperature.java) | | -| 2475 | [Number of Unequal Triplets in Array](https://leetcode.com/problems/number-of-unequal-triplets-in-array) | | | +| 2475 | [Number of Unequal Triplets in Array](https://leetcode.com/problems/number-of-unequal-triplets-in-array) | [![Java](assets/java.png)](src/NumberOfUnequalTripletsInArray.java) | | | 2481 | [Minimum Cuts to Divide a Circle](https://leetcode.com/problems/minimum-cuts-to-divide-a-circle) | | | | 2485 | [Find the Pivot Integer](https://leetcode.com/problems/find-the-pivot-integer) | | | | 2490 | [Circular Sentence](https://leetcode.com/problems/circular-sentence) | | | diff --git a/src/NumberOfUnequalTripletsInArray.java b/src/NumberOfUnequalTripletsInArray.java new file mode 100644 index 0000000..5a0cbc7 --- /dev/null +++ b/src/NumberOfUnequalTripletsInArray.java @@ -0,0 +1,21 @@ +// https://leetcode.com/problems/number-of-unequal-triplets-in-array +// T: O(N) +// S: O(N) + +import java.util.HashMap; +import java.util.Map; + +public class NumberOfUnequalTripletsInArray { + public int unequalTriplets(int[] array) { + final Map frequency = new HashMap<>(); + int pairs = 0, triplets = 0; + for (int index = 0 ; index < array.length ; index++) { + frequency.put(array[index], frequency.getOrDefault(array[index], 0) + 1); + final int pairsWithElement = index + 1 - frequency.getOrDefault(array[index], 0); + pairs += pairsWithElement; + final int pairsWithoutElement = pairs - pairsWithElement * frequency.getOrDefault(array[index], 0); + triplets += pairsWithoutElement; + } + return triplets; + } +} From f84f1589828af20f177c61b83e63654a9e41f384 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 3 Jun 2023 16:09:35 +0200 Subject: [PATCH 079/280] solves #2481: Minimum Cuts to Divide a Circle in java --- README.md | 2 +- src/MinimumCutsToDivideACircle.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 src/MinimumCutsToDivideACircle.java diff --git a/README.md b/README.md index 7eb6eaf..a4c78cd 100644 --- a/README.md +++ b/README.md @@ -782,7 +782,7 @@ | 2466 | [Count Ways To Build Good Strings](https://leetcode.com/problems/count-ways-to-build-good-strings) | | | | 2469 | [Convert the Temperature](https://leetcode.com/problems/convert-the-temperature) | [![Java](assets/java.png)](src/ConvertTheTemperature.java) | | | 2475 | [Number of Unequal Triplets in Array](https://leetcode.com/problems/number-of-unequal-triplets-in-array) | [![Java](assets/java.png)](src/NumberOfUnequalTripletsInArray.java) | | -| 2481 | [Minimum Cuts to Divide a Circle](https://leetcode.com/problems/minimum-cuts-to-divide-a-circle) | | | +| 2481 | [Minimum Cuts to Divide a Circle](https://leetcode.com/problems/minimum-cuts-to-divide-a-circle) | [![Java](assets/java.png)](src/MinimumCutsToDivideACircle.java) | | | 2485 | [Find the Pivot Integer](https://leetcode.com/problems/find-the-pivot-integer) | | | | 2490 | [Circular Sentence](https://leetcode.com/problems/circular-sentence) | | | | 2492 | [Minimum Score of a Path Between Two Cities](https://leetcode.com/problems/minimum-score-of-a-path-between-two-cities) | [![Python](assets/python.png)](python/minimum_score_of_a_path_between_two_cities.py) | | diff --git a/src/MinimumCutsToDivideACircle.java b/src/MinimumCutsToDivideACircle.java new file mode 100644 index 0000000..82fb626 --- /dev/null +++ b/src/MinimumCutsToDivideACircle.java @@ -0,0 +1,10 @@ +// https://leetcode.com/problems/minimum-cuts-to-divide-a-circle +// T: O(1) +// S: O(1) + +public class MinimumCutsToDivideACircle { + public int numberOfCuts(int n) { + if (n == 1) return 0; + return n % 2 == 0 ? n / 2 : n; + } +} From 15347550df17891deaf826f6dcb4efd1341f90e1 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 3 Jun 2023 16:22:24 +0200 Subject: [PATCH 080/280] solves #2485: Find the Pivot Integer in java --- README.md | 2 +- src/FindThePivotInteger.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/FindThePivotInteger.java diff --git a/README.md b/README.md index a4c78cd..e947782 100644 --- a/README.md +++ b/README.md @@ -783,7 +783,7 @@ | 2469 | [Convert the Temperature](https://leetcode.com/problems/convert-the-temperature) | [![Java](assets/java.png)](src/ConvertTheTemperature.java) | | | 2475 | [Number of Unequal Triplets in Array](https://leetcode.com/problems/number-of-unequal-triplets-in-array) | [![Java](assets/java.png)](src/NumberOfUnequalTripletsInArray.java) | | | 2481 | [Minimum Cuts to Divide a Circle](https://leetcode.com/problems/minimum-cuts-to-divide-a-circle) | [![Java](assets/java.png)](src/MinimumCutsToDivideACircle.java) | | -| 2485 | [Find the Pivot Integer](https://leetcode.com/problems/find-the-pivot-integer) | | | +| 2485 | [Find the Pivot Integer](https://leetcode.com/problems/find-the-pivot-integer) | [![Java](assets/java.png)](src/FindThePivotInteger.java) | | | 2490 | [Circular Sentence](https://leetcode.com/problems/circular-sentence) | | | | 2492 | [Minimum Score of a Path Between Two Cities](https://leetcode.com/problems/minimum-score-of-a-path-between-two-cities) | [![Python](assets/python.png)](python/minimum_score_of_a_path_between_two_cities.py) | | | 2496 | [Maximum Value of a String in an Array](https://leetcode.com/problems/maximum-value-of-a-string-in-an-array) | | | diff --git a/src/FindThePivotInteger.java b/src/FindThePivotInteger.java new file mode 100644 index 0000000..75c8145 --- /dev/null +++ b/src/FindThePivotInteger.java @@ -0,0 +1,19 @@ +// https://leetcode.com/problems/find-the-pivot-integer +// T: O(N) +// S: O(1) + +public class FindThePivotInteger { + public int pivotInteger(int n) { + for (int pivot = 1, left = 1, right = summation(n) ; pivot <= n ; pivot++) { + if (left == right) return pivot; + if (left > right) break; + left += pivot + 1; + right -= pivot; + } + return -1; + } + + private int summation(int n) { + return (n * (n + 1)) / 2; + } +} From fc73fe6151acf50c4f185f2ed6b297a78a935339 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 3 Jun 2023 16:27:10 +0200 Subject: [PATCH 081/280] solves #2490: Circular Sentence in java --- README.md | 2 +- src/CircularSentence.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/CircularSentence.java diff --git a/README.md b/README.md index e947782..655ee5c 100644 --- a/README.md +++ b/README.md @@ -784,7 +784,7 @@ | 2475 | [Number of Unequal Triplets in Array](https://leetcode.com/problems/number-of-unequal-triplets-in-array) | [![Java](assets/java.png)](src/NumberOfUnequalTripletsInArray.java) | | | 2481 | [Minimum Cuts to Divide a Circle](https://leetcode.com/problems/minimum-cuts-to-divide-a-circle) | [![Java](assets/java.png)](src/MinimumCutsToDivideACircle.java) | | | 2485 | [Find the Pivot Integer](https://leetcode.com/problems/find-the-pivot-integer) | [![Java](assets/java.png)](src/FindThePivotInteger.java) | | -| 2490 | [Circular Sentence](https://leetcode.com/problems/circular-sentence) | | | +| 2490 | [Circular Sentence](https://leetcode.com/problems/circular-sentence) | [![Java](assets/java.png)](src/CircularSentence.java) | | | 2492 | [Minimum Score of a Path Between Two Cities](https://leetcode.com/problems/minimum-score-of-a-path-between-two-cities) | [![Python](assets/python.png)](python/minimum_score_of_a_path_between_two_cities.py) | | | 2496 | [Maximum Value of a String in an Array](https://leetcode.com/problems/maximum-value-of-a-string-in-an-array) | | | | 2500 | [Delete Greatest Value in Each Row](https://leetcode.com/problems/delete-greatest-value-in-each-row) | | | diff --git a/src/CircularSentence.java b/src/CircularSentence.java new file mode 100644 index 0000000..2c531ea --- /dev/null +++ b/src/CircularSentence.java @@ -0,0 +1,15 @@ +// https://leetcode.com/problems/circular-sentence +// T: O(N) +// S: O(1) + +public class CircularSentence { + public boolean isCircularSentence(String sentence) { + for (int index = 0 ; index < sentence.length() ; index++) { + char letter = sentence.charAt(index); + if (letter == ' ' && sentence.charAt(index - 1) != sentence.charAt(index + 1)) { + return false; + } + } + return sentence.charAt(0) == sentence.charAt(sentence.length() - 1); + } +} From dc9d309ea9eaccba368b69b93c2fb833bd842883 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 3 Jun 2023 16:32:23 +0200 Subject: [PATCH 082/280] solves #2496: Maximum Value of a String in an Array in java --- README.md | 2 +- src/MaximumValueOfAStringInAnArray.java | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 src/MaximumValueOfAStringInAnArray.java diff --git a/README.md b/README.md index 655ee5c..8e41f2d 100644 --- a/README.md +++ b/README.md @@ -786,7 +786,7 @@ | 2485 | [Find the Pivot Integer](https://leetcode.com/problems/find-the-pivot-integer) | [![Java](assets/java.png)](src/FindThePivotInteger.java) | | | 2490 | [Circular Sentence](https://leetcode.com/problems/circular-sentence) | [![Java](assets/java.png)](src/CircularSentence.java) | | | 2492 | [Minimum Score of a Path Between Two Cities](https://leetcode.com/problems/minimum-score-of-a-path-between-two-cities) | [![Python](assets/python.png)](python/minimum_score_of_a_path_between_two_cities.py) | | -| 2496 | [Maximum Value of a String in an Array](https://leetcode.com/problems/maximum-value-of-a-string-in-an-array) | | | +| 2496 | [Maximum Value of a String in an Array](https://leetcode.com/problems/maximum-value-of-a-string-in-an-array) | [![Java](assets/java.png)](src/MaximumValueOfAStringInAnArray.java) | | | 2500 | [Delete Greatest Value in Each Row](https://leetcode.com/problems/delete-greatest-value-in-each-row) | | | | 2506 | [Count Pairs Of Similar Strings](https://leetcode.com/problems/count-pairs-of-similar-strings) | | | | 2511 | [Maximum Enemy Forts That Can Be Captured](https://leetcode.com/problems/maximum-enemy-forts-that-can-be-captured) | | | diff --git a/src/MaximumValueOfAStringInAnArray.java b/src/MaximumValueOfAStringInAnArray.java new file mode 100644 index 0000000..a0d352f --- /dev/null +++ b/src/MaximumValueOfAStringInAnArray.java @@ -0,0 +1,21 @@ +// https://leetcode.com/problems/maximum-value-of-a-string-in-an-array +// T: O(|strings| * |strings[i]|) +// S: O(1) + +public class MaximumValueOfAStringInAnArray { + public int maximumValue(String[] strings) { + int max = -1; + for (String string : strings) { + max = Math.max(max, value(string)); + } + return max; + } + + private int value(String string) { + try { + return Integer.parseInt(string); + } catch (Exception e) { + return string.length(); + } + } +} From cd1c790f0166e0994dcac54d5c66dbaac16fc0a0 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 3 Jun 2023 16:40:43 +0200 Subject: [PATCH 083/280] solves #2500: Delete Greatest Value in Each Row in java --- README.md | 2 +- src/DeleteGreatestValueInEachRow.java | 34 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/DeleteGreatestValueInEachRow.java diff --git a/README.md b/README.md index 8e41f2d..b6bc972 100644 --- a/README.md +++ b/README.md @@ -787,7 +787,7 @@ | 2490 | [Circular Sentence](https://leetcode.com/problems/circular-sentence) | [![Java](assets/java.png)](src/CircularSentence.java) | | | 2492 | [Minimum Score of a Path Between Two Cities](https://leetcode.com/problems/minimum-score-of-a-path-between-two-cities) | [![Python](assets/python.png)](python/minimum_score_of_a_path_between_two_cities.py) | | | 2496 | [Maximum Value of a String in an Array](https://leetcode.com/problems/maximum-value-of-a-string-in-an-array) | [![Java](assets/java.png)](src/MaximumValueOfAStringInAnArray.java) | | -| 2500 | [Delete Greatest Value in Each Row](https://leetcode.com/problems/delete-greatest-value-in-each-row) | | | +| 2500 | [Delete Greatest Value in Each Row](https://leetcode.com/problems/delete-greatest-value-in-each-row) | [![Java](assets/java.png)](src/DeleteGreatestValueInEachRow.java) | | | 2506 | [Count Pairs Of Similar Strings](https://leetcode.com/problems/count-pairs-of-similar-strings) | | | | 2511 | [Maximum Enemy Forts That Can Be Captured](https://leetcode.com/problems/maximum-enemy-forts-that-can-be-captured) | | | | 2515 | [Shortest Distance to Target String in a Circular Array](https://leetcode.com/problems/shortest-distance-to-target-string-in-a-circular-array) | | | diff --git a/src/DeleteGreatestValueInEachRow.java b/src/DeleteGreatestValueInEachRow.java new file mode 100644 index 0000000..db8efbc --- /dev/null +++ b/src/DeleteGreatestValueInEachRow.java @@ -0,0 +1,34 @@ +// https://leetcode.com/problems/delete-greatest-value-in-each-row +// T: O(mn * log(N)) +// S: O(log(n)) + +import java.util.Arrays; + +public class DeleteGreatestValueInEachRow { + public int deleteGreatestValue(int[][] grid) { + final int columns = grid[0].length; + int maxDeletions = 0; + + sortAllRows(grid); + + for (int column = 0 ; column < columns ; column++) { + maxDeletions += columnMax(grid, column); + } + + return maxDeletions; + } + + private int columnMax(int[][] grid, int column) { + int max = Integer.MIN_VALUE; + for (int[] row : grid) { + max = Math.max(max, row[column]); + } + return max; + } + + private void sortAllRows(int[][] grid) { + for (int[] row : grid) { + Arrays.sort(row); + } + } +} From 5c9661fb25d17123f9cf077b46d054dc1d0d4dc5 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 3 Jun 2023 16:50:09 +0200 Subject: [PATCH 084/280] solves #2506: Count Pairs Of Similar Strings in java --- README.md | 2 +- src/CountPairsOfSimilarStrings.java | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/CountPairsOfSimilarStrings.java diff --git a/README.md b/README.md index b6bc972..fd86baf 100644 --- a/README.md +++ b/README.md @@ -788,7 +788,7 @@ | 2492 | [Minimum Score of a Path Between Two Cities](https://leetcode.com/problems/minimum-score-of-a-path-between-two-cities) | [![Python](assets/python.png)](python/minimum_score_of_a_path_between_two_cities.py) | | | 2496 | [Maximum Value of a String in an Array](https://leetcode.com/problems/maximum-value-of-a-string-in-an-array) | [![Java](assets/java.png)](src/MaximumValueOfAStringInAnArray.java) | | | 2500 | [Delete Greatest Value in Each Row](https://leetcode.com/problems/delete-greatest-value-in-each-row) | [![Java](assets/java.png)](src/DeleteGreatestValueInEachRow.java) | | -| 2506 | [Count Pairs Of Similar Strings](https://leetcode.com/problems/count-pairs-of-similar-strings) | | | +| 2506 | [Count Pairs Of Similar Strings](https://leetcode.com/problems/count-pairs-of-similar-strings) | [![Java](assets/java.png)](src/CountPairsOfSimilarStrings.java) | | | 2511 | [Maximum Enemy Forts That Can Be Captured](https://leetcode.com/problems/maximum-enemy-forts-that-can-be-captured) | | | | 2515 | [Shortest Distance to Target String in a Circular Array](https://leetcode.com/problems/shortest-distance-to-target-string-in-a-circular-array) | | | | 2520 | [Count the Digits That Divide a Number](https://leetcode.com/problems/count-the-digits-that-divide-a-number) | | | diff --git a/src/CountPairsOfSimilarStrings.java b/src/CountPairsOfSimilarStrings.java new file mode 100644 index 0000000..ab5ef27 --- /dev/null +++ b/src/CountPairsOfSimilarStrings.java @@ -0,0 +1,29 @@ +// https://leetcode.com/problems/count-pairs-of-similar-strings +// T: O(|words| * |words[i]|) +// S: O(|words|) + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public class CountPairsOfSimilarStrings { + public int similarPairs(String[] words) { + Map, Integer> frequency = new HashMap<>(); + int pairs = 0; + for (String word : words) { + final Set letters = getLetters(word); + pairs += frequency.getOrDefault(letters, 0); + frequency.put(letters, frequency.getOrDefault(letters, 0) + 1); + } + return pairs; + } + + private Set getLetters(String word) { + final Set set = new HashSet<>(); + for (int index = 0 ; index < word.length() ; index++) { + set.add(word.charAt(index)); + } + return set; + } +} From 983e2ea44bba2b215660c5a1b0457f777ae2c304 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 3 Jun 2023 17:02:07 +0200 Subject: [PATCH 085/280] solves #2511: Maximum Enemy Forts That Can Be Captured in java --- README.md | 2 +- src/MaximumEnemyFortsThatCanBeCaptured.java | 25 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/MaximumEnemyFortsThatCanBeCaptured.java diff --git a/README.md b/README.md index fd86baf..d956876 100644 --- a/README.md +++ b/README.md @@ -789,7 +789,7 @@ | 2496 | [Maximum Value of a String in an Array](https://leetcode.com/problems/maximum-value-of-a-string-in-an-array) | [![Java](assets/java.png)](src/MaximumValueOfAStringInAnArray.java) | | | 2500 | [Delete Greatest Value in Each Row](https://leetcode.com/problems/delete-greatest-value-in-each-row) | [![Java](assets/java.png)](src/DeleteGreatestValueInEachRow.java) | | | 2506 | [Count Pairs Of Similar Strings](https://leetcode.com/problems/count-pairs-of-similar-strings) | [![Java](assets/java.png)](src/CountPairsOfSimilarStrings.java) | | -| 2511 | [Maximum Enemy Forts That Can Be Captured](https://leetcode.com/problems/maximum-enemy-forts-that-can-be-captured) | | | +| 2511 | [Maximum Enemy Forts That Can Be Captured](https://leetcode.com/problems/maximum-enemy-forts-that-can-be-captured) | [![Java](assets/java.png)](src/MaximumEnemyFortsThatCanBeCaptured.java) | | | 2515 | [Shortest Distance to Target String in a Circular Array](https://leetcode.com/problems/shortest-distance-to-target-string-in-a-circular-array) | | | | 2520 | [Count the Digits That Divide a Number](https://leetcode.com/problems/count-the-digits-that-divide-a-number) | | | | 2525 | [Categorize Box According to Criteria](https://leetcode.com/problems/categorize-box-according-to-criteria) | | | diff --git a/src/MaximumEnemyFortsThatCanBeCaptured.java b/src/MaximumEnemyFortsThatCanBeCaptured.java new file mode 100644 index 0000000..f6dcccd --- /dev/null +++ b/src/MaximumEnemyFortsThatCanBeCaptured.java @@ -0,0 +1,25 @@ +// https://leetcode.com/problems/maximum-enemy-forts-that-can-be-captured +// T: O(N) +// S: O(1) + +public class MaximumEnemyFortsThatCanBeCaptured { + public int captureForts(int[] forts) { + int last1 = Integer.MAX_VALUE, last_1 = Integer.MAX_VALUE, maxCapture = 0, previous = 0; + for (int index = 0 ; index < forts.length ; index++) { + if (forts[index] == 1) { + if (last_1 != Integer.MAX_VALUE && previous == -1) { + maxCapture = Math.max(maxCapture, index - last_1 - 1); + } + previous = 1; + last1 = index; + } else if (forts[index] == -1) { + if (last1 != Integer.MAX_VALUE && previous == 1) { + maxCapture = Math.max(maxCapture, index - last1 - 1); + } + previous = -1; + last_1 = index; + } + } + return maxCapture; + } +} From 43be83440d8cbbeef745d427fc8e9c9256c43be1 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 3 Jun 2023 17:20:46 +0200 Subject: [PATCH 086/280] solves #2515: Shortest Distance to Target String in a Circular Array in java --- README.md | 2 +- ...tDistanceToTargetStringInACircularArray.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/ShortestDistanceToTargetStringInACircularArray.java diff --git a/README.md b/README.md index d956876..9ff790b 100644 --- a/README.md +++ b/README.md @@ -790,7 +790,7 @@ | 2500 | [Delete Greatest Value in Each Row](https://leetcode.com/problems/delete-greatest-value-in-each-row) | [![Java](assets/java.png)](src/DeleteGreatestValueInEachRow.java) | | | 2506 | [Count Pairs Of Similar Strings](https://leetcode.com/problems/count-pairs-of-similar-strings) | [![Java](assets/java.png)](src/CountPairsOfSimilarStrings.java) | | | 2511 | [Maximum Enemy Forts That Can Be Captured](https://leetcode.com/problems/maximum-enemy-forts-that-can-be-captured) | [![Java](assets/java.png)](src/MaximumEnemyFortsThatCanBeCaptured.java) | | -| 2515 | [Shortest Distance to Target String in a Circular Array](https://leetcode.com/problems/shortest-distance-to-target-string-in-a-circular-array) | | | +| 2515 | [Shortest Distance to Target String in a Circular Array](https://leetcode.com/problems/shortest-distance-to-target-string-in-a-circular-array) | [![Java](assets/java.png)](src/ShortestDistanceToTargetStringInACircularArray.java) | | | 2520 | [Count the Digits That Divide a Number](https://leetcode.com/problems/count-the-digits-that-divide-a-number) | | | | 2525 | [Categorize Box According to Criteria](https://leetcode.com/problems/categorize-box-according-to-criteria) | | | | 2529 | [Maximum Count of Positive Integer and Negative Integer](https://leetcode.com/problems/maximum-count-of-positive-integer-and-negative-integer) | | | diff --git a/src/ShortestDistanceToTargetStringInACircularArray.java b/src/ShortestDistanceToTargetStringInACircularArray.java new file mode 100644 index 0000000..bfc4b96 --- /dev/null +++ b/src/ShortestDistanceToTargetStringInACircularArray.java @@ -0,0 +1,17 @@ +// https://leetcode.com/problems/shortest-distance-to-target-string-in-a-circular-array +// T: O(N) +// S: O(1) + +public class ShortestDistanceToTargetStringInACircularArray { + public int closetTarget(String[] words, String target, int startIndex) { + if (words[startIndex].equals(target)) return 0; + + for (int left = (startIndex - 1 + words.length) % words.length, right = (startIndex + 1) % words.length, count = 1; + count <= words.length / 2; + left = (left - 1 + words.length) % words.length, right = (right + 1) % words.length, count++ + ) { + if (words[left].equals(target) || words[right].equals(target)) return count; + } + return -1; + } +} From e3c901c68cdc9be72bfed29044b9f687a178aaed Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 3 Jun 2023 17:26:08 +0200 Subject: [PATCH 087/280] solves #2520: Count the Digits That Divide a Number in java --- README.md | 2 +- src/CountTheDigitsThatDivideANumber.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/CountTheDigitsThatDivideANumber.java diff --git a/README.md b/README.md index 9ff790b..253a216 100644 --- a/README.md +++ b/README.md @@ -791,7 +791,7 @@ | 2506 | [Count Pairs Of Similar Strings](https://leetcode.com/problems/count-pairs-of-similar-strings) | [![Java](assets/java.png)](src/CountPairsOfSimilarStrings.java) | | | 2511 | [Maximum Enemy Forts That Can Be Captured](https://leetcode.com/problems/maximum-enemy-forts-that-can-be-captured) | [![Java](assets/java.png)](src/MaximumEnemyFortsThatCanBeCaptured.java) | | | 2515 | [Shortest Distance to Target String in a Circular Array](https://leetcode.com/problems/shortest-distance-to-target-string-in-a-circular-array) | [![Java](assets/java.png)](src/ShortestDistanceToTargetStringInACircularArray.java) | | -| 2520 | [Count the Digits That Divide a Number](https://leetcode.com/problems/count-the-digits-that-divide-a-number) | | | +| 2520 | [Count the Digits That Divide a Number](https://leetcode.com/problems/count-the-digits-that-divide-a-number) | [![Java](assets/java.png)](src/CountTheDigitsThatDivideANumber.java) | | | 2525 | [Categorize Box According to Criteria](https://leetcode.com/problems/categorize-box-according-to-criteria) | | | | 2529 | [Maximum Count of Positive Integer and Negative Integer](https://leetcode.com/problems/maximum-count-of-positive-integer-and-negative-integer) | | | | 2535 | [Difference Between Element Sum and Digit Sum of an Array](https://leetcode.com/problems/difference-between-element-sum-and-digit-sum-of-an-array) | | | diff --git a/src/CountTheDigitsThatDivideANumber.java b/src/CountTheDigitsThatDivideANumber.java new file mode 100644 index 0000000..861e170 --- /dev/null +++ b/src/CountTheDigitsThatDivideANumber.java @@ -0,0 +1,15 @@ +// https://leetcode.com/problems/count-the-digits-that-divide-a-number +// T: O(log(N)) +// S: O(1) + +public class CountTheDigitsThatDivideANumber { + public int countDigits(int num) { + final String number = num + ""; + int divisors = 0; + for (int index = 0 ; index < number.length() ; index++) { + int digit = number.charAt(index) - '0'; + if (num % digit == 0) divisors++; + } + return divisors; + } +} From 6c09db4ed6c06ff1aa93f0097c922097342d87db Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 3 Jun 2023 17:34:37 +0200 Subject: [PATCH 088/280] solves #2525: Categorize Box According to Criteria in java --- README.md | 2 +- src/CategorizeBoxAccordingToCriteria.java | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/CategorizeBoxAccordingToCriteria.java diff --git a/README.md b/README.md index 253a216..5c60f60 100644 --- a/README.md +++ b/README.md @@ -792,7 +792,7 @@ | 2511 | [Maximum Enemy Forts That Can Be Captured](https://leetcode.com/problems/maximum-enemy-forts-that-can-be-captured) | [![Java](assets/java.png)](src/MaximumEnemyFortsThatCanBeCaptured.java) | | | 2515 | [Shortest Distance to Target String in a Circular Array](https://leetcode.com/problems/shortest-distance-to-target-string-in-a-circular-array) | [![Java](assets/java.png)](src/ShortestDistanceToTargetStringInACircularArray.java) | | | 2520 | [Count the Digits That Divide a Number](https://leetcode.com/problems/count-the-digits-that-divide-a-number) | [![Java](assets/java.png)](src/CountTheDigitsThatDivideANumber.java) | | -| 2525 | [Categorize Box According to Criteria](https://leetcode.com/problems/categorize-box-according-to-criteria) | | | +| 2525 | [Categorize Box According to Criteria](https://leetcode.com/problems/categorize-box-according-to-criteria) | [![Java](assets/java.png)](src/CategorizeBoxAccordingToCriteria.java) | | | 2529 | [Maximum Count of Positive Integer and Negative Integer](https://leetcode.com/problems/maximum-count-of-positive-integer-and-negative-integer) | | | | 2535 | [Difference Between Element Sum and Digit Sum of an Array](https://leetcode.com/problems/difference-between-element-sum-and-digit-sum-of-an-array) | | | | 2540 | [Minimum Common Value](https://leetcode.com/problems/minimum-common-value) | | | diff --git a/src/CategorizeBoxAccordingToCriteria.java b/src/CategorizeBoxAccordingToCriteria.java new file mode 100644 index 0000000..52ffd7e --- /dev/null +++ b/src/CategorizeBoxAccordingToCriteria.java @@ -0,0 +1,20 @@ +// https://leetcode.com/problems/categorize-box-according-to-criteria +// T: O(1) +// S: O(1) + +public class CategorizeBoxAccordingToCriteria { + public String categorizeBox(int length, int width, int height, int mass) { + final boolean isBulky = isBulky(length, width, height, mass); + final boolean isHeavy = mass >= 100; + + if (isBulky && isHeavy) return "Both"; + if (!isBulky && !isHeavy) return "Neither"; + if (isBulky) return "Bulky"; + return "Heavy"; + } + + private boolean isBulky(long length, long width, long height, long mass) { + long volume = length * width * height; + return length >= 10_000 || width >= 10_000 || height >= 10_000 || mass >= 10_000 || volume >= 1_000_000_000; + } +} From dc24bcad8cc60c14a75997c09f885c139633be9f Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 3 Jun 2023 17:55:39 +0200 Subject: [PATCH 089/280] solves #2529: Maximum Count of Positive Integer and Negative Integer in java --- README.md | 2 +- ...ntOfPositiveIntegerAndNegativeInteger.java | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/MaximumCountOfPositiveIntegerAndNegativeInteger.java diff --git a/README.md b/README.md index 5c60f60..8e9daef 100644 --- a/README.md +++ b/README.md @@ -793,7 +793,7 @@ | 2515 | [Shortest Distance to Target String in a Circular Array](https://leetcode.com/problems/shortest-distance-to-target-string-in-a-circular-array) | [![Java](assets/java.png)](src/ShortestDistanceToTargetStringInACircularArray.java) | | | 2520 | [Count the Digits That Divide a Number](https://leetcode.com/problems/count-the-digits-that-divide-a-number) | [![Java](assets/java.png)](src/CountTheDigitsThatDivideANumber.java) | | | 2525 | [Categorize Box According to Criteria](https://leetcode.com/problems/categorize-box-according-to-criteria) | [![Java](assets/java.png)](src/CategorizeBoxAccordingToCriteria.java) | | -| 2529 | [Maximum Count of Positive Integer and Negative Integer](https://leetcode.com/problems/maximum-count-of-positive-integer-and-negative-integer) | | | +| 2529 | [Maximum Count of Positive Integer and Negative Integer](https://leetcode.com/problems/maximum-count-of-positive-integer-and-negative-integer) | [![Java](assets/java.png)](src/MaximumCountOfPositiveIntegerAndNegativeInteger.java) | | | 2535 | [Difference Between Element Sum and Digit Sum of an Array](https://leetcode.com/problems/difference-between-element-sum-and-digit-sum-of-an-array) | | | | 2540 | [Minimum Common Value](https://leetcode.com/problems/minimum-common-value) | | | | 2544 | [Alternating Digit Sum](https://leetcode.com/problems/alternating-digit-sum) | | | diff --git a/src/MaximumCountOfPositiveIntegerAndNegativeInteger.java b/src/MaximumCountOfPositiveIntegerAndNegativeInteger.java new file mode 100644 index 0000000..70da0bf --- /dev/null +++ b/src/MaximumCountOfPositiveIntegerAndNegativeInteger.java @@ -0,0 +1,39 @@ +// https://leetcode.com/problems/maximum-count-of-positive-integer-and-negative-integer +// T: O(log(N)) +// S: O(1) + +public class MaximumCountOfPositiveIntegerAndNegativeInteger { + public int maximumCount(int[] nums) { + int firstIndex = binarySearchFirstIndex(nums, 0); + int lastIndex = binarySearchLastIndex(nums, 0); + return Math.max(firstIndex, nums.length - lastIndex - (lastIndex < nums.length && nums[lastIndex] == 0 ? 1 : 0)); + } + + // left leaning binary search with insertion point + private int binarySearchFirstIndex(int[] array, int x) { + int left = 0, right = array.length - 1, middle, index = -1; + while (left <= right) { + middle = left + (right - left) / 2; + if (array[middle] == x) { + index = middle; + right = middle - 1; + } else if (array[middle] > x) right = middle - 1; + else left = middle + 1; + } + return index == -1 ? left : index; + } + + // right leaning binary search with insertion point + private int binarySearchLastIndex(int[] array, int x) { + int left = 0, right = array.length - 1, middle, index = -1; + while (left <= right) { + middle = left + (right - left) / 2; + if (array[middle] == x) { + index = middle; + left = middle + 1; + } else if (array[middle] > x) right = middle - 1; + else left = middle + 1; + } + return index == -1 ? left : index; + } +} From 5fe1765a78e5b5e30d3feecd76056d9adca4c353 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 3 Jun 2023 18:00:57 +0200 Subject: [PATCH 090/280] solves #2535: Difference Between Element Sum and Digit Sum of an Array in java --- README.md | 2 +- ...BetweenElementSumAndDigitSumOfAnArray.java | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/DifferenceBetweenElementSumAndDigitSumOfAnArray.java diff --git a/README.md b/README.md index 8e9daef..6990ca4 100644 --- a/README.md +++ b/README.md @@ -794,7 +794,7 @@ | 2520 | [Count the Digits That Divide a Number](https://leetcode.com/problems/count-the-digits-that-divide-a-number) | [![Java](assets/java.png)](src/CountTheDigitsThatDivideANumber.java) | | | 2525 | [Categorize Box According to Criteria](https://leetcode.com/problems/categorize-box-according-to-criteria) | [![Java](assets/java.png)](src/CategorizeBoxAccordingToCriteria.java) | | | 2529 | [Maximum Count of Positive Integer and Negative Integer](https://leetcode.com/problems/maximum-count-of-positive-integer-and-negative-integer) | [![Java](assets/java.png)](src/MaximumCountOfPositiveIntegerAndNegativeInteger.java) | | -| 2535 | [Difference Between Element Sum and Digit Sum of an Array](https://leetcode.com/problems/difference-between-element-sum-and-digit-sum-of-an-array) | | | +| 2535 | [Difference Between Element Sum and Digit Sum of an Array](https://leetcode.com/problems/difference-between-element-sum-and-digit-sum-of-an-array) | [![Java](assets/java.png)](src/DifferenceBetweenElementSumAndDigitSumOfAnArray.java) | | | 2540 | [Minimum Common Value](https://leetcode.com/problems/minimum-common-value) | | | | 2544 | [Alternating Digit Sum](https://leetcode.com/problems/alternating-digit-sum) | | | | 2549 | [Count Distinct Numbers on Board](https://leetcode.com/problems/count-distinct-numbers-on-board) | | | diff --git a/src/DifferenceBetweenElementSumAndDigitSumOfAnArray.java b/src/DifferenceBetweenElementSumAndDigitSumOfAnArray.java new file mode 100644 index 0000000..397d413 --- /dev/null +++ b/src/DifferenceBetweenElementSumAndDigitSumOfAnArray.java @@ -0,0 +1,31 @@ +// https://leetcode.com/problems/difference-between-element-sum-and-digit-sum-of-an-array +// T: O(N) +// S: O(1) + +import java.util.Arrays; + +public class DifferenceBetweenElementSumAndDigitSumOfAnArray { + public int differenceOfSum(int[] nums) { + final int elementSum = Arrays.stream(nums).sum(); + final int digitSum = getDigitSum(nums); + return Math.abs(elementSum - digitSum); + } + + private int getDigitSum(int[] array) { + int sum = 0; + for (int number : array) { + sum += getDigitSum(number); + } + return sum; + } + + private int getDigitSum(int number) { + final String num = number + ""; + int sum = 0; + for (int index = 0 ; index < num.length() ; index++) { + int digit = num.charAt(index) - '0'; + sum += digit; + } + return sum; + } +} From 4e0c2f88def8abca428689f1b9cf6819ae1bba78 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 3 Jun 2023 18:04:31 +0200 Subject: [PATCH 091/280] solves #2540: Minimum Common Value in java --- README.md | 2 +- src/MinimumCommonValue.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/MinimumCommonValue.java diff --git a/README.md b/README.md index 6990ca4..c0136da 100644 --- a/README.md +++ b/README.md @@ -795,7 +795,7 @@ | 2525 | [Categorize Box According to Criteria](https://leetcode.com/problems/categorize-box-according-to-criteria) | [![Java](assets/java.png)](src/CategorizeBoxAccordingToCriteria.java) | | | 2529 | [Maximum Count of Positive Integer and Negative Integer](https://leetcode.com/problems/maximum-count-of-positive-integer-and-negative-integer) | [![Java](assets/java.png)](src/MaximumCountOfPositiveIntegerAndNegativeInteger.java) | | | 2535 | [Difference Between Element Sum and Digit Sum of an Array](https://leetcode.com/problems/difference-between-element-sum-and-digit-sum-of-an-array) | [![Java](assets/java.png)](src/DifferenceBetweenElementSumAndDigitSumOfAnArray.java) | | -| 2540 | [Minimum Common Value](https://leetcode.com/problems/minimum-common-value) | | | +| 2540 | [Minimum Common Value](https://leetcode.com/problems/minimum-common-value) | [![Java](assets/java.png)](src/MinimumCommonValue.java) | | | 2544 | [Alternating Digit Sum](https://leetcode.com/problems/alternating-digit-sum) | | | | 2549 | [Count Distinct Numbers on Board](https://leetcode.com/problems/count-distinct-numbers-on-board) | | | | 2553 | [Separate the Digits in an Array](https://leetcode.com/problems/separate-the-digits-in-an-array) | | | diff --git a/src/MinimumCommonValue.java b/src/MinimumCommonValue.java new file mode 100644 index 0000000..783133c --- /dev/null +++ b/src/MinimumCommonValue.java @@ -0,0 +1,18 @@ +// https://leetcode.com/problems/minimum-common-value +// T: O(m + n) +// S: O(1) + +public class MinimumCommonValue { + public int getCommon(int[] array1, int[] array2) { + for (int i = 0, j = 0 ; i < array1.length && j < array2.length ; ) { + if (array1[i] == array2[j]) return array1[i]; + + if (array1[i] < array2[j]) { + i++; + } else { + j++; + } + } + return -1; + } +} From 989025d0e4d638cc21234c0cb6b0b0bbfe8bb9f7 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 3 Jun 2023 18:23:45 +0200 Subject: [PATCH 092/280] solves #2544: Alternating Digit Sum in java --- README.md | 2 +- src/AlternatingDigitSum.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/AlternatingDigitSum.java diff --git a/README.md b/README.md index c0136da..5a06f03 100644 --- a/README.md +++ b/README.md @@ -796,7 +796,7 @@ | 2529 | [Maximum Count of Positive Integer and Negative Integer](https://leetcode.com/problems/maximum-count-of-positive-integer-and-negative-integer) | [![Java](assets/java.png)](src/MaximumCountOfPositiveIntegerAndNegativeInteger.java) | | | 2535 | [Difference Between Element Sum and Digit Sum of an Array](https://leetcode.com/problems/difference-between-element-sum-and-digit-sum-of-an-array) | [![Java](assets/java.png)](src/DifferenceBetweenElementSumAndDigitSumOfAnArray.java) | | | 2540 | [Minimum Common Value](https://leetcode.com/problems/minimum-common-value) | [![Java](assets/java.png)](src/MinimumCommonValue.java) | | -| 2544 | [Alternating Digit Sum](https://leetcode.com/problems/alternating-digit-sum) | | | +| 2544 | [Alternating Digit Sum](https://leetcode.com/problems/alternating-digit-sum) | [![Java](assets/java.png)](src/AlternatingDigitSum.java) | | | 2549 | [Count Distinct Numbers on Board](https://leetcode.com/problems/count-distinct-numbers-on-board) | | | | 2553 | [Separate the Digits in an Array](https://leetcode.com/problems/separate-the-digits-in-an-array) | | | | 2558 | [Take Gifts From the Richest Pile](https://leetcode.com/problems/take-gifts-from-the-richest-pile) | | | diff --git a/src/AlternatingDigitSum.java b/src/AlternatingDigitSum.java new file mode 100644 index 0000000..45c4ec5 --- /dev/null +++ b/src/AlternatingDigitSum.java @@ -0,0 +1,14 @@ +// https://leetcode.com/problems/alternating-digit-sum +// T: O(log(n)) +// S: O(1) + +public class AlternatingDigitSum { + public int alternateDigitSum(int n) { + final String number = n + ""; + int sum = 0; + for (int index = 0, parity = 1 ; index < number.length() ; index++, parity *= -1) { + sum += parity * (number.charAt(index) - '0'); + } + return sum; + } +} From e2565d3584935a4de304ed786d6e6852ecd4ce82 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 3 Jun 2023 19:02:10 +0200 Subject: [PATCH 093/280] solves #2549: Count Distinct Numbers on Board in java --- README.md | 2 +- src/CountDistinctNumbersOnBoard.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 src/CountDistinctNumbersOnBoard.java diff --git a/README.md b/README.md index 5a06f03..df9d465 100644 --- a/README.md +++ b/README.md @@ -797,7 +797,7 @@ | 2535 | [Difference Between Element Sum and Digit Sum of an Array](https://leetcode.com/problems/difference-between-element-sum-and-digit-sum-of-an-array) | [![Java](assets/java.png)](src/DifferenceBetweenElementSumAndDigitSumOfAnArray.java) | | | 2540 | [Minimum Common Value](https://leetcode.com/problems/minimum-common-value) | [![Java](assets/java.png)](src/MinimumCommonValue.java) | | | 2544 | [Alternating Digit Sum](https://leetcode.com/problems/alternating-digit-sum) | [![Java](assets/java.png)](src/AlternatingDigitSum.java) | | -| 2549 | [Count Distinct Numbers on Board](https://leetcode.com/problems/count-distinct-numbers-on-board) | | | +| 2549 | [Count Distinct Numbers on Board](https://leetcode.com/problems/count-distinct-numbers-on-board) | [![Java](assets/java.png)](src/CountDistinctNumbersOnBoard.java) | | | 2553 | [Separate the Digits in an Array](https://leetcode.com/problems/separate-the-digits-in-an-array) | | | | 2558 | [Take Gifts From the Richest Pile](https://leetcode.com/problems/take-gifts-from-the-richest-pile) | | | | 2562 | [Find the Array Concatenation Value](https://leetcode.com/problems/find-the-array-concatenation-value) | | | diff --git a/src/CountDistinctNumbersOnBoard.java b/src/CountDistinctNumbersOnBoard.java new file mode 100644 index 0000000..0924043 --- /dev/null +++ b/src/CountDistinctNumbersOnBoard.java @@ -0,0 +1,10 @@ +// https://leetcode.com/problems/count-distinct-numbers-on-board +// T: O(1) +// S: O(1) + +public class CountDistinctNumbersOnBoard { + public int distinctIntegers(int n) { + if (n <= 2) return 0; + return n - 1; + } +} From 2b59f60dd6b0a97042341d555e8469932e5316a4 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 3 Jun 2023 19:06:37 +0200 Subject: [PATCH 094/280] solves #2553: Separate the Digits in an Array in java --- README.md | 2 +- src/SeparateTheDigitsInAnArray.java | 31 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/SeparateTheDigitsInAnArray.java diff --git a/README.md b/README.md index df9d465..d001353 100644 --- a/README.md +++ b/README.md @@ -798,7 +798,7 @@ | 2540 | [Minimum Common Value](https://leetcode.com/problems/minimum-common-value) | [![Java](assets/java.png)](src/MinimumCommonValue.java) | | | 2544 | [Alternating Digit Sum](https://leetcode.com/problems/alternating-digit-sum) | [![Java](assets/java.png)](src/AlternatingDigitSum.java) | | | 2549 | [Count Distinct Numbers on Board](https://leetcode.com/problems/count-distinct-numbers-on-board) | [![Java](assets/java.png)](src/CountDistinctNumbersOnBoard.java) | | -| 2553 | [Separate the Digits in an Array](https://leetcode.com/problems/separate-the-digits-in-an-array) | | | +| 2553 | [Separate the Digits in an Array](https://leetcode.com/problems/separate-the-digits-in-an-array) | [![Java](assets/java.png)](src/SeparateTheDigitsInAnArray.java) | | | 2558 | [Take Gifts From the Richest Pile](https://leetcode.com/problems/take-gifts-from-the-richest-pile) | | | | 2562 | [Find the Array Concatenation Value](https://leetcode.com/problems/find-the-array-concatenation-value) | | | | 2566 | [Maximum Difference by Remapping a Digit](https://leetcode.com/problems/maximum-difference-by-remapping-a-digit) | | | diff --git a/src/SeparateTheDigitsInAnArray.java b/src/SeparateTheDigitsInAnArray.java new file mode 100644 index 0000000..b9b94a6 --- /dev/null +++ b/src/SeparateTheDigitsInAnArray.java @@ -0,0 +1,31 @@ +// https://leetcode.com/problems/separate-the-digits-in-an-array +// T: O(N) +// S: O(N) + +import java.util.ArrayList; +import java.util.List; + +public class SeparateTheDigitsInAnArray { + public int[] separateDigits(int[] nums) { + final List digits = new ArrayList<>(); + for (int number : nums) { + addDigitsToList(digits, number); + } + return toArray(digits); + } + + private int[] toArray(List list) { + final int[] array = new int[list.size()]; + for (int index = 0 ; index < list.size() ; index++) { + array[index] = list.get(index); + } + return array; + } + + private void addDigitsToList(List digits, int number) { + final String num = number + ""; + for (int index = 0 ; index < num.length() ; index++) { + digits.add(num.charAt(index) - '0'); + } + } +} From c9e3b26d5366c033ca571a53fa817d298977a318 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 10 Jun 2023 21:00:00 +0200 Subject: [PATCH 095/280] solves #2526: Find the Array Concatenation Value in java --- README.md | 4 +-- src/FindTheArrayConcatenationValue.java | 19 +++++++++++++ src/TakeGiftsFromTheRichestPile.java | 37 +++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 src/FindTheArrayConcatenationValue.java create mode 100644 src/TakeGiftsFromTheRichestPile.java diff --git a/README.md b/README.md index d001353..e4eb94b 100644 --- a/README.md +++ b/README.md @@ -799,8 +799,8 @@ | 2544 | [Alternating Digit Sum](https://leetcode.com/problems/alternating-digit-sum) | [![Java](assets/java.png)](src/AlternatingDigitSum.java) | | | 2549 | [Count Distinct Numbers on Board](https://leetcode.com/problems/count-distinct-numbers-on-board) | [![Java](assets/java.png)](src/CountDistinctNumbersOnBoard.java) | | | 2553 | [Separate the Digits in an Array](https://leetcode.com/problems/separate-the-digits-in-an-array) | [![Java](assets/java.png)](src/SeparateTheDigitsInAnArray.java) | | -| 2558 | [Take Gifts From the Richest Pile](https://leetcode.com/problems/take-gifts-from-the-richest-pile) | | | -| 2562 | [Find the Array Concatenation Value](https://leetcode.com/problems/find-the-array-concatenation-value) | | | +| 2558 | [Take Gifts From the Richest Pile](https://leetcode.com/problems/take-gifts-from-the-richest-pile) | [![Java](assets/java.png)](src/TakeGiftsFromTheRichestPile.java) | | +| 2562 | [Find the Array Concatenation Value](https://leetcode.com/problems/find-the-array-concatenation-value) | [![Java](assets/java.png)](src/FindTheArrayConcatenationValue.java) | | | 2566 | [Maximum Difference by Remapping a Digit](https://leetcode.com/problems/maximum-difference-by-remapping-a-digit) | | | | 2570 | [Merge Two 2D Arrays by Summing Values](https://leetcode.com/problems/merge-two-2d-arrays-by-summing-values) | | | | 2574 | [Left and Right Sum Differences](https://leetcode.com/problems/left-and-right-sum-differences) | | | diff --git a/src/FindTheArrayConcatenationValue.java b/src/FindTheArrayConcatenationValue.java new file mode 100644 index 0000000..5d1c6b8 --- /dev/null +++ b/src/FindTheArrayConcatenationValue.java @@ -0,0 +1,19 @@ +// https://leetcode.com/problems/find-the-array-concatenation-value +// T: O(N) +// S: O(1) + +public class FindTheArrayConcatenationValue { + public long findTheArrayConcVal(int[] nums) { + long result = 0; + + for (int i = 0 ; i < nums.length / 2 ; i++) { + result += Integer.parseInt(nums[i] + "" + nums[nums.length - 1 - i]); + } + + if (nums.length % 2 == 1) { + result += nums[nums.length / 2]; + } + + return result; + } +} diff --git a/src/TakeGiftsFromTheRichestPile.java b/src/TakeGiftsFromTheRichestPile.java new file mode 100644 index 0000000..aea8a64 --- /dev/null +++ b/src/TakeGiftsFromTheRichestPile.java @@ -0,0 +1,37 @@ +// https://leetcode.com/problems/take-gifts-from-the-richest-pile +// T: O(k * log(N)) +// S: O(N) + +import java.util.Comparator; +import java.util.PriorityQueue; +import java.util.Queue; + +public class TakeGiftsFromTheRichestPile { + public long pickGifts(int[] gifts, int k) { + final Queue maxHeap = maHeapFrom(gifts); + + for (int i = 0 ; i < k ; i++) { + final int maxPile = maxHeap.poll(); + final int giftsToLeaveBehind = (int) Math.max(Math.sqrt(maxPile), 0); + maxHeap.add(giftsToLeaveBehind); + } + + return sum(maxHeap); + } + + private long sum(Queue heap) { + long sum = 0; + while (!heap.isEmpty()) { + sum += heap.poll(); + } + return sum; + } + + private Queue maHeapFrom(int[] array) { + final Queue maxHeap = new PriorityQueue<>(Comparator.reverseOrder()); + for (int element : array) { + maxHeap.add(element); + } + return maxHeap; + } +} From 16da7678b0634a089d8b986499fdf589e898a050 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 10 Jun 2023 21:15:42 +0200 Subject: [PATCH 096/280] solves #2566: Maximum Difference by Remapping a Digit in java --- README.md | 2 +- src/MaximumDifferenceByRemappingADigit.java | 37 +++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/MaximumDifferenceByRemappingADigit.java diff --git a/README.md b/README.md index e4eb94b..02f923e 100644 --- a/README.md +++ b/README.md @@ -801,7 +801,7 @@ | 2553 | [Separate the Digits in an Array](https://leetcode.com/problems/separate-the-digits-in-an-array) | [![Java](assets/java.png)](src/SeparateTheDigitsInAnArray.java) | | | 2558 | [Take Gifts From the Richest Pile](https://leetcode.com/problems/take-gifts-from-the-richest-pile) | [![Java](assets/java.png)](src/TakeGiftsFromTheRichestPile.java) | | | 2562 | [Find the Array Concatenation Value](https://leetcode.com/problems/find-the-array-concatenation-value) | [![Java](assets/java.png)](src/FindTheArrayConcatenationValue.java) | | -| 2566 | [Maximum Difference by Remapping a Digit](https://leetcode.com/problems/maximum-difference-by-remapping-a-digit) | | | +| 2566 | [Maximum Difference by Remapping a Digit](https://leetcode.com/problems/maximum-difference-by-remapping-a-digit) | [![Java](assets/java.png)](src/MaximumDifferenceByRemappingADigit.java) | | | 2570 | [Merge Two 2D Arrays by Summing Values](https://leetcode.com/problems/merge-two-2d-arrays-by-summing-values) | | | | 2574 | [Left and Right Sum Differences](https://leetcode.com/problems/left-and-right-sum-differences) | | | | 2578 | [Split With Minimum Sum](https://leetcode.com/problems/split-with-minimum-sum) | | | diff --git a/src/MaximumDifferenceByRemappingADigit.java b/src/MaximumDifferenceByRemappingADigit.java new file mode 100644 index 0000000..a5f4443 --- /dev/null +++ b/src/MaximumDifferenceByRemappingADigit.java @@ -0,0 +1,37 @@ +// https://leetcode.com/problems/maximum-difference-by-remapping-a-digit +// T: O(log(N)) +// S: O(1) + +public class MaximumDifferenceByRemappingADigit { + public int minMaxDifference(int num) { + final String number = num + ""; + final int maxDigit = maxDigit(number); + final int minDigit = minDigit(number); + return maxDigit - minDigit; + } + + private int maxDigit(String x) { + for (int i = 0 ; i < x.length() ; i++) { + int digit = x.charAt(i) - '0'; + if (digit < 9) { + return changeOccurrence(x, digit, 9); + } + } + return Integer.parseInt(x); + } + + private int minDigit(String x) { + for (int i = 0 ; i < x.length() ; i++) { + int digit = x.charAt(i) - '0'; + if (digit != 0) { + return changeOccurrence(x, digit, 0); + } + } + return Integer.parseInt(x); + } + + private int changeOccurrence(String x, int digit, int to) { + final String result = x.replace((char) (digit + '0'), (char) (to + '0')); + return Integer.parseInt(result); + } +} From 35a1739c4170124152687500b164615c03bb4eee Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 10 Jun 2023 21:24:22 +0200 Subject: [PATCH 097/280] solves #2570: Merge Two 2D Arrays by Summing Values in java --- README.md | 2 +- src/MergeTwo2DArraysBySummingValues.java | 43 ++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 src/MergeTwo2DArraysBySummingValues.java diff --git a/README.md b/README.md index 02f923e..cfecf6a 100644 --- a/README.md +++ b/README.md @@ -802,7 +802,7 @@ | 2558 | [Take Gifts From the Richest Pile](https://leetcode.com/problems/take-gifts-from-the-richest-pile) | [![Java](assets/java.png)](src/TakeGiftsFromTheRichestPile.java) | | | 2562 | [Find the Array Concatenation Value](https://leetcode.com/problems/find-the-array-concatenation-value) | [![Java](assets/java.png)](src/FindTheArrayConcatenationValue.java) | | | 2566 | [Maximum Difference by Remapping a Digit](https://leetcode.com/problems/maximum-difference-by-remapping-a-digit) | [![Java](assets/java.png)](src/MaximumDifferenceByRemappingADigit.java) | | -| 2570 | [Merge Two 2D Arrays by Summing Values](https://leetcode.com/problems/merge-two-2d-arrays-by-summing-values) | | | +| 2570 | [Merge Two 2D Arrays by Summing Values](https://leetcode.com/problems/merge-two-2d-arrays-by-summing-values) | [![Java](assets/java.png)](src/MergeTwo2DArraysBySummingValues.java) | | | 2574 | [Left and Right Sum Differences](https://leetcode.com/problems/left-and-right-sum-differences) | | | | 2578 | [Split With Minimum Sum](https://leetcode.com/problems/split-with-minimum-sum) | | | | 2582 | [Pass the Pillow](https://leetcode.com/problems/pass-the-pillow) | | | diff --git a/src/MergeTwo2DArraysBySummingValues.java b/src/MergeTwo2DArraysBySummingValues.java new file mode 100644 index 0000000..eef8c6d --- /dev/null +++ b/src/MergeTwo2DArraysBySummingValues.java @@ -0,0 +1,43 @@ +// https://leetcode.com/problems/merge-two-2d-arrays-by-summing-values +// T: O(N + M) +// S: O(N + M) + +import java.util.ArrayList; +import java.util.List; + +public class MergeTwo2DArraysBySummingValues { + public int[][] mergeArrays(int[][] array1, int[][] array2) { + final List result = new ArrayList<>(); + int i = 0, j = 0; + while (i < array1.length && j < array2.length) { + if (array1[i][0] == array2[j][0]) { + result.add(new int[] {array1[i][0], array1[i][1] + array2[j][1]}); + i++; + j++; + } else if (array1[i][0] < array2[j][0]) { + result.add(array1[i++]); + } else { + result.add(array2[j++]); + } + } + + while (i < array1.length) { + result.add(array1[i++]); + } + + while (j < array2.length) { + result.add(array2[j++]); + } + + return toArray(result); + } + + private int[][] toArray(List list) { + final int[][] array = new int[list.size()][2]; + int k = 0; + for (int[] slice : list) { + array[k++] = slice; + } + return array; + } +} From b4e66503c1f62ad8eba5d4c997fbbc04afd11dfd Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 10 Jun 2023 21:34:34 +0200 Subject: [PATCH 098/280] solves #2574: Left and Right Sum Differences in java --- README.md | 2 +- src/LeftAndRightSumDifferences.java | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/LeftAndRightSumDifferences.java diff --git a/README.md b/README.md index cfecf6a..3dff64f 100644 --- a/README.md +++ b/README.md @@ -803,7 +803,7 @@ | 2562 | [Find the Array Concatenation Value](https://leetcode.com/problems/find-the-array-concatenation-value) | [![Java](assets/java.png)](src/FindTheArrayConcatenationValue.java) | | | 2566 | [Maximum Difference by Remapping a Digit](https://leetcode.com/problems/maximum-difference-by-remapping-a-digit) | [![Java](assets/java.png)](src/MaximumDifferenceByRemappingADigit.java) | | | 2570 | [Merge Two 2D Arrays by Summing Values](https://leetcode.com/problems/merge-two-2d-arrays-by-summing-values) | [![Java](assets/java.png)](src/MergeTwo2DArraysBySummingValues.java) | | -| 2574 | [Left and Right Sum Differences](https://leetcode.com/problems/left-and-right-sum-differences) | | | +| 2574 | [Left and Right Sum Differences](https://leetcode.com/problems/left-and-right-sum-differences) | [![Java](assets/java.png)](src/LeftAndRightSumDifferences.java) | | | 2578 | [Split With Minimum Sum](https://leetcode.com/problems/split-with-minimum-sum) | | | | 2582 | [Pass the Pillow](https://leetcode.com/problems/pass-the-pillow) | | | | 2586 | [Count the Number of Vowel Strings in Range](https://leetcode.com/problems/count-the-number-of-vowel-strings-in-range) | | | diff --git a/src/LeftAndRightSumDifferences.java b/src/LeftAndRightSumDifferences.java new file mode 100644 index 0000000..e86ff06 --- /dev/null +++ b/src/LeftAndRightSumDifferences.java @@ -0,0 +1,26 @@ +// https://leetcode.com/problems/left-and-right-sum-differences +// T: O(N) +// S: O(N) + +public class LeftAndRightSumDifferences { + public int[] leftRightDifference(int[] nums) { + final int[] result = new int[nums.length]; + int leftSum = 0, rightSum = sum(nums, 1, nums.length); + + for (int index = 0 ; index < nums.length ; index++) { + result[index] = Math.abs(leftSum - rightSum); + leftSum += nums[index]; + rightSum -= (index + 1 < nums.length ? nums[index + 1] : 0); + } + + return result; + } + + private int sum(int[] array, int startIndex, int endIndex) { + int sum = 0; + for (int i = startIndex ; i < endIndex ; i++) { + sum += array[i]; + } + return sum; + } +} From eba888ac78d201f9ff725b0434b85bc0de8ff03e Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 10 Jun 2023 21:50:26 +0200 Subject: [PATCH 099/280] solves #2587: Split With Minimum Sum in java --- README.md | 2 +- src/SplitWithMinimumSum.java | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/SplitWithMinimumSum.java diff --git a/README.md b/README.md index 3dff64f..fa27383 100644 --- a/README.md +++ b/README.md @@ -804,7 +804,7 @@ | 2566 | [Maximum Difference by Remapping a Digit](https://leetcode.com/problems/maximum-difference-by-remapping-a-digit) | [![Java](assets/java.png)](src/MaximumDifferenceByRemappingADigit.java) | | | 2570 | [Merge Two 2D Arrays by Summing Values](https://leetcode.com/problems/merge-two-2d-arrays-by-summing-values) | [![Java](assets/java.png)](src/MergeTwo2DArraysBySummingValues.java) | | | 2574 | [Left and Right Sum Differences](https://leetcode.com/problems/left-and-right-sum-differences) | [![Java](assets/java.png)](src/LeftAndRightSumDifferences.java) | | -| 2578 | [Split With Minimum Sum](https://leetcode.com/problems/split-with-minimum-sum) | | | +| 2578 | [Split With Minimum Sum](https://leetcode.com/problems/split-with-minimum-sum) | [![Java](assets/java.png)](src/SplitWithMinimumSum.java) | | | 2582 | [Pass the Pillow](https://leetcode.com/problems/pass-the-pillow) | | | | 2586 | [Count the Number of Vowel Strings in Range](https://leetcode.com/problems/count-the-number-of-vowel-strings-in-range) | | | | 2591 | [Distribute Money to Maximum Children](https://leetcode.com/problems/distribute-money-to-maximum-children) | | | diff --git a/src/SplitWithMinimumSum.java b/src/SplitWithMinimumSum.java new file mode 100644 index 0000000..228107b --- /dev/null +++ b/src/SplitWithMinimumSum.java @@ -0,0 +1,32 @@ +// https://leetcode.com/problems/split-with-minimum-sum +// T: O(log(N)log(log(N))) +// S: O(log(log(N))) + +import java.util.ArrayList; +import java.util.List; + +public class SplitWithMinimumSum { + public int splitNum(int num) { + final List digits = getDigits(num); + digits.sort(Integer::compareTo); + int a = 0, b = 0, k = 0; + for (int digit : digits) { + if (k == 0) { + a = 10 * a + digit; + } else { + b = 10 * b + digit; + } + k ^= 1; + } + return a + b; + } + + private List getDigits(int x) { + final List digits = new ArrayList<>(); + final String number = x + ""; + for (int index = 0 ; index < number.length() ; index++) { + digits.add(number.charAt(index) - '0'); + } + return digits; + } +} From b29755c38fc4394010e4862ca0e1b8721292b428 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 10 Jun 2023 22:12:35 +0200 Subject: [PATCH 100/280] solves #2582: Pass the Pillow in java --- README.md | 2 +- src/PassThePillow.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/PassThePillow.java diff --git a/README.md b/README.md index fa27383..f2c4b4b 100644 --- a/README.md +++ b/README.md @@ -805,7 +805,7 @@ | 2570 | [Merge Two 2D Arrays by Summing Values](https://leetcode.com/problems/merge-two-2d-arrays-by-summing-values) | [![Java](assets/java.png)](src/MergeTwo2DArraysBySummingValues.java) | | | 2574 | [Left and Right Sum Differences](https://leetcode.com/problems/left-and-right-sum-differences) | [![Java](assets/java.png)](src/LeftAndRightSumDifferences.java) | | | 2578 | [Split With Minimum Sum](https://leetcode.com/problems/split-with-minimum-sum) | [![Java](assets/java.png)](src/SplitWithMinimumSum.java) | | -| 2582 | [Pass the Pillow](https://leetcode.com/problems/pass-the-pillow) | | | +| 2582 | [Pass the Pillow](https://leetcode.com/problems/pass-the-pillow) | [![Java](assets/java.png)](src/PassThePillow.java) | | | 2586 | [Count the Number of Vowel Strings in Range](https://leetcode.com/problems/count-the-number-of-vowel-strings-in-range) | | | | 2591 | [Distribute Money to Maximum Children](https://leetcode.com/problems/distribute-money-to-maximum-children) | | | | 2595 | [Number of Even and Odd Bits](https://leetcode.com/problems/number-of-even-and-odd-bits) | | | diff --git a/src/PassThePillow.java b/src/PassThePillow.java new file mode 100644 index 0000000..d4cf152 --- /dev/null +++ b/src/PassThePillow.java @@ -0,0 +1,15 @@ +// https://leetcode.com/problems/pass-the-pillow +// T: O(1) +// S: O(1) + +public class PassThePillow { + public int passThePillow(int n, int time) { + final int direction = (int) Math.ceil((double) time / (n - 1)); + final int multiplier = direction % 2 == 0 ? -1 : 1; + final int steps = time - (direction - 1) * (n - 1); + if (multiplier == 1) { + return steps + 1; + } + return n - steps; + } +} From 72d8cf628a96dedaaaaa31e93270e017d1817aa6 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 10 Jun 2023 22:17:20 +0200 Subject: [PATCH 101/280] solves #2586: Count the Number of Vowel Strings in Range in java --- README.md | 2 +- src/CountTheNumberOfVowelStringsInRange.java | 27 ++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/CountTheNumberOfVowelStringsInRange.java diff --git a/README.md b/README.md index f2c4b4b..bb65d1c 100644 --- a/README.md +++ b/README.md @@ -806,7 +806,7 @@ | 2574 | [Left and Right Sum Differences](https://leetcode.com/problems/left-and-right-sum-differences) | [![Java](assets/java.png)](src/LeftAndRightSumDifferences.java) | | | 2578 | [Split With Minimum Sum](https://leetcode.com/problems/split-with-minimum-sum) | [![Java](assets/java.png)](src/SplitWithMinimumSum.java) | | | 2582 | [Pass the Pillow](https://leetcode.com/problems/pass-the-pillow) | [![Java](assets/java.png)](src/PassThePillow.java) | | -| 2586 | [Count the Number of Vowel Strings in Range](https://leetcode.com/problems/count-the-number-of-vowel-strings-in-range) | | | +| 2586 | [Count the Number of Vowel Strings in Range](https://leetcode.com/problems/count-the-number-of-vowel-strings-in-range) | [![Java](assets/java.png)](src/CountTheNumberOfVowelStringsInRange.java) | | | 2591 | [Distribute Money to Maximum Children](https://leetcode.com/problems/distribute-money-to-maximum-children) | | | | 2595 | [Number of Even and Odd Bits](https://leetcode.com/problems/number-of-even-and-odd-bits) | | | | 2600 | [K Items With the Maximum Sum](https://leetcode.com/problems/k-items-with-the-maximum-sum) | | | diff --git a/src/CountTheNumberOfVowelStringsInRange.java b/src/CountTheNumberOfVowelStringsInRange.java new file mode 100644 index 0000000..05c1780 --- /dev/null +++ b/src/CountTheNumberOfVowelStringsInRange.java @@ -0,0 +1,27 @@ +// https://leetcode.com/problems/count-the-number-of-vowel-strings-in-range +// T: O(N) +// S: O(1) + +import java.util.Set; + +public class CountTheNumberOfVowelStringsInRange { + private final static Set VOWELS = Set.of('a', 'e', 'i', 'o', 'u'); + + public int vowelStrings(String[] words, int left, int right) { + int vowelStrings = 0; + for (int i = left ; i <= right ; i++) { + if (isVowelString(words[i])) { + vowelStrings++; + } + } + return vowelStrings; + } + + private boolean isVowelString(String word) { + return isVowel(word.charAt(0)) && isVowel(word.charAt(word.length() - 1)); + } + + private boolean isVowel(char c) { + return VOWELS.contains(c); + } +} From 1ac15920d060e1b295e795bbbf1ff8de3516d9ba Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 10 Jun 2023 22:36:31 +0200 Subject: [PATCH 102/280] solves #2591: Distribute Money to Maximum Children in java --- README.md | 2 +- src/DistributeMoneyToMaximumChildren.java | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 src/DistributeMoneyToMaximumChildren.java diff --git a/README.md b/README.md index bb65d1c..e1af549 100644 --- a/README.md +++ b/README.md @@ -807,7 +807,7 @@ | 2578 | [Split With Minimum Sum](https://leetcode.com/problems/split-with-minimum-sum) | [![Java](assets/java.png)](src/SplitWithMinimumSum.java) | | | 2582 | [Pass the Pillow](https://leetcode.com/problems/pass-the-pillow) | [![Java](assets/java.png)](src/PassThePillow.java) | | | 2586 | [Count the Number of Vowel Strings in Range](https://leetcode.com/problems/count-the-number-of-vowel-strings-in-range) | [![Java](assets/java.png)](src/CountTheNumberOfVowelStringsInRange.java) | | -| 2591 | [Distribute Money to Maximum Children](https://leetcode.com/problems/distribute-money-to-maximum-children) | | | +| 2591 | [Distribute Money to Maximum Children](https://leetcode.com/problems/distribute-money-to-maximum-children) | [![Java](assets/java.png)](src/DistributeMoneyToMaximumChildren.java) | | | 2595 | [Number of Even and Odd Bits](https://leetcode.com/problems/number-of-even-and-odd-bits) | | | | 2600 | [K Items With the Maximum Sum](https://leetcode.com/problems/k-items-with-the-maximum-sum) | | | | 2605 | [Form Smallest Number From Two Digit Arrays](https://leetcode.com/problems/form-smallest-number-from-two-digit-arrays) | | | diff --git a/src/DistributeMoneyToMaximumChildren.java b/src/DistributeMoneyToMaximumChildren.java new file mode 100644 index 0000000..7c35b0a --- /dev/null +++ b/src/DistributeMoneyToMaximumChildren.java @@ -0,0 +1,23 @@ +// https://leetcode.com/problems/distribute-money-to-maximum-children +// T: O(1) +// S: O(1) + +public class DistributeMoneyToMaximumChildren { + public int distMoney(int money, int children) { + if (children > money) return -1; + + int childrenReceiving8 = Math.min((money - children) / 7, children); + final int childrenNotReceiving8 = children - childrenReceiving8; + final int moneyLeft = money - 8 * childrenReceiving8; + + if (childrenNotReceiving8 == 1 && moneyLeft == 4) { + childrenReceiving8--; + } + + if (children == childrenReceiving8 && (money / 8 != children || money % 8 != 0)) { + childrenReceiving8--; + } + + return childrenReceiving8; + } +} From 9e449f73bf0b919541947dedd0e8a27fced8188e Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 10 Jun 2023 22:44:03 +0200 Subject: [PATCH 103/280] solves #2595: Number of Even and Odd Bits in java --- README.md | 2 +- src/NumberOfEvenAndOddBits.java | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/NumberOfEvenAndOddBits.java diff --git a/README.md b/README.md index e1af549..2b27cec 100644 --- a/README.md +++ b/README.md @@ -808,7 +808,7 @@ | 2582 | [Pass the Pillow](https://leetcode.com/problems/pass-the-pillow) | [![Java](assets/java.png)](src/PassThePillow.java) | | | 2586 | [Count the Number of Vowel Strings in Range](https://leetcode.com/problems/count-the-number-of-vowel-strings-in-range) | [![Java](assets/java.png)](src/CountTheNumberOfVowelStringsInRange.java) | | | 2591 | [Distribute Money to Maximum Children](https://leetcode.com/problems/distribute-money-to-maximum-children) | [![Java](assets/java.png)](src/DistributeMoneyToMaximumChildren.java) | | -| 2595 | [Number of Even and Odd Bits](https://leetcode.com/problems/number-of-even-and-odd-bits) | | | +| 2595 | [Number of Even and Odd Bits](https://leetcode.com/problems/number-of-even-and-odd-bits) | [![Java](assets/java.png)](src/NumberOfEvenAndOddBits.java) | | | 2600 | [K Items With the Maximum Sum](https://leetcode.com/problems/k-items-with-the-maximum-sum) | | | | 2605 | [Form Smallest Number From Two Digit Arrays](https://leetcode.com/problems/form-smallest-number-from-two-digit-arrays) | | | | 2605 | [Form Smallest Number From Two Digit Arrays](https://leetcode.com/problems/form-smallest-number-from-two-digit-arrays) | | | diff --git a/src/NumberOfEvenAndOddBits.java b/src/NumberOfEvenAndOddBits.java new file mode 100644 index 0000000..fafa92e --- /dev/null +++ b/src/NumberOfEvenAndOddBits.java @@ -0,0 +1,27 @@ +// https://leetcode.com/problems/number-of-even-and-odd-bits +// T: O(log(N)) +// S: O(1) + +public class NumberOfEvenAndOddBits { + public int[] evenOddBit(int n) { + return new int[] { evenBits(n), oddBits(n)}; + } + + private int evenBits(int x) { + int bits = 0, num = 1; + while (num <= x) { + bits += (x & num) > 0 ? 1 : 0; + num <<= 2; + } + return bits; + } + + private int oddBits(int x) { + int bits = 0, num = 2; + while (num <= x) { + bits += (x & num) > 0 ? 1 : 0; + num <<= 2; + } + return bits; + } +} From ed0d722ae2f60155df8e8f8a3cd5effb2213a284 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 10 Jun 2023 22:50:33 +0200 Subject: [PATCH 104/280] solves #2600: K Items With the Maximum Sum in java --- README.md | 2 +- src/KItemsWithTheMaximumSum.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/KItemsWithTheMaximumSum.java diff --git a/README.md b/README.md index 2b27cec..2f5e78a 100644 --- a/README.md +++ b/README.md @@ -809,7 +809,7 @@ | 2586 | [Count the Number of Vowel Strings in Range](https://leetcode.com/problems/count-the-number-of-vowel-strings-in-range) | [![Java](assets/java.png)](src/CountTheNumberOfVowelStringsInRange.java) | | | 2591 | [Distribute Money to Maximum Children](https://leetcode.com/problems/distribute-money-to-maximum-children) | [![Java](assets/java.png)](src/DistributeMoneyToMaximumChildren.java) | | | 2595 | [Number of Even and Odd Bits](https://leetcode.com/problems/number-of-even-and-odd-bits) | [![Java](assets/java.png)](src/NumberOfEvenAndOddBits.java) | | -| 2600 | [K Items With the Maximum Sum](https://leetcode.com/problems/k-items-with-the-maximum-sum) | | | +| 2600 | [K Items With the Maximum Sum](https://leetcode.com/problems/k-items-with-the-maximum-sum) | [![Java](assets/java.png)](src/KItemsWithTheMaximumSum.java) | | | 2605 | [Form Smallest Number From Two Digit Arrays](https://leetcode.com/problems/form-smallest-number-from-two-digit-arrays) | | | | 2605 | [Form Smallest Number From Two Digit Arrays](https://leetcode.com/problems/form-smallest-number-from-two-digit-arrays) | | | | 2609 | [Find the Longest Balanced Substring of a Binary String](https://leetcode.com/problems/find-the-longest-balanced-substring-of-a-binary-string) | | | diff --git a/src/KItemsWithTheMaximumSum.java b/src/KItemsWithTheMaximumSum.java new file mode 100644 index 0000000..ae7f8b0 --- /dev/null +++ b/src/KItemsWithTheMaximumSum.java @@ -0,0 +1,16 @@ +// https://leetcode.com/problems/k-items-with-the-maximum-sum +// T: O(1) +// S: O(1) + +public class KItemsWithTheMaximumSum { + public int kItemsWithMaximumSum(int numOnes, int numZeros, int numNegOnes, int k) { + int maxSum = Math.min(numOnes, k); + k -= numOnes; + if (k <= 0) return maxSum; + + k -= numZeros; + if (k <= 0) return maxSum; + + return maxSum - k; + } +} From 9831a3698c22d7db73791ccc1781eeb1dd447817 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 10 Jun 2023 23:00:53 +0200 Subject: [PATCH 105/280] solves #2605: Form Smallest Number From Two Digit Arrays in java --- README.md | 2 +- src/FormSmallestNumberFromTwoDigitArrays.java | 58 +++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/FormSmallestNumberFromTwoDigitArrays.java diff --git a/README.md b/README.md index 2f5e78a..2445560 100644 --- a/README.md +++ b/README.md @@ -810,7 +810,7 @@ | 2591 | [Distribute Money to Maximum Children](https://leetcode.com/problems/distribute-money-to-maximum-children) | [![Java](assets/java.png)](src/DistributeMoneyToMaximumChildren.java) | | | 2595 | [Number of Even and Odd Bits](https://leetcode.com/problems/number-of-even-and-odd-bits) | [![Java](assets/java.png)](src/NumberOfEvenAndOddBits.java) | | | 2600 | [K Items With the Maximum Sum](https://leetcode.com/problems/k-items-with-the-maximum-sum) | [![Java](assets/java.png)](src/KItemsWithTheMaximumSum.java) | | -| 2605 | [Form Smallest Number From Two Digit Arrays](https://leetcode.com/problems/form-smallest-number-from-two-digit-arrays) | | | +| 2605 | [Form Smallest Number From Two Digit Arrays](https://leetcode.com/problems/form-smallest-number-from-two-digit-arrays) | [![Java](assets/java.png)](src/FormSmallestNumberFromTwoDigitArrays.java) | | | 2605 | [Form Smallest Number From Two Digit Arrays](https://leetcode.com/problems/form-smallest-number-from-two-digit-arrays) | | | | 2609 | [Find the Longest Balanced Substring of a Binary String](https://leetcode.com/problems/find-the-longest-balanced-substring-of-a-binary-string) | | | | 2614 | [Prime In Diagonal](https://leetcode.com/problems/prime-in-diagonal) | | | diff --git a/src/FormSmallestNumberFromTwoDigitArrays.java b/src/FormSmallestNumberFromTwoDigitArrays.java new file mode 100644 index 0000000..7b098d1 --- /dev/null +++ b/src/FormSmallestNumberFromTwoDigitArrays.java @@ -0,0 +1,58 @@ +// https://leetcode.com/problems/form-smallest-number-from-two-digit-arrays +// T: O(N log(N) + M log(M)) +// S: O(log(N) + log(M)) + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +public class FormSmallestNumberFromTwoDigitArrays { + public int minNumber(int[] nums1, int[] nums2) { + final Set intersection = intersection(nums1, nums2); + + if (!intersection.isEmpty()) { + final int[] digits = toArray(intersection); + Arrays.sort(digits); + return digits[0]; + } + + Arrays.sort(nums1); + Arrays.sort(nums2); + final int smallerDigit = Math.min(nums1[0], nums2[0]); + final int largerDigit = Math.max(nums1[0], nums2[0]); + return smallerDigit * 10 + largerDigit; + } + + private Set intersection(int[] array1, int[] array2) { + final Set set1 = toSet(array1); + final Set set2 = toSet(array2); + return intersection(set1, set2); + } + + private Set toSet(int[] array) { + final Set set = new HashSet<>(); + for (int element : array) { + set.add(element); + } + return set; + } + + private Set intersection(Set set1, Set set2) { + final Set set = new HashSet<>(); + for (int element : set1) { + if (set2.contains(element)) { + set.add(element); + } + } + return set; + } + + private int[] toArray(Set set) { + final int[] array = new int[set.size()]; + int index = 0; + for (int element : set) { + array[index++] = element; + } + return array; + } +} From 75382b26a8572563b59b65a9c5b405f8f8c121f7 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 7 Aug 2023 06:03:09 +0200 Subject: [PATCH 106/280] solves #2609: FindTheLongestBalancedSubstringOfABinaryString in java --- README.md | 3 +-- ...ngestBalancedSubstringOfABinaryString.java | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 src/FindTheLongestBalancedSubstringOfABinaryString.java diff --git a/README.md b/README.md index 2445560..c860a4c 100644 --- a/README.md +++ b/README.md @@ -811,8 +811,7 @@ | 2595 | [Number of Even and Odd Bits](https://leetcode.com/problems/number-of-even-and-odd-bits) | [![Java](assets/java.png)](src/NumberOfEvenAndOddBits.java) | | | 2600 | [K Items With the Maximum Sum](https://leetcode.com/problems/k-items-with-the-maximum-sum) | [![Java](assets/java.png)](src/KItemsWithTheMaximumSum.java) | | | 2605 | [Form Smallest Number From Two Digit Arrays](https://leetcode.com/problems/form-smallest-number-from-two-digit-arrays) | [![Java](assets/java.png)](src/FormSmallestNumberFromTwoDigitArrays.java) | | -| 2605 | [Form Smallest Number From Two Digit Arrays](https://leetcode.com/problems/form-smallest-number-from-two-digit-arrays) | | | -| 2609 | [Find the Longest Balanced Substring of a Binary String](https://leetcode.com/problems/find-the-longest-balanced-substring-of-a-binary-string) | | | +| 2609 | [Find the Longest Balanced Substring of a Binary String](https://leetcode.com/problems/find-the-longest-balanced-substring-of-a-binary-string) | [![Java](assets/java.png)](src/FindTheLongestBalancedSubstringOfABinaryString.java) | | | 2614 | [Prime In Diagonal](https://leetcode.com/problems/prime-in-diagonal) | | | | 2639 | [Find the Width of Columns of a Grid](https://leetcode.com/problems/find-the-width-of-columns-of-a-grid) | | | | 2643 | [Row With Maximum Ones](https://leetcode.com/problems/row-with-maximum-ones) | | | diff --git a/src/FindTheLongestBalancedSubstringOfABinaryString.java b/src/FindTheLongestBalancedSubstringOfABinaryString.java new file mode 100644 index 0000000..0a37b80 --- /dev/null +++ b/src/FindTheLongestBalancedSubstringOfABinaryString.java @@ -0,0 +1,26 @@ +// https://leetcode.com/problems/find-the-longest-balanced-substring-of-a-binary-string +// T: O(n) +// S: O(1) + +public class FindTheLongestBalancedSubstringOfABinaryString { + public int findTheLongestBalancedSubstring(String s) { + int result = 0; + for (int maxZeros = 0, maxOnes = 0, i = 0 ; i < s.length() ; i++) { + if (s.charAt(i) == '0') { + if (i - 1 >= 0 && s.charAt(i - 1) == '1') { + result = Math.max(result, 2 * Math.min(maxOnes, maxZeros)); + maxOnes = 0; + maxZeros = 1; + } else { + maxZeros++; + } + } else { + maxOnes++; + if (i == s.length() - 1) { + result = Math.max(result, 2 * Math.min(maxOnes, maxZeros)); + } + } + } + return result; + } +} From b870a9c06fd65310d17f3e35d39756e155b4c179 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 7 Aug 2023 06:12:02 +0200 Subject: [PATCH 107/280] solves #2614: PrimeInDiagonal in java --- README.md | 2 +- src/PrimeInDiagonal.java | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/PrimeInDiagonal.java diff --git a/README.md b/README.md index c860a4c..3f76c61 100644 --- a/README.md +++ b/README.md @@ -812,7 +812,7 @@ | 2600 | [K Items With the Maximum Sum](https://leetcode.com/problems/k-items-with-the-maximum-sum) | [![Java](assets/java.png)](src/KItemsWithTheMaximumSum.java) | | | 2605 | [Form Smallest Number From Two Digit Arrays](https://leetcode.com/problems/form-smallest-number-from-two-digit-arrays) | [![Java](assets/java.png)](src/FormSmallestNumberFromTwoDigitArrays.java) | | | 2609 | [Find the Longest Balanced Substring of a Binary String](https://leetcode.com/problems/find-the-longest-balanced-substring-of-a-binary-string) | [![Java](assets/java.png)](src/FindTheLongestBalancedSubstringOfABinaryString.java) | | -| 2614 | [Prime In Diagonal](https://leetcode.com/problems/prime-in-diagonal) | | | +| 2614 | [Prime In Diagonal](https://leetcode.com/problems/prime-in-diagonal) | [![Java](assets/java.png)](src/PrimeInDiagonal.java) | | | 2639 | [Find the Width of Columns of a Grid](https://leetcode.com/problems/find-the-width-of-columns-of-a-grid) | | | | 2643 | [Row With Maximum Ones](https://leetcode.com/problems/row-with-maximum-ones) | | | | 2644 | [Find the Maximum Divisibility Score](https://leetcode.com/problems/find-the-maximum-divisibility-score) | | | diff --git a/src/PrimeInDiagonal.java b/src/PrimeInDiagonal.java new file mode 100644 index 0000000..2498225 --- /dev/null +++ b/src/PrimeInDiagonal.java @@ -0,0 +1,37 @@ +// https://leetcode.com/problems/prime-in-diagonal +// m: number of rows in matrix +// n: size of numbers in matrix +// T: O(m * sqrt(n)) +// S: O(1) + +public class PrimeInDiagonal { + public int diagonalPrime(int[][] nums) { + final int rows = nums.length; + int maxPrime = 0; + // left to right diagonal + for (int row = 0 ; row < rows ; row++) { + if (row % 2 == 1 && row == rows / 2) { + continue; + } + if (isPrime(nums[row][row])) { + maxPrime = Math.max(maxPrime, nums[row][row]); + } + } + + // top right to bottom left diagonal + for (int row = 0 ; row < rows ; row++) { + if (isPrime(nums[row][rows - row - 1])) { + maxPrime = Math.max(maxPrime, nums[row][rows - row - 1]); + } + } + return maxPrime; + } + + private boolean isPrime(int x) { + if (x <= 1) return false; + for (int i = 2 ; i * i <= x ; i++) { + if (x % i == 0) return false; + } + return true; + } +} From 63ba1743f16e48bbad01b4382379148f57f5f8c4 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 7 Aug 2023 06:20:28 +0200 Subject: [PATCH 108/280] solves #2639: FindTheWidthOfColumnsOfAGri in java --- README.md | 2 +- src/FindTheWidthOfColumnsOfAGrid.java | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/FindTheWidthOfColumnsOfAGrid.java diff --git a/README.md b/README.md index 3f76c61..8910d27 100644 --- a/README.md +++ b/README.md @@ -813,7 +813,7 @@ | 2605 | [Form Smallest Number From Two Digit Arrays](https://leetcode.com/problems/form-smallest-number-from-two-digit-arrays) | [![Java](assets/java.png)](src/FormSmallestNumberFromTwoDigitArrays.java) | | | 2609 | [Find the Longest Balanced Substring of a Binary String](https://leetcode.com/problems/find-the-longest-balanced-substring-of-a-binary-string) | [![Java](assets/java.png)](src/FindTheLongestBalancedSubstringOfABinaryString.java) | | | 2614 | [Prime In Diagonal](https://leetcode.com/problems/prime-in-diagonal) | [![Java](assets/java.png)](src/PrimeInDiagonal.java) | | -| 2639 | [Find the Width of Columns of a Grid](https://leetcode.com/problems/find-the-width-of-columns-of-a-grid) | | | +| 2639 | [Find the Width of Columns of a Grid](https://leetcode.com/problems/find-the-width-of-columns-of-a-grid) | [![Java](assets/java.png)](src/FindTheWidthOfColumnsOfAGrid.java) | | | 2643 | [Row With Maximum Ones](https://leetcode.com/problems/row-with-maximum-ones) | | | | 2644 | [Find the Maximum Divisibility Score](https://leetcode.com/problems/find-the-maximum-divisibility-score) | | | | 2651 | [Calculate Delayed Arrival Time](https://leetcode.com/problems/calculate-delayed-arrival-time) | | | diff --git a/src/FindTheWidthOfColumnsOfAGrid.java b/src/FindTheWidthOfColumnsOfAGrid.java new file mode 100644 index 0000000..f1096aa --- /dev/null +++ b/src/FindTheWidthOfColumnsOfAGrid.java @@ -0,0 +1,20 @@ +// https://leetcode.com/problems/find-the-width-of-columns-of-a-grid +// m: rows in matrix +// n: columns in matrix +// T: O(m * n) +// S: O(n) + +public class FindTheWidthOfColumnsOfAGrid { + public int[] findColumnWidth(int[][] grid) { + final int columns = grid[0].length; + final int[] result = new int[columns]; + for (int column = 0 ; column < columns ; column++) { + int maxLen = 0; + for (int[] row : grid) { + maxLen = Math.max(maxLen, (String.valueOf(row[column])).length()); + } + result[column] = maxLen; + } + return result; + } +} From 2d0fb1507bd626bf624a5e9a870108aeeb1191e9 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 7 Aug 2023 06:26:07 +0200 Subject: [PATCH 109/280] solves #2643: RowWithMaximumOnes in java --- README.md | 2 +- src/RowWithMaximumOnes.java | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/RowWithMaximumOnes.java diff --git a/README.md b/README.md index 8910d27..a36a45b 100644 --- a/README.md +++ b/README.md @@ -814,7 +814,7 @@ | 2609 | [Find the Longest Balanced Substring of a Binary String](https://leetcode.com/problems/find-the-longest-balanced-substring-of-a-binary-string) | [![Java](assets/java.png)](src/FindTheLongestBalancedSubstringOfABinaryString.java) | | | 2614 | [Prime In Diagonal](https://leetcode.com/problems/prime-in-diagonal) | [![Java](assets/java.png)](src/PrimeInDiagonal.java) | | | 2639 | [Find the Width of Columns of a Grid](https://leetcode.com/problems/find-the-width-of-columns-of-a-grid) | [![Java](assets/java.png)](src/FindTheWidthOfColumnsOfAGrid.java) | | -| 2643 | [Row With Maximum Ones](https://leetcode.com/problems/row-with-maximum-ones) | | | +| 2643 | [Row With Maximum Ones](https://leetcode.com/problems/row-with-maximum-ones) | [![Java](assets/java.png)](src/RowWithMaximumOnes.java) | | | 2644 | [Find the Maximum Divisibility Score](https://leetcode.com/problems/find-the-maximum-divisibility-score) | | | | 2651 | [Calculate Delayed Arrival Time](https://leetcode.com/problems/calculate-delayed-arrival-time) | | | | 2652 | [Sum Multiples](https://leetcode.com/problems/sum-multiples) | | | diff --git a/src/RowWithMaximumOnes.java b/src/RowWithMaximumOnes.java new file mode 100644 index 0000000..9330490 --- /dev/null +++ b/src/RowWithMaximumOnes.java @@ -0,0 +1,28 @@ +// https://leetcode.com/problems/row-with-maximum-ones +// m: number of rows in matrix +// n: number of columns in matrix +// T: O(m * n) +// S: O(m * n) + +public class RowWithMaximumOnes { + public int[] rowAndMaximumOnes(int[][] matrix) { + final int rows = matrix.length, columns = matrix[0].length; + int maxOnes = 0, maxRow = 0; + for (int row = 0 ; row < rows ; row++) { + final int onesCount = getOnesCount(matrix[row]); + if (onesCount > maxOnes) { + maxOnes = onesCount; + maxRow = row; + } + } + return new int[] { maxRow, maxOnes }; + } + + private int getOnesCount(int[] array) { + int count = 0; + for (int element : array) { + if (element == 1) count++; + } + return count; + } +} From fa033bdcfac88f1d18a446241979a1f721832810 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 7 Aug 2023 06:59:43 +0200 Subject: [PATCH 110/280] solves #2644: RowWithMaximumOnes in java --- README.md | 2 +- src/FindTheMaximumDivisibilityScore.java | 37 ++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/FindTheMaximumDivisibilityScore.java diff --git a/README.md b/README.md index a36a45b..9dc3aab 100644 --- a/README.md +++ b/README.md @@ -815,7 +815,7 @@ | 2614 | [Prime In Diagonal](https://leetcode.com/problems/prime-in-diagonal) | [![Java](assets/java.png)](src/PrimeInDiagonal.java) | | | 2639 | [Find the Width of Columns of a Grid](https://leetcode.com/problems/find-the-width-of-columns-of-a-grid) | [![Java](assets/java.png)](src/FindTheWidthOfColumnsOfAGrid.java) | | | 2643 | [Row With Maximum Ones](https://leetcode.com/problems/row-with-maximum-ones) | [![Java](assets/java.png)](src/RowWithMaximumOnes.java) | | -| 2644 | [Find the Maximum Divisibility Score](https://leetcode.com/problems/find-the-maximum-divisibility-score) | | | +| 2644 | [Find the Maximum Divisibility Score](https://leetcode.com/problems/find-the-maximum-divisibility-score) | [![Java](assets/java.png)](src/RowWithMaximumOnes.java) | | | 2651 | [Calculate Delayed Arrival Time](https://leetcode.com/problems/calculate-delayed-arrival-time) | | | | 2652 | [Sum Multiples](https://leetcode.com/problems/sum-multiples) | | | | 2656 | [Maximum Sum With Exactly K Elements](https://leetcode.com/problems/maximum-sum-with-exactly-k-elements) | | | diff --git a/src/FindTheMaximumDivisibilityScore.java b/src/FindTheMaximumDivisibilityScore.java new file mode 100644 index 0000000..dfab7d6 --- /dev/null +++ b/src/FindTheMaximumDivisibilityScore.java @@ -0,0 +1,37 @@ +// https://leetcode.com/problems/find-the-maximum-divisibility-score +// m: length of divisors +// n: length of nums +// T: O(m * n) +// S: O(m) + +import java.util.HashSet; +import java.util.Set; + +public class FindTheMaximumDivisibilityScore { + public int maxDivScore(int[] nums, int[] divisors) { + final Set setDivisors = new HashSet<>(); + int maxDivisibilityScore = 0, minDivisor = Integer.MAX_VALUE; + for (int divisor : divisors) { + if (setDivisors.contains(divisor)) { + continue; + } + setDivisors.add(divisor); + final int divisorScore = getDivisorScore(nums, divisor); + if (divisorScore > maxDivisibilityScore) { + maxDivisibilityScore = divisorScore; + minDivisor = divisor; + } else if (divisorScore == maxDivisibilityScore) { + minDivisor = Math.min(minDivisor, divisor); + } + } + return minDivisor; + } + + private int getDivisorScore(int[] array, int divisor) { + int count = 0; + for (int element : array) { + if (element % divisor == 0) count++; + } + return count; + } +} From 781581028ef77f6fab76fa33a15cb2c862e54bd1 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 7 Aug 2023 07:03:10 +0200 Subject: [PATCH 111/280] solves #2652: Calculate Delayed Arrival Time in java --- README.md | 4 ++-- src/CalculateDelayedArrivalTime.java | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 src/CalculateDelayedArrivalTime.java diff --git a/README.md b/README.md index 9dc3aab..c87da40 100644 --- a/README.md +++ b/README.md @@ -815,8 +815,8 @@ | 2614 | [Prime In Diagonal](https://leetcode.com/problems/prime-in-diagonal) | [![Java](assets/java.png)](src/PrimeInDiagonal.java) | | | 2639 | [Find the Width of Columns of a Grid](https://leetcode.com/problems/find-the-width-of-columns-of-a-grid) | [![Java](assets/java.png)](src/FindTheWidthOfColumnsOfAGrid.java) | | | 2643 | [Row With Maximum Ones](https://leetcode.com/problems/row-with-maximum-ones) | [![Java](assets/java.png)](src/RowWithMaximumOnes.java) | | -| 2644 | [Find the Maximum Divisibility Score](https://leetcode.com/problems/find-the-maximum-divisibility-score) | [![Java](assets/java.png)](src/RowWithMaximumOnes.java) | | -| 2651 | [Calculate Delayed Arrival Time](https://leetcode.com/problems/calculate-delayed-arrival-time) | | | +| 2644 | [Find the Maximum Divisibility Score](https://leetcode.com/problems/find-the-maximum-divisibility-score) | [![Java](assets/java.png)](src/FindTheMaximumDivisibilityScore.java) | | +| 2651 | [Calculate Delayed Arrival Time](https://leetcode.com/problems/calculate-delayed-arrival-time) | [![Java](assets/java.png)](src/CalculateDelayedArrivalTime.java) | | | 2652 | [Sum Multiples](https://leetcode.com/problems/sum-multiples) | | | | 2656 | [Maximum Sum With Exactly K Elements](https://leetcode.com/problems/maximum-sum-with-exactly-k-elements) | | | | 2660 | [Determine the Winner of a Bowling Game](https://leetcode.com/problems/determine-the-winner-of-a-bowling-game) | | | diff --git a/src/CalculateDelayedArrivalTime.java b/src/CalculateDelayedArrivalTime.java new file mode 100644 index 0000000..58b259c --- /dev/null +++ b/src/CalculateDelayedArrivalTime.java @@ -0,0 +1,9 @@ +// https://leetcode.com/problems/calculate-delayed-arrival-time +// T: O(1) +// S: O(1) + +public class CalculateDelayedArrivalTime { + public int findDelayedArrivalTime(int arrivalTime, int delayedTime) { + return (arrivalTime + delayedTime) % 24; + } +} From 6b2b5097a8e358f0097d2ba500f3675eafee5159 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 7 Aug 2023 07:11:19 +0200 Subject: [PATCH 112/280] solves #2652: Sum Multiples in java --- README.md | 2 +- src/SumMultiples.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/SumMultiples.java diff --git a/README.md b/README.md index c87da40..41b46b8 100644 --- a/README.md +++ b/README.md @@ -817,7 +817,7 @@ | 2643 | [Row With Maximum Ones](https://leetcode.com/problems/row-with-maximum-ones) | [![Java](assets/java.png)](src/RowWithMaximumOnes.java) | | | 2644 | [Find the Maximum Divisibility Score](https://leetcode.com/problems/find-the-maximum-divisibility-score) | [![Java](assets/java.png)](src/FindTheMaximumDivisibilityScore.java) | | | 2651 | [Calculate Delayed Arrival Time](https://leetcode.com/problems/calculate-delayed-arrival-time) | [![Java](assets/java.png)](src/CalculateDelayedArrivalTime.java) | | -| 2652 | [Sum Multiples](https://leetcode.com/problems/sum-multiples) | | | +| 2652 | [Sum Multiples](https://leetcode.com/problems/sum-multiples) | [![Java](assets/java.png)](src/SumMultiples.java) | | | 2656 | [Maximum Sum With Exactly K Elements](https://leetcode.com/problems/maximum-sum-with-exactly-k-elements) | | | | 2660 | [Determine the Winner of a Bowling Game](https://leetcode.com/problems/determine-the-winner-of-a-bowling-game) | | | | 2670 | [Find the Distinct Difference Array](https://leetcode.com/problems/find-the-distinct-difference-array) | | | diff --git a/src/SumMultiples.java b/src/SumMultiples.java new file mode 100644 index 0000000..1c1bd3c --- /dev/null +++ b/src/SumMultiples.java @@ -0,0 +1,19 @@ +// https://leetcode.com/problems/sum-multiples +// T: O(1) +// S: O(1) + +public class SumMultiples { + public int sumOfMultiples(int n) { + return 3 * summation(n / 3) + + 5 * summation(n / 5) + + 7 * summation(n / 7) + - 15 * summation(n / 15) + - 21 * summation(n / 21) + - 35 * summation(n / 35) + + 105 * summation(n / 105); + } + + private int summation(int x) { + return (x * (x + 1)) / 2; + } +} From f90e94a7dd30c33b77a96d58df6602830774590c Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 7 Aug 2023 07:15:23 +0200 Subject: [PATCH 113/280] solves 2656: Maximum Sum With Exactly K Elements in java --- README.md | 2 +- src/MaximumSumWithExactlyKElements.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/MaximumSumWithExactlyKElements.java diff --git a/README.md b/README.md index 41b46b8..79cdf7e 100644 --- a/README.md +++ b/README.md @@ -818,7 +818,7 @@ | 2644 | [Find the Maximum Divisibility Score](https://leetcode.com/problems/find-the-maximum-divisibility-score) | [![Java](assets/java.png)](src/FindTheMaximumDivisibilityScore.java) | | | 2651 | [Calculate Delayed Arrival Time](https://leetcode.com/problems/calculate-delayed-arrival-time) | [![Java](assets/java.png)](src/CalculateDelayedArrivalTime.java) | | | 2652 | [Sum Multiples](https://leetcode.com/problems/sum-multiples) | [![Java](assets/java.png)](src/SumMultiples.java) | | -| 2656 | [Maximum Sum With Exactly K Elements](https://leetcode.com/problems/maximum-sum-with-exactly-k-elements) | | | +| 2656 | [Maximum Sum With Exactly K Elements](https://leetcode.com/problems/maximum-sum-with-exactly-k-elements) | [![Java](assets/java.png)](src/MaximumSumWithExactlyKElements.java) | | | 2660 | [Determine the Winner of a Bowling Game](https://leetcode.com/problems/determine-the-winner-of-a-bowling-game) | | | | 2670 | [Find the Distinct Difference Array](https://leetcode.com/problems/find-the-distinct-difference-array) | | | | 2678 | [Number of Senior Citizens](https://leetcode.com/problems/number-of-senior-citizens) | | | diff --git a/src/MaximumSumWithExactlyKElements.java b/src/MaximumSumWithExactlyKElements.java new file mode 100644 index 0000000..c31662d --- /dev/null +++ b/src/MaximumSumWithExactlyKElements.java @@ -0,0 +1,16 @@ +// https://leetcode.com/problems/maximum-sum-with-exactly-k-elements +// T: O(n) +// S: O(1) + +import java.util.Arrays; + +public class MaximumSumWithExactlyKElements { + public int maximizeSum(int[] nums, int k) { + final int maxElement = Arrays.stream(nums).max().getAsInt(); + return maxElement * k + summation(k - 1); + } + + private int summation(int x) { + return (x * (x + 1)) / 2; + } +} From cda5db8708131ccea8d1b7f27567260587c54297 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 7 Aug 2023 07:46:40 +0200 Subject: [PATCH 114/280] solves #2660: Determine the Winner of a Bowling Game in java --- README.md | 2 +- src/DetermineTheWinnerOfABowlingGame.java | 29 +++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/DetermineTheWinnerOfABowlingGame.java diff --git a/README.md b/README.md index 79cdf7e..6dbe919 100644 --- a/README.md +++ b/README.md @@ -819,6 +819,6 @@ | 2651 | [Calculate Delayed Arrival Time](https://leetcode.com/problems/calculate-delayed-arrival-time) | [![Java](assets/java.png)](src/CalculateDelayedArrivalTime.java) | | | 2652 | [Sum Multiples](https://leetcode.com/problems/sum-multiples) | [![Java](assets/java.png)](src/SumMultiples.java) | | | 2656 | [Maximum Sum With Exactly K Elements](https://leetcode.com/problems/maximum-sum-with-exactly-k-elements) | [![Java](assets/java.png)](src/MaximumSumWithExactlyKElements.java) | | -| 2660 | [Determine the Winner of a Bowling Game](https://leetcode.com/problems/determine-the-winner-of-a-bowling-game) | | | +| 2660 | [Determine the Winner of a Bowling Game](https://leetcode.com/problems/determine-the-winner-of-a-bowling-game) | [![Java](assets/java.png)](src/DetermineTheWinnerOfABowlingGame.java) | | | 2670 | [Find the Distinct Difference Array](https://leetcode.com/problems/find-the-distinct-difference-array) | | | | 2678 | [Number of Senior Citizens](https://leetcode.com/problems/number-of-senior-citizens) | | | diff --git a/src/DetermineTheWinnerOfABowlingGame.java b/src/DetermineTheWinnerOfABowlingGame.java new file mode 100644 index 0000000..03d2b8a --- /dev/null +++ b/src/DetermineTheWinnerOfABowlingGame.java @@ -0,0 +1,29 @@ +// https://leetcode.com/problems/determine-the-winner-of-a-bowling-game +// T: O(n) +// S: O(1) + +public class DetermineTheWinnerOfABowlingGame { + public int isWinner(int[] player1, int[] player2) { + final int score1 = getPlayerScore(player1); + final int score2 = getPlayerScore(player2); + if (score1 > score2) return 1; + if (score1 < score2) return 2; + return 0; + } + + private int getPlayerScore(int[] scores) { + int total = 0, seen10 = 0; + for (int score : scores) { + if (seen10 > 0) { + total += 2 * score; + seen10--; + } else { + total += score; + } + if (score == 10) { + seen10 = 2; + } + } + return total; + } +} From 27d8d75f3ab4ed65d0cb83ec45103f05a663aec5 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 7 Aug 2023 08:38:35 +0200 Subject: [PATCH 115/280] update stats --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6dbe919..d7a23d1 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-593/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-556/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-682/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-664/2081-1abc9c.svg) ![problems-solved-python](https://img.shields.io/badge/Python-205/2081-1abc9c.svg) ![problems-solved-javascript](https://img.shields.io/badge/JavaScript-4/2081-1abc9c.svg) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md) From 9c87bd1896978e1af7ac4ff9655bee1fc6b6af8e Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 7 Aug 2023 08:39:33 +0200 Subject: [PATCH 116/280] update stats --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d7a23d1..4a75f2c 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-682/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-664/2081-1abc9c.svg) -![problems-solved-python](https://img.shields.io/badge/Python-205/2081-1abc9c.svg) -![problems-solved-javascript](https://img.shields.io/badge/JavaScript-4/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-682/2813-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-664/2813-1abc9c.svg) +![problems-solved-python](https://img.shields.io/badge/Python-205/2813-1abc9c.svg) +![problems-solved-javascript](https://img.shields.io/badge/JavaScript-4/2813-1abc9c.svg) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md) [![cp](https://img.shields.io/badge/also%20see-Competitve%20Programming-1f72ff.svg)](https://github.com/anishLearnsToCode/competitive-programming) From f21c1363aa90b30c2fdfdd952671f01289afda25 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 7 Aug 2023 16:22:46 +0200 Subject: [PATCH 117/280] solves #2670: Find the Distinct Difference Array in java --- README.md | 2 +- src/FindTheDistinctDifferenceArray.java | 42 +++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 src/FindTheDistinctDifferenceArray.java diff --git a/README.md b/README.md index 4a75f2c..1e1f764 100644 --- a/README.md +++ b/README.md @@ -820,5 +820,5 @@ | 2652 | [Sum Multiples](https://leetcode.com/problems/sum-multiples) | [![Java](assets/java.png)](src/SumMultiples.java) | | | 2656 | [Maximum Sum With Exactly K Elements](https://leetcode.com/problems/maximum-sum-with-exactly-k-elements) | [![Java](assets/java.png)](src/MaximumSumWithExactlyKElements.java) | | | 2660 | [Determine the Winner of a Bowling Game](https://leetcode.com/problems/determine-the-winner-of-a-bowling-game) | [![Java](assets/java.png)](src/DetermineTheWinnerOfABowlingGame.java) | | -| 2670 | [Find the Distinct Difference Array](https://leetcode.com/problems/find-the-distinct-difference-array) | | | +| 2670 | [Find the Distinct Difference Array](https://leetcode.com/problems/find-the-distinct-difference-array) | [![Java](assets/java.png)](src/FindTheDistinctDifferenceArray.java) | | | 2678 | [Number of Senior Citizens](https://leetcode.com/problems/number-of-senior-citizens) | | | diff --git a/src/FindTheDistinctDifferenceArray.java b/src/FindTheDistinctDifferenceArray.java new file mode 100644 index 0000000..99369ed --- /dev/null +++ b/src/FindTheDistinctDifferenceArray.java @@ -0,0 +1,42 @@ +// https://leetcode.com/problems/find-the-distinct-difference-array +// N: length of array +// T: O(N) +// S: O(N) + +import java.util.HashMap; +import java.util.Map; + +public class FindTheDistinctDifferenceArray { + public int[] distinctDifferenceArray(int[] nums) { + final Map leftFrequencies = new HashMap<>(); + final Map rightFrequencies = getNumberFrequencies(nums); + final int[] result = new int[nums.length]; + int k = 0; + for (int element : nums) { + addToFrequency(leftFrequencies, element); + removeFromFrequency(rightFrequencies, element); + result[k++] = leftFrequencies.size() - rightFrequencies.size(); + } + return result; + } + + private void removeFromFrequency(Map frequencies, int element) { + if (frequencies.get(element) == 1) { + frequencies.remove(element); + } else { + frequencies.put(element, frequencies.getOrDefault(element, 0) - 1); + } + } + + private void addToFrequency(Map frequencies, int element) { + frequencies.put(element, frequencies.getOrDefault(element, 0) + 1); + } + + private Map getNumberFrequencies(int[] array) { + final Map result = new HashMap<>(); + for (int element : array) { + result.put(element, result.getOrDefault(element, 0) + 1); + } + return result; + } +} From cb3aa349944ba6ad1f0ffc21d595330e931e595d Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 7 Aug 2023 16:26:36 +0200 Subject: [PATCH 118/280] solves #2678: Number of Senior Citizens in java --- README.md | 2 +- src/NumberOfSeniorCitizens.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/NumberOfSeniorCitizens.java diff --git a/README.md b/README.md index 1e1f764..5280312 100644 --- a/README.md +++ b/README.md @@ -821,4 +821,4 @@ | 2656 | [Maximum Sum With Exactly K Elements](https://leetcode.com/problems/maximum-sum-with-exactly-k-elements) | [![Java](assets/java.png)](src/MaximumSumWithExactlyKElements.java) | | | 2660 | [Determine the Winner of a Bowling Game](https://leetcode.com/problems/determine-the-winner-of-a-bowling-game) | [![Java](assets/java.png)](src/DetermineTheWinnerOfABowlingGame.java) | | | 2670 | [Find the Distinct Difference Array](https://leetcode.com/problems/find-the-distinct-difference-array) | [![Java](assets/java.png)](src/FindTheDistinctDifferenceArray.java) | | -| 2678 | [Number of Senior Citizens](https://leetcode.com/problems/number-of-senior-citizens) | | | +| 2678 | [Number of Senior Citizens](https://leetcode.com/problems/number-of-senior-citizens) | [![Java](assets/java.png)](src/NumberOfSeniorCitizens.java) | | diff --git a/src/NumberOfSeniorCitizens.java b/src/NumberOfSeniorCitizens.java new file mode 100644 index 0000000..edf10fe --- /dev/null +++ b/src/NumberOfSeniorCitizens.java @@ -0,0 +1,18 @@ +// https://leetcode.com/problems/number-of-senior-citizens +// T: O(N) +// S: O(1) + +public class NumberOfSeniorCitizens { + public int countSeniors(String[] details) { + int seniors = 0; + for (String detail : details) { + int age = getAge(detail); + if (age > 60) seniors++; + } + return seniors; + } + + private int getAge(String detail) { + return Integer.parseInt(detail.substring(11, 13)); + } +} From 080b52dd3f17d9450f66056f1170f6132fc55737 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 12 Aug 2023 12:30:16 +0200 Subject: [PATCH 119/280] solves #2682: Find the Losers of the Circular Game in java --- src/FindTheLosersOfTheCircularGame.java | 26 +++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/FindTheLosersOfTheCircularGame.java diff --git a/src/FindTheLosersOfTheCircularGame.java b/src/FindTheLosersOfTheCircularGame.java new file mode 100644 index 0000000..ddd7af0 --- /dev/null +++ b/src/FindTheLosersOfTheCircularGame.java @@ -0,0 +1,26 @@ +// https://leetcode.com/problems/find-the-losers-of-the-circular-game +// T: O(N) +// S: O(N) + +import java.util.HashSet; +import java.util.Set; + +public class FindTheLosersOfTheCircularGame { + public int[] circularGameLosers(int n, int k) { + final Set players = new HashSet<>(); + for (int i = 0, turn = 1 ; ; i = (i + turn * k) % n, turn++) { + if (players.contains(i)) { + break; + } + players.add(i); + } + final int totalLosers = n - players.size(); + final int[] losers = new int[totalLosers]; + for (int i = 1, j = 0 ; i <= n ; i++) { + if (!players.contains(i - 1)) { + losers[j++] = i; + } + } + return losers; + } +} From 5a7f1067c6e88455833b5cace021ef9b723098bc Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 12 Aug 2023 12:38:09 +0200 Subject: [PATCH 120/280] solves #2696: Minimum string length after removing substrings --- ...umStringLengthAfterRemovingSubstrings.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/MinimumStringLengthAfterRemovingSubstrings.java diff --git a/src/MinimumStringLengthAfterRemovingSubstrings.java b/src/MinimumStringLengthAfterRemovingSubstrings.java new file mode 100644 index 0000000..5ffbdb2 --- /dev/null +++ b/src/MinimumStringLengthAfterRemovingSubstrings.java @@ -0,0 +1,31 @@ +// https://leetcode.com/problems/minimum-string-length-after-removing-substrings +// T: O(N) +// S: O(N) + +import java.util.Set; +import java.util.Stack; + +public class MinimumStringLengthAfterRemovingSubstrings { + final static Set REMOVAL_TERMINATING_CHARS = Set.of('B', 'D'); + + public int minLength(String s) { + final Stack stack = new Stack<>(); + for (int i = 0 ; i < s.length() ; i++) { + final char letter = s.charAt(i); + if (!stack.isEmpty() && REMOVAL_TERMINATING_CHARS.contains(letter) && stack.peek() == inverse(letter)) { + stack.pop(); + } else { + stack.push(letter); + } + } + return stack.size(); + } + + private char inverse(char letter) { + return switch (letter) { + case 'B' -> 'A'; + case 'D' -> 'C'; + default -> ' '; + }; + } +} From 05b144fcccd6d8c36adb839e722ba3343cb465e8 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 12 Aug 2023 12:54:55 +0200 Subject: [PATCH 121/280] solves #2697: lexographically smallest palindrome --- README.md | 1 + src/LexicographicallySmallestPalindrome.java | 27 ++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/LexicographicallySmallestPalindrome.java diff --git a/README.md b/README.md index 5280312..ddbe27e 100644 --- a/README.md +++ b/README.md @@ -822,3 +822,4 @@ | 2660 | [Determine the Winner of a Bowling Game](https://leetcode.com/problems/determine-the-winner-of-a-bowling-game) | [![Java](assets/java.png)](src/DetermineTheWinnerOfABowlingGame.java) | | | 2670 | [Find the Distinct Difference Array](https://leetcode.com/problems/find-the-distinct-difference-array) | [![Java](assets/java.png)](src/FindTheDistinctDifferenceArray.java) | | | 2678 | [Number of Senior Citizens](https://leetcode.com/problems/number-of-senior-citizens) | [![Java](assets/java.png)](src/NumberOfSeniorCitizens.java) | | +| 268 | [Number of Senior Citizens](https://leetcode.com/problems/number-of-senior-citizens) | [![Java](assets/java.png)](src/NumberOfSeniorCitizens.java) | | \ No newline at end of file diff --git a/src/LexicographicallySmallestPalindrome.java b/src/LexicographicallySmallestPalindrome.java new file mode 100644 index 0000000..0963bdf --- /dev/null +++ b/src/LexicographicallySmallestPalindrome.java @@ -0,0 +1,27 @@ +// https://leetcode.com/problems/lexicographically-smallest-palindrome +// T: O(N) +// S: O(N) + +public class LexicographicallySmallestPalindrome { + public String makeSmallestPalindrome(String s) { + final StringBuilder firstPart = new StringBuilder(); + final StringBuilder lastPart = new StringBuilder(); + + for (int i = 0 ; i < s.length() / 2 ; i++) { + char first = s.charAt(i), last = s.charAt(s.length() - 1 - i); + if (first != last) { + char smaller = (char) Math.min(first, last); + firstPart.append(smaller); + lastPart.append(smaller); + } else { + firstPart.append(first); + lastPart.append(first); + } + } + + if (s.length() % 2 == 0) { + return firstPart.append(lastPart.reverse()).toString(); + } + return firstPart.append(s.charAt(s.length() / 2)).append(lastPart.reverse()).toString(); + } +} From 6e6169650f3fbaa6d45dceac58256d0e5cad3f3d Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 12 Aug 2023 13:17:27 +0200 Subject: [PATCH 122/280] solves #2706: buy two chocolates in java --- README.md => README.txt | 23 ++++++++++++++++++++++- src/BuyTwoChocolates.java | 19 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) rename README.md => README.txt (97%) create mode 100644 src/BuyTwoChocolates.java diff --git a/README.md b/README.txt similarity index 97% rename from README.md rename to README.txt index ddbe27e..ec44ef2 100644 --- a/README.md +++ b/README.txt @@ -822,4 +822,25 @@ | 2660 | [Determine the Winner of a Bowling Game](https://leetcode.com/problems/determine-the-winner-of-a-bowling-game) | [![Java](assets/java.png)](src/DetermineTheWinnerOfABowlingGame.java) | | | 2670 | [Find the Distinct Difference Array](https://leetcode.com/problems/find-the-distinct-difference-array) | [![Java](assets/java.png)](src/FindTheDistinctDifferenceArray.java) | | | 2678 | [Number of Senior Citizens](https://leetcode.com/problems/number-of-senior-citizens) | [![Java](assets/java.png)](src/NumberOfSeniorCitizens.java) | | -| 268 | [Number of Senior Citizens](https://leetcode.com/problems/number-of-senior-citizens) | [![Java](assets/java.png)](src/NumberOfSeniorCitizens.java) | | \ No newline at end of file +| 2682 | [Find the Losers of the Circular Game](https://leetcode.com/problems/find-the-losers-of-the-circular-game) | [![Java](assets/java.png)](src/FindTheLosersOfTheCircularGame.java) | | +| 2696 | [Minimum String Length After Removing Substrings](https://leetcode.com/problems/minimum-string-length-after-removing-substrings) | [![Java](assets/java.png)](src/MinimumStringLengthAfterRemovingSubstrings.java) | | +| 2697 | [Lexicographically Smallest Palindrome](https://leetcode.com/problems/lexicographically-smallest-palindrome) | [![Java](assets/java.png)](src/LexicographicallySmallestPalindrome.java) | | +| 2706 | [Buy Two Chocolates](https://leetcode.com/problems/buy-two-chocolates) | [![Java](assets/java.png)](src/BuyTwoChocolates.java) | | +| 2710 | [Remove Trailing Zeros From a String](https://leetcode.com/problems/remove-trailing-zeros-from-a-string) | | | +| 2716 | [Minimize String Length](https://leetcode.com/problems/minimize-string-length) | | | +| 2717 | [Semi-Ordered Permutation](https://leetcode.com/problems/semi-ordered-permutation) | | | +| 2728 | [Count Houses in a Circular Street](https://leetcode.com/problems/count-houses-in-a-circular-street) | | | +| 2729 | [Check if The Number is Fascinating](https://leetcode.com/problems/check-if-the-number-is-fascinating) | | | +| 2733 | [Neither Minimum nor Maximum](https://leetcode.com/problems/neither-minimum-nor-maximum) | | | +| 2739 | [Total Distance Traveled](https://leetcode.com/problems/total-distance-traveled) | | | +| 2744 | [Find Maximum Number of String Pairs](https://leetcode.com/problems/find-maximum-number-of-string-pairs) | | | +| 2748 | [Number of Beautiful Pairs](https://leetcode.com/problems/number-of-beautiful-pairs) | | | +| 2760 | [Longest Even Odd Subarray With Threshold](https://leetcode.com/problems/longest-even-odd-subarray-with-threshold) | | | +| 2765 | [Longest Alternating Subarray](https://leetcode.com/problems/longest-alternating-subarray) | | | +| 2769 | [Find the Maximum Achievable Number](https://leetcode.com/problems/find-the-maximum-achievable-number) | | | +| 2778 | [Sum of Squares of Special Elements](https://leetcode.com/problems/sum-of-squares-of-special-elements) | | | +| 2784 | [Check if Array is Good](https://leetcode.com/problems/check-if-array-is-good) | | | +| 2788 | [Split Strings by Separator](https://leetcode.com/problems/split-strings-by-separator) | | | +| 2798 | [Number of Employees Who Met the Target](https://leetcode.com/problems/number-of-employees-who-met-the-target) | | | +| 2806 | [Account Balance After Rounded Purchase](https://leetcode.com/problems/account-balance-after-rounded-purchase) | | | +| 2810 | [Faulty Keyboard](https://leetcode.com/problems/faulty-keyboard) | | | \ No newline at end of file diff --git a/src/BuyTwoChocolates.java b/src/BuyTwoChocolates.java new file mode 100644 index 0000000..ccb466e --- /dev/null +++ b/src/BuyTwoChocolates.java @@ -0,0 +1,19 @@ +// https://leetcode.com/problems/buy-two-chocolates +// T: O(N) +// S: O(1) + +public class BuyTwoChocolates { + public int buyChoco(int[] prices, int money) { + int minimum = Integer.MAX_VALUE, secondMinimum = Integer.MAX_VALUE; + for (int price : prices) { + if (price <= minimum) { + secondMinimum = minimum; + minimum = price; + } else if (price < secondMinimum) { + secondMinimum = price; + } + } + if (minimum + secondMinimum > money) return money; + return money - (minimum + secondMinimum); + } +} From bcaf090f0877107da6ba05222ed3a88a63a174a7 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 12 Aug 2023 13:20:52 +0200 Subject: [PATCH 123/280] solves #2710: Remove Trailing Zeros From a String in java --- README.txt | 2 +- src/RemoveTrailingZerosFromAString.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/RemoveTrailingZerosFromAString.java diff --git a/README.txt b/README.txt index ec44ef2..e5403f3 100644 --- a/README.txt +++ b/README.txt @@ -826,7 +826,7 @@ | 2696 | [Minimum String Length After Removing Substrings](https://leetcode.com/problems/minimum-string-length-after-removing-substrings) | [![Java](assets/java.png)](src/MinimumStringLengthAfterRemovingSubstrings.java) | | | 2697 | [Lexicographically Smallest Palindrome](https://leetcode.com/problems/lexicographically-smallest-palindrome) | [![Java](assets/java.png)](src/LexicographicallySmallestPalindrome.java) | | | 2706 | [Buy Two Chocolates](https://leetcode.com/problems/buy-two-chocolates) | [![Java](assets/java.png)](src/BuyTwoChocolates.java) | | -| 2710 | [Remove Trailing Zeros From a String](https://leetcode.com/problems/remove-trailing-zeros-from-a-string) | | | +| 2710 | [Remove Trailing Zeros From a String](https://leetcode.com/problems/remove-trailing-zeros-from-a-string) | [![Java](assets/java.png)](src/RemoveTrailingZerosFromAString.java) | | | 2716 | [Minimize String Length](https://leetcode.com/problems/minimize-string-length) | | | | 2717 | [Semi-Ordered Permutation](https://leetcode.com/problems/semi-ordered-permutation) | | | | 2728 | [Count Houses in a Circular Street](https://leetcode.com/problems/count-houses-in-a-circular-street) | | | diff --git a/src/RemoveTrailingZerosFromAString.java b/src/RemoveTrailingZerosFromAString.java new file mode 100644 index 0000000..ea86a44 --- /dev/null +++ b/src/RemoveTrailingZerosFromAString.java @@ -0,0 +1,14 @@ +// https://leetcode.com/problems/remove-trailing-zeros-from-a-string +// T: O(|s|) +// S: O(|s|) + +public class RemoveTrailingZerosFromAString { + public String removeTrailingZeros(String num) { + for (int i = num.length() - 1; i >= 0 ; i--) { + if (num.charAt(i) != '0') { + return num.substring(0, i + 1); + } + } + return ""; + } +} From cdf59786777aba209363a71b14a4abc7fa089b48 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 12 Aug 2023 13:25:45 +0200 Subject: [PATCH 124/280] solves #2716: Minimize String Length in java --- README.txt | 4 ++-- src/MinimizeStringLength.java | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 src/MinimizeStringLength.java diff --git a/README.txt b/README.txt index e5403f3..76e31fc 100644 --- a/README.txt +++ b/README.txt @@ -826,8 +826,8 @@ | 2696 | [Minimum String Length After Removing Substrings](https://leetcode.com/problems/minimum-string-length-after-removing-substrings) | [![Java](assets/java.png)](src/MinimumStringLengthAfterRemovingSubstrings.java) | | | 2697 | [Lexicographically Smallest Palindrome](https://leetcode.com/problems/lexicographically-smallest-palindrome) | [![Java](assets/java.png)](src/LexicographicallySmallestPalindrome.java) | | | 2706 | [Buy Two Chocolates](https://leetcode.com/problems/buy-two-chocolates) | [![Java](assets/java.png)](src/BuyTwoChocolates.java) | | -| 2710 | [Remove Trailing Zeros From a String](https://leetcode.com/problems/remove-trailing-zeros-from-a-string) | [![Java](assets/java.png)](src/RemoveTrailingZerosFromAString.java) | | -| 2716 | [Minimize String Length](https://leetcode.com/problems/minimize-string-length) | | | +| 2710 | [Remove Trailing Zeros From a String](https://leetcode.com/problems/remove-trailing-zeros-from-a-string) | [![Java](assets/java.png)](src/RemoveTrailingZerosFromAString.java) | | +| 2716 | [Minimize String Length](https://leetcode.com/problems/minimize-string-length) | [![Java](assets/java.png)](src/MinimizeStringLength.java) | | | 2717 | [Semi-Ordered Permutation](https://leetcode.com/problems/semi-ordered-permutation) | | | | 2728 | [Count Houses in a Circular Street](https://leetcode.com/problems/count-houses-in-a-circular-street) | | | | 2729 | [Check if The Number is Fascinating](https://leetcode.com/problems/check-if-the-number-is-fascinating) | | | diff --git a/src/MinimizeStringLength.java b/src/MinimizeStringLength.java new file mode 100644 index 0000000..e88b12b --- /dev/null +++ b/src/MinimizeStringLength.java @@ -0,0 +1,16 @@ +// https://leetcode.com/problems/minimize-string-length +// T: O(N) +// S: O(1) + +import java.util.HashSet; +import java.util.Set; + +public class MinimizeStringLength { + public int minimizedStringLength(String s) { + final Set letters = new HashSet<>(); + for (int i = 0 ; i < s.length() ; i++) { + letters.add(s.charAt(i)); + } + return letters.size(); + } +} From 40399af6f65d6f5bd26e3d101dbad318136d8523 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 12 Aug 2023 13:32:09 +0200 Subject: [PATCH 125/280] solves #2717: Semi-Ordered Permutation in java --- README.txt | 2 +- src/SemiOrderedPermutation.java | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/SemiOrderedPermutation.java diff --git a/README.txt b/README.txt index 76e31fc..b43c615 100644 --- a/README.txt +++ b/README.txt @@ -828,7 +828,7 @@ | 2706 | [Buy Two Chocolates](https://leetcode.com/problems/buy-two-chocolates) | [![Java](assets/java.png)](src/BuyTwoChocolates.java) | | | 2710 | [Remove Trailing Zeros From a String](https://leetcode.com/problems/remove-trailing-zeros-from-a-string) | [![Java](assets/java.png)](src/RemoveTrailingZerosFromAString.java) | | | 2716 | [Minimize String Length](https://leetcode.com/problems/minimize-string-length) | [![Java](assets/java.png)](src/MinimizeStringLength.java) | | -| 2717 | [Semi-Ordered Permutation](https://leetcode.com/problems/semi-ordered-permutation) | | | +| 2717 | [Semi-Ordered Permutation](https://leetcode.com/problems/semi-ordered-permutation) | [![Java](assets/java.png)](src/SemiOrderedPermutation.java) | | | 2728 | [Count Houses in a Circular Street](https://leetcode.com/problems/count-houses-in-a-circular-street) | | | | 2729 | [Check if The Number is Fascinating](https://leetcode.com/problems/check-if-the-number-is-fascinating) | | | | 2733 | [Neither Minimum nor Maximum](https://leetcode.com/problems/neither-minimum-nor-maximum) | | | diff --git a/src/SemiOrderedPermutation.java b/src/SemiOrderedPermutation.java new file mode 100644 index 0000000..47bb5a9 --- /dev/null +++ b/src/SemiOrderedPermutation.java @@ -0,0 +1,25 @@ +// https://leetcode.com/problems/semi-ordered-permutation +// T: O(N) +// S: O(1) + +import java.util.Arrays; + +public class SemiOrderedPermutation { + public int semiOrderedPermutation(int[] nums) { + final int startIndex = findIndexOf(nums, 1); + final int endIndex = findIndexOf(nums, nums.length); + final int endDrift = nums.length - endIndex - 1; + + if (endIndex < startIndex) { + return startIndex + endDrift - 1; + } + return startIndex + endDrift; + } + + private int findIndexOf(int[] array, int element) { + for (int i = 0 ; i < array.length ; i++) { + if (array[i] == element) return i; + } + return -1; + } +} From f1e6b1724eb5b9dc409569d8e17e7be1a3e9e28f Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 12 Aug 2023 13:39:29 +0200 Subject: [PATCH 126/280] solves #2729: Check if The Number is Fascinating in java --- README.txt | 2 +- src/CheckIfTheNumberIsFascinating.java | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/CheckIfTheNumberIsFascinating.java diff --git a/README.txt b/README.txt index b43c615..410ffaa 100644 --- a/README.txt +++ b/README.txt @@ -830,7 +830,7 @@ | 2716 | [Minimize String Length](https://leetcode.com/problems/minimize-string-length) | [![Java](assets/java.png)](src/MinimizeStringLength.java) | | | 2717 | [Semi-Ordered Permutation](https://leetcode.com/problems/semi-ordered-permutation) | [![Java](assets/java.png)](src/SemiOrderedPermutation.java) | | | 2728 | [Count Houses in a Circular Street](https://leetcode.com/problems/count-houses-in-a-circular-street) | | | -| 2729 | [Check if The Number is Fascinating](https://leetcode.com/problems/check-if-the-number-is-fascinating) | | | +| 2729 | [Check if The Number is Fascinating](https://leetcode.com/problems/check-if-the-number-is-fascinating) | [![Java](assets/java.png)](src/CheckIfTheNumberIsFascinating.java) | | | 2733 | [Neither Minimum nor Maximum](https://leetcode.com/problems/neither-minimum-nor-maximum) | | | | 2739 | [Total Distance Traveled](https://leetcode.com/problems/total-distance-traveled) | | | | 2744 | [Find Maximum Number of String Pairs](https://leetcode.com/problems/find-maximum-number-of-string-pairs) | | | diff --git a/src/CheckIfTheNumberIsFascinating.java b/src/CheckIfTheNumberIsFascinating.java new file mode 100644 index 0000000..e642aba --- /dev/null +++ b/src/CheckIfTheNumberIsFascinating.java @@ -0,0 +1,22 @@ +// https://leetcode.com/problems/check-if-the-number-is-fascinating +// T: O(log(N)) +// S: O(1) + +import java.util.HashSet; +import java.util.Set; + +public class CheckIfTheNumberIsFascinating { + public boolean isFascinating(int number) { + final String modifiedNumber = "" + number + (2 * number) + (3 * number); + final Set digits = toSet(modifiedNumber); + return digits.size() == 9 && !digits.contains('0') && modifiedNumber.length() == 9; + } + + private Set toSet(String str) { + final Set set = new HashSet<>(); + for (int i = 0 ; i < str.length() ; i++) { + set.add(str.charAt(i)); + } + return set; + } +} From b8755f9ac09086b73161a8242fe9757c572823e8 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 12 Aug 2023 13:47:35 +0200 Subject: [PATCH 127/280] solves #2733: Neither Minimum nor Maximum in java --- README.txt | 4 ++-- src/NeitherMinimumNorMaximum.java | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 src/NeitherMinimumNorMaximum.java diff --git a/README.txt b/README.txt index 410ffaa..901a716 100644 --- a/README.txt +++ b/README.txt @@ -1,7 +1,7 @@ # LeetCode Algorithms ![problems-solved](https://img.shields.io/badge/Problems%20Solved-682/2813-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-664/2813-1abc9c.svg) +![problems-solved-java](https://img.shields.io/badge/Java-674/2813-1abc9c.svg) ![problems-solved-python](https://img.shields.io/badge/Python-205/2813-1abc9c.svg) ![problems-solved-javascript](https://img.shields.io/badge/JavaScript-4/2813-1abc9c.svg) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md) @@ -831,7 +831,7 @@ | 2717 | [Semi-Ordered Permutation](https://leetcode.com/problems/semi-ordered-permutation) | [![Java](assets/java.png)](src/SemiOrderedPermutation.java) | | | 2728 | [Count Houses in a Circular Street](https://leetcode.com/problems/count-houses-in-a-circular-street) | | | | 2729 | [Check if The Number is Fascinating](https://leetcode.com/problems/check-if-the-number-is-fascinating) | [![Java](assets/java.png)](src/CheckIfTheNumberIsFascinating.java) | | -| 2733 | [Neither Minimum nor Maximum](https://leetcode.com/problems/neither-minimum-nor-maximum) | | | +| 2733 | [Neither Minimum nor Maximum](https://leetcode.com/problems/neither-minimum-nor-maximum) | [![Java](assets/java.png)](src/NeitherMinimumNorMaximum.java ) | | | 2739 | [Total Distance Traveled](https://leetcode.com/problems/total-distance-traveled) | | | | 2744 | [Find Maximum Number of String Pairs](https://leetcode.com/problems/find-maximum-number-of-string-pairs) | | | | 2748 | [Number of Beautiful Pairs](https://leetcode.com/problems/number-of-beautiful-pairs) | | | diff --git a/src/NeitherMinimumNorMaximum.java b/src/NeitherMinimumNorMaximum.java new file mode 100644 index 0000000..56fec25 --- /dev/null +++ b/src/NeitherMinimumNorMaximum.java @@ -0,0 +1,15 @@ +// https://leetcode.com/problems/neither-minimum-nor-maximum +// T: O(1) +// S: O(1) + +public class NeitherMinimumNorMaximum { + public int findNonMinOrMax(int[] nums) { + if (nums.length < 3) return -1; + final int max = Math.max(nums[0], nums[1]); + final int min = Math.min(nums[0], nums[1]); + + if (nums[2] < min) return min; + else if (nums[2] < max) return nums[2]; + return max; + } +} From ea9ddb767f0707ee88413993a5f44411a2a6ecc3 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 12 Aug 2023 13:55:16 +0200 Subject: [PATCH 128/280] solves #2739: TotalDistanceTravele in java --- README.txt | 4 ++-- src/TotalDistanceTraveled.java | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 src/TotalDistanceTraveled.java diff --git a/README.txt b/README.txt index 901a716..1da6dad 100644 --- a/README.txt +++ b/README.txt @@ -831,8 +831,8 @@ | 2717 | [Semi-Ordered Permutation](https://leetcode.com/problems/semi-ordered-permutation) | [![Java](assets/java.png)](src/SemiOrderedPermutation.java) | | | 2728 | [Count Houses in a Circular Street](https://leetcode.com/problems/count-houses-in-a-circular-street) | | | | 2729 | [Check if The Number is Fascinating](https://leetcode.com/problems/check-if-the-number-is-fascinating) | [![Java](assets/java.png)](src/CheckIfTheNumberIsFascinating.java) | | -| 2733 | [Neither Minimum nor Maximum](https://leetcode.com/problems/neither-minimum-nor-maximum) | [![Java](assets/java.png)](src/NeitherMinimumNorMaximum.java ) | | -| 2739 | [Total Distance Traveled](https://leetcode.com/problems/total-distance-traveled) | | | +| 2733 | [Neither Minimum nor Maximum](https://leetcode.com/problems/neither-minimum-nor-maximum) | [![Java](assets/java.png)](src/NeitherMinimumNorMaximum.java) | | +| 2739 | [Total Distance Traveled](https://leetcode.com/problems/total-distance-traveled) | [![Java](assets/java.png)](src/TotalDistanceTraveled.java) | | | 2744 | [Find Maximum Number of String Pairs](https://leetcode.com/problems/find-maximum-number-of-string-pairs) | | | | 2748 | [Number of Beautiful Pairs](https://leetcode.com/problems/number-of-beautiful-pairs) | | | | 2760 | [Longest Even Odd Subarray With Threshold](https://leetcode.com/problems/longest-even-odd-subarray-with-threshold) | | | diff --git a/src/TotalDistanceTraveled.java b/src/TotalDistanceTraveled.java new file mode 100644 index 0000000..11d6490 --- /dev/null +++ b/src/TotalDistanceTraveled.java @@ -0,0 +1,25 @@ +// https://leetcode.com/problems/total-distance-traveled +// M = mainTank +// T: O(M) +// S: O(1) + +public class TotalDistanceTraveled { + public int distanceTraveled(int mainTank, int additionalTank) { + int totalDistance = 0; + while (mainTank > 0) { + if (mainTank >= 5) { + mainTank -= 5; + totalDistance += 50; + if (additionalTank > 0) { + mainTank++; + additionalTank--; + } + } else { + totalDistance += mainTank * 10; + mainTank = 0; + } + } + + return totalDistance; + } +} From c4401eeb84c72332363381d1215f9f61725eac8a Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 12 Aug 2023 14:00:50 +0200 Subject: [PATCH 129/280] solves #2744: FindMaximumNumberOfStringPair in java --- README.txt | 2 +- src/FindMaximumNumberOfStringPairs.java | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 src/FindMaximumNumberOfStringPairs.java diff --git a/README.txt b/README.txt index 1da6dad..c508885 100644 --- a/README.txt +++ b/README.txt @@ -833,7 +833,7 @@ | 2729 | [Check if The Number is Fascinating](https://leetcode.com/problems/check-if-the-number-is-fascinating) | [![Java](assets/java.png)](src/CheckIfTheNumberIsFascinating.java) | | | 2733 | [Neither Minimum nor Maximum](https://leetcode.com/problems/neither-minimum-nor-maximum) | [![Java](assets/java.png)](src/NeitherMinimumNorMaximum.java) | | | 2739 | [Total Distance Traveled](https://leetcode.com/problems/total-distance-traveled) | [![Java](assets/java.png)](src/TotalDistanceTraveled.java) | | -| 2744 | [Find Maximum Number of String Pairs](https://leetcode.com/problems/find-maximum-number-of-string-pairs) | | | +| 2744 | [Find Maximum Number of String Pairs](https://leetcode.com/problems/find-maximum-number-of-string-pairs) | [![Java](assets/java.png)](src/FindMaximumNumberOfStringPairs.java) | | | 2748 | [Number of Beautiful Pairs](https://leetcode.com/problems/number-of-beautiful-pairs) | | | | 2760 | [Longest Even Odd Subarray With Threshold](https://leetcode.com/problems/longest-even-odd-subarray-with-threshold) | | | | 2765 | [Longest Alternating Subarray](https://leetcode.com/problems/longest-alternating-subarray) | | | diff --git a/src/FindMaximumNumberOfStringPairs.java b/src/FindMaximumNumberOfStringPairs.java new file mode 100644 index 0000000..50053c6 --- /dev/null +++ b/src/FindMaximumNumberOfStringPairs.java @@ -0,0 +1,23 @@ +// https://leetcode.com/problems/find-maximum-number-of-string-pairs +// T: O(N * |s|) +// S: O(N * |s|) + +import java.util.HashSet; +import java.util.Set; + +public class FindMaximumNumberOfStringPairs { + public int maximumNumberOfStringPairs(String[] words) { + final Set strings = new HashSet<>(); + int pairs = 0; + for (String word : words) { + final String reversed = new StringBuilder(word).reverse().toString(); + if (strings.contains(reversed)) { + pairs++; + strings.remove(reversed); + } else { + strings.add(word); + } + } + return pairs; + } +} From 26bd3974a89a67b2de624614b8684fb61e44ba63 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 12 Aug 2023 14:22:20 +0200 Subject: [PATCH 130/280] solves #2748: Number of Beautiful Pairs in java --- README.txt | 2 +- src/NumberOfBeautifulPairs.java | 41 +++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/NumberOfBeautifulPairs.java diff --git a/README.txt b/README.txt index c508885..a116e41 100644 --- a/README.txt +++ b/README.txt @@ -834,7 +834,7 @@ | 2733 | [Neither Minimum nor Maximum](https://leetcode.com/problems/neither-minimum-nor-maximum) | [![Java](assets/java.png)](src/NeitherMinimumNorMaximum.java) | | | 2739 | [Total Distance Traveled](https://leetcode.com/problems/total-distance-traveled) | [![Java](assets/java.png)](src/TotalDistanceTraveled.java) | | | 2744 | [Find Maximum Number of String Pairs](https://leetcode.com/problems/find-maximum-number-of-string-pairs) | [![Java](assets/java.png)](src/FindMaximumNumberOfStringPairs.java) | | -| 2748 | [Number of Beautiful Pairs](https://leetcode.com/problems/number-of-beautiful-pairs) | | | +| 2748 | [Number of Beautiful Pairs](https://leetcode.com/problems/number-of-beautiful-pairs) | [![Java](assets/java.png)](src/)NumberOfBeautifulPairs.java) | | | 2760 | [Longest Even Odd Subarray With Threshold](https://leetcode.com/problems/longest-even-odd-subarray-with-threshold) | | | | 2765 | [Longest Alternating Subarray](https://leetcode.com/problems/longest-alternating-subarray) | | | | 2769 | [Find the Maximum Achievable Number](https://leetcode.com/problems/find-the-maximum-achievable-number) | | | diff --git a/src/NumberOfBeautifulPairs.java b/src/NumberOfBeautifulPairs.java new file mode 100644 index 0000000..d04b286 --- /dev/null +++ b/src/NumberOfBeautifulPairs.java @@ -0,0 +1,41 @@ +// https://leetcode.com/problems/number-of-beautiful-pairs/description +// N: length of number array +// m: size of average number +// T: O(N * log(m)) +// S: O(N) + +import java.util.HashMap; +import java.util.Map; + +public class NumberOfBeautifulPairs { + public int countBeautifulPairs(int[] array) { + final Map firstDigitFrequencies = new HashMap<>(); + int pairs = 0; + for (int element : array) { + final int firstDigit = getFirstDigit(element); + final int lastDigit = getLastDigit(element); + for (Map.Entry entry : firstDigitFrequencies.entrySet()) { + if (gcd(lastDigit, entry.getKey()) == 1) { + pairs += entry.getValue(); + } + } + firstDigitFrequencies.put(firstDigit, firstDigitFrequencies.getOrDefault(firstDigit, 0) + 1); + } + return pairs; + } + + private int getFirstDigit(int number) { + return (number + "").charAt(0) - '0'; + } + + private int getLastDigit(int number) { + return number % 10; + } + + // T: O(log(max(a, b))) + // S: O(log(max(a, b))) + private int gcd(int a, int b) { + if (b == 0) return a; + return gcd(b, a % b); + } +} From 171c6e7c4191337532ab9eb0f794fd7b94b09783 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 12 Aug 2023 14:44:35 +0200 Subject: [PATCH 131/280] solves #2760: Longest Even Odd Subarray With Threshold in java --- README.txt | 14 +++++++------- src/LongestEvenOddSubarrayWithThreshold.java | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 src/LongestEvenOddSubarrayWithThreshold.java diff --git a/README.txt b/README.txt index a116e41..ec806c4 100644 --- a/README.txt +++ b/README.txt @@ -828,14 +828,14 @@ | 2706 | [Buy Two Chocolates](https://leetcode.com/problems/buy-two-chocolates) | [![Java](assets/java.png)](src/BuyTwoChocolates.java) | | | 2710 | [Remove Trailing Zeros From a String](https://leetcode.com/problems/remove-trailing-zeros-from-a-string) | [![Java](assets/java.png)](src/RemoveTrailingZerosFromAString.java) | | | 2716 | [Minimize String Length](https://leetcode.com/problems/minimize-string-length) | [![Java](assets/java.png)](src/MinimizeStringLength.java) | | -| 2717 | [Semi-Ordered Permutation](https://leetcode.com/problems/semi-ordered-permutation) | [![Java](assets/java.png)](src/SemiOrderedPermutation.java) | | +| 2717 | [Semi-Ordered Permutation](https://leetcode.com/problems/semi-ordered-permutation) | [![Java](assets/java.png)](src/SemiOrderedPermutation.java) | | | 2728 | [Count Houses in a Circular Street](https://leetcode.com/problems/count-houses-in-a-circular-street) | | | -| 2729 | [Check if The Number is Fascinating](https://leetcode.com/problems/check-if-the-number-is-fascinating) | [![Java](assets/java.png)](src/CheckIfTheNumberIsFascinating.java) | | -| 2733 | [Neither Minimum nor Maximum](https://leetcode.com/problems/neither-minimum-nor-maximum) | [![Java](assets/java.png)](src/NeitherMinimumNorMaximum.java) | | -| 2739 | [Total Distance Traveled](https://leetcode.com/problems/total-distance-traveled) | [![Java](assets/java.png)](src/TotalDistanceTraveled.java) | | -| 2744 | [Find Maximum Number of String Pairs](https://leetcode.com/problems/find-maximum-number-of-string-pairs) | [![Java](assets/java.png)](src/FindMaximumNumberOfStringPairs.java) | | -| 2748 | [Number of Beautiful Pairs](https://leetcode.com/problems/number-of-beautiful-pairs) | [![Java](assets/java.png)](src/)NumberOfBeautifulPairs.java) | | -| 2760 | [Longest Even Odd Subarray With Threshold](https://leetcode.com/problems/longest-even-odd-subarray-with-threshold) | | | +| 2729 | [Check if The Number is Fascinating](https://leetcode.com/problems/check-if-the-number-is-fascinating) | [![Java](assets/java.png)](src/CheckIfTheNumberIsFascinating.java) | | +| 2733 | [Neither Minimum nor Maximum](https://leetcode.com/problems/neither-minimum-nor-maximum) | [![Java](assets/java.png)](src/NeitherMinimumNorMaximum.java) | | +| 2739 | [Total Distance Traveled](https://leetcode.com/problems/total-distance-traveled) | [![Java](assets/java.png)](src/TotalDistanceTraveled.java) | | +| 2744 | [Find Maximum Number of String Pairs](https://leetcode.com/problems/find-maximum-number-of-string-pairs) | [![Java](assets/java.png)](src/FindMaximumNumberOfStringPairs.java) | | +| 2748 | [Number of Beautiful Pairs](https://leetcode.com/problems/number-of-beautiful-pairs) | [![Java](assets/java.png)](src/NumberOfBeautifulPairs.java) | | +| 2760 | [Longest Even Odd Subarray With Threshold](https://leetcode.com/problems/longest-even-odd-subarray-with-threshold) | [![Java](assets/java.png)](src/LongestEvenOddSubarrayWithThreshold.java) | | | 2765 | [Longest Alternating Subarray](https://leetcode.com/problems/longest-alternating-subarray) | | | | 2769 | [Find the Maximum Achievable Number](https://leetcode.com/problems/find-the-maximum-achievable-number) | | | | 2778 | [Sum of Squares of Special Elements](https://leetcode.com/problems/sum-of-squares-of-special-elements) | | | diff --git a/src/LongestEvenOddSubarrayWithThreshold.java b/src/LongestEvenOddSubarrayWithThreshold.java new file mode 100644 index 0000000..3e3b10e --- /dev/null +++ b/src/LongestEvenOddSubarrayWithThreshold.java @@ -0,0 +1,18 @@ +// https://leetcode.com/problems/longest-even-odd-subarray-with-threshold +// T: O(N) +// S: O(N) + +public class LongestEvenOddSubarrayWithThreshold { + public int longestAlternatingSubarray(int[] array, int threshold) { + final int[] dp = new int[array.length]; + dp[0] = array[0] % 2 == 0 && array[0] <= threshold ? 1 : 0; + int maxLength = dp[0]; + for (int i = 1 ; i < dp.length ; i++) { + if (array[i] <= threshold && array[i] % 2 != array[i - 1] % 2 && dp[i - 1] > 0) dp[i] = dp[i - 1] + 1; + else if (array[i] % 2 == 0 && array[i] <= threshold) dp[i] = 1; + else dp[i] = 0; + maxLength = Math.max(maxLength, dp[i]); + } + return maxLength; + } +} From 6af4af17d38484ff611ee07a0be18fe5caec946f Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 12 Aug 2023 15:12:27 +0200 Subject: [PATCH 132/280] solves --- README.txt | 2 +- src/LongestAlternatingSubarray.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/LongestAlternatingSubarray.java diff --git a/README.txt b/README.txt index ec806c4..bd153f1 100644 --- a/README.txt +++ b/README.txt @@ -836,7 +836,7 @@ | 2744 | [Find Maximum Number of String Pairs](https://leetcode.com/problems/find-maximum-number-of-string-pairs) | [![Java](assets/java.png)](src/FindMaximumNumberOfStringPairs.java) | | | 2748 | [Number of Beautiful Pairs](https://leetcode.com/problems/number-of-beautiful-pairs) | [![Java](assets/java.png)](src/NumberOfBeautifulPairs.java) | | | 2760 | [Longest Even Odd Subarray With Threshold](https://leetcode.com/problems/longest-even-odd-subarray-with-threshold) | [![Java](assets/java.png)](src/LongestEvenOddSubarrayWithThreshold.java) | | -| 2765 | [Longest Alternating Subarray](https://leetcode.com/problems/longest-alternating-subarray) | | | +| 2765 | [Longest Alternating Subarray](https://leetcode.com/problems/longest-alternating-subarray) | [![Java](assets/java.png)](src/LongestAlternatingSubarray.java) | | | 2769 | [Find the Maximum Achievable Number](https://leetcode.com/problems/find-the-maximum-achievable-number) | | | | 2778 | [Sum of Squares of Special Elements](https://leetcode.com/problems/sum-of-squares-of-special-elements) | | | | 2784 | [Check if Array is Good](https://leetcode.com/problems/check-if-array-is-good) | | | diff --git a/src/LongestAlternatingSubarray.java b/src/LongestAlternatingSubarray.java new file mode 100644 index 0000000..c77ada3 --- /dev/null +++ b/src/LongestAlternatingSubarray.java @@ -0,0 +1,15 @@ +// https://leetcode.com/problems/longest-alternating-subarray +// T: O(N) +// S: O(1) + +public class LongestAlternatingSubarray { + public int alternatingSubarray(int[] array) { + int maxLength = 0, j = 0; + for (int i = 0 ; i < array.length ; i = Math.max(i + 1, j - 1)) { + for (j = i + 1 ; j < array.length && array[j] == array[i] + (j - i) % 2 ; j++) { + maxLength = Math.max(maxLength, j - i + 1); + } + } + return maxLength > 1 ? maxLength : -1; + } +} From 0515813860b6e91f9e1a5b74c5ce0508ea80ea60 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 12 Aug 2023 15:15:50 +0200 Subject: [PATCH 133/280] solves #2769: Find the Maximum Achievable Number in java --- README.txt | 2 +- src/FindTheMaximumAchievableNumber.java | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/FindTheMaximumAchievableNumber.java diff --git a/README.txt b/README.txt index bd153f1..34683f2 100644 --- a/README.txt +++ b/README.txt @@ -837,7 +837,7 @@ | 2748 | [Number of Beautiful Pairs](https://leetcode.com/problems/number-of-beautiful-pairs) | [![Java](assets/java.png)](src/NumberOfBeautifulPairs.java) | | | 2760 | [Longest Even Odd Subarray With Threshold](https://leetcode.com/problems/longest-even-odd-subarray-with-threshold) | [![Java](assets/java.png)](src/LongestEvenOddSubarrayWithThreshold.java) | | | 2765 | [Longest Alternating Subarray](https://leetcode.com/problems/longest-alternating-subarray) | [![Java](assets/java.png)](src/LongestAlternatingSubarray.java) | | -| 2769 | [Find the Maximum Achievable Number](https://leetcode.com/problems/find-the-maximum-achievable-number) | | | +| 2769 | [Find the Maximum Achievable Number](https://leetcode.com/problems/find-the-maximum-achievable-number) | [![Java](assets/java.png)](src/FindTheMaximumAchievableNumber.java) | | | 2778 | [Sum of Squares of Special Elements](https://leetcode.com/problems/sum-of-squares-of-special-elements) | | | | 2784 | [Check if Array is Good](https://leetcode.com/problems/check-if-array-is-good) | | | | 2788 | [Split Strings by Separator](https://leetcode.com/problems/split-strings-by-separator) | | | diff --git a/src/FindTheMaximumAchievableNumber.java b/src/FindTheMaximumAchievableNumber.java new file mode 100644 index 0000000..422271c --- /dev/null +++ b/src/FindTheMaximumAchievableNumber.java @@ -0,0 +1,9 @@ +// https://leetcode.com/problems/find-the-maximum-achievable-number +// T: O(1) +// S: O(1) + +public class FindTheMaximumAchievableNumber { + public int theMaximumAchievableX(int num, int t) { + return num + 2 * t; + } +} From 220fa26dfc31b7a191a89a7a1fc41fbfc92ef2f5 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 12 Aug 2023 15:18:41 +0200 Subject: [PATCH 134/280] solves #2778: Sum of Squares of Special Elements in java --- README.txt | 2 +- src/SumOfSquaresOfSpecialElements.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/SumOfSquaresOfSpecialElements.java diff --git a/README.txt b/README.txt index 34683f2..948393a 100644 --- a/README.txt +++ b/README.txt @@ -838,7 +838,7 @@ | 2760 | [Longest Even Odd Subarray With Threshold](https://leetcode.com/problems/longest-even-odd-subarray-with-threshold) | [![Java](assets/java.png)](src/LongestEvenOddSubarrayWithThreshold.java) | | | 2765 | [Longest Alternating Subarray](https://leetcode.com/problems/longest-alternating-subarray) | [![Java](assets/java.png)](src/LongestAlternatingSubarray.java) | | | 2769 | [Find the Maximum Achievable Number](https://leetcode.com/problems/find-the-maximum-achievable-number) | [![Java](assets/java.png)](src/FindTheMaximumAchievableNumber.java) | | -| 2778 | [Sum of Squares of Special Elements](https://leetcode.com/problems/sum-of-squares-of-special-elements) | | | +| 2778 | [Sum of Squares of Special Elements](https://leetcode.com/problems/sum-of-squares-of-special-elements) | [![Java](assets/java.png)](src/SumOfSquaresOfSpecialElements.java) | | | 2784 | [Check if Array is Good](https://leetcode.com/problems/check-if-array-is-good) | | | | 2788 | [Split Strings by Separator](https://leetcode.com/problems/split-strings-by-separator) | | | | 2798 | [Number of Employees Who Met the Target](https://leetcode.com/problems/number-of-employees-who-met-the-target) | | | diff --git a/src/SumOfSquaresOfSpecialElements.java b/src/SumOfSquaresOfSpecialElements.java new file mode 100644 index 0000000..b8059c6 --- /dev/null +++ b/src/SumOfSquaresOfSpecialElements.java @@ -0,0 +1,15 @@ +// https://leetcode.com/problems/sum-of-squares-of-special-elements +// T: O(N) +// S: O(1) + +public class SumOfSquaresOfSpecialElements { + public int sumOfSquares(int[] nums) { + int result = 0; + for (int i = 0 ; i < nums.length ; i++) { + if (nums.length % (i + 1) == 0) { + result += nums[i] * nums[i]; + } + } + return result; + } +} From ac819312a0f5238a15a78b2f84adae7e068b5cef Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 12 Aug 2023 15:27:23 +0200 Subject: [PATCH 135/280] solves #2784: Check if Array is Good in java --- README.txt | 2 +- src/CheckIfArrayIsGood.java | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/CheckIfArrayIsGood.java diff --git a/README.txt b/README.txt index 948393a..c75f951 100644 --- a/README.txt +++ b/README.txt @@ -839,7 +839,7 @@ | 2765 | [Longest Alternating Subarray](https://leetcode.com/problems/longest-alternating-subarray) | [![Java](assets/java.png)](src/LongestAlternatingSubarray.java) | | | 2769 | [Find the Maximum Achievable Number](https://leetcode.com/problems/find-the-maximum-achievable-number) | [![Java](assets/java.png)](src/FindTheMaximumAchievableNumber.java) | | | 2778 | [Sum of Squares of Special Elements](https://leetcode.com/problems/sum-of-squares-of-special-elements) | [![Java](assets/java.png)](src/SumOfSquaresOfSpecialElements.java) | | -| 2784 | [Check if Array is Good](https://leetcode.com/problems/check-if-array-is-good) | | | +| 2784 | [Check if Array is Good](https://leetcode.com/problems/check-if-array-is-good) | [![Java](assets/java.png)](src/CheckIfArrayIsGood.java) | | | 2788 | [Split Strings by Separator](https://leetcode.com/problems/split-strings-by-separator) | | | | 2798 | [Number of Employees Who Met the Target](https://leetcode.com/problems/number-of-employees-who-met-the-target) | | | | 2806 | [Account Balance After Rounded Purchase](https://leetcode.com/problems/account-balance-after-rounded-purchase) | | | diff --git a/src/CheckIfArrayIsGood.java b/src/CheckIfArrayIsGood.java new file mode 100644 index 0000000..f7d3140 --- /dev/null +++ b/src/CheckIfArrayIsGood.java @@ -0,0 +1,26 @@ +// https://leetcode.com/problems/check-if-array-is-good +// T: O(N) +// S: O(N) + +import java.util.HashMap; +import java.util.Map; + +public class CheckIfArrayIsGood { + public boolean isGood(int[] array) { + final Map frequencies = getFrequencies(array); + for (int i = 1 ; i < array.length - 1 ; i++) { + if (frequencies.getOrDefault(i, 0) != 1) { + return false; + } + } + return frequencies.getOrDefault(array.length - 1, 0) == 2; + } + + private Map getFrequencies(int[] array) { + final Map result = new HashMap<>(); + for (int element : array) { + result.put(element, result.getOrDefault(element, 0) + 1); + } + return result; + } +} From 702fac74b83e85040dd7bf7fa6bb00d7af71af28 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 12 Aug 2023 15:46:26 +0200 Subject: [PATCH 136/280] solves #2788: Split Strings by Separator in java --- README.txt | 2 +- src/HelloWorld.java | 14 +++++------ src/SplitStringsBySeparator.java | 40 ++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 src/SplitStringsBySeparator.java diff --git a/README.txt b/README.txt index c75f951..b79a7a3 100644 --- a/README.txt +++ b/README.txt @@ -840,7 +840,7 @@ | 2769 | [Find the Maximum Achievable Number](https://leetcode.com/problems/find-the-maximum-achievable-number) | [![Java](assets/java.png)](src/FindTheMaximumAchievableNumber.java) | | | 2778 | [Sum of Squares of Special Elements](https://leetcode.com/problems/sum-of-squares-of-special-elements) | [![Java](assets/java.png)](src/SumOfSquaresOfSpecialElements.java) | | | 2784 | [Check if Array is Good](https://leetcode.com/problems/check-if-array-is-good) | [![Java](assets/java.png)](src/CheckIfArrayIsGood.java) | | -| 2788 | [Split Strings by Separator](https://leetcode.com/problems/split-strings-by-separator) | | | +| 2788 | [Split Strings by Separator](https://leetcode.com/problems/split-strings-by-separator) | [![Java](assets/java.png)](src/SplitStringsBySeparator.java) | | | 2798 | [Number of Employees Who Met the Target](https://leetcode.com/problems/number-of-employees-who-met-the-target) | | | | 2806 | [Account Balance After Rounded Purchase](https://leetcode.com/problems/account-balance-after-rounded-purchase) | | | | 2810 | [Faulty Keyboard](https://leetcode.com/problems/faulty-keyboard) | | | \ No newline at end of file diff --git a/src/HelloWorld.java b/src/HelloWorld.java index fce5a54..1f44d58 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -1,13 +1,13 @@ -import java.util.PriorityQueue; -import java.util.Queue; +import java.util.*; public class HelloWorld { public static void main(String[] args) { - final Queue queue = new PriorityQueue<>(); - queue.add(10); - queue.add(4); - queue.add(-2); + final List words = new ArrayList<>(); + words.add("apple.ball.cat"); + words.add("apple.ball.cat.dog"); - System.out.println(queue.peek()); + final String word = "apple.ball.cat.dog"; + + System.out.println(Arrays.toString(word.split("/."))); } } diff --git a/src/SplitStringsBySeparator.java b/src/SplitStringsBySeparator.java new file mode 100644 index 0000000..5531ff7 --- /dev/null +++ b/src/SplitStringsBySeparator.java @@ -0,0 +1,40 @@ +// https://leetcode.com/problems/split-strings-by-separator +// W: number of words +// s: string in words +// T: O(W * |s|) +// S: O(W * |s|) + +import java.util.ArrayList; +import java.util.List; + +public class SplitStringsBySeparator { + public List splitWordsBySeparator(List words, char separator) { + final List result = new ArrayList<>(); + for (String word : words) { + final List splitStrings = split(word, separator); + for (String split : splitStrings) { + if (!split.isEmpty()) { + result.add(split); + } + } + } + return result; + } + + private List split(String string, char separator) { + final List result = new ArrayList<>(); + StringBuilder builder = new StringBuilder(); + for (int i = 0 ; i < string.length() ; i++) { + if (string.charAt(i) == separator) { + result.add(builder.toString()); + builder = new StringBuilder(); + } else { + builder.append(string.charAt(i)); + } + } + if (!builder.isEmpty()) { + result.add(builder.toString()); + } + return result; + } +} From 7d204ca10d17f7e410e66f9a3007316500e9ade4 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 14 Aug 2023 08:40:58 +0200 Subject: [PATCH 137/280] adds readme.md --- README.md | 846 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 846 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..b79a7a3 --- /dev/null +++ b/README.md @@ -0,0 +1,846 @@ +# LeetCode Algorithms + +![problems-solved](https://img.shields.io/badge/Problems%20Solved-682/2813-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-674/2813-1abc9c.svg) +![problems-solved-python](https://img.shields.io/badge/Python-205/2813-1abc9c.svg) +![problems-solved-javascript](https://img.shields.io/badge/JavaScript-4/2813-1abc9c.svg) +[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md) +[![cp](https://img.shields.io/badge/also%20see-Competitve%20Programming-1f72ff.svg)](https://github.com/anishLearnsToCode/competitive-programming) + +🔒 = Subscription Content + +## Problems +| # | Name | Solution | Youtube | +|:----:|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:---------------------------------------------------------------------------------------------------------------------------------:| +| 1 | [Two Sum](https://leetcode.com/problems/two-sum) | [![Java](assets/java.png)](src/TwoSum.java) [![Python](assets/python.png)](python/two_sum.py) | [![java-yt](assets/java-yt.png)](https://youtu.be/9wSL_7NN-A8) [![python-yt](assets/python-yt.png)](https://youtu.be/N5FXCTg0TDE) | +| 2 | [Add Two Numbers](https://leetcode.com/problems/add-two-numbers) | [![Java](assets/java.png)](src/AddTwoNumbers.java) [![js](assets/javascript.png)](javascript/AddTwoNumbers.js) | | +| 3 | [Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters) | [![Java](assets/java.png)](src/LongestSubstringWithoutRepeatingCharacters.java) | | +| 5 | [Longest Palindromic Substring](https://leetcode.com/problems/longest-palindromic-substring) | [![Java](assets/java.png)](src/LongestPalindromicSubstring.java) | | +| 6 | [Zigzag Conversion](https://leetcode.com/problems/zigzag-conversion) | [![Java](assets/java.png)](src/ZigZagConversion.java) | | +| 7 | [Reverse Integer](https://leetcode.com/problems/reverse-integer) | [![Java](assets/java.png)](src/ReverseInteger.java) [![Python](assets/python.png)](python/reverse_integer.py) [![js](assets/javascript.png)](javascript/ReverseInteger.js) | [![java-yt](assets/java-yt.png)](https://youtu.be/7bOhyl5lWjI) [![python-yt](assets/python-yt.png)](https://youtu.be/lmLG30TLcSg) | +| 8 | [String to Integer (atoi)](https://leetcode.com/problems/string-to-integer-atoi) | [![Java](assets/java.png)](src/StringToIntegerAtoi.java) | | +| 9 | [Palindrome Number](https://leetcode.com/problems/palindrome-number) | [![Java](assets/java.png)](src/PalindromeNumber.java) [![Python](assets/python.png)](python/palindrome_number.py) [![js](assets/javascript.png)](javascript/PalindromeNumber.js) | | +| 11 | [Container With Most Water](https://leetcode.com/problems/container-with-most-water) | [![Java](assets/java.png)](src/ContainerWitMostWater.java) | | +| 12 | [Integer to Roman](https://leetcode.com/problems/integer-to-roman) | [![Java](assets/java.png)](src/IntegerToRoman.java) | | +| 13 | [Roman To Integer](https://leetcode.com/problems/roman-to-integer/) | [![Java](assets/java.png)](src/RomanToInteger.java) [![Python](assets/python.png)](python/roman_to_integer.py) | [![java-yt](assets/java-yt.png)](https://youtu.be/BCue_mO_81A) [![python-yt](assets/python-yt.png)](https://youtu.be/8h_yGTNvKMA) | +| 14 | [Longest Common Prefix](https://leetcode.com/problems/longest-common-prefix/) | [![Java](assets/java.png)](src/LongestCommonPrefix.java) [![Python](assets/python.png)](python/longest_common_prefix.py) | | +| 15 | [3Sum](https://leetcode.com/problems/3sum) | [![Java](assets/java.png)](src/ThreeSum.java) | | +| 16 | [3Sum Closest](https://leetcode.com/problems/3sum-closest) | [![Java](assets/java.png)](src/ThreeSumClosest.java) | | +| 17 | [Letter Combinations of a Phone Number](https://leetcode.com/problems/letter-combinations-of-a-phone-number) | [![Java](assets/java.png)](src/LetterCombinationsOfAPhoneNumber.java) | | +| 18 | [4Sum](https://leetcode.com/problems/4sum) | [![Java](assets/java.png)](src/FourSum.java) | | +| 19 | [Remove Nth Node From End of List](https://leetcode.com/problems/remove-nth-node-from-end-of-list) | [![Java](assets/java.png)](src/RemoveNthNodeFromEndOfList.java) | | +| 20 | [ValidParentheses](https://leetcode.com/problems/valid-parentheses/) | [![Java](assets/java.png)](src/ValidParentheses.java) [![Python](assets/python.png)](python/valid_parentheses.py) | | +| 21 | [Merge 2 Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/) | [![Java](assets/java.png)](src/Merge2SortedLists.java) [![Python](assets/python.png)](python/merge_2_sorted_lists.py) | | +| 22 | [Generate Parentheses](https://leetcode.com/problems/generate-parentheses) | [![Java](assets/java.png)](src/GenerateParentheses.java) | | +| 24 | [Swap Nodes in Pairs](https://leetcode.com/problems/swap-nodes-in-pairs) | [![Java](assets/java.png)](src/SwapNodesInPairs.java) | | +| 26 | [Remove Duplicates From Sorted Array](https://leetcode.com/problems/remove-duplicates-from-sorted-array) | [![Java](assets/java.png)](src/RemoveDuplicatesFromSortedArray.java) [![Python](assets/python.png)](python/remove_duplicates_from_sorted_array.py) [![js](assets/javascript.png)](javascript/RemoveDuplicatesFromSortedArray.js) | | +| 27 | [Remove Element](https://leetcode.com/problems/remove-element/) | [![Java](assets/java.png)](src/RemoveElement.java) [![Python](assets/python.png)](python/remove_element.py) | | +| 28 | [Needle in Haystack](https://leetcode.com/problems/implement-strstr) | [![Java](assets/java.png)](src/NeedleInHaystack.java) [![Python](assets/python.png)](python/needle_in_haystack.py) | | +| 29 | [Divide Two Integers](https://leetcode.com/problems/divide-two-integers) | [![Java](assets/java.png)](src/DivideTwoIntegers.java) | | +| 31 | [Next Permutation](https://leetcode.com/problems/next-permutation) | [![Java](assets/java.png)](src/NextPermutation.java) | | +| 33 | [Search in Rotated Sorted Array](https://leetcode.com/problems/search-in-rotated-sorted-array) | [![Java](assets/java.png)](src/SearchInRotatedSortedArray.java) | | +| 34 | [Find First and Last Position of Element in Sorted Array](https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array) | [![Java](assets/java.png)](src/FindFirstAndLastPositionOfElementInSortedArray.java) | | +| 35 | [Search Inserted Position](https://leetcode.com/problems/search-insert-position/) | [![Java](assets/java.png)](src/SearchInsertPosition.java) [![Python](assets/python.png)](python/search_insert_position.py) | | +| 36 | [Valid Sudoku](https://leetcode.com/problems/valid-sudoku) | [![Java](assets/java.png)](src/ValidSudoku.java) | | +| 37 | [Sudoku Solver](https://leetcode.com/problems/sudoku-solver) | [![Java](assets/java.png)](src/SudokuSolver.java) | | +| 38 | [Count and Say](https://leetcode.com/problems/count-and-say) | [![Java](assets/java.png)](src/CountAndSay.java) [![Python](assets/python.png)](python/count_and_say.py) | | +| 39 | [Combination Sum](https://leetcode.com/problems/combination-sum) | [![Java](assets/java.png)](src/CombinationSum.java) | | +| 40 | [Combination Sum II](https://leetcode.com/problems/combination-sum-ii) | [![Java](assets/java.png)](src/CombinationSumII.java) | | +| 42 | [Trapping Rain Water](https://leetcode.com/problems/trapping-rain-water) | [![Java](assets/java.png)](src/TrappingRainwater.java) | | +| 43 | [Multiply Strings](https://leetcode.com/problems/multiply-strings) | [![Java](assets/java.png)](src/MultiplyStrings.java) | | +| 45 | [Jump Game II](https://leetcode.com/problems/jump-game-ii) | [![Java](assets/java.png)](src/JumpGameII.java) | | +| 46 | [Permutations](https://leetcode.com/problems/permutations) | [![Java](assets/java.png)](src/Permutations.java) | | +| 47 | [Permutations II](https://leetcode.com/problems/permutations-ii) | [![Java](assets/java.png)](src/PermutationsII.java) | | +| 48 | [Rotate Image](https://leetcode.com/problems/rotate-image) | [![Java](assets/java.png)](src/RotateImage.java) | | +| 49 | [Group Anagrams](https://leetcode.com/problems/group-anagrams) | [![Java](assets/java.png)](src/GroupAnagrams.java) | | +| 50 | [Pow(x,n)](https://leetcode.com/problems/powx-n) | [![Java](assets/java.png)](src/Powxn.java) | | +| 53 | [Maximum SubArray](https://leetcode.com/problems/maximum-subarray) | [![Java](assets/java.png)](src/MaximumSubArray.java) [![Python](assets/python.png)](python/maximum_sum_subarray.py) | | +| 54 | [Spiral Matrix](https://leetcode.com/problems/spiral-matrix) | [![Java](assets/java.png)](src/SpiralMatrix.java) | | +| 55 | [Jump Game](https://leetcode.com/problems/jump-game) | [![Java](assets/java.png)](src/JumpGame.java) | | +| 56 | [Merge Intervals](https://leetcode.com/problems/merge-intervals) | [![Java](assets/java.png)](src/MergeIntervals.java) | | +| 57 | [Insert Interval](https://leetcode.com/problems/insert-interval) | [![Java](assets/java.png)](src/InsertInterval.java) | | +| 58 | [Length of Last Word](https://leetcode.com/problems/length-of-last-word) | [![Java](assets/java.png)](src/LengthOfLastWord.java) [![Python](assets/python.png)](python/length_of_last_word.py) | | +| 59 | [Spiral Matrix II](https://leetcode.com/problems/spiral-matrix-ii) | [![Java](assets/java.png)](src/SpiralMatrixII.java) | | +| 61 | [Rotate List](https://leetcode.com/problems/rotate-list) | [![Java](assets/java.png)](src/RotateList.java) | | +| 62 | [Unique Paths](https://leetcode.com/problems/unique-paths) | [![Java](assets/java.png)](src/UniquePaths.java) | | +| 63 | [Unique Paths II](https://leetcode.com/problems/unique-paths-ii) | [![Java](assets/java.png)](src/UniquePathII.java) | | +| 64 | [Minimum Path Sum](https://leetcode.com/problems/minimum-path-sum) | [![Java](assets/java.png)](src/MinimumPathSum.java) [![Python](assets/python.png)](python/minimum_path_sum.py) | | +| 66 | [Plus One](https://leetcode.com/problems/plus-one) | [![Java](assets/java.png)](src/PlusOne.java) [![Python](assets/python.png)](python/plus_one.py) | | +| 67 | [Add Binary](https://leetcode.com/problems/add-binary) | [![Java](assets/java.png)](src/AddBinary.java) [![Python](assets/python.png)](python/add_binary.py) | | +| 69 | [Sqrt(x)](https://leetcode.com/problems/sqrtx) | [![Java](assets/java.png)](src/Sqrtx.java) [![Python](assets/python.png)](python/sqrt.py) | | +| 70 | [Climbing Stairs](https://leetcode.com/problems/climbing-stairs) | [![Java](assets/java.png)](src/ClimbingStairs.java) [![Python](assets/python.png)](python/climbing_stairs.py) | | +| 71 | [Simplify Path](https://leetcode.com/problems/simplify-path) | [![Java](assets/java.png)](src/SimplifyPath.java) | | +| 73 | [Set Matrix Zeroes](https://leetcode.com/problems/set-matrix-zeroes) | [![Java](assets/java.png)](src/SetMatrixZeroes.java) | | +| 74 | [Search a 2D Matrix](https://leetcode.com/problems/search-a-2d-matrix) | [![Java](assets/java.png)](src/SearchA2DMatrix.java) | | +| 75 | [Sort Colors](https://leetcode.com/problems/sort-colors) | [![Java](assets/java.png)](src/SortColors.java) | | +| 77 | [Combinations](https://leetcode.com/problems/combinations) | [![Java](assets/java.png)](src/Combinations.java) | | +| 78 | [Subsets](https://leetcode.com/problems/subsets) | [![Java](assets/java.png)](src/Subsets.java) | | +| 79 | [Word Search](https://leetcode.com/problems/word-search) | [![Java](assets/java.png)](src/WordSearch.java) | | +| 80 | [Remove Duplicates from Sorted Array II](https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii) | [![Java](assets/java.png)](src/RemoveDuplicatesFromSortedArrayII.java) | | +| 81 | [Search in Rotated Sorted Array II](https://leetcode.com/problems/search-in-rotated-sorted-array-ii) | [![Java](assets/java.png)](src/SearchInRotatedSortedArrayII.java) | | +| 82 | [Remove Duplicates from Sorted List II](https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii) | [![Java](assets/java.png)](src/RemoveDuplicatesFromSortedListII.java) | | +| 83 | [Remove Duplicates from Sorted List](https://leetcode.com/problems/remove-duplicates-from-sorted-list) | [![Java](assets/java.png)](src/RemoveDuplicatesFromSortedList.java) [![Python](assets/python.png)](python/remove_duplicates_from_linked_list.py) | | +| 86 | [Partition List](https://leetcode.com/problems/partition-list) | [![Java](assets/java.png)](src/PartitionList.java) | | +| 87 | [Scramble String](https://leetcode.com/problems/scramble-string) | [![Python](assets/python.png)](python/scramble_strings.py) | | +| 88 | [Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array) | [![Java](assets/java.png)](src/MergeSortedArray.java) [![Python](assets/python.png)](python/merge_sorted_array.py) | | +| 89 | [Gray Code](https://leetcode.com/problems/gray-code) | [![Java](assets/java.png)](src/GrayCode.java) | | +| 90 | [Subsets II](https://leetcode.com/problems/subsets-ii) | [![Java](assets/java.png)](src/SubsetsII.java) | | +| 91 | [Decode Ways](https://leetcode.com/problems/decode-ways) | [![Java](assets/java.png)](src/DecodeWays.java) | | +| 92 | [Reverse Linked List II](https://leetcode.com/problems/reverse-linked-list-ii) | [![Java](assets/java.png)](src/ReverseLinkedListII.java) | | +| 93 | [Restore IP Addresses](https://leetcode.com/problems/restore-ip-addresses) | [![Java](assets/java.png)](src/RestoreIPAddresses.java) | | +| 94 | [Binary Tree Inorder Traversal](https://leetcode.com/problems/binary-tree-inorder-traversal) | [![Java](assets/java.png)](src/BinaryTreeInorderTraversal.java) [![Python](assets/python.png)](python/binary_tree_inorder_traversal.py) | | +| 95 | [Unique Binary Search Trees II](https://leetcode.com/problems/unique-binary-search-trees-ii) | [![Java](assets/java.png)](src/UniqueBinarySearchTreesII.java) | | +| 96 | [Unique Binary Search Trees](https://leetcode.com/problems/unique-binary-search-trees) | [![Java](assets/java.png)](src/UniqueBinarySearchTrees.java) | | +| 97 | [Interleaving String](https://leetcode.com/problems/interleaving-string) | [![Java](assets/java.png)](src/InterleavingString.java) | | +| 98 | [Validate Binary Search Tree](https://leetcode.com/problems/validate-binary-search-tree) | [![Java](assets/java.png)](src/ValidateBinarySearchTree.java) | | +| 99 | [Recover Binary Search Tree](https://leetcode.com/problems/recover-binary-search-tree) | [![Java](assets/java.png)](src/RecoverBinarySearchTree.java) | | +| 100 | [Same Tree](https://leetcode.com/problems/same-tree) | [![Java](assets/java.png)](src/SameTree.java) [![Python](assets/python.png)](python/same_tree.py) | | +| 101 | [Symmetric Tree](https://leetcode.com/problems/symmetric-tree) | [![Java](assets/java.png)](src/SymmetricTree.java) [![Python](assets/python.png)](python/symmetric_tree.py) | | +| 102 | [Binary Tree Level Order Traversal](https://leetcode.com/problems/binary-tree-level-order-traversal) | [![Java](assets/java.png)](src/BinaryTreeLevelOrderTraversal.java) | | +| 103 | [Binary Tree Zigzag Level Order Traversal](https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal) | [![Java](assets/java.png)](src/BinaryTreeZigzagLevelOrderTraversal.java) | | +| 104 | [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree) | [![Java](assets/java.png)](src/MaximumDepthOfBinaryTree.java) [![Python](assets/python.png)](python/maximum_depth_of_binary_tree.py) | | +| 105 | [Construct Binary Tree from Preorder and Inorder Traversal](https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal) | [![Java](assets/java.png)](src/ConstructBinaryTreeFromPreorderAndInorderTraversal.java) | | +| 106 | [Construct Binary Tree from Inorder and Postorder Traversal](https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal) | [![Java](assets/java.png)](src/ConstructBinaryTreeFromInorderAndPostorderTraversal.java) | | +| 107 | [Binary Tree Level Order Traversal II](https://leetcode.com/problems/binary-tree-level-order-traversal-ii) | [![Java](assets/java.png)](src/BinaryTreeLevelOrderTraversalII.java) [![Python](assets/python.png)](python/binary_tree_level_order_traversal_ii.py) | | +| 108 | [Convert Sorted Array To Binary Search Tree](https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree) | [![Java](assets/java.png)](src/ConvertSortedArrayToBinarySearchTree.java) [![Python](assets/python.png)](python/converted_sorted_array_to_binary_search_tree.py) | | +| 109 | [Convert Sorted List to Binary Search Tree](https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree) | [![Java](assets/java.png)](src/ConvertSortedListToBinarySearchTree.java) | | +| 110 | [Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree) | [![Java](assets/java.png)](src/BalancedBinaryTree.java) [![Python](assets/python.png)](python/balanced_binary_tree.py) | | +| 111 | [Minimum Depth of Binary Tree](https://leetcode.com/problems/minimum-depth-of-binary-tree) | [![Java](assets/java.png)](src/MinimumDepthOfBinaryTree.java) [![Python](assets/python.png)](python/minimum_depth_of_binary_tree.py) | | +| 112 | [Path Sum](https://leetcode.com/problems/path-sum) | [![Java](assets/java.png)](src/PathSum.java) [![Python](assets/python.png)](python/path_sum.py) | | +| 113 | [Path Sum II](https://leetcode.com/problems/path-sum-ii) | [![Java](assets/java.png)](src/PathSumII.java) | | +| 114 | [Flatten Binary Tree to Linked List](https://leetcode.com/problems/flatten-binary-tree-to-linked-list) | [![Java](assets/java.png)](src/FlattenBinaryTreeToLinkedList.java) | | +| 116 | [Populating Next Right Pointers in Each Node](https://leetcode.com/problems/populating-next-right-pointers-in-each-node) | [![Java](assets/java.png)](src/PopulatingNextRightPointersInEachNode.java) | | +| 117 | [Populating Next Right Pointers in Each Node II](https://leetcode.com/problems/populating-next-right-pointers-in-each-node-ii) | [![Java](assets/java.png)](src/PopulatingNextRightPointersInEachNodeII.java) | | +| 118 | [Pascal's Triangle](https://leetcode.com/problems/pascals-triangle) | [![Java](assets/java.png)](src/PascalsTriangle.java) [![Python](assets/python.png)](python/pascals_triangle.py) | | +| 119 | [Pascal's Triangle II](https://leetcode.com/problems/pascals-triangle-ii) | [![Java](assets/java.png)](src/PascalsTriangleII.java) [![Python](assets/python.png)](python/pascals_triangle_ii.py) | | +| 120 | [Triangle](https://leetcode.com/problems/triangle) | [![Java](assets/java.png)](src/Triangle.java) | | +| 121 | [Best Time to Buy and Sell Stocks](https://leetcode.com/problems/best-time-to-buy-and-sell-stock) | [![Java](assets/java.png)](src/BestTimeToBuyAndSellStock.java) [![Python](assets/python.png)](python/best_time_to_buy_and_sell_stock.py) | | +| 122 | [Best Time to Buy and Sell Stocks II](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii) | [![Java](assets/java.png)](src/BestTimeToBuyAndSellStockII.java) [![Python](assets/python.png)](python/best_time_to_buy_and_sell_stock_ii.py) | | +| 125 | [Valid Palindrome](https://leetcode.com/problems/valid-palindrome) | [![Java](assets/java.png)](src/ValidPalindrome.java) [![Python](assets/python.png)](python/valid_palindrome.py) | | +| 128 | [Longest Consecutive Sequence](https://leetcode.com/problems/longest-consecutive-sequence) | [![Java](assets/java.png)](src/LongestConsecutiveSequence.java) | | +| 129 | [Sum Root to Leaf Numbers](https://leetcode.com/problems/sum-root-to-leaf-numbers) | [![Java](assets/java.png)](src/SumRootToLeafNumbers.java) | | +| 130 | [Surrounded Regions](https://leetcode.com/problems/surrounded-regions) | [![Java](assets/java.png)](src/SurroundedRegions.java) | | +| 131 | [Palindrome Partitioning](https://leetcode.com/problems/palindrome-partitioning) | [![Java](assets/java.png)](src/PalindromePartitioning.java) | | +| 133 | [Clone Graph](https://leetcode.com/problems/clone-graph) | [![Java](assets/java.png)](src/CloneGraph.java) [![Python](assets/python.png)](python/clone_graph.py) | | +| 134 | [Gas Station](https://leetcode.com/problems/gas-station) | [![Java](assets/java.png)](src/GasStation.java) | | +| 136 | [Single Number](https://leetcode.com/problems/single-number) | [![Java](assets/java.png)](src/SingleNumber.java) [![Python](assets/python.png)](python/single_number.py) | | +| 137 | [Single Number II](https://leetcode.com/problems/single-number-ii) | [![Java](assets/java.png)](src/SingleNumberII.java) | | +| 138 | [Copy List with Random Pointer](https://leetcode.com/problems/copy-list-with-random-pointer) | [![Java](assets/java.png)](src/CopyListWithRandomPointer.java) | | +| 139 | [Word Break](https://leetcode.com/problems/word-break) | [![Java](assets/java.png)](src/WordBreak.java) | | +| 141 | [Linked List Cycle](https://leetcode.com/problems/linked-list-cycle) | [![Java](assets/java.png)](src/LinkedListCycle.java) [![Python](assets/python.png)](python/linked_list_cycle.py) | | +| 142 | [Linked List Cycle II](https://leetcode.com/problems/linked-list-cycle-ii) | [![Java](assets/java.png)](src/LinkedListCycleII.java) | | +| 143 | [Reorder List](https://leetcode.com/problems/reorder-list) | [![Java](assets/java.png)](src/ReorderList.java) | | +| 144 | [Binary Tree Preorder Traversal](https://leetcode.com/problems/binary-tree-preorder-traversal) | [![Java](assets/java.png)](src/BinaryTreePreOrderTraversal.java) [![Python](assets/python.png)](python/binary_tree_preorder_traversal.py) | | +| 145 | [Binary Tree Postorder Traversal](https://leetcode.com/problems/binary-tree-postorder-traversal) | [![Java](assets/java.png)](src/BinaryTreePostorderTraversal.java) [![Python](assets/python.png)](python/binary_tree_postorder_traversal.py) | | +| 146 | [LRU Cache](https://leetcode.com/problems/lru-cache) | [![Java](assets/java.png)](src/LRUCache.java) | | +| 147 | [Insertion Sort List](https://leetcode.com/problems/insertion-sort-list) | [![Java](assets/java.png)](src/InsertionSortList.java) | | +| 148 | [Sort List](https://leetcode.com/problems/sort-list) | [![Java](assets/java.png)](src/SortList.java) | | +| 150 | [Evaluate Reverse Polish Notation](https://leetcode.com/problems/evaluate-reverse-polish-notation) | [![Java](assets/java.png)](src/EvaluateReversePolishNotation.java) | | +| 151 | [Reverse Words in a String](https://leetcode.com/problems/reverse-words-in-a-string) | [![Java](assets/java.png)](src/ReverseWordsInAString.java) | | +| 152 | [Maximum Product Subarray](https://leetcode.com/problems/maximum-product-subarray) | [![Java](assets/java.png)](src/MaximumProductSubarray.java) | | +| 153 | [Find Minimum in Rotated Sorted Array](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array) | [![Java](assets/java.png)](src/FindMinimumInRotatedSortedArray.java) | | +| 155 | [Min Stack](https://leetcode.com/problems/min-stack) | [![Java](assets/java.png)](src/MinStack.java) [![Python](assets/python.png)](python/min_stack.py) | | +| 156 | 🔒 [Binary Tree Upside Down](https://leetcode.com/problems/binary-tree-upside-down) | | | +| 157 | [Read N Characters Given Read4](https://leetcode.com/problems/read-n-characters-given-read4) | | | +| 159 | 🔒 [Longest Substring With At Most Two Distinct Characters](https://leetcode.com/problems/longest-substring-with-at-most-two-distinct-characters) | | | +| 160 | [Intersection of Two Linked Lists](https://leetcode.com/problems/intersection-of-two-linked-lists) | [![Java](assets/java.png)](src/IntersectionOf2LinkedLists.java) [![Python](assets/python.png)](python/intersecction_of_two_linked_lists.py) | | +| 161 | 🔒 [One Edit Distance](https://leetcode.com/problems/one-edit-distance) | | | +| 162 | [Find Peak Element](https://leetcode.com/problems/find-peak-element) | [![Java](assets/java.png)](src/FindPeakElement.java) | | +| 165 | [Compare Version Numbers](https://leetcode.com/problems/compare-version-numbers) | [![Java](assets/java.png)](src/CompareVersionNumbers.java) | | +| 166 | [Fraction to Recurring Decimal](https://leetcode.com/problems/fraction-to-recurring-decimal) | [![Java](assets/java.png)](src/FractionToRecurringDecimal.java) | | +| 167 | [Two Sum II - Input Array is Sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted) | [![Java](assets/java.png)](src/TwoSumIIInputArrayIsSorted.java) [![Python](assets/python.png)](python/two_sum_ii.py) | | +| 168 | [Excel Sheet Column Title](https://leetcode.com/problems/excel-sheet-column-title) | [![Java](assets/java.png)](src/ExcelSheetColumnTitle.java) [![Python](assets/python.png)](python/excel_sheet_column_title.py) | | +| 169 | [Majority Element](https://leetcode.com/problems/majority-element) | [![Java](assets/java.png)](src/MajorityElement.java) [![Python](assets/python.png)](python/majority_element.py) | | +| 170 | 🔒 [Two Sum III - Data Structure Design](https://leetcode.com/problems/two-sum-iii-data-structure-design) | | | +| 171 | [Excel Sheet Column Number](https://leetcode.com/problems/excel-sheet-column-number) | [![Java](assets/java.png)](src/ExcelSheetColumnNumber.java) [![Python](assets/python.png)](python/excel_sheet_column_number.py) | | +| 172 | [Factoring Trailing Zeroes](https://leetcode.com/problems/factorial-trailing-zeroes) | [![Java](assets/java.png)](src/FactorialTrailingZeros.java) [![Python](assets/python.png)](python/factorial_trailing_zeroes.py) | | +| 173 | [Binary Search Tree Iterator](https://leetcode.com/problems/binary-search-tree-iterator) | [![Java](assets/java.png)](src/BinarySearchTreeIterator.java) | | +| 179 | [Largest Number](https://leetcode.com/problems/largest-number) | [![Java](assets/java.png)](src/LargestNumber.java) | | +| 187 | [Repeated DNA Sequences](https://leetcode.com/problems/repeated-dna-sequences) | [![Java](assets/java.png)](src/RepeatedDNASequences.java) | | +| 189 | [Rotate Array](https://leetcode.com/problems/rotate-array) | [![Java](assets/java.png)](src/RotateArray.java) [![Python](assets/python.png)](python/rotate_array.py) | | +| 190 | [Reverse Bits](https://leetcode.com/problems/reverse-bits) | [![Java](assets/java.png)](src/ReverseBits.java) [![Python](assets/python.png)](python/reverse_bits.py) | | +| 191 | [Number of One Bits](https://leetcode.com/problems/number-of-1-bits) | [![Java](assets/java.png)](src/NumberOf1Bit.java) [![Python](assets/python.png)](python/number_of_1_bits.py) | | +| 198 | [House Robber](https://leetcode.com/problems/house-robber) | [![Java](assets/java.png)](src/HouseRobber.java) [![Python](assets/python.png)](python/house_robber.py) | | +| 199 | [Binary Tree Right Side View](https://leetcode.com/problems/binary-tree-right-side-view) | [![Java](assets/java.png)](src/BinaryTreeRightSideView.java) | | +| 200 | [Number of Islands](https://leetcode.com/problems/number-of-islands) | [![Java](assets/java.png)](src/NumberOfIslands.java) [![Python](assets/python.png)](python/number_of_islands.py) | | +| 201 | [Bitwise AND of Numbers Range](https://leetcode.com/problems/bitwise-and-of-numbers-range) | [![Java](assets/java.png)](src/BitwiseANDOfNumbersRange.java) | | +| 202 | [Happy Number](https://leetcode.com/problems/happy-number) | [![Java](assets/java.png)](src/HappyNumber.java) [![Python](assets/python.png)](python/happy_number.py) | | +| 203 | [Remove Linked List Elements](https://leetcode.com/problems/remove-linked-list-elements) | [![Java](assets/java.png)](src/RemoveLinkedListElements.java) [![Python](assets/python.png)](python/remove_linked_list_elements.py) | | +| 204 | [Count Primes](https://leetcode.com/problems/count-primes) | [![Java](assets/java.png)](src/CountPrimes.java) [![Python](assets/python.png)](python/count_primes.py) | | +| 205 | [Isomorphic Strings](https://leetcode.com/problems/isomorphic-strings) | [![Java](assets/java.png)](src/IsomorphicStrings.java) [![Python](assets/python.png)](python/isomorphic_strings.py) | | +| 206 | [Reverse Linked List](https://leetcode.com/problems/reverse-linked-list) | [![Java](assets/java.png)](src/ReverseLinkedList.java) [![Python](assets/python.png)](python/reverse_linked_list.py) | | +| 207 | [Course Schedule](https://leetcode.com/problems/course-schedule) | [![Java](assets/java.png)](src/CourseSchedule.java) | | +| 208 | [Implement Trie (Prefix Tree)](https://leetcode.com/problems/implement-trie-prefix-tree) | [![Java](assets/java.png)](src/Trie.java) [![Python](assets/python.png)](python/trie.py) | | +| 209 | [Minimum Size Subarray Sum](https://leetcode.com/problems/minimum-size-subarray-sum) | [![Java](assets/java.png)](src/MinimumSizeSubarraySum.java) | | +| 210 | [Course Schedule II](https://leetcode.com/problems/course-schedule-ii) | [![Java](assets/java.png)](src/CourseScheduleII.java) | | +| 211 | [Design Add and Search Words Data Structure](https://leetcode.com/problems/design-add-and-search-words-data-structure) | [![Java](assets/java.png)](src/DesignAddAndSearchWordsDataStructure.java) [![Python](assets/python.png)](python/design_add_and_search_words_data_structure.py) | | +| 213 | [House Robber II](https://leetcode.com/problems/house-robber-ii) | [![Java](assets/java.png)](src/HouseRobberII.java) | | +| 215 | [Kth Largest Element in an Array](https://leetcode.com/problems/kth-largest-element-in-an-array) | [![Java](assets/java.png)](src/KthLargestElementInAnArray.java) | | +| 216 | [Combination Sum III](https://leetcode.com/problems/combination-sum-iii) | [![Java](assets/java.png)](src/CombinationSumIII.java) | | +| 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate) | [![Java](assets/java.png)](src/ContainsDuplicate.java) [![Python](assets/python.png)](python/contains_duplicate.py) | | +| 218 | [The Skyline Problem](https://leetcode.com/problems/the-skyline-problem) | [![Python](assets/python.png)](python/the_skyline_problem.py) | | +| 219 | [Contains Duplicate II](https://leetcode.com/problems/contains-duplicate-ii) | [![Java](assets/java.png)](src/ContainsDuplicateII.java) [![Python](assets/python.png)](python/contains_duplicate_ii.py) | | +| 220 | [Contains Duplicate III](https://leetcode.com/problems/contains-duplicate-iii) | [![Java](assets/java.png)](src/ContainsDuplicateIII.java) | | +| 221 | [Maximal Square](https://leetcode.com/problems/maximal-square) | [![Java](assets/java.png)](src/MaximalSquare.java) | | +| 222 | [Count Complete Tree Nodes](https://leetcode.com/problems/count-complete-tree-nodes) | [![Java](assets/java.png)](src/CountCompleteTreeNodes.java) | | +| 223 | [Rectangle Area](https://leetcode.com/problems/rectangle-area) | [![Java](assets/java.png)](src/RectangleArea.java) | | +| 225 | [Implement Stack using Queues](https://leetcode.com/problems/implement-stack-using-queues) | [![Java](assets/java.png)](src/MyStack.java) [![Python](assets/python.png)](python/implement_stack_using_queues.py) | | +| 226 | [Invert Binary Tree](https://leetcode.com/problems/invert-binary-tree) | [![Java](assets/java.png)](src/InvertBinaryTree.java) [![Python](assets/python.png)](python/invert_binary_tree.py) | | +| 227 | [Basic Calculator II](https://leetcode.com/problems/basic-calculator-ii) | [![Java](assets/java.png)](src/BasicCalculatorII.java) | | +| 229 | [Majority Element II](https://leetcode.com/problems/majority-element-ii) | [![Java](assets/java.png)](src/MajorityElementII.java) | | +| 230 | [Kth Smallest Element in a BST](https://leetcode.com/problems/kth-smallest-element-in-a-bst) | [![Java](assets/java.png)](src/KthSmallestElementInABST.java) | | +| 231 | [Power of Two](https://leetcode.com/problems/power-of-two) | [![Java](assets/java.png)](src/PowerOf2.java) [![Python](assets/python.png)](python/is_power_of_2.py) | | +| 232 | [Implement Queue Using Stacks](https://leetcode.com/problems/implement-queue-using-stacks) | [![Java](assets/java.png)](src/MyQueue.java) [![Python](assets/python.png)](python/implement_queue_using_stacks.py) | | +| 234 | [Palindrome Linked Lists](https://leetcode.com/problems/palindrome-linked-list) | [![Java](assets/java.png)](src/PalindromeLinkedList.java) [![Python](assets/python.png)](python/palindrome_linked_list.py) | | +| 235 | [Lowest Common Ancestor of a Binary Search Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree) | [![Java](assets/java.png)](src/LowestCommonAncestorOfBinarySearchTree.java) [![Python](assets/python.png)](python/lowest_common_ancestor_of_bst.py) | | +| 236 | [Lowest Common Ancestor of a Binary Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree) | [![Java](assets/java.png)](src/LowestCommonAncestorOfBinaryTree.java) | | +| 237 | [Delete a Node In A Linked List](https://leetcode.com/problems/delete-node-in-a-linked-list) | [![Java](assets/java.png)](src/DeleteANodeInLinkedList.java) [![Python](assets/python.png)](python/delete_node_in_linked_list.py) | | +| 238 | [Product of Array Except Self](https://leetcode.com/problems/product-of-array-except-self) | [![Java](assets/java.png)](src/ProductOfArrayExceptItself.java) | | +| 240 | [Search a 2D Matrix II](https://leetcode.com/problems/search-a-2d-matrix-ii) | [![Java](assets/java.png)](src/SearchA2DMatrixII.java) | | +| 241 | [Different Ways to Add Parentheses](https://leetcode.com/problems/different-ways-to-add-parentheses) | | | +| 242 | [Valid Anagram](https://leetcode.com/problems/valid-anagram) | [![Java](assets/java.png)](src/ValidAnagram.java) [![Python](assets/python.png)](python/delete_node_in_linked_list.py) | | +| 243 | 🔒 [Shortest Word Distance](https://leetcode.com/problems/shortest-word-distance) | | | +| 244 | 🔒 [Shortest Word Distance II](https://leetcode.com/problems/shortest-word-distance-ii) | | | +| 245 | 🔒 [Shortest Word Distance III](https://leetcode.com/problems/shortest-word-distance-iii) | | | +| 246 | 🔒 [Strobogramatic Number](https://leetcode.com/problems/strobogrammatic-number) | | | +| 247 | 🔒 [Strobogramatic Number II](https://leetcode.com/problems/strobogrammatic-number-ii) | | | +| 249 | 🔒 [Group Shifted Strings](https://leetcode.com/problems/group-shifted-strings) | | | +| 250 | 🔒 [Count Univalue Subtrees](https://leetcode.com/problems/count-univalue-subtrees) | | | +| 251 | 🔒 [Flatten 2D Vector](https://leetcode.com/problems/flatten-2d-vector) | | | +| 252 | 🔒 [Meeting Rooms](https://leetcode.com/problems/meeting-rooms) | | | +| 253 | 🔒 [Meeting Rooms II](https://leetcode.com/problems/meeting-rooms-ii) | | | +| 254 | 🔒 [Factor Combinations](https://leetcode.com/problems/factor-combinations) | | | +| 255 | 🔒 [Verify Preorder Sequence In Binary Search Tree](https://leetcode.com/problems/verify-preorder-sequence-in-binary-search-tree) | | | +| 256 | 🔒 [Paint House](https://leetcode.com/problems/paint-house) | | | +| 257 | [Binary Tree Paths](https://leetcode.com/problems/binary-tree-paths) | [![Java](assets/java.png)](src/BinaryTreePaths.java) [![Python](assets/python.png)](python/binary_tree_paths.py) | | +| 258 | [Add Digits](https://leetcode.com/problems/add-digits) | [![Java](assets/java.png)](src/AddDigits.java) [![Python](assets/python.png)](python/add_digits.py) | | +| 259 | 🔒 [3Sum Smaller](https://leetcode.com/problems/3sum-smaller) | | | +| 260 | [Single Number III](https://leetcode.com/problems/single-number-iii) | [![Java](assets/java.png)](src/SingleNumberIII.java) | | +| 261 | 🔒 [Graph Valid Tree](https://leetcode.com/problems/graph-valid-tree) | | | +| 263 | [Ugly Number](https://leetcode.com/problems/ugly-number) | [![Java](assets/java.png)](src/UglyNumber.java) [![Python](assets/python.png)](python/ugly_number.py) | | +| 264 | [Ugly Number II](https://leetcode.com/problems/ugly-number-ii) | [![Java](assets/java.png)](src/UglyNumberII.java) | | +| 266 | 🔒 [Palindrome Permutation](https://leetcode.com/problems/palindrome-permutation) | | | +| 267 | 🔒 [Palindrome Permutation II](https://leetcode.com/problems/palindrome-permutation-ii) | | | +| 268 | [Missing Number](https://leetcode.com/problems/missing-number) | [![Java](assets/java.png)](src/MissingNumber.java) [![Python](assets/python.png)](python/missing_number.py) | | +| 270 | 🔒 [Closest Binary Search Tree Value](https://leetcode.com/problems/closest-binary-search-tree-value) | | | +| 271 | 🔒 [Encode and Decode Strings](https://leetcode.com/problems/encode-and-decode-strings) | | | +| 274 | [H-Index](https://leetcode.com/problems/h-index) | [![Java](assets/java.png)](src/HIndex.java) | | +| 275 | [H-Index II](https://leetcode.com/problems/h-index-ii) | [![Java](assets/java.png)](src/HIndexII.java) | | +| 276 | 🔒 [Paint Fence](https://leetcode.com/problems/paint-fence) | | | +| 277 | 🔒 [Find The Celebrity](https://leetcode.com/problems/find-the-celebrity) | | | +| 278 | [First Bad Version](https://leetcode.com/problems/first-bad-version) | [![Java](assets/java.png)](src/FirstBadVersion.java) [![Python](assets/python.png)](python/first_bad_version.py) | | +| 279 | [Perfect Squares](https://leetcode.com/problems/perfect-squares) | [![Java](assets/java.png)](src/PerfectSquares.java) | | +| 280 | 🔒 [Wiggle Sort](https://leetcode.com/problems/wiggle-sort) | | | +| 281 | 🔒 [Zigzag Iterator](https://leetcode.com/problems/zigzag-iterator) | | | +| 283 | [Move Zeroes](https://leetcode.com/problems/move-zeroes) | [![Java](assets/java.png)](src/MoveZeros.java) [![Python](assets/python.png)](python/move_zeroes.py) | | +| 284 | [Peeking Iterator](https://leetcode.com/problems/peeking-iterator) | [![Java](assets/java.png)](src/PeekingIterator.java) | | +| 285 | 🔒 [Inorder Successor in BST](https://leetcode.com/problems/inorder-successor-in-bst) | | | +| 286 | 🔒 [Walls and Gates](https://leetcode.com/problems/walls-and-gates) | | | +| 287 | [Find the Duplicate Number](https://leetcode.com/problems/find-the-duplicate-number) | [![Java](assets/java.png)](src/FindTheDuplicateNumber.java) | | +| 288 | 🔒 [Unique Word Abbreviation](https://leetcode.com/problems/unique-word-abbreviation) | | | +| 289 | [Game of Life](https://leetcode.com/problems/game-of-life) | | | +| 290 | [Word Pattern](https://leetcode.com/problems/word-pattern) | [![Java](assets/java.png)](src/WordPattern.java) [![Python](assets/python.png)](python/word_pattern.py) | | +| 291 | 🔒 [Word Pattern II](https://leetcode.com/problems/word-pattern-ii) | | | +| 292 | [Nim Game](https://leetcode.com/problems/nim-game) | [![Java](assets/java.png)](src/NimGame.java) [![Python](assets/python.png)](python/nim_game.py) | | +| 293 | 🔒 [Flip Game](https://leetcode.com/problems/flip-game) | | | +| 294 | 🔒 [Flip Game II](https://leetcode.com/problems/flip-game-ii) | | | +| 298 | 🔒 [Binary Tree Longest Consecutive Sequence](https://leetcode.com/problems/binary-tree-longest-consecutive-sequence) | | | +| 299 | [Bulls and Cows](https://leetcode.com/problems/bulls-and-cows) | [![Java](assets/java.png)](src/BullsAndCows.java) [![Python](assets/python.png)](python/bulls_and_cows.py) | | +| 300 | [Longest Increasing Subsequence](https://leetcode.com/problems/longest-increasing-subsequence) | | | +| 303 | [Range Sum Query - Immutable](https://leetcode.com/problems/range-sum-query-immutable) | [![Java](assets/java.png)](src/RangeSumQueryImmutable.java) [![Python](assets/python.png)](python/range_sum_query_immutable.py) | | +| 304 | [Range Sum Query 2D - Immutable](https://leetcode.com/problems/range-sum-query-2d-immutable) | | | +| 306 | [Additive Number](https://leetcode.com/problems/additive-number) | | | +| 307 | [Range Sum Query - Mutable](https://leetcode.com/problems/range-sum-query-mutable) | | | +| 309 | [Best Time to Buy and Sell Stock with Cooldown](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown) | | | +| 310 | [Minimum Height Trees](https://leetcode.com/problems/minimum-height-trees) | | | +| 311 | 🔒 [Sparse Matrix Multiplication](https://leetcode.com/problems/sparse-matrix-multiplication) | | | +| 313 | [Super Ugly Number](https://leetcode.com/problems/super-ugly-number) | | | +| 314 | 🔒 [Binary Tree Vertical Order Traversal](https://leetcode.com/problems/binary-tree-vertical-order-traversal) | | | +| 316 | [Remove Duplicate Letters](https://leetcode.com/problems/remove-duplicate-letters) | | | +| 318 | [Maximum Product of Word Lengths](https://leetcode.com/problems/maximum-product-of-word-lengths) | | | +| 319 | [Bulb Switcher](https://leetcode.com/problems/bulb-switcher) | | | +| 320 | 🔒 [Generalized Abbreviation](https://leetcode.com/problems/generalized-abbreviation) | | | +| 322 | [Coin Change](https://leetcode.com/problems/coin-change) | | | +| 323 | 🔒 [Number of Connected Components in Undirected Graph](https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph) | | | +| 324 | [Wiggle Sort II](https://leetcode.com/problems/wiggle-sort-ii) | | | +| 325 | 🔒 [Maximum Size Subarray Sum Equals K](https://leetcode.com/problems/maximum-size-subarray-sum-equals-k) | | | +| 326 | [Power of Three](https://leetcode.com/problems/power-of-three) | [![Java](assets/java.png)](src/PowerOfThree.java) [![Python](assets/python.png)](python/power_of_three.py) | | +| 328 | [Odd Even Linked List](https://leetcode.com/problems/odd-even-linked-list) | | | +| 331 | [Verify Preorder Serialization of a Binary Tree](https://leetcode.com/problems/verify-preorder-serialization-of-a-binary-tree) | | | +| 331 | 🔒 [Largest BST Subtree](https://leetcode.com/problems/largest-bst-subtree) | | | +| 334 | [Increasing Triplet Subsequence](https://leetcode.com/problems/increasing-triplet-subsequence) | | | +| 337 | [House Robber III](https://leetcode.com/problems/increasing-triplet-subsequence) | | | +| 338 | [Counting Bits](https://leetcode.com/problems/counting-bits/) | [![Java](assets/java.png)](src/CountingBits.java) [![Python](assets/python.png)](python/counting_bits.py) | | +| 339 | 🔒 [Nested List Weight Sum](https://leetcode.com/problems/nested-list-weight-sum) | | | +| 340 | 🔒 [Longest Substring with At Most K Distinct Characters](https://leetcode.com/problems/longest-substring-with-at-most-k-distinct-characters) | | | +| 341 | [Flatten Nested List Iterator](https://leetcode.com/problems/flatten-nested-list-iterator) | | | +| 342 | [Power of Four](https://leetcode.com/problems/power-of-four) | [![Java](assets/java.png)](src/PowerOf4.java) [![Python](assets/python.png)](python/power_of_four.py) | | +| 343 | [Integer Break](https://leetcode.com/problems/integer-break) | | | +| 344 | [Reverse A String](https://leetcode.com/problems/reverse-string) | [![Java](assets/java.png)](src/ReverseString.java) [![Python](assets/python.png)](python/reverse_a_string.py) | | +| 345 | [Reverse Vowels of A String](https://leetcode.com/problems/reverse-vowels-of-a-string) | [![Java](assets/java.png)](src/ReverseVowelsOfString.java) [![Python](assets/python.png)](python/reverse_vowels_of_a_string.py) | | +| 346 | 🔒 [Moving Average From Data Stream](https://leetcode.com/problems/moving-average-from-data-stream) | | | +| 347 | [Top K frequent Elements](https://leetcode.com/problems/top-k-frequent-elements) | | | +| 348 | 🔒 [Design Tic-Tac-Toe](https://leetcode.com/problems/design-tic-tac-toe) | | | +| 349 | [Intersection of 2 Arrays](https://leetcode.com/problems/intersection-of-two-arrays) | [![Java](assets/java.png)](src/IntersectionOfTwoArrays.java) [![Python](assets/python.png)](python/intersection_of_2_array.py) | | +| 350 | [Intersection of 2 Arrays II](https://leetcode.com/problems/intersection-of-two-arrays-ii) | [![Java](assets/java.png)](src/IntersectionOfTwoArraysII.java) [![Python](assets/python.png)](python/intersection_of_2_arrays_II.py) | | +| 351 | 🔒 [Android Unlock Patterns](https://leetcode.com/problems/android-unlock-patterns) | | | +| 355 | [Design Twitter](https://leetcode.com/problems/design-twitter) | | | +| 357 | [Count Numbers with Unique Digits](https://leetcode.com/problems/count-numbers-with-unique-digits) | | | +| 359 | 🔒 [Logger Rate Limiter](https://leetcode.com/problems/logger-rate-limiter) | | | +| 367 | [Valid Perfect Square](https://leetcode.com/problems/valid-perfect-square) | [![Java](assets/java.png)](src/IsPerfectSquare.java) [![Python](assets/python.png)](python/valid_perfect_square.py) | | +| 374 | [Guess Number Higher or Lower](https://leetcode.com/problems/guess-number-higher-or-lower) | [![Java](assets/java.png)](src/GuessNumberHigherOrLower.java) [![Python](assets/python.png)](python/guess_number_higher_or_lower.py) | | +| 383 | [Ransom Note](https://leetcode.com/problems/ransom-note) | [![Java](assets/java.png)](src/RansomNote.java) [![Python](assets/python.png)](python/ransom_note.py) | | +| 387 | [First Unique Character in String](https://leetcode.com/problems/first-unique-character-in-a-string) | [![Java](assets/java.png)](src/FirstUniqueCharacter.java) [![Python](assets/python.png)](python/first_unique_character_in_string.py) | | +| 389 | [Find the Difference](https://leetcode.com/problems/find-the-difference) | [![Java](assets/java.png)](src/FindTheDifference.java) [![Python](assets/python.png)](python/find_the_difference.py) | | +| 392 | [Is Subsequence](https://leetcode.com/problems/is-subsequence) | [![Java](assets/java.png)](src/IsSubsequence.java) [![Python](assets/python.png)](python/is_subsequence.py) | | +| 401 | [Binary Watch](https://leetcode.com/problems/binary-watch) | [![Java](assets/java.png)](src/BinaryWatch.java) [![Python](assets/python.png)](python/binary_watch.py) | | +| 404 | [Sum of Left Leaves](https://leetcode.com/problems/sum-of-left-leaves) | [![Java](assets/java.png)](src/SumOfLeftLeaves.java) [![Python](assets/python.png)](python/sum_of_left_leaves.py) | | +| 405 | [Convert a Number to Hexadecimal](https://leetcode.com/problems/convert-a-number-to-hexadecimal) | [![Java](assets/java.png)](src/ConvertNumberToHexadecimal.java) [![Python](assets/python.png)](python/convert_a_number_to_hexadecimal.py) | | +| 408 | 🔒 [Valid Word Abbreviation](https://leetcode.com/problems/valid-word-abbreviation) | | | +| 409 | [Longest Palindrome](https://leetcode.com/problems/longest-palindrome) | [![Java](assets/java.png)](src/LongestPalindrome.java) [![Python](assets/python.png)](python/longest_palindrome.py) | | +| 412 | [Fizz Buzz](https://leetcode.com/problems/fizz-buzz) | [![Java](assets/java.png)](src/FizzBuzz.java) [![Python](assets/python.png)](python/fizz_buzz.py) | | +| 414 | [Third Maximum Number](https://leetcode.com/problems/third-maximum-number) | [![Java](assets/java.png)](src/ThirdMaximumNumber.java) [![Python](assets/python.png)](python/fizz_buzz.py) | | +| 415 | [Add Strings](https://leetcode.com/problems/add-strings) | [![Java](assets/java.png)](src/AddString.java) [![Python](assets/python.png)](python/add_strings.py) | | +| 422 | 🔒 [Valid Word Square](https://leetcode.com/problems/valid-word-square) | | | +| 430 | [Flatten a Multilevel Doubly Linked List](https://leetcode.com/problems/flatten-a-multilevel-doubly-linked-list) | [![Java](assets/java.png)](src/FlattenAMultiLevelDoublyLinkedList.java) | | +| 434 | [Number of Segments in a String](https://leetcode.com/problems/number-of-segments-in-a-string) | [![Java](assets/java.png)](src/NumberOfSegmentsInString.java) [![Python](assets/python.png)](python/number_of_segments_in_a_string.py) | | +| 441 | [Arranging Coins](https://leetcode.com/problems/arranging-coins) | [![Java](assets/java.png)](src/ArrangingCoins.java) [![Python](assets/python.png)](python/arranging_coins.py) | | +| 443 | [String Compression](https://leetcode.com/problems/string-compression) | [![Java](assets/java.png)](src/StringCompression.java) [![Python](assets/python.png)](python/string_compression.py) | | +| 447 | [Number of Boomerangs](https://leetcode.com/problems/number-of-boomerangs) | [![Java](assets/java.png)](src/NumberOfBoomerangs.java) [![Python](assets/python.png)](python/number_of_boomerangs.py) | | +| 448 | [Find All Numbers Disappeared in an Array](https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array) | [![Java](assets/java.png)](src/FindAllNumbersDisappearedInAnArray.java) [![Python](assets/python.png)](python/find_all_numbers_disappeared_in_an_array.py) | | +| 453 | [Minimum Moves to Equal Array Elements](https://leetcode.com/problems/minimum-moves-to-equal-array-elements) | [![Java](assets/java.png)](src/MinimumMovesToEqualArrayElements.java) [![Python](assets/python.png)](python/minimum_moves_to_equal_array_element.py) | | +| 455 | [Assign Cookies](https://leetcode.com/problems/assign-cookies) | [![Java](assets/java.png)](src/AssignCookies.java) [![Python](assets/python.png)](python/assign_cookies.py) | | +| 459 | [Repeated Substring Pattern](https://leetcode.com/problems/repeated-substring-pattern) | [![Java](assets/java.png)](src/RepeatedSubstringPattern.java) [![Python](assets/python.png)](python/repeated_substring_pattern.py) | | +| 461 | [Hamming Distance](https://leetcode.com/problems/hamming-distance) | [![Java](assets/java.png)](src/HammingDistance.java) [![Python](assets/python.png)](python/hamming_distance.py) | | +| 463 | [Island Perimeter](https://leetcode.com/problems/island-perimeter) | [![Java](assets/java.png)](src/IslandPerimeter.java) [![Python](assets/python.png)](python/island_perimeter.py) | | +| 475 | [Heaters](https://leetcode.com/problems/heaters) | [![Java](assets/java.png)](src/Heaters.java) [![Python](assets/python.png)](python/heaters.py) | | +| 476 | [Number Complement](https://leetcode.com/problems/number-complement) | [![Java](assets/java.png)](src/NumberComplement.java) [![Python](assets/python.png)](python/number_complement.py) | | +| 482 | [License Key Formatting](https://leetcode.com/problems/license-key-formatting) | [![Java](assets/java.png)](src/LicenseKeyFormatting.java) [![Python](assets/python.png)](python/license_key_formatting.py) | | +| 485 | [Max Consecutive Ones](https://leetcode.com/problems/max-consecutive-ones) | [![Java](assets/java.png)](src/MaxConsecutiveOnes.java) [![Python](assets/python.png)](python/max_consecutive_ones.py) | | +| 492 | [Construct the Rectangle](https://leetcode.com/problems/construct-the-rectangle) | [![Java](assets/java.png)](src/ConstructTheRectangle.java) [![Python](assets/python.png)](python/construct_the_rectangle.py) | | +| 495 | [Teemo Attacking](https://leetcode.com/problems/teemo-attacking/) | [![Java](assets/java.png)](src/TeemoAttacking.java) [![Python](assets/python.png)](python/teemo_attacking.py) | | +| 496 | [Next Greater Element I](https://leetcode.com/problems/next-greater-element-i) | [![Java](assets/java.png)](src/NextGreaterElementI.java) [![Python](assets/python.png)](python/next_greater_element_i.py) | | +| 500 | [Keyboard Row](https://leetcode.com/problems/keyboard-row) | [![Java](assets/java.png)](src/KeyBoardRow.java) [![Python](assets/python.png)](python/keyboard_row.py) | | +| 501 | [Find Mode in Binary Search Tree](https://leetcode.com/problems/find-mode-in-binary-search-tree) | [![Java](assets/java.png)](src/FindModeInBinarySearchTree.java) [![Python](assets/python.png)](python/find_mode_in_binary_search_tree.py) | | +| 504 | [Base 7](https://leetcode.com/problems/base-7) | [![Java](assets/java.png)](src/Base7.java) [![Python](assets/python.png)](python/base_7.py) | | +| 506 | [Relative Ranks](https://leetcode.com/problems/relative-ranks) | [![Java](assets/java.png)](src/RelativeRanks.java) [![Python](assets/python.png)](python/relative_ranks.py) | | +| 507 | [Perfect Number](https://leetcode.com/problems/perfect-number) | [![Java](assets/java.png)](src/CheckPerfectNumber.java) [![Python](assets/python.png)](python/check_perfect_number.py) | | +| 509 | [Fibonacci Number](https://leetcode.com/problems/fibonacci-number) | [![Java](assets/java.png)](src/FibonacciNumber.java) [![Python](assets/python.png)](python/fibonacci_number.py) | | +| 520 | [Detect Capital](https://leetcode.com/problems/detect-capital) | [![Java](assets/java.png)](src/DetectCapital.java) [![Python](assets/python.png)](python/detect_capital.py) | | +| 521 | [Longest Uncommon Subsequence I](https://leetcode.com/problems/longest-uncommon-subsequence-i) | [![Java](assets/java.png)](src/LongestUncommonSubsequenceI.java) [![Python](assets/python.png)](python/longest_uncommon_subsequence_I.py) | | +| 530 | [Minimum Absolute Difference in BST](https://leetcode.com/problems/minimum-absolute-difference-in-bst) | [![Java](assets/java.png)](src/MinimumAbsoluteDifferenceInBST.java) [![Python](assets/python.png)](python/minimum_absolute_difference_in_bst.py) | | +| 532 | [K - Diff Pairs in Array](https://leetcode.com/problems/k-diff-pairs-in-an-array) | [![Java](assets/java.png)](src/KDiffPairsInAnArray.java) [![Python](assets/python.png)](python/k_dif_pairs_in_an_array.py) | | +| 538 | [Convert BST to Greater Tree](https://leetcode.com/problems/convert-bst-to-greater-tree) | [![Java](assets/java.png)](src/ConvertBSTToGreaterTree.java) [![Python](assets/python.png)](python/convert_bst_to_greater_tree.py) | | +| 541 | [Reverse String II](https://leetcode.com/problems/reverse-string-ii) | [![Java](assets/java.png)](src/ReverseStringII.java) [![Python](assets/python.png)](python/reverse_string_ii.py) | | +| 543 | [Diameter of Binary Tree](https://leetcode.com/problems/diameter-of-binary-tree) | [![Java](assets/java.png)](src/DiameterOfBinaryTree.java) [![Python](assets/python.png)](python/diameter_of_binary_tree.py) | | +| 551 | [Student Attendance Record I](https://leetcode.com/problems/student-attendance-record-i) | [![Java](assets/java.png)](src/StudentAttendanceRecordI.java) [![Python](assets/python.png)](python/student_attendance_record_I.py) | | +| 557 | [Reverse Words in a String III](https://leetcode.com/problems/reverse-words-in-a-string-iii) | [![Java](assets/java.png)](src/ReverseWordsInStringIII.java) [![Python](assets/python.png)](python/reverse_words_in_string_iii.py) | | +| 559 | [Maximum Depth of N-Ary Tree](https://leetcode.com/problems/maximum-depth-of-n-ary-tree) | [![Java](assets/java.png)](src/MaximumDepthOfNAryTree.java) [![Python](assets/python.png)](python/maximum_depth_of_n_ary_tree.py) | | +| 561 | [Array Partition I](https://leetcode.com/problems/array-partition-i) | [![Java](assets/java.png)](src/ArrayPartitionI.java) [![Python](assets/python.png)](python/array_partiton_I.py) | | +| 563 | [Binary Tree Tilt](https://leetcode.com/problems/binary-tree-tilt) | [![Java](assets/java.png)](src/BinaryTreeTilt.java) [![Python](assets/python.png)](python/binary_tree_tilt.py) | | +| 566 | [Reshape The Matrix](https://leetcode.com/problems/reshape-the-matrix) | [![Java](assets/java.png)](src/ReshapeTheMatrix.java) [![Python](assets/python.png)](python/reshape_the_matrix.py) | | +| 572 | [Subtree of Another Tree](https://leetcode.com/problems/subtree-of-another-tree) | [![Java](assets/java.png)](src/SubtreeOfAnotherTree.java) [![Python](assets/python.png)](python/subtree_of_another_tree.py) | | +| 575 | [Distribute Candies](https://leetcode.com/problems/distribute-candies) | [![Java](assets/java.png)](src/DistributeCandies.java) [![Python](assets/python.png)](python/distribute_candies.py) | | +| 581 | [Shortest Unsorted Continuous Subarray](https://leetcode.com/problems/shortest-unsorted-continuous-subarray) | [![Java](assets/java.png)](src/ShortestUnsortedContinuousSubarray.java) [![Python](assets/python.png)](python/shortest_continuous_unsorted_subarray.py) | | +| 589 | [N-Ary Tree Preorder Traversal](https://leetcode.com/problems/n-ary-tree-preorder-traversal) | [![Java](assets/java.png)](src/NArayTreePreOrderTraversal.java) [![Python](assets/python.png)](python/n_ary_tree_preorder_traversal.py) | | +| 590 | [N-Ary Tree Postorder Traversal](https://leetcode.com/problems/n-ary-tree-postorder-traversal) | [![Java](assets/java.png)](src/NAryTreePostorderTraversal.java) [![Python](assets/python.png)](python/n_ary_tree_postorder_traversal.py) | | +| 594 | [Longest Harmonious Subsequence](https://leetcode.com/problems/longest-harmonious-subsequence) | [![Java](assets/java.png)](src/LongestHarmoniousSubsequence.java) [![Python](assets/python.png)](python/longest_harmonious_subequence.py) | | +| 598 | [Range Addition II](https://leetcode.com/problems/range-addition-ii) | [![Java](assets/java.png)](src/RangeAdditionII.java) [![Python](assets/python.png)](python/range_addition_ii.py) | | +| 599 | [Minimum Index Sum of 2 Lists](https://leetcode.com/problems/minimum-index-sum-of-two-lists) | [![Java](assets/java.png)](src/MinimumIndexSumOfTwoLists.java) [![Python](assets/python.png)](python/minimum_index_sum_of_two_lists.py) | | +| 604 | 🔒 [Design Compressed String Iterator](https://leetcode.com/problems/design-compressed-string-iterator) | | | +| 605 | [Can Place Flowers](https://leetcode.com/problems/can-place-flowers) | [![Java](assets/java.png)](src/CanPlaceFlowers.java) [![Python](assets/python.png)](python/can_place_flowers.py) | | +| 606 | [Construct String from Binary Tree](https://leetcode.com/problems/construct-string-from-binary-tree) | [![Java](assets/java.png)](src/ConstructStringFromBinaryTree.java) [![Python](assets/python.png)](python/construct_string_from_binary_tree.py) | | +| 617 | [Merge Two Binary Trees](https://leetcode.com/problems/merge-two-binary-trees) | [![Java](assets/java.png)](src/MergeTwoBinaryTrees.java) [![Python](assets/python.png)](python/merge_two_binary_trees.py) | | +| 624 | 🔒 [Maximum Distance in Arrays](https://leetcode.com/problems/maximum-distance-in-arrays) | | | +| 628 | [Maximum Product of Three Numbers](https://leetcode.com/problems/maximum-product-of-three-numbers) | [![Java](assets/java.png)](src/MaximumProductOfThreeNumbers.java) [![Python](assets/python.png)](python/maximum_product_of_three_numbers.py) | | +| 633 | [Sum Square Numbers](https://leetcode.com/problems/sum-of-square-numbers) | [![Java](assets/java.png)](src/SumOfSquareNumbers.java) [![Python](assets/python.png)](python/sum_of_squares_numbers.py) | | +| 637 | [Average of Levels in Binary Tree](https://leetcode.com/problems/average-of-levels-in-binary-tree) | [![Java](assets/java.png)](src/AverageLevelsOfBinaryTree.java) [![Python](assets/python.png)](python/average_levels_of_binary_tree.py) | | +| 643 | [Maximum Average SubArray I](https://leetcode.com/problems/maximum-average-subarray-i) | [![Java](assets/java.png)](src/MaximumAverageSubArrayI.java) [![Python](assets/python.png)](python/maximum_average_subarray_I.py) | | +| 645 | [Set Mismatch](https://leetcode.com/problems/set-mismatch) | [![Java](assets/java.png)](src/SetMismatch.java) [![Python](assets/python.png)](python/set_mismatch.py) | | +| 653 | [Two Sum IV - Input is a BST](https://leetcode.com/problems/two-sum-iv-input-is-a-bst) | [![Java](assets/java.png)](src/TwoSumIVInputIsABST.java) [![Python](assets/python.png)](python/two_sum_iv.py) | | +| 657 | [Robot Return to Origin](https://leetcode.com/problems/robot-return-to-origin) | [![Java](assets/java.png)](src/RobotReturnToOrigin.java) [![Python](assets/python.png)](python/robot_return_to_origin.py) | | +| 661 | [Image Smoother](https://leetcode.com/problems/image-smoother) | [![Java](assets/java.png)](src/ImageSmoother.java) [![Python](assets/python.png)](python/image_smoother.py) | | +| 665 | [Non Deceasing Array](https://leetcode.com/problems/non-decreasing-array) | [![Java](assets/java.png)](src/NonDecreasingArray.java) [![Python](assets/python.png)](python/non_decreasing_array.py) | | +| 669 | [Trim a Binary Search Tree](https://leetcode.com/problems/trim-a-binary-search-tree) | [![Java](assets/java.png)](src/TrimABinarySearchTree.java) [![Python](assets/python.png)](python/trim_a_binary_search_tree.py) | | +| 671 | [Second Minimum Node in Binary Tree](https://leetcode.com/problems/second-minimum-node-in-a-binary-tree) | [![Java](assets/java.png)](src/SecondMinimumNodeInBinaryTree.java) [![Python](assets/python.png)](python/second_minimum_node_in_binary_tree.py) | | +| 674 | [Longest Continuous Increasing Subsequence](https://leetcode.com/problems/longest-continuous-increasing-subsequence) | [![Java](assets/java.png)](src/LongestContinuousIncreasingSubsequence.java) [![Python](assets/python.png)](python/longest_continuous_increasing_subsequence.py) | | +| 680 | [Valid Palindrome II](https://leetcode.com/problems/valid-palindrome-ii) | [![Java](assets/java.png)](src/ValidPalindromeII.java) [![Python](assets/python.png)](python/valid_pallindrome_ii.py) | | +| 682 | [Baseball Game](https://leetcode.com/problems/baseball-game) | [![Java](assets/java.png)](src/BaseballGame.java) [![Python](assets/python.png)](python/baseball_game.py) | | +| 686 | [Repeated String Match](https://leetcode.com/problems/repeated-string-match) | | | +| 687 | [Longest Univalue Path](https://leetcode.com/problems/longest-univalue-path) | | | +| 688 | [Knight Probability in Chessboard](https://leetcode.com/problems/knight-probability-in-chessboard) | [![Java](assets/java.png)](src/KnightProbabilityInChessboard.java) | | +| 690 | [Employee Importance](https://leetcode.com/problems/employee-importance) | | | +| 693 | [Binary Number with Alternating Bits](https://leetcode.com/problems/binary-number-with-alternating-bits) | [![Java](assets/java.png)](src/BinaryNumberWithAlternatingBits.java) [![Python](assets/python.png)](python/binary_number_with_alternating_bits.py) | | +| 696 | [Count Binary Substrings](https://leetcode.com/problems/count-binary-substrings) | [![Java](assets/java.png)](src/CountBinarySubstrings.java) [![Python](assets/python.png)](python/count_binary_substrings.py) | | +| 697 | [Degree of an Array](https://leetcode.com/problems/degree-of-an-array) | [![Java](assets/java.png)](src/DegreeOfAnArray.java) [![Python](assets/python.png)](python/degree_of_an_array.py) | | +| 700 | [Search in a Binary Search Tree](https://leetcode.com/problems/search-in-a-binary-search-tree) | [![Java](assets/java.png)](src/SearchInBinarySearchTree.java) [![Python](assets/python.png)](python/search_in_binary_search_tree.py) | | +| 703 | [Kth Largest Element in a Stream](https://leetcode.com/problems/kth-largest-element-in-a-stream) | [![Java](assets/java.png)](src/KthLargestElementInAStream.java) [![Python](assets/python.png)](python/k_th_largest_element_in_a_stream.py) | | +| 704 | [Binary Search](https://leetcode.com/problems/binary-search) | [![Java](assets/java.png)](src/BinarySearch.java) [![Python](assets/python.png)](python/binary_search.py) | | +| 705 | [Design HashSet](https://leetcode.com/problems/design-hashset) | [![Java](assets/java.png)](src/DesignHashSet.java) [![Python](assets/python.png)](python/design_hash_set.py) | | +| 706 | [Design HashMap](https://leetcode.com/problems/design-hashmap) | [![Java](assets/java.png)](src/DesignHashMap.java) [![Python](assets/python.png)](python/design_hash_map.py) | | +| 709 | [To Lower Case](https://leetcode.com/problems/to-lower-case) | [![Java](assets/java.png)](src/ToLowerCase.java) [![Python](assets/python.png)](python/to_lower_case.py) | | +| 716 | 🔒 [Max Stack](https://leetcode.com/problems/max-stack) | | | +| 717 | [1-bit and 2-bit Characters](https://leetcode.com/problems/1-bit-and-2-bit-characters) | [![Java](assets/java.png)](src/OneBitAndTwoBitCharacters.java) [![Python](assets/python.png)](python/one_bit_and_two_bit_characters.py) | | +| 718 | [Maximum Length of Repeated Subarray](https://leetcode.com/problems/maximum-length-of-repeated-subarray) | [![Java](assets/java.png)](src/MaximumLengthOfRepeatedSubArray.java) | | +| 720 | [Longest Word in Dictionary](https://leetcode.com/problems/longest-word-in-dictionary) | | | +| 724 | [Find Pivot Index](https://leetcode.com/problems/find-pivot-index) | [![Java](assets/java.png)](src/FindPivotIndex.java) [![Python](assets/python.png)](python/find_pivot_index.py) | | +| 728 | [Self Dividing Numbers](https://leetcode.com/problems/self-dividing-numbers) | [![Java](assets/java.png)](src/SelfDividingNumbers.java) [![Python](assets/python.png)](python/self_dividing_number.py) | | +| 733 | [Flood Fill](https://leetcode.com/problems/flood-fill) | [![Java](assets/java.png)](src/FloodFill.java) [![Python](assets/python.png)](python/flood_fill.py) | | +| 743 | [Network Delay Time](https://leetcode.com/problems/network-delay-time) | [![Java](assets/java.png)](src/NetworkDelayTime.java) | | +| 734 | [Sentence Similarity](https://leetcode.com/problems/sentence-similarity) | | | +| 744 | [Find Smallest Letter Greater Than Target](https://leetcode.com/problems/find-smallest-letter-greater-than-target) | [![Java](assets/java.png)](src/FindSmallestLetterGreaterThanTarget.java) [![Python](assets/python.png)](python/find_smallest_letter_greater_than.py) | | +| 746 | [Min Cost Climbing Stairs](https://leetcode.com/problems/min-cost-climbing-stairs) | [![Java](assets/java.png)](src/MinCostClimbingStairs.java) [![Python](assets/python.png)](python/min_cost_climbing_stairs.py) | | +| 747 | [Largest Number at least Twice of Others](https://leetcode.com/problems/largest-number-at-least-twice-of-others) | [![Java](assets/java.png)](src/LargestNumberAtLeastTwiceOfOthers.java) [![Python](assets/python.png)](python/largest_number_at_least_twice_of_others.py) | | +| 748 | [Shortest Completing Word](https://leetcode.com/problems/shortest-completing-word) | [![Java](assets/java.png)](src/ShortestCompletingWord.java) [![Python](assets/python.png)](python/shortest_completing_word.py) | | +| 758 | [Bold Words in String](https://leetcode.com/problems/bold-words-in-string) | | | +| 760 | [Find Anagram Mappings](https://leetcode.com/problems/find-anagram-mappings) | | | +| 762 | [Prime Number of Set Bits in Primary Representation](https://leetcode.com/problems/prime-number-of-set-bits-in-binary-representation) | [![Java](assets/java.png)](src/PrimeNumberOfSetBitsInBinaryRepresentation.java) [![Python](assets/python.png)](python/prime_number_of_set_bits_in_binary_representation.py) | | +| 766 | [Toeplitz Matrix](https://leetcode.com/problems/toeplitz-matrix) | [![Java](assets/java.png)](src/ToeplitzMatrix.java) [![Python](assets/python.png)](python/toeplitz_matrix.py) | | +| 771 | [Jewels and Stones](https://leetcode.com/problems/jewels-and-stones) | [![Java](assets/java.png)](src/JewelsAndStones.java) [![Python](assets/python.png)](python/jewels_and_stones.py) | | +| 783 | [Minimum Distance Between BST Nodes](https://leetcode.com/problems/minimum-distance-between-bst-nodes) | [![Java](assets/java.png)](src/MinimumAbsoluteDifferenceInBST.java) [![Python](assets/python.png)](python/minimum_distance_between_bst_nodes.py) | | +| 788 | [Rotated Digits](https://leetcode.com/problems/rotated-digits) | | | +| 796 | [Rotate String](https://leetcode.com/problems/rotate-string) | [![Java](assets/java.png)](src/RotateString.java) | | +| 800 | [Similar RGB Color](https://leetcode.com/problems/similar-rgb-color) | | | +| 804 | [Unique Morse Code Words](https://leetcode.com/problems/unique-morse-code-words) | [![Java](assets/java.png)](src/UniqueMorseCodeWords.java) | | +| 806 | [Number of Lines to Write String](https://leetcode.com/problems/number-of-lines-to-write-string) | [![Java](assets/java.png)](src/NumberOfLinesToWriteInString.java) | | +| 811 | [Subdomain Visit Count](https://leetcode.com/problems/subdomain-visit-count) | | | +| 812 | [Largest Triangle Area](https://leetcode.com/problems/largest-triangle-area) | [![Java](assets/java.png)](src/LargestTriangleArea.java) | | +| 819 | [Most Common Word](https://leetcode.com/problems/most-common-word) | [![Java](assets/java.png)](src/MostCommonWord.java) | | +| 821 | [Shortest Distance to Character](https://leetcode.com/problems/shortest-distance-to-a-character) | [![Java](assets/java.png)](src/ShortestDistanceToACharacter.java) | | +| 824 | [Goat Latin](https://leetcode.com/problems/goat-latin) | [![Java](assets/java.png)](src/GoatLatin.java) | | +| 830 | [Positions of Large Groups](https://leetcode.com/problems/positions-of-large-groups) | [![Java](assets/java.png)](src/PositionsOfLargeGroups.java) | | +| 832 | [Flipping an Image](https://leetcode.com/problems/flipping-an-image) | [![Java](assets/java.png)](src/FlippingAnImage.java) | | +| 836 | [Rectangle Overlap](https://leetcode.com/problems/rectangle-overlap) | [![Java](assets/java.png)](src/RectangleOverlap.java) | | +| 840 | [Magic Squares in Grid](https://leetcode.com/problems/magic-squares-in-grid) | | | +| 844 | [Backspace String Compare](https://leetcode.com/problems/backspace-string-compare) | [![Java](assets/java.png)](src/BackspaceStringCompare.java) | | +| 849 | [Maximize Distance to Closest Person](https://leetcode.com/problems/maximize-distance-to-closest-person) | | | +| 852 | [Peak Index in Mountain Array](https://leetcode.com/problems/peak-index-in-a-mountain-array) | [![Java](assets/java.png)](src/PeakIndexInMountainArray.java) | | +| 859 | [Buddy Strings](https://leetcode.com/problems/buddy-strings) | [![Java](assets/java.png)](src/BuddyStrings.java) | | +| 860 | [Lemonade Change](https://leetcode.com/problems/lemonade-change) | [![Java](assets/java.png)](src/LemonadeChange.java) | | +| 867 | [Transpose Matrix](https://leetcode.com/problems/transpose-matrix) | [![Java](assets/java.png)](src/TransposeMatrix.java) | | +| 868 | [Binary Gap](https://leetcode.com/problems/binary-gap) | [![Java](assets/java.png)](src/BinaryGap.java) | | +| 872 | [Leaf-Similar Trees](https://leetcode.com/problems/leaf-similar-trees) | [![Java](assets/java.png)](src/LeafSimilarTrees.java) | | +| 874 | [Walking Robot Simulation](https://leetcode.com/problems/walking-robot-simulation) | | | +| 876 | [Middle of the Linked List](https://leetcode.com/problems/middle-of-the-linked-list) | [![Java](assets/java.png)](src/MiddleOfTheLinkedList.java) | | +| 881 | [Boats to Save People](https://leetcode.com/problems/boats-to-save-people) | [![Python](assets/python.png)](python/boats_to_save_people.py) | | +| 883 | [Projection Area of 3D Shapes](https://leetcode.com/problems/projection-area-of-3d-shapes) | [![Java](assets/java.png)](src/ProjectionAreaOf3DShapes.java) | | +| 884 | [Uncommon Words from 2 Sentences](https://leetcode.com/problems/uncommon-words-from-two-sentences) | [![Java](assets/java.png)](src/UncommonWordsFromTwoSentences.java) | | +| 888 | [Fair Candy Swap](https://leetcode.com/problems/fair-candy-swap) | [![Java](assets/java.png)](src/FairCandySwap.java) | | +| 892 | [Surface Area of 3D Shapes](https://leetcode.com/problems/surface-area-of-3d-shapes) | [![Java](assets/java.png)](src/SurfaceAreaOf3DShapes.java) | | +| 893 | [Groups of Special Equivalent Strings](https://leetcode.com/problems/groups-of-special-equivalent-strings) | | | +| 896 | [Monotonic Array](https://leetcode.com/problems/monotonic-array) | [![Java](assets/java.png)](src/MonotonicArray.java) | | +| 897 | [Increasing Order Search Tree](https://leetcode.com/problems/increasing-order-search-tree) | [![Java](assets/java.png)](src/IncreasingOrderSearchTree.java) | | +| 905 | [Sort Array by Parity](https://leetcode.com/problems/sort-array-by-parity) | | | +| 908 | [Smallest Range I](https://leetcode.com/problems/smallest-range-i) | [![Java](assets/java.png)](src/SmallestRangeI.java) | | +| 914 | [X of a kind in a Deck of Cards](https://leetcode.com/problems/x-of-a-kind-in-a-deck-of-cards) | [![Java](assets/java.png)](src/XOfAKindInADeckOfCards.java) | | +| 917 | [Reverse Only Letters](https://leetcode.com/problems/reverse-only-letters) | [![Java](assets/java.png)](src/ReverseOnlyLetters.java) | | +| 922 | [Sort Array by Parity II](https://leetcode.com/problems/sort-array-by-parity-ii) | [![Java](assets/java.png)](src/SortArrayByParityII.java) | | +| 925 | [Long Pressed Name](https://leetcode.com/problems/long-pressed-name) | [![Java](assets/java.png)](src/LongPressedName.java) | | +| 929 | [Unique Email Addresses](https://leetcode.com/problems/unique-email-addresses) | [![Java](assets/java.png)](src/UniqueEmailAddresses.java) | | +| 933 | [Number of Recent Calls](https://leetcode.com/problems/number-of-recent-calls) | [![Java](assets/java.png)](src/NumberOfRecentCalls.java) | | +| 937 | [Reorder Data In Log Files](https://leetcode.com/problems/reorder-data-in-log-files) | [![Java](assets/java.png)](src/ReorderDataInLogFiles.java) | | +| 938 | [Range Sum of BST](https://leetcode.com/problems/range-sum-of-bst) | [![Java](assets/java.png)](src/RangeSumOfBST.java) | | +| 941 | [Valid Mountain Array](https://leetcode.com/problems/valid-mountain-array) | [![Java](assets/java.png)](src/ValidMountainArray.java) [![Python](assets/python.png)](python/valid_mountain_array.py) | | +| 942 | [DI String Match](https://leetcode.com/problems/di-string-match) | [![Java](assets/java.png)](src/DIStringMatch.java) | | +| 944 | [Delete Columns to Make Sorted](https://leetcode.com/problems/delete-columns-to-make-sorted) | [![Java](assets/java.png)](src/DeleteColumnsToMakeSorted.java) | | +| 949 | [Largest Time for Given Digits](https://leetcode.com/problems/largest-time-for-given-digits) | | | +| 953 | [Verifying an Alien Dictionary](https://leetcode.com/problems/verifying-an-alien-dictionary) | [![Java](assets/java.png)](src/VerifyAnAlienDictionary.java) | | +| 961 | [N-Repeated Elements in Size 2N Array](https://leetcode.com/problems/n-repeated-element-in-size-2n-array) | [![Java](assets/java.png)](src/NRepeatedElementInSizeNArray.java) | | +| 965 | [Univalued Binary Tree](https://leetcode.com/problems/univalued-binary-tree) | [![Java](assets/java.png)](src/UnivaluedBinaryTree.java) | | +| 970 | [Powerful Integers](https://leetcode.com/problems/powerful-integers) | | | +| 976 | [Largest Perimeter Triangle](https://leetcode.com/problems/largest-perimeter-triangle) | [![Java](assets/java.png)](src/LargestPerimeterTriangle.java) | | +| 977 | [Squares of a Sorted Array](https://leetcode.com/problems/squares-of-a-sorted-array) | | | +| 983 | [Minimum Cost For Tickets](https://leetcode.com/problems/minimum-cost-for-tickets) | [![Python](assets/python.png)](python/minimum_cost_for_tickets.py) | | +| 985 | [Sum of Even Numbers after Queries](https://leetcode.com/problems/sum-of-even-numbers-after-queries) | | | +| 989 | [Add to Array Form of Integer](https://leetcode.com/problems/add-to-array-form-of-integer) | [![Java](assets/java.png)](src/AddToArrayFormOfInteger.java) | | +| 993 | [Cousins in Binary Tree](https://leetcode.com/problems/cousins-in-binary-tree) | [![Java](assets/java.png)](src/CousinsInBinaryTree.java) | | +| 994 | [Rotting Oranges](https://leetcode.com/problems/rotting-oranges) | [![Java](assets/java.png)](src/RottingOranges.java) | | +| 997 | [Find the Town Judge](https://leetcode.com/problems/find-the-town-judge) | [![Java](assets/java.png)](src/FindTheTownJudge.java) | | +| 999 | [Available Captures for Rook](https://leetcode.com/problems/available-captures-for-rook) | [![Java](assets/java.png)](src/AvailableCapturesForRook.java) | | +| 1002 | [Find Common Characters](https://leetcode.com/problems/find-common-characters) | [![Java](assets/java.png)](src/FindCommonCharacters.java) | | +| 1005 | [Maximize Sum of Array After K Negations](https://leetcode.com/problems/maximize-sum-of-array-after-k-negations) | [![Java](assets/java.png)](src/MaximizeSumOfArrayAfterKNegations.java) | | +| 1009 | [Complement of Base 10 Integer](https://leetcode.com/problems/complement-of-base-10-integer) | [![Java](assets/java.png)](src/NumberComplement.java) | | +| 1010 | [Pairs of Songs With Total Durations Divisible by 60](https://leetcode.com/problems/pairs-of-songs-with-total-durations-divisible-by-60) | [![Java](assets/java.png)](src/PartitionArrayIntoThreePartsWithEqualSum.java) | | +| 1013 | [Partition Array into Three Parts with equal Sum](https://leetcode.com/problems/partition-array-into-three-parts-with-equal-sum) | | | +| 1018 | [Binary Prefix Divisible by 5](https://leetcode.com/problems/binary-prefix-divisible-by-5) | [![Java](assets/java.png)](src/BinaryPrefixDivisibleBy5.java) | | +| 1020 | [Number of Enclaves](https://leetcode.com/problems/number-of-enclaves) | [![Python](assets/python.png)](python/number_of_enclaves.py) | | +| 1021 | [Remove Outermost Parenthesis](https://leetcode.com/problems/remove-outermost-parentheses) | [![Java](assets/java.png)](src/RemoveOutermostParentheses.java) | | +| 1022 | [Sum of Root to Leaf Binary Numbers](https://leetcode.com/problems/sum-of-root-to-leaf-binary-numbers) | [![Java](assets/java.png)](src/SumOfRootToLeafBinaryNumbers.java) | | +| 1025 | [Divisor Game](https://leetcode.com/problems/divisor-game) | [![Java](assets/java.png)](src/DivisorGame.java) | | +| 1029 | [Two City Scheduling](https://leetcode.com/problems/two-city-scheduling) | | | +| 1030 | [Matrix Cells in Distance Order](https://leetcode.com/problems/matrix-cells-in-distance-order) | [![Java](assets/java.png)](src/MatrixCellsInDistanceOrder.java) | | +| 1033 | [Moving Stones Until Consecutive](https://leetcode.com/problems/moving-stones-until-consecutive) | | | +| 1037 | [Valid Boomerang](https://leetcode.com/problems/valid-boomerang) | [![Java](assets/java.png)](src/ValidBoomerang.java) | | +| 1042 | [Flower Planting with no Adjacent](https://leetcode.com/problems/flower-planting-with-no-adjacent) | | | +| 1046 | [Last Stone Weight](https://leetcode.com/problems/last-stone-weight) | [![Java](assets/java.png)](src/LastStoneWeight.java) | | +| 1047 | [Remove All adjacent Duplicates in String](https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string) | [![Java](assets/java.png)](src/RemoveAllAdjacentDuplicatesInAString.java) | | +| 1051 | [Height Checker](https://leetcode.com/problems/height-checker) | | | +| 1056 | 🔒 [Confusing Number](https://leetcode.com/problems/confusing-number) | | | +| 1064 | 🔒 [Fixed Point](https://leetcode.com/problems/fixed-point) | | | +| 1065 | 🔒 [Index Pairs of a String](https://leetcode.com/problems/index-pairs-of-a-string) | | | +| 1071 | [Greatest Common Divisors of Strings](https://leetcode.com/problems/greatest-common-divisor-of-strings) | [![Java](assets/java.png)](src/GreatestCommonDivisorOfStrings.java) | | +| 1078 | [Occurrence After Bigram](https://leetcode.com/problems/occurrences-after-bigram) | [![Java](assets/java.png)](src/OccurrencesAfterBigram.java) | | +| 1085 | 🔒 [Sum of Digits in Minimum Number](https://leetcode.com/problems/sum-of-digits-in-the-minimum-number) | | | +| 1086 | 🔒 [High Five](https://leetcode.com/problems/high-five) | | | +| 1089 | [Duplicate Zeroes](https://leetcode.com/problems/duplicate-zeros) | [![Java](assets/java.png)](src/DuplicateZeros.java) | | +| 1099 | 🔒 [Two Sum Less Than K](https://leetcode.com/problems/two-sum-less-than-k) | | | +| 1103 | [Distribute Candies to People](https://leetcode.com/problems/distribute-candies-to-people) | [![Java](assets/java.png)](src/DistributeCandiesToPeople.java) | | +| 1108 | [Defanging an IP Address](https://leetcode.com/problems/defanging-an-ip-address) | [![Java](assets/java.png)](src/DefangingAnIPAddress.java) | | +| 1118 | 🔒 [Number of Days in a Month](https://leetcode.com/problems/number-of-days-in-a-month) | | | +| 1119 | 🔒 [Remove Vowels From String](https://leetcode.com/problems/remove-vowels-from-a-string) | | | +| 1122 | [Relative Sort Array](https://leetcode.com/problems/relative-sort-array) | [![Java](assets/java.png)](src/RelativeSortArray.java) | | +| 1128 | [Number of Equivalent Domino Pairs](https://leetcode.com/problems/number-of-equivalent-domino-pairs) | [![Java](assets/java.png)](src/NumberOfEquivalentDominoPairs.java) | | +| 1133 | 🔒 [Largest Unique Number](https://leetcode.com/problems/largest-unique-number) | | | +| 1134 | 🔒 [Armstrong Number](https://leetcode.com/problems/armstrong-number) | | | +| 1137 | [Nth Tribonacci Number](https://leetcode.com/problems/n-th-tribonacci-number) | [![Java](assets/java.png)](src/NthTribonacciNumber.java) | | +| 1143 | [Longest Common Subsequence](https://leetcode.com/problems/longest-common-subsequence) | [![Java](assets/java.png)](src/LongestCommonSubsequence.java) | | +| 1150 | [Check if Number is Majority Element in Sorted Array](https://leetcode.com/problems/check-if-a-number-is-majority-element-in-a-sorted-array) | | | +| 1154 | [Day of The Year](https://leetcode.com/problems/day-of-the-year) | [![Java](assets/java.png)](src/DayOfTheYear.java) | | +| 1160 | [Find Words That Can Be Formed By Characters](https://leetcode.com/problems/find-words-that-can-be-formed-by-characters) | | | +| 1165 | [Single Row Keyboard](https://leetcode.com/problems/single-row-keyboard) | [![Java](assets/java.png)](src/FindWordsThatCanBeFormedByCharacters.java) | | +| 1170 | [Compare Strings By Frequency of the Smallest Character](https://leetcode.com/problems/compare-strings-by-frequency-of-the-smallest-character) | | | +| 1175 | [Prime Arrangements](https://leetcode.com/problems/prime-arrangements) | [![Java](assets/java.png)](src/PrimeArrangements.java) | | +| 1176 | 🔒 [Diet Plan Performance](https://leetcode.com/problems/diet-plan-performance) | | | +| 1180 | 🔒 [Count Substrings with only one Distinct Letter](https://leetcode.com/problems/count-substrings-with-only-one-distinct-letter) | | | +| 1184 | [Distance Between Bus Stops](https://leetcode.com/problems/distance-between-bus-stops) | [![Java](assets/java.png)](src/DistanceBetweenBusStops.java) | | +| 1185 | [Day of the Week](https://leetcode.com/problems/day-of-the-week) | [![Java](assets/java.png)](src/DayOfWeek.java) | | +| 1189 | [Maximum Number of Balloons](https://leetcode.com/problems/maximum-number-of-balloons) | [![Java](assets/java.png)](src/MaximumNumberOfBalloons.java) | | +| 1196 | 🔒 [How Many Apples Can You Put into the Basket](https://leetcode.com/problems/how-many-apples-can-you-put-into-the-basket) | | | +| 1200 | [Minimum Absolute Difference](https://leetcode.com/problems/minimum-absolute-difference) | [![Java](assets/java.png)](src/MinimumAbsoluteDifference.java) | | +| 1201 | [Ugly Number III](https://leetcode.com/problems/ugly-number-iii) | [![Java](assets/java.png)](src/UglyNumberIII.java) | | +| 1207 | [Unique Number of Occurrences](https://leetcode.com/problems/unique-number-of-occurrences) | [![Java](assets/java.png)](src/UniqueNumberOfOccurrences.java) | | +| 1213 | 🔒 [Intersection of Three Sorted Arrays](https://leetcode.com/problems/intersection-of-three-sorted-arrays) | | | +| 1217 | [Minimum Cost to Move Chips to The Same Position](https://leetcode.com/problems/minimum-cost-to-move-chips-to-the-same-position) | [![Java](assets/java.png)](src/MinimumCostToMoveChipsToTheSamePosition.java) | | +| 1221 | [Split A String In Balanced Strings](https://leetcode.com/problems/split-a-string-in-balanced-strings) | [![Java](assets/java.png)](src/SplitAStringInBalancedStrings.java) | | +| 1228 | 🔒 [Missing A Number In Arithmetic Progression](https://leetcode.com/problems/missing-number-in-arithmetic-progression) | | | +| 1232 | [Check If It Is A Straight Line](https://leetcode.com/problems/check-if-it-is-a-straight-line) | [![Java](assets/java.png)](src/CheckIfItIsASStraightLine.java) | | +| 1237 | [Find Positive Integer Solutions for a Given Equation](https://leetcode.com/problems/find-positive-integer-solution-for-a-given-equation) | | | +| 1243 | 🔒 [Array Transformation](https://leetcode.com/problems/array-transformation) | | | +| 1249 | [Minimum Remove to Make Valid Parentheses](https://leetcode.com/problems/minimum-remove-to-make-valid-parentheses) | [![Java](assets/java.png)](src/MinimumRemoveToMakeValidParentheses.java) | | +| 1252 | [Cells With Odd Values In Matrix](https://leetcode.com/problems/cells-with-odd-values-in-a-matrix) | [![Java](assets/java.png)](src/CellsWithOddValuesInMatrix.java) | | +| 1254 | [Number of Closed Islands](https://leetcode.com/problems/number-of-closed-islands) | [![Python](assets/python.png)](python/number_of_closed_islands.py) | | +| 1260 | [Shift 2D Grid](https://leetcode.com/problems/shift-2d-grid) | [![Java](assets/java.png)](src/Shift2DGrid.java) | | +| 1266 | [Minimum Time Visiting All Points](https://leetcode.com/problems/minimum-time-visiting-all-points) | [![Java](assets/java.png)](src/MinimumTimeVisitingAllPoints.java) | | +| 1271 | 🔒 [Hexspeak](https://leetcode.com/problems/hexspeak) | | | +| 1275 | [Find Winner On a Tic Tac Toe Game](https://leetcode.com/problems/find-winner-on-a-tic-tac-toe-game) | [![Java](assets/java.png)](src/FindWinnerOnATicTacToeGame.java) | | +| 1281 | [Subtract the Product and Sum of Digits of a Integer](https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer) | [![Java](assets/java.png)](src/SubtractTheProductAndSumOfDigitsOfAnInteger.java) | | +| 1287 | [Element Appearing More Than 25% in Sorted Array](https://leetcode.com/problems/element-appearing-more-than-25-in-sorted-array) | [![Java](assets/java.png)](src/ElementAppearingMoreThan25PercentInSortedArray.java) | | +| 1290 | [Convert Binary Number In A Linked List to Integer](https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer) | [![Java](assets/java.png)](src/ConvertBinaryNumberInLinkedListToInteger.java) | | +| 1295 | [Find Numbers With Even Numbers of Digits](https://leetcode.com/problems/find-numbers-with-even-number-of-digits) | [![Java](assets/java.png)](src/FindNumbersWithEvenNumbersOfDigits.java) [![Python](assets/python.png)](python/find_numbers_with_even_number_of_digits.py) | | +| 1299 | [Replace Elements With Greatest Element on Right Side](https://leetcode.com/problems/replace-elements-with-greatest-element-on-right-side) | [![Java](assets/java.png)](src/ReplaceElementWithGreatestElementOnRightSide.java) [![Python](assets/python.png)](python/replace_element_with_greatest_element_on_right_hand_side.py) | | +| 1304 | [Find N Unique Integers Sum Up To Zero](https://leetcode.com/problems/find-n-unique-integers-sum-up-to-zero) | [![Java](assets/java.png)](src/FindNUniqueIntegersSumUpToZero.java) | | +| 1309 | [Decrypt String From Alphabet To Integer Mapping](https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping) | [![Java](assets/java.png)](src/DecryptStringFromAlphabetToIntegerMapping.java) | | +| 1313 | [Decompress Run-Length Encoded Strings](https://leetcode.com/problems/decompress-run-length-encoded-list) | [![Java](assets/java.png)](src/DecompressRunLengthEncodedList.java) | | +| 1317 | [Convert Integer to Sum Of Two Non-Zero Integers](https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers) | [![Java](assets/java.png)](src/ConvertIntegerToTheSumOfTwoNoZeroIntegers.java) | | +| 1319 | [Number of Operations to Make Network Connected](https://leetcode.com/problems/number-of-operations-to-make-network-connected) | [![Python](assets/python.png)](python/no_of_operations_to_make_network_connected.py) | | +| 1323 | [Maximum 69 Number](https://leetcode.com/problems/maximum-69-number) | [![Java](assets/java.png)](src/Maximum69Number.java) | | +| 1331 | [Rank Transform of An Array](https://leetcode.com/problems/rank-transform-of-an-array) | [![Java](assets/java.png)](src/RankTransformOfArray.java) | | +| 1332 | [Remove Palindromic Subsequences](https://leetcode.com/problems/remove-palindromic-subsequences) | [![Java](assets/java.png)](src/RemovePalindromicSubSequences.java) | | +| 1337 | [The K Weakest Rows In A Matrix](https://leetcode.com/problems/the-k-weakest-rows-in-a-matrix) | [![Java](assets/java.png)](src/TheKWeakestRowsInAMatrix.java) | | +| 1342 | [Number of Steps to Reduce a Number to Zero](https://leetcode.com/problems/number-of-steps-to-reduce-a-number-to-zero) | [![Java](assets/java.png)](src/NumberOfStepsToReduceANumberToZero.java) | | +| 1346 | [Check if N and It's Double Exist](https://leetcode.com/problems/check-if-n-and-its-double-exist) | [![Java](assets/java.png)](src/CheckIfNAndItsDoubleExist.java) [![Python](assets/python.png)](python/check_if_n_and_its_double_exist.py) | | +| 1351 | [Count Negative Numbers In A Sorted Matrix](https://leetcode.com/problems/count-negative-numbers-in-a-sorted-matrix) | [![Java](assets/java.png)](src/CountNegativeNumbersInSortedMatrix.java) | | +| 1356 | [Sort Integers by Number of 1 Bits](https://leetcode.com/problems/sort-integers-by-the-number-of-1-bits) | [![Java](assets/java.png)](src/SortIntegersByTheNumberOf1Bits.java) | | +| 1360 | [Number of Days Between Two Dates](https://leetcode.com/problems/number-of-days-between-two-dates) | [![Java](assets/java.png)](src/NumberOfDaysBetweenTwoDates.java) | | +| 1365 | [How Many Numbers Are Smaller Than Current Number](https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number) | [![Java](assets/java.png)](src/HowManyNumbersAreSmallerThanCurrentNumber.java) | | +| 1370 | [Increasing Decreasing String](https://leetcode.com/problems/increasing-decreasing-string) | [![Java](assets/java.png)](src/IncreasingDecreasingString.java) | | +| 1374 | [Generate A String With Characters That Have Odd Count](https://leetcode.com/problems/generate-a-string-with-characters-that-have-odd-counts) | [![Java](assets/java.png)](src/GenerateAStringWithCharactersThatHaveOddCounts.java) | | +| 1376 | [Time Needed to Inform All Employees](https://leetcode.com/problems/time-needed-to-inform-all-employees) | [![Java](assets/java.png)](src/TimeNeededToInformAllEmployees.java) | | +| 1379 | [Find a Corresponding Node of a Binary Tree in a Clone of That Tree](https://leetcode.com/problems/find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree) | [![Java](assets/java.png)](src/FindACorrespondingNodeOfABinaryTreeInACloneOfThatTree.java) | | +| 1380 | [Lucky Numbers In A Matrix](https://leetcode.com/problems/lucky-numbers-in-a-matrix) | [![Java](assets/java.png)](src/LuckyNumbersInAMatrix.java) | | +| 1385 | [Find The Distance Value Between 2 Arrays](https://leetcode.com/problems/find-the-distance-value-between-two-arrays) | [![Java](assets/java.png)](src/FindTheDistanceValuesBetweenTwoArrays.java) | | +| 1389 | [Create Target Array in Given Order](https://leetcode.com/problems/create-target-array-in-the-given-order) | [![Java](assets/java.png)](src/CreateTargetArrayInGivenOrder.java) | | +| 1394 | [Find Lucky Integer In An Array](https://leetcode.com/problems/find-lucky-integer-in-an-array) | [![Java](assets/java.png)](src/FindTheLuckyIntegerInAnArray.java) | | +| 1399 | [Count Largest Group](https://leetcode.com/problems/count-largest-group) | [![Java](assets/java.png)](src/CountLargestGroup.java) | | +| 1402 | [Reducing Dishes](https://leetcode.com/problems/reducing-dishes) | [![Python](assets/python.png)](python/reducing_dishes.py) | | +| 1403 | [Minimum Subsequence in Non-Increasing Order](https://leetcode.com/problems/minimum-subsequence-in-non-increasing-order) | [![Java](assets/java.png)](src/MinimumSubSequenceInNonIncreasingOrder.java) | | +| 1408 | [String Matching In An Array](https://leetcode.com/problems/string-matching-in-an-array) | [![Java](assets/java.png)](src/StringMatchingInAnArray.java) | | +| 1413 | [Minimum Value To Get Positive Step By Step Sum](https://leetcode.com/problems/minimum-value-to-get-positive-step-by-step-sum) | [![Java](assets/java.png)](src/MinimumValueToGetPositiveStepByStepSum.java) | | +| 1417 | [Reformat The String](https://leetcode.com/problems/reformat-the-string) | [![Java](assets/java.png)](src/ReformatTheString.java) | | +| 1422 | [Maximum Score After Splitting A String](https://leetcode.com/problems/maximum-score-after-splitting-a-string) | [![Java](assets/java.png)](src/MaximumScoreAfterSplittingAString.java) | | +| 1426 | 🔒 [Counting Elements](https://leetcode.com/problems/counting-elements) | | | +| 1427 | 🔒 [Performing String Shifts](https://leetcode.com/problems/perform-string-shifts) | | | +| 1431 | [Kids With The Greatest Number Of Candies](https://leetcode.com/problems/kids-with-the-greatest-number-of-candies) | [![Java](assets/java.png)](src/KidsWithTheGreatestNumberOfCandies.java) | | +| 1436 | [Destination City](https://leetcode.com/problems/destination-city) | [![Java](assets/java.png)](src/DestinationCity.java) | | +| 1437 | [Check If All 1's Are at Least Length K Places Away](https://leetcode.com/problems/check-if-all-1s-are-at-least-length-k-places-away) | [![Java](assets/java.png)](src/CheckIfAll1sAreAtLeastKPlacesAway.java) | | +| 1441 | [Build An Array With Stack Operation](https://leetcode.com/problems/build-an-array-with-stack-operations) | [![Java](assets/java.png)](src/BuildAnArrayWithStackOperations.java) | | +| 1444 | [Number of Ways of Cutting a Pizza](https://leetcode.com/problems/number-of-ways-of-cutting-a-pizza) | [![Python](assets/python.png)](python/number_of_ways_of_cutting_pizza.py) | | +| 1446 | [Consecutive Characters](https://leetcode.com/problems/consecutive-characters) | [![Java](assets/java.png)](src/ConsecutiveCharacters.java) | | +| 1450 | [Number of Students Doing Homework at Given Time](https://leetcode.com/problems/number-of-students-doing-homework-at-a-given-time) | [![Java](assets/java.png)](src/NumberOfStudentsDoingHomeworkAtGivenTime.java) | | +| 1455 | [Check If Word Occurs as Prefix of any Word in Sentence](https://leetcode.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence) | [![Java](assets/java.png)](src/CheckIfAWordOccursAsAPrefixOfAnyWordInASentence.java) | | +| 1460 | [Make 2 Arrays Equal by Reversing Sub Arrays](https://leetcode.com/problems/make-two-arrays-equal-by-reversing-sub-arrays) | [![Java](assets/java.png)](src/MakeTwoArraysEqualByReversingSubArrays.java) | | +| 1464 | [Maximum Product of 2 Elements in Array](https://leetcode.com/problems/maximum-product-of-two-elements-in-an-array) | [![Java](assets/java.png)](src/MaximumProductOfTwoElementsInArray.java) | | +| 1466 | [Reorder Routes to Make All Paths Lead to the City Zero](https://leetcode.com/problems/reorder-routes-to-make-all-paths-lead-to-the-city-zero) | [![Java](assets/java.png)](src/MaximumProductOfTwoElementsInArray.java) | | +| 1469 | 🔒 [Find All Lonely Nodes](https://leetcode.com/problems/find-all-the-lonely-nodes) | [![Python](assets/python.png)](python/reorder_routes_to_make_all_paths_lead_to_city_zero.py) | | +| 1470 | [Shuffle The Array](https://leetcode.com/problems/shuffle-the-array) | [![Java](assets/java.png)](src/ShuffleTheArray.java) | | +| 1472 | [Design Browser History](https://leetcode.com/problems/design-browser-history) | [![Java](assets/java.png)](src/DesignBrowserHistory.java) [![Python](assets/python.png)](python/design_browser_history.py) | | +| 1474 | [Delete N Nodes After M Nodes In A Linked List](https://leetcode.com/problems/delete-n-nodes-after-m-nodes-of-a-linked-list) | | | +| 1475 | [Final Prices With Special Discount in a Shop](https://leetcode.com/problems/final-prices-with-a-special-discount-in-a-shop) | [![Java](assets/java.png)](src/FinalPricesWithASpecialDiscountInAShop.java) | | +| 1480 | [Running Sum of 1D Array](https://leetcode.com/problems/running-sum-of-1d-array) | [![Java](assets/java.png)](src/RunningSumOf1DArray.java) | | +| 1486 | [XOR Operations in An Array](https://leetcode.com/problems/xor-operation-in-an-array) | [![Java](assets/java.png)](src/XOROperationInAnArray.java) | | +| 1491 | [Average Salary Excluding the Minimum and Maximum Salary](https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary) | [![Java](assets/java.png)](src/AverageSalaryExcludingTheMinimumAndMaximumSalary.java) | | +| 1496 | [Path Crossing](https://leetcode.com/problems/path-crossing) | [![Java](assets/java.png)](src/PathCrossing.java) | | +| 1502 | [Can Make Arithmetic Progression From Sequence](https://leetcode.com/problems/can-make-arithmetic-progression-from-sequence) | [![Java](assets/java.png)](src/CanMakeArithmeticProgressionFromSequence.java) | | +| 1507 | [Reformat Date](https://leetcode.com/problems/reformat-date) | [![Java](assets/java.png)](src/ReformatDate.java) | | +| 1512 | [Number of Good Pairs](https://leetcode.com/problems/number-of-good-pairs) | [![Java](assets/java.png)](src/NumberOfGoodPairs.java) | | +| 1518 | [Water Bottles](https://leetcode.com/problems/water-bottles) | [![Java](assets/java.png)](src/WaterBottles.java) | | +| 1523 | [Count Odd Numbers In Interval Range](https://leetcode.com/problems/count-odd-numbers-in-an-interval-range) | [![Java](assets/java.png)](src/CountOddNumbersInIntervalRange.java) | | +| 1528 | [Shuffle Strings](https://leetcode.com/problems/shuffle-string) | [![Java](assets/java.png)](src/ShuffleString.java) | | +| 1534 | [Count Good Triplets](https://leetcode.com/problems/count-good-triplets) | [![Java](assets/java.png)](src/CountGoodTriplets.java) | | +| 1539 | [Kth Missing Positive Number](https://leetcode.com/problems/kth-missing-positive-number) | [![Java](assets/java.png)](src/KthMissingPositiveNumber.java) | | +| 1544 | [Make The String Great](https://leetcode.com/problems/make-the-string-great) | [![Java](assets/java.png)](src/MakeTheStringGreat.java) | | +| 1550 | [Three Consecutive Odds](https://leetcode.com/problems/three-consecutive-odds) | [![Java](assets/java.png)](src/ThreeConsecutiveOdds.java) | | +| 1556 | [Thousand Separator](https://leetcode.com/problems/thousand-separator) | [![Java](assets/java.png)](src/ThousandSeparator.java) | | +| 1560 | [Most Visited Sector in a Circular Track](https://leetcode.com/problems/most-visited-sector-in-a-circular-track) | [![Java](assets/java.png)](src/MostVisitedSectorInACircularTrack.java) | | +| 1566 | [Detect Pattern of Length M Repeated K or More Times](https://leetcode.com/problems/detect-pattern-of-length-m-repeated-k-or-more-times) | [![Java](assets/java.png)](src/DetectPatternOfLengthMRepeatedKOrMoreTimes.java) | | +| 1572 | [Matrix Diagonal Sum](https://leetcode.com/problems/matrix-diagonal-sum) | [![Java](assets/java.png)](src/MatrixDiagonalSum.java) | | +| 1576 | [Replace All ?'s to Avoid Consecutive Repeating Characters](https://leetcode.com/problems/replace-all-s-to-avoid-consecutive-repeating-characters) | [![Java](assets/java.png)](src/ReplaceAllToAvoidConsecutiveRepeatingCharacters.java) | | +| 1582 | [Special Positions in a Binary Matrix](https://leetcode.com/problems/special-positions-in-a-binary-matrix) | [![Java](assets/java.png)](src/SpecialPositionInABinaryMatrix.java) | | +| 1588 | [Sum of All Odd Length Subarrays](https://leetcode.com/problems/sum-of-all-odd-length-subarrays) | [![Java](assets/java.png)](src/SumOfAllOddLengthSubArrays.java) | | +| 1592 | [Rearrange Spaces Between Words](https://leetcode.com/problems/rearrange-spaces-between-words) | [![Java](assets/java.png)](src/RearrangeSpacesBetweenWords.java) | | +| 1598 | [Crawler Log Folder](https://leetcode.com/problems/crawler-log-folder) | [![Java](assets/java.png)](src/CrawlerLogFolder.java) | | +| 1600 | [Throne Inheritance](https://leetcode.com/problems/throne-inheritance) | [![Java](assets/java.png)](src/ThroneInheritance.java) | | +| 1603 | [Design Parking System](https://leetcode.com/problems/design-parking-system) | [![Java](assets/java.png)](src/DesignParkingSystem.java) | | +| 1608 | [Special Array With X Elements Greater Than or Equal X](https://leetcode.com/problems/special-array-with-x-elements-greater-than-or-equal-x) | [![Java](assets/java.png)](src/SpecialArrayWithXElementsGreaterThanEqualToX.java) | | +| 1614 | [Maximum Nesting Depth of the Parentheses](https://leetcode.com/problems/maximum-nesting-depth-of-the-parentheses) | [![Java](assets/java.png)](src/MaximumNestingDepthOfTheParentheses.java) | | +| 1619 | [Mean of Array After Removing Some Elements](https://leetcode.com/problems/mean-of-array-after-removing-some-elements) | [![Java](assets/java.png)](src/MeanOfArrayAfterRemovingSomeElements.java) | | +| 1624 | [Largest Substring Between Two Equal Characters](https://leetcode.com/problems/largest-substring-between-two-equal-characters) | [![Java](assets/java.png)](src/LargestSubStringBetweenTwoEqualCharacters.java) | | +| 1629 | [Slowest Key](https://leetcode.com/problems/slowest-key) | [![Java](assets/java.png)](src/SlowestKey.java) | | +| 1636 | [Sort Array by Increasing Frequency](https://leetcode.com/problems/sort-array-by-increasing-frequency) | [![Java](assets/java.png)](src/SortArrayByIncreasingFrequency.java) | | +| 1640 | [Check Array Formation Through Concatenation](https://leetcode.com/problems/check-array-formation-through-concatenation) | [![Java](assets/java.png)](src/CheckArrayFormationThroughConcatenation.java) | | +| 1646 | [Get Maximum in Generated Array](https://leetcode.com/problems/get-maximum-in-generated-array) | [![Java](assets/java.png)](src/GetMaximumInGeneratedArray.java) | | +| 1652 | [Defuse the Bomb](https://leetcode.com/problems/defuse-the-bomb) | [![Java](assets/java.png)](src/DefuseTheBomb.java) | | +| 1656 | [Design an Ordered Stream](https://leetcode.com/problems/design-an-ordered-stream) | [![Java](assets/java.png)](src/DesignAnOrderedStream.java) | | +| 1662 | [Check If Two String Arrays are Equivalent](https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent) | [![Java](assets/java.png)](src/CheckIfTwoStringArraysAreEquivalent.java) | | +| 1668 | [Maximum Repeating Substring](https://leetcode.com/problems/maximum-repeating-substring) | [![Java](assets/java.png)](src/MaximumRepeatingSubString.java) | | +| 1672 | [Richest Customer Wealth](https://leetcode.com/problems/richest-customer-wealth) | [![Java](assets/java.png)](src/RichestCustomerWealth.java) | | +| 1678 | [Goal Parser Interpretation](https://leetcode.com/problems/goal-parser-interpretation) | [![Java](assets/java.png)](src/GoalParserInterpretation.java) | | +| 1684 | [Count the Number of Consistent Strings](https://leetcode.com/problems/count-the-number-of-consistent-strings) | [![Java](assets/java.png)](src/CountTheNumberOfConsistentStrings.java) | | +| 1688 | [Count of Matches in Tournament](https://leetcode.com/problems/count-of-matches-in-tournament) | [![Java](assets/java.png)](src/CountOfMatchesInTournament.java) | | +| 1694 | [Reformat Phone Number](https://leetcode.com/problems/reformat-phone-number) | [![Java](assets/java.png)](src/ReformatPhoneNumber.java) | | +| 1700 | [Number of Students Unable to Eat Lunch](https://leetcode.com/problems/number-of-students-unable-to-eat-lunch) | [![Java](assets/java.png)](src/NumberOfStudentsUnableToEatLunch.java) | | +| 1704 | [Determine if String Halves Are Alike](https://leetcode.com/problems/determine-if-string-halves-are-alike) | [![Java](assets/java.png)](src/DetermineIfStringHalvesAreAlike.java) | | +| 1708 | 🔒 [Largest Subarray Length K](https://leetcode.com/problems/largest-subarray-length-k/) | | | +| 1710 | [Maximum Units on a Truck](https://leetcode.com/problems/maximum-units-on-a-truck/) | [![Java](assets/java.png)](src/MaximumUnitsOnATruck.java) | | +| 1716 | [Calculate Money in Leetcode Bank](https://leetcode.com/problems/calculate-money-in-leetcode-bank) | [![Java](assets/java.png)](src/CalculateMoneyInLeetCodeBank.java) | | +| 1720 | [Decode XORed Array](https://leetcode.com/problems/decode-xored-array) | [![Java](assets/java.png)](src/DecodeXORedArray.java) | | +| 1725 | [Number Of Rectangles That Can Form The Largest Square](https://leetcode.com/problems/number-of-rectangles-that-can-form-the-largest-square) | [![Java](assets/java.png)](src/NumberOfRectanglesThatCanFormTheLargestSquare.java) | | +| 1732 | [Find the Highest Altitude](https://leetcode.com/problems/find-the-highest-altitude) | [![Java](assets/java.png)](src/FindTheHighestAltitude.java) | | +| 1736 | [Latest Time by Replacing Hidden Digits](https://leetcode.com/problems/latest-time-by-replacing-hidden-digits) | [![Java](assets/java.png)](src/LatestTimeByReplacingHiddenDigits.java) | | +| 1742 | [Maximum Number of Balls in a Box](https://leetcode.com/problems/maximum-number-of-balls-in-a-box) | [![Java](assets/java.png)](src/MaximumNumberOfBallsInABox.java) | | +| 1748 | [Sum of Unique Elements](https://leetcode.com/problems/sum-of-unique-elements) | [![Java](assets/java.png)](src/SumOfUniqueElements.java) | | +| 1752 | [Check if Array Is Sorted and Rotated](https://leetcode.com/problems/check-if-array-is-sorted-and-rotated) | [![Java](assets/java.png)](src/CheckIfArrayIsSortedAndRotated.java) | | +| 1758 | [Minimum Changes To Make Alternating Binary String](https://leetcode.com/problems/minimum-changes-to-make-alternating-binary-string) | [![Java](assets/java.png)](src/MinimumChangesToMakeAlternatingBinaryString.java) | | +| 1763 | [Longest Nice Substring](https://leetcode.com/problems/longest-nice-substring) | [![Java](assets/java.png)](src/LongestNiceSubstring.java) | | +| 1768 | [Merge Strings Alternately](https://leetcode.com/problems/merge-strings-alternately) | [![Java](assets/java.png)](src/MergeStringsAlternately.java) | | +| 1773 | [Count Items Matching a Rule](https://leetcode.com/problems/count-items-matching-a-rule) | [![Java](assets/java.png)](src/CountItemsMatchingARule.java) | | +| 1779 | [Find Nearest Point That Has the Same X or Y Coordinate](https://leetcode.com/problems/find-nearest-point-that-has-the-same-x-or-y-coordinate) | [![Java](assets/java.png)](src/FindNearestPointThatHasTheSameXOrYCoordinate.java) | | +| 1784 | [Check if Binary String Has at Most One Segment of Ones](https://leetcode.com/problems/check-if-binary-string-has-at-most-one-segment-of-ones) | [![Java](assets/java.png)](src/CheckIfBinaryStringHasAtMostOneSegmentOfOnes.java) | | +| 1790 | [Check if One String Swap Can Make Strings Equal](https://leetcode.com/problems/check-if-one-string-swap-can-make-strings-equal) | [![Java](assets/java.png)](src/CheckIfOneStringSwapCanMakeStringsEqual.java) | | +| 1791 | [Find Center of Star Graph](https://leetcode.com/problems/find-center-of-star-graph) | [![Java](assets/java.png)](src/FindCenterOfStarGraph.java) | | +| 1796 | [Second Largest Digit in a String](https://leetcode.com/problems/second-largest-digit-in-a-string) | [![Java](assets/java.png)](src/SecondLargestDigitInAString.java) | | +| 1800 | [Maximum Ascending Subarray Sum](https://leetcode.com/problems/maximum-ascending-subarray-sum) | [![Java](assets/java.png)](src/MaximumAscendingSubArraySum.java) | | +| 1805 | [Number of Different Integers in a String](https://leetcode.com/problems/number-of-different-integers-in-a-string) | [![Java](assets/java.png)](src/NumberOfDifferentIntegersInString.java) | | +| 1812 | [Determine Color of a Chessboard Square](https://leetcode.com/problems/determine-color-of-a-chessboard-square) | [![Java](assets/java.png)](src/DetermineColorOfChessboardSquare.java) | | +| 1816 | [Truncate Sentence](https://leetcode.com/problems/truncate-sentence) | [![Java](assets/java.png)](src/TruncateSentences.java) | | +| 1822 | [Sign of the Product of an Array](https://leetcode.com/problems/sign-of-the-product-of-an-array) | [![Java](assets/java.png)](src/SignOfTheProductOfAnArray.java) | | +| 1826 | 🔒 [Faulty Sensor](https://leetcode.com/problems/faulty-sensor) | | | +| 1827 | [Minimum Operations to Make the Array Increasing](https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing) | [![Java](assets/java.png)](src/MinimumOperationsToMakeTheArrayIncreasing.java) | | +| 1832 | [Check if the Sentence Is Pangram](https://leetcode.com/problems/check-if-the-sentence-is-pangram) | [![Java](assets/java.png)](src/CheckIfSentenceIsPangram.java) | | +| 1837 | [Sum of Digits in Base K](https://leetcode.com/problems/sum-of-digits-in-base-k) | [![Java](assets/java.png)](src/SumOfDigitsInBaseK.java) | | +| 1844 | [Replace All Digits with Characters](https://leetcode.com/problems/replace-all-digits-with-characters) | [![Java](assets/java.png)](src/ReplaceAllDigitsWithCharacters.java) | | +| 1848 | [Minimum Distance to the Target Element](https://leetcode.com/problems/minimum-distance-to-the-target-element) | [![Java](assets/java.png)](src/MinimumDistanceToTheTargetElement.java) | | +| 1854 | [Maximum Population Year](https://leetcode.com/problems/maximum-population-year) | [![Java](assets/java.png)](src/MaximumPopulationYear.java) | | +| 1859 | [Sorting the Sentence](https://leetcode.com/problems/sorting-the-sentence) | [![Java](assets/java.png)](src/SortingTheSentence.java) | | +| 1863 | [Sum of All Subset XOR Totals](https://leetcode.com/problems/sum-of-all-subset-xor-totals) | [![Java](assets/java.png)](src/SumOfAllSubsetXORTotals.java) | | +| 1869 | [Longer Contiguous Segments of Ones than Zeros](https://leetcode.com/problems/longer-contiguous-segments-of-ones-than-zeros) | [![Java](assets/java.png)](src/LongerContiguousSegmentOfOnesThanZeros.java) | | +| 1876 | [Substrings of Size Three with Distinct Characters](https://leetcode.com/problems/substrings-of-size-three-with-distinct-characters) | [![Java](assets/java.png)](src/SubstringsOfSizeThreeWithDistinctCharacters.java) | | +| 1880 | [Check if Word Equals Summation of Two Words](https://leetcode.com/problems/check-if-word-equals-summation-of-two-words) | [![Java](assets/java.png)](src/CheckIfWordEqualsSummationOfTwoWords.java) | | +| 1886 | [Determine Whether Matrix Can Be Obtained By Rotation](https://leetcode.com/problems/determine-whether-matrix-can-be-obtained-by-rotation) | [![Java](assets/java.png)](src/DetermineWhetherMatrixCanBeObtainedByRotation.java) | | +| 1893 | [Check if All the Integers in a Range Are Covered](https://leetcode.com/problems/check-if-all-the-integers-in-a-range-are-covered) | [![Java](assets/java.png)](src/CheckIfAllTheIntegersInARangeAreCovered.java) | | +| 1897 | [Redistribute Characters to Make All Strings Equal](https://leetcode.com/problems/redistribute-characters-to-make-all-strings-equal) | [![Java](assets/java.png)](src/RedistributeCharactersToMakeAllStringsEqual.java) | | +| 1903 | [Largest Odd Number in String](https://leetcode.com/problems/largest-odd-number-in-string) | [![Java](assets/java.png)](src/LargestOddNumberInString.java) | | +| 1909 | [Remove One Element to Make the Array Strictly Increasing](https://leetcode.com/problems/remove-one-element-to-make-the-array-strictly-increasing) | [![Java](assets/java.png)](src/RemoveOneElementToMakeTheArrayStrictlyIncreasing.java) | | +| 1913 | [Maximum Product Difference Between Two Pairs](https://leetcode.com/problems/maximum-product-difference-between-two-pairs) | [![Java](assets/java.png)](src/MaximumProductDifferenceBetweenTwoPairs.java) | | +| 1920 | [Build Array from Permutation](https://leetcode.com/problems/build-array-from-permutation) | [![Java](assets/java.png)](src/BuildArrayFromPermutation.java) | | +| 1925 | [Count Square Sum Triples](https://leetcode.com/problems/count-square-sum-triples) | [![Java](assets/java.png)](src/CountSquareSumTriplets.java) | | +| 1929 | [Concatenation of Array](https://leetcode.com/problems/concatenation-of-array) | [![Java](assets/java.png)](src/ConcatenationOfArray.java) | | +| 1933 | 🔒 [Check If String Is Decomposable Into Value EqualSubstrings](https://leetcode.com/problems/check-if-string-is-decomposable-into-value-equal-substring) | | | +| 1935 | [Maximum Number of Words You Can Type](https://leetcode.com/problems/maximum-number-of-words-you-can-type) | [![Java](assets/java.png)](src/MaximumNumberOfWordsYouCanType.java) | | +| 1941 | [Check if All Characters Have Equal Number of Occurrences](https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences) | [![Java](assets/java.png)](src/CheckIfAllCharactersHaveEqualNumberOfOccurrences.java) | | +| 1945 | [Sum of Digits of String After Convert](https://leetcode.com/problems/sum-of-digits-of-string-after-convert) | [![Java](assets/java.png)](src/SumOfDigitsOfStringAfterConvert.java) | | +| 1952 | [Three Divisors](https://leetcode.com/problems/three-divisors) | [![Java](assets/java.png)](src/ThreeDivisors.java) | | +| 1957 | [Delete Characters to Make Fancy String](https://leetcode.com/problems/delete-characters-to-make-fancy-string) | [![Java](assets/java.png)](src/DeleteCharactersToMakeFancyString.java) | | +| 1961 | [Check If String Is a Prefix of Array](https://leetcode.com/problems/check-if-string-is-a-prefix-of-array) | [![Java](assets/java.png)](src/CheckIfStringIsAPrefixOfArray.java) | | +| 1967 | [Number of Strings That Appear as Substrings in Word](https://leetcode.com/problems/number-of-strings-that-appear-as-substrings-in-word) | [![Java](assets/java.png)](src/NumberOfStringsThatAppearAsSubstringsInWord.java) | | +| 1971 | [Find if Path Exists in Graph](https://leetcode.com/problems/find-if-path-exists-in-graph) | [![Java](assets/java.png)](src/FindIfPathExistsInGraph.java) | | +| 1974 | [Minimum Time to Type Word Using Special Typewriter](https://leetcode.com/problems/minimum-time-to-type-word-using-special-typewriter) | [![Java](assets/java.png)](src/MinimumTimeToTypeWordUsingSpecialTypewriter.java) | | +| 1979 | [Find Greatest Common Divisor of Array](https://leetcode.com/problems/find-greatest-common-divisor-of-array) | [![Java](assets/java.png)](src/FindGreatestCommonDivisorOfArray.java) | | +| 1984 | [Minimum Difference Between Highest and Lowest of K Scores](https://leetcode.com/problems/minimum-difference-between-highest-and-lowest-of-k-scores) | [![Java](assets/java.png)](src/MinimumDifferenceBetweenHighestAndLowestOfKScores.java) | | +| 1991 | [Find the Middle Index in Array](https://leetcode.com/problems/find-the-middle-index-in-array) | [![Java](assets/java.png)](src/FindTheMiddleIndexInArray.java) | | +| 1995 | [Count Special Quadruplets](https://leetcode.com/problems/count-special-quadruplets) | [![Java](assets/java.png)](src/CountSpecialQuadruplets.java) | | +| 2000 | [Reverse Prefix of Word](https://leetcode.com/problems/reverse-prefix-of-word) | [![Java](assets/java.png)](src/ReversePrefixOfWord.java) | | +| 2006 | [Count Number of Pairs With Absolute Difference K](https://leetcode.com/problems/count-number-of-pairs-with-absolute-difference-k) | [![Java](assets/java.png)](src/CountNumberOfPairsWithAbsoluteDifferenceK.java) | | +| 2011 | [Final Value of Variable After Performing Operations](https://leetcode.com/problems/final-value-of-variable-after-performing-operations) | [![Java](assets/java.png)](src/FinalValueOfVariableAfterPerformingOperations.java) | | +| 2016 | [Maximum Difference Between Increasing Elements](https://leetcode.com/problems/maximum-difference-between-increasing-elements) | [![Java](assets/java.png)](src/MaximumDifferenceBetweenIncreasingElements.java) | | +| 2022 | [Convert 1D Array Into 2D Array](https://leetcode.com/problems/convert-1d-array-into-2d-array) | [![Java](assets/java.png)](src/Convert1DArrayInto2DArray.java) | | +| 2027 | [Minimum Moves to Convert String](https://leetcode.com/problems/minimum-moves-to-convert-string) | [![Java](assets/java.png)](src/MinimumMovesToConvertString.java) | | +| 2032 | [Two Out of Three](https://leetcode.com/problems/two-out-of-three) | [![Java](assets/java.png)](src/TwoOutOfThree.java) | | +| 2037 | [Minimum Number of Moves to Seat Everyone](https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone) | [![Java](assets/java.png)](src/MinimumNumberOfMovesToSeatEveryone.java) | | +| 2042 | [Check if Numbers Are Ascending in a Sentence](https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence) | [![Java](assets/java.png)](src/CheckIfNumbersAreAscendingInASentence.java) | | +| 2047 | [Number of Valid Words in a Sentence](https://leetcode.com/problems/number-of-valid-words-in-a-sentence) | [![Java](assets/java.png)](src/NumberOfValidWordsInASentence.java) | | +| 2053 | [Kth Distinct String in an Array](https://leetcode.com/problems/kth-distinct-string-in-an-array) | [![Java](assets/java.png)](src/KthDistinctStringInAnArray.java) | | +| 2057 | [Smallest Index With Equal Value](https://leetcode.com/problems/smallest-index-with-equal-value) | [![Java](assets/java.png)](src/SmallestIndexWithEqualValue.java) | | +| 2062 | [Count Vowel Substrings of a String](https://leetcode.com/problems/count-vowel-substrings-of-a-string) | [![Java](assets/java.png)](src/CountVowelSubstringsOfAString.java) | | +| 2068 | [Check Whether Two Strings are Almost Equivalent](https://leetcode.com/problems/check-whether-two-strings-are-almost-equivalent) | [![Java](assets/java.png)](src/CheckWhetherTwoStringsAreAlmostEquivalent.java) | | +| 2073 | [Time Needed to Buy Tickets](https://leetcode.com/problems/time-needed-to-buy-tickets) | [![Java](assets/java.png)](src/TimeNeededToBuyTickets.java) | | +| 2078 | [Two Furthest Houses With Different Colors](https://leetcode.com/problems/two-furthest-houses-with-different-colors) | [![Java](assets/java.png)](src/TwoFurthestHousesWithDifferentColors.java) | | +| 2085 | [Count Common Words With One Occurrence](https://leetcode.com/problems/count-common-words-with-one-occurrence) | [![Java](assets/java.png)](src/CountCommonWordsWithOneOccurrence.java) | | +| 2089 | [Find Target Indices After Sorting Array](https://leetcode.com/problems/find-target-indices-after-sorting-array) | [![Java](assets/java.png)](src/FindTargetIndicesAfterSortingArray.java) | | +| 2094 | [Finding 3-Digit Even Numbers](https://leetcode.com/problems/finding-3-digit-even-numbers) | [![Java](assets/java.png)](src/Finding3DigitEvenNumbers.java) | | +| 2099 | [Find Subsequence of Length K With the Largest Sum](https://leetcode.com/problems/find-subsequence-of-length-k-with-the-largest-sum) | [![Java](assets/java.png)](src/FindSubsequenceOfLengthKWithTheLargestSum.java) | | +| 2103 | [Rings and Rods](https://leetcode.com/problems/rings-and-rods) | [![Java](assets/java.png)](src/RingsAndRods.java) | | +| 2108 | [Find First Palindromic String in the Array](https://leetcode.com/problems/find-first-palindromic-string-in-the-array) | [![Java](assets/java.png)](src/FindFirstPalindromicStringInArray.java) | | +| 2114 | [Maximum Number of Words Found in Sentences](https://leetcode.com/problems/maximum-number-of-words-found-in-sentences) | [![Java](assets/java.png)](src/MaximumNumberOfWordsFoundInSentences.java) | | +| 2119 | [A Number After a Double Reversal](https://leetcode.com/problems/a-number-after-a-double-reversal) | [![Java](assets/java.png)](src/ANumberAfterADoubleReversal.java) | | +| 2124 | [Check if All A's Appears Before All B's](https://leetcode.com/problems/check-if-all-as-appears-before-all-bs) | [![Java](assets/java.png)](src/CheckIfAllTheAsAppearBeforeAllTheBs.java) | | +| 2129 | [Capitalize the Title](https://leetcode.com/problems/capitalize-the-title) | [![Java](assets/java.png)](src/CapitalizeTheTitle.java) | | +| 2133 | [Check if Every Row and Column Contains All Numbers](https://leetcode.com/problems/check-if-every-row-and-column-contains-all-numbers) | [![Java](assets/java.png)](src/CheckIfEveryRowAndEveryColumnContainAllNumbers.java) | | +| 2138 | [Divide a String Into Groups of Size k](https://leetcode.com/problems/divide-a-string-into-groups-of-size-k) | [![Java](assets/java.png)](src/DivideTheStringIntoGroupsOfSizeK.java) | | +| 2144 | [Minimum Cost of Buying Candies With Discount](https://leetcode.com/problems/minimum-cost-of-buying-candies-with-discount) | [![Java](assets/java.png)](src/MinimumCostOfBuyingCandiesWithDiscount.java) | | +| 2148 | [Count Elements With Strictly Smaller and Greater Elements](https://leetcode.com/problems/count-elements-with-strictly-smaller-and-greater-elements) | [![Java](assets/java.png)](src/CountElementsWithStrictlySmallerAndGreaterElements.java) | | +| 2154 | [Keep Multiplying Found Values by Two](https://leetcode.com/problems/keep-multiplying-found-values-by-two) | [![Java](assets/java.png)](src/KeepMultiplyingFoundValuesByTwo.java) | | +| 2160 | [Minimum Sum of Four Digit Number After Splitting Digits](https://leetcode.com/problems/minimum-sum-of-four-digit-number-after-splitting-digits) | [![Java](assets/java.png)](src/MinimumSumOfFourDigitNumberAfterSplittingDigits.java) | | +| 2164 | [Sort Even and Odd Indices Independently](https://leetcode.com/problems/sort-even-and-odd-indices-independently) | [![Java](assets/java.png)](src/SortEvenAndOddIndicesIndependently.java) | | +| 2169 | [Count Operations to Obtain Zero](https://leetcode.com/problems/count-operations-to-obtain-zero) | [![Java](assets/java.png)](src/CountOperationsToObtainZero.java) | | +| 2176 | [Count Equal and Divisible Pairs in an Array](https://leetcode.com/problems/count-equal-and-divisible-pairs-in-an-array) | [![Java](assets/java.png)](src/CountEqualAndDivisiblePairsInAnArray.java) | | +| 2180 | [Count Integers With Even Digit Sum](https://leetcode.com/problems/count-integers-with-even-digit-sum) | [![Java](assets/java.png)](src/CountIntegersWithEvenDigitSum.java) | | +| 2185 | [Counting Words With a Given Prefix](https://leetcode.com/problems/counting-words-with-a-given-prefix) | [![Java](assets/java.png)](src/CountingWordsWithAGivenPrefix.java) | | +| 2190 | [Most Frequent Number Following Key In an Array](https://leetcode.com/problems/most-frequent-number-following-key-in-an-array) | [![Java](assets/java.png)](src/MostFrequentNumberFollowingKeyInAnArray.java) | | +| 2194 | [Cells in a Range on an Excel Sheet](https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet) | [![Java](assets/java.png)](src/CellsInARangeOnAnExcelSheet.java) | | +| 2200 | [Find All K-Distant Indices in an Array](https://leetcode.com/problems/find-all-k-distant-indices-in-an-array) | [![Java](assets/java.png)](src/FindAllKDistantIndicesInAnArray.java) | | +| 2206 | [Divide Array Into Equal Pairs](https://leetcode.com/problems/divide-array-into-equal-pairs) | [![Java](assets/java.png)](src/DivideArrayIntoEqualPairs.java) | | +| 2210 | [Count Hills and Valleys in an Array](https://leetcode.com/problems/count-hills-and-valleys-in-an-array) | [![Java](assets/java.png)](src/CountHillsAndValleysInAnArray.java) | | +| 2215 | [Find the Difference of Two Arrays](https://leetcode.com/problems/find-the-difference-of-two-arrays) | [![Java](assets/java.png)](src/FindTheDifferenceOfTwoArrays.java) | | +| 2220 | [Minimum Bit Flips to Convert Number](https://leetcode.com/problems/minimum-bit-flips-to-convert-number) | [![Java](assets/java.png)](src/MinimumBitFlipsToConvertNumber.java) | | +| 2224 | [Minimum Number of Operations to Convert Time](https://leetcode.com/problems/minimum-number-of-operations-to-convert-time) | [![Java](assets/java.png)](src/MinimumNumberOfOperationsToConvertTime.java) | | +| 2229 | 🔒 [Check if an array is consecutive](https://leetcode.com/problems/check-if-an-array-is-consecutive) | | | +| 2231 | [Largest Number After Digit Swaps by Parity](https://leetcode.com/problems/largest-number-after-digit-swaps-by-parity) | [![Java](assets/java.png)](src/LargestNumberAfterDigitSwapsByParity.java) | | +| 2235 | [Add Two Integers](https://leetcode.com/problems/add-two-integers) | [![Java](assets/java.png)](src/AddTwoIntegers.java) | | +| 2236 | [Root Equals Sum of Children](https://leetcode.com/problems/root-equals-sum-of-children) | [![Java](assets/java.png)](src/RootEqualsSumOfChildren.java) | | +| 2239 | [Find Closest Number to Zero](https://leetcode.com/problems/find-closest-number-to-zero) | [![Java](assets/java.png)](src/FindClosestNumberToZero.java) | | +| 2243 | [Calculate Digit Sum of a String](https://leetcode.com/problems/calculate-digit-sum-of-a-string) | [![Java](assets/java.png)](src/CalculateDigitSumOfAString.java) | | +| 2248 | [Intersection of Multiple Arrays](https://leetcode.com/problems/intersection-of-multiple-arrays) | [![Java](assets/java.png)](src/IntersectionOfMultipleArrays.java) | | +| 2255 | [Count Prefixes of a Given String](https://leetcode.com/problems/count-prefixes-of-a-given-string) | [![Java](assets/java.png)](src/CountPrefixesOfAGivenString.java) | | +| 2259 | [Remove Digit From Number to Maximize Result](https://leetcode.com/problems/remove-digit-from-number-to-maximize-result) | [![Java](assets/java.png)](src/RemoveDigitFromNumberToMaximizeResult.java) | | +| 2264 | [Largest 3-Same-Digit Number in String](https://leetcode.com/problems/largest-3-same-digit-number-in-string) | [![Java](assets/java.png)](src/Largest3SameDigitNumberInString.java) | | +| 2269 | [Find the K-Beauty of a Number](https://leetcode.com/problems/find-the-k-beauty-of-a-number) | [![Java](assets/java.png)](src/FindTheKBeautyOfANumber.java) | | +| 2273 | [Find Resultant Array After Removing Anagrams](https://leetcode.com/problems/find-resultant-array-after-removing-anagrams) | [![Java](assets/java.png)](src/FindResultantArrayAfterRemovingAnagrams.java) | | +| 2278 | [Percentage of Letter in String](https://leetcode.com/problems/percentage-of-letter-in-string) | [![Java](assets/java.png)](src/PercentageOfLetterInString.java) | | +| 2283 | [Check if Number Has Equal Digit Count and Digit Value](https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value) | [![Java](assets/java.png)](src/CheckIfNumberHasEqualDigitCountAndDigitValue.java) | | +| 2287 | [Rearrange Characters to Make Target String](https://leetcode.com/problems/rearrange-characters-to-make-target-string) | [![Java](assets/java.png)](src/RearrangeCharactersToMakeTargetString.java) | | +| 2293 | [Min Max Game](https://leetcode.com/problems/min-max-game) | [![Java](assets/java.png)](src/MinMaxGame.java) | | +| 2299 | [Strong Password Checker II](https://leetcode.com/problems/strong-password-checker-ii) | [![Java](assets/java.png)](src/StrongPasswordCheckerII.java) | | +| 2300 | [Successful Pairs of Spells and Potions](https://leetcode.com/problems/successful-pairs-of-spells-and-potions) | [![Python](assets/python.png)](python/successfull_pairs_of_spells_and_potions.py) | | +| 2303 | [Calculate Amount Paid in Taxes](https://leetcode.com/problems/calculate-amount-paid-in-taxes) | [![Java](assets/java.png)](src/CalculateAmountPaidInTaxes.java) | | +| 2309 | [Greatest English Letter in Upper and Lower Case](https://leetcode.com/problems/greatest-english-letter-in-upper-and-lower-case) | [![Java](assets/java.png)](src/GreatestEnglishLetterInUpperAndLowerCase.java) | | +| 2315 | [Count Asterisks](https://leetcode.com/problems/count-asterisks) | [![Java](assets/java.png)](src/CountAsterisks.java) [![Python](assets/python.png)](python/successfull_pairs_of_spells_and_potions.py) | | +| 2316 | [Count Unreachable Pairs of Nodes in an Undirected Graph](https://leetcode.com/problems/count-unreachable-pairs-of-nodes-in-an-undirected-graph) | [![Python](assets/python.png)](python/count_unreachable_pair_of_node_in_an_undirectable_graph.py) | | +| 2319 | [Check if Matrix Is X-Matrix](https://leetcode.com/problems/check-if-matrix-is-x-matrix) | [![Java](assets/java.png)](src/CountAsterisks.java) | | +| 2325 | [Decode the Message](https://leetcode.com/problems/decode-the-message) | [![Java](assets/java.png)](src/DecodeTheMessage.java) | | +| 2331 | [Evaluate Boolean Binary Tree](https://leetcode.com/problems/evaluate-boolean-binary-tree) | [![Java](assets/java.png)](src/EvaluateBooleanBinaryTree.java) | | +| 2335 | [Minimum Amount of Time to Fill Cups](https://leetcode.com/problems/minimum-amount-of-time-to-fill-cups) | [![Java](assets/java.png)](src/MinimumAmountOfTimeToFillCups.java) | | +| 2439 | [Minimize Maximum of Array](https://leetcode.com/problems/minimize-maximum-of-array) | [![Python](assets/python.png)](python/minimize_maximum_of_array.py) | | +| 2341 | [Maximum Number of Pairs in Array](https://leetcode.com/problems/maximum-number-of-pairs-in-array) | [![Java](assets/java.png)](src/MaximumNumberOfPairsInArray.java) | | +| 2347 | [Best Poker Hand](https://leetcode.com/problems/best-poker-hand) | [![Java](assets/java.png)](src/BestPokerHand.java) | | +| 2348 | [Number of Zero-Filled Subarrays](https://leetcode.com/problems/number-of-zero-filled-subarrays) | [![Python](assets/python.png)](python/number_of_zero_filled_subarrays.py) | | +| 2351 | [First Letter to Appear Twice](https://leetcode.com/problems/first-letter-to-appear-twice) | [![Java](assets/java.png)](src/FirstLetterToAppearTwice.java) | | +| 2357 | [Make Array Zero by Subtracting Equal Amounts](https://leetcode.com/problems/make-array-zero-by-subtracting-equal-amounts) | [![Java](assets/java.png)](src/MakeArrayZeroBySubtractingEqualAmounts.java) | | +| 2360 | [Longest Cycle in a Graph](https://leetcode.com/problems/longest-cycle-in-a-graph) | [![Python](assets/python.png)](python/longest_cycle_in_graph.py) | | +| 2363 | [Merge Similar Items](https://leetcode.com/problems/merge-similar-items) | [![Java](assets/java.png)](src/MergeSimilarItems.java) | | +| 2367 | [Number of Arithmetic Triplets](https://leetcode.com/problems/number-of-arithmetic-triplets) | [![Java](assets/java.png)](src/NumberOfArithmeticTriplets.java) | | +| 2373 | [Largest Local Values in a Matrix](https://leetcode.com/problems/largest-local-values-in-a-matrix) | [![Java](assets/java.png)](src/LargestLocalValuesInAMatrix.java) | | +| 2379 | [Minimum Recolors to Get K Consecutive Black Blocks](https://leetcode.com/problems/minimum-recolors-to-get-k-consecutive-black-blocks) | [![Java](assets/java.png)](src/MinimumRecolorsToGetKConsecutiveBlackBlocks.java) | | +| 2383 | [Minimum Hours of Training to Win a Competition](https://leetcode.com/problems/minimum-hours-of-training-to-win-a-competition) | [![Java](assets/java.png)](src/MinimumHoursOfTrainingToWinACompetition.java) | | +| 2389 | [Longest Subsequence With Limited Sum](https://leetcode.com/problems/longest-subsequence-with-limited-sum) | [![Java](assets/java.png)](src/LongestSubsequenceWithLimitedSum.java) | | +| 2395 | [Find Subarrays With Equal Sum](https://leetcode.com/problems/find-subarrays-with-equal-sum) | [![Java](assets/java.png)](src/FindSubarraysWithEqualSum.java) | | +| 2399 | [Check Distances Between Same Letters](https://leetcode.com/problems/check-distances-between-same-letters) | [![Java](assets/java.png)](src/CheckDistancesBetweenSameLetters.java) | | +| 2404 | [Most Frequent Even Element](https://leetcode.com/problems/most-frequent-even-element) | [![Java](assets/java.png)](src/MostFrequentEvenElement.java) | | +| 2409 | [Count Days Spent Together](https://leetcode.com/problems/count-days-spent-together) | [![Java](assets/java.png)](src/CountDaysSpentTogether.java) | | +| 2413 | [Smallest Even Multiple](https://leetcode.com/problems/smallest-even-multiple) | [![Java](assets/java.png)](src/SmallestEvenMultiple.java) | | +| 2418 | [Sort the People](https://leetcode.com/problems/sort-the-people) | [![Java](assets/java.png)](src/SortThePeople.java) | | +| 2423 | [Remove Letter To Equalize Frequency](https://leetcode.com/problems/remove-letter-to-equalize-frequency) | [![Java](assets/java.png)](src/RemoveLetterToEqualizeFrequency.java) | | +| 2427 | [Number of Common Factors](https://leetcode.com/problems/number-of-common-factors) | [![Java](assets/java.png)](src/NumberOfCommonFactors.java) | | +| 2432 | [The Employee That Worked on the Longest Task](https://leetcode.com/problems/the-employee-that-worked-on-the-longest-task) | [![Java](assets/java.png)](src/TheEmployeeThatWorkedOnTheLongestTask.java) | | +| 2437 | [Number of Valid Clock Times](https://leetcode.com/problems/number-of-valid-clock-times) | [![Java](assets/java.png)](src/NumberOfValidClockTimes.java) | | +| 2441 | [Largest Positive Integer That Exists With Its Negative](https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative) | [![Java](assets/java.png)](src/LargestPositiveIntegerThatExistsWithItsNegative.java) | | +| 2446 | [Determine if Two Events Have Conflict](https://leetcode.com/problems/determine-if-two-events-have-conflict) | [![Java](assets/java.png)](src/DetermineIfTwoEventsHaveConflict.java) | | +| 2451 | [Odd String Difference](https://leetcode.com/problems/odd-string-difference) | [![Java](assets/java.png)](src/OddStringDifference.java) | | +| 2455 | [Average Value of Even Numbers That Are Divisible by Three](https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three) | [![Java](assets/java.png)](src/AverageValueOfEvenNumbersThatAreDivisibleByThree.java) | | +| 2460 | [Apply Operations to an Array](https://leetcode.com/problems/apply-operations-to-an-array) | [![Java](assets/java.png)](src/ApplyOperationsToAnArray.java) | | +| 2465 | [Number of Distinct Averages](https://leetcode.com/problems/number-of-distinct-averages) | [![Java](assets/java.png)](src/NumberOfDistinctAverages.java) | | +| 2466 | [Count Ways To Build Good Strings](https://leetcode.com/problems/count-ways-to-build-good-strings) | | | +| 2469 | [Convert the Temperature](https://leetcode.com/problems/convert-the-temperature) | [![Java](assets/java.png)](src/ConvertTheTemperature.java) | | +| 2475 | [Number of Unequal Triplets in Array](https://leetcode.com/problems/number-of-unequal-triplets-in-array) | [![Java](assets/java.png)](src/NumberOfUnequalTripletsInArray.java) | | +| 2481 | [Minimum Cuts to Divide a Circle](https://leetcode.com/problems/minimum-cuts-to-divide-a-circle) | [![Java](assets/java.png)](src/MinimumCutsToDivideACircle.java) | | +| 2485 | [Find the Pivot Integer](https://leetcode.com/problems/find-the-pivot-integer) | [![Java](assets/java.png)](src/FindThePivotInteger.java) | | +| 2490 | [Circular Sentence](https://leetcode.com/problems/circular-sentence) | [![Java](assets/java.png)](src/CircularSentence.java) | | +| 2492 | [Minimum Score of a Path Between Two Cities](https://leetcode.com/problems/minimum-score-of-a-path-between-two-cities) | [![Python](assets/python.png)](python/minimum_score_of_a_path_between_two_cities.py) | | +| 2496 | [Maximum Value of a String in an Array](https://leetcode.com/problems/maximum-value-of-a-string-in-an-array) | [![Java](assets/java.png)](src/MaximumValueOfAStringInAnArray.java) | | +| 2500 | [Delete Greatest Value in Each Row](https://leetcode.com/problems/delete-greatest-value-in-each-row) | [![Java](assets/java.png)](src/DeleteGreatestValueInEachRow.java) | | +| 2506 | [Count Pairs Of Similar Strings](https://leetcode.com/problems/count-pairs-of-similar-strings) | [![Java](assets/java.png)](src/CountPairsOfSimilarStrings.java) | | +| 2511 | [Maximum Enemy Forts That Can Be Captured](https://leetcode.com/problems/maximum-enemy-forts-that-can-be-captured) | [![Java](assets/java.png)](src/MaximumEnemyFortsThatCanBeCaptured.java) | | +| 2515 | [Shortest Distance to Target String in a Circular Array](https://leetcode.com/problems/shortest-distance-to-target-string-in-a-circular-array) | [![Java](assets/java.png)](src/ShortestDistanceToTargetStringInACircularArray.java) | | +| 2520 | [Count the Digits That Divide a Number](https://leetcode.com/problems/count-the-digits-that-divide-a-number) | [![Java](assets/java.png)](src/CountTheDigitsThatDivideANumber.java) | | +| 2525 | [Categorize Box According to Criteria](https://leetcode.com/problems/categorize-box-according-to-criteria) | [![Java](assets/java.png)](src/CategorizeBoxAccordingToCriteria.java) | | +| 2529 | [Maximum Count of Positive Integer and Negative Integer](https://leetcode.com/problems/maximum-count-of-positive-integer-and-negative-integer) | [![Java](assets/java.png)](src/MaximumCountOfPositiveIntegerAndNegativeInteger.java) | | +| 2535 | [Difference Between Element Sum and Digit Sum of an Array](https://leetcode.com/problems/difference-between-element-sum-and-digit-sum-of-an-array) | [![Java](assets/java.png)](src/DifferenceBetweenElementSumAndDigitSumOfAnArray.java) | | +| 2540 | [Minimum Common Value](https://leetcode.com/problems/minimum-common-value) | [![Java](assets/java.png)](src/MinimumCommonValue.java) | | +| 2544 | [Alternating Digit Sum](https://leetcode.com/problems/alternating-digit-sum) | [![Java](assets/java.png)](src/AlternatingDigitSum.java) | | +| 2549 | [Count Distinct Numbers on Board](https://leetcode.com/problems/count-distinct-numbers-on-board) | [![Java](assets/java.png)](src/CountDistinctNumbersOnBoard.java) | | +| 2553 | [Separate the Digits in an Array](https://leetcode.com/problems/separate-the-digits-in-an-array) | [![Java](assets/java.png)](src/SeparateTheDigitsInAnArray.java) | | +| 2558 | [Take Gifts From the Richest Pile](https://leetcode.com/problems/take-gifts-from-the-richest-pile) | [![Java](assets/java.png)](src/TakeGiftsFromTheRichestPile.java) | | +| 2562 | [Find the Array Concatenation Value](https://leetcode.com/problems/find-the-array-concatenation-value) | [![Java](assets/java.png)](src/FindTheArrayConcatenationValue.java) | | +| 2566 | [Maximum Difference by Remapping a Digit](https://leetcode.com/problems/maximum-difference-by-remapping-a-digit) | [![Java](assets/java.png)](src/MaximumDifferenceByRemappingADigit.java) | | +| 2570 | [Merge Two 2D Arrays by Summing Values](https://leetcode.com/problems/merge-two-2d-arrays-by-summing-values) | [![Java](assets/java.png)](src/MergeTwo2DArraysBySummingValues.java) | | +| 2574 | [Left and Right Sum Differences](https://leetcode.com/problems/left-and-right-sum-differences) | [![Java](assets/java.png)](src/LeftAndRightSumDifferences.java) | | +| 2578 | [Split With Minimum Sum](https://leetcode.com/problems/split-with-minimum-sum) | [![Java](assets/java.png)](src/SplitWithMinimumSum.java) | | +| 2582 | [Pass the Pillow](https://leetcode.com/problems/pass-the-pillow) | [![Java](assets/java.png)](src/PassThePillow.java) | | +| 2586 | [Count the Number of Vowel Strings in Range](https://leetcode.com/problems/count-the-number-of-vowel-strings-in-range) | [![Java](assets/java.png)](src/CountTheNumberOfVowelStringsInRange.java) | | +| 2591 | [Distribute Money to Maximum Children](https://leetcode.com/problems/distribute-money-to-maximum-children) | [![Java](assets/java.png)](src/DistributeMoneyToMaximumChildren.java) | | +| 2595 | [Number of Even and Odd Bits](https://leetcode.com/problems/number-of-even-and-odd-bits) | [![Java](assets/java.png)](src/NumberOfEvenAndOddBits.java) | | +| 2600 | [K Items With the Maximum Sum](https://leetcode.com/problems/k-items-with-the-maximum-sum) | [![Java](assets/java.png)](src/KItemsWithTheMaximumSum.java) | | +| 2605 | [Form Smallest Number From Two Digit Arrays](https://leetcode.com/problems/form-smallest-number-from-two-digit-arrays) | [![Java](assets/java.png)](src/FormSmallestNumberFromTwoDigitArrays.java) | | +| 2609 | [Find the Longest Balanced Substring of a Binary String](https://leetcode.com/problems/find-the-longest-balanced-substring-of-a-binary-string) | [![Java](assets/java.png)](src/FindTheLongestBalancedSubstringOfABinaryString.java) | | +| 2614 | [Prime In Diagonal](https://leetcode.com/problems/prime-in-diagonal) | [![Java](assets/java.png)](src/PrimeInDiagonal.java) | | +| 2639 | [Find the Width of Columns of a Grid](https://leetcode.com/problems/find-the-width-of-columns-of-a-grid) | [![Java](assets/java.png)](src/FindTheWidthOfColumnsOfAGrid.java) | | +| 2643 | [Row With Maximum Ones](https://leetcode.com/problems/row-with-maximum-ones) | [![Java](assets/java.png)](src/RowWithMaximumOnes.java) | | +| 2644 | [Find the Maximum Divisibility Score](https://leetcode.com/problems/find-the-maximum-divisibility-score) | [![Java](assets/java.png)](src/FindTheMaximumDivisibilityScore.java) | | +| 2651 | [Calculate Delayed Arrival Time](https://leetcode.com/problems/calculate-delayed-arrival-time) | [![Java](assets/java.png)](src/CalculateDelayedArrivalTime.java) | | +| 2652 | [Sum Multiples](https://leetcode.com/problems/sum-multiples) | [![Java](assets/java.png)](src/SumMultiples.java) | | +| 2656 | [Maximum Sum With Exactly K Elements](https://leetcode.com/problems/maximum-sum-with-exactly-k-elements) | [![Java](assets/java.png)](src/MaximumSumWithExactlyKElements.java) | | +| 2660 | [Determine the Winner of a Bowling Game](https://leetcode.com/problems/determine-the-winner-of-a-bowling-game) | [![Java](assets/java.png)](src/DetermineTheWinnerOfABowlingGame.java) | | +| 2670 | [Find the Distinct Difference Array](https://leetcode.com/problems/find-the-distinct-difference-array) | [![Java](assets/java.png)](src/FindTheDistinctDifferenceArray.java) | | +| 2678 | [Number of Senior Citizens](https://leetcode.com/problems/number-of-senior-citizens) | [![Java](assets/java.png)](src/NumberOfSeniorCitizens.java) | | +| 2682 | [Find the Losers of the Circular Game](https://leetcode.com/problems/find-the-losers-of-the-circular-game) | [![Java](assets/java.png)](src/FindTheLosersOfTheCircularGame.java) | | +| 2696 | [Minimum String Length After Removing Substrings](https://leetcode.com/problems/minimum-string-length-after-removing-substrings) | [![Java](assets/java.png)](src/MinimumStringLengthAfterRemovingSubstrings.java) | | +| 2697 | [Lexicographically Smallest Palindrome](https://leetcode.com/problems/lexicographically-smallest-palindrome) | [![Java](assets/java.png)](src/LexicographicallySmallestPalindrome.java) | | +| 2706 | [Buy Two Chocolates](https://leetcode.com/problems/buy-two-chocolates) | [![Java](assets/java.png)](src/BuyTwoChocolates.java) | | +| 2710 | [Remove Trailing Zeros From a String](https://leetcode.com/problems/remove-trailing-zeros-from-a-string) | [![Java](assets/java.png)](src/RemoveTrailingZerosFromAString.java) | | +| 2716 | [Minimize String Length](https://leetcode.com/problems/minimize-string-length) | [![Java](assets/java.png)](src/MinimizeStringLength.java) | | +| 2717 | [Semi-Ordered Permutation](https://leetcode.com/problems/semi-ordered-permutation) | [![Java](assets/java.png)](src/SemiOrderedPermutation.java) | | +| 2728 | [Count Houses in a Circular Street](https://leetcode.com/problems/count-houses-in-a-circular-street) | | | +| 2729 | [Check if The Number is Fascinating](https://leetcode.com/problems/check-if-the-number-is-fascinating) | [![Java](assets/java.png)](src/CheckIfTheNumberIsFascinating.java) | | +| 2733 | [Neither Minimum nor Maximum](https://leetcode.com/problems/neither-minimum-nor-maximum) | [![Java](assets/java.png)](src/NeitherMinimumNorMaximum.java) | | +| 2739 | [Total Distance Traveled](https://leetcode.com/problems/total-distance-traveled) | [![Java](assets/java.png)](src/TotalDistanceTraveled.java) | | +| 2744 | [Find Maximum Number of String Pairs](https://leetcode.com/problems/find-maximum-number-of-string-pairs) | [![Java](assets/java.png)](src/FindMaximumNumberOfStringPairs.java) | | +| 2748 | [Number of Beautiful Pairs](https://leetcode.com/problems/number-of-beautiful-pairs) | [![Java](assets/java.png)](src/NumberOfBeautifulPairs.java) | | +| 2760 | [Longest Even Odd Subarray With Threshold](https://leetcode.com/problems/longest-even-odd-subarray-with-threshold) | [![Java](assets/java.png)](src/LongestEvenOddSubarrayWithThreshold.java) | | +| 2765 | [Longest Alternating Subarray](https://leetcode.com/problems/longest-alternating-subarray) | [![Java](assets/java.png)](src/LongestAlternatingSubarray.java) | | +| 2769 | [Find the Maximum Achievable Number](https://leetcode.com/problems/find-the-maximum-achievable-number) | [![Java](assets/java.png)](src/FindTheMaximumAchievableNumber.java) | | +| 2778 | [Sum of Squares of Special Elements](https://leetcode.com/problems/sum-of-squares-of-special-elements) | [![Java](assets/java.png)](src/SumOfSquaresOfSpecialElements.java) | | +| 2784 | [Check if Array is Good](https://leetcode.com/problems/check-if-array-is-good) | [![Java](assets/java.png)](src/CheckIfArrayIsGood.java) | | +| 2788 | [Split Strings by Separator](https://leetcode.com/problems/split-strings-by-separator) | [![Java](assets/java.png)](src/SplitStringsBySeparator.java) | | +| 2798 | [Number of Employees Who Met the Target](https://leetcode.com/problems/number-of-employees-who-met-the-target) | | | +| 2806 | [Account Balance After Rounded Purchase](https://leetcode.com/problems/account-balance-after-rounded-purchase) | | | +| 2810 | [Faulty Keyboard](https://leetcode.com/problems/faulty-keyboard) | | | \ No newline at end of file From 1dc56056b6ea87adcaac03c89ed23435d3c084b6 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sun, 20 Aug 2023 15:23:43 +0200 Subject: [PATCH 138/280] f --- README.md | 846 ---------------------- src/HelloWorld.java | 40 +- src/NumberOfEmployeesWhoMetTheTarget.java | 15 + 3 files changed, 47 insertions(+), 854 deletions(-) delete mode 100644 README.md create mode 100644 src/NumberOfEmployeesWhoMetTheTarget.java diff --git a/README.md b/README.md deleted file mode 100644 index b79a7a3..0000000 --- a/README.md +++ /dev/null @@ -1,846 +0,0 @@ -# LeetCode Algorithms - -![problems-solved](https://img.shields.io/badge/Problems%20Solved-682/2813-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-674/2813-1abc9c.svg) -![problems-solved-python](https://img.shields.io/badge/Python-205/2813-1abc9c.svg) -![problems-solved-javascript](https://img.shields.io/badge/JavaScript-4/2813-1abc9c.svg) -[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md) -[![cp](https://img.shields.io/badge/also%20see-Competitve%20Programming-1f72ff.svg)](https://github.com/anishLearnsToCode/competitive-programming) - -🔒 = Subscription Content - -## Problems -| # | Name | Solution | Youtube | -|:----:|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:---------------------------------------------------------------------------------------------------------------------------------:| -| 1 | [Two Sum](https://leetcode.com/problems/two-sum) | [![Java](assets/java.png)](src/TwoSum.java) [![Python](assets/python.png)](python/two_sum.py) | [![java-yt](assets/java-yt.png)](https://youtu.be/9wSL_7NN-A8) [![python-yt](assets/python-yt.png)](https://youtu.be/N5FXCTg0TDE) | -| 2 | [Add Two Numbers](https://leetcode.com/problems/add-two-numbers) | [![Java](assets/java.png)](src/AddTwoNumbers.java) [![js](assets/javascript.png)](javascript/AddTwoNumbers.js) | | -| 3 | [Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters) | [![Java](assets/java.png)](src/LongestSubstringWithoutRepeatingCharacters.java) | | -| 5 | [Longest Palindromic Substring](https://leetcode.com/problems/longest-palindromic-substring) | [![Java](assets/java.png)](src/LongestPalindromicSubstring.java) | | -| 6 | [Zigzag Conversion](https://leetcode.com/problems/zigzag-conversion) | [![Java](assets/java.png)](src/ZigZagConversion.java) | | -| 7 | [Reverse Integer](https://leetcode.com/problems/reverse-integer) | [![Java](assets/java.png)](src/ReverseInteger.java) [![Python](assets/python.png)](python/reverse_integer.py) [![js](assets/javascript.png)](javascript/ReverseInteger.js) | [![java-yt](assets/java-yt.png)](https://youtu.be/7bOhyl5lWjI) [![python-yt](assets/python-yt.png)](https://youtu.be/lmLG30TLcSg) | -| 8 | [String to Integer (atoi)](https://leetcode.com/problems/string-to-integer-atoi) | [![Java](assets/java.png)](src/StringToIntegerAtoi.java) | | -| 9 | [Palindrome Number](https://leetcode.com/problems/palindrome-number) | [![Java](assets/java.png)](src/PalindromeNumber.java) [![Python](assets/python.png)](python/palindrome_number.py) [![js](assets/javascript.png)](javascript/PalindromeNumber.js) | | -| 11 | [Container With Most Water](https://leetcode.com/problems/container-with-most-water) | [![Java](assets/java.png)](src/ContainerWitMostWater.java) | | -| 12 | [Integer to Roman](https://leetcode.com/problems/integer-to-roman) | [![Java](assets/java.png)](src/IntegerToRoman.java) | | -| 13 | [Roman To Integer](https://leetcode.com/problems/roman-to-integer/) | [![Java](assets/java.png)](src/RomanToInteger.java) [![Python](assets/python.png)](python/roman_to_integer.py) | [![java-yt](assets/java-yt.png)](https://youtu.be/BCue_mO_81A) [![python-yt](assets/python-yt.png)](https://youtu.be/8h_yGTNvKMA) | -| 14 | [Longest Common Prefix](https://leetcode.com/problems/longest-common-prefix/) | [![Java](assets/java.png)](src/LongestCommonPrefix.java) [![Python](assets/python.png)](python/longest_common_prefix.py) | | -| 15 | [3Sum](https://leetcode.com/problems/3sum) | [![Java](assets/java.png)](src/ThreeSum.java) | | -| 16 | [3Sum Closest](https://leetcode.com/problems/3sum-closest) | [![Java](assets/java.png)](src/ThreeSumClosest.java) | | -| 17 | [Letter Combinations of a Phone Number](https://leetcode.com/problems/letter-combinations-of-a-phone-number) | [![Java](assets/java.png)](src/LetterCombinationsOfAPhoneNumber.java) | | -| 18 | [4Sum](https://leetcode.com/problems/4sum) | [![Java](assets/java.png)](src/FourSum.java) | | -| 19 | [Remove Nth Node From End of List](https://leetcode.com/problems/remove-nth-node-from-end-of-list) | [![Java](assets/java.png)](src/RemoveNthNodeFromEndOfList.java) | | -| 20 | [ValidParentheses](https://leetcode.com/problems/valid-parentheses/) | [![Java](assets/java.png)](src/ValidParentheses.java) [![Python](assets/python.png)](python/valid_parentheses.py) | | -| 21 | [Merge 2 Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/) | [![Java](assets/java.png)](src/Merge2SortedLists.java) [![Python](assets/python.png)](python/merge_2_sorted_lists.py) | | -| 22 | [Generate Parentheses](https://leetcode.com/problems/generate-parentheses) | [![Java](assets/java.png)](src/GenerateParentheses.java) | | -| 24 | [Swap Nodes in Pairs](https://leetcode.com/problems/swap-nodes-in-pairs) | [![Java](assets/java.png)](src/SwapNodesInPairs.java) | | -| 26 | [Remove Duplicates From Sorted Array](https://leetcode.com/problems/remove-duplicates-from-sorted-array) | [![Java](assets/java.png)](src/RemoveDuplicatesFromSortedArray.java) [![Python](assets/python.png)](python/remove_duplicates_from_sorted_array.py) [![js](assets/javascript.png)](javascript/RemoveDuplicatesFromSortedArray.js) | | -| 27 | [Remove Element](https://leetcode.com/problems/remove-element/) | [![Java](assets/java.png)](src/RemoveElement.java) [![Python](assets/python.png)](python/remove_element.py) | | -| 28 | [Needle in Haystack](https://leetcode.com/problems/implement-strstr) | [![Java](assets/java.png)](src/NeedleInHaystack.java) [![Python](assets/python.png)](python/needle_in_haystack.py) | | -| 29 | [Divide Two Integers](https://leetcode.com/problems/divide-two-integers) | [![Java](assets/java.png)](src/DivideTwoIntegers.java) | | -| 31 | [Next Permutation](https://leetcode.com/problems/next-permutation) | [![Java](assets/java.png)](src/NextPermutation.java) | | -| 33 | [Search in Rotated Sorted Array](https://leetcode.com/problems/search-in-rotated-sorted-array) | [![Java](assets/java.png)](src/SearchInRotatedSortedArray.java) | | -| 34 | [Find First and Last Position of Element in Sorted Array](https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array) | [![Java](assets/java.png)](src/FindFirstAndLastPositionOfElementInSortedArray.java) | | -| 35 | [Search Inserted Position](https://leetcode.com/problems/search-insert-position/) | [![Java](assets/java.png)](src/SearchInsertPosition.java) [![Python](assets/python.png)](python/search_insert_position.py) | | -| 36 | [Valid Sudoku](https://leetcode.com/problems/valid-sudoku) | [![Java](assets/java.png)](src/ValidSudoku.java) | | -| 37 | [Sudoku Solver](https://leetcode.com/problems/sudoku-solver) | [![Java](assets/java.png)](src/SudokuSolver.java) | | -| 38 | [Count and Say](https://leetcode.com/problems/count-and-say) | [![Java](assets/java.png)](src/CountAndSay.java) [![Python](assets/python.png)](python/count_and_say.py) | | -| 39 | [Combination Sum](https://leetcode.com/problems/combination-sum) | [![Java](assets/java.png)](src/CombinationSum.java) | | -| 40 | [Combination Sum II](https://leetcode.com/problems/combination-sum-ii) | [![Java](assets/java.png)](src/CombinationSumII.java) | | -| 42 | [Trapping Rain Water](https://leetcode.com/problems/trapping-rain-water) | [![Java](assets/java.png)](src/TrappingRainwater.java) | | -| 43 | [Multiply Strings](https://leetcode.com/problems/multiply-strings) | [![Java](assets/java.png)](src/MultiplyStrings.java) | | -| 45 | [Jump Game II](https://leetcode.com/problems/jump-game-ii) | [![Java](assets/java.png)](src/JumpGameII.java) | | -| 46 | [Permutations](https://leetcode.com/problems/permutations) | [![Java](assets/java.png)](src/Permutations.java) | | -| 47 | [Permutations II](https://leetcode.com/problems/permutations-ii) | [![Java](assets/java.png)](src/PermutationsII.java) | | -| 48 | [Rotate Image](https://leetcode.com/problems/rotate-image) | [![Java](assets/java.png)](src/RotateImage.java) | | -| 49 | [Group Anagrams](https://leetcode.com/problems/group-anagrams) | [![Java](assets/java.png)](src/GroupAnagrams.java) | | -| 50 | [Pow(x,n)](https://leetcode.com/problems/powx-n) | [![Java](assets/java.png)](src/Powxn.java) | | -| 53 | [Maximum SubArray](https://leetcode.com/problems/maximum-subarray) | [![Java](assets/java.png)](src/MaximumSubArray.java) [![Python](assets/python.png)](python/maximum_sum_subarray.py) | | -| 54 | [Spiral Matrix](https://leetcode.com/problems/spiral-matrix) | [![Java](assets/java.png)](src/SpiralMatrix.java) | | -| 55 | [Jump Game](https://leetcode.com/problems/jump-game) | [![Java](assets/java.png)](src/JumpGame.java) | | -| 56 | [Merge Intervals](https://leetcode.com/problems/merge-intervals) | [![Java](assets/java.png)](src/MergeIntervals.java) | | -| 57 | [Insert Interval](https://leetcode.com/problems/insert-interval) | [![Java](assets/java.png)](src/InsertInterval.java) | | -| 58 | [Length of Last Word](https://leetcode.com/problems/length-of-last-word) | [![Java](assets/java.png)](src/LengthOfLastWord.java) [![Python](assets/python.png)](python/length_of_last_word.py) | | -| 59 | [Spiral Matrix II](https://leetcode.com/problems/spiral-matrix-ii) | [![Java](assets/java.png)](src/SpiralMatrixII.java) | | -| 61 | [Rotate List](https://leetcode.com/problems/rotate-list) | [![Java](assets/java.png)](src/RotateList.java) | | -| 62 | [Unique Paths](https://leetcode.com/problems/unique-paths) | [![Java](assets/java.png)](src/UniquePaths.java) | | -| 63 | [Unique Paths II](https://leetcode.com/problems/unique-paths-ii) | [![Java](assets/java.png)](src/UniquePathII.java) | | -| 64 | [Minimum Path Sum](https://leetcode.com/problems/minimum-path-sum) | [![Java](assets/java.png)](src/MinimumPathSum.java) [![Python](assets/python.png)](python/minimum_path_sum.py) | | -| 66 | [Plus One](https://leetcode.com/problems/plus-one) | [![Java](assets/java.png)](src/PlusOne.java) [![Python](assets/python.png)](python/plus_one.py) | | -| 67 | [Add Binary](https://leetcode.com/problems/add-binary) | [![Java](assets/java.png)](src/AddBinary.java) [![Python](assets/python.png)](python/add_binary.py) | | -| 69 | [Sqrt(x)](https://leetcode.com/problems/sqrtx) | [![Java](assets/java.png)](src/Sqrtx.java) [![Python](assets/python.png)](python/sqrt.py) | | -| 70 | [Climbing Stairs](https://leetcode.com/problems/climbing-stairs) | [![Java](assets/java.png)](src/ClimbingStairs.java) [![Python](assets/python.png)](python/climbing_stairs.py) | | -| 71 | [Simplify Path](https://leetcode.com/problems/simplify-path) | [![Java](assets/java.png)](src/SimplifyPath.java) | | -| 73 | [Set Matrix Zeroes](https://leetcode.com/problems/set-matrix-zeroes) | [![Java](assets/java.png)](src/SetMatrixZeroes.java) | | -| 74 | [Search a 2D Matrix](https://leetcode.com/problems/search-a-2d-matrix) | [![Java](assets/java.png)](src/SearchA2DMatrix.java) | | -| 75 | [Sort Colors](https://leetcode.com/problems/sort-colors) | [![Java](assets/java.png)](src/SortColors.java) | | -| 77 | [Combinations](https://leetcode.com/problems/combinations) | [![Java](assets/java.png)](src/Combinations.java) | | -| 78 | [Subsets](https://leetcode.com/problems/subsets) | [![Java](assets/java.png)](src/Subsets.java) | | -| 79 | [Word Search](https://leetcode.com/problems/word-search) | [![Java](assets/java.png)](src/WordSearch.java) | | -| 80 | [Remove Duplicates from Sorted Array II](https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii) | [![Java](assets/java.png)](src/RemoveDuplicatesFromSortedArrayII.java) | | -| 81 | [Search in Rotated Sorted Array II](https://leetcode.com/problems/search-in-rotated-sorted-array-ii) | [![Java](assets/java.png)](src/SearchInRotatedSortedArrayII.java) | | -| 82 | [Remove Duplicates from Sorted List II](https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii) | [![Java](assets/java.png)](src/RemoveDuplicatesFromSortedListII.java) | | -| 83 | [Remove Duplicates from Sorted List](https://leetcode.com/problems/remove-duplicates-from-sorted-list) | [![Java](assets/java.png)](src/RemoveDuplicatesFromSortedList.java) [![Python](assets/python.png)](python/remove_duplicates_from_linked_list.py) | | -| 86 | [Partition List](https://leetcode.com/problems/partition-list) | [![Java](assets/java.png)](src/PartitionList.java) | | -| 87 | [Scramble String](https://leetcode.com/problems/scramble-string) | [![Python](assets/python.png)](python/scramble_strings.py) | | -| 88 | [Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array) | [![Java](assets/java.png)](src/MergeSortedArray.java) [![Python](assets/python.png)](python/merge_sorted_array.py) | | -| 89 | [Gray Code](https://leetcode.com/problems/gray-code) | [![Java](assets/java.png)](src/GrayCode.java) | | -| 90 | [Subsets II](https://leetcode.com/problems/subsets-ii) | [![Java](assets/java.png)](src/SubsetsII.java) | | -| 91 | [Decode Ways](https://leetcode.com/problems/decode-ways) | [![Java](assets/java.png)](src/DecodeWays.java) | | -| 92 | [Reverse Linked List II](https://leetcode.com/problems/reverse-linked-list-ii) | [![Java](assets/java.png)](src/ReverseLinkedListII.java) | | -| 93 | [Restore IP Addresses](https://leetcode.com/problems/restore-ip-addresses) | [![Java](assets/java.png)](src/RestoreIPAddresses.java) | | -| 94 | [Binary Tree Inorder Traversal](https://leetcode.com/problems/binary-tree-inorder-traversal) | [![Java](assets/java.png)](src/BinaryTreeInorderTraversal.java) [![Python](assets/python.png)](python/binary_tree_inorder_traversal.py) | | -| 95 | [Unique Binary Search Trees II](https://leetcode.com/problems/unique-binary-search-trees-ii) | [![Java](assets/java.png)](src/UniqueBinarySearchTreesII.java) | | -| 96 | [Unique Binary Search Trees](https://leetcode.com/problems/unique-binary-search-trees) | [![Java](assets/java.png)](src/UniqueBinarySearchTrees.java) | | -| 97 | [Interleaving String](https://leetcode.com/problems/interleaving-string) | [![Java](assets/java.png)](src/InterleavingString.java) | | -| 98 | [Validate Binary Search Tree](https://leetcode.com/problems/validate-binary-search-tree) | [![Java](assets/java.png)](src/ValidateBinarySearchTree.java) | | -| 99 | [Recover Binary Search Tree](https://leetcode.com/problems/recover-binary-search-tree) | [![Java](assets/java.png)](src/RecoverBinarySearchTree.java) | | -| 100 | [Same Tree](https://leetcode.com/problems/same-tree) | [![Java](assets/java.png)](src/SameTree.java) [![Python](assets/python.png)](python/same_tree.py) | | -| 101 | [Symmetric Tree](https://leetcode.com/problems/symmetric-tree) | [![Java](assets/java.png)](src/SymmetricTree.java) [![Python](assets/python.png)](python/symmetric_tree.py) | | -| 102 | [Binary Tree Level Order Traversal](https://leetcode.com/problems/binary-tree-level-order-traversal) | [![Java](assets/java.png)](src/BinaryTreeLevelOrderTraversal.java) | | -| 103 | [Binary Tree Zigzag Level Order Traversal](https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal) | [![Java](assets/java.png)](src/BinaryTreeZigzagLevelOrderTraversal.java) | | -| 104 | [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree) | [![Java](assets/java.png)](src/MaximumDepthOfBinaryTree.java) [![Python](assets/python.png)](python/maximum_depth_of_binary_tree.py) | | -| 105 | [Construct Binary Tree from Preorder and Inorder Traversal](https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal) | [![Java](assets/java.png)](src/ConstructBinaryTreeFromPreorderAndInorderTraversal.java) | | -| 106 | [Construct Binary Tree from Inorder and Postorder Traversal](https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal) | [![Java](assets/java.png)](src/ConstructBinaryTreeFromInorderAndPostorderTraversal.java) | | -| 107 | [Binary Tree Level Order Traversal II](https://leetcode.com/problems/binary-tree-level-order-traversal-ii) | [![Java](assets/java.png)](src/BinaryTreeLevelOrderTraversalII.java) [![Python](assets/python.png)](python/binary_tree_level_order_traversal_ii.py) | | -| 108 | [Convert Sorted Array To Binary Search Tree](https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree) | [![Java](assets/java.png)](src/ConvertSortedArrayToBinarySearchTree.java) [![Python](assets/python.png)](python/converted_sorted_array_to_binary_search_tree.py) | | -| 109 | [Convert Sorted List to Binary Search Tree](https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree) | [![Java](assets/java.png)](src/ConvertSortedListToBinarySearchTree.java) | | -| 110 | [Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree) | [![Java](assets/java.png)](src/BalancedBinaryTree.java) [![Python](assets/python.png)](python/balanced_binary_tree.py) | | -| 111 | [Minimum Depth of Binary Tree](https://leetcode.com/problems/minimum-depth-of-binary-tree) | [![Java](assets/java.png)](src/MinimumDepthOfBinaryTree.java) [![Python](assets/python.png)](python/minimum_depth_of_binary_tree.py) | | -| 112 | [Path Sum](https://leetcode.com/problems/path-sum) | [![Java](assets/java.png)](src/PathSum.java) [![Python](assets/python.png)](python/path_sum.py) | | -| 113 | [Path Sum II](https://leetcode.com/problems/path-sum-ii) | [![Java](assets/java.png)](src/PathSumII.java) | | -| 114 | [Flatten Binary Tree to Linked List](https://leetcode.com/problems/flatten-binary-tree-to-linked-list) | [![Java](assets/java.png)](src/FlattenBinaryTreeToLinkedList.java) | | -| 116 | [Populating Next Right Pointers in Each Node](https://leetcode.com/problems/populating-next-right-pointers-in-each-node) | [![Java](assets/java.png)](src/PopulatingNextRightPointersInEachNode.java) | | -| 117 | [Populating Next Right Pointers in Each Node II](https://leetcode.com/problems/populating-next-right-pointers-in-each-node-ii) | [![Java](assets/java.png)](src/PopulatingNextRightPointersInEachNodeII.java) | | -| 118 | [Pascal's Triangle](https://leetcode.com/problems/pascals-triangle) | [![Java](assets/java.png)](src/PascalsTriangle.java) [![Python](assets/python.png)](python/pascals_triangle.py) | | -| 119 | [Pascal's Triangle II](https://leetcode.com/problems/pascals-triangle-ii) | [![Java](assets/java.png)](src/PascalsTriangleII.java) [![Python](assets/python.png)](python/pascals_triangle_ii.py) | | -| 120 | [Triangle](https://leetcode.com/problems/triangle) | [![Java](assets/java.png)](src/Triangle.java) | | -| 121 | [Best Time to Buy and Sell Stocks](https://leetcode.com/problems/best-time-to-buy-and-sell-stock) | [![Java](assets/java.png)](src/BestTimeToBuyAndSellStock.java) [![Python](assets/python.png)](python/best_time_to_buy_and_sell_stock.py) | | -| 122 | [Best Time to Buy and Sell Stocks II](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii) | [![Java](assets/java.png)](src/BestTimeToBuyAndSellStockII.java) [![Python](assets/python.png)](python/best_time_to_buy_and_sell_stock_ii.py) | | -| 125 | [Valid Palindrome](https://leetcode.com/problems/valid-palindrome) | [![Java](assets/java.png)](src/ValidPalindrome.java) [![Python](assets/python.png)](python/valid_palindrome.py) | | -| 128 | [Longest Consecutive Sequence](https://leetcode.com/problems/longest-consecutive-sequence) | [![Java](assets/java.png)](src/LongestConsecutiveSequence.java) | | -| 129 | [Sum Root to Leaf Numbers](https://leetcode.com/problems/sum-root-to-leaf-numbers) | [![Java](assets/java.png)](src/SumRootToLeafNumbers.java) | | -| 130 | [Surrounded Regions](https://leetcode.com/problems/surrounded-regions) | [![Java](assets/java.png)](src/SurroundedRegions.java) | | -| 131 | [Palindrome Partitioning](https://leetcode.com/problems/palindrome-partitioning) | [![Java](assets/java.png)](src/PalindromePartitioning.java) | | -| 133 | [Clone Graph](https://leetcode.com/problems/clone-graph) | [![Java](assets/java.png)](src/CloneGraph.java) [![Python](assets/python.png)](python/clone_graph.py) | | -| 134 | [Gas Station](https://leetcode.com/problems/gas-station) | [![Java](assets/java.png)](src/GasStation.java) | | -| 136 | [Single Number](https://leetcode.com/problems/single-number) | [![Java](assets/java.png)](src/SingleNumber.java) [![Python](assets/python.png)](python/single_number.py) | | -| 137 | [Single Number II](https://leetcode.com/problems/single-number-ii) | [![Java](assets/java.png)](src/SingleNumberII.java) | | -| 138 | [Copy List with Random Pointer](https://leetcode.com/problems/copy-list-with-random-pointer) | [![Java](assets/java.png)](src/CopyListWithRandomPointer.java) | | -| 139 | [Word Break](https://leetcode.com/problems/word-break) | [![Java](assets/java.png)](src/WordBreak.java) | | -| 141 | [Linked List Cycle](https://leetcode.com/problems/linked-list-cycle) | [![Java](assets/java.png)](src/LinkedListCycle.java) [![Python](assets/python.png)](python/linked_list_cycle.py) | | -| 142 | [Linked List Cycle II](https://leetcode.com/problems/linked-list-cycle-ii) | [![Java](assets/java.png)](src/LinkedListCycleII.java) | | -| 143 | [Reorder List](https://leetcode.com/problems/reorder-list) | [![Java](assets/java.png)](src/ReorderList.java) | | -| 144 | [Binary Tree Preorder Traversal](https://leetcode.com/problems/binary-tree-preorder-traversal) | [![Java](assets/java.png)](src/BinaryTreePreOrderTraversal.java) [![Python](assets/python.png)](python/binary_tree_preorder_traversal.py) | | -| 145 | [Binary Tree Postorder Traversal](https://leetcode.com/problems/binary-tree-postorder-traversal) | [![Java](assets/java.png)](src/BinaryTreePostorderTraversal.java) [![Python](assets/python.png)](python/binary_tree_postorder_traversal.py) | | -| 146 | [LRU Cache](https://leetcode.com/problems/lru-cache) | [![Java](assets/java.png)](src/LRUCache.java) | | -| 147 | [Insertion Sort List](https://leetcode.com/problems/insertion-sort-list) | [![Java](assets/java.png)](src/InsertionSortList.java) | | -| 148 | [Sort List](https://leetcode.com/problems/sort-list) | [![Java](assets/java.png)](src/SortList.java) | | -| 150 | [Evaluate Reverse Polish Notation](https://leetcode.com/problems/evaluate-reverse-polish-notation) | [![Java](assets/java.png)](src/EvaluateReversePolishNotation.java) | | -| 151 | [Reverse Words in a String](https://leetcode.com/problems/reverse-words-in-a-string) | [![Java](assets/java.png)](src/ReverseWordsInAString.java) | | -| 152 | [Maximum Product Subarray](https://leetcode.com/problems/maximum-product-subarray) | [![Java](assets/java.png)](src/MaximumProductSubarray.java) | | -| 153 | [Find Minimum in Rotated Sorted Array](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array) | [![Java](assets/java.png)](src/FindMinimumInRotatedSortedArray.java) | | -| 155 | [Min Stack](https://leetcode.com/problems/min-stack) | [![Java](assets/java.png)](src/MinStack.java) [![Python](assets/python.png)](python/min_stack.py) | | -| 156 | 🔒 [Binary Tree Upside Down](https://leetcode.com/problems/binary-tree-upside-down) | | | -| 157 | [Read N Characters Given Read4](https://leetcode.com/problems/read-n-characters-given-read4) | | | -| 159 | 🔒 [Longest Substring With At Most Two Distinct Characters](https://leetcode.com/problems/longest-substring-with-at-most-two-distinct-characters) | | | -| 160 | [Intersection of Two Linked Lists](https://leetcode.com/problems/intersection-of-two-linked-lists) | [![Java](assets/java.png)](src/IntersectionOf2LinkedLists.java) [![Python](assets/python.png)](python/intersecction_of_two_linked_lists.py) | | -| 161 | 🔒 [One Edit Distance](https://leetcode.com/problems/one-edit-distance) | | | -| 162 | [Find Peak Element](https://leetcode.com/problems/find-peak-element) | [![Java](assets/java.png)](src/FindPeakElement.java) | | -| 165 | [Compare Version Numbers](https://leetcode.com/problems/compare-version-numbers) | [![Java](assets/java.png)](src/CompareVersionNumbers.java) | | -| 166 | [Fraction to Recurring Decimal](https://leetcode.com/problems/fraction-to-recurring-decimal) | [![Java](assets/java.png)](src/FractionToRecurringDecimal.java) | | -| 167 | [Two Sum II - Input Array is Sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted) | [![Java](assets/java.png)](src/TwoSumIIInputArrayIsSorted.java) [![Python](assets/python.png)](python/two_sum_ii.py) | | -| 168 | [Excel Sheet Column Title](https://leetcode.com/problems/excel-sheet-column-title) | [![Java](assets/java.png)](src/ExcelSheetColumnTitle.java) [![Python](assets/python.png)](python/excel_sheet_column_title.py) | | -| 169 | [Majority Element](https://leetcode.com/problems/majority-element) | [![Java](assets/java.png)](src/MajorityElement.java) [![Python](assets/python.png)](python/majority_element.py) | | -| 170 | 🔒 [Two Sum III - Data Structure Design](https://leetcode.com/problems/two-sum-iii-data-structure-design) | | | -| 171 | [Excel Sheet Column Number](https://leetcode.com/problems/excel-sheet-column-number) | [![Java](assets/java.png)](src/ExcelSheetColumnNumber.java) [![Python](assets/python.png)](python/excel_sheet_column_number.py) | | -| 172 | [Factoring Trailing Zeroes](https://leetcode.com/problems/factorial-trailing-zeroes) | [![Java](assets/java.png)](src/FactorialTrailingZeros.java) [![Python](assets/python.png)](python/factorial_trailing_zeroes.py) | | -| 173 | [Binary Search Tree Iterator](https://leetcode.com/problems/binary-search-tree-iterator) | [![Java](assets/java.png)](src/BinarySearchTreeIterator.java) | | -| 179 | [Largest Number](https://leetcode.com/problems/largest-number) | [![Java](assets/java.png)](src/LargestNumber.java) | | -| 187 | [Repeated DNA Sequences](https://leetcode.com/problems/repeated-dna-sequences) | [![Java](assets/java.png)](src/RepeatedDNASequences.java) | | -| 189 | [Rotate Array](https://leetcode.com/problems/rotate-array) | [![Java](assets/java.png)](src/RotateArray.java) [![Python](assets/python.png)](python/rotate_array.py) | | -| 190 | [Reverse Bits](https://leetcode.com/problems/reverse-bits) | [![Java](assets/java.png)](src/ReverseBits.java) [![Python](assets/python.png)](python/reverse_bits.py) | | -| 191 | [Number of One Bits](https://leetcode.com/problems/number-of-1-bits) | [![Java](assets/java.png)](src/NumberOf1Bit.java) [![Python](assets/python.png)](python/number_of_1_bits.py) | | -| 198 | [House Robber](https://leetcode.com/problems/house-robber) | [![Java](assets/java.png)](src/HouseRobber.java) [![Python](assets/python.png)](python/house_robber.py) | | -| 199 | [Binary Tree Right Side View](https://leetcode.com/problems/binary-tree-right-side-view) | [![Java](assets/java.png)](src/BinaryTreeRightSideView.java) | | -| 200 | [Number of Islands](https://leetcode.com/problems/number-of-islands) | [![Java](assets/java.png)](src/NumberOfIslands.java) [![Python](assets/python.png)](python/number_of_islands.py) | | -| 201 | [Bitwise AND of Numbers Range](https://leetcode.com/problems/bitwise-and-of-numbers-range) | [![Java](assets/java.png)](src/BitwiseANDOfNumbersRange.java) | | -| 202 | [Happy Number](https://leetcode.com/problems/happy-number) | [![Java](assets/java.png)](src/HappyNumber.java) [![Python](assets/python.png)](python/happy_number.py) | | -| 203 | [Remove Linked List Elements](https://leetcode.com/problems/remove-linked-list-elements) | [![Java](assets/java.png)](src/RemoveLinkedListElements.java) [![Python](assets/python.png)](python/remove_linked_list_elements.py) | | -| 204 | [Count Primes](https://leetcode.com/problems/count-primes) | [![Java](assets/java.png)](src/CountPrimes.java) [![Python](assets/python.png)](python/count_primes.py) | | -| 205 | [Isomorphic Strings](https://leetcode.com/problems/isomorphic-strings) | [![Java](assets/java.png)](src/IsomorphicStrings.java) [![Python](assets/python.png)](python/isomorphic_strings.py) | | -| 206 | [Reverse Linked List](https://leetcode.com/problems/reverse-linked-list) | [![Java](assets/java.png)](src/ReverseLinkedList.java) [![Python](assets/python.png)](python/reverse_linked_list.py) | | -| 207 | [Course Schedule](https://leetcode.com/problems/course-schedule) | [![Java](assets/java.png)](src/CourseSchedule.java) | | -| 208 | [Implement Trie (Prefix Tree)](https://leetcode.com/problems/implement-trie-prefix-tree) | [![Java](assets/java.png)](src/Trie.java) [![Python](assets/python.png)](python/trie.py) | | -| 209 | [Minimum Size Subarray Sum](https://leetcode.com/problems/minimum-size-subarray-sum) | [![Java](assets/java.png)](src/MinimumSizeSubarraySum.java) | | -| 210 | [Course Schedule II](https://leetcode.com/problems/course-schedule-ii) | [![Java](assets/java.png)](src/CourseScheduleII.java) | | -| 211 | [Design Add and Search Words Data Structure](https://leetcode.com/problems/design-add-and-search-words-data-structure) | [![Java](assets/java.png)](src/DesignAddAndSearchWordsDataStructure.java) [![Python](assets/python.png)](python/design_add_and_search_words_data_structure.py) | | -| 213 | [House Robber II](https://leetcode.com/problems/house-robber-ii) | [![Java](assets/java.png)](src/HouseRobberII.java) | | -| 215 | [Kth Largest Element in an Array](https://leetcode.com/problems/kth-largest-element-in-an-array) | [![Java](assets/java.png)](src/KthLargestElementInAnArray.java) | | -| 216 | [Combination Sum III](https://leetcode.com/problems/combination-sum-iii) | [![Java](assets/java.png)](src/CombinationSumIII.java) | | -| 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate) | [![Java](assets/java.png)](src/ContainsDuplicate.java) [![Python](assets/python.png)](python/contains_duplicate.py) | | -| 218 | [The Skyline Problem](https://leetcode.com/problems/the-skyline-problem) | [![Python](assets/python.png)](python/the_skyline_problem.py) | | -| 219 | [Contains Duplicate II](https://leetcode.com/problems/contains-duplicate-ii) | [![Java](assets/java.png)](src/ContainsDuplicateII.java) [![Python](assets/python.png)](python/contains_duplicate_ii.py) | | -| 220 | [Contains Duplicate III](https://leetcode.com/problems/contains-duplicate-iii) | [![Java](assets/java.png)](src/ContainsDuplicateIII.java) | | -| 221 | [Maximal Square](https://leetcode.com/problems/maximal-square) | [![Java](assets/java.png)](src/MaximalSquare.java) | | -| 222 | [Count Complete Tree Nodes](https://leetcode.com/problems/count-complete-tree-nodes) | [![Java](assets/java.png)](src/CountCompleteTreeNodes.java) | | -| 223 | [Rectangle Area](https://leetcode.com/problems/rectangle-area) | [![Java](assets/java.png)](src/RectangleArea.java) | | -| 225 | [Implement Stack using Queues](https://leetcode.com/problems/implement-stack-using-queues) | [![Java](assets/java.png)](src/MyStack.java) [![Python](assets/python.png)](python/implement_stack_using_queues.py) | | -| 226 | [Invert Binary Tree](https://leetcode.com/problems/invert-binary-tree) | [![Java](assets/java.png)](src/InvertBinaryTree.java) [![Python](assets/python.png)](python/invert_binary_tree.py) | | -| 227 | [Basic Calculator II](https://leetcode.com/problems/basic-calculator-ii) | [![Java](assets/java.png)](src/BasicCalculatorII.java) | | -| 229 | [Majority Element II](https://leetcode.com/problems/majority-element-ii) | [![Java](assets/java.png)](src/MajorityElementII.java) | | -| 230 | [Kth Smallest Element in a BST](https://leetcode.com/problems/kth-smallest-element-in-a-bst) | [![Java](assets/java.png)](src/KthSmallestElementInABST.java) | | -| 231 | [Power of Two](https://leetcode.com/problems/power-of-two) | [![Java](assets/java.png)](src/PowerOf2.java) [![Python](assets/python.png)](python/is_power_of_2.py) | | -| 232 | [Implement Queue Using Stacks](https://leetcode.com/problems/implement-queue-using-stacks) | [![Java](assets/java.png)](src/MyQueue.java) [![Python](assets/python.png)](python/implement_queue_using_stacks.py) | | -| 234 | [Palindrome Linked Lists](https://leetcode.com/problems/palindrome-linked-list) | [![Java](assets/java.png)](src/PalindromeLinkedList.java) [![Python](assets/python.png)](python/palindrome_linked_list.py) | | -| 235 | [Lowest Common Ancestor of a Binary Search Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree) | [![Java](assets/java.png)](src/LowestCommonAncestorOfBinarySearchTree.java) [![Python](assets/python.png)](python/lowest_common_ancestor_of_bst.py) | | -| 236 | [Lowest Common Ancestor of a Binary Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree) | [![Java](assets/java.png)](src/LowestCommonAncestorOfBinaryTree.java) | | -| 237 | [Delete a Node In A Linked List](https://leetcode.com/problems/delete-node-in-a-linked-list) | [![Java](assets/java.png)](src/DeleteANodeInLinkedList.java) [![Python](assets/python.png)](python/delete_node_in_linked_list.py) | | -| 238 | [Product of Array Except Self](https://leetcode.com/problems/product-of-array-except-self) | [![Java](assets/java.png)](src/ProductOfArrayExceptItself.java) | | -| 240 | [Search a 2D Matrix II](https://leetcode.com/problems/search-a-2d-matrix-ii) | [![Java](assets/java.png)](src/SearchA2DMatrixII.java) | | -| 241 | [Different Ways to Add Parentheses](https://leetcode.com/problems/different-ways-to-add-parentheses) | | | -| 242 | [Valid Anagram](https://leetcode.com/problems/valid-anagram) | [![Java](assets/java.png)](src/ValidAnagram.java) [![Python](assets/python.png)](python/delete_node_in_linked_list.py) | | -| 243 | 🔒 [Shortest Word Distance](https://leetcode.com/problems/shortest-word-distance) | | | -| 244 | 🔒 [Shortest Word Distance II](https://leetcode.com/problems/shortest-word-distance-ii) | | | -| 245 | 🔒 [Shortest Word Distance III](https://leetcode.com/problems/shortest-word-distance-iii) | | | -| 246 | 🔒 [Strobogramatic Number](https://leetcode.com/problems/strobogrammatic-number) | | | -| 247 | 🔒 [Strobogramatic Number II](https://leetcode.com/problems/strobogrammatic-number-ii) | | | -| 249 | 🔒 [Group Shifted Strings](https://leetcode.com/problems/group-shifted-strings) | | | -| 250 | 🔒 [Count Univalue Subtrees](https://leetcode.com/problems/count-univalue-subtrees) | | | -| 251 | 🔒 [Flatten 2D Vector](https://leetcode.com/problems/flatten-2d-vector) | | | -| 252 | 🔒 [Meeting Rooms](https://leetcode.com/problems/meeting-rooms) | | | -| 253 | 🔒 [Meeting Rooms II](https://leetcode.com/problems/meeting-rooms-ii) | | | -| 254 | 🔒 [Factor Combinations](https://leetcode.com/problems/factor-combinations) | | | -| 255 | 🔒 [Verify Preorder Sequence In Binary Search Tree](https://leetcode.com/problems/verify-preorder-sequence-in-binary-search-tree) | | | -| 256 | 🔒 [Paint House](https://leetcode.com/problems/paint-house) | | | -| 257 | [Binary Tree Paths](https://leetcode.com/problems/binary-tree-paths) | [![Java](assets/java.png)](src/BinaryTreePaths.java) [![Python](assets/python.png)](python/binary_tree_paths.py) | | -| 258 | [Add Digits](https://leetcode.com/problems/add-digits) | [![Java](assets/java.png)](src/AddDigits.java) [![Python](assets/python.png)](python/add_digits.py) | | -| 259 | 🔒 [3Sum Smaller](https://leetcode.com/problems/3sum-smaller) | | | -| 260 | [Single Number III](https://leetcode.com/problems/single-number-iii) | [![Java](assets/java.png)](src/SingleNumberIII.java) | | -| 261 | 🔒 [Graph Valid Tree](https://leetcode.com/problems/graph-valid-tree) | | | -| 263 | [Ugly Number](https://leetcode.com/problems/ugly-number) | [![Java](assets/java.png)](src/UglyNumber.java) [![Python](assets/python.png)](python/ugly_number.py) | | -| 264 | [Ugly Number II](https://leetcode.com/problems/ugly-number-ii) | [![Java](assets/java.png)](src/UglyNumberII.java) | | -| 266 | 🔒 [Palindrome Permutation](https://leetcode.com/problems/palindrome-permutation) | | | -| 267 | 🔒 [Palindrome Permutation II](https://leetcode.com/problems/palindrome-permutation-ii) | | | -| 268 | [Missing Number](https://leetcode.com/problems/missing-number) | [![Java](assets/java.png)](src/MissingNumber.java) [![Python](assets/python.png)](python/missing_number.py) | | -| 270 | 🔒 [Closest Binary Search Tree Value](https://leetcode.com/problems/closest-binary-search-tree-value) | | | -| 271 | 🔒 [Encode and Decode Strings](https://leetcode.com/problems/encode-and-decode-strings) | | | -| 274 | [H-Index](https://leetcode.com/problems/h-index) | [![Java](assets/java.png)](src/HIndex.java) | | -| 275 | [H-Index II](https://leetcode.com/problems/h-index-ii) | [![Java](assets/java.png)](src/HIndexII.java) | | -| 276 | 🔒 [Paint Fence](https://leetcode.com/problems/paint-fence) | | | -| 277 | 🔒 [Find The Celebrity](https://leetcode.com/problems/find-the-celebrity) | | | -| 278 | [First Bad Version](https://leetcode.com/problems/first-bad-version) | [![Java](assets/java.png)](src/FirstBadVersion.java) [![Python](assets/python.png)](python/first_bad_version.py) | | -| 279 | [Perfect Squares](https://leetcode.com/problems/perfect-squares) | [![Java](assets/java.png)](src/PerfectSquares.java) | | -| 280 | 🔒 [Wiggle Sort](https://leetcode.com/problems/wiggle-sort) | | | -| 281 | 🔒 [Zigzag Iterator](https://leetcode.com/problems/zigzag-iterator) | | | -| 283 | [Move Zeroes](https://leetcode.com/problems/move-zeroes) | [![Java](assets/java.png)](src/MoveZeros.java) [![Python](assets/python.png)](python/move_zeroes.py) | | -| 284 | [Peeking Iterator](https://leetcode.com/problems/peeking-iterator) | [![Java](assets/java.png)](src/PeekingIterator.java) | | -| 285 | 🔒 [Inorder Successor in BST](https://leetcode.com/problems/inorder-successor-in-bst) | | | -| 286 | 🔒 [Walls and Gates](https://leetcode.com/problems/walls-and-gates) | | | -| 287 | [Find the Duplicate Number](https://leetcode.com/problems/find-the-duplicate-number) | [![Java](assets/java.png)](src/FindTheDuplicateNumber.java) | | -| 288 | 🔒 [Unique Word Abbreviation](https://leetcode.com/problems/unique-word-abbreviation) | | | -| 289 | [Game of Life](https://leetcode.com/problems/game-of-life) | | | -| 290 | [Word Pattern](https://leetcode.com/problems/word-pattern) | [![Java](assets/java.png)](src/WordPattern.java) [![Python](assets/python.png)](python/word_pattern.py) | | -| 291 | 🔒 [Word Pattern II](https://leetcode.com/problems/word-pattern-ii) | | | -| 292 | [Nim Game](https://leetcode.com/problems/nim-game) | [![Java](assets/java.png)](src/NimGame.java) [![Python](assets/python.png)](python/nim_game.py) | | -| 293 | 🔒 [Flip Game](https://leetcode.com/problems/flip-game) | | | -| 294 | 🔒 [Flip Game II](https://leetcode.com/problems/flip-game-ii) | | | -| 298 | 🔒 [Binary Tree Longest Consecutive Sequence](https://leetcode.com/problems/binary-tree-longest-consecutive-sequence) | | | -| 299 | [Bulls and Cows](https://leetcode.com/problems/bulls-and-cows) | [![Java](assets/java.png)](src/BullsAndCows.java) [![Python](assets/python.png)](python/bulls_and_cows.py) | | -| 300 | [Longest Increasing Subsequence](https://leetcode.com/problems/longest-increasing-subsequence) | | | -| 303 | [Range Sum Query - Immutable](https://leetcode.com/problems/range-sum-query-immutable) | [![Java](assets/java.png)](src/RangeSumQueryImmutable.java) [![Python](assets/python.png)](python/range_sum_query_immutable.py) | | -| 304 | [Range Sum Query 2D - Immutable](https://leetcode.com/problems/range-sum-query-2d-immutable) | | | -| 306 | [Additive Number](https://leetcode.com/problems/additive-number) | | | -| 307 | [Range Sum Query - Mutable](https://leetcode.com/problems/range-sum-query-mutable) | | | -| 309 | [Best Time to Buy and Sell Stock with Cooldown](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown) | | | -| 310 | [Minimum Height Trees](https://leetcode.com/problems/minimum-height-trees) | | | -| 311 | 🔒 [Sparse Matrix Multiplication](https://leetcode.com/problems/sparse-matrix-multiplication) | | | -| 313 | [Super Ugly Number](https://leetcode.com/problems/super-ugly-number) | | | -| 314 | 🔒 [Binary Tree Vertical Order Traversal](https://leetcode.com/problems/binary-tree-vertical-order-traversal) | | | -| 316 | [Remove Duplicate Letters](https://leetcode.com/problems/remove-duplicate-letters) | | | -| 318 | [Maximum Product of Word Lengths](https://leetcode.com/problems/maximum-product-of-word-lengths) | | | -| 319 | [Bulb Switcher](https://leetcode.com/problems/bulb-switcher) | | | -| 320 | 🔒 [Generalized Abbreviation](https://leetcode.com/problems/generalized-abbreviation) | | | -| 322 | [Coin Change](https://leetcode.com/problems/coin-change) | | | -| 323 | 🔒 [Number of Connected Components in Undirected Graph](https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph) | | | -| 324 | [Wiggle Sort II](https://leetcode.com/problems/wiggle-sort-ii) | | | -| 325 | 🔒 [Maximum Size Subarray Sum Equals K](https://leetcode.com/problems/maximum-size-subarray-sum-equals-k) | | | -| 326 | [Power of Three](https://leetcode.com/problems/power-of-three) | [![Java](assets/java.png)](src/PowerOfThree.java) [![Python](assets/python.png)](python/power_of_three.py) | | -| 328 | [Odd Even Linked List](https://leetcode.com/problems/odd-even-linked-list) | | | -| 331 | [Verify Preorder Serialization of a Binary Tree](https://leetcode.com/problems/verify-preorder-serialization-of-a-binary-tree) | | | -| 331 | 🔒 [Largest BST Subtree](https://leetcode.com/problems/largest-bst-subtree) | | | -| 334 | [Increasing Triplet Subsequence](https://leetcode.com/problems/increasing-triplet-subsequence) | | | -| 337 | [House Robber III](https://leetcode.com/problems/increasing-triplet-subsequence) | | | -| 338 | [Counting Bits](https://leetcode.com/problems/counting-bits/) | [![Java](assets/java.png)](src/CountingBits.java) [![Python](assets/python.png)](python/counting_bits.py) | | -| 339 | 🔒 [Nested List Weight Sum](https://leetcode.com/problems/nested-list-weight-sum) | | | -| 340 | 🔒 [Longest Substring with At Most K Distinct Characters](https://leetcode.com/problems/longest-substring-with-at-most-k-distinct-characters) | | | -| 341 | [Flatten Nested List Iterator](https://leetcode.com/problems/flatten-nested-list-iterator) | | | -| 342 | [Power of Four](https://leetcode.com/problems/power-of-four) | [![Java](assets/java.png)](src/PowerOf4.java) [![Python](assets/python.png)](python/power_of_four.py) | | -| 343 | [Integer Break](https://leetcode.com/problems/integer-break) | | | -| 344 | [Reverse A String](https://leetcode.com/problems/reverse-string) | [![Java](assets/java.png)](src/ReverseString.java) [![Python](assets/python.png)](python/reverse_a_string.py) | | -| 345 | [Reverse Vowels of A String](https://leetcode.com/problems/reverse-vowels-of-a-string) | [![Java](assets/java.png)](src/ReverseVowelsOfString.java) [![Python](assets/python.png)](python/reverse_vowels_of_a_string.py) | | -| 346 | 🔒 [Moving Average From Data Stream](https://leetcode.com/problems/moving-average-from-data-stream) | | | -| 347 | [Top K frequent Elements](https://leetcode.com/problems/top-k-frequent-elements) | | | -| 348 | 🔒 [Design Tic-Tac-Toe](https://leetcode.com/problems/design-tic-tac-toe) | | | -| 349 | [Intersection of 2 Arrays](https://leetcode.com/problems/intersection-of-two-arrays) | [![Java](assets/java.png)](src/IntersectionOfTwoArrays.java) [![Python](assets/python.png)](python/intersection_of_2_array.py) | | -| 350 | [Intersection of 2 Arrays II](https://leetcode.com/problems/intersection-of-two-arrays-ii) | [![Java](assets/java.png)](src/IntersectionOfTwoArraysII.java) [![Python](assets/python.png)](python/intersection_of_2_arrays_II.py) | | -| 351 | 🔒 [Android Unlock Patterns](https://leetcode.com/problems/android-unlock-patterns) | | | -| 355 | [Design Twitter](https://leetcode.com/problems/design-twitter) | | | -| 357 | [Count Numbers with Unique Digits](https://leetcode.com/problems/count-numbers-with-unique-digits) | | | -| 359 | 🔒 [Logger Rate Limiter](https://leetcode.com/problems/logger-rate-limiter) | | | -| 367 | [Valid Perfect Square](https://leetcode.com/problems/valid-perfect-square) | [![Java](assets/java.png)](src/IsPerfectSquare.java) [![Python](assets/python.png)](python/valid_perfect_square.py) | | -| 374 | [Guess Number Higher or Lower](https://leetcode.com/problems/guess-number-higher-or-lower) | [![Java](assets/java.png)](src/GuessNumberHigherOrLower.java) [![Python](assets/python.png)](python/guess_number_higher_or_lower.py) | | -| 383 | [Ransom Note](https://leetcode.com/problems/ransom-note) | [![Java](assets/java.png)](src/RansomNote.java) [![Python](assets/python.png)](python/ransom_note.py) | | -| 387 | [First Unique Character in String](https://leetcode.com/problems/first-unique-character-in-a-string) | [![Java](assets/java.png)](src/FirstUniqueCharacter.java) [![Python](assets/python.png)](python/first_unique_character_in_string.py) | | -| 389 | [Find the Difference](https://leetcode.com/problems/find-the-difference) | [![Java](assets/java.png)](src/FindTheDifference.java) [![Python](assets/python.png)](python/find_the_difference.py) | | -| 392 | [Is Subsequence](https://leetcode.com/problems/is-subsequence) | [![Java](assets/java.png)](src/IsSubsequence.java) [![Python](assets/python.png)](python/is_subsequence.py) | | -| 401 | [Binary Watch](https://leetcode.com/problems/binary-watch) | [![Java](assets/java.png)](src/BinaryWatch.java) [![Python](assets/python.png)](python/binary_watch.py) | | -| 404 | [Sum of Left Leaves](https://leetcode.com/problems/sum-of-left-leaves) | [![Java](assets/java.png)](src/SumOfLeftLeaves.java) [![Python](assets/python.png)](python/sum_of_left_leaves.py) | | -| 405 | [Convert a Number to Hexadecimal](https://leetcode.com/problems/convert-a-number-to-hexadecimal) | [![Java](assets/java.png)](src/ConvertNumberToHexadecimal.java) [![Python](assets/python.png)](python/convert_a_number_to_hexadecimal.py) | | -| 408 | 🔒 [Valid Word Abbreviation](https://leetcode.com/problems/valid-word-abbreviation) | | | -| 409 | [Longest Palindrome](https://leetcode.com/problems/longest-palindrome) | [![Java](assets/java.png)](src/LongestPalindrome.java) [![Python](assets/python.png)](python/longest_palindrome.py) | | -| 412 | [Fizz Buzz](https://leetcode.com/problems/fizz-buzz) | [![Java](assets/java.png)](src/FizzBuzz.java) [![Python](assets/python.png)](python/fizz_buzz.py) | | -| 414 | [Third Maximum Number](https://leetcode.com/problems/third-maximum-number) | [![Java](assets/java.png)](src/ThirdMaximumNumber.java) [![Python](assets/python.png)](python/fizz_buzz.py) | | -| 415 | [Add Strings](https://leetcode.com/problems/add-strings) | [![Java](assets/java.png)](src/AddString.java) [![Python](assets/python.png)](python/add_strings.py) | | -| 422 | 🔒 [Valid Word Square](https://leetcode.com/problems/valid-word-square) | | | -| 430 | [Flatten a Multilevel Doubly Linked List](https://leetcode.com/problems/flatten-a-multilevel-doubly-linked-list) | [![Java](assets/java.png)](src/FlattenAMultiLevelDoublyLinkedList.java) | | -| 434 | [Number of Segments in a String](https://leetcode.com/problems/number-of-segments-in-a-string) | [![Java](assets/java.png)](src/NumberOfSegmentsInString.java) [![Python](assets/python.png)](python/number_of_segments_in_a_string.py) | | -| 441 | [Arranging Coins](https://leetcode.com/problems/arranging-coins) | [![Java](assets/java.png)](src/ArrangingCoins.java) [![Python](assets/python.png)](python/arranging_coins.py) | | -| 443 | [String Compression](https://leetcode.com/problems/string-compression) | [![Java](assets/java.png)](src/StringCompression.java) [![Python](assets/python.png)](python/string_compression.py) | | -| 447 | [Number of Boomerangs](https://leetcode.com/problems/number-of-boomerangs) | [![Java](assets/java.png)](src/NumberOfBoomerangs.java) [![Python](assets/python.png)](python/number_of_boomerangs.py) | | -| 448 | [Find All Numbers Disappeared in an Array](https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array) | [![Java](assets/java.png)](src/FindAllNumbersDisappearedInAnArray.java) [![Python](assets/python.png)](python/find_all_numbers_disappeared_in_an_array.py) | | -| 453 | [Minimum Moves to Equal Array Elements](https://leetcode.com/problems/minimum-moves-to-equal-array-elements) | [![Java](assets/java.png)](src/MinimumMovesToEqualArrayElements.java) [![Python](assets/python.png)](python/minimum_moves_to_equal_array_element.py) | | -| 455 | [Assign Cookies](https://leetcode.com/problems/assign-cookies) | [![Java](assets/java.png)](src/AssignCookies.java) [![Python](assets/python.png)](python/assign_cookies.py) | | -| 459 | [Repeated Substring Pattern](https://leetcode.com/problems/repeated-substring-pattern) | [![Java](assets/java.png)](src/RepeatedSubstringPattern.java) [![Python](assets/python.png)](python/repeated_substring_pattern.py) | | -| 461 | [Hamming Distance](https://leetcode.com/problems/hamming-distance) | [![Java](assets/java.png)](src/HammingDistance.java) [![Python](assets/python.png)](python/hamming_distance.py) | | -| 463 | [Island Perimeter](https://leetcode.com/problems/island-perimeter) | [![Java](assets/java.png)](src/IslandPerimeter.java) [![Python](assets/python.png)](python/island_perimeter.py) | | -| 475 | [Heaters](https://leetcode.com/problems/heaters) | [![Java](assets/java.png)](src/Heaters.java) [![Python](assets/python.png)](python/heaters.py) | | -| 476 | [Number Complement](https://leetcode.com/problems/number-complement) | [![Java](assets/java.png)](src/NumberComplement.java) [![Python](assets/python.png)](python/number_complement.py) | | -| 482 | [License Key Formatting](https://leetcode.com/problems/license-key-formatting) | [![Java](assets/java.png)](src/LicenseKeyFormatting.java) [![Python](assets/python.png)](python/license_key_formatting.py) | | -| 485 | [Max Consecutive Ones](https://leetcode.com/problems/max-consecutive-ones) | [![Java](assets/java.png)](src/MaxConsecutiveOnes.java) [![Python](assets/python.png)](python/max_consecutive_ones.py) | | -| 492 | [Construct the Rectangle](https://leetcode.com/problems/construct-the-rectangle) | [![Java](assets/java.png)](src/ConstructTheRectangle.java) [![Python](assets/python.png)](python/construct_the_rectangle.py) | | -| 495 | [Teemo Attacking](https://leetcode.com/problems/teemo-attacking/) | [![Java](assets/java.png)](src/TeemoAttacking.java) [![Python](assets/python.png)](python/teemo_attacking.py) | | -| 496 | [Next Greater Element I](https://leetcode.com/problems/next-greater-element-i) | [![Java](assets/java.png)](src/NextGreaterElementI.java) [![Python](assets/python.png)](python/next_greater_element_i.py) | | -| 500 | [Keyboard Row](https://leetcode.com/problems/keyboard-row) | [![Java](assets/java.png)](src/KeyBoardRow.java) [![Python](assets/python.png)](python/keyboard_row.py) | | -| 501 | [Find Mode in Binary Search Tree](https://leetcode.com/problems/find-mode-in-binary-search-tree) | [![Java](assets/java.png)](src/FindModeInBinarySearchTree.java) [![Python](assets/python.png)](python/find_mode_in_binary_search_tree.py) | | -| 504 | [Base 7](https://leetcode.com/problems/base-7) | [![Java](assets/java.png)](src/Base7.java) [![Python](assets/python.png)](python/base_7.py) | | -| 506 | [Relative Ranks](https://leetcode.com/problems/relative-ranks) | [![Java](assets/java.png)](src/RelativeRanks.java) [![Python](assets/python.png)](python/relative_ranks.py) | | -| 507 | [Perfect Number](https://leetcode.com/problems/perfect-number) | [![Java](assets/java.png)](src/CheckPerfectNumber.java) [![Python](assets/python.png)](python/check_perfect_number.py) | | -| 509 | [Fibonacci Number](https://leetcode.com/problems/fibonacci-number) | [![Java](assets/java.png)](src/FibonacciNumber.java) [![Python](assets/python.png)](python/fibonacci_number.py) | | -| 520 | [Detect Capital](https://leetcode.com/problems/detect-capital) | [![Java](assets/java.png)](src/DetectCapital.java) [![Python](assets/python.png)](python/detect_capital.py) | | -| 521 | [Longest Uncommon Subsequence I](https://leetcode.com/problems/longest-uncommon-subsequence-i) | [![Java](assets/java.png)](src/LongestUncommonSubsequenceI.java) [![Python](assets/python.png)](python/longest_uncommon_subsequence_I.py) | | -| 530 | [Minimum Absolute Difference in BST](https://leetcode.com/problems/minimum-absolute-difference-in-bst) | [![Java](assets/java.png)](src/MinimumAbsoluteDifferenceInBST.java) [![Python](assets/python.png)](python/minimum_absolute_difference_in_bst.py) | | -| 532 | [K - Diff Pairs in Array](https://leetcode.com/problems/k-diff-pairs-in-an-array) | [![Java](assets/java.png)](src/KDiffPairsInAnArray.java) [![Python](assets/python.png)](python/k_dif_pairs_in_an_array.py) | | -| 538 | [Convert BST to Greater Tree](https://leetcode.com/problems/convert-bst-to-greater-tree) | [![Java](assets/java.png)](src/ConvertBSTToGreaterTree.java) [![Python](assets/python.png)](python/convert_bst_to_greater_tree.py) | | -| 541 | [Reverse String II](https://leetcode.com/problems/reverse-string-ii) | [![Java](assets/java.png)](src/ReverseStringII.java) [![Python](assets/python.png)](python/reverse_string_ii.py) | | -| 543 | [Diameter of Binary Tree](https://leetcode.com/problems/diameter-of-binary-tree) | [![Java](assets/java.png)](src/DiameterOfBinaryTree.java) [![Python](assets/python.png)](python/diameter_of_binary_tree.py) | | -| 551 | [Student Attendance Record I](https://leetcode.com/problems/student-attendance-record-i) | [![Java](assets/java.png)](src/StudentAttendanceRecordI.java) [![Python](assets/python.png)](python/student_attendance_record_I.py) | | -| 557 | [Reverse Words in a String III](https://leetcode.com/problems/reverse-words-in-a-string-iii) | [![Java](assets/java.png)](src/ReverseWordsInStringIII.java) [![Python](assets/python.png)](python/reverse_words_in_string_iii.py) | | -| 559 | [Maximum Depth of N-Ary Tree](https://leetcode.com/problems/maximum-depth-of-n-ary-tree) | [![Java](assets/java.png)](src/MaximumDepthOfNAryTree.java) [![Python](assets/python.png)](python/maximum_depth_of_n_ary_tree.py) | | -| 561 | [Array Partition I](https://leetcode.com/problems/array-partition-i) | [![Java](assets/java.png)](src/ArrayPartitionI.java) [![Python](assets/python.png)](python/array_partiton_I.py) | | -| 563 | [Binary Tree Tilt](https://leetcode.com/problems/binary-tree-tilt) | [![Java](assets/java.png)](src/BinaryTreeTilt.java) [![Python](assets/python.png)](python/binary_tree_tilt.py) | | -| 566 | [Reshape The Matrix](https://leetcode.com/problems/reshape-the-matrix) | [![Java](assets/java.png)](src/ReshapeTheMatrix.java) [![Python](assets/python.png)](python/reshape_the_matrix.py) | | -| 572 | [Subtree of Another Tree](https://leetcode.com/problems/subtree-of-another-tree) | [![Java](assets/java.png)](src/SubtreeOfAnotherTree.java) [![Python](assets/python.png)](python/subtree_of_another_tree.py) | | -| 575 | [Distribute Candies](https://leetcode.com/problems/distribute-candies) | [![Java](assets/java.png)](src/DistributeCandies.java) [![Python](assets/python.png)](python/distribute_candies.py) | | -| 581 | [Shortest Unsorted Continuous Subarray](https://leetcode.com/problems/shortest-unsorted-continuous-subarray) | [![Java](assets/java.png)](src/ShortestUnsortedContinuousSubarray.java) [![Python](assets/python.png)](python/shortest_continuous_unsorted_subarray.py) | | -| 589 | [N-Ary Tree Preorder Traversal](https://leetcode.com/problems/n-ary-tree-preorder-traversal) | [![Java](assets/java.png)](src/NArayTreePreOrderTraversal.java) [![Python](assets/python.png)](python/n_ary_tree_preorder_traversal.py) | | -| 590 | [N-Ary Tree Postorder Traversal](https://leetcode.com/problems/n-ary-tree-postorder-traversal) | [![Java](assets/java.png)](src/NAryTreePostorderTraversal.java) [![Python](assets/python.png)](python/n_ary_tree_postorder_traversal.py) | | -| 594 | [Longest Harmonious Subsequence](https://leetcode.com/problems/longest-harmonious-subsequence) | [![Java](assets/java.png)](src/LongestHarmoniousSubsequence.java) [![Python](assets/python.png)](python/longest_harmonious_subequence.py) | | -| 598 | [Range Addition II](https://leetcode.com/problems/range-addition-ii) | [![Java](assets/java.png)](src/RangeAdditionII.java) [![Python](assets/python.png)](python/range_addition_ii.py) | | -| 599 | [Minimum Index Sum of 2 Lists](https://leetcode.com/problems/minimum-index-sum-of-two-lists) | [![Java](assets/java.png)](src/MinimumIndexSumOfTwoLists.java) [![Python](assets/python.png)](python/minimum_index_sum_of_two_lists.py) | | -| 604 | 🔒 [Design Compressed String Iterator](https://leetcode.com/problems/design-compressed-string-iterator) | | | -| 605 | [Can Place Flowers](https://leetcode.com/problems/can-place-flowers) | [![Java](assets/java.png)](src/CanPlaceFlowers.java) [![Python](assets/python.png)](python/can_place_flowers.py) | | -| 606 | [Construct String from Binary Tree](https://leetcode.com/problems/construct-string-from-binary-tree) | [![Java](assets/java.png)](src/ConstructStringFromBinaryTree.java) [![Python](assets/python.png)](python/construct_string_from_binary_tree.py) | | -| 617 | [Merge Two Binary Trees](https://leetcode.com/problems/merge-two-binary-trees) | [![Java](assets/java.png)](src/MergeTwoBinaryTrees.java) [![Python](assets/python.png)](python/merge_two_binary_trees.py) | | -| 624 | 🔒 [Maximum Distance in Arrays](https://leetcode.com/problems/maximum-distance-in-arrays) | | | -| 628 | [Maximum Product of Three Numbers](https://leetcode.com/problems/maximum-product-of-three-numbers) | [![Java](assets/java.png)](src/MaximumProductOfThreeNumbers.java) [![Python](assets/python.png)](python/maximum_product_of_three_numbers.py) | | -| 633 | [Sum Square Numbers](https://leetcode.com/problems/sum-of-square-numbers) | [![Java](assets/java.png)](src/SumOfSquareNumbers.java) [![Python](assets/python.png)](python/sum_of_squares_numbers.py) | | -| 637 | [Average of Levels in Binary Tree](https://leetcode.com/problems/average-of-levels-in-binary-tree) | [![Java](assets/java.png)](src/AverageLevelsOfBinaryTree.java) [![Python](assets/python.png)](python/average_levels_of_binary_tree.py) | | -| 643 | [Maximum Average SubArray I](https://leetcode.com/problems/maximum-average-subarray-i) | [![Java](assets/java.png)](src/MaximumAverageSubArrayI.java) [![Python](assets/python.png)](python/maximum_average_subarray_I.py) | | -| 645 | [Set Mismatch](https://leetcode.com/problems/set-mismatch) | [![Java](assets/java.png)](src/SetMismatch.java) [![Python](assets/python.png)](python/set_mismatch.py) | | -| 653 | [Two Sum IV - Input is a BST](https://leetcode.com/problems/two-sum-iv-input-is-a-bst) | [![Java](assets/java.png)](src/TwoSumIVInputIsABST.java) [![Python](assets/python.png)](python/two_sum_iv.py) | | -| 657 | [Robot Return to Origin](https://leetcode.com/problems/robot-return-to-origin) | [![Java](assets/java.png)](src/RobotReturnToOrigin.java) [![Python](assets/python.png)](python/robot_return_to_origin.py) | | -| 661 | [Image Smoother](https://leetcode.com/problems/image-smoother) | [![Java](assets/java.png)](src/ImageSmoother.java) [![Python](assets/python.png)](python/image_smoother.py) | | -| 665 | [Non Deceasing Array](https://leetcode.com/problems/non-decreasing-array) | [![Java](assets/java.png)](src/NonDecreasingArray.java) [![Python](assets/python.png)](python/non_decreasing_array.py) | | -| 669 | [Trim a Binary Search Tree](https://leetcode.com/problems/trim-a-binary-search-tree) | [![Java](assets/java.png)](src/TrimABinarySearchTree.java) [![Python](assets/python.png)](python/trim_a_binary_search_tree.py) | | -| 671 | [Second Minimum Node in Binary Tree](https://leetcode.com/problems/second-minimum-node-in-a-binary-tree) | [![Java](assets/java.png)](src/SecondMinimumNodeInBinaryTree.java) [![Python](assets/python.png)](python/second_minimum_node_in_binary_tree.py) | | -| 674 | [Longest Continuous Increasing Subsequence](https://leetcode.com/problems/longest-continuous-increasing-subsequence) | [![Java](assets/java.png)](src/LongestContinuousIncreasingSubsequence.java) [![Python](assets/python.png)](python/longest_continuous_increasing_subsequence.py) | | -| 680 | [Valid Palindrome II](https://leetcode.com/problems/valid-palindrome-ii) | [![Java](assets/java.png)](src/ValidPalindromeII.java) [![Python](assets/python.png)](python/valid_pallindrome_ii.py) | | -| 682 | [Baseball Game](https://leetcode.com/problems/baseball-game) | [![Java](assets/java.png)](src/BaseballGame.java) [![Python](assets/python.png)](python/baseball_game.py) | | -| 686 | [Repeated String Match](https://leetcode.com/problems/repeated-string-match) | | | -| 687 | [Longest Univalue Path](https://leetcode.com/problems/longest-univalue-path) | | | -| 688 | [Knight Probability in Chessboard](https://leetcode.com/problems/knight-probability-in-chessboard) | [![Java](assets/java.png)](src/KnightProbabilityInChessboard.java) | | -| 690 | [Employee Importance](https://leetcode.com/problems/employee-importance) | | | -| 693 | [Binary Number with Alternating Bits](https://leetcode.com/problems/binary-number-with-alternating-bits) | [![Java](assets/java.png)](src/BinaryNumberWithAlternatingBits.java) [![Python](assets/python.png)](python/binary_number_with_alternating_bits.py) | | -| 696 | [Count Binary Substrings](https://leetcode.com/problems/count-binary-substrings) | [![Java](assets/java.png)](src/CountBinarySubstrings.java) [![Python](assets/python.png)](python/count_binary_substrings.py) | | -| 697 | [Degree of an Array](https://leetcode.com/problems/degree-of-an-array) | [![Java](assets/java.png)](src/DegreeOfAnArray.java) [![Python](assets/python.png)](python/degree_of_an_array.py) | | -| 700 | [Search in a Binary Search Tree](https://leetcode.com/problems/search-in-a-binary-search-tree) | [![Java](assets/java.png)](src/SearchInBinarySearchTree.java) [![Python](assets/python.png)](python/search_in_binary_search_tree.py) | | -| 703 | [Kth Largest Element in a Stream](https://leetcode.com/problems/kth-largest-element-in-a-stream) | [![Java](assets/java.png)](src/KthLargestElementInAStream.java) [![Python](assets/python.png)](python/k_th_largest_element_in_a_stream.py) | | -| 704 | [Binary Search](https://leetcode.com/problems/binary-search) | [![Java](assets/java.png)](src/BinarySearch.java) [![Python](assets/python.png)](python/binary_search.py) | | -| 705 | [Design HashSet](https://leetcode.com/problems/design-hashset) | [![Java](assets/java.png)](src/DesignHashSet.java) [![Python](assets/python.png)](python/design_hash_set.py) | | -| 706 | [Design HashMap](https://leetcode.com/problems/design-hashmap) | [![Java](assets/java.png)](src/DesignHashMap.java) [![Python](assets/python.png)](python/design_hash_map.py) | | -| 709 | [To Lower Case](https://leetcode.com/problems/to-lower-case) | [![Java](assets/java.png)](src/ToLowerCase.java) [![Python](assets/python.png)](python/to_lower_case.py) | | -| 716 | 🔒 [Max Stack](https://leetcode.com/problems/max-stack) | | | -| 717 | [1-bit and 2-bit Characters](https://leetcode.com/problems/1-bit-and-2-bit-characters) | [![Java](assets/java.png)](src/OneBitAndTwoBitCharacters.java) [![Python](assets/python.png)](python/one_bit_and_two_bit_characters.py) | | -| 718 | [Maximum Length of Repeated Subarray](https://leetcode.com/problems/maximum-length-of-repeated-subarray) | [![Java](assets/java.png)](src/MaximumLengthOfRepeatedSubArray.java) | | -| 720 | [Longest Word in Dictionary](https://leetcode.com/problems/longest-word-in-dictionary) | | | -| 724 | [Find Pivot Index](https://leetcode.com/problems/find-pivot-index) | [![Java](assets/java.png)](src/FindPivotIndex.java) [![Python](assets/python.png)](python/find_pivot_index.py) | | -| 728 | [Self Dividing Numbers](https://leetcode.com/problems/self-dividing-numbers) | [![Java](assets/java.png)](src/SelfDividingNumbers.java) [![Python](assets/python.png)](python/self_dividing_number.py) | | -| 733 | [Flood Fill](https://leetcode.com/problems/flood-fill) | [![Java](assets/java.png)](src/FloodFill.java) [![Python](assets/python.png)](python/flood_fill.py) | | -| 743 | [Network Delay Time](https://leetcode.com/problems/network-delay-time) | [![Java](assets/java.png)](src/NetworkDelayTime.java) | | -| 734 | [Sentence Similarity](https://leetcode.com/problems/sentence-similarity) | | | -| 744 | [Find Smallest Letter Greater Than Target](https://leetcode.com/problems/find-smallest-letter-greater-than-target) | [![Java](assets/java.png)](src/FindSmallestLetterGreaterThanTarget.java) [![Python](assets/python.png)](python/find_smallest_letter_greater_than.py) | | -| 746 | [Min Cost Climbing Stairs](https://leetcode.com/problems/min-cost-climbing-stairs) | [![Java](assets/java.png)](src/MinCostClimbingStairs.java) [![Python](assets/python.png)](python/min_cost_climbing_stairs.py) | | -| 747 | [Largest Number at least Twice of Others](https://leetcode.com/problems/largest-number-at-least-twice-of-others) | [![Java](assets/java.png)](src/LargestNumberAtLeastTwiceOfOthers.java) [![Python](assets/python.png)](python/largest_number_at_least_twice_of_others.py) | | -| 748 | [Shortest Completing Word](https://leetcode.com/problems/shortest-completing-word) | [![Java](assets/java.png)](src/ShortestCompletingWord.java) [![Python](assets/python.png)](python/shortest_completing_word.py) | | -| 758 | [Bold Words in String](https://leetcode.com/problems/bold-words-in-string) | | | -| 760 | [Find Anagram Mappings](https://leetcode.com/problems/find-anagram-mappings) | | | -| 762 | [Prime Number of Set Bits in Primary Representation](https://leetcode.com/problems/prime-number-of-set-bits-in-binary-representation) | [![Java](assets/java.png)](src/PrimeNumberOfSetBitsInBinaryRepresentation.java) [![Python](assets/python.png)](python/prime_number_of_set_bits_in_binary_representation.py) | | -| 766 | [Toeplitz Matrix](https://leetcode.com/problems/toeplitz-matrix) | [![Java](assets/java.png)](src/ToeplitzMatrix.java) [![Python](assets/python.png)](python/toeplitz_matrix.py) | | -| 771 | [Jewels and Stones](https://leetcode.com/problems/jewels-and-stones) | [![Java](assets/java.png)](src/JewelsAndStones.java) [![Python](assets/python.png)](python/jewels_and_stones.py) | | -| 783 | [Minimum Distance Between BST Nodes](https://leetcode.com/problems/minimum-distance-between-bst-nodes) | [![Java](assets/java.png)](src/MinimumAbsoluteDifferenceInBST.java) [![Python](assets/python.png)](python/minimum_distance_between_bst_nodes.py) | | -| 788 | [Rotated Digits](https://leetcode.com/problems/rotated-digits) | | | -| 796 | [Rotate String](https://leetcode.com/problems/rotate-string) | [![Java](assets/java.png)](src/RotateString.java) | | -| 800 | [Similar RGB Color](https://leetcode.com/problems/similar-rgb-color) | | | -| 804 | [Unique Morse Code Words](https://leetcode.com/problems/unique-morse-code-words) | [![Java](assets/java.png)](src/UniqueMorseCodeWords.java) | | -| 806 | [Number of Lines to Write String](https://leetcode.com/problems/number-of-lines-to-write-string) | [![Java](assets/java.png)](src/NumberOfLinesToWriteInString.java) | | -| 811 | [Subdomain Visit Count](https://leetcode.com/problems/subdomain-visit-count) | | | -| 812 | [Largest Triangle Area](https://leetcode.com/problems/largest-triangle-area) | [![Java](assets/java.png)](src/LargestTriangleArea.java) | | -| 819 | [Most Common Word](https://leetcode.com/problems/most-common-word) | [![Java](assets/java.png)](src/MostCommonWord.java) | | -| 821 | [Shortest Distance to Character](https://leetcode.com/problems/shortest-distance-to-a-character) | [![Java](assets/java.png)](src/ShortestDistanceToACharacter.java) | | -| 824 | [Goat Latin](https://leetcode.com/problems/goat-latin) | [![Java](assets/java.png)](src/GoatLatin.java) | | -| 830 | [Positions of Large Groups](https://leetcode.com/problems/positions-of-large-groups) | [![Java](assets/java.png)](src/PositionsOfLargeGroups.java) | | -| 832 | [Flipping an Image](https://leetcode.com/problems/flipping-an-image) | [![Java](assets/java.png)](src/FlippingAnImage.java) | | -| 836 | [Rectangle Overlap](https://leetcode.com/problems/rectangle-overlap) | [![Java](assets/java.png)](src/RectangleOverlap.java) | | -| 840 | [Magic Squares in Grid](https://leetcode.com/problems/magic-squares-in-grid) | | | -| 844 | [Backspace String Compare](https://leetcode.com/problems/backspace-string-compare) | [![Java](assets/java.png)](src/BackspaceStringCompare.java) | | -| 849 | [Maximize Distance to Closest Person](https://leetcode.com/problems/maximize-distance-to-closest-person) | | | -| 852 | [Peak Index in Mountain Array](https://leetcode.com/problems/peak-index-in-a-mountain-array) | [![Java](assets/java.png)](src/PeakIndexInMountainArray.java) | | -| 859 | [Buddy Strings](https://leetcode.com/problems/buddy-strings) | [![Java](assets/java.png)](src/BuddyStrings.java) | | -| 860 | [Lemonade Change](https://leetcode.com/problems/lemonade-change) | [![Java](assets/java.png)](src/LemonadeChange.java) | | -| 867 | [Transpose Matrix](https://leetcode.com/problems/transpose-matrix) | [![Java](assets/java.png)](src/TransposeMatrix.java) | | -| 868 | [Binary Gap](https://leetcode.com/problems/binary-gap) | [![Java](assets/java.png)](src/BinaryGap.java) | | -| 872 | [Leaf-Similar Trees](https://leetcode.com/problems/leaf-similar-trees) | [![Java](assets/java.png)](src/LeafSimilarTrees.java) | | -| 874 | [Walking Robot Simulation](https://leetcode.com/problems/walking-robot-simulation) | | | -| 876 | [Middle of the Linked List](https://leetcode.com/problems/middle-of-the-linked-list) | [![Java](assets/java.png)](src/MiddleOfTheLinkedList.java) | | -| 881 | [Boats to Save People](https://leetcode.com/problems/boats-to-save-people) | [![Python](assets/python.png)](python/boats_to_save_people.py) | | -| 883 | [Projection Area of 3D Shapes](https://leetcode.com/problems/projection-area-of-3d-shapes) | [![Java](assets/java.png)](src/ProjectionAreaOf3DShapes.java) | | -| 884 | [Uncommon Words from 2 Sentences](https://leetcode.com/problems/uncommon-words-from-two-sentences) | [![Java](assets/java.png)](src/UncommonWordsFromTwoSentences.java) | | -| 888 | [Fair Candy Swap](https://leetcode.com/problems/fair-candy-swap) | [![Java](assets/java.png)](src/FairCandySwap.java) | | -| 892 | [Surface Area of 3D Shapes](https://leetcode.com/problems/surface-area-of-3d-shapes) | [![Java](assets/java.png)](src/SurfaceAreaOf3DShapes.java) | | -| 893 | [Groups of Special Equivalent Strings](https://leetcode.com/problems/groups-of-special-equivalent-strings) | | | -| 896 | [Monotonic Array](https://leetcode.com/problems/monotonic-array) | [![Java](assets/java.png)](src/MonotonicArray.java) | | -| 897 | [Increasing Order Search Tree](https://leetcode.com/problems/increasing-order-search-tree) | [![Java](assets/java.png)](src/IncreasingOrderSearchTree.java) | | -| 905 | [Sort Array by Parity](https://leetcode.com/problems/sort-array-by-parity) | | | -| 908 | [Smallest Range I](https://leetcode.com/problems/smallest-range-i) | [![Java](assets/java.png)](src/SmallestRangeI.java) | | -| 914 | [X of a kind in a Deck of Cards](https://leetcode.com/problems/x-of-a-kind-in-a-deck-of-cards) | [![Java](assets/java.png)](src/XOfAKindInADeckOfCards.java) | | -| 917 | [Reverse Only Letters](https://leetcode.com/problems/reverse-only-letters) | [![Java](assets/java.png)](src/ReverseOnlyLetters.java) | | -| 922 | [Sort Array by Parity II](https://leetcode.com/problems/sort-array-by-parity-ii) | [![Java](assets/java.png)](src/SortArrayByParityII.java) | | -| 925 | [Long Pressed Name](https://leetcode.com/problems/long-pressed-name) | [![Java](assets/java.png)](src/LongPressedName.java) | | -| 929 | [Unique Email Addresses](https://leetcode.com/problems/unique-email-addresses) | [![Java](assets/java.png)](src/UniqueEmailAddresses.java) | | -| 933 | [Number of Recent Calls](https://leetcode.com/problems/number-of-recent-calls) | [![Java](assets/java.png)](src/NumberOfRecentCalls.java) | | -| 937 | [Reorder Data In Log Files](https://leetcode.com/problems/reorder-data-in-log-files) | [![Java](assets/java.png)](src/ReorderDataInLogFiles.java) | | -| 938 | [Range Sum of BST](https://leetcode.com/problems/range-sum-of-bst) | [![Java](assets/java.png)](src/RangeSumOfBST.java) | | -| 941 | [Valid Mountain Array](https://leetcode.com/problems/valid-mountain-array) | [![Java](assets/java.png)](src/ValidMountainArray.java) [![Python](assets/python.png)](python/valid_mountain_array.py) | | -| 942 | [DI String Match](https://leetcode.com/problems/di-string-match) | [![Java](assets/java.png)](src/DIStringMatch.java) | | -| 944 | [Delete Columns to Make Sorted](https://leetcode.com/problems/delete-columns-to-make-sorted) | [![Java](assets/java.png)](src/DeleteColumnsToMakeSorted.java) | | -| 949 | [Largest Time for Given Digits](https://leetcode.com/problems/largest-time-for-given-digits) | | | -| 953 | [Verifying an Alien Dictionary](https://leetcode.com/problems/verifying-an-alien-dictionary) | [![Java](assets/java.png)](src/VerifyAnAlienDictionary.java) | | -| 961 | [N-Repeated Elements in Size 2N Array](https://leetcode.com/problems/n-repeated-element-in-size-2n-array) | [![Java](assets/java.png)](src/NRepeatedElementInSizeNArray.java) | | -| 965 | [Univalued Binary Tree](https://leetcode.com/problems/univalued-binary-tree) | [![Java](assets/java.png)](src/UnivaluedBinaryTree.java) | | -| 970 | [Powerful Integers](https://leetcode.com/problems/powerful-integers) | | | -| 976 | [Largest Perimeter Triangle](https://leetcode.com/problems/largest-perimeter-triangle) | [![Java](assets/java.png)](src/LargestPerimeterTriangle.java) | | -| 977 | [Squares of a Sorted Array](https://leetcode.com/problems/squares-of-a-sorted-array) | | | -| 983 | [Minimum Cost For Tickets](https://leetcode.com/problems/minimum-cost-for-tickets) | [![Python](assets/python.png)](python/minimum_cost_for_tickets.py) | | -| 985 | [Sum of Even Numbers after Queries](https://leetcode.com/problems/sum-of-even-numbers-after-queries) | | | -| 989 | [Add to Array Form of Integer](https://leetcode.com/problems/add-to-array-form-of-integer) | [![Java](assets/java.png)](src/AddToArrayFormOfInteger.java) | | -| 993 | [Cousins in Binary Tree](https://leetcode.com/problems/cousins-in-binary-tree) | [![Java](assets/java.png)](src/CousinsInBinaryTree.java) | | -| 994 | [Rotting Oranges](https://leetcode.com/problems/rotting-oranges) | [![Java](assets/java.png)](src/RottingOranges.java) | | -| 997 | [Find the Town Judge](https://leetcode.com/problems/find-the-town-judge) | [![Java](assets/java.png)](src/FindTheTownJudge.java) | | -| 999 | [Available Captures for Rook](https://leetcode.com/problems/available-captures-for-rook) | [![Java](assets/java.png)](src/AvailableCapturesForRook.java) | | -| 1002 | [Find Common Characters](https://leetcode.com/problems/find-common-characters) | [![Java](assets/java.png)](src/FindCommonCharacters.java) | | -| 1005 | [Maximize Sum of Array After K Negations](https://leetcode.com/problems/maximize-sum-of-array-after-k-negations) | [![Java](assets/java.png)](src/MaximizeSumOfArrayAfterKNegations.java) | | -| 1009 | [Complement of Base 10 Integer](https://leetcode.com/problems/complement-of-base-10-integer) | [![Java](assets/java.png)](src/NumberComplement.java) | | -| 1010 | [Pairs of Songs With Total Durations Divisible by 60](https://leetcode.com/problems/pairs-of-songs-with-total-durations-divisible-by-60) | [![Java](assets/java.png)](src/PartitionArrayIntoThreePartsWithEqualSum.java) | | -| 1013 | [Partition Array into Three Parts with equal Sum](https://leetcode.com/problems/partition-array-into-three-parts-with-equal-sum) | | | -| 1018 | [Binary Prefix Divisible by 5](https://leetcode.com/problems/binary-prefix-divisible-by-5) | [![Java](assets/java.png)](src/BinaryPrefixDivisibleBy5.java) | | -| 1020 | [Number of Enclaves](https://leetcode.com/problems/number-of-enclaves) | [![Python](assets/python.png)](python/number_of_enclaves.py) | | -| 1021 | [Remove Outermost Parenthesis](https://leetcode.com/problems/remove-outermost-parentheses) | [![Java](assets/java.png)](src/RemoveOutermostParentheses.java) | | -| 1022 | [Sum of Root to Leaf Binary Numbers](https://leetcode.com/problems/sum-of-root-to-leaf-binary-numbers) | [![Java](assets/java.png)](src/SumOfRootToLeafBinaryNumbers.java) | | -| 1025 | [Divisor Game](https://leetcode.com/problems/divisor-game) | [![Java](assets/java.png)](src/DivisorGame.java) | | -| 1029 | [Two City Scheduling](https://leetcode.com/problems/two-city-scheduling) | | | -| 1030 | [Matrix Cells in Distance Order](https://leetcode.com/problems/matrix-cells-in-distance-order) | [![Java](assets/java.png)](src/MatrixCellsInDistanceOrder.java) | | -| 1033 | [Moving Stones Until Consecutive](https://leetcode.com/problems/moving-stones-until-consecutive) | | | -| 1037 | [Valid Boomerang](https://leetcode.com/problems/valid-boomerang) | [![Java](assets/java.png)](src/ValidBoomerang.java) | | -| 1042 | [Flower Planting with no Adjacent](https://leetcode.com/problems/flower-planting-with-no-adjacent) | | | -| 1046 | [Last Stone Weight](https://leetcode.com/problems/last-stone-weight) | [![Java](assets/java.png)](src/LastStoneWeight.java) | | -| 1047 | [Remove All adjacent Duplicates in String](https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string) | [![Java](assets/java.png)](src/RemoveAllAdjacentDuplicatesInAString.java) | | -| 1051 | [Height Checker](https://leetcode.com/problems/height-checker) | | | -| 1056 | 🔒 [Confusing Number](https://leetcode.com/problems/confusing-number) | | | -| 1064 | 🔒 [Fixed Point](https://leetcode.com/problems/fixed-point) | | | -| 1065 | 🔒 [Index Pairs of a String](https://leetcode.com/problems/index-pairs-of-a-string) | | | -| 1071 | [Greatest Common Divisors of Strings](https://leetcode.com/problems/greatest-common-divisor-of-strings) | [![Java](assets/java.png)](src/GreatestCommonDivisorOfStrings.java) | | -| 1078 | [Occurrence After Bigram](https://leetcode.com/problems/occurrences-after-bigram) | [![Java](assets/java.png)](src/OccurrencesAfterBigram.java) | | -| 1085 | 🔒 [Sum of Digits in Minimum Number](https://leetcode.com/problems/sum-of-digits-in-the-minimum-number) | | | -| 1086 | 🔒 [High Five](https://leetcode.com/problems/high-five) | | | -| 1089 | [Duplicate Zeroes](https://leetcode.com/problems/duplicate-zeros) | [![Java](assets/java.png)](src/DuplicateZeros.java) | | -| 1099 | 🔒 [Two Sum Less Than K](https://leetcode.com/problems/two-sum-less-than-k) | | | -| 1103 | [Distribute Candies to People](https://leetcode.com/problems/distribute-candies-to-people) | [![Java](assets/java.png)](src/DistributeCandiesToPeople.java) | | -| 1108 | [Defanging an IP Address](https://leetcode.com/problems/defanging-an-ip-address) | [![Java](assets/java.png)](src/DefangingAnIPAddress.java) | | -| 1118 | 🔒 [Number of Days in a Month](https://leetcode.com/problems/number-of-days-in-a-month) | | | -| 1119 | 🔒 [Remove Vowels From String](https://leetcode.com/problems/remove-vowels-from-a-string) | | | -| 1122 | [Relative Sort Array](https://leetcode.com/problems/relative-sort-array) | [![Java](assets/java.png)](src/RelativeSortArray.java) | | -| 1128 | [Number of Equivalent Domino Pairs](https://leetcode.com/problems/number-of-equivalent-domino-pairs) | [![Java](assets/java.png)](src/NumberOfEquivalentDominoPairs.java) | | -| 1133 | 🔒 [Largest Unique Number](https://leetcode.com/problems/largest-unique-number) | | | -| 1134 | 🔒 [Armstrong Number](https://leetcode.com/problems/armstrong-number) | | | -| 1137 | [Nth Tribonacci Number](https://leetcode.com/problems/n-th-tribonacci-number) | [![Java](assets/java.png)](src/NthTribonacciNumber.java) | | -| 1143 | [Longest Common Subsequence](https://leetcode.com/problems/longest-common-subsequence) | [![Java](assets/java.png)](src/LongestCommonSubsequence.java) | | -| 1150 | [Check if Number is Majority Element in Sorted Array](https://leetcode.com/problems/check-if-a-number-is-majority-element-in-a-sorted-array) | | | -| 1154 | [Day of The Year](https://leetcode.com/problems/day-of-the-year) | [![Java](assets/java.png)](src/DayOfTheYear.java) | | -| 1160 | [Find Words That Can Be Formed By Characters](https://leetcode.com/problems/find-words-that-can-be-formed-by-characters) | | | -| 1165 | [Single Row Keyboard](https://leetcode.com/problems/single-row-keyboard) | [![Java](assets/java.png)](src/FindWordsThatCanBeFormedByCharacters.java) | | -| 1170 | [Compare Strings By Frequency of the Smallest Character](https://leetcode.com/problems/compare-strings-by-frequency-of-the-smallest-character) | | | -| 1175 | [Prime Arrangements](https://leetcode.com/problems/prime-arrangements) | [![Java](assets/java.png)](src/PrimeArrangements.java) | | -| 1176 | 🔒 [Diet Plan Performance](https://leetcode.com/problems/diet-plan-performance) | | | -| 1180 | 🔒 [Count Substrings with only one Distinct Letter](https://leetcode.com/problems/count-substrings-with-only-one-distinct-letter) | | | -| 1184 | [Distance Between Bus Stops](https://leetcode.com/problems/distance-between-bus-stops) | [![Java](assets/java.png)](src/DistanceBetweenBusStops.java) | | -| 1185 | [Day of the Week](https://leetcode.com/problems/day-of-the-week) | [![Java](assets/java.png)](src/DayOfWeek.java) | | -| 1189 | [Maximum Number of Balloons](https://leetcode.com/problems/maximum-number-of-balloons) | [![Java](assets/java.png)](src/MaximumNumberOfBalloons.java) | | -| 1196 | 🔒 [How Many Apples Can You Put into the Basket](https://leetcode.com/problems/how-many-apples-can-you-put-into-the-basket) | | | -| 1200 | [Minimum Absolute Difference](https://leetcode.com/problems/minimum-absolute-difference) | [![Java](assets/java.png)](src/MinimumAbsoluteDifference.java) | | -| 1201 | [Ugly Number III](https://leetcode.com/problems/ugly-number-iii) | [![Java](assets/java.png)](src/UglyNumberIII.java) | | -| 1207 | [Unique Number of Occurrences](https://leetcode.com/problems/unique-number-of-occurrences) | [![Java](assets/java.png)](src/UniqueNumberOfOccurrences.java) | | -| 1213 | 🔒 [Intersection of Three Sorted Arrays](https://leetcode.com/problems/intersection-of-three-sorted-arrays) | | | -| 1217 | [Minimum Cost to Move Chips to The Same Position](https://leetcode.com/problems/minimum-cost-to-move-chips-to-the-same-position) | [![Java](assets/java.png)](src/MinimumCostToMoveChipsToTheSamePosition.java) | | -| 1221 | [Split A String In Balanced Strings](https://leetcode.com/problems/split-a-string-in-balanced-strings) | [![Java](assets/java.png)](src/SplitAStringInBalancedStrings.java) | | -| 1228 | 🔒 [Missing A Number In Arithmetic Progression](https://leetcode.com/problems/missing-number-in-arithmetic-progression) | | | -| 1232 | [Check If It Is A Straight Line](https://leetcode.com/problems/check-if-it-is-a-straight-line) | [![Java](assets/java.png)](src/CheckIfItIsASStraightLine.java) | | -| 1237 | [Find Positive Integer Solutions for a Given Equation](https://leetcode.com/problems/find-positive-integer-solution-for-a-given-equation) | | | -| 1243 | 🔒 [Array Transformation](https://leetcode.com/problems/array-transformation) | | | -| 1249 | [Minimum Remove to Make Valid Parentheses](https://leetcode.com/problems/minimum-remove-to-make-valid-parentheses) | [![Java](assets/java.png)](src/MinimumRemoveToMakeValidParentheses.java) | | -| 1252 | [Cells With Odd Values In Matrix](https://leetcode.com/problems/cells-with-odd-values-in-a-matrix) | [![Java](assets/java.png)](src/CellsWithOddValuesInMatrix.java) | | -| 1254 | [Number of Closed Islands](https://leetcode.com/problems/number-of-closed-islands) | [![Python](assets/python.png)](python/number_of_closed_islands.py) | | -| 1260 | [Shift 2D Grid](https://leetcode.com/problems/shift-2d-grid) | [![Java](assets/java.png)](src/Shift2DGrid.java) | | -| 1266 | [Minimum Time Visiting All Points](https://leetcode.com/problems/minimum-time-visiting-all-points) | [![Java](assets/java.png)](src/MinimumTimeVisitingAllPoints.java) | | -| 1271 | 🔒 [Hexspeak](https://leetcode.com/problems/hexspeak) | | | -| 1275 | [Find Winner On a Tic Tac Toe Game](https://leetcode.com/problems/find-winner-on-a-tic-tac-toe-game) | [![Java](assets/java.png)](src/FindWinnerOnATicTacToeGame.java) | | -| 1281 | [Subtract the Product and Sum of Digits of a Integer](https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer) | [![Java](assets/java.png)](src/SubtractTheProductAndSumOfDigitsOfAnInteger.java) | | -| 1287 | [Element Appearing More Than 25% in Sorted Array](https://leetcode.com/problems/element-appearing-more-than-25-in-sorted-array) | [![Java](assets/java.png)](src/ElementAppearingMoreThan25PercentInSortedArray.java) | | -| 1290 | [Convert Binary Number In A Linked List to Integer](https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer) | [![Java](assets/java.png)](src/ConvertBinaryNumberInLinkedListToInteger.java) | | -| 1295 | [Find Numbers With Even Numbers of Digits](https://leetcode.com/problems/find-numbers-with-even-number-of-digits) | [![Java](assets/java.png)](src/FindNumbersWithEvenNumbersOfDigits.java) [![Python](assets/python.png)](python/find_numbers_with_even_number_of_digits.py) | | -| 1299 | [Replace Elements With Greatest Element on Right Side](https://leetcode.com/problems/replace-elements-with-greatest-element-on-right-side) | [![Java](assets/java.png)](src/ReplaceElementWithGreatestElementOnRightSide.java) [![Python](assets/python.png)](python/replace_element_with_greatest_element_on_right_hand_side.py) | | -| 1304 | [Find N Unique Integers Sum Up To Zero](https://leetcode.com/problems/find-n-unique-integers-sum-up-to-zero) | [![Java](assets/java.png)](src/FindNUniqueIntegersSumUpToZero.java) | | -| 1309 | [Decrypt String From Alphabet To Integer Mapping](https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping) | [![Java](assets/java.png)](src/DecryptStringFromAlphabetToIntegerMapping.java) | | -| 1313 | [Decompress Run-Length Encoded Strings](https://leetcode.com/problems/decompress-run-length-encoded-list) | [![Java](assets/java.png)](src/DecompressRunLengthEncodedList.java) | | -| 1317 | [Convert Integer to Sum Of Two Non-Zero Integers](https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers) | [![Java](assets/java.png)](src/ConvertIntegerToTheSumOfTwoNoZeroIntegers.java) | | -| 1319 | [Number of Operations to Make Network Connected](https://leetcode.com/problems/number-of-operations-to-make-network-connected) | [![Python](assets/python.png)](python/no_of_operations_to_make_network_connected.py) | | -| 1323 | [Maximum 69 Number](https://leetcode.com/problems/maximum-69-number) | [![Java](assets/java.png)](src/Maximum69Number.java) | | -| 1331 | [Rank Transform of An Array](https://leetcode.com/problems/rank-transform-of-an-array) | [![Java](assets/java.png)](src/RankTransformOfArray.java) | | -| 1332 | [Remove Palindromic Subsequences](https://leetcode.com/problems/remove-palindromic-subsequences) | [![Java](assets/java.png)](src/RemovePalindromicSubSequences.java) | | -| 1337 | [The K Weakest Rows In A Matrix](https://leetcode.com/problems/the-k-weakest-rows-in-a-matrix) | [![Java](assets/java.png)](src/TheKWeakestRowsInAMatrix.java) | | -| 1342 | [Number of Steps to Reduce a Number to Zero](https://leetcode.com/problems/number-of-steps-to-reduce-a-number-to-zero) | [![Java](assets/java.png)](src/NumberOfStepsToReduceANumberToZero.java) | | -| 1346 | [Check if N and It's Double Exist](https://leetcode.com/problems/check-if-n-and-its-double-exist) | [![Java](assets/java.png)](src/CheckIfNAndItsDoubleExist.java) [![Python](assets/python.png)](python/check_if_n_and_its_double_exist.py) | | -| 1351 | [Count Negative Numbers In A Sorted Matrix](https://leetcode.com/problems/count-negative-numbers-in-a-sorted-matrix) | [![Java](assets/java.png)](src/CountNegativeNumbersInSortedMatrix.java) | | -| 1356 | [Sort Integers by Number of 1 Bits](https://leetcode.com/problems/sort-integers-by-the-number-of-1-bits) | [![Java](assets/java.png)](src/SortIntegersByTheNumberOf1Bits.java) | | -| 1360 | [Number of Days Between Two Dates](https://leetcode.com/problems/number-of-days-between-two-dates) | [![Java](assets/java.png)](src/NumberOfDaysBetweenTwoDates.java) | | -| 1365 | [How Many Numbers Are Smaller Than Current Number](https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number) | [![Java](assets/java.png)](src/HowManyNumbersAreSmallerThanCurrentNumber.java) | | -| 1370 | [Increasing Decreasing String](https://leetcode.com/problems/increasing-decreasing-string) | [![Java](assets/java.png)](src/IncreasingDecreasingString.java) | | -| 1374 | [Generate A String With Characters That Have Odd Count](https://leetcode.com/problems/generate-a-string-with-characters-that-have-odd-counts) | [![Java](assets/java.png)](src/GenerateAStringWithCharactersThatHaveOddCounts.java) | | -| 1376 | [Time Needed to Inform All Employees](https://leetcode.com/problems/time-needed-to-inform-all-employees) | [![Java](assets/java.png)](src/TimeNeededToInformAllEmployees.java) | | -| 1379 | [Find a Corresponding Node of a Binary Tree in a Clone of That Tree](https://leetcode.com/problems/find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree) | [![Java](assets/java.png)](src/FindACorrespondingNodeOfABinaryTreeInACloneOfThatTree.java) | | -| 1380 | [Lucky Numbers In A Matrix](https://leetcode.com/problems/lucky-numbers-in-a-matrix) | [![Java](assets/java.png)](src/LuckyNumbersInAMatrix.java) | | -| 1385 | [Find The Distance Value Between 2 Arrays](https://leetcode.com/problems/find-the-distance-value-between-two-arrays) | [![Java](assets/java.png)](src/FindTheDistanceValuesBetweenTwoArrays.java) | | -| 1389 | [Create Target Array in Given Order](https://leetcode.com/problems/create-target-array-in-the-given-order) | [![Java](assets/java.png)](src/CreateTargetArrayInGivenOrder.java) | | -| 1394 | [Find Lucky Integer In An Array](https://leetcode.com/problems/find-lucky-integer-in-an-array) | [![Java](assets/java.png)](src/FindTheLuckyIntegerInAnArray.java) | | -| 1399 | [Count Largest Group](https://leetcode.com/problems/count-largest-group) | [![Java](assets/java.png)](src/CountLargestGroup.java) | | -| 1402 | [Reducing Dishes](https://leetcode.com/problems/reducing-dishes) | [![Python](assets/python.png)](python/reducing_dishes.py) | | -| 1403 | [Minimum Subsequence in Non-Increasing Order](https://leetcode.com/problems/minimum-subsequence-in-non-increasing-order) | [![Java](assets/java.png)](src/MinimumSubSequenceInNonIncreasingOrder.java) | | -| 1408 | [String Matching In An Array](https://leetcode.com/problems/string-matching-in-an-array) | [![Java](assets/java.png)](src/StringMatchingInAnArray.java) | | -| 1413 | [Minimum Value To Get Positive Step By Step Sum](https://leetcode.com/problems/minimum-value-to-get-positive-step-by-step-sum) | [![Java](assets/java.png)](src/MinimumValueToGetPositiveStepByStepSum.java) | | -| 1417 | [Reformat The String](https://leetcode.com/problems/reformat-the-string) | [![Java](assets/java.png)](src/ReformatTheString.java) | | -| 1422 | [Maximum Score After Splitting A String](https://leetcode.com/problems/maximum-score-after-splitting-a-string) | [![Java](assets/java.png)](src/MaximumScoreAfterSplittingAString.java) | | -| 1426 | 🔒 [Counting Elements](https://leetcode.com/problems/counting-elements) | | | -| 1427 | 🔒 [Performing String Shifts](https://leetcode.com/problems/perform-string-shifts) | | | -| 1431 | [Kids With The Greatest Number Of Candies](https://leetcode.com/problems/kids-with-the-greatest-number-of-candies) | [![Java](assets/java.png)](src/KidsWithTheGreatestNumberOfCandies.java) | | -| 1436 | [Destination City](https://leetcode.com/problems/destination-city) | [![Java](assets/java.png)](src/DestinationCity.java) | | -| 1437 | [Check If All 1's Are at Least Length K Places Away](https://leetcode.com/problems/check-if-all-1s-are-at-least-length-k-places-away) | [![Java](assets/java.png)](src/CheckIfAll1sAreAtLeastKPlacesAway.java) | | -| 1441 | [Build An Array With Stack Operation](https://leetcode.com/problems/build-an-array-with-stack-operations) | [![Java](assets/java.png)](src/BuildAnArrayWithStackOperations.java) | | -| 1444 | [Number of Ways of Cutting a Pizza](https://leetcode.com/problems/number-of-ways-of-cutting-a-pizza) | [![Python](assets/python.png)](python/number_of_ways_of_cutting_pizza.py) | | -| 1446 | [Consecutive Characters](https://leetcode.com/problems/consecutive-characters) | [![Java](assets/java.png)](src/ConsecutiveCharacters.java) | | -| 1450 | [Number of Students Doing Homework at Given Time](https://leetcode.com/problems/number-of-students-doing-homework-at-a-given-time) | [![Java](assets/java.png)](src/NumberOfStudentsDoingHomeworkAtGivenTime.java) | | -| 1455 | [Check If Word Occurs as Prefix of any Word in Sentence](https://leetcode.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence) | [![Java](assets/java.png)](src/CheckIfAWordOccursAsAPrefixOfAnyWordInASentence.java) | | -| 1460 | [Make 2 Arrays Equal by Reversing Sub Arrays](https://leetcode.com/problems/make-two-arrays-equal-by-reversing-sub-arrays) | [![Java](assets/java.png)](src/MakeTwoArraysEqualByReversingSubArrays.java) | | -| 1464 | [Maximum Product of 2 Elements in Array](https://leetcode.com/problems/maximum-product-of-two-elements-in-an-array) | [![Java](assets/java.png)](src/MaximumProductOfTwoElementsInArray.java) | | -| 1466 | [Reorder Routes to Make All Paths Lead to the City Zero](https://leetcode.com/problems/reorder-routes-to-make-all-paths-lead-to-the-city-zero) | [![Java](assets/java.png)](src/MaximumProductOfTwoElementsInArray.java) | | -| 1469 | 🔒 [Find All Lonely Nodes](https://leetcode.com/problems/find-all-the-lonely-nodes) | [![Python](assets/python.png)](python/reorder_routes_to_make_all_paths_lead_to_city_zero.py) | | -| 1470 | [Shuffle The Array](https://leetcode.com/problems/shuffle-the-array) | [![Java](assets/java.png)](src/ShuffleTheArray.java) | | -| 1472 | [Design Browser History](https://leetcode.com/problems/design-browser-history) | [![Java](assets/java.png)](src/DesignBrowserHistory.java) [![Python](assets/python.png)](python/design_browser_history.py) | | -| 1474 | [Delete N Nodes After M Nodes In A Linked List](https://leetcode.com/problems/delete-n-nodes-after-m-nodes-of-a-linked-list) | | | -| 1475 | [Final Prices With Special Discount in a Shop](https://leetcode.com/problems/final-prices-with-a-special-discount-in-a-shop) | [![Java](assets/java.png)](src/FinalPricesWithASpecialDiscountInAShop.java) | | -| 1480 | [Running Sum of 1D Array](https://leetcode.com/problems/running-sum-of-1d-array) | [![Java](assets/java.png)](src/RunningSumOf1DArray.java) | | -| 1486 | [XOR Operations in An Array](https://leetcode.com/problems/xor-operation-in-an-array) | [![Java](assets/java.png)](src/XOROperationInAnArray.java) | | -| 1491 | [Average Salary Excluding the Minimum and Maximum Salary](https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary) | [![Java](assets/java.png)](src/AverageSalaryExcludingTheMinimumAndMaximumSalary.java) | | -| 1496 | [Path Crossing](https://leetcode.com/problems/path-crossing) | [![Java](assets/java.png)](src/PathCrossing.java) | | -| 1502 | [Can Make Arithmetic Progression From Sequence](https://leetcode.com/problems/can-make-arithmetic-progression-from-sequence) | [![Java](assets/java.png)](src/CanMakeArithmeticProgressionFromSequence.java) | | -| 1507 | [Reformat Date](https://leetcode.com/problems/reformat-date) | [![Java](assets/java.png)](src/ReformatDate.java) | | -| 1512 | [Number of Good Pairs](https://leetcode.com/problems/number-of-good-pairs) | [![Java](assets/java.png)](src/NumberOfGoodPairs.java) | | -| 1518 | [Water Bottles](https://leetcode.com/problems/water-bottles) | [![Java](assets/java.png)](src/WaterBottles.java) | | -| 1523 | [Count Odd Numbers In Interval Range](https://leetcode.com/problems/count-odd-numbers-in-an-interval-range) | [![Java](assets/java.png)](src/CountOddNumbersInIntervalRange.java) | | -| 1528 | [Shuffle Strings](https://leetcode.com/problems/shuffle-string) | [![Java](assets/java.png)](src/ShuffleString.java) | | -| 1534 | [Count Good Triplets](https://leetcode.com/problems/count-good-triplets) | [![Java](assets/java.png)](src/CountGoodTriplets.java) | | -| 1539 | [Kth Missing Positive Number](https://leetcode.com/problems/kth-missing-positive-number) | [![Java](assets/java.png)](src/KthMissingPositiveNumber.java) | | -| 1544 | [Make The String Great](https://leetcode.com/problems/make-the-string-great) | [![Java](assets/java.png)](src/MakeTheStringGreat.java) | | -| 1550 | [Three Consecutive Odds](https://leetcode.com/problems/three-consecutive-odds) | [![Java](assets/java.png)](src/ThreeConsecutiveOdds.java) | | -| 1556 | [Thousand Separator](https://leetcode.com/problems/thousand-separator) | [![Java](assets/java.png)](src/ThousandSeparator.java) | | -| 1560 | [Most Visited Sector in a Circular Track](https://leetcode.com/problems/most-visited-sector-in-a-circular-track) | [![Java](assets/java.png)](src/MostVisitedSectorInACircularTrack.java) | | -| 1566 | [Detect Pattern of Length M Repeated K or More Times](https://leetcode.com/problems/detect-pattern-of-length-m-repeated-k-or-more-times) | [![Java](assets/java.png)](src/DetectPatternOfLengthMRepeatedKOrMoreTimes.java) | | -| 1572 | [Matrix Diagonal Sum](https://leetcode.com/problems/matrix-diagonal-sum) | [![Java](assets/java.png)](src/MatrixDiagonalSum.java) | | -| 1576 | [Replace All ?'s to Avoid Consecutive Repeating Characters](https://leetcode.com/problems/replace-all-s-to-avoid-consecutive-repeating-characters) | [![Java](assets/java.png)](src/ReplaceAllToAvoidConsecutiveRepeatingCharacters.java) | | -| 1582 | [Special Positions in a Binary Matrix](https://leetcode.com/problems/special-positions-in-a-binary-matrix) | [![Java](assets/java.png)](src/SpecialPositionInABinaryMatrix.java) | | -| 1588 | [Sum of All Odd Length Subarrays](https://leetcode.com/problems/sum-of-all-odd-length-subarrays) | [![Java](assets/java.png)](src/SumOfAllOddLengthSubArrays.java) | | -| 1592 | [Rearrange Spaces Between Words](https://leetcode.com/problems/rearrange-spaces-between-words) | [![Java](assets/java.png)](src/RearrangeSpacesBetweenWords.java) | | -| 1598 | [Crawler Log Folder](https://leetcode.com/problems/crawler-log-folder) | [![Java](assets/java.png)](src/CrawlerLogFolder.java) | | -| 1600 | [Throne Inheritance](https://leetcode.com/problems/throne-inheritance) | [![Java](assets/java.png)](src/ThroneInheritance.java) | | -| 1603 | [Design Parking System](https://leetcode.com/problems/design-parking-system) | [![Java](assets/java.png)](src/DesignParkingSystem.java) | | -| 1608 | [Special Array With X Elements Greater Than or Equal X](https://leetcode.com/problems/special-array-with-x-elements-greater-than-or-equal-x) | [![Java](assets/java.png)](src/SpecialArrayWithXElementsGreaterThanEqualToX.java) | | -| 1614 | [Maximum Nesting Depth of the Parentheses](https://leetcode.com/problems/maximum-nesting-depth-of-the-parentheses) | [![Java](assets/java.png)](src/MaximumNestingDepthOfTheParentheses.java) | | -| 1619 | [Mean of Array After Removing Some Elements](https://leetcode.com/problems/mean-of-array-after-removing-some-elements) | [![Java](assets/java.png)](src/MeanOfArrayAfterRemovingSomeElements.java) | | -| 1624 | [Largest Substring Between Two Equal Characters](https://leetcode.com/problems/largest-substring-between-two-equal-characters) | [![Java](assets/java.png)](src/LargestSubStringBetweenTwoEqualCharacters.java) | | -| 1629 | [Slowest Key](https://leetcode.com/problems/slowest-key) | [![Java](assets/java.png)](src/SlowestKey.java) | | -| 1636 | [Sort Array by Increasing Frequency](https://leetcode.com/problems/sort-array-by-increasing-frequency) | [![Java](assets/java.png)](src/SortArrayByIncreasingFrequency.java) | | -| 1640 | [Check Array Formation Through Concatenation](https://leetcode.com/problems/check-array-formation-through-concatenation) | [![Java](assets/java.png)](src/CheckArrayFormationThroughConcatenation.java) | | -| 1646 | [Get Maximum in Generated Array](https://leetcode.com/problems/get-maximum-in-generated-array) | [![Java](assets/java.png)](src/GetMaximumInGeneratedArray.java) | | -| 1652 | [Defuse the Bomb](https://leetcode.com/problems/defuse-the-bomb) | [![Java](assets/java.png)](src/DefuseTheBomb.java) | | -| 1656 | [Design an Ordered Stream](https://leetcode.com/problems/design-an-ordered-stream) | [![Java](assets/java.png)](src/DesignAnOrderedStream.java) | | -| 1662 | [Check If Two String Arrays are Equivalent](https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent) | [![Java](assets/java.png)](src/CheckIfTwoStringArraysAreEquivalent.java) | | -| 1668 | [Maximum Repeating Substring](https://leetcode.com/problems/maximum-repeating-substring) | [![Java](assets/java.png)](src/MaximumRepeatingSubString.java) | | -| 1672 | [Richest Customer Wealth](https://leetcode.com/problems/richest-customer-wealth) | [![Java](assets/java.png)](src/RichestCustomerWealth.java) | | -| 1678 | [Goal Parser Interpretation](https://leetcode.com/problems/goal-parser-interpretation) | [![Java](assets/java.png)](src/GoalParserInterpretation.java) | | -| 1684 | [Count the Number of Consistent Strings](https://leetcode.com/problems/count-the-number-of-consistent-strings) | [![Java](assets/java.png)](src/CountTheNumberOfConsistentStrings.java) | | -| 1688 | [Count of Matches in Tournament](https://leetcode.com/problems/count-of-matches-in-tournament) | [![Java](assets/java.png)](src/CountOfMatchesInTournament.java) | | -| 1694 | [Reformat Phone Number](https://leetcode.com/problems/reformat-phone-number) | [![Java](assets/java.png)](src/ReformatPhoneNumber.java) | | -| 1700 | [Number of Students Unable to Eat Lunch](https://leetcode.com/problems/number-of-students-unable-to-eat-lunch) | [![Java](assets/java.png)](src/NumberOfStudentsUnableToEatLunch.java) | | -| 1704 | [Determine if String Halves Are Alike](https://leetcode.com/problems/determine-if-string-halves-are-alike) | [![Java](assets/java.png)](src/DetermineIfStringHalvesAreAlike.java) | | -| 1708 | 🔒 [Largest Subarray Length K](https://leetcode.com/problems/largest-subarray-length-k/) | | | -| 1710 | [Maximum Units on a Truck](https://leetcode.com/problems/maximum-units-on-a-truck/) | [![Java](assets/java.png)](src/MaximumUnitsOnATruck.java) | | -| 1716 | [Calculate Money in Leetcode Bank](https://leetcode.com/problems/calculate-money-in-leetcode-bank) | [![Java](assets/java.png)](src/CalculateMoneyInLeetCodeBank.java) | | -| 1720 | [Decode XORed Array](https://leetcode.com/problems/decode-xored-array) | [![Java](assets/java.png)](src/DecodeXORedArray.java) | | -| 1725 | [Number Of Rectangles That Can Form The Largest Square](https://leetcode.com/problems/number-of-rectangles-that-can-form-the-largest-square) | [![Java](assets/java.png)](src/NumberOfRectanglesThatCanFormTheLargestSquare.java) | | -| 1732 | [Find the Highest Altitude](https://leetcode.com/problems/find-the-highest-altitude) | [![Java](assets/java.png)](src/FindTheHighestAltitude.java) | | -| 1736 | [Latest Time by Replacing Hidden Digits](https://leetcode.com/problems/latest-time-by-replacing-hidden-digits) | [![Java](assets/java.png)](src/LatestTimeByReplacingHiddenDigits.java) | | -| 1742 | [Maximum Number of Balls in a Box](https://leetcode.com/problems/maximum-number-of-balls-in-a-box) | [![Java](assets/java.png)](src/MaximumNumberOfBallsInABox.java) | | -| 1748 | [Sum of Unique Elements](https://leetcode.com/problems/sum-of-unique-elements) | [![Java](assets/java.png)](src/SumOfUniqueElements.java) | | -| 1752 | [Check if Array Is Sorted and Rotated](https://leetcode.com/problems/check-if-array-is-sorted-and-rotated) | [![Java](assets/java.png)](src/CheckIfArrayIsSortedAndRotated.java) | | -| 1758 | [Minimum Changes To Make Alternating Binary String](https://leetcode.com/problems/minimum-changes-to-make-alternating-binary-string) | [![Java](assets/java.png)](src/MinimumChangesToMakeAlternatingBinaryString.java) | | -| 1763 | [Longest Nice Substring](https://leetcode.com/problems/longest-nice-substring) | [![Java](assets/java.png)](src/LongestNiceSubstring.java) | | -| 1768 | [Merge Strings Alternately](https://leetcode.com/problems/merge-strings-alternately) | [![Java](assets/java.png)](src/MergeStringsAlternately.java) | | -| 1773 | [Count Items Matching a Rule](https://leetcode.com/problems/count-items-matching-a-rule) | [![Java](assets/java.png)](src/CountItemsMatchingARule.java) | | -| 1779 | [Find Nearest Point That Has the Same X or Y Coordinate](https://leetcode.com/problems/find-nearest-point-that-has-the-same-x-or-y-coordinate) | [![Java](assets/java.png)](src/FindNearestPointThatHasTheSameXOrYCoordinate.java) | | -| 1784 | [Check if Binary String Has at Most One Segment of Ones](https://leetcode.com/problems/check-if-binary-string-has-at-most-one-segment-of-ones) | [![Java](assets/java.png)](src/CheckIfBinaryStringHasAtMostOneSegmentOfOnes.java) | | -| 1790 | [Check if One String Swap Can Make Strings Equal](https://leetcode.com/problems/check-if-one-string-swap-can-make-strings-equal) | [![Java](assets/java.png)](src/CheckIfOneStringSwapCanMakeStringsEqual.java) | | -| 1791 | [Find Center of Star Graph](https://leetcode.com/problems/find-center-of-star-graph) | [![Java](assets/java.png)](src/FindCenterOfStarGraph.java) | | -| 1796 | [Second Largest Digit in a String](https://leetcode.com/problems/second-largest-digit-in-a-string) | [![Java](assets/java.png)](src/SecondLargestDigitInAString.java) | | -| 1800 | [Maximum Ascending Subarray Sum](https://leetcode.com/problems/maximum-ascending-subarray-sum) | [![Java](assets/java.png)](src/MaximumAscendingSubArraySum.java) | | -| 1805 | [Number of Different Integers in a String](https://leetcode.com/problems/number-of-different-integers-in-a-string) | [![Java](assets/java.png)](src/NumberOfDifferentIntegersInString.java) | | -| 1812 | [Determine Color of a Chessboard Square](https://leetcode.com/problems/determine-color-of-a-chessboard-square) | [![Java](assets/java.png)](src/DetermineColorOfChessboardSquare.java) | | -| 1816 | [Truncate Sentence](https://leetcode.com/problems/truncate-sentence) | [![Java](assets/java.png)](src/TruncateSentences.java) | | -| 1822 | [Sign of the Product of an Array](https://leetcode.com/problems/sign-of-the-product-of-an-array) | [![Java](assets/java.png)](src/SignOfTheProductOfAnArray.java) | | -| 1826 | 🔒 [Faulty Sensor](https://leetcode.com/problems/faulty-sensor) | | | -| 1827 | [Minimum Operations to Make the Array Increasing](https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing) | [![Java](assets/java.png)](src/MinimumOperationsToMakeTheArrayIncreasing.java) | | -| 1832 | [Check if the Sentence Is Pangram](https://leetcode.com/problems/check-if-the-sentence-is-pangram) | [![Java](assets/java.png)](src/CheckIfSentenceIsPangram.java) | | -| 1837 | [Sum of Digits in Base K](https://leetcode.com/problems/sum-of-digits-in-base-k) | [![Java](assets/java.png)](src/SumOfDigitsInBaseK.java) | | -| 1844 | [Replace All Digits with Characters](https://leetcode.com/problems/replace-all-digits-with-characters) | [![Java](assets/java.png)](src/ReplaceAllDigitsWithCharacters.java) | | -| 1848 | [Minimum Distance to the Target Element](https://leetcode.com/problems/minimum-distance-to-the-target-element) | [![Java](assets/java.png)](src/MinimumDistanceToTheTargetElement.java) | | -| 1854 | [Maximum Population Year](https://leetcode.com/problems/maximum-population-year) | [![Java](assets/java.png)](src/MaximumPopulationYear.java) | | -| 1859 | [Sorting the Sentence](https://leetcode.com/problems/sorting-the-sentence) | [![Java](assets/java.png)](src/SortingTheSentence.java) | | -| 1863 | [Sum of All Subset XOR Totals](https://leetcode.com/problems/sum-of-all-subset-xor-totals) | [![Java](assets/java.png)](src/SumOfAllSubsetXORTotals.java) | | -| 1869 | [Longer Contiguous Segments of Ones than Zeros](https://leetcode.com/problems/longer-contiguous-segments-of-ones-than-zeros) | [![Java](assets/java.png)](src/LongerContiguousSegmentOfOnesThanZeros.java) | | -| 1876 | [Substrings of Size Three with Distinct Characters](https://leetcode.com/problems/substrings-of-size-three-with-distinct-characters) | [![Java](assets/java.png)](src/SubstringsOfSizeThreeWithDistinctCharacters.java) | | -| 1880 | [Check if Word Equals Summation of Two Words](https://leetcode.com/problems/check-if-word-equals-summation-of-two-words) | [![Java](assets/java.png)](src/CheckIfWordEqualsSummationOfTwoWords.java) | | -| 1886 | [Determine Whether Matrix Can Be Obtained By Rotation](https://leetcode.com/problems/determine-whether-matrix-can-be-obtained-by-rotation) | [![Java](assets/java.png)](src/DetermineWhetherMatrixCanBeObtainedByRotation.java) | | -| 1893 | [Check if All the Integers in a Range Are Covered](https://leetcode.com/problems/check-if-all-the-integers-in-a-range-are-covered) | [![Java](assets/java.png)](src/CheckIfAllTheIntegersInARangeAreCovered.java) | | -| 1897 | [Redistribute Characters to Make All Strings Equal](https://leetcode.com/problems/redistribute-characters-to-make-all-strings-equal) | [![Java](assets/java.png)](src/RedistributeCharactersToMakeAllStringsEqual.java) | | -| 1903 | [Largest Odd Number in String](https://leetcode.com/problems/largest-odd-number-in-string) | [![Java](assets/java.png)](src/LargestOddNumberInString.java) | | -| 1909 | [Remove One Element to Make the Array Strictly Increasing](https://leetcode.com/problems/remove-one-element-to-make-the-array-strictly-increasing) | [![Java](assets/java.png)](src/RemoveOneElementToMakeTheArrayStrictlyIncreasing.java) | | -| 1913 | [Maximum Product Difference Between Two Pairs](https://leetcode.com/problems/maximum-product-difference-between-two-pairs) | [![Java](assets/java.png)](src/MaximumProductDifferenceBetweenTwoPairs.java) | | -| 1920 | [Build Array from Permutation](https://leetcode.com/problems/build-array-from-permutation) | [![Java](assets/java.png)](src/BuildArrayFromPermutation.java) | | -| 1925 | [Count Square Sum Triples](https://leetcode.com/problems/count-square-sum-triples) | [![Java](assets/java.png)](src/CountSquareSumTriplets.java) | | -| 1929 | [Concatenation of Array](https://leetcode.com/problems/concatenation-of-array) | [![Java](assets/java.png)](src/ConcatenationOfArray.java) | | -| 1933 | 🔒 [Check If String Is Decomposable Into Value EqualSubstrings](https://leetcode.com/problems/check-if-string-is-decomposable-into-value-equal-substring) | | | -| 1935 | [Maximum Number of Words You Can Type](https://leetcode.com/problems/maximum-number-of-words-you-can-type) | [![Java](assets/java.png)](src/MaximumNumberOfWordsYouCanType.java) | | -| 1941 | [Check if All Characters Have Equal Number of Occurrences](https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences) | [![Java](assets/java.png)](src/CheckIfAllCharactersHaveEqualNumberOfOccurrences.java) | | -| 1945 | [Sum of Digits of String After Convert](https://leetcode.com/problems/sum-of-digits-of-string-after-convert) | [![Java](assets/java.png)](src/SumOfDigitsOfStringAfterConvert.java) | | -| 1952 | [Three Divisors](https://leetcode.com/problems/three-divisors) | [![Java](assets/java.png)](src/ThreeDivisors.java) | | -| 1957 | [Delete Characters to Make Fancy String](https://leetcode.com/problems/delete-characters-to-make-fancy-string) | [![Java](assets/java.png)](src/DeleteCharactersToMakeFancyString.java) | | -| 1961 | [Check If String Is a Prefix of Array](https://leetcode.com/problems/check-if-string-is-a-prefix-of-array) | [![Java](assets/java.png)](src/CheckIfStringIsAPrefixOfArray.java) | | -| 1967 | [Number of Strings That Appear as Substrings in Word](https://leetcode.com/problems/number-of-strings-that-appear-as-substrings-in-word) | [![Java](assets/java.png)](src/NumberOfStringsThatAppearAsSubstringsInWord.java) | | -| 1971 | [Find if Path Exists in Graph](https://leetcode.com/problems/find-if-path-exists-in-graph) | [![Java](assets/java.png)](src/FindIfPathExistsInGraph.java) | | -| 1974 | [Minimum Time to Type Word Using Special Typewriter](https://leetcode.com/problems/minimum-time-to-type-word-using-special-typewriter) | [![Java](assets/java.png)](src/MinimumTimeToTypeWordUsingSpecialTypewriter.java) | | -| 1979 | [Find Greatest Common Divisor of Array](https://leetcode.com/problems/find-greatest-common-divisor-of-array) | [![Java](assets/java.png)](src/FindGreatestCommonDivisorOfArray.java) | | -| 1984 | [Minimum Difference Between Highest and Lowest of K Scores](https://leetcode.com/problems/minimum-difference-between-highest-and-lowest-of-k-scores) | [![Java](assets/java.png)](src/MinimumDifferenceBetweenHighestAndLowestOfKScores.java) | | -| 1991 | [Find the Middle Index in Array](https://leetcode.com/problems/find-the-middle-index-in-array) | [![Java](assets/java.png)](src/FindTheMiddleIndexInArray.java) | | -| 1995 | [Count Special Quadruplets](https://leetcode.com/problems/count-special-quadruplets) | [![Java](assets/java.png)](src/CountSpecialQuadruplets.java) | | -| 2000 | [Reverse Prefix of Word](https://leetcode.com/problems/reverse-prefix-of-word) | [![Java](assets/java.png)](src/ReversePrefixOfWord.java) | | -| 2006 | [Count Number of Pairs With Absolute Difference K](https://leetcode.com/problems/count-number-of-pairs-with-absolute-difference-k) | [![Java](assets/java.png)](src/CountNumberOfPairsWithAbsoluteDifferenceK.java) | | -| 2011 | [Final Value of Variable After Performing Operations](https://leetcode.com/problems/final-value-of-variable-after-performing-operations) | [![Java](assets/java.png)](src/FinalValueOfVariableAfterPerformingOperations.java) | | -| 2016 | [Maximum Difference Between Increasing Elements](https://leetcode.com/problems/maximum-difference-between-increasing-elements) | [![Java](assets/java.png)](src/MaximumDifferenceBetweenIncreasingElements.java) | | -| 2022 | [Convert 1D Array Into 2D Array](https://leetcode.com/problems/convert-1d-array-into-2d-array) | [![Java](assets/java.png)](src/Convert1DArrayInto2DArray.java) | | -| 2027 | [Minimum Moves to Convert String](https://leetcode.com/problems/minimum-moves-to-convert-string) | [![Java](assets/java.png)](src/MinimumMovesToConvertString.java) | | -| 2032 | [Two Out of Three](https://leetcode.com/problems/two-out-of-three) | [![Java](assets/java.png)](src/TwoOutOfThree.java) | | -| 2037 | [Minimum Number of Moves to Seat Everyone](https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone) | [![Java](assets/java.png)](src/MinimumNumberOfMovesToSeatEveryone.java) | | -| 2042 | [Check if Numbers Are Ascending in a Sentence](https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence) | [![Java](assets/java.png)](src/CheckIfNumbersAreAscendingInASentence.java) | | -| 2047 | [Number of Valid Words in a Sentence](https://leetcode.com/problems/number-of-valid-words-in-a-sentence) | [![Java](assets/java.png)](src/NumberOfValidWordsInASentence.java) | | -| 2053 | [Kth Distinct String in an Array](https://leetcode.com/problems/kth-distinct-string-in-an-array) | [![Java](assets/java.png)](src/KthDistinctStringInAnArray.java) | | -| 2057 | [Smallest Index With Equal Value](https://leetcode.com/problems/smallest-index-with-equal-value) | [![Java](assets/java.png)](src/SmallestIndexWithEqualValue.java) | | -| 2062 | [Count Vowel Substrings of a String](https://leetcode.com/problems/count-vowel-substrings-of-a-string) | [![Java](assets/java.png)](src/CountVowelSubstringsOfAString.java) | | -| 2068 | [Check Whether Two Strings are Almost Equivalent](https://leetcode.com/problems/check-whether-two-strings-are-almost-equivalent) | [![Java](assets/java.png)](src/CheckWhetherTwoStringsAreAlmostEquivalent.java) | | -| 2073 | [Time Needed to Buy Tickets](https://leetcode.com/problems/time-needed-to-buy-tickets) | [![Java](assets/java.png)](src/TimeNeededToBuyTickets.java) | | -| 2078 | [Two Furthest Houses With Different Colors](https://leetcode.com/problems/two-furthest-houses-with-different-colors) | [![Java](assets/java.png)](src/TwoFurthestHousesWithDifferentColors.java) | | -| 2085 | [Count Common Words With One Occurrence](https://leetcode.com/problems/count-common-words-with-one-occurrence) | [![Java](assets/java.png)](src/CountCommonWordsWithOneOccurrence.java) | | -| 2089 | [Find Target Indices After Sorting Array](https://leetcode.com/problems/find-target-indices-after-sorting-array) | [![Java](assets/java.png)](src/FindTargetIndicesAfterSortingArray.java) | | -| 2094 | [Finding 3-Digit Even Numbers](https://leetcode.com/problems/finding-3-digit-even-numbers) | [![Java](assets/java.png)](src/Finding3DigitEvenNumbers.java) | | -| 2099 | [Find Subsequence of Length K With the Largest Sum](https://leetcode.com/problems/find-subsequence-of-length-k-with-the-largest-sum) | [![Java](assets/java.png)](src/FindSubsequenceOfLengthKWithTheLargestSum.java) | | -| 2103 | [Rings and Rods](https://leetcode.com/problems/rings-and-rods) | [![Java](assets/java.png)](src/RingsAndRods.java) | | -| 2108 | [Find First Palindromic String in the Array](https://leetcode.com/problems/find-first-palindromic-string-in-the-array) | [![Java](assets/java.png)](src/FindFirstPalindromicStringInArray.java) | | -| 2114 | [Maximum Number of Words Found in Sentences](https://leetcode.com/problems/maximum-number-of-words-found-in-sentences) | [![Java](assets/java.png)](src/MaximumNumberOfWordsFoundInSentences.java) | | -| 2119 | [A Number After a Double Reversal](https://leetcode.com/problems/a-number-after-a-double-reversal) | [![Java](assets/java.png)](src/ANumberAfterADoubleReversal.java) | | -| 2124 | [Check if All A's Appears Before All B's](https://leetcode.com/problems/check-if-all-as-appears-before-all-bs) | [![Java](assets/java.png)](src/CheckIfAllTheAsAppearBeforeAllTheBs.java) | | -| 2129 | [Capitalize the Title](https://leetcode.com/problems/capitalize-the-title) | [![Java](assets/java.png)](src/CapitalizeTheTitle.java) | | -| 2133 | [Check if Every Row and Column Contains All Numbers](https://leetcode.com/problems/check-if-every-row-and-column-contains-all-numbers) | [![Java](assets/java.png)](src/CheckIfEveryRowAndEveryColumnContainAllNumbers.java) | | -| 2138 | [Divide a String Into Groups of Size k](https://leetcode.com/problems/divide-a-string-into-groups-of-size-k) | [![Java](assets/java.png)](src/DivideTheStringIntoGroupsOfSizeK.java) | | -| 2144 | [Minimum Cost of Buying Candies With Discount](https://leetcode.com/problems/minimum-cost-of-buying-candies-with-discount) | [![Java](assets/java.png)](src/MinimumCostOfBuyingCandiesWithDiscount.java) | | -| 2148 | [Count Elements With Strictly Smaller and Greater Elements](https://leetcode.com/problems/count-elements-with-strictly-smaller-and-greater-elements) | [![Java](assets/java.png)](src/CountElementsWithStrictlySmallerAndGreaterElements.java) | | -| 2154 | [Keep Multiplying Found Values by Two](https://leetcode.com/problems/keep-multiplying-found-values-by-two) | [![Java](assets/java.png)](src/KeepMultiplyingFoundValuesByTwo.java) | | -| 2160 | [Minimum Sum of Four Digit Number After Splitting Digits](https://leetcode.com/problems/minimum-sum-of-four-digit-number-after-splitting-digits) | [![Java](assets/java.png)](src/MinimumSumOfFourDigitNumberAfterSplittingDigits.java) | | -| 2164 | [Sort Even and Odd Indices Independently](https://leetcode.com/problems/sort-even-and-odd-indices-independently) | [![Java](assets/java.png)](src/SortEvenAndOddIndicesIndependently.java) | | -| 2169 | [Count Operations to Obtain Zero](https://leetcode.com/problems/count-operations-to-obtain-zero) | [![Java](assets/java.png)](src/CountOperationsToObtainZero.java) | | -| 2176 | [Count Equal and Divisible Pairs in an Array](https://leetcode.com/problems/count-equal-and-divisible-pairs-in-an-array) | [![Java](assets/java.png)](src/CountEqualAndDivisiblePairsInAnArray.java) | | -| 2180 | [Count Integers With Even Digit Sum](https://leetcode.com/problems/count-integers-with-even-digit-sum) | [![Java](assets/java.png)](src/CountIntegersWithEvenDigitSum.java) | | -| 2185 | [Counting Words With a Given Prefix](https://leetcode.com/problems/counting-words-with-a-given-prefix) | [![Java](assets/java.png)](src/CountingWordsWithAGivenPrefix.java) | | -| 2190 | [Most Frequent Number Following Key In an Array](https://leetcode.com/problems/most-frequent-number-following-key-in-an-array) | [![Java](assets/java.png)](src/MostFrequentNumberFollowingKeyInAnArray.java) | | -| 2194 | [Cells in a Range on an Excel Sheet](https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet) | [![Java](assets/java.png)](src/CellsInARangeOnAnExcelSheet.java) | | -| 2200 | [Find All K-Distant Indices in an Array](https://leetcode.com/problems/find-all-k-distant-indices-in-an-array) | [![Java](assets/java.png)](src/FindAllKDistantIndicesInAnArray.java) | | -| 2206 | [Divide Array Into Equal Pairs](https://leetcode.com/problems/divide-array-into-equal-pairs) | [![Java](assets/java.png)](src/DivideArrayIntoEqualPairs.java) | | -| 2210 | [Count Hills and Valleys in an Array](https://leetcode.com/problems/count-hills-and-valleys-in-an-array) | [![Java](assets/java.png)](src/CountHillsAndValleysInAnArray.java) | | -| 2215 | [Find the Difference of Two Arrays](https://leetcode.com/problems/find-the-difference-of-two-arrays) | [![Java](assets/java.png)](src/FindTheDifferenceOfTwoArrays.java) | | -| 2220 | [Minimum Bit Flips to Convert Number](https://leetcode.com/problems/minimum-bit-flips-to-convert-number) | [![Java](assets/java.png)](src/MinimumBitFlipsToConvertNumber.java) | | -| 2224 | [Minimum Number of Operations to Convert Time](https://leetcode.com/problems/minimum-number-of-operations-to-convert-time) | [![Java](assets/java.png)](src/MinimumNumberOfOperationsToConvertTime.java) | | -| 2229 | 🔒 [Check if an array is consecutive](https://leetcode.com/problems/check-if-an-array-is-consecutive) | | | -| 2231 | [Largest Number After Digit Swaps by Parity](https://leetcode.com/problems/largest-number-after-digit-swaps-by-parity) | [![Java](assets/java.png)](src/LargestNumberAfterDigitSwapsByParity.java) | | -| 2235 | [Add Two Integers](https://leetcode.com/problems/add-two-integers) | [![Java](assets/java.png)](src/AddTwoIntegers.java) | | -| 2236 | [Root Equals Sum of Children](https://leetcode.com/problems/root-equals-sum-of-children) | [![Java](assets/java.png)](src/RootEqualsSumOfChildren.java) | | -| 2239 | [Find Closest Number to Zero](https://leetcode.com/problems/find-closest-number-to-zero) | [![Java](assets/java.png)](src/FindClosestNumberToZero.java) | | -| 2243 | [Calculate Digit Sum of a String](https://leetcode.com/problems/calculate-digit-sum-of-a-string) | [![Java](assets/java.png)](src/CalculateDigitSumOfAString.java) | | -| 2248 | [Intersection of Multiple Arrays](https://leetcode.com/problems/intersection-of-multiple-arrays) | [![Java](assets/java.png)](src/IntersectionOfMultipleArrays.java) | | -| 2255 | [Count Prefixes of a Given String](https://leetcode.com/problems/count-prefixes-of-a-given-string) | [![Java](assets/java.png)](src/CountPrefixesOfAGivenString.java) | | -| 2259 | [Remove Digit From Number to Maximize Result](https://leetcode.com/problems/remove-digit-from-number-to-maximize-result) | [![Java](assets/java.png)](src/RemoveDigitFromNumberToMaximizeResult.java) | | -| 2264 | [Largest 3-Same-Digit Number in String](https://leetcode.com/problems/largest-3-same-digit-number-in-string) | [![Java](assets/java.png)](src/Largest3SameDigitNumberInString.java) | | -| 2269 | [Find the K-Beauty of a Number](https://leetcode.com/problems/find-the-k-beauty-of-a-number) | [![Java](assets/java.png)](src/FindTheKBeautyOfANumber.java) | | -| 2273 | [Find Resultant Array After Removing Anagrams](https://leetcode.com/problems/find-resultant-array-after-removing-anagrams) | [![Java](assets/java.png)](src/FindResultantArrayAfterRemovingAnagrams.java) | | -| 2278 | [Percentage of Letter in String](https://leetcode.com/problems/percentage-of-letter-in-string) | [![Java](assets/java.png)](src/PercentageOfLetterInString.java) | | -| 2283 | [Check if Number Has Equal Digit Count and Digit Value](https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value) | [![Java](assets/java.png)](src/CheckIfNumberHasEqualDigitCountAndDigitValue.java) | | -| 2287 | [Rearrange Characters to Make Target String](https://leetcode.com/problems/rearrange-characters-to-make-target-string) | [![Java](assets/java.png)](src/RearrangeCharactersToMakeTargetString.java) | | -| 2293 | [Min Max Game](https://leetcode.com/problems/min-max-game) | [![Java](assets/java.png)](src/MinMaxGame.java) | | -| 2299 | [Strong Password Checker II](https://leetcode.com/problems/strong-password-checker-ii) | [![Java](assets/java.png)](src/StrongPasswordCheckerII.java) | | -| 2300 | [Successful Pairs of Spells and Potions](https://leetcode.com/problems/successful-pairs-of-spells-and-potions) | [![Python](assets/python.png)](python/successfull_pairs_of_spells_and_potions.py) | | -| 2303 | [Calculate Amount Paid in Taxes](https://leetcode.com/problems/calculate-amount-paid-in-taxes) | [![Java](assets/java.png)](src/CalculateAmountPaidInTaxes.java) | | -| 2309 | [Greatest English Letter in Upper and Lower Case](https://leetcode.com/problems/greatest-english-letter-in-upper-and-lower-case) | [![Java](assets/java.png)](src/GreatestEnglishLetterInUpperAndLowerCase.java) | | -| 2315 | [Count Asterisks](https://leetcode.com/problems/count-asterisks) | [![Java](assets/java.png)](src/CountAsterisks.java) [![Python](assets/python.png)](python/successfull_pairs_of_spells_and_potions.py) | | -| 2316 | [Count Unreachable Pairs of Nodes in an Undirected Graph](https://leetcode.com/problems/count-unreachable-pairs-of-nodes-in-an-undirected-graph) | [![Python](assets/python.png)](python/count_unreachable_pair_of_node_in_an_undirectable_graph.py) | | -| 2319 | [Check if Matrix Is X-Matrix](https://leetcode.com/problems/check-if-matrix-is-x-matrix) | [![Java](assets/java.png)](src/CountAsterisks.java) | | -| 2325 | [Decode the Message](https://leetcode.com/problems/decode-the-message) | [![Java](assets/java.png)](src/DecodeTheMessage.java) | | -| 2331 | [Evaluate Boolean Binary Tree](https://leetcode.com/problems/evaluate-boolean-binary-tree) | [![Java](assets/java.png)](src/EvaluateBooleanBinaryTree.java) | | -| 2335 | [Minimum Amount of Time to Fill Cups](https://leetcode.com/problems/minimum-amount-of-time-to-fill-cups) | [![Java](assets/java.png)](src/MinimumAmountOfTimeToFillCups.java) | | -| 2439 | [Minimize Maximum of Array](https://leetcode.com/problems/minimize-maximum-of-array) | [![Python](assets/python.png)](python/minimize_maximum_of_array.py) | | -| 2341 | [Maximum Number of Pairs in Array](https://leetcode.com/problems/maximum-number-of-pairs-in-array) | [![Java](assets/java.png)](src/MaximumNumberOfPairsInArray.java) | | -| 2347 | [Best Poker Hand](https://leetcode.com/problems/best-poker-hand) | [![Java](assets/java.png)](src/BestPokerHand.java) | | -| 2348 | [Number of Zero-Filled Subarrays](https://leetcode.com/problems/number-of-zero-filled-subarrays) | [![Python](assets/python.png)](python/number_of_zero_filled_subarrays.py) | | -| 2351 | [First Letter to Appear Twice](https://leetcode.com/problems/first-letter-to-appear-twice) | [![Java](assets/java.png)](src/FirstLetterToAppearTwice.java) | | -| 2357 | [Make Array Zero by Subtracting Equal Amounts](https://leetcode.com/problems/make-array-zero-by-subtracting-equal-amounts) | [![Java](assets/java.png)](src/MakeArrayZeroBySubtractingEqualAmounts.java) | | -| 2360 | [Longest Cycle in a Graph](https://leetcode.com/problems/longest-cycle-in-a-graph) | [![Python](assets/python.png)](python/longest_cycle_in_graph.py) | | -| 2363 | [Merge Similar Items](https://leetcode.com/problems/merge-similar-items) | [![Java](assets/java.png)](src/MergeSimilarItems.java) | | -| 2367 | [Number of Arithmetic Triplets](https://leetcode.com/problems/number-of-arithmetic-triplets) | [![Java](assets/java.png)](src/NumberOfArithmeticTriplets.java) | | -| 2373 | [Largest Local Values in a Matrix](https://leetcode.com/problems/largest-local-values-in-a-matrix) | [![Java](assets/java.png)](src/LargestLocalValuesInAMatrix.java) | | -| 2379 | [Minimum Recolors to Get K Consecutive Black Blocks](https://leetcode.com/problems/minimum-recolors-to-get-k-consecutive-black-blocks) | [![Java](assets/java.png)](src/MinimumRecolorsToGetKConsecutiveBlackBlocks.java) | | -| 2383 | [Minimum Hours of Training to Win a Competition](https://leetcode.com/problems/minimum-hours-of-training-to-win-a-competition) | [![Java](assets/java.png)](src/MinimumHoursOfTrainingToWinACompetition.java) | | -| 2389 | [Longest Subsequence With Limited Sum](https://leetcode.com/problems/longest-subsequence-with-limited-sum) | [![Java](assets/java.png)](src/LongestSubsequenceWithLimitedSum.java) | | -| 2395 | [Find Subarrays With Equal Sum](https://leetcode.com/problems/find-subarrays-with-equal-sum) | [![Java](assets/java.png)](src/FindSubarraysWithEqualSum.java) | | -| 2399 | [Check Distances Between Same Letters](https://leetcode.com/problems/check-distances-between-same-letters) | [![Java](assets/java.png)](src/CheckDistancesBetweenSameLetters.java) | | -| 2404 | [Most Frequent Even Element](https://leetcode.com/problems/most-frequent-even-element) | [![Java](assets/java.png)](src/MostFrequentEvenElement.java) | | -| 2409 | [Count Days Spent Together](https://leetcode.com/problems/count-days-spent-together) | [![Java](assets/java.png)](src/CountDaysSpentTogether.java) | | -| 2413 | [Smallest Even Multiple](https://leetcode.com/problems/smallest-even-multiple) | [![Java](assets/java.png)](src/SmallestEvenMultiple.java) | | -| 2418 | [Sort the People](https://leetcode.com/problems/sort-the-people) | [![Java](assets/java.png)](src/SortThePeople.java) | | -| 2423 | [Remove Letter To Equalize Frequency](https://leetcode.com/problems/remove-letter-to-equalize-frequency) | [![Java](assets/java.png)](src/RemoveLetterToEqualizeFrequency.java) | | -| 2427 | [Number of Common Factors](https://leetcode.com/problems/number-of-common-factors) | [![Java](assets/java.png)](src/NumberOfCommonFactors.java) | | -| 2432 | [The Employee That Worked on the Longest Task](https://leetcode.com/problems/the-employee-that-worked-on-the-longest-task) | [![Java](assets/java.png)](src/TheEmployeeThatWorkedOnTheLongestTask.java) | | -| 2437 | [Number of Valid Clock Times](https://leetcode.com/problems/number-of-valid-clock-times) | [![Java](assets/java.png)](src/NumberOfValidClockTimes.java) | | -| 2441 | [Largest Positive Integer That Exists With Its Negative](https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative) | [![Java](assets/java.png)](src/LargestPositiveIntegerThatExistsWithItsNegative.java) | | -| 2446 | [Determine if Two Events Have Conflict](https://leetcode.com/problems/determine-if-two-events-have-conflict) | [![Java](assets/java.png)](src/DetermineIfTwoEventsHaveConflict.java) | | -| 2451 | [Odd String Difference](https://leetcode.com/problems/odd-string-difference) | [![Java](assets/java.png)](src/OddStringDifference.java) | | -| 2455 | [Average Value of Even Numbers That Are Divisible by Three](https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three) | [![Java](assets/java.png)](src/AverageValueOfEvenNumbersThatAreDivisibleByThree.java) | | -| 2460 | [Apply Operations to an Array](https://leetcode.com/problems/apply-operations-to-an-array) | [![Java](assets/java.png)](src/ApplyOperationsToAnArray.java) | | -| 2465 | [Number of Distinct Averages](https://leetcode.com/problems/number-of-distinct-averages) | [![Java](assets/java.png)](src/NumberOfDistinctAverages.java) | | -| 2466 | [Count Ways To Build Good Strings](https://leetcode.com/problems/count-ways-to-build-good-strings) | | | -| 2469 | [Convert the Temperature](https://leetcode.com/problems/convert-the-temperature) | [![Java](assets/java.png)](src/ConvertTheTemperature.java) | | -| 2475 | [Number of Unequal Triplets in Array](https://leetcode.com/problems/number-of-unequal-triplets-in-array) | [![Java](assets/java.png)](src/NumberOfUnequalTripletsInArray.java) | | -| 2481 | [Minimum Cuts to Divide a Circle](https://leetcode.com/problems/minimum-cuts-to-divide-a-circle) | [![Java](assets/java.png)](src/MinimumCutsToDivideACircle.java) | | -| 2485 | [Find the Pivot Integer](https://leetcode.com/problems/find-the-pivot-integer) | [![Java](assets/java.png)](src/FindThePivotInteger.java) | | -| 2490 | [Circular Sentence](https://leetcode.com/problems/circular-sentence) | [![Java](assets/java.png)](src/CircularSentence.java) | | -| 2492 | [Minimum Score of a Path Between Two Cities](https://leetcode.com/problems/minimum-score-of-a-path-between-two-cities) | [![Python](assets/python.png)](python/minimum_score_of_a_path_between_two_cities.py) | | -| 2496 | [Maximum Value of a String in an Array](https://leetcode.com/problems/maximum-value-of-a-string-in-an-array) | [![Java](assets/java.png)](src/MaximumValueOfAStringInAnArray.java) | | -| 2500 | [Delete Greatest Value in Each Row](https://leetcode.com/problems/delete-greatest-value-in-each-row) | [![Java](assets/java.png)](src/DeleteGreatestValueInEachRow.java) | | -| 2506 | [Count Pairs Of Similar Strings](https://leetcode.com/problems/count-pairs-of-similar-strings) | [![Java](assets/java.png)](src/CountPairsOfSimilarStrings.java) | | -| 2511 | [Maximum Enemy Forts That Can Be Captured](https://leetcode.com/problems/maximum-enemy-forts-that-can-be-captured) | [![Java](assets/java.png)](src/MaximumEnemyFortsThatCanBeCaptured.java) | | -| 2515 | [Shortest Distance to Target String in a Circular Array](https://leetcode.com/problems/shortest-distance-to-target-string-in-a-circular-array) | [![Java](assets/java.png)](src/ShortestDistanceToTargetStringInACircularArray.java) | | -| 2520 | [Count the Digits That Divide a Number](https://leetcode.com/problems/count-the-digits-that-divide-a-number) | [![Java](assets/java.png)](src/CountTheDigitsThatDivideANumber.java) | | -| 2525 | [Categorize Box According to Criteria](https://leetcode.com/problems/categorize-box-according-to-criteria) | [![Java](assets/java.png)](src/CategorizeBoxAccordingToCriteria.java) | | -| 2529 | [Maximum Count of Positive Integer and Negative Integer](https://leetcode.com/problems/maximum-count-of-positive-integer-and-negative-integer) | [![Java](assets/java.png)](src/MaximumCountOfPositiveIntegerAndNegativeInteger.java) | | -| 2535 | [Difference Between Element Sum and Digit Sum of an Array](https://leetcode.com/problems/difference-between-element-sum-and-digit-sum-of-an-array) | [![Java](assets/java.png)](src/DifferenceBetweenElementSumAndDigitSumOfAnArray.java) | | -| 2540 | [Minimum Common Value](https://leetcode.com/problems/minimum-common-value) | [![Java](assets/java.png)](src/MinimumCommonValue.java) | | -| 2544 | [Alternating Digit Sum](https://leetcode.com/problems/alternating-digit-sum) | [![Java](assets/java.png)](src/AlternatingDigitSum.java) | | -| 2549 | [Count Distinct Numbers on Board](https://leetcode.com/problems/count-distinct-numbers-on-board) | [![Java](assets/java.png)](src/CountDistinctNumbersOnBoard.java) | | -| 2553 | [Separate the Digits in an Array](https://leetcode.com/problems/separate-the-digits-in-an-array) | [![Java](assets/java.png)](src/SeparateTheDigitsInAnArray.java) | | -| 2558 | [Take Gifts From the Richest Pile](https://leetcode.com/problems/take-gifts-from-the-richest-pile) | [![Java](assets/java.png)](src/TakeGiftsFromTheRichestPile.java) | | -| 2562 | [Find the Array Concatenation Value](https://leetcode.com/problems/find-the-array-concatenation-value) | [![Java](assets/java.png)](src/FindTheArrayConcatenationValue.java) | | -| 2566 | [Maximum Difference by Remapping a Digit](https://leetcode.com/problems/maximum-difference-by-remapping-a-digit) | [![Java](assets/java.png)](src/MaximumDifferenceByRemappingADigit.java) | | -| 2570 | [Merge Two 2D Arrays by Summing Values](https://leetcode.com/problems/merge-two-2d-arrays-by-summing-values) | [![Java](assets/java.png)](src/MergeTwo2DArraysBySummingValues.java) | | -| 2574 | [Left and Right Sum Differences](https://leetcode.com/problems/left-and-right-sum-differences) | [![Java](assets/java.png)](src/LeftAndRightSumDifferences.java) | | -| 2578 | [Split With Minimum Sum](https://leetcode.com/problems/split-with-minimum-sum) | [![Java](assets/java.png)](src/SplitWithMinimumSum.java) | | -| 2582 | [Pass the Pillow](https://leetcode.com/problems/pass-the-pillow) | [![Java](assets/java.png)](src/PassThePillow.java) | | -| 2586 | [Count the Number of Vowel Strings in Range](https://leetcode.com/problems/count-the-number-of-vowel-strings-in-range) | [![Java](assets/java.png)](src/CountTheNumberOfVowelStringsInRange.java) | | -| 2591 | [Distribute Money to Maximum Children](https://leetcode.com/problems/distribute-money-to-maximum-children) | [![Java](assets/java.png)](src/DistributeMoneyToMaximumChildren.java) | | -| 2595 | [Number of Even and Odd Bits](https://leetcode.com/problems/number-of-even-and-odd-bits) | [![Java](assets/java.png)](src/NumberOfEvenAndOddBits.java) | | -| 2600 | [K Items With the Maximum Sum](https://leetcode.com/problems/k-items-with-the-maximum-sum) | [![Java](assets/java.png)](src/KItemsWithTheMaximumSum.java) | | -| 2605 | [Form Smallest Number From Two Digit Arrays](https://leetcode.com/problems/form-smallest-number-from-two-digit-arrays) | [![Java](assets/java.png)](src/FormSmallestNumberFromTwoDigitArrays.java) | | -| 2609 | [Find the Longest Balanced Substring of a Binary String](https://leetcode.com/problems/find-the-longest-balanced-substring-of-a-binary-string) | [![Java](assets/java.png)](src/FindTheLongestBalancedSubstringOfABinaryString.java) | | -| 2614 | [Prime In Diagonal](https://leetcode.com/problems/prime-in-diagonal) | [![Java](assets/java.png)](src/PrimeInDiagonal.java) | | -| 2639 | [Find the Width of Columns of a Grid](https://leetcode.com/problems/find-the-width-of-columns-of-a-grid) | [![Java](assets/java.png)](src/FindTheWidthOfColumnsOfAGrid.java) | | -| 2643 | [Row With Maximum Ones](https://leetcode.com/problems/row-with-maximum-ones) | [![Java](assets/java.png)](src/RowWithMaximumOnes.java) | | -| 2644 | [Find the Maximum Divisibility Score](https://leetcode.com/problems/find-the-maximum-divisibility-score) | [![Java](assets/java.png)](src/FindTheMaximumDivisibilityScore.java) | | -| 2651 | [Calculate Delayed Arrival Time](https://leetcode.com/problems/calculate-delayed-arrival-time) | [![Java](assets/java.png)](src/CalculateDelayedArrivalTime.java) | | -| 2652 | [Sum Multiples](https://leetcode.com/problems/sum-multiples) | [![Java](assets/java.png)](src/SumMultiples.java) | | -| 2656 | [Maximum Sum With Exactly K Elements](https://leetcode.com/problems/maximum-sum-with-exactly-k-elements) | [![Java](assets/java.png)](src/MaximumSumWithExactlyKElements.java) | | -| 2660 | [Determine the Winner of a Bowling Game](https://leetcode.com/problems/determine-the-winner-of-a-bowling-game) | [![Java](assets/java.png)](src/DetermineTheWinnerOfABowlingGame.java) | | -| 2670 | [Find the Distinct Difference Array](https://leetcode.com/problems/find-the-distinct-difference-array) | [![Java](assets/java.png)](src/FindTheDistinctDifferenceArray.java) | | -| 2678 | [Number of Senior Citizens](https://leetcode.com/problems/number-of-senior-citizens) | [![Java](assets/java.png)](src/NumberOfSeniorCitizens.java) | | -| 2682 | [Find the Losers of the Circular Game](https://leetcode.com/problems/find-the-losers-of-the-circular-game) | [![Java](assets/java.png)](src/FindTheLosersOfTheCircularGame.java) | | -| 2696 | [Minimum String Length After Removing Substrings](https://leetcode.com/problems/minimum-string-length-after-removing-substrings) | [![Java](assets/java.png)](src/MinimumStringLengthAfterRemovingSubstrings.java) | | -| 2697 | [Lexicographically Smallest Palindrome](https://leetcode.com/problems/lexicographically-smallest-palindrome) | [![Java](assets/java.png)](src/LexicographicallySmallestPalindrome.java) | | -| 2706 | [Buy Two Chocolates](https://leetcode.com/problems/buy-two-chocolates) | [![Java](assets/java.png)](src/BuyTwoChocolates.java) | | -| 2710 | [Remove Trailing Zeros From a String](https://leetcode.com/problems/remove-trailing-zeros-from-a-string) | [![Java](assets/java.png)](src/RemoveTrailingZerosFromAString.java) | | -| 2716 | [Minimize String Length](https://leetcode.com/problems/minimize-string-length) | [![Java](assets/java.png)](src/MinimizeStringLength.java) | | -| 2717 | [Semi-Ordered Permutation](https://leetcode.com/problems/semi-ordered-permutation) | [![Java](assets/java.png)](src/SemiOrderedPermutation.java) | | -| 2728 | [Count Houses in a Circular Street](https://leetcode.com/problems/count-houses-in-a-circular-street) | | | -| 2729 | [Check if The Number is Fascinating](https://leetcode.com/problems/check-if-the-number-is-fascinating) | [![Java](assets/java.png)](src/CheckIfTheNumberIsFascinating.java) | | -| 2733 | [Neither Minimum nor Maximum](https://leetcode.com/problems/neither-minimum-nor-maximum) | [![Java](assets/java.png)](src/NeitherMinimumNorMaximum.java) | | -| 2739 | [Total Distance Traveled](https://leetcode.com/problems/total-distance-traveled) | [![Java](assets/java.png)](src/TotalDistanceTraveled.java) | | -| 2744 | [Find Maximum Number of String Pairs](https://leetcode.com/problems/find-maximum-number-of-string-pairs) | [![Java](assets/java.png)](src/FindMaximumNumberOfStringPairs.java) | | -| 2748 | [Number of Beautiful Pairs](https://leetcode.com/problems/number-of-beautiful-pairs) | [![Java](assets/java.png)](src/NumberOfBeautifulPairs.java) | | -| 2760 | [Longest Even Odd Subarray With Threshold](https://leetcode.com/problems/longest-even-odd-subarray-with-threshold) | [![Java](assets/java.png)](src/LongestEvenOddSubarrayWithThreshold.java) | | -| 2765 | [Longest Alternating Subarray](https://leetcode.com/problems/longest-alternating-subarray) | [![Java](assets/java.png)](src/LongestAlternatingSubarray.java) | | -| 2769 | [Find the Maximum Achievable Number](https://leetcode.com/problems/find-the-maximum-achievable-number) | [![Java](assets/java.png)](src/FindTheMaximumAchievableNumber.java) | | -| 2778 | [Sum of Squares of Special Elements](https://leetcode.com/problems/sum-of-squares-of-special-elements) | [![Java](assets/java.png)](src/SumOfSquaresOfSpecialElements.java) | | -| 2784 | [Check if Array is Good](https://leetcode.com/problems/check-if-array-is-good) | [![Java](assets/java.png)](src/CheckIfArrayIsGood.java) | | -| 2788 | [Split Strings by Separator](https://leetcode.com/problems/split-strings-by-separator) | [![Java](assets/java.png)](src/SplitStringsBySeparator.java) | | -| 2798 | [Number of Employees Who Met the Target](https://leetcode.com/problems/number-of-employees-who-met-the-target) | | | -| 2806 | [Account Balance After Rounded Purchase](https://leetcode.com/problems/account-balance-after-rounded-purchase) | | | -| 2810 | [Faulty Keyboard](https://leetcode.com/problems/faulty-keyboard) | | | \ No newline at end of file diff --git a/src/HelloWorld.java b/src/HelloWorld.java index 1f44d58..521987c 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -1,13 +1,37 @@ -import java.util.*; - public class HelloWorld { - public static void main(String[] args) { - final List words = new ArrayList<>(); - words.add("apple.ball.cat"); - words.add("apple.ball.cat.dog"); + private final int[] memory; + + public HelloWorld(int[] array, int m) { + this.memory = new int[m + 1]; + for (int element : array) { + memory[element]++; + } + for (int i = 1 ; i < memory.length ; i++) { + memory[i] += memory[i - 1]; + } + } - final String word = "apple.ball.cat.dog"; + public int query(int a, int b) { + if (b > memory.length - 1) { + b = memory.length - 1; + } - System.out.println(Arrays.toString(word.split("/."))); + if (a <= 0) { + a = 1; + } else if (a > memory.length - 1) { + a = memory.length; + } + + return this.memory[b] - this.memory[a - 1]; + } + + public static void main(String[] args) { + HelloWorld helloWorld = new HelloWorld(new int[] {1, 2, 3, 4, 5, 1, 2, 1, 2}, 5); + System.out.println(helloWorld.query(0, 0)); + System.out.println(helloWorld.query(0, 1)); + System.out.println(helloWorld.query(0, 2)); + System.out.println(helloWorld.query(3, 3)); + System.out.println(helloWorld.query(20, 30)); + System.out.println(helloWorld.query(10, 15)); } } diff --git a/src/NumberOfEmployeesWhoMetTheTarget.java b/src/NumberOfEmployeesWhoMetTheTarget.java new file mode 100644 index 0000000..225ae91 --- /dev/null +++ b/src/NumberOfEmployeesWhoMetTheTarget.java @@ -0,0 +1,15 @@ +// https://leetcode.com/problems/number-of-employees-who-met-the-target +// T: O(N) +// S: O(1) + +public class NumberOfEmployeesWhoMetTheTarget { + public int numberOfEmployeesWhoMetTarget(int[] hours, int target) { + int employeesWhoMetTarget = 0; + for (int hour : hours) { + if (hour >= target) { + employeesWhoMetTarget++; + } + } + return employeesWhoMetTarget; + } +} From a36d8d529c5019a7e60f09920b9ac8730350cb05 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sun, 20 Aug 2023 15:24:05 +0200 Subject: [PATCH 139/280] solves #2798: Number of Employees Who Met the Target in java --- README.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.txt b/README.txt index b79a7a3..1ed8a95 100644 --- a/README.txt +++ b/README.txt @@ -841,6 +841,6 @@ | 2778 | [Sum of Squares of Special Elements](https://leetcode.com/problems/sum-of-squares-of-special-elements) | [![Java](assets/java.png)](src/SumOfSquaresOfSpecialElements.java) | | | 2784 | [Check if Array is Good](https://leetcode.com/problems/check-if-array-is-good) | [![Java](assets/java.png)](src/CheckIfArrayIsGood.java) | | | 2788 | [Split Strings by Separator](https://leetcode.com/problems/split-strings-by-separator) | [![Java](assets/java.png)](src/SplitStringsBySeparator.java) | | -| 2798 | [Number of Employees Who Met the Target](https://leetcode.com/problems/number-of-employees-who-met-the-target) | | | +| 2798 | [Number of Employees Who Met the Target](https://leetcode.com/problems/number-of-employees-who-met-the-target) | [![Java](assets/java.png)](src/NumberOfEmployeesWhoMetTheTarget.java) | | | 2806 | [Account Balance After Rounded Purchase](https://leetcode.com/problems/account-balance-after-rounded-purchase) | | | | 2810 | [Faulty Keyboard](https://leetcode.com/problems/faulty-keyboard) | | | \ No newline at end of file From 0b5a511f3e514ce2f25862b21019ec0605f65758 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sun, 20 Aug 2023 15:30:01 +0200 Subject: [PATCH 140/280] solves #2806: account balance after rounded purchases --- README.txt | 2 +- src/AccountBalanceAfterRoundedPurchase.java | 10 ++++++++++ src/HelloWorld.java | 9 ++------- 3 files changed, 13 insertions(+), 8 deletions(-) create mode 100644 src/AccountBalanceAfterRoundedPurchase.java diff --git a/README.txt b/README.txt index 1ed8a95..8078b90 100644 --- a/README.txt +++ b/README.txt @@ -842,5 +842,5 @@ | 2784 | [Check if Array is Good](https://leetcode.com/problems/check-if-array-is-good) | [![Java](assets/java.png)](src/CheckIfArrayIsGood.java) | | | 2788 | [Split Strings by Separator](https://leetcode.com/problems/split-strings-by-separator) | [![Java](assets/java.png)](src/SplitStringsBySeparator.java) | | | 2798 | [Number of Employees Who Met the Target](https://leetcode.com/problems/number-of-employees-who-met-the-target) | [![Java](assets/java.png)](src/NumberOfEmployeesWhoMetTheTarget.java) | | -| 2806 | [Account Balance After Rounded Purchase](https://leetcode.com/problems/account-balance-after-rounded-purchase) | | | +| 2806 | [Account Balance After Rounded Purchase](https://leetcode.com/problems/account-balance-after-rounded-purchase) | [![Java](assets/java.png)](src/AccountBalanceAfterRoundedPurchase.java) | | | 2810 | [Faulty Keyboard](https://leetcode.com/problems/faulty-keyboard) | | | \ No newline at end of file diff --git a/src/AccountBalanceAfterRoundedPurchase.java b/src/AccountBalanceAfterRoundedPurchase.java new file mode 100644 index 0000000..f8fd19e --- /dev/null +++ b/src/AccountBalanceAfterRoundedPurchase.java @@ -0,0 +1,10 @@ +// https://leetcode.com/problems/account-balance-after-rounded-purchase +// T: O(1) +// S: O(1) + +public class AccountBalanceAfterRoundedPurchase { + public int accountBalanceAfterPurchase(int purchaseAmount) { + final int purchaseAmountRounded = (int) (Math.round(purchaseAmount / 10.0) * 10); + return 100 - purchaseAmountRounded; + } +} diff --git a/src/HelloWorld.java b/src/HelloWorld.java index 521987c..3e41f1a 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -26,12 +26,7 @@ public int query(int a, int b) { } public static void main(String[] args) { - HelloWorld helloWorld = new HelloWorld(new int[] {1, 2, 3, 4, 5, 1, 2, 1, 2}, 5); - System.out.println(helloWorld.query(0, 0)); - System.out.println(helloWorld.query(0, 1)); - System.out.println(helloWorld.query(0, 2)); - System.out.println(helloWorld.query(3, 3)); - System.out.println(helloWorld.query(20, 30)); - System.out.println(helloWorld.query(10, 15)); + + System.out.println(Math.round(10.5)); } } From bbcc01c4e69099409a3963abe0c9ac5132d9dc38 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sun, 20 Aug 2023 15:34:56 +0200 Subject: [PATCH 141/280] solves #2810: Faulty Keyboard in java --- README.txt | 2 +- src/FaultyKeyboard.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/FaultyKeyboard.java diff --git a/README.txt b/README.txt index 8078b90..1540f49 100644 --- a/README.txt +++ b/README.txt @@ -843,4 +843,4 @@ | 2788 | [Split Strings by Separator](https://leetcode.com/problems/split-strings-by-separator) | [![Java](assets/java.png)](src/SplitStringsBySeparator.java) | | | 2798 | [Number of Employees Who Met the Target](https://leetcode.com/problems/number-of-employees-who-met-the-target) | [![Java](assets/java.png)](src/NumberOfEmployeesWhoMetTheTarget.java) | | | 2806 | [Account Balance After Rounded Purchase](https://leetcode.com/problems/account-balance-after-rounded-purchase) | [![Java](assets/java.png)](src/AccountBalanceAfterRoundedPurchase.java) | | -| 2810 | [Faulty Keyboard](https://leetcode.com/problems/faulty-keyboard) | | | \ No newline at end of file +| 2810 | [Faulty Keyboard](https://leetcode.com/problems/faulty-keyboard) | [![Java](assets/java.png)](src/FaultyKeyboard.java) | | \ No newline at end of file diff --git a/src/FaultyKeyboard.java b/src/FaultyKeyboard.java new file mode 100644 index 0000000..f476f4c --- /dev/null +++ b/src/FaultyKeyboard.java @@ -0,0 +1,18 @@ +// https://leetcode.com/problems/faulty-keyboard +// T: O(N^2) +// S: O(N) + +public class FaultyKeyboard { + public String finalString(String s) { + final StringBuilder stringBuilder = new StringBuilder(); + for (int i = 0 ; i < s.length() ; i++) { + char character = s.charAt(i); + if (character == 'i') { + stringBuilder.reverse(); + } else { + stringBuilder.append(character); + } + } + return stringBuilder.toString(); + } +} From 9b3fc6bb1a7a9a1447933b1f22d757711fc70303 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sun, 20 Aug 2023 15:53:14 +0200 Subject: [PATCH 142/280] solves #2815: Max Pair Sum in an Array in java --- README.txt | 5 ++++- src/MaxPairSumInAnArray.java | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/MaxPairSumInAnArray.java diff --git a/README.txt b/README.txt index 1540f49..a8ef0a2 100644 --- a/README.txt +++ b/README.txt @@ -843,4 +843,7 @@ | 2788 | [Split Strings by Separator](https://leetcode.com/problems/split-strings-by-separator) | [![Java](assets/java.png)](src/SplitStringsBySeparator.java) | | | 2798 | [Number of Employees Who Met the Target](https://leetcode.com/problems/number-of-employees-who-met-the-target) | [![Java](assets/java.png)](src/NumberOfEmployeesWhoMetTheTarget.java) | | | 2806 | [Account Balance After Rounded Purchase](https://leetcode.com/problems/account-balance-after-rounded-purchase) | [![Java](assets/java.png)](src/AccountBalanceAfterRoundedPurchase.java) | | -| 2810 | [Faulty Keyboard](https://leetcode.com/problems/faulty-keyboard) | [![Java](assets/java.png)](src/FaultyKeyboard.java) | | \ No newline at end of file +| 2810 | [Faulty Keyboard](https://leetcode.com/problems/faulty-keyboard) | [![Java](assets/java.png)](src/FaultyKeyboard.java) | | +| 2815 | [Max Pair Sum in an Array](https://leetcode.com/problems/max-pair-sum-in-an-array) | [![Java](assets/java.png)](src/MaxPairSumInAnArray.java) | | +| 2824 | [Count Pairs Whose Sum is Less than Target](https://leetcode.com/problems/count-pairs-whose-sum-is-less-than-target) | [![Java](assets/java.png)](src/) | | +| 2828 | [Check if a String Is an Acronym of Words](https://leetcode.com/problems/check-if-a-string-is-an-acronym-of-words) | [![Java](assets/java.png)](src/) | | \ No newline at end of file diff --git a/src/MaxPairSumInAnArray.java b/src/MaxPairSumInAnArray.java new file mode 100644 index 0000000..0b9499f --- /dev/null +++ b/src/MaxPairSumInAnArray.java @@ -0,0 +1,27 @@ +// https://leetcode.com/problems/max-pair-sum-in-an-array +// T: O(N) +// S: O(1) + +public class MaxPairSumInAnArray { + public int maxSum(int[] nums) { + final int[] digitMaxSum = new int[9]; + int maxPairSum = 0; + for (int element : nums) { + final int maxDigit = getMaxDigit(element); + if (digitMaxSum[maxDigit - 1] != 0) { + maxPairSum = Math.max(maxPairSum, digitMaxSum[maxDigit - 1] + element); + } + digitMaxSum[maxDigit - 1] = Math.max(digitMaxSum[maxDigit - 1], element); + } + return maxPairSum == 0 ? -1 : maxPairSum; + } + + private int getMaxDigit(int number) { + final String string = number + ""; + int maxDigit = 0; + for (int i = 0 ; i < string.length() ; i++) { + maxDigit = Math.max(maxDigit, string.charAt(i) - '0'); + } + return maxDigit; + } +} From f54c9caeb5d4905f0ed90b9f10d20d40c3e0343a Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sun, 20 Aug 2023 16:51:12 +0200 Subject: [PATCH 143/280] solves #2824: Count Pairs Whose Sum is Less than Target in java --- README.txt | 2 +- src/CountPairsWhoseSumIsLessThanTarget.java | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 src/CountPairsWhoseSumIsLessThanTarget.java diff --git a/README.txt b/README.txt index a8ef0a2..13cdb70 100644 --- a/README.txt +++ b/README.txt @@ -845,5 +845,5 @@ | 2806 | [Account Balance After Rounded Purchase](https://leetcode.com/problems/account-balance-after-rounded-purchase) | [![Java](assets/java.png)](src/AccountBalanceAfterRoundedPurchase.java) | | | 2810 | [Faulty Keyboard](https://leetcode.com/problems/faulty-keyboard) | [![Java](assets/java.png)](src/FaultyKeyboard.java) | | | 2815 | [Max Pair Sum in an Array](https://leetcode.com/problems/max-pair-sum-in-an-array) | [![Java](assets/java.png)](src/MaxPairSumInAnArray.java) | | -| 2824 | [Count Pairs Whose Sum is Less than Target](https://leetcode.com/problems/count-pairs-whose-sum-is-less-than-target) | [![Java](assets/java.png)](src/) | | +| 2824 | [Count Pairs Whose Sum is Less than Target](https://leetcode.com/problems/count-pairs-whose-sum-is-less-than-target) | [![Java](assets/java.png)](src/CountPairsWhoseSumIsLessThanTarget.java) | | | 2828 | [Check if a String Is an Acronym of Words](https://leetcode.com/problems/check-if-a-string-is-an-acronym-of-words) | [![Java](assets/java.png)](src/) | | \ No newline at end of file diff --git a/src/CountPairsWhoseSumIsLessThanTarget.java b/src/CountPairsWhoseSumIsLessThanTarget.java new file mode 100644 index 0000000..25c2f1e --- /dev/null +++ b/src/CountPairsWhoseSumIsLessThanTarget.java @@ -0,0 +1,21 @@ +// https://leetcode.com/problems/count-pairs-whose-sum-is-less-than-target/description +// T: O(NlogN) +// S: O(logN) + +import java.util.List; + +public class CountPairsWhoseSumIsLessThanTarget { + public int countPairs(List nums, int target) { + int pairs = 0; + nums.sort(Integer::compareTo); + for (int i = 0, j = nums.size() - 1 ; i < j ; ) { + if (nums.get(i) + nums.get(j) < target) { + pairs += j - i; + i++; + } else { + j--; + } + } + return pairs; + } +} From bcbcdd9752b606e9b91174644f00d32226a80c4f Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sun, 20 Aug 2023 16:54:31 +0200 Subject: [PATCH 144/280] solves #2828: Check if a String Is an Acronym of Words in java --- README.txt | 2 +- src/CheckIfAStringIsAnAcronymOfWords.java | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 src/CheckIfAStringIsAnAcronymOfWords.java diff --git a/README.txt b/README.txt index 13cdb70..70dae25 100644 --- a/README.txt +++ b/README.txt @@ -846,4 +846,4 @@ | 2810 | [Faulty Keyboard](https://leetcode.com/problems/faulty-keyboard) | [![Java](assets/java.png)](src/FaultyKeyboard.java) | | | 2815 | [Max Pair Sum in an Array](https://leetcode.com/problems/max-pair-sum-in-an-array) | [![Java](assets/java.png)](src/MaxPairSumInAnArray.java) | | | 2824 | [Count Pairs Whose Sum is Less than Target](https://leetcode.com/problems/count-pairs-whose-sum-is-less-than-target) | [![Java](assets/java.png)](src/CountPairsWhoseSumIsLessThanTarget.java) | | -| 2828 | [Check if a String Is an Acronym of Words](https://leetcode.com/problems/check-if-a-string-is-an-acronym-of-words) | [![Java](assets/java.png)](src/) | | \ No newline at end of file +| 2828 | [Check if a String Is an Acronym of Words](https://leetcode.com/problems/check-if-a-string-is-an-acronym-of-words) | [![Java](assets/java.png)](src/CheckIfAStringIsAnAcronymOfWords.java) | | \ No newline at end of file diff --git a/src/CheckIfAStringIsAnAcronymOfWords.java b/src/CheckIfAStringIsAnAcronymOfWords.java new file mode 100644 index 0000000..4402f61 --- /dev/null +++ b/src/CheckIfAStringIsAnAcronymOfWords.java @@ -0,0 +1,21 @@ +// https://leetcode.com/problems/check-if-a-string-is-an-acronym-of-words +// T: O(N) +// S: O(1) + +import java.util.List; + +public class CheckIfAStringIsAnAcronymOfWords { + public boolean isAcronym(List words, String s) { + if (words.size() != s.length()) { + return false; + } + + for (int i = 0 ; i < words.size() ; i++) { + if (words.get(i).charAt(0) != s.charAt(i)) { + return false; + } + } + + return true; + } +} From ea43fcea7106035675b9e7cd3f569b8256c0817a Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sun, 20 Aug 2023 17:43:48 +0200 Subject: [PATCH 145/280] solves #300: Longest Increasing Subsequence in java --- README.txt | 2 +- src/LongestIncreasingSubsequence.java | 43 +++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 src/LongestIncreasingSubsequence.java diff --git a/README.txt b/README.txt index 70dae25..6fd07ef 100644 --- a/README.txt +++ b/README.txt @@ -246,7 +246,7 @@ | 294 | 🔒 [Flip Game II](https://leetcode.com/problems/flip-game-ii) | | | | 298 | 🔒 [Binary Tree Longest Consecutive Sequence](https://leetcode.com/problems/binary-tree-longest-consecutive-sequence) | | | | 299 | [Bulls and Cows](https://leetcode.com/problems/bulls-and-cows) | [![Java](assets/java.png)](src/BullsAndCows.java) [![Python](assets/python.png)](python/bulls_and_cows.py) | | -| 300 | [Longest Increasing Subsequence](https://leetcode.com/problems/longest-increasing-subsequence) | | | +| 300 | [Longest Increasing Subsequence](https://leetcode.com/problems/longest-increasing-subsequence) | [![Java](assets/java.png)](src/LongestIncreasingSubsequence.java) | | | 303 | [Range Sum Query - Immutable](https://leetcode.com/problems/range-sum-query-immutable) | [![Java](assets/java.png)](src/RangeSumQueryImmutable.java) [![Python](assets/python.png)](python/range_sum_query_immutable.py) | | | 304 | [Range Sum Query 2D - Immutable](https://leetcode.com/problems/range-sum-query-2d-immutable) | | | | 306 | [Additive Number](https://leetcode.com/problems/additive-number) | | | diff --git a/src/LongestIncreasingSubsequence.java b/src/LongestIncreasingSubsequence.java new file mode 100644 index 0000000..ce15838 --- /dev/null +++ b/src/LongestIncreasingSubsequence.java @@ -0,0 +1,43 @@ +// https://leetcode.com/problems/longest-increasing-subsequence +// T: O(NlogN) +// S: O(N) + +import java.util.ArrayList; +import java.util.List; + +public class LongestIncreasingSubsequence { + public static int lengthOfLIS(int[] nums) { + final List tail = new ArrayList<>(); + int maxLength = 1; + tail.add(nums[0]); + + for (int i = 1 ; i < nums.length ; i++) { + if (nums[i] > tail.get(maxLength - 1)) { + tail.add(nums[i]); + maxLength++; + } else if (nums[i] < tail.get(0)) { + tail.set(0, nums[i]); + } else { + int insertionIndex = binarySearch(tail, nums[i]); + tail.set(insertionIndex, nums[i]); + } + } + + return maxLength; + } + + private static int binarySearch(List array, int x) { + int left = 0, right = array.size(), middle; + while (left <= right) { + middle = left + (right - left) / 2; + if (array.get(middle) == x) return middle; + else if (array.get(middle) < x) left = middle + 1; + else right = middle - 1; + } + return left; + } + + public static void main(String[] args) { + System.out.println(lengthOfLIS(new int[] {1,3,6,7,9,4,10,5,6})); + } +} From e6569cdad35dae554100e8b21f790f14f2ae288c Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 31 Aug 2023 14:23:00 +0200 Subject: [PATCH 146/280] solves Edit distance in java --- README.txt | 1 + src/EditDistance.java | 42 ++++++++++++++++++++++ src/RangeSumQuery2DImmutable.java | 58 +++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 src/EditDistance.java create mode 100644 src/RangeSumQuery2DImmutable.java diff --git a/README.txt b/README.txt index 6fd07ef..13c2c65 100644 --- a/README.txt +++ b/README.txt @@ -70,6 +70,7 @@ | 69 | [Sqrt(x)](https://leetcode.com/problems/sqrtx) | [![Java](assets/java.png)](src/Sqrtx.java) [![Python](assets/python.png)](python/sqrt.py) | | | 70 | [Climbing Stairs](https://leetcode.com/problems/climbing-stairs) | [![Java](assets/java.png)](src/ClimbingStairs.java) [![Python](assets/python.png)](python/climbing_stairs.py) | | | 71 | [Simplify Path](https://leetcode.com/problems/simplify-path) | [![Java](assets/java.png)](src/SimplifyPath.java) | | +| 72 | [Edit Distance](https://leetcode.com/problems/edit-distance) | [![Java](assets/java.png)](src/EditDistance.java) | | | 73 | [Set Matrix Zeroes](https://leetcode.com/problems/set-matrix-zeroes) | [![Java](assets/java.png)](src/SetMatrixZeroes.java) | | | 74 | [Search a 2D Matrix](https://leetcode.com/problems/search-a-2d-matrix) | [![Java](assets/java.png)](src/SearchA2DMatrix.java) | | | 75 | [Sort Colors](https://leetcode.com/problems/sort-colors) | [![Java](assets/java.png)](src/SortColors.java) | | diff --git a/src/EditDistance.java b/src/EditDistance.java new file mode 100644 index 0000000..b5681db --- /dev/null +++ b/src/EditDistance.java @@ -0,0 +1,42 @@ +// https://leetcode.com/problems/edit-distance +// T: O(m * n) +// S: O(m * n) + +public class EditDistance { + public int minDistance(String word1, String word2) { + if (word1.isEmpty()) return word2.length(); + if (word2.isEmpty()) return word1.length(); + + final int rows = word1.length() + 1, columns = word2.length() + 1; + final int[][] dp = new int[rows][columns]; + + dp[0][0] = 0; + + // first row + for (int column = 1 ; column < columns ; column++) { + dp[0][column] = column; + } + + // first column + for (int row = 1 ; row < rows ; row++) { + dp[row][0] = row; + } + + // rest of table + for (int row = 1 ; row < rows ; row++) { + for (int column = 1 ; column < columns ; column++) { + if (word1.charAt(row - 1) == word2.charAt(column - 1)) { + dp[row][column] = dp[row - 1][column - 1]; + } else { + dp[row][column] = min(dp[row - 1][column - 1], dp[row - 1][column], dp[row][column - 1]) + 1; + } + } + } + + return dp[rows - 1][columns - 1]; + } + + private int min(int a, int b, int c) { + return Math.min(Math.min(a, b), c); + } +} diff --git a/src/RangeSumQuery2DImmutable.java b/src/RangeSumQuery2DImmutable.java new file mode 100644 index 0000000..e35715b --- /dev/null +++ b/src/RangeSumQuery2DImmutable.java @@ -0,0 +1,58 @@ +// https://leetcode.com/problems/range-sum-query-2d-immutable +// n: matrix.length +// m: matrix[0].length + + +class NumMatrix { + + final int rows; + final int columns; + final int[][] dp; + + // T: O(n * m) + // S: O(n * m) + public NumMatrix(int[][] matrix) { + this.rows = matrix.length; + this.columns = matrix[0].length; + this.dp = new int[rows][columns]; + + // first row + dp[0][0] = matrix[0][0]; + for (int column = 1 ; column < columns ; column++) { + dp[0][column] = dp[0][column - 1] + matrix[0][column]; + } + + // first column + for (int row = 1 ; row < rows ; row++) { + dp[row][0] = dp[row - 1][0] + matrix[row][0]; + } + + // rest of the matrix + for (int row = 1 ; row < rows ; row++) { + for (int column = 1 ; column < columns ; column++) { + dp[row][column] = dp[row - 1][column] + dp[row][column - 1] - dp[row - 1][column - 1] + + matrix[row][column]; + } + } + } + + // T: O(1) + // S: O(1) + public int sumRegion(int row1, int col1, int row2, int col2) { + int result = this.dp[row2][col2]; + if (row1 > 0) { + result -= this.dp[row1 - 1][col2]; + } + if (col1 > 0) { + result -= this.dp[row2][col1 - 1]; + } + if (row1 > 0 && col1 > 0) { + result += this.dp[row1 - 1][col1 - 1]; + } + return result; + } +} + +public class RangeSumQuery2DImmutable { + +} From 4502cb0fdf320386d7cd89fd5575afe6638fabe4 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 31 Aug 2023 14:23:44 +0200 Subject: [PATCH 147/280] adds a readme.md file --- README.md | 850 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 850 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..13c2c65 --- /dev/null +++ b/README.md @@ -0,0 +1,850 @@ +# LeetCode Algorithms + +![problems-solved](https://img.shields.io/badge/Problems%20Solved-682/2813-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-674/2813-1abc9c.svg) +![problems-solved-python](https://img.shields.io/badge/Python-205/2813-1abc9c.svg) +![problems-solved-javascript](https://img.shields.io/badge/JavaScript-4/2813-1abc9c.svg) +[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md) +[![cp](https://img.shields.io/badge/also%20see-Competitve%20Programming-1f72ff.svg)](https://github.com/anishLearnsToCode/competitive-programming) + +🔒 = Subscription Content + +## Problems +| # | Name | Solution | Youtube | +|:----:|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:---------------------------------------------------------------------------------------------------------------------------------:| +| 1 | [Two Sum](https://leetcode.com/problems/two-sum) | [![Java](assets/java.png)](src/TwoSum.java) [![Python](assets/python.png)](python/two_sum.py) | [![java-yt](assets/java-yt.png)](https://youtu.be/9wSL_7NN-A8) [![python-yt](assets/python-yt.png)](https://youtu.be/N5FXCTg0TDE) | +| 2 | [Add Two Numbers](https://leetcode.com/problems/add-two-numbers) | [![Java](assets/java.png)](src/AddTwoNumbers.java) [![js](assets/javascript.png)](javascript/AddTwoNumbers.js) | | +| 3 | [Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters) | [![Java](assets/java.png)](src/LongestSubstringWithoutRepeatingCharacters.java) | | +| 5 | [Longest Palindromic Substring](https://leetcode.com/problems/longest-palindromic-substring) | [![Java](assets/java.png)](src/LongestPalindromicSubstring.java) | | +| 6 | [Zigzag Conversion](https://leetcode.com/problems/zigzag-conversion) | [![Java](assets/java.png)](src/ZigZagConversion.java) | | +| 7 | [Reverse Integer](https://leetcode.com/problems/reverse-integer) | [![Java](assets/java.png)](src/ReverseInteger.java) [![Python](assets/python.png)](python/reverse_integer.py) [![js](assets/javascript.png)](javascript/ReverseInteger.js) | [![java-yt](assets/java-yt.png)](https://youtu.be/7bOhyl5lWjI) [![python-yt](assets/python-yt.png)](https://youtu.be/lmLG30TLcSg) | +| 8 | [String to Integer (atoi)](https://leetcode.com/problems/string-to-integer-atoi) | [![Java](assets/java.png)](src/StringToIntegerAtoi.java) | | +| 9 | [Palindrome Number](https://leetcode.com/problems/palindrome-number) | [![Java](assets/java.png)](src/PalindromeNumber.java) [![Python](assets/python.png)](python/palindrome_number.py) [![js](assets/javascript.png)](javascript/PalindromeNumber.js) | | +| 11 | [Container With Most Water](https://leetcode.com/problems/container-with-most-water) | [![Java](assets/java.png)](src/ContainerWitMostWater.java) | | +| 12 | [Integer to Roman](https://leetcode.com/problems/integer-to-roman) | [![Java](assets/java.png)](src/IntegerToRoman.java) | | +| 13 | [Roman To Integer](https://leetcode.com/problems/roman-to-integer/) | [![Java](assets/java.png)](src/RomanToInteger.java) [![Python](assets/python.png)](python/roman_to_integer.py) | [![java-yt](assets/java-yt.png)](https://youtu.be/BCue_mO_81A) [![python-yt](assets/python-yt.png)](https://youtu.be/8h_yGTNvKMA) | +| 14 | [Longest Common Prefix](https://leetcode.com/problems/longest-common-prefix/) | [![Java](assets/java.png)](src/LongestCommonPrefix.java) [![Python](assets/python.png)](python/longest_common_prefix.py) | | +| 15 | [3Sum](https://leetcode.com/problems/3sum) | [![Java](assets/java.png)](src/ThreeSum.java) | | +| 16 | [3Sum Closest](https://leetcode.com/problems/3sum-closest) | [![Java](assets/java.png)](src/ThreeSumClosest.java) | | +| 17 | [Letter Combinations of a Phone Number](https://leetcode.com/problems/letter-combinations-of-a-phone-number) | [![Java](assets/java.png)](src/LetterCombinationsOfAPhoneNumber.java) | | +| 18 | [4Sum](https://leetcode.com/problems/4sum) | [![Java](assets/java.png)](src/FourSum.java) | | +| 19 | [Remove Nth Node From End of List](https://leetcode.com/problems/remove-nth-node-from-end-of-list) | [![Java](assets/java.png)](src/RemoveNthNodeFromEndOfList.java) | | +| 20 | [ValidParentheses](https://leetcode.com/problems/valid-parentheses/) | [![Java](assets/java.png)](src/ValidParentheses.java) [![Python](assets/python.png)](python/valid_parentheses.py) | | +| 21 | [Merge 2 Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/) | [![Java](assets/java.png)](src/Merge2SortedLists.java) [![Python](assets/python.png)](python/merge_2_sorted_lists.py) | | +| 22 | [Generate Parentheses](https://leetcode.com/problems/generate-parentheses) | [![Java](assets/java.png)](src/GenerateParentheses.java) | | +| 24 | [Swap Nodes in Pairs](https://leetcode.com/problems/swap-nodes-in-pairs) | [![Java](assets/java.png)](src/SwapNodesInPairs.java) | | +| 26 | [Remove Duplicates From Sorted Array](https://leetcode.com/problems/remove-duplicates-from-sorted-array) | [![Java](assets/java.png)](src/RemoveDuplicatesFromSortedArray.java) [![Python](assets/python.png)](python/remove_duplicates_from_sorted_array.py) [![js](assets/javascript.png)](javascript/RemoveDuplicatesFromSortedArray.js) | | +| 27 | [Remove Element](https://leetcode.com/problems/remove-element/) | [![Java](assets/java.png)](src/RemoveElement.java) [![Python](assets/python.png)](python/remove_element.py) | | +| 28 | [Needle in Haystack](https://leetcode.com/problems/implement-strstr) | [![Java](assets/java.png)](src/NeedleInHaystack.java) [![Python](assets/python.png)](python/needle_in_haystack.py) | | +| 29 | [Divide Two Integers](https://leetcode.com/problems/divide-two-integers) | [![Java](assets/java.png)](src/DivideTwoIntegers.java) | | +| 31 | [Next Permutation](https://leetcode.com/problems/next-permutation) | [![Java](assets/java.png)](src/NextPermutation.java) | | +| 33 | [Search in Rotated Sorted Array](https://leetcode.com/problems/search-in-rotated-sorted-array) | [![Java](assets/java.png)](src/SearchInRotatedSortedArray.java) | | +| 34 | [Find First and Last Position of Element in Sorted Array](https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array) | [![Java](assets/java.png)](src/FindFirstAndLastPositionOfElementInSortedArray.java) | | +| 35 | [Search Inserted Position](https://leetcode.com/problems/search-insert-position/) | [![Java](assets/java.png)](src/SearchInsertPosition.java) [![Python](assets/python.png)](python/search_insert_position.py) | | +| 36 | [Valid Sudoku](https://leetcode.com/problems/valid-sudoku) | [![Java](assets/java.png)](src/ValidSudoku.java) | | +| 37 | [Sudoku Solver](https://leetcode.com/problems/sudoku-solver) | [![Java](assets/java.png)](src/SudokuSolver.java) | | +| 38 | [Count and Say](https://leetcode.com/problems/count-and-say) | [![Java](assets/java.png)](src/CountAndSay.java) [![Python](assets/python.png)](python/count_and_say.py) | | +| 39 | [Combination Sum](https://leetcode.com/problems/combination-sum) | [![Java](assets/java.png)](src/CombinationSum.java) | | +| 40 | [Combination Sum II](https://leetcode.com/problems/combination-sum-ii) | [![Java](assets/java.png)](src/CombinationSumII.java) | | +| 42 | [Trapping Rain Water](https://leetcode.com/problems/trapping-rain-water) | [![Java](assets/java.png)](src/TrappingRainwater.java) | | +| 43 | [Multiply Strings](https://leetcode.com/problems/multiply-strings) | [![Java](assets/java.png)](src/MultiplyStrings.java) | | +| 45 | [Jump Game II](https://leetcode.com/problems/jump-game-ii) | [![Java](assets/java.png)](src/JumpGameII.java) | | +| 46 | [Permutations](https://leetcode.com/problems/permutations) | [![Java](assets/java.png)](src/Permutations.java) | | +| 47 | [Permutations II](https://leetcode.com/problems/permutations-ii) | [![Java](assets/java.png)](src/PermutationsII.java) | | +| 48 | [Rotate Image](https://leetcode.com/problems/rotate-image) | [![Java](assets/java.png)](src/RotateImage.java) | | +| 49 | [Group Anagrams](https://leetcode.com/problems/group-anagrams) | [![Java](assets/java.png)](src/GroupAnagrams.java) | | +| 50 | [Pow(x,n)](https://leetcode.com/problems/powx-n) | [![Java](assets/java.png)](src/Powxn.java) | | +| 53 | [Maximum SubArray](https://leetcode.com/problems/maximum-subarray) | [![Java](assets/java.png)](src/MaximumSubArray.java) [![Python](assets/python.png)](python/maximum_sum_subarray.py) | | +| 54 | [Spiral Matrix](https://leetcode.com/problems/spiral-matrix) | [![Java](assets/java.png)](src/SpiralMatrix.java) | | +| 55 | [Jump Game](https://leetcode.com/problems/jump-game) | [![Java](assets/java.png)](src/JumpGame.java) | | +| 56 | [Merge Intervals](https://leetcode.com/problems/merge-intervals) | [![Java](assets/java.png)](src/MergeIntervals.java) | | +| 57 | [Insert Interval](https://leetcode.com/problems/insert-interval) | [![Java](assets/java.png)](src/InsertInterval.java) | | +| 58 | [Length of Last Word](https://leetcode.com/problems/length-of-last-word) | [![Java](assets/java.png)](src/LengthOfLastWord.java) [![Python](assets/python.png)](python/length_of_last_word.py) | | +| 59 | [Spiral Matrix II](https://leetcode.com/problems/spiral-matrix-ii) | [![Java](assets/java.png)](src/SpiralMatrixII.java) | | +| 61 | [Rotate List](https://leetcode.com/problems/rotate-list) | [![Java](assets/java.png)](src/RotateList.java) | | +| 62 | [Unique Paths](https://leetcode.com/problems/unique-paths) | [![Java](assets/java.png)](src/UniquePaths.java) | | +| 63 | [Unique Paths II](https://leetcode.com/problems/unique-paths-ii) | [![Java](assets/java.png)](src/UniquePathII.java) | | +| 64 | [Minimum Path Sum](https://leetcode.com/problems/minimum-path-sum) | [![Java](assets/java.png)](src/MinimumPathSum.java) [![Python](assets/python.png)](python/minimum_path_sum.py) | | +| 66 | [Plus One](https://leetcode.com/problems/plus-one) | [![Java](assets/java.png)](src/PlusOne.java) [![Python](assets/python.png)](python/plus_one.py) | | +| 67 | [Add Binary](https://leetcode.com/problems/add-binary) | [![Java](assets/java.png)](src/AddBinary.java) [![Python](assets/python.png)](python/add_binary.py) | | +| 69 | [Sqrt(x)](https://leetcode.com/problems/sqrtx) | [![Java](assets/java.png)](src/Sqrtx.java) [![Python](assets/python.png)](python/sqrt.py) | | +| 70 | [Climbing Stairs](https://leetcode.com/problems/climbing-stairs) | [![Java](assets/java.png)](src/ClimbingStairs.java) [![Python](assets/python.png)](python/climbing_stairs.py) | | +| 71 | [Simplify Path](https://leetcode.com/problems/simplify-path) | [![Java](assets/java.png)](src/SimplifyPath.java) | | +| 72 | [Edit Distance](https://leetcode.com/problems/edit-distance) | [![Java](assets/java.png)](src/EditDistance.java) | | +| 73 | [Set Matrix Zeroes](https://leetcode.com/problems/set-matrix-zeroes) | [![Java](assets/java.png)](src/SetMatrixZeroes.java) | | +| 74 | [Search a 2D Matrix](https://leetcode.com/problems/search-a-2d-matrix) | [![Java](assets/java.png)](src/SearchA2DMatrix.java) | | +| 75 | [Sort Colors](https://leetcode.com/problems/sort-colors) | [![Java](assets/java.png)](src/SortColors.java) | | +| 77 | [Combinations](https://leetcode.com/problems/combinations) | [![Java](assets/java.png)](src/Combinations.java) | | +| 78 | [Subsets](https://leetcode.com/problems/subsets) | [![Java](assets/java.png)](src/Subsets.java) | | +| 79 | [Word Search](https://leetcode.com/problems/word-search) | [![Java](assets/java.png)](src/WordSearch.java) | | +| 80 | [Remove Duplicates from Sorted Array II](https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii) | [![Java](assets/java.png)](src/RemoveDuplicatesFromSortedArrayII.java) | | +| 81 | [Search in Rotated Sorted Array II](https://leetcode.com/problems/search-in-rotated-sorted-array-ii) | [![Java](assets/java.png)](src/SearchInRotatedSortedArrayII.java) | | +| 82 | [Remove Duplicates from Sorted List II](https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii) | [![Java](assets/java.png)](src/RemoveDuplicatesFromSortedListII.java) | | +| 83 | [Remove Duplicates from Sorted List](https://leetcode.com/problems/remove-duplicates-from-sorted-list) | [![Java](assets/java.png)](src/RemoveDuplicatesFromSortedList.java) [![Python](assets/python.png)](python/remove_duplicates_from_linked_list.py) | | +| 86 | [Partition List](https://leetcode.com/problems/partition-list) | [![Java](assets/java.png)](src/PartitionList.java) | | +| 87 | [Scramble String](https://leetcode.com/problems/scramble-string) | [![Python](assets/python.png)](python/scramble_strings.py) | | +| 88 | [Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array) | [![Java](assets/java.png)](src/MergeSortedArray.java) [![Python](assets/python.png)](python/merge_sorted_array.py) | | +| 89 | [Gray Code](https://leetcode.com/problems/gray-code) | [![Java](assets/java.png)](src/GrayCode.java) | | +| 90 | [Subsets II](https://leetcode.com/problems/subsets-ii) | [![Java](assets/java.png)](src/SubsetsII.java) | | +| 91 | [Decode Ways](https://leetcode.com/problems/decode-ways) | [![Java](assets/java.png)](src/DecodeWays.java) | | +| 92 | [Reverse Linked List II](https://leetcode.com/problems/reverse-linked-list-ii) | [![Java](assets/java.png)](src/ReverseLinkedListII.java) | | +| 93 | [Restore IP Addresses](https://leetcode.com/problems/restore-ip-addresses) | [![Java](assets/java.png)](src/RestoreIPAddresses.java) | | +| 94 | [Binary Tree Inorder Traversal](https://leetcode.com/problems/binary-tree-inorder-traversal) | [![Java](assets/java.png)](src/BinaryTreeInorderTraversal.java) [![Python](assets/python.png)](python/binary_tree_inorder_traversal.py) | | +| 95 | [Unique Binary Search Trees II](https://leetcode.com/problems/unique-binary-search-trees-ii) | [![Java](assets/java.png)](src/UniqueBinarySearchTreesII.java) | | +| 96 | [Unique Binary Search Trees](https://leetcode.com/problems/unique-binary-search-trees) | [![Java](assets/java.png)](src/UniqueBinarySearchTrees.java) | | +| 97 | [Interleaving String](https://leetcode.com/problems/interleaving-string) | [![Java](assets/java.png)](src/InterleavingString.java) | | +| 98 | [Validate Binary Search Tree](https://leetcode.com/problems/validate-binary-search-tree) | [![Java](assets/java.png)](src/ValidateBinarySearchTree.java) | | +| 99 | [Recover Binary Search Tree](https://leetcode.com/problems/recover-binary-search-tree) | [![Java](assets/java.png)](src/RecoverBinarySearchTree.java) | | +| 100 | [Same Tree](https://leetcode.com/problems/same-tree) | [![Java](assets/java.png)](src/SameTree.java) [![Python](assets/python.png)](python/same_tree.py) | | +| 101 | [Symmetric Tree](https://leetcode.com/problems/symmetric-tree) | [![Java](assets/java.png)](src/SymmetricTree.java) [![Python](assets/python.png)](python/symmetric_tree.py) | | +| 102 | [Binary Tree Level Order Traversal](https://leetcode.com/problems/binary-tree-level-order-traversal) | [![Java](assets/java.png)](src/BinaryTreeLevelOrderTraversal.java) | | +| 103 | [Binary Tree Zigzag Level Order Traversal](https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal) | [![Java](assets/java.png)](src/BinaryTreeZigzagLevelOrderTraversal.java) | | +| 104 | [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree) | [![Java](assets/java.png)](src/MaximumDepthOfBinaryTree.java) [![Python](assets/python.png)](python/maximum_depth_of_binary_tree.py) | | +| 105 | [Construct Binary Tree from Preorder and Inorder Traversal](https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal) | [![Java](assets/java.png)](src/ConstructBinaryTreeFromPreorderAndInorderTraversal.java) | | +| 106 | [Construct Binary Tree from Inorder and Postorder Traversal](https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal) | [![Java](assets/java.png)](src/ConstructBinaryTreeFromInorderAndPostorderTraversal.java) | | +| 107 | [Binary Tree Level Order Traversal II](https://leetcode.com/problems/binary-tree-level-order-traversal-ii) | [![Java](assets/java.png)](src/BinaryTreeLevelOrderTraversalII.java) [![Python](assets/python.png)](python/binary_tree_level_order_traversal_ii.py) | | +| 108 | [Convert Sorted Array To Binary Search Tree](https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree) | [![Java](assets/java.png)](src/ConvertSortedArrayToBinarySearchTree.java) [![Python](assets/python.png)](python/converted_sorted_array_to_binary_search_tree.py) | | +| 109 | [Convert Sorted List to Binary Search Tree](https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree) | [![Java](assets/java.png)](src/ConvertSortedListToBinarySearchTree.java) | | +| 110 | [Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree) | [![Java](assets/java.png)](src/BalancedBinaryTree.java) [![Python](assets/python.png)](python/balanced_binary_tree.py) | | +| 111 | [Minimum Depth of Binary Tree](https://leetcode.com/problems/minimum-depth-of-binary-tree) | [![Java](assets/java.png)](src/MinimumDepthOfBinaryTree.java) [![Python](assets/python.png)](python/minimum_depth_of_binary_tree.py) | | +| 112 | [Path Sum](https://leetcode.com/problems/path-sum) | [![Java](assets/java.png)](src/PathSum.java) [![Python](assets/python.png)](python/path_sum.py) | | +| 113 | [Path Sum II](https://leetcode.com/problems/path-sum-ii) | [![Java](assets/java.png)](src/PathSumII.java) | | +| 114 | [Flatten Binary Tree to Linked List](https://leetcode.com/problems/flatten-binary-tree-to-linked-list) | [![Java](assets/java.png)](src/FlattenBinaryTreeToLinkedList.java) | | +| 116 | [Populating Next Right Pointers in Each Node](https://leetcode.com/problems/populating-next-right-pointers-in-each-node) | [![Java](assets/java.png)](src/PopulatingNextRightPointersInEachNode.java) | | +| 117 | [Populating Next Right Pointers in Each Node II](https://leetcode.com/problems/populating-next-right-pointers-in-each-node-ii) | [![Java](assets/java.png)](src/PopulatingNextRightPointersInEachNodeII.java) | | +| 118 | [Pascal's Triangle](https://leetcode.com/problems/pascals-triangle) | [![Java](assets/java.png)](src/PascalsTriangle.java) [![Python](assets/python.png)](python/pascals_triangle.py) | | +| 119 | [Pascal's Triangle II](https://leetcode.com/problems/pascals-triangle-ii) | [![Java](assets/java.png)](src/PascalsTriangleII.java) [![Python](assets/python.png)](python/pascals_triangle_ii.py) | | +| 120 | [Triangle](https://leetcode.com/problems/triangle) | [![Java](assets/java.png)](src/Triangle.java) | | +| 121 | [Best Time to Buy and Sell Stocks](https://leetcode.com/problems/best-time-to-buy-and-sell-stock) | [![Java](assets/java.png)](src/BestTimeToBuyAndSellStock.java) [![Python](assets/python.png)](python/best_time_to_buy_and_sell_stock.py) | | +| 122 | [Best Time to Buy and Sell Stocks II](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii) | [![Java](assets/java.png)](src/BestTimeToBuyAndSellStockII.java) [![Python](assets/python.png)](python/best_time_to_buy_and_sell_stock_ii.py) | | +| 125 | [Valid Palindrome](https://leetcode.com/problems/valid-palindrome) | [![Java](assets/java.png)](src/ValidPalindrome.java) [![Python](assets/python.png)](python/valid_palindrome.py) | | +| 128 | [Longest Consecutive Sequence](https://leetcode.com/problems/longest-consecutive-sequence) | [![Java](assets/java.png)](src/LongestConsecutiveSequence.java) | | +| 129 | [Sum Root to Leaf Numbers](https://leetcode.com/problems/sum-root-to-leaf-numbers) | [![Java](assets/java.png)](src/SumRootToLeafNumbers.java) | | +| 130 | [Surrounded Regions](https://leetcode.com/problems/surrounded-regions) | [![Java](assets/java.png)](src/SurroundedRegions.java) | | +| 131 | [Palindrome Partitioning](https://leetcode.com/problems/palindrome-partitioning) | [![Java](assets/java.png)](src/PalindromePartitioning.java) | | +| 133 | [Clone Graph](https://leetcode.com/problems/clone-graph) | [![Java](assets/java.png)](src/CloneGraph.java) [![Python](assets/python.png)](python/clone_graph.py) | | +| 134 | [Gas Station](https://leetcode.com/problems/gas-station) | [![Java](assets/java.png)](src/GasStation.java) | | +| 136 | [Single Number](https://leetcode.com/problems/single-number) | [![Java](assets/java.png)](src/SingleNumber.java) [![Python](assets/python.png)](python/single_number.py) | | +| 137 | [Single Number II](https://leetcode.com/problems/single-number-ii) | [![Java](assets/java.png)](src/SingleNumberII.java) | | +| 138 | [Copy List with Random Pointer](https://leetcode.com/problems/copy-list-with-random-pointer) | [![Java](assets/java.png)](src/CopyListWithRandomPointer.java) | | +| 139 | [Word Break](https://leetcode.com/problems/word-break) | [![Java](assets/java.png)](src/WordBreak.java) | | +| 141 | [Linked List Cycle](https://leetcode.com/problems/linked-list-cycle) | [![Java](assets/java.png)](src/LinkedListCycle.java) [![Python](assets/python.png)](python/linked_list_cycle.py) | | +| 142 | [Linked List Cycle II](https://leetcode.com/problems/linked-list-cycle-ii) | [![Java](assets/java.png)](src/LinkedListCycleII.java) | | +| 143 | [Reorder List](https://leetcode.com/problems/reorder-list) | [![Java](assets/java.png)](src/ReorderList.java) | | +| 144 | [Binary Tree Preorder Traversal](https://leetcode.com/problems/binary-tree-preorder-traversal) | [![Java](assets/java.png)](src/BinaryTreePreOrderTraversal.java) [![Python](assets/python.png)](python/binary_tree_preorder_traversal.py) | | +| 145 | [Binary Tree Postorder Traversal](https://leetcode.com/problems/binary-tree-postorder-traversal) | [![Java](assets/java.png)](src/BinaryTreePostorderTraversal.java) [![Python](assets/python.png)](python/binary_tree_postorder_traversal.py) | | +| 146 | [LRU Cache](https://leetcode.com/problems/lru-cache) | [![Java](assets/java.png)](src/LRUCache.java) | | +| 147 | [Insertion Sort List](https://leetcode.com/problems/insertion-sort-list) | [![Java](assets/java.png)](src/InsertionSortList.java) | | +| 148 | [Sort List](https://leetcode.com/problems/sort-list) | [![Java](assets/java.png)](src/SortList.java) | | +| 150 | [Evaluate Reverse Polish Notation](https://leetcode.com/problems/evaluate-reverse-polish-notation) | [![Java](assets/java.png)](src/EvaluateReversePolishNotation.java) | | +| 151 | [Reverse Words in a String](https://leetcode.com/problems/reverse-words-in-a-string) | [![Java](assets/java.png)](src/ReverseWordsInAString.java) | | +| 152 | [Maximum Product Subarray](https://leetcode.com/problems/maximum-product-subarray) | [![Java](assets/java.png)](src/MaximumProductSubarray.java) | | +| 153 | [Find Minimum in Rotated Sorted Array](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array) | [![Java](assets/java.png)](src/FindMinimumInRotatedSortedArray.java) | | +| 155 | [Min Stack](https://leetcode.com/problems/min-stack) | [![Java](assets/java.png)](src/MinStack.java) [![Python](assets/python.png)](python/min_stack.py) | | +| 156 | 🔒 [Binary Tree Upside Down](https://leetcode.com/problems/binary-tree-upside-down) | | | +| 157 | [Read N Characters Given Read4](https://leetcode.com/problems/read-n-characters-given-read4) | | | +| 159 | 🔒 [Longest Substring With At Most Two Distinct Characters](https://leetcode.com/problems/longest-substring-with-at-most-two-distinct-characters) | | | +| 160 | [Intersection of Two Linked Lists](https://leetcode.com/problems/intersection-of-two-linked-lists) | [![Java](assets/java.png)](src/IntersectionOf2LinkedLists.java) [![Python](assets/python.png)](python/intersecction_of_two_linked_lists.py) | | +| 161 | 🔒 [One Edit Distance](https://leetcode.com/problems/one-edit-distance) | | | +| 162 | [Find Peak Element](https://leetcode.com/problems/find-peak-element) | [![Java](assets/java.png)](src/FindPeakElement.java) | | +| 165 | [Compare Version Numbers](https://leetcode.com/problems/compare-version-numbers) | [![Java](assets/java.png)](src/CompareVersionNumbers.java) | | +| 166 | [Fraction to Recurring Decimal](https://leetcode.com/problems/fraction-to-recurring-decimal) | [![Java](assets/java.png)](src/FractionToRecurringDecimal.java) | | +| 167 | [Two Sum II - Input Array is Sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted) | [![Java](assets/java.png)](src/TwoSumIIInputArrayIsSorted.java) [![Python](assets/python.png)](python/two_sum_ii.py) | | +| 168 | [Excel Sheet Column Title](https://leetcode.com/problems/excel-sheet-column-title) | [![Java](assets/java.png)](src/ExcelSheetColumnTitle.java) [![Python](assets/python.png)](python/excel_sheet_column_title.py) | | +| 169 | [Majority Element](https://leetcode.com/problems/majority-element) | [![Java](assets/java.png)](src/MajorityElement.java) [![Python](assets/python.png)](python/majority_element.py) | | +| 170 | 🔒 [Two Sum III - Data Structure Design](https://leetcode.com/problems/two-sum-iii-data-structure-design) | | | +| 171 | [Excel Sheet Column Number](https://leetcode.com/problems/excel-sheet-column-number) | [![Java](assets/java.png)](src/ExcelSheetColumnNumber.java) [![Python](assets/python.png)](python/excel_sheet_column_number.py) | | +| 172 | [Factoring Trailing Zeroes](https://leetcode.com/problems/factorial-trailing-zeroes) | [![Java](assets/java.png)](src/FactorialTrailingZeros.java) [![Python](assets/python.png)](python/factorial_trailing_zeroes.py) | | +| 173 | [Binary Search Tree Iterator](https://leetcode.com/problems/binary-search-tree-iterator) | [![Java](assets/java.png)](src/BinarySearchTreeIterator.java) | | +| 179 | [Largest Number](https://leetcode.com/problems/largest-number) | [![Java](assets/java.png)](src/LargestNumber.java) | | +| 187 | [Repeated DNA Sequences](https://leetcode.com/problems/repeated-dna-sequences) | [![Java](assets/java.png)](src/RepeatedDNASequences.java) | | +| 189 | [Rotate Array](https://leetcode.com/problems/rotate-array) | [![Java](assets/java.png)](src/RotateArray.java) [![Python](assets/python.png)](python/rotate_array.py) | | +| 190 | [Reverse Bits](https://leetcode.com/problems/reverse-bits) | [![Java](assets/java.png)](src/ReverseBits.java) [![Python](assets/python.png)](python/reverse_bits.py) | | +| 191 | [Number of One Bits](https://leetcode.com/problems/number-of-1-bits) | [![Java](assets/java.png)](src/NumberOf1Bit.java) [![Python](assets/python.png)](python/number_of_1_bits.py) | | +| 198 | [House Robber](https://leetcode.com/problems/house-robber) | [![Java](assets/java.png)](src/HouseRobber.java) [![Python](assets/python.png)](python/house_robber.py) | | +| 199 | [Binary Tree Right Side View](https://leetcode.com/problems/binary-tree-right-side-view) | [![Java](assets/java.png)](src/BinaryTreeRightSideView.java) | | +| 200 | [Number of Islands](https://leetcode.com/problems/number-of-islands) | [![Java](assets/java.png)](src/NumberOfIslands.java) [![Python](assets/python.png)](python/number_of_islands.py) | | +| 201 | [Bitwise AND of Numbers Range](https://leetcode.com/problems/bitwise-and-of-numbers-range) | [![Java](assets/java.png)](src/BitwiseANDOfNumbersRange.java) | | +| 202 | [Happy Number](https://leetcode.com/problems/happy-number) | [![Java](assets/java.png)](src/HappyNumber.java) [![Python](assets/python.png)](python/happy_number.py) | | +| 203 | [Remove Linked List Elements](https://leetcode.com/problems/remove-linked-list-elements) | [![Java](assets/java.png)](src/RemoveLinkedListElements.java) [![Python](assets/python.png)](python/remove_linked_list_elements.py) | | +| 204 | [Count Primes](https://leetcode.com/problems/count-primes) | [![Java](assets/java.png)](src/CountPrimes.java) [![Python](assets/python.png)](python/count_primes.py) | | +| 205 | [Isomorphic Strings](https://leetcode.com/problems/isomorphic-strings) | [![Java](assets/java.png)](src/IsomorphicStrings.java) [![Python](assets/python.png)](python/isomorphic_strings.py) | | +| 206 | [Reverse Linked List](https://leetcode.com/problems/reverse-linked-list) | [![Java](assets/java.png)](src/ReverseLinkedList.java) [![Python](assets/python.png)](python/reverse_linked_list.py) | | +| 207 | [Course Schedule](https://leetcode.com/problems/course-schedule) | [![Java](assets/java.png)](src/CourseSchedule.java) | | +| 208 | [Implement Trie (Prefix Tree)](https://leetcode.com/problems/implement-trie-prefix-tree) | [![Java](assets/java.png)](src/Trie.java) [![Python](assets/python.png)](python/trie.py) | | +| 209 | [Minimum Size Subarray Sum](https://leetcode.com/problems/minimum-size-subarray-sum) | [![Java](assets/java.png)](src/MinimumSizeSubarraySum.java) | | +| 210 | [Course Schedule II](https://leetcode.com/problems/course-schedule-ii) | [![Java](assets/java.png)](src/CourseScheduleII.java) | | +| 211 | [Design Add and Search Words Data Structure](https://leetcode.com/problems/design-add-and-search-words-data-structure) | [![Java](assets/java.png)](src/DesignAddAndSearchWordsDataStructure.java) [![Python](assets/python.png)](python/design_add_and_search_words_data_structure.py) | | +| 213 | [House Robber II](https://leetcode.com/problems/house-robber-ii) | [![Java](assets/java.png)](src/HouseRobberII.java) | | +| 215 | [Kth Largest Element in an Array](https://leetcode.com/problems/kth-largest-element-in-an-array) | [![Java](assets/java.png)](src/KthLargestElementInAnArray.java) | | +| 216 | [Combination Sum III](https://leetcode.com/problems/combination-sum-iii) | [![Java](assets/java.png)](src/CombinationSumIII.java) | | +| 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate) | [![Java](assets/java.png)](src/ContainsDuplicate.java) [![Python](assets/python.png)](python/contains_duplicate.py) | | +| 218 | [The Skyline Problem](https://leetcode.com/problems/the-skyline-problem) | [![Python](assets/python.png)](python/the_skyline_problem.py) | | +| 219 | [Contains Duplicate II](https://leetcode.com/problems/contains-duplicate-ii) | [![Java](assets/java.png)](src/ContainsDuplicateII.java) [![Python](assets/python.png)](python/contains_duplicate_ii.py) | | +| 220 | [Contains Duplicate III](https://leetcode.com/problems/contains-duplicate-iii) | [![Java](assets/java.png)](src/ContainsDuplicateIII.java) | | +| 221 | [Maximal Square](https://leetcode.com/problems/maximal-square) | [![Java](assets/java.png)](src/MaximalSquare.java) | | +| 222 | [Count Complete Tree Nodes](https://leetcode.com/problems/count-complete-tree-nodes) | [![Java](assets/java.png)](src/CountCompleteTreeNodes.java) | | +| 223 | [Rectangle Area](https://leetcode.com/problems/rectangle-area) | [![Java](assets/java.png)](src/RectangleArea.java) | | +| 225 | [Implement Stack using Queues](https://leetcode.com/problems/implement-stack-using-queues) | [![Java](assets/java.png)](src/MyStack.java) [![Python](assets/python.png)](python/implement_stack_using_queues.py) | | +| 226 | [Invert Binary Tree](https://leetcode.com/problems/invert-binary-tree) | [![Java](assets/java.png)](src/InvertBinaryTree.java) [![Python](assets/python.png)](python/invert_binary_tree.py) | | +| 227 | [Basic Calculator II](https://leetcode.com/problems/basic-calculator-ii) | [![Java](assets/java.png)](src/BasicCalculatorII.java) | | +| 229 | [Majority Element II](https://leetcode.com/problems/majority-element-ii) | [![Java](assets/java.png)](src/MajorityElementII.java) | | +| 230 | [Kth Smallest Element in a BST](https://leetcode.com/problems/kth-smallest-element-in-a-bst) | [![Java](assets/java.png)](src/KthSmallestElementInABST.java) | | +| 231 | [Power of Two](https://leetcode.com/problems/power-of-two) | [![Java](assets/java.png)](src/PowerOf2.java) [![Python](assets/python.png)](python/is_power_of_2.py) | | +| 232 | [Implement Queue Using Stacks](https://leetcode.com/problems/implement-queue-using-stacks) | [![Java](assets/java.png)](src/MyQueue.java) [![Python](assets/python.png)](python/implement_queue_using_stacks.py) | | +| 234 | [Palindrome Linked Lists](https://leetcode.com/problems/palindrome-linked-list) | [![Java](assets/java.png)](src/PalindromeLinkedList.java) [![Python](assets/python.png)](python/palindrome_linked_list.py) | | +| 235 | [Lowest Common Ancestor of a Binary Search Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree) | [![Java](assets/java.png)](src/LowestCommonAncestorOfBinarySearchTree.java) [![Python](assets/python.png)](python/lowest_common_ancestor_of_bst.py) | | +| 236 | [Lowest Common Ancestor of a Binary Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree) | [![Java](assets/java.png)](src/LowestCommonAncestorOfBinaryTree.java) | | +| 237 | [Delete a Node In A Linked List](https://leetcode.com/problems/delete-node-in-a-linked-list) | [![Java](assets/java.png)](src/DeleteANodeInLinkedList.java) [![Python](assets/python.png)](python/delete_node_in_linked_list.py) | | +| 238 | [Product of Array Except Self](https://leetcode.com/problems/product-of-array-except-self) | [![Java](assets/java.png)](src/ProductOfArrayExceptItself.java) | | +| 240 | [Search a 2D Matrix II](https://leetcode.com/problems/search-a-2d-matrix-ii) | [![Java](assets/java.png)](src/SearchA2DMatrixII.java) | | +| 241 | [Different Ways to Add Parentheses](https://leetcode.com/problems/different-ways-to-add-parentheses) | | | +| 242 | [Valid Anagram](https://leetcode.com/problems/valid-anagram) | [![Java](assets/java.png)](src/ValidAnagram.java) [![Python](assets/python.png)](python/delete_node_in_linked_list.py) | | +| 243 | 🔒 [Shortest Word Distance](https://leetcode.com/problems/shortest-word-distance) | | | +| 244 | 🔒 [Shortest Word Distance II](https://leetcode.com/problems/shortest-word-distance-ii) | | | +| 245 | 🔒 [Shortest Word Distance III](https://leetcode.com/problems/shortest-word-distance-iii) | | | +| 246 | 🔒 [Strobogramatic Number](https://leetcode.com/problems/strobogrammatic-number) | | | +| 247 | 🔒 [Strobogramatic Number II](https://leetcode.com/problems/strobogrammatic-number-ii) | | | +| 249 | 🔒 [Group Shifted Strings](https://leetcode.com/problems/group-shifted-strings) | | | +| 250 | 🔒 [Count Univalue Subtrees](https://leetcode.com/problems/count-univalue-subtrees) | | | +| 251 | 🔒 [Flatten 2D Vector](https://leetcode.com/problems/flatten-2d-vector) | | | +| 252 | 🔒 [Meeting Rooms](https://leetcode.com/problems/meeting-rooms) | | | +| 253 | 🔒 [Meeting Rooms II](https://leetcode.com/problems/meeting-rooms-ii) | | | +| 254 | 🔒 [Factor Combinations](https://leetcode.com/problems/factor-combinations) | | | +| 255 | 🔒 [Verify Preorder Sequence In Binary Search Tree](https://leetcode.com/problems/verify-preorder-sequence-in-binary-search-tree) | | | +| 256 | 🔒 [Paint House](https://leetcode.com/problems/paint-house) | | | +| 257 | [Binary Tree Paths](https://leetcode.com/problems/binary-tree-paths) | [![Java](assets/java.png)](src/BinaryTreePaths.java) [![Python](assets/python.png)](python/binary_tree_paths.py) | | +| 258 | [Add Digits](https://leetcode.com/problems/add-digits) | [![Java](assets/java.png)](src/AddDigits.java) [![Python](assets/python.png)](python/add_digits.py) | | +| 259 | 🔒 [3Sum Smaller](https://leetcode.com/problems/3sum-smaller) | | | +| 260 | [Single Number III](https://leetcode.com/problems/single-number-iii) | [![Java](assets/java.png)](src/SingleNumberIII.java) | | +| 261 | 🔒 [Graph Valid Tree](https://leetcode.com/problems/graph-valid-tree) | | | +| 263 | [Ugly Number](https://leetcode.com/problems/ugly-number) | [![Java](assets/java.png)](src/UglyNumber.java) [![Python](assets/python.png)](python/ugly_number.py) | | +| 264 | [Ugly Number II](https://leetcode.com/problems/ugly-number-ii) | [![Java](assets/java.png)](src/UglyNumberII.java) | | +| 266 | 🔒 [Palindrome Permutation](https://leetcode.com/problems/palindrome-permutation) | | | +| 267 | 🔒 [Palindrome Permutation II](https://leetcode.com/problems/palindrome-permutation-ii) | | | +| 268 | [Missing Number](https://leetcode.com/problems/missing-number) | [![Java](assets/java.png)](src/MissingNumber.java) [![Python](assets/python.png)](python/missing_number.py) | | +| 270 | 🔒 [Closest Binary Search Tree Value](https://leetcode.com/problems/closest-binary-search-tree-value) | | | +| 271 | 🔒 [Encode and Decode Strings](https://leetcode.com/problems/encode-and-decode-strings) | | | +| 274 | [H-Index](https://leetcode.com/problems/h-index) | [![Java](assets/java.png)](src/HIndex.java) | | +| 275 | [H-Index II](https://leetcode.com/problems/h-index-ii) | [![Java](assets/java.png)](src/HIndexII.java) | | +| 276 | 🔒 [Paint Fence](https://leetcode.com/problems/paint-fence) | | | +| 277 | 🔒 [Find The Celebrity](https://leetcode.com/problems/find-the-celebrity) | | | +| 278 | [First Bad Version](https://leetcode.com/problems/first-bad-version) | [![Java](assets/java.png)](src/FirstBadVersion.java) [![Python](assets/python.png)](python/first_bad_version.py) | | +| 279 | [Perfect Squares](https://leetcode.com/problems/perfect-squares) | [![Java](assets/java.png)](src/PerfectSquares.java) | | +| 280 | 🔒 [Wiggle Sort](https://leetcode.com/problems/wiggle-sort) | | | +| 281 | 🔒 [Zigzag Iterator](https://leetcode.com/problems/zigzag-iterator) | | | +| 283 | [Move Zeroes](https://leetcode.com/problems/move-zeroes) | [![Java](assets/java.png)](src/MoveZeros.java) [![Python](assets/python.png)](python/move_zeroes.py) | | +| 284 | [Peeking Iterator](https://leetcode.com/problems/peeking-iterator) | [![Java](assets/java.png)](src/PeekingIterator.java) | | +| 285 | 🔒 [Inorder Successor in BST](https://leetcode.com/problems/inorder-successor-in-bst) | | | +| 286 | 🔒 [Walls and Gates](https://leetcode.com/problems/walls-and-gates) | | | +| 287 | [Find the Duplicate Number](https://leetcode.com/problems/find-the-duplicate-number) | [![Java](assets/java.png)](src/FindTheDuplicateNumber.java) | | +| 288 | 🔒 [Unique Word Abbreviation](https://leetcode.com/problems/unique-word-abbreviation) | | | +| 289 | [Game of Life](https://leetcode.com/problems/game-of-life) | | | +| 290 | [Word Pattern](https://leetcode.com/problems/word-pattern) | [![Java](assets/java.png)](src/WordPattern.java) [![Python](assets/python.png)](python/word_pattern.py) | | +| 291 | 🔒 [Word Pattern II](https://leetcode.com/problems/word-pattern-ii) | | | +| 292 | [Nim Game](https://leetcode.com/problems/nim-game) | [![Java](assets/java.png)](src/NimGame.java) [![Python](assets/python.png)](python/nim_game.py) | | +| 293 | 🔒 [Flip Game](https://leetcode.com/problems/flip-game) | | | +| 294 | 🔒 [Flip Game II](https://leetcode.com/problems/flip-game-ii) | | | +| 298 | 🔒 [Binary Tree Longest Consecutive Sequence](https://leetcode.com/problems/binary-tree-longest-consecutive-sequence) | | | +| 299 | [Bulls and Cows](https://leetcode.com/problems/bulls-and-cows) | [![Java](assets/java.png)](src/BullsAndCows.java) [![Python](assets/python.png)](python/bulls_and_cows.py) | | +| 300 | [Longest Increasing Subsequence](https://leetcode.com/problems/longest-increasing-subsequence) | [![Java](assets/java.png)](src/LongestIncreasingSubsequence.java) | | +| 303 | [Range Sum Query - Immutable](https://leetcode.com/problems/range-sum-query-immutable) | [![Java](assets/java.png)](src/RangeSumQueryImmutable.java) [![Python](assets/python.png)](python/range_sum_query_immutable.py) | | +| 304 | [Range Sum Query 2D - Immutable](https://leetcode.com/problems/range-sum-query-2d-immutable) | | | +| 306 | [Additive Number](https://leetcode.com/problems/additive-number) | | | +| 307 | [Range Sum Query - Mutable](https://leetcode.com/problems/range-sum-query-mutable) | | | +| 309 | [Best Time to Buy and Sell Stock with Cooldown](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown) | | | +| 310 | [Minimum Height Trees](https://leetcode.com/problems/minimum-height-trees) | | | +| 311 | 🔒 [Sparse Matrix Multiplication](https://leetcode.com/problems/sparse-matrix-multiplication) | | | +| 313 | [Super Ugly Number](https://leetcode.com/problems/super-ugly-number) | | | +| 314 | 🔒 [Binary Tree Vertical Order Traversal](https://leetcode.com/problems/binary-tree-vertical-order-traversal) | | | +| 316 | [Remove Duplicate Letters](https://leetcode.com/problems/remove-duplicate-letters) | | | +| 318 | [Maximum Product of Word Lengths](https://leetcode.com/problems/maximum-product-of-word-lengths) | | | +| 319 | [Bulb Switcher](https://leetcode.com/problems/bulb-switcher) | | | +| 320 | 🔒 [Generalized Abbreviation](https://leetcode.com/problems/generalized-abbreviation) | | | +| 322 | [Coin Change](https://leetcode.com/problems/coin-change) | | | +| 323 | 🔒 [Number of Connected Components in Undirected Graph](https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph) | | | +| 324 | [Wiggle Sort II](https://leetcode.com/problems/wiggle-sort-ii) | | | +| 325 | 🔒 [Maximum Size Subarray Sum Equals K](https://leetcode.com/problems/maximum-size-subarray-sum-equals-k) | | | +| 326 | [Power of Three](https://leetcode.com/problems/power-of-three) | [![Java](assets/java.png)](src/PowerOfThree.java) [![Python](assets/python.png)](python/power_of_three.py) | | +| 328 | [Odd Even Linked List](https://leetcode.com/problems/odd-even-linked-list) | | | +| 331 | [Verify Preorder Serialization of a Binary Tree](https://leetcode.com/problems/verify-preorder-serialization-of-a-binary-tree) | | | +| 331 | 🔒 [Largest BST Subtree](https://leetcode.com/problems/largest-bst-subtree) | | | +| 334 | [Increasing Triplet Subsequence](https://leetcode.com/problems/increasing-triplet-subsequence) | | | +| 337 | [House Robber III](https://leetcode.com/problems/increasing-triplet-subsequence) | | | +| 338 | [Counting Bits](https://leetcode.com/problems/counting-bits/) | [![Java](assets/java.png)](src/CountingBits.java) [![Python](assets/python.png)](python/counting_bits.py) | | +| 339 | 🔒 [Nested List Weight Sum](https://leetcode.com/problems/nested-list-weight-sum) | | | +| 340 | 🔒 [Longest Substring with At Most K Distinct Characters](https://leetcode.com/problems/longest-substring-with-at-most-k-distinct-characters) | | | +| 341 | [Flatten Nested List Iterator](https://leetcode.com/problems/flatten-nested-list-iterator) | | | +| 342 | [Power of Four](https://leetcode.com/problems/power-of-four) | [![Java](assets/java.png)](src/PowerOf4.java) [![Python](assets/python.png)](python/power_of_four.py) | | +| 343 | [Integer Break](https://leetcode.com/problems/integer-break) | | | +| 344 | [Reverse A String](https://leetcode.com/problems/reverse-string) | [![Java](assets/java.png)](src/ReverseString.java) [![Python](assets/python.png)](python/reverse_a_string.py) | | +| 345 | [Reverse Vowels of A String](https://leetcode.com/problems/reverse-vowels-of-a-string) | [![Java](assets/java.png)](src/ReverseVowelsOfString.java) [![Python](assets/python.png)](python/reverse_vowels_of_a_string.py) | | +| 346 | 🔒 [Moving Average From Data Stream](https://leetcode.com/problems/moving-average-from-data-stream) | | | +| 347 | [Top K frequent Elements](https://leetcode.com/problems/top-k-frequent-elements) | | | +| 348 | 🔒 [Design Tic-Tac-Toe](https://leetcode.com/problems/design-tic-tac-toe) | | | +| 349 | [Intersection of 2 Arrays](https://leetcode.com/problems/intersection-of-two-arrays) | [![Java](assets/java.png)](src/IntersectionOfTwoArrays.java) [![Python](assets/python.png)](python/intersection_of_2_array.py) | | +| 350 | [Intersection of 2 Arrays II](https://leetcode.com/problems/intersection-of-two-arrays-ii) | [![Java](assets/java.png)](src/IntersectionOfTwoArraysII.java) [![Python](assets/python.png)](python/intersection_of_2_arrays_II.py) | | +| 351 | 🔒 [Android Unlock Patterns](https://leetcode.com/problems/android-unlock-patterns) | | | +| 355 | [Design Twitter](https://leetcode.com/problems/design-twitter) | | | +| 357 | [Count Numbers with Unique Digits](https://leetcode.com/problems/count-numbers-with-unique-digits) | | | +| 359 | 🔒 [Logger Rate Limiter](https://leetcode.com/problems/logger-rate-limiter) | | | +| 367 | [Valid Perfect Square](https://leetcode.com/problems/valid-perfect-square) | [![Java](assets/java.png)](src/IsPerfectSquare.java) [![Python](assets/python.png)](python/valid_perfect_square.py) | | +| 374 | [Guess Number Higher or Lower](https://leetcode.com/problems/guess-number-higher-or-lower) | [![Java](assets/java.png)](src/GuessNumberHigherOrLower.java) [![Python](assets/python.png)](python/guess_number_higher_or_lower.py) | | +| 383 | [Ransom Note](https://leetcode.com/problems/ransom-note) | [![Java](assets/java.png)](src/RansomNote.java) [![Python](assets/python.png)](python/ransom_note.py) | | +| 387 | [First Unique Character in String](https://leetcode.com/problems/first-unique-character-in-a-string) | [![Java](assets/java.png)](src/FirstUniqueCharacter.java) [![Python](assets/python.png)](python/first_unique_character_in_string.py) | | +| 389 | [Find the Difference](https://leetcode.com/problems/find-the-difference) | [![Java](assets/java.png)](src/FindTheDifference.java) [![Python](assets/python.png)](python/find_the_difference.py) | | +| 392 | [Is Subsequence](https://leetcode.com/problems/is-subsequence) | [![Java](assets/java.png)](src/IsSubsequence.java) [![Python](assets/python.png)](python/is_subsequence.py) | | +| 401 | [Binary Watch](https://leetcode.com/problems/binary-watch) | [![Java](assets/java.png)](src/BinaryWatch.java) [![Python](assets/python.png)](python/binary_watch.py) | | +| 404 | [Sum of Left Leaves](https://leetcode.com/problems/sum-of-left-leaves) | [![Java](assets/java.png)](src/SumOfLeftLeaves.java) [![Python](assets/python.png)](python/sum_of_left_leaves.py) | | +| 405 | [Convert a Number to Hexadecimal](https://leetcode.com/problems/convert-a-number-to-hexadecimal) | [![Java](assets/java.png)](src/ConvertNumberToHexadecimal.java) [![Python](assets/python.png)](python/convert_a_number_to_hexadecimal.py) | | +| 408 | 🔒 [Valid Word Abbreviation](https://leetcode.com/problems/valid-word-abbreviation) | | | +| 409 | [Longest Palindrome](https://leetcode.com/problems/longest-palindrome) | [![Java](assets/java.png)](src/LongestPalindrome.java) [![Python](assets/python.png)](python/longest_palindrome.py) | | +| 412 | [Fizz Buzz](https://leetcode.com/problems/fizz-buzz) | [![Java](assets/java.png)](src/FizzBuzz.java) [![Python](assets/python.png)](python/fizz_buzz.py) | | +| 414 | [Third Maximum Number](https://leetcode.com/problems/third-maximum-number) | [![Java](assets/java.png)](src/ThirdMaximumNumber.java) [![Python](assets/python.png)](python/fizz_buzz.py) | | +| 415 | [Add Strings](https://leetcode.com/problems/add-strings) | [![Java](assets/java.png)](src/AddString.java) [![Python](assets/python.png)](python/add_strings.py) | | +| 422 | 🔒 [Valid Word Square](https://leetcode.com/problems/valid-word-square) | | | +| 430 | [Flatten a Multilevel Doubly Linked List](https://leetcode.com/problems/flatten-a-multilevel-doubly-linked-list) | [![Java](assets/java.png)](src/FlattenAMultiLevelDoublyLinkedList.java) | | +| 434 | [Number of Segments in a String](https://leetcode.com/problems/number-of-segments-in-a-string) | [![Java](assets/java.png)](src/NumberOfSegmentsInString.java) [![Python](assets/python.png)](python/number_of_segments_in_a_string.py) | | +| 441 | [Arranging Coins](https://leetcode.com/problems/arranging-coins) | [![Java](assets/java.png)](src/ArrangingCoins.java) [![Python](assets/python.png)](python/arranging_coins.py) | | +| 443 | [String Compression](https://leetcode.com/problems/string-compression) | [![Java](assets/java.png)](src/StringCompression.java) [![Python](assets/python.png)](python/string_compression.py) | | +| 447 | [Number of Boomerangs](https://leetcode.com/problems/number-of-boomerangs) | [![Java](assets/java.png)](src/NumberOfBoomerangs.java) [![Python](assets/python.png)](python/number_of_boomerangs.py) | | +| 448 | [Find All Numbers Disappeared in an Array](https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array) | [![Java](assets/java.png)](src/FindAllNumbersDisappearedInAnArray.java) [![Python](assets/python.png)](python/find_all_numbers_disappeared_in_an_array.py) | | +| 453 | [Minimum Moves to Equal Array Elements](https://leetcode.com/problems/minimum-moves-to-equal-array-elements) | [![Java](assets/java.png)](src/MinimumMovesToEqualArrayElements.java) [![Python](assets/python.png)](python/minimum_moves_to_equal_array_element.py) | | +| 455 | [Assign Cookies](https://leetcode.com/problems/assign-cookies) | [![Java](assets/java.png)](src/AssignCookies.java) [![Python](assets/python.png)](python/assign_cookies.py) | | +| 459 | [Repeated Substring Pattern](https://leetcode.com/problems/repeated-substring-pattern) | [![Java](assets/java.png)](src/RepeatedSubstringPattern.java) [![Python](assets/python.png)](python/repeated_substring_pattern.py) | | +| 461 | [Hamming Distance](https://leetcode.com/problems/hamming-distance) | [![Java](assets/java.png)](src/HammingDistance.java) [![Python](assets/python.png)](python/hamming_distance.py) | | +| 463 | [Island Perimeter](https://leetcode.com/problems/island-perimeter) | [![Java](assets/java.png)](src/IslandPerimeter.java) [![Python](assets/python.png)](python/island_perimeter.py) | | +| 475 | [Heaters](https://leetcode.com/problems/heaters) | [![Java](assets/java.png)](src/Heaters.java) [![Python](assets/python.png)](python/heaters.py) | | +| 476 | [Number Complement](https://leetcode.com/problems/number-complement) | [![Java](assets/java.png)](src/NumberComplement.java) [![Python](assets/python.png)](python/number_complement.py) | | +| 482 | [License Key Formatting](https://leetcode.com/problems/license-key-formatting) | [![Java](assets/java.png)](src/LicenseKeyFormatting.java) [![Python](assets/python.png)](python/license_key_formatting.py) | | +| 485 | [Max Consecutive Ones](https://leetcode.com/problems/max-consecutive-ones) | [![Java](assets/java.png)](src/MaxConsecutiveOnes.java) [![Python](assets/python.png)](python/max_consecutive_ones.py) | | +| 492 | [Construct the Rectangle](https://leetcode.com/problems/construct-the-rectangle) | [![Java](assets/java.png)](src/ConstructTheRectangle.java) [![Python](assets/python.png)](python/construct_the_rectangle.py) | | +| 495 | [Teemo Attacking](https://leetcode.com/problems/teemo-attacking/) | [![Java](assets/java.png)](src/TeemoAttacking.java) [![Python](assets/python.png)](python/teemo_attacking.py) | | +| 496 | [Next Greater Element I](https://leetcode.com/problems/next-greater-element-i) | [![Java](assets/java.png)](src/NextGreaterElementI.java) [![Python](assets/python.png)](python/next_greater_element_i.py) | | +| 500 | [Keyboard Row](https://leetcode.com/problems/keyboard-row) | [![Java](assets/java.png)](src/KeyBoardRow.java) [![Python](assets/python.png)](python/keyboard_row.py) | | +| 501 | [Find Mode in Binary Search Tree](https://leetcode.com/problems/find-mode-in-binary-search-tree) | [![Java](assets/java.png)](src/FindModeInBinarySearchTree.java) [![Python](assets/python.png)](python/find_mode_in_binary_search_tree.py) | | +| 504 | [Base 7](https://leetcode.com/problems/base-7) | [![Java](assets/java.png)](src/Base7.java) [![Python](assets/python.png)](python/base_7.py) | | +| 506 | [Relative Ranks](https://leetcode.com/problems/relative-ranks) | [![Java](assets/java.png)](src/RelativeRanks.java) [![Python](assets/python.png)](python/relative_ranks.py) | | +| 507 | [Perfect Number](https://leetcode.com/problems/perfect-number) | [![Java](assets/java.png)](src/CheckPerfectNumber.java) [![Python](assets/python.png)](python/check_perfect_number.py) | | +| 509 | [Fibonacci Number](https://leetcode.com/problems/fibonacci-number) | [![Java](assets/java.png)](src/FibonacciNumber.java) [![Python](assets/python.png)](python/fibonacci_number.py) | | +| 520 | [Detect Capital](https://leetcode.com/problems/detect-capital) | [![Java](assets/java.png)](src/DetectCapital.java) [![Python](assets/python.png)](python/detect_capital.py) | | +| 521 | [Longest Uncommon Subsequence I](https://leetcode.com/problems/longest-uncommon-subsequence-i) | [![Java](assets/java.png)](src/LongestUncommonSubsequenceI.java) [![Python](assets/python.png)](python/longest_uncommon_subsequence_I.py) | | +| 530 | [Minimum Absolute Difference in BST](https://leetcode.com/problems/minimum-absolute-difference-in-bst) | [![Java](assets/java.png)](src/MinimumAbsoluteDifferenceInBST.java) [![Python](assets/python.png)](python/minimum_absolute_difference_in_bst.py) | | +| 532 | [K - Diff Pairs in Array](https://leetcode.com/problems/k-diff-pairs-in-an-array) | [![Java](assets/java.png)](src/KDiffPairsInAnArray.java) [![Python](assets/python.png)](python/k_dif_pairs_in_an_array.py) | | +| 538 | [Convert BST to Greater Tree](https://leetcode.com/problems/convert-bst-to-greater-tree) | [![Java](assets/java.png)](src/ConvertBSTToGreaterTree.java) [![Python](assets/python.png)](python/convert_bst_to_greater_tree.py) | | +| 541 | [Reverse String II](https://leetcode.com/problems/reverse-string-ii) | [![Java](assets/java.png)](src/ReverseStringII.java) [![Python](assets/python.png)](python/reverse_string_ii.py) | | +| 543 | [Diameter of Binary Tree](https://leetcode.com/problems/diameter-of-binary-tree) | [![Java](assets/java.png)](src/DiameterOfBinaryTree.java) [![Python](assets/python.png)](python/diameter_of_binary_tree.py) | | +| 551 | [Student Attendance Record I](https://leetcode.com/problems/student-attendance-record-i) | [![Java](assets/java.png)](src/StudentAttendanceRecordI.java) [![Python](assets/python.png)](python/student_attendance_record_I.py) | | +| 557 | [Reverse Words in a String III](https://leetcode.com/problems/reverse-words-in-a-string-iii) | [![Java](assets/java.png)](src/ReverseWordsInStringIII.java) [![Python](assets/python.png)](python/reverse_words_in_string_iii.py) | | +| 559 | [Maximum Depth of N-Ary Tree](https://leetcode.com/problems/maximum-depth-of-n-ary-tree) | [![Java](assets/java.png)](src/MaximumDepthOfNAryTree.java) [![Python](assets/python.png)](python/maximum_depth_of_n_ary_tree.py) | | +| 561 | [Array Partition I](https://leetcode.com/problems/array-partition-i) | [![Java](assets/java.png)](src/ArrayPartitionI.java) [![Python](assets/python.png)](python/array_partiton_I.py) | | +| 563 | [Binary Tree Tilt](https://leetcode.com/problems/binary-tree-tilt) | [![Java](assets/java.png)](src/BinaryTreeTilt.java) [![Python](assets/python.png)](python/binary_tree_tilt.py) | | +| 566 | [Reshape The Matrix](https://leetcode.com/problems/reshape-the-matrix) | [![Java](assets/java.png)](src/ReshapeTheMatrix.java) [![Python](assets/python.png)](python/reshape_the_matrix.py) | | +| 572 | [Subtree of Another Tree](https://leetcode.com/problems/subtree-of-another-tree) | [![Java](assets/java.png)](src/SubtreeOfAnotherTree.java) [![Python](assets/python.png)](python/subtree_of_another_tree.py) | | +| 575 | [Distribute Candies](https://leetcode.com/problems/distribute-candies) | [![Java](assets/java.png)](src/DistributeCandies.java) [![Python](assets/python.png)](python/distribute_candies.py) | | +| 581 | [Shortest Unsorted Continuous Subarray](https://leetcode.com/problems/shortest-unsorted-continuous-subarray) | [![Java](assets/java.png)](src/ShortestUnsortedContinuousSubarray.java) [![Python](assets/python.png)](python/shortest_continuous_unsorted_subarray.py) | | +| 589 | [N-Ary Tree Preorder Traversal](https://leetcode.com/problems/n-ary-tree-preorder-traversal) | [![Java](assets/java.png)](src/NArayTreePreOrderTraversal.java) [![Python](assets/python.png)](python/n_ary_tree_preorder_traversal.py) | | +| 590 | [N-Ary Tree Postorder Traversal](https://leetcode.com/problems/n-ary-tree-postorder-traversal) | [![Java](assets/java.png)](src/NAryTreePostorderTraversal.java) [![Python](assets/python.png)](python/n_ary_tree_postorder_traversal.py) | | +| 594 | [Longest Harmonious Subsequence](https://leetcode.com/problems/longest-harmonious-subsequence) | [![Java](assets/java.png)](src/LongestHarmoniousSubsequence.java) [![Python](assets/python.png)](python/longest_harmonious_subequence.py) | | +| 598 | [Range Addition II](https://leetcode.com/problems/range-addition-ii) | [![Java](assets/java.png)](src/RangeAdditionII.java) [![Python](assets/python.png)](python/range_addition_ii.py) | | +| 599 | [Minimum Index Sum of 2 Lists](https://leetcode.com/problems/minimum-index-sum-of-two-lists) | [![Java](assets/java.png)](src/MinimumIndexSumOfTwoLists.java) [![Python](assets/python.png)](python/minimum_index_sum_of_two_lists.py) | | +| 604 | 🔒 [Design Compressed String Iterator](https://leetcode.com/problems/design-compressed-string-iterator) | | | +| 605 | [Can Place Flowers](https://leetcode.com/problems/can-place-flowers) | [![Java](assets/java.png)](src/CanPlaceFlowers.java) [![Python](assets/python.png)](python/can_place_flowers.py) | | +| 606 | [Construct String from Binary Tree](https://leetcode.com/problems/construct-string-from-binary-tree) | [![Java](assets/java.png)](src/ConstructStringFromBinaryTree.java) [![Python](assets/python.png)](python/construct_string_from_binary_tree.py) | | +| 617 | [Merge Two Binary Trees](https://leetcode.com/problems/merge-two-binary-trees) | [![Java](assets/java.png)](src/MergeTwoBinaryTrees.java) [![Python](assets/python.png)](python/merge_two_binary_trees.py) | | +| 624 | 🔒 [Maximum Distance in Arrays](https://leetcode.com/problems/maximum-distance-in-arrays) | | | +| 628 | [Maximum Product of Three Numbers](https://leetcode.com/problems/maximum-product-of-three-numbers) | [![Java](assets/java.png)](src/MaximumProductOfThreeNumbers.java) [![Python](assets/python.png)](python/maximum_product_of_three_numbers.py) | | +| 633 | [Sum Square Numbers](https://leetcode.com/problems/sum-of-square-numbers) | [![Java](assets/java.png)](src/SumOfSquareNumbers.java) [![Python](assets/python.png)](python/sum_of_squares_numbers.py) | | +| 637 | [Average of Levels in Binary Tree](https://leetcode.com/problems/average-of-levels-in-binary-tree) | [![Java](assets/java.png)](src/AverageLevelsOfBinaryTree.java) [![Python](assets/python.png)](python/average_levels_of_binary_tree.py) | | +| 643 | [Maximum Average SubArray I](https://leetcode.com/problems/maximum-average-subarray-i) | [![Java](assets/java.png)](src/MaximumAverageSubArrayI.java) [![Python](assets/python.png)](python/maximum_average_subarray_I.py) | | +| 645 | [Set Mismatch](https://leetcode.com/problems/set-mismatch) | [![Java](assets/java.png)](src/SetMismatch.java) [![Python](assets/python.png)](python/set_mismatch.py) | | +| 653 | [Two Sum IV - Input is a BST](https://leetcode.com/problems/two-sum-iv-input-is-a-bst) | [![Java](assets/java.png)](src/TwoSumIVInputIsABST.java) [![Python](assets/python.png)](python/two_sum_iv.py) | | +| 657 | [Robot Return to Origin](https://leetcode.com/problems/robot-return-to-origin) | [![Java](assets/java.png)](src/RobotReturnToOrigin.java) [![Python](assets/python.png)](python/robot_return_to_origin.py) | | +| 661 | [Image Smoother](https://leetcode.com/problems/image-smoother) | [![Java](assets/java.png)](src/ImageSmoother.java) [![Python](assets/python.png)](python/image_smoother.py) | | +| 665 | [Non Deceasing Array](https://leetcode.com/problems/non-decreasing-array) | [![Java](assets/java.png)](src/NonDecreasingArray.java) [![Python](assets/python.png)](python/non_decreasing_array.py) | | +| 669 | [Trim a Binary Search Tree](https://leetcode.com/problems/trim-a-binary-search-tree) | [![Java](assets/java.png)](src/TrimABinarySearchTree.java) [![Python](assets/python.png)](python/trim_a_binary_search_tree.py) | | +| 671 | [Second Minimum Node in Binary Tree](https://leetcode.com/problems/second-minimum-node-in-a-binary-tree) | [![Java](assets/java.png)](src/SecondMinimumNodeInBinaryTree.java) [![Python](assets/python.png)](python/second_minimum_node_in_binary_tree.py) | | +| 674 | [Longest Continuous Increasing Subsequence](https://leetcode.com/problems/longest-continuous-increasing-subsequence) | [![Java](assets/java.png)](src/LongestContinuousIncreasingSubsequence.java) [![Python](assets/python.png)](python/longest_continuous_increasing_subsequence.py) | | +| 680 | [Valid Palindrome II](https://leetcode.com/problems/valid-palindrome-ii) | [![Java](assets/java.png)](src/ValidPalindromeII.java) [![Python](assets/python.png)](python/valid_pallindrome_ii.py) | | +| 682 | [Baseball Game](https://leetcode.com/problems/baseball-game) | [![Java](assets/java.png)](src/BaseballGame.java) [![Python](assets/python.png)](python/baseball_game.py) | | +| 686 | [Repeated String Match](https://leetcode.com/problems/repeated-string-match) | | | +| 687 | [Longest Univalue Path](https://leetcode.com/problems/longest-univalue-path) | | | +| 688 | [Knight Probability in Chessboard](https://leetcode.com/problems/knight-probability-in-chessboard) | [![Java](assets/java.png)](src/KnightProbabilityInChessboard.java) | | +| 690 | [Employee Importance](https://leetcode.com/problems/employee-importance) | | | +| 693 | [Binary Number with Alternating Bits](https://leetcode.com/problems/binary-number-with-alternating-bits) | [![Java](assets/java.png)](src/BinaryNumberWithAlternatingBits.java) [![Python](assets/python.png)](python/binary_number_with_alternating_bits.py) | | +| 696 | [Count Binary Substrings](https://leetcode.com/problems/count-binary-substrings) | [![Java](assets/java.png)](src/CountBinarySubstrings.java) [![Python](assets/python.png)](python/count_binary_substrings.py) | | +| 697 | [Degree of an Array](https://leetcode.com/problems/degree-of-an-array) | [![Java](assets/java.png)](src/DegreeOfAnArray.java) [![Python](assets/python.png)](python/degree_of_an_array.py) | | +| 700 | [Search in a Binary Search Tree](https://leetcode.com/problems/search-in-a-binary-search-tree) | [![Java](assets/java.png)](src/SearchInBinarySearchTree.java) [![Python](assets/python.png)](python/search_in_binary_search_tree.py) | | +| 703 | [Kth Largest Element in a Stream](https://leetcode.com/problems/kth-largest-element-in-a-stream) | [![Java](assets/java.png)](src/KthLargestElementInAStream.java) [![Python](assets/python.png)](python/k_th_largest_element_in_a_stream.py) | | +| 704 | [Binary Search](https://leetcode.com/problems/binary-search) | [![Java](assets/java.png)](src/BinarySearch.java) [![Python](assets/python.png)](python/binary_search.py) | | +| 705 | [Design HashSet](https://leetcode.com/problems/design-hashset) | [![Java](assets/java.png)](src/DesignHashSet.java) [![Python](assets/python.png)](python/design_hash_set.py) | | +| 706 | [Design HashMap](https://leetcode.com/problems/design-hashmap) | [![Java](assets/java.png)](src/DesignHashMap.java) [![Python](assets/python.png)](python/design_hash_map.py) | | +| 709 | [To Lower Case](https://leetcode.com/problems/to-lower-case) | [![Java](assets/java.png)](src/ToLowerCase.java) [![Python](assets/python.png)](python/to_lower_case.py) | | +| 716 | 🔒 [Max Stack](https://leetcode.com/problems/max-stack) | | | +| 717 | [1-bit and 2-bit Characters](https://leetcode.com/problems/1-bit-and-2-bit-characters) | [![Java](assets/java.png)](src/OneBitAndTwoBitCharacters.java) [![Python](assets/python.png)](python/one_bit_and_two_bit_characters.py) | | +| 718 | [Maximum Length of Repeated Subarray](https://leetcode.com/problems/maximum-length-of-repeated-subarray) | [![Java](assets/java.png)](src/MaximumLengthOfRepeatedSubArray.java) | | +| 720 | [Longest Word in Dictionary](https://leetcode.com/problems/longest-word-in-dictionary) | | | +| 724 | [Find Pivot Index](https://leetcode.com/problems/find-pivot-index) | [![Java](assets/java.png)](src/FindPivotIndex.java) [![Python](assets/python.png)](python/find_pivot_index.py) | | +| 728 | [Self Dividing Numbers](https://leetcode.com/problems/self-dividing-numbers) | [![Java](assets/java.png)](src/SelfDividingNumbers.java) [![Python](assets/python.png)](python/self_dividing_number.py) | | +| 733 | [Flood Fill](https://leetcode.com/problems/flood-fill) | [![Java](assets/java.png)](src/FloodFill.java) [![Python](assets/python.png)](python/flood_fill.py) | | +| 743 | [Network Delay Time](https://leetcode.com/problems/network-delay-time) | [![Java](assets/java.png)](src/NetworkDelayTime.java) | | +| 734 | [Sentence Similarity](https://leetcode.com/problems/sentence-similarity) | | | +| 744 | [Find Smallest Letter Greater Than Target](https://leetcode.com/problems/find-smallest-letter-greater-than-target) | [![Java](assets/java.png)](src/FindSmallestLetterGreaterThanTarget.java) [![Python](assets/python.png)](python/find_smallest_letter_greater_than.py) | | +| 746 | [Min Cost Climbing Stairs](https://leetcode.com/problems/min-cost-climbing-stairs) | [![Java](assets/java.png)](src/MinCostClimbingStairs.java) [![Python](assets/python.png)](python/min_cost_climbing_stairs.py) | | +| 747 | [Largest Number at least Twice of Others](https://leetcode.com/problems/largest-number-at-least-twice-of-others) | [![Java](assets/java.png)](src/LargestNumberAtLeastTwiceOfOthers.java) [![Python](assets/python.png)](python/largest_number_at_least_twice_of_others.py) | | +| 748 | [Shortest Completing Word](https://leetcode.com/problems/shortest-completing-word) | [![Java](assets/java.png)](src/ShortestCompletingWord.java) [![Python](assets/python.png)](python/shortest_completing_word.py) | | +| 758 | [Bold Words in String](https://leetcode.com/problems/bold-words-in-string) | | | +| 760 | [Find Anagram Mappings](https://leetcode.com/problems/find-anagram-mappings) | | | +| 762 | [Prime Number of Set Bits in Primary Representation](https://leetcode.com/problems/prime-number-of-set-bits-in-binary-representation) | [![Java](assets/java.png)](src/PrimeNumberOfSetBitsInBinaryRepresentation.java) [![Python](assets/python.png)](python/prime_number_of_set_bits_in_binary_representation.py) | | +| 766 | [Toeplitz Matrix](https://leetcode.com/problems/toeplitz-matrix) | [![Java](assets/java.png)](src/ToeplitzMatrix.java) [![Python](assets/python.png)](python/toeplitz_matrix.py) | | +| 771 | [Jewels and Stones](https://leetcode.com/problems/jewels-and-stones) | [![Java](assets/java.png)](src/JewelsAndStones.java) [![Python](assets/python.png)](python/jewels_and_stones.py) | | +| 783 | [Minimum Distance Between BST Nodes](https://leetcode.com/problems/minimum-distance-between-bst-nodes) | [![Java](assets/java.png)](src/MinimumAbsoluteDifferenceInBST.java) [![Python](assets/python.png)](python/minimum_distance_between_bst_nodes.py) | | +| 788 | [Rotated Digits](https://leetcode.com/problems/rotated-digits) | | | +| 796 | [Rotate String](https://leetcode.com/problems/rotate-string) | [![Java](assets/java.png)](src/RotateString.java) | | +| 800 | [Similar RGB Color](https://leetcode.com/problems/similar-rgb-color) | | | +| 804 | [Unique Morse Code Words](https://leetcode.com/problems/unique-morse-code-words) | [![Java](assets/java.png)](src/UniqueMorseCodeWords.java) | | +| 806 | [Number of Lines to Write String](https://leetcode.com/problems/number-of-lines-to-write-string) | [![Java](assets/java.png)](src/NumberOfLinesToWriteInString.java) | | +| 811 | [Subdomain Visit Count](https://leetcode.com/problems/subdomain-visit-count) | | | +| 812 | [Largest Triangle Area](https://leetcode.com/problems/largest-triangle-area) | [![Java](assets/java.png)](src/LargestTriangleArea.java) | | +| 819 | [Most Common Word](https://leetcode.com/problems/most-common-word) | [![Java](assets/java.png)](src/MostCommonWord.java) | | +| 821 | [Shortest Distance to Character](https://leetcode.com/problems/shortest-distance-to-a-character) | [![Java](assets/java.png)](src/ShortestDistanceToACharacter.java) | | +| 824 | [Goat Latin](https://leetcode.com/problems/goat-latin) | [![Java](assets/java.png)](src/GoatLatin.java) | | +| 830 | [Positions of Large Groups](https://leetcode.com/problems/positions-of-large-groups) | [![Java](assets/java.png)](src/PositionsOfLargeGroups.java) | | +| 832 | [Flipping an Image](https://leetcode.com/problems/flipping-an-image) | [![Java](assets/java.png)](src/FlippingAnImage.java) | | +| 836 | [Rectangle Overlap](https://leetcode.com/problems/rectangle-overlap) | [![Java](assets/java.png)](src/RectangleOverlap.java) | | +| 840 | [Magic Squares in Grid](https://leetcode.com/problems/magic-squares-in-grid) | | | +| 844 | [Backspace String Compare](https://leetcode.com/problems/backspace-string-compare) | [![Java](assets/java.png)](src/BackspaceStringCompare.java) | | +| 849 | [Maximize Distance to Closest Person](https://leetcode.com/problems/maximize-distance-to-closest-person) | | | +| 852 | [Peak Index in Mountain Array](https://leetcode.com/problems/peak-index-in-a-mountain-array) | [![Java](assets/java.png)](src/PeakIndexInMountainArray.java) | | +| 859 | [Buddy Strings](https://leetcode.com/problems/buddy-strings) | [![Java](assets/java.png)](src/BuddyStrings.java) | | +| 860 | [Lemonade Change](https://leetcode.com/problems/lemonade-change) | [![Java](assets/java.png)](src/LemonadeChange.java) | | +| 867 | [Transpose Matrix](https://leetcode.com/problems/transpose-matrix) | [![Java](assets/java.png)](src/TransposeMatrix.java) | | +| 868 | [Binary Gap](https://leetcode.com/problems/binary-gap) | [![Java](assets/java.png)](src/BinaryGap.java) | | +| 872 | [Leaf-Similar Trees](https://leetcode.com/problems/leaf-similar-trees) | [![Java](assets/java.png)](src/LeafSimilarTrees.java) | | +| 874 | [Walking Robot Simulation](https://leetcode.com/problems/walking-robot-simulation) | | | +| 876 | [Middle of the Linked List](https://leetcode.com/problems/middle-of-the-linked-list) | [![Java](assets/java.png)](src/MiddleOfTheLinkedList.java) | | +| 881 | [Boats to Save People](https://leetcode.com/problems/boats-to-save-people) | [![Python](assets/python.png)](python/boats_to_save_people.py) | | +| 883 | [Projection Area of 3D Shapes](https://leetcode.com/problems/projection-area-of-3d-shapes) | [![Java](assets/java.png)](src/ProjectionAreaOf3DShapes.java) | | +| 884 | [Uncommon Words from 2 Sentences](https://leetcode.com/problems/uncommon-words-from-two-sentences) | [![Java](assets/java.png)](src/UncommonWordsFromTwoSentences.java) | | +| 888 | [Fair Candy Swap](https://leetcode.com/problems/fair-candy-swap) | [![Java](assets/java.png)](src/FairCandySwap.java) | | +| 892 | [Surface Area of 3D Shapes](https://leetcode.com/problems/surface-area-of-3d-shapes) | [![Java](assets/java.png)](src/SurfaceAreaOf3DShapes.java) | | +| 893 | [Groups of Special Equivalent Strings](https://leetcode.com/problems/groups-of-special-equivalent-strings) | | | +| 896 | [Monotonic Array](https://leetcode.com/problems/monotonic-array) | [![Java](assets/java.png)](src/MonotonicArray.java) | | +| 897 | [Increasing Order Search Tree](https://leetcode.com/problems/increasing-order-search-tree) | [![Java](assets/java.png)](src/IncreasingOrderSearchTree.java) | | +| 905 | [Sort Array by Parity](https://leetcode.com/problems/sort-array-by-parity) | | | +| 908 | [Smallest Range I](https://leetcode.com/problems/smallest-range-i) | [![Java](assets/java.png)](src/SmallestRangeI.java) | | +| 914 | [X of a kind in a Deck of Cards](https://leetcode.com/problems/x-of-a-kind-in-a-deck-of-cards) | [![Java](assets/java.png)](src/XOfAKindInADeckOfCards.java) | | +| 917 | [Reverse Only Letters](https://leetcode.com/problems/reverse-only-letters) | [![Java](assets/java.png)](src/ReverseOnlyLetters.java) | | +| 922 | [Sort Array by Parity II](https://leetcode.com/problems/sort-array-by-parity-ii) | [![Java](assets/java.png)](src/SortArrayByParityII.java) | | +| 925 | [Long Pressed Name](https://leetcode.com/problems/long-pressed-name) | [![Java](assets/java.png)](src/LongPressedName.java) | | +| 929 | [Unique Email Addresses](https://leetcode.com/problems/unique-email-addresses) | [![Java](assets/java.png)](src/UniqueEmailAddresses.java) | | +| 933 | [Number of Recent Calls](https://leetcode.com/problems/number-of-recent-calls) | [![Java](assets/java.png)](src/NumberOfRecentCalls.java) | | +| 937 | [Reorder Data In Log Files](https://leetcode.com/problems/reorder-data-in-log-files) | [![Java](assets/java.png)](src/ReorderDataInLogFiles.java) | | +| 938 | [Range Sum of BST](https://leetcode.com/problems/range-sum-of-bst) | [![Java](assets/java.png)](src/RangeSumOfBST.java) | | +| 941 | [Valid Mountain Array](https://leetcode.com/problems/valid-mountain-array) | [![Java](assets/java.png)](src/ValidMountainArray.java) [![Python](assets/python.png)](python/valid_mountain_array.py) | | +| 942 | [DI String Match](https://leetcode.com/problems/di-string-match) | [![Java](assets/java.png)](src/DIStringMatch.java) | | +| 944 | [Delete Columns to Make Sorted](https://leetcode.com/problems/delete-columns-to-make-sorted) | [![Java](assets/java.png)](src/DeleteColumnsToMakeSorted.java) | | +| 949 | [Largest Time for Given Digits](https://leetcode.com/problems/largest-time-for-given-digits) | | | +| 953 | [Verifying an Alien Dictionary](https://leetcode.com/problems/verifying-an-alien-dictionary) | [![Java](assets/java.png)](src/VerifyAnAlienDictionary.java) | | +| 961 | [N-Repeated Elements in Size 2N Array](https://leetcode.com/problems/n-repeated-element-in-size-2n-array) | [![Java](assets/java.png)](src/NRepeatedElementInSizeNArray.java) | | +| 965 | [Univalued Binary Tree](https://leetcode.com/problems/univalued-binary-tree) | [![Java](assets/java.png)](src/UnivaluedBinaryTree.java) | | +| 970 | [Powerful Integers](https://leetcode.com/problems/powerful-integers) | | | +| 976 | [Largest Perimeter Triangle](https://leetcode.com/problems/largest-perimeter-triangle) | [![Java](assets/java.png)](src/LargestPerimeterTriangle.java) | | +| 977 | [Squares of a Sorted Array](https://leetcode.com/problems/squares-of-a-sorted-array) | | | +| 983 | [Minimum Cost For Tickets](https://leetcode.com/problems/minimum-cost-for-tickets) | [![Python](assets/python.png)](python/minimum_cost_for_tickets.py) | | +| 985 | [Sum of Even Numbers after Queries](https://leetcode.com/problems/sum-of-even-numbers-after-queries) | | | +| 989 | [Add to Array Form of Integer](https://leetcode.com/problems/add-to-array-form-of-integer) | [![Java](assets/java.png)](src/AddToArrayFormOfInteger.java) | | +| 993 | [Cousins in Binary Tree](https://leetcode.com/problems/cousins-in-binary-tree) | [![Java](assets/java.png)](src/CousinsInBinaryTree.java) | | +| 994 | [Rotting Oranges](https://leetcode.com/problems/rotting-oranges) | [![Java](assets/java.png)](src/RottingOranges.java) | | +| 997 | [Find the Town Judge](https://leetcode.com/problems/find-the-town-judge) | [![Java](assets/java.png)](src/FindTheTownJudge.java) | | +| 999 | [Available Captures for Rook](https://leetcode.com/problems/available-captures-for-rook) | [![Java](assets/java.png)](src/AvailableCapturesForRook.java) | | +| 1002 | [Find Common Characters](https://leetcode.com/problems/find-common-characters) | [![Java](assets/java.png)](src/FindCommonCharacters.java) | | +| 1005 | [Maximize Sum of Array After K Negations](https://leetcode.com/problems/maximize-sum-of-array-after-k-negations) | [![Java](assets/java.png)](src/MaximizeSumOfArrayAfterKNegations.java) | | +| 1009 | [Complement of Base 10 Integer](https://leetcode.com/problems/complement-of-base-10-integer) | [![Java](assets/java.png)](src/NumberComplement.java) | | +| 1010 | [Pairs of Songs With Total Durations Divisible by 60](https://leetcode.com/problems/pairs-of-songs-with-total-durations-divisible-by-60) | [![Java](assets/java.png)](src/PartitionArrayIntoThreePartsWithEqualSum.java) | | +| 1013 | [Partition Array into Three Parts with equal Sum](https://leetcode.com/problems/partition-array-into-three-parts-with-equal-sum) | | | +| 1018 | [Binary Prefix Divisible by 5](https://leetcode.com/problems/binary-prefix-divisible-by-5) | [![Java](assets/java.png)](src/BinaryPrefixDivisibleBy5.java) | | +| 1020 | [Number of Enclaves](https://leetcode.com/problems/number-of-enclaves) | [![Python](assets/python.png)](python/number_of_enclaves.py) | | +| 1021 | [Remove Outermost Parenthesis](https://leetcode.com/problems/remove-outermost-parentheses) | [![Java](assets/java.png)](src/RemoveOutermostParentheses.java) | | +| 1022 | [Sum of Root to Leaf Binary Numbers](https://leetcode.com/problems/sum-of-root-to-leaf-binary-numbers) | [![Java](assets/java.png)](src/SumOfRootToLeafBinaryNumbers.java) | | +| 1025 | [Divisor Game](https://leetcode.com/problems/divisor-game) | [![Java](assets/java.png)](src/DivisorGame.java) | | +| 1029 | [Two City Scheduling](https://leetcode.com/problems/two-city-scheduling) | | | +| 1030 | [Matrix Cells in Distance Order](https://leetcode.com/problems/matrix-cells-in-distance-order) | [![Java](assets/java.png)](src/MatrixCellsInDistanceOrder.java) | | +| 1033 | [Moving Stones Until Consecutive](https://leetcode.com/problems/moving-stones-until-consecutive) | | | +| 1037 | [Valid Boomerang](https://leetcode.com/problems/valid-boomerang) | [![Java](assets/java.png)](src/ValidBoomerang.java) | | +| 1042 | [Flower Planting with no Adjacent](https://leetcode.com/problems/flower-planting-with-no-adjacent) | | | +| 1046 | [Last Stone Weight](https://leetcode.com/problems/last-stone-weight) | [![Java](assets/java.png)](src/LastStoneWeight.java) | | +| 1047 | [Remove All adjacent Duplicates in String](https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string) | [![Java](assets/java.png)](src/RemoveAllAdjacentDuplicatesInAString.java) | | +| 1051 | [Height Checker](https://leetcode.com/problems/height-checker) | | | +| 1056 | 🔒 [Confusing Number](https://leetcode.com/problems/confusing-number) | | | +| 1064 | 🔒 [Fixed Point](https://leetcode.com/problems/fixed-point) | | | +| 1065 | 🔒 [Index Pairs of a String](https://leetcode.com/problems/index-pairs-of-a-string) | | | +| 1071 | [Greatest Common Divisors of Strings](https://leetcode.com/problems/greatest-common-divisor-of-strings) | [![Java](assets/java.png)](src/GreatestCommonDivisorOfStrings.java) | | +| 1078 | [Occurrence After Bigram](https://leetcode.com/problems/occurrences-after-bigram) | [![Java](assets/java.png)](src/OccurrencesAfterBigram.java) | | +| 1085 | 🔒 [Sum of Digits in Minimum Number](https://leetcode.com/problems/sum-of-digits-in-the-minimum-number) | | | +| 1086 | 🔒 [High Five](https://leetcode.com/problems/high-five) | | | +| 1089 | [Duplicate Zeroes](https://leetcode.com/problems/duplicate-zeros) | [![Java](assets/java.png)](src/DuplicateZeros.java) | | +| 1099 | 🔒 [Two Sum Less Than K](https://leetcode.com/problems/two-sum-less-than-k) | | | +| 1103 | [Distribute Candies to People](https://leetcode.com/problems/distribute-candies-to-people) | [![Java](assets/java.png)](src/DistributeCandiesToPeople.java) | | +| 1108 | [Defanging an IP Address](https://leetcode.com/problems/defanging-an-ip-address) | [![Java](assets/java.png)](src/DefangingAnIPAddress.java) | | +| 1118 | 🔒 [Number of Days in a Month](https://leetcode.com/problems/number-of-days-in-a-month) | | | +| 1119 | 🔒 [Remove Vowels From String](https://leetcode.com/problems/remove-vowels-from-a-string) | | | +| 1122 | [Relative Sort Array](https://leetcode.com/problems/relative-sort-array) | [![Java](assets/java.png)](src/RelativeSortArray.java) | | +| 1128 | [Number of Equivalent Domino Pairs](https://leetcode.com/problems/number-of-equivalent-domino-pairs) | [![Java](assets/java.png)](src/NumberOfEquivalentDominoPairs.java) | | +| 1133 | 🔒 [Largest Unique Number](https://leetcode.com/problems/largest-unique-number) | | | +| 1134 | 🔒 [Armstrong Number](https://leetcode.com/problems/armstrong-number) | | | +| 1137 | [Nth Tribonacci Number](https://leetcode.com/problems/n-th-tribonacci-number) | [![Java](assets/java.png)](src/NthTribonacciNumber.java) | | +| 1143 | [Longest Common Subsequence](https://leetcode.com/problems/longest-common-subsequence) | [![Java](assets/java.png)](src/LongestCommonSubsequence.java) | | +| 1150 | [Check if Number is Majority Element in Sorted Array](https://leetcode.com/problems/check-if-a-number-is-majority-element-in-a-sorted-array) | | | +| 1154 | [Day of The Year](https://leetcode.com/problems/day-of-the-year) | [![Java](assets/java.png)](src/DayOfTheYear.java) | | +| 1160 | [Find Words That Can Be Formed By Characters](https://leetcode.com/problems/find-words-that-can-be-formed-by-characters) | | | +| 1165 | [Single Row Keyboard](https://leetcode.com/problems/single-row-keyboard) | [![Java](assets/java.png)](src/FindWordsThatCanBeFormedByCharacters.java) | | +| 1170 | [Compare Strings By Frequency of the Smallest Character](https://leetcode.com/problems/compare-strings-by-frequency-of-the-smallest-character) | | | +| 1175 | [Prime Arrangements](https://leetcode.com/problems/prime-arrangements) | [![Java](assets/java.png)](src/PrimeArrangements.java) | | +| 1176 | 🔒 [Diet Plan Performance](https://leetcode.com/problems/diet-plan-performance) | | | +| 1180 | 🔒 [Count Substrings with only one Distinct Letter](https://leetcode.com/problems/count-substrings-with-only-one-distinct-letter) | | | +| 1184 | [Distance Between Bus Stops](https://leetcode.com/problems/distance-between-bus-stops) | [![Java](assets/java.png)](src/DistanceBetweenBusStops.java) | | +| 1185 | [Day of the Week](https://leetcode.com/problems/day-of-the-week) | [![Java](assets/java.png)](src/DayOfWeek.java) | | +| 1189 | [Maximum Number of Balloons](https://leetcode.com/problems/maximum-number-of-balloons) | [![Java](assets/java.png)](src/MaximumNumberOfBalloons.java) | | +| 1196 | 🔒 [How Many Apples Can You Put into the Basket](https://leetcode.com/problems/how-many-apples-can-you-put-into-the-basket) | | | +| 1200 | [Minimum Absolute Difference](https://leetcode.com/problems/minimum-absolute-difference) | [![Java](assets/java.png)](src/MinimumAbsoluteDifference.java) | | +| 1201 | [Ugly Number III](https://leetcode.com/problems/ugly-number-iii) | [![Java](assets/java.png)](src/UglyNumberIII.java) | | +| 1207 | [Unique Number of Occurrences](https://leetcode.com/problems/unique-number-of-occurrences) | [![Java](assets/java.png)](src/UniqueNumberOfOccurrences.java) | | +| 1213 | 🔒 [Intersection of Three Sorted Arrays](https://leetcode.com/problems/intersection-of-three-sorted-arrays) | | | +| 1217 | [Minimum Cost to Move Chips to The Same Position](https://leetcode.com/problems/minimum-cost-to-move-chips-to-the-same-position) | [![Java](assets/java.png)](src/MinimumCostToMoveChipsToTheSamePosition.java) | | +| 1221 | [Split A String In Balanced Strings](https://leetcode.com/problems/split-a-string-in-balanced-strings) | [![Java](assets/java.png)](src/SplitAStringInBalancedStrings.java) | | +| 1228 | 🔒 [Missing A Number In Arithmetic Progression](https://leetcode.com/problems/missing-number-in-arithmetic-progression) | | | +| 1232 | [Check If It Is A Straight Line](https://leetcode.com/problems/check-if-it-is-a-straight-line) | [![Java](assets/java.png)](src/CheckIfItIsASStraightLine.java) | | +| 1237 | [Find Positive Integer Solutions for a Given Equation](https://leetcode.com/problems/find-positive-integer-solution-for-a-given-equation) | | | +| 1243 | 🔒 [Array Transformation](https://leetcode.com/problems/array-transformation) | | | +| 1249 | [Minimum Remove to Make Valid Parentheses](https://leetcode.com/problems/minimum-remove-to-make-valid-parentheses) | [![Java](assets/java.png)](src/MinimumRemoveToMakeValidParentheses.java) | | +| 1252 | [Cells With Odd Values In Matrix](https://leetcode.com/problems/cells-with-odd-values-in-a-matrix) | [![Java](assets/java.png)](src/CellsWithOddValuesInMatrix.java) | | +| 1254 | [Number of Closed Islands](https://leetcode.com/problems/number-of-closed-islands) | [![Python](assets/python.png)](python/number_of_closed_islands.py) | | +| 1260 | [Shift 2D Grid](https://leetcode.com/problems/shift-2d-grid) | [![Java](assets/java.png)](src/Shift2DGrid.java) | | +| 1266 | [Minimum Time Visiting All Points](https://leetcode.com/problems/minimum-time-visiting-all-points) | [![Java](assets/java.png)](src/MinimumTimeVisitingAllPoints.java) | | +| 1271 | 🔒 [Hexspeak](https://leetcode.com/problems/hexspeak) | | | +| 1275 | [Find Winner On a Tic Tac Toe Game](https://leetcode.com/problems/find-winner-on-a-tic-tac-toe-game) | [![Java](assets/java.png)](src/FindWinnerOnATicTacToeGame.java) | | +| 1281 | [Subtract the Product and Sum of Digits of a Integer](https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer) | [![Java](assets/java.png)](src/SubtractTheProductAndSumOfDigitsOfAnInteger.java) | | +| 1287 | [Element Appearing More Than 25% in Sorted Array](https://leetcode.com/problems/element-appearing-more-than-25-in-sorted-array) | [![Java](assets/java.png)](src/ElementAppearingMoreThan25PercentInSortedArray.java) | | +| 1290 | [Convert Binary Number In A Linked List to Integer](https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer) | [![Java](assets/java.png)](src/ConvertBinaryNumberInLinkedListToInteger.java) | | +| 1295 | [Find Numbers With Even Numbers of Digits](https://leetcode.com/problems/find-numbers-with-even-number-of-digits) | [![Java](assets/java.png)](src/FindNumbersWithEvenNumbersOfDigits.java) [![Python](assets/python.png)](python/find_numbers_with_even_number_of_digits.py) | | +| 1299 | [Replace Elements With Greatest Element on Right Side](https://leetcode.com/problems/replace-elements-with-greatest-element-on-right-side) | [![Java](assets/java.png)](src/ReplaceElementWithGreatestElementOnRightSide.java) [![Python](assets/python.png)](python/replace_element_with_greatest_element_on_right_hand_side.py) | | +| 1304 | [Find N Unique Integers Sum Up To Zero](https://leetcode.com/problems/find-n-unique-integers-sum-up-to-zero) | [![Java](assets/java.png)](src/FindNUniqueIntegersSumUpToZero.java) | | +| 1309 | [Decrypt String From Alphabet To Integer Mapping](https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping) | [![Java](assets/java.png)](src/DecryptStringFromAlphabetToIntegerMapping.java) | | +| 1313 | [Decompress Run-Length Encoded Strings](https://leetcode.com/problems/decompress-run-length-encoded-list) | [![Java](assets/java.png)](src/DecompressRunLengthEncodedList.java) | | +| 1317 | [Convert Integer to Sum Of Two Non-Zero Integers](https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers) | [![Java](assets/java.png)](src/ConvertIntegerToTheSumOfTwoNoZeroIntegers.java) | | +| 1319 | [Number of Operations to Make Network Connected](https://leetcode.com/problems/number-of-operations-to-make-network-connected) | [![Python](assets/python.png)](python/no_of_operations_to_make_network_connected.py) | | +| 1323 | [Maximum 69 Number](https://leetcode.com/problems/maximum-69-number) | [![Java](assets/java.png)](src/Maximum69Number.java) | | +| 1331 | [Rank Transform of An Array](https://leetcode.com/problems/rank-transform-of-an-array) | [![Java](assets/java.png)](src/RankTransformOfArray.java) | | +| 1332 | [Remove Palindromic Subsequences](https://leetcode.com/problems/remove-palindromic-subsequences) | [![Java](assets/java.png)](src/RemovePalindromicSubSequences.java) | | +| 1337 | [The K Weakest Rows In A Matrix](https://leetcode.com/problems/the-k-weakest-rows-in-a-matrix) | [![Java](assets/java.png)](src/TheKWeakestRowsInAMatrix.java) | | +| 1342 | [Number of Steps to Reduce a Number to Zero](https://leetcode.com/problems/number-of-steps-to-reduce-a-number-to-zero) | [![Java](assets/java.png)](src/NumberOfStepsToReduceANumberToZero.java) | | +| 1346 | [Check if N and It's Double Exist](https://leetcode.com/problems/check-if-n-and-its-double-exist) | [![Java](assets/java.png)](src/CheckIfNAndItsDoubleExist.java) [![Python](assets/python.png)](python/check_if_n_and_its_double_exist.py) | | +| 1351 | [Count Negative Numbers In A Sorted Matrix](https://leetcode.com/problems/count-negative-numbers-in-a-sorted-matrix) | [![Java](assets/java.png)](src/CountNegativeNumbersInSortedMatrix.java) | | +| 1356 | [Sort Integers by Number of 1 Bits](https://leetcode.com/problems/sort-integers-by-the-number-of-1-bits) | [![Java](assets/java.png)](src/SortIntegersByTheNumberOf1Bits.java) | | +| 1360 | [Number of Days Between Two Dates](https://leetcode.com/problems/number-of-days-between-two-dates) | [![Java](assets/java.png)](src/NumberOfDaysBetweenTwoDates.java) | | +| 1365 | [How Many Numbers Are Smaller Than Current Number](https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number) | [![Java](assets/java.png)](src/HowManyNumbersAreSmallerThanCurrentNumber.java) | | +| 1370 | [Increasing Decreasing String](https://leetcode.com/problems/increasing-decreasing-string) | [![Java](assets/java.png)](src/IncreasingDecreasingString.java) | | +| 1374 | [Generate A String With Characters That Have Odd Count](https://leetcode.com/problems/generate-a-string-with-characters-that-have-odd-counts) | [![Java](assets/java.png)](src/GenerateAStringWithCharactersThatHaveOddCounts.java) | | +| 1376 | [Time Needed to Inform All Employees](https://leetcode.com/problems/time-needed-to-inform-all-employees) | [![Java](assets/java.png)](src/TimeNeededToInformAllEmployees.java) | | +| 1379 | [Find a Corresponding Node of a Binary Tree in a Clone of That Tree](https://leetcode.com/problems/find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree) | [![Java](assets/java.png)](src/FindACorrespondingNodeOfABinaryTreeInACloneOfThatTree.java) | | +| 1380 | [Lucky Numbers In A Matrix](https://leetcode.com/problems/lucky-numbers-in-a-matrix) | [![Java](assets/java.png)](src/LuckyNumbersInAMatrix.java) | | +| 1385 | [Find The Distance Value Between 2 Arrays](https://leetcode.com/problems/find-the-distance-value-between-two-arrays) | [![Java](assets/java.png)](src/FindTheDistanceValuesBetweenTwoArrays.java) | | +| 1389 | [Create Target Array in Given Order](https://leetcode.com/problems/create-target-array-in-the-given-order) | [![Java](assets/java.png)](src/CreateTargetArrayInGivenOrder.java) | | +| 1394 | [Find Lucky Integer In An Array](https://leetcode.com/problems/find-lucky-integer-in-an-array) | [![Java](assets/java.png)](src/FindTheLuckyIntegerInAnArray.java) | | +| 1399 | [Count Largest Group](https://leetcode.com/problems/count-largest-group) | [![Java](assets/java.png)](src/CountLargestGroup.java) | | +| 1402 | [Reducing Dishes](https://leetcode.com/problems/reducing-dishes) | [![Python](assets/python.png)](python/reducing_dishes.py) | | +| 1403 | [Minimum Subsequence in Non-Increasing Order](https://leetcode.com/problems/minimum-subsequence-in-non-increasing-order) | [![Java](assets/java.png)](src/MinimumSubSequenceInNonIncreasingOrder.java) | | +| 1408 | [String Matching In An Array](https://leetcode.com/problems/string-matching-in-an-array) | [![Java](assets/java.png)](src/StringMatchingInAnArray.java) | | +| 1413 | [Minimum Value To Get Positive Step By Step Sum](https://leetcode.com/problems/minimum-value-to-get-positive-step-by-step-sum) | [![Java](assets/java.png)](src/MinimumValueToGetPositiveStepByStepSum.java) | | +| 1417 | [Reformat The String](https://leetcode.com/problems/reformat-the-string) | [![Java](assets/java.png)](src/ReformatTheString.java) | | +| 1422 | [Maximum Score After Splitting A String](https://leetcode.com/problems/maximum-score-after-splitting-a-string) | [![Java](assets/java.png)](src/MaximumScoreAfterSplittingAString.java) | | +| 1426 | 🔒 [Counting Elements](https://leetcode.com/problems/counting-elements) | | | +| 1427 | 🔒 [Performing String Shifts](https://leetcode.com/problems/perform-string-shifts) | | | +| 1431 | [Kids With The Greatest Number Of Candies](https://leetcode.com/problems/kids-with-the-greatest-number-of-candies) | [![Java](assets/java.png)](src/KidsWithTheGreatestNumberOfCandies.java) | | +| 1436 | [Destination City](https://leetcode.com/problems/destination-city) | [![Java](assets/java.png)](src/DestinationCity.java) | | +| 1437 | [Check If All 1's Are at Least Length K Places Away](https://leetcode.com/problems/check-if-all-1s-are-at-least-length-k-places-away) | [![Java](assets/java.png)](src/CheckIfAll1sAreAtLeastKPlacesAway.java) | | +| 1441 | [Build An Array With Stack Operation](https://leetcode.com/problems/build-an-array-with-stack-operations) | [![Java](assets/java.png)](src/BuildAnArrayWithStackOperations.java) | | +| 1444 | [Number of Ways of Cutting a Pizza](https://leetcode.com/problems/number-of-ways-of-cutting-a-pizza) | [![Python](assets/python.png)](python/number_of_ways_of_cutting_pizza.py) | | +| 1446 | [Consecutive Characters](https://leetcode.com/problems/consecutive-characters) | [![Java](assets/java.png)](src/ConsecutiveCharacters.java) | | +| 1450 | [Number of Students Doing Homework at Given Time](https://leetcode.com/problems/number-of-students-doing-homework-at-a-given-time) | [![Java](assets/java.png)](src/NumberOfStudentsDoingHomeworkAtGivenTime.java) | | +| 1455 | [Check If Word Occurs as Prefix of any Word in Sentence](https://leetcode.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence) | [![Java](assets/java.png)](src/CheckIfAWordOccursAsAPrefixOfAnyWordInASentence.java) | | +| 1460 | [Make 2 Arrays Equal by Reversing Sub Arrays](https://leetcode.com/problems/make-two-arrays-equal-by-reversing-sub-arrays) | [![Java](assets/java.png)](src/MakeTwoArraysEqualByReversingSubArrays.java) | | +| 1464 | [Maximum Product of 2 Elements in Array](https://leetcode.com/problems/maximum-product-of-two-elements-in-an-array) | [![Java](assets/java.png)](src/MaximumProductOfTwoElementsInArray.java) | | +| 1466 | [Reorder Routes to Make All Paths Lead to the City Zero](https://leetcode.com/problems/reorder-routes-to-make-all-paths-lead-to-the-city-zero) | [![Java](assets/java.png)](src/MaximumProductOfTwoElementsInArray.java) | | +| 1469 | 🔒 [Find All Lonely Nodes](https://leetcode.com/problems/find-all-the-lonely-nodes) | [![Python](assets/python.png)](python/reorder_routes_to_make_all_paths_lead_to_city_zero.py) | | +| 1470 | [Shuffle The Array](https://leetcode.com/problems/shuffle-the-array) | [![Java](assets/java.png)](src/ShuffleTheArray.java) | | +| 1472 | [Design Browser History](https://leetcode.com/problems/design-browser-history) | [![Java](assets/java.png)](src/DesignBrowserHistory.java) [![Python](assets/python.png)](python/design_browser_history.py) | | +| 1474 | [Delete N Nodes After M Nodes In A Linked List](https://leetcode.com/problems/delete-n-nodes-after-m-nodes-of-a-linked-list) | | | +| 1475 | [Final Prices With Special Discount in a Shop](https://leetcode.com/problems/final-prices-with-a-special-discount-in-a-shop) | [![Java](assets/java.png)](src/FinalPricesWithASpecialDiscountInAShop.java) | | +| 1480 | [Running Sum of 1D Array](https://leetcode.com/problems/running-sum-of-1d-array) | [![Java](assets/java.png)](src/RunningSumOf1DArray.java) | | +| 1486 | [XOR Operations in An Array](https://leetcode.com/problems/xor-operation-in-an-array) | [![Java](assets/java.png)](src/XOROperationInAnArray.java) | | +| 1491 | [Average Salary Excluding the Minimum and Maximum Salary](https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary) | [![Java](assets/java.png)](src/AverageSalaryExcludingTheMinimumAndMaximumSalary.java) | | +| 1496 | [Path Crossing](https://leetcode.com/problems/path-crossing) | [![Java](assets/java.png)](src/PathCrossing.java) | | +| 1502 | [Can Make Arithmetic Progression From Sequence](https://leetcode.com/problems/can-make-arithmetic-progression-from-sequence) | [![Java](assets/java.png)](src/CanMakeArithmeticProgressionFromSequence.java) | | +| 1507 | [Reformat Date](https://leetcode.com/problems/reformat-date) | [![Java](assets/java.png)](src/ReformatDate.java) | | +| 1512 | [Number of Good Pairs](https://leetcode.com/problems/number-of-good-pairs) | [![Java](assets/java.png)](src/NumberOfGoodPairs.java) | | +| 1518 | [Water Bottles](https://leetcode.com/problems/water-bottles) | [![Java](assets/java.png)](src/WaterBottles.java) | | +| 1523 | [Count Odd Numbers In Interval Range](https://leetcode.com/problems/count-odd-numbers-in-an-interval-range) | [![Java](assets/java.png)](src/CountOddNumbersInIntervalRange.java) | | +| 1528 | [Shuffle Strings](https://leetcode.com/problems/shuffle-string) | [![Java](assets/java.png)](src/ShuffleString.java) | | +| 1534 | [Count Good Triplets](https://leetcode.com/problems/count-good-triplets) | [![Java](assets/java.png)](src/CountGoodTriplets.java) | | +| 1539 | [Kth Missing Positive Number](https://leetcode.com/problems/kth-missing-positive-number) | [![Java](assets/java.png)](src/KthMissingPositiveNumber.java) | | +| 1544 | [Make The String Great](https://leetcode.com/problems/make-the-string-great) | [![Java](assets/java.png)](src/MakeTheStringGreat.java) | | +| 1550 | [Three Consecutive Odds](https://leetcode.com/problems/three-consecutive-odds) | [![Java](assets/java.png)](src/ThreeConsecutiveOdds.java) | | +| 1556 | [Thousand Separator](https://leetcode.com/problems/thousand-separator) | [![Java](assets/java.png)](src/ThousandSeparator.java) | | +| 1560 | [Most Visited Sector in a Circular Track](https://leetcode.com/problems/most-visited-sector-in-a-circular-track) | [![Java](assets/java.png)](src/MostVisitedSectorInACircularTrack.java) | | +| 1566 | [Detect Pattern of Length M Repeated K or More Times](https://leetcode.com/problems/detect-pattern-of-length-m-repeated-k-or-more-times) | [![Java](assets/java.png)](src/DetectPatternOfLengthMRepeatedKOrMoreTimes.java) | | +| 1572 | [Matrix Diagonal Sum](https://leetcode.com/problems/matrix-diagonal-sum) | [![Java](assets/java.png)](src/MatrixDiagonalSum.java) | | +| 1576 | [Replace All ?'s to Avoid Consecutive Repeating Characters](https://leetcode.com/problems/replace-all-s-to-avoid-consecutive-repeating-characters) | [![Java](assets/java.png)](src/ReplaceAllToAvoidConsecutiveRepeatingCharacters.java) | | +| 1582 | [Special Positions in a Binary Matrix](https://leetcode.com/problems/special-positions-in-a-binary-matrix) | [![Java](assets/java.png)](src/SpecialPositionInABinaryMatrix.java) | | +| 1588 | [Sum of All Odd Length Subarrays](https://leetcode.com/problems/sum-of-all-odd-length-subarrays) | [![Java](assets/java.png)](src/SumOfAllOddLengthSubArrays.java) | | +| 1592 | [Rearrange Spaces Between Words](https://leetcode.com/problems/rearrange-spaces-between-words) | [![Java](assets/java.png)](src/RearrangeSpacesBetweenWords.java) | | +| 1598 | [Crawler Log Folder](https://leetcode.com/problems/crawler-log-folder) | [![Java](assets/java.png)](src/CrawlerLogFolder.java) | | +| 1600 | [Throne Inheritance](https://leetcode.com/problems/throne-inheritance) | [![Java](assets/java.png)](src/ThroneInheritance.java) | | +| 1603 | [Design Parking System](https://leetcode.com/problems/design-parking-system) | [![Java](assets/java.png)](src/DesignParkingSystem.java) | | +| 1608 | [Special Array With X Elements Greater Than or Equal X](https://leetcode.com/problems/special-array-with-x-elements-greater-than-or-equal-x) | [![Java](assets/java.png)](src/SpecialArrayWithXElementsGreaterThanEqualToX.java) | | +| 1614 | [Maximum Nesting Depth of the Parentheses](https://leetcode.com/problems/maximum-nesting-depth-of-the-parentheses) | [![Java](assets/java.png)](src/MaximumNestingDepthOfTheParentheses.java) | | +| 1619 | [Mean of Array After Removing Some Elements](https://leetcode.com/problems/mean-of-array-after-removing-some-elements) | [![Java](assets/java.png)](src/MeanOfArrayAfterRemovingSomeElements.java) | | +| 1624 | [Largest Substring Between Two Equal Characters](https://leetcode.com/problems/largest-substring-between-two-equal-characters) | [![Java](assets/java.png)](src/LargestSubStringBetweenTwoEqualCharacters.java) | | +| 1629 | [Slowest Key](https://leetcode.com/problems/slowest-key) | [![Java](assets/java.png)](src/SlowestKey.java) | | +| 1636 | [Sort Array by Increasing Frequency](https://leetcode.com/problems/sort-array-by-increasing-frequency) | [![Java](assets/java.png)](src/SortArrayByIncreasingFrequency.java) | | +| 1640 | [Check Array Formation Through Concatenation](https://leetcode.com/problems/check-array-formation-through-concatenation) | [![Java](assets/java.png)](src/CheckArrayFormationThroughConcatenation.java) | | +| 1646 | [Get Maximum in Generated Array](https://leetcode.com/problems/get-maximum-in-generated-array) | [![Java](assets/java.png)](src/GetMaximumInGeneratedArray.java) | | +| 1652 | [Defuse the Bomb](https://leetcode.com/problems/defuse-the-bomb) | [![Java](assets/java.png)](src/DefuseTheBomb.java) | | +| 1656 | [Design an Ordered Stream](https://leetcode.com/problems/design-an-ordered-stream) | [![Java](assets/java.png)](src/DesignAnOrderedStream.java) | | +| 1662 | [Check If Two String Arrays are Equivalent](https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent) | [![Java](assets/java.png)](src/CheckIfTwoStringArraysAreEquivalent.java) | | +| 1668 | [Maximum Repeating Substring](https://leetcode.com/problems/maximum-repeating-substring) | [![Java](assets/java.png)](src/MaximumRepeatingSubString.java) | | +| 1672 | [Richest Customer Wealth](https://leetcode.com/problems/richest-customer-wealth) | [![Java](assets/java.png)](src/RichestCustomerWealth.java) | | +| 1678 | [Goal Parser Interpretation](https://leetcode.com/problems/goal-parser-interpretation) | [![Java](assets/java.png)](src/GoalParserInterpretation.java) | | +| 1684 | [Count the Number of Consistent Strings](https://leetcode.com/problems/count-the-number-of-consistent-strings) | [![Java](assets/java.png)](src/CountTheNumberOfConsistentStrings.java) | | +| 1688 | [Count of Matches in Tournament](https://leetcode.com/problems/count-of-matches-in-tournament) | [![Java](assets/java.png)](src/CountOfMatchesInTournament.java) | | +| 1694 | [Reformat Phone Number](https://leetcode.com/problems/reformat-phone-number) | [![Java](assets/java.png)](src/ReformatPhoneNumber.java) | | +| 1700 | [Number of Students Unable to Eat Lunch](https://leetcode.com/problems/number-of-students-unable-to-eat-lunch) | [![Java](assets/java.png)](src/NumberOfStudentsUnableToEatLunch.java) | | +| 1704 | [Determine if String Halves Are Alike](https://leetcode.com/problems/determine-if-string-halves-are-alike) | [![Java](assets/java.png)](src/DetermineIfStringHalvesAreAlike.java) | | +| 1708 | 🔒 [Largest Subarray Length K](https://leetcode.com/problems/largest-subarray-length-k/) | | | +| 1710 | [Maximum Units on a Truck](https://leetcode.com/problems/maximum-units-on-a-truck/) | [![Java](assets/java.png)](src/MaximumUnitsOnATruck.java) | | +| 1716 | [Calculate Money in Leetcode Bank](https://leetcode.com/problems/calculate-money-in-leetcode-bank) | [![Java](assets/java.png)](src/CalculateMoneyInLeetCodeBank.java) | | +| 1720 | [Decode XORed Array](https://leetcode.com/problems/decode-xored-array) | [![Java](assets/java.png)](src/DecodeXORedArray.java) | | +| 1725 | [Number Of Rectangles That Can Form The Largest Square](https://leetcode.com/problems/number-of-rectangles-that-can-form-the-largest-square) | [![Java](assets/java.png)](src/NumberOfRectanglesThatCanFormTheLargestSquare.java) | | +| 1732 | [Find the Highest Altitude](https://leetcode.com/problems/find-the-highest-altitude) | [![Java](assets/java.png)](src/FindTheHighestAltitude.java) | | +| 1736 | [Latest Time by Replacing Hidden Digits](https://leetcode.com/problems/latest-time-by-replacing-hidden-digits) | [![Java](assets/java.png)](src/LatestTimeByReplacingHiddenDigits.java) | | +| 1742 | [Maximum Number of Balls in a Box](https://leetcode.com/problems/maximum-number-of-balls-in-a-box) | [![Java](assets/java.png)](src/MaximumNumberOfBallsInABox.java) | | +| 1748 | [Sum of Unique Elements](https://leetcode.com/problems/sum-of-unique-elements) | [![Java](assets/java.png)](src/SumOfUniqueElements.java) | | +| 1752 | [Check if Array Is Sorted and Rotated](https://leetcode.com/problems/check-if-array-is-sorted-and-rotated) | [![Java](assets/java.png)](src/CheckIfArrayIsSortedAndRotated.java) | | +| 1758 | [Minimum Changes To Make Alternating Binary String](https://leetcode.com/problems/minimum-changes-to-make-alternating-binary-string) | [![Java](assets/java.png)](src/MinimumChangesToMakeAlternatingBinaryString.java) | | +| 1763 | [Longest Nice Substring](https://leetcode.com/problems/longest-nice-substring) | [![Java](assets/java.png)](src/LongestNiceSubstring.java) | | +| 1768 | [Merge Strings Alternately](https://leetcode.com/problems/merge-strings-alternately) | [![Java](assets/java.png)](src/MergeStringsAlternately.java) | | +| 1773 | [Count Items Matching a Rule](https://leetcode.com/problems/count-items-matching-a-rule) | [![Java](assets/java.png)](src/CountItemsMatchingARule.java) | | +| 1779 | [Find Nearest Point That Has the Same X or Y Coordinate](https://leetcode.com/problems/find-nearest-point-that-has-the-same-x-or-y-coordinate) | [![Java](assets/java.png)](src/FindNearestPointThatHasTheSameXOrYCoordinate.java) | | +| 1784 | [Check if Binary String Has at Most One Segment of Ones](https://leetcode.com/problems/check-if-binary-string-has-at-most-one-segment-of-ones) | [![Java](assets/java.png)](src/CheckIfBinaryStringHasAtMostOneSegmentOfOnes.java) | | +| 1790 | [Check if One String Swap Can Make Strings Equal](https://leetcode.com/problems/check-if-one-string-swap-can-make-strings-equal) | [![Java](assets/java.png)](src/CheckIfOneStringSwapCanMakeStringsEqual.java) | | +| 1791 | [Find Center of Star Graph](https://leetcode.com/problems/find-center-of-star-graph) | [![Java](assets/java.png)](src/FindCenterOfStarGraph.java) | | +| 1796 | [Second Largest Digit in a String](https://leetcode.com/problems/second-largest-digit-in-a-string) | [![Java](assets/java.png)](src/SecondLargestDigitInAString.java) | | +| 1800 | [Maximum Ascending Subarray Sum](https://leetcode.com/problems/maximum-ascending-subarray-sum) | [![Java](assets/java.png)](src/MaximumAscendingSubArraySum.java) | | +| 1805 | [Number of Different Integers in a String](https://leetcode.com/problems/number-of-different-integers-in-a-string) | [![Java](assets/java.png)](src/NumberOfDifferentIntegersInString.java) | | +| 1812 | [Determine Color of a Chessboard Square](https://leetcode.com/problems/determine-color-of-a-chessboard-square) | [![Java](assets/java.png)](src/DetermineColorOfChessboardSquare.java) | | +| 1816 | [Truncate Sentence](https://leetcode.com/problems/truncate-sentence) | [![Java](assets/java.png)](src/TruncateSentences.java) | | +| 1822 | [Sign of the Product of an Array](https://leetcode.com/problems/sign-of-the-product-of-an-array) | [![Java](assets/java.png)](src/SignOfTheProductOfAnArray.java) | | +| 1826 | 🔒 [Faulty Sensor](https://leetcode.com/problems/faulty-sensor) | | | +| 1827 | [Minimum Operations to Make the Array Increasing](https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing) | [![Java](assets/java.png)](src/MinimumOperationsToMakeTheArrayIncreasing.java) | | +| 1832 | [Check if the Sentence Is Pangram](https://leetcode.com/problems/check-if-the-sentence-is-pangram) | [![Java](assets/java.png)](src/CheckIfSentenceIsPangram.java) | | +| 1837 | [Sum of Digits in Base K](https://leetcode.com/problems/sum-of-digits-in-base-k) | [![Java](assets/java.png)](src/SumOfDigitsInBaseK.java) | | +| 1844 | [Replace All Digits with Characters](https://leetcode.com/problems/replace-all-digits-with-characters) | [![Java](assets/java.png)](src/ReplaceAllDigitsWithCharacters.java) | | +| 1848 | [Minimum Distance to the Target Element](https://leetcode.com/problems/minimum-distance-to-the-target-element) | [![Java](assets/java.png)](src/MinimumDistanceToTheTargetElement.java) | | +| 1854 | [Maximum Population Year](https://leetcode.com/problems/maximum-population-year) | [![Java](assets/java.png)](src/MaximumPopulationYear.java) | | +| 1859 | [Sorting the Sentence](https://leetcode.com/problems/sorting-the-sentence) | [![Java](assets/java.png)](src/SortingTheSentence.java) | | +| 1863 | [Sum of All Subset XOR Totals](https://leetcode.com/problems/sum-of-all-subset-xor-totals) | [![Java](assets/java.png)](src/SumOfAllSubsetXORTotals.java) | | +| 1869 | [Longer Contiguous Segments of Ones than Zeros](https://leetcode.com/problems/longer-contiguous-segments-of-ones-than-zeros) | [![Java](assets/java.png)](src/LongerContiguousSegmentOfOnesThanZeros.java) | | +| 1876 | [Substrings of Size Three with Distinct Characters](https://leetcode.com/problems/substrings-of-size-three-with-distinct-characters) | [![Java](assets/java.png)](src/SubstringsOfSizeThreeWithDistinctCharacters.java) | | +| 1880 | [Check if Word Equals Summation of Two Words](https://leetcode.com/problems/check-if-word-equals-summation-of-two-words) | [![Java](assets/java.png)](src/CheckIfWordEqualsSummationOfTwoWords.java) | | +| 1886 | [Determine Whether Matrix Can Be Obtained By Rotation](https://leetcode.com/problems/determine-whether-matrix-can-be-obtained-by-rotation) | [![Java](assets/java.png)](src/DetermineWhetherMatrixCanBeObtainedByRotation.java) | | +| 1893 | [Check if All the Integers in a Range Are Covered](https://leetcode.com/problems/check-if-all-the-integers-in-a-range-are-covered) | [![Java](assets/java.png)](src/CheckIfAllTheIntegersInARangeAreCovered.java) | | +| 1897 | [Redistribute Characters to Make All Strings Equal](https://leetcode.com/problems/redistribute-characters-to-make-all-strings-equal) | [![Java](assets/java.png)](src/RedistributeCharactersToMakeAllStringsEqual.java) | | +| 1903 | [Largest Odd Number in String](https://leetcode.com/problems/largest-odd-number-in-string) | [![Java](assets/java.png)](src/LargestOddNumberInString.java) | | +| 1909 | [Remove One Element to Make the Array Strictly Increasing](https://leetcode.com/problems/remove-one-element-to-make-the-array-strictly-increasing) | [![Java](assets/java.png)](src/RemoveOneElementToMakeTheArrayStrictlyIncreasing.java) | | +| 1913 | [Maximum Product Difference Between Two Pairs](https://leetcode.com/problems/maximum-product-difference-between-two-pairs) | [![Java](assets/java.png)](src/MaximumProductDifferenceBetweenTwoPairs.java) | | +| 1920 | [Build Array from Permutation](https://leetcode.com/problems/build-array-from-permutation) | [![Java](assets/java.png)](src/BuildArrayFromPermutation.java) | | +| 1925 | [Count Square Sum Triples](https://leetcode.com/problems/count-square-sum-triples) | [![Java](assets/java.png)](src/CountSquareSumTriplets.java) | | +| 1929 | [Concatenation of Array](https://leetcode.com/problems/concatenation-of-array) | [![Java](assets/java.png)](src/ConcatenationOfArray.java) | | +| 1933 | 🔒 [Check If String Is Decomposable Into Value EqualSubstrings](https://leetcode.com/problems/check-if-string-is-decomposable-into-value-equal-substring) | | | +| 1935 | [Maximum Number of Words You Can Type](https://leetcode.com/problems/maximum-number-of-words-you-can-type) | [![Java](assets/java.png)](src/MaximumNumberOfWordsYouCanType.java) | | +| 1941 | [Check if All Characters Have Equal Number of Occurrences](https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences) | [![Java](assets/java.png)](src/CheckIfAllCharactersHaveEqualNumberOfOccurrences.java) | | +| 1945 | [Sum of Digits of String After Convert](https://leetcode.com/problems/sum-of-digits-of-string-after-convert) | [![Java](assets/java.png)](src/SumOfDigitsOfStringAfterConvert.java) | | +| 1952 | [Three Divisors](https://leetcode.com/problems/three-divisors) | [![Java](assets/java.png)](src/ThreeDivisors.java) | | +| 1957 | [Delete Characters to Make Fancy String](https://leetcode.com/problems/delete-characters-to-make-fancy-string) | [![Java](assets/java.png)](src/DeleteCharactersToMakeFancyString.java) | | +| 1961 | [Check If String Is a Prefix of Array](https://leetcode.com/problems/check-if-string-is-a-prefix-of-array) | [![Java](assets/java.png)](src/CheckIfStringIsAPrefixOfArray.java) | | +| 1967 | [Number of Strings That Appear as Substrings in Word](https://leetcode.com/problems/number-of-strings-that-appear-as-substrings-in-word) | [![Java](assets/java.png)](src/NumberOfStringsThatAppearAsSubstringsInWord.java) | | +| 1971 | [Find if Path Exists in Graph](https://leetcode.com/problems/find-if-path-exists-in-graph) | [![Java](assets/java.png)](src/FindIfPathExistsInGraph.java) | | +| 1974 | [Minimum Time to Type Word Using Special Typewriter](https://leetcode.com/problems/minimum-time-to-type-word-using-special-typewriter) | [![Java](assets/java.png)](src/MinimumTimeToTypeWordUsingSpecialTypewriter.java) | | +| 1979 | [Find Greatest Common Divisor of Array](https://leetcode.com/problems/find-greatest-common-divisor-of-array) | [![Java](assets/java.png)](src/FindGreatestCommonDivisorOfArray.java) | | +| 1984 | [Minimum Difference Between Highest and Lowest of K Scores](https://leetcode.com/problems/minimum-difference-between-highest-and-lowest-of-k-scores) | [![Java](assets/java.png)](src/MinimumDifferenceBetweenHighestAndLowestOfKScores.java) | | +| 1991 | [Find the Middle Index in Array](https://leetcode.com/problems/find-the-middle-index-in-array) | [![Java](assets/java.png)](src/FindTheMiddleIndexInArray.java) | | +| 1995 | [Count Special Quadruplets](https://leetcode.com/problems/count-special-quadruplets) | [![Java](assets/java.png)](src/CountSpecialQuadruplets.java) | | +| 2000 | [Reverse Prefix of Word](https://leetcode.com/problems/reverse-prefix-of-word) | [![Java](assets/java.png)](src/ReversePrefixOfWord.java) | | +| 2006 | [Count Number of Pairs With Absolute Difference K](https://leetcode.com/problems/count-number-of-pairs-with-absolute-difference-k) | [![Java](assets/java.png)](src/CountNumberOfPairsWithAbsoluteDifferenceK.java) | | +| 2011 | [Final Value of Variable After Performing Operations](https://leetcode.com/problems/final-value-of-variable-after-performing-operations) | [![Java](assets/java.png)](src/FinalValueOfVariableAfterPerformingOperations.java) | | +| 2016 | [Maximum Difference Between Increasing Elements](https://leetcode.com/problems/maximum-difference-between-increasing-elements) | [![Java](assets/java.png)](src/MaximumDifferenceBetweenIncreasingElements.java) | | +| 2022 | [Convert 1D Array Into 2D Array](https://leetcode.com/problems/convert-1d-array-into-2d-array) | [![Java](assets/java.png)](src/Convert1DArrayInto2DArray.java) | | +| 2027 | [Minimum Moves to Convert String](https://leetcode.com/problems/minimum-moves-to-convert-string) | [![Java](assets/java.png)](src/MinimumMovesToConvertString.java) | | +| 2032 | [Two Out of Three](https://leetcode.com/problems/two-out-of-three) | [![Java](assets/java.png)](src/TwoOutOfThree.java) | | +| 2037 | [Minimum Number of Moves to Seat Everyone](https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone) | [![Java](assets/java.png)](src/MinimumNumberOfMovesToSeatEveryone.java) | | +| 2042 | [Check if Numbers Are Ascending in a Sentence](https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence) | [![Java](assets/java.png)](src/CheckIfNumbersAreAscendingInASentence.java) | | +| 2047 | [Number of Valid Words in a Sentence](https://leetcode.com/problems/number-of-valid-words-in-a-sentence) | [![Java](assets/java.png)](src/NumberOfValidWordsInASentence.java) | | +| 2053 | [Kth Distinct String in an Array](https://leetcode.com/problems/kth-distinct-string-in-an-array) | [![Java](assets/java.png)](src/KthDistinctStringInAnArray.java) | | +| 2057 | [Smallest Index With Equal Value](https://leetcode.com/problems/smallest-index-with-equal-value) | [![Java](assets/java.png)](src/SmallestIndexWithEqualValue.java) | | +| 2062 | [Count Vowel Substrings of a String](https://leetcode.com/problems/count-vowel-substrings-of-a-string) | [![Java](assets/java.png)](src/CountVowelSubstringsOfAString.java) | | +| 2068 | [Check Whether Two Strings are Almost Equivalent](https://leetcode.com/problems/check-whether-two-strings-are-almost-equivalent) | [![Java](assets/java.png)](src/CheckWhetherTwoStringsAreAlmostEquivalent.java) | | +| 2073 | [Time Needed to Buy Tickets](https://leetcode.com/problems/time-needed-to-buy-tickets) | [![Java](assets/java.png)](src/TimeNeededToBuyTickets.java) | | +| 2078 | [Two Furthest Houses With Different Colors](https://leetcode.com/problems/two-furthest-houses-with-different-colors) | [![Java](assets/java.png)](src/TwoFurthestHousesWithDifferentColors.java) | | +| 2085 | [Count Common Words With One Occurrence](https://leetcode.com/problems/count-common-words-with-one-occurrence) | [![Java](assets/java.png)](src/CountCommonWordsWithOneOccurrence.java) | | +| 2089 | [Find Target Indices After Sorting Array](https://leetcode.com/problems/find-target-indices-after-sorting-array) | [![Java](assets/java.png)](src/FindTargetIndicesAfterSortingArray.java) | | +| 2094 | [Finding 3-Digit Even Numbers](https://leetcode.com/problems/finding-3-digit-even-numbers) | [![Java](assets/java.png)](src/Finding3DigitEvenNumbers.java) | | +| 2099 | [Find Subsequence of Length K With the Largest Sum](https://leetcode.com/problems/find-subsequence-of-length-k-with-the-largest-sum) | [![Java](assets/java.png)](src/FindSubsequenceOfLengthKWithTheLargestSum.java) | | +| 2103 | [Rings and Rods](https://leetcode.com/problems/rings-and-rods) | [![Java](assets/java.png)](src/RingsAndRods.java) | | +| 2108 | [Find First Palindromic String in the Array](https://leetcode.com/problems/find-first-palindromic-string-in-the-array) | [![Java](assets/java.png)](src/FindFirstPalindromicStringInArray.java) | | +| 2114 | [Maximum Number of Words Found in Sentences](https://leetcode.com/problems/maximum-number-of-words-found-in-sentences) | [![Java](assets/java.png)](src/MaximumNumberOfWordsFoundInSentences.java) | | +| 2119 | [A Number After a Double Reversal](https://leetcode.com/problems/a-number-after-a-double-reversal) | [![Java](assets/java.png)](src/ANumberAfterADoubleReversal.java) | | +| 2124 | [Check if All A's Appears Before All B's](https://leetcode.com/problems/check-if-all-as-appears-before-all-bs) | [![Java](assets/java.png)](src/CheckIfAllTheAsAppearBeforeAllTheBs.java) | | +| 2129 | [Capitalize the Title](https://leetcode.com/problems/capitalize-the-title) | [![Java](assets/java.png)](src/CapitalizeTheTitle.java) | | +| 2133 | [Check if Every Row and Column Contains All Numbers](https://leetcode.com/problems/check-if-every-row-and-column-contains-all-numbers) | [![Java](assets/java.png)](src/CheckIfEveryRowAndEveryColumnContainAllNumbers.java) | | +| 2138 | [Divide a String Into Groups of Size k](https://leetcode.com/problems/divide-a-string-into-groups-of-size-k) | [![Java](assets/java.png)](src/DivideTheStringIntoGroupsOfSizeK.java) | | +| 2144 | [Minimum Cost of Buying Candies With Discount](https://leetcode.com/problems/minimum-cost-of-buying-candies-with-discount) | [![Java](assets/java.png)](src/MinimumCostOfBuyingCandiesWithDiscount.java) | | +| 2148 | [Count Elements With Strictly Smaller and Greater Elements](https://leetcode.com/problems/count-elements-with-strictly-smaller-and-greater-elements) | [![Java](assets/java.png)](src/CountElementsWithStrictlySmallerAndGreaterElements.java) | | +| 2154 | [Keep Multiplying Found Values by Two](https://leetcode.com/problems/keep-multiplying-found-values-by-two) | [![Java](assets/java.png)](src/KeepMultiplyingFoundValuesByTwo.java) | | +| 2160 | [Minimum Sum of Four Digit Number After Splitting Digits](https://leetcode.com/problems/minimum-sum-of-four-digit-number-after-splitting-digits) | [![Java](assets/java.png)](src/MinimumSumOfFourDigitNumberAfterSplittingDigits.java) | | +| 2164 | [Sort Even and Odd Indices Independently](https://leetcode.com/problems/sort-even-and-odd-indices-independently) | [![Java](assets/java.png)](src/SortEvenAndOddIndicesIndependently.java) | | +| 2169 | [Count Operations to Obtain Zero](https://leetcode.com/problems/count-operations-to-obtain-zero) | [![Java](assets/java.png)](src/CountOperationsToObtainZero.java) | | +| 2176 | [Count Equal and Divisible Pairs in an Array](https://leetcode.com/problems/count-equal-and-divisible-pairs-in-an-array) | [![Java](assets/java.png)](src/CountEqualAndDivisiblePairsInAnArray.java) | | +| 2180 | [Count Integers With Even Digit Sum](https://leetcode.com/problems/count-integers-with-even-digit-sum) | [![Java](assets/java.png)](src/CountIntegersWithEvenDigitSum.java) | | +| 2185 | [Counting Words With a Given Prefix](https://leetcode.com/problems/counting-words-with-a-given-prefix) | [![Java](assets/java.png)](src/CountingWordsWithAGivenPrefix.java) | | +| 2190 | [Most Frequent Number Following Key In an Array](https://leetcode.com/problems/most-frequent-number-following-key-in-an-array) | [![Java](assets/java.png)](src/MostFrequentNumberFollowingKeyInAnArray.java) | | +| 2194 | [Cells in a Range on an Excel Sheet](https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet) | [![Java](assets/java.png)](src/CellsInARangeOnAnExcelSheet.java) | | +| 2200 | [Find All K-Distant Indices in an Array](https://leetcode.com/problems/find-all-k-distant-indices-in-an-array) | [![Java](assets/java.png)](src/FindAllKDistantIndicesInAnArray.java) | | +| 2206 | [Divide Array Into Equal Pairs](https://leetcode.com/problems/divide-array-into-equal-pairs) | [![Java](assets/java.png)](src/DivideArrayIntoEqualPairs.java) | | +| 2210 | [Count Hills and Valleys in an Array](https://leetcode.com/problems/count-hills-and-valleys-in-an-array) | [![Java](assets/java.png)](src/CountHillsAndValleysInAnArray.java) | | +| 2215 | [Find the Difference of Two Arrays](https://leetcode.com/problems/find-the-difference-of-two-arrays) | [![Java](assets/java.png)](src/FindTheDifferenceOfTwoArrays.java) | | +| 2220 | [Minimum Bit Flips to Convert Number](https://leetcode.com/problems/minimum-bit-flips-to-convert-number) | [![Java](assets/java.png)](src/MinimumBitFlipsToConvertNumber.java) | | +| 2224 | [Minimum Number of Operations to Convert Time](https://leetcode.com/problems/minimum-number-of-operations-to-convert-time) | [![Java](assets/java.png)](src/MinimumNumberOfOperationsToConvertTime.java) | | +| 2229 | 🔒 [Check if an array is consecutive](https://leetcode.com/problems/check-if-an-array-is-consecutive) | | | +| 2231 | [Largest Number After Digit Swaps by Parity](https://leetcode.com/problems/largest-number-after-digit-swaps-by-parity) | [![Java](assets/java.png)](src/LargestNumberAfterDigitSwapsByParity.java) | | +| 2235 | [Add Two Integers](https://leetcode.com/problems/add-two-integers) | [![Java](assets/java.png)](src/AddTwoIntegers.java) | | +| 2236 | [Root Equals Sum of Children](https://leetcode.com/problems/root-equals-sum-of-children) | [![Java](assets/java.png)](src/RootEqualsSumOfChildren.java) | | +| 2239 | [Find Closest Number to Zero](https://leetcode.com/problems/find-closest-number-to-zero) | [![Java](assets/java.png)](src/FindClosestNumberToZero.java) | | +| 2243 | [Calculate Digit Sum of a String](https://leetcode.com/problems/calculate-digit-sum-of-a-string) | [![Java](assets/java.png)](src/CalculateDigitSumOfAString.java) | | +| 2248 | [Intersection of Multiple Arrays](https://leetcode.com/problems/intersection-of-multiple-arrays) | [![Java](assets/java.png)](src/IntersectionOfMultipleArrays.java) | | +| 2255 | [Count Prefixes of a Given String](https://leetcode.com/problems/count-prefixes-of-a-given-string) | [![Java](assets/java.png)](src/CountPrefixesOfAGivenString.java) | | +| 2259 | [Remove Digit From Number to Maximize Result](https://leetcode.com/problems/remove-digit-from-number-to-maximize-result) | [![Java](assets/java.png)](src/RemoveDigitFromNumberToMaximizeResult.java) | | +| 2264 | [Largest 3-Same-Digit Number in String](https://leetcode.com/problems/largest-3-same-digit-number-in-string) | [![Java](assets/java.png)](src/Largest3SameDigitNumberInString.java) | | +| 2269 | [Find the K-Beauty of a Number](https://leetcode.com/problems/find-the-k-beauty-of-a-number) | [![Java](assets/java.png)](src/FindTheKBeautyOfANumber.java) | | +| 2273 | [Find Resultant Array After Removing Anagrams](https://leetcode.com/problems/find-resultant-array-after-removing-anagrams) | [![Java](assets/java.png)](src/FindResultantArrayAfterRemovingAnagrams.java) | | +| 2278 | [Percentage of Letter in String](https://leetcode.com/problems/percentage-of-letter-in-string) | [![Java](assets/java.png)](src/PercentageOfLetterInString.java) | | +| 2283 | [Check if Number Has Equal Digit Count and Digit Value](https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value) | [![Java](assets/java.png)](src/CheckIfNumberHasEqualDigitCountAndDigitValue.java) | | +| 2287 | [Rearrange Characters to Make Target String](https://leetcode.com/problems/rearrange-characters-to-make-target-string) | [![Java](assets/java.png)](src/RearrangeCharactersToMakeTargetString.java) | | +| 2293 | [Min Max Game](https://leetcode.com/problems/min-max-game) | [![Java](assets/java.png)](src/MinMaxGame.java) | | +| 2299 | [Strong Password Checker II](https://leetcode.com/problems/strong-password-checker-ii) | [![Java](assets/java.png)](src/StrongPasswordCheckerII.java) | | +| 2300 | [Successful Pairs of Spells and Potions](https://leetcode.com/problems/successful-pairs-of-spells-and-potions) | [![Python](assets/python.png)](python/successfull_pairs_of_spells_and_potions.py) | | +| 2303 | [Calculate Amount Paid in Taxes](https://leetcode.com/problems/calculate-amount-paid-in-taxes) | [![Java](assets/java.png)](src/CalculateAmountPaidInTaxes.java) | | +| 2309 | [Greatest English Letter in Upper and Lower Case](https://leetcode.com/problems/greatest-english-letter-in-upper-and-lower-case) | [![Java](assets/java.png)](src/GreatestEnglishLetterInUpperAndLowerCase.java) | | +| 2315 | [Count Asterisks](https://leetcode.com/problems/count-asterisks) | [![Java](assets/java.png)](src/CountAsterisks.java) [![Python](assets/python.png)](python/successfull_pairs_of_spells_and_potions.py) | | +| 2316 | [Count Unreachable Pairs of Nodes in an Undirected Graph](https://leetcode.com/problems/count-unreachable-pairs-of-nodes-in-an-undirected-graph) | [![Python](assets/python.png)](python/count_unreachable_pair_of_node_in_an_undirectable_graph.py) | | +| 2319 | [Check if Matrix Is X-Matrix](https://leetcode.com/problems/check-if-matrix-is-x-matrix) | [![Java](assets/java.png)](src/CountAsterisks.java) | | +| 2325 | [Decode the Message](https://leetcode.com/problems/decode-the-message) | [![Java](assets/java.png)](src/DecodeTheMessage.java) | | +| 2331 | [Evaluate Boolean Binary Tree](https://leetcode.com/problems/evaluate-boolean-binary-tree) | [![Java](assets/java.png)](src/EvaluateBooleanBinaryTree.java) | | +| 2335 | [Minimum Amount of Time to Fill Cups](https://leetcode.com/problems/minimum-amount-of-time-to-fill-cups) | [![Java](assets/java.png)](src/MinimumAmountOfTimeToFillCups.java) | | +| 2439 | [Minimize Maximum of Array](https://leetcode.com/problems/minimize-maximum-of-array) | [![Python](assets/python.png)](python/minimize_maximum_of_array.py) | | +| 2341 | [Maximum Number of Pairs in Array](https://leetcode.com/problems/maximum-number-of-pairs-in-array) | [![Java](assets/java.png)](src/MaximumNumberOfPairsInArray.java) | | +| 2347 | [Best Poker Hand](https://leetcode.com/problems/best-poker-hand) | [![Java](assets/java.png)](src/BestPokerHand.java) | | +| 2348 | [Number of Zero-Filled Subarrays](https://leetcode.com/problems/number-of-zero-filled-subarrays) | [![Python](assets/python.png)](python/number_of_zero_filled_subarrays.py) | | +| 2351 | [First Letter to Appear Twice](https://leetcode.com/problems/first-letter-to-appear-twice) | [![Java](assets/java.png)](src/FirstLetterToAppearTwice.java) | | +| 2357 | [Make Array Zero by Subtracting Equal Amounts](https://leetcode.com/problems/make-array-zero-by-subtracting-equal-amounts) | [![Java](assets/java.png)](src/MakeArrayZeroBySubtractingEqualAmounts.java) | | +| 2360 | [Longest Cycle in a Graph](https://leetcode.com/problems/longest-cycle-in-a-graph) | [![Python](assets/python.png)](python/longest_cycle_in_graph.py) | | +| 2363 | [Merge Similar Items](https://leetcode.com/problems/merge-similar-items) | [![Java](assets/java.png)](src/MergeSimilarItems.java) | | +| 2367 | [Number of Arithmetic Triplets](https://leetcode.com/problems/number-of-arithmetic-triplets) | [![Java](assets/java.png)](src/NumberOfArithmeticTriplets.java) | | +| 2373 | [Largest Local Values in a Matrix](https://leetcode.com/problems/largest-local-values-in-a-matrix) | [![Java](assets/java.png)](src/LargestLocalValuesInAMatrix.java) | | +| 2379 | [Minimum Recolors to Get K Consecutive Black Blocks](https://leetcode.com/problems/minimum-recolors-to-get-k-consecutive-black-blocks) | [![Java](assets/java.png)](src/MinimumRecolorsToGetKConsecutiveBlackBlocks.java) | | +| 2383 | [Minimum Hours of Training to Win a Competition](https://leetcode.com/problems/minimum-hours-of-training-to-win-a-competition) | [![Java](assets/java.png)](src/MinimumHoursOfTrainingToWinACompetition.java) | | +| 2389 | [Longest Subsequence With Limited Sum](https://leetcode.com/problems/longest-subsequence-with-limited-sum) | [![Java](assets/java.png)](src/LongestSubsequenceWithLimitedSum.java) | | +| 2395 | [Find Subarrays With Equal Sum](https://leetcode.com/problems/find-subarrays-with-equal-sum) | [![Java](assets/java.png)](src/FindSubarraysWithEqualSum.java) | | +| 2399 | [Check Distances Between Same Letters](https://leetcode.com/problems/check-distances-between-same-letters) | [![Java](assets/java.png)](src/CheckDistancesBetweenSameLetters.java) | | +| 2404 | [Most Frequent Even Element](https://leetcode.com/problems/most-frequent-even-element) | [![Java](assets/java.png)](src/MostFrequentEvenElement.java) | | +| 2409 | [Count Days Spent Together](https://leetcode.com/problems/count-days-spent-together) | [![Java](assets/java.png)](src/CountDaysSpentTogether.java) | | +| 2413 | [Smallest Even Multiple](https://leetcode.com/problems/smallest-even-multiple) | [![Java](assets/java.png)](src/SmallestEvenMultiple.java) | | +| 2418 | [Sort the People](https://leetcode.com/problems/sort-the-people) | [![Java](assets/java.png)](src/SortThePeople.java) | | +| 2423 | [Remove Letter To Equalize Frequency](https://leetcode.com/problems/remove-letter-to-equalize-frequency) | [![Java](assets/java.png)](src/RemoveLetterToEqualizeFrequency.java) | | +| 2427 | [Number of Common Factors](https://leetcode.com/problems/number-of-common-factors) | [![Java](assets/java.png)](src/NumberOfCommonFactors.java) | | +| 2432 | [The Employee That Worked on the Longest Task](https://leetcode.com/problems/the-employee-that-worked-on-the-longest-task) | [![Java](assets/java.png)](src/TheEmployeeThatWorkedOnTheLongestTask.java) | | +| 2437 | [Number of Valid Clock Times](https://leetcode.com/problems/number-of-valid-clock-times) | [![Java](assets/java.png)](src/NumberOfValidClockTimes.java) | | +| 2441 | [Largest Positive Integer That Exists With Its Negative](https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative) | [![Java](assets/java.png)](src/LargestPositiveIntegerThatExistsWithItsNegative.java) | | +| 2446 | [Determine if Two Events Have Conflict](https://leetcode.com/problems/determine-if-two-events-have-conflict) | [![Java](assets/java.png)](src/DetermineIfTwoEventsHaveConflict.java) | | +| 2451 | [Odd String Difference](https://leetcode.com/problems/odd-string-difference) | [![Java](assets/java.png)](src/OddStringDifference.java) | | +| 2455 | [Average Value of Even Numbers That Are Divisible by Three](https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three) | [![Java](assets/java.png)](src/AverageValueOfEvenNumbersThatAreDivisibleByThree.java) | | +| 2460 | [Apply Operations to an Array](https://leetcode.com/problems/apply-operations-to-an-array) | [![Java](assets/java.png)](src/ApplyOperationsToAnArray.java) | | +| 2465 | [Number of Distinct Averages](https://leetcode.com/problems/number-of-distinct-averages) | [![Java](assets/java.png)](src/NumberOfDistinctAverages.java) | | +| 2466 | [Count Ways To Build Good Strings](https://leetcode.com/problems/count-ways-to-build-good-strings) | | | +| 2469 | [Convert the Temperature](https://leetcode.com/problems/convert-the-temperature) | [![Java](assets/java.png)](src/ConvertTheTemperature.java) | | +| 2475 | [Number of Unequal Triplets in Array](https://leetcode.com/problems/number-of-unequal-triplets-in-array) | [![Java](assets/java.png)](src/NumberOfUnequalTripletsInArray.java) | | +| 2481 | [Minimum Cuts to Divide a Circle](https://leetcode.com/problems/minimum-cuts-to-divide-a-circle) | [![Java](assets/java.png)](src/MinimumCutsToDivideACircle.java) | | +| 2485 | [Find the Pivot Integer](https://leetcode.com/problems/find-the-pivot-integer) | [![Java](assets/java.png)](src/FindThePivotInteger.java) | | +| 2490 | [Circular Sentence](https://leetcode.com/problems/circular-sentence) | [![Java](assets/java.png)](src/CircularSentence.java) | | +| 2492 | [Minimum Score of a Path Between Two Cities](https://leetcode.com/problems/minimum-score-of-a-path-between-two-cities) | [![Python](assets/python.png)](python/minimum_score_of_a_path_between_two_cities.py) | | +| 2496 | [Maximum Value of a String in an Array](https://leetcode.com/problems/maximum-value-of-a-string-in-an-array) | [![Java](assets/java.png)](src/MaximumValueOfAStringInAnArray.java) | | +| 2500 | [Delete Greatest Value in Each Row](https://leetcode.com/problems/delete-greatest-value-in-each-row) | [![Java](assets/java.png)](src/DeleteGreatestValueInEachRow.java) | | +| 2506 | [Count Pairs Of Similar Strings](https://leetcode.com/problems/count-pairs-of-similar-strings) | [![Java](assets/java.png)](src/CountPairsOfSimilarStrings.java) | | +| 2511 | [Maximum Enemy Forts That Can Be Captured](https://leetcode.com/problems/maximum-enemy-forts-that-can-be-captured) | [![Java](assets/java.png)](src/MaximumEnemyFortsThatCanBeCaptured.java) | | +| 2515 | [Shortest Distance to Target String in a Circular Array](https://leetcode.com/problems/shortest-distance-to-target-string-in-a-circular-array) | [![Java](assets/java.png)](src/ShortestDistanceToTargetStringInACircularArray.java) | | +| 2520 | [Count the Digits That Divide a Number](https://leetcode.com/problems/count-the-digits-that-divide-a-number) | [![Java](assets/java.png)](src/CountTheDigitsThatDivideANumber.java) | | +| 2525 | [Categorize Box According to Criteria](https://leetcode.com/problems/categorize-box-according-to-criteria) | [![Java](assets/java.png)](src/CategorizeBoxAccordingToCriteria.java) | | +| 2529 | [Maximum Count of Positive Integer and Negative Integer](https://leetcode.com/problems/maximum-count-of-positive-integer-and-negative-integer) | [![Java](assets/java.png)](src/MaximumCountOfPositiveIntegerAndNegativeInteger.java) | | +| 2535 | [Difference Between Element Sum and Digit Sum of an Array](https://leetcode.com/problems/difference-between-element-sum-and-digit-sum-of-an-array) | [![Java](assets/java.png)](src/DifferenceBetweenElementSumAndDigitSumOfAnArray.java) | | +| 2540 | [Minimum Common Value](https://leetcode.com/problems/minimum-common-value) | [![Java](assets/java.png)](src/MinimumCommonValue.java) | | +| 2544 | [Alternating Digit Sum](https://leetcode.com/problems/alternating-digit-sum) | [![Java](assets/java.png)](src/AlternatingDigitSum.java) | | +| 2549 | [Count Distinct Numbers on Board](https://leetcode.com/problems/count-distinct-numbers-on-board) | [![Java](assets/java.png)](src/CountDistinctNumbersOnBoard.java) | | +| 2553 | [Separate the Digits in an Array](https://leetcode.com/problems/separate-the-digits-in-an-array) | [![Java](assets/java.png)](src/SeparateTheDigitsInAnArray.java) | | +| 2558 | [Take Gifts From the Richest Pile](https://leetcode.com/problems/take-gifts-from-the-richest-pile) | [![Java](assets/java.png)](src/TakeGiftsFromTheRichestPile.java) | | +| 2562 | [Find the Array Concatenation Value](https://leetcode.com/problems/find-the-array-concatenation-value) | [![Java](assets/java.png)](src/FindTheArrayConcatenationValue.java) | | +| 2566 | [Maximum Difference by Remapping a Digit](https://leetcode.com/problems/maximum-difference-by-remapping-a-digit) | [![Java](assets/java.png)](src/MaximumDifferenceByRemappingADigit.java) | | +| 2570 | [Merge Two 2D Arrays by Summing Values](https://leetcode.com/problems/merge-two-2d-arrays-by-summing-values) | [![Java](assets/java.png)](src/MergeTwo2DArraysBySummingValues.java) | | +| 2574 | [Left and Right Sum Differences](https://leetcode.com/problems/left-and-right-sum-differences) | [![Java](assets/java.png)](src/LeftAndRightSumDifferences.java) | | +| 2578 | [Split With Minimum Sum](https://leetcode.com/problems/split-with-minimum-sum) | [![Java](assets/java.png)](src/SplitWithMinimumSum.java) | | +| 2582 | [Pass the Pillow](https://leetcode.com/problems/pass-the-pillow) | [![Java](assets/java.png)](src/PassThePillow.java) | | +| 2586 | [Count the Number of Vowel Strings in Range](https://leetcode.com/problems/count-the-number-of-vowel-strings-in-range) | [![Java](assets/java.png)](src/CountTheNumberOfVowelStringsInRange.java) | | +| 2591 | [Distribute Money to Maximum Children](https://leetcode.com/problems/distribute-money-to-maximum-children) | [![Java](assets/java.png)](src/DistributeMoneyToMaximumChildren.java) | | +| 2595 | [Number of Even and Odd Bits](https://leetcode.com/problems/number-of-even-and-odd-bits) | [![Java](assets/java.png)](src/NumberOfEvenAndOddBits.java) | | +| 2600 | [K Items With the Maximum Sum](https://leetcode.com/problems/k-items-with-the-maximum-sum) | [![Java](assets/java.png)](src/KItemsWithTheMaximumSum.java) | | +| 2605 | [Form Smallest Number From Two Digit Arrays](https://leetcode.com/problems/form-smallest-number-from-two-digit-arrays) | [![Java](assets/java.png)](src/FormSmallestNumberFromTwoDigitArrays.java) | | +| 2609 | [Find the Longest Balanced Substring of a Binary String](https://leetcode.com/problems/find-the-longest-balanced-substring-of-a-binary-string) | [![Java](assets/java.png)](src/FindTheLongestBalancedSubstringOfABinaryString.java) | | +| 2614 | [Prime In Diagonal](https://leetcode.com/problems/prime-in-diagonal) | [![Java](assets/java.png)](src/PrimeInDiagonal.java) | | +| 2639 | [Find the Width of Columns of a Grid](https://leetcode.com/problems/find-the-width-of-columns-of-a-grid) | [![Java](assets/java.png)](src/FindTheWidthOfColumnsOfAGrid.java) | | +| 2643 | [Row With Maximum Ones](https://leetcode.com/problems/row-with-maximum-ones) | [![Java](assets/java.png)](src/RowWithMaximumOnes.java) | | +| 2644 | [Find the Maximum Divisibility Score](https://leetcode.com/problems/find-the-maximum-divisibility-score) | [![Java](assets/java.png)](src/FindTheMaximumDivisibilityScore.java) | | +| 2651 | [Calculate Delayed Arrival Time](https://leetcode.com/problems/calculate-delayed-arrival-time) | [![Java](assets/java.png)](src/CalculateDelayedArrivalTime.java) | | +| 2652 | [Sum Multiples](https://leetcode.com/problems/sum-multiples) | [![Java](assets/java.png)](src/SumMultiples.java) | | +| 2656 | [Maximum Sum With Exactly K Elements](https://leetcode.com/problems/maximum-sum-with-exactly-k-elements) | [![Java](assets/java.png)](src/MaximumSumWithExactlyKElements.java) | | +| 2660 | [Determine the Winner of a Bowling Game](https://leetcode.com/problems/determine-the-winner-of-a-bowling-game) | [![Java](assets/java.png)](src/DetermineTheWinnerOfABowlingGame.java) | | +| 2670 | [Find the Distinct Difference Array](https://leetcode.com/problems/find-the-distinct-difference-array) | [![Java](assets/java.png)](src/FindTheDistinctDifferenceArray.java) | | +| 2678 | [Number of Senior Citizens](https://leetcode.com/problems/number-of-senior-citizens) | [![Java](assets/java.png)](src/NumberOfSeniorCitizens.java) | | +| 2682 | [Find the Losers of the Circular Game](https://leetcode.com/problems/find-the-losers-of-the-circular-game) | [![Java](assets/java.png)](src/FindTheLosersOfTheCircularGame.java) | | +| 2696 | [Minimum String Length After Removing Substrings](https://leetcode.com/problems/minimum-string-length-after-removing-substrings) | [![Java](assets/java.png)](src/MinimumStringLengthAfterRemovingSubstrings.java) | | +| 2697 | [Lexicographically Smallest Palindrome](https://leetcode.com/problems/lexicographically-smallest-palindrome) | [![Java](assets/java.png)](src/LexicographicallySmallestPalindrome.java) | | +| 2706 | [Buy Two Chocolates](https://leetcode.com/problems/buy-two-chocolates) | [![Java](assets/java.png)](src/BuyTwoChocolates.java) | | +| 2710 | [Remove Trailing Zeros From a String](https://leetcode.com/problems/remove-trailing-zeros-from-a-string) | [![Java](assets/java.png)](src/RemoveTrailingZerosFromAString.java) | | +| 2716 | [Minimize String Length](https://leetcode.com/problems/minimize-string-length) | [![Java](assets/java.png)](src/MinimizeStringLength.java) | | +| 2717 | [Semi-Ordered Permutation](https://leetcode.com/problems/semi-ordered-permutation) | [![Java](assets/java.png)](src/SemiOrderedPermutation.java) | | +| 2728 | [Count Houses in a Circular Street](https://leetcode.com/problems/count-houses-in-a-circular-street) | | | +| 2729 | [Check if The Number is Fascinating](https://leetcode.com/problems/check-if-the-number-is-fascinating) | [![Java](assets/java.png)](src/CheckIfTheNumberIsFascinating.java) | | +| 2733 | [Neither Minimum nor Maximum](https://leetcode.com/problems/neither-minimum-nor-maximum) | [![Java](assets/java.png)](src/NeitherMinimumNorMaximum.java) | | +| 2739 | [Total Distance Traveled](https://leetcode.com/problems/total-distance-traveled) | [![Java](assets/java.png)](src/TotalDistanceTraveled.java) | | +| 2744 | [Find Maximum Number of String Pairs](https://leetcode.com/problems/find-maximum-number-of-string-pairs) | [![Java](assets/java.png)](src/FindMaximumNumberOfStringPairs.java) | | +| 2748 | [Number of Beautiful Pairs](https://leetcode.com/problems/number-of-beautiful-pairs) | [![Java](assets/java.png)](src/NumberOfBeautifulPairs.java) | | +| 2760 | [Longest Even Odd Subarray With Threshold](https://leetcode.com/problems/longest-even-odd-subarray-with-threshold) | [![Java](assets/java.png)](src/LongestEvenOddSubarrayWithThreshold.java) | | +| 2765 | [Longest Alternating Subarray](https://leetcode.com/problems/longest-alternating-subarray) | [![Java](assets/java.png)](src/LongestAlternatingSubarray.java) | | +| 2769 | [Find the Maximum Achievable Number](https://leetcode.com/problems/find-the-maximum-achievable-number) | [![Java](assets/java.png)](src/FindTheMaximumAchievableNumber.java) | | +| 2778 | [Sum of Squares of Special Elements](https://leetcode.com/problems/sum-of-squares-of-special-elements) | [![Java](assets/java.png)](src/SumOfSquaresOfSpecialElements.java) | | +| 2784 | [Check if Array is Good](https://leetcode.com/problems/check-if-array-is-good) | [![Java](assets/java.png)](src/CheckIfArrayIsGood.java) | | +| 2788 | [Split Strings by Separator](https://leetcode.com/problems/split-strings-by-separator) | [![Java](assets/java.png)](src/SplitStringsBySeparator.java) | | +| 2798 | [Number of Employees Who Met the Target](https://leetcode.com/problems/number-of-employees-who-met-the-target) | [![Java](assets/java.png)](src/NumberOfEmployeesWhoMetTheTarget.java) | | +| 2806 | [Account Balance After Rounded Purchase](https://leetcode.com/problems/account-balance-after-rounded-purchase) | [![Java](assets/java.png)](src/AccountBalanceAfterRoundedPurchase.java) | | +| 2810 | [Faulty Keyboard](https://leetcode.com/problems/faulty-keyboard) | [![Java](assets/java.png)](src/FaultyKeyboard.java) | | +| 2815 | [Max Pair Sum in an Array](https://leetcode.com/problems/max-pair-sum-in-an-array) | [![Java](assets/java.png)](src/MaxPairSumInAnArray.java) | | +| 2824 | [Count Pairs Whose Sum is Less than Target](https://leetcode.com/problems/count-pairs-whose-sum-is-less-than-target) | [![Java](assets/java.png)](src/CountPairsWhoseSumIsLessThanTarget.java) | | +| 2828 | [Check if a String Is an Acronym of Words](https://leetcode.com/problems/check-if-a-string-is-an-acronym-of-words) | [![Java](assets/java.png)](src/CheckIfAStringIsAnAcronymOfWords.java) | | \ No newline at end of file From 5b6ebaf00a2123b1155c6f82d7637fc6e0971da1 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 5 Jul 2024 03:11:40 +0200 Subject: [PATCH 148/280] solve #1637: WidestVerticalAreaBetweenTwoPointsContainingNoPoints in Java --- README.md | 128 ++- README.txt | 850 ------------------ src/HelloWorld.java | 73 +- ...reaBetweenTwoPointsContainingNoPoints.java | 13 + 4 files changed, 170 insertions(+), 894 deletions(-) delete mode 100644 README.txt create mode 100644 src/WidestVerticalAreaBetweenTwoPointsContainingNoPoints.java diff --git a/README.md b/README.md index 13c2c65..763ceb6 100644 --- a/README.md +++ b/README.md @@ -147,6 +147,7 @@ | 160 | [Intersection of Two Linked Lists](https://leetcode.com/problems/intersection-of-two-linked-lists) | [![Java](assets/java.png)](src/IntersectionOf2LinkedLists.java) [![Python](assets/python.png)](python/intersecction_of_two_linked_lists.py) | | | 161 | 🔒 [One Edit Distance](https://leetcode.com/problems/one-edit-distance) | | | | 162 | [Find Peak Element](https://leetcode.com/problems/find-peak-element) | [![Java](assets/java.png)](src/FindPeakElement.java) | | +| 164 | [Maximum Gap](https://leetcode.com/problems/maximum-gap) | | | | 165 | [Compare Version Numbers](https://leetcode.com/problems/compare-version-numbers) | [![Java](assets/java.png)](src/CompareVersionNumbers.java) | | | 166 | [Fraction to Recurring Decimal](https://leetcode.com/problems/fraction-to-recurring-decimal) | [![Java](assets/java.png)](src/FractionToRecurringDecimal.java) | | | 167 | [Two Sum II - Input Array is Sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted) | [![Java](assets/java.png)](src/TwoSumIIInputArrayIsSorted.java) [![Python](assets/python.png)](python/two_sum_ii.py) | | @@ -247,7 +248,7 @@ | 294 | 🔒 [Flip Game II](https://leetcode.com/problems/flip-game-ii) | | | | 298 | 🔒 [Binary Tree Longest Consecutive Sequence](https://leetcode.com/problems/binary-tree-longest-consecutive-sequence) | | | | 299 | [Bulls and Cows](https://leetcode.com/problems/bulls-and-cows) | [![Java](assets/java.png)](src/BullsAndCows.java) [![Python](assets/python.png)](python/bulls_and_cows.py) | | -| 300 | [Longest Increasing Subsequence](https://leetcode.com/problems/longest-increasing-subsequence) | [![Java](assets/java.png)](src/LongestIncreasingSubsequence.java) | | +| 300 | [Longest Increasing Subsequence](https://leetcode.com/problems/longest-increasing-subsequence) | [![Java](assets/java.png)](src/LongestIncreasingSubsequence.java) | | | 303 | [Range Sum Query - Immutable](https://leetcode.com/problems/range-sum-query-immutable) | [![Java](assets/java.png)](src/RangeSumQueryImmutable.java) [![Python](assets/python.png)](python/range_sum_query_immutable.py) | | | 304 | [Range Sum Query 2D - Immutable](https://leetcode.com/problems/range-sum-query-2d-immutable) | | | | 306 | [Additive Number](https://leetcode.com/problems/additive-number) | | | @@ -608,6 +609,7 @@ | 1624 | [Largest Substring Between Two Equal Characters](https://leetcode.com/problems/largest-substring-between-two-equal-characters) | [![Java](assets/java.png)](src/LargestSubStringBetweenTwoEqualCharacters.java) | | | 1629 | [Slowest Key](https://leetcode.com/problems/slowest-key) | [![Java](assets/java.png)](src/SlowestKey.java) | | | 1636 | [Sort Array by Increasing Frequency](https://leetcode.com/problems/sort-array-by-increasing-frequency) | [![Java](assets/java.png)](src/SortArrayByIncreasingFrequency.java) | | +| 1637 | [Widest Vertical Area Between Two Points Containing No Points](https://leetcode.com/problems/widest-vertical-area-between-two-points-containing-no-points) | [![Java](assets/java.png)](src/WidestVerticalAreaBetweenTwoPointsContainingNoPoints.java) | | | 1640 | [Check Array Formation Through Concatenation](https://leetcode.com/problems/check-array-formation-through-concatenation) | [![Java](assets/java.png)](src/CheckArrayFormationThroughConcatenation.java) | | | 1646 | [Get Maximum in Generated Array](https://leetcode.com/problems/get-maximum-in-generated-array) | [![Java](assets/java.png)](src/GetMaximumInGeneratedArray.java) | | | 1652 | [Defuse the Bomb](https://leetcode.com/problems/defuse-the-bomb) | [![Java](assets/java.png)](src/DefuseTheBomb.java) | | @@ -823,28 +825,106 @@ | 2660 | [Determine the Winner of a Bowling Game](https://leetcode.com/problems/determine-the-winner-of-a-bowling-game) | [![Java](assets/java.png)](src/DetermineTheWinnerOfABowlingGame.java) | | | 2670 | [Find the Distinct Difference Array](https://leetcode.com/problems/find-the-distinct-difference-array) | [![Java](assets/java.png)](src/FindTheDistinctDifferenceArray.java) | | | 2678 | [Number of Senior Citizens](https://leetcode.com/problems/number-of-senior-citizens) | [![Java](assets/java.png)](src/NumberOfSeniorCitizens.java) | | -| 2682 | [Find the Losers of the Circular Game](https://leetcode.com/problems/find-the-losers-of-the-circular-game) | [![Java](assets/java.png)](src/FindTheLosersOfTheCircularGame.java) | | -| 2696 | [Minimum String Length After Removing Substrings](https://leetcode.com/problems/minimum-string-length-after-removing-substrings) | [![Java](assets/java.png)](src/MinimumStringLengthAfterRemovingSubstrings.java) | | -| 2697 | [Lexicographically Smallest Palindrome](https://leetcode.com/problems/lexicographically-smallest-palindrome) | [![Java](assets/java.png)](src/LexicographicallySmallestPalindrome.java) | | -| 2706 | [Buy Two Chocolates](https://leetcode.com/problems/buy-two-chocolates) | [![Java](assets/java.png)](src/BuyTwoChocolates.java) | | -| 2710 | [Remove Trailing Zeros From a String](https://leetcode.com/problems/remove-trailing-zeros-from-a-string) | [![Java](assets/java.png)](src/RemoveTrailingZerosFromAString.java) | | -| 2716 | [Minimize String Length](https://leetcode.com/problems/minimize-string-length) | [![Java](assets/java.png)](src/MinimizeStringLength.java) | | +| 2682 | [Find the Losers of the Circular Game](https://leetcode.com/problems/find-the-losers-of-the-circular-game) | [![Java](assets/java.png)](src/FindTheLosersOfTheCircularGame.java) | | +| 2696 | [Minimum String Length After Removing Substrings](https://leetcode.com/problems/minimum-string-length-after-removing-substrings) | [![Java](assets/java.png)](src/MinimumStringLengthAfterRemovingSubstrings.java) | | +| 2697 | [Lexicographically Smallest Palindrome](https://leetcode.com/problems/lexicographically-smallest-palindrome) | [![Java](assets/java.png)](src/LexicographicallySmallestPalindrome.java) | | +| 2706 | [Buy Two Chocolates](https://leetcode.com/problems/buy-two-chocolates) | [![Java](assets/java.png)](src/BuyTwoChocolates.java) | | +| 2710 | [Remove Trailing Zeros From a String](https://leetcode.com/problems/remove-trailing-zeros-from-a-string) | [![Java](assets/java.png)](src/RemoveTrailingZerosFromAString.java) | | +| 2716 | [Minimize String Length](https://leetcode.com/problems/minimize-string-length) | [![Java](assets/java.png)](src/MinimizeStringLength.java) | | | 2717 | [Semi-Ordered Permutation](https://leetcode.com/problems/semi-ordered-permutation) | [![Java](assets/java.png)](src/SemiOrderedPermutation.java) | | | 2728 | [Count Houses in a Circular Street](https://leetcode.com/problems/count-houses-in-a-circular-street) | | | -| 2729 | [Check if The Number is Fascinating](https://leetcode.com/problems/check-if-the-number-is-fascinating) | [![Java](assets/java.png)](src/CheckIfTheNumberIsFascinating.java) | | -| 2733 | [Neither Minimum nor Maximum](https://leetcode.com/problems/neither-minimum-nor-maximum) | [![Java](assets/java.png)](src/NeitherMinimumNorMaximum.java) | | -| 2739 | [Total Distance Traveled](https://leetcode.com/problems/total-distance-traveled) | [![Java](assets/java.png)](src/TotalDistanceTraveled.java) | | -| 2744 | [Find Maximum Number of String Pairs](https://leetcode.com/problems/find-maximum-number-of-string-pairs) | [![Java](assets/java.png)](src/FindMaximumNumberOfStringPairs.java) | | -| 2748 | [Number of Beautiful Pairs](https://leetcode.com/problems/number-of-beautiful-pairs) | [![Java](assets/java.png)](src/NumberOfBeautifulPairs.java) | | -| 2760 | [Longest Even Odd Subarray With Threshold](https://leetcode.com/problems/longest-even-odd-subarray-with-threshold) | [![Java](assets/java.png)](src/LongestEvenOddSubarrayWithThreshold.java) | | -| 2765 | [Longest Alternating Subarray](https://leetcode.com/problems/longest-alternating-subarray) | [![Java](assets/java.png)](src/LongestAlternatingSubarray.java) | | -| 2769 | [Find the Maximum Achievable Number](https://leetcode.com/problems/find-the-maximum-achievable-number) | [![Java](assets/java.png)](src/FindTheMaximumAchievableNumber.java) | | -| 2778 | [Sum of Squares of Special Elements](https://leetcode.com/problems/sum-of-squares-of-special-elements) | [![Java](assets/java.png)](src/SumOfSquaresOfSpecialElements.java) | | -| 2784 | [Check if Array is Good](https://leetcode.com/problems/check-if-array-is-good) | [![Java](assets/java.png)](src/CheckIfArrayIsGood.java) | | -| 2788 | [Split Strings by Separator](https://leetcode.com/problems/split-strings-by-separator) | [![Java](assets/java.png)](src/SplitStringsBySeparator.java) | | -| 2798 | [Number of Employees Who Met the Target](https://leetcode.com/problems/number-of-employees-who-met-the-target) | [![Java](assets/java.png)](src/NumberOfEmployeesWhoMetTheTarget.java) | | -| 2806 | [Account Balance After Rounded Purchase](https://leetcode.com/problems/account-balance-after-rounded-purchase) | [![Java](assets/java.png)](src/AccountBalanceAfterRoundedPurchase.java) | | -| 2810 | [Faulty Keyboard](https://leetcode.com/problems/faulty-keyboard) | [![Java](assets/java.png)](src/FaultyKeyboard.java) | | -| 2815 | [Max Pair Sum in an Array](https://leetcode.com/problems/max-pair-sum-in-an-array) | [![Java](assets/java.png)](src/MaxPairSumInAnArray.java) | | -| 2824 | [Count Pairs Whose Sum is Less than Target](https://leetcode.com/problems/count-pairs-whose-sum-is-less-than-target) | [![Java](assets/java.png)](src/CountPairsWhoseSumIsLessThanTarget.java) | | -| 2828 | [Check if a String Is an Acronym of Words](https://leetcode.com/problems/check-if-a-string-is-an-acronym-of-words) | [![Java](assets/java.png)](src/CheckIfAStringIsAnAcronymOfWords.java) | | \ No newline at end of file +| 2729 | [Check if The Number is Fascinating](https://leetcode.com/problems/check-if-the-number-is-fascinating) | [![Java](assets/java.png)](src/CheckIfTheNumberIsFascinating.java) | | +| 2733 | [Neither Minimum nor Maximum](https://leetcode.com/problems/neither-minimum-nor-maximum) | [![Java](assets/java.png)](src/NeitherMinimumNorMaximum.java) | | +| 2739 | [Total Distance Traveled](https://leetcode.com/problems/total-distance-traveled) | [![Java](assets/java.png)](src/TotalDistanceTraveled.java) | | +| 2744 | [Find Maximum Number of String Pairs](https://leetcode.com/problems/find-maximum-number-of-string-pairs) | [![Java](assets/java.png)](src/FindMaximumNumberOfStringPairs.java) | | +| 2748 | [Number of Beautiful Pairs](https://leetcode.com/problems/number-of-beautiful-pairs) | [![Java](assets/java.png)](src/NumberOfBeautifulPairs.java) | | +| 2760 | [Longest Even Odd Subarray With Threshold](https://leetcode.com/problems/longest-even-odd-subarray-with-threshold) | [![Java](assets/java.png)](src/LongestEvenOddSubarrayWithThreshold.java) | | +| 2765 | [Longest Alternating Subarray](https://leetcode.com/problems/longest-alternating-subarray) | [![Java](assets/java.png)](src/LongestAlternatingSubarray.java) | | +| 2769 | [Find the Maximum Achievable Number](https://leetcode.com/problems/find-the-maximum-achievable-number) | [![Java](assets/java.png)](src/FindTheMaximumAchievableNumber.java) | | +| 2778 | [Sum of Squares of Special Elements](https://leetcode.com/problems/sum-of-squares-of-special-elements) | [![Java](assets/java.png)](src/SumOfSquaresOfSpecialElements.java) | | +| 2784 | [Check if Array is Good](https://leetcode.com/problems/check-if-array-is-good) | [![Java](assets/java.png)](src/CheckIfArrayIsGood.java) | | +| 2788 | [Split Strings by Separator](https://leetcode.com/problems/split-strings-by-separator) | [![Java](assets/java.png)](src/SplitStringsBySeparator.java) | | +| 2798 | [Number of Employees Who Met the Target](https://leetcode.com/problems/number-of-employees-who-met-the-target) | [![Java](assets/java.png)](src/NumberOfEmployeesWhoMetTheTarget.java) | | +| 2806 | [Account Balance After Rounded Purchase](https://leetcode.com/problems/account-balance-after-rounded-purchase) | [![Java](assets/java.png)](src/AccountBalanceAfterRoundedPurchase.java) | | +| 2810 | [Faulty Keyboard](https://leetcode.com/problems/faulty-keyboard) | [![Java](assets/java.png)](src/FaultyKeyboard.java) | | +| 2815 | [Max Pair Sum in an Array](https://leetcode.com/problems/max-pair-sum-in-an-array) | [![Java](assets/java.png)](src/MaxPairSumInAnArray.java) | | +| 2824 | [Count Pairs Whose Sum is Less than Target](https://leetcode.com/problems/count-pairs-whose-sum-is-less-than-target) | [![Java](assets/java.png)](src/CountPairsWhoseSumIsLessThanTarget.java) | | +| 2828 | [Check if a String Is an Acronym of Words](https://leetcode.com/problems/check-if-a-string-is-an-acronym-of-words) | [![Java](assets/java.png)](src/CheckIfAStringIsAnAcronymOfWords.java) | | +| 2833 | [Furthest Point From Origin](https://leetcode.com/problems/furthest-point-from-origin) | | | +| 2839 | [Check if Strings Can be Made Equal With Operations I](https://leetcode.com/problems/check-if-strings-can-be-made-equal-with-operations-i) | | | +| 2843 | [Count Symmetric Integers](https://leetcode.com/problems/count-symmetric-integers) | | | +| 2848 | [Points That Intersect With Cars](https://leetcode.com/problems/points-that-intersect-with-cars) | | | +| 2855 | [Minimum Right Shifts to Sort the Array](https://leetcode.com/problems/minimum-right-shifts-to-sort-the-array) | | | +| 2859 | [Sum of Values at Indices With K Set Bits](https://leetcode.com/problems/sum-of-values-at-indices-with-k-set-bits) | | | +| 2833 | [Furthest Point From Origin](https://leetcode.com/problems/furthest-point-from-origin) | | | +| 2839 | [Check if Strings Can be Made Equal With Operations I](https://leetcode.com/problems/check-if-strings-can-be-made-equal-with-operations-i) | | | +| 2843 | [Count Symmetric Integers](https://leetcode.com/problems/count-symmetric-integers) | | | +| 2848 | [Points That Intersect With Cars](https://leetcode.com/problems/points-that-intersect-with-cars) | | | +| 2855 | [Minimum Right Shifts to Sort the Array](https://leetcode.com/problems/minimum-right-shifts-to-sort-the-array) | | | +| 2859 | [Sum of Values at Indices With K Set Bits](https://leetcode.com/problems/sum-of-values-at-indices-with-k-set-bits) | | | +| 2864 | [Maximum Odd Binary Number](https://leetcode.com/problems/maximum-odd-binary-number) | | | +| 2869 | [Minimum Operations to Collect Elements](https://leetcode.com/problems/minimum-operations-to-collect-elements) | | | +| 2873 | [Maximum Value of an Ordered Triplet I](https://leetcode.com/problems/maximum-value-of-an-ordered-triplet-i) | | | +| 2894 | [Divisible and Non-divisible Sums Difference](https://leetcode.com/problems/divisible-and-non-divisible-sums-difference) | | | +| 2899 | [Last Visited Integers](https://leetcode.com/problems/last-visited-integers) | | | +| 2900 | [Longest Unequal Adjacent Groups Subsequence I](https://leetcode.com/problems/longest-unequal-adjacent-groups-subsequence-i) | | | +| 2903 | [Find Indices With Index and Value Difference I](https://leetcode.com/problems/find-indices-with-index-and-value-difference-i) | | | +| 2908 | [Minimum Sum of Mountain Triplets I](https://leetcode.com/problems/minimum-sum-of-mountain-triplets-i) | | | +| 2913 | [Subarrays Distinct Element Sum of Squares I](https://leetcode.com/problems/subarrays-distinct-element-sum-of-squares-i) | | | +| 2917 | [Find the K-or of an Array](https://leetcode.com/problems/find-the-k-or-of-an-array) | | | +| 2923 | [Find Champion I](https://leetcode.com/problems/find-champion-i) | | | +| 2928 | [Distribute Candies Among Children I](https://leetcode.com/problems/distribute-candies-among-children-i) | | | +| 2932 | [Maximum Strong Pair XOR I](https://leetcode.com/problems/maximum-strong-pair-xor-i) | | | +| 2937 | [Make Three Strings Equal](https://leetcode.com/problems/make-three-strings-equal) | | | +| 2942 | [Find Words Containing Character](https://leetcode.com/problems/find-words-containing-character) | | | +| 2946 | [Matrix Similarity After Cyclic Shifts](https://leetcode.com/problems/matrix-similarity-after-cyclic-shifts) | | | +| 2951 | [Find the Peaks](https://leetcode.com/problems/find-the-peaks) | | | +| 2956 | [Find Common Elements Between Two Arrays](https://leetcode.com/problems/find-common-elements-between-two-arrays) | | | +| 2960 | [Count Tested Devices After Test Operations](https://leetcode.com/problems/count-tested-devices-after-test-operations) | | | +| 2965 | [Find Missing and Repeated Values](https://leetcode.com/problems/find-missing-and-repeated-values) | | | +| 2970 | [Count the Number of Irremovable Subarrays I](https://leetcode.com/problems/count-the-number-of-incremovable-subarrays-i) | | | +| 2974 | [Minimum Number Game](https://leetcode.com/problems/minimum-number-game) | | | +| 2980 | [Check if Bitwise OR Has Trailing Zeros](https://leetcode.com/problems/check-if-bitwise-or-has-trailing-zeros) | | | +| 2996 | [Smallest Missing Integer Greater Than Sequential Prefix Sum](https://leetcode.com/problems/smallest-missing-integer-greater-than-sequential-prefix-sum) | | | +| 3000 | [Maximum Area of Longest Diagonal Rectangle](https://leetcode.com/problems/maximum-area-of-longest-diagonal-rectangle) | | | +| 3005 | [Count Elements With Maximum Frequency](https://leetcode.com/problems/count-elements-with-maximum-frequency) | | | +| 3010 | [Divide an Array Into Subarrays With Minimum Cost I](https://leetcode.com/problems/divide-an-array-into-subarrays-with-minimum-cost-i) | | | +| 3014 | [Minimum Number of Pushes to Type Word I](https://leetcode.com/problems/minimum-number-of-pushes-to-type-word-i) | | | +| 3019 | [Number of Changing Keys](https://leetcode.com/problems/number-of-changing-keys) | | | +| 3024 | [Type of Triangle](https://leetcode.com/problems/type-of-triangle) | | | +| 3028 | [Ant on the Boundary](https://leetcode.com/problems/ant-on-the-boundary) | | | +| 3032 | 🔒 [Count Numbers With Unique Digits II](https://leetcode.com/problems/count-numbers-with-unique-digits-ii) | | | +| 3038 | [Maximum Number of Operations With the Same Score I](https://leetcode.com/problems/maximum-number-of-operations-with-the-same-score-i) | | | +| 3042 | [Count Prefix and Suffix Pairs I](https://leetcode.com/problems/count-prefix-and-suffix-pairs-i) | | | +| 3046 | [Split the Array](https://leetcode.com/problems/split-the-array) | | | +| 3062 | 🔒 [Winner of the Linked List Game](https://leetcode.com/problems/winner-of-the-linked-list-game) | | | +| 3063 | 🔒 [Linked List Frequency](https://leetcode.com/problems/linked-list-frequency) | | | +| 3065 | [Minimum Operations to Exceed Threshold Value I](https://leetcode.com/problems/minimum-operations-to-exceed-threshold-value-i) | | | +| 3069 | [Distribute Elements Into Two Arrays I](https://leetcode.com/problems/distribute-elements-into-two-arrays-i) | | | +| 3074 | [Apple Redistribution into Boxes](https://leetcode.com/problems/apple-redistribution-into-boxes) | | | +| 3079 | [Find the Sum of Encrypted Integers](https://leetcode.com/problems/find-the-sum-of-encrypted-integers) | | | +| 3083 | [Existence of a Substring in a String and Its Reverse](https://leetcode.com/problems/existence-of-a-substring-in-a-string-and-its-reverse) | | | +| 3090 | [Maximum Length Substring With Two Occurrences](https://leetcode.com/problems/maximum-length-substring-with-two-occurrences) | | | +| 3095 | [Shortest Subarray With OR at Least K I](https://leetcode.com/problems/shortest-subarray-with-or-at-least-k-i) | | | +| 3099 | [Harshad Number](https://leetcode.com/problems/harshad-number) | | | +| 3105 | [Longest Strictly Increasing or Strictly Decreasing Subarray](https://leetcode.com/problems/longest-strictly-increasing-or-strictly-decreasing-subarray) | | | +| 3110 | [Score of a String](https://leetcode.com/problems/score-of-a-string) | | | +| 3114 | [Latest Time You Can Obtain After Replacing Characters](https://leetcode.com/problems/latest-time-you-can-obtain-after-replacing-characters) | | | +| 3120 | [Count the Number of Special Characters I](https://leetcode.com/problems/count-the-number-of-special-characters-i) | | | +| 3127 | [Make a Square with the Same Color](https://leetcode.com/problems/make-a-square-with-the-same-color) | | | +| 3131 | [Find the Integer Added to Array I](https://leetcode.com/problems/find-the-integer-added-to-array-i) | | | +| 3136 | [Valid Word](https://leetcode.com/problems/valid-word) | | | +| 3142 | [Check if Grid Satisfies Conditions](https://leetcode.com/problems/check-if-grid-satisfies-conditions) | | | +| 3146 | [Permutation Difference between Two Strings](https://leetcode.com/problems/permutation-difference-between-two-strings) | | | +| 3151 | [Special Array I](https://leetcode.com/problems/special-array-i) | | | +| 3158 | [Find the XOR of Numbers Which Appear Twice](https://leetcode.com/problems/find-the-xor-of-numbers-which-appear-twice) | | | +| 3162 | [Find the Number of Good Pairs I](https://leetcode.com/problems/find-the-number-of-good-pairs-i) | | | +| 3168 | [Minimum Number of Chairs in a Waiting Room](https://leetcode.com/problems/minimum-number-of-chairs-in-a-waiting-room) | | | +| 3173 | [Bitwise OR of Adjacent Elements](https://leetcode.com/problems/bitwise-or-of-adjacent-elements) | | | +| 3174 | [Clear Digits](https://leetcode.com/problems/clear-digits) | | | +| 3178 | [Find the Child Who Has the Ball After K Seconds](https://leetcode.com/problems/find-the-child-who-has-the-ball-after-k-seconds) | | | +| 3184 | [Count Pairs That Form a Complete Day I](https://leetcode.com/problems/count-pairs-that-form-a-complete-day-i) | | | +| 3190 | [Find Minimum Operations to Make All Elements Divisible by Three](https://leetcode.com/problems/find-minimum-operations-to-make-all-elements-divisible-by-three) | | | +| 3194 | [Minimum Average of Smallest and Largest Elements](https://leetcode.com/problems/minimum-average-of-smallest-and-largest-elements) | | | +| 3199 | [Count Triplets With Even XOR Set Bits I](https://leetcode.com/problems/count-triplets-with-even-xor-set-bits-i) | | | +| 3200 | [Maximum Height of a Triangle](https://leetcode.com/problems/maximum-height-of-a-triangle) | | | diff --git a/README.txt b/README.txt deleted file mode 100644 index 13c2c65..0000000 --- a/README.txt +++ /dev/null @@ -1,850 +0,0 @@ -# LeetCode Algorithms - -![problems-solved](https://img.shields.io/badge/Problems%20Solved-682/2813-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-674/2813-1abc9c.svg) -![problems-solved-python](https://img.shields.io/badge/Python-205/2813-1abc9c.svg) -![problems-solved-javascript](https://img.shields.io/badge/JavaScript-4/2813-1abc9c.svg) -[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md) -[![cp](https://img.shields.io/badge/also%20see-Competitve%20Programming-1f72ff.svg)](https://github.com/anishLearnsToCode/competitive-programming) - -🔒 = Subscription Content - -## Problems -| # | Name | Solution | Youtube | -|:----:|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:---------------------------------------------------------------------------------------------------------------------------------:| -| 1 | [Two Sum](https://leetcode.com/problems/two-sum) | [![Java](assets/java.png)](src/TwoSum.java) [![Python](assets/python.png)](python/two_sum.py) | [![java-yt](assets/java-yt.png)](https://youtu.be/9wSL_7NN-A8) [![python-yt](assets/python-yt.png)](https://youtu.be/N5FXCTg0TDE) | -| 2 | [Add Two Numbers](https://leetcode.com/problems/add-two-numbers) | [![Java](assets/java.png)](src/AddTwoNumbers.java) [![js](assets/javascript.png)](javascript/AddTwoNumbers.js) | | -| 3 | [Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters) | [![Java](assets/java.png)](src/LongestSubstringWithoutRepeatingCharacters.java) | | -| 5 | [Longest Palindromic Substring](https://leetcode.com/problems/longest-palindromic-substring) | [![Java](assets/java.png)](src/LongestPalindromicSubstring.java) | | -| 6 | [Zigzag Conversion](https://leetcode.com/problems/zigzag-conversion) | [![Java](assets/java.png)](src/ZigZagConversion.java) | | -| 7 | [Reverse Integer](https://leetcode.com/problems/reverse-integer) | [![Java](assets/java.png)](src/ReverseInteger.java) [![Python](assets/python.png)](python/reverse_integer.py) [![js](assets/javascript.png)](javascript/ReverseInteger.js) | [![java-yt](assets/java-yt.png)](https://youtu.be/7bOhyl5lWjI) [![python-yt](assets/python-yt.png)](https://youtu.be/lmLG30TLcSg) | -| 8 | [String to Integer (atoi)](https://leetcode.com/problems/string-to-integer-atoi) | [![Java](assets/java.png)](src/StringToIntegerAtoi.java) | | -| 9 | [Palindrome Number](https://leetcode.com/problems/palindrome-number) | [![Java](assets/java.png)](src/PalindromeNumber.java) [![Python](assets/python.png)](python/palindrome_number.py) [![js](assets/javascript.png)](javascript/PalindromeNumber.js) | | -| 11 | [Container With Most Water](https://leetcode.com/problems/container-with-most-water) | [![Java](assets/java.png)](src/ContainerWitMostWater.java) | | -| 12 | [Integer to Roman](https://leetcode.com/problems/integer-to-roman) | [![Java](assets/java.png)](src/IntegerToRoman.java) | | -| 13 | [Roman To Integer](https://leetcode.com/problems/roman-to-integer/) | [![Java](assets/java.png)](src/RomanToInteger.java) [![Python](assets/python.png)](python/roman_to_integer.py) | [![java-yt](assets/java-yt.png)](https://youtu.be/BCue_mO_81A) [![python-yt](assets/python-yt.png)](https://youtu.be/8h_yGTNvKMA) | -| 14 | [Longest Common Prefix](https://leetcode.com/problems/longest-common-prefix/) | [![Java](assets/java.png)](src/LongestCommonPrefix.java) [![Python](assets/python.png)](python/longest_common_prefix.py) | | -| 15 | [3Sum](https://leetcode.com/problems/3sum) | [![Java](assets/java.png)](src/ThreeSum.java) | | -| 16 | [3Sum Closest](https://leetcode.com/problems/3sum-closest) | [![Java](assets/java.png)](src/ThreeSumClosest.java) | | -| 17 | [Letter Combinations of a Phone Number](https://leetcode.com/problems/letter-combinations-of-a-phone-number) | [![Java](assets/java.png)](src/LetterCombinationsOfAPhoneNumber.java) | | -| 18 | [4Sum](https://leetcode.com/problems/4sum) | [![Java](assets/java.png)](src/FourSum.java) | | -| 19 | [Remove Nth Node From End of List](https://leetcode.com/problems/remove-nth-node-from-end-of-list) | [![Java](assets/java.png)](src/RemoveNthNodeFromEndOfList.java) | | -| 20 | [ValidParentheses](https://leetcode.com/problems/valid-parentheses/) | [![Java](assets/java.png)](src/ValidParentheses.java) [![Python](assets/python.png)](python/valid_parentheses.py) | | -| 21 | [Merge 2 Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/) | [![Java](assets/java.png)](src/Merge2SortedLists.java) [![Python](assets/python.png)](python/merge_2_sorted_lists.py) | | -| 22 | [Generate Parentheses](https://leetcode.com/problems/generate-parentheses) | [![Java](assets/java.png)](src/GenerateParentheses.java) | | -| 24 | [Swap Nodes in Pairs](https://leetcode.com/problems/swap-nodes-in-pairs) | [![Java](assets/java.png)](src/SwapNodesInPairs.java) | | -| 26 | [Remove Duplicates From Sorted Array](https://leetcode.com/problems/remove-duplicates-from-sorted-array) | [![Java](assets/java.png)](src/RemoveDuplicatesFromSortedArray.java) [![Python](assets/python.png)](python/remove_duplicates_from_sorted_array.py) [![js](assets/javascript.png)](javascript/RemoveDuplicatesFromSortedArray.js) | | -| 27 | [Remove Element](https://leetcode.com/problems/remove-element/) | [![Java](assets/java.png)](src/RemoveElement.java) [![Python](assets/python.png)](python/remove_element.py) | | -| 28 | [Needle in Haystack](https://leetcode.com/problems/implement-strstr) | [![Java](assets/java.png)](src/NeedleInHaystack.java) [![Python](assets/python.png)](python/needle_in_haystack.py) | | -| 29 | [Divide Two Integers](https://leetcode.com/problems/divide-two-integers) | [![Java](assets/java.png)](src/DivideTwoIntegers.java) | | -| 31 | [Next Permutation](https://leetcode.com/problems/next-permutation) | [![Java](assets/java.png)](src/NextPermutation.java) | | -| 33 | [Search in Rotated Sorted Array](https://leetcode.com/problems/search-in-rotated-sorted-array) | [![Java](assets/java.png)](src/SearchInRotatedSortedArray.java) | | -| 34 | [Find First and Last Position of Element in Sorted Array](https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array) | [![Java](assets/java.png)](src/FindFirstAndLastPositionOfElementInSortedArray.java) | | -| 35 | [Search Inserted Position](https://leetcode.com/problems/search-insert-position/) | [![Java](assets/java.png)](src/SearchInsertPosition.java) [![Python](assets/python.png)](python/search_insert_position.py) | | -| 36 | [Valid Sudoku](https://leetcode.com/problems/valid-sudoku) | [![Java](assets/java.png)](src/ValidSudoku.java) | | -| 37 | [Sudoku Solver](https://leetcode.com/problems/sudoku-solver) | [![Java](assets/java.png)](src/SudokuSolver.java) | | -| 38 | [Count and Say](https://leetcode.com/problems/count-and-say) | [![Java](assets/java.png)](src/CountAndSay.java) [![Python](assets/python.png)](python/count_and_say.py) | | -| 39 | [Combination Sum](https://leetcode.com/problems/combination-sum) | [![Java](assets/java.png)](src/CombinationSum.java) | | -| 40 | [Combination Sum II](https://leetcode.com/problems/combination-sum-ii) | [![Java](assets/java.png)](src/CombinationSumII.java) | | -| 42 | [Trapping Rain Water](https://leetcode.com/problems/trapping-rain-water) | [![Java](assets/java.png)](src/TrappingRainwater.java) | | -| 43 | [Multiply Strings](https://leetcode.com/problems/multiply-strings) | [![Java](assets/java.png)](src/MultiplyStrings.java) | | -| 45 | [Jump Game II](https://leetcode.com/problems/jump-game-ii) | [![Java](assets/java.png)](src/JumpGameII.java) | | -| 46 | [Permutations](https://leetcode.com/problems/permutations) | [![Java](assets/java.png)](src/Permutations.java) | | -| 47 | [Permutations II](https://leetcode.com/problems/permutations-ii) | [![Java](assets/java.png)](src/PermutationsII.java) | | -| 48 | [Rotate Image](https://leetcode.com/problems/rotate-image) | [![Java](assets/java.png)](src/RotateImage.java) | | -| 49 | [Group Anagrams](https://leetcode.com/problems/group-anagrams) | [![Java](assets/java.png)](src/GroupAnagrams.java) | | -| 50 | [Pow(x,n)](https://leetcode.com/problems/powx-n) | [![Java](assets/java.png)](src/Powxn.java) | | -| 53 | [Maximum SubArray](https://leetcode.com/problems/maximum-subarray) | [![Java](assets/java.png)](src/MaximumSubArray.java) [![Python](assets/python.png)](python/maximum_sum_subarray.py) | | -| 54 | [Spiral Matrix](https://leetcode.com/problems/spiral-matrix) | [![Java](assets/java.png)](src/SpiralMatrix.java) | | -| 55 | [Jump Game](https://leetcode.com/problems/jump-game) | [![Java](assets/java.png)](src/JumpGame.java) | | -| 56 | [Merge Intervals](https://leetcode.com/problems/merge-intervals) | [![Java](assets/java.png)](src/MergeIntervals.java) | | -| 57 | [Insert Interval](https://leetcode.com/problems/insert-interval) | [![Java](assets/java.png)](src/InsertInterval.java) | | -| 58 | [Length of Last Word](https://leetcode.com/problems/length-of-last-word) | [![Java](assets/java.png)](src/LengthOfLastWord.java) [![Python](assets/python.png)](python/length_of_last_word.py) | | -| 59 | [Spiral Matrix II](https://leetcode.com/problems/spiral-matrix-ii) | [![Java](assets/java.png)](src/SpiralMatrixII.java) | | -| 61 | [Rotate List](https://leetcode.com/problems/rotate-list) | [![Java](assets/java.png)](src/RotateList.java) | | -| 62 | [Unique Paths](https://leetcode.com/problems/unique-paths) | [![Java](assets/java.png)](src/UniquePaths.java) | | -| 63 | [Unique Paths II](https://leetcode.com/problems/unique-paths-ii) | [![Java](assets/java.png)](src/UniquePathII.java) | | -| 64 | [Minimum Path Sum](https://leetcode.com/problems/minimum-path-sum) | [![Java](assets/java.png)](src/MinimumPathSum.java) [![Python](assets/python.png)](python/minimum_path_sum.py) | | -| 66 | [Plus One](https://leetcode.com/problems/plus-one) | [![Java](assets/java.png)](src/PlusOne.java) [![Python](assets/python.png)](python/plus_one.py) | | -| 67 | [Add Binary](https://leetcode.com/problems/add-binary) | [![Java](assets/java.png)](src/AddBinary.java) [![Python](assets/python.png)](python/add_binary.py) | | -| 69 | [Sqrt(x)](https://leetcode.com/problems/sqrtx) | [![Java](assets/java.png)](src/Sqrtx.java) [![Python](assets/python.png)](python/sqrt.py) | | -| 70 | [Climbing Stairs](https://leetcode.com/problems/climbing-stairs) | [![Java](assets/java.png)](src/ClimbingStairs.java) [![Python](assets/python.png)](python/climbing_stairs.py) | | -| 71 | [Simplify Path](https://leetcode.com/problems/simplify-path) | [![Java](assets/java.png)](src/SimplifyPath.java) | | -| 72 | [Edit Distance](https://leetcode.com/problems/edit-distance) | [![Java](assets/java.png)](src/EditDistance.java) | | -| 73 | [Set Matrix Zeroes](https://leetcode.com/problems/set-matrix-zeroes) | [![Java](assets/java.png)](src/SetMatrixZeroes.java) | | -| 74 | [Search a 2D Matrix](https://leetcode.com/problems/search-a-2d-matrix) | [![Java](assets/java.png)](src/SearchA2DMatrix.java) | | -| 75 | [Sort Colors](https://leetcode.com/problems/sort-colors) | [![Java](assets/java.png)](src/SortColors.java) | | -| 77 | [Combinations](https://leetcode.com/problems/combinations) | [![Java](assets/java.png)](src/Combinations.java) | | -| 78 | [Subsets](https://leetcode.com/problems/subsets) | [![Java](assets/java.png)](src/Subsets.java) | | -| 79 | [Word Search](https://leetcode.com/problems/word-search) | [![Java](assets/java.png)](src/WordSearch.java) | | -| 80 | [Remove Duplicates from Sorted Array II](https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii) | [![Java](assets/java.png)](src/RemoveDuplicatesFromSortedArrayII.java) | | -| 81 | [Search in Rotated Sorted Array II](https://leetcode.com/problems/search-in-rotated-sorted-array-ii) | [![Java](assets/java.png)](src/SearchInRotatedSortedArrayII.java) | | -| 82 | [Remove Duplicates from Sorted List II](https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii) | [![Java](assets/java.png)](src/RemoveDuplicatesFromSortedListII.java) | | -| 83 | [Remove Duplicates from Sorted List](https://leetcode.com/problems/remove-duplicates-from-sorted-list) | [![Java](assets/java.png)](src/RemoveDuplicatesFromSortedList.java) [![Python](assets/python.png)](python/remove_duplicates_from_linked_list.py) | | -| 86 | [Partition List](https://leetcode.com/problems/partition-list) | [![Java](assets/java.png)](src/PartitionList.java) | | -| 87 | [Scramble String](https://leetcode.com/problems/scramble-string) | [![Python](assets/python.png)](python/scramble_strings.py) | | -| 88 | [Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array) | [![Java](assets/java.png)](src/MergeSortedArray.java) [![Python](assets/python.png)](python/merge_sorted_array.py) | | -| 89 | [Gray Code](https://leetcode.com/problems/gray-code) | [![Java](assets/java.png)](src/GrayCode.java) | | -| 90 | [Subsets II](https://leetcode.com/problems/subsets-ii) | [![Java](assets/java.png)](src/SubsetsII.java) | | -| 91 | [Decode Ways](https://leetcode.com/problems/decode-ways) | [![Java](assets/java.png)](src/DecodeWays.java) | | -| 92 | [Reverse Linked List II](https://leetcode.com/problems/reverse-linked-list-ii) | [![Java](assets/java.png)](src/ReverseLinkedListII.java) | | -| 93 | [Restore IP Addresses](https://leetcode.com/problems/restore-ip-addresses) | [![Java](assets/java.png)](src/RestoreIPAddresses.java) | | -| 94 | [Binary Tree Inorder Traversal](https://leetcode.com/problems/binary-tree-inorder-traversal) | [![Java](assets/java.png)](src/BinaryTreeInorderTraversal.java) [![Python](assets/python.png)](python/binary_tree_inorder_traversal.py) | | -| 95 | [Unique Binary Search Trees II](https://leetcode.com/problems/unique-binary-search-trees-ii) | [![Java](assets/java.png)](src/UniqueBinarySearchTreesII.java) | | -| 96 | [Unique Binary Search Trees](https://leetcode.com/problems/unique-binary-search-trees) | [![Java](assets/java.png)](src/UniqueBinarySearchTrees.java) | | -| 97 | [Interleaving String](https://leetcode.com/problems/interleaving-string) | [![Java](assets/java.png)](src/InterleavingString.java) | | -| 98 | [Validate Binary Search Tree](https://leetcode.com/problems/validate-binary-search-tree) | [![Java](assets/java.png)](src/ValidateBinarySearchTree.java) | | -| 99 | [Recover Binary Search Tree](https://leetcode.com/problems/recover-binary-search-tree) | [![Java](assets/java.png)](src/RecoverBinarySearchTree.java) | | -| 100 | [Same Tree](https://leetcode.com/problems/same-tree) | [![Java](assets/java.png)](src/SameTree.java) [![Python](assets/python.png)](python/same_tree.py) | | -| 101 | [Symmetric Tree](https://leetcode.com/problems/symmetric-tree) | [![Java](assets/java.png)](src/SymmetricTree.java) [![Python](assets/python.png)](python/symmetric_tree.py) | | -| 102 | [Binary Tree Level Order Traversal](https://leetcode.com/problems/binary-tree-level-order-traversal) | [![Java](assets/java.png)](src/BinaryTreeLevelOrderTraversal.java) | | -| 103 | [Binary Tree Zigzag Level Order Traversal](https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal) | [![Java](assets/java.png)](src/BinaryTreeZigzagLevelOrderTraversal.java) | | -| 104 | [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree) | [![Java](assets/java.png)](src/MaximumDepthOfBinaryTree.java) [![Python](assets/python.png)](python/maximum_depth_of_binary_tree.py) | | -| 105 | [Construct Binary Tree from Preorder and Inorder Traversal](https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal) | [![Java](assets/java.png)](src/ConstructBinaryTreeFromPreorderAndInorderTraversal.java) | | -| 106 | [Construct Binary Tree from Inorder and Postorder Traversal](https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal) | [![Java](assets/java.png)](src/ConstructBinaryTreeFromInorderAndPostorderTraversal.java) | | -| 107 | [Binary Tree Level Order Traversal II](https://leetcode.com/problems/binary-tree-level-order-traversal-ii) | [![Java](assets/java.png)](src/BinaryTreeLevelOrderTraversalII.java) [![Python](assets/python.png)](python/binary_tree_level_order_traversal_ii.py) | | -| 108 | [Convert Sorted Array To Binary Search Tree](https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree) | [![Java](assets/java.png)](src/ConvertSortedArrayToBinarySearchTree.java) [![Python](assets/python.png)](python/converted_sorted_array_to_binary_search_tree.py) | | -| 109 | [Convert Sorted List to Binary Search Tree](https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree) | [![Java](assets/java.png)](src/ConvertSortedListToBinarySearchTree.java) | | -| 110 | [Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree) | [![Java](assets/java.png)](src/BalancedBinaryTree.java) [![Python](assets/python.png)](python/balanced_binary_tree.py) | | -| 111 | [Minimum Depth of Binary Tree](https://leetcode.com/problems/minimum-depth-of-binary-tree) | [![Java](assets/java.png)](src/MinimumDepthOfBinaryTree.java) [![Python](assets/python.png)](python/minimum_depth_of_binary_tree.py) | | -| 112 | [Path Sum](https://leetcode.com/problems/path-sum) | [![Java](assets/java.png)](src/PathSum.java) [![Python](assets/python.png)](python/path_sum.py) | | -| 113 | [Path Sum II](https://leetcode.com/problems/path-sum-ii) | [![Java](assets/java.png)](src/PathSumII.java) | | -| 114 | [Flatten Binary Tree to Linked List](https://leetcode.com/problems/flatten-binary-tree-to-linked-list) | [![Java](assets/java.png)](src/FlattenBinaryTreeToLinkedList.java) | | -| 116 | [Populating Next Right Pointers in Each Node](https://leetcode.com/problems/populating-next-right-pointers-in-each-node) | [![Java](assets/java.png)](src/PopulatingNextRightPointersInEachNode.java) | | -| 117 | [Populating Next Right Pointers in Each Node II](https://leetcode.com/problems/populating-next-right-pointers-in-each-node-ii) | [![Java](assets/java.png)](src/PopulatingNextRightPointersInEachNodeII.java) | | -| 118 | [Pascal's Triangle](https://leetcode.com/problems/pascals-triangle) | [![Java](assets/java.png)](src/PascalsTriangle.java) [![Python](assets/python.png)](python/pascals_triangle.py) | | -| 119 | [Pascal's Triangle II](https://leetcode.com/problems/pascals-triangle-ii) | [![Java](assets/java.png)](src/PascalsTriangleII.java) [![Python](assets/python.png)](python/pascals_triangle_ii.py) | | -| 120 | [Triangle](https://leetcode.com/problems/triangle) | [![Java](assets/java.png)](src/Triangle.java) | | -| 121 | [Best Time to Buy and Sell Stocks](https://leetcode.com/problems/best-time-to-buy-and-sell-stock) | [![Java](assets/java.png)](src/BestTimeToBuyAndSellStock.java) [![Python](assets/python.png)](python/best_time_to_buy_and_sell_stock.py) | | -| 122 | [Best Time to Buy and Sell Stocks II](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii) | [![Java](assets/java.png)](src/BestTimeToBuyAndSellStockII.java) [![Python](assets/python.png)](python/best_time_to_buy_and_sell_stock_ii.py) | | -| 125 | [Valid Palindrome](https://leetcode.com/problems/valid-palindrome) | [![Java](assets/java.png)](src/ValidPalindrome.java) [![Python](assets/python.png)](python/valid_palindrome.py) | | -| 128 | [Longest Consecutive Sequence](https://leetcode.com/problems/longest-consecutive-sequence) | [![Java](assets/java.png)](src/LongestConsecutiveSequence.java) | | -| 129 | [Sum Root to Leaf Numbers](https://leetcode.com/problems/sum-root-to-leaf-numbers) | [![Java](assets/java.png)](src/SumRootToLeafNumbers.java) | | -| 130 | [Surrounded Regions](https://leetcode.com/problems/surrounded-regions) | [![Java](assets/java.png)](src/SurroundedRegions.java) | | -| 131 | [Palindrome Partitioning](https://leetcode.com/problems/palindrome-partitioning) | [![Java](assets/java.png)](src/PalindromePartitioning.java) | | -| 133 | [Clone Graph](https://leetcode.com/problems/clone-graph) | [![Java](assets/java.png)](src/CloneGraph.java) [![Python](assets/python.png)](python/clone_graph.py) | | -| 134 | [Gas Station](https://leetcode.com/problems/gas-station) | [![Java](assets/java.png)](src/GasStation.java) | | -| 136 | [Single Number](https://leetcode.com/problems/single-number) | [![Java](assets/java.png)](src/SingleNumber.java) [![Python](assets/python.png)](python/single_number.py) | | -| 137 | [Single Number II](https://leetcode.com/problems/single-number-ii) | [![Java](assets/java.png)](src/SingleNumberII.java) | | -| 138 | [Copy List with Random Pointer](https://leetcode.com/problems/copy-list-with-random-pointer) | [![Java](assets/java.png)](src/CopyListWithRandomPointer.java) | | -| 139 | [Word Break](https://leetcode.com/problems/word-break) | [![Java](assets/java.png)](src/WordBreak.java) | | -| 141 | [Linked List Cycle](https://leetcode.com/problems/linked-list-cycle) | [![Java](assets/java.png)](src/LinkedListCycle.java) [![Python](assets/python.png)](python/linked_list_cycle.py) | | -| 142 | [Linked List Cycle II](https://leetcode.com/problems/linked-list-cycle-ii) | [![Java](assets/java.png)](src/LinkedListCycleII.java) | | -| 143 | [Reorder List](https://leetcode.com/problems/reorder-list) | [![Java](assets/java.png)](src/ReorderList.java) | | -| 144 | [Binary Tree Preorder Traversal](https://leetcode.com/problems/binary-tree-preorder-traversal) | [![Java](assets/java.png)](src/BinaryTreePreOrderTraversal.java) [![Python](assets/python.png)](python/binary_tree_preorder_traversal.py) | | -| 145 | [Binary Tree Postorder Traversal](https://leetcode.com/problems/binary-tree-postorder-traversal) | [![Java](assets/java.png)](src/BinaryTreePostorderTraversal.java) [![Python](assets/python.png)](python/binary_tree_postorder_traversal.py) | | -| 146 | [LRU Cache](https://leetcode.com/problems/lru-cache) | [![Java](assets/java.png)](src/LRUCache.java) | | -| 147 | [Insertion Sort List](https://leetcode.com/problems/insertion-sort-list) | [![Java](assets/java.png)](src/InsertionSortList.java) | | -| 148 | [Sort List](https://leetcode.com/problems/sort-list) | [![Java](assets/java.png)](src/SortList.java) | | -| 150 | [Evaluate Reverse Polish Notation](https://leetcode.com/problems/evaluate-reverse-polish-notation) | [![Java](assets/java.png)](src/EvaluateReversePolishNotation.java) | | -| 151 | [Reverse Words in a String](https://leetcode.com/problems/reverse-words-in-a-string) | [![Java](assets/java.png)](src/ReverseWordsInAString.java) | | -| 152 | [Maximum Product Subarray](https://leetcode.com/problems/maximum-product-subarray) | [![Java](assets/java.png)](src/MaximumProductSubarray.java) | | -| 153 | [Find Minimum in Rotated Sorted Array](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array) | [![Java](assets/java.png)](src/FindMinimumInRotatedSortedArray.java) | | -| 155 | [Min Stack](https://leetcode.com/problems/min-stack) | [![Java](assets/java.png)](src/MinStack.java) [![Python](assets/python.png)](python/min_stack.py) | | -| 156 | 🔒 [Binary Tree Upside Down](https://leetcode.com/problems/binary-tree-upside-down) | | | -| 157 | [Read N Characters Given Read4](https://leetcode.com/problems/read-n-characters-given-read4) | | | -| 159 | 🔒 [Longest Substring With At Most Two Distinct Characters](https://leetcode.com/problems/longest-substring-with-at-most-two-distinct-characters) | | | -| 160 | [Intersection of Two Linked Lists](https://leetcode.com/problems/intersection-of-two-linked-lists) | [![Java](assets/java.png)](src/IntersectionOf2LinkedLists.java) [![Python](assets/python.png)](python/intersecction_of_two_linked_lists.py) | | -| 161 | 🔒 [One Edit Distance](https://leetcode.com/problems/one-edit-distance) | | | -| 162 | [Find Peak Element](https://leetcode.com/problems/find-peak-element) | [![Java](assets/java.png)](src/FindPeakElement.java) | | -| 165 | [Compare Version Numbers](https://leetcode.com/problems/compare-version-numbers) | [![Java](assets/java.png)](src/CompareVersionNumbers.java) | | -| 166 | [Fraction to Recurring Decimal](https://leetcode.com/problems/fraction-to-recurring-decimal) | [![Java](assets/java.png)](src/FractionToRecurringDecimal.java) | | -| 167 | [Two Sum II - Input Array is Sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted) | [![Java](assets/java.png)](src/TwoSumIIInputArrayIsSorted.java) [![Python](assets/python.png)](python/two_sum_ii.py) | | -| 168 | [Excel Sheet Column Title](https://leetcode.com/problems/excel-sheet-column-title) | [![Java](assets/java.png)](src/ExcelSheetColumnTitle.java) [![Python](assets/python.png)](python/excel_sheet_column_title.py) | | -| 169 | [Majority Element](https://leetcode.com/problems/majority-element) | [![Java](assets/java.png)](src/MajorityElement.java) [![Python](assets/python.png)](python/majority_element.py) | | -| 170 | 🔒 [Two Sum III - Data Structure Design](https://leetcode.com/problems/two-sum-iii-data-structure-design) | | | -| 171 | [Excel Sheet Column Number](https://leetcode.com/problems/excel-sheet-column-number) | [![Java](assets/java.png)](src/ExcelSheetColumnNumber.java) [![Python](assets/python.png)](python/excel_sheet_column_number.py) | | -| 172 | [Factoring Trailing Zeroes](https://leetcode.com/problems/factorial-trailing-zeroes) | [![Java](assets/java.png)](src/FactorialTrailingZeros.java) [![Python](assets/python.png)](python/factorial_trailing_zeroes.py) | | -| 173 | [Binary Search Tree Iterator](https://leetcode.com/problems/binary-search-tree-iterator) | [![Java](assets/java.png)](src/BinarySearchTreeIterator.java) | | -| 179 | [Largest Number](https://leetcode.com/problems/largest-number) | [![Java](assets/java.png)](src/LargestNumber.java) | | -| 187 | [Repeated DNA Sequences](https://leetcode.com/problems/repeated-dna-sequences) | [![Java](assets/java.png)](src/RepeatedDNASequences.java) | | -| 189 | [Rotate Array](https://leetcode.com/problems/rotate-array) | [![Java](assets/java.png)](src/RotateArray.java) [![Python](assets/python.png)](python/rotate_array.py) | | -| 190 | [Reverse Bits](https://leetcode.com/problems/reverse-bits) | [![Java](assets/java.png)](src/ReverseBits.java) [![Python](assets/python.png)](python/reverse_bits.py) | | -| 191 | [Number of One Bits](https://leetcode.com/problems/number-of-1-bits) | [![Java](assets/java.png)](src/NumberOf1Bit.java) [![Python](assets/python.png)](python/number_of_1_bits.py) | | -| 198 | [House Robber](https://leetcode.com/problems/house-robber) | [![Java](assets/java.png)](src/HouseRobber.java) [![Python](assets/python.png)](python/house_robber.py) | | -| 199 | [Binary Tree Right Side View](https://leetcode.com/problems/binary-tree-right-side-view) | [![Java](assets/java.png)](src/BinaryTreeRightSideView.java) | | -| 200 | [Number of Islands](https://leetcode.com/problems/number-of-islands) | [![Java](assets/java.png)](src/NumberOfIslands.java) [![Python](assets/python.png)](python/number_of_islands.py) | | -| 201 | [Bitwise AND of Numbers Range](https://leetcode.com/problems/bitwise-and-of-numbers-range) | [![Java](assets/java.png)](src/BitwiseANDOfNumbersRange.java) | | -| 202 | [Happy Number](https://leetcode.com/problems/happy-number) | [![Java](assets/java.png)](src/HappyNumber.java) [![Python](assets/python.png)](python/happy_number.py) | | -| 203 | [Remove Linked List Elements](https://leetcode.com/problems/remove-linked-list-elements) | [![Java](assets/java.png)](src/RemoveLinkedListElements.java) [![Python](assets/python.png)](python/remove_linked_list_elements.py) | | -| 204 | [Count Primes](https://leetcode.com/problems/count-primes) | [![Java](assets/java.png)](src/CountPrimes.java) [![Python](assets/python.png)](python/count_primes.py) | | -| 205 | [Isomorphic Strings](https://leetcode.com/problems/isomorphic-strings) | [![Java](assets/java.png)](src/IsomorphicStrings.java) [![Python](assets/python.png)](python/isomorphic_strings.py) | | -| 206 | [Reverse Linked List](https://leetcode.com/problems/reverse-linked-list) | [![Java](assets/java.png)](src/ReverseLinkedList.java) [![Python](assets/python.png)](python/reverse_linked_list.py) | | -| 207 | [Course Schedule](https://leetcode.com/problems/course-schedule) | [![Java](assets/java.png)](src/CourseSchedule.java) | | -| 208 | [Implement Trie (Prefix Tree)](https://leetcode.com/problems/implement-trie-prefix-tree) | [![Java](assets/java.png)](src/Trie.java) [![Python](assets/python.png)](python/trie.py) | | -| 209 | [Minimum Size Subarray Sum](https://leetcode.com/problems/minimum-size-subarray-sum) | [![Java](assets/java.png)](src/MinimumSizeSubarraySum.java) | | -| 210 | [Course Schedule II](https://leetcode.com/problems/course-schedule-ii) | [![Java](assets/java.png)](src/CourseScheduleII.java) | | -| 211 | [Design Add and Search Words Data Structure](https://leetcode.com/problems/design-add-and-search-words-data-structure) | [![Java](assets/java.png)](src/DesignAddAndSearchWordsDataStructure.java) [![Python](assets/python.png)](python/design_add_and_search_words_data_structure.py) | | -| 213 | [House Robber II](https://leetcode.com/problems/house-robber-ii) | [![Java](assets/java.png)](src/HouseRobberII.java) | | -| 215 | [Kth Largest Element in an Array](https://leetcode.com/problems/kth-largest-element-in-an-array) | [![Java](assets/java.png)](src/KthLargestElementInAnArray.java) | | -| 216 | [Combination Sum III](https://leetcode.com/problems/combination-sum-iii) | [![Java](assets/java.png)](src/CombinationSumIII.java) | | -| 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate) | [![Java](assets/java.png)](src/ContainsDuplicate.java) [![Python](assets/python.png)](python/contains_duplicate.py) | | -| 218 | [The Skyline Problem](https://leetcode.com/problems/the-skyline-problem) | [![Python](assets/python.png)](python/the_skyline_problem.py) | | -| 219 | [Contains Duplicate II](https://leetcode.com/problems/contains-duplicate-ii) | [![Java](assets/java.png)](src/ContainsDuplicateII.java) [![Python](assets/python.png)](python/contains_duplicate_ii.py) | | -| 220 | [Contains Duplicate III](https://leetcode.com/problems/contains-duplicate-iii) | [![Java](assets/java.png)](src/ContainsDuplicateIII.java) | | -| 221 | [Maximal Square](https://leetcode.com/problems/maximal-square) | [![Java](assets/java.png)](src/MaximalSquare.java) | | -| 222 | [Count Complete Tree Nodes](https://leetcode.com/problems/count-complete-tree-nodes) | [![Java](assets/java.png)](src/CountCompleteTreeNodes.java) | | -| 223 | [Rectangle Area](https://leetcode.com/problems/rectangle-area) | [![Java](assets/java.png)](src/RectangleArea.java) | | -| 225 | [Implement Stack using Queues](https://leetcode.com/problems/implement-stack-using-queues) | [![Java](assets/java.png)](src/MyStack.java) [![Python](assets/python.png)](python/implement_stack_using_queues.py) | | -| 226 | [Invert Binary Tree](https://leetcode.com/problems/invert-binary-tree) | [![Java](assets/java.png)](src/InvertBinaryTree.java) [![Python](assets/python.png)](python/invert_binary_tree.py) | | -| 227 | [Basic Calculator II](https://leetcode.com/problems/basic-calculator-ii) | [![Java](assets/java.png)](src/BasicCalculatorII.java) | | -| 229 | [Majority Element II](https://leetcode.com/problems/majority-element-ii) | [![Java](assets/java.png)](src/MajorityElementII.java) | | -| 230 | [Kth Smallest Element in a BST](https://leetcode.com/problems/kth-smallest-element-in-a-bst) | [![Java](assets/java.png)](src/KthSmallestElementInABST.java) | | -| 231 | [Power of Two](https://leetcode.com/problems/power-of-two) | [![Java](assets/java.png)](src/PowerOf2.java) [![Python](assets/python.png)](python/is_power_of_2.py) | | -| 232 | [Implement Queue Using Stacks](https://leetcode.com/problems/implement-queue-using-stacks) | [![Java](assets/java.png)](src/MyQueue.java) [![Python](assets/python.png)](python/implement_queue_using_stacks.py) | | -| 234 | [Palindrome Linked Lists](https://leetcode.com/problems/palindrome-linked-list) | [![Java](assets/java.png)](src/PalindromeLinkedList.java) [![Python](assets/python.png)](python/palindrome_linked_list.py) | | -| 235 | [Lowest Common Ancestor of a Binary Search Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree) | [![Java](assets/java.png)](src/LowestCommonAncestorOfBinarySearchTree.java) [![Python](assets/python.png)](python/lowest_common_ancestor_of_bst.py) | | -| 236 | [Lowest Common Ancestor of a Binary Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree) | [![Java](assets/java.png)](src/LowestCommonAncestorOfBinaryTree.java) | | -| 237 | [Delete a Node In A Linked List](https://leetcode.com/problems/delete-node-in-a-linked-list) | [![Java](assets/java.png)](src/DeleteANodeInLinkedList.java) [![Python](assets/python.png)](python/delete_node_in_linked_list.py) | | -| 238 | [Product of Array Except Self](https://leetcode.com/problems/product-of-array-except-self) | [![Java](assets/java.png)](src/ProductOfArrayExceptItself.java) | | -| 240 | [Search a 2D Matrix II](https://leetcode.com/problems/search-a-2d-matrix-ii) | [![Java](assets/java.png)](src/SearchA2DMatrixII.java) | | -| 241 | [Different Ways to Add Parentheses](https://leetcode.com/problems/different-ways-to-add-parentheses) | | | -| 242 | [Valid Anagram](https://leetcode.com/problems/valid-anagram) | [![Java](assets/java.png)](src/ValidAnagram.java) [![Python](assets/python.png)](python/delete_node_in_linked_list.py) | | -| 243 | 🔒 [Shortest Word Distance](https://leetcode.com/problems/shortest-word-distance) | | | -| 244 | 🔒 [Shortest Word Distance II](https://leetcode.com/problems/shortest-word-distance-ii) | | | -| 245 | 🔒 [Shortest Word Distance III](https://leetcode.com/problems/shortest-word-distance-iii) | | | -| 246 | 🔒 [Strobogramatic Number](https://leetcode.com/problems/strobogrammatic-number) | | | -| 247 | 🔒 [Strobogramatic Number II](https://leetcode.com/problems/strobogrammatic-number-ii) | | | -| 249 | 🔒 [Group Shifted Strings](https://leetcode.com/problems/group-shifted-strings) | | | -| 250 | 🔒 [Count Univalue Subtrees](https://leetcode.com/problems/count-univalue-subtrees) | | | -| 251 | 🔒 [Flatten 2D Vector](https://leetcode.com/problems/flatten-2d-vector) | | | -| 252 | 🔒 [Meeting Rooms](https://leetcode.com/problems/meeting-rooms) | | | -| 253 | 🔒 [Meeting Rooms II](https://leetcode.com/problems/meeting-rooms-ii) | | | -| 254 | 🔒 [Factor Combinations](https://leetcode.com/problems/factor-combinations) | | | -| 255 | 🔒 [Verify Preorder Sequence In Binary Search Tree](https://leetcode.com/problems/verify-preorder-sequence-in-binary-search-tree) | | | -| 256 | 🔒 [Paint House](https://leetcode.com/problems/paint-house) | | | -| 257 | [Binary Tree Paths](https://leetcode.com/problems/binary-tree-paths) | [![Java](assets/java.png)](src/BinaryTreePaths.java) [![Python](assets/python.png)](python/binary_tree_paths.py) | | -| 258 | [Add Digits](https://leetcode.com/problems/add-digits) | [![Java](assets/java.png)](src/AddDigits.java) [![Python](assets/python.png)](python/add_digits.py) | | -| 259 | 🔒 [3Sum Smaller](https://leetcode.com/problems/3sum-smaller) | | | -| 260 | [Single Number III](https://leetcode.com/problems/single-number-iii) | [![Java](assets/java.png)](src/SingleNumberIII.java) | | -| 261 | 🔒 [Graph Valid Tree](https://leetcode.com/problems/graph-valid-tree) | | | -| 263 | [Ugly Number](https://leetcode.com/problems/ugly-number) | [![Java](assets/java.png)](src/UglyNumber.java) [![Python](assets/python.png)](python/ugly_number.py) | | -| 264 | [Ugly Number II](https://leetcode.com/problems/ugly-number-ii) | [![Java](assets/java.png)](src/UglyNumberII.java) | | -| 266 | 🔒 [Palindrome Permutation](https://leetcode.com/problems/palindrome-permutation) | | | -| 267 | 🔒 [Palindrome Permutation II](https://leetcode.com/problems/palindrome-permutation-ii) | | | -| 268 | [Missing Number](https://leetcode.com/problems/missing-number) | [![Java](assets/java.png)](src/MissingNumber.java) [![Python](assets/python.png)](python/missing_number.py) | | -| 270 | 🔒 [Closest Binary Search Tree Value](https://leetcode.com/problems/closest-binary-search-tree-value) | | | -| 271 | 🔒 [Encode and Decode Strings](https://leetcode.com/problems/encode-and-decode-strings) | | | -| 274 | [H-Index](https://leetcode.com/problems/h-index) | [![Java](assets/java.png)](src/HIndex.java) | | -| 275 | [H-Index II](https://leetcode.com/problems/h-index-ii) | [![Java](assets/java.png)](src/HIndexII.java) | | -| 276 | 🔒 [Paint Fence](https://leetcode.com/problems/paint-fence) | | | -| 277 | 🔒 [Find The Celebrity](https://leetcode.com/problems/find-the-celebrity) | | | -| 278 | [First Bad Version](https://leetcode.com/problems/first-bad-version) | [![Java](assets/java.png)](src/FirstBadVersion.java) [![Python](assets/python.png)](python/first_bad_version.py) | | -| 279 | [Perfect Squares](https://leetcode.com/problems/perfect-squares) | [![Java](assets/java.png)](src/PerfectSquares.java) | | -| 280 | 🔒 [Wiggle Sort](https://leetcode.com/problems/wiggle-sort) | | | -| 281 | 🔒 [Zigzag Iterator](https://leetcode.com/problems/zigzag-iterator) | | | -| 283 | [Move Zeroes](https://leetcode.com/problems/move-zeroes) | [![Java](assets/java.png)](src/MoveZeros.java) [![Python](assets/python.png)](python/move_zeroes.py) | | -| 284 | [Peeking Iterator](https://leetcode.com/problems/peeking-iterator) | [![Java](assets/java.png)](src/PeekingIterator.java) | | -| 285 | 🔒 [Inorder Successor in BST](https://leetcode.com/problems/inorder-successor-in-bst) | | | -| 286 | 🔒 [Walls and Gates](https://leetcode.com/problems/walls-and-gates) | | | -| 287 | [Find the Duplicate Number](https://leetcode.com/problems/find-the-duplicate-number) | [![Java](assets/java.png)](src/FindTheDuplicateNumber.java) | | -| 288 | 🔒 [Unique Word Abbreviation](https://leetcode.com/problems/unique-word-abbreviation) | | | -| 289 | [Game of Life](https://leetcode.com/problems/game-of-life) | | | -| 290 | [Word Pattern](https://leetcode.com/problems/word-pattern) | [![Java](assets/java.png)](src/WordPattern.java) [![Python](assets/python.png)](python/word_pattern.py) | | -| 291 | 🔒 [Word Pattern II](https://leetcode.com/problems/word-pattern-ii) | | | -| 292 | [Nim Game](https://leetcode.com/problems/nim-game) | [![Java](assets/java.png)](src/NimGame.java) [![Python](assets/python.png)](python/nim_game.py) | | -| 293 | 🔒 [Flip Game](https://leetcode.com/problems/flip-game) | | | -| 294 | 🔒 [Flip Game II](https://leetcode.com/problems/flip-game-ii) | | | -| 298 | 🔒 [Binary Tree Longest Consecutive Sequence](https://leetcode.com/problems/binary-tree-longest-consecutive-sequence) | | | -| 299 | [Bulls and Cows](https://leetcode.com/problems/bulls-and-cows) | [![Java](assets/java.png)](src/BullsAndCows.java) [![Python](assets/python.png)](python/bulls_and_cows.py) | | -| 300 | [Longest Increasing Subsequence](https://leetcode.com/problems/longest-increasing-subsequence) | [![Java](assets/java.png)](src/LongestIncreasingSubsequence.java) | | -| 303 | [Range Sum Query - Immutable](https://leetcode.com/problems/range-sum-query-immutable) | [![Java](assets/java.png)](src/RangeSumQueryImmutable.java) [![Python](assets/python.png)](python/range_sum_query_immutable.py) | | -| 304 | [Range Sum Query 2D - Immutable](https://leetcode.com/problems/range-sum-query-2d-immutable) | | | -| 306 | [Additive Number](https://leetcode.com/problems/additive-number) | | | -| 307 | [Range Sum Query - Mutable](https://leetcode.com/problems/range-sum-query-mutable) | | | -| 309 | [Best Time to Buy and Sell Stock with Cooldown](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown) | | | -| 310 | [Minimum Height Trees](https://leetcode.com/problems/minimum-height-trees) | | | -| 311 | 🔒 [Sparse Matrix Multiplication](https://leetcode.com/problems/sparse-matrix-multiplication) | | | -| 313 | [Super Ugly Number](https://leetcode.com/problems/super-ugly-number) | | | -| 314 | 🔒 [Binary Tree Vertical Order Traversal](https://leetcode.com/problems/binary-tree-vertical-order-traversal) | | | -| 316 | [Remove Duplicate Letters](https://leetcode.com/problems/remove-duplicate-letters) | | | -| 318 | [Maximum Product of Word Lengths](https://leetcode.com/problems/maximum-product-of-word-lengths) | | | -| 319 | [Bulb Switcher](https://leetcode.com/problems/bulb-switcher) | | | -| 320 | 🔒 [Generalized Abbreviation](https://leetcode.com/problems/generalized-abbreviation) | | | -| 322 | [Coin Change](https://leetcode.com/problems/coin-change) | | | -| 323 | 🔒 [Number of Connected Components in Undirected Graph](https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph) | | | -| 324 | [Wiggle Sort II](https://leetcode.com/problems/wiggle-sort-ii) | | | -| 325 | 🔒 [Maximum Size Subarray Sum Equals K](https://leetcode.com/problems/maximum-size-subarray-sum-equals-k) | | | -| 326 | [Power of Three](https://leetcode.com/problems/power-of-three) | [![Java](assets/java.png)](src/PowerOfThree.java) [![Python](assets/python.png)](python/power_of_three.py) | | -| 328 | [Odd Even Linked List](https://leetcode.com/problems/odd-even-linked-list) | | | -| 331 | [Verify Preorder Serialization of a Binary Tree](https://leetcode.com/problems/verify-preorder-serialization-of-a-binary-tree) | | | -| 331 | 🔒 [Largest BST Subtree](https://leetcode.com/problems/largest-bst-subtree) | | | -| 334 | [Increasing Triplet Subsequence](https://leetcode.com/problems/increasing-triplet-subsequence) | | | -| 337 | [House Robber III](https://leetcode.com/problems/increasing-triplet-subsequence) | | | -| 338 | [Counting Bits](https://leetcode.com/problems/counting-bits/) | [![Java](assets/java.png)](src/CountingBits.java) [![Python](assets/python.png)](python/counting_bits.py) | | -| 339 | 🔒 [Nested List Weight Sum](https://leetcode.com/problems/nested-list-weight-sum) | | | -| 340 | 🔒 [Longest Substring with At Most K Distinct Characters](https://leetcode.com/problems/longest-substring-with-at-most-k-distinct-characters) | | | -| 341 | [Flatten Nested List Iterator](https://leetcode.com/problems/flatten-nested-list-iterator) | | | -| 342 | [Power of Four](https://leetcode.com/problems/power-of-four) | [![Java](assets/java.png)](src/PowerOf4.java) [![Python](assets/python.png)](python/power_of_four.py) | | -| 343 | [Integer Break](https://leetcode.com/problems/integer-break) | | | -| 344 | [Reverse A String](https://leetcode.com/problems/reverse-string) | [![Java](assets/java.png)](src/ReverseString.java) [![Python](assets/python.png)](python/reverse_a_string.py) | | -| 345 | [Reverse Vowels of A String](https://leetcode.com/problems/reverse-vowels-of-a-string) | [![Java](assets/java.png)](src/ReverseVowelsOfString.java) [![Python](assets/python.png)](python/reverse_vowels_of_a_string.py) | | -| 346 | 🔒 [Moving Average From Data Stream](https://leetcode.com/problems/moving-average-from-data-stream) | | | -| 347 | [Top K frequent Elements](https://leetcode.com/problems/top-k-frequent-elements) | | | -| 348 | 🔒 [Design Tic-Tac-Toe](https://leetcode.com/problems/design-tic-tac-toe) | | | -| 349 | [Intersection of 2 Arrays](https://leetcode.com/problems/intersection-of-two-arrays) | [![Java](assets/java.png)](src/IntersectionOfTwoArrays.java) [![Python](assets/python.png)](python/intersection_of_2_array.py) | | -| 350 | [Intersection of 2 Arrays II](https://leetcode.com/problems/intersection-of-two-arrays-ii) | [![Java](assets/java.png)](src/IntersectionOfTwoArraysII.java) [![Python](assets/python.png)](python/intersection_of_2_arrays_II.py) | | -| 351 | 🔒 [Android Unlock Patterns](https://leetcode.com/problems/android-unlock-patterns) | | | -| 355 | [Design Twitter](https://leetcode.com/problems/design-twitter) | | | -| 357 | [Count Numbers with Unique Digits](https://leetcode.com/problems/count-numbers-with-unique-digits) | | | -| 359 | 🔒 [Logger Rate Limiter](https://leetcode.com/problems/logger-rate-limiter) | | | -| 367 | [Valid Perfect Square](https://leetcode.com/problems/valid-perfect-square) | [![Java](assets/java.png)](src/IsPerfectSquare.java) [![Python](assets/python.png)](python/valid_perfect_square.py) | | -| 374 | [Guess Number Higher or Lower](https://leetcode.com/problems/guess-number-higher-or-lower) | [![Java](assets/java.png)](src/GuessNumberHigherOrLower.java) [![Python](assets/python.png)](python/guess_number_higher_or_lower.py) | | -| 383 | [Ransom Note](https://leetcode.com/problems/ransom-note) | [![Java](assets/java.png)](src/RansomNote.java) [![Python](assets/python.png)](python/ransom_note.py) | | -| 387 | [First Unique Character in String](https://leetcode.com/problems/first-unique-character-in-a-string) | [![Java](assets/java.png)](src/FirstUniqueCharacter.java) [![Python](assets/python.png)](python/first_unique_character_in_string.py) | | -| 389 | [Find the Difference](https://leetcode.com/problems/find-the-difference) | [![Java](assets/java.png)](src/FindTheDifference.java) [![Python](assets/python.png)](python/find_the_difference.py) | | -| 392 | [Is Subsequence](https://leetcode.com/problems/is-subsequence) | [![Java](assets/java.png)](src/IsSubsequence.java) [![Python](assets/python.png)](python/is_subsequence.py) | | -| 401 | [Binary Watch](https://leetcode.com/problems/binary-watch) | [![Java](assets/java.png)](src/BinaryWatch.java) [![Python](assets/python.png)](python/binary_watch.py) | | -| 404 | [Sum of Left Leaves](https://leetcode.com/problems/sum-of-left-leaves) | [![Java](assets/java.png)](src/SumOfLeftLeaves.java) [![Python](assets/python.png)](python/sum_of_left_leaves.py) | | -| 405 | [Convert a Number to Hexadecimal](https://leetcode.com/problems/convert-a-number-to-hexadecimal) | [![Java](assets/java.png)](src/ConvertNumberToHexadecimal.java) [![Python](assets/python.png)](python/convert_a_number_to_hexadecimal.py) | | -| 408 | 🔒 [Valid Word Abbreviation](https://leetcode.com/problems/valid-word-abbreviation) | | | -| 409 | [Longest Palindrome](https://leetcode.com/problems/longest-palindrome) | [![Java](assets/java.png)](src/LongestPalindrome.java) [![Python](assets/python.png)](python/longest_palindrome.py) | | -| 412 | [Fizz Buzz](https://leetcode.com/problems/fizz-buzz) | [![Java](assets/java.png)](src/FizzBuzz.java) [![Python](assets/python.png)](python/fizz_buzz.py) | | -| 414 | [Third Maximum Number](https://leetcode.com/problems/third-maximum-number) | [![Java](assets/java.png)](src/ThirdMaximumNumber.java) [![Python](assets/python.png)](python/fizz_buzz.py) | | -| 415 | [Add Strings](https://leetcode.com/problems/add-strings) | [![Java](assets/java.png)](src/AddString.java) [![Python](assets/python.png)](python/add_strings.py) | | -| 422 | 🔒 [Valid Word Square](https://leetcode.com/problems/valid-word-square) | | | -| 430 | [Flatten a Multilevel Doubly Linked List](https://leetcode.com/problems/flatten-a-multilevel-doubly-linked-list) | [![Java](assets/java.png)](src/FlattenAMultiLevelDoublyLinkedList.java) | | -| 434 | [Number of Segments in a String](https://leetcode.com/problems/number-of-segments-in-a-string) | [![Java](assets/java.png)](src/NumberOfSegmentsInString.java) [![Python](assets/python.png)](python/number_of_segments_in_a_string.py) | | -| 441 | [Arranging Coins](https://leetcode.com/problems/arranging-coins) | [![Java](assets/java.png)](src/ArrangingCoins.java) [![Python](assets/python.png)](python/arranging_coins.py) | | -| 443 | [String Compression](https://leetcode.com/problems/string-compression) | [![Java](assets/java.png)](src/StringCompression.java) [![Python](assets/python.png)](python/string_compression.py) | | -| 447 | [Number of Boomerangs](https://leetcode.com/problems/number-of-boomerangs) | [![Java](assets/java.png)](src/NumberOfBoomerangs.java) [![Python](assets/python.png)](python/number_of_boomerangs.py) | | -| 448 | [Find All Numbers Disappeared in an Array](https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array) | [![Java](assets/java.png)](src/FindAllNumbersDisappearedInAnArray.java) [![Python](assets/python.png)](python/find_all_numbers_disappeared_in_an_array.py) | | -| 453 | [Minimum Moves to Equal Array Elements](https://leetcode.com/problems/minimum-moves-to-equal-array-elements) | [![Java](assets/java.png)](src/MinimumMovesToEqualArrayElements.java) [![Python](assets/python.png)](python/minimum_moves_to_equal_array_element.py) | | -| 455 | [Assign Cookies](https://leetcode.com/problems/assign-cookies) | [![Java](assets/java.png)](src/AssignCookies.java) [![Python](assets/python.png)](python/assign_cookies.py) | | -| 459 | [Repeated Substring Pattern](https://leetcode.com/problems/repeated-substring-pattern) | [![Java](assets/java.png)](src/RepeatedSubstringPattern.java) [![Python](assets/python.png)](python/repeated_substring_pattern.py) | | -| 461 | [Hamming Distance](https://leetcode.com/problems/hamming-distance) | [![Java](assets/java.png)](src/HammingDistance.java) [![Python](assets/python.png)](python/hamming_distance.py) | | -| 463 | [Island Perimeter](https://leetcode.com/problems/island-perimeter) | [![Java](assets/java.png)](src/IslandPerimeter.java) [![Python](assets/python.png)](python/island_perimeter.py) | | -| 475 | [Heaters](https://leetcode.com/problems/heaters) | [![Java](assets/java.png)](src/Heaters.java) [![Python](assets/python.png)](python/heaters.py) | | -| 476 | [Number Complement](https://leetcode.com/problems/number-complement) | [![Java](assets/java.png)](src/NumberComplement.java) [![Python](assets/python.png)](python/number_complement.py) | | -| 482 | [License Key Formatting](https://leetcode.com/problems/license-key-formatting) | [![Java](assets/java.png)](src/LicenseKeyFormatting.java) [![Python](assets/python.png)](python/license_key_formatting.py) | | -| 485 | [Max Consecutive Ones](https://leetcode.com/problems/max-consecutive-ones) | [![Java](assets/java.png)](src/MaxConsecutiveOnes.java) [![Python](assets/python.png)](python/max_consecutive_ones.py) | | -| 492 | [Construct the Rectangle](https://leetcode.com/problems/construct-the-rectangle) | [![Java](assets/java.png)](src/ConstructTheRectangle.java) [![Python](assets/python.png)](python/construct_the_rectangle.py) | | -| 495 | [Teemo Attacking](https://leetcode.com/problems/teemo-attacking/) | [![Java](assets/java.png)](src/TeemoAttacking.java) [![Python](assets/python.png)](python/teemo_attacking.py) | | -| 496 | [Next Greater Element I](https://leetcode.com/problems/next-greater-element-i) | [![Java](assets/java.png)](src/NextGreaterElementI.java) [![Python](assets/python.png)](python/next_greater_element_i.py) | | -| 500 | [Keyboard Row](https://leetcode.com/problems/keyboard-row) | [![Java](assets/java.png)](src/KeyBoardRow.java) [![Python](assets/python.png)](python/keyboard_row.py) | | -| 501 | [Find Mode in Binary Search Tree](https://leetcode.com/problems/find-mode-in-binary-search-tree) | [![Java](assets/java.png)](src/FindModeInBinarySearchTree.java) [![Python](assets/python.png)](python/find_mode_in_binary_search_tree.py) | | -| 504 | [Base 7](https://leetcode.com/problems/base-7) | [![Java](assets/java.png)](src/Base7.java) [![Python](assets/python.png)](python/base_7.py) | | -| 506 | [Relative Ranks](https://leetcode.com/problems/relative-ranks) | [![Java](assets/java.png)](src/RelativeRanks.java) [![Python](assets/python.png)](python/relative_ranks.py) | | -| 507 | [Perfect Number](https://leetcode.com/problems/perfect-number) | [![Java](assets/java.png)](src/CheckPerfectNumber.java) [![Python](assets/python.png)](python/check_perfect_number.py) | | -| 509 | [Fibonacci Number](https://leetcode.com/problems/fibonacci-number) | [![Java](assets/java.png)](src/FibonacciNumber.java) [![Python](assets/python.png)](python/fibonacci_number.py) | | -| 520 | [Detect Capital](https://leetcode.com/problems/detect-capital) | [![Java](assets/java.png)](src/DetectCapital.java) [![Python](assets/python.png)](python/detect_capital.py) | | -| 521 | [Longest Uncommon Subsequence I](https://leetcode.com/problems/longest-uncommon-subsequence-i) | [![Java](assets/java.png)](src/LongestUncommonSubsequenceI.java) [![Python](assets/python.png)](python/longest_uncommon_subsequence_I.py) | | -| 530 | [Minimum Absolute Difference in BST](https://leetcode.com/problems/minimum-absolute-difference-in-bst) | [![Java](assets/java.png)](src/MinimumAbsoluteDifferenceInBST.java) [![Python](assets/python.png)](python/minimum_absolute_difference_in_bst.py) | | -| 532 | [K - Diff Pairs in Array](https://leetcode.com/problems/k-diff-pairs-in-an-array) | [![Java](assets/java.png)](src/KDiffPairsInAnArray.java) [![Python](assets/python.png)](python/k_dif_pairs_in_an_array.py) | | -| 538 | [Convert BST to Greater Tree](https://leetcode.com/problems/convert-bst-to-greater-tree) | [![Java](assets/java.png)](src/ConvertBSTToGreaterTree.java) [![Python](assets/python.png)](python/convert_bst_to_greater_tree.py) | | -| 541 | [Reverse String II](https://leetcode.com/problems/reverse-string-ii) | [![Java](assets/java.png)](src/ReverseStringII.java) [![Python](assets/python.png)](python/reverse_string_ii.py) | | -| 543 | [Diameter of Binary Tree](https://leetcode.com/problems/diameter-of-binary-tree) | [![Java](assets/java.png)](src/DiameterOfBinaryTree.java) [![Python](assets/python.png)](python/diameter_of_binary_tree.py) | | -| 551 | [Student Attendance Record I](https://leetcode.com/problems/student-attendance-record-i) | [![Java](assets/java.png)](src/StudentAttendanceRecordI.java) [![Python](assets/python.png)](python/student_attendance_record_I.py) | | -| 557 | [Reverse Words in a String III](https://leetcode.com/problems/reverse-words-in-a-string-iii) | [![Java](assets/java.png)](src/ReverseWordsInStringIII.java) [![Python](assets/python.png)](python/reverse_words_in_string_iii.py) | | -| 559 | [Maximum Depth of N-Ary Tree](https://leetcode.com/problems/maximum-depth-of-n-ary-tree) | [![Java](assets/java.png)](src/MaximumDepthOfNAryTree.java) [![Python](assets/python.png)](python/maximum_depth_of_n_ary_tree.py) | | -| 561 | [Array Partition I](https://leetcode.com/problems/array-partition-i) | [![Java](assets/java.png)](src/ArrayPartitionI.java) [![Python](assets/python.png)](python/array_partiton_I.py) | | -| 563 | [Binary Tree Tilt](https://leetcode.com/problems/binary-tree-tilt) | [![Java](assets/java.png)](src/BinaryTreeTilt.java) [![Python](assets/python.png)](python/binary_tree_tilt.py) | | -| 566 | [Reshape The Matrix](https://leetcode.com/problems/reshape-the-matrix) | [![Java](assets/java.png)](src/ReshapeTheMatrix.java) [![Python](assets/python.png)](python/reshape_the_matrix.py) | | -| 572 | [Subtree of Another Tree](https://leetcode.com/problems/subtree-of-another-tree) | [![Java](assets/java.png)](src/SubtreeOfAnotherTree.java) [![Python](assets/python.png)](python/subtree_of_another_tree.py) | | -| 575 | [Distribute Candies](https://leetcode.com/problems/distribute-candies) | [![Java](assets/java.png)](src/DistributeCandies.java) [![Python](assets/python.png)](python/distribute_candies.py) | | -| 581 | [Shortest Unsorted Continuous Subarray](https://leetcode.com/problems/shortest-unsorted-continuous-subarray) | [![Java](assets/java.png)](src/ShortestUnsortedContinuousSubarray.java) [![Python](assets/python.png)](python/shortest_continuous_unsorted_subarray.py) | | -| 589 | [N-Ary Tree Preorder Traversal](https://leetcode.com/problems/n-ary-tree-preorder-traversal) | [![Java](assets/java.png)](src/NArayTreePreOrderTraversal.java) [![Python](assets/python.png)](python/n_ary_tree_preorder_traversal.py) | | -| 590 | [N-Ary Tree Postorder Traversal](https://leetcode.com/problems/n-ary-tree-postorder-traversal) | [![Java](assets/java.png)](src/NAryTreePostorderTraversal.java) [![Python](assets/python.png)](python/n_ary_tree_postorder_traversal.py) | | -| 594 | [Longest Harmonious Subsequence](https://leetcode.com/problems/longest-harmonious-subsequence) | [![Java](assets/java.png)](src/LongestHarmoniousSubsequence.java) [![Python](assets/python.png)](python/longest_harmonious_subequence.py) | | -| 598 | [Range Addition II](https://leetcode.com/problems/range-addition-ii) | [![Java](assets/java.png)](src/RangeAdditionII.java) [![Python](assets/python.png)](python/range_addition_ii.py) | | -| 599 | [Minimum Index Sum of 2 Lists](https://leetcode.com/problems/minimum-index-sum-of-two-lists) | [![Java](assets/java.png)](src/MinimumIndexSumOfTwoLists.java) [![Python](assets/python.png)](python/minimum_index_sum_of_two_lists.py) | | -| 604 | 🔒 [Design Compressed String Iterator](https://leetcode.com/problems/design-compressed-string-iterator) | | | -| 605 | [Can Place Flowers](https://leetcode.com/problems/can-place-flowers) | [![Java](assets/java.png)](src/CanPlaceFlowers.java) [![Python](assets/python.png)](python/can_place_flowers.py) | | -| 606 | [Construct String from Binary Tree](https://leetcode.com/problems/construct-string-from-binary-tree) | [![Java](assets/java.png)](src/ConstructStringFromBinaryTree.java) [![Python](assets/python.png)](python/construct_string_from_binary_tree.py) | | -| 617 | [Merge Two Binary Trees](https://leetcode.com/problems/merge-two-binary-trees) | [![Java](assets/java.png)](src/MergeTwoBinaryTrees.java) [![Python](assets/python.png)](python/merge_two_binary_trees.py) | | -| 624 | 🔒 [Maximum Distance in Arrays](https://leetcode.com/problems/maximum-distance-in-arrays) | | | -| 628 | [Maximum Product of Three Numbers](https://leetcode.com/problems/maximum-product-of-three-numbers) | [![Java](assets/java.png)](src/MaximumProductOfThreeNumbers.java) [![Python](assets/python.png)](python/maximum_product_of_three_numbers.py) | | -| 633 | [Sum Square Numbers](https://leetcode.com/problems/sum-of-square-numbers) | [![Java](assets/java.png)](src/SumOfSquareNumbers.java) [![Python](assets/python.png)](python/sum_of_squares_numbers.py) | | -| 637 | [Average of Levels in Binary Tree](https://leetcode.com/problems/average-of-levels-in-binary-tree) | [![Java](assets/java.png)](src/AverageLevelsOfBinaryTree.java) [![Python](assets/python.png)](python/average_levels_of_binary_tree.py) | | -| 643 | [Maximum Average SubArray I](https://leetcode.com/problems/maximum-average-subarray-i) | [![Java](assets/java.png)](src/MaximumAverageSubArrayI.java) [![Python](assets/python.png)](python/maximum_average_subarray_I.py) | | -| 645 | [Set Mismatch](https://leetcode.com/problems/set-mismatch) | [![Java](assets/java.png)](src/SetMismatch.java) [![Python](assets/python.png)](python/set_mismatch.py) | | -| 653 | [Two Sum IV - Input is a BST](https://leetcode.com/problems/two-sum-iv-input-is-a-bst) | [![Java](assets/java.png)](src/TwoSumIVInputIsABST.java) [![Python](assets/python.png)](python/two_sum_iv.py) | | -| 657 | [Robot Return to Origin](https://leetcode.com/problems/robot-return-to-origin) | [![Java](assets/java.png)](src/RobotReturnToOrigin.java) [![Python](assets/python.png)](python/robot_return_to_origin.py) | | -| 661 | [Image Smoother](https://leetcode.com/problems/image-smoother) | [![Java](assets/java.png)](src/ImageSmoother.java) [![Python](assets/python.png)](python/image_smoother.py) | | -| 665 | [Non Deceasing Array](https://leetcode.com/problems/non-decreasing-array) | [![Java](assets/java.png)](src/NonDecreasingArray.java) [![Python](assets/python.png)](python/non_decreasing_array.py) | | -| 669 | [Trim a Binary Search Tree](https://leetcode.com/problems/trim-a-binary-search-tree) | [![Java](assets/java.png)](src/TrimABinarySearchTree.java) [![Python](assets/python.png)](python/trim_a_binary_search_tree.py) | | -| 671 | [Second Minimum Node in Binary Tree](https://leetcode.com/problems/second-minimum-node-in-a-binary-tree) | [![Java](assets/java.png)](src/SecondMinimumNodeInBinaryTree.java) [![Python](assets/python.png)](python/second_minimum_node_in_binary_tree.py) | | -| 674 | [Longest Continuous Increasing Subsequence](https://leetcode.com/problems/longest-continuous-increasing-subsequence) | [![Java](assets/java.png)](src/LongestContinuousIncreasingSubsequence.java) [![Python](assets/python.png)](python/longest_continuous_increasing_subsequence.py) | | -| 680 | [Valid Palindrome II](https://leetcode.com/problems/valid-palindrome-ii) | [![Java](assets/java.png)](src/ValidPalindromeII.java) [![Python](assets/python.png)](python/valid_pallindrome_ii.py) | | -| 682 | [Baseball Game](https://leetcode.com/problems/baseball-game) | [![Java](assets/java.png)](src/BaseballGame.java) [![Python](assets/python.png)](python/baseball_game.py) | | -| 686 | [Repeated String Match](https://leetcode.com/problems/repeated-string-match) | | | -| 687 | [Longest Univalue Path](https://leetcode.com/problems/longest-univalue-path) | | | -| 688 | [Knight Probability in Chessboard](https://leetcode.com/problems/knight-probability-in-chessboard) | [![Java](assets/java.png)](src/KnightProbabilityInChessboard.java) | | -| 690 | [Employee Importance](https://leetcode.com/problems/employee-importance) | | | -| 693 | [Binary Number with Alternating Bits](https://leetcode.com/problems/binary-number-with-alternating-bits) | [![Java](assets/java.png)](src/BinaryNumberWithAlternatingBits.java) [![Python](assets/python.png)](python/binary_number_with_alternating_bits.py) | | -| 696 | [Count Binary Substrings](https://leetcode.com/problems/count-binary-substrings) | [![Java](assets/java.png)](src/CountBinarySubstrings.java) [![Python](assets/python.png)](python/count_binary_substrings.py) | | -| 697 | [Degree of an Array](https://leetcode.com/problems/degree-of-an-array) | [![Java](assets/java.png)](src/DegreeOfAnArray.java) [![Python](assets/python.png)](python/degree_of_an_array.py) | | -| 700 | [Search in a Binary Search Tree](https://leetcode.com/problems/search-in-a-binary-search-tree) | [![Java](assets/java.png)](src/SearchInBinarySearchTree.java) [![Python](assets/python.png)](python/search_in_binary_search_tree.py) | | -| 703 | [Kth Largest Element in a Stream](https://leetcode.com/problems/kth-largest-element-in-a-stream) | [![Java](assets/java.png)](src/KthLargestElementInAStream.java) [![Python](assets/python.png)](python/k_th_largest_element_in_a_stream.py) | | -| 704 | [Binary Search](https://leetcode.com/problems/binary-search) | [![Java](assets/java.png)](src/BinarySearch.java) [![Python](assets/python.png)](python/binary_search.py) | | -| 705 | [Design HashSet](https://leetcode.com/problems/design-hashset) | [![Java](assets/java.png)](src/DesignHashSet.java) [![Python](assets/python.png)](python/design_hash_set.py) | | -| 706 | [Design HashMap](https://leetcode.com/problems/design-hashmap) | [![Java](assets/java.png)](src/DesignHashMap.java) [![Python](assets/python.png)](python/design_hash_map.py) | | -| 709 | [To Lower Case](https://leetcode.com/problems/to-lower-case) | [![Java](assets/java.png)](src/ToLowerCase.java) [![Python](assets/python.png)](python/to_lower_case.py) | | -| 716 | 🔒 [Max Stack](https://leetcode.com/problems/max-stack) | | | -| 717 | [1-bit and 2-bit Characters](https://leetcode.com/problems/1-bit-and-2-bit-characters) | [![Java](assets/java.png)](src/OneBitAndTwoBitCharacters.java) [![Python](assets/python.png)](python/one_bit_and_two_bit_characters.py) | | -| 718 | [Maximum Length of Repeated Subarray](https://leetcode.com/problems/maximum-length-of-repeated-subarray) | [![Java](assets/java.png)](src/MaximumLengthOfRepeatedSubArray.java) | | -| 720 | [Longest Word in Dictionary](https://leetcode.com/problems/longest-word-in-dictionary) | | | -| 724 | [Find Pivot Index](https://leetcode.com/problems/find-pivot-index) | [![Java](assets/java.png)](src/FindPivotIndex.java) [![Python](assets/python.png)](python/find_pivot_index.py) | | -| 728 | [Self Dividing Numbers](https://leetcode.com/problems/self-dividing-numbers) | [![Java](assets/java.png)](src/SelfDividingNumbers.java) [![Python](assets/python.png)](python/self_dividing_number.py) | | -| 733 | [Flood Fill](https://leetcode.com/problems/flood-fill) | [![Java](assets/java.png)](src/FloodFill.java) [![Python](assets/python.png)](python/flood_fill.py) | | -| 743 | [Network Delay Time](https://leetcode.com/problems/network-delay-time) | [![Java](assets/java.png)](src/NetworkDelayTime.java) | | -| 734 | [Sentence Similarity](https://leetcode.com/problems/sentence-similarity) | | | -| 744 | [Find Smallest Letter Greater Than Target](https://leetcode.com/problems/find-smallest-letter-greater-than-target) | [![Java](assets/java.png)](src/FindSmallestLetterGreaterThanTarget.java) [![Python](assets/python.png)](python/find_smallest_letter_greater_than.py) | | -| 746 | [Min Cost Climbing Stairs](https://leetcode.com/problems/min-cost-climbing-stairs) | [![Java](assets/java.png)](src/MinCostClimbingStairs.java) [![Python](assets/python.png)](python/min_cost_climbing_stairs.py) | | -| 747 | [Largest Number at least Twice of Others](https://leetcode.com/problems/largest-number-at-least-twice-of-others) | [![Java](assets/java.png)](src/LargestNumberAtLeastTwiceOfOthers.java) [![Python](assets/python.png)](python/largest_number_at_least_twice_of_others.py) | | -| 748 | [Shortest Completing Word](https://leetcode.com/problems/shortest-completing-word) | [![Java](assets/java.png)](src/ShortestCompletingWord.java) [![Python](assets/python.png)](python/shortest_completing_word.py) | | -| 758 | [Bold Words in String](https://leetcode.com/problems/bold-words-in-string) | | | -| 760 | [Find Anagram Mappings](https://leetcode.com/problems/find-anagram-mappings) | | | -| 762 | [Prime Number of Set Bits in Primary Representation](https://leetcode.com/problems/prime-number-of-set-bits-in-binary-representation) | [![Java](assets/java.png)](src/PrimeNumberOfSetBitsInBinaryRepresentation.java) [![Python](assets/python.png)](python/prime_number_of_set_bits_in_binary_representation.py) | | -| 766 | [Toeplitz Matrix](https://leetcode.com/problems/toeplitz-matrix) | [![Java](assets/java.png)](src/ToeplitzMatrix.java) [![Python](assets/python.png)](python/toeplitz_matrix.py) | | -| 771 | [Jewels and Stones](https://leetcode.com/problems/jewels-and-stones) | [![Java](assets/java.png)](src/JewelsAndStones.java) [![Python](assets/python.png)](python/jewels_and_stones.py) | | -| 783 | [Minimum Distance Between BST Nodes](https://leetcode.com/problems/minimum-distance-between-bst-nodes) | [![Java](assets/java.png)](src/MinimumAbsoluteDifferenceInBST.java) [![Python](assets/python.png)](python/minimum_distance_between_bst_nodes.py) | | -| 788 | [Rotated Digits](https://leetcode.com/problems/rotated-digits) | | | -| 796 | [Rotate String](https://leetcode.com/problems/rotate-string) | [![Java](assets/java.png)](src/RotateString.java) | | -| 800 | [Similar RGB Color](https://leetcode.com/problems/similar-rgb-color) | | | -| 804 | [Unique Morse Code Words](https://leetcode.com/problems/unique-morse-code-words) | [![Java](assets/java.png)](src/UniqueMorseCodeWords.java) | | -| 806 | [Number of Lines to Write String](https://leetcode.com/problems/number-of-lines-to-write-string) | [![Java](assets/java.png)](src/NumberOfLinesToWriteInString.java) | | -| 811 | [Subdomain Visit Count](https://leetcode.com/problems/subdomain-visit-count) | | | -| 812 | [Largest Triangle Area](https://leetcode.com/problems/largest-triangle-area) | [![Java](assets/java.png)](src/LargestTriangleArea.java) | | -| 819 | [Most Common Word](https://leetcode.com/problems/most-common-word) | [![Java](assets/java.png)](src/MostCommonWord.java) | | -| 821 | [Shortest Distance to Character](https://leetcode.com/problems/shortest-distance-to-a-character) | [![Java](assets/java.png)](src/ShortestDistanceToACharacter.java) | | -| 824 | [Goat Latin](https://leetcode.com/problems/goat-latin) | [![Java](assets/java.png)](src/GoatLatin.java) | | -| 830 | [Positions of Large Groups](https://leetcode.com/problems/positions-of-large-groups) | [![Java](assets/java.png)](src/PositionsOfLargeGroups.java) | | -| 832 | [Flipping an Image](https://leetcode.com/problems/flipping-an-image) | [![Java](assets/java.png)](src/FlippingAnImage.java) | | -| 836 | [Rectangle Overlap](https://leetcode.com/problems/rectangle-overlap) | [![Java](assets/java.png)](src/RectangleOverlap.java) | | -| 840 | [Magic Squares in Grid](https://leetcode.com/problems/magic-squares-in-grid) | | | -| 844 | [Backspace String Compare](https://leetcode.com/problems/backspace-string-compare) | [![Java](assets/java.png)](src/BackspaceStringCompare.java) | | -| 849 | [Maximize Distance to Closest Person](https://leetcode.com/problems/maximize-distance-to-closest-person) | | | -| 852 | [Peak Index in Mountain Array](https://leetcode.com/problems/peak-index-in-a-mountain-array) | [![Java](assets/java.png)](src/PeakIndexInMountainArray.java) | | -| 859 | [Buddy Strings](https://leetcode.com/problems/buddy-strings) | [![Java](assets/java.png)](src/BuddyStrings.java) | | -| 860 | [Lemonade Change](https://leetcode.com/problems/lemonade-change) | [![Java](assets/java.png)](src/LemonadeChange.java) | | -| 867 | [Transpose Matrix](https://leetcode.com/problems/transpose-matrix) | [![Java](assets/java.png)](src/TransposeMatrix.java) | | -| 868 | [Binary Gap](https://leetcode.com/problems/binary-gap) | [![Java](assets/java.png)](src/BinaryGap.java) | | -| 872 | [Leaf-Similar Trees](https://leetcode.com/problems/leaf-similar-trees) | [![Java](assets/java.png)](src/LeafSimilarTrees.java) | | -| 874 | [Walking Robot Simulation](https://leetcode.com/problems/walking-robot-simulation) | | | -| 876 | [Middle of the Linked List](https://leetcode.com/problems/middle-of-the-linked-list) | [![Java](assets/java.png)](src/MiddleOfTheLinkedList.java) | | -| 881 | [Boats to Save People](https://leetcode.com/problems/boats-to-save-people) | [![Python](assets/python.png)](python/boats_to_save_people.py) | | -| 883 | [Projection Area of 3D Shapes](https://leetcode.com/problems/projection-area-of-3d-shapes) | [![Java](assets/java.png)](src/ProjectionAreaOf3DShapes.java) | | -| 884 | [Uncommon Words from 2 Sentences](https://leetcode.com/problems/uncommon-words-from-two-sentences) | [![Java](assets/java.png)](src/UncommonWordsFromTwoSentences.java) | | -| 888 | [Fair Candy Swap](https://leetcode.com/problems/fair-candy-swap) | [![Java](assets/java.png)](src/FairCandySwap.java) | | -| 892 | [Surface Area of 3D Shapes](https://leetcode.com/problems/surface-area-of-3d-shapes) | [![Java](assets/java.png)](src/SurfaceAreaOf3DShapes.java) | | -| 893 | [Groups of Special Equivalent Strings](https://leetcode.com/problems/groups-of-special-equivalent-strings) | | | -| 896 | [Monotonic Array](https://leetcode.com/problems/monotonic-array) | [![Java](assets/java.png)](src/MonotonicArray.java) | | -| 897 | [Increasing Order Search Tree](https://leetcode.com/problems/increasing-order-search-tree) | [![Java](assets/java.png)](src/IncreasingOrderSearchTree.java) | | -| 905 | [Sort Array by Parity](https://leetcode.com/problems/sort-array-by-parity) | | | -| 908 | [Smallest Range I](https://leetcode.com/problems/smallest-range-i) | [![Java](assets/java.png)](src/SmallestRangeI.java) | | -| 914 | [X of a kind in a Deck of Cards](https://leetcode.com/problems/x-of-a-kind-in-a-deck-of-cards) | [![Java](assets/java.png)](src/XOfAKindInADeckOfCards.java) | | -| 917 | [Reverse Only Letters](https://leetcode.com/problems/reverse-only-letters) | [![Java](assets/java.png)](src/ReverseOnlyLetters.java) | | -| 922 | [Sort Array by Parity II](https://leetcode.com/problems/sort-array-by-parity-ii) | [![Java](assets/java.png)](src/SortArrayByParityII.java) | | -| 925 | [Long Pressed Name](https://leetcode.com/problems/long-pressed-name) | [![Java](assets/java.png)](src/LongPressedName.java) | | -| 929 | [Unique Email Addresses](https://leetcode.com/problems/unique-email-addresses) | [![Java](assets/java.png)](src/UniqueEmailAddresses.java) | | -| 933 | [Number of Recent Calls](https://leetcode.com/problems/number-of-recent-calls) | [![Java](assets/java.png)](src/NumberOfRecentCalls.java) | | -| 937 | [Reorder Data In Log Files](https://leetcode.com/problems/reorder-data-in-log-files) | [![Java](assets/java.png)](src/ReorderDataInLogFiles.java) | | -| 938 | [Range Sum of BST](https://leetcode.com/problems/range-sum-of-bst) | [![Java](assets/java.png)](src/RangeSumOfBST.java) | | -| 941 | [Valid Mountain Array](https://leetcode.com/problems/valid-mountain-array) | [![Java](assets/java.png)](src/ValidMountainArray.java) [![Python](assets/python.png)](python/valid_mountain_array.py) | | -| 942 | [DI String Match](https://leetcode.com/problems/di-string-match) | [![Java](assets/java.png)](src/DIStringMatch.java) | | -| 944 | [Delete Columns to Make Sorted](https://leetcode.com/problems/delete-columns-to-make-sorted) | [![Java](assets/java.png)](src/DeleteColumnsToMakeSorted.java) | | -| 949 | [Largest Time for Given Digits](https://leetcode.com/problems/largest-time-for-given-digits) | | | -| 953 | [Verifying an Alien Dictionary](https://leetcode.com/problems/verifying-an-alien-dictionary) | [![Java](assets/java.png)](src/VerifyAnAlienDictionary.java) | | -| 961 | [N-Repeated Elements in Size 2N Array](https://leetcode.com/problems/n-repeated-element-in-size-2n-array) | [![Java](assets/java.png)](src/NRepeatedElementInSizeNArray.java) | | -| 965 | [Univalued Binary Tree](https://leetcode.com/problems/univalued-binary-tree) | [![Java](assets/java.png)](src/UnivaluedBinaryTree.java) | | -| 970 | [Powerful Integers](https://leetcode.com/problems/powerful-integers) | | | -| 976 | [Largest Perimeter Triangle](https://leetcode.com/problems/largest-perimeter-triangle) | [![Java](assets/java.png)](src/LargestPerimeterTriangle.java) | | -| 977 | [Squares of a Sorted Array](https://leetcode.com/problems/squares-of-a-sorted-array) | | | -| 983 | [Minimum Cost For Tickets](https://leetcode.com/problems/minimum-cost-for-tickets) | [![Python](assets/python.png)](python/minimum_cost_for_tickets.py) | | -| 985 | [Sum of Even Numbers after Queries](https://leetcode.com/problems/sum-of-even-numbers-after-queries) | | | -| 989 | [Add to Array Form of Integer](https://leetcode.com/problems/add-to-array-form-of-integer) | [![Java](assets/java.png)](src/AddToArrayFormOfInteger.java) | | -| 993 | [Cousins in Binary Tree](https://leetcode.com/problems/cousins-in-binary-tree) | [![Java](assets/java.png)](src/CousinsInBinaryTree.java) | | -| 994 | [Rotting Oranges](https://leetcode.com/problems/rotting-oranges) | [![Java](assets/java.png)](src/RottingOranges.java) | | -| 997 | [Find the Town Judge](https://leetcode.com/problems/find-the-town-judge) | [![Java](assets/java.png)](src/FindTheTownJudge.java) | | -| 999 | [Available Captures for Rook](https://leetcode.com/problems/available-captures-for-rook) | [![Java](assets/java.png)](src/AvailableCapturesForRook.java) | | -| 1002 | [Find Common Characters](https://leetcode.com/problems/find-common-characters) | [![Java](assets/java.png)](src/FindCommonCharacters.java) | | -| 1005 | [Maximize Sum of Array After K Negations](https://leetcode.com/problems/maximize-sum-of-array-after-k-negations) | [![Java](assets/java.png)](src/MaximizeSumOfArrayAfterKNegations.java) | | -| 1009 | [Complement of Base 10 Integer](https://leetcode.com/problems/complement-of-base-10-integer) | [![Java](assets/java.png)](src/NumberComplement.java) | | -| 1010 | [Pairs of Songs With Total Durations Divisible by 60](https://leetcode.com/problems/pairs-of-songs-with-total-durations-divisible-by-60) | [![Java](assets/java.png)](src/PartitionArrayIntoThreePartsWithEqualSum.java) | | -| 1013 | [Partition Array into Three Parts with equal Sum](https://leetcode.com/problems/partition-array-into-three-parts-with-equal-sum) | | | -| 1018 | [Binary Prefix Divisible by 5](https://leetcode.com/problems/binary-prefix-divisible-by-5) | [![Java](assets/java.png)](src/BinaryPrefixDivisibleBy5.java) | | -| 1020 | [Number of Enclaves](https://leetcode.com/problems/number-of-enclaves) | [![Python](assets/python.png)](python/number_of_enclaves.py) | | -| 1021 | [Remove Outermost Parenthesis](https://leetcode.com/problems/remove-outermost-parentheses) | [![Java](assets/java.png)](src/RemoveOutermostParentheses.java) | | -| 1022 | [Sum of Root to Leaf Binary Numbers](https://leetcode.com/problems/sum-of-root-to-leaf-binary-numbers) | [![Java](assets/java.png)](src/SumOfRootToLeafBinaryNumbers.java) | | -| 1025 | [Divisor Game](https://leetcode.com/problems/divisor-game) | [![Java](assets/java.png)](src/DivisorGame.java) | | -| 1029 | [Two City Scheduling](https://leetcode.com/problems/two-city-scheduling) | | | -| 1030 | [Matrix Cells in Distance Order](https://leetcode.com/problems/matrix-cells-in-distance-order) | [![Java](assets/java.png)](src/MatrixCellsInDistanceOrder.java) | | -| 1033 | [Moving Stones Until Consecutive](https://leetcode.com/problems/moving-stones-until-consecutive) | | | -| 1037 | [Valid Boomerang](https://leetcode.com/problems/valid-boomerang) | [![Java](assets/java.png)](src/ValidBoomerang.java) | | -| 1042 | [Flower Planting with no Adjacent](https://leetcode.com/problems/flower-planting-with-no-adjacent) | | | -| 1046 | [Last Stone Weight](https://leetcode.com/problems/last-stone-weight) | [![Java](assets/java.png)](src/LastStoneWeight.java) | | -| 1047 | [Remove All adjacent Duplicates in String](https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string) | [![Java](assets/java.png)](src/RemoveAllAdjacentDuplicatesInAString.java) | | -| 1051 | [Height Checker](https://leetcode.com/problems/height-checker) | | | -| 1056 | 🔒 [Confusing Number](https://leetcode.com/problems/confusing-number) | | | -| 1064 | 🔒 [Fixed Point](https://leetcode.com/problems/fixed-point) | | | -| 1065 | 🔒 [Index Pairs of a String](https://leetcode.com/problems/index-pairs-of-a-string) | | | -| 1071 | [Greatest Common Divisors of Strings](https://leetcode.com/problems/greatest-common-divisor-of-strings) | [![Java](assets/java.png)](src/GreatestCommonDivisorOfStrings.java) | | -| 1078 | [Occurrence After Bigram](https://leetcode.com/problems/occurrences-after-bigram) | [![Java](assets/java.png)](src/OccurrencesAfterBigram.java) | | -| 1085 | 🔒 [Sum of Digits in Minimum Number](https://leetcode.com/problems/sum-of-digits-in-the-minimum-number) | | | -| 1086 | 🔒 [High Five](https://leetcode.com/problems/high-five) | | | -| 1089 | [Duplicate Zeroes](https://leetcode.com/problems/duplicate-zeros) | [![Java](assets/java.png)](src/DuplicateZeros.java) | | -| 1099 | 🔒 [Two Sum Less Than K](https://leetcode.com/problems/two-sum-less-than-k) | | | -| 1103 | [Distribute Candies to People](https://leetcode.com/problems/distribute-candies-to-people) | [![Java](assets/java.png)](src/DistributeCandiesToPeople.java) | | -| 1108 | [Defanging an IP Address](https://leetcode.com/problems/defanging-an-ip-address) | [![Java](assets/java.png)](src/DefangingAnIPAddress.java) | | -| 1118 | 🔒 [Number of Days in a Month](https://leetcode.com/problems/number-of-days-in-a-month) | | | -| 1119 | 🔒 [Remove Vowels From String](https://leetcode.com/problems/remove-vowels-from-a-string) | | | -| 1122 | [Relative Sort Array](https://leetcode.com/problems/relative-sort-array) | [![Java](assets/java.png)](src/RelativeSortArray.java) | | -| 1128 | [Number of Equivalent Domino Pairs](https://leetcode.com/problems/number-of-equivalent-domino-pairs) | [![Java](assets/java.png)](src/NumberOfEquivalentDominoPairs.java) | | -| 1133 | 🔒 [Largest Unique Number](https://leetcode.com/problems/largest-unique-number) | | | -| 1134 | 🔒 [Armstrong Number](https://leetcode.com/problems/armstrong-number) | | | -| 1137 | [Nth Tribonacci Number](https://leetcode.com/problems/n-th-tribonacci-number) | [![Java](assets/java.png)](src/NthTribonacciNumber.java) | | -| 1143 | [Longest Common Subsequence](https://leetcode.com/problems/longest-common-subsequence) | [![Java](assets/java.png)](src/LongestCommonSubsequence.java) | | -| 1150 | [Check if Number is Majority Element in Sorted Array](https://leetcode.com/problems/check-if-a-number-is-majority-element-in-a-sorted-array) | | | -| 1154 | [Day of The Year](https://leetcode.com/problems/day-of-the-year) | [![Java](assets/java.png)](src/DayOfTheYear.java) | | -| 1160 | [Find Words That Can Be Formed By Characters](https://leetcode.com/problems/find-words-that-can-be-formed-by-characters) | | | -| 1165 | [Single Row Keyboard](https://leetcode.com/problems/single-row-keyboard) | [![Java](assets/java.png)](src/FindWordsThatCanBeFormedByCharacters.java) | | -| 1170 | [Compare Strings By Frequency of the Smallest Character](https://leetcode.com/problems/compare-strings-by-frequency-of-the-smallest-character) | | | -| 1175 | [Prime Arrangements](https://leetcode.com/problems/prime-arrangements) | [![Java](assets/java.png)](src/PrimeArrangements.java) | | -| 1176 | 🔒 [Diet Plan Performance](https://leetcode.com/problems/diet-plan-performance) | | | -| 1180 | 🔒 [Count Substrings with only one Distinct Letter](https://leetcode.com/problems/count-substrings-with-only-one-distinct-letter) | | | -| 1184 | [Distance Between Bus Stops](https://leetcode.com/problems/distance-between-bus-stops) | [![Java](assets/java.png)](src/DistanceBetweenBusStops.java) | | -| 1185 | [Day of the Week](https://leetcode.com/problems/day-of-the-week) | [![Java](assets/java.png)](src/DayOfWeek.java) | | -| 1189 | [Maximum Number of Balloons](https://leetcode.com/problems/maximum-number-of-balloons) | [![Java](assets/java.png)](src/MaximumNumberOfBalloons.java) | | -| 1196 | 🔒 [How Many Apples Can You Put into the Basket](https://leetcode.com/problems/how-many-apples-can-you-put-into-the-basket) | | | -| 1200 | [Minimum Absolute Difference](https://leetcode.com/problems/minimum-absolute-difference) | [![Java](assets/java.png)](src/MinimumAbsoluteDifference.java) | | -| 1201 | [Ugly Number III](https://leetcode.com/problems/ugly-number-iii) | [![Java](assets/java.png)](src/UglyNumberIII.java) | | -| 1207 | [Unique Number of Occurrences](https://leetcode.com/problems/unique-number-of-occurrences) | [![Java](assets/java.png)](src/UniqueNumberOfOccurrences.java) | | -| 1213 | 🔒 [Intersection of Three Sorted Arrays](https://leetcode.com/problems/intersection-of-three-sorted-arrays) | | | -| 1217 | [Minimum Cost to Move Chips to The Same Position](https://leetcode.com/problems/minimum-cost-to-move-chips-to-the-same-position) | [![Java](assets/java.png)](src/MinimumCostToMoveChipsToTheSamePosition.java) | | -| 1221 | [Split A String In Balanced Strings](https://leetcode.com/problems/split-a-string-in-balanced-strings) | [![Java](assets/java.png)](src/SplitAStringInBalancedStrings.java) | | -| 1228 | 🔒 [Missing A Number In Arithmetic Progression](https://leetcode.com/problems/missing-number-in-arithmetic-progression) | | | -| 1232 | [Check If It Is A Straight Line](https://leetcode.com/problems/check-if-it-is-a-straight-line) | [![Java](assets/java.png)](src/CheckIfItIsASStraightLine.java) | | -| 1237 | [Find Positive Integer Solutions for a Given Equation](https://leetcode.com/problems/find-positive-integer-solution-for-a-given-equation) | | | -| 1243 | 🔒 [Array Transformation](https://leetcode.com/problems/array-transformation) | | | -| 1249 | [Minimum Remove to Make Valid Parentheses](https://leetcode.com/problems/minimum-remove-to-make-valid-parentheses) | [![Java](assets/java.png)](src/MinimumRemoveToMakeValidParentheses.java) | | -| 1252 | [Cells With Odd Values In Matrix](https://leetcode.com/problems/cells-with-odd-values-in-a-matrix) | [![Java](assets/java.png)](src/CellsWithOddValuesInMatrix.java) | | -| 1254 | [Number of Closed Islands](https://leetcode.com/problems/number-of-closed-islands) | [![Python](assets/python.png)](python/number_of_closed_islands.py) | | -| 1260 | [Shift 2D Grid](https://leetcode.com/problems/shift-2d-grid) | [![Java](assets/java.png)](src/Shift2DGrid.java) | | -| 1266 | [Minimum Time Visiting All Points](https://leetcode.com/problems/minimum-time-visiting-all-points) | [![Java](assets/java.png)](src/MinimumTimeVisitingAllPoints.java) | | -| 1271 | 🔒 [Hexspeak](https://leetcode.com/problems/hexspeak) | | | -| 1275 | [Find Winner On a Tic Tac Toe Game](https://leetcode.com/problems/find-winner-on-a-tic-tac-toe-game) | [![Java](assets/java.png)](src/FindWinnerOnATicTacToeGame.java) | | -| 1281 | [Subtract the Product and Sum of Digits of a Integer](https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer) | [![Java](assets/java.png)](src/SubtractTheProductAndSumOfDigitsOfAnInteger.java) | | -| 1287 | [Element Appearing More Than 25% in Sorted Array](https://leetcode.com/problems/element-appearing-more-than-25-in-sorted-array) | [![Java](assets/java.png)](src/ElementAppearingMoreThan25PercentInSortedArray.java) | | -| 1290 | [Convert Binary Number In A Linked List to Integer](https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer) | [![Java](assets/java.png)](src/ConvertBinaryNumberInLinkedListToInteger.java) | | -| 1295 | [Find Numbers With Even Numbers of Digits](https://leetcode.com/problems/find-numbers-with-even-number-of-digits) | [![Java](assets/java.png)](src/FindNumbersWithEvenNumbersOfDigits.java) [![Python](assets/python.png)](python/find_numbers_with_even_number_of_digits.py) | | -| 1299 | [Replace Elements With Greatest Element on Right Side](https://leetcode.com/problems/replace-elements-with-greatest-element-on-right-side) | [![Java](assets/java.png)](src/ReplaceElementWithGreatestElementOnRightSide.java) [![Python](assets/python.png)](python/replace_element_with_greatest_element_on_right_hand_side.py) | | -| 1304 | [Find N Unique Integers Sum Up To Zero](https://leetcode.com/problems/find-n-unique-integers-sum-up-to-zero) | [![Java](assets/java.png)](src/FindNUniqueIntegersSumUpToZero.java) | | -| 1309 | [Decrypt String From Alphabet To Integer Mapping](https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping) | [![Java](assets/java.png)](src/DecryptStringFromAlphabetToIntegerMapping.java) | | -| 1313 | [Decompress Run-Length Encoded Strings](https://leetcode.com/problems/decompress-run-length-encoded-list) | [![Java](assets/java.png)](src/DecompressRunLengthEncodedList.java) | | -| 1317 | [Convert Integer to Sum Of Two Non-Zero Integers](https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers) | [![Java](assets/java.png)](src/ConvertIntegerToTheSumOfTwoNoZeroIntegers.java) | | -| 1319 | [Number of Operations to Make Network Connected](https://leetcode.com/problems/number-of-operations-to-make-network-connected) | [![Python](assets/python.png)](python/no_of_operations_to_make_network_connected.py) | | -| 1323 | [Maximum 69 Number](https://leetcode.com/problems/maximum-69-number) | [![Java](assets/java.png)](src/Maximum69Number.java) | | -| 1331 | [Rank Transform of An Array](https://leetcode.com/problems/rank-transform-of-an-array) | [![Java](assets/java.png)](src/RankTransformOfArray.java) | | -| 1332 | [Remove Palindromic Subsequences](https://leetcode.com/problems/remove-palindromic-subsequences) | [![Java](assets/java.png)](src/RemovePalindromicSubSequences.java) | | -| 1337 | [The K Weakest Rows In A Matrix](https://leetcode.com/problems/the-k-weakest-rows-in-a-matrix) | [![Java](assets/java.png)](src/TheKWeakestRowsInAMatrix.java) | | -| 1342 | [Number of Steps to Reduce a Number to Zero](https://leetcode.com/problems/number-of-steps-to-reduce-a-number-to-zero) | [![Java](assets/java.png)](src/NumberOfStepsToReduceANumberToZero.java) | | -| 1346 | [Check if N and It's Double Exist](https://leetcode.com/problems/check-if-n-and-its-double-exist) | [![Java](assets/java.png)](src/CheckIfNAndItsDoubleExist.java) [![Python](assets/python.png)](python/check_if_n_and_its_double_exist.py) | | -| 1351 | [Count Negative Numbers In A Sorted Matrix](https://leetcode.com/problems/count-negative-numbers-in-a-sorted-matrix) | [![Java](assets/java.png)](src/CountNegativeNumbersInSortedMatrix.java) | | -| 1356 | [Sort Integers by Number of 1 Bits](https://leetcode.com/problems/sort-integers-by-the-number-of-1-bits) | [![Java](assets/java.png)](src/SortIntegersByTheNumberOf1Bits.java) | | -| 1360 | [Number of Days Between Two Dates](https://leetcode.com/problems/number-of-days-between-two-dates) | [![Java](assets/java.png)](src/NumberOfDaysBetweenTwoDates.java) | | -| 1365 | [How Many Numbers Are Smaller Than Current Number](https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number) | [![Java](assets/java.png)](src/HowManyNumbersAreSmallerThanCurrentNumber.java) | | -| 1370 | [Increasing Decreasing String](https://leetcode.com/problems/increasing-decreasing-string) | [![Java](assets/java.png)](src/IncreasingDecreasingString.java) | | -| 1374 | [Generate A String With Characters That Have Odd Count](https://leetcode.com/problems/generate-a-string-with-characters-that-have-odd-counts) | [![Java](assets/java.png)](src/GenerateAStringWithCharactersThatHaveOddCounts.java) | | -| 1376 | [Time Needed to Inform All Employees](https://leetcode.com/problems/time-needed-to-inform-all-employees) | [![Java](assets/java.png)](src/TimeNeededToInformAllEmployees.java) | | -| 1379 | [Find a Corresponding Node of a Binary Tree in a Clone of That Tree](https://leetcode.com/problems/find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree) | [![Java](assets/java.png)](src/FindACorrespondingNodeOfABinaryTreeInACloneOfThatTree.java) | | -| 1380 | [Lucky Numbers In A Matrix](https://leetcode.com/problems/lucky-numbers-in-a-matrix) | [![Java](assets/java.png)](src/LuckyNumbersInAMatrix.java) | | -| 1385 | [Find The Distance Value Between 2 Arrays](https://leetcode.com/problems/find-the-distance-value-between-two-arrays) | [![Java](assets/java.png)](src/FindTheDistanceValuesBetweenTwoArrays.java) | | -| 1389 | [Create Target Array in Given Order](https://leetcode.com/problems/create-target-array-in-the-given-order) | [![Java](assets/java.png)](src/CreateTargetArrayInGivenOrder.java) | | -| 1394 | [Find Lucky Integer In An Array](https://leetcode.com/problems/find-lucky-integer-in-an-array) | [![Java](assets/java.png)](src/FindTheLuckyIntegerInAnArray.java) | | -| 1399 | [Count Largest Group](https://leetcode.com/problems/count-largest-group) | [![Java](assets/java.png)](src/CountLargestGroup.java) | | -| 1402 | [Reducing Dishes](https://leetcode.com/problems/reducing-dishes) | [![Python](assets/python.png)](python/reducing_dishes.py) | | -| 1403 | [Minimum Subsequence in Non-Increasing Order](https://leetcode.com/problems/minimum-subsequence-in-non-increasing-order) | [![Java](assets/java.png)](src/MinimumSubSequenceInNonIncreasingOrder.java) | | -| 1408 | [String Matching In An Array](https://leetcode.com/problems/string-matching-in-an-array) | [![Java](assets/java.png)](src/StringMatchingInAnArray.java) | | -| 1413 | [Minimum Value To Get Positive Step By Step Sum](https://leetcode.com/problems/minimum-value-to-get-positive-step-by-step-sum) | [![Java](assets/java.png)](src/MinimumValueToGetPositiveStepByStepSum.java) | | -| 1417 | [Reformat The String](https://leetcode.com/problems/reformat-the-string) | [![Java](assets/java.png)](src/ReformatTheString.java) | | -| 1422 | [Maximum Score After Splitting A String](https://leetcode.com/problems/maximum-score-after-splitting-a-string) | [![Java](assets/java.png)](src/MaximumScoreAfterSplittingAString.java) | | -| 1426 | 🔒 [Counting Elements](https://leetcode.com/problems/counting-elements) | | | -| 1427 | 🔒 [Performing String Shifts](https://leetcode.com/problems/perform-string-shifts) | | | -| 1431 | [Kids With The Greatest Number Of Candies](https://leetcode.com/problems/kids-with-the-greatest-number-of-candies) | [![Java](assets/java.png)](src/KidsWithTheGreatestNumberOfCandies.java) | | -| 1436 | [Destination City](https://leetcode.com/problems/destination-city) | [![Java](assets/java.png)](src/DestinationCity.java) | | -| 1437 | [Check If All 1's Are at Least Length K Places Away](https://leetcode.com/problems/check-if-all-1s-are-at-least-length-k-places-away) | [![Java](assets/java.png)](src/CheckIfAll1sAreAtLeastKPlacesAway.java) | | -| 1441 | [Build An Array With Stack Operation](https://leetcode.com/problems/build-an-array-with-stack-operations) | [![Java](assets/java.png)](src/BuildAnArrayWithStackOperations.java) | | -| 1444 | [Number of Ways of Cutting a Pizza](https://leetcode.com/problems/number-of-ways-of-cutting-a-pizza) | [![Python](assets/python.png)](python/number_of_ways_of_cutting_pizza.py) | | -| 1446 | [Consecutive Characters](https://leetcode.com/problems/consecutive-characters) | [![Java](assets/java.png)](src/ConsecutiveCharacters.java) | | -| 1450 | [Number of Students Doing Homework at Given Time](https://leetcode.com/problems/number-of-students-doing-homework-at-a-given-time) | [![Java](assets/java.png)](src/NumberOfStudentsDoingHomeworkAtGivenTime.java) | | -| 1455 | [Check If Word Occurs as Prefix of any Word in Sentence](https://leetcode.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence) | [![Java](assets/java.png)](src/CheckIfAWordOccursAsAPrefixOfAnyWordInASentence.java) | | -| 1460 | [Make 2 Arrays Equal by Reversing Sub Arrays](https://leetcode.com/problems/make-two-arrays-equal-by-reversing-sub-arrays) | [![Java](assets/java.png)](src/MakeTwoArraysEqualByReversingSubArrays.java) | | -| 1464 | [Maximum Product of 2 Elements in Array](https://leetcode.com/problems/maximum-product-of-two-elements-in-an-array) | [![Java](assets/java.png)](src/MaximumProductOfTwoElementsInArray.java) | | -| 1466 | [Reorder Routes to Make All Paths Lead to the City Zero](https://leetcode.com/problems/reorder-routes-to-make-all-paths-lead-to-the-city-zero) | [![Java](assets/java.png)](src/MaximumProductOfTwoElementsInArray.java) | | -| 1469 | 🔒 [Find All Lonely Nodes](https://leetcode.com/problems/find-all-the-lonely-nodes) | [![Python](assets/python.png)](python/reorder_routes_to_make_all_paths_lead_to_city_zero.py) | | -| 1470 | [Shuffle The Array](https://leetcode.com/problems/shuffle-the-array) | [![Java](assets/java.png)](src/ShuffleTheArray.java) | | -| 1472 | [Design Browser History](https://leetcode.com/problems/design-browser-history) | [![Java](assets/java.png)](src/DesignBrowserHistory.java) [![Python](assets/python.png)](python/design_browser_history.py) | | -| 1474 | [Delete N Nodes After M Nodes In A Linked List](https://leetcode.com/problems/delete-n-nodes-after-m-nodes-of-a-linked-list) | | | -| 1475 | [Final Prices With Special Discount in a Shop](https://leetcode.com/problems/final-prices-with-a-special-discount-in-a-shop) | [![Java](assets/java.png)](src/FinalPricesWithASpecialDiscountInAShop.java) | | -| 1480 | [Running Sum of 1D Array](https://leetcode.com/problems/running-sum-of-1d-array) | [![Java](assets/java.png)](src/RunningSumOf1DArray.java) | | -| 1486 | [XOR Operations in An Array](https://leetcode.com/problems/xor-operation-in-an-array) | [![Java](assets/java.png)](src/XOROperationInAnArray.java) | | -| 1491 | [Average Salary Excluding the Minimum and Maximum Salary](https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary) | [![Java](assets/java.png)](src/AverageSalaryExcludingTheMinimumAndMaximumSalary.java) | | -| 1496 | [Path Crossing](https://leetcode.com/problems/path-crossing) | [![Java](assets/java.png)](src/PathCrossing.java) | | -| 1502 | [Can Make Arithmetic Progression From Sequence](https://leetcode.com/problems/can-make-arithmetic-progression-from-sequence) | [![Java](assets/java.png)](src/CanMakeArithmeticProgressionFromSequence.java) | | -| 1507 | [Reformat Date](https://leetcode.com/problems/reformat-date) | [![Java](assets/java.png)](src/ReformatDate.java) | | -| 1512 | [Number of Good Pairs](https://leetcode.com/problems/number-of-good-pairs) | [![Java](assets/java.png)](src/NumberOfGoodPairs.java) | | -| 1518 | [Water Bottles](https://leetcode.com/problems/water-bottles) | [![Java](assets/java.png)](src/WaterBottles.java) | | -| 1523 | [Count Odd Numbers In Interval Range](https://leetcode.com/problems/count-odd-numbers-in-an-interval-range) | [![Java](assets/java.png)](src/CountOddNumbersInIntervalRange.java) | | -| 1528 | [Shuffle Strings](https://leetcode.com/problems/shuffle-string) | [![Java](assets/java.png)](src/ShuffleString.java) | | -| 1534 | [Count Good Triplets](https://leetcode.com/problems/count-good-triplets) | [![Java](assets/java.png)](src/CountGoodTriplets.java) | | -| 1539 | [Kth Missing Positive Number](https://leetcode.com/problems/kth-missing-positive-number) | [![Java](assets/java.png)](src/KthMissingPositiveNumber.java) | | -| 1544 | [Make The String Great](https://leetcode.com/problems/make-the-string-great) | [![Java](assets/java.png)](src/MakeTheStringGreat.java) | | -| 1550 | [Three Consecutive Odds](https://leetcode.com/problems/three-consecutive-odds) | [![Java](assets/java.png)](src/ThreeConsecutiveOdds.java) | | -| 1556 | [Thousand Separator](https://leetcode.com/problems/thousand-separator) | [![Java](assets/java.png)](src/ThousandSeparator.java) | | -| 1560 | [Most Visited Sector in a Circular Track](https://leetcode.com/problems/most-visited-sector-in-a-circular-track) | [![Java](assets/java.png)](src/MostVisitedSectorInACircularTrack.java) | | -| 1566 | [Detect Pattern of Length M Repeated K or More Times](https://leetcode.com/problems/detect-pattern-of-length-m-repeated-k-or-more-times) | [![Java](assets/java.png)](src/DetectPatternOfLengthMRepeatedKOrMoreTimes.java) | | -| 1572 | [Matrix Diagonal Sum](https://leetcode.com/problems/matrix-diagonal-sum) | [![Java](assets/java.png)](src/MatrixDiagonalSum.java) | | -| 1576 | [Replace All ?'s to Avoid Consecutive Repeating Characters](https://leetcode.com/problems/replace-all-s-to-avoid-consecutive-repeating-characters) | [![Java](assets/java.png)](src/ReplaceAllToAvoidConsecutiveRepeatingCharacters.java) | | -| 1582 | [Special Positions in a Binary Matrix](https://leetcode.com/problems/special-positions-in-a-binary-matrix) | [![Java](assets/java.png)](src/SpecialPositionInABinaryMatrix.java) | | -| 1588 | [Sum of All Odd Length Subarrays](https://leetcode.com/problems/sum-of-all-odd-length-subarrays) | [![Java](assets/java.png)](src/SumOfAllOddLengthSubArrays.java) | | -| 1592 | [Rearrange Spaces Between Words](https://leetcode.com/problems/rearrange-spaces-between-words) | [![Java](assets/java.png)](src/RearrangeSpacesBetweenWords.java) | | -| 1598 | [Crawler Log Folder](https://leetcode.com/problems/crawler-log-folder) | [![Java](assets/java.png)](src/CrawlerLogFolder.java) | | -| 1600 | [Throne Inheritance](https://leetcode.com/problems/throne-inheritance) | [![Java](assets/java.png)](src/ThroneInheritance.java) | | -| 1603 | [Design Parking System](https://leetcode.com/problems/design-parking-system) | [![Java](assets/java.png)](src/DesignParkingSystem.java) | | -| 1608 | [Special Array With X Elements Greater Than or Equal X](https://leetcode.com/problems/special-array-with-x-elements-greater-than-or-equal-x) | [![Java](assets/java.png)](src/SpecialArrayWithXElementsGreaterThanEqualToX.java) | | -| 1614 | [Maximum Nesting Depth of the Parentheses](https://leetcode.com/problems/maximum-nesting-depth-of-the-parentheses) | [![Java](assets/java.png)](src/MaximumNestingDepthOfTheParentheses.java) | | -| 1619 | [Mean of Array After Removing Some Elements](https://leetcode.com/problems/mean-of-array-after-removing-some-elements) | [![Java](assets/java.png)](src/MeanOfArrayAfterRemovingSomeElements.java) | | -| 1624 | [Largest Substring Between Two Equal Characters](https://leetcode.com/problems/largest-substring-between-two-equal-characters) | [![Java](assets/java.png)](src/LargestSubStringBetweenTwoEqualCharacters.java) | | -| 1629 | [Slowest Key](https://leetcode.com/problems/slowest-key) | [![Java](assets/java.png)](src/SlowestKey.java) | | -| 1636 | [Sort Array by Increasing Frequency](https://leetcode.com/problems/sort-array-by-increasing-frequency) | [![Java](assets/java.png)](src/SortArrayByIncreasingFrequency.java) | | -| 1640 | [Check Array Formation Through Concatenation](https://leetcode.com/problems/check-array-formation-through-concatenation) | [![Java](assets/java.png)](src/CheckArrayFormationThroughConcatenation.java) | | -| 1646 | [Get Maximum in Generated Array](https://leetcode.com/problems/get-maximum-in-generated-array) | [![Java](assets/java.png)](src/GetMaximumInGeneratedArray.java) | | -| 1652 | [Defuse the Bomb](https://leetcode.com/problems/defuse-the-bomb) | [![Java](assets/java.png)](src/DefuseTheBomb.java) | | -| 1656 | [Design an Ordered Stream](https://leetcode.com/problems/design-an-ordered-stream) | [![Java](assets/java.png)](src/DesignAnOrderedStream.java) | | -| 1662 | [Check If Two String Arrays are Equivalent](https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent) | [![Java](assets/java.png)](src/CheckIfTwoStringArraysAreEquivalent.java) | | -| 1668 | [Maximum Repeating Substring](https://leetcode.com/problems/maximum-repeating-substring) | [![Java](assets/java.png)](src/MaximumRepeatingSubString.java) | | -| 1672 | [Richest Customer Wealth](https://leetcode.com/problems/richest-customer-wealth) | [![Java](assets/java.png)](src/RichestCustomerWealth.java) | | -| 1678 | [Goal Parser Interpretation](https://leetcode.com/problems/goal-parser-interpretation) | [![Java](assets/java.png)](src/GoalParserInterpretation.java) | | -| 1684 | [Count the Number of Consistent Strings](https://leetcode.com/problems/count-the-number-of-consistent-strings) | [![Java](assets/java.png)](src/CountTheNumberOfConsistentStrings.java) | | -| 1688 | [Count of Matches in Tournament](https://leetcode.com/problems/count-of-matches-in-tournament) | [![Java](assets/java.png)](src/CountOfMatchesInTournament.java) | | -| 1694 | [Reformat Phone Number](https://leetcode.com/problems/reformat-phone-number) | [![Java](assets/java.png)](src/ReformatPhoneNumber.java) | | -| 1700 | [Number of Students Unable to Eat Lunch](https://leetcode.com/problems/number-of-students-unable-to-eat-lunch) | [![Java](assets/java.png)](src/NumberOfStudentsUnableToEatLunch.java) | | -| 1704 | [Determine if String Halves Are Alike](https://leetcode.com/problems/determine-if-string-halves-are-alike) | [![Java](assets/java.png)](src/DetermineIfStringHalvesAreAlike.java) | | -| 1708 | 🔒 [Largest Subarray Length K](https://leetcode.com/problems/largest-subarray-length-k/) | | | -| 1710 | [Maximum Units on a Truck](https://leetcode.com/problems/maximum-units-on-a-truck/) | [![Java](assets/java.png)](src/MaximumUnitsOnATruck.java) | | -| 1716 | [Calculate Money in Leetcode Bank](https://leetcode.com/problems/calculate-money-in-leetcode-bank) | [![Java](assets/java.png)](src/CalculateMoneyInLeetCodeBank.java) | | -| 1720 | [Decode XORed Array](https://leetcode.com/problems/decode-xored-array) | [![Java](assets/java.png)](src/DecodeXORedArray.java) | | -| 1725 | [Number Of Rectangles That Can Form The Largest Square](https://leetcode.com/problems/number-of-rectangles-that-can-form-the-largest-square) | [![Java](assets/java.png)](src/NumberOfRectanglesThatCanFormTheLargestSquare.java) | | -| 1732 | [Find the Highest Altitude](https://leetcode.com/problems/find-the-highest-altitude) | [![Java](assets/java.png)](src/FindTheHighestAltitude.java) | | -| 1736 | [Latest Time by Replacing Hidden Digits](https://leetcode.com/problems/latest-time-by-replacing-hidden-digits) | [![Java](assets/java.png)](src/LatestTimeByReplacingHiddenDigits.java) | | -| 1742 | [Maximum Number of Balls in a Box](https://leetcode.com/problems/maximum-number-of-balls-in-a-box) | [![Java](assets/java.png)](src/MaximumNumberOfBallsInABox.java) | | -| 1748 | [Sum of Unique Elements](https://leetcode.com/problems/sum-of-unique-elements) | [![Java](assets/java.png)](src/SumOfUniqueElements.java) | | -| 1752 | [Check if Array Is Sorted and Rotated](https://leetcode.com/problems/check-if-array-is-sorted-and-rotated) | [![Java](assets/java.png)](src/CheckIfArrayIsSortedAndRotated.java) | | -| 1758 | [Minimum Changes To Make Alternating Binary String](https://leetcode.com/problems/minimum-changes-to-make-alternating-binary-string) | [![Java](assets/java.png)](src/MinimumChangesToMakeAlternatingBinaryString.java) | | -| 1763 | [Longest Nice Substring](https://leetcode.com/problems/longest-nice-substring) | [![Java](assets/java.png)](src/LongestNiceSubstring.java) | | -| 1768 | [Merge Strings Alternately](https://leetcode.com/problems/merge-strings-alternately) | [![Java](assets/java.png)](src/MergeStringsAlternately.java) | | -| 1773 | [Count Items Matching a Rule](https://leetcode.com/problems/count-items-matching-a-rule) | [![Java](assets/java.png)](src/CountItemsMatchingARule.java) | | -| 1779 | [Find Nearest Point That Has the Same X or Y Coordinate](https://leetcode.com/problems/find-nearest-point-that-has-the-same-x-or-y-coordinate) | [![Java](assets/java.png)](src/FindNearestPointThatHasTheSameXOrYCoordinate.java) | | -| 1784 | [Check if Binary String Has at Most One Segment of Ones](https://leetcode.com/problems/check-if-binary-string-has-at-most-one-segment-of-ones) | [![Java](assets/java.png)](src/CheckIfBinaryStringHasAtMostOneSegmentOfOnes.java) | | -| 1790 | [Check if One String Swap Can Make Strings Equal](https://leetcode.com/problems/check-if-one-string-swap-can-make-strings-equal) | [![Java](assets/java.png)](src/CheckIfOneStringSwapCanMakeStringsEqual.java) | | -| 1791 | [Find Center of Star Graph](https://leetcode.com/problems/find-center-of-star-graph) | [![Java](assets/java.png)](src/FindCenterOfStarGraph.java) | | -| 1796 | [Second Largest Digit in a String](https://leetcode.com/problems/second-largest-digit-in-a-string) | [![Java](assets/java.png)](src/SecondLargestDigitInAString.java) | | -| 1800 | [Maximum Ascending Subarray Sum](https://leetcode.com/problems/maximum-ascending-subarray-sum) | [![Java](assets/java.png)](src/MaximumAscendingSubArraySum.java) | | -| 1805 | [Number of Different Integers in a String](https://leetcode.com/problems/number-of-different-integers-in-a-string) | [![Java](assets/java.png)](src/NumberOfDifferentIntegersInString.java) | | -| 1812 | [Determine Color of a Chessboard Square](https://leetcode.com/problems/determine-color-of-a-chessboard-square) | [![Java](assets/java.png)](src/DetermineColorOfChessboardSquare.java) | | -| 1816 | [Truncate Sentence](https://leetcode.com/problems/truncate-sentence) | [![Java](assets/java.png)](src/TruncateSentences.java) | | -| 1822 | [Sign of the Product of an Array](https://leetcode.com/problems/sign-of-the-product-of-an-array) | [![Java](assets/java.png)](src/SignOfTheProductOfAnArray.java) | | -| 1826 | 🔒 [Faulty Sensor](https://leetcode.com/problems/faulty-sensor) | | | -| 1827 | [Minimum Operations to Make the Array Increasing](https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing) | [![Java](assets/java.png)](src/MinimumOperationsToMakeTheArrayIncreasing.java) | | -| 1832 | [Check if the Sentence Is Pangram](https://leetcode.com/problems/check-if-the-sentence-is-pangram) | [![Java](assets/java.png)](src/CheckIfSentenceIsPangram.java) | | -| 1837 | [Sum of Digits in Base K](https://leetcode.com/problems/sum-of-digits-in-base-k) | [![Java](assets/java.png)](src/SumOfDigitsInBaseK.java) | | -| 1844 | [Replace All Digits with Characters](https://leetcode.com/problems/replace-all-digits-with-characters) | [![Java](assets/java.png)](src/ReplaceAllDigitsWithCharacters.java) | | -| 1848 | [Minimum Distance to the Target Element](https://leetcode.com/problems/minimum-distance-to-the-target-element) | [![Java](assets/java.png)](src/MinimumDistanceToTheTargetElement.java) | | -| 1854 | [Maximum Population Year](https://leetcode.com/problems/maximum-population-year) | [![Java](assets/java.png)](src/MaximumPopulationYear.java) | | -| 1859 | [Sorting the Sentence](https://leetcode.com/problems/sorting-the-sentence) | [![Java](assets/java.png)](src/SortingTheSentence.java) | | -| 1863 | [Sum of All Subset XOR Totals](https://leetcode.com/problems/sum-of-all-subset-xor-totals) | [![Java](assets/java.png)](src/SumOfAllSubsetXORTotals.java) | | -| 1869 | [Longer Contiguous Segments of Ones than Zeros](https://leetcode.com/problems/longer-contiguous-segments-of-ones-than-zeros) | [![Java](assets/java.png)](src/LongerContiguousSegmentOfOnesThanZeros.java) | | -| 1876 | [Substrings of Size Three with Distinct Characters](https://leetcode.com/problems/substrings-of-size-three-with-distinct-characters) | [![Java](assets/java.png)](src/SubstringsOfSizeThreeWithDistinctCharacters.java) | | -| 1880 | [Check if Word Equals Summation of Two Words](https://leetcode.com/problems/check-if-word-equals-summation-of-two-words) | [![Java](assets/java.png)](src/CheckIfWordEqualsSummationOfTwoWords.java) | | -| 1886 | [Determine Whether Matrix Can Be Obtained By Rotation](https://leetcode.com/problems/determine-whether-matrix-can-be-obtained-by-rotation) | [![Java](assets/java.png)](src/DetermineWhetherMatrixCanBeObtainedByRotation.java) | | -| 1893 | [Check if All the Integers in a Range Are Covered](https://leetcode.com/problems/check-if-all-the-integers-in-a-range-are-covered) | [![Java](assets/java.png)](src/CheckIfAllTheIntegersInARangeAreCovered.java) | | -| 1897 | [Redistribute Characters to Make All Strings Equal](https://leetcode.com/problems/redistribute-characters-to-make-all-strings-equal) | [![Java](assets/java.png)](src/RedistributeCharactersToMakeAllStringsEqual.java) | | -| 1903 | [Largest Odd Number in String](https://leetcode.com/problems/largest-odd-number-in-string) | [![Java](assets/java.png)](src/LargestOddNumberInString.java) | | -| 1909 | [Remove One Element to Make the Array Strictly Increasing](https://leetcode.com/problems/remove-one-element-to-make-the-array-strictly-increasing) | [![Java](assets/java.png)](src/RemoveOneElementToMakeTheArrayStrictlyIncreasing.java) | | -| 1913 | [Maximum Product Difference Between Two Pairs](https://leetcode.com/problems/maximum-product-difference-between-two-pairs) | [![Java](assets/java.png)](src/MaximumProductDifferenceBetweenTwoPairs.java) | | -| 1920 | [Build Array from Permutation](https://leetcode.com/problems/build-array-from-permutation) | [![Java](assets/java.png)](src/BuildArrayFromPermutation.java) | | -| 1925 | [Count Square Sum Triples](https://leetcode.com/problems/count-square-sum-triples) | [![Java](assets/java.png)](src/CountSquareSumTriplets.java) | | -| 1929 | [Concatenation of Array](https://leetcode.com/problems/concatenation-of-array) | [![Java](assets/java.png)](src/ConcatenationOfArray.java) | | -| 1933 | 🔒 [Check If String Is Decomposable Into Value EqualSubstrings](https://leetcode.com/problems/check-if-string-is-decomposable-into-value-equal-substring) | | | -| 1935 | [Maximum Number of Words You Can Type](https://leetcode.com/problems/maximum-number-of-words-you-can-type) | [![Java](assets/java.png)](src/MaximumNumberOfWordsYouCanType.java) | | -| 1941 | [Check if All Characters Have Equal Number of Occurrences](https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences) | [![Java](assets/java.png)](src/CheckIfAllCharactersHaveEqualNumberOfOccurrences.java) | | -| 1945 | [Sum of Digits of String After Convert](https://leetcode.com/problems/sum-of-digits-of-string-after-convert) | [![Java](assets/java.png)](src/SumOfDigitsOfStringAfterConvert.java) | | -| 1952 | [Three Divisors](https://leetcode.com/problems/three-divisors) | [![Java](assets/java.png)](src/ThreeDivisors.java) | | -| 1957 | [Delete Characters to Make Fancy String](https://leetcode.com/problems/delete-characters-to-make-fancy-string) | [![Java](assets/java.png)](src/DeleteCharactersToMakeFancyString.java) | | -| 1961 | [Check If String Is a Prefix of Array](https://leetcode.com/problems/check-if-string-is-a-prefix-of-array) | [![Java](assets/java.png)](src/CheckIfStringIsAPrefixOfArray.java) | | -| 1967 | [Number of Strings That Appear as Substrings in Word](https://leetcode.com/problems/number-of-strings-that-appear-as-substrings-in-word) | [![Java](assets/java.png)](src/NumberOfStringsThatAppearAsSubstringsInWord.java) | | -| 1971 | [Find if Path Exists in Graph](https://leetcode.com/problems/find-if-path-exists-in-graph) | [![Java](assets/java.png)](src/FindIfPathExistsInGraph.java) | | -| 1974 | [Minimum Time to Type Word Using Special Typewriter](https://leetcode.com/problems/minimum-time-to-type-word-using-special-typewriter) | [![Java](assets/java.png)](src/MinimumTimeToTypeWordUsingSpecialTypewriter.java) | | -| 1979 | [Find Greatest Common Divisor of Array](https://leetcode.com/problems/find-greatest-common-divisor-of-array) | [![Java](assets/java.png)](src/FindGreatestCommonDivisorOfArray.java) | | -| 1984 | [Minimum Difference Between Highest and Lowest of K Scores](https://leetcode.com/problems/minimum-difference-between-highest-and-lowest-of-k-scores) | [![Java](assets/java.png)](src/MinimumDifferenceBetweenHighestAndLowestOfKScores.java) | | -| 1991 | [Find the Middle Index in Array](https://leetcode.com/problems/find-the-middle-index-in-array) | [![Java](assets/java.png)](src/FindTheMiddleIndexInArray.java) | | -| 1995 | [Count Special Quadruplets](https://leetcode.com/problems/count-special-quadruplets) | [![Java](assets/java.png)](src/CountSpecialQuadruplets.java) | | -| 2000 | [Reverse Prefix of Word](https://leetcode.com/problems/reverse-prefix-of-word) | [![Java](assets/java.png)](src/ReversePrefixOfWord.java) | | -| 2006 | [Count Number of Pairs With Absolute Difference K](https://leetcode.com/problems/count-number-of-pairs-with-absolute-difference-k) | [![Java](assets/java.png)](src/CountNumberOfPairsWithAbsoluteDifferenceK.java) | | -| 2011 | [Final Value of Variable After Performing Operations](https://leetcode.com/problems/final-value-of-variable-after-performing-operations) | [![Java](assets/java.png)](src/FinalValueOfVariableAfterPerformingOperations.java) | | -| 2016 | [Maximum Difference Between Increasing Elements](https://leetcode.com/problems/maximum-difference-between-increasing-elements) | [![Java](assets/java.png)](src/MaximumDifferenceBetweenIncreasingElements.java) | | -| 2022 | [Convert 1D Array Into 2D Array](https://leetcode.com/problems/convert-1d-array-into-2d-array) | [![Java](assets/java.png)](src/Convert1DArrayInto2DArray.java) | | -| 2027 | [Minimum Moves to Convert String](https://leetcode.com/problems/minimum-moves-to-convert-string) | [![Java](assets/java.png)](src/MinimumMovesToConvertString.java) | | -| 2032 | [Two Out of Three](https://leetcode.com/problems/two-out-of-three) | [![Java](assets/java.png)](src/TwoOutOfThree.java) | | -| 2037 | [Minimum Number of Moves to Seat Everyone](https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone) | [![Java](assets/java.png)](src/MinimumNumberOfMovesToSeatEveryone.java) | | -| 2042 | [Check if Numbers Are Ascending in a Sentence](https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence) | [![Java](assets/java.png)](src/CheckIfNumbersAreAscendingInASentence.java) | | -| 2047 | [Number of Valid Words in a Sentence](https://leetcode.com/problems/number-of-valid-words-in-a-sentence) | [![Java](assets/java.png)](src/NumberOfValidWordsInASentence.java) | | -| 2053 | [Kth Distinct String in an Array](https://leetcode.com/problems/kth-distinct-string-in-an-array) | [![Java](assets/java.png)](src/KthDistinctStringInAnArray.java) | | -| 2057 | [Smallest Index With Equal Value](https://leetcode.com/problems/smallest-index-with-equal-value) | [![Java](assets/java.png)](src/SmallestIndexWithEqualValue.java) | | -| 2062 | [Count Vowel Substrings of a String](https://leetcode.com/problems/count-vowel-substrings-of-a-string) | [![Java](assets/java.png)](src/CountVowelSubstringsOfAString.java) | | -| 2068 | [Check Whether Two Strings are Almost Equivalent](https://leetcode.com/problems/check-whether-two-strings-are-almost-equivalent) | [![Java](assets/java.png)](src/CheckWhetherTwoStringsAreAlmostEquivalent.java) | | -| 2073 | [Time Needed to Buy Tickets](https://leetcode.com/problems/time-needed-to-buy-tickets) | [![Java](assets/java.png)](src/TimeNeededToBuyTickets.java) | | -| 2078 | [Two Furthest Houses With Different Colors](https://leetcode.com/problems/two-furthest-houses-with-different-colors) | [![Java](assets/java.png)](src/TwoFurthestHousesWithDifferentColors.java) | | -| 2085 | [Count Common Words With One Occurrence](https://leetcode.com/problems/count-common-words-with-one-occurrence) | [![Java](assets/java.png)](src/CountCommonWordsWithOneOccurrence.java) | | -| 2089 | [Find Target Indices After Sorting Array](https://leetcode.com/problems/find-target-indices-after-sorting-array) | [![Java](assets/java.png)](src/FindTargetIndicesAfterSortingArray.java) | | -| 2094 | [Finding 3-Digit Even Numbers](https://leetcode.com/problems/finding-3-digit-even-numbers) | [![Java](assets/java.png)](src/Finding3DigitEvenNumbers.java) | | -| 2099 | [Find Subsequence of Length K With the Largest Sum](https://leetcode.com/problems/find-subsequence-of-length-k-with-the-largest-sum) | [![Java](assets/java.png)](src/FindSubsequenceOfLengthKWithTheLargestSum.java) | | -| 2103 | [Rings and Rods](https://leetcode.com/problems/rings-and-rods) | [![Java](assets/java.png)](src/RingsAndRods.java) | | -| 2108 | [Find First Palindromic String in the Array](https://leetcode.com/problems/find-first-palindromic-string-in-the-array) | [![Java](assets/java.png)](src/FindFirstPalindromicStringInArray.java) | | -| 2114 | [Maximum Number of Words Found in Sentences](https://leetcode.com/problems/maximum-number-of-words-found-in-sentences) | [![Java](assets/java.png)](src/MaximumNumberOfWordsFoundInSentences.java) | | -| 2119 | [A Number After a Double Reversal](https://leetcode.com/problems/a-number-after-a-double-reversal) | [![Java](assets/java.png)](src/ANumberAfterADoubleReversal.java) | | -| 2124 | [Check if All A's Appears Before All B's](https://leetcode.com/problems/check-if-all-as-appears-before-all-bs) | [![Java](assets/java.png)](src/CheckIfAllTheAsAppearBeforeAllTheBs.java) | | -| 2129 | [Capitalize the Title](https://leetcode.com/problems/capitalize-the-title) | [![Java](assets/java.png)](src/CapitalizeTheTitle.java) | | -| 2133 | [Check if Every Row and Column Contains All Numbers](https://leetcode.com/problems/check-if-every-row-and-column-contains-all-numbers) | [![Java](assets/java.png)](src/CheckIfEveryRowAndEveryColumnContainAllNumbers.java) | | -| 2138 | [Divide a String Into Groups of Size k](https://leetcode.com/problems/divide-a-string-into-groups-of-size-k) | [![Java](assets/java.png)](src/DivideTheStringIntoGroupsOfSizeK.java) | | -| 2144 | [Minimum Cost of Buying Candies With Discount](https://leetcode.com/problems/minimum-cost-of-buying-candies-with-discount) | [![Java](assets/java.png)](src/MinimumCostOfBuyingCandiesWithDiscount.java) | | -| 2148 | [Count Elements With Strictly Smaller and Greater Elements](https://leetcode.com/problems/count-elements-with-strictly-smaller-and-greater-elements) | [![Java](assets/java.png)](src/CountElementsWithStrictlySmallerAndGreaterElements.java) | | -| 2154 | [Keep Multiplying Found Values by Two](https://leetcode.com/problems/keep-multiplying-found-values-by-two) | [![Java](assets/java.png)](src/KeepMultiplyingFoundValuesByTwo.java) | | -| 2160 | [Minimum Sum of Four Digit Number After Splitting Digits](https://leetcode.com/problems/minimum-sum-of-four-digit-number-after-splitting-digits) | [![Java](assets/java.png)](src/MinimumSumOfFourDigitNumberAfterSplittingDigits.java) | | -| 2164 | [Sort Even and Odd Indices Independently](https://leetcode.com/problems/sort-even-and-odd-indices-independently) | [![Java](assets/java.png)](src/SortEvenAndOddIndicesIndependently.java) | | -| 2169 | [Count Operations to Obtain Zero](https://leetcode.com/problems/count-operations-to-obtain-zero) | [![Java](assets/java.png)](src/CountOperationsToObtainZero.java) | | -| 2176 | [Count Equal and Divisible Pairs in an Array](https://leetcode.com/problems/count-equal-and-divisible-pairs-in-an-array) | [![Java](assets/java.png)](src/CountEqualAndDivisiblePairsInAnArray.java) | | -| 2180 | [Count Integers With Even Digit Sum](https://leetcode.com/problems/count-integers-with-even-digit-sum) | [![Java](assets/java.png)](src/CountIntegersWithEvenDigitSum.java) | | -| 2185 | [Counting Words With a Given Prefix](https://leetcode.com/problems/counting-words-with-a-given-prefix) | [![Java](assets/java.png)](src/CountingWordsWithAGivenPrefix.java) | | -| 2190 | [Most Frequent Number Following Key In an Array](https://leetcode.com/problems/most-frequent-number-following-key-in-an-array) | [![Java](assets/java.png)](src/MostFrequentNumberFollowingKeyInAnArray.java) | | -| 2194 | [Cells in a Range on an Excel Sheet](https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet) | [![Java](assets/java.png)](src/CellsInARangeOnAnExcelSheet.java) | | -| 2200 | [Find All K-Distant Indices in an Array](https://leetcode.com/problems/find-all-k-distant-indices-in-an-array) | [![Java](assets/java.png)](src/FindAllKDistantIndicesInAnArray.java) | | -| 2206 | [Divide Array Into Equal Pairs](https://leetcode.com/problems/divide-array-into-equal-pairs) | [![Java](assets/java.png)](src/DivideArrayIntoEqualPairs.java) | | -| 2210 | [Count Hills and Valleys in an Array](https://leetcode.com/problems/count-hills-and-valleys-in-an-array) | [![Java](assets/java.png)](src/CountHillsAndValleysInAnArray.java) | | -| 2215 | [Find the Difference of Two Arrays](https://leetcode.com/problems/find-the-difference-of-two-arrays) | [![Java](assets/java.png)](src/FindTheDifferenceOfTwoArrays.java) | | -| 2220 | [Minimum Bit Flips to Convert Number](https://leetcode.com/problems/minimum-bit-flips-to-convert-number) | [![Java](assets/java.png)](src/MinimumBitFlipsToConvertNumber.java) | | -| 2224 | [Minimum Number of Operations to Convert Time](https://leetcode.com/problems/minimum-number-of-operations-to-convert-time) | [![Java](assets/java.png)](src/MinimumNumberOfOperationsToConvertTime.java) | | -| 2229 | 🔒 [Check if an array is consecutive](https://leetcode.com/problems/check-if-an-array-is-consecutive) | | | -| 2231 | [Largest Number After Digit Swaps by Parity](https://leetcode.com/problems/largest-number-after-digit-swaps-by-parity) | [![Java](assets/java.png)](src/LargestNumberAfterDigitSwapsByParity.java) | | -| 2235 | [Add Two Integers](https://leetcode.com/problems/add-two-integers) | [![Java](assets/java.png)](src/AddTwoIntegers.java) | | -| 2236 | [Root Equals Sum of Children](https://leetcode.com/problems/root-equals-sum-of-children) | [![Java](assets/java.png)](src/RootEqualsSumOfChildren.java) | | -| 2239 | [Find Closest Number to Zero](https://leetcode.com/problems/find-closest-number-to-zero) | [![Java](assets/java.png)](src/FindClosestNumberToZero.java) | | -| 2243 | [Calculate Digit Sum of a String](https://leetcode.com/problems/calculate-digit-sum-of-a-string) | [![Java](assets/java.png)](src/CalculateDigitSumOfAString.java) | | -| 2248 | [Intersection of Multiple Arrays](https://leetcode.com/problems/intersection-of-multiple-arrays) | [![Java](assets/java.png)](src/IntersectionOfMultipleArrays.java) | | -| 2255 | [Count Prefixes of a Given String](https://leetcode.com/problems/count-prefixes-of-a-given-string) | [![Java](assets/java.png)](src/CountPrefixesOfAGivenString.java) | | -| 2259 | [Remove Digit From Number to Maximize Result](https://leetcode.com/problems/remove-digit-from-number-to-maximize-result) | [![Java](assets/java.png)](src/RemoveDigitFromNumberToMaximizeResult.java) | | -| 2264 | [Largest 3-Same-Digit Number in String](https://leetcode.com/problems/largest-3-same-digit-number-in-string) | [![Java](assets/java.png)](src/Largest3SameDigitNumberInString.java) | | -| 2269 | [Find the K-Beauty of a Number](https://leetcode.com/problems/find-the-k-beauty-of-a-number) | [![Java](assets/java.png)](src/FindTheKBeautyOfANumber.java) | | -| 2273 | [Find Resultant Array After Removing Anagrams](https://leetcode.com/problems/find-resultant-array-after-removing-anagrams) | [![Java](assets/java.png)](src/FindResultantArrayAfterRemovingAnagrams.java) | | -| 2278 | [Percentage of Letter in String](https://leetcode.com/problems/percentage-of-letter-in-string) | [![Java](assets/java.png)](src/PercentageOfLetterInString.java) | | -| 2283 | [Check if Number Has Equal Digit Count and Digit Value](https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value) | [![Java](assets/java.png)](src/CheckIfNumberHasEqualDigitCountAndDigitValue.java) | | -| 2287 | [Rearrange Characters to Make Target String](https://leetcode.com/problems/rearrange-characters-to-make-target-string) | [![Java](assets/java.png)](src/RearrangeCharactersToMakeTargetString.java) | | -| 2293 | [Min Max Game](https://leetcode.com/problems/min-max-game) | [![Java](assets/java.png)](src/MinMaxGame.java) | | -| 2299 | [Strong Password Checker II](https://leetcode.com/problems/strong-password-checker-ii) | [![Java](assets/java.png)](src/StrongPasswordCheckerII.java) | | -| 2300 | [Successful Pairs of Spells and Potions](https://leetcode.com/problems/successful-pairs-of-spells-and-potions) | [![Python](assets/python.png)](python/successfull_pairs_of_spells_and_potions.py) | | -| 2303 | [Calculate Amount Paid in Taxes](https://leetcode.com/problems/calculate-amount-paid-in-taxes) | [![Java](assets/java.png)](src/CalculateAmountPaidInTaxes.java) | | -| 2309 | [Greatest English Letter in Upper and Lower Case](https://leetcode.com/problems/greatest-english-letter-in-upper-and-lower-case) | [![Java](assets/java.png)](src/GreatestEnglishLetterInUpperAndLowerCase.java) | | -| 2315 | [Count Asterisks](https://leetcode.com/problems/count-asterisks) | [![Java](assets/java.png)](src/CountAsterisks.java) [![Python](assets/python.png)](python/successfull_pairs_of_spells_and_potions.py) | | -| 2316 | [Count Unreachable Pairs of Nodes in an Undirected Graph](https://leetcode.com/problems/count-unreachable-pairs-of-nodes-in-an-undirected-graph) | [![Python](assets/python.png)](python/count_unreachable_pair_of_node_in_an_undirectable_graph.py) | | -| 2319 | [Check if Matrix Is X-Matrix](https://leetcode.com/problems/check-if-matrix-is-x-matrix) | [![Java](assets/java.png)](src/CountAsterisks.java) | | -| 2325 | [Decode the Message](https://leetcode.com/problems/decode-the-message) | [![Java](assets/java.png)](src/DecodeTheMessage.java) | | -| 2331 | [Evaluate Boolean Binary Tree](https://leetcode.com/problems/evaluate-boolean-binary-tree) | [![Java](assets/java.png)](src/EvaluateBooleanBinaryTree.java) | | -| 2335 | [Minimum Amount of Time to Fill Cups](https://leetcode.com/problems/minimum-amount-of-time-to-fill-cups) | [![Java](assets/java.png)](src/MinimumAmountOfTimeToFillCups.java) | | -| 2439 | [Minimize Maximum of Array](https://leetcode.com/problems/minimize-maximum-of-array) | [![Python](assets/python.png)](python/minimize_maximum_of_array.py) | | -| 2341 | [Maximum Number of Pairs in Array](https://leetcode.com/problems/maximum-number-of-pairs-in-array) | [![Java](assets/java.png)](src/MaximumNumberOfPairsInArray.java) | | -| 2347 | [Best Poker Hand](https://leetcode.com/problems/best-poker-hand) | [![Java](assets/java.png)](src/BestPokerHand.java) | | -| 2348 | [Number of Zero-Filled Subarrays](https://leetcode.com/problems/number-of-zero-filled-subarrays) | [![Python](assets/python.png)](python/number_of_zero_filled_subarrays.py) | | -| 2351 | [First Letter to Appear Twice](https://leetcode.com/problems/first-letter-to-appear-twice) | [![Java](assets/java.png)](src/FirstLetterToAppearTwice.java) | | -| 2357 | [Make Array Zero by Subtracting Equal Amounts](https://leetcode.com/problems/make-array-zero-by-subtracting-equal-amounts) | [![Java](assets/java.png)](src/MakeArrayZeroBySubtractingEqualAmounts.java) | | -| 2360 | [Longest Cycle in a Graph](https://leetcode.com/problems/longest-cycle-in-a-graph) | [![Python](assets/python.png)](python/longest_cycle_in_graph.py) | | -| 2363 | [Merge Similar Items](https://leetcode.com/problems/merge-similar-items) | [![Java](assets/java.png)](src/MergeSimilarItems.java) | | -| 2367 | [Number of Arithmetic Triplets](https://leetcode.com/problems/number-of-arithmetic-triplets) | [![Java](assets/java.png)](src/NumberOfArithmeticTriplets.java) | | -| 2373 | [Largest Local Values in a Matrix](https://leetcode.com/problems/largest-local-values-in-a-matrix) | [![Java](assets/java.png)](src/LargestLocalValuesInAMatrix.java) | | -| 2379 | [Minimum Recolors to Get K Consecutive Black Blocks](https://leetcode.com/problems/minimum-recolors-to-get-k-consecutive-black-blocks) | [![Java](assets/java.png)](src/MinimumRecolorsToGetKConsecutiveBlackBlocks.java) | | -| 2383 | [Minimum Hours of Training to Win a Competition](https://leetcode.com/problems/minimum-hours-of-training-to-win-a-competition) | [![Java](assets/java.png)](src/MinimumHoursOfTrainingToWinACompetition.java) | | -| 2389 | [Longest Subsequence With Limited Sum](https://leetcode.com/problems/longest-subsequence-with-limited-sum) | [![Java](assets/java.png)](src/LongestSubsequenceWithLimitedSum.java) | | -| 2395 | [Find Subarrays With Equal Sum](https://leetcode.com/problems/find-subarrays-with-equal-sum) | [![Java](assets/java.png)](src/FindSubarraysWithEqualSum.java) | | -| 2399 | [Check Distances Between Same Letters](https://leetcode.com/problems/check-distances-between-same-letters) | [![Java](assets/java.png)](src/CheckDistancesBetweenSameLetters.java) | | -| 2404 | [Most Frequent Even Element](https://leetcode.com/problems/most-frequent-even-element) | [![Java](assets/java.png)](src/MostFrequentEvenElement.java) | | -| 2409 | [Count Days Spent Together](https://leetcode.com/problems/count-days-spent-together) | [![Java](assets/java.png)](src/CountDaysSpentTogether.java) | | -| 2413 | [Smallest Even Multiple](https://leetcode.com/problems/smallest-even-multiple) | [![Java](assets/java.png)](src/SmallestEvenMultiple.java) | | -| 2418 | [Sort the People](https://leetcode.com/problems/sort-the-people) | [![Java](assets/java.png)](src/SortThePeople.java) | | -| 2423 | [Remove Letter To Equalize Frequency](https://leetcode.com/problems/remove-letter-to-equalize-frequency) | [![Java](assets/java.png)](src/RemoveLetterToEqualizeFrequency.java) | | -| 2427 | [Number of Common Factors](https://leetcode.com/problems/number-of-common-factors) | [![Java](assets/java.png)](src/NumberOfCommonFactors.java) | | -| 2432 | [The Employee That Worked on the Longest Task](https://leetcode.com/problems/the-employee-that-worked-on-the-longest-task) | [![Java](assets/java.png)](src/TheEmployeeThatWorkedOnTheLongestTask.java) | | -| 2437 | [Number of Valid Clock Times](https://leetcode.com/problems/number-of-valid-clock-times) | [![Java](assets/java.png)](src/NumberOfValidClockTimes.java) | | -| 2441 | [Largest Positive Integer That Exists With Its Negative](https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative) | [![Java](assets/java.png)](src/LargestPositiveIntegerThatExistsWithItsNegative.java) | | -| 2446 | [Determine if Two Events Have Conflict](https://leetcode.com/problems/determine-if-two-events-have-conflict) | [![Java](assets/java.png)](src/DetermineIfTwoEventsHaveConflict.java) | | -| 2451 | [Odd String Difference](https://leetcode.com/problems/odd-string-difference) | [![Java](assets/java.png)](src/OddStringDifference.java) | | -| 2455 | [Average Value of Even Numbers That Are Divisible by Three](https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three) | [![Java](assets/java.png)](src/AverageValueOfEvenNumbersThatAreDivisibleByThree.java) | | -| 2460 | [Apply Operations to an Array](https://leetcode.com/problems/apply-operations-to-an-array) | [![Java](assets/java.png)](src/ApplyOperationsToAnArray.java) | | -| 2465 | [Number of Distinct Averages](https://leetcode.com/problems/number-of-distinct-averages) | [![Java](assets/java.png)](src/NumberOfDistinctAverages.java) | | -| 2466 | [Count Ways To Build Good Strings](https://leetcode.com/problems/count-ways-to-build-good-strings) | | | -| 2469 | [Convert the Temperature](https://leetcode.com/problems/convert-the-temperature) | [![Java](assets/java.png)](src/ConvertTheTemperature.java) | | -| 2475 | [Number of Unequal Triplets in Array](https://leetcode.com/problems/number-of-unequal-triplets-in-array) | [![Java](assets/java.png)](src/NumberOfUnequalTripletsInArray.java) | | -| 2481 | [Minimum Cuts to Divide a Circle](https://leetcode.com/problems/minimum-cuts-to-divide-a-circle) | [![Java](assets/java.png)](src/MinimumCutsToDivideACircle.java) | | -| 2485 | [Find the Pivot Integer](https://leetcode.com/problems/find-the-pivot-integer) | [![Java](assets/java.png)](src/FindThePivotInteger.java) | | -| 2490 | [Circular Sentence](https://leetcode.com/problems/circular-sentence) | [![Java](assets/java.png)](src/CircularSentence.java) | | -| 2492 | [Minimum Score of a Path Between Two Cities](https://leetcode.com/problems/minimum-score-of-a-path-between-two-cities) | [![Python](assets/python.png)](python/minimum_score_of_a_path_between_two_cities.py) | | -| 2496 | [Maximum Value of a String in an Array](https://leetcode.com/problems/maximum-value-of-a-string-in-an-array) | [![Java](assets/java.png)](src/MaximumValueOfAStringInAnArray.java) | | -| 2500 | [Delete Greatest Value in Each Row](https://leetcode.com/problems/delete-greatest-value-in-each-row) | [![Java](assets/java.png)](src/DeleteGreatestValueInEachRow.java) | | -| 2506 | [Count Pairs Of Similar Strings](https://leetcode.com/problems/count-pairs-of-similar-strings) | [![Java](assets/java.png)](src/CountPairsOfSimilarStrings.java) | | -| 2511 | [Maximum Enemy Forts That Can Be Captured](https://leetcode.com/problems/maximum-enemy-forts-that-can-be-captured) | [![Java](assets/java.png)](src/MaximumEnemyFortsThatCanBeCaptured.java) | | -| 2515 | [Shortest Distance to Target String in a Circular Array](https://leetcode.com/problems/shortest-distance-to-target-string-in-a-circular-array) | [![Java](assets/java.png)](src/ShortestDistanceToTargetStringInACircularArray.java) | | -| 2520 | [Count the Digits That Divide a Number](https://leetcode.com/problems/count-the-digits-that-divide-a-number) | [![Java](assets/java.png)](src/CountTheDigitsThatDivideANumber.java) | | -| 2525 | [Categorize Box According to Criteria](https://leetcode.com/problems/categorize-box-according-to-criteria) | [![Java](assets/java.png)](src/CategorizeBoxAccordingToCriteria.java) | | -| 2529 | [Maximum Count of Positive Integer and Negative Integer](https://leetcode.com/problems/maximum-count-of-positive-integer-and-negative-integer) | [![Java](assets/java.png)](src/MaximumCountOfPositiveIntegerAndNegativeInteger.java) | | -| 2535 | [Difference Between Element Sum and Digit Sum of an Array](https://leetcode.com/problems/difference-between-element-sum-and-digit-sum-of-an-array) | [![Java](assets/java.png)](src/DifferenceBetweenElementSumAndDigitSumOfAnArray.java) | | -| 2540 | [Minimum Common Value](https://leetcode.com/problems/minimum-common-value) | [![Java](assets/java.png)](src/MinimumCommonValue.java) | | -| 2544 | [Alternating Digit Sum](https://leetcode.com/problems/alternating-digit-sum) | [![Java](assets/java.png)](src/AlternatingDigitSum.java) | | -| 2549 | [Count Distinct Numbers on Board](https://leetcode.com/problems/count-distinct-numbers-on-board) | [![Java](assets/java.png)](src/CountDistinctNumbersOnBoard.java) | | -| 2553 | [Separate the Digits in an Array](https://leetcode.com/problems/separate-the-digits-in-an-array) | [![Java](assets/java.png)](src/SeparateTheDigitsInAnArray.java) | | -| 2558 | [Take Gifts From the Richest Pile](https://leetcode.com/problems/take-gifts-from-the-richest-pile) | [![Java](assets/java.png)](src/TakeGiftsFromTheRichestPile.java) | | -| 2562 | [Find the Array Concatenation Value](https://leetcode.com/problems/find-the-array-concatenation-value) | [![Java](assets/java.png)](src/FindTheArrayConcatenationValue.java) | | -| 2566 | [Maximum Difference by Remapping a Digit](https://leetcode.com/problems/maximum-difference-by-remapping-a-digit) | [![Java](assets/java.png)](src/MaximumDifferenceByRemappingADigit.java) | | -| 2570 | [Merge Two 2D Arrays by Summing Values](https://leetcode.com/problems/merge-two-2d-arrays-by-summing-values) | [![Java](assets/java.png)](src/MergeTwo2DArraysBySummingValues.java) | | -| 2574 | [Left and Right Sum Differences](https://leetcode.com/problems/left-and-right-sum-differences) | [![Java](assets/java.png)](src/LeftAndRightSumDifferences.java) | | -| 2578 | [Split With Minimum Sum](https://leetcode.com/problems/split-with-minimum-sum) | [![Java](assets/java.png)](src/SplitWithMinimumSum.java) | | -| 2582 | [Pass the Pillow](https://leetcode.com/problems/pass-the-pillow) | [![Java](assets/java.png)](src/PassThePillow.java) | | -| 2586 | [Count the Number of Vowel Strings in Range](https://leetcode.com/problems/count-the-number-of-vowel-strings-in-range) | [![Java](assets/java.png)](src/CountTheNumberOfVowelStringsInRange.java) | | -| 2591 | [Distribute Money to Maximum Children](https://leetcode.com/problems/distribute-money-to-maximum-children) | [![Java](assets/java.png)](src/DistributeMoneyToMaximumChildren.java) | | -| 2595 | [Number of Even and Odd Bits](https://leetcode.com/problems/number-of-even-and-odd-bits) | [![Java](assets/java.png)](src/NumberOfEvenAndOddBits.java) | | -| 2600 | [K Items With the Maximum Sum](https://leetcode.com/problems/k-items-with-the-maximum-sum) | [![Java](assets/java.png)](src/KItemsWithTheMaximumSum.java) | | -| 2605 | [Form Smallest Number From Two Digit Arrays](https://leetcode.com/problems/form-smallest-number-from-two-digit-arrays) | [![Java](assets/java.png)](src/FormSmallestNumberFromTwoDigitArrays.java) | | -| 2609 | [Find the Longest Balanced Substring of a Binary String](https://leetcode.com/problems/find-the-longest-balanced-substring-of-a-binary-string) | [![Java](assets/java.png)](src/FindTheLongestBalancedSubstringOfABinaryString.java) | | -| 2614 | [Prime In Diagonal](https://leetcode.com/problems/prime-in-diagonal) | [![Java](assets/java.png)](src/PrimeInDiagonal.java) | | -| 2639 | [Find the Width of Columns of a Grid](https://leetcode.com/problems/find-the-width-of-columns-of-a-grid) | [![Java](assets/java.png)](src/FindTheWidthOfColumnsOfAGrid.java) | | -| 2643 | [Row With Maximum Ones](https://leetcode.com/problems/row-with-maximum-ones) | [![Java](assets/java.png)](src/RowWithMaximumOnes.java) | | -| 2644 | [Find the Maximum Divisibility Score](https://leetcode.com/problems/find-the-maximum-divisibility-score) | [![Java](assets/java.png)](src/FindTheMaximumDivisibilityScore.java) | | -| 2651 | [Calculate Delayed Arrival Time](https://leetcode.com/problems/calculate-delayed-arrival-time) | [![Java](assets/java.png)](src/CalculateDelayedArrivalTime.java) | | -| 2652 | [Sum Multiples](https://leetcode.com/problems/sum-multiples) | [![Java](assets/java.png)](src/SumMultiples.java) | | -| 2656 | [Maximum Sum With Exactly K Elements](https://leetcode.com/problems/maximum-sum-with-exactly-k-elements) | [![Java](assets/java.png)](src/MaximumSumWithExactlyKElements.java) | | -| 2660 | [Determine the Winner of a Bowling Game](https://leetcode.com/problems/determine-the-winner-of-a-bowling-game) | [![Java](assets/java.png)](src/DetermineTheWinnerOfABowlingGame.java) | | -| 2670 | [Find the Distinct Difference Array](https://leetcode.com/problems/find-the-distinct-difference-array) | [![Java](assets/java.png)](src/FindTheDistinctDifferenceArray.java) | | -| 2678 | [Number of Senior Citizens](https://leetcode.com/problems/number-of-senior-citizens) | [![Java](assets/java.png)](src/NumberOfSeniorCitizens.java) | | -| 2682 | [Find the Losers of the Circular Game](https://leetcode.com/problems/find-the-losers-of-the-circular-game) | [![Java](assets/java.png)](src/FindTheLosersOfTheCircularGame.java) | | -| 2696 | [Minimum String Length After Removing Substrings](https://leetcode.com/problems/minimum-string-length-after-removing-substrings) | [![Java](assets/java.png)](src/MinimumStringLengthAfterRemovingSubstrings.java) | | -| 2697 | [Lexicographically Smallest Palindrome](https://leetcode.com/problems/lexicographically-smallest-palindrome) | [![Java](assets/java.png)](src/LexicographicallySmallestPalindrome.java) | | -| 2706 | [Buy Two Chocolates](https://leetcode.com/problems/buy-two-chocolates) | [![Java](assets/java.png)](src/BuyTwoChocolates.java) | | -| 2710 | [Remove Trailing Zeros From a String](https://leetcode.com/problems/remove-trailing-zeros-from-a-string) | [![Java](assets/java.png)](src/RemoveTrailingZerosFromAString.java) | | -| 2716 | [Minimize String Length](https://leetcode.com/problems/minimize-string-length) | [![Java](assets/java.png)](src/MinimizeStringLength.java) | | -| 2717 | [Semi-Ordered Permutation](https://leetcode.com/problems/semi-ordered-permutation) | [![Java](assets/java.png)](src/SemiOrderedPermutation.java) | | -| 2728 | [Count Houses in a Circular Street](https://leetcode.com/problems/count-houses-in-a-circular-street) | | | -| 2729 | [Check if The Number is Fascinating](https://leetcode.com/problems/check-if-the-number-is-fascinating) | [![Java](assets/java.png)](src/CheckIfTheNumberIsFascinating.java) | | -| 2733 | [Neither Minimum nor Maximum](https://leetcode.com/problems/neither-minimum-nor-maximum) | [![Java](assets/java.png)](src/NeitherMinimumNorMaximum.java) | | -| 2739 | [Total Distance Traveled](https://leetcode.com/problems/total-distance-traveled) | [![Java](assets/java.png)](src/TotalDistanceTraveled.java) | | -| 2744 | [Find Maximum Number of String Pairs](https://leetcode.com/problems/find-maximum-number-of-string-pairs) | [![Java](assets/java.png)](src/FindMaximumNumberOfStringPairs.java) | | -| 2748 | [Number of Beautiful Pairs](https://leetcode.com/problems/number-of-beautiful-pairs) | [![Java](assets/java.png)](src/NumberOfBeautifulPairs.java) | | -| 2760 | [Longest Even Odd Subarray With Threshold](https://leetcode.com/problems/longest-even-odd-subarray-with-threshold) | [![Java](assets/java.png)](src/LongestEvenOddSubarrayWithThreshold.java) | | -| 2765 | [Longest Alternating Subarray](https://leetcode.com/problems/longest-alternating-subarray) | [![Java](assets/java.png)](src/LongestAlternatingSubarray.java) | | -| 2769 | [Find the Maximum Achievable Number](https://leetcode.com/problems/find-the-maximum-achievable-number) | [![Java](assets/java.png)](src/FindTheMaximumAchievableNumber.java) | | -| 2778 | [Sum of Squares of Special Elements](https://leetcode.com/problems/sum-of-squares-of-special-elements) | [![Java](assets/java.png)](src/SumOfSquaresOfSpecialElements.java) | | -| 2784 | [Check if Array is Good](https://leetcode.com/problems/check-if-array-is-good) | [![Java](assets/java.png)](src/CheckIfArrayIsGood.java) | | -| 2788 | [Split Strings by Separator](https://leetcode.com/problems/split-strings-by-separator) | [![Java](assets/java.png)](src/SplitStringsBySeparator.java) | | -| 2798 | [Number of Employees Who Met the Target](https://leetcode.com/problems/number-of-employees-who-met-the-target) | [![Java](assets/java.png)](src/NumberOfEmployeesWhoMetTheTarget.java) | | -| 2806 | [Account Balance After Rounded Purchase](https://leetcode.com/problems/account-balance-after-rounded-purchase) | [![Java](assets/java.png)](src/AccountBalanceAfterRoundedPurchase.java) | | -| 2810 | [Faulty Keyboard](https://leetcode.com/problems/faulty-keyboard) | [![Java](assets/java.png)](src/FaultyKeyboard.java) | | -| 2815 | [Max Pair Sum in an Array](https://leetcode.com/problems/max-pair-sum-in-an-array) | [![Java](assets/java.png)](src/MaxPairSumInAnArray.java) | | -| 2824 | [Count Pairs Whose Sum is Less than Target](https://leetcode.com/problems/count-pairs-whose-sum-is-less-than-target) | [![Java](assets/java.png)](src/CountPairsWhoseSumIsLessThanTarget.java) | | -| 2828 | [Check if a String Is an Acronym of Words](https://leetcode.com/problems/check-if-a-string-is-an-acronym-of-words) | [![Java](assets/java.png)](src/CheckIfAStringIsAnAcronymOfWords.java) | | \ No newline at end of file diff --git a/src/HelloWorld.java b/src/HelloWorld.java index 3e41f1a..c9402d3 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -1,32 +1,65 @@ +import java.util.Scanner; + public class HelloWorld { - private final int[] memory; + private static final Scanner SCANNER = new Scanner(System.in); - public HelloWorld(int[] array, int m) { - this.memory = new int[m + 1]; - for (int element : array) { - memory[element]++; - } - for (int i = 1 ; i < memory.length ; i++) { - memory[i] += memory[i - 1]; + private static void spiralOrder(int[][] matrix){ + final int rows = matrix.length, columns = matrix[0].length, elements = rows * columns; + for (int i = 0, top = 0, bottom = rows, left = 0, right = columns ; ; ) { + for (int row = top, column = left ; column < right ; column++, i++) { + System.out.print(matrix[row][column]); + } + top++; + if (i == elements) break; + for (int row = top, column = right - 1 ; row < bottom ; row++, i++) { + System.out.print(matrix[row][column]); + } + right--; + if (i == elements) break; + for (int row = bottom - 1, column = right - 1 ; column >= left ; column--, i++) { + System.out.print(matrix[row][column]); + } + bottom--; + if (i == elements) break; + for (int row = bottom - 1, column = left ; row >= top ; row--, i++) { + System.out.print(matrix[row][column]); + } + left++; + if (i == elements) break; } } - public int query(int a, int b) { - if (b > memory.length - 1) { - b = memory.length - 1; - } + private static int intInput(final String string) { + System.out.print(string); + final int i = SCANNER.nextInt(); + return i; + } - if (a <= 0) { - a = 1; - } else if (a > memory.length - 1) { - a = memory.length; + private static void print(int[][] matrix) { + for (int[] row : matrix) { + for (int element : row) { + System.out.print(element + " "); + } + System.out.println(); } - - return this.memory[b] - this.memory[a - 1]; } public static void main(String[] args) { + final int rows = intInput("Enter row size: "); + final int columns = intInput("Enter column size: "); + final int[][] matrix = new int[rows][columns]; + + System.out.println("Enter array elements:"); + + for (int i = 0 ; i < rows ; i++) { + for(int j = 0 ; j < columns ; j++) { + matrix[i][j] = SCANNER.nextInt(); + } + } + + spiralOrder(matrix); - System.out.println(Math.round(10.5)); + System.out.println("\n\nOriginal matrix"); + print(matrix); } -} +} \ No newline at end of file diff --git a/src/WidestVerticalAreaBetweenTwoPointsContainingNoPoints.java b/src/WidestVerticalAreaBetweenTwoPointsContainingNoPoints.java new file mode 100644 index 0000000..d434cc5 --- /dev/null +++ b/src/WidestVerticalAreaBetweenTwoPointsContainingNoPoints.java @@ -0,0 +1,13 @@ +import java.util.Arrays; +import java.util.Comparator; + +public class WidestVerticalAreaBetweenTwoPointsContainingNoPoints { + public int maxWidthOfVerticalArea(int[][] points) { + Arrays.sort(points, Comparator.comparingInt(a -> a[0])); + int maxVerticalArea = 0; + for (int i = 0 ; i < points.length - 1; i++) { + maxVerticalArea = Math.max(maxVerticalArea, points[i + 1][0] - points[i][0]); + } + return maxVerticalArea; + } +} From 69ac3835f516e6928db3fc9e70e07d2bdb012613 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 5 Jul 2024 03:18:06 +0200 Subject: [PATCH 149/280] solves #2833: Furthest Point From Origin in jaav --- README.md | 2 +- src/FurthestPointFromOrigin.java | 23 +++++++++++++++++++ ...reaBetweenTwoPointsContainingNoPoints.java | 4 ++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/FurthestPointFromOrigin.java diff --git a/README.md b/README.md index 763ceb6..b2e3912 100644 --- a/README.md +++ b/README.md @@ -850,7 +850,7 @@ | 2815 | [Max Pair Sum in an Array](https://leetcode.com/problems/max-pair-sum-in-an-array) | [![Java](assets/java.png)](src/MaxPairSumInAnArray.java) | | | 2824 | [Count Pairs Whose Sum is Less than Target](https://leetcode.com/problems/count-pairs-whose-sum-is-less-than-target) | [![Java](assets/java.png)](src/CountPairsWhoseSumIsLessThanTarget.java) | | | 2828 | [Check if a String Is an Acronym of Words](https://leetcode.com/problems/check-if-a-string-is-an-acronym-of-words) | [![Java](assets/java.png)](src/CheckIfAStringIsAnAcronymOfWords.java) | | -| 2833 | [Furthest Point From Origin](https://leetcode.com/problems/furthest-point-from-origin) | | | +| 2833 | [Furthest Point From Origin](https://leetcode.com/problems/furthest-point-from-origin) | [![Java](assets/java.png)](src/FurthestPointFromOrigin.java) | | | 2839 | [Check if Strings Can be Made Equal With Operations I](https://leetcode.com/problems/check-if-strings-can-be-made-equal-with-operations-i) | | | | 2843 | [Count Symmetric Integers](https://leetcode.com/problems/count-symmetric-integers) | | | | 2848 | [Points That Intersect With Cars](https://leetcode.com/problems/points-that-intersect-with-cars) | | | diff --git a/src/FurthestPointFromOrigin.java b/src/FurthestPointFromOrigin.java new file mode 100644 index 0000000..5879bc0 --- /dev/null +++ b/src/FurthestPointFromOrigin.java @@ -0,0 +1,23 @@ +// https://leetcode.com/problems/furthest-point-from-origin +// T: O(N) +// S: O(1) + +public class FurthestPointFromOrigin { + public int furthestDistanceFromOrigin(String moves) { + final int numberOfLeftMoves = numberOf(moves, 'L'); + final int numberOfRightMoves = numberOf(moves, 'R'); + final int numberOfFreeMoves = numberOf(moves, '_'); + + return Math.abs(numberOfLeftMoves - numberOfRightMoves) + numberOfFreeMoves; + } + + private static int numberOf(final String moves, final char c) { + int count = 0; + for (int i = 0 ; i < moves.length() ; i++) { + if (moves.charAt(i) == c) { + count++; + } + } + return count; + } +} diff --git a/src/WidestVerticalAreaBetweenTwoPointsContainingNoPoints.java b/src/WidestVerticalAreaBetweenTwoPointsContainingNoPoints.java index d434cc5..c536711 100644 --- a/src/WidestVerticalAreaBetweenTwoPointsContainingNoPoints.java +++ b/src/WidestVerticalAreaBetweenTwoPointsContainingNoPoints.java @@ -1,3 +1,7 @@ +// https://leetcode.com/problems/widest-vertical-area-between-two-points-containing-no-points +// T: O(N log(N)) +// S: O(log(N)) + import java.util.Arrays; import java.util.Comparator; From 5af2af7932eeb620d456c43a1adf0bec7dab475e Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 5 Jul 2024 03:47:30 +0200 Subject: [PATCH 150/280] solve #2839: Check if Strings Can be Made Equal With Operations I in java --- README.md | 2 +- ...kIfStringsCanBeMadeEqualWithOperationsI.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/CheckIfStringsCanBeMadeEqualWithOperationsI.java diff --git a/README.md b/README.md index b2e3912..3a16816 100644 --- a/README.md +++ b/README.md @@ -851,7 +851,7 @@ | 2824 | [Count Pairs Whose Sum is Less than Target](https://leetcode.com/problems/count-pairs-whose-sum-is-less-than-target) | [![Java](assets/java.png)](src/CountPairsWhoseSumIsLessThanTarget.java) | | | 2828 | [Check if a String Is an Acronym of Words](https://leetcode.com/problems/check-if-a-string-is-an-acronym-of-words) | [![Java](assets/java.png)](src/CheckIfAStringIsAnAcronymOfWords.java) | | | 2833 | [Furthest Point From Origin](https://leetcode.com/problems/furthest-point-from-origin) | [![Java](assets/java.png)](src/FurthestPointFromOrigin.java) | | -| 2839 | [Check if Strings Can be Made Equal With Operations I](https://leetcode.com/problems/check-if-strings-can-be-made-equal-with-operations-i) | | | +| 2839 | [Check if Strings Can be Made Equal With Operations I](https://leetcode.com/problems/check-if-strings-can-be-made-equal-with-operations-i) | [![Java](assets/java.png)](src/CheckIfStringsCanBeMadeEqualWithOperationsI.java) | | | 2843 | [Count Symmetric Integers](https://leetcode.com/problems/count-symmetric-integers) | | | | 2848 | [Points That Intersect With Cars](https://leetcode.com/problems/points-that-intersect-with-cars) | | | | 2855 | [Minimum Right Shifts to Sort the Array](https://leetcode.com/problems/minimum-right-shifts-to-sort-the-array) | | | diff --git a/src/CheckIfStringsCanBeMadeEqualWithOperationsI.java b/src/CheckIfStringsCanBeMadeEqualWithOperationsI.java new file mode 100644 index 0000000..9136586 --- /dev/null +++ b/src/CheckIfStringsCanBeMadeEqualWithOperationsI.java @@ -0,0 +1,17 @@ +// https://leetcode.com/problems/check-if-strings-can-be-made-equal-with-operations-i +// T: O(N) +// S: O(1) + +public class CheckIfStringsCanBeMadeEqualWithOperationsI { + public boolean canBeEqual(String s1, String s2) { + for (int i = 0 ; i < s1.length() - 2 ; i++) { + if ( + (s1.charAt(i) == s2.charAt(i) && s1.charAt(i + 2) == s2.charAt(i + 2) || + (s1.charAt(i) == s2.charAt(i + 2) && s1.charAt(i + 2) == s2.charAt(i)))) { + continue; + } + return false; + } + return true; + } +} From 0dadeaad0d4101ea96295fff125639934d2887d8 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 5 Jul 2024 04:14:19 +0200 Subject: [PATCH 151/280] solve 2843: Count Symmetric Integers in java --- README.md | 2 +- src/CountSymmetricIntegers.java | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/CountSymmetricIntegers.java diff --git a/README.md b/README.md index 3a16816..eda0e9f 100644 --- a/README.md +++ b/README.md @@ -852,7 +852,7 @@ | 2828 | [Check if a String Is an Acronym of Words](https://leetcode.com/problems/check-if-a-string-is-an-acronym-of-words) | [![Java](assets/java.png)](src/CheckIfAStringIsAnAcronymOfWords.java) | | | 2833 | [Furthest Point From Origin](https://leetcode.com/problems/furthest-point-from-origin) | [![Java](assets/java.png)](src/FurthestPointFromOrigin.java) | | | 2839 | [Check if Strings Can be Made Equal With Operations I](https://leetcode.com/problems/check-if-strings-can-be-made-equal-with-operations-i) | [![Java](assets/java.png)](src/CheckIfStringsCanBeMadeEqualWithOperationsI.java) | | -| 2843 | [Count Symmetric Integers](https://leetcode.com/problems/count-symmetric-integers) | | | +| 2843 | [Count Symmetric Integers](https://leetcode.com/problems/count-symmetric-integers) | [![Java](assets/java.png)](src/CountSymmetricIntegers.java) | | | 2848 | [Points That Intersect With Cars](https://leetcode.com/problems/points-that-intersect-with-cars) | | | | 2855 | [Minimum Right Shifts to Sort the Array](https://leetcode.com/problems/minimum-right-shifts-to-sort-the-array) | | | | 2859 | [Sum of Values at Indices With K Set Bits](https://leetcode.com/problems/sum-of-values-at-indices-with-k-set-bits) | | | diff --git a/src/CountSymmetricIntegers.java b/src/CountSymmetricIntegers.java new file mode 100644 index 0000000..6b5f692 --- /dev/null +++ b/src/CountSymmetricIntegers.java @@ -0,0 +1,33 @@ +// https://leetcode.com/problems/count-symmetric-integers +// T: O(N) +// S: O(1) + +public class CountSymmetricIntegers { + public int countSymmetricIntegers(int low, int high) { + int count = 0; + for (int start = low ; start <= high ; start++) { + final String number = start + ""; + if (isSymmetric(number)) { + count++; + } + } + return count; + } + + private static boolean isSymmetric(String number) { + if (number.length() % 2 != 0) { + return false; + } + final String firstHalf = number.substring(0, number.length() / 2); + final String secondHalf = number.substring(number.length() / 2); + return sumOfDigits(firstHalf) == sumOfDigits(secondHalf); + } + + private static int sumOfDigits(final String number) { + int sum = 0; + for (int i = 0 ; i < number.length() ; i++) { + sum += number.charAt(i) - '0'; + } + return sum; + } +} From e1bf8a37fffb755cd23ad7a454b91817a9e5f1f5 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 5 Jul 2024 04:40:34 +0200 Subject: [PATCH 152/280] solve #2848: Points That Intersect With Cars in java --- README.md | 2 +- src/PointsThatIntersectWithCars.java | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/PointsThatIntersectWithCars.java diff --git a/README.md b/README.md index eda0e9f..ba79bf6 100644 --- a/README.md +++ b/README.md @@ -853,7 +853,7 @@ | 2833 | [Furthest Point From Origin](https://leetcode.com/problems/furthest-point-from-origin) | [![Java](assets/java.png)](src/FurthestPointFromOrigin.java) | | | 2839 | [Check if Strings Can be Made Equal With Operations I](https://leetcode.com/problems/check-if-strings-can-be-made-equal-with-operations-i) | [![Java](assets/java.png)](src/CheckIfStringsCanBeMadeEqualWithOperationsI.java) | | | 2843 | [Count Symmetric Integers](https://leetcode.com/problems/count-symmetric-integers) | [![Java](assets/java.png)](src/CountSymmetricIntegers.java) | | -| 2848 | [Points That Intersect With Cars](https://leetcode.com/problems/points-that-intersect-with-cars) | | | +| 2848 | [Points That Intersect With Cars](https://leetcode.com/problems/points-that-intersect-with-cars) | [![Java](assets/java.png)](src/PointsThatIntersectWithCars.java) | | | 2855 | [Minimum Right Shifts to Sort the Array](https://leetcode.com/problems/minimum-right-shifts-to-sort-the-array) | | | | 2859 | [Sum of Values at Indices With K Set Bits](https://leetcode.com/problems/sum-of-values-at-indices-with-k-set-bits) | | | | 2833 | [Furthest Point From Origin](https://leetcode.com/problems/furthest-point-from-origin) | | | diff --git a/src/PointsThatIntersectWithCars.java b/src/PointsThatIntersectWithCars.java new file mode 100644 index 0000000..63b86ce --- /dev/null +++ b/src/PointsThatIntersectWithCars.java @@ -0,0 +1,25 @@ +// https://leetcode.com/problems/points-that-intersect-with-cars +// T: O(|nums| + |cars|) +// S: O(|cars|) + +import java.util.List; + +public class PointsThatIntersectWithCars { + public int numberOfPoints(List> nums) { + final int[] points = new int[101]; + int count = 0; + + for (final List car : nums) { + points[car.get(0) - 1]++; + points[car.get(1)]--; + } + + for (int i = 0, overlap = 0 ; i < points.length ; i++) { + overlap += points[i]; + if (overlap > 0) { + count++; + } + } + return count; + } +} From 94230335ae27be9d2188dec8b5222d7277c0876d Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 5 Jul 2024 04:54:03 +0200 Subject: [PATCH 153/280] solves #2855: Minimum Right Shifts to Sort the Array in java --- README.md | 2 +- src/MinimumRightShiftsToSortTheArray.java | 36 +++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 src/MinimumRightShiftsToSortTheArray.java diff --git a/README.md b/README.md index ba79bf6..fa87c5f 100644 --- a/README.md +++ b/README.md @@ -854,7 +854,7 @@ | 2839 | [Check if Strings Can be Made Equal With Operations I](https://leetcode.com/problems/check-if-strings-can-be-made-equal-with-operations-i) | [![Java](assets/java.png)](src/CheckIfStringsCanBeMadeEqualWithOperationsI.java) | | | 2843 | [Count Symmetric Integers](https://leetcode.com/problems/count-symmetric-integers) | [![Java](assets/java.png)](src/CountSymmetricIntegers.java) | | | 2848 | [Points That Intersect With Cars](https://leetcode.com/problems/points-that-intersect-with-cars) | [![Java](assets/java.png)](src/PointsThatIntersectWithCars.java) | | -| 2855 | [Minimum Right Shifts to Sort the Array](https://leetcode.com/problems/minimum-right-shifts-to-sort-the-array) | | | +| 2855 | [Minimum Right Shifts to Sort the Array](https://leetcode.com/problems/minimum-right-shifts-to-sort-the-array) | [![Java](assets/java.png)](src/MinimumRightShiftsToSortTheArray.java) | | | 2859 | [Sum of Values at Indices With K Set Bits](https://leetcode.com/problems/sum-of-values-at-indices-with-k-set-bits) | | | | 2833 | [Furthest Point From Origin](https://leetcode.com/problems/furthest-point-from-origin) | | | | 2839 | [Check if Strings Can be Made Equal With Operations I](https://leetcode.com/problems/check-if-strings-can-be-made-equal-with-operations-i) | | | diff --git a/src/MinimumRightShiftsToSortTheArray.java b/src/MinimumRightShiftsToSortTheArray.java new file mode 100644 index 0000000..e82d265 --- /dev/null +++ b/src/MinimumRightShiftsToSortTheArray.java @@ -0,0 +1,36 @@ +// https://leetcode.com/problems/minimum-right-shifts-to-sort-the-array +// T: O(N) +// S: O(1) + +import java.util.List; + +public class MinimumRightShiftsToSortTheArray { + public int minimumRightShifts(List array) { + final int minElementIndex = getMinElementIndex(array); + if (!canSort(array, minElementIndex)) { + return -1; + } + + return (array.size() - minElementIndex) % array.size(); + } + + private static boolean canSort(List array, int minElementIndex) { + for (int i = (minElementIndex + 1) % array.size(), k = 0 ; k < array.size() - 1; k++, i = (i + 1) % array.size()) { + if (array.get(i) <= array.get((i - 1 + array.size()) % array.size())) { + return false; + } + } + return true; + } + + private static int getMinElementIndex(List array) { + int minElement = Integer.MAX_VALUE, index = -1; + for (int i = 0 ; i < array.size() ; i++) { + if (array.get(i) < minElement) { + minElement = array.get(i); + index = i; + } + } + return index; + } +} From eef7cb0e9a51b95f4281cf407bf2566cb3eb1cd0 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 5 Jul 2024 05:02:26 +0200 Subject: [PATCH 154/280] solve #2859: Sum of Values at Indices With K Set Bits in java --- README.md | 2 +- src/SumOfValuesAtIndicesWithKSetBits.java | 26 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/SumOfValuesAtIndicesWithKSetBits.java diff --git a/README.md b/README.md index fa87c5f..2f06fa9 100644 --- a/README.md +++ b/README.md @@ -855,7 +855,7 @@ | 2843 | [Count Symmetric Integers](https://leetcode.com/problems/count-symmetric-integers) | [![Java](assets/java.png)](src/CountSymmetricIntegers.java) | | | 2848 | [Points That Intersect With Cars](https://leetcode.com/problems/points-that-intersect-with-cars) | [![Java](assets/java.png)](src/PointsThatIntersectWithCars.java) | | | 2855 | [Minimum Right Shifts to Sort the Array](https://leetcode.com/problems/minimum-right-shifts-to-sort-the-array) | [![Java](assets/java.png)](src/MinimumRightShiftsToSortTheArray.java) | | -| 2859 | [Sum of Values at Indices With K Set Bits](https://leetcode.com/problems/sum-of-values-at-indices-with-k-set-bits) | | | +| 2859 | [Sum of Values at Indices With K Set Bits](https://leetcode.com/problems/sum-of-values-at-indices-with-k-set-bits) | [![Java](assets/java.png)](src/SumOfValuesAtIndicesWithKSetBits.java) | | | 2833 | [Furthest Point From Origin](https://leetcode.com/problems/furthest-point-from-origin) | | | | 2839 | [Check if Strings Can be Made Equal With Operations I](https://leetcode.com/problems/check-if-strings-can-be-made-equal-with-operations-i) | | | | 2843 | [Count Symmetric Integers](https://leetcode.com/problems/count-symmetric-integers) | | | diff --git a/src/SumOfValuesAtIndicesWithKSetBits.java b/src/SumOfValuesAtIndicesWithKSetBits.java new file mode 100644 index 0000000..536c9aa --- /dev/null +++ b/src/SumOfValuesAtIndicesWithKSetBits.java @@ -0,0 +1,26 @@ +// https://leetcode.com/problems/sum-of-values-at-indices-with-k-set-bits +// T: O(N) +// S: O(1) + +import java.util.List; + +public class SumOfValuesAtIndicesWithKSetBits { + public int sumIndicesWithKSetBits(List array, int k) { + int sum = 0; + for (int i = 0 ; i < array.size() ; i++) { + if (numberOfSetBits(i) == k) { + sum += array.get(i); + } + } + return sum; + } + + private static int numberOfSetBits(int number) { + int setBits = 0; + while (number > 0) { + setBits += number % 2; + number /= 2; + } + return setBits; + } +} From 4c6b7fd8636c686472509350d4ea80a583731d35 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 5 Jul 2024 05:12:20 +0200 Subject: [PATCH 155/280] solve MaximumOddBinaryNumber in java --- README.md | 12 +++++------- src/MaximumOddBinaryNumber.java | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 src/MaximumOddBinaryNumber.java diff --git a/README.md b/README.md index 2f06fa9..8720f9e 100644 --- a/README.md +++ b/README.md @@ -854,15 +854,13 @@ | 2839 | [Check if Strings Can be Made Equal With Operations I](https://leetcode.com/problems/check-if-strings-can-be-made-equal-with-operations-i) | [![Java](assets/java.png)](src/CheckIfStringsCanBeMadeEqualWithOperationsI.java) | | | 2843 | [Count Symmetric Integers](https://leetcode.com/problems/count-symmetric-integers) | [![Java](assets/java.png)](src/CountSymmetricIntegers.java) | | | 2848 | [Points That Intersect With Cars](https://leetcode.com/problems/points-that-intersect-with-cars) | [![Java](assets/java.png)](src/PointsThatIntersectWithCars.java) | | -| 2855 | [Minimum Right Shifts to Sort the Array](https://leetcode.com/problems/minimum-right-shifts-to-sort-the-array) | [![Java](assets/java.png)](src/MinimumRightShiftsToSortTheArray.java) | | -| 2859 | [Sum of Values at Indices With K Set Bits](https://leetcode.com/problems/sum-of-values-at-indices-with-k-set-bits) | [![Java](assets/java.png)](src/SumOfValuesAtIndicesWithKSetBits.java) | | -| 2833 | [Furthest Point From Origin](https://leetcode.com/problems/furthest-point-from-origin) | | | -| 2839 | [Check if Strings Can be Made Equal With Operations I](https://leetcode.com/problems/check-if-strings-can-be-made-equal-with-operations-i) | | | -| 2843 | [Count Symmetric Integers](https://leetcode.com/problems/count-symmetric-integers) | | | -| 2848 | [Points That Intersect With Cars](https://leetcode.com/problems/points-that-intersect-with-cars) | | | | 2855 | [Minimum Right Shifts to Sort the Array](https://leetcode.com/problems/minimum-right-shifts-to-sort-the-array) | | | | 2859 | [Sum of Values at Indices With K Set Bits](https://leetcode.com/problems/sum-of-values-at-indices-with-k-set-bits) | | | -| 2864 | [Maximum Odd Binary Number](https://leetcode.com/problems/maximum-odd-binary-number) | | | +| 2843 | [Count Symmetric Integers](https://leetcode.com/problems/count-symmetric-integers) | | | +| 2848 | [Points That Intersect With Cars](https://leetcode.com/problems/points-that-intersect-with-cars) | | | +| 2855 | [Minimum Right Shifts to Sort the Array](https://leetcode.com/problems/minimum-right-shifts-to-sort-the-array) | [![Java](assets/java.png)](src/MinimumRightShiftsToSortTheArray.java) | | +| 2859 | [Sum of Values at Indices With K Set Bits](https://leetcode.com/problems/sum-of-values-at-indices-with-k-set-bits) | [![Java](assets/java.png)](src/SumOfValuesAtIndicesWithKSetBits.java) | | +| 2864 | [Maximum Odd Binary Number](https://leetcode.com/problems/maximum-odd-binary-number) | [![Java](assets/java.png)](src/MaximumOddBinaryNumber.java) | | | 2869 | [Minimum Operations to Collect Elements](https://leetcode.com/problems/minimum-operations-to-collect-elements) | | | | 2873 | [Maximum Value of an Ordered Triplet I](https://leetcode.com/problems/maximum-value-of-an-ordered-triplet-i) | | | | 2894 | [Divisible and Non-divisible Sums Difference](https://leetcode.com/problems/divisible-and-non-divisible-sums-difference) | | | diff --git a/src/MaximumOddBinaryNumber.java b/src/MaximumOddBinaryNumber.java new file mode 100644 index 0000000..1ba7415 --- /dev/null +++ b/src/MaximumOddBinaryNumber.java @@ -0,0 +1,20 @@ +// https://leetcode.com/problems/maximum-odd-binary-number +// T: O(S) +// S: O(1) + +public class MaximumOddBinaryNumber { + public String maximumOddBinaryNumber(String s) { + final int numberOfOnes = getNumberOfOnes(s); + return "1".repeat(numberOfOnes - 1) + "0".repeat(s.length() - numberOfOnes) + "1"; + } + + private static int getNumberOfOnes(String s) { + int count = 0; + for (int i = 0 ; i < s.length() ; i++) { + if (s.charAt(i) == '1') { + count++; + } + } + return count; + } +} From 4fc01d800c3ba4d9a058bf1c185733ed817b2c44 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 5 Jul 2024 05:13:40 +0200 Subject: [PATCH 156/280] update readme --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index 8720f9e..1fded18 100644 --- a/README.md +++ b/README.md @@ -854,10 +854,6 @@ | 2839 | [Check if Strings Can be Made Equal With Operations I](https://leetcode.com/problems/check-if-strings-can-be-made-equal-with-operations-i) | [![Java](assets/java.png)](src/CheckIfStringsCanBeMadeEqualWithOperationsI.java) | | | 2843 | [Count Symmetric Integers](https://leetcode.com/problems/count-symmetric-integers) | [![Java](assets/java.png)](src/CountSymmetricIntegers.java) | | | 2848 | [Points That Intersect With Cars](https://leetcode.com/problems/points-that-intersect-with-cars) | [![Java](assets/java.png)](src/PointsThatIntersectWithCars.java) | | -| 2855 | [Minimum Right Shifts to Sort the Array](https://leetcode.com/problems/minimum-right-shifts-to-sort-the-array) | | | -| 2859 | [Sum of Values at Indices With K Set Bits](https://leetcode.com/problems/sum-of-values-at-indices-with-k-set-bits) | | | -| 2843 | [Count Symmetric Integers](https://leetcode.com/problems/count-symmetric-integers) | | | -| 2848 | [Points That Intersect With Cars](https://leetcode.com/problems/points-that-intersect-with-cars) | | | | 2855 | [Minimum Right Shifts to Sort the Array](https://leetcode.com/problems/minimum-right-shifts-to-sort-the-array) | [![Java](assets/java.png)](src/MinimumRightShiftsToSortTheArray.java) | | | 2859 | [Sum of Values at Indices With K Set Bits](https://leetcode.com/problems/sum-of-values-at-indices-with-k-set-bits) | [![Java](assets/java.png)](src/SumOfValuesAtIndicesWithKSetBits.java) | | | 2864 | [Maximum Odd Binary Number](https://leetcode.com/problems/maximum-odd-binary-number) | [![Java](assets/java.png)](src/MaximumOddBinaryNumber.java) | | From d6a336692b2ef38b8e7b4071deca7b16da01ae0e Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 5 Jul 2024 05:19:41 +0200 Subject: [PATCH 157/280] solve #2869: Minimum Operations to Collect Elements in java --- README.md | 2 +- src/MinimumOperationsToCollectElements.java | 22 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/MinimumOperationsToCollectElements.java diff --git a/README.md b/README.md index 1fded18..9127e5a 100644 --- a/README.md +++ b/README.md @@ -857,7 +857,7 @@ | 2855 | [Minimum Right Shifts to Sort the Array](https://leetcode.com/problems/minimum-right-shifts-to-sort-the-array) | [![Java](assets/java.png)](src/MinimumRightShiftsToSortTheArray.java) | | | 2859 | [Sum of Values at Indices With K Set Bits](https://leetcode.com/problems/sum-of-values-at-indices-with-k-set-bits) | [![Java](assets/java.png)](src/SumOfValuesAtIndicesWithKSetBits.java) | | | 2864 | [Maximum Odd Binary Number](https://leetcode.com/problems/maximum-odd-binary-number) | [![Java](assets/java.png)](src/MaximumOddBinaryNumber.java) | | -| 2869 | [Minimum Operations to Collect Elements](https://leetcode.com/problems/minimum-operations-to-collect-elements) | | | +| 2869 | [Minimum Operations to Collect Elements](https://leetcode.com/problems/minimum-operations-to-collect-elements) | [![Java](assets/java.png)](src/MinimumOperationsToCollectElements.java) | | | 2873 | [Maximum Value of an Ordered Triplet I](https://leetcode.com/problems/maximum-value-of-an-ordered-triplet-i) | | | | 2894 | [Divisible and Non-divisible Sums Difference](https://leetcode.com/problems/divisible-and-non-divisible-sums-difference) | | | | 2899 | [Last Visited Integers](https://leetcode.com/problems/last-visited-integers) | | | diff --git a/src/MinimumOperationsToCollectElements.java b/src/MinimumOperationsToCollectElements.java new file mode 100644 index 0000000..3ebd0e3 --- /dev/null +++ b/src/MinimumOperationsToCollectElements.java @@ -0,0 +1,22 @@ +// https://leetcode.com/problems/minimum-operations-to-collect-elements +// T: O(|array|) +// S: O(k) + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class MinimumOperationsToCollectElements { + public int minOperations(List array, int k) { + final Set collection = new HashSet<>(); + for (int i = array.size() - 1 ; i >= 0 ; i--) { + if (array.get(i) <= k) { + collection.add(array.get(i)); + } + if (collection.size() == k) { + return array.size() - i; + } + } + return -1; + } +} From 160642bdbf9d6ff7b308a09a353a6b3fd3525e3c Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 5 Jul 2024 05:25:17 +0200 Subject: [PATCH 158/280] solve #2873: Maximum Value of an Ordered Triplet I in java --- README.md | 2 +- src/MaximumValueOfAnOrderedTripletI.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/MaximumValueOfAnOrderedTripletI.java diff --git a/README.md b/README.md index 9127e5a..5d85698 100644 --- a/README.md +++ b/README.md @@ -858,7 +858,7 @@ | 2859 | [Sum of Values at Indices With K Set Bits](https://leetcode.com/problems/sum-of-values-at-indices-with-k-set-bits) | [![Java](assets/java.png)](src/SumOfValuesAtIndicesWithKSetBits.java) | | | 2864 | [Maximum Odd Binary Number](https://leetcode.com/problems/maximum-odd-binary-number) | [![Java](assets/java.png)](src/MaximumOddBinaryNumber.java) | | | 2869 | [Minimum Operations to Collect Elements](https://leetcode.com/problems/minimum-operations-to-collect-elements) | [![Java](assets/java.png)](src/MinimumOperationsToCollectElements.java) | | -| 2873 | [Maximum Value of an Ordered Triplet I](https://leetcode.com/problems/maximum-value-of-an-ordered-triplet-i) | | | +| 2873 | [Maximum Value of an Ordered Triplet I](https://leetcode.com/problems/maximum-value-of-an-ordered-triplet-i) | [![Java](assets/java.png)](src/MaximumValueOfAnOrderedTripletI.java) | | | 2894 | [Divisible and Non-divisible Sums Difference](https://leetcode.com/problems/divisible-and-non-divisible-sums-difference) | | | | 2899 | [Last Visited Integers](https://leetcode.com/problems/last-visited-integers) | | | | 2900 | [Longest Unequal Adjacent Groups Subsequence I](https://leetcode.com/problems/longest-unequal-adjacent-groups-subsequence-i) | | | diff --git a/src/MaximumValueOfAnOrderedTripletI.java b/src/MaximumValueOfAnOrderedTripletI.java new file mode 100644 index 0000000..9a6e10c --- /dev/null +++ b/src/MaximumValueOfAnOrderedTripletI.java @@ -0,0 +1,18 @@ +// https://leetcode.com/problems/maximum-value-of-an-ordered-triplet-i +// T: O(N^3) +// S: O(1) + +public class MaximumValueOfAnOrderedTripletI { + public long maximumTripletValue(int[] array) { + long result = 0; + for (int i = 0 ; i < array.length ; i++) { + for (int j = i + 1 ; j < array.length ; j++) { + for (int k = j + 1 ; k < array.length ; k++) { + result = Math.max(result, (long) (array[i] - array[j]) * array[k]); + } + } + } + + return result; + } +} From b84843ce592e847ef60908ebe5a62bde056e6905 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 5 Jul 2024 05:30:17 +0200 Subject: [PATCH 159/280] solves #2894: Divisible and Non-divisible Sums Difference in java --- README.md | 2 +- ...ivisibleAndNonDivisibleSumsDifference.java | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/DivisibleAndNonDivisibleSumsDifference.java diff --git a/README.md b/README.md index 5d85698..aec6481 100644 --- a/README.md +++ b/README.md @@ -859,7 +859,7 @@ | 2864 | [Maximum Odd Binary Number](https://leetcode.com/problems/maximum-odd-binary-number) | [![Java](assets/java.png)](src/MaximumOddBinaryNumber.java) | | | 2869 | [Minimum Operations to Collect Elements](https://leetcode.com/problems/minimum-operations-to-collect-elements) | [![Java](assets/java.png)](src/MinimumOperationsToCollectElements.java) | | | 2873 | [Maximum Value of an Ordered Triplet I](https://leetcode.com/problems/maximum-value-of-an-ordered-triplet-i) | [![Java](assets/java.png)](src/MaximumValueOfAnOrderedTripletI.java) | | -| 2894 | [Divisible and Non-divisible Sums Difference](https://leetcode.com/problems/divisible-and-non-divisible-sums-difference) | | | +| 2894 | [Divisible and Non-divisible Sums Difference](https://leetcode.com/problems/divisible-and-non-divisible-sums-difference) | [![Java](assets/java.png)](src/DivisibleAndNonDivisibleSumsDifference.java) | | | 2899 | [Last Visited Integers](https://leetcode.com/problems/last-visited-integers) | | | | 2900 | [Longest Unequal Adjacent Groups Subsequence I](https://leetcode.com/problems/longest-unequal-adjacent-groups-subsequence-i) | | | | 2903 | [Find Indices With Index and Value Difference I](https://leetcode.com/problems/find-indices-with-index-and-value-difference-i) | | | diff --git a/src/DivisibleAndNonDivisibleSumsDifference.java b/src/DivisibleAndNonDivisibleSumsDifference.java new file mode 100644 index 0000000..f5e44ab --- /dev/null +++ b/src/DivisibleAndNonDivisibleSumsDifference.java @@ -0,0 +1,22 @@ +// https://leetcode.com/problems/divisible-and-non-divisible-sums-difference +// T: O(N) +// S: O(1) + +public class DivisibleAndNonDivisibleSumsDifference { + public int differenceOfSums(int n, int m) { + final int sumDivisibleIntegers = getSumOfDivisibleIntegers(n, m); + final int sumNonDivisibleIntegers = (n * (n + 1)) / 2 - sumDivisibleIntegers; + + return sumNonDivisibleIntegers - sumDivisibleIntegers; + } + + private static int getSumOfDivisibleIntegers(int n, int m) { + int sum = 0; + for (int i = 1 ; i <= n ; i++) { + if (i % m == 0) { + sum += i; + } + } + return sum; + } + } From 2572589ebe7b1b6e91acc8159275453b7a055390 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 5 Jul 2024 05:39:10 +0200 Subject: [PATCH 160/280] solves #2899: Last Visited Integers in java --- README.md | 2 +- src/LastVisitedIntegers.java | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/LastVisitedIntegers.java diff --git a/README.md b/README.md index aec6481..7cda0f3 100644 --- a/README.md +++ b/README.md @@ -860,7 +860,7 @@ | 2869 | [Minimum Operations to Collect Elements](https://leetcode.com/problems/minimum-operations-to-collect-elements) | [![Java](assets/java.png)](src/MinimumOperationsToCollectElements.java) | | | 2873 | [Maximum Value of an Ordered Triplet I](https://leetcode.com/problems/maximum-value-of-an-ordered-triplet-i) | [![Java](assets/java.png)](src/MaximumValueOfAnOrderedTripletI.java) | | | 2894 | [Divisible and Non-divisible Sums Difference](https://leetcode.com/problems/divisible-and-non-divisible-sums-difference) | [![Java](assets/java.png)](src/DivisibleAndNonDivisibleSumsDifference.java) | | -| 2899 | [Last Visited Integers](https://leetcode.com/problems/last-visited-integers) | | | +| 2899 | [Last Visited Integers](https://leetcode.com/problems/last-visited-integers) | [![Java](assets/java.png)](src/LastVisitedIntegers.java) | | | 2900 | [Longest Unequal Adjacent Groups Subsequence I](https://leetcode.com/problems/longest-unequal-adjacent-groups-subsequence-i) | | | | 2903 | [Find Indices With Index and Value Difference I](https://leetcode.com/problems/find-indices-with-index-and-value-difference-i) | | | | 2908 | [Minimum Sum of Mountain Triplets I](https://leetcode.com/problems/minimum-sum-of-mountain-triplets-i) | | | diff --git a/src/LastVisitedIntegers.java b/src/LastVisitedIntegers.java new file mode 100644 index 0000000..10ac349 --- /dev/null +++ b/src/LastVisitedIntegers.java @@ -0,0 +1,31 @@ +// https://leetcode.com/problems/last-visited-integers +// T: O(N) +// S: O(N) + +import java.util.ArrayList; +import java.util.List; + +public class LastVisitedIntegers { + public List lastVisitedIntegers(int[] array) { + final List seen = new ArrayList<>(); + final List ans = new ArrayList<>(); + + int k = 0; + + for (int element : array) { + if (element == -1) { + k++; + if (k > seen.size()) { + ans.add(-1); + } else { + ans.add(seen.get(seen.size() - k)); + } + } else { + k = 0; + seen.add(element); + } + } + + return ans; + } +} From b92e2cb59f404a4f0f0dd17ff3eb9870a09a2daf Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 5 Jul 2024 05:54:24 +0200 Subject: [PATCH 161/280] solves 2900: Longest Unequal Adjacent Groups Subsequence I in java --- README.md | 2 +- ...gestUnequalAdjacentGroupsSubsequenceI.java | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 src/LongestUnequalAdjacentGroupsSubsequenceI.java diff --git a/README.md b/README.md index 7cda0f3..eb699f9 100644 --- a/README.md +++ b/README.md @@ -861,7 +861,7 @@ | 2873 | [Maximum Value of an Ordered Triplet I](https://leetcode.com/problems/maximum-value-of-an-ordered-triplet-i) | [![Java](assets/java.png)](src/MaximumValueOfAnOrderedTripletI.java) | | | 2894 | [Divisible and Non-divisible Sums Difference](https://leetcode.com/problems/divisible-and-non-divisible-sums-difference) | [![Java](assets/java.png)](src/DivisibleAndNonDivisibleSumsDifference.java) | | | 2899 | [Last Visited Integers](https://leetcode.com/problems/last-visited-integers) | [![Java](assets/java.png)](src/LastVisitedIntegers.java) | | -| 2900 | [Longest Unequal Adjacent Groups Subsequence I](https://leetcode.com/problems/longest-unequal-adjacent-groups-subsequence-i) | | | +| 2900 | [Longest Unequal Adjacent Groups Subsequence I](https://leetcode.com/problems/longest-unequal-adjacent-groups-subsequence-i) | [![Java](assets/java.png)](src/LongestUnequalAdjacentGroupsSubsequenceI.java) | | | 2903 | [Find Indices With Index and Value Difference I](https://leetcode.com/problems/find-indices-with-index-and-value-difference-i) | | | | 2908 | [Minimum Sum of Mountain Triplets I](https://leetcode.com/problems/minimum-sum-of-mountain-triplets-i) | | | | 2913 | [Subarrays Distinct Element Sum of Squares I](https://leetcode.com/problems/subarrays-distinct-element-sum-of-squares-i) | | | diff --git a/src/LongestUnequalAdjacentGroupsSubsequenceI.java b/src/LongestUnequalAdjacentGroupsSubsequenceI.java new file mode 100644 index 0000000..14c0143 --- /dev/null +++ b/src/LongestUnequalAdjacentGroupsSubsequenceI.java @@ -0,0 +1,21 @@ +// https://leetcode.com/problems/longest-unequal-adjacent-groups-subsequence-i +// T: O(|groups|) +// S: O(1) + +import java.util.ArrayList; +import java.util.List; + +public class LongestUnequalAdjacentGroupsSubsequenceI { + public List getLongestSubsequence(String[] words, int[] groups) { + final List result = new ArrayList<>(); + + for (int i = 0, previous = -1 ; i < groups.length ; i++) { + if (groups[i] != previous) { + result.add(words[i]); + } + previous = groups[i]; + } + + return result; + } +} From 59f36a0653667c22f6f8808e9b20c4ff41004fcd Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 5 Jul 2024 06:05:45 +0200 Subject: [PATCH 162/280] solves #2903: Find Indices With Index and Value Difference I in java --- README.md | 2 +- src/FindIndicesWithIndexAndValueDifferenceI.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/FindIndicesWithIndexAndValueDifferenceI.java diff --git a/README.md b/README.md index eb699f9..19449cb 100644 --- a/README.md +++ b/README.md @@ -862,7 +862,7 @@ | 2894 | [Divisible and Non-divisible Sums Difference](https://leetcode.com/problems/divisible-and-non-divisible-sums-difference) | [![Java](assets/java.png)](src/DivisibleAndNonDivisibleSumsDifference.java) | | | 2899 | [Last Visited Integers](https://leetcode.com/problems/last-visited-integers) | [![Java](assets/java.png)](src/LastVisitedIntegers.java) | | | 2900 | [Longest Unequal Adjacent Groups Subsequence I](https://leetcode.com/problems/longest-unequal-adjacent-groups-subsequence-i) | [![Java](assets/java.png)](src/LongestUnequalAdjacentGroupsSubsequenceI.java) | | -| 2903 | [Find Indices With Index and Value Difference I](https://leetcode.com/problems/find-indices-with-index-and-value-difference-i) | | | +| 2903 | [Find Indices With Index and Value Difference I](https://leetcode.com/problems/find-indices-with-index-and-value-difference-i) | [![Java](assets/java.png)](src/FindIndicesWithIndexAndValueDifferenceI.java) | | | 2908 | [Minimum Sum of Mountain Triplets I](https://leetcode.com/problems/minimum-sum-of-mountain-triplets-i) | | | | 2913 | [Subarrays Distinct Element Sum of Squares I](https://leetcode.com/problems/subarrays-distinct-element-sum-of-squares-i) | | | | 2917 | [Find the K-or of an Array](https://leetcode.com/problems/find-the-k-or-of-an-array) | | | diff --git a/src/FindIndicesWithIndexAndValueDifferenceI.java b/src/FindIndicesWithIndexAndValueDifferenceI.java new file mode 100644 index 0000000..04aa592 --- /dev/null +++ b/src/FindIndicesWithIndexAndValueDifferenceI.java @@ -0,0 +1,16 @@ +// https://leetcode.com/problems/find-indices-with-index-and-value-difference-i +// T: O(N^2) +// S: O(1) + +public class FindIndicesWithIndexAndValueDifferenceI { + public int[] findIndices(int[] array, int indexDifference, int valueDifference) { + for (int i = 0 ; i < array.length ; i++) { + for (int j = i + indexDifference ; j < array.length ; j++) { + if (Math.abs(array[i] - array[j]) >= valueDifference) { + return new int[] { i, j }; + } + } + } + return new int[] { -1, -1}; + } +} From 0522edcd40303b945fcf039e05134ef0a408c106 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 5 Jul 2024 06:18:38 +0200 Subject: [PATCH 163/280] solves #2908: Minimum Sum of Mountain Triplets I in java --- README.md | 2 +- src/MinimumSumOfMountainTripletsI.java | 40 ++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/MinimumSumOfMountainTripletsI.java diff --git a/README.md b/README.md index 19449cb..400ce48 100644 --- a/README.md +++ b/README.md @@ -863,7 +863,7 @@ | 2899 | [Last Visited Integers](https://leetcode.com/problems/last-visited-integers) | [![Java](assets/java.png)](src/LastVisitedIntegers.java) | | | 2900 | [Longest Unequal Adjacent Groups Subsequence I](https://leetcode.com/problems/longest-unequal-adjacent-groups-subsequence-i) | [![Java](assets/java.png)](src/LongestUnequalAdjacentGroupsSubsequenceI.java) | | | 2903 | [Find Indices With Index and Value Difference I](https://leetcode.com/problems/find-indices-with-index-and-value-difference-i) | [![Java](assets/java.png)](src/FindIndicesWithIndexAndValueDifferenceI.java) | | -| 2908 | [Minimum Sum of Mountain Triplets I](https://leetcode.com/problems/minimum-sum-of-mountain-triplets-i) | | | +| 2908 | [Minimum Sum of Mountain Triplets I](https://leetcode.com/problems/minimum-sum-of-mountain-triplets-i) | [![Java](assets/java.png)](src/MinimumSumOfMountainTripletsI.java) | | | 2913 | [Subarrays Distinct Element Sum of Squares I](https://leetcode.com/problems/subarrays-distinct-element-sum-of-squares-i) | | | | 2917 | [Find the K-or of an Array](https://leetcode.com/problems/find-the-k-or-of-an-array) | | | | 2923 | [Find Champion I](https://leetcode.com/problems/find-champion-i) | | | diff --git a/src/MinimumSumOfMountainTripletsI.java b/src/MinimumSumOfMountainTripletsI.java new file mode 100644 index 0000000..e005a61 --- /dev/null +++ b/src/MinimumSumOfMountainTripletsI.java @@ -0,0 +1,40 @@ +// https://leetcode.com/problems/minimum-sum-of-mountain-triplets-i +// T: O(N^2) +// T: O(1) + +public class MinimumSumOfMountainTripletsI { + public int minimumSum(int[] array) { + int minSum = Integer.MAX_VALUE; + + for (int i = 1 ; i < array.length - 1 ; i++) { + final int minLeft = getSmallestOnLeft(array, i); + if (minLeft >= array[i]) { + continue; + } + final int minRight = getSmallestOnRight(array, i); + if (minRight >= array[i]) { + continue; + } + + minSum = Math.min(minSum, minLeft + minRight + array[i]); + } + + return minSum == Integer.MAX_VALUE ? -1 : minSum; + } + + private static int getSmallestOnLeft(int[] array, int index) { + int min = Integer.MAX_VALUE; + for (int i = 0 ; i < index ; i++) { + min = Math.min(min, array[i]); + } + return min; + } + + private static int getSmallestOnRight(int[] array, int index) { + int min = Integer.MAX_VALUE; + for (int i = index + 1 ; i < array.length ; i++) { + min = Math.min(min, array[i]); + } + return min; + } +} From 54b8f275464bc5d8b8b065f23aed6784ff40e031 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 5 Jul 2024 06:30:38 +0200 Subject: [PATCH 164/280] solves ##2913: Subarrays Distinct Element Sum of Squares I in java --- README.md | 2 +- ...SubarraysDistinctElementSumOfSquaresI.java | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 src/SubarraysDistinctElementSumOfSquaresI.java diff --git a/README.md b/README.md index 400ce48..69de9d9 100644 --- a/README.md +++ b/README.md @@ -864,7 +864,7 @@ | 2900 | [Longest Unequal Adjacent Groups Subsequence I](https://leetcode.com/problems/longest-unequal-adjacent-groups-subsequence-i) | [![Java](assets/java.png)](src/LongestUnequalAdjacentGroupsSubsequenceI.java) | | | 2903 | [Find Indices With Index and Value Difference I](https://leetcode.com/problems/find-indices-with-index-and-value-difference-i) | [![Java](assets/java.png)](src/FindIndicesWithIndexAndValueDifferenceI.java) | | | 2908 | [Minimum Sum of Mountain Triplets I](https://leetcode.com/problems/minimum-sum-of-mountain-triplets-i) | [![Java](assets/java.png)](src/MinimumSumOfMountainTripletsI.java) | | -| 2913 | [Subarrays Distinct Element Sum of Squares I](https://leetcode.com/problems/subarrays-distinct-element-sum-of-squares-i) | | | +| 2913 | [Subarrays Distinct Element Sum of Squares I](https://leetcode.com/problems/subarrays-distinct-element-sum-of-squares-i) | [![Java](assets/java.png)](src/SubarraysDistinctElementSumOfSquaresI.java) | | | 2917 | [Find the K-or of an Array](https://leetcode.com/problems/find-the-k-or-of-an-array) | | | | 2923 | [Find Champion I](https://leetcode.com/problems/find-champion-i) | | | | 2928 | [Distribute Candies Among Children I](https://leetcode.com/problems/distribute-candies-among-children-i) | | | diff --git a/src/SubarraysDistinctElementSumOfSquaresI.java b/src/SubarraysDistinctElementSumOfSquaresI.java new file mode 100644 index 0000000..49b6d8f --- /dev/null +++ b/src/SubarraysDistinctElementSumOfSquaresI.java @@ -0,0 +1,23 @@ +// https://leetcode.com/problems/subarrays-distinct-element-sum-of-squares-i +// T: O(N^2) +// S: O(N) + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class SubarraysDistinctElementSumOfSquaresI { + public int sumCounts(List array) { + int sum = 0; + + for (int i = 0 ; i < array.size() ; i++) { + final Set subArray = new HashSet<>(); + for (int j = i ; j < array.size() ; j++) { + subArray.add(array.get(j)); + sum += subArray.size() * subArray.size(); + } + } + + return sum; + } +} From 9777f77a7dbca33fe1adeb89ba83be8650438169 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 5 Jul 2024 06:45:05 +0200 Subject: [PATCH 165/280] solves #2917: Find the K-or of an Array in java --- README.md | 2 +- src/FindTheKOrOfAnArray.java | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/FindTheKOrOfAnArray.java diff --git a/README.md b/README.md index 69de9d9..9dba8b4 100644 --- a/README.md +++ b/README.md @@ -865,7 +865,7 @@ | 2903 | [Find Indices With Index and Value Difference I](https://leetcode.com/problems/find-indices-with-index-and-value-difference-i) | [![Java](assets/java.png)](src/FindIndicesWithIndexAndValueDifferenceI.java) | | | 2908 | [Minimum Sum of Mountain Triplets I](https://leetcode.com/problems/minimum-sum-of-mountain-triplets-i) | [![Java](assets/java.png)](src/MinimumSumOfMountainTripletsI.java) | | | 2913 | [Subarrays Distinct Element Sum of Squares I](https://leetcode.com/problems/subarrays-distinct-element-sum-of-squares-i) | [![Java](assets/java.png)](src/SubarraysDistinctElementSumOfSquaresI.java) | | -| 2917 | [Find the K-or of an Array](https://leetcode.com/problems/find-the-k-or-of-an-array) | | | +| 2917 | [Find the K-or of an Array](https://leetcode.com/problems/find-the-k-or-of-an-array) | [![Java](assets/java.png)](src/FindTheKOrOfAnArray.java) | | | 2923 | [Find Champion I](https://leetcode.com/problems/find-champion-i) | | | | 2928 | [Distribute Candies Among Children I](https://leetcode.com/problems/distribute-candies-among-children-i) | | | | 2932 | [Maximum Strong Pair XOR I](https://leetcode.com/problems/maximum-strong-pair-xor-i) | | | diff --git a/src/FindTheKOrOfAnArray.java b/src/FindTheKOrOfAnArray.java new file mode 100644 index 0000000..5640479 --- /dev/null +++ b/src/FindTheKOrOfAnArray.java @@ -0,0 +1,27 @@ +// https://leetcode.com/problems/find-the-k-or-of-an-array +// T: O(N) +// S: O(1) + +public class FindTheKOrOfAnArray { + public int findKOr(int[] array, int k) { + int mask = 0; + + for (int i = 0 ; i < 32 ; i++) { + int count = 0; + for (int element : array) { + if ((element & (1 << i)) > 0) { + count++; + } + if (count == k) { + break; + } + } + + if(count == k) { + mask |= (1 << i); + } + } + + return mask; + } +} From d1fb71990c744e7b3b941fd9239da4097dcd50ac Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 5 Jul 2024 06:56:04 +0200 Subject: [PATCH 166/280] solves #2923: Find Champion I in java --- README.md | 2 +- src/FindChampionI.java | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/FindChampionI.java diff --git a/README.md b/README.md index 9dba8b4..08cd53d 100644 --- a/README.md +++ b/README.md @@ -866,7 +866,7 @@ | 2908 | [Minimum Sum of Mountain Triplets I](https://leetcode.com/problems/minimum-sum-of-mountain-triplets-i) | [![Java](assets/java.png)](src/MinimumSumOfMountainTripletsI.java) | | | 2913 | [Subarrays Distinct Element Sum of Squares I](https://leetcode.com/problems/subarrays-distinct-element-sum-of-squares-i) | [![Java](assets/java.png)](src/SubarraysDistinctElementSumOfSquaresI.java) | | | 2917 | [Find the K-or of an Array](https://leetcode.com/problems/find-the-k-or-of-an-array) | [![Java](assets/java.png)](src/FindTheKOrOfAnArray.java) | | -| 2923 | [Find Champion I](https://leetcode.com/problems/find-champion-i) | | | +| 2923 | [Find Champion I](https://leetcode.com/problems/find-champion-i) | [![Java](assets/java.png)](src/FindChampionI.java) | | | 2928 | [Distribute Candies Among Children I](https://leetcode.com/problems/distribute-candies-among-children-i) | | | | 2932 | [Maximum Strong Pair XOR I](https://leetcode.com/problems/maximum-strong-pair-xor-i) | | | | 2937 | [Make Three Strings Equal](https://leetcode.com/problems/make-three-strings-equal) | | | diff --git a/src/FindChampionI.java b/src/FindChampionI.java new file mode 100644 index 0000000..c02fd16 --- /dev/null +++ b/src/FindChampionI.java @@ -0,0 +1,26 @@ +// https://leetcode.com/problems/find-champion-i +// T: O(|grid.length| ^ 2) +// S: O(1) + +public class FindChampionI { + public int findChampion(int[][] grid) { + for (int row = 0 ; row < grid.length ; row++) { + if (isChampion(grid, row)) { + return row; + } + } + return -1; + } + + private static boolean isChampion(int[][] grid, int row) { + for (int i = 0 ; i < grid.length ; i++) { + if (i == row) { + continue; + } + if (grid[row][i] == 0) { + return false; + } + } + return true; + } +} From cf705b6b56ac48e6f5a6e6c9e5169646df769a43 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 6 Jul 2024 16:32:27 +0200 Subject: [PATCH 167/280] solve #2928: Distribute Candies Among Children I in java --- README.md | 2 +- src/DistributeCandiesAmongChildrenI.java | 30 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/DistributeCandiesAmongChildrenI.java diff --git a/README.md b/README.md index 08cd53d..2eb3051 100644 --- a/README.md +++ b/README.md @@ -867,7 +867,7 @@ | 2913 | [Subarrays Distinct Element Sum of Squares I](https://leetcode.com/problems/subarrays-distinct-element-sum-of-squares-i) | [![Java](assets/java.png)](src/SubarraysDistinctElementSumOfSquaresI.java) | | | 2917 | [Find the K-or of an Array](https://leetcode.com/problems/find-the-k-or-of-an-array) | [![Java](assets/java.png)](src/FindTheKOrOfAnArray.java) | | | 2923 | [Find Champion I](https://leetcode.com/problems/find-champion-i) | [![Java](assets/java.png)](src/FindChampionI.java) | | -| 2928 | [Distribute Candies Among Children I](https://leetcode.com/problems/distribute-candies-among-children-i) | | | +| 2928 | [Distribute Candies Among Children I](https://leetcode.com/problems/distribute-candies-among-children-i) | [![Java](assets/java.png)](src/DistributeCandiesAmongChildrenI.java) | | | 2932 | [Maximum Strong Pair XOR I](https://leetcode.com/problems/maximum-strong-pair-xor-i) | | | | 2937 | [Make Three Strings Equal](https://leetcode.com/problems/make-three-strings-equal) | | | | 2942 | [Find Words Containing Character](https://leetcode.com/problems/find-words-containing-character) | | | diff --git a/src/DistributeCandiesAmongChildrenI.java b/src/DistributeCandiesAmongChildrenI.java new file mode 100644 index 0000000..89e50e8 --- /dev/null +++ b/src/DistributeCandiesAmongChildrenI.java @@ -0,0 +1,30 @@ +// https://leetcode.com/problems/distribute-candies-among-children-i +// n = number of slots, c = candies +// T: O(n ^ c) +// S: O(c) + +public class DistributeCandiesAmongChildrenI { + public int distributeCandies(int n, int limit) { + // Check if n is greater than 3 times limit + if (n > 3 * limit) { + return 0; + } + + int ans = nC2(n + 2); + + if (n > limit) { + ans -= 3 * nC2(n - limit + 1); + } + + if (n - 2 >= 2 * limit) { + ans += 3 * nC2(n - 2 * limit); + } + + // Return the final result + return ans; + } + + private static int nC2(int n) { + return (n * (n - 1)) / 2; + } +} From f11871c78aadeea8c792244001e3b44e63c488f9 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 6 Jul 2024 16:50:53 +0200 Subject: [PATCH 168/280] solves #2932: Maximum Strong Pair XOR I in java --- README.md | 2 +- src/MaximumStrongPairXORI.java | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 src/MaximumStrongPairXORI.java diff --git a/README.md b/README.md index 2eb3051..be93a5d 100644 --- a/README.md +++ b/README.md @@ -868,7 +868,7 @@ | 2917 | [Find the K-or of an Array](https://leetcode.com/problems/find-the-k-or-of-an-array) | [![Java](assets/java.png)](src/FindTheKOrOfAnArray.java) | | | 2923 | [Find Champion I](https://leetcode.com/problems/find-champion-i) | [![Java](assets/java.png)](src/FindChampionI.java) | | | 2928 | [Distribute Candies Among Children I](https://leetcode.com/problems/distribute-candies-among-children-i) | [![Java](assets/java.png)](src/DistributeCandiesAmongChildrenI.java) | | -| 2932 | [Maximum Strong Pair XOR I](https://leetcode.com/problems/maximum-strong-pair-xor-i) | | | +| 2932 | [Maximum Strong Pair XOR I](https://leetcode.com/problems/maximum-strong-pair-xor-i) | [![Java](assets/java.png)](src/MaximumStrongPairXORI.java) | | | 2937 | [Make Three Strings Equal](https://leetcode.com/problems/make-three-strings-equal) | | | | 2942 | [Find Words Containing Character](https://leetcode.com/problems/find-words-containing-character) | | | | 2946 | [Matrix Similarity After Cyclic Shifts](https://leetcode.com/problems/matrix-similarity-after-cyclic-shifts) | | | diff --git a/src/MaximumStrongPairXORI.java b/src/MaximumStrongPairXORI.java new file mode 100644 index 0000000..d35349e --- /dev/null +++ b/src/MaximumStrongPairXORI.java @@ -0,0 +1,21 @@ +// https://leetcode.com/problems/maximum-strong-pair-xor-i +// T: O(N^2) +// S: O(1) + +import java.util.Arrays; + +public class MaximumStrongPairXORI { + public int maximumStrongPairXor(int[] array) { + int result = 0; + + for (int i = 0 ; i < array.length ; i++) { + for (int j = i ; j < array.length ; j++) { + if (Math.abs(array[i] - array[j]) <= Math.min(array[i], array[j])) { + result = Math.max(result, array[i] ^ array[j]); + } + } + } + + return result; + } +} From a9b0a83d6f665a3b2ded0928a9b2cc4d48b4cc02 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 6 Jul 2024 16:56:00 +0200 Subject: [PATCH 169/280] solves #2937: Make Three Strings Equal in java --- README.md | 2 +- src/MakeThreeStringsEqual.java | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 src/MakeThreeStringsEqual.java diff --git a/README.md b/README.md index be93a5d..506c2e2 100644 --- a/README.md +++ b/README.md @@ -869,7 +869,7 @@ | 2923 | [Find Champion I](https://leetcode.com/problems/find-champion-i) | [![Java](assets/java.png)](src/FindChampionI.java) | | | 2928 | [Distribute Candies Among Children I](https://leetcode.com/problems/distribute-candies-among-children-i) | [![Java](assets/java.png)](src/DistributeCandiesAmongChildrenI.java) | | | 2932 | [Maximum Strong Pair XOR I](https://leetcode.com/problems/maximum-strong-pair-xor-i) | [![Java](assets/java.png)](src/MaximumStrongPairXORI.java) | | -| 2937 | [Make Three Strings Equal](https://leetcode.com/problems/make-three-strings-equal) | | | +| 2937 | [Make Three Strings Equal](https://leetcode.com/problems/make-three-strings-equal) | [![Java](assets/java.png)](src/MakeThreeStringsEqual.java) | | | 2942 | [Find Words Containing Character](https://leetcode.com/problems/find-words-containing-character) | | | | 2946 | [Matrix Similarity After Cyclic Shifts](https://leetcode.com/problems/matrix-similarity-after-cyclic-shifts) | | | | 2951 | [Find the Peaks](https://leetcode.com/problems/find-the-peaks) | | | diff --git a/src/MakeThreeStringsEqual.java b/src/MakeThreeStringsEqual.java new file mode 100644 index 0000000..6bc4c44 --- /dev/null +++ b/src/MakeThreeStringsEqual.java @@ -0,0 +1,21 @@ +// https://leetcode.com/problems/make-three-strings-equal +// T: O(min(|s1|, |s2|, |s3|)) +// S: O(1) + +public class MakeThreeStringsEqual { + public int findMinimumOperations(String s1, String s2, String s3) { + int maxPrefixLength = 0; + for (int i = 0, j = 0, k = 0 ; i < s1.length() && j < s2.length() && k < s3.length() ; i++, j++, k++) { + if (s1.charAt(i) != s2.charAt(j) || s2.charAt(j) != s3.charAt(k)) { + break; + } + maxPrefixLength++; + } + + if (maxPrefixLength == 0) { + return -1; + } + + return s1.length() + s2.length() + s3.length() - 3 * maxPrefixLength; + } +} From 3a771f7e255aff80d7efdc01bde9f5ac8ebbfd77 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 6 Jul 2024 17:14:42 +0200 Subject: [PATCH 170/280] solve #2942: Find Words Containing Character in java --- README.md | 2 +- src/FindWordsContainingCharacter.java | 28 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/FindWordsContainingCharacter.java diff --git a/README.md b/README.md index 506c2e2..f8dfd55 100644 --- a/README.md +++ b/README.md @@ -870,7 +870,7 @@ | 2928 | [Distribute Candies Among Children I](https://leetcode.com/problems/distribute-candies-among-children-i) | [![Java](assets/java.png)](src/DistributeCandiesAmongChildrenI.java) | | | 2932 | [Maximum Strong Pair XOR I](https://leetcode.com/problems/maximum-strong-pair-xor-i) | [![Java](assets/java.png)](src/MaximumStrongPairXORI.java) | | | 2937 | [Make Three Strings Equal](https://leetcode.com/problems/make-three-strings-equal) | [![Java](assets/java.png)](src/MakeThreeStringsEqual.java) | | -| 2942 | [Find Words Containing Character](https://leetcode.com/problems/find-words-containing-character) | | | +| 2942 | [Find Words Containing Character](https://leetcode.com/problems/find-words-containing-character) | [![Java](assets/java.png)](src/FindWordsContainingCharacter.java) | | | 2946 | [Matrix Similarity After Cyclic Shifts](https://leetcode.com/problems/matrix-similarity-after-cyclic-shifts) | | | | 2951 | [Find the Peaks](https://leetcode.com/problems/find-the-peaks) | | | | 2956 | [Find Common Elements Between Two Arrays](https://leetcode.com/problems/find-common-elements-between-two-arrays) | | | diff --git a/src/FindWordsContainingCharacter.java b/src/FindWordsContainingCharacter.java new file mode 100644 index 0000000..9440972 --- /dev/null +++ b/src/FindWordsContainingCharacter.java @@ -0,0 +1,28 @@ +// https://leetcode.com/problems/find-words-containing-character +// T: O(|words| * |words[i].length|) +// S: O(1) + +import java.util.ArrayList; +import java.util.List; + +public class FindWordsContainingCharacter { + public List findWordsContaining(String[] words, char x) { + final List result = new ArrayList<>(); + for (int i = 0 ; i < words.length ; i++) { + if (containsCharacter(words[i], x)) { + result.add(i); + } + } + + return result; + } + + private static boolean containsCharacter(String s, char c) { + for (int i = 0 ; i < s.length() ; i++) { + if (s.charAt(i) == c) { + return true; + } + } + return false; + } +} From f6424b4f3026b6b466d220e2c559f9e2afb7d19a Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 6 Jul 2024 17:37:55 +0200 Subject: [PATCH 171/280] solves 2946. Matrix Similarity After Cyclic Shifts in java --- README.md | 2 +- src/MatrixSimilarityAfterCyclicShifts.java | 48 ++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 src/MatrixSimilarityAfterCyclicShifts.java diff --git a/README.md b/README.md index f8dfd55..48eca53 100644 --- a/README.md +++ b/README.md @@ -871,7 +871,7 @@ | 2932 | [Maximum Strong Pair XOR I](https://leetcode.com/problems/maximum-strong-pair-xor-i) | [![Java](assets/java.png)](src/MaximumStrongPairXORI.java) | | | 2937 | [Make Three Strings Equal](https://leetcode.com/problems/make-three-strings-equal) | [![Java](assets/java.png)](src/MakeThreeStringsEqual.java) | | | 2942 | [Find Words Containing Character](https://leetcode.com/problems/find-words-containing-character) | [![Java](assets/java.png)](src/FindWordsContainingCharacter.java) | | -| 2946 | [Matrix Similarity After Cyclic Shifts](https://leetcode.com/problems/matrix-similarity-after-cyclic-shifts) | | | +| 2946 | [Matrix Similarity After Cyclic Shifts](https://leetcode.com/problems/matrix-similarity-after-cyclic-shifts) | [![Java](assets/java.png)](src/MatrixSimilarityAfterCyclicShifts.java) | | | 2951 | [Find the Peaks](https://leetcode.com/problems/find-the-peaks) | | | | 2956 | [Find Common Elements Between Two Arrays](https://leetcode.com/problems/find-common-elements-between-two-arrays) | | | | 2960 | [Count Tested Devices After Test Operations](https://leetcode.com/problems/count-tested-devices-after-test-operations) | | | diff --git a/src/MatrixSimilarityAfterCyclicShifts.java b/src/MatrixSimilarityAfterCyclicShifts.java new file mode 100644 index 0000000..227b442 --- /dev/null +++ b/src/MatrixSimilarityAfterCyclicShifts.java @@ -0,0 +1,48 @@ +// https://leetcode.com/problems/matrix-similarity-after-cyclic-shifts +// m = rows(mat), n = columns(mat) +// T: O(m * n) +// S: O(1) + +public class MatrixSimilarityAfterCyclicShifts { + public boolean areSimilar(int[][] matrix, int k) { + final int rows = matrix.length, columns = matrix[0].length; + + if (k % columns == 0) { + return true; + } + + for (int i = 0 ; i < rows ; i += 2) { + if (!isValidLeftShift(matrix[i], k)) { + return false; + } + } + + for (int i = 1 ; i < rows ; i += 2) { + if (!isValidRightShift(matrix[i], k)) { + return false; + } + } + + return true; + } + + private static boolean isValidRightShift(int[] row, int shift) { + int shiftLength = shift % row.length; + for (int i = 0, k = 0 ; k < row.length ; i = (i + 1) % row.length, k++) { + if (row[i] != row[(i + shiftLength) % row.length]) { + return false; + } + } + return true; + } + + private static boolean isValidLeftShift(int[] row, int shift) { + final int shiftLength = shift % row.length; + for (int i = 0, k = 0 ; k < row.length ; i = (i + 1) % row.length, k++) { + if (row[i] != row[(i - shiftLength + row.length) % row.length]) { + return false; + } + } + return true; + } +} From d39ac9779ab5c4951cdd274a0cffe076b3e10bd7 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 6 Jul 2024 17:41:24 +0200 Subject: [PATCH 172/280] solves 2951. Find the Peaks in java --- README.md | 2 +- src/FindThePeaks.java | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/FindThePeaks.java diff --git a/README.md b/README.md index 48eca53..76cc0ae 100644 --- a/README.md +++ b/README.md @@ -872,7 +872,7 @@ | 2937 | [Make Three Strings Equal](https://leetcode.com/problems/make-three-strings-equal) | [![Java](assets/java.png)](src/MakeThreeStringsEqual.java) | | | 2942 | [Find Words Containing Character](https://leetcode.com/problems/find-words-containing-character) | [![Java](assets/java.png)](src/FindWordsContainingCharacter.java) | | | 2946 | [Matrix Similarity After Cyclic Shifts](https://leetcode.com/problems/matrix-similarity-after-cyclic-shifts) | [![Java](assets/java.png)](src/MatrixSimilarityAfterCyclicShifts.java) | | -| 2951 | [Find the Peaks](https://leetcode.com/problems/find-the-peaks) | | | +| 2951 | [Find the Peaks](https://leetcode.com/problems/find-the-peaks) | [![Java](assets/java.png)](src/FindThePeaks.java) | | | 2956 | [Find Common Elements Between Two Arrays](https://leetcode.com/problems/find-common-elements-between-two-arrays) | | | | 2960 | [Count Tested Devices After Test Operations](https://leetcode.com/problems/count-tested-devices-after-test-operations) | | | | 2965 | [Find Missing and Repeated Values](https://leetcode.com/problems/find-missing-and-repeated-values) | | | diff --git a/src/FindThePeaks.java b/src/FindThePeaks.java new file mode 100644 index 0000000..cddbc34 --- /dev/null +++ b/src/FindThePeaks.java @@ -0,0 +1,20 @@ +// https://leetcode.com/problems/find-the-peaks +// T: O(n) +// S: O(1) + +import java.util.ArrayList; +import java.util.List; + +public class FindThePeaks { + public List findPeaks(int[] mountain) { + final List peaks = new ArrayList<>(); + + for (int i = 1 ; i < mountain.length - 1 ; i++) { + if (mountain[i] > mountain[i - 1] && mountain[i] > mountain[i + 1]) { + peaks.add(i); + } + } + + return peaks; + } +} From 6200987b5cf78a771fbd8149904112d2ae403479 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 6 Jul 2024 17:49:10 +0200 Subject: [PATCH 173/280] solve #2956: Find Common Elements Between Two Arrays in java --- README.md | 2 +- src/FindCommonElementsBetweenTwoArrays.java | 34 +++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/FindCommonElementsBetweenTwoArrays.java diff --git a/README.md b/README.md index 76cc0ae..1da26d8 100644 --- a/README.md +++ b/README.md @@ -873,7 +873,7 @@ | 2942 | [Find Words Containing Character](https://leetcode.com/problems/find-words-containing-character) | [![Java](assets/java.png)](src/FindWordsContainingCharacter.java) | | | 2946 | [Matrix Similarity After Cyclic Shifts](https://leetcode.com/problems/matrix-similarity-after-cyclic-shifts) | [![Java](assets/java.png)](src/MatrixSimilarityAfterCyclicShifts.java) | | | 2951 | [Find the Peaks](https://leetcode.com/problems/find-the-peaks) | [![Java](assets/java.png)](src/FindThePeaks.java) | | -| 2956 | [Find Common Elements Between Two Arrays](https://leetcode.com/problems/find-common-elements-between-two-arrays) | | | +| 2956 | [Find Common Elements Between Two Arrays](https://leetcode.com/problems/find-common-elements-between-two-arrays) | [![Java](assets/java.png)](src/FindCommonElementsBetweenTwoArrays.java) | | | 2960 | [Count Tested Devices After Test Operations](https://leetcode.com/problems/count-tested-devices-after-test-operations) | | | | 2965 | [Find Missing and Repeated Values](https://leetcode.com/problems/find-missing-and-repeated-values) | | | | 2970 | [Count the Number of Irremovable Subarrays I](https://leetcode.com/problems/count-the-number-of-incremovable-subarrays-i) | | | diff --git a/src/FindCommonElementsBetweenTwoArrays.java b/src/FindCommonElementsBetweenTwoArrays.java new file mode 100644 index 0000000..e9d5f40 --- /dev/null +++ b/src/FindCommonElementsBetweenTwoArrays.java @@ -0,0 +1,34 @@ +// https://leetcode.com/problems/find-common-elements-between-two-arrays +// m = |array1|, n = |array2| +// T: O(m + n) +// S: O(m + n) + +import java.util.HashSet; +import java.util.Set; + +public class FindCommonElementsBetweenTwoArrays { + public int[] findIntersectionValues(int[] array1, int[] array2) { + final Set set1 = toSet(array1); + final Set set2 = toSet(array2); + + return new int[] { commonElements(array1, set2), commonElements(array2, set1) }; + } + + private static Set toSet(int[] array) { + final Set set = new HashSet<>(); + for (int element : array) { + set.add(element); + } + return set; + } + + private static int commonElements(int[] array, Set set) { + int count = 0; + for (int element : array) { + if (set.contains(element)) { + count++; + } + } + return count; + } +} From 8691c4770968781de9466426fb3a44faf1f469ac Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 6 Jul 2024 17:53:55 +0200 Subject: [PATCH 174/280] solve #2960: Count Tested Devices After Test Operations in java --- README.md | 2 +- src/CountTestedDevicesAfterTestOperations.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/CountTestedDevicesAfterTestOperations.java diff --git a/README.md b/README.md index 1da26d8..c865096 100644 --- a/README.md +++ b/README.md @@ -874,7 +874,7 @@ | 2946 | [Matrix Similarity After Cyclic Shifts](https://leetcode.com/problems/matrix-similarity-after-cyclic-shifts) | [![Java](assets/java.png)](src/MatrixSimilarityAfterCyclicShifts.java) | | | 2951 | [Find the Peaks](https://leetcode.com/problems/find-the-peaks) | [![Java](assets/java.png)](src/FindThePeaks.java) | | | 2956 | [Find Common Elements Between Two Arrays](https://leetcode.com/problems/find-common-elements-between-two-arrays) | [![Java](assets/java.png)](src/FindCommonElementsBetweenTwoArrays.java) | | -| 2960 | [Count Tested Devices After Test Operations](https://leetcode.com/problems/count-tested-devices-after-test-operations) | | | +| 2960 | [Count Tested Devices After Test Operations](https://leetcode.com/problems/count-tested-devices-after-test-operations) | [![Java](assets/java.png)](src/CountTestedDevicesAfterTestOperations.java) | | | 2965 | [Find Missing and Repeated Values](https://leetcode.com/problems/find-missing-and-repeated-values) | | | | 2970 | [Count the Number of Irremovable Subarrays I](https://leetcode.com/problems/count-the-number-of-incremovable-subarrays-i) | | | | 2974 | [Minimum Number Game](https://leetcode.com/problems/minimum-number-game) | | | diff --git a/src/CountTestedDevicesAfterTestOperations.java b/src/CountTestedDevicesAfterTestOperations.java new file mode 100644 index 0000000..e5086f5 --- /dev/null +++ b/src/CountTestedDevicesAfterTestOperations.java @@ -0,0 +1,16 @@ +// https://leetcode.com/problems/count-tested-devices-after-test-operations +// T: O(N) +// S: O(1) + +public class CountTestedDevicesAfterTestOperations { + public int countTestedDevices(int[] batteryPercentages) { + int testedDevices = 0; + for (int percentage : batteryPercentages) { + if (percentage - testedDevices > 0) { + testedDevices++; + } + } + + return testedDevices; + } +} From 17ed19002df15b70ce7c41ba3277d706a364401c Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 6 Jul 2024 18:58:52 +0200 Subject: [PATCH 175/280] solve #2965: Find Missing and Repeated Values in java --- README.md | 2 +- src/FindMissingAndRepeatedValues.java | 29 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/FindMissingAndRepeatedValues.java diff --git a/README.md b/README.md index c865096..c63b0d2 100644 --- a/README.md +++ b/README.md @@ -875,7 +875,7 @@ | 2951 | [Find the Peaks](https://leetcode.com/problems/find-the-peaks) | [![Java](assets/java.png)](src/FindThePeaks.java) | | | 2956 | [Find Common Elements Between Two Arrays](https://leetcode.com/problems/find-common-elements-between-two-arrays) | [![Java](assets/java.png)](src/FindCommonElementsBetweenTwoArrays.java) | | | 2960 | [Count Tested Devices After Test Operations](https://leetcode.com/problems/count-tested-devices-after-test-operations) | [![Java](assets/java.png)](src/CountTestedDevicesAfterTestOperations.java) | | -| 2965 | [Find Missing and Repeated Values](https://leetcode.com/problems/find-missing-and-repeated-values) | | | +| 2965 | [Find Missing and Repeated Values](https://leetcode.com/problems/find-missing-and-repeated-values) | [![Java](assets/java.png)](src/FindMissingAndRepeatedValues.java) | | | 2970 | [Count the Number of Irremovable Subarrays I](https://leetcode.com/problems/count-the-number-of-incremovable-subarrays-i) | | | | 2974 | [Minimum Number Game](https://leetcode.com/problems/minimum-number-game) | | | | 2980 | [Check if Bitwise OR Has Trailing Zeros](https://leetcode.com/problems/check-if-bitwise-or-has-trailing-zeros) | | | diff --git a/src/FindMissingAndRepeatedValues.java b/src/FindMissingAndRepeatedValues.java new file mode 100644 index 0000000..848f9cb --- /dev/null +++ b/src/FindMissingAndRepeatedValues.java @@ -0,0 +1,29 @@ +// https://leetcode.com/problems/find-missing-and-repeated-values +// T: O(N*N) +// S: O(N*N) + +import java.util.HashSet; +import java.util.Set; + +public class FindMissingAndRepeatedValues { + public int[] findMissingAndRepeatedValues(int[][] grid) { + final int rows = grid.length, elements = rows * rows; + int expectedSum = (elements * (elements + 1)) / 2, actualSum = 0; + final Set numbers = new HashSet<>(); + int repeatingElement = 0; + + for (int[] row : grid) { + for (int element : row) { + if (numbers.contains(element)) { + repeatingElement = element; + } + numbers.add(element); + actualSum += element; + } + } + + int missingElement = expectedSum - actualSum + repeatingElement; + + return new int[] { repeatingElement, missingElement }; + } +} From 887f07f310773b95ff186c29db109c17f6cd8413 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 6 Jul 2024 19:51:25 +0200 Subject: [PATCH 176/280] solve #2970: Count the Number of Incremovable Subarrays I in java --- README.md | 2 +- ...ountTheNumberOfIncremovableSubarraysI.java | 45 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/CountTheNumberOfIncremovableSubarraysI.java diff --git a/README.md b/README.md index c63b0d2..be40546 100644 --- a/README.md +++ b/README.md @@ -876,7 +876,7 @@ | 2956 | [Find Common Elements Between Two Arrays](https://leetcode.com/problems/find-common-elements-between-two-arrays) | [![Java](assets/java.png)](src/FindCommonElementsBetweenTwoArrays.java) | | | 2960 | [Count Tested Devices After Test Operations](https://leetcode.com/problems/count-tested-devices-after-test-operations) | [![Java](assets/java.png)](src/CountTestedDevicesAfterTestOperations.java) | | | 2965 | [Find Missing and Repeated Values](https://leetcode.com/problems/find-missing-and-repeated-values) | [![Java](assets/java.png)](src/FindMissingAndRepeatedValues.java) | | -| 2970 | [Count the Number of Irremovable Subarrays I](https://leetcode.com/problems/count-the-number-of-incremovable-subarrays-i) | | | +| 2970 | [Count the Number of Irremovable Subarrays I](https://leetcode.com/problems/count-the-number-of-incremovable-subarrays-i) | [![Java](assets/java.png)](src/CountTheNumberOfIncremovableSubarraysI.java) | | | 2974 | [Minimum Number Game](https://leetcode.com/problems/minimum-number-game) | | | | 2980 | [Check if Bitwise OR Has Trailing Zeros](https://leetcode.com/problems/check-if-bitwise-or-has-trailing-zeros) | | | | 2996 | [Smallest Missing Integer Greater Than Sequential Prefix Sum](https://leetcode.com/problems/smallest-missing-integer-greater-than-sequential-prefix-sum) | | | diff --git a/src/CountTheNumberOfIncremovableSubarraysI.java b/src/CountTheNumberOfIncremovableSubarraysI.java new file mode 100644 index 0000000..0956657 --- /dev/null +++ b/src/CountTheNumberOfIncremovableSubarraysI.java @@ -0,0 +1,45 @@ +// https://leetcode.com/problems/count-the-number-of-incremovable-subarrays-i +// T: O(N^3) +// S: O(1) + +import java.util.Enumeration; + +public class CountTheNumberOfIncremovableSubarraysI { + public static int incremovableSubarrayCount(int[] array) { + int numberIncremovableSubarrays = 0; + for (int i = 0 ; i < array.length ; i++) { + for (int j = i ; j < array.length ; j++) { + // we consider subarray [i,j] and check for array - subarray whether it is strictly + // increasing or not + if (isStrictlyIncreasing(array, i, j)) { + numberIncremovableSubarrays += array.length - (i == j ? i : j); + break; + } + } + } + + return numberIncremovableSubarrays; + } + + private static boolean isStrictlyIncreasing(int[] array, int i, int j) { + for (int index = 0, previous = -1 ; index < array.length ; index++) { + if (index == i) { + index = j; + continue; + } + if (previous == -1) { + previous = array[index]; + continue; + } + if (array[index] <= previous) { + return false; + } + previous = array[index]; + } + return true; + } + + public static void main(String[] args) { + System.out.println(incremovableSubarrayCount(new int[] { 1, 2, 3, 4 })); + } +} From ea1fbdcbc6d0b8e41d571884f91e77da1d709054 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 6 Jul 2024 19:54:28 +0200 Subject: [PATCH 177/280] solve #2974: Minimum Number Game in java --- README.md | 2 +- src/MinimumNumberGame.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/MinimumNumberGame.java diff --git a/README.md b/README.md index be40546..7b215f8 100644 --- a/README.md +++ b/README.md @@ -877,7 +877,7 @@ | 2960 | [Count Tested Devices After Test Operations](https://leetcode.com/problems/count-tested-devices-after-test-operations) | [![Java](assets/java.png)](src/CountTestedDevicesAfterTestOperations.java) | | | 2965 | [Find Missing and Repeated Values](https://leetcode.com/problems/find-missing-and-repeated-values) | [![Java](assets/java.png)](src/FindMissingAndRepeatedValues.java) | | | 2970 | [Count the Number of Irremovable Subarrays I](https://leetcode.com/problems/count-the-number-of-incremovable-subarrays-i) | [![Java](assets/java.png)](src/CountTheNumberOfIncremovableSubarraysI.java) | | -| 2974 | [Minimum Number Game](https://leetcode.com/problems/minimum-number-game) | | | +| 2974 | [Minimum Number Game](https://leetcode.com/problems/minimum-number-game) | [![Java](assets/java.png)](src/MinimumNumberGame.java) | | | 2980 | [Check if Bitwise OR Has Trailing Zeros](https://leetcode.com/problems/check-if-bitwise-or-has-trailing-zeros) | | | | 2996 | [Smallest Missing Integer Greater Than Sequential Prefix Sum](https://leetcode.com/problems/smallest-missing-integer-greater-than-sequential-prefix-sum) | | | | 3000 | [Maximum Area of Longest Diagonal Rectangle](https://leetcode.com/problems/maximum-area-of-longest-diagonal-rectangle) | | | diff --git a/src/MinimumNumberGame.java b/src/MinimumNumberGame.java new file mode 100644 index 0000000..d7d56a2 --- /dev/null +++ b/src/MinimumNumberGame.java @@ -0,0 +1,19 @@ +// https://leetcode.com/problems/minimum-number-game +// T: O(N*log(N)) +// S: O(log(N)) + +import java.util.Arrays; + +public class MinimumNumberGame { + public int[] numberGame(int[] array) { + Arrays.sort(array); + final int[] result = new int[array.length]; + + for (int i = 0 ; i < array.length ; i += 2) { + result[i] = array[i + 1]; + result[i + 1] = array[i]; + } + + return result; + } +} From 005bed9a660b993c3b2c9799b1106063bd8414e2 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 6 Jul 2024 20:00:06 +0200 Subject: [PATCH 178/280] solve #2980: Check if Bitwise OR Has Trailing Zeros in java --- README.md | 2 +- src/CheckIfBitwiseORHasTrailingZeros.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/CheckIfBitwiseORHasTrailingZeros.java diff --git a/README.md b/README.md index 7b215f8..7118234 100644 --- a/README.md +++ b/README.md @@ -878,7 +878,7 @@ | 2965 | [Find Missing and Repeated Values](https://leetcode.com/problems/find-missing-and-repeated-values) | [![Java](assets/java.png)](src/FindMissingAndRepeatedValues.java) | | | 2970 | [Count the Number of Irremovable Subarrays I](https://leetcode.com/problems/count-the-number-of-incremovable-subarrays-i) | [![Java](assets/java.png)](src/CountTheNumberOfIncremovableSubarraysI.java) | | | 2974 | [Minimum Number Game](https://leetcode.com/problems/minimum-number-game) | [![Java](assets/java.png)](src/MinimumNumberGame.java) | | -| 2980 | [Check if Bitwise OR Has Trailing Zeros](https://leetcode.com/problems/check-if-bitwise-or-has-trailing-zeros) | | | +| 2980 | [Check if Bitwise OR Has Trailing Zeros](https://leetcode.com/problems/check-if-bitwise-or-has-trailing-zeros) | [![Java](assets/java.png)](src/CheckIfBitwiseORHasTrailingZeros.java) | | | 2996 | [Smallest Missing Integer Greater Than Sequential Prefix Sum](https://leetcode.com/problems/smallest-missing-integer-greater-than-sequential-prefix-sum) | | | | 3000 | [Maximum Area of Longest Diagonal Rectangle](https://leetcode.com/problems/maximum-area-of-longest-diagonal-rectangle) | | | | 3005 | [Count Elements With Maximum Frequency](https://leetcode.com/problems/count-elements-with-maximum-frequency) | | | diff --git a/src/CheckIfBitwiseORHasTrailingZeros.java b/src/CheckIfBitwiseORHasTrailingZeros.java new file mode 100644 index 0000000..1fcaece --- /dev/null +++ b/src/CheckIfBitwiseORHasTrailingZeros.java @@ -0,0 +1,18 @@ +// https://leetcode.com/problems/check-if-bitwise-or-has-trailing-zeros +// T: O(N) +// S: O(1) + +public class CheckIfBitwiseORHasTrailingZeros { + public boolean hasTrailingZeros(int[] array) { + int evenNumbers = 0; + for (int element : array) { + if (element % 2 == 0) { + evenNumbers++; + } + if (evenNumbers == 2) { + return true; + } + } + return false; + } +} From 08e086ecce49a4c76a95e9f4a096fbd86da10a56 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 6 Jul 2024 20:10:09 +0200 Subject: [PATCH 179/280] solves #2996: Smallest Missing Integer Greater Than Sequential Prefix Sum in java --- README.md | 2 +- ...IntegerGreaterThanSequentialPrefixSum.java | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/SmallestMissingIntegerGreaterThanSequentialPrefixSum.java diff --git a/README.md b/README.md index 7118234..74180d1 100644 --- a/README.md +++ b/README.md @@ -879,7 +879,7 @@ | 2970 | [Count the Number of Irremovable Subarrays I](https://leetcode.com/problems/count-the-number-of-incremovable-subarrays-i) | [![Java](assets/java.png)](src/CountTheNumberOfIncremovableSubarraysI.java) | | | 2974 | [Minimum Number Game](https://leetcode.com/problems/minimum-number-game) | [![Java](assets/java.png)](src/MinimumNumberGame.java) | | | 2980 | [Check if Bitwise OR Has Trailing Zeros](https://leetcode.com/problems/check-if-bitwise-or-has-trailing-zeros) | [![Java](assets/java.png)](src/CheckIfBitwiseORHasTrailingZeros.java) | | -| 2996 | [Smallest Missing Integer Greater Than Sequential Prefix Sum](https://leetcode.com/problems/smallest-missing-integer-greater-than-sequential-prefix-sum) | | | +| 2996 | [Smallest Missing Integer Greater Than Sequential Prefix Sum](https://leetcode.com/problems/smallest-missing-integer-greater-than-sequential-prefix-sum) | [![Java](assets/java.png)](src/SmallestMissingIntegerGreaterThanSequentialPrefixSum.java) | | | 3000 | [Maximum Area of Longest Diagonal Rectangle](https://leetcode.com/problems/maximum-area-of-longest-diagonal-rectangle) | | | | 3005 | [Count Elements With Maximum Frequency](https://leetcode.com/problems/count-elements-with-maximum-frequency) | | | | 3010 | [Divide an Array Into Subarrays With Minimum Cost I](https://leetcode.com/problems/divide-an-array-into-subarrays-with-minimum-cost-i) | | | diff --git a/src/SmallestMissingIntegerGreaterThanSequentialPrefixSum.java b/src/SmallestMissingIntegerGreaterThanSequentialPrefixSum.java new file mode 100644 index 0000000..9147482 --- /dev/null +++ b/src/SmallestMissingIntegerGreaterThanSequentialPrefixSum.java @@ -0,0 +1,38 @@ +// https://leetcode.com/problems/smallest-missing-integer-greater-than-sequential-prefix-sum +// T: O(N) +// S: O(N) + +import java.util.HashSet; +import java.util.Set; + +public class SmallestMissingIntegerGreaterThanSequentialPrefixSum { + public int missingInteger(int[] array) { + final int sequentialSum = getLongestSequentialSum(array); + final Set numbers = toSet(array); + for (int start = sequentialSum ; ; start++) { + if (!numbers.contains(start)) { + return start; + } + } + } + + private static Set toSet(int[] array) { + final Set set = new HashSet<>(); + for (int element : array) { + set.add(element); + } + return set; + } + + private static int getLongestSequentialSum(int[] array) { + int sum = array[0]; + for (int i = 1 ; i < array.length ; i++) { + if (array[i] == array[i - 1] + 1) { + sum += array[i]; + } else { + break; + } + } + return sum; + } +} From b7c9405fc35910654e961ed46c0697b859c64884 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 6 Jul 2024 20:35:09 +0200 Subject: [PATCH 180/280] solve #3000: Maximum Area of Longest Diagonal Rectangle in java --- README.md | 2 +- ...MaximumAreaOfLongestDiagonalRectangle.java | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/MaximumAreaOfLongestDiagonalRectangle.java diff --git a/README.md b/README.md index 74180d1..831afe7 100644 --- a/README.md +++ b/README.md @@ -880,7 +880,7 @@ | 2974 | [Minimum Number Game](https://leetcode.com/problems/minimum-number-game) | [![Java](assets/java.png)](src/MinimumNumberGame.java) | | | 2980 | [Check if Bitwise OR Has Trailing Zeros](https://leetcode.com/problems/check-if-bitwise-or-has-trailing-zeros) | [![Java](assets/java.png)](src/CheckIfBitwiseORHasTrailingZeros.java) | | | 2996 | [Smallest Missing Integer Greater Than Sequential Prefix Sum](https://leetcode.com/problems/smallest-missing-integer-greater-than-sequential-prefix-sum) | [![Java](assets/java.png)](src/SmallestMissingIntegerGreaterThanSequentialPrefixSum.java) | | -| 3000 | [Maximum Area of Longest Diagonal Rectangle](https://leetcode.com/problems/maximum-area-of-longest-diagonal-rectangle) | | | +| 3000 | [Maximum Area of Longest Diagonal Rectangle](https://leetcode.com/problems/maximum-area-of-longest-diagonal-rectangle) | [![Java](assets/java.png)](src/MaximumAreaOfLongestDiagonalRectangle.java) | | | 3005 | [Count Elements With Maximum Frequency](https://leetcode.com/problems/count-elements-with-maximum-frequency) | | | | 3010 | [Divide an Array Into Subarrays With Minimum Cost I](https://leetcode.com/problems/divide-an-array-into-subarrays-with-minimum-cost-i) | | | | 3014 | [Minimum Number of Pushes to Type Word I](https://leetcode.com/problems/minimum-number-of-pushes-to-type-word-i) | | | diff --git a/src/MaximumAreaOfLongestDiagonalRectangle.java b/src/MaximumAreaOfLongestDiagonalRectangle.java new file mode 100644 index 0000000..07b4423 --- /dev/null +++ b/src/MaximumAreaOfLongestDiagonalRectangle.java @@ -0,0 +1,31 @@ +// https://leetcode.com/problems/maximum-area-of-longest-diagonal-rectangle +// T: O(N) +// S: O(1) + +public class MaximumAreaOfLongestDiagonalRectangle { + public int areaOfMaxDiagonal(int[][] dimensions) { + int maxArea = 0, maxDiagonal = 0; + + for (final int[] rectangle : dimensions) { + final int diagonal = getDiagonal(rectangle); + final int area = getArea(rectangle); + + if (diagonal > maxDiagonal) { + maxDiagonal = diagonal; + maxArea = area; + } else if (diagonal == maxDiagonal) { + maxArea = Math.max(maxArea, area); + } + } + + return maxArea; + } + + private static int getArea(int[] rectangle) { + return rectangle[0] * rectangle[1]; + } + + private static int getDiagonal(int[] rectangle) { + return rectangle[0] * rectangle[0] + rectangle[1] * rectangle[1]; + } +} From 05a620a3fe79139dc6981eb179ab88515432aea1 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 6 Jul 2024 20:42:29 +0200 Subject: [PATCH 181/280] solve #3005: Count Elements With Maximum Frequency in java --- README.md | 2 +- src/CountElementsWithMaximumFrequency.java | 36 ++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 src/CountElementsWithMaximumFrequency.java diff --git a/README.md b/README.md index 831afe7..f056eb0 100644 --- a/README.md +++ b/README.md @@ -881,7 +881,7 @@ | 2980 | [Check if Bitwise OR Has Trailing Zeros](https://leetcode.com/problems/check-if-bitwise-or-has-trailing-zeros) | [![Java](assets/java.png)](src/CheckIfBitwiseORHasTrailingZeros.java) | | | 2996 | [Smallest Missing Integer Greater Than Sequential Prefix Sum](https://leetcode.com/problems/smallest-missing-integer-greater-than-sequential-prefix-sum) | [![Java](assets/java.png)](src/SmallestMissingIntegerGreaterThanSequentialPrefixSum.java) | | | 3000 | [Maximum Area of Longest Diagonal Rectangle](https://leetcode.com/problems/maximum-area-of-longest-diagonal-rectangle) | [![Java](assets/java.png)](src/MaximumAreaOfLongestDiagonalRectangle.java) | | -| 3005 | [Count Elements With Maximum Frequency](https://leetcode.com/problems/count-elements-with-maximum-frequency) | | | +| 3005 | [Count Elements With Maximum Frequency](https://leetcode.com/problems/count-elements-with-maximum-frequency) | [![Java](assets/java.png)](src/CountElementsWithMaximumFrequency.java) | | | 3010 | [Divide an Array Into Subarrays With Minimum Cost I](https://leetcode.com/problems/divide-an-array-into-subarrays-with-minimum-cost-i) | | | | 3014 | [Minimum Number of Pushes to Type Word I](https://leetcode.com/problems/minimum-number-of-pushes-to-type-word-i) | | | | 3019 | [Number of Changing Keys](https://leetcode.com/problems/number-of-changing-keys) | | | diff --git a/src/CountElementsWithMaximumFrequency.java b/src/CountElementsWithMaximumFrequency.java new file mode 100644 index 0000000..6671636 --- /dev/null +++ b/src/CountElementsWithMaximumFrequency.java @@ -0,0 +1,36 @@ +// https://leetcode.com/problems/count-elements-with-maximum-frequency +// T: O(N) +// S: O(N) + +import java.util.HashMap; +import java.util.Map; + +public class CountElementsWithMaximumFrequency { + public int maxFrequencyElements(int[] array) { + final Map frequencies = computeFrequencies(array); + final int maxFrequency = getMaxFrequency(frequencies); + return numberOfElementsWithFrequency(frequencies, maxFrequency); + } + + private static Map computeFrequencies(int[] array) { + final Map map = new HashMap<>(); + for (int element : array) { + map.put(element, map.getOrDefault(element, 0) + 1); + } + return map; + } + + private static int getMaxFrequency(final Map frequencies) { + return frequencies.values().stream().max(Integer::compareTo).get(); + } + + private static int numberOfElementsWithFrequency(Map frequencies, int frequency) { + int sum = 0; + for (Map.Entry entry : frequencies.entrySet()) { + if (entry.getValue() == frequency) { + sum += frequency; + } + } + return sum; + } +} From abeb834ee2a1dd84ab97fbd75edb376975d6c97f Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 6 Jul 2024 20:54:07 +0200 Subject: [PATCH 182/280] solve #3010: Divide an Array Into Subarrays With Minimum Cost I in java --- README.md | 2 +- ...deAnArrayIntoSubarraysWithMinimumCostI.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/DivideAnArrayIntoSubarraysWithMinimumCostI.java diff --git a/README.md b/README.md index f056eb0..1cb53d6 100644 --- a/README.md +++ b/README.md @@ -882,7 +882,7 @@ | 2996 | [Smallest Missing Integer Greater Than Sequential Prefix Sum](https://leetcode.com/problems/smallest-missing-integer-greater-than-sequential-prefix-sum) | [![Java](assets/java.png)](src/SmallestMissingIntegerGreaterThanSequentialPrefixSum.java) | | | 3000 | [Maximum Area of Longest Diagonal Rectangle](https://leetcode.com/problems/maximum-area-of-longest-diagonal-rectangle) | [![Java](assets/java.png)](src/MaximumAreaOfLongestDiagonalRectangle.java) | | | 3005 | [Count Elements With Maximum Frequency](https://leetcode.com/problems/count-elements-with-maximum-frequency) | [![Java](assets/java.png)](src/CountElementsWithMaximumFrequency.java) | | -| 3010 | [Divide an Array Into Subarrays With Minimum Cost I](https://leetcode.com/problems/divide-an-array-into-subarrays-with-minimum-cost-i) | | | +| 3010 | [Divide an Array Into Subarrays With Minimum Cost I](https://leetcode.com/problems/divide-an-array-into-subarrays-with-minimum-cost-i) | [![Java](assets/java.png)](src/DivideAnArrayIntoSubarraysWithMinimumCostI.java) | | | 3014 | [Minimum Number of Pushes to Type Word I](https://leetcode.com/problems/minimum-number-of-pushes-to-type-word-i) | | | | 3019 | [Number of Changing Keys](https://leetcode.com/problems/number-of-changing-keys) | | | | 3024 | [Type of Triangle](https://leetcode.com/problems/type-of-triangle) | | | diff --git a/src/DivideAnArrayIntoSubarraysWithMinimumCostI.java b/src/DivideAnArrayIntoSubarraysWithMinimumCostI.java new file mode 100644 index 0000000..908d9db --- /dev/null +++ b/src/DivideAnArrayIntoSubarraysWithMinimumCostI.java @@ -0,0 +1,18 @@ +// https://leetcode.com/problems/divide-an-array-into-subarrays-with-minimum-cost-i +// T: O(N) +// S: O(1) + +public class DivideAnArrayIntoSubarraysWithMinimumCostI { + public int minimumCost(int[] array) { + int smallest = Integer.MAX_VALUE, secondSmallest = Integer.MAX_VALUE; + for (int i = 1 ; i < array.length ; i++) { + if (array[i] < smallest) { + secondSmallest = smallest; + smallest = array[i]; + } else if (array[i] < secondSmallest) { + secondSmallest = array[i]; + } + } + return array[0] + smallest + secondSmallest; + } +} From 6c8ca95dac8eae6b9f7a10e2d2cfd6d1f58205e5 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 11 Jul 2024 16:23:16 +0200 Subject: [PATCH 183/280] solve Minimum Number of Pushes to Type Word I in java --- README.md | 2 +- src/MinimumNumberOfPushesToTypeWordI.java | 28 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/MinimumNumberOfPushesToTypeWordI.java diff --git a/README.md b/README.md index 1cb53d6..73fecf2 100644 --- a/README.md +++ b/README.md @@ -883,7 +883,7 @@ | 3000 | [Maximum Area of Longest Diagonal Rectangle](https://leetcode.com/problems/maximum-area-of-longest-diagonal-rectangle) | [![Java](assets/java.png)](src/MaximumAreaOfLongestDiagonalRectangle.java) | | | 3005 | [Count Elements With Maximum Frequency](https://leetcode.com/problems/count-elements-with-maximum-frequency) | [![Java](assets/java.png)](src/CountElementsWithMaximumFrequency.java) | | | 3010 | [Divide an Array Into Subarrays With Minimum Cost I](https://leetcode.com/problems/divide-an-array-into-subarrays-with-minimum-cost-i) | [![Java](assets/java.png)](src/DivideAnArrayIntoSubarraysWithMinimumCostI.java) | | -| 3014 | [Minimum Number of Pushes to Type Word I](https://leetcode.com/problems/minimum-number-of-pushes-to-type-word-i) | | | +| 3014 | [Minimum Number of Pushes to Type Word I](https://leetcode.com/problems/minimum-number-of-pushes-to-type-word-i) | [![Java](assets/java.png)](src/MinimumNumberOfPushesToTypeWordI.java) | | | 3019 | [Number of Changing Keys](https://leetcode.com/problems/number-of-changing-keys) | | | | 3024 | [Type of Triangle](https://leetcode.com/problems/type-of-triangle) | | | | 3028 | [Ant on the Boundary](https://leetcode.com/problems/ant-on-the-boundary) | | | diff --git a/src/MinimumNumberOfPushesToTypeWordI.java b/src/MinimumNumberOfPushesToTypeWordI.java new file mode 100644 index 0000000..2231bb3 --- /dev/null +++ b/src/MinimumNumberOfPushesToTypeWordI.java @@ -0,0 +1,28 @@ +// https://leetcode.com/problems/minimum-number-of-pushes-to-type-word-i +// T: O(|word|) +// S: O(|word|) + +import java.util.HashMap; +import java.util.Map; + +public class MinimumNumberOfPushesToTypeWordI { + public static int minimumPushes(String word) { + final Map letterFrequency = getLetterFrequencies(word); + final var entries = letterFrequency.entrySet().stream().sorted((a, b) -> Integer.compare(b.getValue(), a.getValue())).toList(); + + int pushes = 0; + for (int i = 0 ; i < entries.size() ; i++) { + pushes += entries.get(i).getValue() * ((i + 8) / 8); + } + + return pushes; + } + + private static Map getLetterFrequencies(String s) { + final Map frequencies = new HashMap<>(); + for (int i = 0 ; i < s.length() ; i++) { + frequencies.put(s.charAt(i), frequencies.getOrDefault(s.charAt(i), 0) + 1); + } + return frequencies; + } +} From f22a25baee7d5e04a78556054c3d6de1bbef1cc4 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 11 Jul 2024 16:27:59 +0200 Subject: [PATCH 184/280] solve #3019: Number of Changing Keys in java --- README.md | 2 +- src/NumberOfChangingKeys.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/NumberOfChangingKeys.java diff --git a/README.md b/README.md index 73fecf2..bf27955 100644 --- a/README.md +++ b/README.md @@ -884,7 +884,7 @@ | 3005 | [Count Elements With Maximum Frequency](https://leetcode.com/problems/count-elements-with-maximum-frequency) | [![Java](assets/java.png)](src/CountElementsWithMaximumFrequency.java) | | | 3010 | [Divide an Array Into Subarrays With Minimum Cost I](https://leetcode.com/problems/divide-an-array-into-subarrays-with-minimum-cost-i) | [![Java](assets/java.png)](src/DivideAnArrayIntoSubarraysWithMinimumCostI.java) | | | 3014 | [Minimum Number of Pushes to Type Word I](https://leetcode.com/problems/minimum-number-of-pushes-to-type-word-i) | [![Java](assets/java.png)](src/MinimumNumberOfPushesToTypeWordI.java) | | -| 3019 | [Number of Changing Keys](https://leetcode.com/problems/number-of-changing-keys) | | | +| 3019 | [Number of Changing Keys](https://leetcode.com/problems/number-of-changing-keys) | [![Java](assets/java.png)](src/NumberOfChangingKeys.java) | | | 3024 | [Type of Triangle](https://leetcode.com/problems/type-of-triangle) | | | | 3028 | [Ant on the Boundary](https://leetcode.com/problems/ant-on-the-boundary) | | | | 3032 | 🔒 [Count Numbers With Unique Digits II](https://leetcode.com/problems/count-numbers-with-unique-digits-ii) | | | diff --git a/src/NumberOfChangingKeys.java b/src/NumberOfChangingKeys.java new file mode 100644 index 0000000..6bef959 --- /dev/null +++ b/src/NumberOfChangingKeys.java @@ -0,0 +1,19 @@ +// https://leetcode.com/problems/number-of-changing-keys +// T: O(|s|) +// S: O(1) + +public class NumberOfChangingKeys { + public int countKeyChanges(String s) { + int changes = 0; + for (int i = 1 ; i < s.length() ; i++) { + if (isDifferent(s.charAt(i - 1), s.charAt(i))) { + changes++; + } + } + return changes; + } + + private static boolean isDifferent(char a, char b) { + return Character.toLowerCase(a) != Character.toLowerCase(b); + } +} From 46398d2d77898f819af889dc26894de220a7f887 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 11 Jul 2024 16:45:35 +0200 Subject: [PATCH 185/280] solve #3024: Type of Triangle in java --- README.md | 2 +- src/TypeOfTriangle.java | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/TypeOfTriangle.java diff --git a/README.md b/README.md index bf27955..69eb610 100644 --- a/README.md +++ b/README.md @@ -885,7 +885,7 @@ | 3010 | [Divide an Array Into Subarrays With Minimum Cost I](https://leetcode.com/problems/divide-an-array-into-subarrays-with-minimum-cost-i) | [![Java](assets/java.png)](src/DivideAnArrayIntoSubarraysWithMinimumCostI.java) | | | 3014 | [Minimum Number of Pushes to Type Word I](https://leetcode.com/problems/minimum-number-of-pushes-to-type-word-i) | [![Java](assets/java.png)](src/MinimumNumberOfPushesToTypeWordI.java) | | | 3019 | [Number of Changing Keys](https://leetcode.com/problems/number-of-changing-keys) | [![Java](assets/java.png)](src/NumberOfChangingKeys.java) | | -| 3024 | [Type of Triangle](https://leetcode.com/problems/type-of-triangle) | | | +| 3024 | [Type of Triangle](https://leetcode.com/problems/type-of-triangle) | [![Java](assets/java.png)](src/TypeOfTriangle.java) | | | 3028 | [Ant on the Boundary](https://leetcode.com/problems/ant-on-the-boundary) | | | | 3032 | 🔒 [Count Numbers With Unique Digits II](https://leetcode.com/problems/count-numbers-with-unique-digits-ii) | | | | 3038 | [Maximum Number of Operations With the Same Score I](https://leetcode.com/problems/maximum-number-of-operations-with-the-same-score-i) | | | diff --git a/src/TypeOfTriangle.java b/src/TypeOfTriangle.java new file mode 100644 index 0000000..9b39e0f --- /dev/null +++ b/src/TypeOfTriangle.java @@ -0,0 +1,22 @@ +// https://leetcode.com/problems/type-of-triangle +// T: O(1) +// S: O(1) + +public class TypeOfTriangle { + public String triangleType(int[] sides) { + if (!isValidTriangle(sides)) { + return "none"; + } + if (sides[0] == sides[1] && sides[1] == sides[2]) { + return "equilateral"; + } + if (sides[0] == sides[1] || sides[0] == sides[2] || sides[1] == sides[2]) { + return "isosceles"; + } + return "scalene"; + } + + private static boolean isValidTriangle(int[] sides) { + return sides[0] + sides[1] > sides[2] && sides[0] + sides[2] > sides[1] && sides[1] + sides[2] > sides[0]; + } +} From b5c0a5c5c3c851fbdc4acb12e896bffd5ea08dfe Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 11 Jul 2024 16:49:52 +0200 Subject: [PATCH 186/280] solves #3028: ant on the boundary --- README.md | 2 +- src/AntOnTheBoundary.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/AntOnTheBoundary.java diff --git a/README.md b/README.md index 69eb610..698645a 100644 --- a/README.md +++ b/README.md @@ -886,7 +886,7 @@ | 3014 | [Minimum Number of Pushes to Type Word I](https://leetcode.com/problems/minimum-number-of-pushes-to-type-word-i) | [![Java](assets/java.png)](src/MinimumNumberOfPushesToTypeWordI.java) | | | 3019 | [Number of Changing Keys](https://leetcode.com/problems/number-of-changing-keys) | [![Java](assets/java.png)](src/NumberOfChangingKeys.java) | | | 3024 | [Type of Triangle](https://leetcode.com/problems/type-of-triangle) | [![Java](assets/java.png)](src/TypeOfTriangle.java) | | -| 3028 | [Ant on the Boundary](https://leetcode.com/problems/ant-on-the-boundary) | | | +| 3028 | [Ant on the Boundary](https://leetcode.com/problems/ant-on-the-boundary) | [![Java](assets/java.png)](src/AntOnTheBoundary.java) | | | 3032 | 🔒 [Count Numbers With Unique Digits II](https://leetcode.com/problems/count-numbers-with-unique-digits-ii) | | | | 3038 | [Maximum Number of Operations With the Same Score I](https://leetcode.com/problems/maximum-number-of-operations-with-the-same-score-i) | | | | 3042 | [Count Prefix and Suffix Pairs I](https://leetcode.com/problems/count-prefix-and-suffix-pairs-i) | | | diff --git a/src/AntOnTheBoundary.java b/src/AntOnTheBoundary.java new file mode 100644 index 0000000..0920f7c --- /dev/null +++ b/src/AntOnTheBoundary.java @@ -0,0 +1,16 @@ +// https://leetcode.com/problems/ant-on-the-boundary +// T: O(N) +// S: O(1) + +public class AntOnTheBoundary { + public int returnToBoundaryCount(int[] array) { + int onTheBoundary = 0, distance = 0; + for (int element : array) { + distance += element; + if (distance == 0) { + onTheBoundary++; + } + } + return onTheBoundary; + } +} From 3dae99a9ddeebe095829a220f6658a1f05598d58 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 11 Jul 2024 16:58:05 +0200 Subject: [PATCH 187/280] solve #3033: Modify the Matrix in java --- README.md | 1 + src/ModifyTheMatrix.java | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/ModifyTheMatrix.java diff --git a/README.md b/README.md index 698645a..a34f70a 100644 --- a/README.md +++ b/README.md @@ -888,6 +888,7 @@ | 3024 | [Type of Triangle](https://leetcode.com/problems/type-of-triangle) | [![Java](assets/java.png)](src/TypeOfTriangle.java) | | | 3028 | [Ant on the Boundary](https://leetcode.com/problems/ant-on-the-boundary) | [![Java](assets/java.png)](src/AntOnTheBoundary.java) | | | 3032 | 🔒 [Count Numbers With Unique Digits II](https://leetcode.com/problems/count-numbers-with-unique-digits-ii) | | | +| 3033 | [Modify the Matrix](https://leetcode.com/problems/modify-the-matrix) | [![Java](assets/java.png)](src/ModifyTheMatrix.java) | | | 3038 | [Maximum Number of Operations With the Same Score I](https://leetcode.com/problems/maximum-number-of-operations-with-the-same-score-i) | | | | 3042 | [Count Prefix and Suffix Pairs I](https://leetcode.com/problems/count-prefix-and-suffix-pairs-i) | | | | 3046 | [Split the Array](https://leetcode.com/problems/split-the-array) | | | diff --git a/src/ModifyTheMatrix.java b/src/ModifyTheMatrix.java new file mode 100644 index 0000000..12db3fb --- /dev/null +++ b/src/ModifyTheMatrix.java @@ -0,0 +1,32 @@ +// https://leetcode.com/problems/modify-the-matrix +// T: O(m * n) +// S: O(1) + +public class ModifyTheMatrix { + public int[][] modifiedMatrix(int[][] matrix) { + final int rows = matrix.length, columns = matrix[0].length; + + for (int column = 0 ; column < columns ; column++) { + final int maxValueColumn = getMaxInColumn(matrix, column); + replaceAllNegative1With(matrix, column, maxValueColumn); + } + + return matrix; + } + + private static int getMaxInColumn(int[][] matrix, int column) { + int maxValue = Integer.MIN_VALUE; + for (int[] row : matrix) { + maxValue = Math.max(maxValue, row[column]); + } + return maxValue; + } + + private static void replaceAllNegative1With(int[][] matrix, int column, int value) { + for (int row = 0 ; row < matrix.length ; row++) { + if (matrix[row][column] == -1) { + matrix[row][column] = value; + } + } + } +} From 1dcab3401d36f44f2fc32dd7c4d2b94b59339a07 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 11 Jul 2024 17:03:53 +0200 Subject: [PATCH 188/280] solves #3038: Maximum Number of Operations With the Same Score I in java --- README.md | 2 +- ...imumNumberOfOperationsWithTheSameScoreI.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/MaximumNumberOfOperationsWithTheSameScoreI.java diff --git a/README.md b/README.md index a34f70a..26c36fc 100644 --- a/README.md +++ b/README.md @@ -889,7 +889,7 @@ | 3028 | [Ant on the Boundary](https://leetcode.com/problems/ant-on-the-boundary) | [![Java](assets/java.png)](src/AntOnTheBoundary.java) | | | 3032 | 🔒 [Count Numbers With Unique Digits II](https://leetcode.com/problems/count-numbers-with-unique-digits-ii) | | | | 3033 | [Modify the Matrix](https://leetcode.com/problems/modify-the-matrix) | [![Java](assets/java.png)](src/ModifyTheMatrix.java) | | -| 3038 | [Maximum Number of Operations With the Same Score I](https://leetcode.com/problems/maximum-number-of-operations-with-the-same-score-i) | | | +| 3038 | [Maximum Number of Operations With the Same Score I](https://leetcode.com/problems/maximum-number-of-operations-with-the-same-score-i) | [![Java](assets/java.png)](src/MaximumNumberOfOperationsWithTheSameScoreI.java) | | | 3042 | [Count Prefix and Suffix Pairs I](https://leetcode.com/problems/count-prefix-and-suffix-pairs-i) | | | | 3046 | [Split the Array](https://leetcode.com/problems/split-the-array) | | | | 3062 | 🔒 [Winner of the Linked List Game](https://leetcode.com/problems/winner-of-the-linked-list-game) | | | diff --git a/src/MaximumNumberOfOperationsWithTheSameScoreI.java b/src/MaximumNumberOfOperationsWithTheSameScoreI.java new file mode 100644 index 0000000..7314091 --- /dev/null +++ b/src/MaximumNumberOfOperationsWithTheSameScoreI.java @@ -0,0 +1,17 @@ +// https://leetcode.com/problems/maximum-number-of-operations-with-the-same-score-i +// T: O(N) +// S: O(1) + +public class MaximumNumberOfOperationsWithTheSameScoreI { + public int maxOperations(int[] array) { + int maxOperations = 1; + for (int i = 2 ; i < array.length - 1 ; i += 2) { + if ((array[i] + array[i + 1]) == (array[0] + array[1])) { + maxOperations++; + } else { + break; + } + } + return maxOperations; + } +} From 1509c99a12e988b04d41310399ec914234fdcaaa Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 11 Jul 2024 17:10:14 +0200 Subject: [PATCH 189/280] solves #3042: Count Prefix and Suffix Pairs I in java --- README.md | 2 +- src/CountPrefixAndSuffixPairsI.java | 39 +++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/CountPrefixAndSuffixPairsI.java diff --git a/README.md b/README.md index 26c36fc..e409a71 100644 --- a/README.md +++ b/README.md @@ -890,7 +890,7 @@ | 3032 | 🔒 [Count Numbers With Unique Digits II](https://leetcode.com/problems/count-numbers-with-unique-digits-ii) | | | | 3033 | [Modify the Matrix](https://leetcode.com/problems/modify-the-matrix) | [![Java](assets/java.png)](src/ModifyTheMatrix.java) | | | 3038 | [Maximum Number of Operations With the Same Score I](https://leetcode.com/problems/maximum-number-of-operations-with-the-same-score-i) | [![Java](assets/java.png)](src/MaximumNumberOfOperationsWithTheSameScoreI.java) | | -| 3042 | [Count Prefix and Suffix Pairs I](https://leetcode.com/problems/count-prefix-and-suffix-pairs-i) | | | +| 3042 | [Count Prefix and Suffix Pairs I](https://leetcode.com/problems/count-prefix-and-suffix-pairs-i) | [![Java](assets/java.png)](src/CountPrefixAndSuffixPairsI.java) | | | 3046 | [Split the Array](https://leetcode.com/problems/split-the-array) | | | | 3062 | 🔒 [Winner of the Linked List Game](https://leetcode.com/problems/winner-of-the-linked-list-game) | | | | 3063 | 🔒 [Linked List Frequency](https://leetcode.com/problems/linked-list-frequency) | | | diff --git a/src/CountPrefixAndSuffixPairsI.java b/src/CountPrefixAndSuffixPairsI.java new file mode 100644 index 0000000..c53fb4b --- /dev/null +++ b/src/CountPrefixAndSuffixPairsI.java @@ -0,0 +1,39 @@ +// https://leetcode.com/problems/count-prefix-and-suffix-pairs-i +// T: O(|words|^2 * |words[i].length|) +// S: O(1) + +public class CountPrefixAndSuffixPairsI { + public int countPrefixSuffixPairs(String[] words) { + int pairs = 0; + for (int i = 0 ; i < words.length ; i++) { + for (int j = i + 1 ; j < words.length ; j++) { + if (isPrefixAndSuffix(words[i], words[j])) { + pairs++; + } + } + } + return pairs; + } + + private static boolean isPrefixAndSuffix(String a, String b) { + if (a.length() > b.length()) { + return false; + } + + // prefix + for (int i = 0 ; i < a.length() ; i++) { + if (a.charAt(i) != b.charAt(i)) { + return false; + } + } + + //suffix + for (int i = 0; i < a.length() ; i++) { + if (a.charAt(i) != b.charAt(b.length() - a.length() + i)) { + return false; + } + } + + return true; + } +} From 87a907e2c78b8aacf8adbf6e632c1a13b8cc79ee Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 11 Jul 2024 17:14:23 +0200 Subject: [PATCH 190/280] solves #3046: Split the Array in java --- README.md | 2 +- src/SplitTheArray.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/SplitTheArray.java diff --git a/README.md b/README.md index e409a71..58a2a19 100644 --- a/README.md +++ b/README.md @@ -891,7 +891,7 @@ | 3033 | [Modify the Matrix](https://leetcode.com/problems/modify-the-matrix) | [![Java](assets/java.png)](src/ModifyTheMatrix.java) | | | 3038 | [Maximum Number of Operations With the Same Score I](https://leetcode.com/problems/maximum-number-of-operations-with-the-same-score-i) | [![Java](assets/java.png)](src/MaximumNumberOfOperationsWithTheSameScoreI.java) | | | 3042 | [Count Prefix and Suffix Pairs I](https://leetcode.com/problems/count-prefix-and-suffix-pairs-i) | [![Java](assets/java.png)](src/CountPrefixAndSuffixPairsI.java) | | -| 3046 | [Split the Array](https://leetcode.com/problems/split-the-array) | | | +| 3046 | [Split the Array](https://leetcode.com/problems/split-the-array) | [![Java](assets/java.png)](src/SplitTheArray.java) | | | 3062 | 🔒 [Winner of the Linked List Game](https://leetcode.com/problems/winner-of-the-linked-list-game) | | | | 3063 | 🔒 [Linked List Frequency](https://leetcode.com/problems/linked-list-frequency) | | | | 3065 | [Minimum Operations to Exceed Threshold Value I](https://leetcode.com/problems/minimum-operations-to-exceed-threshold-value-i) | | | diff --git a/src/SplitTheArray.java b/src/SplitTheArray.java new file mode 100644 index 0000000..c86c43a --- /dev/null +++ b/src/SplitTheArray.java @@ -0,0 +1,19 @@ +// https://leetcode.com/problems/split-the-array +// T: O(N) +// S: O(N) + +import java.util.HashMap; +import java.util.Map; + +public class SplitTheArray { + public boolean isPossibleToSplit(int[] array) { + final Map frequencies = new HashMap<>(); + for (int element : array) { + if (frequencies.getOrDefault(element, 0) == 2) { + return false; + } + frequencies.put(element, frequencies.getOrDefault(element, 0) + 1); + } + return true; + } +} From 4300da2e13ecd921f8bc4494cf2a5b943c742ba7 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 11 Jul 2024 17:36:00 +0200 Subject: [PATCH 191/280] solves #3065: Minimum Operations to Exceed Threshold Value I in java --- README.md | 8 +++---- ...imumOperationsToExceedThresholdValueI.java | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 src/MinimumOperationsToExceedThresholdValueI.java diff --git a/README.md b/README.md index 58a2a19..a88dad4 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # LeetCode Algorithms ![problems-solved](https://img.shields.io/badge/Problems%20Solved-682/2813-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-674/2813-1abc9c.svg) -![problems-solved-python](https://img.shields.io/badge/Python-205/2813-1abc9c.svg) -![problems-solved-javascript](https://img.shields.io/badge/JavaScript-4/2813-1abc9c.svg) +![problems-solved-java](https://img.shields.io/badge/Java-752/3215-1abc9c.svg) +![problems-solved-python](https://img.shields.io/badge/Python-204/3215-1abc9c.svg) +![problems-solved-javascript](https://img.shields.io/badge/JavaScript-4/3215-1abc9c.svg) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md) [![cp](https://img.shields.io/badge/also%20see-Competitve%20Programming-1f72ff.svg)](https://github.com/anishLearnsToCode/competitive-programming) @@ -894,7 +894,7 @@ | 3046 | [Split the Array](https://leetcode.com/problems/split-the-array) | [![Java](assets/java.png)](src/SplitTheArray.java) | | | 3062 | 🔒 [Winner of the Linked List Game](https://leetcode.com/problems/winner-of-the-linked-list-game) | | | | 3063 | 🔒 [Linked List Frequency](https://leetcode.com/problems/linked-list-frequency) | | | -| 3065 | [Minimum Operations to Exceed Threshold Value I](https://leetcode.com/problems/minimum-operations-to-exceed-threshold-value-i) | | | +| 3065 | [Minimum Operations to Exceed Threshold Value I](https://leetcode.com/problems/minimum-operations-to-exceed-threshold-value-i) | [![Java](assets/java.png)](src/MinimumOperationsToExceedThresholdValueI.java) | | | 3069 | [Distribute Elements Into Two Arrays I](https://leetcode.com/problems/distribute-elements-into-two-arrays-i) | | | | 3074 | [Apple Redistribution into Boxes](https://leetcode.com/problems/apple-redistribution-into-boxes) | | | | 3079 | [Find the Sum of Encrypted Integers](https://leetcode.com/problems/find-the-sum-of-encrypted-integers) | | | diff --git a/src/MinimumOperationsToExceedThresholdValueI.java b/src/MinimumOperationsToExceedThresholdValueI.java new file mode 100644 index 0000000..c864ae3 --- /dev/null +++ b/src/MinimumOperationsToExceedThresholdValueI.java @@ -0,0 +1,24 @@ +// https://leetcode.com/problems/minimum-operations-to-exceed-threshold-value-i +// T: O(N log(N)) +// S: O(log(N)) + +import java.util.Arrays; + +public class MinimumOperationsToExceedThresholdValueI { + public int minOperations(int[] array, int k) { + Arrays.sort(array); + return binarySearch(array, k); + } + + // binary search with left drag + private static int binarySearch(int[] array, int element) { + int left = 0, right = array.length - 1, middle; + while (left <= right) { + middle = left + (right - left) / 2; + if (array[middle] == element) right = middle - 1; + else if (array[middle] <= element) left = middle + 1; + else right = middle - 1; + } + return left; + } +} From 0f49e4b9f3570a1ad719c844a86fa8028a1422d5 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 11 Jul 2024 17:51:14 +0200 Subject: [PATCH 192/280] solve #3069: Distribute Elements Into Two Arrays I in java --- README.md | 2 +- src/DistributeElementsIntoTwoArraysI.java | 37 +++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/DistributeElementsIntoTwoArraysI.java diff --git a/README.md b/README.md index a88dad4..de56f35 100644 --- a/README.md +++ b/README.md @@ -895,7 +895,7 @@ | 3062 | 🔒 [Winner of the Linked List Game](https://leetcode.com/problems/winner-of-the-linked-list-game) | | | | 3063 | 🔒 [Linked List Frequency](https://leetcode.com/problems/linked-list-frequency) | | | | 3065 | [Minimum Operations to Exceed Threshold Value I](https://leetcode.com/problems/minimum-operations-to-exceed-threshold-value-i) | [![Java](assets/java.png)](src/MinimumOperationsToExceedThresholdValueI.java) | | -| 3069 | [Distribute Elements Into Two Arrays I](https://leetcode.com/problems/distribute-elements-into-two-arrays-i) | | | +| 3069 | [Distribute Elements Into Two Arrays I](https://leetcode.com/problems/distribute-elements-into-two-arrays-i) | [![Java](assets/java.png)](src/DistributeElementsIntoTwoArraysI.java) | | | 3074 | [Apple Redistribution into Boxes](https://leetcode.com/problems/apple-redistribution-into-boxes) | | | | 3079 | [Find the Sum of Encrypted Integers](https://leetcode.com/problems/find-the-sum-of-encrypted-integers) | | | | 3083 | [Existence of a Substring in a String and Its Reverse](https://leetcode.com/problems/existence-of-a-substring-in-a-string-and-its-reverse) | | | diff --git a/src/DistributeElementsIntoTwoArraysI.java b/src/DistributeElementsIntoTwoArraysI.java new file mode 100644 index 0000000..4584f66 --- /dev/null +++ b/src/DistributeElementsIntoTwoArraysI.java @@ -0,0 +1,37 @@ +// https://leetcode.com/problems/distribute-elements-into-two-arrays-i +// T: O(N) +// S: O(N) + +import java.util.ArrayList; +import java.util.List; + +public class DistributeElementsIntoTwoArraysI { + public int[] resultArray(int[] array) { + final List array1 = new ArrayList<>(); + final List array2 = new ArrayList<>(); + + array1.add(array[0]); + array2.add(array[1]); + + for (int i = 2 ; i < array.length ; i++) { + if (array1.get(array1.size() - 1) > array2.get(array2.size() - 1)) { + array1.add(array[i]); + } else { + array2.add(array[i]); + } + } + + return concatenate(array1, array2); + } + + private static int[] concatenate(List array1, List array2) { + final int[] result = new int[array1.size() + array2.size()]; + for (int i = 0 ; i < array1.size() ; i++) { + result[i] = array1.get(i); + } + for (int i = 0 ; i < array2.size() ; i++) { + result[array1.size() + i] = array2.get(i); + } + return result; + } +} From 7d6d5825c825beb72ea7e46cd06868ae37c2c394 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 11 Jul 2024 18:00:12 +0200 Subject: [PATCH 193/280] solves #3074: Apple Redistribution into Boxes in java --- README.md | 2 +- src/AppleRedistributionIntoBoxes.java | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 src/AppleRedistributionIntoBoxes.java diff --git a/README.md b/README.md index de56f35..6fc8784 100644 --- a/README.md +++ b/README.md @@ -896,7 +896,7 @@ | 3063 | 🔒 [Linked List Frequency](https://leetcode.com/problems/linked-list-frequency) | | | | 3065 | [Minimum Operations to Exceed Threshold Value I](https://leetcode.com/problems/minimum-operations-to-exceed-threshold-value-i) | [![Java](assets/java.png)](src/MinimumOperationsToExceedThresholdValueI.java) | | | 3069 | [Distribute Elements Into Two Arrays I](https://leetcode.com/problems/distribute-elements-into-two-arrays-i) | [![Java](assets/java.png)](src/DistributeElementsIntoTwoArraysI.java) | | -| 3074 | [Apple Redistribution into Boxes](https://leetcode.com/problems/apple-redistribution-into-boxes) | | | +| 3074 | [Apple Redistribution into Boxes](https://leetcode.com/problems/apple-redistribution-into-boxes) | [![Java](assets/java.png)](src/AppleRedistributionIntoBoxes.java) | | | 3079 | [Find the Sum of Encrypted Integers](https://leetcode.com/problems/find-the-sum-of-encrypted-integers) | | | | 3083 | [Existence of a Substring in a String and Its Reverse](https://leetcode.com/problems/existence-of-a-substring-in-a-string-and-its-reverse) | | | | 3090 | [Maximum Length Substring With Two Occurrences](https://leetcode.com/problems/maximum-length-substring-with-two-occurrences) | | | diff --git a/src/AppleRedistributionIntoBoxes.java b/src/AppleRedistributionIntoBoxes.java new file mode 100644 index 0000000..ebb707c --- /dev/null +++ b/src/AppleRedistributionIntoBoxes.java @@ -0,0 +1,23 @@ +// https://leetcode.com/problems/apple-redistribution-into-boxes +// N = |apples|, M = |capacity| +// T: O(N + M log(M)) +// S: O(log(M)) + +import java.util.Arrays; + +public class AppleRedistributionIntoBoxes { + public int minimumBoxes(int[] apple, int[] capacity) { + int totalApples = Arrays.stream(apple).sum(); + Arrays.sort(capacity); + + int boxesRequired = 0; + for (int i = capacity.length - 1 ; i >= 0 ; i--) { + if (totalApples <= 0) { + break; + } + totalApples -= capacity[i]; + boxesRequired++; + } + return boxesRequired; + } +} From 227aff08604fd8290968f7b1e9211ef3b6939fd1 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 11 Jul 2024 18:06:23 +0200 Subject: [PATCH 194/280] solves #3079: Find the Sum of Encrypted Integers in java --- README.md | 2 +- src/FindTheSumOfEncryptedIntegers.java | 27 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/FindTheSumOfEncryptedIntegers.java diff --git a/README.md b/README.md index 6fc8784..c85ae42 100644 --- a/README.md +++ b/README.md @@ -897,7 +897,7 @@ | 3065 | [Minimum Operations to Exceed Threshold Value I](https://leetcode.com/problems/minimum-operations-to-exceed-threshold-value-i) | [![Java](assets/java.png)](src/MinimumOperationsToExceedThresholdValueI.java) | | | 3069 | [Distribute Elements Into Two Arrays I](https://leetcode.com/problems/distribute-elements-into-two-arrays-i) | [![Java](assets/java.png)](src/DistributeElementsIntoTwoArraysI.java) | | | 3074 | [Apple Redistribution into Boxes](https://leetcode.com/problems/apple-redistribution-into-boxes) | [![Java](assets/java.png)](src/AppleRedistributionIntoBoxes.java) | | -| 3079 | [Find the Sum of Encrypted Integers](https://leetcode.com/problems/find-the-sum-of-encrypted-integers) | | | +| 3079 | [Find the Sum of Encrypted Integers](https://leetcode.com/problems/find-the-sum-of-encrypted-integers) | [![Java](assets/java.png)](src/FindTheSumOfEncryptedIntegers.java) | | | 3083 | [Existence of a Substring in a String and Its Reverse](https://leetcode.com/problems/existence-of-a-substring-in-a-string-and-its-reverse) | | | | 3090 | [Maximum Length Substring With Two Occurrences](https://leetcode.com/problems/maximum-length-substring-with-two-occurrences) | | | | 3095 | [Shortest Subarray With OR at Least K I](https://leetcode.com/problems/shortest-subarray-with-or-at-least-k-i) | | | diff --git a/src/FindTheSumOfEncryptedIntegers.java b/src/FindTheSumOfEncryptedIntegers.java new file mode 100644 index 0000000..aaae55d --- /dev/null +++ b/src/FindTheSumOfEncryptedIntegers.java @@ -0,0 +1,27 @@ +// https://leetcode.com/problems/find-the-sum-of-encrypted-integers +// T: O(N) +// S: O(1) + +public class FindTheSumOfEncryptedIntegers { + public int sumOfEncryptedInt(int[] array) { + int sum = 0; + for (int element : array) { + sum += encryptedInteger(element); + } + return sum; + } + + private static int encryptedInteger(int x) { + int maxDigit = 0, digits = 0; + while (x > 0) { + maxDigit = Math.max(maxDigit, x % 10); + digits++; + x /= 10; + } + int result = 0; + while (digits-- > 0) { + result = 10 * result + maxDigit; + } + return result; + } +} From c14dd2d29790f3265b4d9c13b84a6ee6f4f88886 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 11 Jul 2024 18:11:56 +0200 Subject: [PATCH 195/280] solve #3083: Existence of a Substring in a String and Its Reverse in java --- README.md | 2 +- ...nceOfASubstringInAStringAndItsReverse.java | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/ExistenceOfASubstringInAStringAndItsReverse.java diff --git a/README.md b/README.md index c85ae42..c03af12 100644 --- a/README.md +++ b/README.md @@ -898,7 +898,7 @@ | 3069 | [Distribute Elements Into Two Arrays I](https://leetcode.com/problems/distribute-elements-into-two-arrays-i) | [![Java](assets/java.png)](src/DistributeElementsIntoTwoArraysI.java) | | | 3074 | [Apple Redistribution into Boxes](https://leetcode.com/problems/apple-redistribution-into-boxes) | [![Java](assets/java.png)](src/AppleRedistributionIntoBoxes.java) | | | 3079 | [Find the Sum of Encrypted Integers](https://leetcode.com/problems/find-the-sum-of-encrypted-integers) | [![Java](assets/java.png)](src/FindTheSumOfEncryptedIntegers.java) | | -| 3083 | [Existence of a Substring in a String and Its Reverse](https://leetcode.com/problems/existence-of-a-substring-in-a-string-and-its-reverse) | | | +| 3083 | [Existence of a Substring in a String and Its Reverse](https://leetcode.com/problems/existence-of-a-substring-in-a-string-and-its-reverse) | [![Java](assets/java.png)](src/ExistenceOfASubstringInAStringAndItsReverse.java) | | | 3090 | [Maximum Length Substring With Two Occurrences](https://leetcode.com/problems/maximum-length-substring-with-two-occurrences) | | | | 3095 | [Shortest Subarray With OR at Least K I](https://leetcode.com/problems/shortest-subarray-with-or-at-least-k-i) | | | | 3099 | [Harshad Number](https://leetcode.com/problems/harshad-number) | | | diff --git a/src/ExistenceOfASubstringInAStringAndItsReverse.java b/src/ExistenceOfASubstringInAStringAndItsReverse.java new file mode 100644 index 0000000..1753057 --- /dev/null +++ b/src/ExistenceOfASubstringInAStringAndItsReverse.java @@ -0,0 +1,24 @@ +// https://leetcode.com/problems/existence-of-a-substring-in-a-string-and-its-reverse +// T: O(N^2) +// S: O(1) + +public class ExistenceOfASubstringInAStringAndItsReverse { + public boolean isSubstringPresent(String s) { + for (int i = 0 ; i < s.length() - 1 ; i++) { + final String substring = s.substring(i, i + 2); + if (reverseStringContains(s, substring)) { + return true; + } + } + return false; + } + + private static boolean reverseStringContains(String s, String substring) { + for (int i = s.length() - 1 ; i > 0 ; i--) { + if (s.charAt(i) == substring.charAt(0) && s.charAt(i - 1) == substring.charAt(1)) { + return true; + } + } + return false; + } +} From e4e5920796726a5a036000537684ab995532989e Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 11 Jul 2024 18:28:11 +0200 Subject: [PATCH 196/280] solves #3090: Maximum Length Substring With Two Occurrences in java --- README.md | 2 +- ...imumLengthSubstringWithTwoOccurrences.java | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/MaximumLengthSubstringWithTwoOccurrences.java diff --git a/README.md b/README.md index c03af12..0912a98 100644 --- a/README.md +++ b/README.md @@ -899,7 +899,7 @@ | 3074 | [Apple Redistribution into Boxes](https://leetcode.com/problems/apple-redistribution-into-boxes) | [![Java](assets/java.png)](src/AppleRedistributionIntoBoxes.java) | | | 3079 | [Find the Sum of Encrypted Integers](https://leetcode.com/problems/find-the-sum-of-encrypted-integers) | [![Java](assets/java.png)](src/FindTheSumOfEncryptedIntegers.java) | | | 3083 | [Existence of a Substring in a String and Its Reverse](https://leetcode.com/problems/existence-of-a-substring-in-a-string-and-its-reverse) | [![Java](assets/java.png)](src/ExistenceOfASubstringInAStringAndItsReverse.java) | | -| 3090 | [Maximum Length Substring With Two Occurrences](https://leetcode.com/problems/maximum-length-substring-with-two-occurrences) | | | +| 3090 | [Maximum Length Substring With Two Occurrences](https://leetcode.com/problems/maximum-length-substring-with-two-occurrences) | [![Java](assets/java.png)](src/MaximumLengthSubstringWithTwoOccurrences.java) | | | 3095 | [Shortest Subarray With OR at Least K I](https://leetcode.com/problems/shortest-subarray-with-or-at-least-k-i) | | | | 3099 | [Harshad Number](https://leetcode.com/problems/harshad-number) | | | | 3105 | [Longest Strictly Increasing or Strictly Decreasing Subarray](https://leetcode.com/problems/longest-strictly-increasing-or-strictly-decreasing-subarray) | | | diff --git a/src/MaximumLengthSubstringWithTwoOccurrences.java b/src/MaximumLengthSubstringWithTwoOccurrences.java new file mode 100644 index 0000000..37b0abe --- /dev/null +++ b/src/MaximumLengthSubstringWithTwoOccurrences.java @@ -0,0 +1,26 @@ +// https://leetcode.com/problems/maximum-length-substring-with-two-occurrences +// T: O(N) +// S: O(1) + +import java.util.HashMap; +import java.util.Map; + +public class MaximumLengthSubstringWithTwoOccurrences { + public int maximumLengthSubstring(String s) { + final Map frequencies = new HashMap<>(); + int maxLength = 1; + + for (int left = 0, right = 0 ; left < s.length() && right < s.length() ; ) { + if (frequencies.getOrDefault(s.charAt(right), 0) == 2) { + frequencies.put(s.charAt(left), frequencies.get(s.charAt(left)) - 1); + left++; + } else { + frequencies.put(s.charAt(right), frequencies.getOrDefault(s.charAt(right), 0) + 1); + right++; + maxLength = Math.max(maxLength, right - left); + } + } + + return maxLength; + } +} From 80f303bd062254c39544fc5892a1ecc07f0b10b8 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 15 Jul 2024 21:03:17 +0200 Subject: [PATCH 197/280] solve #3095: Shortest Subarray With OR at Least K I in java --- README.md | 2 +- src/ShortestSubarrayWithORAtLeastKI.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/ShortestSubarrayWithORAtLeastKI.java diff --git a/README.md b/README.md index 0912a98..cda92bb 100644 --- a/README.md +++ b/README.md @@ -900,7 +900,7 @@ | 3079 | [Find the Sum of Encrypted Integers](https://leetcode.com/problems/find-the-sum-of-encrypted-integers) | [![Java](assets/java.png)](src/FindTheSumOfEncryptedIntegers.java) | | | 3083 | [Existence of a Substring in a String and Its Reverse](https://leetcode.com/problems/existence-of-a-substring-in-a-string-and-its-reverse) | [![Java](assets/java.png)](src/ExistenceOfASubstringInAStringAndItsReverse.java) | | | 3090 | [Maximum Length Substring With Two Occurrences](https://leetcode.com/problems/maximum-length-substring-with-two-occurrences) | [![Java](assets/java.png)](src/MaximumLengthSubstringWithTwoOccurrences.java) | | -| 3095 | [Shortest Subarray With OR at Least K I](https://leetcode.com/problems/shortest-subarray-with-or-at-least-k-i) | | | +| 3095 | [Shortest Subarray With OR at Least K I](https://leetcode.com/problems/shortest-subarray-with-or-at-least-k-i) | [![Java](assets/java.png)](src/ShortestSubarrayWithORAtLeastKI.java) | | | 3099 | [Harshad Number](https://leetcode.com/problems/harshad-number) | | | | 3105 | [Longest Strictly Increasing or Strictly Decreasing Subarray](https://leetcode.com/problems/longest-strictly-increasing-or-strictly-decreasing-subarray) | | | | 3110 | [Score of a String](https://leetcode.com/problems/score-of-a-string) | | | diff --git a/src/ShortestSubarrayWithORAtLeastKI.java b/src/ShortestSubarrayWithORAtLeastKI.java new file mode 100644 index 0000000..4a3ed45 --- /dev/null +++ b/src/ShortestSubarrayWithORAtLeastKI.java @@ -0,0 +1,19 @@ +// https://leetcode.com/problems/shortest-subarray-with-or-at-least-k-i +// T: O(N^2) +// S: O(1) + +public class ShortestSubarrayWithORAtLeastKI { + public int minimumSubarrayLength(int[] array, int k) { + int minLength = Integer.MAX_VALUE; + for (int i = 0 ; i < array.length ; i++) { + int current = array[i]; + for (int j = i ; j < array.length ; j++) { + current |= array[j]; + if (current >= k) { + minLength = Math.min(minLength, j - i + 1); + } + } + } + return minLength == Integer.MAX_VALUE ? -1 : minLength; + } +} From a645e7cba715ae1f44cdb9df3fd9b4eefb85e7c5 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 15 Jul 2024 21:06:30 +0200 Subject: [PATCH 198/280] solves #3099: Harshad Number in java --- README.md | 2 +- src/HarshadNumber.java | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/HarshadNumber.java diff --git a/README.md b/README.md index cda92bb..565f192 100644 --- a/README.md +++ b/README.md @@ -901,7 +901,7 @@ | 3083 | [Existence of a Substring in a String and Its Reverse](https://leetcode.com/problems/existence-of-a-substring-in-a-string-and-its-reverse) | [![Java](assets/java.png)](src/ExistenceOfASubstringInAStringAndItsReverse.java) | | | 3090 | [Maximum Length Substring With Two Occurrences](https://leetcode.com/problems/maximum-length-substring-with-two-occurrences) | [![Java](assets/java.png)](src/MaximumLengthSubstringWithTwoOccurrences.java) | | | 3095 | [Shortest Subarray With OR at Least K I](https://leetcode.com/problems/shortest-subarray-with-or-at-least-k-i) | [![Java](assets/java.png)](src/ShortestSubarrayWithORAtLeastKI.java) | | -| 3099 | [Harshad Number](https://leetcode.com/problems/harshad-number) | | | +| 3099 | [Harshad Number](https://leetcode.com/problems/harshad-number) | [![Java](assets/java.png)](src/HarshadNumber.java) | | | 3105 | [Longest Strictly Increasing or Strictly Decreasing Subarray](https://leetcode.com/problems/longest-strictly-increasing-or-strictly-decreasing-subarray) | | | | 3110 | [Score of a String](https://leetcode.com/problems/score-of-a-string) | | | | 3114 | [Latest Time You Can Obtain After Replacing Characters](https://leetcode.com/problems/latest-time-you-can-obtain-after-replacing-characters) | | | diff --git a/src/HarshadNumber.java b/src/HarshadNumber.java new file mode 100644 index 0000000..a7ba4b8 --- /dev/null +++ b/src/HarshadNumber.java @@ -0,0 +1,22 @@ +// https://leetcode.com/problems/harshad-number +// T: O(log(N)) +// S: O(1) + +public class HarshadNumber { + public int sumOfTheDigitsOfHarshadNumber(int x) { + final int sumOfDigits = sumOfDigits(x); + if (x % sumOfDigits == 0) { + return sumOfDigits; + } + return -1; + } + + private static int sumOfDigits(int x) { + int sum = 0; + while (x > 0) { + sum += x % 10; + x /= 10; + } + return sum; + } +} From 20cc5c0522013e9a4159b35a52fc2801a5a4a9c9 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 15 Jul 2024 21:21:00 +0200 Subject: [PATCH 199/280] solves #3105: Longest Strictly Increasing or Strictly Decreasing Subarray in java --- README.md | 2 +- ...ncreasingOrStrictlyDecreasingSubarray.java | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/LongestStrictlyIncreasingOrStrictlyDecreasingSubarray.java diff --git a/README.md b/README.md index 565f192..0c0bfca 100644 --- a/README.md +++ b/README.md @@ -902,7 +902,7 @@ | 3090 | [Maximum Length Substring With Two Occurrences](https://leetcode.com/problems/maximum-length-substring-with-two-occurrences) | [![Java](assets/java.png)](src/MaximumLengthSubstringWithTwoOccurrences.java) | | | 3095 | [Shortest Subarray With OR at Least K I](https://leetcode.com/problems/shortest-subarray-with-or-at-least-k-i) | [![Java](assets/java.png)](src/ShortestSubarrayWithORAtLeastKI.java) | | | 3099 | [Harshad Number](https://leetcode.com/problems/harshad-number) | [![Java](assets/java.png)](src/HarshadNumber.java) | | -| 3105 | [Longest Strictly Increasing or Strictly Decreasing Subarray](https://leetcode.com/problems/longest-strictly-increasing-or-strictly-decreasing-subarray) | | | +| 3105 | [Longest Strictly Increasing or Strictly Decreasing Subarray](https://leetcode.com/problems/longest-strictly-increasing-or-strictly-decreasing-subarray) | [![Java](assets/java.png)](src/LongestStrictlyIncreasingOrStrictlyDecreasingSubarray.java) | | | 3110 | [Score of a String](https://leetcode.com/problems/score-of-a-string) | | | | 3114 | [Latest Time You Can Obtain After Replacing Characters](https://leetcode.com/problems/latest-time-you-can-obtain-after-replacing-characters) | | | | 3120 | [Count the Number of Special Characters I](https://leetcode.com/problems/count-the-number-of-special-characters-i) | | | diff --git a/src/LongestStrictlyIncreasingOrStrictlyDecreasingSubarray.java b/src/LongestStrictlyIncreasingOrStrictlyDecreasingSubarray.java new file mode 100644 index 0000000..dd161f5 --- /dev/null +++ b/src/LongestStrictlyIncreasingOrStrictlyDecreasingSubarray.java @@ -0,0 +1,38 @@ +// https://leetcode.com/problems/longest-strictly-increasing-or-strictly-decreasing-subarray +// T: O(N) +// S: O(1) + +public class LongestStrictlyIncreasingOrStrictlyDecreasingSubarray { + public int longestMonotonicSubarray(int[] array) { + return Math.max( + lengthLongestIncreasingSubarray(array), + lengthLongestDecreasingSubarray(array) + ); + } + + private static int lengthLongestIncreasingSubarray(int[] array) { + int length = 1; + for (int i = 1, current = 1 ; i < array.length ; i++) { + if (array[i] > array[i - 1]) { + current++; + } else { + current = 1; + } + length = Math.max(length, current); + } + return length; + } + + private static int lengthLongestDecreasingSubarray(int[] array) { + int length = 1; + for (int i = 1, current = 1 ; i < array.length ; i++) { + if (array[i] < array[i - 1]) { + current++; + } else { + current = 1; + } + length = Math.max(length, current); + } + return length; + } +} From de065fa6de28abf5fb6829421875ff92c5d7e743 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 15 Jul 2024 21:23:51 +0200 Subject: [PATCH 200/280] solves #3110: Score of a String in java --- README.md | 2 +- src/ScoreOfAString.java | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/ScoreOfAString.java diff --git a/README.md b/README.md index 0c0bfca..433ddcc 100644 --- a/README.md +++ b/README.md @@ -903,7 +903,7 @@ | 3095 | [Shortest Subarray With OR at Least K I](https://leetcode.com/problems/shortest-subarray-with-or-at-least-k-i) | [![Java](assets/java.png)](src/ShortestSubarrayWithORAtLeastKI.java) | | | 3099 | [Harshad Number](https://leetcode.com/problems/harshad-number) | [![Java](assets/java.png)](src/HarshadNumber.java) | | | 3105 | [Longest Strictly Increasing or Strictly Decreasing Subarray](https://leetcode.com/problems/longest-strictly-increasing-or-strictly-decreasing-subarray) | [![Java](assets/java.png)](src/LongestStrictlyIncreasingOrStrictlyDecreasingSubarray.java) | | -| 3110 | [Score of a String](https://leetcode.com/problems/score-of-a-string) | | | +| 3110 | [Score of a String](https://leetcode.com/problems/score-of-a-string) | [![Java](assets/java.png)](src/ScoreOfAString.java) | | | 3114 | [Latest Time You Can Obtain After Replacing Characters](https://leetcode.com/problems/latest-time-you-can-obtain-after-replacing-characters) | | | | 3120 | [Count the Number of Special Characters I](https://leetcode.com/problems/count-the-number-of-special-characters-i) | | | | 3127 | [Make a Square with the Same Color](https://leetcode.com/problems/make-a-square-with-the-same-color) | | | diff --git a/src/ScoreOfAString.java b/src/ScoreOfAString.java new file mode 100644 index 0000000..eedb041 --- /dev/null +++ b/src/ScoreOfAString.java @@ -0,0 +1,13 @@ +// https://leetcode.com/problems/score-of-a-string +// T: O(N) +// S: O(1) + +public class ScoreOfAString { + public int scoreOfString(String s) { + int sum = 0; + for (int i = 0 ; i < s.length() - 1 ; i++) { + sum += Math.abs(s.charAt(i) - s.charAt(i + 1)); + } + return sum; + } +} From f194fb48fee85391bcc56b28180358290ade5f94 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 15 Jul 2024 21:39:52 +0200 Subject: [PATCH 201/280] solves #3114: Latest Time You Can Obtain After Replacing Characters in java --- README.md | 2 +- ...eYouCanObtainAfterReplacingCharacters.java | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/LatestTimeYouCanObtainAfterReplacingCharacters.java diff --git a/README.md b/README.md index 433ddcc..e3edc56 100644 --- a/README.md +++ b/README.md @@ -904,7 +904,7 @@ | 3099 | [Harshad Number](https://leetcode.com/problems/harshad-number) | [![Java](assets/java.png)](src/HarshadNumber.java) | | | 3105 | [Longest Strictly Increasing or Strictly Decreasing Subarray](https://leetcode.com/problems/longest-strictly-increasing-or-strictly-decreasing-subarray) | [![Java](assets/java.png)](src/LongestStrictlyIncreasingOrStrictlyDecreasingSubarray.java) | | | 3110 | [Score of a String](https://leetcode.com/problems/score-of-a-string) | [![Java](assets/java.png)](src/ScoreOfAString.java) | | -| 3114 | [Latest Time You Can Obtain After Replacing Characters](https://leetcode.com/problems/latest-time-you-can-obtain-after-replacing-characters) | | | +| 3114 | [Latest Time You Can Obtain After Replacing Characters](https://leetcode.com/problems/latest-time-you-can-obtain-after-replacing-characters) | [![Java](assets/java.png)](src/LatestTimeYouCanObtainAfterReplacingCharacters.java) | | | 3120 | [Count the Number of Special Characters I](https://leetcode.com/problems/count-the-number-of-special-characters-i) | | | | 3127 | [Make a Square with the Same Color](https://leetcode.com/problems/make-a-square-with-the-same-color) | | | | 3131 | [Find the Integer Added to Array I](https://leetcode.com/problems/find-the-integer-added-to-array-i) | | | diff --git a/src/LatestTimeYouCanObtainAfterReplacingCharacters.java b/src/LatestTimeYouCanObtainAfterReplacingCharacters.java new file mode 100644 index 0000000..34d1ff7 --- /dev/null +++ b/src/LatestTimeYouCanObtainAfterReplacingCharacters.java @@ -0,0 +1,35 @@ +// https://leetcode.com/problems/latest-time-you-can-obtain-after-replacing-characters +// T: O(1) +// S: O(1) + +public class LatestTimeYouCanObtainAfterReplacingCharacters { + public String findLatestTime(String s) { + return maxHour(s.substring(0, 2)) + ":" + maxMinutes(s.substring(3)); + } + + private static String maxHour(String s) { + if (s.charAt(0) == '?' && s.charAt(1) == '?') { + return "11"; + } + if (s.charAt(0) == '?') { + return (s.charAt(1) <= '1' ? "1" : "0") + s.charAt(1); + } + if (s.charAt(1) == '?') { + return s.charAt(0) + (s.charAt(0) == '0' ? "9" : "1"); + } + return s; + } + + private static String maxMinutes(String s) { + if (s.charAt(0) == '?' && s.charAt(1) == '?') { + return "59"; + } + if (s.charAt(0) == '?') { + return "5" + s.charAt(1); + } + if (s.charAt(1) == '?') { + return s.charAt(0) + "9"; + } + return s; + } +} From cea492982a94a7b79f19a150a36fc0fc93d6cf8d Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 15 Jul 2024 21:45:31 +0200 Subject: [PATCH 202/280] solves #3120: Count the Number of Special Characters I in java --- README.md | 2 +- src/CountTheNumberOfSpecialCharactersI.java | 32 +++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/CountTheNumberOfSpecialCharactersI.java diff --git a/README.md b/README.md index e3edc56..d4aa3f8 100644 --- a/README.md +++ b/README.md @@ -905,7 +905,7 @@ | 3105 | [Longest Strictly Increasing or Strictly Decreasing Subarray](https://leetcode.com/problems/longest-strictly-increasing-or-strictly-decreasing-subarray) | [![Java](assets/java.png)](src/LongestStrictlyIncreasingOrStrictlyDecreasingSubarray.java) | | | 3110 | [Score of a String](https://leetcode.com/problems/score-of-a-string) | [![Java](assets/java.png)](src/ScoreOfAString.java) | | | 3114 | [Latest Time You Can Obtain After Replacing Characters](https://leetcode.com/problems/latest-time-you-can-obtain-after-replacing-characters) | [![Java](assets/java.png)](src/LatestTimeYouCanObtainAfterReplacingCharacters.java) | | -| 3120 | [Count the Number of Special Characters I](https://leetcode.com/problems/count-the-number-of-special-characters-i) | | | +| 3120 | [Count the Number of Special Characters I](https://leetcode.com/problems/count-the-number-of-special-characters-i) | [![Java](assets/java.png)](src/CountTheNumberOfSpecialCharactersI.java) | | | 3127 | [Make a Square with the Same Color](https://leetcode.com/problems/make-a-square-with-the-same-color) | | | | 3131 | [Find the Integer Added to Array I](https://leetcode.com/problems/find-the-integer-added-to-array-i) | | | | 3136 | [Valid Word](https://leetcode.com/problems/valid-word) | | | diff --git a/src/CountTheNumberOfSpecialCharactersI.java b/src/CountTheNumberOfSpecialCharactersI.java new file mode 100644 index 0000000..538a318 --- /dev/null +++ b/src/CountTheNumberOfSpecialCharactersI.java @@ -0,0 +1,32 @@ +// https://leetcode.com/problems/count-the-number-of-special-characters-i +// T: O(N) +// S: O(1) + +import java.util.HashSet; +import java.util.Set; + +public class CountTheNumberOfSpecialCharactersI { + public int numberOfSpecialChars(String word) { + final Set characters = new HashSet<>(); + final Set alreadyCounted = new HashSet<>(); + int specialChars = 0; + + for (int i = 0 ; i < word.length() ; i++) { + characters.add(word.charAt(i)); + if (characters.contains(inverse(word.charAt(i))) && !alreadyCounted.contains(word.charAt(i))) { + specialChars++; + alreadyCounted.add(word.charAt(i)); + alreadyCounted.add(inverse(word.charAt(i))); + } + } + + return specialChars; + } + + private static char inverse(char c) { + if (Character.isLowerCase(c)) { + return Character.toUpperCase(c); + } + return Character.toLowerCase(c); + } +} From b3b46dc0bb8c076bca023f7973bceb67ec06224d Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 16 Jul 2024 16:49:35 +0200 Subject: [PATCH 203/280] solves #3127: Make a Square with the Same Color in java --- README.md | 2 +- src/MakeASquareWithTheSameColor.java | 33 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/MakeASquareWithTheSameColor.java diff --git a/README.md b/README.md index d4aa3f8..ac86dda 100644 --- a/README.md +++ b/README.md @@ -906,7 +906,7 @@ | 3110 | [Score of a String](https://leetcode.com/problems/score-of-a-string) | [![Java](assets/java.png)](src/ScoreOfAString.java) | | | 3114 | [Latest Time You Can Obtain After Replacing Characters](https://leetcode.com/problems/latest-time-you-can-obtain-after-replacing-characters) | [![Java](assets/java.png)](src/LatestTimeYouCanObtainAfterReplacingCharacters.java) | | | 3120 | [Count the Number of Special Characters I](https://leetcode.com/problems/count-the-number-of-special-characters-i) | [![Java](assets/java.png)](src/CountTheNumberOfSpecialCharactersI.java) | | -| 3127 | [Make a Square with the Same Color](https://leetcode.com/problems/make-a-square-with-the-same-color) | | | +| 3127 | [Make a Square with the Same Color](https://leetcode.com/problems/make-a-square-with-the-same-color) | [![Java](assets/java.png)](src/MakeASquareWithTheSameColor.java) | | | 3131 | [Find the Integer Added to Array I](https://leetcode.com/problems/find-the-integer-added-to-array-i) | | | | 3136 | [Valid Word](https://leetcode.com/problems/valid-word) | | | | 3142 | [Check if Grid Satisfies Conditions](https://leetcode.com/problems/check-if-grid-satisfies-conditions) | | | diff --git a/src/MakeASquareWithTheSameColor.java b/src/MakeASquareWithTheSameColor.java new file mode 100644 index 0000000..9d04700 --- /dev/null +++ b/src/MakeASquareWithTheSameColor.java @@ -0,0 +1,33 @@ +// https://leetcode.com/problems/make-a-square-with-the-same-color +// T: O(1) +// S: O(1) + +public class MakeASquareWithTheSameColor { + public boolean canMakeSquare(char[][] grid) { + for (int i = 0 ; i < 2 ; i++) { + for (int j = 0 ; j < 2 ; j++) { + if (isPossibleToMakeSquare(grid, i, j)) { + return true; + } + } + } + return false; + } + + private static boolean isPossibleToMakeSquare(char[][] grid, int i, int j) { + int numberOfBlacks = 0; + int numberOfWhites = 0; + + for (int row = i ; row < i + 2 ; row++) { + for (int column = j ; column < j + 2 ; column++) { + if (grid[row][column] == 'W') { + numberOfWhites++; + } else { + numberOfBlacks++; + } + } + } + + return numberOfBlacks == 4 || numberOfWhites == 4 || numberOfBlacks == 3 || numberOfWhites == 3; + } +} From 1a47bf15e329482316bf0cd57e71d159f0e9a189 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 16 Jul 2024 16:54:07 +0200 Subject: [PATCH 204/280] a --- README.md | 2 +- src/FindTheIntegerAddedToArrayI.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/FindTheIntegerAddedToArrayI.java diff --git a/README.md b/README.md index ac86dda..9b7f04d 100644 --- a/README.md +++ b/README.md @@ -907,7 +907,7 @@ | 3114 | [Latest Time You Can Obtain After Replacing Characters](https://leetcode.com/problems/latest-time-you-can-obtain-after-replacing-characters) | [![Java](assets/java.png)](src/LatestTimeYouCanObtainAfterReplacingCharacters.java) | | | 3120 | [Count the Number of Special Characters I](https://leetcode.com/problems/count-the-number-of-special-characters-i) | [![Java](assets/java.png)](src/CountTheNumberOfSpecialCharactersI.java) | | | 3127 | [Make a Square with the Same Color](https://leetcode.com/problems/make-a-square-with-the-same-color) | [![Java](assets/java.png)](src/MakeASquareWithTheSameColor.java) | | -| 3131 | [Find the Integer Added to Array I](https://leetcode.com/problems/find-the-integer-added-to-array-i) | | | +| 3131 | [Find the Integer Added to Array I](https://leetcode.com/problems/find-the-integer-added-to-array-i) | [![Java](assets/java.png)](src/FindTheIntegerAddedToArrayI.java) | | | 3136 | [Valid Word](https://leetcode.com/problems/valid-word) | | | | 3142 | [Check if Grid Satisfies Conditions](https://leetcode.com/problems/check-if-grid-satisfies-conditions) | | | | 3146 | [Permutation Difference between Two Strings](https://leetcode.com/problems/permutation-difference-between-two-strings) | | | diff --git a/src/FindTheIntegerAddedToArrayI.java b/src/FindTheIntegerAddedToArrayI.java new file mode 100644 index 0000000..4b1898f --- /dev/null +++ b/src/FindTheIntegerAddedToArrayI.java @@ -0,0 +1,19 @@ +// https://leetcode.com/problems/find-the-integer-added-to-array-i +// T: O(N) +// S: O(1) + +public class FindTheIntegerAddedToArrayI { + public int addedInteger(int[] array1, int[] array2) { + final int min1 = smallestElement(array1); + final int min2 = smallestElement(array2); + return min2 - min1; + } + + private static int smallestElement(int[] array) { + int result = Integer.MAX_VALUE; + for (int element : array) { + result = Math.min(result, element); + } + return result; + } +} From 7529944fc9801bf20969e29b2c107969510b9aa3 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 18 Jul 2024 02:20:39 +0200 Subject: [PATCH 205/280] solves #3142: Check if Grid Satisfies Conditions in java --- README.md | 4 +-- src/CheckIfGridSatisfiesConditions.java | 19 ++++++++++++ src/ValidWord.java | 40 +++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 src/CheckIfGridSatisfiesConditions.java create mode 100644 src/ValidWord.java diff --git a/README.md b/README.md index 9b7f04d..6a10897 100644 --- a/README.md +++ b/README.md @@ -908,8 +908,8 @@ | 3120 | [Count the Number of Special Characters I](https://leetcode.com/problems/count-the-number-of-special-characters-i) | [![Java](assets/java.png)](src/CountTheNumberOfSpecialCharactersI.java) | | | 3127 | [Make a Square with the Same Color](https://leetcode.com/problems/make-a-square-with-the-same-color) | [![Java](assets/java.png)](src/MakeASquareWithTheSameColor.java) | | | 3131 | [Find the Integer Added to Array I](https://leetcode.com/problems/find-the-integer-added-to-array-i) | [![Java](assets/java.png)](src/FindTheIntegerAddedToArrayI.java) | | -| 3136 | [Valid Word](https://leetcode.com/problems/valid-word) | | | -| 3142 | [Check if Grid Satisfies Conditions](https://leetcode.com/problems/check-if-grid-satisfies-conditions) | | | +| 3136 | [Valid Word](https://leetcode.com/problems/valid-word) | [![Java](assets/java.png)](src/ValidWord.java) | | +| 3142 | [Check if Grid Satisfies Conditions](https://leetcode.com/problems/check-if-grid-satisfies-conditions) | [![Java](assets/java.png)](src/CheckIfGridSatisfiesConditions.java) | | | 3146 | [Permutation Difference between Two Strings](https://leetcode.com/problems/permutation-difference-between-two-strings) | | | | 3151 | [Special Array I](https://leetcode.com/problems/special-array-i) | | | | 3158 | [Find the XOR of Numbers Which Appear Twice](https://leetcode.com/problems/find-the-xor-of-numbers-which-appear-twice) | | | diff --git a/src/CheckIfGridSatisfiesConditions.java b/src/CheckIfGridSatisfiesConditions.java new file mode 100644 index 0000000..76acc40 --- /dev/null +++ b/src/CheckIfGridSatisfiesConditions.java @@ -0,0 +1,19 @@ +// https://leetcode.com/problems/check-if-grid-satisfies-conditions +// T: O(m * n) +// S: O(1) + +public class CheckIfGridSatisfiesConditions { + public boolean satisfiesConditions(int[][] grid) { + for (int i = 0 ; i < grid.length ; i++) { + for (int j = 0 ; j < grid[i].length ; j++) { + if (j + 1 < grid[i].length && grid[i][j] == grid[i][j + 1]) { + return false; + } + if (i + 1 < grid.length && grid[i][j] != grid[i + 1][j]) { + return false; + } + } + } + return true; + } +} diff --git a/src/ValidWord.java b/src/ValidWord.java new file mode 100644 index 0000000..3bb2733 --- /dev/null +++ b/src/ValidWord.java @@ -0,0 +1,40 @@ +// https://leetcode.com/problems/valid-word +// T: O(N) +// S: O(1) + +import java.util.Set; + +public class ValidWord { + private static final Set VOWELS = Set.of('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'); + + public boolean isValid(String word) { + return word.length() >= 3 && isAlphaNum(word) && hasOneVowel(word) && hasOneConsonant(word); + } + + private static boolean isAlphaNum(String s) { + for (int i = 0 ; i < s.length() ; i++) { + if (!Character.isAlphabetic(s.charAt(i)) && !Character.isDigit(s.charAt(i))) { + return false; + } + } + return true; + } + + private static boolean hasOneVowel(String s) { + for (int i = 0 ; i < s.length() ; i++) { + if (VOWELS.contains(s.charAt(i))) { + return true; + } + } + return false; + } + + private static boolean hasOneConsonant(String s) { + for (int i = 0 ; i < s.length() ; i++) { + if (Character.isAlphabetic(s.charAt(i)) && !VOWELS.contains(s.charAt(i))) { + return true; + } + } + return false; + } +} From 6a9c74d546540d89689d4e989b02b047109d6ac2 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 18 Jul 2024 02:26:05 +0200 Subject: [PATCH 206/280] solves #3146: Permutation Difference between Two Strings in java --- README.md | 2 +- ...ermutationDifferenceBetweenTwoStrings.java | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/PermutationDifferenceBetweenTwoStrings.java diff --git a/README.md b/README.md index 6a10897..9bbbeb8 100644 --- a/README.md +++ b/README.md @@ -910,7 +910,7 @@ | 3131 | [Find the Integer Added to Array I](https://leetcode.com/problems/find-the-integer-added-to-array-i) | [![Java](assets/java.png)](src/FindTheIntegerAddedToArrayI.java) | | | 3136 | [Valid Word](https://leetcode.com/problems/valid-word) | [![Java](assets/java.png)](src/ValidWord.java) | | | 3142 | [Check if Grid Satisfies Conditions](https://leetcode.com/problems/check-if-grid-satisfies-conditions) | [![Java](assets/java.png)](src/CheckIfGridSatisfiesConditions.java) | | -| 3146 | [Permutation Difference between Two Strings](https://leetcode.com/problems/permutation-difference-between-two-strings) | | | +| 3146 | [Permutation Difference between Two Strings](https://leetcode.com/problems/permutation-difference-between-two-strings) | [![Java](assets/java.png)](src/PermutationDifferenceBetweenTwoStrings.java) | | | 3151 | [Special Array I](https://leetcode.com/problems/special-array-i) | | | | 3158 | [Find the XOR of Numbers Which Appear Twice](https://leetcode.com/problems/find-the-xor-of-numbers-which-appear-twice) | | | | 3162 | [Find the Number of Good Pairs I](https://leetcode.com/problems/find-the-number-of-good-pairs-i) | | | diff --git a/src/PermutationDifferenceBetweenTwoStrings.java b/src/PermutationDifferenceBetweenTwoStrings.java new file mode 100644 index 0000000..dd9a6ac --- /dev/null +++ b/src/PermutationDifferenceBetweenTwoStrings.java @@ -0,0 +1,27 @@ +// https://leetcode.com/problems/permutation-difference-between-two-strings +// T: O(N) +// S: O(1) + +import java.util.HashMap; +import java.util.Map; + +public class PermutationDifferenceBetweenTwoStrings { + public int findPermutationDifference(String s, String t) { + final Map letterIndexes = getCharacterIndexMapping(s); + int sum = 0; + + for (int i = 0 ; i < t.length() ; i++) { + sum += Math.abs(i - letterIndexes.get(t.charAt(i))); + } + + return sum; + } + + private static Map getCharacterIndexMapping(String s) { + final Map map = new HashMap<>(); + for (int i = 0 ; i < s.length() ; i++) { + map.put(s.charAt(i), i); + } + return map; + } +} From ad6f88fbc39d1f0e6d77768905f23321aa580779 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 18 Jul 2024 02:32:07 +0200 Subject: [PATCH 207/280] solves --- README.md | 2 +- src/SpecialArrayI.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/SpecialArrayI.java diff --git a/README.md b/README.md index 9bbbeb8..eb74aa1 100644 --- a/README.md +++ b/README.md @@ -911,7 +911,7 @@ | 3136 | [Valid Word](https://leetcode.com/problems/valid-word) | [![Java](assets/java.png)](src/ValidWord.java) | | | 3142 | [Check if Grid Satisfies Conditions](https://leetcode.com/problems/check-if-grid-satisfies-conditions) | [![Java](assets/java.png)](src/CheckIfGridSatisfiesConditions.java) | | | 3146 | [Permutation Difference between Two Strings](https://leetcode.com/problems/permutation-difference-between-two-strings) | [![Java](assets/java.png)](src/PermutationDifferenceBetweenTwoStrings.java) | | -| 3151 | [Special Array I](https://leetcode.com/problems/special-array-i) | | | +| 3151 | [Special Array I](https://leetcode.com/problems/special-array-i) | [![Java](assets/java.png)](src/SpecialArrayI.java) | | | 3158 | [Find the XOR of Numbers Which Appear Twice](https://leetcode.com/problems/find-the-xor-of-numbers-which-appear-twice) | | | | 3162 | [Find the Number of Good Pairs I](https://leetcode.com/problems/find-the-number-of-good-pairs-i) | | | | 3168 | [Minimum Number of Chairs in a Waiting Room](https://leetcode.com/problems/minimum-number-of-chairs-in-a-waiting-room) | | | diff --git a/src/SpecialArrayI.java b/src/SpecialArrayI.java new file mode 100644 index 0000000..4c2b537 --- /dev/null +++ b/src/SpecialArrayI.java @@ -0,0 +1,14 @@ +// https://leetcode.com/problems/special-array-i +// T: O(N) +// S: O(1) + +public class SpecialArrayI { + public boolean isArraySpecial(int[] array) { + for (int i = 0 ; i < array.length - 1 ; i++) { + if (array[i] % 2 == array[i + 1] % 2) { + return false; + } + } + return true; + } +} From e9424d07d8ee0c028fa0444810db35d720968f0d Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 18 Jul 2024 02:39:09 +0200 Subject: [PATCH 208/280] solves #3158: Find the XOR of Numbers Which Appear Twice --- README.md | 2 +- src/FindTheXOROfNumbersWhichAppearTwice.java | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/FindTheXOROfNumbersWhichAppearTwice.java diff --git a/README.md b/README.md index eb74aa1..984e556 100644 --- a/README.md +++ b/README.md @@ -912,7 +912,7 @@ | 3142 | [Check if Grid Satisfies Conditions](https://leetcode.com/problems/check-if-grid-satisfies-conditions) | [![Java](assets/java.png)](src/CheckIfGridSatisfiesConditions.java) | | | 3146 | [Permutation Difference between Two Strings](https://leetcode.com/problems/permutation-difference-between-two-strings) | [![Java](assets/java.png)](src/PermutationDifferenceBetweenTwoStrings.java) | | | 3151 | [Special Array I](https://leetcode.com/problems/special-array-i) | [![Java](assets/java.png)](src/SpecialArrayI.java) | | -| 3158 | [Find the XOR of Numbers Which Appear Twice](https://leetcode.com/problems/find-the-xor-of-numbers-which-appear-twice) | | | +| 3158 | [Find the XOR of Numbers Which Appear Twice](https://leetcode.com/problems/find-the-xor-of-numbers-which-appear-twice) | [![Java](assets/java.png)](src/FindTheXOROfNumbersWhichAppearTwice.java) | | | 3162 | [Find the Number of Good Pairs I](https://leetcode.com/problems/find-the-number-of-good-pairs-i) | | | | 3168 | [Minimum Number of Chairs in a Waiting Room](https://leetcode.com/problems/minimum-number-of-chairs-in-a-waiting-room) | | | | 3173 | [Bitwise OR of Adjacent Elements](https://leetcode.com/problems/bitwise-or-of-adjacent-elements) | | | diff --git a/src/FindTheXOROfNumbersWhichAppearTwice.java b/src/FindTheXOROfNumbersWhichAppearTwice.java new file mode 100644 index 0000000..83cb97d --- /dev/null +++ b/src/FindTheXOROfNumbersWhichAppearTwice.java @@ -0,0 +1,20 @@ +// https://leetcode.com/problems/find-the-xor-of-numbers-which-appear-twice +// T: O(N) +// S: O(N) + +import java.util.HashSet; +import java.util.Set; + +public class FindTheXOROfNumbersWhichAppearTwice { + public int duplicateNumbersXOR(int[] array) { + final Set numbers = new HashSet<>(); + int result = 0; + for (int element : array) { + if (numbers.contains(element)) { + result ^= element; + } + numbers.add(element); + } + return result; + } +} From faaa538e5bbae32c4d96e6cb2e696e298aa59ab2 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 18 Jul 2024 03:05:19 +0200 Subject: [PATCH 209/280] solves #3162: Find the Number of Good Pairs I in java --- README.md | 2 +- src/FindTheNumberOfGoodPairsI.java | 50 ++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 src/FindTheNumberOfGoodPairsI.java diff --git a/README.md b/README.md index 984e556..8efc5ac 100644 --- a/README.md +++ b/README.md @@ -913,7 +913,7 @@ | 3146 | [Permutation Difference between Two Strings](https://leetcode.com/problems/permutation-difference-between-two-strings) | [![Java](assets/java.png)](src/PermutationDifferenceBetweenTwoStrings.java) | | | 3151 | [Special Array I](https://leetcode.com/problems/special-array-i) | [![Java](assets/java.png)](src/SpecialArrayI.java) | | | 3158 | [Find the XOR of Numbers Which Appear Twice](https://leetcode.com/problems/find-the-xor-of-numbers-which-appear-twice) | [![Java](assets/java.png)](src/FindTheXOROfNumbersWhichAppearTwice.java) | | -| 3162 | [Find the Number of Good Pairs I](https://leetcode.com/problems/find-the-number-of-good-pairs-i) | | | +| 3162 | [Find the Number of Good Pairs I](https://leetcode.com/problems/find-the-number-of-good-pairs-i) | [![Java](assets/java.png)](src/FindTheNumberOfGoodPairsI.java) | | | 3168 | [Minimum Number of Chairs in a Waiting Room](https://leetcode.com/problems/minimum-number-of-chairs-in-a-waiting-room) | | | | 3173 | [Bitwise OR of Adjacent Elements](https://leetcode.com/problems/bitwise-or-of-adjacent-elements) | | | | 3174 | [Clear Digits](https://leetcode.com/problems/clear-digits) | | | diff --git a/src/FindTheNumberOfGoodPairsI.java b/src/FindTheNumberOfGoodPairsI.java new file mode 100644 index 0000000..883f236 --- /dev/null +++ b/src/FindTheNumberOfGoodPairsI.java @@ -0,0 +1,50 @@ +// https://leetcode.com/problems/find-the-number-of-good-pairs-i +// x = largest possible integer +// T: O(n*sqrt(x) + m) +// S: O(n + m) + +import java.util.HashMap; +import java.util.Map; + +public class FindTheNumberOfGoodPairsI { + public int numberOfPairs(int[] array1, int[] array2, int k) { + final Map dividends = getDividendFrequencies(array1, k); + final Map divisors = getElementFrequencies(array2); + int pairs = 0; + + for (Map.Entry entry : dividends.entrySet()) { + final int dividend = entry.getKey(); + final int frequency = entry.getValue(); + + for (int i = 1 ; i * i <= dividend ; i++) { + if (dividend % i == 0) { + pairs += frequency * divisors.getOrDefault(i, 0); + if (i != dividend / i) { + pairs += frequency * divisors.getOrDefault(dividend / i, 0); + } + } + } + } + + return pairs; + } + + private static Map getElementFrequencies(int[] array) { + final Map frequencies = new HashMap<>(); + for (int element : array) { + frequencies.put(element, frequencies.getOrDefault(element, 0) + 1); + } + return frequencies; + } + + private static Map getDividendFrequencies(int[] array, int k) { + final Map frequencies = new HashMap<>(); + for (int element : array) { + if (element % k == 0) { + int quotient = element / k; + frequencies.put(quotient, frequencies.getOrDefault(quotient, 0) + 1); + } + } + return frequencies; + } +} From f15db2e904d5a427c1a40fdf8a603fdf51706c0e Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 18 Jul 2024 03:11:49 +0200 Subject: [PATCH 210/280] solves #3168: Minimum Number of Chairs in a Waiting Room in java --- README.md | 2 +- src/MinimumNumberOfChairsInAWaitingRoom.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/MinimumNumberOfChairsInAWaitingRoom.java diff --git a/README.md b/README.md index 8efc5ac..270af56 100644 --- a/README.md +++ b/README.md @@ -914,7 +914,7 @@ | 3151 | [Special Array I](https://leetcode.com/problems/special-array-i) | [![Java](assets/java.png)](src/SpecialArrayI.java) | | | 3158 | [Find the XOR of Numbers Which Appear Twice](https://leetcode.com/problems/find-the-xor-of-numbers-which-appear-twice) | [![Java](assets/java.png)](src/FindTheXOROfNumbersWhichAppearTwice.java) | | | 3162 | [Find the Number of Good Pairs I](https://leetcode.com/problems/find-the-number-of-good-pairs-i) | [![Java](assets/java.png)](src/FindTheNumberOfGoodPairsI.java) | | -| 3168 | [Minimum Number of Chairs in a Waiting Room](https://leetcode.com/problems/minimum-number-of-chairs-in-a-waiting-room) | | | +| 3168 | [Minimum Number of Chairs in a Waiting Room](https://leetcode.com/problems/minimum-number-of-chairs-in-a-waiting-room) | [![Java](assets/java.png)](src/MinimumNumberOfChairsInAWaitingRoom.java) | | | 3173 | [Bitwise OR of Adjacent Elements](https://leetcode.com/problems/bitwise-or-of-adjacent-elements) | | | | 3174 | [Clear Digits](https://leetcode.com/problems/clear-digits) | | | | 3178 | [Find the Child Who Has the Ball After K Seconds](https://leetcode.com/problems/find-the-child-who-has-the-ball-after-k-seconds) | | | diff --git a/src/MinimumNumberOfChairsInAWaitingRoom.java b/src/MinimumNumberOfChairsInAWaitingRoom.java new file mode 100644 index 0000000..b6e94b0 --- /dev/null +++ b/src/MinimumNumberOfChairsInAWaitingRoom.java @@ -0,0 +1,18 @@ +// https://leetcode.com/problems/minimum-number-of-chairs-in-a-waiting-room +// T: O(N) +// S: O(1) + +public class MinimumNumberOfChairsInAWaitingRoom { + public int minimumChairs(String s) { + int minChairs = 0; + for (int i = 0, sum = 0 ; i < s.length() ; i++) { + if (s.charAt(i) == 'E') { + sum++; + } else { + sum--; + } + minChairs = Math.max(minChairs, sum); + } + return minChairs; + } +} From a5d5471368243ed0a252595fe14118619c2fe96f Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 18 Jul 2024 03:27:32 +0200 Subject: [PATCH 211/280] solves #3174: Clear Digits in java --- README.md | 2 +- src/ClearDigits.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/ClearDigits.java diff --git a/README.md b/README.md index 270af56..51a8c56 100644 --- a/README.md +++ b/README.md @@ -915,7 +915,7 @@ | 3158 | [Find the XOR of Numbers Which Appear Twice](https://leetcode.com/problems/find-the-xor-of-numbers-which-appear-twice) | [![Java](assets/java.png)](src/FindTheXOROfNumbersWhichAppearTwice.java) | | | 3162 | [Find the Number of Good Pairs I](https://leetcode.com/problems/find-the-number-of-good-pairs-i) | [![Java](assets/java.png)](src/FindTheNumberOfGoodPairsI.java) | | | 3168 | [Minimum Number of Chairs in a Waiting Room](https://leetcode.com/problems/minimum-number-of-chairs-in-a-waiting-room) | [![Java](assets/java.png)](src/MinimumNumberOfChairsInAWaitingRoom.java) | | -| 3173 | [Bitwise OR of Adjacent Elements](https://leetcode.com/problems/bitwise-or-of-adjacent-elements) | | | +| 3173 | [Bitwise OR of Adjacent Elements](https://leetcode.com/problems/bitwise-or-of-adjacent-elements) | [![Java](assets/java.png)](src/ClearDigits.java) | | | 3174 | [Clear Digits](https://leetcode.com/problems/clear-digits) | | | | 3178 | [Find the Child Who Has the Ball After K Seconds](https://leetcode.com/problems/find-the-child-who-has-the-ball-after-k-seconds) | | | | 3184 | [Count Pairs That Form a Complete Day I](https://leetcode.com/problems/count-pairs-that-form-a-complete-day-i) | | | diff --git a/src/ClearDigits.java b/src/ClearDigits.java new file mode 100644 index 0000000..9d2bdbd --- /dev/null +++ b/src/ClearDigits.java @@ -0,0 +1,18 @@ +// https://leetcode.com/problems/clear-digits +// T: O(N) +// S: O(N) + +public class ClearDigits { + public String clearDigits(String s) { + final StringBuilder builder = new StringBuilder(); + for (int i = 0, chars = 0, digits = 0 ; i < s.length() ; i++) { + if (Character.isDigit(s.charAt(i))) { + builder.deleteCharAt(builder.length() - 1); + } else { + builder.append(s.charAt(i)); + } + } + + return builder.toString(); + } +} From 8f2fb41152b28901e033c098fa1639e2ef0137ee Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 18 Jul 2024 03:38:24 +0200 Subject: [PATCH 212/280] solves #3178: Find the Child Who Has the Ball After K Seconds in java --- README.md | 6 +++--- src/FindTheChildWhoHasTheBallAfterKSeconds.java | 13 +++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 src/FindTheChildWhoHasTheBallAfterKSeconds.java diff --git a/README.md b/README.md index 51a8c56..26d2303 100644 --- a/README.md +++ b/README.md @@ -915,9 +915,9 @@ | 3158 | [Find the XOR of Numbers Which Appear Twice](https://leetcode.com/problems/find-the-xor-of-numbers-which-appear-twice) | [![Java](assets/java.png)](src/FindTheXOROfNumbersWhichAppearTwice.java) | | | 3162 | [Find the Number of Good Pairs I](https://leetcode.com/problems/find-the-number-of-good-pairs-i) | [![Java](assets/java.png)](src/FindTheNumberOfGoodPairsI.java) | | | 3168 | [Minimum Number of Chairs in a Waiting Room](https://leetcode.com/problems/minimum-number-of-chairs-in-a-waiting-room) | [![Java](assets/java.png)](src/MinimumNumberOfChairsInAWaitingRoom.java) | | -| 3173 | [Bitwise OR of Adjacent Elements](https://leetcode.com/problems/bitwise-or-of-adjacent-elements) | [![Java](assets/java.png)](src/ClearDigits.java) | | -| 3174 | [Clear Digits](https://leetcode.com/problems/clear-digits) | | | -| 3178 | [Find the Child Who Has the Ball After K Seconds](https://leetcode.com/problems/find-the-child-who-has-the-ball-after-k-seconds) | | | +| 3173 | 🔒 [Bitwise OR of Adjacent Elements](https://leetcode.com/problems/bitwise-or-of-adjacent-elements) | | | +| 3174 | [Clear Digits](https://leetcode.com/problems/clear-digits) | [![Java](assets/java.png)](src/ClearDigits.java) | | +| 3178 | [Find the Child Who Has the Ball After K Seconds](https://leetcode.com/problems/find-the-child-who-has-the-ball-after-k-seconds) | [![Java](assets/java.png)](src/FindTheChildWhoHasTheBallAfterKSeconds.java) | | | 3184 | [Count Pairs That Form a Complete Day I](https://leetcode.com/problems/count-pairs-that-form-a-complete-day-i) | | | | 3190 | [Find Minimum Operations to Make All Elements Divisible by Three](https://leetcode.com/problems/find-minimum-operations-to-make-all-elements-divisible-by-three) | | | | 3194 | [Minimum Average of Smallest and Largest Elements](https://leetcode.com/problems/minimum-average-of-smallest-and-largest-elements) | | | diff --git a/src/FindTheChildWhoHasTheBallAfterKSeconds.java b/src/FindTheChildWhoHasTheBallAfterKSeconds.java new file mode 100644 index 0000000..600698f --- /dev/null +++ b/src/FindTheChildWhoHasTheBallAfterKSeconds.java @@ -0,0 +1,13 @@ +// https://leetcode.com/problems/find-the-child-who-has-the-ball-after-k-seconds +// T: O(1) +// S: O(1) + +public class FindTheChildWhoHasTheBallAfterKSeconds { + public int numberOfChild(int n, int k) { + final boolean isLeftDirection = (k / (n - 1)) % 2 == 0; + if (isLeftDirection) { + return k % (n - 1); + } + return n - 1 - (k % (n - 1)); + } +} From e718e7168fea0c6ac5a5af444e9a3717350bb232 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 18 Jul 2024 03:51:24 +0200 Subject: [PATCH 213/280] solves #3184: Count Pairs That Form a Complete Day I in java --- README.md | 2 +- src/CountPairsThatFormACompleteDayI.java | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/CountPairsThatFormACompleteDayI.java diff --git a/README.md b/README.md index 26d2303..ac5ca25 100644 --- a/README.md +++ b/README.md @@ -918,7 +918,7 @@ | 3173 | 🔒 [Bitwise OR of Adjacent Elements](https://leetcode.com/problems/bitwise-or-of-adjacent-elements) | | | | 3174 | [Clear Digits](https://leetcode.com/problems/clear-digits) | [![Java](assets/java.png)](src/ClearDigits.java) | | | 3178 | [Find the Child Who Has the Ball After K Seconds](https://leetcode.com/problems/find-the-child-who-has-the-ball-after-k-seconds) | [![Java](assets/java.png)](src/FindTheChildWhoHasTheBallAfterKSeconds.java) | | -| 3184 | [Count Pairs That Form a Complete Day I](https://leetcode.com/problems/count-pairs-that-form-a-complete-day-i) | | | +| 3184 | [Count Pairs That Form a Complete Day I](https://leetcode.com/problems/count-pairs-that-form-a-complete-day-i) | [![Java](assets/java.png)](src/CountPairsThatFormACompleteDayI.java) | | | 3190 | [Find Minimum Operations to Make All Elements Divisible by Three](https://leetcode.com/problems/find-minimum-operations-to-make-all-elements-divisible-by-three) | | | | 3194 | [Minimum Average of Smallest and Largest Elements](https://leetcode.com/problems/minimum-average-of-smallest-and-largest-elements) | | | | 3199 | [Count Triplets With Even XOR Set Bits I](https://leetcode.com/problems/count-triplets-with-even-xor-set-bits-i) | | | diff --git a/src/CountPairsThatFormACompleteDayI.java b/src/CountPairsThatFormACompleteDayI.java new file mode 100644 index 0000000..16fe939 --- /dev/null +++ b/src/CountPairsThatFormACompleteDayI.java @@ -0,0 +1,22 @@ +// https://leetcode.com/problems/count-pairs-that-form-a-complete-day-i +// T: O(N) +// S: O(N) + +import java.util.HashMap; +import java.util.Map; + +public class CountPairsThatFormACompleteDayI { + public int countCompleteDayPairs(int[] hours) { + final Map frequencies = new HashMap<>(); + int pairs = 0; + + for (int element : hours) { + int required = (24 - (element % 24)) % 24; + int current = element % 24; + pairs += frequencies.getOrDefault(required, 0); + frequencies.put(current, frequencies.getOrDefault(current, 0) + 1); + } + + return pairs; + } +} From d6584042c5eabda53501c4855d91d518c81c6baf Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 18 Jul 2024 03:54:30 +0200 Subject: [PATCH 214/280] solves #3190: Find Minimum Operations to Make All Elements Divisible by Three in java --- README.md | 2 +- ...erationsToMakeAllElementsDivisibleByThree.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/FindMinimumOperationsToMakeAllElementsDivisibleByThree.java diff --git a/README.md b/README.md index ac5ca25..d61f592 100644 --- a/README.md +++ b/README.md @@ -919,7 +919,7 @@ | 3174 | [Clear Digits](https://leetcode.com/problems/clear-digits) | [![Java](assets/java.png)](src/ClearDigits.java) | | | 3178 | [Find the Child Who Has the Ball After K Seconds](https://leetcode.com/problems/find-the-child-who-has-the-ball-after-k-seconds) | [![Java](assets/java.png)](src/FindTheChildWhoHasTheBallAfterKSeconds.java) | | | 3184 | [Count Pairs That Form a Complete Day I](https://leetcode.com/problems/count-pairs-that-form-a-complete-day-i) | [![Java](assets/java.png)](src/CountPairsThatFormACompleteDayI.java) | | -| 3190 | [Find Minimum Operations to Make All Elements Divisible by Three](https://leetcode.com/problems/find-minimum-operations-to-make-all-elements-divisible-by-three) | | | +| 3190 | [Find Minimum Operations to Make All Elements Divisible by Three](https://leetcode.com/problems/find-minimum-operations-to-make-all-elements-divisible-by-three) | [![Java](assets/java.png)](src/FindMinimumOperationsToMakeAllElementsDivisibleByThree.java) | | | 3194 | [Minimum Average of Smallest and Largest Elements](https://leetcode.com/problems/minimum-average-of-smallest-and-largest-elements) | | | | 3199 | [Count Triplets With Even XOR Set Bits I](https://leetcode.com/problems/count-triplets-with-even-xor-set-bits-i) | | | | 3200 | [Maximum Height of a Triangle](https://leetcode.com/problems/maximum-height-of-a-triangle) | | | diff --git a/src/FindMinimumOperationsToMakeAllElementsDivisibleByThree.java b/src/FindMinimumOperationsToMakeAllElementsDivisibleByThree.java new file mode 100644 index 0000000..837e5ae --- /dev/null +++ b/src/FindMinimumOperationsToMakeAllElementsDivisibleByThree.java @@ -0,0 +1,15 @@ +// https://leetcode.com/problems/find-minimum-operations-to-make-all-elements-divisible-by-three +// T: O(N) +// S: O(1) + +public class FindMinimumOperationsToMakeAllElementsDivisibleByThree { + public int minimumOperations(int[] array) { + int minOperations = 0; + for (int element : array) { + if (element % 3 != 0) { + minOperations++; + } + } + return minOperations; + } +} From 2fe97f48817a341cfff8fee4822f01b10b2759cf Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 18 Jul 2024 04:07:39 +0200 Subject: [PATCH 215/280] solves #3194: Minimum Average of Smallest and Largest Elements in java --- README.md | 2 +- ...mumAverageOfSmallestAndLargestElements.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/MinimumAverageOfSmallestAndLargestElements.java diff --git a/README.md b/README.md index d61f592..4ea71c1 100644 --- a/README.md +++ b/README.md @@ -920,6 +920,6 @@ | 3178 | [Find the Child Who Has the Ball After K Seconds](https://leetcode.com/problems/find-the-child-who-has-the-ball-after-k-seconds) | [![Java](assets/java.png)](src/FindTheChildWhoHasTheBallAfterKSeconds.java) | | | 3184 | [Count Pairs That Form a Complete Day I](https://leetcode.com/problems/count-pairs-that-form-a-complete-day-i) | [![Java](assets/java.png)](src/CountPairsThatFormACompleteDayI.java) | | | 3190 | [Find Minimum Operations to Make All Elements Divisible by Three](https://leetcode.com/problems/find-minimum-operations-to-make-all-elements-divisible-by-three) | [![Java](assets/java.png)](src/FindMinimumOperationsToMakeAllElementsDivisibleByThree.java) | | -| 3194 | [Minimum Average of Smallest and Largest Elements](https://leetcode.com/problems/minimum-average-of-smallest-and-largest-elements) | | | +| 3194 | [Minimum Average of Smallest and Largest Elements](https://leetcode.com/problems/minimum-average-of-smallest-and-largest-elements) | [![Java](assets/java.png)](src/MinimumAverageOfSmallestAndLargestElements.java) | | | 3199 | [Count Triplets With Even XOR Set Bits I](https://leetcode.com/problems/count-triplets-with-even-xor-set-bits-i) | | | | 3200 | [Maximum Height of a Triangle](https://leetcode.com/problems/maximum-height-of-a-triangle) | | | diff --git a/src/MinimumAverageOfSmallestAndLargestElements.java b/src/MinimumAverageOfSmallestAndLargestElements.java new file mode 100644 index 0000000..8c86527 --- /dev/null +++ b/src/MinimumAverageOfSmallestAndLargestElements.java @@ -0,0 +1,18 @@ +// https://leetcode.com/problems/minimum-average-of-smallest-and-largest-elements +// T: O(N log(N)) +// S: O(log(N)) + +import java.util.Arrays; + +public class MinimumAverageOfSmallestAndLargestElements { + public double minimumAverage(int[] array) { + Arrays.sort(array); + double minAverage = Double.MAX_VALUE; + + for (int i = 0 ; i < array.length / 2 ; i++) { + minAverage = Math.min(minAverage, ((double) array[i] + array[array.length - i - 1]) / 2); + } + + return minAverage; + } +} From 493d73630e3a25eef48a09a8423dda5d7f10dd8f Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 18 Jul 2024 13:12:39 +0200 Subject: [PATCH 216/280] solves #41: First Missing Positive in java --- README.md | 1 + src/FirstMissingPositive.java | 39 +++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 src/FirstMissingPositive.java diff --git a/README.md b/README.md index 4ea71c1..c8f0cc3 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ | 38 | [Count and Say](https://leetcode.com/problems/count-and-say) | [![Java](assets/java.png)](src/CountAndSay.java) [![Python](assets/python.png)](python/count_and_say.py) | | | 39 | [Combination Sum](https://leetcode.com/problems/combination-sum) | [![Java](assets/java.png)](src/CombinationSum.java) | | | 40 | [Combination Sum II](https://leetcode.com/problems/combination-sum-ii) | [![Java](assets/java.png)](src/CombinationSumII.java) | | +| 41 | [First Missing Positive](https://leetcode.com/problems/first-missing-positive) | [![Java](assets/java.png)](src/FirstMissingPositive.java) | | | 42 | [Trapping Rain Water](https://leetcode.com/problems/trapping-rain-water) | [![Java](assets/java.png)](src/TrappingRainwater.java) | | | 43 | [Multiply Strings](https://leetcode.com/problems/multiply-strings) | [![Java](assets/java.png)](src/MultiplyStrings.java) | | | 45 | [Jump Game II](https://leetcode.com/problems/jump-game-ii) | [![Java](assets/java.png)](src/JumpGameII.java) | | diff --git a/src/FirstMissingPositive.java b/src/FirstMissingPositive.java new file mode 100644 index 0000000..81370c0 --- /dev/null +++ b/src/FirstMissingPositive.java @@ -0,0 +1,39 @@ +// https://leetcode.com/problems/first-missing-positive +// T: O(N) +// S: O(1) + +public class FirstMissingPositive { + public static int firstMissingPositive(int[] nums) { + int n = nums.length; + + // Use cycle sort to place positive elements smaller than n at the correct index + for (int i = 0 ; i < n ; ) { + if (nums[i] > 0 && nums[i] <= n && nums[i] != nums[nums[i] - 1]) { + swap(nums, i, nums[i] - 1); + } else { + i++; + } + } + + // Iterate through nums return smallest missing positive integer + for (int i = 0; i < n; i++) { + if (nums[i] != i + 1) { + return i + 1; + } + } + + // If all elements are at the correct index + // the smallest missing positive number is n + 1 + return n + 1; + } + + private static void swap(int[] nums, int i, int j) { + int temp = nums[i]; + nums[i] = nums[j]; + nums[j] = temp; + } + + public static void main(String[] args) { + System.out.println(firstMissingPositive(new int[] {3, 4, -1, 1})); + } +} From 64f4c4552a13804bf4d8c5bd700e19ad892a2efb Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 18 Jul 2024 23:23:54 +0200 Subject: [PATCH 217/280] a --- src/FirstMissingPositive.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/FirstMissingPositive.java b/src/FirstMissingPositive.java index 81370c0..1d063de 100644 --- a/src/FirstMissingPositive.java +++ b/src/FirstMissingPositive.java @@ -3,7 +3,7 @@ // S: O(1) public class FirstMissingPositive { - public static int firstMissingPositive(int[] nums) { + public int firstMissingPositive(int[] nums) { int n = nums.length; // Use cycle sort to place positive elements smaller than n at the correct index @@ -32,8 +32,4 @@ private static void swap(int[] nums, int i, int j) { nums[i] = nums[j]; nums[j] = temp; } - - public static void main(String[] args) { - System.out.println(firstMissingPositive(new int[] {3, 4, -1, 1})); - } } From 15deee8b632357b8eebfe002a73a2fb44c4b5889 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 21 Jul 2024 22:00:42 +0200 Subject: [PATCH 218/280] solves #3200: Maximum Height of a Triangle --- README.md | 2 +- src/MaximumHeightOfATriangle.java | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/MaximumHeightOfATriangle.java diff --git a/README.md b/README.md index c8f0cc3..ec13844 100644 --- a/README.md +++ b/README.md @@ -923,4 +923,4 @@ | 3190 | [Find Minimum Operations to Make All Elements Divisible by Three](https://leetcode.com/problems/find-minimum-operations-to-make-all-elements-divisible-by-three) | [![Java](assets/java.png)](src/FindMinimumOperationsToMakeAllElementsDivisibleByThree.java) | | | 3194 | [Minimum Average of Smallest and Largest Elements](https://leetcode.com/problems/minimum-average-of-smallest-and-largest-elements) | [![Java](assets/java.png)](src/MinimumAverageOfSmallestAndLargestElements.java) | | | 3199 | [Count Triplets With Even XOR Set Bits I](https://leetcode.com/problems/count-triplets-with-even-xor-set-bits-i) | | | -| 3200 | [Maximum Height of a Triangle](https://leetcode.com/problems/maximum-height-of-a-triangle) | | | +| 3200 | [Maximum Height of a Triangle](https://leetcode.com/problems/maximum-height-of-a-triangle) | [![Java](assets/java.png)](src/MaximumHeightOfATriangle.java) | | diff --git a/src/MaximumHeightOfATriangle.java b/src/MaximumHeightOfATriangle.java new file mode 100644 index 0000000..b84ff88 --- /dev/null +++ b/src/MaximumHeightOfATriangle.java @@ -0,0 +1,31 @@ +// https://leetcode.com/problems/maximum-height-of-a-triangle +// T: O(log(n) + log(m)) +// S: O(1) + +public class MaximumHeightOfATriangle { + public static int maxHeightOfTriangle(int red, int blue) { + return Math.max(possibleRows(red, blue), possibleRows(blue, red)); + } + + private static int possibleRows(int oddRowBalls, int evenRowBalls) { + final int evenRows = possibleEvenRows(evenRowBalls); + final int oddRows = possibleOddRows(oddRowBalls); + return Math.min(oddRows, evenRows + 1) + Math.min(oddRows, evenRows); + } + + private static int possibleOddRows(int balls) { + return (int) Math.sqrt(balls); + } + + /* + k - (-1 + sqrt(1 + 4b)) / 2 = 0 + k = (-1 + sqrt(1 + 4b)) / 2 + */ + private static int possibleEvenRows(int balls) { + return (int) ((Math.sqrt(1 + 4 * balls) - 1) / 2); + } + + public static void main(String[] args) { + System.out.println(maxHeightOfTriangle(10, 1)); + } +} From bc2aacbe03acb35ce504d07f63e4566fd7b05c51 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 21 Jul 2024 22:12:26 +0200 Subject: [PATCH 219/280] solves #3206: solves Alternating Groups I in java --- README.md | 7 ++++++- src/AlternatingGroupsI.java | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/AlternatingGroupsI.java diff --git a/README.md b/README.md index ec13844..4b814fc 100644 --- a/README.md +++ b/README.md @@ -922,5 +922,10 @@ | 3184 | [Count Pairs That Form a Complete Day I](https://leetcode.com/problems/count-pairs-that-form-a-complete-day-i) | [![Java](assets/java.png)](src/CountPairsThatFormACompleteDayI.java) | | | 3190 | [Find Minimum Operations to Make All Elements Divisible by Three](https://leetcode.com/problems/find-minimum-operations-to-make-all-elements-divisible-by-three) | [![Java](assets/java.png)](src/FindMinimumOperationsToMakeAllElementsDivisibleByThree.java) | | | 3194 | [Minimum Average of Smallest and Largest Elements](https://leetcode.com/problems/minimum-average-of-smallest-and-largest-elements) | [![Java](assets/java.png)](src/MinimumAverageOfSmallestAndLargestElements.java) | | -| 3199 | [Count Triplets With Even XOR Set Bits I](https://leetcode.com/problems/count-triplets-with-even-xor-set-bits-i) | | | +| 3199 | 🔒 [Count Triplets With Even XOR Set Bits I](https://leetcode.com/problems/count-triplets-with-even-xor-set-bits-i) | | | | 3200 | [Maximum Height of a Triangle](https://leetcode.com/problems/maximum-height-of-a-triangle) | [![Java](assets/java.png)](src/MaximumHeightOfATriangle.java) | | +| 3206 | [Alternating Groups I](https://leetcode.com/problems/alternating-groups-i) | [![Java](assets/java.png)](src/AlternatingGroupsI.java) | | +| 3210 | [Find the Encrypted String](https://leetcode.com/problems/find-the-encrypted-string) | | | +| 3216 | [Lexicographically Smallest String After a Swap](https://leetcode.com/problems/lexicographically-smallest-string-after-a-swap) | | | +| 3222 | [Find the Winning Player in Coin Game](https://leetcode.com/problems/find-the-winning-player-in-coin-game) | | | +| 3226 | [Number of Bit Changes to Make Two Integers Equal](https://leetcode.com/problems/number-of-bit-changes-to-make-two-integers-equal) | | | diff --git a/src/AlternatingGroupsI.java b/src/AlternatingGroupsI.java new file mode 100644 index 0000000..218e398 --- /dev/null +++ b/src/AlternatingGroupsI.java @@ -0,0 +1,19 @@ +// https://leetcode.com/problems/alternating-groups-i +// T: O(N) +// S: O(1) + +public class AlternatingGroupsI { + public int numberOfAlternatingGroups(int[] colors) { + int groups = 0; + for (int i = 0 ; i < colors.length ; i++) { + if (isAlternating(colors, i)) { + groups++; + } + } + return groups; + } + private static boolean isAlternating(int[] colors, int startIndex) { + return colors[startIndex] == colors[(startIndex + 2) % colors.length] && + colors[startIndex] != colors[(startIndex + 1) % colors.length] + } +} From 7e90579a1fbb5b5a33395b9f02a1ee19e10ee85b Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 21 Jul 2024 22:17:41 +0200 Subject: [PATCH 220/280] solves #3210: Find the Encrypted String in java --- README.md | 2 +- src/AlternatingGroupsI.java | 2 +- src/FindTheEncryptedString.java | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 src/FindTheEncryptedString.java diff --git a/README.md b/README.md index 4b814fc..9d47216 100644 --- a/README.md +++ b/README.md @@ -925,7 +925,7 @@ | 3199 | 🔒 [Count Triplets With Even XOR Set Bits I](https://leetcode.com/problems/count-triplets-with-even-xor-set-bits-i) | | | | 3200 | [Maximum Height of a Triangle](https://leetcode.com/problems/maximum-height-of-a-triangle) | [![Java](assets/java.png)](src/MaximumHeightOfATriangle.java) | | | 3206 | [Alternating Groups I](https://leetcode.com/problems/alternating-groups-i) | [![Java](assets/java.png)](src/AlternatingGroupsI.java) | | -| 3210 | [Find the Encrypted String](https://leetcode.com/problems/find-the-encrypted-string) | | | +| 3210 | [Find the Encrypted String](https://leetcode.com/problems/find-the-encrypted-string) | [![Java](assets/java.png)](src/FindTheEncryptedString.java) | | | 3216 | [Lexicographically Smallest String After a Swap](https://leetcode.com/problems/lexicographically-smallest-string-after-a-swap) | | | | 3222 | [Find the Winning Player in Coin Game](https://leetcode.com/problems/find-the-winning-player-in-coin-game) | | | | 3226 | [Number of Bit Changes to Make Two Integers Equal](https://leetcode.com/problems/number-of-bit-changes-to-make-two-integers-equal) | | | diff --git a/src/AlternatingGroupsI.java b/src/AlternatingGroupsI.java index 218e398..af13e71 100644 --- a/src/AlternatingGroupsI.java +++ b/src/AlternatingGroupsI.java @@ -14,6 +14,6 @@ public int numberOfAlternatingGroups(int[] colors) { } private static boolean isAlternating(int[] colors, int startIndex) { return colors[startIndex] == colors[(startIndex + 2) % colors.length] && - colors[startIndex] != colors[(startIndex + 1) % colors.length] + colors[startIndex] != colors[(startIndex + 1) % colors.length]; } } diff --git a/src/FindTheEncryptedString.java b/src/FindTheEncryptedString.java new file mode 100644 index 0000000..9facfb5 --- /dev/null +++ b/src/FindTheEncryptedString.java @@ -0,0 +1,21 @@ +// https://leetcode.com/problems/find-the-encrypted-string +// T: O(|s|) +// S: O(|s|) + +public class FindTheEncryptedString { + public String getEncryptedString(String s, int k) { + final int rotations = k % s.length(); + if (rotations == 0) { + return s; + } + return rotateString(s, rotations); + } + + private static String rotateString(String s, int rotations) { + final StringBuilder builder = new StringBuilder(); + for (int i = 0 ; i < s.length() ; i++) { + builder.append(s.charAt((i + rotations) % s.length())); + } + return builder.toString(); + } +} From b32da14e7df738e9b053ecb21bc5061ff91f8e4b Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 21 Jul 2024 22:27:58 +0200 Subject: [PATCH 221/280] solves #3216: Lexicographically Smallest String After a Swap in java --- README.md | 2 +- ...cographicallySmallestStringAfterASwap.java | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/LexicographicallySmallestStringAfterASwap.java diff --git a/README.md b/README.md index 9d47216..2a8a527 100644 --- a/README.md +++ b/README.md @@ -926,6 +926,6 @@ | 3200 | [Maximum Height of a Triangle](https://leetcode.com/problems/maximum-height-of-a-triangle) | [![Java](assets/java.png)](src/MaximumHeightOfATriangle.java) | | | 3206 | [Alternating Groups I](https://leetcode.com/problems/alternating-groups-i) | [![Java](assets/java.png)](src/AlternatingGroupsI.java) | | | 3210 | [Find the Encrypted String](https://leetcode.com/problems/find-the-encrypted-string) | [![Java](assets/java.png)](src/FindTheEncryptedString.java) | | -| 3216 | [Lexicographically Smallest String After a Swap](https://leetcode.com/problems/lexicographically-smallest-string-after-a-swap) | | | +| 3216 | [Lexicographically Smallest String After a Swap](https://leetcode.com/problems/lexicographically-smallest-string-after-a-swap) | [![Java](assets/java.png)](src/LexicographicallySmallestStringAfterASwap.java) | | | 3222 | [Find the Winning Player in Coin Game](https://leetcode.com/problems/find-the-winning-player-in-coin-game) | | | | 3226 | [Number of Bit Changes to Make Two Integers Equal](https://leetcode.com/problems/number-of-bit-changes-to-make-two-integers-equal) | | | diff --git a/src/LexicographicallySmallestStringAfterASwap.java b/src/LexicographicallySmallestStringAfterASwap.java new file mode 100644 index 0000000..db13761 --- /dev/null +++ b/src/LexicographicallySmallestStringAfterASwap.java @@ -0,0 +1,24 @@ +// https://leetcode.com/problems/lexicographically-smallest-string-after-a-swap +// T: O(|s|) +// S: O(|s|) + +public class LexicographicallySmallestStringAfterASwap { + public String getSmallestString(String s) { + for (int i = 0 ; i < s.length() - 1 ; i++) { + if (sameParity(s, i) && s.charAt(i) > s.charAt(i + 1)) { + return swapCharWithNextChar(s, i); + } + } + return s; + } + + private static boolean sameParity(String s, int index) { + return Integer.parseInt(s.charAt(index) + "") % 2 == + Integer.parseInt(s.charAt(index + 1) + "") % 2; + } + + private static String swapCharWithNextChar(String s, int index) { + return s.substring(0, index) + s.charAt(index + 1) + + s.charAt(index) + s.substring(index + 2); + } +} From a6a3df834de92595390d5c82a2916f70bb631a4a Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 21 Jul 2024 22:36:17 +0200 Subject: [PATCH 222/280] solves 3222: Find the Winning Player in Coin Game in java --- README.md | 2 +- src/FindTheWinningPlayerInCoinGame.java | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/FindTheWinningPlayerInCoinGame.java diff --git a/README.md b/README.md index 2a8a527..3705d65 100644 --- a/README.md +++ b/README.md @@ -927,5 +927,5 @@ | 3206 | [Alternating Groups I](https://leetcode.com/problems/alternating-groups-i) | [![Java](assets/java.png)](src/AlternatingGroupsI.java) | | | 3210 | [Find the Encrypted String](https://leetcode.com/problems/find-the-encrypted-string) | [![Java](assets/java.png)](src/FindTheEncryptedString.java) | | | 3216 | [Lexicographically Smallest String After a Swap](https://leetcode.com/problems/lexicographically-smallest-string-after-a-swap) | [![Java](assets/java.png)](src/LexicographicallySmallestStringAfterASwap.java) | | -| 3222 | [Find the Winning Player in Coin Game](https://leetcode.com/problems/find-the-winning-player-in-coin-game) | | | +| 3222 | [Find the Winning Player in Coin Game](https://leetcode.com/problems/find-the-winning-player-in-coin-game) | [![Java](assets/java.png)](src/FindTheWinningPlayerInCoinGame.java) | | | 3226 | [Number of Bit Changes to Make Two Integers Equal](https://leetcode.com/problems/number-of-bit-changes-to-make-two-integers-equal) | | | diff --git a/src/FindTheWinningPlayerInCoinGame.java b/src/FindTheWinningPlayerInCoinGame.java new file mode 100644 index 0000000..78786a8 --- /dev/null +++ b/src/FindTheWinningPlayerInCoinGame.java @@ -0,0 +1,11 @@ +// https://leetcode.com/problems/find-the-winning-player-in-coin-game +// T: O(1) +// S: O(1) + +public class FindTheWinningPlayerInCoinGame { + public String losingPlayer(int x, int y) { + final int maxGames10CentCoins = y / 4; + final int maxGamesPossible = Math.min(x, maxGames10CentCoins); + return maxGamesPossible % 2 == 0 ? "Bob" : "Alice"; + } +} From d9f7c8c9bb84e2d9250aebdee429979a9c79badf Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 21 Jul 2024 22:49:11 +0200 Subject: [PATCH 223/280] solves #3226: Number of Bit Changes to Make Two Integers Equal in java --- README.md | 2 +- ...berOfBitChangesToMakeTwoIntegersEqual.java | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/NumberOfBitChangesToMakeTwoIntegersEqual.java diff --git a/README.md b/README.md index 3705d65..1e383b4 100644 --- a/README.md +++ b/README.md @@ -928,4 +928,4 @@ | 3210 | [Find the Encrypted String](https://leetcode.com/problems/find-the-encrypted-string) | [![Java](assets/java.png)](src/FindTheEncryptedString.java) | | | 3216 | [Lexicographically Smallest String After a Swap](https://leetcode.com/problems/lexicographically-smallest-string-after-a-swap) | [![Java](assets/java.png)](src/LexicographicallySmallestStringAfterASwap.java) | | | 3222 | [Find the Winning Player in Coin Game](https://leetcode.com/problems/find-the-winning-player-in-coin-game) | [![Java](assets/java.png)](src/FindTheWinningPlayerInCoinGame.java) | | -| 3226 | [Number of Bit Changes to Make Two Integers Equal](https://leetcode.com/problems/number-of-bit-changes-to-make-two-integers-equal) | | | +| 3226 | [Number of Bit Changes to Make Two Integers Equal](https://leetcode.com/problems/number-of-bit-changes-to-make-two-integers-equal) | [![Java](assets/java.png)](src/NumberOfBitChangesToMakeTwoIntegersEqual.java) | | diff --git a/src/NumberOfBitChangesToMakeTwoIntegersEqual.java b/src/NumberOfBitChangesToMakeTwoIntegersEqual.java new file mode 100644 index 0000000..cd24c4a --- /dev/null +++ b/src/NumberOfBitChangesToMakeTwoIntegersEqual.java @@ -0,0 +1,25 @@ +// https://leetcode.com/problems/number-of-bit-changes-to-make-two-integers-equal +// T: O(max(log(N), log(K))) +// S: O(1) + +public class NumberOfBitChangesToMakeTwoIntegersEqual { + public int minChanges(int n, int k) { + if (n == k) { + return 0; + } + + int changes = 0; + while (n > 0 || k > 0) { + final int nLastBit = n & 1; + final int kLastBit = k & 1; + if (kLastBit == 1 && nLastBit == 0) { + return -1; + } else if (kLastBit == 0 && nLastBit == 1) { + changes++; + } + n >>= 1; + k >>= 1; + } + return changes; + } +} From 2cc35cf05f2f9baca6149343b5516e00edc444e3 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 22 Jul 2024 02:03:04 +0200 Subject: [PATCH 224/280] solves #380: Insert Delete GetRandom O(1) in java --- README.md | 1 + src/HelloWorld.java | 80 +++++++++++--------------------- src/InsertDeleteGetRandomO1.java | 45 ++++++++++++++++++ 3 files changed, 73 insertions(+), 53 deletions(-) create mode 100644 src/InsertDeleteGetRandomO1.java diff --git a/README.md b/README.md index 1e383b4..3fb020a 100644 --- a/README.md +++ b/README.md @@ -292,6 +292,7 @@ | 359 | 🔒 [Logger Rate Limiter](https://leetcode.com/problems/logger-rate-limiter) | | | | 367 | [Valid Perfect Square](https://leetcode.com/problems/valid-perfect-square) | [![Java](assets/java.png)](src/IsPerfectSquare.java) [![Python](assets/python.png)](python/valid_perfect_square.py) | | | 374 | [Guess Number Higher or Lower](https://leetcode.com/problems/guess-number-higher-or-lower) | [![Java](assets/java.png)](src/GuessNumberHigherOrLower.java) [![Python](assets/python.png)](python/guess_number_higher_or_lower.py) | | +| 380 | [Insert Delete GetRandom O(1)](https://leetcode.com/problems/insert-delete-getrandom-o1) | [![Java](assets/java.png)](src/InsertDeleteGetRandomO1.java) | | | 383 | [Ransom Note](https://leetcode.com/problems/ransom-note) | [![Java](assets/java.png)](src/RansomNote.java) [![Python](assets/python.png)](python/ransom_note.py) | | | 387 | [First Unique Character in String](https://leetcode.com/problems/first-unique-character-in-a-string) | [![Java](assets/java.png)](src/FirstUniqueCharacter.java) [![Python](assets/python.png)](python/first_unique_character_in_string.py) | | | 389 | [Find the Difference](https://leetcode.com/problems/find-the-difference) | [![Java](assets/java.png)](src/FindTheDifference.java) [![Python](assets/python.png)](python/find_the_difference.py) | | diff --git a/src/HelloWorld.java b/src/HelloWorld.java index c9402d3..76d5f4d 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -1,65 +1,39 @@ -import java.util.Scanner; +import java.util.*; public class HelloWorld { - private static final Scanner SCANNER = new Scanner(System.in); - - private static void spiralOrder(int[][] matrix){ - final int rows = matrix.length, columns = matrix[0].length, elements = rows * columns; - for (int i = 0, top = 0, bottom = rows, left = 0, right = columns ; ; ) { - for (int row = top, column = left ; column < right ; column++, i++) { - System.out.print(matrix[row][column]); - } - top++; - if (i == elements) break; - for (int row = top, column = right - 1 ; row < bottom ; row++, i++) { - System.out.print(matrix[row][column]); - } - right--; - if (i == elements) break; - for (int row = bottom - 1, column = right - 1 ; column >= left ; column--, i++) { - System.out.print(matrix[row][column]); - } - bottom--; - if (i == elements) break; - for (int row = bottom - 1, column = left ; row >= top ; row--, i++) { - System.out.print(matrix[row][column]); + static class RandomizedSet { + private final Random random = new Random(); + private final List list = new ArrayList<>(); + private final Map indexMapping = new HashMap<>(); + + public boolean insert(int val) { + if (indexMapping.containsKey(val)) { + return false; } - left++; - if (i == elements) break; + list.add(val); + indexMapping.put(val, list.size() - 1); + return true; } - } - - private static int intInput(final String string) { - System.out.print(string); - final int i = SCANNER.nextInt(); - return i; - } - private static void print(int[][] matrix) { - for (int[] row : matrix) { - for (int element : row) { - System.out.print(element + " "); - } - System.out.println(); + private int last() { + return this.list.getLast(); } - } - - public static void main(String[] args) { - final int rows = intInput("Enter row size: "); - final int columns = intInput("Enter column size: "); - final int[][] matrix = new int[rows][columns]; - System.out.println("Enter array elements:"); - - for (int i = 0 ; i < rows ; i++) { - for(int j = 0 ; j < columns ; j++) { - matrix[i][j] = SCANNER.nextInt(); + public boolean remove(int val) { + if (!indexMapping.containsKey(val)) { + return false; } + final int index = indexMapping.get(val); + indexMapping.put(last(), index); + indexMapping.remove(val); + list.set(index, last()); + list.removeLast(); + return true; } - spiralOrder(matrix); - - System.out.println("\n\nOriginal matrix"); - print(matrix); + public int getRandom() { + final int randomIndex = random.nextInt(list.size()); + return list.get(randomIndex); + } } } \ No newline at end of file diff --git a/src/InsertDeleteGetRandomO1.java b/src/InsertDeleteGetRandomO1.java new file mode 100644 index 0000000..a92e73b --- /dev/null +++ b/src/InsertDeleteGetRandomO1.java @@ -0,0 +1,45 @@ +// https://leetcode.com/problems/insert-delete-getrandom-o1 + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Random; + +public class InsertDeleteGetRandomO1 { + static class RandomizedSet { + private final Random random = new Random(); + private final List list = new ArrayList<>(); + private final Map indexMapping = new HashMap<>(); + + public boolean insert(int val) { + if (indexMapping.containsKey(val)) { + return false; + } + list.add(val); + indexMapping.put(val, list.size() - 1); + return true; + } + + private int last() { + return this.list.getLast(); + } + + public boolean remove(int val) { + if (!indexMapping.containsKey(val)) { + return false; + } + final int index = indexMapping.get(val); + indexMapping.put(last(), index); + indexMapping.remove(val); + list.set(index, last()); + list.removeLast(); + return true; + } + + public int getRandom() { + final int randomIndex = random.nextInt(list.size()); + return list.get(randomIndex); + } + } +} From 90ccae98903b161fcdc1fb42d9b87ed8dc17daef Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 22 Jul 2024 03:00:53 +0200 Subject: [PATCH 225/280] solves #135: Candy in java --- README.md | 1 + src/Candy.java | 27 +++++++++++++++++++++++++++ src/HelloWorld.java | 43 +++++++++++++------------------------------ 3 files changed, 41 insertions(+), 30 deletions(-) create mode 100644 src/Candy.java diff --git a/README.md b/README.md index 3fb020a..320ef6c 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,7 @@ | 131 | [Palindrome Partitioning](https://leetcode.com/problems/palindrome-partitioning) | [![Java](assets/java.png)](src/PalindromePartitioning.java) | | | 133 | [Clone Graph](https://leetcode.com/problems/clone-graph) | [![Java](assets/java.png)](src/CloneGraph.java) [![Python](assets/python.png)](python/clone_graph.py) | | | 134 | [Gas Station](https://leetcode.com/problems/gas-station) | [![Java](assets/java.png)](src/GasStation.java) | | +| 135 | [Candy](https://leetcode.com/problems/candy) | [![Java](assets/java.png)](src/Candy.java) | | | 136 | [Single Number](https://leetcode.com/problems/single-number) | [![Java](assets/java.png)](src/SingleNumber.java) [![Python](assets/python.png)](python/single_number.py) | | | 137 | [Single Number II](https://leetcode.com/problems/single-number-ii) | [![Java](assets/java.png)](src/SingleNumberII.java) | | | 138 | [Copy List with Random Pointer](https://leetcode.com/problems/copy-list-with-random-pointer) | [![Java](assets/java.png)](src/CopyListWithRandomPointer.java) | | diff --git a/src/Candy.java b/src/Candy.java new file mode 100644 index 0000000..defcad4 --- /dev/null +++ b/src/Candy.java @@ -0,0 +1,27 @@ +// https://leetcode.com/problems/candy +// T: O(N) +// S: O(N) + +import java.util.Arrays; + +public class Candy { + public int candy(int[] ratings) { + final int[] candies = new int[ratings.length]; + + // left pass + for (int i = 1 ; i < ratings.length ; i++) { + if (ratings[i] > ratings[i - 1]) { + candies[i] = candies[i - 1] + 1; + } + } + + // right pass + for (int i = ratings.length - 2 ; i >= 0 ; i--) { + if (ratings[i] > ratings[i + 1]) { + candies[i] = Math.max(candies[i], candies[i + 1] + 1); + } + } + + return Arrays.stream(candies).sum() + ratings.length; + } +} diff --git a/src/HelloWorld.java b/src/HelloWorld.java index 76d5f4d..9a89ba3 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -1,39 +1,22 @@ -import java.util.*; +import java.util.Arrays; public class HelloWorld { - static class RandomizedSet { - private final Random random = new Random(); - private final List list = new ArrayList<>(); - private final Map indexMapping = new HashMap<>(); + public int canCompleteCircuit(int[] gas, int[] cost) { + final int totalGas = Arrays.stream(gas).sum(); + final int totalCost = Arrays.stream(cost).sum(); - public boolean insert(int val) { - if (indexMapping.containsKey(val)) { - return false; - } - list.add(val); - indexMapping.put(val, list.size() - 1); - return true; - } - - private int last() { - return this.list.getLast(); + if (totalCost > totalGas) { + return -1; } - public boolean remove(int val) { - if (!indexMapping.containsKey(val)) { - return false; + int startingIndex = 0; + for (int i = 0, currentGas = 0 ; i < cost.length ; i++) { + currentGas += gas[i] - cost[i]; + if (currentGas < 0) { + currentGas = 0; + startingIndex = i + 1; } - final int index = indexMapping.get(val); - indexMapping.put(last(), index); - indexMapping.remove(val); - list.set(index, last()); - list.removeLast(); - return true; - } - - public int getRandom() { - final int randomIndex = random.nextInt(list.size()); - return list.get(randomIndex); } + return startingIndex; } } \ No newline at end of file From 4030185ffd77854607835f30491a638db9a60f84 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 22 Jul 2024 11:19:38 +0200 Subject: [PATCH 226/280] update roman to int and int --> roman --- src/HelloWorld.java | 29 ++++++++--------- src/IntegerToRoman.java | 66 ++++++++++++--------------------------- src/LengthOfLastWord.java | 23 +++++++++++--- src/RomanToInteger.java | 54 ++++++++++++++++++-------------- 4 files changed, 81 insertions(+), 91 deletions(-) diff --git a/src/HelloWorld.java b/src/HelloWorld.java index 9a89ba3..73a1695 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -1,22 +1,19 @@ -import java.util.Arrays; - public class HelloWorld { - public int canCompleteCircuit(int[] gas, int[] cost) { - final int totalGas = Arrays.stream(gas).sum(); - final int totalCost = Arrays.stream(cost).sum(); + public int lengthOfLastWord(String s) { + int i = s.length() - 1; - if (totalCost > totalGas) { - return -1; + // skip all spaces at the end of the word + while (i >= 0 && s.charAt(i) == ' ') { + i--; } - int startingIndex = 0; - for (int i = 0, currentGas = 0 ; i < cost.length ; i++) { - currentGas += gas[i] - cost[i]; - if (currentGas < 0) { - currentGas = 0; - startingIndex = i + 1; - } + final int wordEndIndex = i; + + // arrive at the start of the word + while (i >= 0 && s.charAt(i) != ' ') { + i--; } - return startingIndex; + + return wordEndIndex - i; } -} \ No newline at end of file +} diff --git a/src/IntegerToRoman.java b/src/IntegerToRoman.java index 8668211..dbc0e9c 100644 --- a/src/IntegerToRoman.java +++ b/src/IntegerToRoman.java @@ -2,61 +2,35 @@ // T: O(log n) // S: O(log n) -import java.util.Map; - public class IntegerToRoman { - private final static int ONE = 1; - private final static int FIVE = 5; - private final static int TEN = 10; - - private final static Map ONES_PLACE_ROMAN_CHARS = Map.ofEntries( - Map.entry(ONE, "I"), - Map.entry(FIVE, "V"), - Map.entry(TEN, "X") - ); - - private final static Map TENS_PLACE_ROMAN_CHARS = Map.ofEntries( - Map.entry(ONE, "X"), - Map.entry(FIVE, "L"), - Map.entry(TEN, "C") - ); - - private final static Map HUNDREDS_PLACE_ROMAN_CHARS = Map.ofEntries( - Map.entry(ONE, "C"), - Map.entry(FIVE, "D"), - Map.entry(TEN, "M") - ); + private static final String[] ROMAN_VALUES = new String[] { "I", "V", "X", "L", "C", "D", "M" }; public String intToRoman(int num) { - final StringBuilder result = new StringBuilder(); - for (int place = 1000 ; num > 0 ; place /= 10) { - result.append(toRoman(num / place, place)); - num -= (num / place) * place; + final StringBuilder builder = new StringBuilder(); + final String number = num + ""; + for (int i = 0 ; i < number.length() ; i++) { + builder.append(getRomanString(number.charAt(i), number.length() - i - 1)); } - return result.toString(); + return builder.toString(); } - private String toRoman(int digit, int place) { - return switch (place) { - case 1 -> toRomanFromPlace(digit, ONES_PLACE_ROMAN_CHARS); - case 10 -> toRomanFromPlace(digit, TENS_PLACE_ROMAN_CHARS); - case 100 -> toRomanFromPlace(digit, HUNDREDS_PLACE_ROMAN_CHARS); - case 1000 -> thousandsPlaceToRoman(digit); - default -> ""; - }; - } + private static String getRomanString(char digit, int power) { + if (digit == '4') { + return ROMAN_VALUES[2 * power] + ROMAN_VALUES[2 * power + 1]; + } + if (digit == '9') { + return ROMAN_VALUES[2 * power] + ROMAN_VALUES[2 * power + 2]; + } - private String toRomanFromPlace(int digit, Map romanChars) { return switch (digit) { - case 1, 2, 3 -> romanChars.get(ONE).repeat(digit); - case 4 -> romanChars.get(ONE) + romanChars.get(FIVE); - case 5, 6, 7, 8 -> romanChars.get(FIVE) + romanChars.get(ONE).repeat(digit - 1); - case 9 -> romanChars.get(ONE) + romanChars.get(TEN); + case '1' -> ROMAN_VALUES[2 * power].repeat(1); + case '2' -> ROMAN_VALUES[2 * power].repeat(2); + case '3' -> ROMAN_VALUES[2 * power].repeat(3); + case '5' -> ROMAN_VALUES[2 * power + 1]; + case '6' -> ROMAN_VALUES[2 * power + 1] + ROMAN_VALUES[2 * power].repeat(1); + case '7' -> ROMAN_VALUES[2 * power + 1] + ROMAN_VALUES[2 * power].repeat(2); + case '8' -> ROMAN_VALUES[2 * power + 1] + ROMAN_VALUES[2 * power].repeat(3); default -> ""; }; } - - private String thousandsPlaceToRoman(int digit) { - return "M".repeat(digit); - } } diff --git a/src/LengthOfLastWord.java b/src/LengthOfLastWord.java index 10d5c73..78f3c30 100644 --- a/src/LengthOfLastWord.java +++ b/src/LengthOfLastWord.java @@ -1,10 +1,23 @@ +// https://leetcode.com/problems/length-of-last-word +// T: O(N) +// S: O(1) + public class LengthOfLastWord { - public int lengthOfLastWord(String sentence) { - String[] words = sentence.split(" "); - if (words.length == 0) { - return 0; + public int lengthOfLastWord(String s) { + int i = s.length() - 1; + + // skip all spaces at the end of the word + while (i >= 0 && s.charAt(i) == ' ') { + i--; + } + + final int wordEndIndex = i; + + // arrive at the start of the word + while (i >= 0 && s.charAt(i) != ' ') { + i--; } - return words[words.length - 1].length(); + return wordEndIndex - i; } } diff --git a/src/RomanToInteger.java b/src/RomanToInteger.java index 0522fcd..b40d94f 100644 --- a/src/RomanToInteger.java +++ b/src/RomanToInteger.java @@ -1,35 +1,41 @@ -// https://leetcode.com/problems/roman-to-integer/ +// https://leetcode.com/problems/roman-to-integer +// T: O(|S|) +// S: O(1) -import java.util.HashMap; import java.util.Map; -import java.util.Scanner; +import java.util.Set; public class RomanToInteger { - private static final Map romanNumerals = new HashMap<>(); + private static final Map ROMAN_NUMERALS = Map.of( + 'I', 1, + 'V', 5, + 'X', 10, + 'L', 50, + 'C', 100, + 'D', 500, + 'M', 1000 + ); - static { - romanNumerals.put('I', 1); - romanNumerals.put('V', 5); - romanNumerals.put('X', 10); - romanNumerals.put('L', 50); - romanNumerals.put('C', 100); - romanNumerals.put('D', 500); - romanNumerals.put('M', 1000); - } + private static final Map> DECREMENT_ROMAN_NUMERALS = Map.of( + 'I', Set.of('V', 'X'), + 'X', Set.of('L', 'C'), + 'C', Set.of('D', 'M') + ); - private static int romanToInt(String string) { - int value = 0; - for (int index = 0 ; index < string.length() ; index++) { - if (index < string.length() - 1 && value(string.charAt(index)) < value(string.charAt(index + 1))) { - value -= value(string.charAt(index)); + public int romanToInt(String s) { + int number = 0; + for (int i = 0 ; i < s.length() ; ) { + final char c = s.charAt(i); + if (DECREMENT_ROMAN_NUMERALS.containsKey(c) + && i + 1 < s.length() + && DECREMENT_ROMAN_NUMERALS.get(c).contains(s.charAt(i + 1))) { + number += ROMAN_NUMERALS.get(s.charAt(i + 1)) - ROMAN_NUMERALS.get(c); + i += 2; } else { - value += value(string.charAt(index)); + number += ROMAN_NUMERALS.get(c); + i++; } } - return value; - } - - private static int value(char character) { - return romanNumerals.get(character); + return number; } } From 042029daa3adbc86c764a824b7576c9c5a8f4c7a Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 22 Jul 2024 15:02:25 +0200 Subject: [PATCH 227/280] solves #68: Text Justification in java --- README.md | 1 + src/HelloWorld.java | 30 ++++++++++------ src/LongestCommonPrefix.java | 4 ++- src/TextJustification.java | 66 ++++++++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+), 12 deletions(-) create mode 100644 src/TextJustification.java diff --git a/README.md b/README.md index 320ef6c..eb17ae4 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,7 @@ | 64 | [Minimum Path Sum](https://leetcode.com/problems/minimum-path-sum) | [![Java](assets/java.png)](src/MinimumPathSum.java) [![Python](assets/python.png)](python/minimum_path_sum.py) | | | 66 | [Plus One](https://leetcode.com/problems/plus-one) | [![Java](assets/java.png)](src/PlusOne.java) [![Python](assets/python.png)](python/plus_one.py) | | | 67 | [Add Binary](https://leetcode.com/problems/add-binary) | [![Java](assets/java.png)](src/AddBinary.java) [![Python](assets/python.png)](python/add_binary.py) | | +| 68 | [Text Justification](https://leetcode.com/problems/text-justification) | [![Java](assets/java.png)](src/AddBinary.java) | | | 69 | [Sqrt(x)](https://leetcode.com/problems/sqrtx) | [![Java](assets/java.png)](src/Sqrtx.java) [![Python](assets/python.png)](python/sqrt.py) | | | 70 | [Climbing Stairs](https://leetcode.com/problems/climbing-stairs) | [![Java](assets/java.png)](src/ClimbingStairs.java) [![Python](assets/python.png)](python/climbing_stairs.py) | | | 71 | [Simplify Path](https://leetcode.com/problems/simplify-path) | [![Java](assets/java.png)](src/SimplifyPath.java) | | diff --git a/src/HelloWorld.java b/src/HelloWorld.java index 73a1695..873b5d8 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -1,19 +1,27 @@ public class HelloWorld { - public int lengthOfLastWord(String s) { - int i = s.length() - 1; + public int strStr(String haystack, String needle) { + if (needle.length() > haystack.length()) { + return -1; + } - // skip all spaces at the end of the word - while (i >= 0 && s.charAt(i) == ' ') { - i--; + for (int i = 0 ; i < haystack.length() ; i++) { + if (needle.charAt(0) == haystack.charAt(i) && containsAt(haystack, needle, i)) { + return i; + } } - final int wordEndIndex = i; + return -1; + } - // arrive at the start of the word - while (i >= 0 && s.charAt(i) != ' ') { - i--; + private static boolean containsAt(String haystack, String needle, int i) { + if (needle.length() > haystack.length() - i) { + return false; } - - return wordEndIndex - i; + for (int index = i + 1 ; index < haystack.length() && index - i < needle.length() ; index++) { + if (needle.charAt(index - i) != haystack.charAt(index)) { + return false; + } + } + return true; } } diff --git a/src/LongestCommonPrefix.java b/src/LongestCommonPrefix.java index 6f289c4..33e9033 100644 --- a/src/LongestCommonPrefix.java +++ b/src/LongestCommonPrefix.java @@ -1,4 +1,6 @@ -// https://leetcode.com/problems/longest-common-prefix/ +// https://leetcode.com/problems/longest-common-prefix +// T: O(|array| * |array[i]|) +// S: O(|array[i]|) public class LongestCommonPrefix { public String longestCommonPrefix(String[] array) { diff --git a/src/TextJustification.java b/src/TextJustification.java new file mode 100644 index 0000000..cd1e156 --- /dev/null +++ b/src/TextJustification.java @@ -0,0 +1,66 @@ +// https://leetcode.com/problems/text-justification +// T: O(|words|) +// S: O(|words|) + +import java.util.ArrayList; +import java.util.List; + +public class TextJustification { + public List fullJustify(String[] words, int maxWidth) { + List ans = new ArrayList<>(); + int i = 0; + + while (i < words.length) { + List currentLine = getWords(i, words, maxWidth); + i += currentLine.size(); + ans.add(createLine(currentLine, i, words, maxWidth)); + } + + return ans; + } + + private List getWords(int i, String[] words, int maxWidth) { + List currentLine = new ArrayList<>(); + int currLength = 0; + + while (i < words.length && currLength + words[i].length() <= maxWidth) { + currentLine.add(words[i]); + currLength += words[i].length() + 1; + i++; + } + + return currentLine; + } + + private String createLine( + List line, + int i, + String[] words, + int maxWidth + ) { + int baseLength = -1; + for (String word : line) { + baseLength += word.length() + 1; + } + + int extraSpaces = maxWidth - baseLength; + + if (line.size() == 1 || i == words.length) { + return String.join(" ", line) + " ".repeat(extraSpaces); + } + + int wordCount = line.size() - 1; + int spacesPerWord = extraSpaces / wordCount; + int needsExtraSpace = extraSpaces % wordCount; + + for (int j = 0; j < needsExtraSpace; j++) { + line.set(j, line.get(j) + " "); + } + + for (int j = 0; j < wordCount; j++) { + line.set(j, line.get(j) + " ".repeat(spacesPerWord)); + } + + return String.join(" ", line); + } +} \ No newline at end of file From 8ed59b785019bcf8cb8029d3fb43ee6bace2673c Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 24 Jul 2024 11:42:35 +0200 Subject: [PATCH 228/280] solves #30: Substring with Concatenation of All Words in java --- README.md | 1 + src/HelloWorld.java | 44 ++++++---- src/SubstringWithConcatenationOfAllWords.java | 88 +++++++++++++++++++ 3 files changed, 115 insertions(+), 18 deletions(-) create mode 100644 src/SubstringWithConcatenationOfAllWords.java diff --git a/README.md b/README.md index eb17ae4..7d54f6e 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ | 27 | [Remove Element](https://leetcode.com/problems/remove-element/) | [![Java](assets/java.png)](src/RemoveElement.java) [![Python](assets/python.png)](python/remove_element.py) | | | 28 | [Needle in Haystack](https://leetcode.com/problems/implement-strstr) | [![Java](assets/java.png)](src/NeedleInHaystack.java) [![Python](assets/python.png)](python/needle_in_haystack.py) | | | 29 | [Divide Two Integers](https://leetcode.com/problems/divide-two-integers) | [![Java](assets/java.png)](src/DivideTwoIntegers.java) | | +| 30 | [Substring with Concatenation of All Words](https://leetcode.com/problems/substring-with-concatenation-of-all-words) | [![Java](assets/java.png)](src/SubstringWithConcatenationOfAllWords.java) | | | 31 | [Next Permutation](https://leetcode.com/problems/next-permutation) | [![Java](assets/java.png)](src/NextPermutation.java) | | | 33 | [Search in Rotated Sorted Array](https://leetcode.com/problems/search-in-rotated-sorted-array) | [![Java](assets/java.png)](src/SearchInRotatedSortedArray.java) | | | 34 | [Find First and Last Position of Element in Sorted Array](https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array) | [![Java](assets/java.png)](src/FindFirstAndLastPositionOfElementInSortedArray.java) | | diff --git a/src/HelloWorld.java b/src/HelloWorld.java index 873b5d8..1907ca4 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -1,27 +1,35 @@ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + public class HelloWorld { - public int strStr(String haystack, String needle) { - if (needle.length() > haystack.length()) { - return -1; + public int lengthOfLongestSubstring(String s) { + if (s.isEmpty()) { + return 0; } - for (int i = 0 ; i < haystack.length() ; i++) { - if (needle.charAt(0) == haystack.charAt(i) && containsAt(haystack, needle, i)) { - return i; + int maxLength = 1; + final Set slidingWindow = new HashSet<>() {{ + add(s.charAt(0)); + }}; + + for (int left = 0, right = 1, currentLength = 1 ; right < s.length() ; ) { + if (slidingWindow.contains(s.charAt(right))) { + slidingWindow.remove(s.charAt(left)); + left++; + currentLength--; + } else { + slidingWindow.add(s.charAt(right)); + currentLength++; + maxLength = Math.max(maxLength, currentLength); + right++; } } - return -1; - } - private static boolean containsAt(String haystack, String needle, int i) { - if (needle.length() > haystack.length() - i) { - return false; - } - for (int index = i + 1 ; index < haystack.length() && index - i < needle.length() ; index++) { - if (needle.charAt(index - i) != haystack.charAt(index)) { - return false; - } - } - return true; + return maxLength; } } diff --git a/src/SubstringWithConcatenationOfAllWords.java b/src/SubstringWithConcatenationOfAllWords.java new file mode 100644 index 0000000..8c6bf39 --- /dev/null +++ b/src/SubstringWithConcatenationOfAllWords.java @@ -0,0 +1,88 @@ +// https://leetcode.com/problems/substring-with-concatenation-of-all-words +// T: O(|words| + |s| * |words[i]|) +// S: O(|words| + |words[i]|) + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +class SubstringWithConcatenationOfAllWords { + private final Map wordCount = new HashMap<>(); + private int n; + private int wordLength; + private int substringSize; + private int k; + + private void slidingWindow(int left, String s, List answer) { + HashMap wordsFound = new HashMap<>(); + int wordsUsed = 0; + boolean excessWord = false; + + // Do the same iteration pattern as the previous approach - iterate + // word_length at a time, and at each iteration we focus on one word + for (int right = left; right <= n - wordLength; right += wordLength) { + String sub = s.substring(right, right + wordLength); + if (!wordCount.containsKey(sub)) { + // Mismatched word - reset the window + wordsFound.clear(); + wordsUsed = 0; + excessWord = false; + left = right + wordLength; + } else { + // If we reached max window size or have an excess word + while (right - left == substringSize || excessWord) { + String leftmostWord = s.substring(left, left + wordLength); + left += wordLength; + wordsFound.put( + leftmostWord, + wordsFound.get(leftmostWord) - 1 + ); + + if ( + wordsFound.get(leftmostWord) >= + wordCount.get(leftmostWord) + ) { + // This word was an excess word + excessWord = false; + } else { + // Otherwise we actually needed it + wordsUsed--; + } + } + + // Keep track of how many times this word occurs in the window + wordsFound.put(sub, wordsFound.getOrDefault(sub, 0) + 1); + if (wordsFound.get(sub) <= wordCount.get(sub)) { + wordsUsed++; + } else { + // Found too many instances already + excessWord = true; + } + + if (wordsUsed == k && !excessWord) { + // Found a valid substring + answer.add(left); + } + } + } + } + + public List findSubstring(String s, String[] words) { + n = s.length(); + k = words.length; + wordLength = words[0].length(); + substringSize = wordLength * k; + + for (String word : words) { + wordCount.put(word, wordCount.getOrDefault(word, 0) + 1); + } + + List answer = new ArrayList<>(); + for (int i = 0; i < wordLength; i++) { + slidingWindow(i, s, answer); + } + + return answer; + } +} \ No newline at end of file From 2e02d14b32e5c8be3f3a5991a47da0490842e028 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 24 Jul 2024 15:15:30 +0200 Subject: [PATCH 229/280] solves #452: Minimum Number of Arrows to Burst Balloons in java --- README.md | 1 + src/HelloWorld.java | 85 ++++++++++++++----- src/MinimumNumberOfArrowsToBurstBalloons.java | 26 ++++++ 3 files changed, 92 insertions(+), 20 deletions(-) create mode 100644 src/MinimumNumberOfArrowsToBurstBalloons.java diff --git a/README.md b/README.md index 7d54f6e..edb0729 100644 --- a/README.md +++ b/README.md @@ -315,6 +315,7 @@ | 443 | [String Compression](https://leetcode.com/problems/string-compression) | [![Java](assets/java.png)](src/StringCompression.java) [![Python](assets/python.png)](python/string_compression.py) | | | 447 | [Number of Boomerangs](https://leetcode.com/problems/number-of-boomerangs) | [![Java](assets/java.png)](src/NumberOfBoomerangs.java) [![Python](assets/python.png)](python/number_of_boomerangs.py) | | | 448 | [Find All Numbers Disappeared in an Array](https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array) | [![Java](assets/java.png)](src/FindAllNumbersDisappearedInAnArray.java) [![Python](assets/python.png)](python/find_all_numbers_disappeared_in_an_array.py) | | +| 452 | [Minimum Number of Arrows to Burst Balloons](https://leetcode.com/problems/minimum-number-of-arrows-to-burst-balloons) | [![Java](assets/java.png)](src/MinimumNumberOfArrowsToBurstBalloons.java) | | | 453 | [Minimum Moves to Equal Array Elements](https://leetcode.com/problems/minimum-moves-to-equal-array-elements) | [![Java](assets/java.png)](src/MinimumMovesToEqualArrayElements.java) [![Python](assets/python.png)](python/minimum_moves_to_equal_array_element.py) | | | 455 | [Assign Cookies](https://leetcode.com/problems/assign-cookies) | [![Java](assets/java.png)](src/AssignCookies.java) [![Python](assets/python.png)](python/assign_cookies.py) | | | 459 | [Repeated Substring Pattern](https://leetcode.com/problems/repeated-substring-pattern) | [![Java](assets/java.png)](src/RepeatedSubstringPattern.java) [![Python](assets/python.png)](python/repeated_substring_pattern.py) | | diff --git a/src/HelloWorld.java b/src/HelloWorld.java index 1907ca4..c9e24ec 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -1,35 +1,80 @@ import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; import java.util.List; -import java.util.Set; public class HelloWorld { - public int lengthOfLongestSubstring(String s) { - if (s.isEmpty()) { - return 0; + public static int[][] insert(int[][] intervals, int[] newInterval) { + if (intervals.length == 0) { + return new int[][] { newInterval }; } - int maxLength = 1; - final Set slidingWindow = new HashSet<>() {{ - add(s.charAt(0)); - }}; + final int startIndex = binarySearch(intervals, newInterval[0]); - for (int left = 0, right = 1, currentLength = 1 ; right < s.length() ; ) { - if (slidingWindow.contains(s.charAt(right))) { - slidingWindow.remove(s.charAt(left)); - left++; - currentLength--; + final List result = new ArrayList<>(); + for (int i = 0 ; i < startIndex ; i++) { + result.add(intervals[i]); + } + result.add(newInterval); + for (int i = startIndex ; i < intervals.length ; i++) { + result.add(intervals[i]); + } + + return mergeIntervals(result); + } + + private static int[][] mergeIntervals(List intervals) { + final List result = new ArrayList<>(); + int start = intervals.getFirst()[0], end = intervals.getFirst()[1]; + for (int[] interval : intervals) { + if (interval[0] <= end) { + end = Math.max(interval[1], end); } else { - slidingWindow.add(s.charAt(right)); - currentLength++; - maxLength = Math.max(maxLength, currentLength); - right++; + result.add(new int[]{start, end}); + start = interval[0]; + end = interval[1]; } } + result.add(new int[] { start, end }); + return toArray(result); + } + + private static int binarySearch(int[][] intervals, int x) { + int left = 0, right = intervals.length - 1, middle; + while (left <= right) { + middle = left + (right - left) / 2; + if (intervals[middle][0] == x) return middle; + else if (intervals[middle][0] < x) left = middle + 1; + else right = middle - 1; + } + return left; + } + + private static int[][] toArray(List intervals) { + final int[][] result = new int[intervals.size()][2]; + int k = 0; + for (int[] interval : intervals) { + result[k++] = interval; + } + return result; + } + + public static void main(String[] args) { +// System.out.println(Arrays.deepToString( +// insert(new int[][]{{1, 3}, {6, 9}}, new int[] {2, 5}) +// )); +// System.out.println(Arrays.deepToString( +// insert( +// new int[][] {{1, 2}, {3, 5}, {6, 7}, {8, 10}, {12, 16}}, +// new int[] {4, 8} +// ) +// )); - return maxLength; + System.out.println(Arrays.deepToString( + insert( + new int[][] {{1, 3}, {6, 9}}, + new int[] {2, 5} + ) + )); } } diff --git a/src/MinimumNumberOfArrowsToBurstBalloons.java b/src/MinimumNumberOfArrowsToBurstBalloons.java new file mode 100644 index 0000000..41410b1 --- /dev/null +++ b/src/MinimumNumberOfArrowsToBurstBalloons.java @@ -0,0 +1,26 @@ +// https://leetcode.com/problems/minimum-number-of-arrows-to-burst-balloons +// T: O(NlogN) +// S: O(logN) + +import java.util.Arrays; +import java.util.Comparator; + +public class MinimumNumberOfArrowsToBurstBalloons { + public int findMinArrowShots(int[][] points) { + if (points.length == 0) { + return 0; + } + + Arrays.sort(points, Comparator.comparingInt(o -> o[1])); + + int arrows = 1, endPoint = points[0][1]; + for (int[] p: points) { + if (endPoint < p[0]) { + arrows++; + endPoint = p[1]; + } + } + + return arrows; + } +} From 1fe65c6ba1fd39dab248a0c932282a8c6da4c994 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 25 Jul 2024 05:53:29 +0200 Subject: [PATCH 230/280] solves #224: Basic Calculator in java --- README.md | 1 + src/BasicCalculator.java | 38 ++++++++++++++++ src/HelloWorld.java | 93 +++++++++++----------------------------- 3 files changed, 63 insertions(+), 69 deletions(-) create mode 100644 src/BasicCalculator.java diff --git a/README.md b/README.md index edb0729..11bf953 100644 --- a/README.md +++ b/README.md @@ -190,6 +190,7 @@ | 221 | [Maximal Square](https://leetcode.com/problems/maximal-square) | [![Java](assets/java.png)](src/MaximalSquare.java) | | | 222 | [Count Complete Tree Nodes](https://leetcode.com/problems/count-complete-tree-nodes) | [![Java](assets/java.png)](src/CountCompleteTreeNodes.java) | | | 223 | [Rectangle Area](https://leetcode.com/problems/rectangle-area) | [![Java](assets/java.png)](src/RectangleArea.java) | | +| 224 | [Basic Calculator](https://leetcode.com/problems/basic-calculator) | [![Java](assets/java.png)](src/BasicCalculator.java) | | | 225 | [Implement Stack using Queues](https://leetcode.com/problems/implement-stack-using-queues) | [![Java](assets/java.png)](src/MyStack.java) [![Python](assets/python.png)](python/implement_stack_using_queues.py) | | | 226 | [Invert Binary Tree](https://leetcode.com/problems/invert-binary-tree) | [![Java](assets/java.png)](src/InvertBinaryTree.java) [![Python](assets/python.png)](python/invert_binary_tree.py) | | | 227 | [Basic Calculator II](https://leetcode.com/problems/basic-calculator-ii) | [![Java](assets/java.png)](src/BasicCalculatorII.java) | | diff --git a/src/BasicCalculator.java b/src/BasicCalculator.java new file mode 100644 index 0000000..ea9c270 --- /dev/null +++ b/src/BasicCalculator.java @@ -0,0 +1,38 @@ +import java.util.Stack; + +class BasicCalculator { + public int calculate(String s) { + final Stack stack = new Stack(); + int number = 0; + int result = 0; // For the ongoing result + int sign = 1; // 1 means positive, -1 means negative + + for (int i = 0; i < s.length(); i++) { + final char ch = s.charAt(i); + + if (Character.isDigit(ch)) { + number = 10 * number + (ch - '0'); + } else if (isOperator(ch)) { + result += sign * number; + number = 0; + sign = ch == '+' ? 1 : -1; + } else if (ch == '(') { + stack.push(result); + stack.push(sign); + sign = 1; + result = 0; + } else if (ch == ')') { + result += sign * number; + result *= stack.pop(); + result += stack.pop(); + number = 0; + } + } + + return result + (sign * number); + } + + private static boolean isOperator(char c) { + return c == '+' || c == '-'; + } +} \ No newline at end of file diff --git a/src/HelloWorld.java b/src/HelloWorld.java index c9e24ec..e856c84 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -1,80 +1,35 @@ -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; +import java.util.Set; +import java.util.Stack; public class HelloWorld { - public static int[][] insert(int[][] intervals, int[] newInterval) { - if (intervals.length == 0) { - return new int[][] { newInterval }; - } - - final int startIndex = binarySearch(intervals, newInterval[0]); - - final List result = new ArrayList<>(); - for (int i = 0 ; i < startIndex ; i++) { - result.add(intervals[i]); - } - result.add(newInterval); - for (int i = startIndex ; i < intervals.length ; i++) { - result.add(intervals[i]); - } - - return mergeIntervals(result); - } - - private static int[][] mergeIntervals(List intervals) { - final List result = new ArrayList<>(); - int start = intervals.getFirst()[0], end = intervals.getFirst()[1]; - for (int[] interval : intervals) { - if (interval[0] <= end) { - end = Math.max(interval[1], end); + private static final Set OPERATORS = Set.of("+", "-", "*", "/"); + + public int evalRPN(String[] tokens) { + final Stack stack = new Stack<>(); + for (String token : tokens) { + if (isOperator(token)) { + final int second = stack.pop(); + final int first = stack.pop(); + final int result = apply(token, first, second); + stack.push(result); } else { - result.add(new int[]{start, end}); - start = interval[0]; - end = interval[1]; + stack.push(Integer.parseInt(token)); } } - result.add(new int[] { start, end }); - return toArray(result); + return stack.peek(); } - private static int binarySearch(int[][] intervals, int x) { - int left = 0, right = intervals.length - 1, middle; - while (left <= right) { - middle = left + (right - left) / 2; - if (intervals[middle][0] == x) return middle; - else if (intervals[middle][0] < x) left = middle + 1; - else right = middle - 1; - } - return left; + private static boolean isOperator(String token) { + return OPERATORS.contains(token); } - private static int[][] toArray(List intervals) { - final int[][] result = new int[intervals.size()][2]; - int k = 0; - for (int[] interval : intervals) { - result[k++] = interval; - } - return result; - } - - public static void main(String[] args) { -// System.out.println(Arrays.deepToString( -// insert(new int[][]{{1, 3}, {6, 9}}, new int[] {2, 5}) -// )); - -// System.out.println(Arrays.deepToString( -// insert( -// new int[][] {{1, 2}, {3, 5}, {6, 7}, {8, 10}, {12, 16}}, -// new int[] {4, 8} -// ) -// )); - - System.out.println(Arrays.deepToString( - insert( - new int[][] {{1, 3}, {6, 9}}, - new int[] {2, 5} - ) - )); + private static int apply(String operator, int first, int second) { + return switch (operator) { + case "+" -> first + second; + case "-" -> first - second; + case "/" -> first / second; + case "*" -> first * second; + default -> 0; + }; } } From 9d46e880ee6c7fd37344000099bfd0fefe5eca1c Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 25 Jul 2024 06:51:41 +0200 Subject: [PATCH 231/280] update Copy List with Random Pointer --- src/CopyListWithRandomPointer.java | 48 ++++++++++------- src/HelloWorld.java | 86 ++++++++++++++++++++---------- 2 files changed, 88 insertions(+), 46 deletions(-) diff --git a/src/CopyListWithRandomPointer.java b/src/CopyListWithRandomPointer.java index 3c97e95..547d1c1 100644 --- a/src/CopyListWithRandomPointer.java +++ b/src/CopyListWithRandomPointer.java @@ -1,6 +1,6 @@ // https://leetcode.com/problems/copy-list-with-random-pointer // T: O(N) -// S: O(N) +// S: O(1) import java.util.HashMap; import java.util.Map; @@ -18,30 +18,40 @@ public Node(int val) { } } - private static final Map nodes = new HashMap<>(); + public HelloWorld.Node copyRandomList(HelloWorld.Node head) { + if (head == null) { + return null; + } - public Node copyRandomList(Node head) { - if (head == null) return null; + createWeavedList(head); + linkRandomPointersForNewNodes(head); + return unweaveList(head); + } - for (Node current = head ; current != null ; current = current.next) { - Node node = getNode(current); - if (current.next != null) { - node.next = getNode(current.next); - } - if (current.random != null) { - node.random = getNode(current.random); - } + // A->B->C --> A->A'->B->B' + private static void createWeavedList(HelloWorld.Node head) { + for (HelloWorld.Node i = head; i != null ; i = i.next.next) { + HelloWorld.Node newNode = new HelloWorld.Node(i.val); + newNode.next = i.next; + i.next = newNode; } + } - return getNode(head); + private static void linkRandomPointersForNewNodes(HelloWorld.Node head) { + for (HelloWorld.Node i = head; i != null ; i = i.next.next) { + if (i.random == null) { + continue; + } + i.next.random = i.random.next; + } } - private Node getNode(Node node) { - if (nodes.containsKey(node)) { - return nodes.get(node); + private static HelloWorld.Node unweaveList(HelloWorld.Node head) { + final HelloWorld.Node pointerNew = head.next; + for (HelloWorld.Node old = head, i = head.next; i != null && old != null ; i = i.next, old = old.next) { + old.next = old.next == null ? null : old.next.next; + i.next = i.next == null ? null : i.next.next; } - Node copyNode = new Node(node.val); - nodes.put(node, copyNode); - return copyNode; + return pointerNew; } } diff --git a/src/HelloWorld.java b/src/HelloWorld.java index e856c84..7f674c3 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -1,35 +1,67 @@ -import java.util.Set; -import java.util.Stack; - public class HelloWorld { - private static final Set OPERATORS = Set.of("+", "-", "*", "/"); - - public int evalRPN(String[] tokens) { - final Stack stack = new Stack<>(); - for (String token : tokens) { - if (isOperator(token)) { - final int second = stack.pop(); - final int first = stack.pop(); - final int result = apply(token, first, second); - stack.push(result); - } else { - stack.push(Integer.parseInt(token)); - } + public static class Node { + int val; + Node next; + Node random; + + public Node(int val) { + this.val = val; + this.next = null; + this.random = null; } - return stack.peek(); } - private static boolean isOperator(String token) { - return OPERATORS.contains(token); + /* +// Definition for a Node. +class Node { + public int val; + public Node next; + public Node random; + + public Node() {} + + public Node(int _val,Node _next,Node _random) { + val = _val; + next = _next; + random = _random; + } +}; +*/ + + public Node copyRandomList(Node head) { + if (head == null) { + return null; + } + + createWeavedList(head); + linkRandomPointersForNewNodes(head); + return unweaveList(head); } - private static int apply(String operator, int first, int second) { - return switch (operator) { - case "+" -> first + second; - case "-" -> first - second; - case "/" -> first / second; - case "*" -> first * second; - default -> 0; - }; + // A->B->C --> A->A'->B->B' + private static void createWeavedList(Node head) { + for (Node i = head ; i != null ; i = i.next.next) { + Node newNode = new Node(i.val); + newNode.next = i.next; + i.next = newNode; + } + } + + private static void linkRandomPointersForNewNodes(Node head) { + for (Node i = head ; i != null ; i = i.next.next) { + if (i.random == null) { + continue; + } + i.next.random = i.random.next; + } + } + + private static Node unweaveList(Node head) { + final Node pointerNew = head.next; + for (Node old = head, i = head.next ; i != null && old != null ; i = i.next, old = old.next) { + old.next = old.next == null ? null : old.next.next; + i.next = i.next == null ? null : i.next.next; + } + return pointerNew; } } From a3715bffc1c44fe493fe6ffba2fcb6988c1c0c74 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 25 Jul 2024 11:00:08 +0200 Subject: [PATCH 232/280] solves #25: Reverse Nodes in k-Group in java --- README.md | 1 + src/CopyListWithRandomPointer.java | 20 ++++---- src/HelloWorld.java | 76 +++++++++--------------------- src/ListNode.java | 7 +++ src/ReverseNodesInKGroup.java | 44 +++++++++++++++++ 5 files changed, 84 insertions(+), 64 deletions(-) create mode 100644 src/ReverseNodesInKGroup.java diff --git a/README.md b/README.md index 11bf953..52390cb 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ | 21 | [Merge 2 Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/) | [![Java](assets/java.png)](src/Merge2SortedLists.java) [![Python](assets/python.png)](python/merge_2_sorted_lists.py) | | | 22 | [Generate Parentheses](https://leetcode.com/problems/generate-parentheses) | [![Java](assets/java.png)](src/GenerateParentheses.java) | | | 24 | [Swap Nodes in Pairs](https://leetcode.com/problems/swap-nodes-in-pairs) | [![Java](assets/java.png)](src/SwapNodesInPairs.java) | | +| 25 | [Reverse Nodes in k-Group](https://leetcode.com/problems/reverse-nodes-in-k-group) | [![Java](assets/java.png)](src/ReverseNodesInKGroup.java) | | | 26 | [Remove Duplicates From Sorted Array](https://leetcode.com/problems/remove-duplicates-from-sorted-array) | [![Java](assets/java.png)](src/RemoveDuplicatesFromSortedArray.java) [![Python](assets/python.png)](python/remove_duplicates_from_sorted_array.py) [![js](assets/javascript.png)](javascript/RemoveDuplicatesFromSortedArray.js) | | | 27 | [Remove Element](https://leetcode.com/problems/remove-element/) | [![Java](assets/java.png)](src/RemoveElement.java) [![Python](assets/python.png)](python/remove_element.py) | | | 28 | [Needle in Haystack](https://leetcode.com/problems/implement-strstr) | [![Java](assets/java.png)](src/NeedleInHaystack.java) [![Python](assets/python.png)](python/needle_in_haystack.py) | | diff --git a/src/CopyListWithRandomPointer.java b/src/CopyListWithRandomPointer.java index 547d1c1..9be7db0 100644 --- a/src/CopyListWithRandomPointer.java +++ b/src/CopyListWithRandomPointer.java @@ -6,7 +6,7 @@ import java.util.Map; public class CopyListWithRandomPointer { - private static final class Node { + public static final class Node { int val; Node next; Node random; @@ -18,7 +18,7 @@ public Node(int val) { } } - public HelloWorld.Node copyRandomList(HelloWorld.Node head) { + public Node copyRandomList(Node head) { if (head == null) { return null; } @@ -29,16 +29,16 @@ public HelloWorld.Node copyRandomList(HelloWorld.Node head) { } // A->B->C --> A->A'->B->B' - private static void createWeavedList(HelloWorld.Node head) { - for (HelloWorld.Node i = head; i != null ; i = i.next.next) { - HelloWorld.Node newNode = new HelloWorld.Node(i.val); + private static void createWeavedList(Node head) { + for (Node i = head; i != null ; i = i.next.next) { + Node newNode = new Node(i.val); newNode.next = i.next; i.next = newNode; } } - private static void linkRandomPointersForNewNodes(HelloWorld.Node head) { - for (HelloWorld.Node i = head; i != null ; i = i.next.next) { + private static void linkRandomPointersForNewNodes(Node head) { + for (Node i = head; i != null ; i = i.next.next) { if (i.random == null) { continue; } @@ -46,9 +46,9 @@ private static void linkRandomPointersForNewNodes(HelloWorld.Node head) { } } - private static HelloWorld.Node unweaveList(HelloWorld.Node head) { - final HelloWorld.Node pointerNew = head.next; - for (HelloWorld.Node old = head, i = head.next; i != null && old != null ; i = i.next, old = old.next) { + private static Node unweaveList(Node head) { + final Node pointerNew = head.next; + for (Node old = head, i = head.next; i != null && old != null ; i = i.next, old = old.next) { old.next = old.next == null ? null : old.next.next; i.next = i.next == null ? null : i.next.next; } diff --git a/src/HelloWorld.java b/src/HelloWorld.java index 7f674c3..573e356 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -1,67 +1,35 @@ public class HelloWorld { - public static class Node { - int val; - Node next; - Node random; - - public Node(int val) { - this.val = val; - this.next = null; - this.random = null; - } - } - - /* -// Definition for a Node. -class Node { - public int val; - public Node next; - public Node random; - - public Node() {} - - public Node(int _val,Node _next,Node _random) { - val = _val; - next = _next; - random = _random; - } -}; -*/ - - public Node copyRandomList(Node head) { + public ListNode reverseBetween(ListNode head, int left, int right) { if (head == null) { return null; } - createWeavedList(head); - linkRandomPointersForNewNodes(head); - return unweaveList(head); - } + ListNode result = new ListNode(0); + result.next = head; - // A->B->C --> A->A'->B->B' - private static void createWeavedList(Node head) { - for (Node i = head ; i != null ; i = i.next.next) { - Node newNode = new Node(i.val); - newNode.next = i.next; - i.next = newNode; + ListNode start = result; + for (int i = 1 ; i < left ; i++) { + start = start.next; } - } - private static void linkRandomPointersForNewNodes(Node head) { - for (Node i = head ; i != null ; i = i.next.next) { - if (i.random == null) { - continue; - } - i.next.random = i.random.next; + ListNode startNext = start.next, a = startNext, b = start.next.next; + for (int count = left ; b != null && count < right ; count++) { + ListNode c = b.next; + b.next = a; + a = b; + b = c; } + + start.next = a; + startNext.next = b; + + return result.next; } - private static Node unweaveList(Node head) { - final Node pointerNew = head.next; - for (Node old = head, i = head.next ; i != null && old != null ; i = i.next, old = old.next) { - old.next = old.next == null ? null : old.next.next; - i.next = i.next == null ? null : i.next.next; - } - return pointerNew; + public static void main(String[] args) { + ListNode node = new ListNode(1); + node.next = new ListNode(2); + node.next.next = new ListNode(3); + node.next.next.next = new ListNode(4); } } diff --git a/src/ListNode.java b/src/ListNode.java index df94d59..8f00c5b 100644 --- a/src/ListNode.java +++ b/src/ListNode.java @@ -12,4 +12,11 @@ public class ListNode { this.val = val; this.next = next; } + + @Override + public String toString() { + return "ListNode{" + + "val=" + val + + '}'; + } } diff --git a/src/ReverseNodesInKGroup.java b/src/ReverseNodesInKGroup.java new file mode 100644 index 0000000..25c6825 --- /dev/null +++ b/src/ReverseNodesInKGroup.java @@ -0,0 +1,44 @@ +// https://leetcode.com/problems/reverse-nodes-in-k-group +// T: O(N) +// S: O(1) + +public class ReverseNodesInKGroup { + public static ListNode reverseKGroup(ListNode head, int k) { + if (head == null || head.next == null || k == 1) { + return head; + } + + final ListNode result = new ListNode(0); + result.next = head; + + for (ListNode i = result ; i != null ; ) { + ListNode start = i; + + // go forward k steps + int count = 0; + for ( ; count < k && i != null ; count++) { + i = i.next; + } + + if (count == k && i != null) { + i = reverse(start, i); + } + } + + return result.next; + } + + private static ListNode reverse(ListNode start, ListNode end) { + ListNode a = start.next, b = start.next.next, terminal = end.next; + a.next = end.next; + while (b != terminal) { + ListNode c = b.next; + b.next = a; + a = b; + b = c; + } + ListNode newStart = start.next; + start.next = a; + return newStart; + } +} From cb98b2b14a2f780c16a7698fc77121ba6807e11f Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 26 Jul 2024 13:25:06 +0200 Subject: [PATCH 233/280] solves #124: Binary Tree Maximum Path Sum in java --- README.md | 1 + src/BinaryTreeMaximumPathSum.java | 29 ++++++++++ src/HelloWorld.java | 42 ++++++--------- src/LRUCache.java | 89 ++++++++++++++++--------------- 4 files changed, 93 insertions(+), 68 deletions(-) create mode 100644 src/BinaryTreeMaximumPathSum.java diff --git a/README.md b/README.md index 52390cb..8b1f132 100644 --- a/README.md +++ b/README.md @@ -121,6 +121,7 @@ | 120 | [Triangle](https://leetcode.com/problems/triangle) | [![Java](assets/java.png)](src/Triangle.java) | | | 121 | [Best Time to Buy and Sell Stocks](https://leetcode.com/problems/best-time-to-buy-and-sell-stock) | [![Java](assets/java.png)](src/BestTimeToBuyAndSellStock.java) [![Python](assets/python.png)](python/best_time_to_buy_and_sell_stock.py) | | | 122 | [Best Time to Buy and Sell Stocks II](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii) | [![Java](assets/java.png)](src/BestTimeToBuyAndSellStockII.java) [![Python](assets/python.png)](python/best_time_to_buy_and_sell_stock_ii.py) | | +| 123 | [Binary Tree Maximum Path Sum](https://leetcode.com/problems/binary-tree-maximum-path-sum) | [![Java](assets/java.png)](src/BinaryTreeMaximumPathSum.java) | | | 125 | [Valid Palindrome](https://leetcode.com/problems/valid-palindrome) | [![Java](assets/java.png)](src/ValidPalindrome.java) [![Python](assets/python.png)](python/valid_palindrome.py) | | | 128 | [Longest Consecutive Sequence](https://leetcode.com/problems/longest-consecutive-sequence) | [![Java](assets/java.png)](src/LongestConsecutiveSequence.java) | | | 129 | [Sum Root to Leaf Numbers](https://leetcode.com/problems/sum-root-to-leaf-numbers) | [![Java](assets/java.png)](src/SumRootToLeafNumbers.java) | | diff --git a/src/BinaryTreeMaximumPathSum.java b/src/BinaryTreeMaximumPathSum.java new file mode 100644 index 0000000..cbc3ecb --- /dev/null +++ b/src/BinaryTreeMaximumPathSum.java @@ -0,0 +1,29 @@ +// https://leetcode.com/problems/binary-tree-maximum-path-sum +// T: O(N) +// S: O(logN) + +public class BinaryTreeMaximumPathSum { + private static int result = Integer.MIN_VALUE; + + public int maxPathSum(TreeNode root) { + result = Integer.MIN_VALUE; + if (root == null) { + return 0; + } + maxSum(root); + return result; + } + + private static int maxSum(TreeNode root) { + if (root == null) { + return 0; + } + + final int maxSumLeftSubtree = Math.max(maxSum(root.left), 0); + final int maxSumRightSubtree = Math.max(maxSum(root.right), 0); + final int maxPathSum = root.val + maxSumLeftSubtree + maxSumRightSubtree; + result = Math.max(result, maxPathSum); + + return Math.max(root.val + maxSumLeftSubtree, root.val + maxSumRightSubtree); + } +} diff --git a/src/HelloWorld.java b/src/HelloWorld.java index 573e356..7544439 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -1,35 +1,25 @@ public class HelloWorld { - public ListNode reverseBetween(ListNode head, int left, int right) { - if (head == null) { - return null; - } - - ListNode result = new ListNode(0); - result.next = head; + private static int result = Integer.MIN_VALUE; - ListNode start = result; - for (int i = 1 ; i < left ; i++) { - start = start.next; + public static int maxPathSum(TreeNode root) { + result = Integer.MIN_VALUE; + if (root == null) { + return 0; } + maxSum(root); + return result; + } - ListNode startNext = start.next, a = startNext, b = start.next.next; - for (int count = left ; b != null && count < right ; count++) { - ListNode c = b.next; - b.next = a; - a = b; - b = c; + private static int maxSum(TreeNode root) { + if (root == null) { + return 0; } - start.next = a; - startNext.next = b; - - return result.next; - } + final int maxGainLeftSubtree = Math.max(maxSum(root.left), 0); + final int maxGainRightSubtree = Math.max(maxSum(root.right), 0); + final int maxPathSum = root.val + maxGainLeftSubtree + maxGainRightSubtree; + result = Math.max(result, maxPathSum); - public static void main(String[] args) { - ListNode node = new ListNode(1); - node.next = new ListNode(2); - node.next.next = new ListNode(3); - node.next.next.next = new ListNode(4); + return Math.max(root.val + maxGainLeftSubtree, root.val + maxGainRightSubtree); } } diff --git a/src/LRUCache.java b/src/LRUCache.java index f0862e2..445b433 100644 --- a/src/LRUCache.java +++ b/src/LRUCache.java @@ -8,77 +8,82 @@ public class LRUCache { private static class Node { int key; int value; - Node next; Node previous; + Node next; - Node() { } - Node(int key, int value) { + public Node(int key, int value) { this.key = key; this.value = value; } } - private final int capacity; private final Map cache = new HashMap<>(); + private final int capacity; private Node head, tail; public LRUCache(int capacity) { this.capacity = capacity; - head = new Node(); - tail = new Node(); - head.next = tail; - tail.previous = head; } public int get(int key) { - Node node = cache.get(key); - if(node == null) { + if (!cache.containsKey(key)) { return -1; } - moveToHead(node); + final Node node = cache.get(key); + moveNodeToTail(node); return node.value; } public void put(int key, int value) { - Node node = cache.get(key); - - if(node == null) { - Node newNode = new Node(key, value); - this.cache.put(key, newNode); - this.addNode(newNode); + if (cache.containsKey(key)) { + Node node = cache.get(key); + node.value = value; + moveNodeToTail(node); + } else if (cache.size() == capacity) { + Node node = new Node(key, value); + cache.put(key, node); + cache.remove(head.key); + appendToTail(node); + popHead(); + } else { + Node node = new Node(key, value); + cache.put(key, node); - if(cache.size() > capacity){ - Node tail = popTail(); - this.cache.remove(tail.key); + if (cache.size() == 1) { + head = node; + tail = node; + } else { + appendToTail(node); } - } else { - node.value = value; - moveToHead(node); } } - private Node popTail(){ - Node res = tail.previous; - this.removeNode(res); - return res; - } + private void moveNodeToTail(Node node) { + if (node == tail) { + return; + } + + if (node == head) { + appendToTail(node); + popHead(); + return; + } + + Node previous = node.previous, next = node.next; + previous.next = next; + next.previous = previous; - private void addNode(Node node) { - node.previous = head; - node.next = head.next; - head.next.previous = node; - head.next = node; + appendToTail(node); } - private void removeNode(Node node){ - Node pre = node.previous; - Node post = node.next; - pre.next = post; - post.previous = pre; + private void appendToTail(Node node) { + tail.next = node; + node.previous = tail; + tail = node; } - private void moveToHead(Node node){ - this.removeNode(node); - this.addNode(node); + private void popHead() { + head = head.next; + head.previous = null; } -} +} \ No newline at end of file From 41f558190ad04fdf2d7f02949d86aa09f1411034 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 26 Jul 2024 14:03:54 +0200 Subject: [PATCH 234/280] updates count nodes complete tree --- src/CountCompleteTreeNodes.java | 49 ++++++++++++++++++++++++++------- src/HelloWorld.java | 45 +++++++++++++++++++++--------- 2 files changed, 71 insertions(+), 23 deletions(-) diff --git a/src/CountCompleteTreeNodes.java b/src/CountCompleteTreeNodes.java index b0611fb..0a1176f 100644 --- a/src/CountCompleteTreeNodes.java +++ b/src/CountCompleteTreeNodes.java @@ -3,17 +3,46 @@ // S: O(log(n)) public class CountCompleteTreeNodes { - private static int depth(TreeNode root) { - if (root == null) return 0; - return 1 + depth(root.left); + public int countNodes(TreeNode root) { + if (root == null) { + return 0; + } + + final int depth = depthTree(root) - 1; + if (depth == 0) { + return 1; + } + + int left = 0, right = (int) Math.pow(2, depth) - 1, middle; + while (left <= right) { + middle = left + (right - left) / 2; + if (exists(root, depth, middle)) left = middle + 1; + else right = middle - 1; + } + + return (int) Math.pow(2, depth) - 1 + left; } - public static int countNodes(TreeNode root) { - if (root == null) return 0; - int leftDepth = depth(root.left); - int rightDepth = depth(root.right); - return 1 + (leftDepth == rightDepth - ? ((1 << leftDepth) - 1) + countNodes(root.right) - : countNodes(root.left) + countNodes(root.right)); + private static boolean exists(TreeNode root, int depth, int index) { + TreeNode current = root; + int value = -1; + for (int i = 0 ; i < depth ; i++) { + final int middle = (int) Math.pow(2, depth - 1 - i); + if (index > value + middle) { + current = current.right; + value += middle; + } else { + current = current.left; + } + } + return current != null; + } + + private static int depthTree(TreeNode root) { + if (root == null) { + return 0; + } + + return 1 + Math.max(depthTree(root.left), depthTree(root.right)); } } diff --git a/src/HelloWorld.java b/src/HelloWorld.java index 7544439..982c34e 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -1,25 +1,44 @@ public class HelloWorld { - private static int result = Integer.MIN_VALUE; - - public static int maxPathSum(TreeNode root) { - result = Integer.MIN_VALUE; + public int countNodes(TreeNode root) { if (root == null) { return 0; } - maxSum(root); - return result; + + final int depth = depthTree(root) - 1; + if (depth == 0) { + return 1; + } + + int left = 0, right = (int) Math.pow(2, depth) - 1, middle; + while (left <= right) { + middle = left + (right - left) / 2; + if (exists(root, depth, middle)) left = middle + 1; + else right = middle - 1; + } + + return (int) Math.pow(2, depth) - 1 + left; } - private static int maxSum(TreeNode root) { + private static boolean exists(TreeNode root, int depth, int index) { + TreeNode current = root; + int value = -1; + for (int i = 0 ; i < depth ; i++) { + final int middle = (int) Math.pow(2, depth - 1 - i); + if (index > value + middle) { + current = current.right; + value += middle; + } else { + current = current.left; + } + } + return current != null; + } + + private static int depthTree(TreeNode root) { if (root == null) { return 0; } - final int maxGainLeftSubtree = Math.max(maxSum(root.left), 0); - final int maxGainRightSubtree = Math.max(maxSum(root.right), 0); - final int maxPathSum = root.val + maxGainLeftSubtree + maxGainRightSubtree; - result = Math.max(result, maxPathSum); - - return Math.max(root.val + maxGainLeftSubtree, root.val + maxGainRightSubtree); + return 1 + Math.max(depthTree(root.left), depthTree(root.right)); } } From 1c9fad3d71ce49d53252332c1924156129923359 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 27 Jul 2024 18:08:23 +0200 Subject: [PATCH 235/280] solves #399: Evaluate Division in java --- README.md | 1 + src/EvaluateDivision.java | 67 ++++++++++++++++++++++++++++ src/HelloWorld.java | 94 ++++++++++++++++++++++++++------------- 3 files changed, 131 insertions(+), 31 deletions(-) create mode 100644 src/EvaluateDivision.java diff --git a/README.md b/README.md index 8b1f132..0b5ea7a 100644 --- a/README.md +++ b/README.md @@ -303,6 +303,7 @@ | 387 | [First Unique Character in String](https://leetcode.com/problems/first-unique-character-in-a-string) | [![Java](assets/java.png)](src/FirstUniqueCharacter.java) [![Python](assets/python.png)](python/first_unique_character_in_string.py) | | | 389 | [Find the Difference](https://leetcode.com/problems/find-the-difference) | [![Java](assets/java.png)](src/FindTheDifference.java) [![Python](assets/python.png)](python/find_the_difference.py) | | | 392 | [Is Subsequence](https://leetcode.com/problems/is-subsequence) | [![Java](assets/java.png)](src/IsSubsequence.java) [![Python](assets/python.png)](python/is_subsequence.py) | | +| 399 | [Evaluate Division](https://leetcode.com/problems/evaluate-division) | [![Java](assets/java.png)](src/EvaluateDivision.java) | | | 401 | [Binary Watch](https://leetcode.com/problems/binary-watch) | [![Java](assets/java.png)](src/BinaryWatch.java) [![Python](assets/python.png)](python/binary_watch.py) | | | 404 | [Sum of Left Leaves](https://leetcode.com/problems/sum-of-left-leaves) | [![Java](assets/java.png)](src/SumOfLeftLeaves.java) [![Python](assets/python.png)](python/sum_of_left_leaves.py) | | | 405 | [Convert a Number to Hexadecimal](https://leetcode.com/problems/convert-a-number-to-hexadecimal) | [![Java](assets/java.png)](src/ConvertNumberToHexadecimal.java) [![Python](assets/python.png)](python/convert_a_number_to_hexadecimal.py) | | diff --git a/src/EvaluateDivision.java b/src/EvaluateDivision.java new file mode 100644 index 0000000..20dcc0c --- /dev/null +++ b/src/EvaluateDivision.java @@ -0,0 +1,67 @@ +// https://leetcode.com/problems/evaluate-division +// N = |equations|, M = |queries| +// T: O(N + M*N) = O(MN) +// S: O(N + M) + +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +public class EvaluateDivision { + public static double[] calcEquation(List> equations, double[] values, List> queries) { + final Map> graph = createGraph(equations, values); + return computeQueries(graph, queries); + } + + private static Map> createGraph(List> equations, double[] values) { + final Map> result = new HashMap<>(); + for (int i = 0 ; i < equations.size() ; i++) { + final List equation = equations.get(i); + final String dividend = equation.get(0), divisor = equation.get(1); + result.putIfAbsent(dividend, new HashMap<>()); + result.putIfAbsent(divisor, new HashMap<>()); + result.get(dividend).put(divisor, values[i]); + result.get(divisor).put(dividend, 1 / values[i]); + } + return result; + } + + private static double[] computeQueries(Map> graph, List> queries) { + final double[] result = new double[queries.size()]; + for (int i = 0 ; i < queries.size() ; i++) { + final List query = queries.get(i); + final String dividend = query.get(0), divisor = query.get(1); + if (!graph.containsKey(dividend) || !graph.containsKey(divisor)) { + result[i] = -1; + } else if (dividend.equals(divisor)) { + result[i] = 1; + } else { + result[i] = computeDfs(graph, dividend, divisor); + } + } + return result; + } + + private static double computeDfs(Map> graph, String dividend, String divisor) { + return dfs(graph, dividend, divisor, 1, new HashSet<>()); + } + + private static double dfs(Map> graph, String current, String target, double product, Set visited) { + if (current.equals(target)) { + return product; + } + if (visited.contains(current)) { + return -1; + } + visited.add(current); + for (Map.Entry edges : graph.get(current).entrySet()) { + final double result = dfs(graph, edges.getKey(), target, product * edges.getValue(), visited); + if (result != -1) { + return result; + } + } + return -1; + } +} diff --git a/src/HelloWorld.java b/src/HelloWorld.java index 982c34e..4a97287 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -1,44 +1,76 @@ +import java.util.*; + public class HelloWorld { - public int countNodes(TreeNode root) { - if (root == null) { - return 0; + public static class Node { + public int val; + public List neighbors; + public Node() { + val = 0; + neighbors = new ArrayList<>(); } - - final int depth = depthTree(root) - 1; - if (depth == 0) { - return 1; + public Node(int _val) { + val = _val; + neighbors = new ArrayList<>(); } - - int left = 0, right = (int) Math.pow(2, depth) - 1, middle; - while (left <= right) { - middle = left + (right - left) / 2; - if (exists(root, depth, middle)) left = middle + 1; - else right = middle - 1; + public Node(int _val, ArrayList _neighbors) { + val = _val; + neighbors = _neighbors; } - return (int) Math.pow(2, depth) - 1 + left; + @Override + public String toString() { + return "Node{" + + "val=" + val + + '}'; + } } - private static boolean exists(TreeNode root, int depth, int index) { - TreeNode current = root; - int value = -1; - for (int i = 0 ; i < depth ; i++) { - final int middle = (int) Math.pow(2, depth - 1 - i); - if (index > value + middle) { - current = current.right; - value += middle; - } else { - current = current.left; + public static Node cloneGraph(Node root) { + final Queue queue = new LinkedList<>(); + final Map oldToNew = new HashMap<>(); + final Set processed = new HashSet<>(); + queue.add(root); + + while (!queue.isEmpty()) { + final Node node = queue.poll(); + if (processed.contains(node)) { + continue; + } + processed.add(node); + + final Node newNode = oldToNew.getOrDefault(node, new Node(node.val)); + oldToNew.putIfAbsent(node, newNode); + + for (Node edge : node.neighbors) { + final Node newEdge = oldToNew.getOrDefault(edge, new Node(edge.val)); + oldToNew.putIfAbsent(edge, newEdge); + newNode.neighbors.add(newEdge); + queue.add(edge); } } - return current != null; + + return oldToNew.get(root); } - private static int depthTree(TreeNode root) { - if (root == null) { - return 0; - } + public static void main(String[] args) { + final Node node1 = new Node(1); + final Node node2 = new Node(2); + final Node node3 = new Node(3); + final Node node4 = new Node(4); + + node1.neighbors.add(node2); + node1.neighbors.add(node4); + + node2.neighbors.add(node1); + node2.neighbors.add(node3); + + node3.neighbors.add(node2); + node3.neighbors.add(node4); + + node4.neighbors.add(node1); + node4.neighbors.add(node3); - return 1 + Math.max(depthTree(root.left), depthTree(root.right)); + final Node clone = cloneGraph(node1); + System.out.println(clone); } -} +} \ No newline at end of file From 042c8452edf06c54fb49078bbe0212342cf97579 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 27 Jul 2024 21:52:41 +0200 Subject: [PATCH 236/280] solves #547: Number of Provinces in java --- README.md | 1 + src/HelloWorld.java | 159 ++++++++++++++++++++++++------------- src/NumberOfProvinces.java | 71 +++++++++++++++++ src/SnakesAndLadders.java | 6 ++ 4 files changed, 183 insertions(+), 54 deletions(-) create mode 100644 src/NumberOfProvinces.java create mode 100644 src/SnakesAndLadders.java diff --git a/README.md b/README.md index 0b5ea7a..c9b7e97 100644 --- a/README.md +++ b/README.md @@ -345,6 +345,7 @@ | 538 | [Convert BST to Greater Tree](https://leetcode.com/problems/convert-bst-to-greater-tree) | [![Java](assets/java.png)](src/ConvertBSTToGreaterTree.java) [![Python](assets/python.png)](python/convert_bst_to_greater_tree.py) | | | 541 | [Reverse String II](https://leetcode.com/problems/reverse-string-ii) | [![Java](assets/java.png)](src/ReverseStringII.java) [![Python](assets/python.png)](python/reverse_string_ii.py) | | | 543 | [Diameter of Binary Tree](https://leetcode.com/problems/diameter-of-binary-tree) | [![Java](assets/java.png)](src/DiameterOfBinaryTree.java) [![Python](assets/python.png)](python/diameter_of_binary_tree.py) | | +| 547 | [Number of Provinces](https://leetcode.com/problems/number-of-provinces) | [![Java](assets/java.png)](src/NumberOfProvinces.java) | | | 551 | [Student Attendance Record I](https://leetcode.com/problems/student-attendance-record-i) | [![Java](assets/java.png)](src/StudentAttendanceRecordI.java) [![Python](assets/python.png)](python/student_attendance_record_I.py) | | | 557 | [Reverse Words in a String III](https://leetcode.com/problems/reverse-words-in-a-string-iii) | [![Java](assets/java.png)](src/ReverseWordsInStringIII.java) [![Python](assets/python.png)](python/reverse_words_in_string_iii.py) | | | 559 | [Maximum Depth of N-Ary Tree](https://leetcode.com/problems/maximum-depth-of-n-ary-tree) | [![Java](assets/java.png)](src/MaximumDepthOfNAryTree.java) [![Python](assets/python.png)](python/maximum_depth_of_n_ary_tree.py) | | diff --git a/src/HelloWorld.java b/src/HelloWorld.java index 4a97287..1e092d5 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -1,76 +1,127 @@ -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Queue; +import java.util.Set; + +/* +kahns algorithm +t: O(V + E) +S: O(E) + */ public class HelloWorld { - public static class Node { - public int val; - public List neighbors; - public Node() { - val = 0; - neighbors = new ArrayList<>(); + private static class QuickUnionFind { + private final int[] array; + + public QuickUnionFind(int size) { + array = new int[size]; + for (int i = 0 ; i < array.length ; i++) { + array[i] = i; + } } - public Node(int _val) { - val = _val; - neighbors = new ArrayList<>(); + + public void union(int x, int y) { + final int rootX = find(x), rootY = find(y); + if (rootY == rootX) { + return; + } + + for (int i = 0 ; i < array.length ; i++) { + if (array[i] == rootY) { + array[i] = rootX; + } + } } - public Node(int _val, ArrayList _neighbors) { - val = _val; - neighbors = _neighbors; + + public int find(int num) { + return array[num]; } - @Override - public String toString() { - return "Node{" + - "val=" + val + - '}'; + public boolean areConnected(int x, int y) { + return find(x) == find(y); } } - public static Node cloneGraph(Node root) { - final Queue queue = new LinkedList<>(); - final Map oldToNew = new HashMap<>(); - final Set processed = new HashSet<>(); - queue.add(root); + private static final class QuickUnionDisjointSet { + private final int[] array; - while (!queue.isEmpty()) { - final Node node = queue.poll(); - if (processed.contains(node)) { - continue; + public QuickUnionDisjointSet(int size) { + array = new int[size]; + for (int i = 0 ; i < array.length ; i++) { + array[i] = i; } - processed.add(node); - - final Node newNode = oldToNew.getOrDefault(node, new Node(node.val)); - oldToNew.putIfAbsent(node, newNode); + } - for (Node edge : node.neighbors) { - final Node newEdge = oldToNew.getOrDefault(edge, new Node(edge.val)); - oldToNew.putIfAbsent(edge, newEdge); - newNode.neighbors.add(newEdge); - queue.add(edge); + public int find(int num) { + while (array[num] != num) { + num = array[num]; } + return num; } - return oldToNew.get(root); - } + public boolean areConnected(int x, int y) { + return find(x) == find(y); + } - public static void main(String[] args) { - final Node node1 = new Node(1); - final Node node2 = new Node(2); - final Node node3 = new Node(3); - final Node node4 = new Node(4); + public void union(int x, int y) { + final int rootX = find(x), rootY = find(y); + if (rootX == rootY) { + return; + } + array[rootY] = rootX; + } + } - node1.neighbors.add(node2); - node1.neighbors.add(node4); + private static final class DisjointSetRank { + private final int[] array; + private final int[] rank; - node2.neighbors.add(node1); - node2.neighbors.add(node3); + public DisjointSetRank(int size) { + array = new int[size]; + rank = new int[size]; + for (int i = 0 ; i < array.length ; i++) { + rank[i] = 1; + array[i] = i; + } + } - node3.neighbors.add(node2); - node3.neighbors.add(node4); + // T: O(logN) + // S: O(1) + public int find(int num) { + if (num == array[num]) { + return num; + } + final int root = find(array[num]); + array[num] = root; + return root; + } - node4.neighbors.add(node1); - node4.neighbors.add(node3); + // T: O(logN) + // S: O(1) + public void union(int x, int y) { + final int rootX = find(x), rootY = find(y); + if (rootX == rootY) { + return; + } + if (rank[rootX] > rank[rootY]) { + array[rootY] = rootX; + } else if (rank[rootX] < rank[rootY]) { + array[rootX] = rootY; + } else { + array[rootY] = rootX; + rank[rootX]++; + } + } - final Node clone = cloneGraph(node1); - System.out.println(clone); + // T: O(logN) + // S: O(1) + public boolean areConnected(int x, int y) { + return find(x) == find(y); + } } -} \ No newline at end of file +} diff --git a/src/NumberOfProvinces.java b/src/NumberOfProvinces.java new file mode 100644 index 0000000..728d922 --- /dev/null +++ b/src/NumberOfProvinces.java @@ -0,0 +1,71 @@ +// https://leetcode.com/problems/number-of-provinces +// T: O(N^2) +// S: O(N) + +public class NumberOfProvinces { + private static final class DisjointSet { + private final int[] array, rank; + + public DisjointSet(int size) { + this.array = new int[size]; + this.rank = new int[size]; + for (int i = 0 ; i < size ; i++) { + array[i] = i; + rank[i] = 1; + } + } + + // T: O(1) + public int find(int x) { + if (x == array[x]) { + return x; + } + final int rank = find(array[x]); + array[x] = rank; + return rank; + } + + // T: O(1) + public boolean areConnected(int x, int y) { + return find(x) == find(y); + } + + // T: O(1) + public void union(int x, int y) { + final int rootX = find(x), rootY = find(y); + if (rootX == rootY) { + return; + } + if (array[rootX] > array[rootY]) { + array[rootY] = rootX; + } else if (array[rootX] < array[rootY]) { + array[rootX] = rootY; + } else { + array[rootY] = rootX; + rank[rootX]++; + } + } + + private int size() { + return array.length; + } + } + + // T: O(n^2) + public int findCircleNum(int[][] isConnected) { + final int cities = isConnected.length; + final DisjointSet disjointSet = new DisjointSet(cities); + int provinces = cities; + + for (int i = 0 ; i < cities ; i++) { + for (int j = i + 1 ; j < cities ; j++) { + if (isConnected[i][j] == 1 && disjointSet.find(i) != disjointSet.find(j)) { + disjointSet.union(i, j); + provinces--; + } + } + } + + return provinces; + } +} diff --git a/src/SnakesAndLadders.java b/src/SnakesAndLadders.java new file mode 100644 index 0000000..06edb72 --- /dev/null +++ b/src/SnakesAndLadders.java @@ -0,0 +1,6 @@ +// https://leetcode.com/problems/snakes-and-ladders +// T: O() +// S: O() + +public class SnakesAndLadders { +} From bfb5f6c9b8a95fa8e6c79e61510c927f83b706b1 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 27 Jul 2024 22:02:04 +0200 Subject: [PATCH 237/280] solves #261: Graph Valid Tree in java --- README.md | 2 +- src/GraphValidTree.java | 59 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 src/GraphValidTree.java diff --git a/README.md b/README.md index c9b7e97..d793b9c 100644 --- a/README.md +++ b/README.md @@ -225,7 +225,7 @@ | 258 | [Add Digits](https://leetcode.com/problems/add-digits) | [![Java](assets/java.png)](src/AddDigits.java) [![Python](assets/python.png)](python/add_digits.py) | | | 259 | 🔒 [3Sum Smaller](https://leetcode.com/problems/3sum-smaller) | | | | 260 | [Single Number III](https://leetcode.com/problems/single-number-iii) | [![Java](assets/java.png)](src/SingleNumberIII.java) | | -| 261 | 🔒 [Graph Valid Tree](https://leetcode.com/problems/graph-valid-tree) | | | +| 261 | 🔒 [Graph Valid Tree](https://leetcode.com/problems/graph-valid-tree) | [![Java](assets/java.png)](src/GraphValidTree.java) | | | 263 | [Ugly Number](https://leetcode.com/problems/ugly-number) | [![Java](assets/java.png)](src/UglyNumber.java) [![Python](assets/python.png)](python/ugly_number.py) | | | 264 | [Ugly Number II](https://leetcode.com/problems/ugly-number-ii) | [![Java](assets/java.png)](src/UglyNumberII.java) | | | 266 | 🔒 [Palindrome Permutation](https://leetcode.com/problems/palindrome-permutation) | | | diff --git a/src/GraphValidTree.java b/src/GraphValidTree.java new file mode 100644 index 0000000..06c9e0d --- /dev/null +++ b/src/GraphValidTree.java @@ -0,0 +1,59 @@ +// https://leetcode.com/problems/graph-valid-tree +// T: O(N) +// S: O(N) + +public class GraphValidTree { + private static final class DisjointSet { + private final int[] root, rank; + + public DisjointSet(int size) { + root = new int[size]; + rank = new int[size]; + for (int i = 0 ; i < size ; i++) { + root[i] = i; + rank[i] = 1; + } + } + + public int find(int num) { + if (root[num] == num) { + return num; + } + return root[num] = find(root[num]); + } + + public boolean areConnected(int x, int y) { + return find(x) == find(y); + } + + public void union(int x, int y) { + final int rootX = find(x), rootY = find(y); + if (rootX == rootY) { + return; + } + if (root[rootX] < root[rootY]) { + root[rootX] = rootY; + } else if (root[rootX] > root[rootY]) { + root[rootY] = rootX; + } else { + root[rootY] = rootX; + rank[rootX]++; + } + } + } + + public boolean validTree(int n, int[][] edges) { + if (edges.length != n - 1) { + return false; + } + + final DisjointSet disjointSet = new DisjointSet(n); + for (int[] edge : edges) { + if (disjointSet.areConnected(edge[0], edge[1])) { + return false; + } + disjointSet.union(edge[0], edge[1]); + } + return true; + } +} From 54958ecbbc78c21f97ba2989860d0640baf5936b Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 27 Jul 2024 22:18:13 +0200 Subject: [PATCH 238/280] solves #684: Redundant Connection in java --- README.md | 1 + src/GraphValidTree.java | 4 +-- src/RedundantConnection.java | 55 ++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 src/RedundantConnection.java diff --git a/README.md b/README.md index d793b9c..9df788f 100644 --- a/README.md +++ b/README.md @@ -379,6 +379,7 @@ | 674 | [Longest Continuous Increasing Subsequence](https://leetcode.com/problems/longest-continuous-increasing-subsequence) | [![Java](assets/java.png)](src/LongestContinuousIncreasingSubsequence.java) [![Python](assets/python.png)](python/longest_continuous_increasing_subsequence.py) | | | 680 | [Valid Palindrome II](https://leetcode.com/problems/valid-palindrome-ii) | [![Java](assets/java.png)](src/ValidPalindromeII.java) [![Python](assets/python.png)](python/valid_pallindrome_ii.py) | | | 682 | [Baseball Game](https://leetcode.com/problems/baseball-game) | [![Java](assets/java.png)](src/BaseballGame.java) [![Python](assets/python.png)](python/baseball_game.py) | | +| 684 | [Redundant Connection](https://leetcode.com/problems/redundant-connection) | [![Java](assets/java.png)](src/RedundantConnection.java) | | | 686 | [Repeated String Match](https://leetcode.com/problems/repeated-string-match) | | | | 687 | [Longest Univalue Path](https://leetcode.com/problems/longest-univalue-path) | | | | 688 | [Knight Probability in Chessboard](https://leetcode.com/problems/knight-probability-in-chessboard) | [![Java](assets/java.png)](src/KnightProbabilityInChessboard.java) | | diff --git a/src/GraphValidTree.java b/src/GraphValidTree.java index 06c9e0d..da28c61 100644 --- a/src/GraphValidTree.java +++ b/src/GraphValidTree.java @@ -31,9 +31,9 @@ public void union(int x, int y) { if (rootX == rootY) { return; } - if (root[rootX] < root[rootY]) { + if (rank[rootX] < rank[rootY]) { root[rootX] = rootY; - } else if (root[rootX] > root[rootY]) { + } else if (rank[rootX] > rank[rootY]) { root[rootY] = rootX; } else { root[rootY] = rootX; diff --git a/src/RedundantConnection.java b/src/RedundantConnection.java new file mode 100644 index 0000000..925eea7 --- /dev/null +++ b/src/RedundantConnection.java @@ -0,0 +1,55 @@ +// https://leetcode.com/problems/redundant-connection +// T: O(N) +// S: O(N) + +public class RedundantConnection { + private static final class DisjointSet { + private final int[] root, rank; + + public DisjointSet(int size) { + this.root = new int[size]; + this.rank = new int[size]; + for (int i = 0 ; i < size ; i++) { + root[i] = i; + rank[i] = 1; + } + } + + public int find(int num) { + if (num == root[num]) { + return num; + } + return root[num] = find(root[num]); + } + + public boolean areConnected(int x, int y) { + return find(x) == find(y); + } + + public void union(int x, int y) { + final int rootX = find(x), rootY = find(y); + if (rootX == rootY) { + return; + } + if (rank[rootX] < rank[rootY]) { + root[rootY] = rootX; + } else if (rank[rootX] > rank[rootY]) { + root[rootY] = rootX; + } else { + root[rootY] = rootX; + rank[rootX]++; + } + } + } + + public int[] findRedundantConnection(int[][] edges) { + final DisjointSet disjointSet = new DisjointSet(edges.length); + for (int[] edge : edges) { + if (disjointSet.areConnected(edge[0] - 1, edge[1] - 1)) { + return edge; + } + disjointSet.union(edge[0] - 1, edge[1] - 1); + } + return new int[] {}; + } +} From b19d3cbb97749809ae478544ef8d6c294c34d798 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 27 Jul 2024 22:28:03 +0200 Subject: [PATCH 239/280] solves #323: Number of Connected Components in an Undirected Graph in java --- README.md | 2 +- ...onnectedComponentsInAnUndirectedGraph.java | 55 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 src/NumberOfConnectedComponentsInAnUndirectedGraph.java diff --git a/README.md b/README.md index 9df788f..d46047e 100644 --- a/README.md +++ b/README.md @@ -270,7 +270,7 @@ | 319 | [Bulb Switcher](https://leetcode.com/problems/bulb-switcher) | | | | 320 | 🔒 [Generalized Abbreviation](https://leetcode.com/problems/generalized-abbreviation) | | | | 322 | [Coin Change](https://leetcode.com/problems/coin-change) | | | -| 323 | 🔒 [Number of Connected Components in Undirected Graph](https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph) | | | +| 323 | 🔒 [Number of Connected Components in Undirected Graph](https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph) | [![Java](assets/java.png)](src/NumberOfConnectedComponentsInAnUndirectedGraph.java) | | | 324 | [Wiggle Sort II](https://leetcode.com/problems/wiggle-sort-ii) | | | | 325 | 🔒 [Maximum Size Subarray Sum Equals K](https://leetcode.com/problems/maximum-size-subarray-sum-equals-k) | | | | 326 | [Power of Three](https://leetcode.com/problems/power-of-three) | [![Java](assets/java.png)](src/PowerOfThree.java) [![Python](assets/python.png)](python/power_of_three.py) | | diff --git a/src/NumberOfConnectedComponentsInAnUndirectedGraph.java b/src/NumberOfConnectedComponentsInAnUndirectedGraph.java new file mode 100644 index 0000000..1d49eda --- /dev/null +++ b/src/NumberOfConnectedComponentsInAnUndirectedGraph.java @@ -0,0 +1,55 @@ +// https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph +// T: O(V + E * alpha(V)) alpha = inverse ackerman function +// S: O(V) + +public class NumberOfConnectedComponentsInAnUndirectedGraph { + private static final class DisjointSet { + private final int[] root, rank; + + public DisjointSet(int size) { + root = new int[size]; + rank = new int[size]; + for (int i = 0 ; i < size ; i++) { + root[i] = i; + rank[i] = 1; + } + } + + public int find(int num) { + if (num == root[num]) { + return num; + } + return root[num] = find(root[num]); + } + + public boolean areConnected(int x, int y) { + return find(x) == find(y); + } + + public void union(int x, int y) { + final int rootX = find(x), rootY = find(y); + if (rootX == rootY) { + return; + } + if (rank[rootX] < rank[rootY]) { + root[rootX] = rootY; + } else if (rank[rootX] > rank[rootY]) { + root[rootY] = rootX; + } else { + root[rootY] = rootX; + rank[rootX]++; + } + } + } + + public int countComponents(int n, int[][] edges) { + final DisjointSet disjointSet = new DisjointSet(n); + for (int[] edge : edges) { + if (!disjointSet.areConnected(edge[0], edge[1])) { + disjointSet.union(edge[0], edge[1]); + n--; + } + } + return n; + } +} From 65f5f540029d3100eed370e75d8d9ee593d6e09d Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 27 Jul 2024 22:40:40 +0200 Subject: [PATCH 240/280] solve #1101: the earliest moment when everyone become friend in java --- README.md | 1 + ...rliestMomentWhenEveryoneBecomeFriends.java | 63 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 src/TheEarliestMomentWhenEveryoneBecomeFriends.java diff --git a/README.md b/README.md index d46047e..3548bd4 100644 --- a/README.md +++ b/README.md @@ -498,6 +498,7 @@ | 1086 | 🔒 [High Five](https://leetcode.com/problems/high-five) | | | | 1089 | [Duplicate Zeroes](https://leetcode.com/problems/duplicate-zeros) | [![Java](assets/java.png)](src/DuplicateZeros.java) | | | 1099 | 🔒 [Two Sum Less Than K](https://leetcode.com/problems/two-sum-less-than-k) | | | +| 1101 | [The Earliest Moment When Everyone Become Friend](https://leetcode.com/problems/the-earliest-moment-when-everyone-become-friends) | [![Java](assets/java.png)](src/TheEarliestMomentWhenEveryoneBecomeFriends.java) | | | 1103 | [Distribute Candies to People](https://leetcode.com/problems/distribute-candies-to-people) | [![Java](assets/java.png)](src/DistributeCandiesToPeople.java) | | | 1108 | [Defanging an IP Address](https://leetcode.com/problems/defanging-an-ip-address) | [![Java](assets/java.png)](src/DefangingAnIPAddress.java) | | | 1118 | 🔒 [Number of Days in a Month](https://leetcode.com/problems/number-of-days-in-a-month) | | | diff --git a/src/TheEarliestMomentWhenEveryoneBecomeFriends.java b/src/TheEarliestMomentWhenEveryoneBecomeFriends.java new file mode 100644 index 0000000..3962b3c --- /dev/null +++ b/src/TheEarliestMomentWhenEveryoneBecomeFriends.java @@ -0,0 +1,63 @@ +// https://leetcode.com/problems/the-earliest-moment-when-everyone-become-friends +// M = |logs| +// T: O(N + M logM + M al(N)) al = inverse Ackermann function +// S: O(N + logM) + +import java.util.Arrays; +import java.util.Comparator; + +public class TheEarliestMomentWhenEveryoneBecomeFriends { + private static final class DisjointSet { + private final int[] root, rank; + + public DisjointSet(int size) { + root = new int[size]; + rank = new int[size]; + for (int i = 0 ; i < size ; i++) { + root[i] = i; + rank[i] = 1; + } + } + + public int find(int num) { + if (num == root[num]) { + return num; + } + return root[num] = find(root[num]); + } + + public boolean areConnected(int x, int y) { + return find(x) == find(y); + } + + public void union(int x, int y) { + final int rootX = find(x), rootY = find(y); + if (rootX == rootY) { + return; + } + if (rank[rootX] > rank[rootY]) { + root[rootY] = rootX; + } else if (rank[rootX] < rank[rootY]) { + root[rootX] = rootY; + } else { + root[rootY] = rootX; + rank[rootX]++; + } + } + } + + public int earliestAcq(int[][] logs, int n) { + final DisjointSet disjointSet = new DisjointSet(n); + Arrays.sort(logs, Comparator.comparingInt(a -> a[0])); + for (int[] log : logs) { + if (!disjointSet.areConnected(log[1], log[2])) { + disjointSet.union(log[1], log[2]); + n--; + if (n == 1) { + return log[0]; + } + } + } + return -1; + } +} From 98b4999b43feadf3fcc8056fc13f9ebe57c4b64c Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 27 Jul 2024 22:55:42 +0200 Subject: [PATCH 241/280] solves 1202: Smallest String With Swaps in java --- README.md | 1 + src/SmallestStringWithSwaps.java | 71 ++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 src/SmallestStringWithSwaps.java diff --git a/README.md b/README.md index 3548bd4..bb7b663 100644 --- a/README.md +++ b/README.md @@ -523,6 +523,7 @@ | 1196 | 🔒 [How Many Apples Can You Put into the Basket](https://leetcode.com/problems/how-many-apples-can-you-put-into-the-basket) | | | | 1200 | [Minimum Absolute Difference](https://leetcode.com/problems/minimum-absolute-difference) | [![Java](assets/java.png)](src/MinimumAbsoluteDifference.java) | | | 1201 | [Ugly Number III](https://leetcode.com/problems/ugly-number-iii) | [![Java](assets/java.png)](src/UglyNumberIII.java) | | +| 1202 | [Smallest String With Swaps](https://leetcode.com/problems/smallest-string-with-swaps) | [![Java](assets/java.png)](src/SmallestStringWithSwaps.java) | | | 1207 | [Unique Number of Occurrences](https://leetcode.com/problems/unique-number-of-occurrences) | [![Java](assets/java.png)](src/UniqueNumberOfOccurrences.java) | | | 1213 | 🔒 [Intersection of Three Sorted Arrays](https://leetcode.com/problems/intersection-of-three-sorted-arrays) | | | | 1217 | [Minimum Cost to Move Chips to The Same Position](https://leetcode.com/problems/minimum-cost-to-move-chips-to-the-same-position) | [![Java](assets/java.png)](src/MinimumCostToMoveChipsToTheSamePosition.java) | | diff --git a/src/SmallestStringWithSwaps.java b/src/SmallestStringWithSwaps.java new file mode 100644 index 0000000..7835ef1 --- /dev/null +++ b/src/SmallestStringWithSwaps.java @@ -0,0 +1,71 @@ +// https://leetcode.com/problems/smallest-string-with-swaps +// s = |s|, p = |pairs| +// T: O(s + p * al(s) + s log(s)) al = inverse Ackermann function +// S: O(s + log(s)) + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.PriorityQueue; +import java.util.Queue; + +public class SmallestStringWithSwaps { + private static final class DisjointSet { + private final int[] root, rank; + + public DisjointSet(int size) { + root = new int[size]; + rank = new int[size]; + for (int i = 0 ; i < size ; i++) { + root[i] = i; + rank[i] = 1; + } + } + + public int find(int num) { + if (num == root[num]) { + return num; + } + return root[num] = find(root[num]); + } + + public boolean areConnected(int x, int y) { + return find(x) == find(y); + } + + public void union(int x, int y) { + final int rootX = find(x), rootY = find(y); + if (rootX == rootY) { + return; + } + if (rank[rootX] > rank[rootY]) { + root[rootY] = rootX; + } else if (rank[rootX] < rank[rootY]) { + root[rootX] = rootY; + } else { + root[rootY] = rootX; + rank[rootX]++; + } + } + } + + public String smallestStringWithSwaps(String s, List> pairs) { + final DisjointSet disjointSet = new DisjointSet(s.length()); + for (List pair : pairs) { + disjointSet.union(pair.get(0), pair.get(1)); + } + final Map> charMinHeaps = new HashMap<>(); + for (int i = 0 ; i < s.length() ; i++) { + final int root = disjointSet.find(i); + final Queue minHeap = charMinHeaps.getOrDefault(root, new PriorityQueue<>()); + minHeap.add(s.charAt(i)); + charMinHeaps.putIfAbsent(root, minHeap); + } + final StringBuilder builder = new StringBuilder(); + for (int i = 0 ; i < s.length() ; i++) { + final int root = disjointSet.find(i); + builder.append(charMinHeaps.get(root).poll()); + } + return builder.toString(); + } +} From 3b8abbc222dc52384c4e28f81791752d0a3adfe2 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 27 Jul 2024 23:26:02 +0200 Subject: [PATCH 242/280] solves #952: Largest Component Size by Common Factor in java --- README.md | 1 + src/LargestComponentSizeByCommonFactor.java | 78 +++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 src/LargestComponentSizeByCommonFactor.java diff --git a/README.md b/README.md index bb7b663..e577310 100644 --- a/README.md +++ b/README.md @@ -458,6 +458,7 @@ | 942 | [DI String Match](https://leetcode.com/problems/di-string-match) | [![Java](assets/java.png)](src/DIStringMatch.java) | | | 944 | [Delete Columns to Make Sorted](https://leetcode.com/problems/delete-columns-to-make-sorted) | [![Java](assets/java.png)](src/DeleteColumnsToMakeSorted.java) | | | 949 | [Largest Time for Given Digits](https://leetcode.com/problems/largest-time-for-given-digits) | | | +| 952 | [Largest Component Size by Common Factor](https://leetcode.com/problems/largest-component-size-by-common-factor) | [![Java](assets/java.png)](src/LargestComponentSizeByCommonFactor.java) | | | 953 | [Verifying an Alien Dictionary](https://leetcode.com/problems/verifying-an-alien-dictionary) | [![Java](assets/java.png)](src/VerifyAnAlienDictionary.java) | | | 961 | [N-Repeated Elements in Size 2N Array](https://leetcode.com/problems/n-repeated-element-in-size-2n-array) | [![Java](assets/java.png)](src/NRepeatedElementInSizeNArray.java) | | | 965 | [Univalued Binary Tree](https://leetcode.com/problems/univalued-binary-tree) | [![Java](assets/java.png)](src/UnivaluedBinaryTree.java) | | diff --git a/src/LargestComponentSizeByCommonFactor.java b/src/LargestComponentSizeByCommonFactor.java new file mode 100644 index 0000000..c2e0d19 --- /dev/null +++ b/src/LargestComponentSizeByCommonFactor.java @@ -0,0 +1,78 @@ +// https://leetcode.com/problems/largest-component-size-by-common-factor +// N = nums, M = max(N) +// T: O(M + N sqrt(M) al(M) + N al(N)) al = inverse Ackermann function +// S: O(M + N) + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +public class LargestComponentSizeByCommonFactor { + private static final class DisjointSet { + private final int[] root, rank; + + public DisjointSet(int size) { + root = new int[size]; + rank = new int[size]; + for (int i = 0 ; i < size ; i++) { + root[i] = i; + rank[i] = 1; + } + } + + public int find(int num) { + if (num == root[num]) { + return num; + } + return root[num] = find(root[num]); + } + + public boolean areConnected(int x, int y) { + return find(x) == find(y); + } + + public void union(int x, int y) { + final int rootX = find(x), rootY = find(y); + if (rootX == rootY) { + return; + } + if (rank[rootX] > rank[rootY]) { + root[rootY] = rootX; + } else if (rank[rootX] < rank[rootY]) { + root[rootY] = rootX; + } else { + root[rootY] = rootX; + rank[rootX]++; + } + } + + public int size() { + return root.length; + } + } + + public int largestComponentSize(int[] nums) { + final int maxValue = Arrays.stream(nums).max().getAsInt(); + final DisjointSet disjointSet = new DisjointSet(maxValue + 1); + for (int number : nums) { + for (int i = 2 ; i * i <= number ; i++) { + if (number % i == 0) { + disjointSet.union(number, i); + disjointSet.union(number, number/ i); + } + } + } + return largestComponentSize(disjointSet, nums); + } + + private static int largestComponentSize(DisjointSet disjointSet, int[] numbers) { + final Map rootFrequencies = new HashMap<>(); + int maxSize = 1; + for (int number : numbers) { + final int root = disjointSet.find(number); + rootFrequencies.put(root, rootFrequencies.getOrDefault(root, 0) + 1); + maxSize = Math.max(maxSize, rootFrequencies.get(root)); + } + return maxSize; + } +} From c06e63f40048432d3d84c1e538e5179b7d187c60 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sun, 28 Jul 2024 00:36:03 +0200 Subject: [PATCH 243/280] solves #1168: optimize water distribution in village --- README.md | 1 + src/HelloWorld.java | 127 +------------------ src/OptimizeWaterDistributionInAVillage.java | 81 ++++++++++++ 3 files changed, 83 insertions(+), 126 deletions(-) create mode 100644 src/OptimizeWaterDistributionInAVillage.java diff --git a/README.md b/README.md index e577310..149b832 100644 --- a/README.md +++ b/README.md @@ -514,6 +514,7 @@ | 1154 | [Day of The Year](https://leetcode.com/problems/day-of-the-year) | [![Java](assets/java.png)](src/DayOfTheYear.java) | | | 1160 | [Find Words That Can Be Formed By Characters](https://leetcode.com/problems/find-words-that-can-be-formed-by-characters) | | | | 1165 | [Single Row Keyboard](https://leetcode.com/problems/single-row-keyboard) | [![Java](assets/java.png)](src/FindWordsThatCanBeFormedByCharacters.java) | | +| 1168 | [Optimize Water Distribution in a Village](https://leetcode.com/problems/optimize-water-distribution-in-a-village) | [![Java](assets/java.png)](src/OptimizeWaterDistributionInAVillage.java) | | | 1170 | [Compare Strings By Frequency of the Smallest Character](https://leetcode.com/problems/compare-strings-by-frequency-of-the-smallest-character) | | | | 1175 | [Prime Arrangements](https://leetcode.com/problems/prime-arrangements) | [![Java](assets/java.png)](src/PrimeArrangements.java) | | | 1176 | 🔒 [Diet Plan Performance](https://leetcode.com/problems/diet-plan-performance) | | | diff --git a/src/HelloWorld.java b/src/HelloWorld.java index 1e092d5..c374d08 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -1,127 +1,2 @@ -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Queue; -import java.util.Set; - -/* -kahns algorithm -t: O(V + E) -S: O(E) - */ - public class HelloWorld { - private static class QuickUnionFind { - private final int[] array; - - public QuickUnionFind(int size) { - array = new int[size]; - for (int i = 0 ; i < array.length ; i++) { - array[i] = i; - } - } - - public void union(int x, int y) { - final int rootX = find(x), rootY = find(y); - if (rootY == rootX) { - return; - } - - for (int i = 0 ; i < array.length ; i++) { - if (array[i] == rootY) { - array[i] = rootX; - } - } - } - - public int find(int num) { - return array[num]; - } - - public boolean areConnected(int x, int y) { - return find(x) == find(y); - } - } - - private static final class QuickUnionDisjointSet { - private final int[] array; - - public QuickUnionDisjointSet(int size) { - array = new int[size]; - for (int i = 0 ; i < array.length ; i++) { - array[i] = i; - } - } - - public int find(int num) { - while (array[num] != num) { - num = array[num]; - } - return num; - } - - public boolean areConnected(int x, int y) { - return find(x) == find(y); - } - - public void union(int x, int y) { - final int rootX = find(x), rootY = find(y); - if (rootX == rootY) { - return; - } - array[rootY] = rootX; - } - } - - private static final class DisjointSetRank { - private final int[] array; - private final int[] rank; - - public DisjointSetRank(int size) { - array = new int[size]; - rank = new int[size]; - for (int i = 0 ; i < array.length ; i++) { - rank[i] = 1; - array[i] = i; - } - } - - // T: O(logN) - // S: O(1) - public int find(int num) { - if (num == array[num]) { - return num; - } - final int root = find(array[num]); - array[num] = root; - return root; - } - - // T: O(logN) - // S: O(1) - public void union(int x, int y) { - final int rootX = find(x), rootY = find(y); - if (rootX == rootY) { - return; - } - if (rank[rootX] > rank[rootY]) { - array[rootY] = rootX; - } else if (rank[rootX] < rank[rootY]) { - array[rootX] = rootY; - } else { - array[rootY] = rootX; - rank[rootX]++; - } - } - - // T: O(logN) - // S: O(1) - public boolean areConnected(int x, int y) { - return find(x) == find(y); - } - } -} +} \ No newline at end of file diff --git a/src/OptimizeWaterDistributionInAVillage.java b/src/OptimizeWaterDistributionInAVillage.java new file mode 100644 index 0000000..86fa90f --- /dev/null +++ b/src/OptimizeWaterDistributionInAVillage.java @@ -0,0 +1,81 @@ +// https://leetcode.com/problems/optimize-water-distribution-in-a-village +// N = n, E = |pipes| +// T: O(N + (N + E) log(N + E) + E al(N)) = O((N + E) log(N + E)) al = inverse Ackermann function +// S: O(N + E) + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; + +public class OptimizeWaterDistributionInAVillage { + private static final class DisjointSet { + private final int[] roots, rank; + + public DisjointSet(int size) { + roots = new int[size]; + rank = new int[size]; + for (int i = 0 ; i < size ; i++) { + roots[i] = i; + rank[i] = 1; + } + } + + public int find(int num) { + if (num == roots[num]) { + return num; + } + return roots[num] = find(roots[num]); + } + + public boolean isConnected(int x, int y) { + return find(x) == find(y); + } + + public void union(int x, int y) { + final int rootX = find(x), rootY = find(y); + if (rootX == rootY) { + return; + } + if (rank[rootX] > rank[rootY]) { + roots[rootY] = rootX; + } else if (rank[rootX] < rank[rootY]) { + roots[rootX] = rootY; + } else { + roots[rootY] = rootX; + rank[rootX]++; + } + } + } + + // Kruskal's algorithm to find MST in unordered weighted graph + public int minCostToSupplyWater(int n, int[] wells, int[][] pipes) { + final List edges = new ArrayList<>(pipes.length + n + 1); + final DisjointSet disjointSet = new DisjointSet(n + 1); + + // add extra vertex and extra edges + for (int i = 0 ; i < n ; i++) { + edges.add(new int[] {0, i + 1, wells[i]}); + } + + // add preexisting edges + edges.addAll(Arrays.asList(pipes)); + + // sort edges according to weight + edges.sort(Comparator.comparingInt(a -> a[2])); + + int totalCost = 0; + for (int[] edge : edges) { + final int house1 = edge[0], house2 = edge[1], cost = edge[2]; + if (!disjointSet.isConnected(house1, house2)) { + disjointSet.union(house1, house2); + totalCost += cost; + n--; + if (n == 0) { + break; + } + } + } + return totalCost; + } +} From 398cdea56b5ebcb75d4871c69976096eae6dc277 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sun, 28 Jul 2024 01:04:53 +0200 Subject: [PATCH 244/280] solves #797: All Paths From Source to Target in java --- README.md | 1 + src/AllPathsFromSourceToTarget.java | 28 +++++++++++++++++ src/HelloWorld.java | 49 +++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 src/AllPathsFromSourceToTarget.java diff --git a/README.md b/README.md index 149b832..58d3265 100644 --- a/README.md +++ b/README.md @@ -414,6 +414,7 @@ | 783 | [Minimum Distance Between BST Nodes](https://leetcode.com/problems/minimum-distance-between-bst-nodes) | [![Java](assets/java.png)](src/MinimumAbsoluteDifferenceInBST.java) [![Python](assets/python.png)](python/minimum_distance_between_bst_nodes.py) | | | 788 | [Rotated Digits](https://leetcode.com/problems/rotated-digits) | | | | 796 | [Rotate String](https://leetcode.com/problems/rotate-string) | [![Java](assets/java.png)](src/RotateString.java) | | +| 797 | [All Paths From Source to Target](https://leetcode.com/problems/all-paths-from-source-to-target) | [![Java](assets/java.png)](src/AllPathsFromSourceToTarget.java) | | | 800 | [Similar RGB Color](https://leetcode.com/problems/similar-rgb-color) | | | | 804 | [Unique Morse Code Words](https://leetcode.com/problems/unique-morse-code-words) | [![Java](assets/java.png)](src/UniqueMorseCodeWords.java) | | | 806 | [Number of Lines to Write String](https://leetcode.com/problems/number-of-lines-to-write-string) | [![Java](assets/java.png)](src/NumberOfLinesToWriteInString.java) | | diff --git a/src/AllPathsFromSourceToTarget.java b/src/AllPathsFromSourceToTarget.java new file mode 100644 index 0000000..f970fea --- /dev/null +++ b/src/AllPathsFromSourceToTarget.java @@ -0,0 +1,28 @@ +// https://leetcode.com/problems/all-paths-from-source-to-target +// maximum edges for DAG = V-1, possible paths = 2^(V-1), for every path we clone path O(V) +// T: O(2^V * V) +// S: O(V) + +import java.util.ArrayList; +import java.util.List; + +public class AllPathsFromSourceToTarget { + public List> allPathsSourceTarget(int[][] graph) { + final List> result = new ArrayList<>(); + final int n = graph.length; + dfs(graph, 0, n - 1, new ArrayList<>() {{ add(0); }}, result); + return result; + } + + private static void dfs(int[][] graph, int current, int target, List path, List> result) { + if (current == target) { + result.add(new ArrayList<>(path)); + return; + } + for (int edge : graph[current]) { + path.add(edge); + dfs(graph, edge, target, path, result); + path.removeLast(); + } + } +} diff --git a/src/HelloWorld.java b/src/HelloWorld.java index c374d08..bb86d84 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -1,2 +1,51 @@ +// T: O(N + E alp(N)) +// S: O(N) + public class HelloWorld { + private static final class DisjointSet { + private final int[] roots, rank; + + public DisjointSet(int size) { + roots = new int[size]; + rank = new int[size]; + for (int i = 0 ; i < size ; i++) { + roots[i] = i; + rank[i] = 1; + } + } + + public int find(int num) { + if (num == roots[num]) { + return num; + } + return roots[num] = find(roots[num]); + } + + public boolean areConnected(int x, int y) { + return find(x) == find(y); + } + + public void union(int x, int y) { + final int rootX = find(x), rootY = find(y); + if (rootX == rootY) { + return; + } + if (rank[rootX] > rank[rootY]) { + roots[rootY] = rootX; + } else if (rank[rootX] < rank[rootY]) { + roots[rootX] = rootY; + } else { + roots[rootY] = rootX; + rank[rootX]++; + } + } + } + + public boolean validPath(int n, int[][] edges, int source, int destination) { + final DisjointSet disjointSet = new DisjointSet(n); + for (int[] edge : edges) { + disjointSet.union(edge[0], edge[1]); + } + return disjointSet.areConnected(source, destination); + } } \ No newline at end of file From 0a181b97f99dfab4236f7d24d9da06b9be22f7fd Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sun, 28 Jul 2024 01:37:31 +0200 Subject: [PATCH 245/280] solves #332: Reconstruct Itinerary in java --- README.md | 1 + src/ReconstructItinerary.java | 40 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 src/ReconstructItinerary.java diff --git a/README.md b/README.md index 58d3265..67e9e56 100644 --- a/README.md +++ b/README.md @@ -277,6 +277,7 @@ | 328 | [Odd Even Linked List](https://leetcode.com/problems/odd-even-linked-list) | | | | 331 | [Verify Preorder Serialization of a Binary Tree](https://leetcode.com/problems/verify-preorder-serialization-of-a-binary-tree) | | | | 331 | 🔒 [Largest BST Subtree](https://leetcode.com/problems/largest-bst-subtree) | | | +| 332 | [Reconstruct Itinerary](https://leetcode.com/problems/reconstruct-itinerary) | [![Java](assets/java.png)](src/ReconstructItinerary.java) | | | 334 | [Increasing Triplet Subsequence](https://leetcode.com/problems/increasing-triplet-subsequence) | | | | 337 | [House Robber III](https://leetcode.com/problems/increasing-triplet-subsequence) | | | | 338 | [Counting Bits](https://leetcode.com/problems/counting-bits/) | [![Java](assets/java.png)](src/CountingBits.java) [![Python](assets/python.png)](python/counting_bits.py) | | diff --git a/src/ReconstructItinerary.java b/src/ReconstructItinerary.java new file mode 100644 index 0000000..114a03c --- /dev/null +++ b/src/ReconstructItinerary.java @@ -0,0 +1,40 @@ +// https://leetcode.com/problems/reconstruct-itinerary +// E = |flights|, V = |airports| N = E / V +// T: O(V * NlogN) = O(E log(E / V)) +// S: O(V + E) + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.PriorityQueue; +import java.util.Queue; + +public class ReconstructItinerary { + public List findItinerary(List> tickets) { + final Map> graph = createGraph(tickets); + final List result = new ArrayList<>(); + dfs(graph, "JFK", result); + return result.reversed(); + } + + private static void dfs(Map> graph, String current, List result) { + final Queue queue = graph.getOrDefault(current, new PriorityQueue<>()); + while (!queue.isEmpty()) { + final String to = queue.poll(); + dfs(graph, to, result); + } + result.add(current); + } + + private static Map> createGraph(List> tickets) { + final Map> graph = new HashMap<>(); + for (List ticket : tickets) { + final String from = ticket.get(0), to = ticket.get(1); + final Queue queue = graph.getOrDefault(from, new PriorityQueue<>()); + queue.add(to); + graph.putIfAbsent(from, queue); + } + return graph; + } +} From 758a9e4409e6ea23d66b71bcf997836b9440316d Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sun, 28 Jul 2024 09:56:25 +0200 Subject: [PATCH 246/280] solves #1059: all paths from source lead to destination --- README.md | 1 + src/AllPathsFromSourceLeadToDestination.java | 53 ++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 src/AllPathsFromSourceLeadToDestination.java diff --git a/README.md b/README.md index 67e9e56..7f5d7eb 100644 --- a/README.md +++ b/README.md @@ -493,6 +493,7 @@ | 1047 | [Remove All adjacent Duplicates in String](https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string) | [![Java](assets/java.png)](src/RemoveAllAdjacentDuplicatesInAString.java) | | | 1051 | [Height Checker](https://leetcode.com/problems/height-checker) | | | | 1056 | 🔒 [Confusing Number](https://leetcode.com/problems/confusing-number) | | | +| 1059 | 🔒 [All Paths From Source Lead To Destination](https://leetcode.com/problems/all-paths-from-source-lead-to-destination) | [![Java](assets/java.png)](src/AllPathsFromSourceLeadToDestination.java) | | | 1064 | 🔒 [Fixed Point](https://leetcode.com/problems/fixed-point) | | | | 1065 | 🔒 [Index Pairs of a String](https://leetcode.com/problems/index-pairs-of-a-string) | | | | 1071 | [Greatest Common Divisors of Strings](https://leetcode.com/problems/greatest-common-divisor-of-strings) | [![Java](assets/java.png)](src/GreatestCommonDivisorOfStrings.java) | | diff --git a/src/AllPathsFromSourceLeadToDestination.java b/src/AllPathsFromSourceLeadToDestination.java new file mode 100644 index 0000000..82dd89f --- /dev/null +++ b/src/AllPathsFromSourceLeadToDestination.java @@ -0,0 +1,53 @@ +// https://leetcode.com/problems/all-paths-from-source-lead-to-destination +// T: O(V + E) +// S: O(V) + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public class AllPathsFromSourceLeadToDestination { + // We don't use the state WHITE as such anywhere. Instead, the "null" value in the states array below is a substitute for WHITE. + enum Color { GRAY, BLACK }; + + public boolean leadsToDestination(int n, int[][] edges, int source, int destination) { + Map> graph = buildGraph(edges); + return leadsToDestination(graph, source, destination, new Color[n]); + } + + private boolean leadsToDestination(Map> graph, int node, int target, Color[] states) { + // If the state is GRAY, this is a backward edge and hence, it creates a loop. + if (states[node] != null) { + return states[node] == Color.BLACK; + } + + // If this is a leaf node, it should be equal to the destination. + if (!graph.containsKey(node)) { + return node == target; + } + + // Now, we are processing this node. So we mark it as GRAY + states[node] = Color.GRAY; + + for (int next : graph.get(node)) { + if (!leadsToDestination(graph, next, target, states)) { + return false; + } + } + + states[node] = Color.BLACK; + return true; + } + + private Map> buildGraph(int[][] edges) { + final Map> graph = new HashMap<>(); + for (int[] edge : edges) { + final int from = edge[0], to = edge[1]; + final Set neighbours = graph.getOrDefault(from, new HashSet<>()); + neighbours.add(to); + graph.putIfAbsent(from, neighbours); + } + return graph; + } +} From 219f754b4f858054dad4db9d856cbff6028b776f Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sun, 28 Jul 2024 17:54:04 +0200 Subject: [PATCH 247/280] solves #1091: Shortest Path in Binary Matrix in java --- README.md | 1 + src/HelloWorld.java | 83 +++++++++++++++++------------ src/ShortestPathInBinaryMatrix.java | 64 ++++++++++++++++++++++ 3 files changed, 114 insertions(+), 34 deletions(-) create mode 100644 src/ShortestPathInBinaryMatrix.java diff --git a/README.md b/README.md index 7f5d7eb..9e970ce 100644 --- a/README.md +++ b/README.md @@ -501,6 +501,7 @@ | 1085 | 🔒 [Sum of Digits in Minimum Number](https://leetcode.com/problems/sum-of-digits-in-the-minimum-number) | | | | 1086 | 🔒 [High Five](https://leetcode.com/problems/high-five) | | | | 1089 | [Duplicate Zeroes](https://leetcode.com/problems/duplicate-zeros) | [![Java](assets/java.png)](src/DuplicateZeros.java) | | +| 1091 | [Shortest Path in Binary Matrix](https://leetcode.com/problems/shortest-path-in-binary-matrix) | [![Java](assets/java.png)](src/ShortestPathInBinaryMatrix.java) | | | 1099 | 🔒 [Two Sum Less Than K](https://leetcode.com/problems/two-sum-less-than-k) | | | | 1101 | [The Earliest Moment When Everyone Become Friend](https://leetcode.com/problems/the-earliest-moment-when-everyone-become-friends) | [![Java](assets/java.png)](src/TheEarliestMomentWhenEveryoneBecomeFriends.java) | | | 1103 | [Distribute Candies to People](https://leetcode.com/problems/distribute-candies-to-people) | [![Java](assets/java.png)](src/DistributeCandiesToPeople.java) | | diff --git a/src/HelloWorld.java b/src/HelloWorld.java index bb86d84..84244db 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -1,51 +1,66 @@ // T: O(N + E alp(N)) // S: O(N) +import java.security.cert.Certificate; +import java.util.LinkedList; +import java.util.Queue; + + + public class HelloWorld { - private static final class DisjointSet { - private final int[] roots, rank; - - public DisjointSet(int size) { - roots = new int[size]; - rank = new int[size]; - for (int i = 0 ; i < size ; i++) { - roots[i] = i; - rank[i] = 1; - } + public static class Node { + public int val; + public Node left; + public Node right; + public Node next; + + public Node() {} + + public Node(int _val) { + val = _val; } - public int find(int num) { - if (num == roots[num]) { - return num; - } - return roots[num] = find(roots[num]); + public Node(int _val, Node _left, Node _right, Node _next) { + val = _val; + left = _left; + right = _right; + next = _next; } + }; - public boolean areConnected(int x, int y) { - return find(x) == find(y); + public Node connect(Node root) { + if (root == null) { + return null; } - public void union(int x, int y) { - final int rootX = find(x), rootY = find(y); - if (rootX == rootY) { - return; + final Queue queue = new LinkedList<>(); + queue.add(root); + queue.add(null); + Node current = null; + + while (!queue.isEmpty()) { + final Node node = queue.poll(); + if (node == null) { + if (!queue.isEmpty()) { + queue.add(null); + current = null; + } + continue; } - if (rank[rootX] > rank[rootY]) { - roots[rootY] = rootX; - } else if (rank[rootX] < rank[rootY]) { - roots[rootX] = rootY; - } else { - roots[rootY] = rootX; - rank[rootX]++; + + addChildrenToQueue(queue, node); + + if (current != null) { + current.next = node; } + current = node; } + + return root; } - public boolean validPath(int n, int[][] edges, int source, int destination) { - final DisjointSet disjointSet = new DisjointSet(n); - for (int[] edge : edges) { - disjointSet.union(edge[0], edge[1]); - } - return disjointSet.areConnected(source, destination); + private static void addChildrenToQueue(Queue queue, Node node) { + if (node.left != null) queue.add(node.left); + if (node.right != null) queue.add(node.right); } } \ No newline at end of file diff --git a/src/ShortestPathInBinaryMatrix.java b/src/ShortestPathInBinaryMatrix.java new file mode 100644 index 0000000..0a21dd3 --- /dev/null +++ b/src/ShortestPathInBinaryMatrix.java @@ -0,0 +1,64 @@ +// https://leetcode.com/problems/shortest-path-in-binary-matrix +// N = total number of vertices +// T: O(N) +// S: O(N) + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; + +public class ShortestPathInBinaryMatrix { + private static final List> directions = List.of( + List.of(-1, -1), + List.of(-1, 0), + List.of(-1, 1), + List.of(1, -1), + List.of(1, 0), + List.of(1, 1), + List.of(0, -1), + List.of(0, 1) + ); + + public int shortestPathBinaryMatrix(int[][] grid) { + final int n = grid.length; + if (grid[0][0] == 1 || grid[n - 1][n - 1] == 1) { + return -1; + } + + final Queue queue = new LinkedList<>(); + queue.add(new int[] {0, 0}); + grid[0][0] = 1; + + while (!queue.isEmpty()) { + final int[] position = queue.poll(); + if (position[0] == n - 1 && position[1] == n - 1) { + return grid[n - 1][n - 1]; + } + + for (int[] neighbour : getNeighbours(position, grid)) { + queue.add(neighbour); + grid[neighbour[0]][neighbour[1]] = grid[position[0]][position[1]] + 1; + } + } + + return -1; + } + + private static List getNeighbours(int[] position, int[][] grid) { + final List result = new ArrayList<>(); + for (List direction : directions) { + final int row = position[0] + direction.get(0); + final int column = position[1] + direction.get(1); + if (isValid(grid, row, column) && grid[row][column] == 0) { + result.add(new int[] { row, column }); + } + } + return result; + } + + private static boolean isValid(int[][] grid, int row, int column) { + final int n = grid.length; + return row >= 0 && row < n && column >= 0 && column < n; + } +} From 015cc5f0c2b099d9643d1fdb5454503ba2fc01ae Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sun, 28 Jul 2024 18:24:46 +0200 Subject: [PATCH 248/280] solves #429: N-ary Tree Level Order Traversal in java --- README.md | 1 + src/NAryTreeLevelOrderTraversal.java | 56 ++++++++++++++++++++ src/PathsInMatrixWhoseSumIsDivisibleByK.java | 39 ++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 src/NAryTreeLevelOrderTraversal.java create mode 100644 src/PathsInMatrixWhoseSumIsDivisibleByK.java diff --git a/README.md b/README.md index 9e970ce..2f31370 100644 --- a/README.md +++ b/README.md @@ -314,6 +314,7 @@ | 414 | [Third Maximum Number](https://leetcode.com/problems/third-maximum-number) | [![Java](assets/java.png)](src/ThirdMaximumNumber.java) [![Python](assets/python.png)](python/fizz_buzz.py) | | | 415 | [Add Strings](https://leetcode.com/problems/add-strings) | [![Java](assets/java.png)](src/AddString.java) [![Python](assets/python.png)](python/add_strings.py) | | | 422 | 🔒 [Valid Word Square](https://leetcode.com/problems/valid-word-square) | | | +| 429 | 🔒 [N-ary Tree Level Order Traversal](https://leetcode.com/problems/n-ary-tree-level-order-traversal) | [![Java](assets/java.png)](src/NAryTreeLevelOrderTraversal.java) | | | 430 | [Flatten a Multilevel Doubly Linked List](https://leetcode.com/problems/flatten-a-multilevel-doubly-linked-list) | [![Java](assets/java.png)](src/FlattenAMultiLevelDoublyLinkedList.java) | | | 434 | [Number of Segments in a String](https://leetcode.com/problems/number-of-segments-in-a-string) | [![Java](assets/java.png)](src/NumberOfSegmentsInString.java) [![Python](assets/python.png)](python/number_of_segments_in_a_string.py) | | | 441 | [Arranging Coins](https://leetcode.com/problems/arranging-coins) | [![Java](assets/java.png)](src/ArrangingCoins.java) [![Python](assets/python.png)](python/arranging_coins.py) | | diff --git a/src/NAryTreeLevelOrderTraversal.java b/src/NAryTreeLevelOrderTraversal.java new file mode 100644 index 0000000..5627945 --- /dev/null +++ b/src/NAryTreeLevelOrderTraversal.java @@ -0,0 +1,56 @@ +// https://leetcode.com/problems/n-ary-tree-level-order-traversal +// T: O(N) +// S: O(N) + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; + +public class NAryTreeLevelOrderTraversal { + public static class Node { + public int val; + public List children; + + public Node() {} + + public Node(int _val) { + val = _val; + } + + public Node(int _val, List _children) { + val = _val; + children = _children; + } + } + + public List> levelOrder(Node root) { + if (root == null) { + return new ArrayList<>(); + } + + final List> result = new ArrayList<>(); + final Queue queue = new LinkedList<>(); + List current = new ArrayList<>(); + + queue.add(root); + queue.add(null); + + while (!queue.isEmpty()) { + final Node node = queue.poll(); + if (node == null) { + result.add(current); + current = new ArrayList<>(); + if (!queue.isEmpty()) { + queue.add(null); + } + continue; + } + + current.add(node.val); + queue.addAll(node.children); + } + + return result; + } +} diff --git a/src/PathsInMatrixWhoseSumIsDivisibleByK.java b/src/PathsInMatrixWhoseSumIsDivisibleByK.java new file mode 100644 index 0000000..a053638 --- /dev/null +++ b/src/PathsInMatrixWhoseSumIsDivisibleByK.java @@ -0,0 +1,39 @@ +// https://leetcode.com/problems/paths-in-matrix-whose-sum-is-divisible-by-k +// T: O() +// S: O() + +import java.util.LinkedList; +import java.util.Queue; + +public class PathsInMatrixWhoseSumIsDivisibleByK { + private static final int MODULO = (int) (10e9 + 7); + + public int numberOfPaths(int[][] grid, int k) { + final int rows = grid.length, columns = grid[0].length; + // row, column, currentSum + final Queue queue = new LinkedList<>(); + queue.add(new int[] {0, 0, grid[0][0]}); + + int paths = 0; + + while (!queue.isEmpty()) { + final int[] position = queue.poll(); + final int row = position[0], column = position[1], currentSum = position[2]; + if (row == rows - 1 && column == columns - 1) { + if (currentSum % k == 0) { + paths = (paths + 1) % MODULO; + } + continue; + } + + if (column + 1 < columns) { + queue.add(new int[] { row, column + 1, currentSum + grid[row][column + 1]}); + } + if (row + 1 < rows) { + queue.add(new int[] { row + 1, column, currentSum + grid[row + 1][column]}); + } + } + + return paths; + } +} From 1bb0219f57f24cded8c5c717c325a54a6456033b Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sun, 28 Jul 2024 20:14:56 +0200 Subject: [PATCH 249/280] solves #1584: Min Cost to Connect All Points in java --- README.md | 1 + src/HelloWorld.java | 92 +++++++++++++++++------------- src/MinCostToConnectAllPoints.java | 82 ++++++++++++++++++++++++++ 3 files changed, 135 insertions(+), 40 deletions(-) create mode 100644 src/MinCostToConnectAllPoints.java diff --git a/README.md b/README.md index 2f31370..8db0825 100644 --- a/README.md +++ b/README.md @@ -619,6 +619,7 @@ | 1572 | [Matrix Diagonal Sum](https://leetcode.com/problems/matrix-diagonal-sum) | [![Java](assets/java.png)](src/MatrixDiagonalSum.java) | | | 1576 | [Replace All ?'s to Avoid Consecutive Repeating Characters](https://leetcode.com/problems/replace-all-s-to-avoid-consecutive-repeating-characters) | [![Java](assets/java.png)](src/ReplaceAllToAvoidConsecutiveRepeatingCharacters.java) | | | 1582 | [Special Positions in a Binary Matrix](https://leetcode.com/problems/special-positions-in-a-binary-matrix) | [![Java](assets/java.png)](src/SpecialPositionInABinaryMatrix.java) | | +| 1584 | [Min Cost to Connect All Points](https://leetcode.com/problems/min-cost-to-connect-all-points) | [![Java](assets/java.png)](src/MinCostToConnectAllPoints.java) | | | 1588 | [Sum of All Odd Length Subarrays](https://leetcode.com/problems/sum-of-all-odd-length-subarrays) | [![Java](assets/java.png)](src/SumOfAllOddLengthSubArrays.java) | | | 1592 | [Rearrange Spaces Between Words](https://leetcode.com/problems/rearrange-spaces-between-words) | [![Java](assets/java.png)](src/RearrangeSpacesBetweenWords.java) | | | 1598 | [Crawler Log Folder](https://leetcode.com/problems/crawler-log-folder) | [![Java](assets/java.png)](src/CrawlerLogFolder.java) | | diff --git a/src/HelloWorld.java b/src/HelloWorld.java index 84244db..18a8621 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -2,65 +2,77 @@ // S: O(N) import java.security.cert.Certificate; +import java.util.ArrayList; import java.util.LinkedList; +import java.util.List; import java.util.Queue; public class HelloWorld { - public static class Node { - public int val; - public Node left; - public Node right; - public Node next; + private static final List> DIRECTIONS = List.of( + List.of(1, 0), + List.of(0, 1), + List.of(-1, 0), + List.of(0, -1) + ); - public Node() {} + public int orangesRotting(int[][] grid) { + final Queue queue = new LinkedList<>(); + addRottenOrangesToQueue(queue, grid); + int maxTime = 0; - public Node(int _val) { - val = _val; - } + while (!queue.isEmpty()) { + final int[] info = queue.poll(); + final int row = info[0], column = info[1], time = info[2]; - public Node(int _val, Node _left, Node _right, Node _next) { - val = _val; - left = _left; - right = _right; - next = _next; - } - }; + if (grid[row][column] == 0) { + continue; + } - public Node connect(Node root) { - if (root == null) { - return null; + maxTime = Math.max(time, maxTime); + grid[row][column] = 0; + + for (int[] neighbour : getNeighbours(grid, row, column)) { + queue.add(new int[] { neighbour[0], neighbour[1], time + 1}); + } } - final Queue queue = new LinkedList<>(); - queue.add(root); - queue.add(null); - Node current = null; + if (containsFreshOranges(grid)) { + return -1; + } + return maxTime; + } - while (!queue.isEmpty()) { - final Node node = queue.poll(); - if (node == null) { - if (!queue.isEmpty()) { - queue.add(null); - current = null; + private static boolean containsFreshOranges(int[][] grid) { + for (int[] row : grid) { + for (int orange : row) { + if (orange == 1) { + return true; } - continue; } + } + return false; + } - addChildrenToQueue(queue, node); - - if (current != null) { - current.next = node; + private static void addRottenOrangesToQueue(Queue queue, int[][] grid) { + for(int row = 0 ; row < grid.length ; row++) { + for (int column = 0 ; column < grid[0].length ; column++) { + if (grid[row][column] == 2) { + queue.add(new int[] { row, column, 0 }); + } } - current = node; } - - return root; } - private static void addChildrenToQueue(Queue queue, Node node) { - if (node.left != null) queue.add(node.left); - if (node.right != null) queue.add(node.right); + private static List getNeighbours(int[][] grid, int row, int column) { + final List result = new ArrayList<>(); + for (List direction : DIRECTIONS) { + final int r = row + direction.get(0), c = column + direction.get(1); + if (r >= 0 && r < grid.length && c >= 0 && c < grid[0].length && grid[r][c] == 1) { + result.add(new int[] {r, c}); + } + } + return result; } } \ No newline at end of file diff --git a/src/MinCostToConnectAllPoints.java b/src/MinCostToConnectAllPoints.java new file mode 100644 index 0000000..443bb1b --- /dev/null +++ b/src/MinCostToConnectAllPoints.java @@ -0,0 +1,82 @@ +// https://leetcode.com/problems/min-cost-to-connect-all-points +// P = |points|, E = P^2 +// T: O(E logE + E al(P)) al = inverse Ackerman function +// S: O(P + E) = S(E) + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; + +public class MinCostToConnectAllPoints { + private static class DisjointSet { + private final int[] roots, rank; + + DisjointSet(int size) { + roots = new int[size]; + rank = new int[size]; + for (int i = 0 ; i < size ; i++) { + roots[i] = i; + rank[i] = i; + } + } + + public int find(int num) { + if (num == roots[num]) { + return num; + } + return roots[num] = find(roots[num]); + } + + public boolean areConnected(int x, int y) { + return find(x) == find(y); + } + + public void union(int x, int y) { + final int rootX = find(x), rootY = find(y); + if (rootX == rootY) { + return; + } + if (rank[rootX] > rank[rootY]) { + roots[rootY] = rootX; + } else if (rank[rootX] < rank[rootY]) { + roots[rootX] = rootY; + } else { + roots[rootY] = rootX; + rank[rootX]++; + } + } + } + + // Kruskal's algorithm + public int minCostConnectPoints(int[][] points) { + final List edges = createEdges(points); + final DisjointSet disjointSet = new DisjointSet(points.length); + edges.sort(Comparator.comparingInt(a -> a[2])); + + int minCost = 0; + + for (int[] edge : edges) { + final int from = edge[0], to = edge[1], weight = edge[2]; + if (!disjointSet.areConnected(from, to)) { + disjointSet.union(from, to); + minCost += weight; + } + } + + return minCost; + } + + private static List createEdges(int[][] points) { + final List edges = new ArrayList<>(); + for (int i = 0 ; i < points.length ; i++) { + for (int j = i + 1 ; j < points.length ; j++) { + edges.add(new int[] { i, j, manhattanDistance(points[i], points[j]) }); + } + } + return edges; + } + + private static int manhattanDistance(int[] p1, int[] p2) { + return Math.abs(p1[0] - p2[0]) + Math.abs(p1[1] - p2[1]); + } +} From 6a9916f33286050031beb44e2cc87386f8c2d9a3 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 29 Jul 2024 19:05:26 +0200 Subject: [PATCH 250/280] solves #1514: Path with Maximum Probability in java --- README.md | 1 + src/HelloWorld.java | 96 +++++++++++++---------------- src/PathWithMaximumProbability.java | 66 ++++++++++++++++++++ 3 files changed, 109 insertions(+), 54 deletions(-) create mode 100644 src/PathWithMaximumProbability.java diff --git a/README.md b/README.md index 8db0825..801d85f 100644 --- a/README.md +++ b/README.md @@ -606,6 +606,7 @@ | 1502 | [Can Make Arithmetic Progression From Sequence](https://leetcode.com/problems/can-make-arithmetic-progression-from-sequence) | [![Java](assets/java.png)](src/CanMakeArithmeticProgressionFromSequence.java) | | | 1507 | [Reformat Date](https://leetcode.com/problems/reformat-date) | [![Java](assets/java.png)](src/ReformatDate.java) | | | 1512 | [Number of Good Pairs](https://leetcode.com/problems/number-of-good-pairs) | [![Java](assets/java.png)](src/NumberOfGoodPairs.java) | | +| 1514 | [Path with Maximum Probability](https://leetcode.com/problems/path-with-maximum-probability) | [![Java](assets/java.png)](src/PathWithMaximumProbability.java) | | | 1518 | [Water Bottles](https://leetcode.com/problems/water-bottles) | [![Java](assets/java.png)](src/WaterBottles.java) | | | 1523 | [Count Odd Numbers In Interval Range](https://leetcode.com/problems/count-odd-numbers-in-an-interval-range) | [![Java](assets/java.png)](src/CountOddNumbersInIntervalRange.java) | | | 1528 | [Shuffle Strings](https://leetcode.com/problems/shuffle-string) | [![Java](assets/java.png)](src/ShuffleString.java) | | diff --git a/src/HelloWorld.java b/src/HelloWorld.java index 18a8621..6493515 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -1,78 +1,66 @@ -// T: O(N + E alp(N)) -// S: O(N) +// T: O(V + EllogV) +// S: O(E + V) -import java.security.cert.Certificate; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.PriorityQueue; import java.util.Queue; - +import java.util.Set; public class HelloWorld { - private static final List> DIRECTIONS = List.of( - List.of(1, 0), - List.of(0, 1), - List.of(-1, 0), - List.of(0, -1) - ); + private static final record Pair(int vertex, int distance) {} + + public int networkDelayTime(int[][] times, int n, int k) { + final Map> graph = createGraph(times); + final Map distances = new HashMap<>(); + final Queue minHeap = new PriorityQueue<>(Comparator.comparingInt(a -> a.distance)); - public int orangesRotting(int[][] grid) { - final Queue queue = new LinkedList<>(); - addRottenOrangesToQueue(queue, grid); - int maxTime = 0; + minHeap.add(new Pair(k, 0)); - while (!queue.isEmpty()) { - final int[] info = queue.poll(); - final int row = info[0], column = info[1], time = info[2]; + while (!minHeap.isEmpty()) { + final Pair pair = minHeap.poll(); + final int vertex = pair.vertex, distanceToVertex = pair.distance; + final int currentVertexTime = distances.getOrDefault(vertex, Integer.MAX_VALUE); - if (grid[row][column] == 0) { + if (currentVertexTime < distanceToVertex) { continue; } - maxTime = Math.max(time, maxTime); - grid[row][column] = 0; - - for (int[] neighbour : getNeighbours(grid, row, column)) { - queue.add(new int[] { neighbour[0], neighbour[1], time + 1}); - } - } + distances.put(vertex, distanceToVertex); - if (containsFreshOranges(grid)) { - return -1; - } - return maxTime; - } + for (Map.Entry entry : graph.getOrDefault(pair.vertex, new HashMap<>()).entrySet()) { + final int neighbour = entry.getKey(), distance = entry.getValue(); + final int currentMinDistance = distances.getOrDefault(neighbour, Integer.MAX_VALUE); + final int minDistance = Math.min(currentMinDistance, distances.get(pair.vertex) + distance); - private static boolean containsFreshOranges(int[][] grid) { - for (int[] row : grid) { - for (int orange : row) { - if (orange == 1) { - return true; + if (minDistance < currentMinDistance) { + distances.put(neighbour, minDistance); + minHeap.add(new Pair(neighbour, minDistance)); } } } - return false; + + return minTimeRequired(distances, n); } - private static void addRottenOrangesToQueue(Queue queue, int[][] grid) { - for(int row = 0 ; row < grid.length ; row++) { - for (int column = 0 ; column < grid[0].length ; column++) { - if (grid[row][column] == 2) { - queue.add(new int[] { row, column, 0 }); - } - } + private static Map> createGraph(int[][] edges) { + final Map> result = new HashMap<>(); + for (int[] edge : edges) { + final int from = edge[0], to = edge[1], weight = edge[2]; + final Map weights = result.getOrDefault(from, new HashMap<>()); + weights.put(to, weight); + result.putIfAbsent(from, weights); } + return result; } - private static List getNeighbours(int[][] grid, int row, int column) { - final List result = new ArrayList<>(); - for (List direction : DIRECTIONS) { - final int r = row + direction.get(0), c = column + direction.get(1); - if (r >= 0 && r < grid.length && c >= 0 && c < grid[0].length && grid[r][c] == 1) { - result.add(new int[] {r, c}); - } + private static int minTimeRequired(Map distances, int n) { + if (distances.size() != n) { + return -1; } - return result; + return distances.values().stream().max(Integer::compareTo).get(); } } \ No newline at end of file diff --git a/src/PathWithMaximumProbability.java b/src/PathWithMaximumProbability.java new file mode 100644 index 0000000..df05fd4 --- /dev/null +++ b/src/PathWithMaximumProbability.java @@ -0,0 +1,66 @@ +// https://leetcode.com/problems/path-with-maximum-probability +// T: O(E + N + E logN) +// S: O(E + N) + +import java.util.Comparator; +import java.util.HashMap; +import java.util.Map; +import java.util.PriorityQueue; +import java.util.Queue; + +public class PathWithMaximumProbability { + private record Pair(int vertex, double probability) {} + + public static double maxProbability(int n, int[][] edges, double[] probabilities, int start, int end) { + final Map> graph = createGraph(edges, probabilities); + final Map distances = dijkstra(graph, start, end); + return distances.getOrDefault(end, 0.0); + } + + private static Map> createGraph(int[][] edges, double[] probabilities) { + final Map> graph = new HashMap<>(); + int k = 0; + for (int[] edge : edges) { + final int from = edge[0], to = edge[1]; + final double weight = probabilities[k++]; + final Map fromNeighbours = graph.getOrDefault(from, new HashMap<>()); + final Map toNeighbours = graph.getOrDefault(to, new HashMap<>()); + fromNeighbours.put(to, weight); + toNeighbours.put(from, weight); + graph.putIfAbsent(from, fromNeighbours); + graph.putIfAbsent(to, toNeighbours); + } + return graph; + } + + private static Map dijkstra(Map> graph, int start, int end) { + final Map distances = new HashMap<>(); + final Queue minHeap = new PriorityQueue<>(Comparator.comparingDouble(a -> a.probability)); + minHeap.add(new Pair(start, 1)); + distances.put(start, 1.0); + + while (!minHeap.isEmpty()) { + final Pair pair = minHeap.poll(); + + if (pair.vertex == end) { + break; + } + + for (Map.Entry neighbour : graph.getOrDefault(pair.vertex, new HashMap<>()).entrySet()) { + final int edgeVertex = neighbour.getKey(); + final double edgeWeight = neighbour.getValue(); + final double currentProbability = distances.getOrDefault(edgeVertex, 0.0); + final double edgeProbability = Math.max( + currentProbability, + pair.probability * edgeWeight + ); + if (edgeProbability > currentProbability) { + distances.put(edgeVertex, edgeProbability); + minHeap.add(new Pair(edgeVertex, edgeProbability)); + } + } + } + + return distances; + } +} From afaac2508cf00871d997da7c012ff88d174b2c78 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 29 Jul 2024 20:15:05 +0200 Subject: [PATCH 251/280] solves maze --- README.md | 1 + src/TheMazeII.java | 78 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 src/TheMazeII.java diff --git a/README.md b/README.md index 801d85f..346d139 100644 --- a/README.md +++ b/README.md @@ -337,6 +337,7 @@ | 500 | [Keyboard Row](https://leetcode.com/problems/keyboard-row) | [![Java](assets/java.png)](src/KeyBoardRow.java) [![Python](assets/python.png)](python/keyboard_row.py) | | | 501 | [Find Mode in Binary Search Tree](https://leetcode.com/problems/find-mode-in-binary-search-tree) | [![Java](assets/java.png)](src/FindModeInBinarySearchTree.java) [![Python](assets/python.png)](python/find_mode_in_binary_search_tree.py) | | | 504 | [Base 7](https://leetcode.com/problems/base-7) | [![Java](assets/java.png)](src/Base7.java) [![Python](assets/python.png)](python/base_7.py) | | +| 505 | [The Maze II](https://leetcode.com/problems/the-maze-ii) | [![Java](assets/java.png)](src/TheMazeII.java) | | | 506 | [Relative Ranks](https://leetcode.com/problems/relative-ranks) | [![Java](assets/java.png)](src/RelativeRanks.java) [![Python](assets/python.png)](python/relative_ranks.py) | | | 507 | [Perfect Number](https://leetcode.com/problems/perfect-number) | [![Java](assets/java.png)](src/CheckPerfectNumber.java) [![Python](assets/python.png)](python/check_perfect_number.py) | | | 509 | [Fibonacci Number](https://leetcode.com/problems/fibonacci-number) | [![Java](assets/java.png)](src/FibonacciNumber.java) [![Python](assets/python.png)](python/fibonacci_number.py) | | diff --git a/src/TheMazeII.java b/src/TheMazeII.java new file mode 100644 index 0000000..c42110f --- /dev/null +++ b/src/TheMazeII.java @@ -0,0 +1,78 @@ +// https://leetcode.com/problems/the-maze-ii +// T: O(m * n * log(m * n)) +// S: O(m * n) + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.PriorityQueue; +import java.util.Queue; + +public class TheMazeII { + private static final int[][] DIRECTIONS = new int[][] {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; + + public int shortestDistance(int[][] maze, int[] start, int[] destination) { + final int rows = maze.length, columns = maze[0].length; + final int[][] distance = dijkstra(maze, start); + return distance[destination[0]][destination[1]] == Integer.MAX_VALUE ? -1 : distance[destination[0]][destination[1]]; + } + + // T: O(m * n * log(mn)) + // S: O(m * n) + public int[][] dijkstra(int[][] maze, int[] start) { + final int[][] distance = getDistances(maze.length, maze[0].length); + final Queue queue = new PriorityQueue<>(Comparator.comparingInt(a -> a[2])); + + queue.add(new int[] { start[0], start[1], 0 }); + + while (!queue.isEmpty()) { + final int[] s = queue.poll(); + final int row = s[0], column = s[1], d = s[2]; + + if (distance[row][column] <= d) { + continue; + } + + distance[row][column] = d; + + for (int[] position: validPositions(maze, s[0], s[1])) { + final int newDistance = distance[row][column] + manhattanDistance(s[0], s[1], position); + queue.add(new int[] { position[0], position[1], newDistance}); + } + } + + return distance; + } + + // T: O(m + n) + // S: O(1) + private static List validPositions(int[][] grid, int row, int column) { + final List result = new ArrayList<>(); + for (int[] direction : DIRECTIONS) { + int i = row, j = column; + while (i >= 0 && j >= 0 && i < grid.length && j < grid[0].length && grid[i][j] == 0) { + i += direction[0]; + j += direction[1]; + } + result.add(new int[] { i - direction[0], j - direction[1] }); + } + return result; + } + + // T: O(m * n) + // S: O(m * n) + private static int[][] getDistances(int rows, int columns) { + final int[][] result = new int[rows][columns]; + for (int i = 0 ; i < rows ; i++) { + for (int j = 0 ; j < columns ; j++) { + result[i][j] = Integer.MAX_VALUE; + } + } + return result; + } + + // T: O(1), S: O(1) + private static int manhattanDistance(int row, int column, int[] position) { + return Math.abs(row - position[0]) + Math.abs(column - position[1]); + } +} From d97db067dff7e8d5ece7ab2a0f45653b2c7498f5 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 29 Jul 2024 20:56:26 +0200 Subject: [PATCH 252/280] solves #499: The maze III in java --- README.md | 1 + src/TheMazeIII.java | 98 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 src/TheMazeIII.java diff --git a/README.md b/README.md index 346d139..2ee36b4 100644 --- a/README.md +++ b/README.md @@ -334,6 +334,7 @@ | 492 | [Construct the Rectangle](https://leetcode.com/problems/construct-the-rectangle) | [![Java](assets/java.png)](src/ConstructTheRectangle.java) [![Python](assets/python.png)](python/construct_the_rectangle.py) | | | 495 | [Teemo Attacking](https://leetcode.com/problems/teemo-attacking/) | [![Java](assets/java.png)](src/TeemoAttacking.java) [![Python](assets/python.png)](python/teemo_attacking.py) | | | 496 | [Next Greater Element I](https://leetcode.com/problems/next-greater-element-i) | [![Java](assets/java.png)](src/NextGreaterElementI.java) [![Python](assets/python.png)](python/next_greater_element_i.py) | | +| 499 | [The Maze III](https://leetcode.com/problems/the-maze-iii) | [![Java](assets/java.png)](src/TheMazeIII.java) | | | 500 | [Keyboard Row](https://leetcode.com/problems/keyboard-row) | [![Java](assets/java.png)](src/KeyBoardRow.java) [![Python](assets/python.png)](python/keyboard_row.py) | | | 501 | [Find Mode in Binary Search Tree](https://leetcode.com/problems/find-mode-in-binary-search-tree) | [![Java](assets/java.png)](src/FindModeInBinarySearchTree.java) [![Python](assets/python.png)](python/find_mode_in_binary_search_tree.py) | | | 504 | [Base 7](https://leetcode.com/problems/base-7) | [![Java](assets/java.png)](src/Base7.java) [![Python](assets/python.png)](python/base_7.py) | | diff --git a/src/TheMazeIII.java b/src/TheMazeIII.java new file mode 100644 index 0000000..edc13fc --- /dev/null +++ b/src/TheMazeIII.java @@ -0,0 +1,98 @@ +// https://leetcode.com/problems/the-maze-iii +// T: O(m * n log(m * n)) +// S: O(m * n) + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.PriorityQueue; +import java.util.Queue; + +public class TheMazeIII { + private record Info(int[] position, int distance, String path) {} + + private record Position(int[] position, String direction) {} + + private static final Position[] DIRECTIONS = new Position[] { + new Position(new int[] { 1, 0 }, "d"), + new Position(new int[] { 0, -1 }, "l"), + new Position(new int[] { 0, 1 }, "r"), + new Position(new int[] { -1, 0 }, "u") + }; + + // T: O(m * n * log(m * n)), S: O(m * n) + public String findShortestWay(int[][] maze, int[] ball, int[] hole) { + final int[][] distances = getDistances(maze.length, maze[0].length); + final Queue queue = new PriorityQueue<>((a, b) -> { + if (a.distance == b.distance) { + return a.path.compareTo(b.path); + } + return Integer.compare(a.distance, b.distance); + }); + queue.add(new Info(ball, 0, "")); + String path = null; + + while (!queue.isEmpty()) { + final Info info = queue.poll(); + + if (distances[info.position[0]][info.position[1]] <= info.distance) { + continue; + } + + distances[info.position[0]][info.position[1]] = info.distance; + + if (info.position[0] == hole[0] && info.position[1] == hole[1]) { + if (path == null) { + path = info.path; + } else { + path = path.compareTo(info.path) > 0 ? info.path : path; + } + } + + for (Position position : validPositions(maze, info.position, hole)) { + queue.add(new Info( + position.position, + info.distance + manhattanDistance(position.position, info.position), + info.path + position.direction + )); + } + } + + final int minDistance = distances[hole[0]][hole[1]]; + return minDistance == Integer.MAX_VALUE ? "impossible" : path; + } + + // T: O(1), S:O(1) + private static int manhattanDistance(int[] p1, int[] p2) { + return Math.abs(p1[0] - p2[0]) + Math.abs(p1[1] - p2[1]); + } + + // T: O(m + n), S: O(1) + private static List validPositions(int[][] grid, int[] position, int[] target) { + final List result = new ArrayList<>(); + for (Position p : DIRECTIONS) { + int row = position[0], column = position[1]; + while (row >= 0 && row < grid.length + && column >= 0 && column < grid[0].length && grid[row][column] == 0 && + (row != target[0] || column != target[1])) { + row += p.position[0]; + column += p.position[1]; + } + if (row == target[0] && column == target[1]) { + result.add(new Position(new int[] { row, column}, p.direction)); + } else { + result.add(new Position(new int[]{row - p.position[0], column - p.position[1]}, p.direction)); + } + } + return result; + } + + // T: O(m * n), S: O(m * n) + private static int[][] getDistances(int rows, int columns) { + final int[][] distances = new int[rows][columns]; + for (int[] row : distances) { + Arrays.fill(row, Integer.MAX_VALUE); + } + return distances; + } +} From 040badf3a29834299555aff0bd1ae8e1d180d6ac Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 29 Jul 2024 21:17:52 +0200 Subject: [PATCH 253/280] solves #1631: Path With Minimum Effort in java --- README.md | 1 + src/PathWithMinimumEffort.java | 65 ++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 src/PathWithMinimumEffort.java diff --git a/README.md b/README.md index 2ee36b4..73fd2c0 100644 --- a/README.md +++ b/README.md @@ -633,6 +633,7 @@ | 1619 | [Mean of Array After Removing Some Elements](https://leetcode.com/problems/mean-of-array-after-removing-some-elements) | [![Java](assets/java.png)](src/MeanOfArrayAfterRemovingSomeElements.java) | | | 1624 | [Largest Substring Between Two Equal Characters](https://leetcode.com/problems/largest-substring-between-two-equal-characters) | [![Java](assets/java.png)](src/LargestSubStringBetweenTwoEqualCharacters.java) | | | 1629 | [Slowest Key](https://leetcode.com/problems/slowest-key) | [![Java](assets/java.png)](src/SlowestKey.java) | | +| 1631 | [Path With Minimum Effort](https://leetcode.com/problems/path-with-minimum-effort) | [![Java](assets/java.png)](src/PathWithMinimumEffort.java) | | | 1636 | [Sort Array by Increasing Frequency](https://leetcode.com/problems/sort-array-by-increasing-frequency) | [![Java](assets/java.png)](src/SortArrayByIncreasingFrequency.java) | | | 1637 | [Widest Vertical Area Between Two Points Containing No Points](https://leetcode.com/problems/widest-vertical-area-between-two-points-containing-no-points) | [![Java](assets/java.png)](src/WidestVerticalAreaBetweenTwoPointsContainingNoPoints.java) | | | 1640 | [Check Array Formation Through Concatenation](https://leetcode.com/problems/check-array-formation-through-concatenation) | [![Java](assets/java.png)](src/CheckArrayFormationThroughConcatenation.java) | | diff --git a/src/PathWithMinimumEffort.java b/src/PathWithMinimumEffort.java new file mode 100644 index 0000000..58c27e5 --- /dev/null +++ b/src/PathWithMinimumEffort.java @@ -0,0 +1,65 @@ +// https://leetcode.com/problems/path-with-minimum-effort +// T: O(m * n * log(m * n)) +// S: O(m * n) + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; +import java.util.PriorityQueue; +import java.util.Queue; + +public class PathWithMinimumEffort { + private record Position(int x, int y) {} + + private record Info(Position position, int effort) {} + + private static final int[][] Directions = new int[][] {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; + + // T: O(m * n * log(m * n)) S: O(m * n) + public int minimumEffortPath(int[][] heights) { + final int[][] minEffort = initialiseMinEfforts(heights.length, heights[0].length); + final Queue queue = new PriorityQueue<>(Comparator.comparingInt(a -> a.effort)); + queue.add(new Info(new Position(0, 0), 0)); + + while (!queue.isEmpty()) { + final Info info = queue.poll(); + if (info.effort >= minEffort[info.position.x][info.position.y]) { + continue; + } + minEffort[info.position.x][info.position.y] = info.effort; + + for (Position position : validPositions(heights, info.position)) { + queue.add(new Info(position, Math.max(info.effort, absDiff(info.position, position, heights)))); + } + } + + return minEffort[heights.length - 1][heights[0].length - 1]; + } + + // T: O(m * n), S: O(m * n) + private static int[][] initialiseMinEfforts(int rows, int columns) { + final int[][] result = new int[rows][columns]; + for (int[] row : result) { + Arrays.fill(row, Integer.MAX_VALUE); + } + return result; + } + + // T: O(1), S: O(1) + private static int absDiff(Position p1, Position p2, int[][] heights) { + return Math.abs(heights[p1.x][p1.y] - heights[p2.x][p2.y]); + } + + // T: O(1), S: O(1) + private static List validPositions(int[][] heights, Position position) { + final List result = new ArrayList<>(); + for (int[] direction : Directions) { + final int row = position.x + direction[0], column = position.y + direction[1]; + if (row >= 0 && row < heights.length && column >= 0 && column < heights[0].length) { + result.add(new Position(row, column)); + } + } + return result; + } +} From 8e4a60cb739bef8b8d0827d8c718b2019dfbde86 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 30 Jul 2024 11:37:40 +0200 Subject: [PATCH 254/280] solves #787: cheapest flights within k stops --- README.md | 1 + src/CheapestFlightsWithinKStops.java | 44 +++++++++++++++ src/HelloWorld.java | 84 +++++++++++++--------------- 3 files changed, 83 insertions(+), 46 deletions(-) create mode 100644 src/CheapestFlightsWithinKStops.java diff --git a/README.md b/README.md index 73fd2c0..59a5d5e 100644 --- a/README.md +++ b/README.md @@ -416,6 +416,7 @@ | 766 | [Toeplitz Matrix](https://leetcode.com/problems/toeplitz-matrix) | [![Java](assets/java.png)](src/ToeplitzMatrix.java) [![Python](assets/python.png)](python/toeplitz_matrix.py) | | | 771 | [Jewels and Stones](https://leetcode.com/problems/jewels-and-stones) | [![Java](assets/java.png)](src/JewelsAndStones.java) [![Python](assets/python.png)](python/jewels_and_stones.py) | | | 783 | [Minimum Distance Between BST Nodes](https://leetcode.com/problems/minimum-distance-between-bst-nodes) | [![Java](assets/java.png)](src/MinimumAbsoluteDifferenceInBST.java) [![Python](assets/python.png)](python/minimum_distance_between_bst_nodes.py) | | +| 787 | [Cheapest Flights Within K Stops](https://leetcode.com/problems/cheapest-flights-within-k-stops) | [![Java](assets/java.png)](src/CheapestFlightsWithinKStops.java) | | | 788 | [Rotated Digits](https://leetcode.com/problems/rotated-digits) | | | | 796 | [Rotate String](https://leetcode.com/problems/rotate-string) | [![Java](assets/java.png)](src/RotateString.java) | | | 797 | [All Paths From Source to Target](https://leetcode.com/problems/all-paths-from-source-to-target) | [![Java](assets/java.png)](src/AllPathsFromSourceToTarget.java) | | diff --git a/src/CheapestFlightsWithinKStops.java b/src/CheapestFlightsWithinKStops.java new file mode 100644 index 0000000..82d5931 --- /dev/null +++ b/src/CheapestFlightsWithinKStops.java @@ -0,0 +1,44 @@ +// https://leetcode.com/problems/cheapest-flights-within-k-stops +// T: O((N + E) * K) +// S: O(N) + +import java.util.Arrays; + +public class CheapestFlightsWithinKStops { + + public static int findCheapestPrice(int n, int[][] flights, int src, int dst, int k) { + final int[] distances = bellmanFord(flights, n, k, src); + return distances[dst] == Integer.MAX_VALUE ? -1 : distances[dst]; + } + + // T: O(N * K + E * K) = T: O((N + E) * K) S: O(N) + private static int[] bellmanFord(int[][] edges, int n, int k, int source) { + int[] distances = initializeDistances(n); + distances[source] = 0; + for (int i = 0 ; i < k + 1 ; i++) { + final int[] temp = cloneArray(distances); + for (int[] edge : edges) { + final int from = edge[0], to = edge[1], weight = edge[2]; + if (distances[from] != Integer.MAX_VALUE) { + temp[to] = Math.min(temp[to], distances[from] + weight); + } + } + distances = temp; + } + return distances; + } + + // T: O(N), S: O(N) + private static int[] initializeDistances(int n) { + final int[] distances = new int[n]; + Arrays.fill(distances, Integer.MAX_VALUE); + return distances; + } + + // T: O(N), S: O(N) + private static int[] cloneArray(int[] array) { + final int[] result = new int[array.length]; + System.arraycopy(array, 0, result, 0, array.length); + return result; + } +} diff --git a/src/HelloWorld.java b/src/HelloWorld.java index 6493515..f0888bb 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -1,66 +1,58 @@ -// T: O(V + EllogV) -// S: O(E + V) - -import java.util.Comparator; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.PriorityQueue; -import java.util.Queue; -import java.util.Set; - +import java.util.*; public class HelloWorld { - private static final record Pair(int vertex, int distance) {} + private record Edge(int vertex, int time) {} public int networkDelayTime(int[][] times, int n, int k) { final Map> graph = createGraph(times); - final Map distances = new HashMap<>(); - final Queue minHeap = new PriorityQueue<>(Comparator.comparingInt(a -> a.distance)); + final Map delayTimes = dijkstra(graph, k); + if (delayTimes.size() != n) { + return -1; + } + return delayTimes.values().stream().max(Integer::compare).get(); + } - minHeap.add(new Pair(k, 0)); + // T: O(E), S: O(E) + private static Map> createGraph(int[][] edges) { + final Map> graph = new HashMap<>(); + for (int[] edge : edges) { + final int from = edge[0], to = edge[1], weight = edge[2]; + final Map neighbours = graph.getOrDefault(from, new HashMap<>()); + neighbours.put(to, weight); + graph.putIfAbsent(from, neighbours); + } + return graph; + } - while (!minHeap.isEmpty()) { - final Pair pair = minHeap.poll(); - final int vertex = pair.vertex, distanceToVertex = pair.distance; - final int currentVertexTime = distances.getOrDefault(vertex, Integer.MAX_VALUE); + // T: O(V + E logV) + private static Map dijkstra(Map> graph, int start) { + final Map distances = new HashMap<>(); + final Queue queue = new PriorityQueue<>(Comparator.comparingInt(a -> a.time)); + queue.add(new Edge(start, 0)); - if (currentVertexTime < distanceToVertex) { + while (!queue.isEmpty()) { + final Edge edge = queue.poll(); + if (edge.time >= distances.getOrDefault(edge.vertex, Integer.MAX_VALUE)) { continue; } - distances.put(vertex, distanceToVertex); - - for (Map.Entry entry : graph.getOrDefault(pair.vertex, new HashMap<>()).entrySet()) { - final int neighbour = entry.getKey(), distance = entry.getValue(); - final int currentMinDistance = distances.getOrDefault(neighbour, Integer.MAX_VALUE); - final int minDistance = Math.min(currentMinDistance, distances.get(pair.vertex) + distance); + distances.put(edge.vertex, edge.time); - if (minDistance < currentMinDistance) { - distances.put(neighbour, minDistance); - minHeap.add(new Pair(neighbour, minDistance)); - } + for (Map.Entry entry : graph.getOrDefault(edge.vertex, new HashMap<>()).entrySet()) { + final int neighbour = entry.getKey(), time = entry.getValue(); + queue.add(new Edge(neighbour, edge.time + time)); } } - return minTimeRequired(distances, n); + return distances; } - private static Map> createGraph(int[][] edges) { - final Map> result = new HashMap<>(); - for (int[] edge : edges) { - final int from = edge[0], to = edge[1], weight = edge[2]; - final Map weights = result.getOrDefault(from, new HashMap<>()); - weights.put(to, weight); - result.putIfAbsent(from, weights); - } - return result; - } + public static void main(String[] args) { + int[] b = new int[] {1, 2, 3}; + int[] a = b; + System.out.println(Arrays.toString(a)); + b = new int[] {5, 6, 7}; + System.out.println(Arrays.toString(a)); - private static int minTimeRequired(Map distances, int n) { - if (distances.size() != n) { - return -1; - } - return distances.values().stream().max(Integer::compareTo).get(); } } \ No newline at end of file From a4a68b5ec026010f4c21898dc6b8b33002aa8995 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 30 Jul 2024 12:04:35 +0200 Subject: [PATCH 255/280] solves #2093: Minimum Cost To Reach City With Discounts in java --- README.md | 1 + src/MinimumCostToReachCityWithDiscounts.java | 78 ++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 src/MinimumCostToReachCityWithDiscounts.java diff --git a/README.md b/README.md index 59a5d5e..49cd9f8 100644 --- a/README.md +++ b/README.md @@ -727,6 +727,7 @@ | 2078 | [Two Furthest Houses With Different Colors](https://leetcode.com/problems/two-furthest-houses-with-different-colors) | [![Java](assets/java.png)](src/TwoFurthestHousesWithDifferentColors.java) | | | 2085 | [Count Common Words With One Occurrence](https://leetcode.com/problems/count-common-words-with-one-occurrence) | [![Java](assets/java.png)](src/CountCommonWordsWithOneOccurrence.java) | | | 2089 | [Find Target Indices After Sorting Array](https://leetcode.com/problems/find-target-indices-after-sorting-array) | [![Java](assets/java.png)](src/FindTargetIndicesAfterSortingArray.java) | | +| 2093 | [Minimum Cost To Reach City With Discounts](https://leetcode.com/problems/minimum-cost-to-reach-city-with-discounts) | [![Java](assets/java.png)](src/MinimumCostToReachCityWithDiscounts.java) | | | 2094 | [Finding 3-Digit Even Numbers](https://leetcode.com/problems/finding-3-digit-even-numbers) | [![Java](assets/java.png)](src/Finding3DigitEvenNumbers.java) | | | 2099 | [Find Subsequence of Length K With the Largest Sum](https://leetcode.com/problems/find-subsequence-of-length-k-with-the-largest-sum) | [![Java](assets/java.png)](src/FindSubsequenceOfLengthKWithTheLargestSum.java) | | | 2103 | [Rings and Rods](https://leetcode.com/problems/rings-and-rods) | [![Java](assets/java.png)](src/RingsAndRods.java) | | diff --git a/src/MinimumCostToReachCityWithDiscounts.java b/src/MinimumCostToReachCityWithDiscounts.java new file mode 100644 index 0000000..d4aa0cb --- /dev/null +++ b/src/MinimumCostToReachCityWithDiscounts.java @@ -0,0 +1,78 @@ +// https://leetcode.com/problems/minimum-cost-to-reach-city-with-discounts +// T: O((N * K + E) log(N * K)) +// S: O(N * K + E) + +import java.util.Arrays; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Map; +import java.util.PriorityQueue; +import java.util.Queue; + +public class MinimumCostToReachCityWithDiscounts { + private record Info(int vertex, int cost, int discounts) {} + + public static int minimumCost(int n, int[][] highways, int discounts) { + final Map> graph = createGraph(highways); + final int[][] minCosts = dijkstra(n, graph, discounts); + return minCost(minCosts[n -1]); + } + + // N = n, K = |discounts|, E + // T: O(N * K + E log(N * K)) = O((N * K + E) log(N * K)) + // S: O(N * K + E) + private static int[][] dijkstra(int n, Map> graph, int discount) { + final int[][] dp = initializeDp(n, discount); + final Queue queue = new PriorityQueue<>(Comparator.comparingInt(a -> a.cost)); + queue.add(new Info(0, 0, discount)); + + while (!queue.isEmpty()) { + final Info info = queue.poll(); + if (dp[info.vertex][info.discounts] <= info.cost) { + continue; + } + + dp[info.vertex][info.discounts] = info.cost; + + for (Map.Entry entry : graph.getOrDefault(info.vertex, new HashMap<>()).entrySet()) { + final int vertex = entry.getKey(), cost = entry.getValue(); + queue.add(new Info(vertex, info.cost + cost, info.discounts)); + if (info.discounts > 0) { + queue.add(new Info(vertex, info.cost + cost / 2, info.discounts - 1)); + } + } + } + + return dp; + } + + private static int[][] initializeDp(int n, int discounts) { + final int[][] dp = new int[n][discounts + 1]; + for (int[] row : dp) { + Arrays.fill(row, Integer.MAX_VALUE); + } + return dp; + } + + private static int minCost(int[] array) { + final int result = Arrays.stream(array).min().getAsInt(); + if (result == Integer.MAX_VALUE) { + return -1; + } + return result; + } + + private static Map> createGraph(int[][] edges) { + final Map> graph = new HashMap<>(); + for (int[] edge : edges) { + final int from = edge[0], to = edge[1], cost = edge[2]; + final Map fromNeighbours = graph.getOrDefault(from, new HashMap<>()); + final Map toNeighbours = graph.getOrDefault(to, new HashMap<>()); + fromNeighbours.put(to, cost); + toNeighbours.put(from, cost); + graph.putIfAbsent(from, fromNeighbours); + graph.putIfAbsent(to, toNeighbours); + } + return graph; + } +} From 60a076ddce739fed3bcc9701496ff7711c61b898 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 30 Jul 2024 13:39:43 +0200 Subject: [PATCH 256/280] solves #310: Minimum Height Trees in java --- README.md | 2 +- src/AlienDictionary.java | 91 +++++++++++++++++++++++++++ src/HelloWorld.java | 106 +++++++++++++++++++------------- src/MaximumDepthOfNAryTree.java | 6 +- src/MinimumHeightTrees.java | 78 +++++++++++++++++++++++ 5 files changed, 239 insertions(+), 44 deletions(-) create mode 100644 src/AlienDictionary.java create mode 100644 src/MinimumHeightTrees.java diff --git a/README.md b/README.md index 49cd9f8..27d30a4 100644 --- a/README.md +++ b/README.md @@ -261,7 +261,7 @@ | 306 | [Additive Number](https://leetcode.com/problems/additive-number) | | | | 307 | [Range Sum Query - Mutable](https://leetcode.com/problems/range-sum-query-mutable) | | | | 309 | [Best Time to Buy and Sell Stock with Cooldown](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown) | | | -| 310 | [Minimum Height Trees](https://leetcode.com/problems/minimum-height-trees) | | | +| 310 | [Minimum Height Trees](https://leetcode.com/problems/minimum-height-trees) | [![Java](assets/java.png)](src/MinimumHeightTrees.java) | | | 311 | 🔒 [Sparse Matrix Multiplication](https://leetcode.com/problems/sparse-matrix-multiplication) | | | | 313 | [Super Ugly Number](https://leetcode.com/problems/super-ugly-number) | | | | 314 | 🔒 [Binary Tree Vertical Order Traversal](https://leetcode.com/problems/binary-tree-vertical-order-traversal) | | | diff --git a/src/AlienDictionary.java b/src/AlienDictionary.java new file mode 100644 index 0000000..ed80366 --- /dev/null +++ b/src/AlienDictionary.java @@ -0,0 +1,91 @@ +// https://leetcode.com/problems/alien-dictionary +// T: O() +// S: O() + +import java.util.*; + +public class AlienDictionary { + public String alienOrder(String[] words) { + final Map> graph = createGraphFrom(words); + return lexicographicallySmallest(graph); + } + + private static String lexicographicallySmallest(Map> graph) { + final Map inDegree = computeInDegree(graph); + final Queue queue = new LinkedList<>(); + final StringBuilder builder = new StringBuilder(); + add0InDegreeInQueue(queue, inDegree); + + while (!queue.isEmpty()) { + final char c = queue.poll(); + builder.append(c); + for (char neighbour : graph.getOrDefault(c, new HashSet<>())) { + inDegree.put(neighbour, inDegree.get(neighbour) - 1); + if (inDegree.get(neighbour) == 0) { + queue.add(neighbour); + } + } + graph.remove(c); + } + + if (graph.isEmpty()) { + return builder.toString(); + } + return ""; + } + + private static Map> createGraphFrom(String[] words) { + final Map> graph = new HashMap<>(); + addAllLettersInGraph(graph, words); + for (int i = 0 ; i < words.length ; i++) { + for (int j = i + 1 ; j < words.length ; j++) { + if (words[i].equals(words[j])) { + continue; + } + final char[] charDiff = firstDifferentCharacter(words[i], words[j]); + if (charDiff.length == 0) { + continue; + } + final Set set = graph.getOrDefault(charDiff[0], new HashSet<>()); + set.add(charDiff[1]); + graph.putIfAbsent(charDiff[0], set); + } + } + return graph; + } + + private static void addAllLettersInGraph(Map> graph, String[] words) { + for (String word : words) { + for (int i = 0 ; i < word.length() ; i++) { + graph.putIfAbsent(word.charAt(i), new HashSet<>()); + } + } + } + + private static char[] firstDifferentCharacter(String s1, String s2) { + for (int i = 0 ; i < s1.length() && i < s2.length() ; i++) { + if (s1.charAt(i) != s2.charAt(i)) { + return new char[] { s1.charAt(i), s2.charAt(i) }; + } + } + return new char[] {}; + } + + private static Map computeInDegree(Map> graph) { + final Map inDegree = new HashMap<>(); + for (Set set : graph.values()) { + for (char c : set) { + inDegree.put(c, inDegree.getOrDefault(c, 0) + 1); + } + } + return inDegree; + } + + private static void add0InDegreeInQueue(Queue queue, Map inDegree) { + for (Map.Entry entry : inDegree.entrySet()) { + if (entry.getValue() == 0) { + queue.add(entry.getKey()); + } + } + } +} diff --git a/src/HelloWorld.java b/src/HelloWorld.java index f0888bb..cd0a3f2 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -1,58 +1,80 @@ -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.PriorityQueue; +import java.util.Queue; +import java.util.Set; public class HelloWorld { - private record Edge(int vertex, int time) {} - - public int networkDelayTime(int[][] times, int n, int k) { - final Map> graph = createGraph(times); - final Map delayTimes = dijkstra(graph, k); - if (delayTimes.size() != n) { - return -1; - } - return delayTimes.values().stream().max(Integer::compare).get(); - } - - // T: O(E), S: O(E) - private static Map> createGraph(int[][] edges) { - final Map> graph = new HashMap<>(); - for (int[] edge : edges) { - final int from = edge[0], to = edge[1], weight = edge[2]; - final Map neighbours = graph.getOrDefault(from, new HashMap<>()); - neighbours.put(to, weight); - graph.putIfAbsent(from, neighbours); - } - return graph; + // T: O(V + E) S: O(V + E) + public int[] findOrder(int numCourses, int[][] prerequisites) { + final Map> graph = createGraph(prerequisites); + final int[] inDegree = computeInDegree(numCourses, prerequisites); + return orderOfCourses(graph, inDegree); } - // T: O(V + E logV) - private static Map dijkstra(Map> graph, int start) { - final Map distances = new HashMap<>(); - final Queue queue = new PriorityQueue<>(Comparator.comparingInt(a -> a.time)); - queue.add(new Edge(start, 0)); + // T: O(V + E) S: O(V) + private static int[] orderOfCourses(Map> graph, int[] inDegree) { + final Queue queue = new PriorityQueue<>(); + final List order = new ArrayList<>(); + addAll0InDegreeToQueue(queue, inDegree); while (!queue.isEmpty()) { - final Edge edge = queue.poll(); - if (edge.time >= distances.getOrDefault(edge.vertex, Integer.MAX_VALUE)) { - continue; + final int vertex = queue.poll(); + order.add(vertex); + for (int neighbour : graph.getOrDefault(vertex, new HashSet<>())) { + inDegree[neighbour]--; + if (inDegree[neighbour] == 0) { + queue.add(neighbour); + } } + graph.remove(vertex); + } + + if (order.size() != inDegree.length) { + return new int[] {}; + } + return toArray(order); + } - distances.put(edge.vertex, edge.time); + private static int[] toArray(List list) { + final int[] array = new int[list.size()]; + for (int i = 0 ; i < array.length ; i++) { + array[i] = list.get(i); + } + return array; + } - for (Map.Entry entry : graph.getOrDefault(edge.vertex, new HashMap<>()).entrySet()) { - final int neighbour = entry.getKey(), time = entry.getValue(); - queue.add(new Edge(neighbour, edge.time + time)); + // T: O(E) S: O(1) + private static void addAll0InDegreeToQueue(Queue queue, int[] inDegree) { + for (int i = 0 ; i < inDegree.length ; i++) { + if (inDegree[i] == 0) { + queue.add(i); } } - - return distances; } - public static void main(String[] args) { - int[] b = new int[] {1, 2, 3}; - int[] a = b; - System.out.println(Arrays.toString(a)); - b = new int[] {5, 6, 7}; - System.out.println(Arrays.toString(a)); + // T: O(E) S: O(E) + private static int[] computeInDegree(int n, int[][] edges) { + final int[] inDegree = new int[n]; + for (int[] edge : edges) { + final int to = edge[0]; + inDegree[to]++; + } + return inDegree; + } + // T: O(|E|), S: O(E) + private static Map> createGraph(int[][] edges) { + final Map> graph = new HashMap<>(); + for (int[] edge : edges) { + final int to = edge[0], from = edge[1]; + final Set set = graph.getOrDefault(from, new HashSet<>()); + set.add(to); + graph.putIfAbsent(from, set); + } + return graph; } } \ No newline at end of file diff --git a/src/MaximumDepthOfNAryTree.java b/src/MaximumDepthOfNAryTree.java index e553a24..3cd2fd0 100644 --- a/src/MaximumDepthOfNAryTree.java +++ b/src/MaximumDepthOfNAryTree.java @@ -1,7 +1,11 @@ +// https://leetcode.com/problems/maximum-depth-of-n-ary-tree +// T: O(N) +// S: O(logN) + import java.util.List; public class MaximumDepthOfNAryTree { - private static class Node { + public static class Node { public int val; public List children; diff --git a/src/MinimumHeightTrees.java b/src/MinimumHeightTrees.java new file mode 100644 index 0000000..b244d1e --- /dev/null +++ b/src/MinimumHeightTrees.java @@ -0,0 +1,78 @@ +// https://leetcode.com/problems/minimum-height-trees +// T: O(N) +// S: O(N) + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +public class MinimumHeightTrees { + public List findMinHeightTrees(int n, int[][] edges) { + if (n == 0) return new ArrayList<>(); + if (n == 1) return new ArrayList<>() {{ add(0); }}; + + final Map> graph = createGraph(edges); + return minHeightTreeRoots(graph); + } + + // T: O(N), S: O(N) + private static List minHeightTreeRoots(Map> graph) { + final int[] degree = computeDegree(graph); + Set leafNodes = addLeafNodes(degree); + + while (graph.size() > 2) { + final Set newLeafNodes = new HashSet<>(); + for (int leafNode : leafNodes) { + degree[leafNode]--; + for (int neighbour : graph.get(leafNode)) { + degree[neighbour]--; + if (degree[neighbour] == 1) { + newLeafNodes.add(neighbour); + } + } + graph.remove(leafNode); + } + leafNodes = newLeafNodes; + } + + return new ArrayList<>(graph.keySet()); + } + + // T: O(N), S: O(N) + private static Set addLeafNodes(int[] degree) { + final Set leafNodes = new HashSet<>(); + for (int i = 0 ; i < degree.length ; i++) { + if (degree[i] == 1) { + leafNodes.add(i); + } + } + return leafNodes; + } + + // T: O(N), S: O(N) + private static int[] computeDegree(Map> graph) { + final int[] degree = new int[graph.size()]; + for (Map.Entry> entry : graph.entrySet()) { + degree[entry.getKey()] = entry.getValue().size(); + } + return degree; + } + + // T: O(N), S: O(N) + private static Map> createGraph(int[][] edges) { + final Map> graph = new HashMap<>(); + for (int[] edge : edges) { + final int from = edge[0], to = edge[1]; + final Set fromSet = graph.getOrDefault(from, new HashSet<>()); + final Set toSet = graph.getOrDefault(to, new HashSet<>()); + fromSet.add(to); + toSet.add(from); + graph.putIfAbsent(from, fromSet); + graph.putIfAbsent(to, toSet); + } + return graph; + } +} From 6c10ca9680bc44216d1809edfbeca46655ef9ecf Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 30 Jul 2024 13:43:28 +0200 Subject: [PATCH 257/280] solves #269: Alien Dictionary in java --- README.md | 1 + src/AlienDictionary.java | 117 ++++++++++++++++----------------------- 2 files changed, 48 insertions(+), 70 deletions(-) diff --git a/README.md b/README.md index 27d30a4..4f0643d 100644 --- a/README.md +++ b/README.md @@ -231,6 +231,7 @@ | 266 | 🔒 [Palindrome Permutation](https://leetcode.com/problems/palindrome-permutation) | | | | 267 | 🔒 [Palindrome Permutation II](https://leetcode.com/problems/palindrome-permutation-ii) | | | | 268 | [Missing Number](https://leetcode.com/problems/missing-number) | [![Java](assets/java.png)](src/MissingNumber.java) [![Python](assets/python.png)](python/missing_number.py) | | +| 269 | [Alien Dictionary](https://leetcode.com/problems/alien-dictionary) | [![Java](assets/java.png)](src/AlienDictionary.java) | | | 270 | 🔒 [Closest Binary Search Tree Value](https://leetcode.com/problems/closest-binary-search-tree-value) | | | | 271 | 🔒 [Encode and Decode Strings](https://leetcode.com/problems/encode-and-decode-strings) | | | | 274 | [H-Index](https://leetcode.com/problems/h-index) | [![Java](assets/java.png)](src/HIndex.java) | | diff --git a/src/AlienDictionary.java b/src/AlienDictionary.java index ed80366..9090889 100644 --- a/src/AlienDictionary.java +++ b/src/AlienDictionary.java @@ -1,91 +1,68 @@ // https://leetcode.com/problems/alien-dictionary -// T: O() -// S: O() +// C = length of all words added together +// T: O(C) +// S: O(1) -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Queue; public class AlienDictionary { public String alienOrder(String[] words) { - final Map> graph = createGraphFrom(words); - return lexicographicallySmallest(graph); - } - - private static String lexicographicallySmallest(Map> graph) { - final Map inDegree = computeInDegree(graph); - final Queue queue = new LinkedList<>(); - final StringBuilder builder = new StringBuilder(); - add0InDegreeInQueue(queue, inDegree); - while (!queue.isEmpty()) { - final char c = queue.poll(); - builder.append(c); - for (char neighbour : graph.getOrDefault(c, new HashSet<>())) { - inDegree.put(neighbour, inDegree.get(neighbour) - 1); - if (inDegree.get(neighbour) == 0) { - queue.add(neighbour); - } + // Step 0: Create data structures and find all unique letters. + Map> adjList = new HashMap<>(); + Map counts = new HashMap<>(); + for (String word : words) { + for (char c : word.toCharArray()) { + counts.put(c, 0); + adjList.put(c, new ArrayList<>()); } - graph.remove(c); } - if (graph.isEmpty()) { - return builder.toString(); - } - return ""; - } - - private static Map> createGraphFrom(String[] words) { - final Map> graph = new HashMap<>(); - addAllLettersInGraph(graph, words); - for (int i = 0 ; i < words.length ; i++) { - for (int j = i + 1 ; j < words.length ; j++) { - if (words[i].equals(words[j])) { - continue; - } - final char[] charDiff = firstDifferentCharacter(words[i], words[j]); - if (charDiff.length == 0) { - continue; - } - final Set set = graph.getOrDefault(charDiff[0], new HashSet<>()); - set.add(charDiff[1]); - graph.putIfAbsent(charDiff[0], set); + // Step 1: Find all edges. + for (int i = 0; i < words.length - 1; i++) { + String word1 = words[i]; + String word2 = words[i + 1]; + // Check that word2 is not a prefix of word1. + if (word1.length() > word2.length() && word1.startsWith(word2)) { + return ""; } - } - return graph; - } - - private static void addAllLettersInGraph(Map> graph, String[] words) { - for (String word : words) { - for (int i = 0 ; i < word.length() ; i++) { - graph.putIfAbsent(word.charAt(i), new HashSet<>()); + // Find the first non match and insert the corresponding relation. + for (int j = 0; j < Math.min(word1.length(), word2.length()); j++) { + if (word1.charAt(j) != word2.charAt(j)) { + adjList.get(word1.charAt(j)).add(word2.charAt(j)); + counts.put(word2.charAt(j), counts.get(word2.charAt(j)) + 1); + break; + } } } - } - private static char[] firstDifferentCharacter(String s1, String s2) { - for (int i = 0 ; i < s1.length() && i < s2.length() ; i++) { - if (s1.charAt(i) != s2.charAt(i)) { - return new char[] { s1.charAt(i), s2.charAt(i) }; + // Step 2: Breadth-first search. + StringBuilder sb = new StringBuilder(); + Queue queue = new LinkedList<>(); + for (Character c : counts.keySet()) { + if (counts.get(c).equals(0)) { + queue.add(c); } } - return new char[] {}; - } - - private static Map computeInDegree(Map> graph) { - final Map inDegree = new HashMap<>(); - for (Set set : graph.values()) { - for (char c : set) { - inDegree.put(c, inDegree.getOrDefault(c, 0) + 1); + while (!queue.isEmpty()) { + Character c = queue.remove(); + sb.append(c); + for (Character next : adjList.get(c)) { + counts.put(next, counts.get(next) - 1); + if (counts.get(next).equals(0)) { + queue.add(next); + } } } - return inDegree; - } - private static void add0InDegreeInQueue(Queue queue, Map inDegree) { - for (Map.Entry entry : inDegree.entrySet()) { - if (entry.getValue() == 0) { - queue.add(entry.getKey()); - } + if (sb.length() < counts.size()) { + return ""; } + return sb.toString(); } } From 64c5bbbe90a6f7a557c30b3e631520538adf17b0 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 30 Jul 2024 14:06:20 +0200 Subject: [PATCH 258/280] solves #1136: Parallel courses in java --- README.md | 1 + src/ParallelCourses.java | 73 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 src/ParallelCourses.java diff --git a/README.md b/README.md index 4f0643d..b2d2e61 100644 --- a/README.md +++ b/README.md @@ -517,6 +517,7 @@ | 1128 | [Number of Equivalent Domino Pairs](https://leetcode.com/problems/number-of-equivalent-domino-pairs) | [![Java](assets/java.png)](src/NumberOfEquivalentDominoPairs.java) | | | 1133 | 🔒 [Largest Unique Number](https://leetcode.com/problems/largest-unique-number) | | | | 1134 | 🔒 [Armstrong Number](https://leetcode.com/problems/armstrong-number) | | | +| 1136 | 🔒 [Parallel Courses](https://leetcode.com/problems/parallel-courses) | [![Java](assets/java.png)](src/ParallelCourses.java) | | | 1137 | [Nth Tribonacci Number](https://leetcode.com/problems/n-th-tribonacci-number) | [![Java](assets/java.png)](src/NthTribonacciNumber.java) | | | 1143 | [Longest Common Subsequence](https://leetcode.com/problems/longest-common-subsequence) | [![Java](assets/java.png)](src/LongestCommonSubsequence.java) | | | 1150 | [Check if Number is Majority Element in Sorted Array](https://leetcode.com/problems/check-if-a-number-is-majority-element-in-a-sorted-array) | | | diff --git a/src/ParallelCourses.java b/src/ParallelCourses.java new file mode 100644 index 0000000..0756749 --- /dev/null +++ b/src/ParallelCourses.java @@ -0,0 +1,73 @@ +// https://leetcode.com/problems/parallel-courses +// T: O(N + E) +// S: O(N + E) + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public class ParallelCourses { + public int minimumSemesters(int n, int[][] relations) { + final Map> graph = createGraph(relations); + final int[] inDegree = computeInDegree(relations, n); + return minimumSemesters(graph, inDegree); + } + + // Kahn's algorithm T: O(N + E), S: O(N) + private static int minimumSemesters(Map> graph, int[] inDegree) { + Set noPrerequisites = coursesWithoutPrerequisites(inDegree); + int minSemesters = 0; + + while (!noPrerequisites.isEmpty()) { + final Set newCourses = new HashSet<>(); + for (int course : noPrerequisites) { + inDegree[course]--; + for (int neighbour : graph.getOrDefault(course, new HashSet<>())) { + inDegree[neighbour]--; + if (inDegree[neighbour] == 0) { + newCourses.add(neighbour); + } + } + graph.remove(course); + } + noPrerequisites = newCourses; + minSemesters++; + } + + return graph.isEmpty() ? minSemesters : -1; + } + + // T: O(E), S: O(N) + private static int[] computeInDegree(int[][] edges, int n) { + final int[] inDegree = new int[n]; + for (int[] edge : edges) { + final int to = edge[1] - 1; + inDegree[to]++; + } + return inDegree; + } + + // T: O(N), S: O(N) + private static Set coursesWithoutPrerequisites(int[] inDegree) { + final Set set = new HashSet<>(); + for (int i = 0 ; i < inDegree.length ; i++) { + if (inDegree[i] == 0) { + set.add(i); + } + } + return set; + } + + // T: O(E), S: O(E) + private static Map> createGraph(int[][] edges) { + final Map> graph = new HashMap<>(); + for (int[] edge : edges) { + final int from = edge[0] - 1, to = edge[1] - 1; + final Set fromNeighbours = graph.getOrDefault(from, new HashSet<>()); + fromNeighbours.add(to); + graph.putIfAbsent(from, fromNeighbours); + } + return graph; + } +} From f16c03f70fc99f38aa65244d7f38822266a87dc0 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 30 Jul 2024 17:17:17 +0200 Subject: [PATCH 259/280] solves #909: Snakes and Ladders in java --- README.md | 1 + src/SnakesAndLadders.java | 75 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 74 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b2d2e61..6874981 100644 --- a/README.md +++ b/README.md @@ -453,6 +453,7 @@ | 897 | [Increasing Order Search Tree](https://leetcode.com/problems/increasing-order-search-tree) | [![Java](assets/java.png)](src/IncreasingOrderSearchTree.java) | | | 905 | [Sort Array by Parity](https://leetcode.com/problems/sort-array-by-parity) | | | | 908 | [Smallest Range I](https://leetcode.com/problems/smallest-range-i) | [![Java](assets/java.png)](src/SmallestRangeI.java) | | +| 909 | [Snakes and Ladders](https://leetcode.com/problems/snakes-and-ladders) | [![Java](assets/java.png)](src/SnakesAndLadders.java) | | | 914 | [X of a kind in a Deck of Cards](https://leetcode.com/problems/x-of-a-kind-in-a-deck-of-cards) | [![Java](assets/java.png)](src/XOfAKindInADeckOfCards.java) | | | 917 | [Reverse Only Letters](https://leetcode.com/problems/reverse-only-letters) | [![Java](assets/java.png)](src/ReverseOnlyLetters.java) | | | 922 | [Sort Array by Parity II](https://leetcode.com/problems/sort-array-by-parity-ii) | [![Java](assets/java.png)](src/SortArrayByParityII.java) | | diff --git a/src/SnakesAndLadders.java b/src/SnakesAndLadders.java index 06edb72..324c29e 100644 --- a/src/SnakesAndLadders.java +++ b/src/SnakesAndLadders.java @@ -1,6 +1,77 @@ // https://leetcode.com/problems/snakes-and-ladders -// T: O() -// S: O() +// T: O(n^2) +// S: O(n^2) + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Queue; public class SnakesAndLadders { + private record Position(int row, int column) {} + + private record Info(int square, int cost) {} + + // BFS: T: O(V + E), V = n^2, E = 6n^2 T: O(n^2), S: O(V) = O(n^2) + public int snakesAndLadders(int[][] board) { + final int n = board.length; + final Map squareToPosition = createSquaresToPositions(n); + final Queue queue = new LinkedList<>() {{ add(new Info(1, 0)); }}; + final int[] distances = initializeDistances(n); + + while (!queue.isEmpty()) { + final Info info = queue.poll(); + if (distances[info.square] <= info.cost) { + continue; + } + + distances[info.square] = info.cost; + + for (int nextSquare : validPositions(board, info.square, squareToPosition)) { + queue.add(new Info(nextSquare, info.cost + 1)); + } + } + + return distances[n * n] == Integer.MAX_VALUE ? -1 : distances[n * n]; + } + + // T: O(1), S: O(1) + private static List validPositions(int[][] grid, int square, Map positions) { + final int n = grid.length; + final List result = new ArrayList<>(); + for (int i = 1 ; i <= 6 ; i++) { + final int nextSquare = square + i; + if (nextSquare > n * n) { + break; + } + final Position position = positions.get(nextSquare); + if (grid[position.row][position.column] == -1) { + result.add(nextSquare); + } else { + result.add(grid[position.row][position.column]); + } + } + return result; + } + + // T: O(n^2), S: O(n^2) + private static int[] initializeDistances(int n) { + final int[] distances = new int[n * n + 1]; + Arrays.fill(distances, Integer.MAX_VALUE); + return distances; + } + + // T: O(n^2), S: O(n^2) + private static Map createSquaresToPositions(int n) { + final Map result = new HashMap<>(); + for (int i = 1 ; i <= n * n ; i++) { + final int row = n - ((i - 1) / n) - 1; + final int column = (n - 1 - row) % 2 == 0 ? (i - 1) % n : n - 1 - ((i - 1) % n); + result.put(i, new Position(row, column)); + } + return result; + } } From 3d079ddfbbb02d7fa14889e5ca9d7f5386f66b70 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 30 Jul 2024 17:44:43 +0200 Subject: [PATCH 260/280] solves #433: Minimum Genetic Mutation in java --- README.md | 1 + src/MinimumGeneticMutation.java | 66 +++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 src/MinimumGeneticMutation.java diff --git a/README.md b/README.md index 6874981..66b7947 100644 --- a/README.md +++ b/README.md @@ -317,6 +317,7 @@ | 422 | 🔒 [Valid Word Square](https://leetcode.com/problems/valid-word-square) | | | | 429 | 🔒 [N-ary Tree Level Order Traversal](https://leetcode.com/problems/n-ary-tree-level-order-traversal) | [![Java](assets/java.png)](src/NAryTreeLevelOrderTraversal.java) | | | 430 | [Flatten a Multilevel Doubly Linked List](https://leetcode.com/problems/flatten-a-multilevel-doubly-linked-list) | [![Java](assets/java.png)](src/FlattenAMultiLevelDoublyLinkedList.java) | | +| 433 | [Minimum Genetic Mutation](https://leetcode.com/problems/minimum-genetic-mutation) | [![Java](assets/java.png)](src/MinimumGeneticMutation.java) | | | 434 | [Number of Segments in a String](https://leetcode.com/problems/number-of-segments-in-a-string) | [![Java](assets/java.png)](src/NumberOfSegmentsInString.java) [![Python](assets/python.png)](python/number_of_segments_in_a_string.py) | | | 441 | [Arranging Coins](https://leetcode.com/problems/arranging-coins) | [![Java](assets/java.png)](src/ArrangingCoins.java) [![Python](assets/python.png)](python/arranging_coins.py) | | | 443 | [String Compression](https://leetcode.com/problems/string-compression) | [![Java](assets/java.png)](src/StringCompression.java) [![Python](assets/python.png)](python/string_compression.py) | | diff --git a/src/MinimumGeneticMutation.java b/src/MinimumGeneticMutation.java new file mode 100644 index 0000000..fafd13d --- /dev/null +++ b/src/MinimumGeneticMutation.java @@ -0,0 +1,66 @@ +// https://leetcode.com/problems/minimum-genetic-mutation +// T: O(B) +// S: O(1) + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Queue; +import java.util.Set; + +public class MinimumGeneticMutation { + private record Info(String mutation, int steps) {} + + private static final char[] GENES = new char[] {'A', 'G', 'C', 'T'}; + + // n = length of string (8), m = possible number of characters + // BFS, T: O(V + E) = O(nB + n^m * mn) S: O(n^m) + public static int minMutation(String startGene, String endGene, String[] bank) { + final Set genePool = toSet(bank); + if (!genePool.contains(endGene)) { + return -1; + } + + final Queue queue = new LinkedList<>() {{ add(new Info(startGene, 0)); }}; + final Map distances = new HashMap<>(); + + while (!queue.isEmpty()) { + final Info info = queue.poll(); + if (distances.getOrDefault(info.mutation, Integer.MAX_VALUE) <= info.steps) { + continue; + } + distances.put(info.mutation, info.steps); + + for (String neighbour : validMutations(genePool, info.mutation)) { + queue.add(new Info(neighbour, info.steps + 1)); + } + } + + return distances.getOrDefault(endGene, -1); + } + + // T: O(|s|), S: O(|s|) + private static List validMutations(Set genePool, String s) { + final List result = new ArrayList<>(); + for (int i = 0 ; i < s.length() ; i++) { + for (char c : GENES) { + final String mutation = s.substring(0, i) + c + s.substring(i + 1); + if (genePool.contains(mutation)) { + result.add(mutation); + } + } + } + return result; + } + + // T: O(nB) S: O(nB) + private static Set toSet(String[] bank) { + final Set set = new HashSet<>(); + Collections.addAll(set, bank); + return set; + } +} From b7c02bd0b2a849b9bc8469d45f1216065c0d9e56 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 30 Jul 2024 18:03:28 +0200 Subject: [PATCH 261/280] solves #127: word ladder in java --- README.md | 1 + src/MinimumGeneticMutation.java | 12 ++++--- src/WordLadder.java | 58 +++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 src/WordLadder.java diff --git a/README.md b/README.md index 66b7947..c0e91af 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,7 @@ | 122 | [Best Time to Buy and Sell Stocks II](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii) | [![Java](assets/java.png)](src/BestTimeToBuyAndSellStockII.java) [![Python](assets/python.png)](python/best_time_to_buy_and_sell_stock_ii.py) | | | 123 | [Binary Tree Maximum Path Sum](https://leetcode.com/problems/binary-tree-maximum-path-sum) | [![Java](assets/java.png)](src/BinaryTreeMaximumPathSum.java) | | | 125 | [Valid Palindrome](https://leetcode.com/problems/valid-palindrome) | [![Java](assets/java.png)](src/ValidPalindrome.java) [![Python](assets/python.png)](python/valid_palindrome.py) | | +| 127 | [Word Ladder](https://leetcode.com/problems/word-ladder) | [![Java](assets/java.png)](src/WordLadder.java) | | | 128 | [Longest Consecutive Sequence](https://leetcode.com/problems/longest-consecutive-sequence) | [![Java](assets/java.png)](src/LongestConsecutiveSequence.java) | | | 129 | [Sum Root to Leaf Numbers](https://leetcode.com/problems/sum-root-to-leaf-numbers) | [![Java](assets/java.png)](src/SumRootToLeafNumbers.java) | | | 130 | [Surrounded Regions](https://leetcode.com/problems/surrounded-regions) | [![Java](assets/java.png)](src/SurroundedRegions.java) | | diff --git a/src/MinimumGeneticMutation.java b/src/MinimumGeneticMutation.java index fafd13d..2d7c0ad 100644 --- a/src/MinimumGeneticMutation.java +++ b/src/MinimumGeneticMutation.java @@ -26,21 +26,25 @@ public static int minMutation(String startGene, String endGene, String[] bank) { } final Queue queue = new LinkedList<>() {{ add(new Info(startGene, 0)); }}; - final Map distances = new HashMap<>(); + final Set visited = new HashSet<>(); while (!queue.isEmpty()) { final Info info = queue.poll(); - if (distances.getOrDefault(info.mutation, Integer.MAX_VALUE) <= info.steps) { + if (visited.contains(info.mutation)) { continue; } - distances.put(info.mutation, info.steps); + visited.add(info.mutation); + + if (endGene.equals(info.mutation)) { + return info.steps; + } for (String neighbour : validMutations(genePool, info.mutation)) { queue.add(new Info(neighbour, info.steps + 1)); } } - return distances.getOrDefault(endGene, -1); + return -1; } // T: O(|s|), S: O(|s|) diff --git a/src/WordLadder.java b/src/WordLadder.java new file mode 100644 index 0000000..11eedde --- /dev/null +++ b/src/WordLadder.java @@ -0,0 +1,58 @@ +// https://leetcode.com/problems/word-ladder +// T: O(nB + n^m * nm) +// S: O(nB + n^m) + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; +import java.util.Set; + +public class WordLadder { + private record Info(String string, int steps) {} + + // n = possible chars, m = |s| + // V = n^m + // BFS, T: O(V + E) = O(nB + n^m * nm), S: O(n^m) + public int ladderLength(String beginWord, String endWord, List wordList) { + final Set words = new HashSet<>(wordList); + if (!words.contains(endWord)) { + return 0; + } + + final Queue queue = new LinkedList<>() {{ add(new Info(beginWord, 0)); }}; + final Set visited = new HashSet<>(); + + while (!queue.isEmpty()) { + final Info info = queue.poll(); + if (visited.contains(info.string)) { + continue; + } + visited.add(info.string); + if (endWord.equals(info.string)) { + return info.steps + 1; + } + + for (String neighbour : validMutations(words, info.string)) { + queue.add(new Info(neighbour, info.steps + 1)); + } + } + + return -1; + } + + // T: O(n * m), S: O(n * m) + private static List validMutations(Set words, String string) { + final List list = new ArrayList<>(); + for (int i = 0 ; i < string.length() ; i++) { + for (char c = 'a' ; c <= 'z' ; c++) { + final String word = string.substring(0, i) + c + string.substring(i + 1); + if (words.contains(word)) { + list.add(word); + } + } + } + return list; + } +} From cb364a5acfa55fa2dc2dd43ba59562d4ec54f8d6 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 30 Jul 2024 21:00:11 +0200 Subject: [PATCH 262/280] solves #51: N-Queens in java --- README.md | 1 + src/CombinationSum.java | 5 ++- src/HelloWorld.java | 78 +++++++-------------------------- src/NQueens.java | 96 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 115 insertions(+), 65 deletions(-) create mode 100644 src/NQueens.java diff --git a/README.md b/README.md index c0e91af..c9006f7 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ | 48 | [Rotate Image](https://leetcode.com/problems/rotate-image) | [![Java](assets/java.png)](src/RotateImage.java) | | | 49 | [Group Anagrams](https://leetcode.com/problems/group-anagrams) | [![Java](assets/java.png)](src/GroupAnagrams.java) | | | 50 | [Pow(x,n)](https://leetcode.com/problems/powx-n) | [![Java](assets/java.png)](src/Powxn.java) | | +| 51 | [N-Queens](https://leetcode.com/problems/n-queens) | [![Java](assets/java.png)](src/NQueens.java) | | | 53 | [Maximum SubArray](https://leetcode.com/problems/maximum-subarray) | [![Java](assets/java.png)](src/MaximumSubArray.java) [![Python](assets/python.png)](python/maximum_sum_subarray.py) | | | 54 | [Spiral Matrix](https://leetcode.com/problems/spiral-matrix) | [![Java](assets/java.png)](src/SpiralMatrix.java) | | | 55 | [Jump Game](https://leetcode.com/problems/jump-game) | [![Java](assets/java.png)](src/JumpGame.java) | | diff --git a/src/CombinationSum.java b/src/CombinationSum.java index 10ca632..d9df7e0 100644 --- a/src/CombinationSum.java +++ b/src/CombinationSum.java @@ -1,6 +1,7 @@ // https://leetcode.com/problems/combination-sum -// T: O(|candidates| ^ target) -// S: O(target + candidate ^ 2) // not sure tho --> if anyone has any idea please feel free to contact me +// M = smallest candidate +// T: O(|candidates| ^ (target / M)) +// S: O(target / M) // not sure tho --> if anyone has any idea please feel free to contact me import java.util.ArrayList; import java.util.List; diff --git a/src/HelloWorld.java b/src/HelloWorld.java index cd0a3f2..1a3efa4 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -8,73 +8,25 @@ import java.util.Set; public class HelloWorld { - // T: O(V + E) S: O(V + E) - public int[] findOrder(int numCourses, int[][] prerequisites) { - final Map> graph = createGraph(prerequisites); - final int[] inDegree = computeInDegree(numCourses, prerequisites); - return orderOfCourses(graph, inDegree); + public List> combinationSum(int[] candidates, int target) { + final Set> result = new HashSet<>(); + computeSums(candidates, target, result, 0, new ArrayList<>(), 0); + return new ArrayList<>(result); } - // T: O(V + E) S: O(V) - private static int[] orderOfCourses(Map> graph, int[] inDegree) { - final Queue queue = new PriorityQueue<>(); - final List order = new ArrayList<>(); - addAll0InDegreeToQueue(queue, inDegree); - - while (!queue.isEmpty()) { - final int vertex = queue.poll(); - order.add(vertex); - for (int neighbour : graph.getOrDefault(vertex, new HashSet<>())) { - inDegree[neighbour]--; - if (inDegree[neighbour] == 0) { - queue.add(neighbour); - } - } - graph.remove(vertex); + private static void computeSums(int[] candidates, int target, Set> result, int currentSum, List current, int i) { + if (currentSum > target || i >= candidates.length) { + return; } - - if (order.size() != inDegree.length) { - return new int[] {}; + if (currentSum == target) { + result.add(new ArrayList<>(current)); + return; } - return toArray(order); - } - private static int[] toArray(List list) { - final int[] array = new int[list.size()]; - for (int i = 0 ; i < array.length ; i++) { - array[i] = list.get(i); - } - return array; - } - - // T: O(E) S: O(1) - private static void addAll0InDegreeToQueue(Queue queue, int[] inDegree) { - for (int i = 0 ; i < inDegree.length ; i++) { - if (inDegree[i] == 0) { - queue.add(i); - } - } - } - - // T: O(E) S: O(E) - private static int[] computeInDegree(int n, int[][] edges) { - final int[] inDegree = new int[n]; - for (int[] edge : edges) { - final int to = edge[0]; - inDegree[to]++; - } - return inDegree; - } - - // T: O(|E|), S: O(E) - private static Map> createGraph(int[][] edges) { - final Map> graph = new HashMap<>(); - for (int[] edge : edges) { - final int to = edge[0], from = edge[1]; - final Set set = graph.getOrDefault(from, new HashSet<>()); - set.add(to); - graph.putIfAbsent(from, set); - } - return graph; + computeSums(candidates, target, result, currentSum, current, i + 1); + current.add(candidates[i]); + computeSums(candidates, target, result, currentSum + candidates[i], current, i); + computeSums(candidates, target, result, currentSum + candidates[i], current, i + 1); + current.removeLast(); } } \ No newline at end of file diff --git a/src/NQueens.java b/src/NQueens.java new file mode 100644 index 0000000..61a3c20 --- /dev/null +++ b/src/NQueens.java @@ -0,0 +1,96 @@ +// https://leetcode.com/problems/n-queens +// T: O(N!) +// S: O(N^2) + +import java.util.ArrayList; +import java.util.List; + +public class NQueens { + private static boolean[] rows, columns; + + public static List> solveNQueens(int n) { + final List> result = new ArrayList<>(); + final List board = getEmptyBoard(n); + rows = new boolean[n]; + columns = new boolean[n]; + nQueens(0, n, result, board, 0); + return result; + } + + private static void nQueens(int row, int n, List> result, List board, int queens) { + if (row == n) { + if (queens == n) { + result.add(new ArrayList<>(board)); + } + return; + } + + for (int column = 0 ; column < n ; column++) { + if (canPlace(board, row, column)) { + placeQueen(board, row, column); + nQueens(row + 1, n, result, board, queens + 1); + removeQueen(board, row, column); + } + } + } + + private static void placeQueen(List board, int row, int column) { + board.set( + row, + board.get(row).substring(0, column) + 'Q' + board.get(row).substring(column + 1) + ); + rows[row] = true; + columns[column] = true; + } + + private static void removeQueen(List board, int row, int column) { + board.set( + row, + board.get(row).substring(0, column) + '.' + board.get(row).substring(column + 1) + ); + rows[row] = false; + columns[column] = false; + } + + private static boolean canPlace(List board, int row, int column) { + return !rows[row] && !columns[column] && !queenInLeftDiagonal(board, row, column) + && !queenInRightDiagonal(board, row, column); + } + + private static boolean queenInLeftDiagonal(List board, int row, int column) { + for (int i = row - 1, j = column - 1 ; i >= 0 && j >= 0 ; i--, j--) { + if (board.get(i).charAt(j) == 'Q') { + return true; + } + } + for (int i = row + 1, j = column + 1 ; i < board.size() && j < board.size() ; i++, j++) { + if (board.get(i).charAt(j) == 'Q') { + return true; + } + } + return false; + } + + private static boolean queenInRightDiagonal(List board, int row, int column) { + for (int i = row - 1, j = column + 1 ; i >= 0 && j < board.size() ; i--, j++) { + if (board.get(i).charAt(j) == 'Q') { + return true; + } + } + for (int i = row + 1, j = column - 1 ; i < board.size() && j >= 0 ; i++, j--) { + if (board.get(i).charAt(j) == 'Q') { + return true; + } + } + return false; + } + + private static List getEmptyBoard(int n) { + final List board = new ArrayList<>(); + final String line = ".".repeat(n); + for (int i = 0 ; i < n ; i++) { + board.add(line); + } + return board; + } +} From ab603716e2e33401047b0640913ee0ae58521d58 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 30 Jul 2024 22:16:07 +0200 Subject: [PATCH 263/280] solves #52: n queens ii in java --- README.md | 1 + src/NQueensII.java | 97 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 src/NQueensII.java diff --git a/README.md b/README.md index c9006f7..827d6b4 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,7 @@ | 49 | [Group Anagrams](https://leetcode.com/problems/group-anagrams) | [![Java](assets/java.png)](src/GroupAnagrams.java) | | | 50 | [Pow(x,n)](https://leetcode.com/problems/powx-n) | [![Java](assets/java.png)](src/Powxn.java) | | | 51 | [N-Queens](https://leetcode.com/problems/n-queens) | [![Java](assets/java.png)](src/NQueens.java) | | +| 51 | [N-Queens II](https://leetcode.com/problems/n-queens-ii) | [![Java](assets/java.png)](src/NQueensII.java) | | | 53 | [Maximum SubArray](https://leetcode.com/problems/maximum-subarray) | [![Java](assets/java.png)](src/MaximumSubArray.java) [![Python](assets/python.png)](python/maximum_sum_subarray.py) | | | 54 | [Spiral Matrix](https://leetcode.com/problems/spiral-matrix) | [![Java](assets/java.png)](src/SpiralMatrix.java) | | | 55 | [Jump Game](https://leetcode.com/problems/jump-game) | [![Java](assets/java.png)](src/JumpGame.java) | | diff --git a/src/NQueensII.java b/src/NQueensII.java new file mode 100644 index 0000000..2cc8e68 --- /dev/null +++ b/src/NQueensII.java @@ -0,0 +1,97 @@ +// https://leetcode.com/problems/n-queens-ii +// T: O(N!) +// S: O(N^2) + +import java.util.ArrayList; +import java.util.List; + +public class NQueensII { + private static boolean[] rows, columns; + private static int result = 0; + + public int totalNQueens(int n) { + result = 0; + final List board = getEmptyBoard(n); + rows = new boolean[n]; + columns = new boolean[n]; + nQueens(0, n, board, 0); + return result; + } + + private static void nQueens(int row, int n, List board, int queens) { + if (row == n) { + if (queens == n) { + result++; + } + return; + } + + for (int column = 0 ; column < n ; column++) { + if (canPlace(board, row, column)) { + placeQueen(board, row, column); + nQueens(row + 1, n, board, queens + 1); + removeQueen(board, row, column); + } + } + } + + private static void placeQueen(List board, int row, int column) { + board.set( + row, + board.get(row).substring(0, column) + 'Q' + board.get(row).substring(column + 1) + ); + rows[row] = true; + columns[column] = true; + } + + private static void removeQueen(List board, int row, int column) { + board.set( + row, + board.get(row).substring(0, column) + '.' + board.get(row).substring(column + 1) + ); + rows[row] = false; + columns[column] = false; + } + + private static boolean canPlace(List board, int row, int column) { + return !rows[row] && !columns[column] && !queenInLeftDiagonal(board, row, column) + && !queenInRightDiagonal(board, row, column); + } + + private static boolean queenInLeftDiagonal(List board, int row, int column) { + for (int i = row - 1, j = column - 1 ; i >= 0 && j >= 0 ; i--, j--) { + if (board.get(i).charAt(j) == 'Q') { + return true; + } + } + for (int i = row + 1, j = column + 1 ; i < board.size() && j < board.size() ; i++, j++) { + if (board.get(i).charAt(j) == 'Q') { + return true; + } + } + return false; + } + + private static boolean queenInRightDiagonal(List board, int row, int column) { + for (int i = row - 1, j = column + 1 ; i >= 0 && j < board.size() ; i--, j++) { + if (board.get(i).charAt(j) == 'Q') { + return true; + } + } + for (int i = row + 1, j = column - 1 ; i < board.size() && j >= 0 ; i++, j--) { + if (board.get(i).charAt(j) == 'Q') { + return true; + } + } + return false; + } + + private static List getEmptyBoard(int n) { + final List board = new ArrayList<>(); + final String line = ".".repeat(n); + for (int i = 0 ; i < n ; i++) { + board.add(line); + } + return board; + } +} From f11d33dfbc58a698fc8b1c6a5ddb534bd2793bcb Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 1 Aug 2024 17:09:46 +0200 Subject: [PATCH 264/280] update search in rotated sorted array --- src/BinarySearch.java | 4 ++ src/EdmondsKarp.java | 72 +++++++++++++++++++++++++++++ src/HelloWorld.java | 51 ++++++++++---------- src/MedianOfTwoSortedArrays.java | 34 ++++++++++++++ src/SearchInRotatedSortedArray.java | 39 +++++++++------- 5 files changed, 158 insertions(+), 42 deletions(-) create mode 100644 src/EdmondsKarp.java create mode 100644 src/MedianOfTwoSortedArrays.java diff --git a/src/BinarySearch.java b/src/BinarySearch.java index 8ce598e..19ddd73 100644 --- a/src/BinarySearch.java +++ b/src/BinarySearch.java @@ -1,3 +1,7 @@ +// https://leetcode.com/problems/binary-search +// T: O(logN) +// S: O(1) + public class BinarySearch { public int search(int[] array, int val) { int left = 0, right = array.length - 1, middle; diff --git a/src/EdmondsKarp.java b/src/EdmondsKarp.java new file mode 100644 index 0000000..ae630ad --- /dev/null +++ b/src/EdmondsKarp.java @@ -0,0 +1,72 @@ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; + +public class EdmondsKarp { + private static int[][] adj_matrix; + + private static int edmonds_karp(int n, int source, int sink) { + int[] parent = initializeParent(n); + int max_flow = 0; + + while (bfs(n, source, sink, parent)) { + int path_flow = Integer.MAX_VALUE; + int s = sink; + while (s != source) { + path_flow = Math.min(path_flow, adj_matrix[parent[s]][s]); + s = parent[s]; + } + max_flow += path_flow; + + int v = sink; + while (v != source) { + int u = parent[v]; + adj_matrix[u][v] -= path_flow; + adj_matrix[v][u] += path_flow; + v = parent[v]; + } + + List path = new ArrayList<>(); + v = sink; + while (v != source) { + path.add(v); + v = parent[v]; + } + path.add(source); + path = path.reversed(); + System.out.println(path); + + parent = initializeParent(n); + } + + return max_flow; + } + + private static int[] initializeParent(int n) { + final int[] result = new int[n]; + Arrays.fill(result, -1); + return result; + } + + private static boolean bfs(int n, int s, int t, int[] parent) { + final boolean[] visited = new boolean[n]; + final Queue queue = new LinkedList<>() {{ add(s); }}; + visited[s] = true; + + while (!queue.isEmpty()) { + int u = queue.poll(); + for (int i = 0 ; i < n ; i++) { + final int value = adj_matrix[u][i]; + if (!visited[i] && value > 0) { + queue.add(i); + visited[i] = true; + parent[i] = u; + } + } + } + + return visited[t]; + } +} diff --git a/src/HelloWorld.java b/src/HelloWorld.java index 1a3efa4..c4bf421 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -1,32 +1,31 @@ -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.PriorityQueue; -import java.util.Queue; -import java.util.Set; - public class HelloWorld { - public List> combinationSum(int[] candidates, int target) { - final Set> result = new HashSet<>(); - computeSums(candidates, target, result, 0, new ArrayList<>(), 0); - return new ArrayList<>(result); + public int search(int[] nums, int target) { + final int pivotIndex = binarySearchPivotIndex(nums); + final int answer = binarySearch(nums, 0, pivotIndex - 1, target); + if (answer != -1) { + return answer; + } + return binarySearch(nums, pivotIndex, nums.length - 1, target); } - private static void computeSums(int[] candidates, int target, Set> result, int currentSum, List current, int i) { - if (currentSum > target || i >= candidates.length) { - return; - } - if (currentSum == target) { - result.add(new ArrayList<>(current)); - return; + private static int binarySearchPivotIndex(int[] array) { + int left = 0, right = array.length - 1, middle; + while (left <= right) { + middle = left + (right - left) / 2; + if (array[middle] > array[array.length - 1]) left = middle + 1; + else right = middle - 1; } + return left; + } - computeSums(candidates, target, result, currentSum, current, i + 1); - current.add(candidates[i]); - computeSums(candidates, target, result, currentSum + candidates[i], current, i); - computeSums(candidates, target, result, currentSum + candidates[i], current, i + 1); - current.removeLast(); + private static int binarySearch(int[] array, int start, int end, int x) { + int left = start, right = end, middle; + while (left <= right) { + middle = left + (right - left) / 2; + if (array[middle] == x) return middle; + else if (array[middle] < x) left = middle + 1; + else right = middle - 1; + } + return -1; } -} \ No newline at end of file +} diff --git a/src/MedianOfTwoSortedArrays.java b/src/MedianOfTwoSortedArrays.java new file mode 100644 index 0000000..de4891b --- /dev/null +++ b/src/MedianOfTwoSortedArrays.java @@ -0,0 +1,34 @@ +// https://leetcode.com/problems/median-of-two-sorted-arrays + +public class MedianOfTwoSortedArrays { + static public double findMedianSortedArrays(int[] nums1, int[] nums2) { + final int[] array = merge(nums1, nums2); + if (array.length % 2 == 1) { + return array[array.length / 2]; + } + return ((double) array[array.length / 2 - 1] + array[array.length / 2]) / 2; + } + + private static int[] merge(int[] array1, int[] array2) { + final int[] result = new int[array1.length + array2.length]; + int i = 0, j = 0, k = 0; + + while (i < array1.length && j < array2.length) { + if (array1[i] <= array2[j]) { + result[k++] = array1[i++]; + } else { + result[k++] = array2[j++]; + } + } + + while (i < array1.length) { + result[k++] = array1[i++]; + } + + while (j < array2.length) { + result[k++] = array2[j++]; + } + + return result; + } +} diff --git a/src/SearchInRotatedSortedArray.java b/src/SearchInRotatedSortedArray.java index f689436..971e701 100644 --- a/src/SearchInRotatedSortedArray.java +++ b/src/SearchInRotatedSortedArray.java @@ -1,28 +1,35 @@ // https://leetcode.com/problems/search-in-rotated-sorted-array // T: O(logN) -// SL O(1) +// S: O(1) public class SearchInRotatedSortedArray { - int search(int[] array, int target) { - final int shift = minElementIndex(array); - int left = 0, right = array.length - 1, middle, realMiddle; - while (left <= right) { - middle = (left + right) / 2; - realMiddle = (middle + shift) % array.length; - if(array[realMiddle] == target) return realMiddle; - if(array[realMiddle] < target) left = middle + 1; - else right = middle - 1; + public int search(int[] nums, int target) { + final int pivotIndex = binarySearchPivotIndex(nums); + final int answer = binarySearch(nums, 0, pivotIndex - 1, target); + if (answer != -1) { + return answer; } - return -1; + return binarySearch(nums, pivotIndex, nums.length - 1, target); } - private int minElementIndex(int[] array) { + private static int binarySearchPivotIndex(int[] array) { int left = 0, right = array.length - 1, middle; - while(left < right){ - middle = (left + right) / 2; - if(array[middle] > array[right]) left = middle + 1; - else right = middle; + while (left <= right) { + middle = left + (right - left) / 2; + if (array[middle] > array[array.length - 1]) left = middle + 1; + else right = middle - 1; } return left; } + + private static int binarySearch(int[] array, int start, int end, int x) { + int left = start, right = end, middle; + while (left <= right) { + middle = left + (right - left) / 2; + if (array[middle] == x) return middle; + else if (array[middle] < x) left = middle + 1; + else right = middle - 1; + } + return -1; + } } From 6c3753fe8698b7a12981a9b00cd5b4606d90b48d Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 1 Aug 2024 18:30:18 +0200 Subject: [PATCH 265/280] solves Find K Closest Elements in java --- README.md | 1 + src/FindKClosestElements.java | 45 ++++++++++++++++++++++++ src/FindMinimumInRotatedSortedArray.java | 24 ++++++------- src/FindPeakElement.java | 22 +++++------- src/HelloWorld.java | 35 +++++++++++------- 5 files changed, 87 insertions(+), 40 deletions(-) create mode 100644 src/FindKClosestElements.java diff --git a/README.md b/README.md index 827d6b4..0290546 100644 --- a/README.md +++ b/README.md @@ -381,6 +381,7 @@ | 645 | [Set Mismatch](https://leetcode.com/problems/set-mismatch) | [![Java](assets/java.png)](src/SetMismatch.java) [![Python](assets/python.png)](python/set_mismatch.py) | | | 653 | [Two Sum IV - Input is a BST](https://leetcode.com/problems/two-sum-iv-input-is-a-bst) | [![Java](assets/java.png)](src/TwoSumIVInputIsABST.java) [![Python](assets/python.png)](python/two_sum_iv.py) | | | 657 | [Robot Return to Origin](https://leetcode.com/problems/robot-return-to-origin) | [![Java](assets/java.png)](src/RobotReturnToOrigin.java) [![Python](assets/python.png)](python/robot_return_to_origin.py) | | +| 658 | [Find K Closest Elements](https://leetcode.com/problems/find-k-closest-elements) | [![Java](assets/java.png)](src/FindKClosestElements.java) | | | 661 | [Image Smoother](https://leetcode.com/problems/image-smoother) | [![Java](assets/java.png)](src/ImageSmoother.java) [![Python](assets/python.png)](python/image_smoother.py) | | | 665 | [Non Deceasing Array](https://leetcode.com/problems/non-decreasing-array) | [![Java](assets/java.png)](src/NonDecreasingArray.java) [![Python](assets/python.png)](python/non_decreasing_array.py) | | | 669 | [Trim a Binary Search Tree](https://leetcode.com/problems/trim-a-binary-search-tree) | [![Java](assets/java.png)](src/TrimABinarySearchTree.java) [![Python](assets/python.png)](python/trim_a_binary_search_tree.py) | | diff --git a/src/FindKClosestElements.java b/src/FindKClosestElements.java new file mode 100644 index 0000000..6ffa54b --- /dev/null +++ b/src/FindKClosestElements.java @@ -0,0 +1,45 @@ +// https://leetcode.com/problems/find-k-closest-elements +// T: O(logN + KLogK) +// S: O(logK) + +import java.util.ArrayList; +import java.util.List; + +public class FindKClosestElements { + public static List findClosestElements(int[] array, int k, int x) { + final int index = binarySearch(array, x); + final List result = new ArrayList<>(); + + for (int left = index - 1, right = index ; k > 0 ; k--) { + if (left == -1) { + result.add(array[right++]); + } else if (right == array.length) { + result.add(array[left--]); + } else { + if (Math.abs(array[left] - x) <= Math.abs(array[right] - x)) { + result.add(array[left--]); + } else { + result.add(array[right++]); + } + } + } + + result.sort(Integer::compareTo); + return result; + } + + private static int binarySearch(int[] array, int x) { + int left = 0, right = array.length - 1, middle; + while (left <= right) { + middle = left + (right - left) / 2; + if (array[middle] == x) return middle; + else if (array[middle] < x) left = middle + 1; + else right = middle - 1; + } + return left; + } + + public static void main(String[] args) { + System.out.println(findClosestElements(new int[] {}, 3, 5)); + } +} diff --git a/src/FindMinimumInRotatedSortedArray.java b/src/FindMinimumInRotatedSortedArray.java index 7965aea..ba9cdad 100644 --- a/src/FindMinimumInRotatedSortedArray.java +++ b/src/FindMinimumInRotatedSortedArray.java @@ -3,21 +3,17 @@ // T: O(1) public class FindMinimumInRotatedSortedArray { - public int findMin(int[] array) { - if (!isRotated(array)) return array[0]; - - for (int left = 0, right = array.length - 1 ; left <= right ; ) { - int middle = left + (right - left) / 2; - if (array[middle] > array[middle + 1]) return array[middle + 1]; - if (array[middle] < array[middle - 1]) return array[middle]; - - if (array[middle] < array[array.length - 1]) right = middle - 1; - else left = middle + 1; - } - return -1; + public int findMin(int[] nums) { + return nums[binarySearchPivotIndex(nums)]; } - private boolean isRotated(int[] array) { - return array[0] > array[array.length - 1]; + private static int binarySearchPivotIndex(int[] array) { + int left = 0, right = array.length - 1, middle; + while (left <= right) { + middle = left + (right - left) / 2; + if (array[middle] > array[array.length - 1]) left = middle + 1; + else right = middle - 1; + } + return left; } } diff --git a/src/FindPeakElement.java b/src/FindPeakElement.java index 57e2505..886a192 100644 --- a/src/FindPeakElement.java +++ b/src/FindPeakElement.java @@ -3,25 +3,19 @@ // S: O(1) public class FindPeakElement { - public static int findPeakElement(int[] array) { - for (int left = 0, right = array.length - 1, middle ; left <= right ; ) { + public int findPeakElement(int[] nums) { + int left = 0, right = nums.length - 1, middle; + while (left <= right) { middle = left + (right - left) / 2; - - if (isPeakElement(array, middle)) return middle; - - if (isOnIncreasingSlope(array, middle)) left = middle + 1; + if (isPeak(nums, middle)) return middle; + else if (middle + 1 < nums.length && nums[middle] < nums[middle + 1]) left = middle + 1; else right = middle - 1; } return -1; } - private static boolean isOnIncreasingSlope(int[] array, int index) { - return ((index > 0 && array[index - 1] < array[index]) || index == 0) - && ((index + 1 < array.length && array[index] < array[index + 1]) || index == array.length - 1); - } - - private static boolean isPeakElement(int[] array, int index) { - return ((index > 0 && array[index - 1] < array[index]) || index == 0) - && ((index + 1 < array.length && array[index + 1] < array[index]) || index == array.length - 1); + private static boolean isPeak(int[] array, int x) { + return (x - 1 < 0 || array[x - 1] < array[x]) + && (x + 1 >= array.length || array[x] > array[x + 1]); } } diff --git a/src/HelloWorld.java b/src/HelloWorld.java index c4bf421..e867406 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -1,28 +1,39 @@ public class HelloWorld { - public int search(int[] nums, int target) { - final int pivotIndex = binarySearchPivotIndex(nums); - final int answer = binarySearch(nums, 0, pivotIndex - 1, target); - if (answer != -1) { - return answer; + public int[] searchRange(int[] nums, int target) { + if (nums.length == 0) { + return new int[] {-1, -1}; } - return binarySearch(nums, pivotIndex, nums.length - 1, target); + + return new int[] { + leftBinarySearch(nums, target), + rightBinarySearch(nums, target) + }; } - private static int binarySearchPivotIndex(int[] array) { + private static int leftBinarySearch(int[] array, int x) { int left = 0, right = array.length - 1, middle; while (left <= right) { middle = left + (right - left) / 2; - if (array[middle] > array[array.length - 1]) left = middle + 1; + if (array[middle] == x) { + if (middle - 1 >= 0 && array[middle - 1] == x) { + right = middle - 1; + } else return middle; + } + else if (array[middle] < x) left = middle + 1; else right = middle - 1; } - return left; + return -1; } - private static int binarySearch(int[] array, int start, int end, int x) { - int left = start, right = end, middle; + private static int rightBinarySearch(int[] array, int x) { + int left = 0, right = array.length - 1, middle; while (left <= right) { middle = left + (right - left) / 2; - if (array[middle] == x) return middle; + if (array[middle] == x) { + if (middle + 1 < array.length && array[middle + 1] == x) { + left = middle + 1; + } else return middle; + } else if (array[middle] < x) left = middle + 1; else right = middle - 1; } From e57910c207e90373174f830889ebafccd62106ab Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 1 Aug 2024 18:39:21 +0200 Subject: [PATCH 266/280] solves #270: Closes binary search tree value in java --- README.md | 2 +- src/ClosestBinaryTreeSearchValue.java | 36 +++++++++++++++++++++++++++ src/FindKClosestElements.java | 4 --- 3 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 src/ClosestBinaryTreeSearchValue.java diff --git a/README.md b/README.md index 0290546..56b99a0 100644 --- a/README.md +++ b/README.md @@ -235,7 +235,7 @@ | 267 | 🔒 [Palindrome Permutation II](https://leetcode.com/problems/palindrome-permutation-ii) | | | | 268 | [Missing Number](https://leetcode.com/problems/missing-number) | [![Java](assets/java.png)](src/MissingNumber.java) [![Python](assets/python.png)](python/missing_number.py) | | | 269 | [Alien Dictionary](https://leetcode.com/problems/alien-dictionary) | [![Java](assets/java.png)](src/AlienDictionary.java) | | -| 270 | 🔒 [Closest Binary Search Tree Value](https://leetcode.com/problems/closest-binary-search-tree-value) | | | +| 270 | 🔒 [Closest Binary Search Tree Value](https://leetcode.com/problems/closest-binary-search-tree-value) | [![Java](assets/java.png)](src/ClosestBinaryTreeSearchValue.java) | | | 271 | 🔒 [Encode and Decode Strings](https://leetcode.com/problems/encode-and-decode-strings) | | | | 274 | [H-Index](https://leetcode.com/problems/h-index) | [![Java](assets/java.png)](src/HIndex.java) | | | 275 | [H-Index II](https://leetcode.com/problems/h-index-ii) | [![Java](assets/java.png)](src/HIndexII.java) | | diff --git a/src/ClosestBinaryTreeSearchValue.java b/src/ClosestBinaryTreeSearchValue.java new file mode 100644 index 0000000..3135f3c --- /dev/null +++ b/src/ClosestBinaryTreeSearchValue.java @@ -0,0 +1,36 @@ +// https://leetcode.com/problems/closest-binary-search-tree-value +// T: O(logN) +// S: O(logN) + +public class ClosestBinaryTreeSearchValue { + private static int result = Integer.MAX_VALUE; + + public int closestValue(TreeNode root, double target) { + result = Integer.MAX_VALUE; + computeClosestValue(root, target); + return result; + } + + private static void computeClosestValue(TreeNode root, double target) { + if (root == null) { + return; + } + + if (root.val == target) { + result = root.val; + return; + } + + if (Math.abs(root.val - target) == Math.abs(result - target) && root.val < result) { + result = root.val; + } else if (Math.abs(root.val - target) < Math.abs(result - target)) { + result = root.val; + } + + if (root.val < target) { + computeClosestValue(root.right, target); + } else { + computeClosestValue(root.left, target); + } + } +} diff --git a/src/FindKClosestElements.java b/src/FindKClosestElements.java index 6ffa54b..8d9f5b0 100644 --- a/src/FindKClosestElements.java +++ b/src/FindKClosestElements.java @@ -38,8 +38,4 @@ private static int binarySearch(int[] array, int x) { } return left; } - - public static void main(String[] args) { - System.out.println(findClosestElements(new int[] {}, 3, 5)); - } } From ec76554a3376aef945baac187016d685385ad0f7 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 1 Aug 2024 18:47:22 +0200 Subject: [PATCH 267/280] solves #702: Search in sorted array of unknown size in java --- README.md | 1 + src/SearchInSortedArrayOfUnknownSize.java | 26 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 src/SearchInSortedArrayOfUnknownSize.java diff --git a/README.md b/README.md index 56b99a0..22998d4 100644 --- a/README.md +++ b/README.md @@ -398,6 +398,7 @@ | 696 | [Count Binary Substrings](https://leetcode.com/problems/count-binary-substrings) | [![Java](assets/java.png)](src/CountBinarySubstrings.java) [![Python](assets/python.png)](python/count_binary_substrings.py) | | | 697 | [Degree of an Array](https://leetcode.com/problems/degree-of-an-array) | [![Java](assets/java.png)](src/DegreeOfAnArray.java) [![Python](assets/python.png)](python/degree_of_an_array.py) | | | 700 | [Search in a Binary Search Tree](https://leetcode.com/problems/search-in-a-binary-search-tree) | [![Java](assets/java.png)](src/SearchInBinarySearchTree.java) [![Python](assets/python.png)](python/search_in_binary_search_tree.py) | | +| 702 | [Search In A Sorted Array of Unknown Size](https://leetcode.com/problems/search-in-a-sorted-array-of-unknown-size) | [![Java](assets/java.png)](src/SearchInSortedArrayOfUnknownSize.java) | | | 703 | [Kth Largest Element in a Stream](https://leetcode.com/problems/kth-largest-element-in-a-stream) | [![Java](assets/java.png)](src/KthLargestElementInAStream.java) [![Python](assets/python.png)](python/k_th_largest_element_in_a_stream.py) | | | 704 | [Binary Search](https://leetcode.com/problems/binary-search) | [![Java](assets/java.png)](src/BinarySearch.java) [![Python](assets/python.png)](python/binary_search.py) | | | 705 | [Design HashSet](https://leetcode.com/problems/design-hashset) | [![Java](assets/java.png)](src/DesignHashSet.java) [![Python](assets/python.png)](python/design_hash_set.py) | | diff --git a/src/SearchInSortedArrayOfUnknownSize.java b/src/SearchInSortedArrayOfUnknownSize.java new file mode 100644 index 0000000..f6d3389 --- /dev/null +++ b/src/SearchInSortedArrayOfUnknownSize.java @@ -0,0 +1,26 @@ +// https://leetcode.com/problems/search-in-a-sorted-array-of-unknown-size +// T: O(logN) +// S: O(1) + +public class SearchInSortedArrayOfUnknownSize { + public interface ArrayReader { + int get(int index); + } + + public int search(ArrayReader reader, int target) { + int left = 0, right = 1, middle; + + while (reader.get(right) < target) { + left = right; + right *= 2; + } + + while (left <= right) { + middle = left + (right - left) / 2; + if (reader.get(middle) == target) return middle; + else if (reader.get(middle) < target) left = middle + 1; + else right = middle - 1; + } + return -1; + } +} From 88b06571a77591fc06e6c26ea5eb1b2656ceb9b3 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 30 Sep 2024 15:23:01 +0200 Subject: [PATCH 268/280] a --- README.md | 2 +- src/MedianOfTwoSortedArrays.java | 2 ++ src/{IsPerfectSquare.java => ValidPerfectSquare.java} | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) rename src/{IsPerfectSquare.java => ValidPerfectSquare.java} (91%) diff --git a/README.md b/README.md index 22998d4..dd48daa 100644 --- a/README.md +++ b/README.md @@ -301,7 +301,7 @@ | 355 | [Design Twitter](https://leetcode.com/problems/design-twitter) | | | | 357 | [Count Numbers with Unique Digits](https://leetcode.com/problems/count-numbers-with-unique-digits) | | | | 359 | 🔒 [Logger Rate Limiter](https://leetcode.com/problems/logger-rate-limiter) | | | -| 367 | [Valid Perfect Square](https://leetcode.com/problems/valid-perfect-square) | [![Java](assets/java.png)](src/IsPerfectSquare.java) [![Python](assets/python.png)](python/valid_perfect_square.py) | | +| 367 | [Valid Perfect Square](https://leetcode.com/problems/valid-perfect-square) | [![Java](assets/java.png)](src/ValidPerfectSquare.java) [![Python](assets/python.png)](python/valid_perfect_square.py) | | | 374 | [Guess Number Higher or Lower](https://leetcode.com/problems/guess-number-higher-or-lower) | [![Java](assets/java.png)](src/GuessNumberHigherOrLower.java) [![Python](assets/python.png)](python/guess_number_higher_or_lower.py) | | | 380 | [Insert Delete GetRandom O(1)](https://leetcode.com/problems/insert-delete-getrandom-o1) | [![Java](assets/java.png)](src/InsertDeleteGetRandomO1.java) | | | 383 | [Ransom Note](https://leetcode.com/problems/ransom-note) | [![Java](assets/java.png)](src/RansomNote.java) [![Python](assets/python.png)](python/ransom_note.py) | | diff --git a/src/MedianOfTwoSortedArrays.java b/src/MedianOfTwoSortedArrays.java index de4891b..0622582 100644 --- a/src/MedianOfTwoSortedArrays.java +++ b/src/MedianOfTwoSortedArrays.java @@ -1,4 +1,6 @@ // https://leetcode.com/problems/median-of-two-sorted-arrays +// T: O(m + n) +// S: O(m + n) public class MedianOfTwoSortedArrays { static public double findMedianSortedArrays(int[] nums1, int[] nums2) { diff --git a/src/IsPerfectSquare.java b/src/ValidPerfectSquare.java similarity index 91% rename from src/IsPerfectSquare.java rename to src/ValidPerfectSquare.java index 2ce8973..ef42b4d 100644 --- a/src/IsPerfectSquare.java +++ b/src/ValidPerfectSquare.java @@ -1,4 +1,4 @@ -public class IsPerfectSquare { +public class ValidPerfectSquare { public static boolean isPerfectSquare(long number) { long left = 0, right = number, mid; while (left <= right) { From 59c35f00dc4f3faa41a2a1eb5c6891982249f6e7 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 30 Sep 2024 15:32:29 +0200 Subject: [PATCH 269/280] solves #157: Read N Characters Given Read 4 in java --- README.md | 2 +- src/ReadNCharactersGivenRead4.java | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/ReadNCharactersGivenRead4.java diff --git a/README.md b/README.md index dd48daa..635a55e 100644 --- a/README.md +++ b/README.md @@ -151,7 +151,7 @@ | 153 | [Find Minimum in Rotated Sorted Array](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array) | [![Java](assets/java.png)](src/FindMinimumInRotatedSortedArray.java) | | | 155 | [Min Stack](https://leetcode.com/problems/min-stack) | [![Java](assets/java.png)](src/MinStack.java) [![Python](assets/python.png)](python/min_stack.py) | | | 156 | 🔒 [Binary Tree Upside Down](https://leetcode.com/problems/binary-tree-upside-down) | | | -| 157 | [Read N Characters Given Read4](https://leetcode.com/problems/read-n-characters-given-read4) | | | +| 157 | 🔒 [Read N Characters Given Read4](https://leetcode.com/problems/read-n-characters-given-read4) | [![Java](assets/java.png)](src/ReadNCharactersGivenRead4java) | | | 159 | 🔒 [Longest Substring With At Most Two Distinct Characters](https://leetcode.com/problems/longest-substring-with-at-most-two-distinct-characters) | | | | 160 | [Intersection of Two Linked Lists](https://leetcode.com/problems/intersection-of-two-linked-lists) | [![Java](assets/java.png)](src/IntersectionOf2LinkedLists.java) [![Python](assets/python.png)](python/intersecction_of_two_linked_lists.py) | | | 161 | 🔒 [One Edit Distance](https://leetcode.com/problems/one-edit-distance) | | | diff --git a/src/ReadNCharactersGivenRead4.java b/src/ReadNCharactersGivenRead4.java new file mode 100644 index 0000000..bbcbca0 --- /dev/null +++ b/src/ReadNCharactersGivenRead4.java @@ -0,0 +1,29 @@ +// https://leetcode.com/problems/read-n-characters-given-read4 +// T: O(N) +// S: O(1) + +public class ReadNCharactersGivenRead4 { + static class Reader4 { + public int read4(char[] buffer) { + return 0; + } + } + + static class Solution extends Reader4 { + public int read(char[] buf, int n) { + int copiedChars = 0, readChars = 4; + char[] buf4 = new char[4]; + + while (copiedChars < n && readChars == 4) { + readChars = read4(buf4); + + for (int i = 0; i < readChars; ++i) { + if (copiedChars == n) return copiedChars; + buf[copiedChars] = buf4[i]; + ++copiedChars; + } + } + return copiedChars; + } + } +} From 0f69c55d836edd6f16b55b96d9d769faca2ac40c Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 30 Sep 2024 15:44:22 +0200 Subject: [PATCH 270/280] solves #163: Missing ranges in java --- README.md | 1 + src/MissingRanges.java | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/MissingRanges.java diff --git a/README.md b/README.md index 635a55e..049ae80 100644 --- a/README.md +++ b/README.md @@ -156,6 +156,7 @@ | 160 | [Intersection of Two Linked Lists](https://leetcode.com/problems/intersection-of-two-linked-lists) | [![Java](assets/java.png)](src/IntersectionOf2LinkedLists.java) [![Python](assets/python.png)](python/intersecction_of_two_linked_lists.py) | | | 161 | 🔒 [One Edit Distance](https://leetcode.com/problems/one-edit-distance) | | | | 162 | [Find Peak Element](https://leetcode.com/problems/find-peak-element) | [![Java](assets/java.png)](src/FindPeakElement.java) | | +| 163 | [Missing Ranges](https://leetcode.com/problems/missing-ranges) | [![Java](assets/java.png)](src/MissingRanges.java) | | | 164 | [Maximum Gap](https://leetcode.com/problems/maximum-gap) | | | | 165 | [Compare Version Numbers](https://leetcode.com/problems/compare-version-numbers) | [![Java](assets/java.png)](src/CompareVersionNumbers.java) | | | 166 | [Fraction to Recurring Decimal](https://leetcode.com/problems/fraction-to-recurring-decimal) | [![Java](assets/java.png)](src/FractionToRecurringDecimal.java) | | diff --git a/src/MissingRanges.java b/src/MissingRanges.java new file mode 100644 index 0000000..7a41bd3 --- /dev/null +++ b/src/MissingRanges.java @@ -0,0 +1,28 @@ +// https://leetcode.com/problems/missing-ranges +// T: O(N) +// S: O(N) + +import java.util.ArrayList; +import java.util.List; + +public class MissingRanges { + public List> findMissingRanges(int[] nums, int lower, int upper) { + if (nums.length == 0) { + return List.of(List.of(lower, upper)); + } + + final List> result = new ArrayList<>(); + if (lower != nums[0]) { + result.add(List.of(lower, nums[0] - 1)); + } + for (int i = 0 ; i < nums.length - 1 ; i++) { + if (nums[i + 1] - nums[i] > 1) { + result.add(List.of(nums[i] + 1, nums[i + 1] - 1)); + } + } + if (nums[nums.length - 1] != upper) { + result.add(List.of(nums[nums.length - 1] + 1, upper)); + } + return result; + } +} From 2cb17d013fb10e5b93cf832e7b091eb14a5745fa Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 30 Sep 2024 15:53:20 +0200 Subject: [PATCH 271/280] solves #170: Two Sum III: Data structure design --- README.md | 2 +- src/TwoSumIIIDataStructureDesign.java | 34 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/TwoSumIIIDataStructureDesign.java diff --git a/README.md b/README.md index 049ae80..44fc95b 100644 --- a/README.md +++ b/README.md @@ -163,7 +163,7 @@ | 167 | [Two Sum II - Input Array is Sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted) | [![Java](assets/java.png)](src/TwoSumIIInputArrayIsSorted.java) [![Python](assets/python.png)](python/two_sum_ii.py) | | | 168 | [Excel Sheet Column Title](https://leetcode.com/problems/excel-sheet-column-title) | [![Java](assets/java.png)](src/ExcelSheetColumnTitle.java) [![Python](assets/python.png)](python/excel_sheet_column_title.py) | | | 169 | [Majority Element](https://leetcode.com/problems/majority-element) | [![Java](assets/java.png)](src/MajorityElement.java) [![Python](assets/python.png)](python/majority_element.py) | | -| 170 | 🔒 [Two Sum III - Data Structure Design](https://leetcode.com/problems/two-sum-iii-data-structure-design) | | | +| 170 | 🔒 [Two Sum III - Data Structure Design](https://leetcode.com/problems/two-sum-iii-data-structure-design) | [![Java](assets/java.png)](src/TwoSumIIIDataStructureDesign.java) | | | 171 | [Excel Sheet Column Number](https://leetcode.com/problems/excel-sheet-column-number) | [![Java](assets/java.png)](src/ExcelSheetColumnNumber.java) [![Python](assets/python.png)](python/excel_sheet_column_number.py) | | | 172 | [Factoring Trailing Zeroes](https://leetcode.com/problems/factorial-trailing-zeroes) | [![Java](assets/java.png)](src/FactorialTrailingZeros.java) [![Python](assets/python.png)](python/factorial_trailing_zeroes.py) | | | 173 | [Binary Search Tree Iterator](https://leetcode.com/problems/binary-search-tree-iterator) | [![Java](assets/java.png)](src/BinarySearchTreeIterator.java) | | diff --git a/src/TwoSumIIIDataStructureDesign.java b/src/TwoSumIIIDataStructureDesign.java new file mode 100644 index 0000000..637824d --- /dev/null +++ b/src/TwoSumIIIDataStructureDesign.java @@ -0,0 +1,34 @@ +import java.util.HashMap; +import java.util.Map; + +public class TwoSumIIIDataStructureDesign { + static class TwoSum { + private final Map map = new HashMap<>(); + + // T: O(1) + public void add(int number) { + map.put(number, map.getOrDefault(number, 0) + 1); + } + + // N: number of unique elements we have seen so far + // T: O(N) + public boolean find(int sum) { + for (int current : map.keySet()) { + final int required = sum - current; + if (required == current) { + if (map.get(required) >= 2) { + return true; + } else { + continue; + } + } + + if (map.containsKey(required)) { + return true; + } + } + + return false; + } + } +} From b4f3197b0e20f2d82e853bc61985e4577afeed8b Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 30 Sep 2024 16:10:21 +0200 Subject: [PATCH 272/280] solves #243: Shortest Word Distance --- README.md | 2 +- src/ShortestWordDistance.java | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/ShortestWordDistance.java diff --git a/README.md b/README.md index 44fc95b..499b83e 100644 --- a/README.md +++ b/README.md @@ -212,7 +212,7 @@ | 240 | [Search a 2D Matrix II](https://leetcode.com/problems/search-a-2d-matrix-ii) | [![Java](assets/java.png)](src/SearchA2DMatrixII.java) | | | 241 | [Different Ways to Add Parentheses](https://leetcode.com/problems/different-ways-to-add-parentheses) | | | | 242 | [Valid Anagram](https://leetcode.com/problems/valid-anagram) | [![Java](assets/java.png)](src/ValidAnagram.java) [![Python](assets/python.png)](python/delete_node_in_linked_list.py) | | -| 243 | 🔒 [Shortest Word Distance](https://leetcode.com/problems/shortest-word-distance) | | | +| 243 | 🔒 [Shortest Word Distance](https://leetcode.com/problems/shortest-word-distance) | [![Java](assets/java.png)](src/ShortestWordDistance.java) | | | 244 | 🔒 [Shortest Word Distance II](https://leetcode.com/problems/shortest-word-distance-ii) | | | | 245 | 🔒 [Shortest Word Distance III](https://leetcode.com/problems/shortest-word-distance-iii) | | | | 246 | 🔒 [Strobogramatic Number](https://leetcode.com/problems/strobogrammatic-number) | | | diff --git a/src/ShortestWordDistance.java b/src/ShortestWordDistance.java new file mode 100644 index 0000000..bca102e --- /dev/null +++ b/src/ShortestWordDistance.java @@ -0,0 +1,22 @@ +// https://leetcode.com/problems/shortest-word-distance +// N: number of words, M: average word length +// T: O(N * M) +// S: O(1) + +public class ShortestWordDistance { + public int shortestDistance(String[] wordsDict, String word1, String word2) { + int result = wordsDict.length, i = -1, j = -1; + for (int index = 0 ; index < wordsDict.length ; index++) { + if (wordsDict[index].equals(word1)) { + i = index; + } else if (wordsDict[index].equals(word2)) { + j = index; + } + + if (i != -1 && j != -1) { + result = Math.min(result, Math.abs(j - i)); + } + } + return result; + } +} From 26ca7948c408522034fe551741559df767c4b131 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 30 Sep 2024 18:43:35 +0200 Subject: [PATCH 273/280] solves #246: Strobogrammatic Number in java --- README.md | 4 ++-- src/StrobogrammaticNumber.java | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 src/StrobogrammaticNumber.java diff --git a/README.md b/README.md index 499b83e..d56a216 100644 --- a/README.md +++ b/README.md @@ -215,8 +215,8 @@ | 243 | 🔒 [Shortest Word Distance](https://leetcode.com/problems/shortest-word-distance) | [![Java](assets/java.png)](src/ShortestWordDistance.java) | | | 244 | 🔒 [Shortest Word Distance II](https://leetcode.com/problems/shortest-word-distance-ii) | | | | 245 | 🔒 [Shortest Word Distance III](https://leetcode.com/problems/shortest-word-distance-iii) | | | -| 246 | 🔒 [Strobogramatic Number](https://leetcode.com/problems/strobogrammatic-number) | | | -| 247 | 🔒 [Strobogramatic Number II](https://leetcode.com/problems/strobogrammatic-number-ii) | | | +| 246 | 🔒 [Strobogrammatic Number](https://leetcode.com/problems/strobogrammatic-number) | [![Java](assets/java.png)](src/StrobogrammaticNumber.java) | | +| 247 | 🔒 [Strobogrammatic Number II](https://leetcode.com/problems/strobogrammatic-number-ii) | | | | 249 | 🔒 [Group Shifted Strings](https://leetcode.com/problems/group-shifted-strings) | | | | 250 | 🔒 [Count Univalue Subtrees](https://leetcode.com/problems/count-univalue-subtrees) | | | | 251 | 🔒 [Flatten 2D Vector](https://leetcode.com/problems/flatten-2d-vector) | | | diff --git a/src/StrobogrammaticNumber.java b/src/StrobogrammaticNumber.java new file mode 100644 index 0000000..1292ba0 --- /dev/null +++ b/src/StrobogrammaticNumber.java @@ -0,0 +1,30 @@ +// https://leetcode.com/problems/strobogrammatic-number +// T: O(N) +// S: O(1) + +import java.util.HashMap; +import java.util.Map; + +// Strobogrammatic digits: 0, 1, 8 +// Strobogrammatic interchangeable digits: 6 --> 9, 9 --> 6 +public class StrobogrammaticNumber { + private static final Map STROBOGRAMMATIC_MIRROR = new HashMap<>() {{ + put('0', '0'); + put('1', '1'); + put('6', '9'); + put('8', '8'); + put('9', '6'); + }}; + + public boolean isStrobogrammatic(String number) { + for (int i = 0 ; i < number.length() ; i++) { + final char digit = number.charAt(i); + if (!STROBOGRAMMATIC_MIRROR.containsKey(digit) + || STROBOGRAMMATIC_MIRROR.get(digit) != number.charAt(number.length() - 1 - i) + ) { + return false; + } + } + return true; + } +} From 505b08bde636a828e875b9c9abe05efe1a3801e5 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 30 Sep 2024 18:48:59 +0200 Subject: [PATCH 274/280] solves #252: Meeting rooms in java --- README.md | 2 +- src/MeetingRooms.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/MeetingRooms.java diff --git a/README.md b/README.md index d56a216..acf3c10 100644 --- a/README.md +++ b/README.md @@ -220,7 +220,7 @@ | 249 | 🔒 [Group Shifted Strings](https://leetcode.com/problems/group-shifted-strings) | | | | 250 | 🔒 [Count Univalue Subtrees](https://leetcode.com/problems/count-univalue-subtrees) | | | | 251 | 🔒 [Flatten 2D Vector](https://leetcode.com/problems/flatten-2d-vector) | | | -| 252 | 🔒 [Meeting Rooms](https://leetcode.com/problems/meeting-rooms) | | | +| 252 | 🔒 [Meeting Rooms](https://leetcode.com/problems/meeting-rooms) | [![Java](assets/java.png)](src/MeetingRooms.java) | | | 253 | 🔒 [Meeting Rooms II](https://leetcode.com/problems/meeting-rooms-ii) | | | | 254 | 🔒 [Factor Combinations](https://leetcode.com/problems/factor-combinations) | | | | 255 | 🔒 [Verify Preorder Sequence In Binary Search Tree](https://leetcode.com/problems/verify-preorder-sequence-in-binary-search-tree) | | | diff --git a/src/MeetingRooms.java b/src/MeetingRooms.java new file mode 100644 index 0000000..a608cb2 --- /dev/null +++ b/src/MeetingRooms.java @@ -0,0 +1,18 @@ +// https://leetcode.com/problems/meeting-rooms +// T: O(N logN) +// S: O(logN) + +import java.util.Arrays; +import java.util.Comparator; + +public class MeetingRooms { + public boolean canAttendMeetings(int[][] intervals) { + Arrays.sort(intervals, Comparator.comparingInt(a -> a[0])); + for (int i = 0 ; i < intervals.length - 1 ; i++) { + if (intervals[i][1] > intervals[i + 1][0]) { + return false; + } + } + return true; + } +} From ac58f56ccc0d0a883dad385edeca683df9260617 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 30 Sep 2024 18:55:16 +0200 Subject: [PATCH 275/280] solves #266: solves Palindrome number in java --- README.md | 2 +- src/PalindromePermutation.java | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/PalindromePermutation.java diff --git a/README.md b/README.md index acf3c10..cba1839 100644 --- a/README.md +++ b/README.md @@ -232,7 +232,7 @@ | 261 | 🔒 [Graph Valid Tree](https://leetcode.com/problems/graph-valid-tree) | [![Java](assets/java.png)](src/GraphValidTree.java) | | | 263 | [Ugly Number](https://leetcode.com/problems/ugly-number) | [![Java](assets/java.png)](src/UglyNumber.java) [![Python](assets/python.png)](python/ugly_number.py) | | | 264 | [Ugly Number II](https://leetcode.com/problems/ugly-number-ii) | [![Java](assets/java.png)](src/UglyNumberII.java) | | -| 266 | 🔒 [Palindrome Permutation](https://leetcode.com/problems/palindrome-permutation) | | | +| 266 | 🔒 [Palindrome Permutation](https://leetcode.com/problems/palindrome-permutation) | [![Java](assets/java.png)](src/PalindromePermutation.java) | | | 267 | 🔒 [Palindrome Permutation II](https://leetcode.com/problems/palindrome-permutation-ii) | | | | 268 | [Missing Number](https://leetcode.com/problems/missing-number) | [![Java](assets/java.png)](src/MissingNumber.java) [![Python](assets/python.png)](python/missing_number.py) | | | 269 | [Alien Dictionary](https://leetcode.com/problems/alien-dictionary) | [![Java](assets/java.png)](src/AlienDictionary.java) | | diff --git a/src/PalindromePermutation.java b/src/PalindromePermutation.java new file mode 100644 index 0000000..91d8f6e --- /dev/null +++ b/src/PalindromePermutation.java @@ -0,0 +1,32 @@ +// https://leetcode.com/problems/palindrome-permutation +// T: O(|s|) +// S: O(|s|) + +import java.util.HashMap; +import java.util.Map; + +public class PalindromePermutation { + public boolean canPermutePalindrome(String s) { + final Map frequencies = getCharacterFrequencies(s); + return getNumberOfOddChars(frequencies) <= 1; + } + + private static Map getCharacterFrequencies(String string) { + final Map result = new HashMap<>(); + for (int i = 0 ; i < string.length() ; i++) { + final char c = string.charAt(i); + result.put(c, result.getOrDefault(c, 0) + 1); + } + return result; + } + + private static int getNumberOfOddChars(Map frequencies) { + int result = 0; + for (int freq : frequencies.values()) { + if (freq % 2 == 1) { + result++; + } + } + return result; + } +} From f5726c1358567bde4b9bb68ce7cb867cdde8ff59 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 30 Sep 2024 19:02:59 +0200 Subject: [PATCH 276/280] solves #293: flip game in java --- README.md | 2 +- src/FlipGame.java | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 src/FlipGame.java diff --git a/README.md b/README.md index cba1839..68d80a8 100644 --- a/README.md +++ b/README.md @@ -256,7 +256,7 @@ | 290 | [Word Pattern](https://leetcode.com/problems/word-pattern) | [![Java](assets/java.png)](src/WordPattern.java) [![Python](assets/python.png)](python/word_pattern.py) | | | 291 | 🔒 [Word Pattern II](https://leetcode.com/problems/word-pattern-ii) | | | | 292 | [Nim Game](https://leetcode.com/problems/nim-game) | [![Java](assets/java.png)](src/NimGame.java) [![Python](assets/python.png)](python/nim_game.py) | | -| 293 | 🔒 [Flip Game](https://leetcode.com/problems/flip-game) | | | +| 293 | 🔒 [Flip Game](https://leetcode.com/problems/flip-game) | [![Java](assets/java.png)](src/FlipGame.java) | | | 294 | 🔒 [Flip Game II](https://leetcode.com/problems/flip-game-ii) | | | | 298 | 🔒 [Binary Tree Longest Consecutive Sequence](https://leetcode.com/problems/binary-tree-longest-consecutive-sequence) | | | | 299 | [Bulls and Cows](https://leetcode.com/problems/bulls-and-cows) | [![Java](assets/java.png)](src/BullsAndCows.java) [![Python](assets/python.png)](python/bulls_and_cows.py) | | diff --git a/src/FlipGame.java b/src/FlipGame.java new file mode 100644 index 0000000..f301fd1 --- /dev/null +++ b/src/FlipGame.java @@ -0,0 +1,23 @@ +// https://leetcode.com/problems/flip-game +// N = |currentState| +// T: O(N^2) +// S: O(N^2) + +import java.util.ArrayList; +import java.util.List; + +public class FlipGame { + public List generatePossibleNextMoves(String currentState) { + final List result = new ArrayList<>(); + for (int i = 0 ; i < currentState.length() - 1 ; i++) { + if (currentState.charAt(i) == '+' && currentState.charAt(i + 1) == '+') { + result.add(flip(currentState, i)); + } + } + return result; + } + + private static String flip(String state, int index) { + return state.substring(0, index) + "--" + state.substring(index + 2); + } +} From cf51b3ce748462f68dee8ea0588c24190b200bb5 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 30 Sep 2024 19:19:49 +0200 Subject: [PATCH 277/280] solves #346: Moving Average from data stream in java --- README.md | 2 +- src/MovingAverageFromDataStream.java | 31 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/MovingAverageFromDataStream.java diff --git a/README.md b/README.md index 68d80a8..21e4b0a 100644 --- a/README.md +++ b/README.md @@ -293,7 +293,7 @@ | 343 | [Integer Break](https://leetcode.com/problems/integer-break) | | | | 344 | [Reverse A String](https://leetcode.com/problems/reverse-string) | [![Java](assets/java.png)](src/ReverseString.java) [![Python](assets/python.png)](python/reverse_a_string.py) | | | 345 | [Reverse Vowels of A String](https://leetcode.com/problems/reverse-vowels-of-a-string) | [![Java](assets/java.png)](src/ReverseVowelsOfString.java) [![Python](assets/python.png)](python/reverse_vowels_of_a_string.py) | | -| 346 | 🔒 [Moving Average From Data Stream](https://leetcode.com/problems/moving-average-from-data-stream) | | | +| 346 | 🔒 [Moving Average From Data Stream](https://leetcode.com/problems/moving-average-from-data-stream) | [![Java](assets/java.png)](src/MovingAverageFromDataStream.java) | | | 347 | [Top K frequent Elements](https://leetcode.com/problems/top-k-frequent-elements) | | | | 348 | 🔒 [Design Tic-Tac-Toe](https://leetcode.com/problems/design-tic-tac-toe) | | | | 349 | [Intersection of 2 Arrays](https://leetcode.com/problems/intersection-of-two-arrays) | [![Java](assets/java.png)](src/IntersectionOfTwoArrays.java) [![Python](assets/python.png)](python/intersection_of_2_array.py) | | diff --git a/src/MovingAverageFromDataStream.java b/src/MovingAverageFromDataStream.java new file mode 100644 index 0000000..f7a11d5 --- /dev/null +++ b/src/MovingAverageFromDataStream.java @@ -0,0 +1,31 @@ +// https://leetcode.com/problems/moving-average-from-data-stream +// N: number of calls to next(), M: max window size +// T: O(N) +// S: O(M) + +import java.util.LinkedList; +import java.util.Queue; + +public class MovingAverageFromDataStream { +} + + +class MovingAverage { + final int windowSize; + final Queue queue = new LinkedList<>(); + double windowSum = 0; + + // T: O(1) + public MovingAverage(int size) { + windowSize = size; + } + + // T: O(1) + // S: O(1) + public double next(int val) { + queue.add(val); + final int toRemove = (queue.size() > windowSize && !queue.isEmpty()) ? queue.poll() : 0; + windowSum += val - toRemove; + return windowSum / queue.size(); + } +} \ No newline at end of file From 4da0ba57b092463a1dd56425d7beee3a7ec27ccb Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 30 Sep 2024 19:26:03 +0200 Subject: [PATCH 278/280] solves #359: Logger rate limiter in java --- README.md | 2 +- src/LoggerRateLimiter.java | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/LoggerRateLimiter.java diff --git a/README.md b/README.md index 21e4b0a..bcf7874 100644 --- a/README.md +++ b/README.md @@ -301,7 +301,7 @@ | 351 | 🔒 [Android Unlock Patterns](https://leetcode.com/problems/android-unlock-patterns) | | | | 355 | [Design Twitter](https://leetcode.com/problems/design-twitter) | | | | 357 | [Count Numbers with Unique Digits](https://leetcode.com/problems/count-numbers-with-unique-digits) | | | -| 359 | 🔒 [Logger Rate Limiter](https://leetcode.com/problems/logger-rate-limiter) | | | +| 359 | 🔒 [Logger Rate Limiter](https://leetcode.com/problems/logger-rate-limiter) | [![Java](assets/java.png)](src/LoggerRateLimiter.java) | | | 367 | [Valid Perfect Square](https://leetcode.com/problems/valid-perfect-square) | [![Java](assets/java.png)](src/ValidPerfectSquare.java) [![Python](assets/python.png)](python/valid_perfect_square.py) | | | 374 | [Guess Number Higher or Lower](https://leetcode.com/problems/guess-number-higher-or-lower) | [![Java](assets/java.png)](src/GuessNumberHigherOrLower.java) [![Python](assets/python.png)](python/guess_number_higher_or_lower.py) | | | 380 | [Insert Delete GetRandom O(1)](https://leetcode.com/problems/insert-delete-getrandom-o1) | [![Java](assets/java.png)](src/InsertDeleteGetRandomO1.java) | | diff --git a/src/LoggerRateLimiter.java b/src/LoggerRateLimiter.java new file mode 100644 index 0000000..e657c64 --- /dev/null +++ b/src/LoggerRateLimiter.java @@ -0,0 +1,28 @@ +// https://leetcode.com/problems/logger-rate-limiter +// N: number of requests made to shouldPrint(), M: total number of different messages +// T: O(N) +// S: O(M) + +import java.util.HashMap; +import java.util.Map; + +public class LoggerRateLimiter { +} + +class Logger { + final Map messageTimestamps = new HashMap<>(); + + public boolean shouldPrintMessage(int timestamp, String message) { + if (!messageTimestamps.containsKey(message)) { + messageTimestamps.put(message, timestamp); + return true; + } + + if (messageTimestamps.get(message) + 10 > timestamp) { + return false; + } + + messageTimestamps.put(message, timestamp); + return true; + } +} \ No newline at end of file From c01129c706aab8123b9a5f2c1bdf33cc33ee1e63 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 1 Oct 2024 20:20:23 +0200 Subject: [PATCH 279/280] solves ##408: Valid word abbreviation in java --- README.md | 2 +- src/ValidWordAbbreviation.java | 35 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/ValidWordAbbreviation.java diff --git a/README.md b/README.md index bcf7874..2eaca81 100644 --- a/README.md +++ b/README.md @@ -313,7 +313,7 @@ | 401 | [Binary Watch](https://leetcode.com/problems/binary-watch) | [![Java](assets/java.png)](src/BinaryWatch.java) [![Python](assets/python.png)](python/binary_watch.py) | | | 404 | [Sum of Left Leaves](https://leetcode.com/problems/sum-of-left-leaves) | [![Java](assets/java.png)](src/SumOfLeftLeaves.java) [![Python](assets/python.png)](python/sum_of_left_leaves.py) | | | 405 | [Convert a Number to Hexadecimal](https://leetcode.com/problems/convert-a-number-to-hexadecimal) | [![Java](assets/java.png)](src/ConvertNumberToHexadecimal.java) [![Python](assets/python.png)](python/convert_a_number_to_hexadecimal.py) | | -| 408 | 🔒 [Valid Word Abbreviation](https://leetcode.com/problems/valid-word-abbreviation) | | | +| 408 | 🔒 [Valid Word Abbreviation](https://leetcode.com/problems/valid-word-abbreviation) | [![Java](assets/java.png)](src/ValidWordAbbreviation.java) | | | 409 | [Longest Palindrome](https://leetcode.com/problems/longest-palindrome) | [![Java](assets/java.png)](src/LongestPalindrome.java) [![Python](assets/python.png)](python/longest_palindrome.py) | | | 412 | [Fizz Buzz](https://leetcode.com/problems/fizz-buzz) | [![Java](assets/java.png)](src/FizzBuzz.java) [![Python](assets/python.png)](python/fizz_buzz.py) | | | 414 | [Third Maximum Number](https://leetcode.com/problems/third-maximum-number) | [![Java](assets/java.png)](src/ThirdMaximumNumber.java) [![Python](assets/python.png)](python/fizz_buzz.py) | | diff --git a/src/ValidWordAbbreviation.java b/src/ValidWordAbbreviation.java new file mode 100644 index 0000000..a2b826a --- /dev/null +++ b/src/ValidWordAbbreviation.java @@ -0,0 +1,35 @@ +// https://leetcode.com/problems/valid-word-abbreviation +// T: O(|word|) +// S: O(1) + +public class ValidWordAbbreviation { + public boolean validWordAbbreviation(String word, String abbr) { + if(abbr.length() > word.length()) { + return false; + } + + int i = 0, j = 0; + while(i < word.length() && j < abbr.length()) { + final char wc = word.charAt(i), ac = abbr.charAt(j); + // if both characters are different, return false + if(Character.isLetter(ac) && wc != ac) return false; + else{ + // encountering a digit + if(Character.isDigit(ac)){ + int a = ac - '0'; + if(a == 0) return false; + // while we get digits, we create bigger number + while(j + 1 < abbr.length() && Character.isDigit(abbr.charAt(j + 1))){ + a = a * 10 + abbr.charAt(j + 1) - '0'; + j++; + } + // jump i end of digits position + i += a - 1; + } + } + j++; + i++; + } + return i == word.length() && j == abbr.length(); + } +} From b990d84329f2dfea3267653c8cebe4655d5f6ba2 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 5 Nov 2024 15:26:59 +0100 Subject: [PATCH 280/280] adds leetcode questions in README --- README.md | 27 +++++++++-- src/HelloWorld.java | 108 +++++++++++++++++++++++++++++++++----------- 2 files changed, 104 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 2eaca81..d5aa028 100644 --- a/README.md +++ b/README.md @@ -412,6 +412,7 @@ | 724 | [Find Pivot Index](https://leetcode.com/problems/find-pivot-index) | [![Java](assets/java.png)](src/FindPivotIndex.java) [![Python](assets/python.png)](python/find_pivot_index.py) | | | 728 | [Self Dividing Numbers](https://leetcode.com/problems/self-dividing-numbers) | [![Java](assets/java.png)](src/SelfDividingNumbers.java) [![Python](assets/python.png)](python/self_dividing_number.py) | | | 733 | [Flood Fill](https://leetcode.com/problems/flood-fill) | [![Java](assets/java.png)](src/FloodFill.java) [![Python](assets/python.png)](python/flood_fill.py) | | +| 734 | 🔒 [Sentence Similarity](https://leetcode.com/problems/sentence-similarity) | | | | 743 | [Network Delay Time](https://leetcode.com/problems/network-delay-time) | [![Java](assets/java.png)](src/NetworkDelayTime.java) | | | 734 | [Sentence Similarity](https://leetcode.com/problems/sentence-similarity) | | | | 744 | [Find Smallest Letter Greater Than Target](https://leetcode.com/problems/find-smallest-letter-greater-than-target) | [![Java](assets/java.png)](src/FindSmallestLetterGreaterThanTarget.java) [![Python](assets/python.png)](python/find_smallest_letter_greater_than.py) | | @@ -419,7 +420,7 @@ | 747 | [Largest Number at least Twice of Others](https://leetcode.com/problems/largest-number-at-least-twice-of-others) | [![Java](assets/java.png)](src/LargestNumberAtLeastTwiceOfOthers.java) [![Python](assets/python.png)](python/largest_number_at_least_twice_of_others.py) | | | 748 | [Shortest Completing Word](https://leetcode.com/problems/shortest-completing-word) | [![Java](assets/java.png)](src/ShortestCompletingWord.java) [![Python](assets/python.png)](python/shortest_completing_word.py) | | | 758 | [Bold Words in String](https://leetcode.com/problems/bold-words-in-string) | | | -| 760 | [Find Anagram Mappings](https://leetcode.com/problems/find-anagram-mappings) | | | +| 760 | 🔒 [Find Anagram Mappings](https://leetcode.com/problems/find-anagram-mappings) | | | | 762 | [Prime Number of Set Bits in Primary Representation](https://leetcode.com/problems/prime-number-of-set-bits-in-binary-representation) | [![Java](assets/java.png)](src/PrimeNumberOfSetBitsInBinaryRepresentation.java) [![Python](assets/python.png)](python/prime_number_of_set_bits_in_binary_representation.py) | | | 766 | [Toeplitz Matrix](https://leetcode.com/problems/toeplitz-matrix) | [![Java](assets/java.png)](src/ToeplitzMatrix.java) [![Python](assets/python.png)](python/toeplitz_matrix.py) | | | 771 | [Jewels and Stones](https://leetcode.com/problems/jewels-and-stones) | [![Java](assets/java.png)](src/JewelsAndStones.java) [![Python](assets/python.png)](python/jewels_and_stones.py) | | @@ -428,7 +429,7 @@ | 788 | [Rotated Digits](https://leetcode.com/problems/rotated-digits) | | | | 796 | [Rotate String](https://leetcode.com/problems/rotate-string) | [![Java](assets/java.png)](src/RotateString.java) | | | 797 | [All Paths From Source to Target](https://leetcode.com/problems/all-paths-from-source-to-target) | [![Java](assets/java.png)](src/AllPathsFromSourceToTarget.java) | | -| 800 | [Similar RGB Color](https://leetcode.com/problems/similar-rgb-color) | | | +| 800 | 🔒 [Similar RGB Color](https://leetcode.com/problems/similar-rgb-color) | | | | 804 | [Unique Morse Code Words](https://leetcode.com/problems/unique-morse-code-words) | [![Java](assets/java.png)](src/UniqueMorseCodeWords.java) | | | 806 | [Number of Lines to Write String](https://leetcode.com/problems/number-of-lines-to-write-string) | [![Java](assets/java.png)](src/NumberOfLinesToWriteInString.java) | | | 811 | [Subdomain Visit Count](https://leetcode.com/problems/subdomain-visit-count) | | | @@ -610,7 +611,7 @@ | 1469 | 🔒 [Find All Lonely Nodes](https://leetcode.com/problems/find-all-the-lonely-nodes) | [![Python](assets/python.png)](python/reorder_routes_to_make_all_paths_lead_to_city_zero.py) | | | 1470 | [Shuffle The Array](https://leetcode.com/problems/shuffle-the-array) | [![Java](assets/java.png)](src/ShuffleTheArray.java) | | | 1472 | [Design Browser History](https://leetcode.com/problems/design-browser-history) | [![Java](assets/java.png)](src/DesignBrowserHistory.java) [![Python](assets/python.png)](python/design_browser_history.py) | | -| 1474 | [Delete N Nodes After M Nodes In A Linked List](https://leetcode.com/problems/delete-n-nodes-after-m-nodes-of-a-linked-list) | | | +| 1474 | 🔒 [Delete N Nodes After M Nodes In A Linked List](https://leetcode.com/problems/delete-n-nodes-after-m-nodes-of-a-linked-list) | | | | 1475 | [Final Prices With Special Discount in a Shop](https://leetcode.com/problems/final-prices-with-a-special-discount-in-a-shop) | [![Java](assets/java.png)](src/FinalPricesWithASpecialDiscountInAShop.java) | | | 1480 | [Running Sum of 1D Array](https://leetcode.com/problems/running-sum-of-1d-array) | [![Java](assets/java.png)](src/RunningSumOf1DArray.java) | | | 1486 | [XOR Operations in An Array](https://leetcode.com/problems/xor-operation-in-an-array) | [![Java](assets/java.png)](src/XOROperationInAnArray.java) | | @@ -864,13 +865,14 @@ | 2670 | [Find the Distinct Difference Array](https://leetcode.com/problems/find-the-distinct-difference-array) | [![Java](assets/java.png)](src/FindTheDistinctDifferenceArray.java) | | | 2678 | [Number of Senior Citizens](https://leetcode.com/problems/number-of-senior-citizens) | [![Java](assets/java.png)](src/NumberOfSeniorCitizens.java) | | | 2682 | [Find the Losers of the Circular Game](https://leetcode.com/problems/find-the-losers-of-the-circular-game) | [![Java](assets/java.png)](src/FindTheLosersOfTheCircularGame.java) | | +| 2689 | 🔒 [Extract Kth Character From The Rope Tree](https://leetcode.com/problems/extract-kth-character-from-the-rope-tree) | | | | 2696 | [Minimum String Length After Removing Substrings](https://leetcode.com/problems/minimum-string-length-after-removing-substrings) | [![Java](assets/java.png)](src/MinimumStringLengthAfterRemovingSubstrings.java) | | | 2697 | [Lexicographically Smallest Palindrome](https://leetcode.com/problems/lexicographically-smallest-palindrome) | [![Java](assets/java.png)](src/LexicographicallySmallestPalindrome.java) | | | 2706 | [Buy Two Chocolates](https://leetcode.com/problems/buy-two-chocolates) | [![Java](assets/java.png)](src/BuyTwoChocolates.java) | | | 2710 | [Remove Trailing Zeros From a String](https://leetcode.com/problems/remove-trailing-zeros-from-a-string) | [![Java](assets/java.png)](src/RemoveTrailingZerosFromAString.java) | | | 2716 | [Minimize String Length](https://leetcode.com/problems/minimize-string-length) | [![Java](assets/java.png)](src/MinimizeStringLength.java) | | | 2717 | [Semi-Ordered Permutation](https://leetcode.com/problems/semi-ordered-permutation) | [![Java](assets/java.png)](src/SemiOrderedPermutation.java) | | -| 2728 | [Count Houses in a Circular Street](https://leetcode.com/problems/count-houses-in-a-circular-street) | | | +| 2728 | 🔒 [Count Houses in a Circular Street](https://leetcode.com/problems/count-houses-in-a-circular-street) | | | | 2729 | [Check if The Number is Fascinating](https://leetcode.com/problems/check-if-the-number-is-fascinating) | [![Java](assets/java.png)](src/CheckIfTheNumberIsFascinating.java) | | | 2733 | [Neither Minimum nor Maximum](https://leetcode.com/problems/neither-minimum-nor-maximum) | [![Java](assets/java.png)](src/NeitherMinimumNorMaximum.java) | | | 2739 | [Total Distance Traveled](https://leetcode.com/problems/total-distance-traveled) | [![Java](assets/java.png)](src/TotalDistanceTraveled.java) | | @@ -966,3 +968,20 @@ | 3216 | [Lexicographically Smallest String After a Swap](https://leetcode.com/problems/lexicographically-smallest-string-after-a-swap) | [![Java](assets/java.png)](src/LexicographicallySmallestStringAfterASwap.java) | | | 3222 | [Find the Winning Player in Coin Game](https://leetcode.com/problems/find-the-winning-player-in-coin-game) | [![Java](assets/java.png)](src/FindTheWinningPlayerInCoinGame.java) | | | 3226 | [Number of Bit Changes to Make Two Integers Equal](https://leetcode.com/problems/number-of-bit-changes-to-make-two-integers-equal) | [![Java](assets/java.png)](src/NumberOfBitChangesToMakeTwoIntegersEqual.java) | | +| 3232 | [Find if Digit Game Can Be Won](https://leetcode.com/problems/find-if-digit-game-can-be-won) | | | +| 3238 | [Find the Number of Winning Players](https://leetcode.com/problems/find-the-number-of-winning-players) | | | +| 3242 | [Design Neighbor Sum Service](https://leetcode.com/problems/design-neighbor-sum-service) | | | +| 3248 | [Snake in Matrix](https://leetcode.com/problems/snake-in-matrix) | | | +| 3258 | [Count Substrings That Satisfy K-Constraint I](https://leetcode.com/problems/count-substrings-that-satisfy-k-constraint-i) | | | +| 3263 | 🔒 [Convert Doubly Linked List To Array I](https://leetcode.com/problems/convert-doubly-linked-list-to-array-i) | | | +| 3270 | [Find the Key of the Numbers](https://leetcode.com/problems/find-the-key-of-the-numbers) | | | +| 3274 | [Check if Two Chessboard Squares Have the Same Color](https://leetcode.com/problems/check-if-two-chessboard-squares-have-the-same-color) | | | +| 3280 | [Convert Date to Binary](https://leetcode.com/problems/convert-date-to-binary) | | | +| 3285 | [Find Indices of Stable Mountains](https://leetcode.com/problems/find-indices-of-stable-mountains) | | | +| 3289 | [The Two Sneaky Numbers of Digitville](https://leetcode.com/problems/the-two-sneaky-numbers-of-digitville) | | | +| 3300 | [Minimum Element After Replacement With Digit Sum](https://leetcode.com/problems/minimum-element-after-replacement-with-digit-sum) | | | +| 3304 | [Find the K-th Character in String Game I](https://leetcode.com/problems/find-the-k-th-character-in-string-game-i) | | | +| 3314 | [Construct the Minimum Bitwise Array I](https://leetcode.com/problems/construct-the-minimum-bitwise-array-i) | | | +| 3318 | [Find X-Sum of All K-Long Subarrays I](https://leetcode.com/problems/find-x-sum-of-all-k-long-subarrays-i) | | | +| 3330 | [Find the Original Typed String I](https://leetcode.com/problems/find-the-original-typed-string-i) | | | +| 3340 | [Check Balanced String](https://leetcode.com/problems/check-balanced-string) | | | diff --git a/src/HelloWorld.java b/src/HelloWorld.java index e867406..e483972 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -1,42 +1,96 @@ +import java.util.*; + public class HelloWorld { - public int[] searchRange(int[] nums, int target) { - if (nums.length == 0) { - return new int[] {-1, -1}; + public static List> buyVolumes(List volumes) { + if (volumes.isEmpty()) { + return new ArrayList<>(); } - return new int[] { - leftBinarySearch(nums, target), - rightBinarySearch(nums, target) - }; + final List> result = new ArrayList<>(); + int max = 0, required = 1, elements = 0; + boolean found = false; + for (int volumeNumber : volumes) { + max = Math.max(max, volumeNumber); + elements++; + if (volumeNumber == required) { + found = true; + } + if (found) { + if (elements == max - required + 1) { + result.add(sorted(required, max)); + elements = 0; + required = max + 1; + found = false; + } else { + result.add(List.of(-1)); + } + } else { + result.add(List.of(-1)); + } + } + return result; } - private static int leftBinarySearch(int[] array, int x) { - int left = 0, right = array.length - 1, middle; - while (left <= right) { - middle = left + (right - left) / 2; - if (array[middle] == x) { - if (middle - 1 >= 0 && array[middle - 1] == x) { - right = middle - 1; - } else return middle; + private static List sorted(int start, int end) { + final List result = new ArrayList<>(); + for (int element = start ; element <= end ; element++) { + result.add(element); + } + return result; + } + + private static List hello(List prices, List start, List end, List querries) { + final Map orderPrices = getPricesFrequency(prices, start, end); + final long[][] pairs = createPairs(orderPrices); + final List result = new ArrayList<>(); + for (int query : querries) { + final int index = binarySearch(pairs, query - 1); + if (pairs[index][0] == query - 1) { + result.add(pairs[index][1]); + } else { + result.add(pairs[index - 1][1]); } - else if (array[middle] < x) left = middle + 1; - else right = middle - 1; } - return -1; + return result; } - private static int rightBinarySearch(int[] array, int x) { + private static Map getPricesFrequency(List prices, List start, List end) { + final Map result = new HashMap<>(); + final int queries = start.size(); + for (int i = 0 ; i < queries ; i++) { + final int startIndex = start.get(i), endIndex = end.get(i); + addToFrequencies(result, prices, startIndex, endIndex); + } + return result; + } + + private static void addToFrequencies(Map frequencies, List prices, int start, int end) { + for (int i = start ; i <= end ; i++) { + frequencies.put(prices.get(i), frequencies.getOrDefault(prices.get(i), 0L) + 1); + } + } + + private static long[][] createPairs(Map frequencies) { + final long[][] result = new long[frequencies.size()][2]; + int k = 0; + for (Map.Entry entry : frequencies.entrySet()) { + result[k++] = new long[] {entry.getKey(), entry.getValue()}; + } + for (int i = 1 ; i < result.length ; i++) { + result[i][1] += result[i - 1][1]; + } + Arrays.sort(result, Comparator.comparingLong(a -> a[0])); + return result; + } + + private static int binarySearch(long[][] array, int x) { int left = 0, right = array.length - 1, middle; while (left <= right) { middle = left + (right - left) / 2; - if (array[middle] == x) { - if (middle + 1 < array.length && array[middle + 1] == x) { - left = middle + 1; - } else return middle; - } - else if (array[middle] < x) left = middle + 1; + if (array[middle][0] == x) return middle; + else if (array[middle][0] < x) left = middle + 1; else right = middle - 1; } - return -1; + return left; } -} + }