From ffce2d8dc2d84187f5600212fa02d833d94279b8 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva <38917450+anishLearnsToCode@users.noreply.github.com> Date: Mon, 18 Jan 2021 22:16:19 +0530 Subject: [PATCH 001/947] updates problem no --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 35c1486..b847c96 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Leetcode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-107/1412-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-107/1412-1abc9c.svg) -![problems-solved-python](https://img.shields.io/badge/Python-20/1412-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-107/571-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-107/1571-1abc9c.svg) +![problems-solved-python](https://img.shields.io/badge/Python-20/1571-1abc9c.svg) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md) ## Problems From 364102621db8b2df0ecc93dbd042552981d24fdb Mon Sep 17 00:00:00 2001 From: anishSachdeva Date: Thu, 27 May 2021 14:03:28 +0530 Subject: [PATCH 002/947] changes difficulty count and ay easy --> medium --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b847c96..eed25bf 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ | 27 | [Remove Element](https://leetcode.com/problems/remove-element/) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RemoveElement.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/remove_element.py)| | 28 | [Needle in Haystack](https://leetcode.com/problems/implement-strstr) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/NeedleInHaystack.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/needle_in_haystack.py) | | 35 | [Search Inserted Position](https://leetcode.com/problems/search-insert-position/) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/SearchInsertPosition.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/search_insert_position.py) | -| 38 | [Count and Say](https://leetcode.com/problems/count-and-say) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/CountAndSay.java) | +| 38 | [Count and Say](https://leetcode.com/problems/count-and-say) | Medium | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/CountAndSay.java) | | 53 | [Maximum SubArray](https://leetcode.com/problems/maximum-subarray) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MaximumSubArray.java) | | 58 | [Length of Last Word](https://leetcode.com/problems/length-of-last-word) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/LengthOfLastWord.java) | | 66 | [Plus One](https://leetcode.com/problems/plus-one) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PlusOne.java) | From 44783b6c1fc51083381421893bc48850be1b55b2 Mon Sep 17 00:00:00 2001 From: anishSachdeva Date: Thu, 27 May 2021 14:17:22 +0530 Subject: [PATCH 003/947] solves count and say in python --- README.md | 2 +- python/count_and_say.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 python/count_and_say.py diff --git a/README.md b/README.md index eed25bf..6f6d4b7 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ | 27 | [Remove Element](https://leetcode.com/problems/remove-element/) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RemoveElement.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/remove_element.py)| | 28 | [Needle in Haystack](https://leetcode.com/problems/implement-strstr) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/NeedleInHaystack.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/needle_in_haystack.py) | | 35 | [Search Inserted Position](https://leetcode.com/problems/search-insert-position/) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/SearchInsertPosition.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/search_insert_position.py) | -| 38 | [Count and Say](https://leetcode.com/problems/count-and-say) | Medium | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/CountAndSay.java) | +| 38 | [Count and Say](https://leetcode.com/problems/count-and-say) | Medium | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/CountAndSay.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/count_and_say.py) | | 53 | [Maximum SubArray](https://leetcode.com/problems/maximum-subarray) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MaximumSubArray.java) | | 58 | [Length of Last Word](https://leetcode.com/problems/length-of-last-word) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/LengthOfLastWord.java) | | 66 | [Plus One](https://leetcode.com/problems/plus-one) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PlusOne.java) | diff --git a/python/count_and_say.py b/python/count_and_say.py new file mode 100644 index 0000000..db8a076 --- /dev/null +++ b/python/count_and_say.py @@ -0,0 +1,19 @@ +class Solution: + def countAndSay(self, n: int) -> str: + if n == 1: + return '1' + + previous = self.countAndSay(n - 1) + # print('previous', n - 1, previous) + current = previous[0] + frequency = 0 + result = '' + for number in previous: + if number == current: + frequency += 1 + else: + result += f'{frequency}{current}' + frequency = 1 + current = number + result += f'{frequency}{current}' if frequency > 0 else '' + return result From 6756c5c6b41af93888a889805418e15e331c1b93 Mon Sep 17 00:00:00 2001 From: anishSachdeva Date: Thu, 27 May 2021 14:26:13 +0530 Subject: [PATCH 004/947] solves maximum sum subarray in python --- README.md | 2 +- python/maximum_sum_subarray.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 python/maximum_sum_subarray.py diff --git a/README.md b/README.md index 6f6d4b7..ab70be9 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ | 28 | [Needle in Haystack](https://leetcode.com/problems/implement-strstr) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/NeedleInHaystack.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/needle_in_haystack.py) | | 35 | [Search Inserted Position](https://leetcode.com/problems/search-insert-position/) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/SearchInsertPosition.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/search_insert_position.py) | | 38 | [Count and Say](https://leetcode.com/problems/count-and-say) | Medium | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/CountAndSay.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/count_and_say.py) | -| 53 | [Maximum SubArray](https://leetcode.com/problems/maximum-subarray) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MaximumSubArray.java) | +| 53 | [Maximum SubArray](https://leetcode.com/problems/maximum-subarray) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MaximumSubArray.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/maximum_sum_subarray.py) | | 58 | [Length of Last Word](https://leetcode.com/problems/length-of-last-word) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/LengthOfLastWord.java) | | 66 | [Plus One](https://leetcode.com/problems/plus-one) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PlusOne.java) | | 67 | [Add Binary](https://leetcode.com/problems/add-binary) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/AddBinary.java) | diff --git a/python/maximum_sum_subarray.py b/python/maximum_sum_subarray.py new file mode 100644 index 0000000..8eecc3f --- /dev/null +++ b/python/maximum_sum_subarray.py @@ -0,0 +1,12 @@ +# Kadane's Algorithm +from typing import List + + +class Solution: + def maxSubArray(self, array: List[int]) -> int: + max_sum, current_sum = -float('infinity'), 0 + for element in array: + current_sum += element + max_sum = max(current_sum, max_sum) + current_sum = max(current_sum, 0) + return int(max_sum) From 61296e3a8de8588e90bdc1af9e5161aac67b5307 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 21 Jun 2021 00:23:11 +0530 Subject: [PATCH 005/947] solves length of last word in python --- python/length_of_last_word.py | 9 +++++++++ src/CountAndSay.java | 1 - src/FindModeInBinarySearchTree.java | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 python/length_of_last_word.py create mode 100644 src/FindModeInBinarySearchTree.java diff --git a/python/length_of_last_word.py b/python/length_of_last_word.py new file mode 100644 index 0000000..8617a91 --- /dev/null +++ b/python/length_of_last_word.py @@ -0,0 +1,9 @@ +def length_last_word(s: str) -> int: + s = s.strip() + for index in range(len(s) - 1, -1, -1): + if s[index] == ' ': + return len(s) - index - 1 + return len(s) + + +print(length_last_word(input())) diff --git a/src/CountAndSay.java b/src/CountAndSay.java index 25606f7..7bea157 100644 --- a/src/CountAndSay.java +++ b/src/CountAndSay.java @@ -1,6 +1,5 @@ import java.util.ArrayList; import java.util.List; -import java.util.Scanner; public class CountAndSay { private static String countAndSay(int number) { diff --git a/src/FindModeInBinarySearchTree.java b/src/FindModeInBinarySearchTree.java new file mode 100644 index 0000000..0a8ee15 --- /dev/null +++ b/src/FindModeInBinarySearchTree.java @@ -0,0 +1,3 @@ +public class FindModeInBinarySearchTree { + +} From f6e8f9cad6b502a59ee4c3cbe079b69179f17ab4 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 21 Jun 2021 00:24:49 +0530 Subject: [PATCH 006/947] solves length of last word in python --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ab70be9..900489a 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,8 @@ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md) ## Problems -| # Number | Name | Difficulty | Solution | -|:--------:|------|:----------:|:--------:| +| # Number | Name | Difficulty | Solution | Youtube Solution Video | +|:--------:|------|:----------:|:--------:|:----------------------:| | 1 | [Two Sum](https://leetcode.com/problems/two-sum/) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/TwoSum.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/two_sum.py) | | 7 | [Reverse Integer](https://leetcode.com/problems/reverse-integer/) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ReverseInteger.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_integer.py) | | 9 | [PalindromeNumber](https://leetcode.com/problems/palindrome-number/) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PalindromeNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/palindrome_number.py) | @@ -21,7 +21,7 @@ | 35 | [Search Inserted Position](https://leetcode.com/problems/search-insert-position/) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/SearchInsertPosition.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/search_insert_position.py) | | 38 | [Count and Say](https://leetcode.com/problems/count-and-say) | Medium | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/CountAndSay.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/count_and_say.py) | | 53 | [Maximum SubArray](https://leetcode.com/problems/maximum-subarray) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MaximumSubArray.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/maximum_sum_subarray.py) | -| 58 | [Length of Last Word](https://leetcode.com/problems/length-of-last-word) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/LengthOfLastWord.java) | +| 58 | [Length of Last Word](https://leetcode.com/problems/length-of-last-word) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/LengthOfLastWord.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/length_of_last_word.py) | | 66 | [Plus One](https://leetcode.com/problems/plus-one) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PlusOne.java) | | 67 | [Add Binary](https://leetcode.com/problems/add-binary) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/AddBinary.java) | | 69 | [Sqrt(x)](https://leetcode.com/problems/sqrtx) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/Sqrtx.java) | From 6bbc35570dc9c3a81e82f3a0d9da3a91ebef8f3f Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 21 Jun 2021 00:26:00 +0530 Subject: [PATCH 007/947] renames column to --> Youtube --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 900489a..151b94b 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md) ## Problems -| # Number | Name | Difficulty | Solution | Youtube Solution Video | +| # Number | Name | Difficulty | Solution | Youtube | |:--------:|------|:----------:|:--------:|:----------------------:| | 1 | [Two Sum](https://leetcode.com/problems/two-sum/) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/TwoSum.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/two_sum.py) | | 7 | [Reverse Integer](https://leetcode.com/problems/reverse-integer/) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ReverseInteger.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_integer.py) | From 70217400bb40111d916caca2f2c62649117955fd Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 21 Jun 2021 00:37:41 +0530 Subject: [PATCH 008/947] solves plus one in python --- README.md | 2 +- python/plus_one.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 python/plus_one.py diff --git a/README.md b/README.md index 151b94b..31ab691 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ | 38 | [Count and Say](https://leetcode.com/problems/count-and-say) | Medium | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/CountAndSay.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/count_and_say.py) | | 53 | [Maximum SubArray](https://leetcode.com/problems/maximum-subarray) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MaximumSubArray.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/maximum_sum_subarray.py) | | 58 | [Length of Last Word](https://leetcode.com/problems/length-of-last-word) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/LengthOfLastWord.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/length_of_last_word.py) | -| 66 | [Plus One](https://leetcode.com/problems/plus-one) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PlusOne.java) | +| 66 | [Plus One](https://leetcode.com/problems/plus-one) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PlusOne.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/plus_one.py) | | 67 | [Add Binary](https://leetcode.com/problems/add-binary) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/AddBinary.java) | | 69 | [Sqrt(x)](https://leetcode.com/problems/sqrtx) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/Sqrtx.java) | | 70 | [Climbing Stairs](https://leetcode.com/problems/climbing-stairs) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ClimbingStairs.java) | diff --git a/python/plus_one.py b/python/plus_one.py new file mode 100644 index 0000000..7ba5443 --- /dev/null +++ b/python/plus_one.py @@ -0,0 +1,15 @@ +from typing import List + + +def plusOne(digits: List[int]) -> List[int]: + carry = 1 + for index in range(len(digits) - 1, -1, -1): + result = digits[index] + carry + digits[index] = result % 10 + carry = result // 10 + if carry == 0: + return digits + return [1, *digits] + + +print(plusOne([int(digit) for digit in input()])) From 3bfa63dbb9e5b981447838faba69b0b84cf2a7eb Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 21 Jun 2021 00:38:25 +0530 Subject: [PATCH 009/947] solves plus one in python --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 31ab691..1820457 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md) ## Problems -| # Number | Name | Difficulty | Solution | Youtube | +| #Number | Name | Difficulty | Solution | Youtube | |:--------:|------|:----------:|:--------:|:----------------------:| | 1 | [Two Sum](https://leetcode.com/problems/two-sum/) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/TwoSum.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/two_sum.py) | | 7 | [Reverse Integer](https://leetcode.com/problems/reverse-integer/) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ReverseInteger.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_integer.py) | From a6f4a957b1dd34dd5959d487d23aef66ce6621c8 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 21 Jun 2021 00:45:06 +0530 Subject: [PATCH 010/947] solves add binary --- README.md | 2 +- python/add_binary.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 python/add_binary.py diff --git a/README.md b/README.md index 1820457..b5d3fc2 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ | 53 | [Maximum SubArray](https://leetcode.com/problems/maximum-subarray) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MaximumSubArray.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/maximum_sum_subarray.py) | | 58 | [Length of Last Word](https://leetcode.com/problems/length-of-last-word) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/LengthOfLastWord.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/length_of_last_word.py) | | 66 | [Plus One](https://leetcode.com/problems/plus-one) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PlusOne.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/plus_one.py) | -| 67 | [Add Binary](https://leetcode.com/problems/add-binary) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/AddBinary.java) | +| 67 | [Add Binary](https://leetcode.com/problems/add-binary) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/AddBinary.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/add_binary.py) | | 69 | [Sqrt(x)](https://leetcode.com/problems/sqrtx) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/Sqrtx.java) | | 70 | [Climbing Stairs](https://leetcode.com/problems/climbing-stairs) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ClimbingStairs.java) | | 83 | [Remove Duplicates from Sorted List](https://leetcode.com/problems/remove-duplicates-from-sorted-list) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RemoveDuplicatesFromSortedList.java) | diff --git a/python/add_binary.py b/python/add_binary.py new file mode 100644 index 0000000..a99f439 --- /dev/null +++ b/python/add_binary.py @@ -0,0 +1,4 @@ +class Solution: + def addBinary(self, a: str, b: str) -> str: + return bin(int(a, base=2) + int(b, base=2))[2:] + From 22c8f5f7a12273a77e81c19b9c9c6de76996861b Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 21 Jun 2021 01:33:16 +0530 Subject: [PATCH 011/947] solves sqrt in python --- README.md | 4 ++-- python/sqrt.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 python/sqrt.py diff --git a/README.md b/README.md index b5d3fc2..ae2859f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ![problems-solved](https://img.shields.io/badge/Problems%20Solved-107/571-1f425f.svg) ![problems-solved-java](https://img.shields.io/badge/Java-107/1571-1abc9c.svg) -![problems-solved-python](https://img.shields.io/badge/Python-20/1571-1abc9c.svg) +![problems-solved-python](https://img.shields.io/badge/Python-26/1571-1abc9c.svg) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md) ## Problems @@ -24,7 +24,7 @@ | 58 | [Length of Last Word](https://leetcode.com/problems/length-of-last-word) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/LengthOfLastWord.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/length_of_last_word.py) | | 66 | [Plus One](https://leetcode.com/problems/plus-one) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PlusOne.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/plus_one.py) | | 67 | [Add Binary](https://leetcode.com/problems/add-binary) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/AddBinary.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/add_binary.py) | -| 69 | [Sqrt(x)](https://leetcode.com/problems/sqrtx) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/Sqrtx.java) | +| 69 | [Sqrt(x)](https://leetcode.com/problems/sqrtx) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/Sqrtx.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/sqrt.py) | | 70 | [Climbing Stairs](https://leetcode.com/problems/climbing-stairs) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ClimbingStairs.java) | | 83 | [Remove Duplicates from Sorted List](https://leetcode.com/problems/remove-duplicates-from-sorted-list) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RemoveDuplicatesFromSortedList.java) | | 88 | [Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MergeSortedArray.java) | diff --git a/python/sqrt.py b/python/sqrt.py new file mode 100644 index 0000000..43bbc95 --- /dev/null +++ b/python/sqrt.py @@ -0,0 +1,32 @@ +def mySqrt(x: int) -> int: + left, right, ans = 0, x, 0 + while left <= right: + middle = left + (right - left) // 2 + result = middle ** 2 + if result == x: + return middle + elif result > x: + right = middle - 1 + else: + ans = middle + left = middle + 1 + return ans + + +# faster method, herons formula approach +def heron_approximation(x: int) -> int: + if x is 0 or x is 1: + return x + guess = x / 2 + epsilon = 10 ** -4 + while True: + new_guess = 0.5 * (guess + x / guess) + if abs(guess - new_guess) < epsilon: + return int(guess) + guess = new_guess + + +# print(mySqrt(int(8))) + +for i in range(50): + print(f'sqrt({i})={mySqrt(i)}') From ee603bfe7a976ef8c10419e47de30b985c767682 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 21 Jun 2021 01:40:38 +0530 Subject: [PATCH 012/947] solves climbing stairs in python --- README.md | 4 ++-- python/climbing_stairs.py | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 python/climbing_stairs.py diff --git a/README.md b/README.md index ae2859f..a701158 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ![problems-solved](https://img.shields.io/badge/Problems%20Solved-107/571-1f425f.svg) ![problems-solved-java](https://img.shields.io/badge/Java-107/1571-1abc9c.svg) -![problems-solved-python](https://img.shields.io/badge/Python-26/1571-1abc9c.svg) +![problems-solved-python](https://img.shields.io/badge/Python-27/1571-1abc9c.svg) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md) ## Problems @@ -25,7 +25,7 @@ | 66 | [Plus One](https://leetcode.com/problems/plus-one) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PlusOne.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/plus_one.py) | | 67 | [Add Binary](https://leetcode.com/problems/add-binary) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/AddBinary.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/add_binary.py) | | 69 | [Sqrt(x)](https://leetcode.com/problems/sqrtx) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/Sqrtx.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/sqrt.py) | -| 70 | [Climbing Stairs](https://leetcode.com/problems/climbing-stairs) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ClimbingStairs.java) | +| 70 | [Climbing Stairs](https://leetcode.com/problems/climbing-stairs) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ClimbingStairs.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/climbing_stairs.py) | | 83 | [Remove Duplicates from Sorted List](https://leetcode.com/problems/remove-duplicates-from-sorted-list) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RemoveDuplicatesFromSortedList.java) | | 88 | [Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MergeSortedArray.java) | | 100 | [Same Tree](https://leetcode.com/problems/same-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/SameTree.java) | diff --git a/python/climbing_stairs.py b/python/climbing_stairs.py new file mode 100644 index 0000000..6bc24a6 --- /dev/null +++ b/python/climbing_stairs.py @@ -0,0 +1,5 @@ +def climbStairs(n: int) -> int: + prev, current = 1, 1 + for i in range(n - 1): + prev, current = current, prev + current + return current From 1d62120d602ef9a38fb61e9a18043807d5f5495d Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 21 Jun 2021 01:48:58 +0530 Subject: [PATCH 013/947] solves remove linked listnode in python --- README.md | 4 ++-- python/remove_duplicates_from_linked_list.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 python/remove_duplicates_from_linked_list.py diff --git a/README.md b/README.md index a701158..48c0902 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ![problems-solved](https://img.shields.io/badge/Problems%20Solved-107/571-1f425f.svg) ![problems-solved-java](https://img.shields.io/badge/Java-107/1571-1abc9c.svg) -![problems-solved-python](https://img.shields.io/badge/Python-27/1571-1abc9c.svg) +![problems-solved-python](https://img.shields.io/badge/Python-28/1571-1abc9c.svg) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md) ## Problems @@ -26,7 +26,7 @@ | 67 | [Add Binary](https://leetcode.com/problems/add-binary) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/AddBinary.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/add_binary.py) | | 69 | [Sqrt(x)](https://leetcode.com/problems/sqrtx) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/Sqrtx.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/sqrt.py) | | 70 | [Climbing Stairs](https://leetcode.com/problems/climbing-stairs) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ClimbingStairs.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/climbing_stairs.py) | -| 83 | [Remove Duplicates from Sorted List](https://leetcode.com/problems/remove-duplicates-from-sorted-list) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RemoveDuplicatesFromSortedList.java) | +| 83 | [Remove Duplicates from Sorted List](https://leetcode.com/problems/remove-duplicates-from-sorted-list) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RemoveDuplicatesFromSortedList.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/remove_duplicates_from_linked_list.py) | | 88 | [Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MergeSortedArray.java) | | 100 | [Same Tree](https://leetcode.com/problems/same-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/SameTree.java) | | 101 | [Symmetric Tree](https://leetcode.com/problems/symmetric-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/SymmetricTree.java) | diff --git a/python/remove_duplicates_from_linked_list.py b/python/remove_duplicates_from_linked_list.py new file mode 100644 index 0000000..2990e38 --- /dev/null +++ b/python/remove_duplicates_from_linked_list.py @@ -0,0 +1,16 @@ +class ListNode: + def __init__(self, val=0, next=None): + self.val = val + self.next = next + + +def deleteDuplicates(head: ListNode) -> ListNode: + if head is None: + return None + current = head + while current is not None: + if current.val == current.next.val: + current.next = current.next.next + else: + current = current.next + return head From 3f8e26d28e2f6d69c8313963fbe721d6282632dc Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Tue, 22 Jun 2021 23:54:33 +0530 Subject: [PATCH 014/947] solves merge sorted array python --- README.md | 4 ++-- python/merge_sorted_array.py | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 python/merge_sorted_array.py diff --git a/README.md b/README.md index 48c0902..bf6fcb8 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ![problems-solved](https://img.shields.io/badge/Problems%20Solved-107/571-1f425f.svg) ![problems-solved-java](https://img.shields.io/badge/Java-107/1571-1abc9c.svg) -![problems-solved-python](https://img.shields.io/badge/Python-28/1571-1abc9c.svg) +![problems-solved-python](https://img.shields.io/badge/Python-29/1571-1abc9c.svg) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md) ## Problems @@ -27,7 +27,7 @@ | 69 | [Sqrt(x)](https://leetcode.com/problems/sqrtx) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/Sqrtx.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/sqrt.py) | | 70 | [Climbing Stairs](https://leetcode.com/problems/climbing-stairs) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ClimbingStairs.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/climbing_stairs.py) | | 83 | [Remove Duplicates from Sorted List](https://leetcode.com/problems/remove-duplicates-from-sorted-list) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RemoveDuplicatesFromSortedList.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/remove_duplicates_from_linked_list.py) | -| 88 | [Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MergeSortedArray.java) | +| 88 | [Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MergeSortedArray.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/merge_sorted_array.py) | | 100 | [Same Tree](https://leetcode.com/problems/same-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/SameTree.java) | | 101 | [Symmetric Tree](https://leetcode.com/problems/symmetric-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/SymmetricTree.java) | | 104 | [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MaximumDepthOfBinaryTree.java) | diff --git a/python/merge_sorted_array.py b/python/merge_sorted_array.py new file mode 100644 index 0000000..ec333fd --- /dev/null +++ b/python/merge_sorted_array.py @@ -0,0 +1,25 @@ +from typing import List + + +class Solution: + def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None: + result = [0] * (m + n) + i, j, k = 0, 0, 0 + while i < m and j < n: + if nums1[i] < nums2[j]: + result[k] = nums1[i] + i += 1 + else: + result[k] = nums2[j] + j += 1 + k += 1 + while i < m: + result[k] = nums1[i] + i += 1 + k += 1 + while j < n: + result[k] = nums2[j] + j += 1 + k += 1 + for i in range(m + n): + nums1[i] = result[i] From 37a9a0f01437b5480a3842b9777bb0b719b7d6ec Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 23 Jun 2021 00:05:36 +0530 Subject: [PATCH 015/947] solves same trees --- README.md | 4 ++-- python/same_tree.py | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 python/same_tree.py diff --git a/README.md b/README.md index bf6fcb8..bc04e81 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ![problems-solved](https://img.shields.io/badge/Problems%20Solved-107/571-1f425f.svg) ![problems-solved-java](https://img.shields.io/badge/Java-107/1571-1abc9c.svg) -![problems-solved-python](https://img.shields.io/badge/Python-29/1571-1abc9c.svg) +![problems-solved-python](https://img.shields.io/badge/Python-30/1571-1abc9c.svg) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md) ## Problems @@ -28,7 +28,7 @@ | 70 | [Climbing Stairs](https://leetcode.com/problems/climbing-stairs) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ClimbingStairs.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/climbing_stairs.py) | | 83 | [Remove Duplicates from Sorted List](https://leetcode.com/problems/remove-duplicates-from-sorted-list) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RemoveDuplicatesFromSortedList.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/remove_duplicates_from_linked_list.py) | | 88 | [Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MergeSortedArray.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/merge_sorted_array.py) | -| 100 | [Same Tree](https://leetcode.com/problems/same-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/SameTree.java) | +| 100 | [Same Tree](https://leetcode.com/problems/same-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/SameTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/same_tree.py) | | 101 | [Symmetric Tree](https://leetcode.com/problems/symmetric-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/SymmetricTree.java) | | 104 | [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MaximumDepthOfBinaryTree.java) | | 107 | [Binary Tree Level Order Traversal II](https://leetcode.com/problems/binary-tree-level-order-traversal-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BinaryTreeLevelOrderTraversalII.java) | diff --git a/python/same_tree.py b/python/same_tree.py new file mode 100644 index 0000000..fd3a398 --- /dev/null +++ b/python/same_tree.py @@ -0,0 +1,13 @@ +# Definition for a binary tree node. +class TreeNode: + def __init__(self, val=0, left=None, right=None): + self.val = val + self.left = left + self.right = right + + +class Solution: + def isSameTree(self, p: TreeNode, q: TreeNode) -> bool: + if p is None or q is None: + return p == q + return p.val == q.val and self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right) From 396b4e7fb9976bfcd0c5e318ccfb17c7975264ae Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 23 Jun 2021 00:27:38 +0530 Subject: [PATCH 016/947] solves symmetric tree in python --- README.md | 4 ++-- python/symmetric_tree.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 python/symmetric_tree.py diff --git a/README.md b/README.md index bc04e81..4dc1ac1 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ![problems-solved](https://img.shields.io/badge/Problems%20Solved-107/571-1f425f.svg) ![problems-solved-java](https://img.shields.io/badge/Java-107/1571-1abc9c.svg) -![problems-solved-python](https://img.shields.io/badge/Python-30/1571-1abc9c.svg) +![problems-solved-python](https://img.shields.io/badge/Python-31/1571-1abc9c.svg) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md) ## Problems @@ -29,7 +29,7 @@ | 83 | [Remove Duplicates from Sorted List](https://leetcode.com/problems/remove-duplicates-from-sorted-list) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RemoveDuplicatesFromSortedList.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/remove_duplicates_from_linked_list.py) | | 88 | [Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MergeSortedArray.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/merge_sorted_array.py) | | 100 | [Same Tree](https://leetcode.com/problems/same-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/SameTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/same_tree.py) | -| 101 | [Symmetric Tree](https://leetcode.com/problems/symmetric-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/SymmetricTree.java) | +| 101 | [Symmetric Tree](https://leetcode.com/problems/symmetric-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/SymmetricTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/symmetric_tree.py) | | 104 | [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MaximumDepthOfBinaryTree.java) | | 107 | [Binary Tree Level Order Traversal II](https://leetcode.com/problems/binary-tree-level-order-traversal-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BinaryTreeLevelOrderTraversalII.java) | | 108 | [Convert Sorted Array To Binary Search Tree](https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ConvertSortedArrayToBinarySearchTree.java) | diff --git a/python/symmetric_tree.py b/python/symmetric_tree.py new file mode 100644 index 0000000..5e20b96 --- /dev/null +++ b/python/symmetric_tree.py @@ -0,0 +1,17 @@ +# Definition for a binary tree node. +class TreeNode: + def __init__(self, val=0, left=None, right=None): + self.val = val + self.left = left + self.right = right + + +class Solution: + def is_symmetric(self, left: TreeNode, right: TreeNode) -> bool: + if left and right: + return left.val == right.val and self.is_symmetric(left.left, right.right) \ + and self.is_symmetric(left.right, right.left) + return left == right + + def isSymmetric(self, root: TreeNode) -> bool: + return root is None or self.is_symmetric(root.left, root.right) From ccdf72bd2b3879d99f43483f3892c9ff83ab9c8c Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 23 Jun 2021 00:29:27 +0530 Subject: [PATCH 017/947] improves Java solution --- README.md | 2 +- src/SymmetricTree.java | 21 +++------------------ 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 4dc1ac1..d5b267c 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ | #Number | Name | Difficulty | Solution | Youtube | |:--------:|------|:----------:|:--------:|:----------------------:| | 1 | [Two Sum](https://leetcode.com/problems/two-sum/) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/TwoSum.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/two_sum.py) | -| 7 | [Reverse Integer](https://leetcode.com/problems/reverse-integer/) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ReverseInteger.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_integer.py) | +| 7 | [Reverse Integer](https://leetcode.com/problems/reverse-isnteger/) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ReverseInteger.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_integer.py) | | 9 | [PalindromeNumber](https://leetcode.com/problems/palindrome-number/) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PalindromeNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/palindrome_number.py) | | 13 | [Roman To Integer](https://leetcode.com/problems/roman-to-integer/) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RomanToInteger.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/roman_to_integer.py) | | 14 | [Longest Common Prefix](https://leetcode.com/problems/longest-common-prefix/) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/LongestCommonPrefix.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/longest_common_prefix.py) | diff --git a/src/SymmetricTree.java b/src/SymmetricTree.java index ac48e1d..16940ab 100644 --- a/src/SymmetricTree.java +++ b/src/SymmetricTree.java @@ -10,24 +10,9 @@ public boolean isSymmetric(TreeNode root) { } public boolean isSymmetric(TreeNode p, TreeNode q) { - if (p == null && q == null) { - return true; + if (p != null && q != null) { + return p.val == q.val && isSymmetric(p.left, q.right) && isSymmetric(p.right, q.left); } - - if (p == null || q == null || p.val != q.val) { - return false; - } - - boolean left = (p.left == null && q.right == null) || (p.left != null && q.right != null); - if (p.left != null && q.right != null) { - left = isSymmetric(p.left, q.right); - } - - boolean right = (p.right == null && q.left == null) || (p.right != null && q.left != null); - if (p.right != null && q.left != null) { - right = isSymmetric(p.right, q.left); - } - - return left && right; + return p == q; } } From b98577dbd4b09678e3ecb19fa84dbe9a643b01a1 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 23 Jun 2021 00:33:04 +0530 Subject: [PATCH 018/947] solve smax depth / height of binary tree --- README.md | 4 ++-- python/maximum_depth_of_binary_tree.py | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 python/maximum_depth_of_binary_tree.py diff --git a/README.md b/README.md index d5b267c..e47e487 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ![problems-solved](https://img.shields.io/badge/Problems%20Solved-107/571-1f425f.svg) ![problems-solved-java](https://img.shields.io/badge/Java-107/1571-1abc9c.svg) -![problems-solved-python](https://img.shields.io/badge/Python-31/1571-1abc9c.svg) +![problems-solved-python](https://img.shields.io/badge/Python-32/1571-1abc9c.svg) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md) ## Problems @@ -30,7 +30,7 @@ | 88 | [Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MergeSortedArray.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/merge_sorted_array.py) | | 100 | [Same Tree](https://leetcode.com/problems/same-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/SameTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/same_tree.py) | | 101 | [Symmetric Tree](https://leetcode.com/problems/symmetric-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/SymmetricTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/symmetric_tree.py) | -| 104 | [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MaximumDepthOfBinaryTree.java) | +| 104 | [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MaximumDepthOfBinaryTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/maximum_depth_of_binary_tree.py) | | 107 | [Binary Tree Level Order Traversal II](https://leetcode.com/problems/binary-tree-level-order-traversal-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BinaryTreeLevelOrderTraversalII.java) | | 108 | [Convert Sorted Array To Binary Search Tree](https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ConvertSortedArrayToBinarySearchTree.java) | | 110 | [Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BalancedBinaryTree.java) | diff --git a/python/maximum_depth_of_binary_tree.py b/python/maximum_depth_of_binary_tree.py new file mode 100644 index 0000000..7911611 --- /dev/null +++ b/python/maximum_depth_of_binary_tree.py @@ -0,0 +1,13 @@ +# Definition for a binary tree node. +class TreeNode: + def __init__(self, val=0, left=None, right=None): + self.val = val + self.left = left + self.right = right + + +class Solution: + def maxDepth(self, root: TreeNode) -> int: + if root is None: + return 0 + return 1 + max(self.maxDepth(root.left), self.maxDepth(root.right)) From 283e09e244d2bacea8829c9db4674619584c33d6 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 23 Jun 2021 16:26:34 +0530 Subject: [PATCH 019/947] solves binary tree level order traversal in python --- README.md | 2 +- .../binary_tree_level_order_traversal_ii.py | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 python/binary_tree_level_order_traversal_ii.py diff --git a/README.md b/README.md index e47e487..17fe14b 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ | 100 | [Same Tree](https://leetcode.com/problems/same-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/SameTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/same_tree.py) | | 101 | [Symmetric Tree](https://leetcode.com/problems/symmetric-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/SymmetricTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/symmetric_tree.py) | | 104 | [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MaximumDepthOfBinaryTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/maximum_depth_of_binary_tree.py) | -| 107 | [Binary Tree Level Order Traversal II](https://leetcode.com/problems/binary-tree-level-order-traversal-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BinaryTreeLevelOrderTraversalII.java) | +| 107 | [Binary Tree Level Order Traversal II](https://leetcode.com/problems/binary-tree-level-order-traversal-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BinaryTreeLevelOrderTraversalII.java) [![Python](https://img.icons8.com/color/35/000000/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) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ConvertSortedArrayToBinarySearchTree.java) | | 110 | [Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BalancedBinaryTree.java) | | 111 | [Minimum Depth of Binary Tree](https://leetcode.com/problems/minimum-depth-of-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MinimumDepthOfBinaryTree.java) | diff --git a/python/binary_tree_level_order_traversal_ii.py b/python/binary_tree_level_order_traversal_ii.py new file mode 100644 index 0000000..b3e5534 --- /dev/null +++ b/python/binary_tree_level_order_traversal_ii.py @@ -0,0 +1,35 @@ +# Definition for a binary tree node. +from typing import List +from collections import deque + + +class TreeNode: + def __init__(self, val=0, left=None, right=None): + self.val = val + self.left = left + self.right = right + + +class Solution: + def levelOrderBottom(self, root: TreeNode) -> List[List[int]]: + if root is None: + return [] + + queue = deque() + queue.append(root) + result = [] + current_level = [] + + while len(queue): + current_level_length = len(queue) + for _ in range(current_level_length): + current = queue.popleft() + current_level.append(current.val) + if current.left: + queue.append(current.left) + if current.right: + queue.append(current.right) + result.append(current_level) + current_level = [] + + return result[::-1] From d26fdf34bbe91e52bd18aef6e748b4f94ce17ceb Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 23 Jun 2021 17:33:36 +0530 Subject: [PATCH 020/947] solves convert sorted array to bst in python --- README.md | 2 +- ...rted_sorted_array_to_binary_search_tree.py | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 python/converted_sorted_array_to_binary_search_tree.py diff --git a/README.md b/README.md index 17fe14b..90e4ca6 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ | 101 | [Symmetric Tree](https://leetcode.com/problems/symmetric-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/SymmetricTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/symmetric_tree.py) | | 104 | [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MaximumDepthOfBinaryTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/maximum_depth_of_binary_tree.py) | | 107 | [Binary Tree Level Order Traversal II](https://leetcode.com/problems/binary-tree-level-order-traversal-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BinaryTreeLevelOrderTraversalII.java) [![Python](https://img.icons8.com/color/35/000000/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) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ConvertSortedArrayToBinarySearchTree.java) | +| 108 | [Convert Sorted Array To Binary Search Tree](https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ConvertSortedArrayToBinarySearchTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/converted_sorted_array_to_binary_search_tree.py) | | 110 | [Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BalancedBinaryTree.java) | | 111 | [Minimum Depth of Binary Tree](https://leetcode.com/problems/minimum-depth-of-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MinimumDepthOfBinaryTree.java) | | 112 | [Path Sum](https://leetcode.com/problems/path-sum) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PathSum.java) | diff --git a/python/converted_sorted_array_to_binary_search_tree.py b/python/converted_sorted_array_to_binary_search_tree.py new file mode 100644 index 0000000..3ffdf70 --- /dev/null +++ b/python/converted_sorted_array_to_binary_search_tree.py @@ -0,0 +1,27 @@ +# Definition for a binary tree node. +from typing import List, Optional + + +class TreeNode: + def __init__(self, val=0, left=None, right=None): + self.val = val + self.left = left + self.right = right + + def __repr__(self): + return f'Tree(val={self.val})' + + +class Solution: + def sorted_array_to_bst(self, array: List[int], start: int, end: int) -> Optional[TreeNode]: + if end == start: + return None + + middle = (start + end) // 2 + root = TreeNode(val=array[middle]) + root.left = self.sorted_array_to_bst(array, start, middle) + root.right = self.sorted_array_to_bst(array, middle + 1, end) + return root + + def sortedArrayToBST(self, nums: List[int]) -> TreeNode: + return self.sorted_array_to_bst(nums, 0, len(nums)) From a4ad9be87576ac9d6f8fc958dab8e2f119744abb Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 23 Jun 2021 17:47:10 +0530 Subject: [PATCH 021/947] solves balanced binary tree python --- README.md | 2 +- python/balanced_binary_tree.py | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 python/balanced_binary_tree.py diff --git a/README.md b/README.md index 90e4ca6..5f79391 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ | 104 | [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MaximumDepthOfBinaryTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/maximum_depth_of_binary_tree.py) | | 107 | [Binary Tree Level Order Traversal II](https://leetcode.com/problems/binary-tree-level-order-traversal-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BinaryTreeLevelOrderTraversalII.java) [![Python](https://img.icons8.com/color/35/000000/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) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ConvertSortedArrayToBinarySearchTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/converted_sorted_array_to_binary_search_tree.py) | -| 110 | [Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BalancedBinaryTree.java) | +| 110 | [Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BalancedBinaryTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/balanced_binary_tree.py) | | 111 | [Minimum Depth of Binary Tree](https://leetcode.com/problems/minimum-depth-of-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MinimumDepthOfBinaryTree.java) | | 112 | [Path Sum](https://leetcode.com/problems/path-sum) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PathSum.java) | | 118 | [Pascal's Triangle](https://leetcode.com/problems/pascals-triangle) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PascalsTriangle.java) | diff --git a/python/balanced_binary_tree.py b/python/balanced_binary_tree.py new file mode 100644 index 0000000..217cab4 --- /dev/null +++ b/python/balanced_binary_tree.py @@ -0,0 +1,24 @@ +# Definition for a binary tree node. +class TreeNode: + def __init__(self, val=0, left=None, right=None): + self.val = val + self.left = left + self.right = right + + +class Solution: + def _is_balanced(self, root: TreeNode) -> int: + if root is None: + return 0 + + left_height = self._is_balanced(root.left) + right_height = self._is_balanced(root.right) + if left_height == -1 or right_height == -1 or abs(left_height - right_height) > 1: + return -1 + + return 1 + max(left_height, right_height) + + def isBalanced(self, root: TreeNode) -> bool: + if root is None: + return True + return self._is_balanced(root) is not -1 From cf8f462ad7635963369a28b5e8af7973c1fc98ce Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 23 Jun 2021 18:24:08 +0530 Subject: [PATCH 022/947] solves min depth binary tree in python --- README.md | 2 +- python/minimum_depth_of_binary_tree.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 python/minimum_depth_of_binary_tree.py diff --git a/README.md b/README.md index 5f79391..3cd1673 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ | 107 | [Binary Tree Level Order Traversal II](https://leetcode.com/problems/binary-tree-level-order-traversal-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BinaryTreeLevelOrderTraversalII.java) [![Python](https://img.icons8.com/color/35/000000/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) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ConvertSortedArrayToBinarySearchTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/converted_sorted_array_to_binary_search_tree.py) | | 110 | [Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BalancedBinaryTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/balanced_binary_tree.py) | -| 111 | [Minimum Depth of Binary Tree](https://leetcode.com/problems/minimum-depth-of-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MinimumDepthOfBinaryTree.java) | +| 111 | [Minimum Depth of Binary Tree](https://leetcode.com/problems/minimum-depth-of-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MinimumDepthOfBinaryTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/minimum_depth_of_binary_tree.py) | | 112 | [Path Sum](https://leetcode.com/problems/path-sum) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PathSum.java) | | 118 | [Pascal's Triangle](https://leetcode.com/problems/pascals-triangle) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PascalsTriangle.java) | | 119 | [Pascal's Triangle II](https://leetcode.com/problems/pascals-triangle-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PascalsTriangleII.java) | diff --git a/python/minimum_depth_of_binary_tree.py b/python/minimum_depth_of_binary_tree.py new file mode 100644 index 0000000..985cff9 --- /dev/null +++ b/python/minimum_depth_of_binary_tree.py @@ -0,0 +1,17 @@ +# Definition for a binary tree node. +class TreeNode: + def __init__(self, val=0, left=None, right=None): + self.val = val + self.left = left + self.right = right + + +class Solution: + def minDepth(self, root: TreeNode) -> int: + if root is None: + return 0 + if root.left is None: + return 1 + self.minDepth(root.right) + if root.right is None: + return 1 + self.minDepth(root.left) + return 1 + min(self.minDepth(root.left), self.minDepth(root.right)) \ No newline at end of file From 25e3010f9626f24c866347bcf461285195a07923 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 23 Jun 2021 20:48:21 +0530 Subject: [PATCH 023/947] solves path sum in python --- README.md | 2 +- python/path_sum.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 python/path_sum.py diff --git a/README.md b/README.md index 3cd1673..5f24cdd 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ | 108 | [Convert Sorted Array To Binary Search Tree](https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ConvertSortedArrayToBinarySearchTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/converted_sorted_array_to_binary_search_tree.py) | | 110 | [Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BalancedBinaryTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/balanced_binary_tree.py) | | 111 | [Minimum Depth of Binary Tree](https://leetcode.com/problems/minimum-depth-of-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MinimumDepthOfBinaryTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/minimum_depth_of_binary_tree.py) | -| 112 | [Path Sum](https://leetcode.com/problems/path-sum) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PathSum.java) | +| 112 | [Path Sum](https://leetcode.com/problems/path-sum) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PathSum.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/path_sum.py) | | 118 | [Pascal's Triangle](https://leetcode.com/problems/pascals-triangle) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PascalsTriangle.java) | | 119 | [Pascal's Triangle II](https://leetcode.com/problems/pascals-triangle-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PascalsTriangleII.java) | | 121 | [Best Time to Buy and Sell Stocks](https://leetcode.com/problems/best-time-to-buy-and-sell-stock) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BestTimeToBuyAndSellStock.java) | diff --git a/python/path_sum.py b/python/path_sum.py new file mode 100644 index 0000000..bf1e7bc --- /dev/null +++ b/python/path_sum.py @@ -0,0 +1,30 @@ +# Definition for a binary tree node. +class TreeNode: + def __init__(self, val=0, left=None, right=None): + self.val = val + self.left = left + self.right = right + + +class Solution: + def _is_leaf_node(self, node: TreeNode) -> bool: + return node.left is None and node.right is None + + def _has_path_sum(self, root: TreeNode, target: int, currentSum: int) -> bool: + if root is None: + return False + currentSum += root.val + if self._is_leaf_node(root): + return currentSum == target + return self._has_path_sum(root.left, target, currentSum) or \ + self._has_path_sum(root.right, target, currentSum) + + def hasPathSum(self, root: TreeNode, targetSum: int) -> bool: + if root is None: + return False + return self._has_path_sum(root, targetSum, 0) + + +root = TreeNode(val=1) +root.right = TreeNode(val=2) +print(Solution().hasPathSum(root, 3)) From 99d063cea0219b5a12503ed224ab31894f4c6566 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 23 Jun 2021 21:01:39 +0530 Subject: [PATCH 024/947] solves pascals triangle in python --- README.md | 2 +- python/pascals_triangle.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 python/pascals_triangle.py diff --git a/README.md b/README.md index 5f24cdd..e1667e8 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ | 110 | [Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BalancedBinaryTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/balanced_binary_tree.py) | | 111 | [Minimum Depth of Binary Tree](https://leetcode.com/problems/minimum-depth-of-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MinimumDepthOfBinaryTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/minimum_depth_of_binary_tree.py) | | 112 | [Path Sum](https://leetcode.com/problems/path-sum) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PathSum.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/path_sum.py) | -| 118 | [Pascal's Triangle](https://leetcode.com/problems/pascals-triangle) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PascalsTriangle.java) | +| 118 | [Pascal's Triangle](https://leetcode.com/problems/pascals-triangle) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PascalsTriangle.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/pascals_triangle.py) | | 119 | [Pascal's Triangle II](https://leetcode.com/problems/pascals-triangle-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PascalsTriangleII.java) | | 121 | [Best Time to Buy and Sell Stocks](https://leetcode.com/problems/best-time-to-buy-and-sell-stock) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BestTimeToBuyAndSellStock.java) | | 122 | [Best Time to Buy and Sell Stocks II](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BestTimeToBuyAndSellStockII.java) | diff --git a/python/pascals_triangle.py b/python/pascals_triangle.py new file mode 100644 index 0000000..d2b959c --- /dev/null +++ b/python/pascals_triangle.py @@ -0,0 +1,13 @@ +from typing import List + + +class Solution: + def generate(self, numRows: int) -> List[List[int]]: + ans = [None] * numRows + for i in range(numRows): + row, mid = [1] * (i + 1), (i >> 1) + 1 + for j in range(1, mid): + val = ans[i - 1][j - 1] + ans[i-1][j] + row[j], row[len(row) - j-1] = val, val + ans[i] = row + return ans From 9f51a80d51d7701fcb86d84055a8741514ccd01c Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 24 Jun 2021 08:11:38 +0530 Subject: [PATCH 025/947] solves pascals triangle ii in python --- README.md | 2 +- python/pascals_triangle_ii.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 python/pascals_triangle_ii.py diff --git a/README.md b/README.md index e1667e8..45cda8f 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ | 111 | [Minimum Depth of Binary Tree](https://leetcode.com/problems/minimum-depth-of-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MinimumDepthOfBinaryTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/minimum_depth_of_binary_tree.py) | | 112 | [Path Sum](https://leetcode.com/problems/path-sum) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PathSum.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/path_sum.py) | | 118 | [Pascal's Triangle](https://leetcode.com/problems/pascals-triangle) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PascalsTriangle.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/pascals_triangle.py) | -| 119 | [Pascal's Triangle II](https://leetcode.com/problems/pascals-triangle-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PascalsTriangleII.java) | +| 119 | [Pascal's Triangle II](https://leetcode.com/problems/pascals-triangle-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PascalsTriangleII.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/pascals_triangle_ii.py) | | 121 | [Best Time to Buy and Sell Stocks](https://leetcode.com/problems/best-time-to-buy-and-sell-stock) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BestTimeToBuyAndSellStock.java) | | 122 | [Best Time to Buy and Sell Stocks II](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BestTimeToBuyAndSellStockII.java) | | 125 | [Valid Palindrome](https://leetcode.com/problems/valid-palindrome) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ValidPalindrome.java) | diff --git a/python/pascals_triangle_ii.py b/python/pascals_triangle_ii.py new file mode 100644 index 0000000..4a561b0 --- /dev/null +++ b/python/pascals_triangle_ii.py @@ -0,0 +1,12 @@ +from typing import List + + +class Solution: + def getRow(self, rowIndex: int) -> List[int]: + result = [1] * (rowIndex + 1) + val = 1 + for i in range(1, rowIndex): + val *= (rowIndex + 1 - i) + val //= i + result[i] = val + return result From 9bdbfcb7b0a63cd7a091dbea5ca9238d50619bec Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 24 Jun 2021 08:20:41 +0530 Subject: [PATCH 026/947] solves best time to buy and sell stock in python --- README.md | 2 +- python/best_time_to_buy_and_sell_stock.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 python/best_time_to_buy_and_sell_stock.py diff --git a/README.md b/README.md index 45cda8f..448ccd4 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ | 112 | [Path Sum](https://leetcode.com/problems/path-sum) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PathSum.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/path_sum.py) | | 118 | [Pascal's Triangle](https://leetcode.com/problems/pascals-triangle) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PascalsTriangle.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/pascals_triangle.py) | | 119 | [Pascal's Triangle II](https://leetcode.com/problems/pascals-triangle-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PascalsTriangleII.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/pascals_triangle_ii.py) | -| 121 | [Best Time to Buy and Sell Stocks](https://leetcode.com/problems/best-time-to-buy-and-sell-stock) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BestTimeToBuyAndSellStock.java) | +| 121 | [Best Time to Buy and Sell Stocks](https://leetcode.com/problems/best-time-to-buy-and-sell-stock) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BestTimeToBuyAndSellStock.java) [![Python](https://img.icons8.com/color/35/000000/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) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BestTimeToBuyAndSellStockII.java) | | 125 | [Valid Palindrome](https://leetcode.com/problems/valid-palindrome) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ValidPalindrome.java) | | 136 | [Single Number](https://leetcode.com/problems/single-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/SingleNumber.java) | diff --git a/python/best_time_to_buy_and_sell_stock.py b/python/best_time_to_buy_and_sell_stock.py new file mode 100644 index 0000000..c7b614d --- /dev/null +++ b/python/best_time_to_buy_and_sell_stock.py @@ -0,0 +1,10 @@ +from typing import List + + +class Solution: + def maxProfit(self, prices: List[int]) -> int: + max_profit, buy_price = 0, prices[0] + for price in prices: + max_profit = max(max_profit, price - buy_price) + buy_price = min(buy_price, price) + return max_profit From 939d30c1b9b3bcaf543eb1f133c6232ee7ce93f9 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 24 Jun 2021 08:45:59 +0530 Subject: [PATCH 027/947] solves buy and sell stock ii in python --- README.md | 2 +- python/best_time_to_buy_and_sell_stock_ii.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 python/best_time_to_buy_and_sell_stock_ii.py diff --git a/README.md b/README.md index 448ccd4..9b5da6d 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ | 118 | [Pascal's Triangle](https://leetcode.com/problems/pascals-triangle) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PascalsTriangle.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/pascals_triangle.py) | | 119 | [Pascal's Triangle II](https://leetcode.com/problems/pascals-triangle-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PascalsTriangleII.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/pascals_triangle_ii.py) | | 121 | [Best Time to Buy and Sell Stocks](https://leetcode.com/problems/best-time-to-buy-and-sell-stock) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BestTimeToBuyAndSellStock.java) [![Python](https://img.icons8.com/color/35/000000/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) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BestTimeToBuyAndSellStockII.java) | +| 122 | [Best Time to Buy and Sell Stocks II](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BestTimeToBuyAndSellStockII.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/best_time_to_buy_and_sell_stock_ii.py) | | 125 | [Valid Palindrome](https://leetcode.com/problems/valid-palindrome) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ValidPalindrome.java) | | 136 | [Single Number](https://leetcode.com/problems/single-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/SingleNumber.java) | | 141 | [Linked List Cycle](https://leetcode.com/problems/linked-list-cycle) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/LinkedListCycle.java) | diff --git a/python/best_time_to_buy_and_sell_stock_ii.py b/python/best_time_to_buy_and_sell_stock_ii.py new file mode 100644 index 0000000..a218dff --- /dev/null +++ b/python/best_time_to_buy_and_sell_stock_ii.py @@ -0,0 +1,15 @@ +from typing import List + + +class Solution: + def maxProfit(self, prices: List[int]) -> int: + buy_price, sell_price, profit = prices[0], prices[0], 0 + for price in prices: + if price < sell_price: + profit += sell_price - buy_price + buy_price = price + sell_price = price + else: + sell_price = price + profit += sell_price - buy_price + return profit From 11c5bd49ac9c9a6aaf0f8427304be4ed5fff13b2 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 24 Jun 2021 09:01:31 +0530 Subject: [PATCH 028/947] solves valid palindrome in python --- README.md | 2 +- python/valid_palindrome.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 python/valid_palindrome.py diff --git a/README.md b/README.md index 9b5da6d..cd7e178 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ | 119 | [Pascal's Triangle II](https://leetcode.com/problems/pascals-triangle-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PascalsTriangleII.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/pascals_triangle_ii.py) | | 121 | [Best Time to Buy and Sell Stocks](https://leetcode.com/problems/best-time-to-buy-and-sell-stock) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BestTimeToBuyAndSellStock.java) [![Python](https://img.icons8.com/color/35/000000/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) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BestTimeToBuyAndSellStockII.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/best_time_to_buy_and_sell_stock_ii.py) | -| 125 | [Valid Palindrome](https://leetcode.com/problems/valid-palindrome) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ValidPalindrome.java) | +| 125 | [Valid Palindrome](https://leetcode.com/problems/valid-palindrome) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ValidPalindrome.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/valid_palindrome.py) | | 136 | [Single Number](https://leetcode.com/problems/single-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/SingleNumber.java) | | 141 | [Linked List Cycle](https://leetcode.com/problems/linked-list-cycle) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/LinkedListCycle.java) | | 155 | [Min Stack](https://leetcode.com/problems/min-stack) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MinStack.java) | diff --git a/python/valid_palindrome.py b/python/valid_palindrome.py new file mode 100644 index 0000000..cd365e6 --- /dev/null +++ b/python/valid_palindrome.py @@ -0,0 +1,10 @@ +import string + + +class Solution: + def isPalindrome(self, s: str) -> bool: + for x in string.punctuation: + s = s.replace(x, '') + + s = s.replace(' ', '').lower() + return s == s[::-1] From 53566f04db7326a3dbb0bab8ea1d44045bfb8eb2 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 24 Jun 2021 09:10:06 +0530 Subject: [PATCH 029/947] solves --- README.md | 2 +- python/single_number.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 python/single_number.py diff --git a/README.md b/README.md index cd7e178..37b0dc7 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ | 121 | [Best Time to Buy and Sell Stocks](https://leetcode.com/problems/best-time-to-buy-and-sell-stock) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BestTimeToBuyAndSellStock.java) [![Python](https://img.icons8.com/color/35/000000/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) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BestTimeToBuyAndSellStockII.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/best_time_to_buy_and_sell_stock_ii.py) | | 125 | [Valid Palindrome](https://leetcode.com/problems/valid-palindrome) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ValidPalindrome.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/valid_palindrome.py) | -| 136 | [Single Number](https://leetcode.com/problems/single-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/SingleNumber.java) | +| 136 | [Single Number](https://leetcode.com/problems/single-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/SingleNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/single_number.py) | | 141 | [Linked List Cycle](https://leetcode.com/problems/linked-list-cycle) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/LinkedListCycle.java) | | 155 | [Min Stack](https://leetcode.com/problems/min-stack) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MinStack.java) | | 157 | [Read N Characters Given Read4](https://leetcode.com/problems/read-n-characters-given-read4) | Easy | | diff --git a/python/single_number.py b/python/single_number.py new file mode 100644 index 0000000..e8044b2 --- /dev/null +++ b/python/single_number.py @@ -0,0 +1,9 @@ +from typing import List + + +class Solution: + def singleNumber(self, nums: List[int]) -> int: + val = 0 + for number in nums: + val ^= number + return val From e5cb25a4571e6c2002cb6ab8b3aed29281a13bea Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 24 Jun 2021 09:20:21 +0530 Subject: [PATCH 030/947] solves linked list cycle --- README.md | 2 +- python/linked_list_cycle.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 python/linked_list_cycle.py diff --git a/README.md b/README.md index 37b0dc7..598443c 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ | 122 | [Best Time to Buy and Sell Stocks II](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BestTimeToBuyAndSellStockII.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/best_time_to_buy_and_sell_stock_ii.py) | | 125 | [Valid Palindrome](https://leetcode.com/problems/valid-palindrome) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ValidPalindrome.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/valid_palindrome.py) | | 136 | [Single Number](https://leetcode.com/problems/single-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/SingleNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/single_number.py) | -| 141 | [Linked List Cycle](https://leetcode.com/problems/linked-list-cycle) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/LinkedListCycle.java) | +| 141 | [Linked List Cycle](https://leetcode.com/problems/linked-list-cycle) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/LinkedListCycle.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/linked_list_cycle.py) | | 155 | [Min Stack](https://leetcode.com/problems/min-stack) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MinStack.java) | | 157 | [Read N Characters Given Read4](https://leetcode.com/problems/read-n-characters-given-read4) | Easy | | | 160 | [Intersection of Two Linked Lists](https://leetcode.com/problems/intersection-of-two-linked-lists) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/IntersectionOf2LinkedLists.java) | diff --git a/python/linked_list_cycle.py b/python/linked_list_cycle.py new file mode 100644 index 0000000..f2872d4 --- /dev/null +++ b/python/linked_list_cycle.py @@ -0,0 +1,21 @@ +# Definition for singly-linked list. +class ListNode: + def __init__(self, x): + self.val = x + self.next = None + + +class Solution: + def not_null(self, head: ListNode) -> bool: + return head is not None + + def hasCycle(self, head: ListNode) -> bool: + if head is None: + return False + slow, fast = head, head.next + while self.not_null(slow) and self.not_null(fast) and self.not_null(slow.next) and self.not_null(fast.next): + if slow is fast: + return True + slow = slow.next + fast = fast.next.next + return False From 36f65045f67d049d5887a7faa5806e2495332f2f Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 24 Jun 2021 14:52:48 +0530 Subject: [PATCH 031/947] solves min stack in python --- README.md | 2 +- python/min_stack.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 python/min_stack.py diff --git a/README.md b/README.md index 598443c..713d847 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ | 125 | [Valid Palindrome](https://leetcode.com/problems/valid-palindrome) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ValidPalindrome.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/valid_palindrome.py) | | 136 | [Single Number](https://leetcode.com/problems/single-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/SingleNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/single_number.py) | | 141 | [Linked List Cycle](https://leetcode.com/problems/linked-list-cycle) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/LinkedListCycle.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/linked_list_cycle.py) | -| 155 | [Min Stack](https://leetcode.com/problems/min-stack) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MinStack.java) | +| 155 | [Min Stack](https://leetcode.com/problems/min-stack) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MinStack.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/min_stack.py) | | 157 | [Read N Characters Given Read4](https://leetcode.com/problems/read-n-characters-given-read4) | Easy | | | 160 | [Intersection of Two Linked Lists](https://leetcode.com/problems/intersection-of-two-linked-lists) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/IntersectionOf2LinkedLists.java) | | 167 | [Two Sum II - Input Array is Sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/TwoSumIIInputArrayIsSorted.java) | diff --git a/python/min_stack.py b/python/min_stack.py new file mode 100644 index 0000000..a080dd7 --- /dev/null +++ b/python/min_stack.py @@ -0,0 +1,32 @@ +class Node: + def __init__(self, val, min, previous): + self.val = val + self.next = next + self.min = min + self.previous = previous + +class MinStack: + + def __init__(self): + """ + initialize your data structure here. + """ + self.current = None + + def push(self, val: int) -> None: + if self.current is None: + self.current = Node(val, val, None) + else: + self.current.next = Node(val, min(val, self.current.min), self.current) + self.current = self.current.next + + def pop(self) -> None: + val = self.current.val + self.current = self.current.previous + return val + + def top(self) -> int: + return self.current.val + + def getMin(self) -> int: + return self.current.min From 949f41ac2b5d9631bd229453fa9175161a19c465 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 24 Jun 2021 17:14:46 +0530 Subject: [PATCH 032/947] solves intersection of 2linked lists in python --- README.md | 2 +- python/intersecction_of_two_linked_lists.py | 22 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 python/intersecction_of_two_linked_lists.py diff --git a/README.md b/README.md index 713d847..eb52adc 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ | 141 | [Linked List Cycle](https://leetcode.com/problems/linked-list-cycle) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/LinkedListCycle.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/linked_list_cycle.py) | | 155 | [Min Stack](https://leetcode.com/problems/min-stack) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MinStack.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/min_stack.py) | | 157 | [Read N Characters Given Read4](https://leetcode.com/problems/read-n-characters-given-read4) | Easy | | -| 160 | [Intersection of Two Linked Lists](https://leetcode.com/problems/intersection-of-two-linked-lists) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/IntersectionOf2LinkedLists.java) | +| 160 | [Intersection of Two Linked Lists](https://leetcode.com/problems/intersection-of-two-linked-lists) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/IntersectionOf2LinkedLists.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/intersecction_of_two_linked_lists.py) | | 167 | [Two Sum II - Input Array is Sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/TwoSumIIInputArrayIsSorted.java) | | 168 | [Excel Sheet Column Title](https://leetcode.com/problems/excel-sheet-column-title) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ExcelSheetColumnTitle.java) | | 169 | [Majority Element](https://leetcode.com/problems/majority-element) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MajorityElement.java) | diff --git a/python/intersecction_of_two_linked_lists.py b/python/intersecction_of_two_linked_lists.py new file mode 100644 index 0000000..8b771ab --- /dev/null +++ b/python/intersecction_of_two_linked_lists.py @@ -0,0 +1,22 @@ +class ListNode: + def __init__(self, x): + self.val = x + self.next = None + + +class Solution: + def getIntersectionNode(self, headA: ListNode, headB: ListNode) -> ListNode: + runner_1, runner_2 = headA, headB + + while runner_1 is not runner_2: + if runner_1 is None: + runner_1 = headB + else: + runner_1 = runner_1.next + + if runner_2 is None: + runner_2 = headA + else: + runner_2 = runner_2.next + + return None if runner_1 is None else runner_1 From 4798e4df7432cd0977c63be036543f49bce3f923 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 26 Jun 2021 14:00:04 +0530 Subject: [PATCH 033/947] solves excel sheet column number in python --- README.md | 4 ++-- python/excel_sheet_column_title.py | 7 +++++++ python/two_sum_ii.py | 13 +++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 python/excel_sheet_column_title.py create mode 100644 python/two_sum_ii.py diff --git a/README.md b/README.md index eb52adc..0b5f5da 100644 --- a/README.md +++ b/README.md @@ -46,8 +46,8 @@ | 155 | [Min Stack](https://leetcode.com/problems/min-stack) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MinStack.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/min_stack.py) | | 157 | [Read N Characters Given Read4](https://leetcode.com/problems/read-n-characters-given-read4) | Easy | | | 160 | [Intersection of Two Linked Lists](https://leetcode.com/problems/intersection-of-two-linked-lists) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/IntersectionOf2LinkedLists.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/intersecction_of_two_linked_lists.py) | -| 167 | [Two Sum II - Input Array is Sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/TwoSumIIInputArrayIsSorted.java) | -| 168 | [Excel Sheet Column Title](https://leetcode.com/problems/excel-sheet-column-title) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ExcelSheetColumnTitle.java) | +| 167 | [Two Sum II - Input Array is Sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/TwoSumIIInputArrayIsSorted.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/two_sum_ii.py) | +| 168 | [Excel Sheet Column Title](https://leetcode.com/problems/excel-sheet-column-title) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ExcelSheetColumnTitle.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/excel_sheet_column_title.py) | | 169 | [Majority Element](https://leetcode.com/problems/majority-element) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MajorityElement.java) | | 170 | [Two Sum III - Data Structure Design](https://leetcode.com/problems/two-sum-iii-data-structure-design) | Easy | | | 171 | [Excel Sheet Column Number](https://leetcode.com/problems/excel-sheet-column-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ExcelSheetColumnNumber.java) | diff --git a/python/excel_sheet_column_title.py b/python/excel_sheet_column_title.py new file mode 100644 index 0000000..d4c4d3a --- /dev/null +++ b/python/excel_sheet_column_title.py @@ -0,0 +1,7 @@ +class Solution: + def convertToTitle(self, columnNumber: int) -> str: + column_title = '' + while columnNumber > 0: + columnNumber, digit = divmod(columnNumber - 1, 26) + column_title = chr(digit + 65) + column_title + return column_title diff --git a/python/two_sum_ii.py b/python/two_sum_ii.py new file mode 100644 index 0000000..55f34c3 --- /dev/null +++ b/python/two_sum_ii.py @@ -0,0 +1,13 @@ +from typing import List + + +class Solution: + def twoSum(self, numbers: List[int], target: int) -> List[int]: + left, right = 0, len(numbers) - 1 + while left < right: + if numbers[left] + numbers[right] == target: + return [left + 1, right + 1] + elif numbers[left] + numbers[right] < target: + left += 1 + else: + right -= 1 From cd6c364803d14092f4b8c266e0c15bbf1ac67f9b Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 26 Jun 2021 14:14:38 +0530 Subject: [PATCH 034/947] solves majority element in python --- README.md | 2 +- python/majority_element.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 python/majority_element.py diff --git a/README.md b/README.md index 0b5f5da..5952a93 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ | 160 | [Intersection of Two Linked Lists](https://leetcode.com/problems/intersection-of-two-linked-lists) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/IntersectionOf2LinkedLists.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/intersecction_of_two_linked_lists.py) | | 167 | [Two Sum II - Input Array is Sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/TwoSumIIInputArrayIsSorted.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/two_sum_ii.py) | | 168 | [Excel Sheet Column Title](https://leetcode.com/problems/excel-sheet-column-title) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ExcelSheetColumnTitle.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/excel_sheet_column_title.py) | -| 169 | [Majority Element](https://leetcode.com/problems/majority-element) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MajorityElement.java) | +| 169 | [Majority Element](https://leetcode.com/problems/majority-element) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MajorityElement.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/majority_element.py) | | 170 | [Two Sum III - Data Structure Design](https://leetcode.com/problems/two-sum-iii-data-structure-design) | Easy | | | 171 | [Excel Sheet Column Number](https://leetcode.com/problems/excel-sheet-column-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ExcelSheetColumnNumber.java) | | 172 | [Factoring Trailing Zeroes](https://leetcode.com/problems/factorial-trailing-zeroes) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FactorialTrailingZeros.java) | diff --git a/python/majority_element.py b/python/majority_element.py new file mode 100644 index 0000000..10326bd --- /dev/null +++ b/python/majority_element.py @@ -0,0 +1,12 @@ +from typing import List + + +class Solution: + def majorityElement(self, nums: List[int]) -> int: + element, count = nums[0], 0 + for number in nums: + count += 1 if number == element else -1 + if count == 0: + element = number + count = 1 + return element From d378369ab8cc9688af8527f880e1726b4e0092e2 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 26 Jun 2021 14:22:34 +0530 Subject: [PATCH 035/947] solves excel sheet column number in python --- README.md | 2 +- python/excel_sheet_column_number.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 python/excel_sheet_column_number.py diff --git a/README.md b/README.md index 5952a93..f335ac0 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ | 168 | [Excel Sheet Column Title](https://leetcode.com/problems/excel-sheet-column-title) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ExcelSheetColumnTitle.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/excel_sheet_column_title.py) | | 169 | [Majority Element](https://leetcode.com/problems/majority-element) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MajorityElement.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/majority_element.py) | | 170 | [Two Sum III - Data Structure Design](https://leetcode.com/problems/two-sum-iii-data-structure-design) | Easy | | -| 171 | [Excel Sheet Column Number](https://leetcode.com/problems/excel-sheet-column-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ExcelSheetColumnNumber.java) | +| 171 | [Excel Sheet Column Number](https://leetcode.com/problems/excel-sheet-column-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ExcelSheetColumnNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/excel_sheet_column_number.py) | | 172 | [Factoring Trailing Zeroes](https://leetcode.com/problems/factorial-trailing-zeroes) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FactorialTrailingZeros.java) | | 189 | [Rotate Array](https://leetcode.com/problems/rotate-array) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RotateArray.java) | | 190 | [Reverse Bits](https://leetcode.com/problems/reverse-bits) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ReverseBits.java) | diff --git a/python/excel_sheet_column_number.py b/python/excel_sheet_column_number.py new file mode 100644 index 0000000..8f69cff --- /dev/null +++ b/python/excel_sheet_column_number.py @@ -0,0 +1,6 @@ +class Solution: + def titleToNumber(self, columnTitle: str) -> int: + value = 0 + for character in columnTitle: + value = 26 * value + ord(character) - 64 + return value From 3b55b07e16f948f4d66ca9546444a2bc6ff8d00e Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 26 Jun 2021 16:34:47 +0530 Subject: [PATCH 036/947] solves trailing factorial zeroes in python --- README.md | 2 +- python/factorial_trailing_zeroes.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 python/factorial_trailing_zeroes.py diff --git a/README.md b/README.md index f335ac0..d43ba29 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ | 169 | [Majority Element](https://leetcode.com/problems/majority-element) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MajorityElement.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/majority_element.py) | | 170 | [Two Sum III - Data Structure Design](https://leetcode.com/problems/two-sum-iii-data-structure-design) | Easy | | | 171 | [Excel Sheet Column Number](https://leetcode.com/problems/excel-sheet-column-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ExcelSheetColumnNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/excel_sheet_column_number.py) | -| 172 | [Factoring Trailing Zeroes](https://leetcode.com/problems/factorial-trailing-zeroes) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FactorialTrailingZeros.java) | +| 172 | [Factoring Trailing Zeroes](https://leetcode.com/problems/factorial-trailing-zeroes) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FactorialTrailingZeros.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/factorial_trailing_zeroes.py) | | 189 | [Rotate Array](https://leetcode.com/problems/rotate-array) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RotateArray.java) | | 190 | [Reverse Bits](https://leetcode.com/problems/reverse-bits) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ReverseBits.java) | | 191 | [Number of One Bits](https://leetcode.com/problems/number-of-1-bits) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/NumberOf1Bit.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/number_of_1_bits.py) | diff --git a/python/factorial_trailing_zeroes.py b/python/factorial_trailing_zeroes.py new file mode 100644 index 0000000..ab34b34 --- /dev/null +++ b/python/factorial_trailing_zeroes.py @@ -0,0 +1,7 @@ +class Solution: + def trailingZeroes(self, n: int) -> int: + divisor, count = 5, 0 + while n // divisor > 0: + count += n // divisor + divisor *= 5 + return count From 8a9b472cf29656275501922f459dab14fbd99c2d Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 26 Jun 2021 16:58:27 +0530 Subject: [PATCH 037/947] solves rotate array in python --- README.md | 2 +- python/factorial_trailing_zeroes.py | 2 +- python/rotate_array.py | 31 +++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 python/rotate_array.py diff --git a/README.md b/README.md index d43ba29..8532930 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ | 170 | [Two Sum III - Data Structure Design](https://leetcode.com/problems/two-sum-iii-data-structure-design) | Easy | | | 171 | [Excel Sheet Column Number](https://leetcode.com/problems/excel-sheet-column-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ExcelSheetColumnNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/excel_sheet_column_number.py) | | 172 | [Factoring Trailing Zeroes](https://leetcode.com/problems/factorial-trailing-zeroes) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FactorialTrailingZeros.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/factorial_trailing_zeroes.py) | -| 189 | [Rotate Array](https://leetcode.com/problems/rotate-array) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RotateArray.java) | +| 189 | [Rotate Array](https://leetcode.com/problems/rotate-array) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RotateArray.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/rotate_array.py) | | 190 | [Reverse Bits](https://leetcode.com/problems/reverse-bits) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ReverseBits.java) | | 191 | [Number of One Bits](https://leetcode.com/problems/number-of-1-bits) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/NumberOf1Bit.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/number_of_1_bits.py) | | 198 | [House Robber](https://leetcode.com/problems/house-robber) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/HouseRobber.java) | diff --git a/python/factorial_trailing_zeroes.py b/python/factorial_trailing_zeroes.py index ab34b34..6751ffc 100644 --- a/python/factorial_trailing_zeroes.py +++ b/python/factorial_trailing_zeroes.py @@ -1,7 +1,7 @@ class Solution: def trailingZeroes(self, n: int) -> int: divisor, count = 5, 0 - while n // divisor > 0: + while divisor <= n: count += n // divisor divisor *= 5 return count diff --git a/python/rotate_array.py b/python/rotate_array.py new file mode 100644 index 0000000..0ecd64e --- /dev/null +++ b/python/rotate_array.py @@ -0,0 +1,31 @@ +from typing import List + + +class Solution: + def rotate(self, nums: List[int], k: int) -> None: + """ + Do not return anything, modify nums in-place instead. + """ + k %= len(nums) + if k == 0: + return + temp = nums[-k:] + for i in range(len(nums) - 1, k - 1, -1): + nums[i] = nums[i - k] + for i, val in enumerate(temp): + nums[i] = val + + def reverse(self, A, i, j): + while i < j: + A[i], A[j] = A[j], A[i] + i += 1 + j -= 1 + + # this is method no. 2 to solve it with O(1) space complexity + def rotate_2(self, A, k): + L = len(A) + k %= L + if k: + self.reverse(A, 0, L - 1) + self.reverse(A, 0, k - 1) + self.reverse(A, k, L - 1) From cccfd843245cbe0cad00799d0de4f18b4f06443c Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 26 Jun 2021 17:11:06 +0530 Subject: [PATCH 038/947] solves reverse bits in python --- README.md | 2 +- python/reverse_bits.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 python/reverse_bits.py diff --git a/README.md b/README.md index 8532930..8cca15a 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ | 171 | [Excel Sheet Column Number](https://leetcode.com/problems/excel-sheet-column-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ExcelSheetColumnNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/excel_sheet_column_number.py) | | 172 | [Factoring Trailing Zeroes](https://leetcode.com/problems/factorial-trailing-zeroes) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FactorialTrailingZeros.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/factorial_trailing_zeroes.py) | | 189 | [Rotate Array](https://leetcode.com/problems/rotate-array) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RotateArray.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/rotate_array.py) | -| 190 | [Reverse Bits](https://leetcode.com/problems/reverse-bits) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ReverseBits.java) | +| 190 | [Reverse Bits](https://leetcode.com/problems/reverse-bits) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ReverseBits.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_bits.py) | | 191 | [Number of One Bits](https://leetcode.com/problems/number-of-1-bits) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/NumberOf1Bit.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/number_of_1_bits.py) | | 198 | [House Robber](https://leetcode.com/problems/house-robber) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/HouseRobber.java) | | 202 | [Happy Number](https://leetcode.com/problems/happy-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/HappyNumber.java) | diff --git a/python/reverse_bits.py b/python/reverse_bits.py new file mode 100644 index 0000000..ad24511 --- /dev/null +++ b/python/reverse_bits.py @@ -0,0 +1,7 @@ +class Solution: + def reverseBits(self, n: int) -> int: + binary_str = bin(n)[2:] + binary_str = '0' * (32 - len(binary_str)) + binary_str + print(binary_str) + reverse = binary_str[::-1] + return int(reverse, base=2) From b534f3b87a6f3b3ffebcdf73273f6e3797298899 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 26 Jun 2021 17:19:50 +0530 Subject: [PATCH 039/947] solves happy number in python --- README.md | 2 +- python/happy_number.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 python/happy_number.py diff --git a/README.md b/README.md index 8cca15a..886e074 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ | 190 | [Reverse Bits](https://leetcode.com/problems/reverse-bits) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ReverseBits.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_bits.py) | | 191 | [Number of One Bits](https://leetcode.com/problems/number-of-1-bits) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/NumberOf1Bit.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/number_of_1_bits.py) | | 198 | [House Robber](https://leetcode.com/problems/house-robber) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/HouseRobber.java) | -| 202 | [Happy Number](https://leetcode.com/problems/happy-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/HappyNumber.java) | +| 202 | [Happy Number](https://leetcode.com/problems/happy-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/HappyNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/happy_number.py) | | 203 | [Remove Linked List Elements](https://leetcode.com/problems/remove-linked-list-elements) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RemoveLinkedListElements.java) | | 204 | [Count Primes](https://leetcode.com/problems/count-primes) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/CountPrimes.java) | | 205 | [Isomorphic Strings](https://leetcode.com/problems/isomorphic-strings) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/IsomorphicStrings.java) | diff --git a/python/happy_number.py b/python/happy_number.py new file mode 100644 index 0000000..898f2ff --- /dev/null +++ b/python/happy_number.py @@ -0,0 +1,12 @@ +class Solution: + def _is_happy(self, number: int, previously_used: set) -> bool: + if number is 1: + return True + new_number = sum(int(digit) ** 2 for digit in str(number)) + if new_number in previously_used: + return False + previously_used.add(new_number) + return self._is_happy(new_number, previously_used) + + def isHappy(self, n: int) -> bool: + return self._is_happy(number=n, previously_used={n}) From 90317bd593f86e43f6545730fa1da31957362800 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 26 Jun 2021 23:01:46 +0530 Subject: [PATCH 040/947] solves house robber in python --- README.md | 2 +- python/house_robber.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 python/house_robber.py diff --git a/README.md b/README.md index 886e074..0f8afda 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ | 189 | [Rotate Array](https://leetcode.com/problems/rotate-array) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RotateArray.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/rotate_array.py) | | 190 | [Reverse Bits](https://leetcode.com/problems/reverse-bits) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ReverseBits.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_bits.py) | | 191 | [Number of One Bits](https://leetcode.com/problems/number-of-1-bits) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/NumberOf1Bit.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/number_of_1_bits.py) | -| 198 | [House Robber](https://leetcode.com/problems/house-robber) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/HouseRobber.java) | +| 198 | [House Robber](https://leetcode.com/problems/house-robber) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/HouseRobber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/house_robber.py) | | 202 | [Happy Number](https://leetcode.com/problems/happy-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/HappyNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/happy_number.py) | | 203 | [Remove Linked List Elements](https://leetcode.com/problems/remove-linked-list-elements) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RemoveLinkedListElements.java) | | 204 | [Count Primes](https://leetcode.com/problems/count-primes) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/CountPrimes.java) | diff --git a/python/house_robber.py b/python/house_robber.py new file mode 100644 index 0000000..c7b71e5 --- /dev/null +++ b/python/house_robber.py @@ -0,0 +1,10 @@ +from typing import List + + +class Solution: + def rob(self, nums: List[int]) -> int: + a, b, max_amount = 0, nums[0], nums[0] + for index in range(1, len(nums)): + max_amount = max(a + nums[index], b) + a, b = b, max_amount + return max_amount From 2ad1b6f429b64222b259656fe4f6f05409e2a2b6 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 27 Jun 2021 00:39:02 +0530 Subject: [PATCH 041/947] solves remove a linked list element --- README.md | 2 +- python/remove_linked_list_elements.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 python/remove_linked_list_elements.py diff --git a/README.md b/README.md index 0f8afda..454f70b 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ | 191 | [Number of One Bits](https://leetcode.com/problems/number-of-1-bits) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/NumberOf1Bit.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/number_of_1_bits.py) | | 198 | [House Robber](https://leetcode.com/problems/house-robber) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/HouseRobber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/house_robber.py) | | 202 | [Happy Number](https://leetcode.com/problems/happy-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/HappyNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/happy_number.py) | -| 203 | [Remove Linked List Elements](https://leetcode.com/problems/remove-linked-list-elements) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RemoveLinkedListElements.java) | +| 203 | [Remove Linked List Elements](https://leetcode.com/problems/remove-linked-list-elements) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RemoveLinkedListElements.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/remove_linked_list_elements.py) | | 204 | [Count Primes](https://leetcode.com/problems/count-primes) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/CountPrimes.java) | | 205 | [Isomorphic Strings](https://leetcode.com/problems/isomorphic-strings) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/IsomorphicStrings.java) | | 206 | [Reverse Linked Lists](https://leetcode.com/problems/reverse-linked-list) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ReverseLinkedList.java) | diff --git a/python/remove_linked_list_elements.py b/python/remove_linked_list_elements.py new file mode 100644 index 0000000..9ffcf55 --- /dev/null +++ b/python/remove_linked_list_elements.py @@ -0,0 +1,20 @@ +from typing import Union + + +# Definition for singly-linked list. +class ListNode: + def __init__(self, val=0, next=None): + self.val = val + self.next = next + + +class Solution: + def removeElements(self, head: ListNode, val: int) -> Union[None, ListNode]: + current = ListNode(val=0, next=head) + start = current + while current is not None and current.next is not None: + if current.next.val == val: + current.next = current.next.next + else: + current = current.next + return start.next From 344af903e644277aca2ecfb4165bea3e1bba8386 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 27 Jun 2021 00:47:09 +0530 Subject: [PATCH 042/947] solves count primes in python --- README.md | 2 +- python/count_primes.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 python/count_primes.py diff --git a/README.md b/README.md index 454f70b..eacec5e 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ | 198 | [House Robber](https://leetcode.com/problems/house-robber) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/HouseRobber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/house_robber.py) | | 202 | [Happy Number](https://leetcode.com/problems/happy-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/HappyNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/happy_number.py) | | 203 | [Remove Linked List Elements](https://leetcode.com/problems/remove-linked-list-elements) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RemoveLinkedListElements.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/remove_linked_list_elements.py) | -| 204 | [Count Primes](https://leetcode.com/problems/count-primes) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/CountPrimes.java) | +| 204 | [Count Primes](https://leetcode.com/problems/count-primes) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/CountPrimes.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/count_primes.py) | | 205 | [Isomorphic Strings](https://leetcode.com/problems/isomorphic-strings) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/IsomorphicStrings.java) | | 206 | [Reverse Linked Lists](https://leetcode.com/problems/reverse-linked-list) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ReverseLinkedList.java) | | 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ContainsDuplicate.java) | diff --git a/python/count_primes.py b/python/count_primes.py new file mode 100644 index 0000000..afba245 --- /dev/null +++ b/python/count_primes.py @@ -0,0 +1,15 @@ +from typing import List + + +class Solution: + def _get_prime_sieve(self, size: int) -> List[int]: + sieve = [1] * (max(size, 2)) + sieve[0], sieve[1] = 0, 0 + for number in range(2, len(sieve)): + if sieve[number]: + for dividend in range(number ** 2, len(sieve), number): + sieve[dividend] = 0 + return sieve + + def countPrimes(self, n: int) -> int: + return sum(self._get_prime_sieve(n)) From de401057a435235af151478e1579004685401206 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 27 Jun 2021 00:57:26 +0530 Subject: [PATCH 043/947] solves isomorphic strings in python --- README.md | 2 +- python/isomorphic_strings.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 python/isomorphic_strings.py diff --git a/README.md b/README.md index eacec5e..d299f05 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ | 202 | [Happy Number](https://leetcode.com/problems/happy-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/HappyNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/happy_number.py) | | 203 | [Remove Linked List Elements](https://leetcode.com/problems/remove-linked-list-elements) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RemoveLinkedListElements.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/remove_linked_list_elements.py) | | 204 | [Count Primes](https://leetcode.com/problems/count-primes) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/CountPrimes.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/count_primes.py) | -| 205 | [Isomorphic Strings](https://leetcode.com/problems/isomorphic-strings) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/IsomorphicStrings.java) | +| 205 | [Isomorphic Strings](https://leetcode.com/problems/isomorphic-strings) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/IsomorphicStrings.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/isomorphic_strings.py) | | 206 | [Reverse Linked Lists](https://leetcode.com/problems/reverse-linked-list) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ReverseLinkedList.java) | | 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ContainsDuplicate.java) | | 219 | [Contains Duplicate II](https://leetcode.com/problems/contains-duplicate-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ContainsDuplicateII.java) | diff --git a/python/isomorphic_strings.py b/python/isomorphic_strings.py new file mode 100644 index 0000000..5200671 --- /dev/null +++ b/python/isomorphic_strings.py @@ -0,0 +1,17 @@ +from typing import Dict + + +class Solution: + def isIsomorphic(self, s: str, t: str) -> bool: + mapping = {} + mapped_chars = set() + for char_s, char_t in zip(s, t): + if char_s in mapping: + if mapping[char_s] != char_t: + return False + else: + if char_t in mapped_chars: + return False + mapping[char_s] = char_t + mapped_chars.add(char_t) + return True From 16b2bee634dee5f12ec568f22b3ede2ac9af7651 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 27 Jun 2021 01:05:07 +0530 Subject: [PATCH 044/947] solves reverse a linked list in python --- README.md | 2 +- python/reverse_linked_list.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 python/reverse_linked_list.py diff --git a/README.md b/README.md index d299f05..1ba8773 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ | 203 | [Remove Linked List Elements](https://leetcode.com/problems/remove-linked-list-elements) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RemoveLinkedListElements.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/remove_linked_list_elements.py) | | 204 | [Count Primes](https://leetcode.com/problems/count-primes) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/CountPrimes.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/count_primes.py) | | 205 | [Isomorphic Strings](https://leetcode.com/problems/isomorphic-strings) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/IsomorphicStrings.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/isomorphic_strings.py) | -| 206 | [Reverse Linked Lists](https://leetcode.com/problems/reverse-linked-list) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ReverseLinkedList.java) | +| 206 | [Reverse Linked Lists](https://leetcode.com/problems/reverse-linked-list) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ReverseLinkedList.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_linked_list.py) | | 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ContainsDuplicate.java) | | 219 | [Contains Duplicate II](https://leetcode.com/problems/contains-duplicate-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ContainsDuplicateII.java) | | 225 | [Implement Stack using Queues](https://leetcode.com/problems/implement-stack-using-queues) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MyStack.java) | diff --git a/python/reverse_linked_list.py b/python/reverse_linked_list.py new file mode 100644 index 0000000..eb941f7 --- /dev/null +++ b/python/reverse_linked_list.py @@ -0,0 +1,21 @@ +from typing import Optional + + +# Definition for singly-linked list. +class ListNode: + def __init__(self, val=0, next=None): + self.val = val + self.next = next + + +class Solution: + def reverseList(self, head: ListNode) -> Optional[ListNode]: + if head is None or head.next is None: + return head + a, b, c = head, head.next, head.next.next + a.next = None + while c is not None: + b.next = a + a, b, c = b, c, c.next + b.next = a + return b From 57e9e2681f991323f6d6450bdba7ce938a758288 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 27 Jun 2021 01:07:57 +0530 Subject: [PATCH 045/947] solves contains duplicate in python --- README.md | 2 +- python/contains_duplicate.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 python/contains_duplicate.py diff --git a/README.md b/README.md index 1ba8773..2492b82 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ | 204 | [Count Primes](https://leetcode.com/problems/count-primes) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/CountPrimes.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/count_primes.py) | | 205 | [Isomorphic Strings](https://leetcode.com/problems/isomorphic-strings) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/IsomorphicStrings.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/isomorphic_strings.py) | | 206 | [Reverse Linked Lists](https://leetcode.com/problems/reverse-linked-list) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ReverseLinkedList.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_linked_list.py) | -| 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ContainsDuplicate.java) | +| 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ContainsDuplicate.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/contains_duplicate.py) | | 219 | [Contains Duplicate II](https://leetcode.com/problems/contains-duplicate-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ContainsDuplicateII.java) | | 225 | [Implement Stack using Queues](https://leetcode.com/problems/implement-stack-using-queues) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MyStack.java) | | 226 | [Invert Binary Tree](https://leetcode.com/problems/invert-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/InvertBinaryTree.java) | diff --git a/python/contains_duplicate.py b/python/contains_duplicate.py new file mode 100644 index 0000000..c58e2fe --- /dev/null +++ b/python/contains_duplicate.py @@ -0,0 +1,11 @@ +from typing import List + + +class Solution: + def containsDuplicate(self, nums: List[int]) -> bool: + numbers = set() + for number in nums: + if number in numbers: + return True + numbers.add(number) + return False From 16c49c18d07d94c0be701d254a0f7d349e7dab71 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 27 Jun 2021 01:15:06 +0530 Subject: [PATCH 046/947] solves contains duplicate II in python --- README.md | 2 +- python/contains_duplicate_ii.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 python/contains_duplicate_ii.py diff --git a/README.md b/README.md index 2492b82..7ca3df2 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ | 205 | [Isomorphic Strings](https://leetcode.com/problems/isomorphic-strings) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/IsomorphicStrings.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/isomorphic_strings.py) | | 206 | [Reverse Linked Lists](https://leetcode.com/problems/reverse-linked-list) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ReverseLinkedList.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_linked_list.py) | | 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ContainsDuplicate.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/contains_duplicate.py) | -| 219 | [Contains Duplicate II](https://leetcode.com/problems/contains-duplicate-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ContainsDuplicateII.java) | +| 219 | [Contains Duplicate II](https://leetcode.com/problems/contains-duplicate-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ContainsDuplicateII.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/contains_duplicate_ii.py) | | 225 | [Implement Stack using Queues](https://leetcode.com/problems/implement-stack-using-queues) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MyStack.java) | | 226 | [Invert Binary Tree](https://leetcode.com/problems/invert-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/InvertBinaryTree.java) | | 231 | [Power of Two](https://leetcode.com/problems/power-of-two) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PowerOf2.java) | diff --git a/python/contains_duplicate_ii.py b/python/contains_duplicate_ii.py new file mode 100644 index 0000000..c09fa35 --- /dev/null +++ b/python/contains_duplicate_ii.py @@ -0,0 +1,11 @@ +from typing import List + + +class Solution: + def containsNearbyDuplicate(self, nums: List[int], k: int) -> bool: + position = {} + for index, number in enumerate(nums): + if number in position and abs(index - position[number]) <= k: + return True + position[number] = index + return False From 9a6604e9c22577ee00fbf04cbe6c30b610e83e03 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 27 Jun 2021 01:20:47 +0530 Subject: [PATCH 047/947] implement stack using queues --- README.md | 2 +- python/implement_stack_using_queues.py | 41 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 python/implement_stack_using_queues.py diff --git a/README.md b/README.md index 7ca3df2..9fe4702 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ | 206 | [Reverse Linked Lists](https://leetcode.com/problems/reverse-linked-list) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ReverseLinkedList.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_linked_list.py) | | 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ContainsDuplicate.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/contains_duplicate.py) | | 219 | [Contains Duplicate II](https://leetcode.com/problems/contains-duplicate-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ContainsDuplicateII.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/contains_duplicate_ii.py) | -| 225 | [Implement Stack using Queues](https://leetcode.com/problems/implement-stack-using-queues) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MyStack.java) | +| 225 | [Implement Stack using Queues](https://leetcode.com/problems/implement-stack-using-queues) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MyStack.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/implement_stack_using_queues.py) | | 226 | [Invert Binary Tree](https://leetcode.com/problems/invert-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/InvertBinaryTree.java) | | 231 | [Power of Two](https://leetcode.com/problems/power-of-two) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PowerOf2.java) | | 232 | [Implement Queue Using Stacks]() | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MyQueue.java) | diff --git a/python/implement_stack_using_queues.py b/python/implement_stack_using_queues.py new file mode 100644 index 0000000..8d47c3c --- /dev/null +++ b/python/implement_stack_using_queues.py @@ -0,0 +1,41 @@ +from collections import deque + + +class MyStack: + + def __init__(self): + """ + Initialize your data structure here. + """ + self.queue = deque() + + def push(self, x: int) -> None: + """ + Push element x onto stack. + """ + self.queue.append(x) + + def pop(self) -> int: + """ + Removes the element on top of the stack and returns that element. + """ + return self.queue.pop() + + def top(self) -> int: + """ + Get the top element. + """ + return self.queue[-1] + + def empty(self) -> bool: + """ + Returns whether the stack is empty. + """ + return len(self.queue) == 0 + +# Your MyStack object will be instantiated and called as such: +# obj = MyStack() +# obj.push(x) +# param_2 = obj.pop() +# param_3 = obj.top() +# param_4 = obj.empty() \ No newline at end of file From 432a27283e8a930165142f34d585ff8feb287940 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 27 Jun 2021 14:07:39 +0530 Subject: [PATCH 048/947] solves invert a binary tree in python --- README.md | 2 +- python/invert_binary_tree.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 python/invert_binary_tree.py diff --git a/README.md b/README.md index 9fe4702..a9eb069 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ | 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ContainsDuplicate.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/contains_duplicate.py) | | 219 | [Contains Duplicate II](https://leetcode.com/problems/contains-duplicate-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ContainsDuplicateII.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/contains_duplicate_ii.py) | | 225 | [Implement Stack using Queues](https://leetcode.com/problems/implement-stack-using-queues) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MyStack.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/implement_stack_using_queues.py) | -| 226 | [Invert Binary Tree](https://leetcode.com/problems/invert-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/InvertBinaryTree.java) | +| 226 | [Invert Binary Tree](https://leetcode.com/problems/invert-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/InvertBinaryTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/invert_binary_tree.py) | | 231 | [Power of Two](https://leetcode.com/problems/power-of-two) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PowerOf2.java) | | 232 | [Implement Queue Using Stacks]() | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MyQueue.java) | | 234 | [Palindrome Linked Lists](https://leetcode.com/problems/palindrome-linked-list) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PalindromeLinkedList.java) | diff --git a/python/invert_binary_tree.py b/python/invert_binary_tree.py new file mode 100644 index 0000000..8c726e5 --- /dev/null +++ b/python/invert_binary_tree.py @@ -0,0 +1,17 @@ +# Definition for a binary tree node. +from typing import Optional + + +class TreeNode: + def __init__(self, val=0, left=None, right=None): + self.val = val + self.left = left + self.right = right + + +class Solution: + def invertTree(self, root: TreeNode) -> Optional[TreeNode]: + if root is None: + return None + root.left, root.right = self.invertTree(root.right), self.invertTree(root.left) + return root From 6467c6483dbd5da422c35872059aabc212e031cd Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 27 Jun 2021 14:10:18 +0530 Subject: [PATCH 049/947] adds premium icon --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a9eb069..b232986 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ | 167 | [Two Sum II - Input Array is Sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/TwoSumIIInputArrayIsSorted.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/two_sum_ii.py) | | 168 | [Excel Sheet Column Title](https://leetcode.com/problems/excel-sheet-column-title) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ExcelSheetColumnTitle.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/excel_sheet_column_title.py) | | 169 | [Majority Element](https://leetcode.com/problems/majority-element) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MajorityElement.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/majority_element.py) | -| 170 | [Two Sum III - Data Structure Design](https://leetcode.com/problems/two-sum-iii-data-structure-design) | Easy | | +| 170 | [🔒 Two Sum III - Data Structure Design](https://leetcode.com/problems/two-sum-iii-data-structure-design) | Easy | | | 171 | [Excel Sheet Column Number](https://leetcode.com/problems/excel-sheet-column-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ExcelSheetColumnNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/excel_sheet_column_number.py) | | 172 | [Factoring Trailing Zeroes](https://leetcode.com/problems/factorial-trailing-zeroes) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FactorialTrailingZeros.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/factorial_trailing_zeroes.py) | | 189 | [Rotate Array](https://leetcode.com/problems/rotate-array) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RotateArray.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/rotate_array.py) | From 7043bd71c965a532036bb714ff65a2cf5d2144b8 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 27 Jun 2021 14:23:05 +0530 Subject: [PATCH 050/947] solves is power of 2 in python --- README.md | 6 ++++-- python/is_power_of_2.py | 13 +++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 python/is_power_of_2.py diff --git a/README.md b/README.md index b232986..45f6bfc 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,8 @@ ![problems-solved-python](https://img.shields.io/badge/Python-32/1571-1abc9c.svg) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md) +🔒 = Subscription Content + ## Problems | #Number | Name | Difficulty | Solution | Youtube | |:--------:|------|:----------:|:--------:|:----------------------:| @@ -49,7 +51,7 @@ | 167 | [Two Sum II - Input Array is Sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/TwoSumIIInputArrayIsSorted.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/two_sum_ii.py) | | 168 | [Excel Sheet Column Title](https://leetcode.com/problems/excel-sheet-column-title) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ExcelSheetColumnTitle.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/excel_sheet_column_title.py) | | 169 | [Majority Element](https://leetcode.com/problems/majority-element) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MajorityElement.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/majority_element.py) | -| 170 | [🔒 Two Sum III - Data Structure Design](https://leetcode.com/problems/two-sum-iii-data-structure-design) | Easy | | +| 170 | 🔒 [Two Sum III - Data Structure Design](https://leetcode.com/problems/two-sum-iii-data-structure-design) | Easy | | | 171 | [Excel Sheet Column Number](https://leetcode.com/problems/excel-sheet-column-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ExcelSheetColumnNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/excel_sheet_column_number.py) | | 172 | [Factoring Trailing Zeroes](https://leetcode.com/problems/factorial-trailing-zeroes) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FactorialTrailingZeros.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/factorial_trailing_zeroes.py) | | 189 | [Rotate Array](https://leetcode.com/problems/rotate-array) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RotateArray.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/rotate_array.py) | @@ -65,7 +67,7 @@ | 219 | [Contains Duplicate II](https://leetcode.com/problems/contains-duplicate-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ContainsDuplicateII.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/contains_duplicate_ii.py) | | 225 | [Implement Stack using Queues](https://leetcode.com/problems/implement-stack-using-queues) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MyStack.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/implement_stack_using_queues.py) | | 226 | [Invert Binary Tree](https://leetcode.com/problems/invert-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/InvertBinaryTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/invert_binary_tree.py) | -| 231 | [Power of Two](https://leetcode.com/problems/power-of-two) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PowerOf2.java) | +| 231 | [Power of Two](https://leetcode.com/problems/power-of-two) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PowerOf2.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/is_power_of_2.py) | | 232 | [Implement Queue Using Stacks]() | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MyQueue.java) | | 234 | [Palindrome Linked Lists](https://leetcode.com/problems/palindrome-linked-list) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PalindromeLinkedList.java) | | 235 | [Lowest Common Ancestor of a Binary Search Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/LowestCommonAncestorOfBinarySearchTree.java) | diff --git a/python/is_power_of_2.py b/python/is_power_of_2.py new file mode 100644 index 0000000..2f0f086 --- /dev/null +++ b/python/is_power_of_2.py @@ -0,0 +1,13 @@ +class Solution: + def isPowerOfTwo(self, n: int) -> bool: + if n == 1: + return True + if n == 0: + return False + if n % 2 == 1: + return False + return self.isPowerOfTwo(n // 2) + + # alternate version + # def isPowerOfTwo(self, n: int) -> bool: + # return n > 0 and (n & (n - 1)) == 0 \ No newline at end of file From ac7f87308098d63f22b4e06ca6ad0102181b7b87 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 27 Jun 2021 14:30:22 +0530 Subject: [PATCH 051/947] adds question link to queue using stack --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 45f6bfc..182c928 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ | 225 | [Implement Stack using Queues](https://leetcode.com/problems/implement-stack-using-queues) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MyStack.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/implement_stack_using_queues.py) | | 226 | [Invert Binary Tree](https://leetcode.com/problems/invert-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/InvertBinaryTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/invert_binary_tree.py) | | 231 | [Power of Two](https://leetcode.com/problems/power-of-two) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PowerOf2.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/is_power_of_2.py) | -| 232 | [Implement Queue Using Stacks]() | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MyQueue.java) | +| 232 | [Implement Queue Using Stacks](https://leetcode.com/problems/implement-queue-using-stacks) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MyQueue.java) | | 234 | [Palindrome Linked Lists](https://leetcode.com/problems/palindrome-linked-list) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PalindromeLinkedList.java) | | 235 | [Lowest Common Ancestor of a Binary Search Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/LowestCommonAncestorOfBinarySearchTree.java) | | 237 | [Delete a Node In A Linked List](https://leetcode.com/problems/delete-node-in-a-linked-list) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/DeleteANodeInLinkedList.java) | From dcd207eb8ff6aa90e38455fe0c734bb1c2c4746e Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 27 Jun 2021 15:01:46 +0530 Subject: [PATCH 052/947] solves implement queue using stack --- README.md | 2 +- python/implement_queue_using_stacks.py | 45 ++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 python/implement_queue_using_stacks.py diff --git a/README.md b/README.md index 182c928..e647d39 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ | 225 | [Implement Stack using Queues](https://leetcode.com/problems/implement-stack-using-queues) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MyStack.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/implement_stack_using_queues.py) | | 226 | [Invert Binary Tree](https://leetcode.com/problems/invert-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/InvertBinaryTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/invert_binary_tree.py) | | 231 | [Power of Two](https://leetcode.com/problems/power-of-two) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PowerOf2.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/is_power_of_2.py) | -| 232 | [Implement Queue Using Stacks](https://leetcode.com/problems/implement-queue-using-stacks) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MyQueue.java) | +| 232 | [Implement Queue Using Stacks](https://leetcode.com/problems/implement-queue-using-stacks) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MyQueue.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/implement_queue_using_stacks.py) | | 234 | [Palindrome Linked Lists](https://leetcode.com/problems/palindrome-linked-list) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PalindromeLinkedList.java) | | 235 | [Lowest Common Ancestor of a Binary Search Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/LowestCommonAncestorOfBinarySearchTree.java) | | 237 | [Delete a Node In A Linked List](https://leetcode.com/problems/delete-node-in-a-linked-list) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/DeleteANodeInLinkedList.java) | diff --git a/python/implement_queue_using_stacks.py b/python/implement_queue_using_stacks.py new file mode 100644 index 0000000..58f11cf --- /dev/null +++ b/python/implement_queue_using_stacks.py @@ -0,0 +1,45 @@ +from collections import deque + + +class MyQueue: + def __init__(self): + """ + Initialize your data structure here. + """ + self.s1 = deque() + self.s2 = deque() + + def push(self, x: int) -> None: + """ + Push element x to the back of queue. + """ + while len(self.s1) > 0: + self.s2.append(self.s1.pop()) + self.s1.append(x) + while len(self.s2) > 0: + self.s1.append(self.s2.pop()) + + def pop(self) -> int: + """ + Removes the element from in front of queue and returns that element. + """ + return self.s1.pop() + + def peek(self) -> int: + """ + Get the front element. + """ + return self.s1[-1] + + def empty(self) -> bool: + """ + Returns whether the queue is empty. + """ + return len(self.s1) == 0 + +# Your MyQueue object will be instantiated and called as such: +# obj = MyQueue() +# obj.push(x) +# param_2 = obj.pop() +# param_3 = obj.peek() +# param_4 = obj.empty() \ No newline at end of file From 4e8a308df1ccbbe8db02368bd16200d64f36470b Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 27 Jun 2021 16:45:21 +0530 Subject: [PATCH 053/947] solves palindrome linked list --- README.md | 2 +- python/palindrome_linked_list.py | 42 ++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 python/palindrome_linked_list.py diff --git a/README.md b/README.md index e647d39..8428dc4 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ | 226 | [Invert Binary Tree](https://leetcode.com/problems/invert-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/InvertBinaryTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/invert_binary_tree.py) | | 231 | [Power of Two](https://leetcode.com/problems/power-of-two) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PowerOf2.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/is_power_of_2.py) | | 232 | [Implement Queue Using Stacks](https://leetcode.com/problems/implement-queue-using-stacks) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MyQueue.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/implement_queue_using_stacks.py) | -| 234 | [Palindrome Linked Lists](https://leetcode.com/problems/palindrome-linked-list) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PalindromeLinkedList.java) | +| 234 | [Palindrome Linked Lists](https://leetcode.com/problems/palindrome-linked-list) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PalindromeLinkedList.java) [![Python](https://img.icons8.com/color/35/000000/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) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/LowestCommonAncestorOfBinarySearchTree.java) | | 237 | [Delete a Node In A Linked List](https://leetcode.com/problems/delete-node-in-a-linked-list) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/DeleteANodeInLinkedList.java) | | 242 | [Valid Anagram](https://leetcode.com/problems/valid-anagram) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ValidAnagram.java) | diff --git a/python/palindrome_linked_list.py b/python/palindrome_linked_list.py new file mode 100644 index 0000000..52b8a29 --- /dev/null +++ b/python/palindrome_linked_list.py @@ -0,0 +1,42 @@ +# Definition for singly-linked list. +from typing import Optional + + +class ListNode: + def __init__(self, val=0, next=None): + self.val = val + self.next = next + + +class Solution: + def length(self, head: ListNode) -> int: + count = 0 + while head is not None: + count += 1 + head = head.next + return count + + def reverse(self, head: ListNode) -> Optional[ListNode]: + if head is None or head.next is None: + return head + a, b, c = head, head.next, head.next.next + a.next = None + while c is not None: + b.next = a + a, b, c = b, c, c.next + b.next = a + return b + + def isPalindrome(self, head: ListNode) -> bool: + list_length = self.length(head) + first_half = head + second_half = head + for i in range((list_length + 1) // 2): + second_half = second_half.next + second_half = self.reverse(second_half) + while second_half is not None: + if first_half.val != second_half.val: + return False + second_half = second_half.next + first_half = first_half.next + return True From e081cf9e0c05a7b3b601634ef362c52eeec3791b Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 27 Jun 2021 16:57:07 +0530 Subject: [PATCH 054/947] solves delete node in linked list using python --- README.md | 2 +- python/delete_node_in_linked_list.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 python/delete_node_in_linked_list.py diff --git a/README.md b/README.md index 8428dc4..d61102a 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ | 232 | [Implement Queue Using Stacks](https://leetcode.com/problems/implement-queue-using-stacks) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MyQueue.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/implement_queue_using_stacks.py) | | 234 | [Palindrome Linked Lists](https://leetcode.com/problems/palindrome-linked-list) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PalindromeLinkedList.java) [![Python](https://img.icons8.com/color/35/000000/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) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/LowestCommonAncestorOfBinarySearchTree.java) | -| 237 | [Delete a Node In A Linked List](https://leetcode.com/problems/delete-node-in-a-linked-list) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/DeleteANodeInLinkedList.java) | +| 237 | [Delete a Node In A Linked List](https://leetcode.com/problems/delete-node-in-a-linked-list) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/DeleteANodeInLinkedList.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/delete_node_in_linked_list.py) | | 242 | [Valid Anagram](https://leetcode.com/problems/valid-anagram) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ValidAnagram.java) | | 243 | [Shortest Word Distance](https://leetcode.com/problems/shortest-word-distance) | Easy | | | 246 | [Strobogramatic Number](https://leetcode.com/problems/strobogrammatic-number) | Easy | | diff --git a/python/delete_node_in_linked_list.py b/python/delete_node_in_linked_list.py new file mode 100644 index 0000000..43efe6b --- /dev/null +++ b/python/delete_node_in_linked_list.py @@ -0,0 +1,18 @@ +# Definition for singly-linked list. +class ListNode: + def __init__(self, x): + self.val = x + self.next = None + + +class Solution: + def deleteNode(self, node: ListNode) -> None: + """ + :type node: ListNode + :rtype: void Do not return anything, modify node in-place instead. + """ + while node is not None and node.next is not None and node.next.next is not None: + node.val = node.next.val + node = node.next + node.val = node.next.val + node.next = None From bd643876415a010bdbf04b967354e2ca1201e9b5 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 28 Jun 2021 13:09:24 +0530 Subject: [PATCH 055/947] solves lowest common ancestor in bst --- README.md | 2 +- python/lowest_common_ancestor_of_bst.py | 35 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 python/lowest_common_ancestor_of_bst.py diff --git a/README.md b/README.md index d61102a..67e2d6b 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ | 231 | [Power of Two](https://leetcode.com/problems/power-of-two) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PowerOf2.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/is_power_of_2.py) | | 232 | [Implement Queue Using Stacks](https://leetcode.com/problems/implement-queue-using-stacks) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MyQueue.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/implement_queue_using_stacks.py) | | 234 | [Palindrome Linked Lists](https://leetcode.com/problems/palindrome-linked-list) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PalindromeLinkedList.java) [![Python](https://img.icons8.com/color/35/000000/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) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/LowestCommonAncestorOfBinarySearchTree.java) | +| 235 | [Lowest Common Ancestor of a Binary Search Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/LowestCommonAncestorOfBinarySearchTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/lowest_common_ancestor_of_bst.py) | | 237 | [Delete a Node In A Linked List](https://leetcode.com/problems/delete-node-in-a-linked-list) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/DeleteANodeInLinkedList.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/delete_node_in_linked_list.py) | | 242 | [Valid Anagram](https://leetcode.com/problems/valid-anagram) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ValidAnagram.java) | | 243 | [Shortest Word Distance](https://leetcode.com/problems/shortest-word-distance) | Easy | | diff --git a/python/lowest_common_ancestor_of_bst.py b/python/lowest_common_ancestor_of_bst.py new file mode 100644 index 0000000..3c8de68 --- /dev/null +++ b/python/lowest_common_ancestor_of_bst.py @@ -0,0 +1,35 @@ +from collections import deque + + +# Definition for a binary tree node. +class TreeNode: + def __init__(self, x): + self.val = x + self.left = None + self.right = None + + def __repr__(self): + return str(self.val) + + def __str__(self): + return str(self.val) + + +class Solution: + def get_path_to(self, root: TreeNode, node: TreeNode) -> deque: + path = deque() + while root.val != node.val: + path.append(root) + root = root.left if root.val > node.val else root.right + path.append(root) + return path + + def lowestCommonAncestor(self, root: TreeNode, p: TreeNode, q: TreeNode) -> TreeNode: + path_p = self.get_path_to(root, p) + path_q = self.get_path_to(root, q) + index = 0 + for node_p, node_q in zip(path_p, path_q): + if node_p is not node_q: + break + index += 1 + return path_p[index - 1] From 0a5c4d9049b5d9f9892493ea658f2e9cecd7caca Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 28 Jun 2021 13:16:18 +0530 Subject: [PATCH 056/947] solves valid anagram in python --- README.md | 2 +- python/lowest_common_ancestor_of_bst.py | 6 ------ python/valid_anagram.py | 16 ++++++++++++++++ 3 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 python/valid_anagram.py diff --git a/README.md b/README.md index 67e2d6b..11dcbc7 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ | 234 | [Palindrome Linked Lists](https://leetcode.com/problems/palindrome-linked-list) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PalindromeLinkedList.java) [![Python](https://img.icons8.com/color/35/000000/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) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/LowestCommonAncestorOfBinarySearchTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/lowest_common_ancestor_of_bst.py) | | 237 | [Delete a Node In A Linked List](https://leetcode.com/problems/delete-node-in-a-linked-list) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/DeleteANodeInLinkedList.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/delete_node_in_linked_list.py) | -| 242 | [Valid Anagram](https://leetcode.com/problems/valid-anagram) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ValidAnagram.java) | +| 242 | [Valid Anagram](https://leetcode.com/problems/valid-anagram) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ValidAnagram.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/delete_node_in_linked_list.py) | | 243 | [Shortest Word Distance](https://leetcode.com/problems/shortest-word-distance) | Easy | | | 246 | [Strobogramatic Number](https://leetcode.com/problems/strobogrammatic-number) | Easy | | | 252 | [Meeting Rooms](https://leetcode.com/problems/meeting-rooms) | Easy | | diff --git a/python/lowest_common_ancestor_of_bst.py b/python/lowest_common_ancestor_of_bst.py index 3c8de68..dce7ad6 100644 --- a/python/lowest_common_ancestor_of_bst.py +++ b/python/lowest_common_ancestor_of_bst.py @@ -8,12 +8,6 @@ def __init__(self, x): self.left = None self.right = None - def __repr__(self): - return str(self.val) - - def __str__(self): - return str(self.val) - class Solution: def get_path_to(self, root: TreeNode, node: TreeNode) -> deque: diff --git a/python/valid_anagram.py b/python/valid_anagram.py new file mode 100644 index 0000000..9236cd9 --- /dev/null +++ b/python/valid_anagram.py @@ -0,0 +1,16 @@ +from typing import Dict + + +class Solution: + def character_frequency(self, string: str) -> Dict[str, int]: + frequencies = {} + for character in string: + frequencies[character] = frequencies.get(character, 0) + 1 + return frequencies + + def isAnagram(self, s: str, t: str) -> bool: + if len(s) != len(t): + return False + char_freq_s = self.character_frequency(s) + char_freq_t = self.character_frequency(t) + return char_freq_s == char_freq_t From 18cb51b89a746eb620f13d2c081f91cf4bf71a7c Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 28 Jun 2021 13:18:06 +0530 Subject: [PATCH 057/947] adds lock symbol in front of premium content --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 11dcbc7..8ec4b27 100644 --- a/README.md +++ b/README.md @@ -73,10 +73,10 @@ | 235 | [Lowest Common Ancestor of a Binary Search Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/LowestCommonAncestorOfBinarySearchTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/lowest_common_ancestor_of_bst.py) | | 237 | [Delete a Node In A Linked List](https://leetcode.com/problems/delete-node-in-a-linked-list) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/DeleteANodeInLinkedList.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/delete_node_in_linked_list.py) | | 242 | [Valid Anagram](https://leetcode.com/problems/valid-anagram) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ValidAnagram.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/delete_node_in_linked_list.py) | -| 243 | [Shortest Word Distance](https://leetcode.com/problems/shortest-word-distance) | Easy | | -| 246 | [Strobogramatic Number](https://leetcode.com/problems/strobogrammatic-number) | Easy | | -| 252 | [Meeting Rooms](https://leetcode.com/problems/meeting-rooms) | Easy | | -| 256 | [Paint House](https://leetcode.com/problems/paint-house) | Easy | | +| 243 | 🔒 [Shortest Word Distance](https://leetcode.com/problems/shortest-word-distance) | Easy | | +| 246 | 🔒 [Strobogramatic Number](https://leetcode.com/problems/strobogrammatic-number) | Easy | | +| 252 | 🔒 [Meeting Rooms](https://leetcode.com/problems/meeting-rooms) | Easy | | +| 256 | 🔒 [Paint House](https://leetcode.com/problems/paint-house) | Easy | | | 257 | [Binary Tree Paths](https://leetcode.com/problems/binary-tree-paths) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BinaryTreePaths.java) | | 258 | [Add Digits](https://leetcode.com/problems/add-digits) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/AddDigits.java) | | 263 | [Ugly Number](https://leetcode.com/problems/ugly-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/UglyNumber.java) | From 0df85176b1ad1560e238e7fba77d9cc97ea1c23a Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 28 Jun 2021 13:32:09 +0530 Subject: [PATCH 058/947] solves binary tree paths in python --- README.md | 2 +- python/binary_tree_paths.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 python/binary_tree_paths.py diff --git a/README.md b/README.md index 8ec4b27..cfe9d37 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ | 246 | 🔒 [Strobogramatic Number](https://leetcode.com/problems/strobogrammatic-number) | Easy | | | 252 | 🔒 [Meeting Rooms](https://leetcode.com/problems/meeting-rooms) | Easy | | | 256 | 🔒 [Paint House](https://leetcode.com/problems/paint-house) | Easy | | -| 257 | [Binary Tree Paths](https://leetcode.com/problems/binary-tree-paths) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BinaryTreePaths.java) | +| 257 | [Binary Tree Paths](https://leetcode.com/problems/binary-tree-paths) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BinaryTreePaths.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/binary_tree_paths.py) | | 258 | [Add Digits](https://leetcode.com/problems/add-digits) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/AddDigits.java) | | 263 | [Ugly Number](https://leetcode.com/problems/ugly-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/UglyNumber.java) | | 266 | [Palindrome Permutation](https://leetcode.com/problems/palindrome-permutation) | Easy | | diff --git a/python/binary_tree_paths.py b/python/binary_tree_paths.py new file mode 100644 index 0000000..e770cb4 --- /dev/null +++ b/python/binary_tree_paths.py @@ -0,0 +1,28 @@ +from typing import List + + +# Definition for a binary tree node. +class TreeNode: + def __init__(self, val=0, left=None, right=None): + self.val = val + self.left = left + self.right = right + + +class Solution: + def is_leaf_node(self, root: TreeNode) -> bool: + return root.left is None and root.right is None + + def binary_tree_paths(self, root: TreeNode, current_path: str, results: List[str]): + if root is None: + return + if self.is_leaf_node(root): + results.append(f'{current_path}->{root.val}'[2:]) + return + self.binary_tree_paths(root.left, f'{current_path}->{root.val}', results) + self.binary_tree_paths(root.right, f'{current_path}->{root.val}', results) + + def binaryTreePaths(self, root: TreeNode) -> List[str]: + result = [] + self.binary_tree_paths(root, '', results=result) + return result From c3dfcd8567060c8a1e40b27ab6504d7599401e75 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 28 Jun 2021 13:35:47 +0530 Subject: [PATCH 059/947] solves add digits in python --- README.md | 2 +- python/add_digits.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 python/add_digits.py diff --git a/README.md b/README.md index cfe9d37..357fd03 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ | 252 | 🔒 [Meeting Rooms](https://leetcode.com/problems/meeting-rooms) | Easy | | | 256 | 🔒 [Paint House](https://leetcode.com/problems/paint-house) | Easy | | | 257 | [Binary Tree Paths](https://leetcode.com/problems/binary-tree-paths) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BinaryTreePaths.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/binary_tree_paths.py) | -| 258 | [Add Digits](https://leetcode.com/problems/add-digits) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/AddDigits.java) | +| 258 | [Add Digits](https://leetcode.com/problems/add-digits) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/AddDigits.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/add_digits.py) | | 263 | [Ugly Number](https://leetcode.com/problems/ugly-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/UglyNumber.java) | | 266 | [Palindrome Permutation](https://leetcode.com/problems/palindrome-permutation) | Easy | | | 268 | [Missing Number](https://leetcode.com/problems/missing-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MissingNumber.java) | diff --git a/python/add_digits.py b/python/add_digits.py new file mode 100644 index 0000000..3b139ed --- /dev/null +++ b/python/add_digits.py @@ -0,0 +1,6 @@ +class Solution: + def addDigits(self, num: int) -> int: + number_str = str(num) + if len(number_str) == 1: + return num + return self.addDigits(sum(int(digit) for digit in number_str)) From e1538372db036198a1d4a3741c28d8a7099e9dfa Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 28 Jun 2021 13:40:47 +0530 Subject: [PATCH 060/947] solves ugly number in python --- README.md | 2 +- python/ugly_number.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 python/ugly_number.py diff --git a/README.md b/README.md index 357fd03..b1d7af4 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ | 256 | 🔒 [Paint House](https://leetcode.com/problems/paint-house) | Easy | | | 257 | [Binary Tree Paths](https://leetcode.com/problems/binary-tree-paths) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BinaryTreePaths.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/binary_tree_paths.py) | | 258 | [Add Digits](https://leetcode.com/problems/add-digits) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/AddDigits.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/add_digits.py) | -| 263 | [Ugly Number](https://leetcode.com/problems/ugly-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/UglyNumber.java) | +| 263 | [Ugly Number](https://leetcode.com/problems/ugly-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/UglyNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/ugly_number.py) | | 266 | [Palindrome Permutation](https://leetcode.com/problems/palindrome-permutation) | Easy | | | 268 | [Missing Number](https://leetcode.com/problems/missing-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MissingNumber.java) | | 270 | [Closest Binary Search Tree Value](https://leetcode.com/problems/closest-binary-search-tree-value) | Easy | | diff --git a/python/ugly_number.py b/python/ugly_number.py new file mode 100644 index 0000000..9c73f46 --- /dev/null +++ b/python/ugly_number.py @@ -0,0 +1,11 @@ +class Solution: + def eliminate_prime_factor(self, number: int, prime_factor: int) -> int: + while number % prime_factor == 0 and number != 0: + number //= prime_factor + return number + + def isUgly(self, n: int) -> bool: + n = self.eliminate_prime_factor(n, 2) + n = self.eliminate_prime_factor(n, 3) + n = self.eliminate_prime_factor(n, 5) + return n == 1 From 7f54a718ae0e6185729a63ed196f3516d169227d Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 28 Jun 2021 13:41:56 +0530 Subject: [PATCH 061/947] adds premium content logo in palindrom permutation --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b1d7af4..20f6d51 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ | 257 | [Binary Tree Paths](https://leetcode.com/problems/binary-tree-paths) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BinaryTreePaths.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/binary_tree_paths.py) | | 258 | [Add Digits](https://leetcode.com/problems/add-digits) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/AddDigits.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/add_digits.py) | | 263 | [Ugly Number](https://leetcode.com/problems/ugly-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/UglyNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/ugly_number.py) | -| 266 | [Palindrome Permutation](https://leetcode.com/problems/palindrome-permutation) | Easy | | +| 266 | 🔒 [Palindrome Permutation](https://leetcode.com/problems/palindrome-permutation) | Easy | | | 268 | [Missing Number](https://leetcode.com/problems/missing-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MissingNumber.java) | | 270 | [Closest Binary Search Tree Value](https://leetcode.com/problems/closest-binary-search-tree-value) | Easy | | | 276 | [Paint Fence](https://leetcode.com/problems/paint-fence) | Easy | | From 6b9d289ff7e6ef576a7b753407f34e42ec21cbde Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 28 Jun 2021 13:53:25 +0530 Subject: [PATCH 062/947] solves missing number in python --- README.md | 2 +- python/missing_number.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 python/missing_number.py diff --git a/README.md b/README.md index 20f6d51..8667517 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ | 258 | [Add Digits](https://leetcode.com/problems/add-digits) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/AddDigits.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/add_digits.py) | | 263 | [Ugly Number](https://leetcode.com/problems/ugly-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/UglyNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/ugly_number.py) | | 266 | 🔒 [Palindrome Permutation](https://leetcode.com/problems/palindrome-permutation) | Easy | | -| 268 | [Missing Number](https://leetcode.com/problems/missing-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MissingNumber.java) | +| 268 | [Missing Number](https://leetcode.com/problems/missing-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MissingNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/missing_number.py) | | 270 | [Closest Binary Search Tree Value](https://leetcode.com/problems/closest-binary-search-tree-value) | Easy | | | 276 | [Paint Fence](https://leetcode.com/problems/paint-fence) | Easy | | | 278 | [First Bad Version](https://leetcode.com/problems/first-bad-version) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FirstBadVersion.java) | diff --git a/python/missing_number.py b/python/missing_number.py new file mode 100644 index 0000000..51b3bb4 --- /dev/null +++ b/python/missing_number.py @@ -0,0 +1,8 @@ +from typing import List + + +class Solution: + def missingNumber(self, nums: List[int]) -> int: + n = len(nums) + acttual_sum = (n * (n + 1)) // 2 + return acttual_sum - sum(nums) From b6cb5773cc8cbfcc430f753b32044f005f23f158 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 28 Jun 2021 13:54:31 +0530 Subject: [PATCH 063/947] adds premium content logo --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8667517..cdf2325 100644 --- a/README.md +++ b/README.md @@ -82,8 +82,8 @@ | 263 | [Ugly Number](https://leetcode.com/problems/ugly-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/UglyNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/ugly_number.py) | | 266 | 🔒 [Palindrome Permutation](https://leetcode.com/problems/palindrome-permutation) | Easy | | | 268 | [Missing Number](https://leetcode.com/problems/missing-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MissingNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/missing_number.py) | -| 270 | [Closest Binary Search Tree Value](https://leetcode.com/problems/closest-binary-search-tree-value) | Easy | | -| 276 | [Paint Fence](https://leetcode.com/problems/paint-fence) | Easy | | +| 270 | 🔒 [Closest Binary Search Tree Value](https://leetcode.com/problems/closest-binary-search-tree-value) | Easy | | +| 276 | 🔒 [Paint Fence](https://leetcode.com/problems/paint-fence) | Easy | | | 278 | [First Bad Version](https://leetcode.com/problems/first-bad-version) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FirstBadVersion.java) | | 283 | [Move Zeroes](https://leetcode.com/problems/move-zeroes) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MoveZeros.java) | | 290 | [Word Pattern](https://leetcode.com/problems/word-pattern) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/WordPattern.java) | From fb67b565904f6e7c368403d4e86a2c4acc68a3f1 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 28 Jun 2021 13:59:20 +0530 Subject: [PATCH 064/947] first bad version --- README.md | 2 +- python/first_bad_version.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 python/first_bad_version.py diff --git a/README.md b/README.md index cdf2325..5025930 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ | 268 | [Missing Number](https://leetcode.com/problems/missing-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MissingNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/missing_number.py) | | 270 | 🔒 [Closest Binary Search Tree Value](https://leetcode.com/problems/closest-binary-search-tree-value) | Easy | | | 276 | 🔒 [Paint Fence](https://leetcode.com/problems/paint-fence) | Easy | | -| 278 | [First Bad Version](https://leetcode.com/problems/first-bad-version) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FirstBadVersion.java) | +| 278 | [First Bad Version](https://leetcode.com/problems/first-bad-version) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FirstBadVersion.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/first_bad_version.py)| | 283 | [Move Zeroes](https://leetcode.com/problems/move-zeroes) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MoveZeros.java) | | 290 | [Word Pattern](https://leetcode.com/problems/word-pattern) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/WordPattern.java) | | 292 | [Nim Game](https://leetcode.com/problems/nim-game) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/NimGame.java) | diff --git a/python/first_bad_version.py b/python/first_bad_version.py new file mode 100644 index 0000000..25766aa --- /dev/null +++ b/python/first_bad_version.py @@ -0,0 +1,21 @@ +# The isBadVersion API is already defined for you. +# @param version, an integer +# @return an integer +def isBadVersion(version): + return None + + +class Solution: + def firstBadVersion(self, n: int) -> int: + """ + :type n: int + :rtype: int + """ + left, right = 0, n + while left <= right: + middle = left + (right - left) // 2 + if isBadVersion(middle): + right = middle - 1 + else: + left = middle + 1 + return left From 6e7e8c627e1252e9d56e5bac2ca4ddd7086e4c88 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 28 Jun 2021 14:08:10 +0530 Subject: [PATCH 065/947] solves move zeroes in python --- README.md | 4 ++-- python/move_zeroes.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 python/move_zeroes.py diff --git a/README.md b/README.md index 5025930..3564d25 100644 --- a/README.md +++ b/README.md @@ -84,8 +84,8 @@ | 268 | [Missing Number](https://leetcode.com/problems/missing-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MissingNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/missing_number.py) | | 270 | 🔒 [Closest Binary Search Tree Value](https://leetcode.com/problems/closest-binary-search-tree-value) | Easy | | | 276 | 🔒 [Paint Fence](https://leetcode.com/problems/paint-fence) | Easy | | -| 278 | [First Bad Version](https://leetcode.com/problems/first-bad-version) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FirstBadVersion.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/first_bad_version.py)| -| 283 | [Move Zeroes](https://leetcode.com/problems/move-zeroes) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MoveZeros.java) | +| 278 | [First Bad Version](https://leetcode.com/problems/first-bad-version) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FirstBadVersion.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/first_bad_version.py) | +| 283 | [Move Zeroes](https://leetcode.com/problems/move-zeroes) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MoveZeros.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/move_zeroes.py) | | 290 | [Word Pattern](https://leetcode.com/problems/word-pattern) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/WordPattern.java) | | 292 | [Nim Game](https://leetcode.com/problems/nim-game) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/NimGame.java) | | 293 | [Flip Game](https://leetcode.com/problems/flip-game) | Easy | | diff --git a/python/move_zeroes.py b/python/move_zeroes.py new file mode 100644 index 0000000..e469ed1 --- /dev/null +++ b/python/move_zeroes.py @@ -0,0 +1,16 @@ +from typing import List + + +class Solution: + def moveZeroes(self, nums: List[int]) -> None: + if len(nums) == 1: + return + i, j = 0, 1 + while True: + while i < len(nums) and nums[i] != 0: + i += 1 + while j < len(nums) and (nums[j] == 0 or j < i): + j += 1 + if i >= len(nums) or j >= len(nums): + break + nums[i], nums[j] = nums[j], 0 From 84ddebfff7084a1f58db3837a3e5fa13c3b90488 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 28 Jun 2021 15:02:04 +0530 Subject: [PATCH 066/947] solves word pattern in python --- README.md | 2 +- python/word_pattern.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 python/word_pattern.py diff --git a/README.md b/README.md index 3564d25..8ffdd8b 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ | 276 | 🔒 [Paint Fence](https://leetcode.com/problems/paint-fence) | Easy | | | 278 | [First Bad Version](https://leetcode.com/problems/first-bad-version) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FirstBadVersion.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/first_bad_version.py) | | 283 | [Move Zeroes](https://leetcode.com/problems/move-zeroes) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MoveZeros.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/move_zeroes.py) | -| 290 | [Word Pattern](https://leetcode.com/problems/word-pattern) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/WordPattern.java) | +| 290 | [Word Pattern](https://leetcode.com/problems/word-pattern) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/WordPattern.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/word_pattern.py) | | 292 | [Nim Game](https://leetcode.com/problems/nim-game) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/NimGame.java) | | 293 | [Flip Game](https://leetcode.com/problems/flip-game) | Easy | | | 299 | [Bulls and Cows](https://leetcode.com/problems/bulls-and-cows) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/BullsAndCows.java) | diff --git a/python/word_pattern.py b/python/word_pattern.py new file mode 100644 index 0000000..cabfaf2 --- /dev/null +++ b/python/word_pattern.py @@ -0,0 +1,20 @@ +class Solution: + def wordPattern(self, pattern: str, s: str) -> bool: + words = s.split() + if len(words) != len(pattern): + return False + mapping = {} + used_words = set() + for character, word in zip(pattern, words): + if character in mapping: + if mapping[character] != word: + return False + elif word in used_words: + return False + else: + mapping[character] = word + used_words.add(word) + return True + + +print(Solution().wordPattern('abba', 'dog dog dog dog')) From a72119aa7d8431c080b1597a807b7a3b8b1260eb Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 28 Jun 2021 15:16:27 +0530 Subject: [PATCH 067/947] solves nim game in python --- README.md | 2 +- python/nim_game.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 python/nim_game.py diff --git a/README.md b/README.md index 8ffdd8b..e692ead 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ | 278 | [First Bad Version](https://leetcode.com/problems/first-bad-version) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FirstBadVersion.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/first_bad_version.py) | | 283 | [Move Zeroes](https://leetcode.com/problems/move-zeroes) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MoveZeros.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/move_zeroes.py) | | 290 | [Word Pattern](https://leetcode.com/problems/word-pattern) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/WordPattern.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/word_pattern.py) | -| 292 | [Nim Game](https://leetcode.com/problems/nim-game) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/NimGame.java) | +| 292 | [Nim Game](https://leetcode.com/problems/nim-game) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/NimGame.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/nim_game.py) | | 293 | [Flip Game](https://leetcode.com/problems/flip-game) | Easy | | | 299 | [Bulls and Cows](https://leetcode.com/problems/bulls-and-cows) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/BullsAndCows.java) | | 303 | [Range Sum Query - Immutable](https://leetcode.com/problems/range-sum-query-immutable) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/RangeSumQueryImmutable.java) | diff --git a/python/nim_game.py b/python/nim_game.py new file mode 100644 index 0000000..990afa9 --- /dev/null +++ b/python/nim_game.py @@ -0,0 +1,3 @@ +class Solution: + def canWinNim(self, n: int) -> bool: + return n % 4 is not 0 From 00676d3959270016234c32a9e181b79d81fe55f7 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 28 Jun 2021 15:17:01 +0530 Subject: [PATCH 068/947] flip game is premium content --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e692ead..571637a 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ | 283 | [Move Zeroes](https://leetcode.com/problems/move-zeroes) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MoveZeros.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/move_zeroes.py) | | 290 | [Word Pattern](https://leetcode.com/problems/word-pattern) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/WordPattern.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/word_pattern.py) | | 292 | [Nim Game](https://leetcode.com/problems/nim-game) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/NimGame.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/nim_game.py) | -| 293 | [Flip Game](https://leetcode.com/problems/flip-game) | Easy | | +| 293 | 🔒 [Flip Game](https://leetcode.com/problems/flip-game) | Easy | | | 299 | [Bulls and Cows](https://leetcode.com/problems/bulls-and-cows) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/BullsAndCows.java) | | 303 | [Range Sum Query - Immutable](https://leetcode.com/problems/range-sum-query-immutable) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/RangeSumQueryImmutable.java) | | 326 | [Power of Three](https://leetcode.com/problems/power-of-three) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/PowerOfThree.java) | From 2c3d16d12ca3cbfa336825fd0bb66e8cfcc8acef Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 28 Jun 2021 15:30:17 +0530 Subject: [PATCH 069/947] solves cows and bulls in python --- README.md | 2 +- python/bulls_and_cows.py | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 python/bulls_and_cows.py diff --git a/README.md b/README.md index 571637a..3d26d99 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,7 @@ | 290 | [Word Pattern](https://leetcode.com/problems/word-pattern) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/WordPattern.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/word_pattern.py) | | 292 | [Nim Game](https://leetcode.com/problems/nim-game) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/NimGame.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/nim_game.py) | | 293 | 🔒 [Flip Game](https://leetcode.com/problems/flip-game) | Easy | | -| 299 | [Bulls and Cows](https://leetcode.com/problems/bulls-and-cows) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/BullsAndCows.java) | +| 299 | [Bulls and Cows](https://leetcode.com/problems/bulls-and-cows) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/BullsAndCows.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/bulls_and_cows.py) | | 303 | [Range Sum Query - Immutable](https://leetcode.com/problems/range-sum-query-immutable) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/RangeSumQueryImmutable.java) | | 326 | [Power of Three](https://leetcode.com/problems/power-of-three) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/PowerOfThree.java) | | 339 | [Nested List Weight Sum](https://leetcode.com/problems/nested-list-weight-sum) | Easy | | diff --git a/python/bulls_and_cows.py b/python/bulls_and_cows.py new file mode 100644 index 0000000..b1b6123 --- /dev/null +++ b/python/bulls_and_cows.py @@ -0,0 +1,23 @@ +from string import digits +from typing import Dict + + +class Solution: + def get_digit_frequency(self, number: str) -> Dict[str, int]: + freq = {} + for digit in number: + freq[digit] = freq.get(digit, 0) + 1 + return freq + + def getHint(self, secret: str, guess: str) -> str: + bulls = {} + frequency_secret = self.get_digit_frequency(secret) + frequency_guess = self.get_digit_frequency(guess) + for s, g in zip(secret, guess): + if s == g: + bulls[s] = bulls.get(s, 0) + 1 + total_bulls = sum(bulls.values()) + total_cows = 0 + for i in digits: + total_cows += min(frequency_secret.get(i, 0), frequency_guess.get(i, 0)) - bulls.get(i, 0) + return f'{total_bulls}A{total_cows}B' From f03a34cbd53b67ea76b1581db5ab5938cfef34c3 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 28 Jun 2021 15:40:42 +0530 Subject: [PATCH 070/947] solves range sum query imutable in python --- README.md | 2 +- python/range_sum_query_immutable.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 python/range_sum_query_immutable.py diff --git a/README.md b/README.md index 3d26d99..795b35a 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ | 292 | [Nim Game](https://leetcode.com/problems/nim-game) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/NimGame.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/nim_game.py) | | 293 | 🔒 [Flip Game](https://leetcode.com/problems/flip-game) | Easy | | | 299 | [Bulls and Cows](https://leetcode.com/problems/bulls-and-cows) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/BullsAndCows.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/bulls_and_cows.py) | -| 303 | [Range Sum Query - Immutable](https://leetcode.com/problems/range-sum-query-immutable) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/RangeSumQueryImmutable.java) | +| 303 | [Range Sum Query - Immutable](https://leetcode.com/problems/range-sum-query-immutable) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/RangeSumQueryImmutable.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/range_sum_query_immutable.py) | | 326 | [Power of Three](https://leetcode.com/problems/power-of-three) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/PowerOfThree.java) | | 339 | [Nested List Weight Sum](https://leetcode.com/problems/nested-list-weight-sum) | Easy | | | 342 | [Power of Four](https://leetcode.com/problems/power-of-four) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/PowerOf4.java) | diff --git a/python/range_sum_query_immutable.py b/python/range_sum_query_immutable.py new file mode 100644 index 0000000..b131d75 --- /dev/null +++ b/python/range_sum_query_immutable.py @@ -0,0 +1,12 @@ +from typing import List + + +class NumArray: + + def __init__(self, nums: List[int]): + self.sum_till = [0] * (len(nums) + 1) + for index, number in enumerate(nums): + self.sum_till[index + 1] = self.sum_till[index] + number + + def sumRange(self, left: int, right: int) -> int: + return self.sum_till[right + 1] - self.sum_till[left] From 5011b378018595722fd04398de81fc9b69a2a000 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 28 Jun 2021 15:47:21 +0530 Subject: [PATCH 071/947] solves power of three in python --- README.md | 2 +- python/power_of_three.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 python/power_of_three.py diff --git a/README.md b/README.md index 795b35a..9788f16 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ | 293 | 🔒 [Flip Game](https://leetcode.com/problems/flip-game) | Easy | | | 299 | [Bulls and Cows](https://leetcode.com/problems/bulls-and-cows) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/BullsAndCows.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/bulls_and_cows.py) | | 303 | [Range Sum Query - Immutable](https://leetcode.com/problems/range-sum-query-immutable) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/RangeSumQueryImmutable.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/range_sum_query_immutable.py) | -| 326 | [Power of Three](https://leetcode.com/problems/power-of-three) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/PowerOfThree.java) | +| 326 | [Power of Three](https://leetcode.com/problems/power-of-three) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/PowerOfThree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/power_of_three.py) | | 339 | [Nested List Weight Sum](https://leetcode.com/problems/nested-list-weight-sum) | Easy | | | 342 | [Power of Four](https://leetcode.com/problems/power-of-four) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/PowerOf4.java) | | 344 | [Reverse A String](https://leetcode.com/problems/reverse-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ReverseString.java) | diff --git a/python/power_of_three.py b/python/power_of_three.py new file mode 100644 index 0000000..8b1a2c0 --- /dev/null +++ b/python/power_of_three.py @@ -0,0 +1,9 @@ +class Solution: + def isPowerOfThree(self, n: int) -> bool: + if n <= 0: + return False + if n == 1: + return True + while n % 3 == 0: + n //= 3 + return n == 1 From c1c6298f8aad460974da8de58ebdbe74bab5b078 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 28 Jun 2021 15:48:28 +0530 Subject: [PATCH 072/947] adds premium content logo in question --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9788f16..54c0548 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ | 299 | [Bulls and Cows](https://leetcode.com/problems/bulls-and-cows) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/BullsAndCows.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/bulls_and_cows.py) | | 303 | [Range Sum Query - Immutable](https://leetcode.com/problems/range-sum-query-immutable) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/RangeSumQueryImmutable.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/range_sum_query_immutable.py) | | 326 | [Power of Three](https://leetcode.com/problems/power-of-three) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/PowerOfThree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/power_of_three.py) | -| 339 | [Nested List Weight Sum](https://leetcode.com/problems/nested-list-weight-sum) | Easy | | +| 339 | 🔒 [Nested List Weight Sum](https://leetcode.com/problems/nested-list-weight-sum) | Easy | | | 342 | [Power of Four](https://leetcode.com/problems/power-of-four) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/PowerOf4.java) | | 344 | [Reverse A String](https://leetcode.com/problems/reverse-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ReverseString.java) | | 345 | [Reverse Vowels of A String](https://leetcode.com/problems/reverse-vowels-of-a-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ReverseVowelsOfString.java) | From 3f6327cbcb9b197a40a011c49f94047c319bf717 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 28 Jun 2021 15:53:18 +0530 Subject: [PATCH 073/947] solves power of 4 in python --- README.md | 2 +- python/power_of_four.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 python/power_of_four.py diff --git a/README.md b/README.md index 54c0548..74efbee 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ | 303 | [Range Sum Query - Immutable](https://leetcode.com/problems/range-sum-query-immutable) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/RangeSumQueryImmutable.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/range_sum_query_immutable.py) | | 326 | [Power of Three](https://leetcode.com/problems/power-of-three) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/PowerOfThree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/power_of_three.py) | | 339 | 🔒 [Nested List Weight Sum](https://leetcode.com/problems/nested-list-weight-sum) | Easy | | -| 342 | [Power of Four](https://leetcode.com/problems/power-of-four) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/PowerOf4.java) | +| 342 | [Power of Four](https://leetcode.com/problems/power-of-four) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/PowerOf4.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/power_of_four.py) | | 344 | [Reverse A String](https://leetcode.com/problems/reverse-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ReverseString.java) | | 345 | [Reverse Vowels of A String](https://leetcode.com/problems/reverse-vowels-of-a-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ReverseVowelsOfString.java) | | 346 | [Moving Average From Data Stream](https://leetcode.com/problems/moving-average-from-data-stream) | Easy | | diff --git a/python/power_of_four.py b/python/power_of_four.py new file mode 100644 index 0000000..5302247 --- /dev/null +++ b/python/power_of_four.py @@ -0,0 +1,9 @@ +class Solution: + def isPowerOfFour(self, n: int) -> bool: + if n <= 0: + return False + if n == 1: + return True + while n % 4 == 0: + n //= 4 + return n == 1 From 81ebc2b07613aa586422702d2460977217cdc801 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 28 Jun 2021 15:56:15 +0530 Subject: [PATCH 074/947] solves reverse a string in python --- README.md | 2 +- python/reverse_a_string.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 python/reverse_a_string.py diff --git a/README.md b/README.md index 74efbee..9093e7e 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ | 326 | [Power of Three](https://leetcode.com/problems/power-of-three) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/PowerOfThree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/power_of_three.py) | | 339 | 🔒 [Nested List Weight Sum](https://leetcode.com/problems/nested-list-weight-sum) | Easy | | | 342 | [Power of Four](https://leetcode.com/problems/power-of-four) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/PowerOf4.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/power_of_four.py) | -| 344 | [Reverse A String](https://leetcode.com/problems/reverse-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ReverseString.java) | +| 344 | [Reverse A String](https://leetcode.com/problems/reverse-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ReverseString.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_a_string.py) | | 345 | [Reverse Vowels of A String](https://leetcode.com/problems/reverse-vowels-of-a-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ReverseVowelsOfString.java) | | 346 | [Moving Average From Data Stream](https://leetcode.com/problems/moving-average-from-data-stream) | Easy | | | 349 | [Intersection of 2 Arrays](https://leetcode.com/problems/intersection-of-two-arrays) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IntersectionOfTwoArrays.java) | diff --git a/python/reverse_a_string.py b/python/reverse_a_string.py new file mode 100644 index 0000000..f323fbe --- /dev/null +++ b/python/reverse_a_string.py @@ -0,0 +1,7 @@ +from typing import List + + +class Solution: + def reverseString(self, s: List[str]) -> None: + for index in range(len(s) // 2): + s[index], s[len(s) - index - 1] = s[len(s) - index - 1], s[index] From d3ed46c49c2f90a2120a5b0f5137b86a5de6c973 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Tue, 29 Jun 2021 12:14:40 +0530 Subject: [PATCH 075/947] solves reverse vowels in a string in python --- README.md | 2 +- python/reverse_vowels_of_a_string.py | 34 ++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 python/reverse_vowels_of_a_string.py diff --git a/README.md b/README.md index 9093e7e..83edc08 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ | 339 | 🔒 [Nested List Weight Sum](https://leetcode.com/problems/nested-list-weight-sum) | Easy | | | 342 | [Power of Four](https://leetcode.com/problems/power-of-four) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/PowerOf4.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/power_of_four.py) | | 344 | [Reverse A String](https://leetcode.com/problems/reverse-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ReverseString.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_a_string.py) | -| 345 | [Reverse Vowels of A String](https://leetcode.com/problems/reverse-vowels-of-a-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ReverseVowelsOfString.java) | +| 345 | [Reverse Vowels of A String](https://leetcode.com/problems/reverse-vowels-of-a-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ReverseVowelsOfString.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_vowels_of_a_string.py) | | 346 | [Moving Average From Data Stream](https://leetcode.com/problems/moving-average-from-data-stream) | Easy | | | 349 | [Intersection of 2 Arrays](https://leetcode.com/problems/intersection-of-two-arrays) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IntersectionOfTwoArrays.java) | | 350 | [Intersection of 2 Arrays II](https://leetcode.com/problems/intersection-of-two-arrays-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IntersectionOfTwoArraysII.java) | diff --git a/python/reverse_vowels_of_a_string.py b/python/reverse_vowels_of_a_string.py new file mode 100644 index 0000000..c4b19da --- /dev/null +++ b/python/reverse_vowels_of_a_string.py @@ -0,0 +1,34 @@ +import re + + +class Solution: + def __init__(self): + self.vowels = {'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'} + + def is_vowel(self, character: str) -> bool: + return character in self.vowels + + def index_in_range(self, l: iter, index: int) -> bool: + return 0 <= index < len(l) + + # 2 pointer approach + # def reverseVowels(self, s: str) -> str: + # characters = [character for character in s] + # left, right = 0, len(characters) - 1 + # while left < right: + # while left < right and not self.is_vowel(s[left]): + # left += 1 + # while left < right and not self.is_vowel(s[right]): + # right -= 1 + # if left < right: + # characters[left], characters[right] = characters[right], characters[left] + # left += 1 + # right -= 1 + # return ''.join(characters) + + # faster method + def reverseVowels(self, s): + vowels = re.findall('(?i)[aeiou]', s) + return re.sub('(?i)[aeiou]', lambda m: vowels.pop(), s) + +print(Solution().reverseVowels('aA')) From b8ee26431fc362ff1eb157af53f9676f2ac79ce1 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Tue, 29 Jun 2021 12:15:31 +0530 Subject: [PATCH 076/947] adds premium content logo for moving average --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 83edc08..fd39aff 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ | 342 | [Power of Four](https://leetcode.com/problems/power-of-four) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/PowerOf4.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/power_of_four.py) | | 344 | [Reverse A String](https://leetcode.com/problems/reverse-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ReverseString.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_a_string.py) | | 345 | [Reverse Vowels of A String](https://leetcode.com/problems/reverse-vowels-of-a-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ReverseVowelsOfString.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_vowels_of_a_string.py) | -| 346 | [Moving Average From Data Stream](https://leetcode.com/problems/moving-average-from-data-stream) | Easy | | +| 346 | 🔒 [Moving Average From Data Stream](https://leetcode.com/problems/moving-average-from-data-stream) | Easy | | | 349 | [Intersection of 2 Arrays](https://leetcode.com/problems/intersection-of-two-arrays) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IntersectionOfTwoArrays.java) | | 350 | [Intersection of 2 Arrays II](https://leetcode.com/problems/intersection-of-two-arrays-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IntersectionOfTwoArraysII.java) | | 359 | [Logger Rate Limiter](https://leetcode.com/problems/logger-rate-limiter) | Easy | | From 89c505184045f748d32fc8b2b81dacf4e32e2da4 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Tue, 29 Jun 2021 12:26:50 +0530 Subject: [PATCH 077/947] solves intersection of 2 arrays in python --- README.md | 2 +- python/intersection_of_2_array.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 python/intersection_of_2_array.py diff --git a/README.md b/README.md index fd39aff..e19ebd9 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ | 344 | [Reverse A String](https://leetcode.com/problems/reverse-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ReverseString.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_a_string.py) | | 345 | [Reverse Vowels of A String](https://leetcode.com/problems/reverse-vowels-of-a-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ReverseVowelsOfString.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_vowels_of_a_string.py) | | 346 | 🔒 [Moving Average From Data Stream](https://leetcode.com/problems/moving-average-from-data-stream) | Easy | | -| 349 | [Intersection of 2 Arrays](https://leetcode.com/problems/intersection-of-two-arrays) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IntersectionOfTwoArrays.java) | +| 349 | [Intersection of 2 Arrays](https://leetcode.com/problems/intersection-of-two-arrays) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IntersectionOfTwoArrays.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/intersection_of_2_array.py) | | 350 | [Intersection of 2 Arrays II](https://leetcode.com/problems/intersection-of-two-arrays-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IntersectionOfTwoArraysII.java) | | 359 | [Logger Rate Limiter](https://leetcode.com/problems/logger-rate-limiter) | Easy | | | 367 | [Valid Perfect Square](https://leetcode.com/problems/valid-perfect-square) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IsPerfectSquare.java) | diff --git a/python/intersection_of_2_array.py b/python/intersection_of_2_array.py new file mode 100644 index 0000000..d5d44f7 --- /dev/null +++ b/python/intersection_of_2_array.py @@ -0,0 +1,8 @@ +from typing import List + + +class Solution: + def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]: + nums_1_unique = set(nums1) + nums_2_unique = set(nums2) + return list(nums_1_unique.intersection(nums_2_unique)) From cd7fd43becf669e0422f570a1acad5aaa515528b Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Tue, 29 Jun 2021 12:47:35 +0530 Subject: [PATCH 078/947] solves intersection of array 2 in python --- README.md | 2 +- python/intersection_of_2_arrays_II.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 python/intersection_of_2_arrays_II.py diff --git a/README.md b/README.md index e19ebd9..b281fe3 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,7 @@ | 345 | [Reverse Vowels of A String](https://leetcode.com/problems/reverse-vowels-of-a-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ReverseVowelsOfString.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_vowels_of_a_string.py) | | 346 | 🔒 [Moving Average From Data Stream](https://leetcode.com/problems/moving-average-from-data-stream) | Easy | | | 349 | [Intersection of 2 Arrays](https://leetcode.com/problems/intersection-of-two-arrays) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IntersectionOfTwoArrays.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/intersection_of_2_array.py) | -| 350 | [Intersection of 2 Arrays II](https://leetcode.com/problems/intersection-of-two-arrays-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IntersectionOfTwoArraysII.java) | +| 350 | [Intersection of 2 Arrays II](https://leetcode.com/problems/intersection-of-two-arrays-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IntersectionOfTwoArraysII.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/intersection_of_2_arrays_II.py) | | 359 | [Logger Rate Limiter](https://leetcode.com/problems/logger-rate-limiter) | Easy | | | 367 | [Valid Perfect Square](https://leetcode.com/problems/valid-perfect-square) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IsPerfectSquare.java) | | 374 | [Guess Number Higher or Lower](https://leetcode.com/problems/guess-number-higher-or-lower) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/GuessNumberHigherOrLower.java) | diff --git a/python/intersection_of_2_arrays_II.py b/python/intersection_of_2_arrays_II.py new file mode 100644 index 0000000..96fa3a0 --- /dev/null +++ b/python/intersection_of_2_arrays_II.py @@ -0,0 +1,19 @@ +from typing import List, Dict + + +class Solution: + def get_frequency(self, numbers: List[int]) -> Dict[int, int]: + frequency = {} + for number in numbers: + frequency[number] = frequency.get(number, 0) + 1 + return frequency + + def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]: + result = [] + nums1, nums2 = (nums1, nums2) if len(nums1) < len(nums2) else (nums2, nums1) + nums_1_freq = self.get_frequency(nums1) + for number in nums2: + if nums_1_freq.get(number, 0) >= 1: + result.append(number) + nums_1_freq[number] -= 1 + return result From 6fb2b12713ead8a3d50d3791446e917a8e3771bc Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Tue, 29 Jun 2021 12:48:07 +0530 Subject: [PATCH 079/947] logger rate limitter is premium content --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b281fe3..ee39bda 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ | 346 | 🔒 [Moving Average From Data Stream](https://leetcode.com/problems/moving-average-from-data-stream) | Easy | | | 349 | [Intersection of 2 Arrays](https://leetcode.com/problems/intersection-of-two-arrays) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IntersectionOfTwoArrays.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/intersection_of_2_array.py) | | 350 | [Intersection of 2 Arrays II](https://leetcode.com/problems/intersection-of-two-arrays-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IntersectionOfTwoArraysII.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/intersection_of_2_arrays_II.py) | -| 359 | [Logger Rate Limiter](https://leetcode.com/problems/logger-rate-limiter) | Easy | | +| 359 | 🔒 [Logger Rate Limiter](https://leetcode.com/problems/logger-rate-limiter) | Easy | | | 367 | [Valid Perfect Square](https://leetcode.com/problems/valid-perfect-square) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IsPerfectSquare.java) | | 374 | [Guess Number Higher or Lower](https://leetcode.com/problems/guess-number-higher-or-lower) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/GuessNumberHigherOrLower.java) | | 383 | [Ransom Note](https://leetcode.com/problems/ransom-note) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/RansomNote.java) | From 1bfc95324ed3bb4715c213ecaac2968511b9bbe0 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Tue, 29 Jun 2021 13:42:05 +0530 Subject: [PATCH 080/947] solves Valid perfect square --- README.md | 2 +- python/valid_perfect_square.py | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 python/valid_perfect_square.py diff --git a/README.md b/README.md index ee39bda..ca373fc 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ | 349 | [Intersection of 2 Arrays](https://leetcode.com/problems/intersection-of-two-arrays) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IntersectionOfTwoArrays.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/intersection_of_2_array.py) | | 350 | [Intersection of 2 Arrays II](https://leetcode.com/problems/intersection-of-two-arrays-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IntersectionOfTwoArraysII.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/intersection_of_2_arrays_II.py) | | 359 | 🔒 [Logger Rate Limiter](https://leetcode.com/problems/logger-rate-limiter) | Easy | | -| 367 | [Valid Perfect Square](https://leetcode.com/problems/valid-perfect-square) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IsPerfectSquare.java) | +| 367 | [Valid Perfect Square](https://leetcode.com/problems/valid-perfect-square) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IsPerfectSquare.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/valid_perfect_square.py) | | 374 | [Guess Number Higher or Lower](https://leetcode.com/problems/guess-number-higher-or-lower) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/GuessNumberHigherOrLower.java) | | 383 | [Ransom Note](https://leetcode.com/problems/ransom-note) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/RansomNote.java) | | 387 | [First Unique Character in String](https://leetcode.com/problems/first-unique-character-in-a-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/FirstUniqueCharacter.java) | diff --git a/python/valid_perfect_square.py b/python/valid_perfect_square.py new file mode 100644 index 0000000..9097a9f --- /dev/null +++ b/python/valid_perfect_square.py @@ -0,0 +1,24 @@ +class Solution: + # binary search method + def isPerfectSquare(self, number: int) -> bool: + if number == 1: + return True + left, right = 0, number // 2 + while left <= right: + middle = (left + right) // 2 + mid_square = middle * middle + if mid_square == number: + return True + elif mid_square < number: + left = middle + 1 + else: + right = middle - 1 + return False + + # Newton's Method + # def isPerfectSquare(self, number: int) -> bool: + # r = number + # while r * r > number: + # r = (r + number / r) // 2 + # return r * r == number + From 34e7cbeea6948a1c1a3d782eadb0be136537fa8d Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Tue, 29 Jun 2021 13:50:07 +0530 Subject: [PATCH 081/947] solves guess number higher or lower in python --- README.md | 2 +- python/guess_number_higher_or_lower.py | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 python/guess_number_higher_or_lower.py diff --git a/README.md b/README.md index ca373fc..cdc140a 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ | 350 | [Intersection of 2 Arrays II](https://leetcode.com/problems/intersection-of-two-arrays-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IntersectionOfTwoArraysII.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/intersection_of_2_arrays_II.py) | | 359 | 🔒 [Logger Rate Limiter](https://leetcode.com/problems/logger-rate-limiter) | Easy | | | 367 | [Valid Perfect Square](https://leetcode.com/problems/valid-perfect-square) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IsPerfectSquare.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/valid_perfect_square.py) | -| 374 | [Guess Number Higher or Lower](https://leetcode.com/problems/guess-number-higher-or-lower) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/GuessNumberHigherOrLower.java) | +| 374 | [Guess Number Higher or Lower](https://leetcode.com/problems/guess-number-higher-or-lower) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/GuessNumberHigherOrLower.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/guess_number_higher_or_lower.py) | | 383 | [Ransom Note](https://leetcode.com/problems/ransom-note) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/RansomNote.java) | | 387 | [First Unique Character in String](https://leetcode.com/problems/first-unique-character-in-a-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/FirstUniqueCharacter.java) | | 389 | [Find the Difference](https://leetcode.com/problems/find-the-difference) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/FindTheDifference.java) | diff --git a/python/guess_number_higher_or_lower.py b/python/guess_number_higher_or_lower.py new file mode 100644 index 0000000..ce8cb38 --- /dev/null +++ b/python/guess_number_higher_or_lower.py @@ -0,0 +1,22 @@ +# The guess API is already defined for you. +# @param num, your guess +# @return -1 if my number is lower, 1 if my number is higher, otherwise return 0 + +def guess(num: int) -> int: + # temp purposes + return 0 + + +class Solution: + def guessNumber(self, n: int) -> int: + left, right = 1, n + while left <= right: + middle = (left + right) // 2 + hypothesis = guess(middle) + if hypothesis == 0: + return middle + elif hypothesis == 1: + left = middle + 1 + else: + right = middle - 1 + return 0 From 98629ade28a50f494c32d2472e3db5aeed5ff254 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Tue, 29 Jun 2021 13:54:38 +0530 Subject: [PATCH 082/947] solves ransom note in python --- README.md | 2 +- python/ransom_note.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 python/ransom_note.py diff --git a/README.md b/README.md index cdc140a..ab4f140 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ | 359 | 🔒 [Logger Rate Limiter](https://leetcode.com/problems/logger-rate-limiter) | Easy | | | 367 | [Valid Perfect Square](https://leetcode.com/problems/valid-perfect-square) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IsPerfectSquare.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/valid_perfect_square.py) | | 374 | [Guess Number Higher or Lower](https://leetcode.com/problems/guess-number-higher-or-lower) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/GuessNumberHigherOrLower.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/guess_number_higher_or_lower.py) | -| 383 | [Ransom Note](https://leetcode.com/problems/ransom-note) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/RansomNote.java) | +| 383 | [Ransom Note](https://leetcode.com/problems/ransom-note) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/RansomNote.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/ransom_note.py) | | 387 | [First Unique Character in String](https://leetcode.com/problems/first-unique-character-in-a-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/FirstUniqueCharacter.java) | | 389 | [Find the Difference](https://leetcode.com/problems/find-the-difference) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/FindTheDifference.java) | | 392 | [Is Subsequence](https://leetcode.com/problems/is-subsequence) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IsSubsequence.java) | diff --git a/python/ransom_note.py b/python/ransom_note.py new file mode 100644 index 0000000..b14fb21 --- /dev/null +++ b/python/ransom_note.py @@ -0,0 +1,18 @@ +from typing import Dict + + +class Solution: + def get_char_frequency(self, string: str) -> Dict[str, int]: + frequency = {} + for character in string: + frequency[character] = frequency.get(character, 0) + 1 + return frequency + + def canConstruct(self, ransomNote: str, magazine: str) -> bool: + magazine_characters = self.get_char_frequency(magazine) + for character in ransomNote: + if magazine_characters.get(character, 0) == 0: + return False + else: + magazine_characters[character] -= 1 + return True From b24c78bb30f2494c56c8c548de13d78167f56a3e Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Tue, 29 Jun 2021 14:03:28 +0530 Subject: [PATCH 083/947] solves first unique character in string --- README.md | 2 +- python/first_unique_character_in_string.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 python/first_unique_character_in_string.py diff --git a/README.md b/README.md index ab4f140..c4bca70 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ | 367 | [Valid Perfect Square](https://leetcode.com/problems/valid-perfect-square) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IsPerfectSquare.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/valid_perfect_square.py) | | 374 | [Guess Number Higher or Lower](https://leetcode.com/problems/guess-number-higher-or-lower) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/GuessNumberHigherOrLower.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/guess_number_higher_or_lower.py) | | 383 | [Ransom Note](https://leetcode.com/problems/ransom-note) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/RansomNote.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/ransom_note.py) | -| 387 | [First Unique Character in String](https://leetcode.com/problems/first-unique-character-in-a-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/FirstUniqueCharacter.java) | +| 387 | [First Unique Character in String](https://leetcode.com/problems/first-unique-character-in-a-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/FirstUniqueCharacter.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/first_unique_character_in_string.py) | | 389 | [Find the Difference](https://leetcode.com/problems/find-the-difference) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/FindTheDifference.java) | | 392 | [Is Subsequence](https://leetcode.com/problems/is-subsequence) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IsSubsequence.java) | | 401 | [Binary Watch](https://leetcode.com/problems/binary-watch) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/BinaryWatch.java) | diff --git a/python/first_unique_character_in_string.py b/python/first_unique_character_in_string.py new file mode 100644 index 0000000..6043a21 --- /dev/null +++ b/python/first_unique_character_in_string.py @@ -0,0 +1,9 @@ +class Solution: + def firstUniqChar(self, s: str) -> int: + frequencies = {} + for index, character in enumerate(s): + frequencies[character] = frequencies.get(character, 0) + 1 + for index, character in enumerate(s): + if frequencies[character] == 1: + return index + return -1 From eff67a938074c2ae9acdf4df75329f9c961bcc7a Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Tue, 29 Jun 2021 14:09:33 +0530 Subject: [PATCH 084/947] solves find the difference in python --- README.md | 2 +- python/find_the_difference.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 python/find_the_difference.py diff --git a/README.md b/README.md index c4bca70..0e2632f 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,7 @@ | 374 | [Guess Number Higher or Lower](https://leetcode.com/problems/guess-number-higher-or-lower) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/GuessNumberHigherOrLower.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/guess_number_higher_or_lower.py) | | 383 | [Ransom Note](https://leetcode.com/problems/ransom-note) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/RansomNote.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/ransom_note.py) | | 387 | [First Unique Character in String](https://leetcode.com/problems/first-unique-character-in-a-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/FirstUniqueCharacter.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/first_unique_character_in_string.py) | -| 389 | [Find the Difference](https://leetcode.com/problems/find-the-difference) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/FindTheDifference.java) | +| 389 | [Find the Difference](https://leetcode.com/problems/find-the-difference) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/FindTheDifference.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/find_the_difference.py) | | 392 | [Is Subsequence](https://leetcode.com/problems/is-subsequence) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IsSubsequence.java) | | 401 | [Binary Watch](https://leetcode.com/problems/binary-watch) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/BinaryWatch.java) | | 404 | [Sum of Left Leaves](https://leetcode.com/problems/sum-of-left-leaves) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/SumOfLeftLeaves.java) | diff --git a/python/find_the_difference.py b/python/find_the_difference.py new file mode 100644 index 0000000..3e1d9ee --- /dev/null +++ b/python/find_the_difference.py @@ -0,0 +1,17 @@ +from typing import Dict + + +class Solution: + def get_character_frequency(self, string: str) -> Dict[str, int]: + frequency = {} + for character in string: + frequency[character] = frequency.get(character, 0) + 1 + return frequency + + def findTheDifference(self, s: str, t: str) -> str: + characters_s = self.get_character_frequency(s) + for character in t: + if characters_s.get(character, 0) == 0: + return character + else: + characters_s[character] -= 1 From cc6dc92b82c0ac8bf3beaeaa6b5333fa71582afe Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Tue, 29 Jun 2021 18:45:53 +0530 Subject: [PATCH 085/947] solves is subsequence in python --- README.md | 2 +- python/find_the_difference.py | 17 +++-------------- python/is_subsequence.py | 8 ++++++++ 3 files changed, 12 insertions(+), 15 deletions(-) create mode 100644 python/is_subsequence.py diff --git a/README.md b/README.md index 0e2632f..7ef5290 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,7 @@ | 383 | [Ransom Note](https://leetcode.com/problems/ransom-note) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/RansomNote.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/ransom_note.py) | | 387 | [First Unique Character in String](https://leetcode.com/problems/first-unique-character-in-a-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/FirstUniqueCharacter.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/first_unique_character_in_string.py) | | 389 | [Find the Difference](https://leetcode.com/problems/find-the-difference) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/FindTheDifference.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/find_the_difference.py) | -| 392 | [Is Subsequence](https://leetcode.com/problems/is-subsequence) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IsSubsequence.java) | +| 392 | [Is Subsequence](https://leetcode.com/problems/is-subsequence) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IsSubsequence.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/is_subsequence.py) | | 401 | [Binary Watch](https://leetcode.com/problems/binary-watch) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/BinaryWatch.java) | | 404 | [Sum of Left Leaves](https://leetcode.com/problems/sum-of-left-leaves) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/SumOfLeftLeaves.java) | | 405 | [Convert a Number to Hexadecimal](https://leetcode.com/problems/convert-a-number-to-hexadecimal) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ConvertNumberToHexadecimal.java) | diff --git a/python/find_the_difference.py b/python/find_the_difference.py index 3e1d9ee..3813e18 100644 --- a/python/find_the_difference.py +++ b/python/find_the_difference.py @@ -1,17 +1,6 @@ -from typing import Dict - - class Solution: - def get_character_frequency(self, string: str) -> Dict[str, int]: - frequency = {} - for character in string: - frequency[character] = frequency.get(character, 0) + 1 - return frequency + def ascii_sum(self, string: str) -> int: + return sum(ord(character) for character in string) def findTheDifference(self, s: str, t: str) -> str: - characters_s = self.get_character_frequency(s) - for character in t: - if characters_s.get(character, 0) == 0: - return character - else: - characters_s[character] -= 1 + return chr(self.ascii_sum(t) - self.ascii_sum(s)) diff --git a/python/is_subsequence.py b/python/is_subsequence.py new file mode 100644 index 0000000..adf416f --- /dev/null +++ b/python/is_subsequence.py @@ -0,0 +1,8 @@ +class Solution: + def isSubsequence(self, s: str, t: str) -> bool: + i, j = 0, 0 + while i < len(s) and j < len(t): + if s[i] == t[j]: + i += 1 + j += 1 + return i == len(s) From abb6b278bc88bbfd94b6f17831f2906f78fe630a Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Tue, 29 Jun 2021 20:44:09 +0530 Subject: [PATCH 086/947] solves binary watch in python --- README.md | 2 +- python/binary_watch.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 python/binary_watch.py diff --git a/README.md b/README.md index 7ef5290..531888c 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,7 @@ | 387 | [First Unique Character in String](https://leetcode.com/problems/first-unique-character-in-a-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/FirstUniqueCharacter.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/first_unique_character_in_string.py) | | 389 | [Find the Difference](https://leetcode.com/problems/find-the-difference) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/FindTheDifference.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/find_the_difference.py) | | 392 | [Is Subsequence](https://leetcode.com/problems/is-subsequence) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IsSubsequence.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/is_subsequence.py) | -| 401 | [Binary Watch](https://leetcode.com/problems/binary-watch) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/BinaryWatch.java) | +| 401 | [Binary Watch](https://leetcode.com/problems/binary-watch) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/BinaryWatch.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/binary_watch.py) | | 404 | [Sum of Left Leaves](https://leetcode.com/problems/sum-of-left-leaves) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/SumOfLeftLeaves.java) | | 405 | [Convert a Number to Hexadecimal](https://leetcode.com/problems/convert-a-number-to-hexadecimal) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ConvertNumberToHexadecimal.java) | | 408 | [Valid Word Abbreviation](https://leetcode.com/problems/valid-word-abbreviation) | Easy | | diff --git a/python/binary_watch.py b/python/binary_watch.py new file mode 100644 index 0000000..df70d0e --- /dev/null +++ b/python/binary_watch.py @@ -0,0 +1,5 @@ +class Solution: + def readBinaryWatch(self, num): + return ['%d:%02d' % (h, m) + for h in range(12) for m in range(60) + if (bin(h) + bin(m)).count('1') == num] From 7226d6816e99c36ccdf2f96f54277de60136d20c Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Tue, 29 Jun 2021 23:08:18 +0530 Subject: [PATCH 087/947] solves sum left leaves in python --- README.md | 2 +- python/sum_of_left_leaves.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 python/sum_of_left_leaves.py diff --git a/README.md b/README.md index 531888c..6fca92d 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ | 389 | [Find the Difference](https://leetcode.com/problems/find-the-difference) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/FindTheDifference.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/find_the_difference.py) | | 392 | [Is Subsequence](https://leetcode.com/problems/is-subsequence) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IsSubsequence.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/is_subsequence.py) | | 401 | [Binary Watch](https://leetcode.com/problems/binary-watch) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/BinaryWatch.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/binary_watch.py) | -| 404 | [Sum of Left Leaves](https://leetcode.com/problems/sum-of-left-leaves) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/SumOfLeftLeaves.java) | +| 404 | [Sum of Left Leaves](https://leetcode.com/problems/sum-of-left-leaves) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/SumOfLeftLeaves.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/sum_of_left_leaves.py) | | 405 | [Convert a Number to Hexadecimal](https://leetcode.com/problems/convert-a-number-to-hexadecimal) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ConvertNumberToHexadecimal.java) | | 408 | [Valid Word Abbreviation](https://leetcode.com/problems/valid-word-abbreviation) | Easy | | | 409 | [Longest Palindrome](https://leetcode.com/problems/longest-palindrome) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/LongestPalindrome.java) | diff --git a/python/sum_of_left_leaves.py b/python/sum_of_left_leaves.py new file mode 100644 index 0000000..d504ec7 --- /dev/null +++ b/python/sum_of_left_leaves.py @@ -0,0 +1,21 @@ +# Definition for a binary tree node. +class TreeNode: + def __init__(self, val=0, left=None, right=None): + self.val = val + self.left = left + self.right = right + + +class Solution: + def is_leaf_node(self, root: TreeNode) -> bool: + return root.left is None and root.right is None + + def sum_left_leaves(self, root: TreeNode, is_left_branch: bool) -> int: + if root is None: + return 0 + if self.is_leaf_node(root) and is_left_branch: + return root.val + return self.sum_left_leaves(root.left, is_left_branch=True) + self.sum_left_leaves(root.right, is_left_branch=False) + + def sumOfLeftLeaves(self, root: TreeNode) -> int: + return self.sum_left_leaves(root, is_left_branch=False) From 322688c687a2ed8b0e008a1c70ef511e01365d2c Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Tue, 29 Jun 2021 23:46:48 +0530 Subject: [PATCH 088/947] solves convert a number to hexadecimal in python --- README.md | 2 +- python/convert_a_number_to_hexadecimal.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 python/convert_a_number_to_hexadecimal.py diff --git a/README.md b/README.md index 6fca92d..8d8b9bf 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,7 @@ | 392 | [Is Subsequence](https://leetcode.com/problems/is-subsequence) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IsSubsequence.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/is_subsequence.py) | | 401 | [Binary Watch](https://leetcode.com/problems/binary-watch) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/BinaryWatch.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/binary_watch.py) | | 404 | [Sum of Left Leaves](https://leetcode.com/problems/sum-of-left-leaves) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/SumOfLeftLeaves.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/sum_of_left_leaves.py) | -| 405 | [Convert a Number to Hexadecimal](https://leetcode.com/problems/convert-a-number-to-hexadecimal) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ConvertNumberToHexadecimal.java) | +| 405 | [Convert a Number to Hexadecimal](https://leetcode.com/problems/convert-a-number-to-hexadecimal) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ConvertNumberToHexadecimal.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/convert_a_number_to_hexadecimal.py) | | 408 | [Valid Word Abbreviation](https://leetcode.com/problems/valid-word-abbreviation) | Easy | | | 409 | [Longest Palindrome](https://leetcode.com/problems/longest-palindrome) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/LongestPalindrome.java) | | 412 | [Fizz Buzz](https://leetcode.com/problems/fizz-buzz) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/FizzBuzz.java) | diff --git a/python/convert_a_number_to_hexadecimal.py b/python/convert_a_number_to_hexadecimal.py new file mode 100644 index 0000000..f1386bd --- /dev/null +++ b/python/convert_a_number_to_hexadecimal.py @@ -0,0 +1,14 @@ +class Solution: + def __init__(self): + self.hex_chars = [str(i) for i in range(10)] + [chr(97 + i) for i in range(7)] + + def toHex(self, num: int) -> str: + if num == 0: + return '0' + if num < 0: + num = 2 ** 32 + num + result = '' + while num != 0: + result = self.hex_chars[num & 15] + result + num = (num >> 4) + return result From 52ec50127c0796735b09685ac5ad5116581f26a2 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Tue, 29 Jun 2021 23:47:33 +0530 Subject: [PATCH 089/947] adds premium content logo in front of valid word abbreviation --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8d8b9bf..95e9b4c 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ | 401 | [Binary Watch](https://leetcode.com/problems/binary-watch) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/BinaryWatch.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/binary_watch.py) | | 404 | [Sum of Left Leaves](https://leetcode.com/problems/sum-of-left-leaves) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/SumOfLeftLeaves.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/sum_of_left_leaves.py) | | 405 | [Convert a Number to Hexadecimal](https://leetcode.com/problems/convert-a-number-to-hexadecimal) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ConvertNumberToHexadecimal.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/convert_a_number_to_hexadecimal.py) | -| 408 | [Valid Word Abbreviation](https://leetcode.com/problems/valid-word-abbreviation) | Easy | | +| 408 | 🔒 [Valid Word Abbreviation](https://leetcode.com/problems/valid-word-abbreviation) | Easy | | | 409 | [Longest Palindrome](https://leetcode.com/problems/longest-palindrome) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/LongestPalindrome.java) | | 412 | [Fizz Buzz](https://leetcode.com/problems/fizz-buzz) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/FizzBuzz.java) | | 414 | [Third Maximum Number](https://leetcode.com/problems/third-maximum-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ThirdMaximumNumber.java) | From 87da63a7e21ba330f17738fe7793aa7a49aa29e0 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Tue, 29 Jun 2021 23:53:47 +0530 Subject: [PATCH 090/947] solves longest palindrome in python --- README.md | 2 +- python/longest_palindrome.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 python/longest_palindrome.py diff --git a/README.md b/README.md index 95e9b4c..a8d302a 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,7 @@ | 404 | [Sum of Left Leaves](https://leetcode.com/problems/sum-of-left-leaves) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/SumOfLeftLeaves.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/sum_of_left_leaves.py) | | 405 | [Convert a Number to Hexadecimal](https://leetcode.com/problems/convert-a-number-to-hexadecimal) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ConvertNumberToHexadecimal.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/convert_a_number_to_hexadecimal.py) | | 408 | 🔒 [Valid Word Abbreviation](https://leetcode.com/problems/valid-word-abbreviation) | Easy | | -| 409 | [Longest Palindrome](https://leetcode.com/problems/longest-palindrome) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/LongestPalindrome.java) | +| 409 | [Longest Palindrome](https://leetcode.com/problems/longest-palindrome) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/LongestPalindrome.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/longest_palindrome.py) | | 412 | [Fizz Buzz](https://leetcode.com/problems/fizz-buzz) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/FizzBuzz.java) | | 414 | [Third Maximum Number](https://leetcode.com/problems/third-maximum-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ThirdMaximumNumber.java) | | 415 | [Add Strings](https://leetcode.com/problems/add-strings) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/AddString.java) | diff --git a/python/longest_palindrome.py b/python/longest_palindrome.py new file mode 100644 index 0000000..251ce24 --- /dev/null +++ b/python/longest_palindrome.py @@ -0,0 +1,14 @@ +class Solution: + def longestPalindrome(self, s: str) -> int: + character_frequency = {} + for character in s: + character_frequency[character] = character_frequency.get(character, 0) + 1 + length = 0 + had_odd_length = False + for frequency in character_frequency.values(): + if frequency % 2 == 0: + length += frequency + else: + length += frequency - 1 + had_odd_length = True + return length + int(had_odd_length) From a8a57b90fde4195c8da6711dc1a8964f3951dabb Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 30 Jun 2021 00:17:49 +0530 Subject: [PATCH 091/947] solves fizz buzz in python --- README.md | 4 ++-- python/fizz_buzz.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 python/fizz_buzz.py diff --git a/README.md b/README.md index a8d302a..4476e34 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Leetcode Algorithms +# LeetCode Algorithms ![problems-solved](https://img.shields.io/badge/Problems%20Solved-107/571-1f425f.svg) ![problems-solved-java](https://img.shields.io/badge/Java-107/1571-1abc9c.svg) @@ -111,7 +111,7 @@ | 405 | [Convert a Number to Hexadecimal](https://leetcode.com/problems/convert-a-number-to-hexadecimal) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ConvertNumberToHexadecimal.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/convert_a_number_to_hexadecimal.py) | | 408 | 🔒 [Valid Word Abbreviation](https://leetcode.com/problems/valid-word-abbreviation) | Easy | | | 409 | [Longest Palindrome](https://leetcode.com/problems/longest-palindrome) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/LongestPalindrome.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/longest_palindrome.py) | -| 412 | [Fizz Buzz](https://leetcode.com/problems/fizz-buzz) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/FizzBuzz.java) | +| 412 | [Fizz Buzz](https://leetcode.com/problems/fizz-buzz) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/FizzBuzz.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/fizz_buzz.py) | | 414 | [Third Maximum Number](https://leetcode.com/problems/third-maximum-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ThirdMaximumNumber.java) | | 415 | [Add Strings](https://leetcode.com/problems/add-strings) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/AddString.java) | | 422 | [Valid Word Square](https://leetcode.com/problems/valid-word-square) | Easy | | diff --git a/python/fizz_buzz.py b/python/fizz_buzz.py new file mode 100644 index 0000000..62a42c4 --- /dev/null +++ b/python/fizz_buzz.py @@ -0,0 +1,16 @@ +from typing import List + + +class Solution: + def fizzBuzz(self, n: int) -> List[str]: + result = [] + for i in range(1, n + 1): + if i % 15 == 0: + result.append('FizzBuzz') + elif i % 3 == 0: + result.append('Fizz') + elif i % 5 == 0: + result.append('Buzz') + else: + result.append(str(i)) + return result From 793260c23c613416b8311817c24bf0ef70f94ed2 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 30 Jun 2021 00:56:39 +0530 Subject: [PATCH 092/947] solves third largest number in python --- README.md | 2 +- python/third_maximum_number.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 python/third_maximum_number.py diff --git a/README.md b/README.md index 4476e34..b21dd93 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,7 @@ | 408 | 🔒 [Valid Word Abbreviation](https://leetcode.com/problems/valid-word-abbreviation) | Easy | | | 409 | [Longest Palindrome](https://leetcode.com/problems/longest-palindrome) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/LongestPalindrome.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/longest_palindrome.py) | | 412 | [Fizz Buzz](https://leetcode.com/problems/fizz-buzz) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/FizzBuzz.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/fizz_buzz.py) | -| 414 | [Third Maximum Number](https://leetcode.com/problems/third-maximum-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ThirdMaximumNumber.java) | +| 414 | [Third Maximum Number](https://leetcode.com/problems/third-maximum-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ThirdMaximumNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/fizz_buzz.py) | | 415 | [Add Strings](https://leetcode.com/problems/add-strings) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/AddString.java) | | 422 | [Valid Word Square](https://leetcode.com/problems/valid-word-square) | Easy | | | 434 | [Number of Segments in a String](https://leetcode.com/problems/number-of-segments-in-a-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/NumberOfSegmentsInString.java) | diff --git a/python/third_maximum_number.py b/python/third_maximum_number.py new file mode 100644 index 0000000..08ffe53 --- /dev/null +++ b/python/third_maximum_number.py @@ -0,0 +1,15 @@ +from typing import List +import heapq + + +class Solution: + def thirdMax(self, nums: List[int]) -> int: + distinct = set(nums) + if len(distinct) < 3: + return max(distinct) + heap = [] + for number in distinct: + heapq.heappush(heap, -number) + heapq.heappop(heap) + heapq.heappop(heap) + return heapq.heappop(heap) From 553d89aa182731ad9d5ef0151eb3848617d3a1b9 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 30 Jun 2021 10:58:18 +0530 Subject: [PATCH 093/947] solves add strings on python --- README.md | 2 +- python/add_strings.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 python/add_strings.py diff --git a/README.md b/README.md index b21dd93..5ad741c 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,7 @@ | 409 | [Longest Palindrome](https://leetcode.com/problems/longest-palindrome) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/LongestPalindrome.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/longest_palindrome.py) | | 412 | [Fizz Buzz](https://leetcode.com/problems/fizz-buzz) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/FizzBuzz.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/fizz_buzz.py) | | 414 | [Third Maximum Number](https://leetcode.com/problems/third-maximum-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ThirdMaximumNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/fizz_buzz.py) | -| 415 | [Add Strings](https://leetcode.com/problems/add-strings) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/AddString.java) | +| 415 | [Add Strings](https://leetcode.com/problems/add-strings) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/AddString.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/add_strings.py) | | 422 | [Valid Word Square](https://leetcode.com/problems/valid-word-square) | Easy | | | 434 | [Number of Segments in a String](https://leetcode.com/problems/number-of-segments-in-a-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/NumberOfSegmentsInString.java) | | 441 | [Arranging Coins](https://leetcode.com/problems/arranging-coins) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ArrangingCoins.java) | diff --git a/python/add_strings.py b/python/add_strings.py new file mode 100644 index 0000000..108a0aa --- /dev/null +++ b/python/add_strings.py @@ -0,0 +1,18 @@ +class Solution: + def str_to_int(self, number: str) -> int: + value = 0 + for character in number: + value = 10 * value + ord(character) - 48 + return value + + def int_to_str(self, number: int) -> str: + if number == 0: + return '0' + value = '' + while number > 0: + value = str(number % 10) + value + number //= 10 + return value + + def addStrings(self, num1: str, num2: str) -> str: + return self.int_to_str(self.str_to_int(num1) + self.str_to_int(num2)) From 07f8a54cf8041df721466f2f2487c87f571ec664 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 30 Jun 2021 10:59:09 +0530 Subject: [PATCH 094/947] adds premium content logo in valid word square --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5ad741c..656e506 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,7 @@ | 412 | [Fizz Buzz](https://leetcode.com/problems/fizz-buzz) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/FizzBuzz.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/fizz_buzz.py) | | 414 | [Third Maximum Number](https://leetcode.com/problems/third-maximum-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ThirdMaximumNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/fizz_buzz.py) | | 415 | [Add Strings](https://leetcode.com/problems/add-strings) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/AddString.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/add_strings.py) | -| 422 | [Valid Word Square](https://leetcode.com/problems/valid-word-square) | Easy | | +| 422 | 🔒 [Valid Word Square](https://leetcode.com/problems/valid-word-square) | Easy | | | 434 | [Number of Segments in a String](https://leetcode.com/problems/number-of-segments-in-a-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/NumberOfSegmentsInString.java) | | 441 | [Arranging Coins](https://leetcode.com/problems/arranging-coins) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ArrangingCoins.java) | | 443 | [String Compression](https://leetcode.com/problems/string-compression) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/StringCompression.java) | From 60241b6dacc063f31e1b8120e03017325b2f36b7 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 30 Jun 2021 17:23:20 +0530 Subject: [PATCH 095/947] solves number of segments in a string in python --- README.md | 2 +- python/number_of_segments_in_a_string.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 python/number_of_segments_in_a_string.py diff --git a/README.md b/README.md index 656e506..19baea4 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ | 414 | [Third Maximum Number](https://leetcode.com/problems/third-maximum-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ThirdMaximumNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/fizz_buzz.py) | | 415 | [Add Strings](https://leetcode.com/problems/add-strings) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/AddString.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/add_strings.py) | | 422 | 🔒 [Valid Word Square](https://leetcode.com/problems/valid-word-square) | Easy | | -| 434 | [Number of Segments in a String](https://leetcode.com/problems/number-of-segments-in-a-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/NumberOfSegmentsInString.java) | +| 434 | [Number of Segments in a String](https://leetcode.com/problems/number-of-segments-in-a-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/NumberOfSegmentsInString.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/number_of_segments_in_a_string.py) | | 441 | [Arranging Coins](https://leetcode.com/problems/arranging-coins) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ArrangingCoins.java) | | 443 | [String Compression](https://leetcode.com/problems/string-compression) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/StringCompression.java) | | 447 | [Number of Boomerangs](https://leetcode.com/problems/number-of-boomerangs) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/NumberOfBoomerangs.java) | diff --git a/python/number_of_segments_in_a_string.py b/python/number_of_segments_in_a_string.py new file mode 100644 index 0000000..ce40742 --- /dev/null +++ b/python/number_of_segments_in_a_string.py @@ -0,0 +1,11 @@ +class Solution: + def countSegments(self, s: str) -> int: + counting, segments = False, 0 + for character in s: + if counting and character == ' ': + counting = False + continue + if not counting and character != ' ': + segments += 1 + counting = True + return segments From bd097b786778671d1261f91e4b39a458307d53bb Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 1 Jul 2021 10:22:20 +0530 Subject: [PATCH 096/947] solves arranging coins in python --- README.md | 2 +- python/arranging_coins.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 python/arranging_coins.py diff --git a/README.md b/README.md index 19baea4..42fc760 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,7 @@ | 415 | [Add Strings](https://leetcode.com/problems/add-strings) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/AddString.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/add_strings.py) | | 422 | 🔒 [Valid Word Square](https://leetcode.com/problems/valid-word-square) | Easy | | | 434 | [Number of Segments in a String](https://leetcode.com/problems/number-of-segments-in-a-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/NumberOfSegmentsInString.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/number_of_segments_in_a_string.py) | -| 441 | [Arranging Coins](https://leetcode.com/problems/arranging-coins) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ArrangingCoins.java) | +| 441 | [Arranging Coins](https://leetcode.com/problems/arranging-coins) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ArrangingCoins.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/arranging_coins.py) | | 443 | [String Compression](https://leetcode.com/problems/string-compression) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/StringCompression.java) | | 447 | [Number of Boomerangs](https://leetcode.com/problems/number-of-boomerangs) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/NumberOfBoomerangs.java) | | 448 | [Find All Numbers Disappeared in an Array](https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FindAllNumbersDisappearedInAnArray.java) | diff --git a/python/arranging_coins.py b/python/arranging_coins.py new file mode 100644 index 0000000..4833455 --- /dev/null +++ b/python/arranging_coins.py @@ -0,0 +1,6 @@ +import math + + +class Solution: + def arrangeCoins(self, n: int) -> int: + return math.floor((math.sqrt(8 * n + 1) - 1) / 2) From 7ab932cba5dbbaefb41ef72d38b7841e6a51dd89 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 1 Jul 2021 10:29:57 +0530 Subject: [PATCH 097/947] shortens urls --- README.md | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 42fc760..689e2ec 100644 --- a/README.md +++ b/README.md @@ -86,39 +86,39 @@ | 276 | 🔒 [Paint Fence](https://leetcode.com/problems/paint-fence) | Easy | | | 278 | [First Bad Version](https://leetcode.com/problems/first-bad-version) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FirstBadVersion.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/first_bad_version.py) | | 283 | [Move Zeroes](https://leetcode.com/problems/move-zeroes) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MoveZeros.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/move_zeroes.py) | -| 290 | [Word Pattern](https://leetcode.com/problems/word-pattern) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/WordPattern.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/word_pattern.py) | -| 292 | [Nim Game](https://leetcode.com/problems/nim-game) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/NimGame.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/nim_game.py) | +| 290 | [Word Pattern](https://leetcode.com/problems/word-pattern) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/WordPattern.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/word_pattern.py) | +| 292 | [Nim Game](https://leetcode.com/problems/nim-game) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/NimGame.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/nim_game.py) | | 293 | 🔒 [Flip Game](https://leetcode.com/problems/flip-game) | Easy | | -| 299 | [Bulls and Cows](https://leetcode.com/problems/bulls-and-cows) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/BullsAndCows.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/bulls_and_cows.py) | -| 303 | [Range Sum Query - Immutable](https://leetcode.com/problems/range-sum-query-immutable) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/RangeSumQueryImmutable.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/range_sum_query_immutable.py) | -| 326 | [Power of Three](https://leetcode.com/problems/power-of-three) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/PowerOfThree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/power_of_three.py) | +| 299 | [Bulls and Cows](https://leetcode.com/problems/bulls-and-cows) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BullsAndCows.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/bulls_and_cows.py) | +| 303 | [Range Sum Query - Immutable](https://leetcode.com/problems/range-sum-query-immutable) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RangeSumQueryImmutable.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/range_sum_query_immutable.py) | +| 326 | [Power of Three](https://leetcode.com/problems/power-of-three) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PowerOfThree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/power_of_three.py) | | 339 | 🔒 [Nested List Weight Sum](https://leetcode.com/problems/nested-list-weight-sum) | Easy | | -| 342 | [Power of Four](https://leetcode.com/problems/power-of-four) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/PowerOf4.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/power_of_four.py) | -| 344 | [Reverse A String](https://leetcode.com/problems/reverse-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ReverseString.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_a_string.py) | -| 345 | [Reverse Vowels of A String](https://leetcode.com/problems/reverse-vowels-of-a-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ReverseVowelsOfString.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_vowels_of_a_string.py) | +| 342 | [Power of Four](https://leetcode.com/problems/power-of-four) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PowerOf4.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/power_of_four.py) | +| 344 | [Reverse A String](https://leetcode.com/problems/reverse-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ReverseString.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_a_string.py) | +| 345 | [Reverse Vowels of A String](https://leetcode.com/problems/reverse-vowels-of-a-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ReverseVowelsOfString.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_vowels_of_a_string.py) | | 346 | 🔒 [Moving Average From Data Stream](https://leetcode.com/problems/moving-average-from-data-stream) | Easy | | -| 349 | [Intersection of 2 Arrays](https://leetcode.com/problems/intersection-of-two-arrays) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IntersectionOfTwoArrays.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/intersection_of_2_array.py) | -| 350 | [Intersection of 2 Arrays II](https://leetcode.com/problems/intersection-of-two-arrays-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IntersectionOfTwoArraysII.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/intersection_of_2_arrays_II.py) | +| 349 | [Intersection of 2 Arrays](https://leetcode.com/problems/intersection-of-two-arrays) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/IntersectionOfTwoArrays.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/intersection_of_2_array.py) | +| 350 | [Intersection of 2 Arrays II](https://leetcode.com/problems/intersection-of-two-arrays-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/IntersectionOfTwoArraysII.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/intersection_of_2_arrays_II.py) | | 359 | 🔒 [Logger Rate Limiter](https://leetcode.com/problems/logger-rate-limiter) | Easy | | -| 367 | [Valid Perfect Square](https://leetcode.com/problems/valid-perfect-square) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IsPerfectSquare.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/valid_perfect_square.py) | -| 374 | [Guess Number Higher or Lower](https://leetcode.com/problems/guess-number-higher-or-lower) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/GuessNumberHigherOrLower.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/guess_number_higher_or_lower.py) | -| 383 | [Ransom Note](https://leetcode.com/problems/ransom-note) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/RansomNote.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/ransom_note.py) | -| 387 | [First Unique Character in String](https://leetcode.com/problems/first-unique-character-in-a-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/FirstUniqueCharacter.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/first_unique_character_in_string.py) | -| 389 | [Find the Difference](https://leetcode.com/problems/find-the-difference) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/FindTheDifference.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/find_the_difference.py) | -| 392 | [Is Subsequence](https://leetcode.com/problems/is-subsequence) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IsSubsequence.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/is_subsequence.py) | -| 401 | [Binary Watch](https://leetcode.com/problems/binary-watch) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/BinaryWatch.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/binary_watch.py) | -| 404 | [Sum of Left Leaves](https://leetcode.com/problems/sum-of-left-leaves) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/SumOfLeftLeaves.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/sum_of_left_leaves.py) | -| 405 | [Convert a Number to Hexadecimal](https://leetcode.com/problems/convert-a-number-to-hexadecimal) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ConvertNumberToHexadecimal.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/convert_a_number_to_hexadecimal.py) | +| 367 | [Valid Perfect Square](https://leetcode.com/problems/valid-perfect-square) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/IsPerfectSquare.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/valid_perfect_square.py) | +| 374 | [Guess Number Higher or Lower](https://leetcode.com/problems/guess-number-higher-or-lower) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/GuessNumberHigherOrLower.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/guess_number_higher_or_lower.py) | +| 383 | [Ransom Note](https://leetcode.com/problems/ransom-note) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RansomNote.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/ransom_note.py) | +| 387 | [First Unique Character in String](https://leetcode.com/problems/first-unique-character-in-a-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FirstUniqueCharacter.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/first_unique_character_in_string.py) | +| 389 | [Find the Difference](https://leetcode.com/problems/find-the-difference) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FindTheDifference.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/find_the_difference.py) | +| 392 | [Is Subsequence](https://leetcode.com/problems/is-subsequence) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/IsSubsequence.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/is_subsequence.py) | +| 401 | [Binary Watch](https://leetcode.com/problems/binary-watch) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BinaryWatch.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/binary_watch.py) | +| 404 | [Sum of Left Leaves](https://leetcode.com/problems/sum-of-left-leaves) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/SumOfLeftLeaves.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/sum_of_left_leaves.py) | +| 405 | [Convert a Number to Hexadecimal](https://leetcode.com/problems/convert-a-number-to-hexadecimal) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ConvertNumberToHexadecimal.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/convert_a_number_to_hexadecimal.py) | | 408 | 🔒 [Valid Word Abbreviation](https://leetcode.com/problems/valid-word-abbreviation) | Easy | | -| 409 | [Longest Palindrome](https://leetcode.com/problems/longest-palindrome) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/LongestPalindrome.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/longest_palindrome.py) | -| 412 | [Fizz Buzz](https://leetcode.com/problems/fizz-buzz) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/FizzBuzz.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/fizz_buzz.py) | -| 414 | [Third Maximum Number](https://leetcode.com/problems/third-maximum-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ThirdMaximumNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/fizz_buzz.py) | -| 415 | [Add Strings](https://leetcode.com/problems/add-strings) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/AddString.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/add_strings.py) | +| 409 | [Longest Palindrome](https://leetcode.com/problems/longest-palindrome) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/LongestPalindrome.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/longest_palindrome.py) | +| 412 | [Fizz Buzz](https://leetcode.com/problems/fizz-buzz) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FizzBuzz.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/fizz_buzz.py) | +| 414 | [Third Maximum Number](https://leetcode.com/problems/third-maximum-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ThirdMaximumNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/fizz_buzz.py) | +| 415 | [Add Strings](https://leetcode.com/problems/add-strings) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/AddString.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/add_strings.py) | | 422 | 🔒 [Valid Word Square](https://leetcode.com/problems/valid-word-square) | Easy | | -| 434 | [Number of Segments in a String](https://leetcode.com/problems/number-of-segments-in-a-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/NumberOfSegmentsInString.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/number_of_segments_in_a_string.py) | -| 441 | [Arranging Coins](https://leetcode.com/problems/arranging-coins) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ArrangingCoins.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/arranging_coins.py) | -| 443 | [String Compression](https://leetcode.com/problems/string-compression) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/StringCompression.java) | -| 447 | [Number of Boomerangs](https://leetcode.com/problems/number-of-boomerangs) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/NumberOfBoomerangs.java) | +| 434 | [Number of Segments in a String](https://leetcode.com/problems/number-of-segments-in-a-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/NumberOfSegmentsInString.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/number_of_segments_in_a_string.py) | +| 441 | [Arranging Coins](https://leetcode.com/problems/arranging-coins) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ArrangingCoins.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/arranging_coins.py) | +| 443 | [String Compression](https://leetcode.com/problems/string-compression) | Medium | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/StringCompression.java) | +| 447 | [Number of Boomerangs](https://leetcode.com/problems/number-of-boomerangs) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/NumberOfBoomerangs.java) | | 448 | [Find All Numbers Disappeared in an Array](https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FindAllNumbersDisappearedInAnArray.java) | | 453 | [Minimum Moves to Equal Array Elements](https://leetcode.com/problems/minimum-moves-to-equal-array-elements) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MinimumMovesToEqualArrayElements.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/minimum_moves_to_equal_array_element.py) | | 455 | [Assign Cookies](https://leetcode.com/problems/assign-cookies) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/AssignCookies.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/assign_cookies.py)| From a0fccd4f176be2a3c86829cf562db109e7831eb4 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 1 Jul 2021 10:50:05 +0530 Subject: [PATCH 098/947] solves string compression in python --- README.md | 2 +- python/string_compression.py | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 python/string_compression.py diff --git a/README.md b/README.md index 689e2ec..a64bafc 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,7 @@ | 422 | 🔒 [Valid Word Square](https://leetcode.com/problems/valid-word-square) | Easy | | | 434 | [Number of Segments in a String](https://leetcode.com/problems/number-of-segments-in-a-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/NumberOfSegmentsInString.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/number_of_segments_in_a_string.py) | | 441 | [Arranging Coins](https://leetcode.com/problems/arranging-coins) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ArrangingCoins.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/arranging_coins.py) | -| 443 | [String Compression](https://leetcode.com/problems/string-compression) | Medium | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/StringCompression.java) | +| 443 | [String Compression](https://leetcode.com/problems/string-compression) | Medium | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/StringCompression.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/string_compression.py) | | 447 | [Number of Boomerangs](https://leetcode.com/problems/number-of-boomerangs) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/NumberOfBoomerangs.java) | | 448 | [Find All Numbers Disappeared in an Array](https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FindAllNumbersDisappearedInAnArray.java) | | 453 | [Minimum Moves to Equal Array Elements](https://leetcode.com/problems/minimum-moves-to-equal-array-elements) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MinimumMovesToEqualArrayElements.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/minimum_moves_to_equal_array_element.py) | diff --git a/python/string_compression.py b/python/string_compression.py new file mode 100644 index 0000000..aea332e --- /dev/null +++ b/python/string_compression.py @@ -0,0 +1,27 @@ +from typing import List +from collections import deque + + +class Solution: + def compress(self, chars: List[str]) -> int: + compressed_strings = deque() + current_char, count,length = chars[0], 0, 0 + for character in chars: + if character == current_char: + count += 1 + else: + compressed_strings.append((current_char, str(count))) + length += 1 + (len(str(count)) if count > 1 else 0) + current_char = character + count = 1 + compressed_strings.append((current_char, str(count))) + length += 1 + (len(str(count)) if count > 1 else 0) + + i = 0 + for compressed_string in compressed_strings: + character, count = compressed_string + chars[i] = character + if int(count) > 1: + chars[i + 1:i + 1 + len(count)] = count + i += 1 + (len(count) if int(count) > 1 else 0) + return length From f487dfc27f52a5f3b12f0a1d4b9de24b5cba4179 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 1 Jul 2021 11:24:36 +0530 Subject: [PATCH 099/947] solves number of boomerangs in python --- README.md | 2 +- python/number_of_boomerangs.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 python/number_of_boomerangs.py diff --git a/README.md b/README.md index a64bafc..6ca01e4 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,7 @@ | 434 | [Number of Segments in a String](https://leetcode.com/problems/number-of-segments-in-a-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/NumberOfSegmentsInString.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/number_of_segments_in_a_string.py) | | 441 | [Arranging Coins](https://leetcode.com/problems/arranging-coins) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ArrangingCoins.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/arranging_coins.py) | | 443 | [String Compression](https://leetcode.com/problems/string-compression) | Medium | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/StringCompression.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/string_compression.py) | -| 447 | [Number of Boomerangs](https://leetcode.com/problems/number-of-boomerangs) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/NumberOfBoomerangs.java) | +| 447 | [Number of Boomerangs](https://leetcode.com/problems/number-of-boomerangs) | Medium | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/NumberOfBoomerangs.java) [![Python](https://img.icons8.com/color/35/000000/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) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FindAllNumbersDisappearedInAnArray.java) | | 453 | [Minimum Moves to Equal Array Elements](https://leetcode.com/problems/minimum-moves-to-equal-array-elements) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MinimumMovesToEqualArrayElements.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/minimum_moves_to_equal_array_element.py) | | 455 | [Assign Cookies](https://leetcode.com/problems/assign-cookies) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/AssignCookies.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/assign_cookies.py)| diff --git a/python/number_of_boomerangs.py b/python/number_of_boomerangs.py new file mode 100644 index 0000000..4e716b1 --- /dev/null +++ b/python/number_of_boomerangs.py @@ -0,0 +1,20 @@ +from typing import List + + +class Solution: + def get_distance(self, p1: List[int], p2: List[int]) -> int: + x1, y1 = p1 + x2, y2 = p2 + dx, dy = x2 - x1, y2 - y1 + return dx ** 2 + dy ** 2 + + def numberOfBoomerangs(self, points: List[List[int]]) -> int: + result = 0 + for p1 in points: + distance_frequency = {} + for p2 in points: + distance = self.get_distance(p1, p2) + distance_frequency[distance] = distance_frequency.get(distance, 0) + 1 + for frequency in distance_frequency.values(): + result += frequency * (frequency - 1) + return result From f2531815624c3625b0eff7f9ef676cf8417f04b5 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 1 Jul 2021 11:32:12 +0530 Subject: [PATCH 100/947] solves find all numbers tha disappeared in array --- README.md | 2 +- python/find_all_numbers_disappeared_in_an_array.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 python/find_all_numbers_disappeared_in_an_array.py diff --git a/README.md b/README.md index 6ca01e4..1ce6ec9 100644 --- a/README.md +++ b/README.md @@ -119,7 +119,7 @@ | 441 | [Arranging Coins](https://leetcode.com/problems/arranging-coins) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ArrangingCoins.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/arranging_coins.py) | | 443 | [String Compression](https://leetcode.com/problems/string-compression) | Medium | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/StringCompression.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/string_compression.py) | | 447 | [Number of Boomerangs](https://leetcode.com/problems/number-of-boomerangs) | Medium | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/NumberOfBoomerangs.java) [![Python](https://img.icons8.com/color/35/000000/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) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FindAllNumbersDisappearedInAnArray.java) | +| 448 | [Find All Numbers Disappeared in an Array](https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FindAllNumbersDisappearedInAnArray.java) [![Python](https://img.icons8.com/color/35/000000/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) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MinimumMovesToEqualArrayElements.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/minimum_moves_to_equal_array_element.py) | | 455 | [Assign Cookies](https://leetcode.com/problems/assign-cookies) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/AssignCookies.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/assign_cookies.py)| | 459 | [Repeated Substring Pattern](https://leetcode.com/problems/repeated-substring-pattern) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RepeatedSubstringPattern.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/repeated_substring_pattern.py) | diff --git a/python/find_all_numbers_disappeared_in_an_array.py b/python/find_all_numbers_disappeared_in_an_array.py new file mode 100644 index 0000000..1c5970f --- /dev/null +++ b/python/find_all_numbers_disappeared_in_an_array.py @@ -0,0 +1,11 @@ +from typing import List + + +class Solution: + def findDisappearedNumbers(self, nums: List[int]) -> List[int]: + numbers = set(nums) + result = [] + for number in range(1, len(nums) + 1): + if number not in numbers: + result.append(number) + return result From 9a2f8b5b7c4f9205744fa94328323815520422a8 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 4 Jul 2021 14:21:49 +0530 Subject: [PATCH 101/947] solves heaters --- README.md | 8 ++++---- python/heaters.py | 24 ++++++++++++++++++++++++ src/Heaters.java | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 python/heaters.py create mode 100644 src/Heaters.java diff --git a/README.md b/README.md index 1ce6ec9..5100c95 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-107/571-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-107/1571-1abc9c.svg) -![problems-solved-python](https://img.shields.io/badge/Python-32/1571-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-108/571-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-108/1571-1abc9c.svg) +![problems-solved-python](https://img.shields.io/badge/Python-108/1571-1abc9c.svg) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md) 🔒 = Subscription Content @@ -125,7 +125,7 @@ | 459 | [Repeated Substring Pattern](https://leetcode.com/problems/repeated-substring-pattern) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RepeatedSubstringPattern.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/repeated_substring_pattern.py) | | 461 | [Hamming Distance](https://leetcode.com/problems/hamming-distance) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/HammingDistance.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/hamming_distance.py) | | 463 | [Island Perimeter](https://leetcode.com/problems/island-perimeter) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/IslandPerimeter.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/island_perimeter.py) | -| 475 | [Heaters](https://leetcode.com/problems/heaters) | Medium | | +| 475 | [Heaters](https://leetcode.com/problems/heaters) | Medium | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/Heaters.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/heaters.py) | | 476 | [Number Complement](https://leetcode.com/problems/number-complement) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/NumberComplement.java) | | 482 | [License Key Formatting](https://leetcode.com/problems/license-key-formatting) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/LicenseKeyFormatting.java) | | 485 | [Max Consecutive Ones](https://leetcode.com/problems/max-consecutive-ones) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MaxConsecutiveOnes.java) | diff --git a/python/heaters.py b/python/heaters.py new file mode 100644 index 0000000..0086221 --- /dev/null +++ b/python/heaters.py @@ -0,0 +1,24 @@ +from typing import List + + +class Solution: + def binary_search(self, array: List[int], element: int) -> int: + left, right = 0, len(array) - 1 + while left <= right: + middle = (left + right) // 2 + if array[middle] == element: return middle + elif array[middle] < element: left = middle + 1 + else: right = middle - 1 + return left + + def findRadius(self, houses: List[int], heaters: List[int]) -> int: + heaters.sort() + minRadius, infinity = 0, float('inf') + for house in houses: + index = self.binary_search(heaters, house) + if index < len(heaters) and house == heaters[index]: + continue + leftRadius = infinity if index == 0 else house - heaters[index - 1] + rightRadius = infinity if index == len(heaters) else heaters[index] - house + minRadius = max(minRadius, min(leftRadius, rightRadius)) + return minRadius diff --git a/src/Heaters.java b/src/Heaters.java new file mode 100644 index 0000000..451abcc --- /dev/null +++ b/src/Heaters.java @@ -0,0 +1,33 @@ +import java.util.Arrays; + +public class Heaters { + private static int binarySearch(int[] array, int element) { + int left = 0, right = array.length - 1, middle; + while (left <= right) { + middle = (left + right) / 2; + if (array[middle] == element) return middle; + else if (array[middle] < element) left = middle + 1; + else right = middle - 1; + } + return left; + } + + public static void main(String[] args) { + System.out.println(findRadius(new int[] {1, 2, 3, 4}, new int[] {1, 4})); + } + + public static int findRadius(int[] houses, int[] heaters) { + Arrays.sort(heaters); + int minRadius = 0, leftRadius, rightRadius; + for (int house : houses) { + int index = binarySearch(heaters, house); + if (index < heaters.length && house == heaters[index]) { + continue; + } + leftRadius = index > 0 ? house - heaters[index - 1] : Integer.MAX_VALUE; + rightRadius = (index == heaters.length ? Integer.MAX_VALUE : heaters[index] - house); + minRadius = Math.max(minRadius, Math.min(leftRadius, rightRadius)); + } + return minRadius; + } +} From ed23dc5281027bc05be4620a3e08eeec41c1684b Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 4 Jul 2021 18:08:40 +0530 Subject: [PATCH 102/947] solves number complemet --- README.md | 2 +- python/number_complement.py | 12 ++++++++++++ src/NumberComplement.java | 5 ++--- 3 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 python/number_complement.py diff --git a/README.md b/README.md index 5100c95..c80b366 100644 --- a/README.md +++ b/README.md @@ -126,7 +126,7 @@ | 461 | [Hamming Distance](https://leetcode.com/problems/hamming-distance) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/HammingDistance.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/hamming_distance.py) | | 463 | [Island Perimeter](https://leetcode.com/problems/island-perimeter) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/IslandPerimeter.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/island_perimeter.py) | | 475 | [Heaters](https://leetcode.com/problems/heaters) | Medium | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/Heaters.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/heaters.py) | -| 476 | [Number Complement](https://leetcode.com/problems/number-complement) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/NumberComplement.java) | +| 476 | [Number Complement](https://leetcode.com/problems/number-complement) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/NumberComplement.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/number_complement.py) | | 482 | [License Key Formatting](https://leetcode.com/problems/license-key-formatting) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/LicenseKeyFormatting.java) | | 485 | [Max Consecutive Ones](https://leetcode.com/problems/max-consecutive-ones) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MaxConsecutiveOnes.java) | | 492 | [Construct the Rectangle](https://leetcode.com/problems/construct-the-rectangle) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ConstructTheRectangle.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/construct_the_rectangle.py) | diff --git a/python/number_complement.py b/python/number_complement.py new file mode 100644 index 0000000..1e7ad0a --- /dev/null +++ b/python/number_complement.py @@ -0,0 +1,12 @@ +class Solution: + def highest_one_bit(self, i: int) -> int: + i |= (i >> 1) + i |= (i >> 2) + i |= (i >> 4) + i |= (i >> 8) + i |= (i >> 16) + return i - (i >> 1) + + def findComplement(self, number: int) -> int: + return ~number & (self.highest_one_bit(number) - 1) + diff --git a/src/NumberComplement.java b/src/NumberComplement.java index ba81197..212dc51 100644 --- a/src/NumberComplement.java +++ b/src/NumberComplement.java @@ -1,6 +1,5 @@ public class NumberComplement { - public static int findComplement(int n) { - int numberOfBits = (int) (Math.floor(Math.log(n) / Math.log(2))) + 1; - return ((1 << numberOfBits) - 1) ^ n; + public static int findComplement(int number) { + return ~number & (Integer.highestOneBit(number) - 1); } } From 168c9064a84ad6487728656dcb8a2d53aaea16d6 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 4 Jul 2021 18:41:44 +0530 Subject: [PATCH 103/947] solves license plate formatting in python --- README.md | 2 +- python/license_key_formatting.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 python/license_key_formatting.py diff --git a/README.md b/README.md index c80b366..fdfe105 100644 --- a/README.md +++ b/README.md @@ -127,7 +127,7 @@ | 463 | [Island Perimeter](https://leetcode.com/problems/island-perimeter) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/IslandPerimeter.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/island_perimeter.py) | | 475 | [Heaters](https://leetcode.com/problems/heaters) | Medium | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/Heaters.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/heaters.py) | | 476 | [Number Complement](https://leetcode.com/problems/number-complement) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/NumberComplement.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/number_complement.py) | -| 482 | [License Key Formatting](https://leetcode.com/problems/license-key-formatting) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/LicenseKeyFormatting.java) | +| 482 | [License Key Formatting](https://leetcode.com/problems/license-key-formatting) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/LicenseKeyFormatting.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/license_key_formatting.py) | | 485 | [Max Consecutive Ones](https://leetcode.com/problems/max-consecutive-ones) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MaxConsecutiveOnes.java) | | 492 | [Construct the Rectangle](https://leetcode.com/problems/construct-the-rectangle) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ConstructTheRectangle.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/construct_the_rectangle.py) | | 496 | [Next Greater Element I](https://leetcode.com/problems/next-greater-element-i) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/NextGreaterElementI.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/next_greater_element_i.py) | diff --git a/python/license_key_formatting.py b/python/license_key_formatting.py new file mode 100644 index 0000000..47a94bc --- /dev/null +++ b/python/license_key_formatting.py @@ -0,0 +1,4 @@ +class Solution: + def licenseKeyFormatting(self, s: str, k: int) -> str: + s = s.replace('-', '').upper()[::-1] + return '-'.join(s[i:i + k] for i in range(0, len(s), k))[::-1] From 849579bd1b3d2b5cd5728bc4c853bb90997dcd0c Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 4 Jul 2021 18:46:31 +0530 Subject: [PATCH 104/947] solves max consecutive ones --- README.md | 2 +- python/max_consecutive_ones.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 python/max_consecutive_ones.py diff --git a/README.md b/README.md index fdfe105..ae41851 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,7 @@ | 475 | [Heaters](https://leetcode.com/problems/heaters) | Medium | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/Heaters.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/heaters.py) | | 476 | [Number Complement](https://leetcode.com/problems/number-complement) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/NumberComplement.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/number_complement.py) | | 482 | [License Key Formatting](https://leetcode.com/problems/license-key-formatting) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/LicenseKeyFormatting.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/license_key_formatting.py) | -| 485 | [Max Consecutive Ones](https://leetcode.com/problems/max-consecutive-ones) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MaxConsecutiveOnes.java) | +| 485 | [Max Consecutive Ones](https://leetcode.com/problems/max-consecutive-ones) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MaxConsecutiveOnes.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/max_consecutive_ones.py) | | 492 | [Construct the Rectangle](https://leetcode.com/problems/construct-the-rectangle) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ConstructTheRectangle.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/construct_the_rectangle.py) | | 496 | [Next Greater Element I](https://leetcode.com/problems/next-greater-element-i) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/NextGreaterElementI.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/next_greater_element_i.py) | | 500 | [Keyboard Row](https://leetcode.com/problems/keyboard-row) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/KeyBoardRow.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/keyboard_row.py) | diff --git a/python/max_consecutive_ones.py b/python/max_consecutive_ones.py new file mode 100644 index 0000000..4424606 --- /dev/null +++ b/python/max_consecutive_ones.py @@ -0,0 +1,14 @@ +from typing import List + + +class Solution: + def findMaxConsecutiveOnes(self, nums: List[int]) -> int: + max_ones, current = 0, 0 + for number in nums: + if number == 1: + current += 1 + else: + max_ones = max(max_ones, current) + current = 0 + max_ones = max(max_ones, current) + return max_ones From 43916120dda9427a6b04a1c79078ede53dc6d00a Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 4 Jul 2021 19:31:36 +0530 Subject: [PATCH 105/947] solves mode in bst --- README.md | 8 +-- python/find_mode_in_binary_search_tree.py | 37 ++++++++++++++ src/FindModeInBinarySearchTree.java | 62 ++++++++++++++++++++++- 3 files changed, 102 insertions(+), 5 deletions(-) create mode 100644 python/find_mode_in_binary_search_tree.py diff --git a/README.md b/README.md index ae41851..c38565f 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-108/571-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-108/1571-1abc9c.svg) -![problems-solved-python](https://img.shields.io/badge/Python-108/1571-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-109/571-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-109/1571-1abc9c.svg) +![problems-solved-python](https://img.shields.io/badge/Python-109/1571-1abc9c.svg) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md) 🔒 = Subscription Content @@ -132,7 +132,7 @@ | 492 | [Construct the Rectangle](https://leetcode.com/problems/construct-the-rectangle) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ConstructTheRectangle.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/construct_the_rectangle.py) | | 496 | [Next Greater Element I](https://leetcode.com/problems/next-greater-element-i) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/NextGreaterElementI.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/next_greater_element_i.py) | | 500 | [Keyboard Row](https://leetcode.com/problems/keyboard-row) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/KeyBoardRow.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/keyboard_row.py) | -| 501 | [Find Mode in Binary Search Tree](https://leetcode.com/problems/find-mode-in-binary-search-tree) | Easy | | +| 501 | [Find Mode in Binary Search Tree](https://leetcode.com/problems/find-mode-in-binary-search-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FindModeInBinarySearchTree) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/find_mode_in_binary_search_tree.py) | | 504 | [Base 7](https://leetcode.com/problems/base-7) | Easy | | | 506 | [Relative Ranks](https://leetcode.com/problems/relative-ranks) | Easy | | | 507 | [Perfect Number](https://leetcode.com/problems/perfect-number) | Easy | | diff --git a/python/find_mode_in_binary_search_tree.py b/python/find_mode_in_binary_search_tree.py new file mode 100644 index 0000000..a1ad6ab --- /dev/null +++ b/python/find_mode_in_binary_search_tree.py @@ -0,0 +1,37 @@ +# Definition for a binary tree node. +from typing import List + + +class TreeNode: + def __init__(self, val=0, left=None, right=None): + self.val = val + self.left = left + self.right = right + + +class Solution: + def __init__(self): + self.count = 1 + self.previous = None + self.max = 0 + + def find_mode(self, root: TreeNode, modes: List[int]): + if root is None: + return + self.find_mode(root.left, modes) + if self.previous: + self.count = self.count + 1 if root.val == self.previous.val else 1 + if self.count > self.max: + self.max = self.count + modes.clear() + modes.append(root.val) + elif self.count == self.max: + modes.append(root.val) + self.previous = root + self.find_mode(root.right, modes) + + def findMode(self, root: TreeNode) -> List[int]: + if root is None: return [] + result = [] + self.find_mode(root, result) + return result diff --git a/src/FindModeInBinarySearchTree.java b/src/FindModeInBinarySearchTree.java index 0a8ee15..8e91197 100644 --- a/src/FindModeInBinarySearchTree.java +++ b/src/FindModeInBinarySearchTree.java @@ -1,3 +1,63 @@ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + public class FindModeInBinarySearchTree { - + static class TreeNode { + int val; + TreeNode left; + TreeNode right; + TreeNode() {} + TreeNode(int val) { this.val = val; } + TreeNode(int val, TreeNode left, TreeNode right) { + this.val = val; + this.left = left; + this.right = right; + } + } + + private static TreeNode previous; + private static int count = 1; + private static int mode = 0; + + public static int[] findMode(TreeNode root) { + if (root == null) { + return new int[0]; + } + + List modes = new ArrayList<>(); + findMode(root, modes); + int[] result = new int[modes.size()]; + for(int index = 0 ; index < modes.size() ; index++) { + result[index] = modes.get(index); + } + previous = null; + count = 1; + mode = 0; + return result; + } + + private static void findMode(TreeNode root, List modes) { + if (root == null) { + return; + } + findMode(root.left, modes); + if (previous != null) { + count = root.val == previous.val ? count + 1 : 1; + } + if (count > mode) { + mode = count; + modes.clear(); + modes.add(root.val); + } else if (count == mode) { + modes.add(root.val); + } + previous = root; + findMode(root.right, modes); + } + + public static void main(String[] args) { + TreeNode root = new TreeNode(0); + System.out.println(Arrays.toString(findMode(root))); + } } From 9fe8bb13bbc002c3a55c724a6bd73162c4b4a5af Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 4 Jul 2021 19:43:39 +0530 Subject: [PATCH 106/947] solves base 7 --- README.md | 4 ++-- python/base_7.py | 11 +++++++++++ src/Base7.java | 19 +++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 python/base_7.py create mode 100644 src/Base7.java diff --git a/README.md b/README.md index c38565f..7eed95c 100644 --- a/README.md +++ b/README.md @@ -132,8 +132,8 @@ | 492 | [Construct the Rectangle](https://leetcode.com/problems/construct-the-rectangle) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ConstructTheRectangle.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/construct_the_rectangle.py) | | 496 | [Next Greater Element I](https://leetcode.com/problems/next-greater-element-i) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/NextGreaterElementI.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/next_greater_element_i.py) | | 500 | [Keyboard Row](https://leetcode.com/problems/keyboard-row) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/KeyBoardRow.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/keyboard_row.py) | -| 501 | [Find Mode in Binary Search Tree](https://leetcode.com/problems/find-mode-in-binary-search-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FindModeInBinarySearchTree) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/find_mode_in_binary_search_tree.py) | -| 504 | [Base 7](https://leetcode.com/problems/base-7) | Easy | | +| 501 | [Find Mode in Binary Search Tree](https://leetcode.com/problems/find-mode-in-binary-search-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FindModeInBinarySearchTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/find_mode_in_binary_search_tree.py) | +| 504 | [Base 7](https://leetcode.com/problems/base-7) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/Base7.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/base_7.py) | | 506 | [Relative Ranks](https://leetcode.com/problems/relative-ranks) | Easy | | | 507 | [Perfect Number](https://leetcode.com/problems/perfect-number) | Easy | | | 509 | [Fibonacci Number](https://leetcode.com/problems/fibonacci-number) | Easy | | diff --git a/python/base_7.py b/python/base_7.py new file mode 100644 index 0000000..5a598ab --- /dev/null +++ b/python/base_7.py @@ -0,0 +1,11 @@ +class Solution: + def convertToBase7(self, num: int) -> str: + if num == 0: + return '0' + is_negative = num < 0 + num = -num if is_negative else num + result = '' + while num > 0: + result = str(num % 7) + result + num //= 7 + return ('-' if is_negative else '') + result diff --git a/src/Base7.java b/src/Base7.java new file mode 100644 index 0000000..a0428d6 --- /dev/null +++ b/src/Base7.java @@ -0,0 +1,19 @@ +public class Base7 { + public static String convertToBase7(int number) { + if (number == 0) return "0"; + StringBuilder result = new StringBuilder(); + boolean isNegative = number < 0; + if (isNegative) { + number *= -1; + } + while (number > 0) { + result.append(number % 7); + number /= 7; + } + return result.append(isNegative ? "-" : "").reverse().toString(); + } + + public static void main(String[] args) { + System.out.println(convertToBase7(-7)); + } +} From 72e88bea9c7245354ea0970e4956043bb5829570 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 5 Jul 2021 02:40:43 +0530 Subject: [PATCH 107/947] solves relative ranks in python --- README.md | 2 +- python/relative_ranks.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 python/relative_ranks.py diff --git a/README.md b/README.md index 7eed95c..9b5306f 100644 --- a/README.md +++ b/README.md @@ -134,7 +134,7 @@ | 500 | [Keyboard Row](https://leetcode.com/problems/keyboard-row) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/KeyBoardRow.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/keyboard_row.py) | | 501 | [Find Mode in Binary Search Tree](https://leetcode.com/problems/find-mode-in-binary-search-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FindModeInBinarySearchTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/find_mode_in_binary_search_tree.py) | | 504 | [Base 7](https://leetcode.com/problems/base-7) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/Base7.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/base_7.py) | -| 506 | [Relative Ranks](https://leetcode.com/problems/relative-ranks) | Easy | | +| 506 | [Relative Ranks](https://leetcode.com/problems/relative-ranks) | Easy | [![Python](https://img.icons8.com/color/35/000000/python.png)](python/relative_ranks.py) | | 507 | [Perfect Number](https://leetcode.com/problems/perfect-number) | Easy | | | 509 | [Fibonacci Number](https://leetcode.com/problems/fibonacci-number) | Easy | | | 520 | [Detect Capital](https://leetcode.com/problems/detect-capital) | Easy | | diff --git a/python/relative_ranks.py b/python/relative_ranks.py new file mode 100644 index 0000000..8908858 --- /dev/null +++ b/python/relative_ranks.py @@ -0,0 +1,20 @@ +from typing import List + + +class Solution: + def get_rank(self, position: int) -> str: + if position == 1: return 'Gold Medal' + if position == 2: return 'Silver Medal' + if position == 3: return 'Bronze Medal' + return str(position) + + def findRelativeRanks(self, score: List[int]) -> List[str]: + numbers = [(index, val) for index, val in enumerate(score)] + numbers.sort(key=lambda x: x[1], reverse=True) + value_to_index = {} + for index, (_, value) in enumerate(numbers): + value_to_index[value] = index + result = [''] * len(score) + for index, value in enumerate(score): + result[index] = self.get_rank(value_to_index[value] + 1) + return result From 1cc22b91e04fbc44ade5dbe68541e84cabaf8dac Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 11 Jul 2021 10:24:15 +0530 Subject: [PATCH 108/947] solvesrelative ranks --- README.md | 2 +- src/RelativeRanks.java | 66 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 src/RelativeRanks.java diff --git a/README.md b/README.md index 9b5306f..3b09d26 100644 --- a/README.md +++ b/README.md @@ -134,7 +134,7 @@ | 500 | [Keyboard Row](https://leetcode.com/problems/keyboard-row) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/KeyBoardRow.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/keyboard_row.py) | | 501 | [Find Mode in Binary Search Tree](https://leetcode.com/problems/find-mode-in-binary-search-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FindModeInBinarySearchTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/find_mode_in_binary_search_tree.py) | | 504 | [Base 7](https://leetcode.com/problems/base-7) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/Base7.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/base_7.py) | -| 506 | [Relative Ranks](https://leetcode.com/problems/relative-ranks) | Easy | [![Python](https://img.icons8.com/color/35/000000/python.png)](python/relative_ranks.py) | +| 506 | [Relative Ranks](https://leetcode.com/problems/relative-ranks) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RelativeRanks.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/relative_ranks.py) | | 507 | [Perfect Number](https://leetcode.com/problems/perfect-number) | Easy | | | 509 | [Fibonacci Number](https://leetcode.com/problems/fibonacci-number) | Easy | | | 520 | [Detect Capital](https://leetcode.com/problems/detect-capital) | Easy | | diff --git a/src/RelativeRanks.java b/src/RelativeRanks.java new file mode 100644 index 0000000..d1ee1ce --- /dev/null +++ b/src/RelativeRanks.java @@ -0,0 +1,66 @@ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class RelativeRanks { + static class Pair { + private final int index; + private final int value; + + Pair(int index, int value) { + this.index = index; + this.value = value; + } + + @Override + public String toString() { + return "Pair{" + + "index=" + index + + ", value=" + value + + '}'; + } + } + + private static List getValuesWithIndex(int[] array) { + List result = new ArrayList<>(); + for (int index = 0 ; index < array.length ; index++) { + result.add(new Pair(index, array[index])); + } + return result; + } + + private static Map getValueToIndexMap(List array) { + Map result = new HashMap<>(); + for (int index = 0 ; index < array.size() ; index++) { + result.put(array.get(index).value, index); + } + return result; + } + + private static String getRank(int position) { + switch (position) { + case 1: return "Gold Medal"; + case 2: return "Silver Medal"; + case 3: return "Bronze Medal"; + default: return position + ""; + } + } + + public static String[] findRelativeRanks(int[] score) { + List sortedScores = getValuesWithIndex(score); + sortedScores.sort(((o1, o2) -> Integer.compare(o2.value, o1.value))); + System.out.println(sortedScores); + Map value2index = getValueToIndexMap(sortedScores); + String[] result = new String[score.length]; + for (int index = 0 ; index < score.length ; index++) { + result[index] = getRank(value2index.get(score[index]) + 1); + } + return result; + } + + public static void main(String[] args) { + System.out.println(Arrays.toString(findRelativeRanks(new int[]{10, 3, 8, 9, 4}))); + } +} From c6e316e93b7d1d318f3b21a213e985e0343c65bb Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 11 Jul 2021 10:58:08 +0530 Subject: [PATCH 109/947] solves check perfect number --- README.md | 2 +- python/check_perfect_number.py | 10 ++++++++++ src/CheckPerfectNumber.java | 13 +++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 python/check_perfect_number.py create mode 100644 src/CheckPerfectNumber.java diff --git a/README.md b/README.md index 3b09d26..d24cd47 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,7 @@ | 501 | [Find Mode in Binary Search Tree](https://leetcode.com/problems/find-mode-in-binary-search-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FindModeInBinarySearchTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/find_mode_in_binary_search_tree.py) | | 504 | [Base 7](https://leetcode.com/problems/base-7) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/Base7.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/base_7.py) | | 506 | [Relative Ranks](https://leetcode.com/problems/relative-ranks) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RelativeRanks.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/relative_ranks.py) | -| 507 | [Perfect Number](https://leetcode.com/problems/perfect-number) | Easy | | +| 507 | [Perfect Number](https://leetcode.com/problems/perfect-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/CheckPerfectNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/check_perfect_number.py) | | 509 | [Fibonacci Number](https://leetcode.com/problems/fibonacci-number) | Easy | | | 520 | [Detect Capital](https://leetcode.com/problems/detect-capital) | Easy | | | 521 | [Longest Uncommon Subsequence I](https://leetcode.com/problems/longest-uncommon-subsequence-i) | Easy | | diff --git a/python/check_perfect_number.py b/python/check_perfect_number.py new file mode 100644 index 0000000..51d6a17 --- /dev/null +++ b/python/check_perfect_number.py @@ -0,0 +1,10 @@ +class Solution: + def checkPerfectNumber(self, num: int) -> bool: + if num == 1: return False + + divisior_sum, divisior = 0, 1 + while divisior * divisior <= num: + if num % divisior == 0: + divisior_sum += (divisior + num // divisior) + divisior += 1 + return divisior_sum == num diff --git a/src/CheckPerfectNumber.java b/src/CheckPerfectNumber.java new file mode 100644 index 0000000..113e4b1 --- /dev/null +++ b/src/CheckPerfectNumber.java @@ -0,0 +1,13 @@ +public class CheckPerfectNumber { + public boolean checkPerfectNumber(int number) { + if (number == 1) return false; + + int sum = 0; + for (int divisor = 2 ; divisor * divisor <= number ; divisor++) { + if (number % divisor == 0) { + sum += divisor + number / divisor; + } + } + return sum + 1 == number; + } +} From fbf6139c6a47389e3a7d52c7da9886b2bed4fb57 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 11 Jul 2021 10:59:08 +0530 Subject: [PATCH 110/947] solves check perfect number --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d24cd47..a8e5088 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-109/571-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-109/1571-1abc9c.svg) -![problems-solved-python](https://img.shields.io/badge/Python-109/1571-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-112/571-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-112/1571-1abc9c.svg) +![problems-solved-python](https://img.shields.io/badge/Python-112/1571-1abc9c.svg) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md) 🔒 = Subscription Content From c5606a7636a8f5a32866d652f788a000bfba376d Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 14 Jul 2021 01:09:05 +0530 Subject: [PATCH 111/947] updates two sum --- python/two_sum.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/python/two_sum.py b/python/two_sum.py index 3d229e4..31ff6da 100644 --- a/python/two_sum.py +++ b/python/two_sum.py @@ -6,14 +6,9 @@ def twoSum(self, nums: List[int], target: int) -> List[int]: # saving indices in a map for every corresponding number positions_map = {} for index, number in enumerate(nums): - positions = positions_map.get(number, []) - positions.append(index) - positions_map[number] = positions + positions_map[number] = index for index, number in enumerate(nums): required = target - number - if required in positions_map: - positions = positions_map[required] - for i in positions: - if i != index: - return [index, i] + if required in positions_map and positions_map[required] != index: + return [index, positions_map[required]] From f2efbd8ec3bbe827ccb4b6f297d129d00a954319 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 14 Jul 2021 10:33:46 +0530 Subject: [PATCH 112/947] solves reverse integer --- README.md | 2 +- src/ReverseInteger.java | 26 ++++++++++++-------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index a8e5088..2fb5b0b 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ | #Number | Name | Difficulty | Solution | Youtube | |:--------:|------|:----------:|:--------:|:----------------------:| | 1 | [Two Sum](https://leetcode.com/problems/two-sum/) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/TwoSum.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/two_sum.py) | -| 7 | [Reverse Integer](https://leetcode.com/problems/reverse-isnteger/) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ReverseInteger.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_integer.py) | +| 7 | [Reverse Integer](https://leetcode.com/problems/reverse-integer/) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ReverseInteger.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_integer.py) | | 9 | [PalindromeNumber](https://leetcode.com/problems/palindrome-number/) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PalindromeNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/palindrome_number.py) | | 13 | [Roman To Integer](https://leetcode.com/problems/roman-to-integer/) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RomanToInteger.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/roman_to_integer.py) | | 14 | [Longest Common Prefix](https://leetcode.com/problems/longest-common-prefix/) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/LongestCommonPrefix.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/longest_common_prefix.py) | diff --git a/src/ReverseInteger.java b/src/ReverseInteger.java index 7cf85cc..f7d00f0 100644 --- a/src/ReverseInteger.java +++ b/src/ReverseInteger.java @@ -3,22 +3,20 @@ import java.util.Scanner; public class ReverseInteger { - public static void main(String[] args) { - Scanner scanner = new Scanner(System.in); - int number = scanner.nextInt(); - System.out.println(reverse(number)); - } - - private static int reverse(int number) { - boolean isPositive = number >= 0; - StringBuilder accumulator = new StringBuilder(number + ""); + public int reverse(int x) { + int result = 0, next; + boolean isPositive = x >= 0; if (!isPositive) { - accumulator.replace(0, 1, ""); + x *= -1; } - try { - return Integer.parseInt(accumulator.reverse().insert(0, isPositive ? "" : "-").toString()); - } catch (NumberFormatException exception) { - return 0; + while (x > 0) { + next = 10 * result + x % 10; + if (((next - x % 10) / 10) != result) { + return 0; + } + result = next; + x /= 10; } + return isPositive ? result : -result; } } From 130dbc32e8e0580e7cbe4a96cdb99a7061cd4f20 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 17 Jul 2021 15:05:57 +0530 Subject: [PATCH 113/947] solves palindrome number --- python/longest_palindrome.py | 22 +++++++++------------- python/palindrome_number.py | 18 +++++++++++++++--- src/PalindromeNumber.java | 21 +++++++++------------ src/ReverseInteger.java | 8 ++------ 4 files changed, 35 insertions(+), 34 deletions(-) diff --git a/python/longest_palindrome.py b/python/longest_palindrome.py index 251ce24..41c66fb 100644 --- a/python/longest_palindrome.py +++ b/python/longest_palindrome.py @@ -1,14 +1,10 @@ class Solution: - def longestPalindrome(self, s: str) -> int: - character_frequency = {} - for character in s: - character_frequency[character] = character_frequency.get(character, 0) + 1 - length = 0 - had_odd_length = False - for frequency in character_frequency.values(): - if frequency % 2 == 0: - length += frequency - else: - length += frequency - 1 - had_odd_length = True - return length + int(had_odd_length) + def isPalindrome(self, number: int) -> bool: + if number == 0: return True + if number % 10 == 0 or number < 0: return False + + right = 0 + while number > right: + right = 10 * right + number % 10 + number //= 10 + return number == right or (number == right // 10) diff --git a/python/palindrome_number.py b/python/palindrome_number.py index 1d4feba..21e447c 100644 --- a/python/palindrome_number.py +++ b/python/palindrome_number.py @@ -1,7 +1,19 @@ +import math + + class Solution: def isPalindrome(self, number: int) -> bool: - number = str(number) - for i in range(len(number) // 2): - if number[i] != number[- (i + 1)]: + if number < 0: return False + if number == 0: return True + + length = math.floor(math.log(number, 10) + 1) + divisor = 10 ** (length - 1) + modulo = 1 + for i in range(length // 2): + left = (number // divisor) % 10 + right = (number % (10 * modulo)) // modulo + if left != right: return False + divisor //= 10 + modulo *= 10 return True diff --git a/src/PalindromeNumber.java b/src/PalindromeNumber.java index 6b34ce2..038431d 100644 --- a/src/PalindromeNumber.java +++ b/src/PalindromeNumber.java @@ -3,19 +3,16 @@ import java.util.Scanner; public class PalindromeNumber { - public static void main(String[] args) { - Scanner scanner = new Scanner(System.in); - int number = scanner.nextInt(); - System.out.println(isPalindrome(number)); - } - private static boolean isPalindrome(int number) { - String representation = number + ""; - for (int index = 0 ; index < representation.length() / 2 ; index++) { - if (representation.charAt(index) != representation.charAt(representation.length() - 1 - index)) { - return false; - } + public boolean isPalindrome(int number) { + if (number < 0 || (number % 10 == 0 && number != 0)) { + return false; + } + int reverse = 0; + while (number > reverse) { + reverse = 10 * reverse + number % 10; + number /= 10; } - return true; + return number == reverse || number == reverse / 10; } } diff --git a/src/ReverseInteger.java b/src/ReverseInteger.java index f7d00f0..db4ef00 100644 --- a/src/ReverseInteger.java +++ b/src/ReverseInteger.java @@ -1,17 +1,13 @@ // https://leetcode.com/problems/reverse-integer/ -import java.util.Scanner; - public class ReverseInteger { public int reverse(int x) { int result = 0, next; boolean isPositive = x >= 0; - if (!isPositive) { - x *= -1; - } + x = isPositive ? x : -x; while (x > 0) { next = 10 * result + x % 10; - if (((next - x % 10) / 10) != result) { + if (next / 10 != result) { return 0; } result = next; From 0cfc697cb6728120e33937fdd88115c7653149d9 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 17 Jul 2021 15:14:44 +0530 Subject: [PATCH 114/947] adds java and python logo --- README.md | 2 +- assets/java.png | Bin 0 -> 1547 bytes assets/python.png | Bin 0 -> 879 bytes 3 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 assets/java.png create mode 100644 assets/python.png diff --git a/README.md b/README.md index 2fb5b0b..5552f40 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ ## Problems | #Number | Name | Difficulty | Solution | Youtube | |:--------:|------|:----------:|:--------:|:----------------------:| -| 1 | [Two Sum](https://leetcode.com/problems/two-sum/) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/TwoSum.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/two_sum.py) | +| 1 | [Two Sum](https://leetcode.com/problems/two-sum/) | Easy | [![Java](assets/java.png)](src/TwoSum.java) [![Python](assets/python.png)](python/two_sum.py) | | 7 | [Reverse Integer](https://leetcode.com/problems/reverse-integer/) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ReverseInteger.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_integer.py) | | 9 | [PalindromeNumber](https://leetcode.com/problems/palindrome-number/) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PalindromeNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/palindrome_number.py) | | 13 | [Roman To Integer](https://leetcode.com/problems/roman-to-integer/) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RomanToInteger.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/roman_to_integer.py) | diff --git a/assets/java.png b/assets/java.png new file mode 100644 index 0000000000000000000000000000000000000000..434661a5a418413b46b3988aa2664319a83ff2f9 GIT binary patch literal 1547 zcmV+m2K4!fP)+LPds(}FkW@IClA|0dmuFE3H zerN*oA2FTuhe~ELoiWj5cKgS;MP_6OE0i$(XR(=PStg5VZ*K>7B1MvkQ#T|`XhVBj zT6)`i%f0u!kAK{2gUaZSdlwSJH#s>u&w1bP^U3?3^FHr6a9g*vFpX~CyrdXDrWhtS zl0TzgEQZg=0;u8eB9teK;q|cqCY`D80@cOvDmvg)L+!(g{1D;YV)zvmF!4a`PKDP1 z$5;*)!_!j?6M)HvP2T~Y2aKSvl}1nfMnR?;Hh&i7A%HSl@{+`2)AR9_Lcuf~_9RX6 zXDWOnANosb+PkHsB=ZQ$Gr%eleYW(D6+e>BPItck1p#UsCV8UvRaJHZD4cg34O`bd z2igcEP}vcPp8VZHa}+ei$>W=Tpyc3yVOQOU#5IrS;U+|ExU9SXOd&ZI{F3OFEhUP4 zJAauq);wAsJ$)XP@8x69mUR^dR}kRjVp$9<1yJ-zY0n={PHx{=i4e-Q(BVSi3IYt& z^^E`@0w8n)1cuExa1{WR#=`Lm0F*YYqI&_1m8}4B`gBH+y}1T7Ohjt#yJdg?fr=IT zfv5_NW8r(30+c4r3%~~e#*y8(6i_-l-Rw2r4&a>E<7)e3wL8@6W<-`F8a0?VhuZ7^44~Ur`=`>u zwSn%F?@l(<9tGYDbpP@B8H1L7Z-_)IDti!8h<-o*a^$U|09JnO#By=6XMsC%5$zD8 z`y}H{WPRytS@9(SO4I2j>ob>^m77Gx?|tj7D%HSBglT`7ckiVa>rz#%(RcZ&vryR*ix}mog^rO!;paZ8T}A8LcRN}2$2;o(quecPjW$?ox`5;HL*Z>j2MjgG zehqvn-}#@ayoZoLS*(Ibl%)u($(2Ei@>1Lco~FGfQ_<8@?TGXPla8YgUOpJPFk8NP z?`F*OwOzKvzZ=VTg?kacK%Q1|=d8f{3U3M8YmM_d?KPQDYwsF$IiSh`@!6kTzV4a4 znHIDkT+!IGXv!;3iOS!7i@nDZ)9xZClPxpWdv)Z<)J#6%cGwMk= zD=N|o+yh)tkynhmU5a@OSOYw)3Nv$@8y`hDE6OnyH~!zAp_bUU;_dbO<}#W$9l@&R z*e-=%Px0}gdO9DU z^&@K5XK-0l^f7D9k5SfM7ycV?PL+!yItV7AN@~VbG$>H1P^rjTgKkvt0RzB(f57+C zOE1=?mNoURbjAJj$e{;%7Yvw_O0c=N#t|ZF^=^>QAgl+KPHvh}hFZ z%Oj^~6I=aMU&*zpbTi7=y`tL&+an_d0_N4y?=5#yfteDPzjiX&GOzXc(jLi*-!pz? z-{&X(r|-^RIid2ZIu&_T&|QjL5W}wc%k>}JEakkHnLGD%1=DFyEy5bCd=k+KQ5jI9 zDY1-;sJd24#Ar~(1V!~OU_<_JMLDK$Fn&0Ed@lJ4`?JudrfM*{5_L8xtOG4qOu3+? x2(DPYq9UWBdeK@vHF6~K{(Kke+xoxPzW~a6PxA@(CrtnV002ovPDHLkV1nN4^56gf literal 0 HcmV?d00001 diff --git a/assets/python.png b/assets/python.png new file mode 100644 index 0000000000000000000000000000000000000000..2bd7a0afffe642f0cdfac8dfcb8d1abc652f2d48 GIT binary patch literal 879 zcmV-#1CacQP)500006VoOIv0RI60 z0RN!9r;`8x10+dAK~z|U?U!4KO<@$rf9u=l;?hv#k`x})NRucpLzo$ZQH+vi@TN?O z#x;hLl9E9lBs{phC=cYxr7+Vl4ax(#UqT`t97KlcIA?#$!;G49&ffc+Ju{T@f7|Q& z+o!d@{T=wPe?Zdf%*OU2NKJ6i(HM;j`YkQIA>RI!ojdJcfpNApFT|Lwik1NpkC693 zligc&=#Rog8k;MvNK0XP+F z7B7Y5>ijSpZw@rE&XYi$MU8KhzG;=V#g59XpZ9wja|YPNI*$X(ynG>Ld6ZDZbGQU+ zmgV%$c-nq>46wA15Wm|!Lua`)t(VbX|^en z>1T2QjTCq;(2?!1@Kuz%Hkv-j?&`NJ7|?|3IG;Mjs+gWzl{vtMkwF71$_>{s_3Wv9 z8bqq?6frlx4|H>$m&)jtwM}BYR<~Qv+(AF)X>CoK>i9Z@3Xrk6Ei{5l3Btet5P*b8 z5RB?azf2>nam#BgA7j@M%DNMB0}DTx?`In_23S-d_#}3un`XCSV(UT53T_u9p(PN; zb-3k|`UOORN&NzXej<`Q5eUPcIgf#RzBR=3^&kXzg6KS%&gX1L&gZ~dS#OLsd-*&i zdJ4<=ym5vUuD+%sbuW8xePP%?`?_sxooS3Vh-wL7EPU{7qVfsHzVh_VNZs*k?4?kb z5^WoB8r9_mC)i|EDoGa_-XAm2Q#Vi+;jy;;52H5U|Dm%|kvtF5HA9JT7m$$GPV*w* zga&knUW-iuT>|o1>Tp9<4+kSBfNuf*VTh~%iV!^)u69TmDers>wjA^pem{}$5|LeW zB-e(8>Gc&~TL+KAaVLNs-eoWe((+QOI^XrS=70SY`UT=O2gopNBmn>b002ovPDHLk FV1kEfnQ;IB literal 0 HcmV?d00001 From 1c5229c58a35386bfc6685e785fd9d98013b229c Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 17 Jul 2021 15:17:09 +0530 Subject: [PATCH 115/947] adds java logo --- README.md | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 5552f40..445824f 100644 --- a/README.md +++ b/README.md @@ -11,25 +11,25 @@ | #Number | Name | Difficulty | Solution | Youtube | |:--------:|------|:----------:|:--------:|:----------------------:| | 1 | [Two Sum](https://leetcode.com/problems/two-sum/) | Easy | [![Java](assets/java.png)](src/TwoSum.java) [![Python](assets/python.png)](python/two_sum.py) | -| 7 | [Reverse Integer](https://leetcode.com/problems/reverse-integer/) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ReverseInteger.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_integer.py) | -| 9 | [PalindromeNumber](https://leetcode.com/problems/palindrome-number/) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PalindromeNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/palindrome_number.py) | -| 13 | [Roman To Integer](https://leetcode.com/problems/roman-to-integer/) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RomanToInteger.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/roman_to_integer.py) | -| 14 | [Longest Common Prefix](https://leetcode.com/problems/longest-common-prefix/) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/LongestCommonPrefix.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/longest_common_prefix.py) | -| 20 | [ValidParentheses](https://leetcode.com/problems/valid-parentheses/) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ValidParentheses.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/valid_parentheses.py) | -| 21 | [Merge 2 Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/Merge2SortedLists.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/merge_2_sorted_lists.py) | -| 26 | [Remove Duplicates From Sorted Array](https://leetcode.com/problems/remove-duplicates-from-sorted-array/) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RemoveDuplicatesFromSortedArray.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/remove_duplicates_from_sorted_array.py) | -| 27 | [Remove Element](https://leetcode.com/problems/remove-element/) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RemoveElement.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/remove_element.py)| -| 28 | [Needle in Haystack](https://leetcode.com/problems/implement-strstr) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/NeedleInHaystack.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/needle_in_haystack.py) | -| 35 | [Search Inserted Position](https://leetcode.com/problems/search-insert-position/) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/SearchInsertPosition.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/search_insert_position.py) | -| 38 | [Count and Say](https://leetcode.com/problems/count-and-say) | Medium | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/CountAndSay.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/count_and_say.py) | -| 53 | [Maximum SubArray](https://leetcode.com/problems/maximum-subarray) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MaximumSubArray.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/maximum_sum_subarray.py) | -| 58 | [Length of Last Word](https://leetcode.com/problems/length-of-last-word) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/LengthOfLastWord.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/length_of_last_word.py) | -| 66 | [Plus One](https://leetcode.com/problems/plus-one) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PlusOne.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/plus_one.py) | -| 67 | [Add Binary](https://leetcode.com/problems/add-binary) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/AddBinary.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/add_binary.py) | -| 69 | [Sqrt(x)](https://leetcode.com/problems/sqrtx) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/Sqrtx.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/sqrt.py) | -| 70 | [Climbing Stairs](https://leetcode.com/problems/climbing-stairs) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ClimbingStairs.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/climbing_stairs.py) | -| 83 | [Remove Duplicates from Sorted List](https://leetcode.com/problems/remove-duplicates-from-sorted-list) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RemoveDuplicatesFromSortedList.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/remove_duplicates_from_linked_list.py) | -| 88 | [Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MergeSortedArray.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/merge_sorted_array.py) | +| 7 | [Reverse Integer](https://leetcode.com/problems/reverse-integer/) | Easy | [![Java](assets/java.png)](src/ReverseInteger.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_integer.py) | +| 9 | [PalindromeNumber](https://leetcode.com/problems/palindrome-number/) | Easy | [![Java](assets/java.png)](src/PalindromeNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/palindrome_number.py) | +| 13 | [Roman To Integer](https://leetcode.com/problems/roman-to-integer/) | Easy | [![Java](assets/java.png)](src/RomanToInteger.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/roman_to_integer.py) | +| 14 | [Longest Common Prefix](https://leetcode.com/problems/longest-common-prefix/) | Easy | [![Java](assets/java.png)](src/LongestCommonPrefix.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/longest_common_prefix.py) | +| 20 | [ValidParentheses](https://leetcode.com/problems/valid-parentheses/) | Easy | [![Java](assets/java.png)](src/ValidParentheses.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/valid_parentheses.py) | +| 21 | [Merge 2 Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/) | Easy | [![Java](assets/java.png)](src/Merge2SortedLists.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/merge_2_sorted_lists.py) | +| 26 | [Remove Duplicates From Sorted Array](https://leetcode.com/problems/remove-duplicates-from-sorted-array/) | Easy | [![Java](assets/java.png)](src/RemoveDuplicatesFromSortedArray.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/remove_duplicates_from_sorted_array.py) | +| 27 | [Remove Element](https://leetcode.com/problems/remove-element/) | Easy | [![Java](assets/java.png)](src/RemoveElement.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/remove_element.py)| +| 28 | [Needle in Haystack](https://leetcode.com/problems/implement-strstr) | Easy | [![Java](assets/java.png)](src/NeedleInHaystack.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/needle_in_haystack.py) | +| 35 | [Search Inserted Position](https://leetcode.com/problems/search-insert-position/) | Easy | [![Java](assets/java.png)](src/SearchInsertPosition.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/search_insert_position.py) | +| 38 | [Count and Say](https://leetcode.com/problems/count-and-say) | Medium | [![Java](assets/java.png)](src/CountAndSay.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/count_and_say.py) | +| 53 | [Maximum SubArray](https://leetcode.com/problems/maximum-subarray) | Easy | [![Java](assets/java.png)](src/MaximumSubArray.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/maximum_sum_subarray.py) | +| 58 | [Length of Last Word](https://leetcode.com/problems/length-of-last-word) | Easy | [![Java](assets/java.png)](src/LengthOfLastWord.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/length_of_last_word.py) | +| 66 | [Plus One](https://leetcode.com/problems/plus-one) | Easy | [![Java](assets/java.png)](src/PlusOne.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/plus_one.py) | +| 67 | [Add Binary](https://leetcode.com/problems/add-binary) | Easy | [![Java](assets/java.png)](src/AddBinary.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/add_binary.py) | +| 69 | [Sqrt(x)](https://leetcode.com/problems/sqrtx) | Easy | [![Java](assets/java.png)](src/Sqrtx.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/sqrt.py) | +| 70 | [Climbing Stairs](https://leetcode.com/problems/climbing-stairs) | Easy | [![Java](assets/java.png)](src/ClimbingStairs.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/climbing_stairs.py) | +| 83 | [Remove Duplicates from Sorted List](https://leetcode.com/problems/remove-duplicates-from-sorted-list) | Easy | [![Java](assets/java.png)](src/RemoveDuplicatesFromSortedList.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/remove_duplicates_from_linked_list.py) | +| 88 | [Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array) | Easy | [![Java](assets/java.png)](src/MergeSortedArray.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/merge_sorted_array.py) | | 100 | [Same Tree](https://leetcode.com/problems/same-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/SameTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/same_tree.py) | | 101 | [Symmetric Tree](https://leetcode.com/problems/symmetric-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/SymmetricTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/symmetric_tree.py) | | 104 | [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MaximumDepthOfBinaryTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/maximum_depth_of_binary_tree.py) | From 7f6c4210fe3b15f65314926d358668995f1b4e67 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 17 Jul 2021 15:28:54 +0530 Subject: [PATCH 116/947] adds java logo --- README.md | 182 +++++++++++++++++++++++++++--------------------------- 1 file changed, 91 insertions(+), 91 deletions(-) diff --git a/README.md b/README.md index 445824f..2cb88f5 100644 --- a/README.md +++ b/README.md @@ -30,112 +30,112 @@ | 70 | [Climbing Stairs](https://leetcode.com/problems/climbing-stairs) | Easy | [![Java](assets/java.png)](src/ClimbingStairs.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/climbing_stairs.py) | | 83 | [Remove Duplicates from Sorted List](https://leetcode.com/problems/remove-duplicates-from-sorted-list) | Easy | [![Java](assets/java.png)](src/RemoveDuplicatesFromSortedList.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/remove_duplicates_from_linked_list.py) | | 88 | [Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array) | Easy | [![Java](assets/java.png)](src/MergeSortedArray.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/merge_sorted_array.py) | -| 100 | [Same Tree](https://leetcode.com/problems/same-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/SameTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/same_tree.py) | -| 101 | [Symmetric Tree](https://leetcode.com/problems/symmetric-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/SymmetricTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/symmetric_tree.py) | -| 104 | [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MaximumDepthOfBinaryTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/maximum_depth_of_binary_tree.py) | -| 107 | [Binary Tree Level Order Traversal II](https://leetcode.com/problems/binary-tree-level-order-traversal-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BinaryTreeLevelOrderTraversalII.java) [![Python](https://img.icons8.com/color/35/000000/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) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ConvertSortedArrayToBinarySearchTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/converted_sorted_array_to_binary_search_tree.py) | -| 110 | [Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BalancedBinaryTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/balanced_binary_tree.py) | -| 111 | [Minimum Depth of Binary Tree](https://leetcode.com/problems/minimum-depth-of-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MinimumDepthOfBinaryTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/minimum_depth_of_binary_tree.py) | -| 112 | [Path Sum](https://leetcode.com/problems/path-sum) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PathSum.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/path_sum.py) | -| 118 | [Pascal's Triangle](https://leetcode.com/problems/pascals-triangle) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PascalsTriangle.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/pascals_triangle.py) | -| 119 | [Pascal's Triangle II](https://leetcode.com/problems/pascals-triangle-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PascalsTriangleII.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/pascals_triangle_ii.py) | -| 121 | [Best Time to Buy and Sell Stocks](https://leetcode.com/problems/best-time-to-buy-and-sell-stock) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BestTimeToBuyAndSellStock.java) [![Python](https://img.icons8.com/color/35/000000/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) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BestTimeToBuyAndSellStockII.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/best_time_to_buy_and_sell_stock_ii.py) | -| 125 | [Valid Palindrome](https://leetcode.com/problems/valid-palindrome) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ValidPalindrome.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/valid_palindrome.py) | -| 136 | [Single Number](https://leetcode.com/problems/single-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/SingleNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/single_number.py) | -| 141 | [Linked List Cycle](https://leetcode.com/problems/linked-list-cycle) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/LinkedListCycle.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/linked_list_cycle.py) | -| 155 | [Min Stack](https://leetcode.com/problems/min-stack) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MinStack.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/min_stack.py) | +| 100 | [Same Tree](https://leetcode.com/problems/same-tree) | Easy | [![Java](assets/java.png)](src/SameTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/same_tree.py) | +| 101 | [Symmetric Tree](https://leetcode.com/problems/symmetric-tree) | Easy | [![Java](assets/java.png)](src/SymmetricTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/symmetric_tree.py) | +| 104 | [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree) | Easy | [![Java](assets/java.png)](src/MaximumDepthOfBinaryTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/maximum_depth_of_binary_tree.py) | +| 107 | [Binary Tree Level Order Traversal II](https://leetcode.com/problems/binary-tree-level-order-traversal-ii) | Easy | [![Java](assets/java.png)](src/BinaryTreeLevelOrderTraversalII.java) [![Python](https://img.icons8.com/color/35/000000/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) | Easy | [![Java](assets/java.png)](src/ConvertSortedArrayToBinarySearchTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/converted_sorted_array_to_binary_search_tree.py) | +| 110 | [Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree) | Easy | [![Java](assets/java.png)](src/BalancedBinaryTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/balanced_binary_tree.py) | +| 111 | [Minimum Depth of Binary Tree](https://leetcode.com/problems/minimum-depth-of-binary-tree) | Easy | [![Java](assets/java.png)](src/MinimumDepthOfBinaryTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/minimum_depth_of_binary_tree.py) | +| 112 | [Path Sum](https://leetcode.com/problems/path-sum) | Easy | [![Java](assets/java.png)](src/PathSum.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/path_sum.py) | +| 118 | [Pascal's Triangle](https://leetcode.com/problems/pascals-triangle) | Easy | [![Java](assets/java.png)](src/PascalsTriangle.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/pascals_triangle.py) | +| 119 | [Pascal's Triangle II](https://leetcode.com/problems/pascals-triangle-ii) | Easy | [![Java](assets/java.png)](src/PascalsTriangleII.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/pascals_triangle_ii.py) | +| 121 | [Best Time to Buy and Sell Stocks](https://leetcode.com/problems/best-time-to-buy-and-sell-stock) | Easy | [![Java](assets/java.png)](src/BestTimeToBuyAndSellStock.java) [![Python](https://img.icons8.com/color/35/000000/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) | Easy | [![Java](assets/java.png)](src/BestTimeToBuyAndSellStockII.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/best_time_to_buy_and_sell_stock_ii.py) | +| 125 | [Valid Palindrome](https://leetcode.com/problems/valid-palindrome) | Easy | [![Java](assets/java.png)](src/ValidPalindrome.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/valid_palindrome.py) | +| 136 | [Single Number](https://leetcode.com/problems/single-number) | Easy | [![Java](assets/java.png)](src/SingleNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/single_number.py) | +| 141 | [Linked List Cycle](https://leetcode.com/problems/linked-list-cycle) | Easy | [![Java](assets/java.png)](src/LinkedListCycle.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/linked_list_cycle.py) | +| 155 | [Min Stack](https://leetcode.com/problems/min-stack) | Easy | [![Java](assets/java.png)](src/MinStack.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/min_stack.py) | | 157 | [Read N Characters Given Read4](https://leetcode.com/problems/read-n-characters-given-read4) | Easy | | -| 160 | [Intersection of Two Linked Lists](https://leetcode.com/problems/intersection-of-two-linked-lists) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/IntersectionOf2LinkedLists.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/intersecction_of_two_linked_lists.py) | -| 167 | [Two Sum II - Input Array is Sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/TwoSumIIInputArrayIsSorted.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/two_sum_ii.py) | -| 168 | [Excel Sheet Column Title](https://leetcode.com/problems/excel-sheet-column-title) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ExcelSheetColumnTitle.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/excel_sheet_column_title.py) | -| 169 | [Majority Element](https://leetcode.com/problems/majority-element) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MajorityElement.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/majority_element.py) | +| 160 | [Intersection of Two Linked Lists](https://leetcode.com/problems/intersection-of-two-linked-lists) | Easy | [![Java](assets/java.png)](src/IntersectionOf2LinkedLists.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/intersecction_of_two_linked_lists.py) | +| 167 | [Two Sum II - Input Array is Sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted) | Easy | [![Java](assets/java.png)](src/TwoSumIIInputArrayIsSorted.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/two_sum_ii.py) | +| 168 | [Excel Sheet Column Title](https://leetcode.com/problems/excel-sheet-column-title) | Easy | [![Java](assets/java.png)](src/ExcelSheetColumnTitle.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/excel_sheet_column_title.py) | +| 169 | [Majority Element](https://leetcode.com/problems/majority-element) | Easy | [![Java](assets/java.png)](src/MajorityElement.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/majority_element.py) | | 170 | 🔒 [Two Sum III - Data Structure Design](https://leetcode.com/problems/two-sum-iii-data-structure-design) | Easy | | -| 171 | [Excel Sheet Column Number](https://leetcode.com/problems/excel-sheet-column-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ExcelSheetColumnNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/excel_sheet_column_number.py) | -| 172 | [Factoring Trailing Zeroes](https://leetcode.com/problems/factorial-trailing-zeroes) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FactorialTrailingZeros.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/factorial_trailing_zeroes.py) | -| 189 | [Rotate Array](https://leetcode.com/problems/rotate-array) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RotateArray.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/rotate_array.py) | -| 190 | [Reverse Bits](https://leetcode.com/problems/reverse-bits) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ReverseBits.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_bits.py) | -| 191 | [Number of One Bits](https://leetcode.com/problems/number-of-1-bits) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/NumberOf1Bit.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/number_of_1_bits.py) | -| 198 | [House Robber](https://leetcode.com/problems/house-robber) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/HouseRobber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/house_robber.py) | -| 202 | [Happy Number](https://leetcode.com/problems/happy-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/HappyNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/happy_number.py) | -| 203 | [Remove Linked List Elements](https://leetcode.com/problems/remove-linked-list-elements) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RemoveLinkedListElements.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/remove_linked_list_elements.py) | -| 204 | [Count Primes](https://leetcode.com/problems/count-primes) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/CountPrimes.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/count_primes.py) | -| 205 | [Isomorphic Strings](https://leetcode.com/problems/isomorphic-strings) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/IsomorphicStrings.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/isomorphic_strings.py) | -| 206 | [Reverse Linked Lists](https://leetcode.com/problems/reverse-linked-list) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ReverseLinkedList.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_linked_list.py) | -| 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ContainsDuplicate.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/contains_duplicate.py) | -| 219 | [Contains Duplicate II](https://leetcode.com/problems/contains-duplicate-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ContainsDuplicateII.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/contains_duplicate_ii.py) | -| 225 | [Implement Stack using Queues](https://leetcode.com/problems/implement-stack-using-queues) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MyStack.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/implement_stack_using_queues.py) | -| 226 | [Invert Binary Tree](https://leetcode.com/problems/invert-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/InvertBinaryTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/invert_binary_tree.py) | -| 231 | [Power of Two](https://leetcode.com/problems/power-of-two) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PowerOf2.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/is_power_of_2.py) | -| 232 | [Implement Queue Using Stacks](https://leetcode.com/problems/implement-queue-using-stacks) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MyQueue.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/implement_queue_using_stacks.py) | -| 234 | [Palindrome Linked Lists](https://leetcode.com/problems/palindrome-linked-list) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PalindromeLinkedList.java) [![Python](https://img.icons8.com/color/35/000000/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) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/LowestCommonAncestorOfBinarySearchTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/lowest_common_ancestor_of_bst.py) | -| 237 | [Delete a Node In A Linked List](https://leetcode.com/problems/delete-node-in-a-linked-list) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/DeleteANodeInLinkedList.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/delete_node_in_linked_list.py) | -| 242 | [Valid Anagram](https://leetcode.com/problems/valid-anagram) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ValidAnagram.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/delete_node_in_linked_list.py) | +| 171 | [Excel Sheet Column Number](https://leetcode.com/problems/excel-sheet-column-number) | Easy | [![Java](assets/java.png)](src/ExcelSheetColumnNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/excel_sheet_column_number.py) | +| 172 | [Factoring Trailing Zeroes](https://leetcode.com/problems/factorial-trailing-zeroes) | Easy | [![Java](assets/java.png)](src/FactorialTrailingZeros.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/factorial_trailing_zeroes.py) | +| 189 | [Rotate Array](https://leetcode.com/problems/rotate-array) | Easy | [![Java](assets/java.png)](src/RotateArray.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/rotate_array.py) | +| 190 | [Reverse Bits](https://leetcode.com/problems/reverse-bits) | Easy | [![Java](assets/java.png)](src/ReverseBits.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_bits.py) | +| 191 | [Number of One Bits](https://leetcode.com/problems/number-of-1-bits) | Easy | [![Java](assets/java.png)](src/NumberOf1Bit.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/number_of_1_bits.py) | +| 198 | [House Robber](https://leetcode.com/problems/house-robber) | Easy | [![Java](assets/java.png)](src/HouseRobber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/house_robber.py) | +| 202 | [Happy Number](https://leetcode.com/problems/happy-number) | Easy | [![Java](assets/java.png)](src/HappyNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/happy_number.py) | +| 203 | [Remove Linked List Elements](https://leetcode.com/problems/remove-linked-list-elements) | Easy | [![Java](assets/java.png)](src/RemoveLinkedListElements.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/remove_linked_list_elements.py) | +| 204 | [Count Primes](https://leetcode.com/problems/count-primes) | Easy | [![Java](assets/java.png)](src/CountPrimes.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/count_primes.py) | +| 205 | [Isomorphic Strings](https://leetcode.com/problems/isomorphic-strings) | Easy | [![Java](assets/java.png)](src/IsomorphicStrings.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/isomorphic_strings.py) | +| 206 | [Reverse Linked Lists](https://leetcode.com/problems/reverse-linked-list) | Easy | [![Java](assets/java.png)](src/ReverseLinkedList.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_linked_list.py) | +| 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate) | Easy | [![Java](assets/java.png)](src/ContainsDuplicate.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/contains_duplicate.py) | +| 219 | [Contains Duplicate II](https://leetcode.com/problems/contains-duplicate-ii) | Easy | [![Java](assets/java.png)](src/ContainsDuplicateII.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/contains_duplicate_ii.py) | +| 225 | [Implement Stack using Queues](https://leetcode.com/problems/implement-stack-using-queues) | Easy | [![Java](assets/java.png)](src/MyStack.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/implement_stack_using_queues.py) | +| 226 | [Invert Binary Tree](https://leetcode.com/problems/invert-binary-tree) | Easy | [![Java](assets/java.png)](src/InvertBinaryTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/invert_binary_tree.py) | +| 231 | [Power of Two](https://leetcode.com/problems/power-of-two) | Easy | [![Java](assets/java.png)](src/PowerOf2.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/is_power_of_2.py) | +| 232 | [Implement Queue Using Stacks](https://leetcode.com/problems/implement-queue-using-stacks) | Easy | [![Java](assets/java.png)](src/MyQueue.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/implement_queue_using_stacks.py) | +| 234 | [Palindrome Linked Lists](https://leetcode.com/problems/palindrome-linked-list) | Easy | [![Java](assets/java.png)](src/PalindromeLinkedList.java) [![Python](https://img.icons8.com/color/35/000000/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) | Easy | [![Java](assets/java.png)](src/LowestCommonAncestorOfBinarySearchTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/lowest_common_ancestor_of_bst.py) | +| 237 | [Delete a Node In A Linked List](https://leetcode.com/problems/delete-node-in-a-linked-list) | Easy | [![Java](assets/java.png)](src/DeleteANodeInLinkedList.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/delete_node_in_linked_list.py) | +| 242 | [Valid Anagram](https://leetcode.com/problems/valid-anagram) | Easy | [![Java](assets/java.png)](src/ValidAnagram.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/delete_node_in_linked_list.py) | | 243 | 🔒 [Shortest Word Distance](https://leetcode.com/problems/shortest-word-distance) | Easy | | | 246 | 🔒 [Strobogramatic Number](https://leetcode.com/problems/strobogrammatic-number) | Easy | | | 252 | 🔒 [Meeting Rooms](https://leetcode.com/problems/meeting-rooms) | Easy | | | 256 | 🔒 [Paint House](https://leetcode.com/problems/paint-house) | Easy | | -| 257 | [Binary Tree Paths](https://leetcode.com/problems/binary-tree-paths) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BinaryTreePaths.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/binary_tree_paths.py) | -| 258 | [Add Digits](https://leetcode.com/problems/add-digits) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/AddDigits.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/add_digits.py) | -| 263 | [Ugly Number](https://leetcode.com/problems/ugly-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/UglyNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/ugly_number.py) | +| 257 | [Binary Tree Paths](https://leetcode.com/problems/binary-tree-paths) | Easy | [![Java](assets/java.png)](src/BinaryTreePaths.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/binary_tree_paths.py) | +| 258 | [Add Digits](https://leetcode.com/problems/add-digits) | Easy | [![Java](assets/java.png)](src/AddDigits.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/add_digits.py) | +| 263 | [Ugly Number](https://leetcode.com/problems/ugly-number) | Easy | [![Java](assets/java.png)](src/UglyNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/ugly_number.py) | | 266 | 🔒 [Palindrome Permutation](https://leetcode.com/problems/palindrome-permutation) | Easy | | -| 268 | [Missing Number](https://leetcode.com/problems/missing-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MissingNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/missing_number.py) | +| 268 | [Missing Number](https://leetcode.com/problems/missing-number) | Easy | [![Java](assets/java.png)](src/MissingNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/missing_number.py) | | 270 | 🔒 [Closest Binary Search Tree Value](https://leetcode.com/problems/closest-binary-search-tree-value) | Easy | | | 276 | 🔒 [Paint Fence](https://leetcode.com/problems/paint-fence) | Easy | | -| 278 | [First Bad Version](https://leetcode.com/problems/first-bad-version) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FirstBadVersion.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/first_bad_version.py) | -| 283 | [Move Zeroes](https://leetcode.com/problems/move-zeroes) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MoveZeros.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/move_zeroes.py) | -| 290 | [Word Pattern](https://leetcode.com/problems/word-pattern) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/WordPattern.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/word_pattern.py) | -| 292 | [Nim Game](https://leetcode.com/problems/nim-game) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/NimGame.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/nim_game.py) | +| 278 | [First Bad Version](https://leetcode.com/problems/first-bad-version) | Easy | [![Java](assets/java.png)](src/FirstBadVersion.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/first_bad_version.py) | +| 283 | [Move Zeroes](https://leetcode.com/problems/move-zeroes) | Easy | [![Java](assets/java.png)](src/MoveZeros.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/move_zeroes.py) | +| 290 | [Word Pattern](https://leetcode.com/problems/word-pattern) | Easy | [![Java](assets/java.png)](src/WordPattern.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/word_pattern.py) | +| 292 | [Nim Game](https://leetcode.com/problems/nim-game) | Easy | [![Java](assets/java.png)](src/NimGame.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/nim_game.py) | | 293 | 🔒 [Flip Game](https://leetcode.com/problems/flip-game) | Easy | | -| 299 | [Bulls and Cows](https://leetcode.com/problems/bulls-and-cows) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BullsAndCows.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/bulls_and_cows.py) | -| 303 | [Range Sum Query - Immutable](https://leetcode.com/problems/range-sum-query-immutable) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RangeSumQueryImmutable.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/range_sum_query_immutable.py) | -| 326 | [Power of Three](https://leetcode.com/problems/power-of-three) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PowerOfThree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/power_of_three.py) | +| 299 | [Bulls and Cows](https://leetcode.com/problems/bulls-and-cows) | Easy | [![Java](assets/java.png)](src/BullsAndCows.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/bulls_and_cows.py) | +| 303 | [Range Sum Query - Immutable](https://leetcode.com/problems/range-sum-query-immutable) | Easy | [![Java](assets/java.png)](src/RangeSumQueryImmutable.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/range_sum_query_immutable.py) | +| 326 | [Power of Three](https://leetcode.com/problems/power-of-three) | Easy | [![Java](assets/java.png)](src/PowerOfThree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/power_of_three.py) | | 339 | 🔒 [Nested List Weight Sum](https://leetcode.com/problems/nested-list-weight-sum) | Easy | | -| 342 | [Power of Four](https://leetcode.com/problems/power-of-four) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PowerOf4.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/power_of_four.py) | -| 344 | [Reverse A String](https://leetcode.com/problems/reverse-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ReverseString.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_a_string.py) | -| 345 | [Reverse Vowels of A String](https://leetcode.com/problems/reverse-vowels-of-a-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ReverseVowelsOfString.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_vowels_of_a_string.py) | +| 342 | [Power of Four](https://leetcode.com/problems/power-of-four) | Easy | [![Java](assets/java.png)](src/PowerOf4.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/power_of_four.py) | +| 344 | [Reverse A String](https://leetcode.com/problems/reverse-string) | Easy | [![Java](assets/java.png)](src/ReverseString.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_a_string.py) | +| 345 | [Reverse Vowels of A String](https://leetcode.com/problems/reverse-vowels-of-a-string) | Easy | [![Java](assets/java.png)](src/ReverseVowelsOfString.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_vowels_of_a_string.py) | | 346 | 🔒 [Moving Average From Data Stream](https://leetcode.com/problems/moving-average-from-data-stream) | Easy | | -| 349 | [Intersection of 2 Arrays](https://leetcode.com/problems/intersection-of-two-arrays) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/IntersectionOfTwoArrays.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/intersection_of_2_array.py) | -| 350 | [Intersection of 2 Arrays II](https://leetcode.com/problems/intersection-of-two-arrays-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/IntersectionOfTwoArraysII.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/intersection_of_2_arrays_II.py) | +| 349 | [Intersection of 2 Arrays](https://leetcode.com/problems/intersection-of-two-arrays) | Easy | [![Java](assets/java.png)](src/IntersectionOfTwoArrays.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/intersection_of_2_array.py) | +| 350 | [Intersection of 2 Arrays II](https://leetcode.com/problems/intersection-of-two-arrays-ii) | Easy | [![Java](assets/java.png)](src/IntersectionOfTwoArraysII.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/intersection_of_2_arrays_II.py) | | 359 | 🔒 [Logger Rate Limiter](https://leetcode.com/problems/logger-rate-limiter) | Easy | | -| 367 | [Valid Perfect Square](https://leetcode.com/problems/valid-perfect-square) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/IsPerfectSquare.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/valid_perfect_square.py) | -| 374 | [Guess Number Higher or Lower](https://leetcode.com/problems/guess-number-higher-or-lower) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/GuessNumberHigherOrLower.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/guess_number_higher_or_lower.py) | -| 383 | [Ransom Note](https://leetcode.com/problems/ransom-note) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RansomNote.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/ransom_note.py) | -| 387 | [First Unique Character in String](https://leetcode.com/problems/first-unique-character-in-a-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FirstUniqueCharacter.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/first_unique_character_in_string.py) | -| 389 | [Find the Difference](https://leetcode.com/problems/find-the-difference) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FindTheDifference.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/find_the_difference.py) | -| 392 | [Is Subsequence](https://leetcode.com/problems/is-subsequence) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/IsSubsequence.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/is_subsequence.py) | -| 401 | [Binary Watch](https://leetcode.com/problems/binary-watch) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BinaryWatch.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/binary_watch.py) | -| 404 | [Sum of Left Leaves](https://leetcode.com/problems/sum-of-left-leaves) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/SumOfLeftLeaves.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/sum_of_left_leaves.py) | -| 405 | [Convert a Number to Hexadecimal](https://leetcode.com/problems/convert-a-number-to-hexadecimal) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ConvertNumberToHexadecimal.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/convert_a_number_to_hexadecimal.py) | +| 367 | [Valid Perfect Square](https://leetcode.com/problems/valid-perfect-square) | Easy | [![Java](assets/java.png)](src/IsPerfectSquare.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/valid_perfect_square.py) | +| 374 | [Guess Number Higher or Lower](https://leetcode.com/problems/guess-number-higher-or-lower) | Easy | [![Java](assets/java.png)](src/GuessNumberHigherOrLower.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/guess_number_higher_or_lower.py) | +| 383 | [Ransom Note](https://leetcode.com/problems/ransom-note) | Easy | [![Java](assets/java.png)](src/RansomNote.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/ransom_note.py) | +| 387 | [First Unique Character in String](https://leetcode.com/problems/first-unique-character-in-a-string) | Easy | [![Java](assets/java.png)](src/FirstUniqueCharacter.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/first_unique_character_in_string.py) | +| 389 | [Find the Difference](https://leetcode.com/problems/find-the-difference) | Easy | [![Java](assets/java.png)](src/FindTheDifference.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/find_the_difference.py) | +| 392 | [Is Subsequence](https://leetcode.com/problems/is-subsequence) | Easy | [![Java](assets/java.png)](src/IsSubsequence.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/is_subsequence.py) | +| 401 | [Binary Watch](https://leetcode.com/problems/binary-watch) | Easy | [![Java](assets/java.png)](src/BinaryWatch.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/binary_watch.py) | +| 404 | [Sum of Left Leaves](https://leetcode.com/problems/sum-of-left-leaves) | Easy | [![Java](assets/java.png)](src/SumOfLeftLeaves.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/sum_of_left_leaves.py) | +| 405 | [Convert a Number to Hexadecimal](https://leetcode.com/problems/convert-a-number-to-hexadecimal) | Easy | [![Java](assets/java.png)](src/ConvertNumberToHexadecimal.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/convert_a_number_to_hexadecimal.py) | | 408 | 🔒 [Valid Word Abbreviation](https://leetcode.com/problems/valid-word-abbreviation) | Easy | | -| 409 | [Longest Palindrome](https://leetcode.com/problems/longest-palindrome) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/LongestPalindrome.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/longest_palindrome.py) | -| 412 | [Fizz Buzz](https://leetcode.com/problems/fizz-buzz) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FizzBuzz.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/fizz_buzz.py) | -| 414 | [Third Maximum Number](https://leetcode.com/problems/third-maximum-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ThirdMaximumNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/fizz_buzz.py) | -| 415 | [Add Strings](https://leetcode.com/problems/add-strings) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/AddString.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/add_strings.py) | +| 409 | [Longest Palindrome](https://leetcode.com/problems/longest-palindrome) | Easy | [![Java](assets/java.png)](src/LongestPalindrome.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/longest_palindrome.py) | +| 412 | [Fizz Buzz](https://leetcode.com/problems/fizz-buzz) | Easy | [![Java](assets/java.png)](src/FizzBuzz.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/fizz_buzz.py) | +| 414 | [Third Maximum Number](https://leetcode.com/problems/third-maximum-number) | Easy | [![Java](assets/java.png)](src/ThirdMaximumNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/fizz_buzz.py) | +| 415 | [Add Strings](https://leetcode.com/problems/add-strings) | Easy | [![Java](assets/java.png)](src/AddString.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/add_strings.py) | | 422 | 🔒 [Valid Word Square](https://leetcode.com/problems/valid-word-square) | Easy | | -| 434 | [Number of Segments in a String](https://leetcode.com/problems/number-of-segments-in-a-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/NumberOfSegmentsInString.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/number_of_segments_in_a_string.py) | -| 441 | [Arranging Coins](https://leetcode.com/problems/arranging-coins) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ArrangingCoins.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/arranging_coins.py) | -| 443 | [String Compression](https://leetcode.com/problems/string-compression) | Medium | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/StringCompression.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/string_compression.py) | -| 447 | [Number of Boomerangs](https://leetcode.com/problems/number-of-boomerangs) | Medium | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/NumberOfBoomerangs.java) [![Python](https://img.icons8.com/color/35/000000/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) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FindAllNumbersDisappearedInAnArray.java) [![Python](https://img.icons8.com/color/35/000000/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) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MinimumMovesToEqualArrayElements.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/minimum_moves_to_equal_array_element.py) | -| 455 | [Assign Cookies](https://leetcode.com/problems/assign-cookies) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/AssignCookies.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/assign_cookies.py)| -| 459 | [Repeated Substring Pattern](https://leetcode.com/problems/repeated-substring-pattern) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RepeatedSubstringPattern.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/repeated_substring_pattern.py) | -| 461 | [Hamming Distance](https://leetcode.com/problems/hamming-distance) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/HammingDistance.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/hamming_distance.py) | -| 463 | [Island Perimeter](https://leetcode.com/problems/island-perimeter) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/IslandPerimeter.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/island_perimeter.py) | -| 475 | [Heaters](https://leetcode.com/problems/heaters) | Medium | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/Heaters.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/heaters.py) | -| 476 | [Number Complement](https://leetcode.com/problems/number-complement) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/NumberComplement.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/number_complement.py) | -| 482 | [License Key Formatting](https://leetcode.com/problems/license-key-formatting) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/LicenseKeyFormatting.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/license_key_formatting.py) | -| 485 | [Max Consecutive Ones](https://leetcode.com/problems/max-consecutive-ones) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MaxConsecutiveOnes.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/max_consecutive_ones.py) | -| 492 | [Construct the Rectangle](https://leetcode.com/problems/construct-the-rectangle) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ConstructTheRectangle.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/construct_the_rectangle.py) | -| 496 | [Next Greater Element I](https://leetcode.com/problems/next-greater-element-i) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/NextGreaterElementI.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/next_greater_element_i.py) | -| 500 | [Keyboard Row](https://leetcode.com/problems/keyboard-row) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/KeyBoardRow.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/keyboard_row.py) | -| 501 | [Find Mode in Binary Search Tree](https://leetcode.com/problems/find-mode-in-binary-search-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FindModeInBinarySearchTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/find_mode_in_binary_search_tree.py) | -| 504 | [Base 7](https://leetcode.com/problems/base-7) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/Base7.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/base_7.py) | -| 506 | [Relative Ranks](https://leetcode.com/problems/relative-ranks) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RelativeRanks.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/relative_ranks.py) | -| 507 | [Perfect Number](https://leetcode.com/problems/perfect-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/CheckPerfectNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/check_perfect_number.py) | +| 434 | [Number of Segments in a String](https://leetcode.com/problems/number-of-segments-in-a-string) | Easy | [![Java](assets/java.png)](src/NumberOfSegmentsInString.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/number_of_segments_in_a_string.py) | +| 441 | [Arranging Coins](https://leetcode.com/problems/arranging-coins) | Easy | [![Java](assets/java.png)](src/ArrangingCoins.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/arranging_coins.py) | +| 443 | [String Compression](https://leetcode.com/problems/string-compression) | Medium | [![Java](assets/java.png)](src/StringCompression.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/string_compression.py) | +| 447 | [Number of Boomerangs](https://leetcode.com/problems/number-of-boomerangs) | Medium | [![Java](assets/java.png)](src/NumberOfBoomerangs.java) [![Python](https://img.icons8.com/color/35/000000/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) | Easy | [![Java](assets/java.png)](src/FindAllNumbersDisappearedInAnArray.java) [![Python](https://img.icons8.com/color/35/000000/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) | Easy | [![Java](assets/java.png)](src/MinimumMovesToEqualArrayElements.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/minimum_moves_to_equal_array_element.py) | +| 455 | [Assign Cookies](https://leetcode.com/problems/assign-cookies) | Easy | [![Java](assets/java.png)](src/AssignCookies.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/assign_cookies.py)| +| 459 | [Repeated Substring Pattern](https://leetcode.com/problems/repeated-substring-pattern) | Easy | [![Java](assets/java.png)](src/RepeatedSubstringPattern.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/repeated_substring_pattern.py) | +| 461 | [Hamming Distance](https://leetcode.com/problems/hamming-distance) | Easy | [![Java](assets/java.png)](src/HammingDistance.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/hamming_distance.py) | +| 463 | [Island Perimeter](https://leetcode.com/problems/island-perimeter) | Easy | [![Java](assets/java.png)](src/IslandPerimeter.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/island_perimeter.py) | +| 475 | [Heaters](https://leetcode.com/problems/heaters) | Medium | [![Java](assets/java.png)](src/Heaters.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/heaters.py) | +| 476 | [Number Complement](https://leetcode.com/problems/number-complement) | Easy | [![Java](assets/java.png)](src/NumberComplement.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/number_complement.py) | +| 482 | [License Key Formatting](https://leetcode.com/problems/license-key-formatting) | Easy | [![Java](assets/java.png)](src/LicenseKeyFormatting.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/license_key_formatting.py) | +| 485 | [Max Consecutive Ones](https://leetcode.com/problems/max-consecutive-ones) | Easy | [![Java](assets/java.png)](src/MaxConsecutiveOnes.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/max_consecutive_ones.py) | +| 492 | [Construct the Rectangle](https://leetcode.com/problems/construct-the-rectangle) | Easy | [![Java](assets/java.png)](src/ConstructTheRectangle.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/construct_the_rectangle.py) | +| 496 | [Next Greater Element I](https://leetcode.com/problems/next-greater-element-i) | Easy | [![Java](assets/java.png)](src/NextGreaterElementI.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/next_greater_element_i.py) | +| 500 | [Keyboard Row](https://leetcode.com/problems/keyboard-row) | Easy | [![Java](assets/java.png)](src/KeyBoardRow.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/keyboard_row.py) | +| 501 | [Find Mode in Binary Search Tree](https://leetcode.com/problems/find-mode-in-binary-search-tree) | Easy | [![Java](assets/java.png)](src/FindModeInBinarySearchTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/find_mode_in_binary_search_tree.py) | +| 504 | [Base 7](https://leetcode.com/problems/base-7) | Easy | [![Java](assets/java.png)](src/Base7.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/base_7.py) | +| 506 | [Relative Ranks](https://leetcode.com/problems/relative-ranks) | Easy | [![Java](assets/java.png)](src/RelativeRanks.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/relative_ranks.py) | +| 507 | [Perfect Number](https://leetcode.com/problems/perfect-number) | Easy | [![Java](assets/java.png)](src/CheckPerfectNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/check_perfect_number.py) | | 509 | [Fibonacci Number](https://leetcode.com/problems/fibonacci-number) | Easy | | | 520 | [Detect Capital](https://leetcode.com/problems/detect-capital) | Easy | | | 521 | [Longest Uncommon Subsequence I](https://leetcode.com/problems/longest-uncommon-subsequence-i) | Easy | | From e18d67ed2473c0e9339182698682c5e114ffcf18 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 17 Jul 2021 15:34:39 +0530 Subject: [PATCH 117/947] replaces python logo with image --- CONTRIBUTING.md | 4 +- README.md | 222 ++++++++++++++++++++++++------------------------ 2 files changed, 113 insertions(+), 113 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4534a6d..577d22d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -32,8 +32,8 @@ For the icon link refer to the table below to obtain the link for a specific pro | Programming Language | Icon | Icon Link| |:--------------------:|:----:|:----:| -| Java | ![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png) | https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png | -| Python | ![Python](https://img.icons8.com/color/35/000000/python.png) | https://img.icons8.com/color/35/000000/python.png | +| Java | ![Java](assets/java.png) | assets/java.png | +| Python | ![Python](assets/python.png) | assets/python.png | | C | ![C](https://img.icons8.com/color/35/000000/c-programming.png) | https://img.icons8.com/color/35/000000/c-programming.png | | C++ | ![C++](https://img.icons8.com/color/35/000000/c-plus-plus-logo.png) | https://img.icons8.com/color/35/000000/c-plus-plus-logo.png | | C# | ![C#](https://img.icons8.com/color/35/000000/c-sharp-logo.png) | https://img.icons8.com/color/35/000000/c-sharp-logo.png | diff --git a/README.md b/README.md index 2cb88f5..a39051b 100644 --- a/README.md +++ b/README.md @@ -10,132 +10,132 @@ ## Problems | #Number | Name | Difficulty | Solution | Youtube | |:--------:|------|:----------:|:--------:|:----------------------:| -| 1 | [Two Sum](https://leetcode.com/problems/two-sum/) | Easy | [![Java](assets/java.png)](src/TwoSum.java) [![Python](assets/python.png)](python/two_sum.py) | -| 7 | [Reverse Integer](https://leetcode.com/problems/reverse-integer/) | Easy | [![Java](assets/java.png)](src/ReverseInteger.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_integer.py) | -| 9 | [PalindromeNumber](https://leetcode.com/problems/palindrome-number/) | Easy | [![Java](assets/java.png)](src/PalindromeNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/palindrome_number.py) | -| 13 | [Roman To Integer](https://leetcode.com/problems/roman-to-integer/) | Easy | [![Java](assets/java.png)](src/RomanToInteger.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/roman_to_integer.py) | -| 14 | [Longest Common Prefix](https://leetcode.com/problems/longest-common-prefix/) | Easy | [![Java](assets/java.png)](src/LongestCommonPrefix.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/longest_common_prefix.py) | -| 20 | [ValidParentheses](https://leetcode.com/problems/valid-parentheses/) | Easy | [![Java](assets/java.png)](src/ValidParentheses.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/valid_parentheses.py) | -| 21 | [Merge 2 Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/) | Easy | [![Java](assets/java.png)](src/Merge2SortedLists.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/merge_2_sorted_lists.py) | -| 26 | [Remove Duplicates From Sorted Array](https://leetcode.com/problems/remove-duplicates-from-sorted-array/) | Easy | [![Java](assets/java.png)](src/RemoveDuplicatesFromSortedArray.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/remove_duplicates_from_sorted_array.py) | -| 27 | [Remove Element](https://leetcode.com/problems/remove-element/) | Easy | [![Java](assets/java.png)](src/RemoveElement.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/remove_element.py)| -| 28 | [Needle in Haystack](https://leetcode.com/problems/implement-strstr) | Easy | [![Java](assets/java.png)](src/NeedleInHaystack.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/needle_in_haystack.py) | -| 35 | [Search Inserted Position](https://leetcode.com/problems/search-insert-position/) | Easy | [![Java](assets/java.png)](src/SearchInsertPosition.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/search_insert_position.py) | -| 38 | [Count and Say](https://leetcode.com/problems/count-and-say) | Medium | [![Java](assets/java.png)](src/CountAndSay.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/count_and_say.py) | -| 53 | [Maximum SubArray](https://leetcode.com/problems/maximum-subarray) | Easy | [![Java](assets/java.png)](src/MaximumSubArray.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/maximum_sum_subarray.py) | -| 58 | [Length of Last Word](https://leetcode.com/problems/length-of-last-word) | Easy | [![Java](assets/java.png)](src/LengthOfLastWord.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/length_of_last_word.py) | -| 66 | [Plus One](https://leetcode.com/problems/plus-one) | Easy | [![Java](assets/java.png)](src/PlusOne.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/plus_one.py) | -| 67 | [Add Binary](https://leetcode.com/problems/add-binary) | Easy | [![Java](assets/java.png)](src/AddBinary.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/add_binary.py) | -| 69 | [Sqrt(x)](https://leetcode.com/problems/sqrtx) | Easy | [![Java](assets/java.png)](src/Sqrtx.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/sqrt.py) | -| 70 | [Climbing Stairs](https://leetcode.com/problems/climbing-stairs) | Easy | [![Java](assets/java.png)](src/ClimbingStairs.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/climbing_stairs.py) | -| 83 | [Remove Duplicates from Sorted List](https://leetcode.com/problems/remove-duplicates-from-sorted-list) | Easy | [![Java](assets/java.png)](src/RemoveDuplicatesFromSortedList.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/remove_duplicates_from_linked_list.py) | -| 88 | [Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array) | Easy | [![Java](assets/java.png)](src/MergeSortedArray.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/merge_sorted_array.py) | -| 100 | [Same Tree](https://leetcode.com/problems/same-tree) | Easy | [![Java](assets/java.png)](src/SameTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/same_tree.py) | -| 101 | [Symmetric Tree](https://leetcode.com/problems/symmetric-tree) | Easy | [![Java](assets/java.png)](src/SymmetricTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/symmetric_tree.py) | -| 104 | [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree) | Easy | [![Java](assets/java.png)](src/MaximumDepthOfBinaryTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/maximum_depth_of_binary_tree.py) | -| 107 | [Binary Tree Level Order Traversal II](https://leetcode.com/problems/binary-tree-level-order-traversal-ii) | Easy | [![Java](assets/java.png)](src/BinaryTreeLevelOrderTraversalII.java) [![Python](https://img.icons8.com/color/35/000000/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) | Easy | [![Java](assets/java.png)](src/ConvertSortedArrayToBinarySearchTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/converted_sorted_array_to_binary_search_tree.py) | -| 110 | [Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree) | Easy | [![Java](assets/java.png)](src/BalancedBinaryTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/balanced_binary_tree.py) | -| 111 | [Minimum Depth of Binary Tree](https://leetcode.com/problems/minimum-depth-of-binary-tree) | Easy | [![Java](assets/java.png)](src/MinimumDepthOfBinaryTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/minimum_depth_of_binary_tree.py) | -| 112 | [Path Sum](https://leetcode.com/problems/path-sum) | Easy | [![Java](assets/java.png)](src/PathSum.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/path_sum.py) | -| 118 | [Pascal's Triangle](https://leetcode.com/problems/pascals-triangle) | Easy | [![Java](assets/java.png)](src/PascalsTriangle.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/pascals_triangle.py) | -| 119 | [Pascal's Triangle II](https://leetcode.com/problems/pascals-triangle-ii) | Easy | [![Java](assets/java.png)](src/PascalsTriangleII.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/pascals_triangle_ii.py) | -| 121 | [Best Time to Buy and Sell Stocks](https://leetcode.com/problems/best-time-to-buy-and-sell-stock) | Easy | [![Java](assets/java.png)](src/BestTimeToBuyAndSellStock.java) [![Python](https://img.icons8.com/color/35/000000/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) | Easy | [![Java](assets/java.png)](src/BestTimeToBuyAndSellStockII.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/best_time_to_buy_and_sell_stock_ii.py) | -| 125 | [Valid Palindrome](https://leetcode.com/problems/valid-palindrome) | Easy | [![Java](assets/java.png)](src/ValidPalindrome.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/valid_palindrome.py) | -| 136 | [Single Number](https://leetcode.com/problems/single-number) | Easy | [![Java](assets/java.png)](src/SingleNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/single_number.py) | -| 141 | [Linked List Cycle](https://leetcode.com/problems/linked-list-cycle) | Easy | [![Java](assets/java.png)](src/LinkedListCycle.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/linked_list_cycle.py) | -| 155 | [Min Stack](https://leetcode.com/problems/min-stack) | Easy | [![Java](assets/java.png)](src/MinStack.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/min_stack.py) | +| 1 | [Two Sum](https://leetcode.com/problems/two-sum/) | Easy | [![Java](assets/java.png)](src/TwoSum.java) [![Python]()](python/two_sum.py) | +| 7 | [Reverse Integer](https://leetcode.com/problems/reverse-integer/) | Easy | [![Java](assets/java.png)](src/ReverseInteger.java) [![Python](assets/python.png)](python/reverse_integer.py) | +| 9 | [PalindromeNumber](https://leetcode.com/problems/palindrome-number/) | Easy | [![Java](assets/java.png)](src/PalindromeNumber.java) [![Python](assets/python.png)](python/palindrome_number.py) | +| 13 | [Roman To Integer](https://leetcode.com/problems/roman-to-integer/) | Easy | [![Java](assets/java.png)](src/RomanToInteger.java) [![Python](assets/python.png)](python/roman_to_integer.py) | +| 14 | [Longest Common Prefix](https://leetcode.com/problems/longest-common-prefix/) | Easy | [![Java](assets/java.png)](src/LongestCommonPrefix.java) [![Python](assets/python.png)](python/longest_common_prefix.py) | +| 20 | [ValidParentheses](https://leetcode.com/problems/valid-parentheses/) | Easy | [![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/) | Easy | [![Java](assets/java.png)](src/Merge2SortedLists.java) [![Python](assets/python.png)](python/merge_2_sorted_lists.py) | +| 26 | [Remove Duplicates From Sorted Array](https://leetcode.com/problems/remove-duplicates-from-sorted-array/) | Easy | [![Java](assets/java.png)](src/RemoveDuplicatesFromSortedArray.java) [![Python](assets/python.png)](python/remove_duplicates_from_sorted_array.py) | +| 27 | [Remove Element](https://leetcode.com/problems/remove-element/) | Easy | [![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) | Easy | [![Java](assets/java.png)](src/NeedleInHaystack.java) [![Python](assets/python.png)](python/needle_in_haystack.py) | +| 35 | [Search Inserted Position](https://leetcode.com/problems/search-insert-position/) | Easy | [![Java](assets/java.png)](src/SearchInsertPosition.java) [![Python](assets/python.png)](python/search_insert_position.py) | +| 38 | [Count and Say](https://leetcode.com/problems/count-and-say) | Medium | [![Java](assets/java.png)](src/CountAndSay.java) [![Python](assets/python.png)](python/count_and_say.py) | +| 53 | [Maximum SubArray](https://leetcode.com/problems/maximum-subarray) | Easy | [![Java](assets/java.png)](src/MaximumSubArray.java) [![Python](assets/python.png)](python/maximum_sum_subarray.py) | +| 58 | [Length of Last Word](https://leetcode.com/problems/length-of-last-word) | Easy | [![Java](assets/java.png)](src/LengthOfLastWord.java) [![Python](assets/python.png)](python/length_of_last_word.py) | +| 66 | [Plus One](https://leetcode.com/problems/plus-one) | Easy | [![Java](assets/java.png)](src/PlusOne.java) [![Python](assets/python.png)](python/plus_one.py) | +| 67 | [Add Binary](https://leetcode.com/problems/add-binary) | Easy | [![Java](assets/java.png)](src/AddBinary.java) [![Python](assets/python.png)](python/add_binary.py) | +| 69 | [Sqrt(x)](https://leetcode.com/problems/sqrtx) | Easy | [![Java](assets/java.png)](src/Sqrtx.java) [![Python](assets/python.png)](python/sqrt.py) | +| 70 | [Climbing Stairs](https://leetcode.com/problems/climbing-stairs) | Easy | [![Java](assets/java.png)](src/ClimbingStairs.java) [![Python](assets/python.png)](python/climbing_stairs.py) | +| 83 | [Remove Duplicates from Sorted List](https://leetcode.com/problems/remove-duplicates-from-sorted-list) | Easy | [![Java](assets/java.png)](src/RemoveDuplicatesFromSortedList.java) [![Python](assets/python.png)](python/remove_duplicates_from_linked_list.py) | +| 88 | [Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array) | Easy | [![Java](assets/java.png)](src/MergeSortedArray.java) [![Python](assets/python.png)](python/merge_sorted_array.py) | +| 100 | [Same Tree](https://leetcode.com/problems/same-tree) | Easy | [![Java](assets/java.png)](src/SameTree.java) [![Python](assets/python.png)](python/same_tree.py) | +| 101 | [Symmetric Tree](https://leetcode.com/problems/symmetric-tree) | Easy | [![Java](assets/java.png)](src/SymmetricTree.java) [![Python](assets/python.png)](python/symmetric_tree.py) | +| 104 | [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree) | Easy | [![Java](assets/java.png)](src/MaximumDepthOfBinaryTree.java) [![Python](assets/python.png)](python/maximum_depth_of_binary_tree.py) | +| 107 | [Binary Tree Level Order Traversal II](https://leetcode.com/problems/binary-tree-level-order-traversal-ii) | Easy | [![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) | Easy | [![Java](assets/java.png)](src/ConvertSortedArrayToBinarySearchTree.java) [![Python](assets/python.png)](python/converted_sorted_array_to_binary_search_tree.py) | +| 110 | [Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree) | Easy | [![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) | Easy | [![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) | Easy | [![Java](assets/java.png)](src/PathSum.java) [![Python](assets/python.png)](python/path_sum.py) | +| 118 | [Pascal's Triangle](https://leetcode.com/problems/pascals-triangle) | Easy | [![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) | Easy | [![Java](assets/java.png)](src/PascalsTriangleII.java) [![Python](assets/python.png)](python/pascals_triangle_ii.py) | +| 121 | [Best Time to Buy and Sell Stocks](https://leetcode.com/problems/best-time-to-buy-and-sell-stock) | Easy | [![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) | Easy | [![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) | Easy | [![Java](assets/java.png)](src/ValidPalindrome.java) [![Python](assets/python.png)](python/valid_palindrome.py) | +| 136 | [Single Number](https://leetcode.com/problems/single-number) | Easy | [![Java](assets/java.png)](src/SingleNumber.java) [![Python](assets/python.png)](python/single_number.py) | +| 141 | [Linked List Cycle](https://leetcode.com/problems/linked-list-cycle) | Easy | [![Java](assets/java.png)](src/LinkedListCycle.java) [![Python](assets/python.png)](python/linked_list_cycle.py) | +| 155 | [Min Stack](https://leetcode.com/problems/min-stack) | Easy | [![Java](assets/java.png)](src/MinStack.java) [![Python](assets/python.png)](python/min_stack.py) | | 157 | [Read N Characters Given Read4](https://leetcode.com/problems/read-n-characters-given-read4) | Easy | | -| 160 | [Intersection of Two Linked Lists](https://leetcode.com/problems/intersection-of-two-linked-lists) | Easy | [![Java](assets/java.png)](src/IntersectionOf2LinkedLists.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/intersecction_of_two_linked_lists.py) | -| 167 | [Two Sum II - Input Array is Sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted) | Easy | [![Java](assets/java.png)](src/TwoSumIIInputArrayIsSorted.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/two_sum_ii.py) | -| 168 | [Excel Sheet Column Title](https://leetcode.com/problems/excel-sheet-column-title) | Easy | [![Java](assets/java.png)](src/ExcelSheetColumnTitle.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/excel_sheet_column_title.py) | -| 169 | [Majority Element](https://leetcode.com/problems/majority-element) | Easy | [![Java](assets/java.png)](src/MajorityElement.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/majority_element.py) | +| 160 | [Intersection of Two Linked Lists](https://leetcode.com/problems/intersection-of-two-linked-lists) | Easy | [![Java](assets/java.png)](src/IntersectionOf2LinkedLists.java) [![Python](assets/python.png)](python/intersecction_of_two_linked_lists.py) | +| 167 | [Two Sum II - Input Array is Sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | | -| 171 | [Excel Sheet Column Number](https://leetcode.com/problems/excel-sheet-column-number) | Easy | [![Java](assets/java.png)](src/ExcelSheetColumnNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/excel_sheet_column_number.py) | -| 172 | [Factoring Trailing Zeroes](https://leetcode.com/problems/factorial-trailing-zeroes) | Easy | [![Java](assets/java.png)](src/FactorialTrailingZeros.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/factorial_trailing_zeroes.py) | -| 189 | [Rotate Array](https://leetcode.com/problems/rotate-array) | Easy | [![Java](assets/java.png)](src/RotateArray.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/rotate_array.py) | -| 190 | [Reverse Bits](https://leetcode.com/problems/reverse-bits) | Easy | [![Java](assets/java.png)](src/ReverseBits.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_bits.py) | -| 191 | [Number of One Bits](https://leetcode.com/problems/number-of-1-bits) | Easy | [![Java](assets/java.png)](src/NumberOf1Bit.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/number_of_1_bits.py) | -| 198 | [House Robber](https://leetcode.com/problems/house-robber) | Easy | [![Java](assets/java.png)](src/HouseRobber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/house_robber.py) | -| 202 | [Happy Number](https://leetcode.com/problems/happy-number) | Easy | [![Java](assets/java.png)](src/HappyNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/happy_number.py) | -| 203 | [Remove Linked List Elements](https://leetcode.com/problems/remove-linked-list-elements) | Easy | [![Java](assets/java.png)](src/RemoveLinkedListElements.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/remove_linked_list_elements.py) | -| 204 | [Count Primes](https://leetcode.com/problems/count-primes) | Easy | [![Java](assets/java.png)](src/CountPrimes.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/count_primes.py) | -| 205 | [Isomorphic Strings](https://leetcode.com/problems/isomorphic-strings) | Easy | [![Java](assets/java.png)](src/IsomorphicStrings.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/isomorphic_strings.py) | -| 206 | [Reverse Linked Lists](https://leetcode.com/problems/reverse-linked-list) | Easy | [![Java](assets/java.png)](src/ReverseLinkedList.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_linked_list.py) | -| 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate) | Easy | [![Java](assets/java.png)](src/ContainsDuplicate.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/contains_duplicate.py) | -| 219 | [Contains Duplicate II](https://leetcode.com/problems/contains-duplicate-ii) | Easy | [![Java](assets/java.png)](src/ContainsDuplicateII.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/contains_duplicate_ii.py) | -| 225 | [Implement Stack using Queues](https://leetcode.com/problems/implement-stack-using-queues) | Easy | [![Java](assets/java.png)](src/MyStack.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/implement_stack_using_queues.py) | -| 226 | [Invert Binary Tree](https://leetcode.com/problems/invert-binary-tree) | Easy | [![Java](assets/java.png)](src/InvertBinaryTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/invert_binary_tree.py) | -| 231 | [Power of Two](https://leetcode.com/problems/power-of-two) | Easy | [![Java](assets/java.png)](src/PowerOf2.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/is_power_of_2.py) | -| 232 | [Implement Queue Using Stacks](https://leetcode.com/problems/implement-queue-using-stacks) | Easy | [![Java](assets/java.png)](src/MyQueue.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/implement_queue_using_stacks.py) | -| 234 | [Palindrome Linked Lists](https://leetcode.com/problems/palindrome-linked-list) | Easy | [![Java](assets/java.png)](src/PalindromeLinkedList.java) [![Python](https://img.icons8.com/color/35/000000/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) | Easy | [![Java](assets/java.png)](src/LowestCommonAncestorOfBinarySearchTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/lowest_common_ancestor_of_bst.py) | -| 237 | [Delete a Node In A Linked List](https://leetcode.com/problems/delete-node-in-a-linked-list) | Easy | [![Java](assets/java.png)](src/DeleteANodeInLinkedList.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/delete_node_in_linked_list.py) | -| 242 | [Valid Anagram](https://leetcode.com/problems/valid-anagram) | Easy | [![Java](assets/java.png)](src/ValidAnagram.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/delete_node_in_linked_list.py) | +| 171 | [Excel Sheet Column Number](https://leetcode.com/problems/excel-sheet-column-number) | Easy | [![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) | Easy | [![Java](assets/java.png)](src/FactorialTrailingZeros.java) [![Python](assets/python.png)](python/factorial_trailing_zeroes.py) | +| 189 | [Rotate Array](https://leetcode.com/problems/rotate-array) | Easy | [![Java](assets/java.png)](src/RotateArray.java) [![Python](assets/python.png)](python/rotate_array.py) | +| 190 | [Reverse Bits](https://leetcode.com/problems/reverse-bits) | Easy | [![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) | Easy | [![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) | Easy | [![Java](assets/java.png)](src/HouseRobber.java) [![Python](assets/python.png)](python/house_robber.py) | +| 202 | [Happy Number](https://leetcode.com/problems/happy-number) | Easy | [![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) | Easy | [![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) | Easy | [![Java](assets/java.png)](src/CountPrimes.java) [![Python](assets/python.png)](python/count_primes.py) | +| 205 | [Isomorphic Strings](https://leetcode.com/problems/isomorphic-strings) | Easy | [![Java](assets/java.png)](src/IsomorphicStrings.java) [![Python](assets/python.png)](python/isomorphic_strings.py) | +| 206 | [Reverse Linked Lists](https://leetcode.com/problems/reverse-linked-list) | Easy | [![Java](assets/java.png)](src/ReverseLinkedList.java) [![Python](assets/python.png)](python/reverse_linked_list.py) | +| 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate) | Easy | [![Java](assets/java.png)](src/ContainsDuplicate.java) [![Python](assets/python.png)](python/contains_duplicate.py) | +| 219 | [Contains Duplicate II](https://leetcode.com/problems/contains-duplicate-ii) | Easy | [![Java](assets/java.png)](src/ContainsDuplicateII.java) [![Python](assets/python.png)](python/contains_duplicate_ii.py) | +| 225 | [Implement Stack using Queues](https://leetcode.com/problems/implement-stack-using-queues) | Easy | [![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) | Easy | [![Java](assets/java.png)](src/InvertBinaryTree.java) [![Python](assets/python.png)](python/invert_binary_tree.py) | +| 231 | [Power of Two](https://leetcode.com/problems/power-of-two) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | [![Java](assets/java.png)](src/LowestCommonAncestorOfBinarySearchTree.java) [![Python](assets/python.png)](python/lowest_common_ancestor_of_bst.py) | +| 237 | [Delete a Node In A Linked List](https://leetcode.com/problems/delete-node-in-a-linked-list) | Easy | [![Java](assets/java.png)](src/DeleteANodeInLinkedList.java) [![Python](assets/python.png)](python/delete_node_in_linked_list.py) | +| 242 | [Valid Anagram](https://leetcode.com/problems/valid-anagram) | Easy | [![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) | Easy | | | 246 | 🔒 [Strobogramatic Number](https://leetcode.com/problems/strobogrammatic-number) | Easy | | | 252 | 🔒 [Meeting Rooms](https://leetcode.com/problems/meeting-rooms) | Easy | | | 256 | 🔒 [Paint House](https://leetcode.com/problems/paint-house) | Easy | | -| 257 | [Binary Tree Paths](https://leetcode.com/problems/binary-tree-paths) | Easy | [![Java](assets/java.png)](src/BinaryTreePaths.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/binary_tree_paths.py) | -| 258 | [Add Digits](https://leetcode.com/problems/add-digits) | Easy | [![Java](assets/java.png)](src/AddDigits.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/add_digits.py) | -| 263 | [Ugly Number](https://leetcode.com/problems/ugly-number) | Easy | [![Java](assets/java.png)](src/UglyNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/ugly_number.py) | +| 257 | [Binary Tree Paths](https://leetcode.com/problems/binary-tree-paths) | Easy | [![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) | Easy | [![Java](assets/java.png)](src/AddDigits.java) [![Python](assets/python.png)](python/add_digits.py) | +| 263 | [Ugly Number](https://leetcode.com/problems/ugly-number) | Easy | [![Java](assets/java.png)](src/UglyNumber.java) [![Python](assets/python.png)](python/ugly_number.py) | | 266 | 🔒 [Palindrome Permutation](https://leetcode.com/problems/palindrome-permutation) | Easy | | -| 268 | [Missing Number](https://leetcode.com/problems/missing-number) | Easy | [![Java](assets/java.png)](src/MissingNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/missing_number.py) | +| 268 | [Missing Number](https://leetcode.com/problems/missing-number) | Easy | [![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) | Easy | | | 276 | 🔒 [Paint Fence](https://leetcode.com/problems/paint-fence) | Easy | | -| 278 | [First Bad Version](https://leetcode.com/problems/first-bad-version) | Easy | [![Java](assets/java.png)](src/FirstBadVersion.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/first_bad_version.py) | -| 283 | [Move Zeroes](https://leetcode.com/problems/move-zeroes) | Easy | [![Java](assets/java.png)](src/MoveZeros.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/move_zeroes.py) | -| 290 | [Word Pattern](https://leetcode.com/problems/word-pattern) | Easy | [![Java](assets/java.png)](src/WordPattern.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/word_pattern.py) | -| 292 | [Nim Game](https://leetcode.com/problems/nim-game) | Easy | [![Java](assets/java.png)](src/NimGame.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/nim_game.py) | +| 278 | [First Bad Version](https://leetcode.com/problems/first-bad-version) | Easy | [![Java](assets/java.png)](src/FirstBadVersion.java) [![Python](assets/python.png)](python/first_bad_version.py) | +| 283 | [Move Zeroes](https://leetcode.com/problems/move-zeroes) | Easy | [![Java](assets/java.png)](src/MoveZeros.java) [![Python](assets/python.png)](python/move_zeroes.py) | +| 290 | [Word Pattern](https://leetcode.com/problems/word-pattern) | Easy | [![Java](assets/java.png)](src/WordPattern.java) [![Python](assets/python.png)](python/word_pattern.py) | +| 292 | [Nim Game](https://leetcode.com/problems/nim-game) | Easy | [![Java](assets/java.png)](src/NimGame.java) [![Python](assets/python.png)](python/nim_game.py) | | 293 | 🔒 [Flip Game](https://leetcode.com/problems/flip-game) | Easy | | -| 299 | [Bulls and Cows](https://leetcode.com/problems/bulls-and-cows) | Easy | [![Java](assets/java.png)](src/BullsAndCows.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/bulls_and_cows.py) | -| 303 | [Range Sum Query - Immutable](https://leetcode.com/problems/range-sum-query-immutable) | Easy | [![Java](assets/java.png)](src/RangeSumQueryImmutable.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/range_sum_query_immutable.py) | -| 326 | [Power of Three](https://leetcode.com/problems/power-of-three) | Easy | [![Java](assets/java.png)](src/PowerOfThree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/power_of_three.py) | +| 299 | [Bulls and Cows](https://leetcode.com/problems/bulls-and-cows) | Easy | [![Java](assets/java.png)](src/BullsAndCows.java) [![Python](assets/python.png)](python/bulls_and_cows.py) | +| 303 | [Range Sum Query - Immutable](https://leetcode.com/problems/range-sum-query-immutable) | Easy | [![Java](assets/java.png)](src/RangeSumQueryImmutable.java) [![Python](assets/python.png)](python/range_sum_query_immutable.py) | +| 326 | [Power of Three](https://leetcode.com/problems/power-of-three) | Easy | [![Java](assets/java.png)](src/PowerOfThree.java) [![Python](assets/python.png)](python/power_of_three.py) | | 339 | 🔒 [Nested List Weight Sum](https://leetcode.com/problems/nested-list-weight-sum) | Easy | | -| 342 | [Power of Four](https://leetcode.com/problems/power-of-four) | Easy | [![Java](assets/java.png)](src/PowerOf4.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/power_of_four.py) | -| 344 | [Reverse A String](https://leetcode.com/problems/reverse-string) | Easy | [![Java](assets/java.png)](src/ReverseString.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_a_string.py) | -| 345 | [Reverse Vowels of A String](https://leetcode.com/problems/reverse-vowels-of-a-string) | Easy | [![Java](assets/java.png)](src/ReverseVowelsOfString.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/reverse_vowels_of_a_string.py) | +| 342 | [Power of Four](https://leetcode.com/problems/power-of-four) | Easy | [![Java](assets/java.png)](src/PowerOf4.java) [![Python](assets/python.png)](python/power_of_four.py) | +| 344 | [Reverse A String](https://leetcode.com/problems/reverse-string) | Easy | [![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) | Easy | [![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) | Easy | | -| 349 | [Intersection of 2 Arrays](https://leetcode.com/problems/intersection-of-two-arrays) | Easy | [![Java](assets/java.png)](src/IntersectionOfTwoArrays.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/intersection_of_2_array.py) | -| 350 | [Intersection of 2 Arrays II](https://leetcode.com/problems/intersection-of-two-arrays-ii) | Easy | [![Java](assets/java.png)](src/IntersectionOfTwoArraysII.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/intersection_of_2_arrays_II.py) | +| 349 | [Intersection of 2 Arrays](https://leetcode.com/problems/intersection-of-two-arrays) | Easy | [![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) | Easy | [![Java](assets/java.png)](src/IntersectionOfTwoArraysII.java) [![Python](assets/python.png)](python/intersection_of_2_arrays_II.py) | | 359 | 🔒 [Logger Rate Limiter](https://leetcode.com/problems/logger-rate-limiter) | Easy | | -| 367 | [Valid Perfect Square](https://leetcode.com/problems/valid-perfect-square) | Easy | [![Java](assets/java.png)](src/IsPerfectSquare.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/valid_perfect_square.py) | -| 374 | [Guess Number Higher or Lower](https://leetcode.com/problems/guess-number-higher-or-lower) | Easy | [![Java](assets/java.png)](src/GuessNumberHigherOrLower.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/guess_number_higher_or_lower.py) | -| 383 | [Ransom Note](https://leetcode.com/problems/ransom-note) | Easy | [![Java](assets/java.png)](src/RansomNote.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/ransom_note.py) | -| 387 | [First Unique Character in String](https://leetcode.com/problems/first-unique-character-in-a-string) | Easy | [![Java](assets/java.png)](src/FirstUniqueCharacter.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/first_unique_character_in_string.py) | -| 389 | [Find the Difference](https://leetcode.com/problems/find-the-difference) | Easy | [![Java](assets/java.png)](src/FindTheDifference.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/find_the_difference.py) | -| 392 | [Is Subsequence](https://leetcode.com/problems/is-subsequence) | Easy | [![Java](assets/java.png)](src/IsSubsequence.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/is_subsequence.py) | -| 401 | [Binary Watch](https://leetcode.com/problems/binary-watch) | Easy | [![Java](assets/java.png)](src/BinaryWatch.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/binary_watch.py) | -| 404 | [Sum of Left Leaves](https://leetcode.com/problems/sum-of-left-leaves) | Easy | [![Java](assets/java.png)](src/SumOfLeftLeaves.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/sum_of_left_leaves.py) | -| 405 | [Convert a Number to Hexadecimal](https://leetcode.com/problems/convert-a-number-to-hexadecimal) | Easy | [![Java](assets/java.png)](src/ConvertNumberToHexadecimal.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/convert_a_number_to_hexadecimal.py) | +| 367 | [Valid Perfect Square](https://leetcode.com/problems/valid-perfect-square) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | [![Java](assets/java.png)](src/IsSubsequence.java) [![Python](assets/python.png)](python/is_subsequence.py) | +| 401 | [Binary Watch](https://leetcode.com/problems/binary-watch) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | | -| 409 | [Longest Palindrome](https://leetcode.com/problems/longest-palindrome) | Easy | [![Java](assets/java.png)](src/LongestPalindrome.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/longest_palindrome.py) | -| 412 | [Fizz Buzz](https://leetcode.com/problems/fizz-buzz) | Easy | [![Java](assets/java.png)](src/FizzBuzz.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/fizz_buzz.py) | -| 414 | [Third Maximum Number](https://leetcode.com/problems/third-maximum-number) | Easy | [![Java](assets/java.png)](src/ThirdMaximumNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/fizz_buzz.py) | -| 415 | [Add Strings](https://leetcode.com/problems/add-strings) | Easy | [![Java](assets/java.png)](src/AddString.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/add_strings.py) | +| 409 | [Longest Palindrome](https://leetcode.com/problems/longest-palindrome) | Easy | [![Java](assets/java.png)](src/LongestPalindrome.java) [![Python](assets/python.png)](python/longest_palindrome.py) | +| 412 | [Fizz Buzz](https://leetcode.com/problems/fizz-buzz) | Easy | [![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) | Easy | [![Java](assets/java.png)](src/ThirdMaximumNumber.java) [![Python](assets/python.png)](python/fizz_buzz.py) | +| 415 | [Add Strings](https://leetcode.com/problems/add-strings) | Easy | [![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) | Easy | | -| 434 | [Number of Segments in a String](https://leetcode.com/problems/number-of-segments-in-a-string) | Easy | [![Java](assets/java.png)](src/NumberOfSegmentsInString.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/number_of_segments_in_a_string.py) | -| 441 | [Arranging Coins](https://leetcode.com/problems/arranging-coins) | Easy | [![Java](assets/java.png)](src/ArrangingCoins.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/arranging_coins.py) | -| 443 | [String Compression](https://leetcode.com/problems/string-compression) | Medium | [![Java](assets/java.png)](src/StringCompression.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/string_compression.py) | -| 447 | [Number of Boomerangs](https://leetcode.com/problems/number-of-boomerangs) | Medium | [![Java](assets/java.png)](src/NumberOfBoomerangs.java) [![Python](https://img.icons8.com/color/35/000000/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) | Easy | [![Java](assets/java.png)](src/FindAllNumbersDisappearedInAnArray.java) [![Python](https://img.icons8.com/color/35/000000/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) | Easy | [![Java](assets/java.png)](src/MinimumMovesToEqualArrayElements.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/minimum_moves_to_equal_array_element.py) | -| 455 | [Assign Cookies](https://leetcode.com/problems/assign-cookies) | Easy | [![Java](assets/java.png)](src/AssignCookies.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/assign_cookies.py)| -| 459 | [Repeated Substring Pattern](https://leetcode.com/problems/repeated-substring-pattern) | Easy | [![Java](assets/java.png)](src/RepeatedSubstringPattern.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/repeated_substring_pattern.py) | -| 461 | [Hamming Distance](https://leetcode.com/problems/hamming-distance) | Easy | [![Java](assets/java.png)](src/HammingDistance.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/hamming_distance.py) | -| 463 | [Island Perimeter](https://leetcode.com/problems/island-perimeter) | Easy | [![Java](assets/java.png)](src/IslandPerimeter.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/island_perimeter.py) | -| 475 | [Heaters](https://leetcode.com/problems/heaters) | Medium | [![Java](assets/java.png)](src/Heaters.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/heaters.py) | -| 476 | [Number Complement](https://leetcode.com/problems/number-complement) | Easy | [![Java](assets/java.png)](src/NumberComplement.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/number_complement.py) | -| 482 | [License Key Formatting](https://leetcode.com/problems/license-key-formatting) | Easy | [![Java](assets/java.png)](src/LicenseKeyFormatting.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/license_key_formatting.py) | -| 485 | [Max Consecutive Ones](https://leetcode.com/problems/max-consecutive-ones) | Easy | [![Java](assets/java.png)](src/MaxConsecutiveOnes.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/max_consecutive_ones.py) | -| 492 | [Construct the Rectangle](https://leetcode.com/problems/construct-the-rectangle) | Easy | [![Java](assets/java.png)](src/ConstructTheRectangle.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/construct_the_rectangle.py) | -| 496 | [Next Greater Element I](https://leetcode.com/problems/next-greater-element-i) | Easy | [![Java](assets/java.png)](src/NextGreaterElementI.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/next_greater_element_i.py) | -| 500 | [Keyboard Row](https://leetcode.com/problems/keyboard-row) | Easy | [![Java](assets/java.png)](src/KeyBoardRow.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/keyboard_row.py) | -| 501 | [Find Mode in Binary Search Tree](https://leetcode.com/problems/find-mode-in-binary-search-tree) | Easy | [![Java](assets/java.png)](src/FindModeInBinarySearchTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/find_mode_in_binary_search_tree.py) | -| 504 | [Base 7](https://leetcode.com/problems/base-7) | Easy | [![Java](assets/java.png)](src/Base7.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/base_7.py) | -| 506 | [Relative Ranks](https://leetcode.com/problems/relative-ranks) | Easy | [![Java](assets/java.png)](src/RelativeRanks.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/relative_ranks.py) | -| 507 | [Perfect Number](https://leetcode.com/problems/perfect-number) | Easy | [![Java](assets/java.png)](src/CheckPerfectNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/check_perfect_number.py) | +| 434 | [Number of Segments in a String](https://leetcode.com/problems/number-of-segments-in-a-string) | Easy | [![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) | Easy | [![Java](assets/java.png)](src/ArrangingCoins.java) [![Python](assets/python.png)](python/arranging_coins.py) | +| 443 | [String Compression](https://leetcode.com/problems/string-compression) | Medium | [![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) | Medium | [![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) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | [![Java](assets/java.png)](src/HammingDistance.java) [![Python](assets/python.png)](python/hamming_distance.py) | +| 463 | [Island Perimeter](https://leetcode.com/problems/island-perimeter) | Easy | [![Java](assets/java.png)](src/IslandPerimeter.java) [![Python](assets/python.png)](python/island_perimeter.py) | +| 475 | [Heaters](https://leetcode.com/problems/heaters) | Medium | [![Java](assets/java.png)](src/Heaters.java) [![Python](assets/python.png)](python/heaters.py) | +| 476 | [Number Complement](https://leetcode.com/problems/number-complement) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | [![Java](assets/java.png)](src/ConstructTheRectangle.java) [![Python](assets/python.png)](python/construct_the_rectangle.py) | +| 496 | [Next Greater Element I](https://leetcode.com/problems/next-greater-element-i) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | [![Java](assets/java.png)](src/Base7.java) [![Python](assets/python.png)](python/base_7.py) | +| 506 | [Relative Ranks](https://leetcode.com/problems/relative-ranks) | Easy | [![Java](assets/java.png)](src/RelativeRanks.java) [![Python](assets/python.png)](python/relative_ranks.py) | +| 507 | [Perfect Number](https://leetcode.com/problems/perfect-number) | Easy | [![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) | Easy | | | 520 | [Detect Capital](https://leetcode.com/problems/detect-capital) | Easy | | | 521 | [Longest Uncommon Subsequence I](https://leetcode.com/problems/longest-uncommon-subsequence-i) | Easy | | From c33b62c6c37a759b0bc1801701c471be1198378b Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 17 Jul 2021 15:43:35 +0530 Subject: [PATCH 118/947] adds java yt icon --- README.md | 2 +- assets/java-yt-icon.jpg | Bin 0 -> 16872 bytes assets/java-yt-icon.psd | Bin 0 -> 35596 bytes assets/java-yt.png | Bin 0 -> 4345 bytes assets/yt-50.png | Bin 0 -> 842 bytes assets/yt.png | Bin 0 -> 8407 bytes 6 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 assets/java-yt-icon.jpg create mode 100644 assets/java-yt-icon.psd create mode 100644 assets/java-yt.png create mode 100644 assets/yt-50.png create mode 100644 assets/yt.png diff --git a/README.md b/README.md index a39051b..d26b071 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ ## Problems | #Number | Name | Difficulty | Solution | Youtube | |:--------:|------|:----------:|:--------:|:----------------------:| -| 1 | [Two Sum](https://leetcode.com/problems/two-sum/) | Easy | [![Java](assets/java.png)](src/TwoSum.java) [![Python]()](python/two_sum.py) | +| 1 | [Two Sum](https://leetcode.com/problems/two-sum/) | Easy | [![Java](assets/java.png)](src/TwoSum.java) [![Python]()](python/two_sum.py) | [![java-yt](assets/java-yt.png)]() | | 7 | [Reverse Integer](https://leetcode.com/problems/reverse-integer/) | Easy | [![Java](assets/java.png)](src/ReverseInteger.java) [![Python](assets/python.png)](python/reverse_integer.py) | | 9 | [PalindromeNumber](https://leetcode.com/problems/palindrome-number/) | Easy | [![Java](assets/java.png)](src/PalindromeNumber.java) [![Python](assets/python.png)](python/palindrome_number.py) | | 13 | [Roman To Integer](https://leetcode.com/problems/roman-to-integer/) | Easy | [![Java](assets/java.png)](src/RomanToInteger.java) [![Python](assets/python.png)](python/roman_to_integer.py) | diff --git a/assets/java-yt-icon.jpg b/assets/java-yt-icon.jpg new file mode 100644 index 0000000000000000000000000000000000000000..399f4a43ec092840b6ab7858ad23e0b6654f5198 GIT binary patch literal 16872 zcmeHucU)7;^XN$-A@tq^2_1w$Na#rKO^SdG#WWxil8}UILqKc@f{KEof>=NWY}gwr zh;UI6Y>0}A1sfuWqR88m0OI}n{oeb2-}l}>@1A^e&g{(W?Ck99p558AqxVL;F)O@M znK2L)6a-C!AV?g-A`~DLfDqsZAv7Q{Aq+uO#FPnm5yE(k2MKsAA#jJZ!Jmg931KAw z7p!7J=&`)}!LuEb_?`hlMsnj%H#&#Pz=yP{P zkce>^2oiEawwTYDJYVnxR)K`i(R-usASq!jqCJ8j#OQlSMwo)=88F{yCzK6IiHnQl z#HDaJDS1f=NqJ>iDJfZHHAO{bMMX7vDd9Et5GDS6M@UObO3O&g$;ikl$;ikk!8aKt zQ5N~XBVhC*Brgt;AQB3p3nAqZD0#$a7pNq9^a{cSXeoveUO-{^LO}>5S`32~$4N*6 z2l$nUfRLzhq8x-kBTz^*QVfd`7eh&r0Z|@>)={t&a|@*?>L#urVU!BW4!i5=D~Da8 zlC5}|w>+>0g){rQKhpTtD&MDwnRum|~8e9sy)koH+cJnd|J!UG?_*NecFt7qxL+koBpu}!fx>tmafbn!f zg@3Ps(N7gdA3#zlVVUxf3p5yBl(L}ra>WzP4PBq@FKxE!i=uzKP&hi zFWO~eEH4c84NbfMwPiNrvMK4n{+uC`zE)bvDos0@WcSnJ1O44kmns{)m@(XRcYZ5l zr?K{+4srPEU95W1_m=%GZCfw!qCd^s*}r`2C}f}iBW2{x>n01^nm3&2njh^SrpnM{ zM?Udh|2Qy0KT&nQC2H@n=y@r}-`=!8qVbyZ!Irm0)@hwtHdcwA{8XA9+pXCu#cR^T z)w|dtY_OYltCsocZ$4o^db9WZg|oR)-pNUMDG#Ah=t8wg^3LeaVJX{Gr)M9eN1@GS9F(}xzOHJwi(%)E2XEN+=8JO?A8JlT4iDXRAXGgx!+c0M zWVZA}fzIXlbB1vr-ktNySHbZv-U!@LJyk1a`6Wv8&h7cmwAG1}{fQr6=V?aY9Z^5K z-REk;NMP;Jn($jc#hqCq5%#gIBH~@x98{F72tGn%>$!ol;pOW-aD}Y)z@FKwL{7qRke@bd^xY? z#kRPF*5xC0rA<7n$_$rf7d-3tXfM`0pQ`R1e`*w3@8PV?>c2Z2dX1sJ*j}%HhGmg$ z=8l`oI6r!BFP%Spyq(AU*njZgv!}OdW){oxlIzW+_go0>I`Orm{CZX6vJbTbB`oZg z^op$SC0+TaqIVlr(w}!Q`TgrXOJ0}nd-e<~*E{rh^XB1zl7U3Zl2lJ)a9k!YpnD0GmX}Ujx5k5ZBe|XUp5@9GNO$dI6n%N z7p`AF+BO)z<$9(5zTS%8JVx)2zLQz@^CdtwCqj1aenDsh;dmq`yid9bX%0d}54gj0 zctD0ANiL7c76c~=xJd$#gx^|F2wyOh%Hgnt9DZy8gTYQpfC(@RKRsAHI4vv8JCm6T zbGS1Fa2}W}lF8uBpd>KDy=I34l&COKh7cZy6El+`Na6-l7tsJw3JQUE5C{BXAUre^ zVn6~Y3F5+{APMdSH%JM^xU&T8F^#0CNlcc2$rg$PbexdeBWO;5$Qq8Y2qXdAe%4rF zQjLST0w#ye2Xs}K(}OEuk5>XzlFFM%gvIiMCK4Vzw#Ux|TktaxNM-RSC^KRO$rA~$ z1eWJS0@(4VXm?tC?3f`$R)WHO+&zFc@N5DKqvP>(P7>9X^8`)`FCQNJUvTcMf8}%M z(ZeIy0&l%A7TmTImphA&{~bPz&k_jnA*n3aunBgFWCl&Z;dxR76u1ULB|~CE_~Tvy z!!R>=!fHc-j2MxaKNTAeCM&-yb|#G_!iVr^u5(}s!b^_E<8WuiF+k%24`s4r$IT}L z6T*N_?i_)DlfdGzW5=>cjZ`aRSh7f*vccLi_ zLfDTCg*2J5Lczl&0}}b0v=9eR-=+#V)qhQ+J_*w};T_x%!dzf#2VW9nodlqT8Vm}t zzK}&s44|;U9Zbf+g&4z>6_-q4NJ9Kva3ANf7Ghw}AHxV`egSC+?pdS1y-=@U@^49_ z{|!xO3s^MhjH241;i)eqoHU9oM---!2$6+hy?9UED#8`UP&r9#I{#0-ohGmZG}vh%xQk5qAxQtpk0JM;{tl}Gh5dAA zIE~@6m^21Ik`)MdNW?GYhzV%`tpNU5VZzUIQd!to9w&+W3kt*GF=Lq%W3AUrSbDG! z2V_W7k^~$d2Ajd72pDvLfWp(b!C`TDlZ-1blJD*_K>%5x85}ljYn*_?1+Q~H zWAZpB!2$!~zhI@P!U6PO@RFd3I4E%4FfuiwO2Oe*sS>TU=2V7am z4Wff74HYb<@L+Kj2VepC^Mw!>a47u+2ObRCMByJE!i8hMXfB0?#6b}telyxF|1nM= z;5t}Xu=(Z`I4EgO<0M$5Qn(f%B546lcS+?^Xz>gIp2`5T2q)bSXD;aCnRF-JS=K?s zAg%`^j_I4uW6VsS5l%~wr`gkWU7YdLQyo$hxCsma1)rM0V)GqRopgo59RLiYEp+ih z7D2p|t}twfpB)r}_u%jtcx!VT0?pFO4sUC3ZfRphB-@zbNkmI~3!CnX7-bb+R#DkN|x#QxS+oO}6Ip%{JwX;W#&{-R+MuA{XBcm{goKGA_yVtFP>ui8%6xcQViCsR zbCP&8hF3CBQ*XR5z95Y8)1JR*H(uDU*#WySGuOd`$Dn{EXE<1Hj<@p9SjVpcZ@9Fv z3=FVDWjN`=5pV+0mSAZc4kF-WI|pk^Qz8I}BGw=dof(t%J62(^{1;Z>Z*;Ki{Yz## z%^`-vOP~O2F%u}U42wlvMyxJ=q7fW~Gc`~$P>(zr@8{tGViz$?79jA!x*zZ77)xPYtCfS9mphmGL2?!O`uuW7lMfm>ZLAy4WF(G3EGAy)dJYsC9G-E~rNQpN02+wU%-`7KZLIVZ$^2pXzfdJP;TYFnD|?-54Gx0WWeH zE;|-4;NU4-E?8z!;EG!$v*}|a>qJxO{@Zf+l;odf{LV!7R%Ck{I?0}3XG0+oNMztL zR6Cm(0yTziO|-HkQz=x&xQTyfBG5fZ6FupFVxlqg)8Z)XSO$0xSo}AYAu~t}I`CM! zHQkaxqFPZ2cD6JI=m{}4L|cj#!xHvbk(U3aGGv?azW#r?GPJ++fWK&T*e@oHEC1F7 z=nNink`qjJvB-!v9<2@K*p3Sl!~`WiAYlT_9fd`HpB0?KZ(T z1dksl{LQC4jmrbO+lUarPo{%F41lu%%t{e(VSFEem8kJBjD+{tlz2cv0IR`ptOzy} z@`zwp7^Ww%!HyOZ)|pFBpu_ML0IyC?f_J)5fdI})W-?L$+zw!UR#E~J!0`5}QUZel zcHhwO7KpxpL5l-05x`Qs@G!7Fj-C!a7L(LI{YdQFwF^@k-!Q*l7?XsxzDmQuvn;f)Fjb{YT;?zW)TmZ7ZUG3Kg~) zLZ#&=?q|-QI8Hg(qy<~qs0}}H)M5xau@ZvR9{j}V?*d`VYzV5mF{wT(u)j=-$1xc+ zbJ(C0*IzPBaQ=H>QhDZZc@yCmyr*c-4i9@Z4eY@s@$h^Q(q!NXe|F;kamGn%P13^* ztQQzO1_=4!BY~HJZy!K&v*}DYD1c|Oe+d#zlJGywHc0{uiu@V?iWNT~rD$_V?uHVC zde;J>6(u25)DA#FOtf1dE)v9-LFifgrO59A4Cuo9FE?a9NFw=6;XW|r5f+Z8CGnC) zENJ*420nn01#xM0Xey)!8G~(k5@ZWGLavY(q&CpG#1L}mHKt0eKs1N!KeFI-?ViD2^MT9y+ z8)1MjMUW772xo*BA`lUVn1fh|h()jwNr)wgEW|oQA)*9PhNwgwMw~)iLNp<6A?_o( z5w8*bh+!lODTP!*Y9S4g7Dzj!8!`YHj+~E-MJ6KCk=e*R_9$2 zzCjLx4{9Y*DkvQk0cD5sKn0`bqGC`y)H2jsR1vBiRgF50YDC>eJwd%ieMMu?ifBBV zfObUtq9f2WbRv2gIu~7n-jA+BUqRnSccc5zKg6WPG{sEC9K`&@W{bs&rHJK-6^ZQ? zJ1%xrtV66v>@x;~QNb8tY%#u=IhaM5#h6@7DW(Q<5pxUk3^RzuV%4#xSSM^SmVy;v zbFjtOgV+n$Hf#^}i@2n?wm3=LTYRoKTRc;|NW4n?ym*`VOYv_wIh+B`0T+y;t?n`}=mX4rgOM$MCt*~3+vcfY(l%k%ZhayceOR+-ns$!24M#)IYPic|T zI;BHOtxA2$3d&Z>k;Y}Nerk|&f~TyETMf-$i( zi8m=Vxj79v&3angv~AOFm?BMWOqr&ornk(*%?3w?{Z76lfK7C(sAL>94v*lDR?>2H~7dD^m{G>t?fZ6mdlrODpp<>Zs(k5;Bu z467Yh_pBAIgRECs*ISR+*xK-Hs%>7|>f0`~-EMo=PRTCBF4yjwy_mhb{c`)W_Fo-r z90U$W96mS_9OE6U9A8a0n$DPBG5wj7t`o(n%;||U-g%+(F6SpMIxZBKa+jyBdaiWW zy{<3aOxzZ^9dvu|PITwFA9o+}aPU~_anTdy>EpT9v(-z%E5fV9>yfvvcdYjT?>--E zpT#~GeZ_nOd<%T<`f2&m{3`wW{B8Z0`d*1!Pliv%{uL4{ z;#d5UNz5$F9LSoLbvj!sJ0ttqN}rVna%6INId@k%uG+a8y_&hYbq#q<@tPlN>1(gA zBd#l2_dS=Edwsp-`mO6n^J4N^^KJ5XY`|<_Z@5$7Qn0^JzA(M;*~Xxab(`>;)@~Zu z9KE@z$f{`P7KtrMTb^tU+D)(yaUAK2+AA8@E{bBpBRN7WnR%uq{ zA3z>RI`H~n)WMsFJP)0$CRCTzsMM^hg=&*(dk-%>eCJ5Ok@}-{N2`w+9NT_e@%Y+0 zL|s~4--);rPfpG`dFzz_sru87r;nd8KeO+w&e?6}l+Wd#mpGq&e)K~6g~5y5i*GN* zUV2s^UEg_m_T}~~p;ub323)UAMb_qS>aouEo0L_#f7P z9B;L0t-E1+*Tsq+b-h z)P7m{iuCI2Ywy=Ld*}7`yy3q2_BQ98{JZV%jo%;p;QFDZZ+2hLN8ZQL{@hRMpY{z{ z4b%^Y3_kjt@cG-&+Ar!~_J6he+BiIG_~o~h@7V8KM@&Xe{|NZ;a5MpYaQGfF6mI51 zbXPDJ0LM?1(I||B=yOVVb})7c&xVLjUi_^)^5=z`xF+R0uED% z&W2n86AbXhE|4~^D|m|IFjxc{i4p_fxqt}(V$!?_D~1tApwKvY<%9)CMqr+?3n4l# zA}@z0D(EUI>FWtkY#_u?Sd6TQ1wKI{CJ%u#8yLAzMT#ydj7nC*uPAfREGN1p7Vrv> z=xw}grEIN&Re(SZ!ATEsEKVdJq~y_%rGlJ}n;0c=ML}8U;Y(DWq7nvAyro;OXWdP5 z56diXBkNl!0;Q1|5qGg9GOig9VXi zi_;#n9SAKQwd^-@`nKISODNM}THCf>P2+ybR}Xk~q2<%!#B+1jrJMDjuKL#AJ98%$ z)tHyKQ?uOvQRK7!!}Hh|NDph+=iZ;c2E^Yln&lJ8!|tej@C z)99LX`D2;mC8ZTDO)E(n*$ssohgVI1aoRK>+Cw+gcTZJej{TwYK{?chL+Q#zd3Tzx z?938s0KRqw8g$Ls9B5>nG6QwtREX)DOzGF}Z<0%}gm9bQAC&Ef)-w%nTRWfBRX_G9 zyy?uPlNKM3Tmd9GcQ} z|I+s31dc%irS``CzU9I)!C53wW)J`6?mAj2Lmk(^xGAf(l{nR zljlo!WbNn*Uyzm3>zwzv=emr4O|O=NV}I|_tvRMIN`g#Yle>?WYW{dnAas&wzB+CE z+J)!&ZTAN%`}TMY=#j*n(*p)xdijSHt(Uo;^!UsZQGJmZ7vylvOYcft+wOh)&P=IR zPT#x~|7v6xo1Al-naQi#>g4-g!l2mNg+O{&@A2j z#R=b=FF(+n?mZ>KS!c^(AB98(({^P_ceHowf=5Twa+;fBHkeVRZX7#Vn&y>V*eQL( zu&50iGe4ng-L854&;9Q<1^OfxwM~h;yokHcw`zN*POW58hZU!4N2t5>^pULl6@zcm}>~q&0Q{`qNTnesrM!qlBYjaF&{n|0mW_{)3 zS>uDJ7pbki_RIj1m_}F(DL+s@wA*QsCA(k$&Zh?B^RG7<_e$>zrd)M)*-8?`efriC zFm-dT4eR|8KmR*x*PMzE?7X0^`Q3T9sF8$*il=?Ba#cFB!@&#lzR-87`49R#u>Z0%2^UQ^QD+Q>M_RL4US7(h%Of!6F*Ne?0wj!rZfu8cKULfXIoLQ z^Zo5Fb^MC{M(q`x6R~C|>Q+{iR$o>2^81#*Zc5G8Qxzc#dZjfrZinLABTw~wI}jZ& z&;E8jkxw&dr@jv>38}qv(N2G5OWSrE#ifSp=Ik~(kXe$6d(|~#?On4)Crx-tp*B9yJ$=U8 zv@hBJamR~Ws~_#T{#@DLXyXU+2dC0|-CNp4{Q-dhKKYe(9o_K9-gAQe<@A*^Zc`g@ zc8#rln<}pR1icKhjjwLJ+;n%J;^3lZm2p_^=1un(-tK=>cceEkV+6Tpsbo0jLEfIG zk-ZJeJ$HFOe(^nZxXzeXJoH0_@U3&+RmSc4Y15AXunaz+PKZ3S2?z}N6Nej@AuuZ$@}2jA03JJ zZ?gsyo>RVic5LZCLr#8wFUY_0_2)n8%t+J1o{iM!e4Rn}Oh^&CUAgXd@|o9jnmS*G z$84$gk1LxOacm=wO|!b)K0SGhVAYG;ET7dK)o%8>hwU2-HWoS8XXA02{mw>+`)bb= zSPL4u=6{)$^ZA}{z=lEnr7^E=5$&2cx?Kp$CA1%nbbUo*NPDh$uT!w*Ztd*VZF5)H zr?!RaWym|{ok28{tFwlR<@b(4`UaJq@|%y&n7!TEdBiOHU}x^;n5K%ssLaHs4YJN; zRk^4%$~8t=L04xPlyybx$@fl@bYqyaz5(*a%9^K*TbY00Hg8nVzq0uAsRfy*9jiXp zJ+=)P*|*PPPV;N?`3lYVD(IzDVo$re=?pf~F*R$?^5?1Fh#T6HWfH5SzIB9l*{izK z-j?p~B%CTKRk7Z5_#SJj&t8W)kyGZk|1cty-tdn+!gMza@Vb-z{he%1u&kf+%it83 z-ld$y@0adyj=nhNQYeIr&i8x!{Tre6amJ;%_Kver$4+S{llG>kl&NjsNOtSrttRpC z$X9jcQb*{qUQ6-iRn9?6!B#osF0#x>2WWBvX3(hTiHKn=IM8S-!-K^?m zk)4Kci&{2KMWHW^e!3*(v6w_)E-qVXiMokjMs0*b%)4CenTi&d(h_fn#AHCPssd-Y z(LGKrirrwOd-}E4Tv_h(Yq|K&EQ9+Iu0=u0u9Xc#4EL;oyogcJI}|CbYRkoNCUwZw zVEq+8@_Ne}i=mn!3nw+_EJA+CvX;5x=|Z4kjPI~Vipb|Wqw^>q}=$CmZD%6!TWRwtRP z<~fS@K3W_^b#m7DFrSw^L+m2j_Ya9+aZ1LN49A1398}e|?ZSPwGmvpbc4lP6M$9g= zM^&X+^%w7!+jEs=McVHbkf*Ppa3s?BlirJ<*lEU%PowmSS>dfSDoZk!tTt-ZLS{)x zKXk9Jnm!5*$PPSSnmnQ{8kdFD?PQT_Z_e1|S3WzWSek#T%VmvL?W;j;%F4@ceA*}$ z7ry&-I}>JalGEJa|5hFGV-(WfhZzZyR~lT%5P#_VCRcvXz-RfJjP6HER$e0&G<@DT z5QTmr-}go4<~6+{)vUs)rbnY5kX{{Cm6l4{vHaz-;wjo~d4`159y^f^CFf=9Y$JD> zPw_VN$~Spp+}HB0d>4Yh%x%fEDKbHiiR%_|A9XbrMy&Sr{h^Ouk=x+o`ccjP+)a8i z*H7t;o=MpotG+#h8;#bwgl^VXS(jq=X@LLrF6YB5P(N_)c5JE!W}Rq4yIp8)rW&M0 zM77v~gXls7Ab4j)8t_m|Mhib)#+_RlY{tzY9HZ;Dm-R zfBRbMyMqCkjDlqZN=D>B!#%cZ7@ol{o3b`7PE%u-ie>oKBQPt^3#FnKLV+x+PC z)4p86&DRf#C$_gh;UU%ryeS&0gB zAh!k`R``P`d;8eCXrUcoznA;o;rc53xJGj3id~5@&k;A>^6Eb1>zsSsa&Pszhog`< zB~I;ZNkDnoQgtO$9^<;?W)sCPsL0}nKJ7nJHR`ub|5oL{;wFT=eq{dc9%B2^)dQON zDZ6qr4cp~r%V#~g*o$6kyaSz6vvs?UoN8SM^ol>%LT`HFM_Gp~US+OXjwNx8mgUw| z`VQ&OA# zI`nE=t;^N$P}y~BbI+~MKj^XAQi6-eNOzm+6_KC6}%h3RLB= zv)Gx{M&HT12lOWT0dRxp2117Vka&fqWWlyge5JEDW=dLV1^0|X52I4I-|czyBGIxm z0{6N#{ovgr4~-)qy4}XE?1*qeE@&UTc(p}b!7Qr~VUY3ZM0S#t<-)miTyr5*TX4jA zqhv4D&rXW8w&Gsdihy%{#V-r$wWBv?Hty3rxM=-BSBYKbkZD}vHXK=!5V%yocEOH- zcXi4Kp7;FmsY@?23P)Mf73m-$p0dlrRE{2`r;c1ZCtLRlW|0G$!`gVxI%;Ll1I!Gl z`NpBDO|($*8sk3{bXN~5w9HdhZPN{L=LOk)S!7;|xPrd4qCwK4G9g)^bkF*xg++&m TXXb7~Xb(;ug@!M9jNboW1oT3O literal 0 HcmV?d00001 diff --git a/assets/java-yt-icon.psd b/assets/java-yt-icon.psd new file mode 100644 index 0000000000000000000000000000000000000000..5bf3f411eb58e8eea884b6529745a9f8b12399d4 GIT binary patch literal 35596 zcmeHw2V4_L^zdvF5_%6sQ6gd&>7hty0Tl&B#O|pf*+3*Dm;|x+Q_pg?vwNQPtfzP9 zSx+H|iWvk3t_@BV!M@|E9@-QUi>dGF1eH*ep}ZsyHyLSvH$ zAp#jT7Mud;!yGXUsG)sBV-u2C9q63B0oRbyG;f>_e;5%pFaxv;1z=jykSYnJfTuW@`8KteZ>Ajp}df=9{&6wzd(L>UVxu} zn6F=`uYaJApMSU?KRh^uXWYCZEdh#9Nu=Q^alMSyK~CV6q0wZA`}*eQ=Jv=9?4eYp z`}&84ftUc_fB+xh@KH}vXhaiz6zcW{A@y?NNVQlc%ht%03Lcg#N>k=&1YTaaBGYDU zS5~&EB89pK-NqhbWtQ(mQMRvt4?o|}6_SWeWwLWra#}Ts*q4-(S)@XvhI0O&Etj34 z)F{;%%73WRME=K$;hH2Rnd<(mzFAqHty-;#p8zH>n)I_J)v1%RN#7Jwt;|u0$@mG- zlm@$k*&?9!aG{D6X_Tr|rBWVgxbDgIjp7A>y?C96$`lf1uDVNv@2C6?=5G*1#)&j! zWPo3QzmH#tkAFz2e{gtUXn3%HH$MRU8VNCQej+1DDUnGheMUx5KzLvi8I3qUl>zQ7 z5otutlG2#BksOIQT&h%Mi8PU->}#>M|8 zI!-Ch!CeDH8%7a{QVil7n&%%9C=Cb}iF^Y6C22k(!9f8&p%Q;TAO8R`Nu~vgr2e6z z`idF}`&&f=R5BRkMDj*FxGfT>EFg&V6Z?sSd_vOv!hHDt(3VhWhL4E!59Uk!Li|Jh z$oeWiBj#^a^^vKeBTS-4FVmnx4`YMK@lCO~^WbqvE~AH|Y>`S$;?5@Us_$*4@yjF$ zm!UgtxJZnhDN>Ak9w~|NZGvr3%T&@>O!oK7**p^%<}#V0IY5iKnqwssPm8%srf3e( zVy@;`$;8uQE|V#m1GJc{IaV_9w3y3eisk?<=4y_WOgt^-GMS<|K#RGWVL4$xw*=2*$Z(_$`@DVhVcn5#KfGV!#S%Vdh?04?Tfj+IP2E#@+rqB%f|xte1o z6Hkk|Or~fK@UP~wYsgM$ODdM3)h(sEcgR-$GWSMQ^h8!&>R<2PP zHL_02k;yeO1uYWj7BsgoX?QLgP}s8R?UG73#YCNWK}Hc|SgYbKa7@mcaXQwHqVAUal@nQkxCmepU@@9xkiiP3IUOJccc3UbhmeFY$Z138@w@JZ zyp1W}me$R^X`cC>&RftaBnBy+4DZ5Q;u`3UpxazY!+nsiR0hv|Hc^fD7R|Vq?Uo>b;1-LOoJ;|sj&MI=`cpSzJX2U!E3W@rY@kOlh z2O6zD?vy6a2jnL`2gNq@FsuqnY3M*W&sM{0+@yMlJP{88M3Z{VXd0j$;o#7jgt$g^ zane=Foa`njwvv7`xqftyAB3eFUNZ(6HliGjvNx$9RrnQOKp^~ju#wr)z>G1Nl8}|o zgVX0K?vt97SU=F3*Q1*- zTVyCzlVjwv^!odtouTo4>e0}0j)atoa_E8I0>6v<8TKLd=%(yeY3cOq^^J_{V2~f% z+eCmOsJ~KyZEc}ZX2S!7nru9>TFPMv{u|ahjUKZ9hPQ&tp7AL=-LpF5il7I9J4d~v zVMC9zqtP%bTlYznDU=Lw|17wx;E)uJ=lLqy|k0A)&_~+qQ z{|%Dp6gty~TZS%m-KS47kJpIS9MD0Wt%BPtkqpd%68NSDz;gkX=W4Ps9&7EKmWg2o z?sCp5P!M1@45u65?lg}9j>fPgO92kfz&dA3vLqNj4e){qIoR=;i2%==AR}`Dz5%ee zJSR&AFdl84vq%wiMi#c2w}upF0PF{_wJJ3Q?$4|Ugv_ne8^LLfU=4U6@FJlydlG$3 zc%8*vc<@1yP+lK0S59g)KFRQ%6p=~-Uopwb7AfGaWoR=lg&hC(Sp^zxNdA@Bi0|J( zd~FT%_XFu`Mz~yRz%`U?z$v%F7!7we=CTG{+B$@ee2I|Tod%ruW_X~Ti_qaKjoRaa z{iV?dR%E2O2R5i_`wtmRoc|0os;>vG&-6(OUYwx|^RQQo;fohJDjqylh)JH$r%wEz zF4#z|MtXElA*CdKdLem3z{}v_3of@pBBQ?*BU3c_a7H5u|H)#FBw*0s*8n(e*CXdK zJ&^qsXT*GS39+245OdTfpb)0(mS`~qemx*G)bqK)?*Rrnoi<4rOCifp%jnwz5~if` z#5t-71{M}RnITJLhn$f+YKz*V&Ty9wKq06nibnCMFB$+(ZNt%MxNm2mEO=(iMN`o% zG!HF8%g`#c9({+lquppf`WYQTCr|-8i!P!+&`op~Jw#7Y33`VuR##Y8Y#$iSQ<09iG;~}Gj zQOQJ1E2ayx9n*&y$`mpOFh?+@OcirFb0Kpzb1QQ{^EmSy^E&e(^ELA$i_LOk@mM~r zo~%Bs!7MRrJZm~@F>5_*7wa(VH0wI6nDvgOH?uMGFzaR(ZkAv+%q-n3*KD5IYP0Xn z4w;=XyJ_~+>;s$4c42p7hp_vwhqK4Ar?3~Zzhxg_YuQ)XkJ*(R4#%C-jU(U;;D|UH z&OFXK&OS~)=NjiJr`p`g+|xY3yqEb1bA|bA^VQ~i%=65znLjtLwXnD7U=eOHz(Qg% z$zrL+c8lW{S1g`d)LJ@NcCr*$rdp1(oMpMza=+yn%X^mZt*orPtir4YTFI_8sko_9FY~_8aVv*%#SY zIygD_I}C8ha#-xJ$Kkxg3rCJ)N5^9)}AfZI*C8h4(1ynCkma`z+d_gk@Ab!|1URc@f|-pYqr+`ulwyS+lRK7 zw*RL6srK)@J-w5>r+V-8zSF^?LuiML4r@A`>rmCPQ^%nl=XX5P@kJ-MP6?eRciP+O zUT2%mQJu$k-rD&_7j~D>E}31v?ea%gM%Uo38C^GYz0!@*jo(ey?b~iwyPI_n>#pd& zwR@3|wNH%C1fRV=#XVelB=(ry<4BLUzTUnge3$#4^VRzW`^o*b``z_-^zZ9G+yA(K zc|g|yalnRv8-X@~y#i+h9t|uD>J~%>Z3?;_>=c|7JU{qUu#O+XSMm4rUxs*xj1Acs zQWWYOnjE?~^tUjxu-LE}VJE^qhV#QU;Xj9$_VnqQ*>g|N7ZIHz$cXI`j|E-=kzkA9 zVI(hdY~<$1hf(dKL{VF#9!0m0mPCIa{XC{i%($3+F>ho2VpXw+VylGV!f8Tn95b$W z+`_oa@s9C>HRaqOr$J)|?HTkTH8yo=>fOPe2j>hvHNWtSi zp=`aZY+Rpl-;Jxv9FVy)laddWAILJ#8k==Y;i$+|oL06~PE=ma?v_0-`{DTT@vFwa zQ}t7QuO`%AsE=x#;bH1hPUoC2bBZTKPS`M^I(JC!!HEtN6%#K_>N@GGNzW(un!IBQ zYl?Wvsj2Oz&YD_0EoR!5>BRK3>8ED2pD}mF)0w?z?wVyeD|6QGv;AhTm|Zbv=$zwo z+svIg_wkp#zuY^|cAjcp(fpqCzgxgsAX{+xtH7_;eWhP0S$JWQ-=fuv>K2O^Us&S5 zWbG2_Yw6dQm-3fxTE`99B$T@pxs@%ERCAzFGK9#i}u@&aVzy{oNYN zH92b@u1#Efbe;FQW$WtJXRN=uA$G%ojUF4n+F13i^i+WWcThp9($JVW$ew_ z`*Po?eSiEA_ruZsKKr*Ea5=E(NAzRPkFS0j`_rwT`~7_CVCcd9zjXLz;~}R*3l9^A zCmnuwB;&}#qr;D0J=XWwspCD5ANsY&uRBk)JF(#;_vF$%%e=XHRQ}}rN^Q3GbwPT; z<5Oc!-7Oqec;ocI)0fZmJM-JwUS|u>#hlCkP4L@^^Wo=@T?oB!00BtPizS3#;9$cYO@~c&=t>&GXvaI!@hMT^HSPeLwv@DvP4%-x|*J z(*S-LFr)MM2^yKf^E~}LQU6PPEkbR61blDgh6w65^#)nfpLiQ1OoIGdWJ~9eWF{_0 z-9>YewYj;ug}Jqbg|&l~rIiEM&f40J>*nOdb#iiZu%Fsgn3p+cbRFYl9z=ifhaSuBe+VmB74&YDq&9!W ztwZA{=*E}aaytC%hMm+uzv^98*FQgA8b%g&3)s7BUR9TOm&NPndxVOuiXW}pTVDKV z8n?r<{x#=|zPL<&*V(hOonOtFB98m&x=XvFuC2{ijd?%vyYd-pDHOI;pQ|f*dEPhV zK#6k90sW2AwzgtB-Fwwb{a&5q$ez4QqrU%T%*fnBum1@9xz$T$X^3i#onTS-xg2N7 zghw`t^kR?8)~fUEElx#+5PZ%z+g!IKc&|DVM*Z?F83m$?-)&qP zDPAyMv}=6X%db7g6zSYgZ0vm|OPBcL!2_vR^$tsA6bhN4D@#jU`Rs7y&egX0OOI*Y zrvH(c&|R&my)mqJ$xqpK*F49rRBqy_)>SW=zJH{?%5F!6WJQAFgqXVeHt%r7#hUqv zO!r^kZh53FxHvcLK<129Z||L`xzJ<#nM219K780)mr{B9G=ukw8=1cRYgt)YcB^eW zop%3LH)87ksEo(%?WMw-1?|r01D}`=^<%!WowDxBl3Sv*Vb|L96KKD>(`gLTYQuq7 zx6=FVzwkognY{I!tLLFVo{v26Y(qxY3{%&yPE`!*hy9-bD9ana3!! zL>TEQFE6SY_#5dyC9HjUfB)4Xvp4-QU8#S1ecBf_hi<4;W##+!J$`gu+}(Hj*Aq^4 zx7m?D;Qo=1H@9Bcb8dR+j}`0XoHdiTB~f9bI?+dA!*Jh>@TmoJH1|8ncj$B#Mo zuc{ubT2<3;{n`8%DGzGyoa~WmQOFB^Q|6G~$ed#fFk^D&v3txaQ_ekx6X#R1}^pQ2PaW9iB$3Yu^f4h0%o}2 zlEc&{N`$%eN#GVLa15B?qv;B@3TQ03Xp)M~Pm)P+9u5Z1i{)u@oW~ak=Vc1%L?fNf zXDTw4jq`GKHf|9vZ;&sRWBIrt^oC`qGqP|Uec+&@2;v+yJ$nZEAUNzX9u6plKL(7y zo@&HcfR>~xRhC8K*j~)-h`qvFE9~fcq!U%xwQ<=`Hym-oaY{cp{0&xT%)v~I-*7#Q zx7g~83s|!Tt6N254%nJ)b=El11gt2QW3)Pc5@OXyF=)Ke+Av2Xq4N#arlTkS?_2v7 z-M(abB3wbHCR;8}gf=q0`67Qm{KZzEFmb5V$6pkb2H$cG4)h5X`;j7ve`r8(D897# zvf=|@CPuWMRXa)dFIPl&gdA+qiDt`wc8NXzw|v4(1HGQ#n5U7A-Gv1o`ovCvyO{-s z2WckB>jNDP2%uVGsu0{xnN`m_L?nkvVsI-!)Ngi}Eg3$pnGIo68GNs@DcSiG@&HW+ zsrrP6t|>*SfzV5R;CFyZLA!e&)npvX`dqBVRxB5()xG3Okp@R>fs5`?IO_C?d^+;< zDGo=UFfKZ-z9ohT)F(K0&H$B!R2gGSxCZuwPce?Tb1Jjq;lreIWi~k!4ALZ8^%*+I z!PnR_i&SSMD15FC@2N?bdYwN#*SF!H&c?RYU%F4vhVf;P68As$ zOtmr*^RwV+Fm8Py6UV|)f<&P)2EjTYK8*kVFb+xp3WYgY9~1^@D6Ajx0lWxC-!y>I zfEtVf0m3|faK8{i34h2106vr+qoML_IZUZbOtPiGB?dYlWa38;A2`Aw9}G}1ln#R3 z2Y94_4FE_CI6ll2lYqyM8&WueA*HwE^#1h=6lhn{KnId1!>4W4MrWnnNC*oW8s#md z_*=MxG-Oi`tv3gDF$-9cgTtW8dZ)*=SxHERG7CQJY(g`J0oq)WWAM@@{{EkpW=Sh2 zgs^gbxQ}i^jKY+s-5m!HjZLDvM5;<5HAace>E3G`18LYeZql%E?EF`}aoqfyoQCn# zQK3}CNTo6bNiW5~UmgEHSUWv_H?elhh>jf;ww4jyU*ri&>DIW7%I_Z(4DqXEBip;|5Kc4AsPUU7NQ~e#|e6z#OsAXra8_h zD5T1!H8x)ULUYiIPK;%24J%AUavZ)ktUbXL{0v+F5ME~|o)&}c|WGy~EF zXbq%0(KbkbML$4#1s#L*E;Z^db+(|r!y2AltYEi=-Ntyv9$;nU;($k30R{U*ScD)lG9ofkpo=5~k@^UI zB#Nj)I>Zn}L_8Hx5lEneMxcoM0!AdZO~hRRA%v#f5zs%Q{}ccm25BUUf;0+6lnaP> z;Y$Gq7^7c(SpuXo0c$ixT^{pVP$od5^%SG-r^L532O3>RG0K)l0Uo%}=o*T+lUYWy zRa3;7!S4ZI4)`jHQME}}`AH6!pxG)wSfk>GG6u=-8r4}!v(@X;SVN=QuYdtO45zqF zVPJV^AAut8&?iIN!5Wc&378Sl2+Tx8MLfY)iqe5g5pmJ_2ueUiMu0IRz?c-+6s!pn zK6N5|3GgMs7saZ{8Fy~Zr~E~z>0X8iOY@hg3^BSr9{mc=tZo#Q=kppM)C~+=yUzJ7 z4TBNhD4FkQ7>s*GP)37bwS%7TX%I|XIn%uIZ*U`)Mg<$oYpAE8_IiD2^_uEjRNu8Y z&^~kcO=$;iYDYUMc2tA2TEh_68W!rgASVcGxWF`v157oz0j4#iuCP0nBV=2JARS$W z-oxb1Mfx=Dc@?TajKsQQRj3j%2Y;jnR>4vS3$>2ghlm~;jd>laMwYDA6m`R9#O>Ot z%v$sjSuplc)crQ!QRTfpLe_j5MZIjVrpo-QQ4KP;D5Yvch*y-V3g=uXY8~QI)F?W~ zct{OFX78vIRk)mjT7l4Xit1U7bIgK6wW%7amsf zVR*3S$~GUL=mXP8J<#R}Fie@ri!Q?y4uxD>y``v)zFw^z96b4bdZo>oVu5^LSJ>n6 z*s-vZV!YjAtw+o)R5*B`Rfl1d*DP7EV5WLVkV7qEo~C%H4l!bir`I5&tG^Dhgw!bn zDChkYReWU6kzX&CQo7}4$m7L59>z1R6i1%xD2v*gJ2Tu-hZ8eEb}h0spOj+Z;9-NT zd%=$(526lmR*R_j2iI*sa=n(i*!?41#ZiUj*VMi5)KX0S_1UgE#8kjDIO_|F+RA|T zwC^{1^q>%@TEq&jg$X*d7#;OO+PV^PIH5~FoQ4TP1{!c%PqB&)uAZvYORXj?+49>* z>d7Pv)GmrbW<>CW%@-?bDXY4YOB=?8z%n|;EoU9FFoU0AW)2=+ZEfoin<-fI;|u9-9Xp*H?AQ_U-4?II;nMDh9nb;X&>gjY{-&I&1Jw*^6~(HocwbqGF;x^3!?iTX z2C$;y1Er^Ps8V0SsH|v|LnZnOR9Qn+V*wTKKj`S(M+$SIcQiLpKSBut3xUFwI*P%y zxBvK_s$jhT@V>T!qV!zK{v(C+09WYBb&%IP6K*bgiu1mrvXlbR^;m|R3s;YMODWJF z#xD~umqWd)s3@l@D)g{YyAht{`tDUld0hp;ZH(o(I@wVbvB1r(=hkt}T>xw69y`!Q z&t-dXUAUmB-nPsLySV6WDXyh6*98bJ&Rl0Z%;o6H<+{0H3e(xe84B7sb7AEP7jX>~ z$_3fhaS;%Za~+ojXf9Xp23W4%^&`{>k`UL~na1h44z4_|i-(;f$Z$cfj*bWjh=RhD zGaN2;T*{T{h@6Z_!r7&ot9N0#axumN)N)2nSfbv=+O;+4>5VB)PR13lj?Uag>y0EMW~4QaU(77$*#iYeKQ5DbfgNX?#31OK&P;q-4kvgrkK* zl5C*pNXPWF44F(kdaRTrrQ@aP5_0TVy||oYj)RPj)Qedp{IyKFo}{GK@K=6fa@=@H zI!R_^=*0{&U8*PTB_!U{#S$n?Qy8Q~TuZWOyq+|}c&IZ2(4_tghEyW?2*Q}@63IAy z20=>nq{A0uNy&JbBuzR_I#Ud*bAf_r3XNJO#@c0xVHqbm7&Io*rS>!_6H0)35)w!{l9FJXSkzNyLKT*no`yiNbo>?w zgMMJLgK^mw{2V_vIKZgv1cw{#)7Y=w@G~voY@sjUQ5$tL=7LuS$ZU_L)s&!^}t1G05|y$J?3WXN$0jC^AjVF^9;d?FY-I@0mk!6AHp2+niZGOJ~Y`K<`PiG1W^k>bq z1^Iaepet2im0wt(#S}<^jnEcUX)R9`XfFW=F3A95xt0Z4+&0K*^~b8TjQmrV^aZ+n z0ve>XJeIF5I9r&1TAL3j233%+r)UCIpwpuKI$Vx|(gq|^kXNOpPB8NeFiNN8QYZ7Y zC-Vvl^72k-wI>c^JY;lQqTr++it7rXNd*{Pu%{r8(B{<`kqD$S&uRLj2IBrF(; zz^^6P@UQ%2k%kUh7@}C20Wbl4&p>5glgoPHnF&sFqd*q*Au$MoX2a_|@E#ie$1=Pb zMZyA_&&_CK?0@6z#aGGwd)rvHvIMC%34P*H;0)0|)Y+U3>0HlrT{JzqFZ~d=ICe)rg8ZVWYcl*Xqm;Tc_>F|z=WJ)Dxf>->CuLgy9CuRtz zj2tof?v#rst4=JPaW8Yug%?YwxH=Ywz(12-ne?Fa{rTEW?;}gYvPT{{lFX;iXiL-d~fmOW*=z7I`--@1*kdu2b84*7O^9=hq$Ez2BQ(2-J3Un0C10Yi`tv%l&in^k&4k)*UBp z{V;g&1V-nLxgItniy}C8%)OKUbXc&d?tZM=Iq1y!#~Y?^e)4dpXz2aHShP(Y%W@L_EecA`i8%6>l9+~svnT5 zM$>EA$z$xG#JF*9eQyX{I2 z^}O*)8n?QAtKhXE^Y4^U)|>ARt=)O8;LxnMD@*(HZ?rZ0%SuC)eRQ9*db)B!T(_=M z>{Av@kJ782{IC@bnf~UqYW&aXvwEr=-q>%e^?sZrnf5Yscv%Oc@Aa1*N&?rcS+ybV zOzE_eAG+Su_MI!6u`aiChigg7;2*9|xeCc*h;vb#~Jgw<}Tm+a8_q`s~*~TRK0!UGS&s%9Ml2e>yI5d%Ek( zua^sppGWTbBEIBqZqMPB=X$=Pw%zl|T*4ogd3@&MGGTF6JjXit+;p3%T^@Y=ZqJGN z%c6(xo89}H9p-z_uZmezo^p@1>HCu%2VK1}=*@x(=E|?P*^Q2LJLWesZ&IoBQpKS! z4xi3%eR0B0p$R9f80T=G8rP4GIbcTU*m3q;wU-;K(9yY9p~mtQ$!c?| zn}R*hZuj_d%#(ofi_3eKw3a#bROj!QvMT z4so9hC@b4CIo$KR%J$=KrDqQxRN-D|?I;>a*j+zR&iX z9y)bukB^qM2mko~`*D899dr1d_c48jCLY_o!+ig+lUu#EZJm5|gdkYuU9O+%`s!{? zeo;QUFlE4diw~WWV04EU+xo}tj~zQ3Kzws)*o^nNc#OetuOxLQfUu&2o*>2O0E`#I zf*2@!8uEXSz~Y4nXoyO!`0PwOOer9&07-L-Yz&2ok&XK}D&F0Xo4oz8mClCHNZaW;5z#<3bWM?bkUs4TUS1{@b zk}cFmf&?;-_1qx!p9@`;Lp`L-Kf*MZzV<^!%}1)3GOw!N&f=Ml?q^=4ia;hp}+Ui3^HJ#CasG+FZimEE8nXRwZ zN#ch`a5~*@>_a}siUfEU}CXmW4Q37o_ayKJ@3HfX5V=DthDrT(dGOd^S`d5 zZgli~M*)p^n^?(ZbjYlL0-4+k6!na{>c@RVQBNsGq5mS7 z3cq~~CgDzTlk|Xc9K+@M4;2p`6z|P-om@jb?H2q9VqA9r6I09zUAbMiJgcP4K3Nq!35K z^juc>$ebnX^joZ#P0#Gzn%iR;nC}cU*-U?Vr99rVmTT?SDQ^6x-*r^g`krr~;TAP8 zF<4Xj^x@<3I*L@)lzj7Q9k6pfEZj>2QXT8SAdq+QD75YQZWRB>I6i8oeuKo z)k6V_t`(q{bnYtTVj*{#&K;pcQjkPr+|M*_lOZ})Az(xaF?KDDU0iOAR8Q9@x9 z5N6VZIXDPq2wc?&tfGa&7=a)%DoP+2Pm`x$GK5ATlBE-v136X@6)TL^3s4$OS7CY$ zWql`85DBwgv5_%CVWdughSAhvbRE!GocZZ^At(r{LYa{?#i)iAs1YrU7C=H*l}-~IwLvc+VuX4DBUTs#nm_~v z4BW^9wE}i5lm^2AbvjKo8LnDjMw6m|w2&qlEv*Ma|G^`YzSXkdB&8@Pg_DoIA#kSHj)krtBCLz7|z!m)d+b=WDNWxf{JMke=-ijIjA zMD>Xj2(X8O59^Dze5LuKce%i35Gfu$Wax015|pnl0#|-d*;o8^G4H1x>((w`G)6&B^KS zalftu6V_F}ef6da`nB%PUiG|}bib~+e)5OIXD{8n^~agxJHEL%%*hSKOQzbxET8NlZUX>x)z~Fv@e}1hD8V6 zAe%>Lx0K^BC?u`?0k@vU%`B&5q7VwS5AFomTpF8EZj6vtA*N$6AL3-jzBdZuh{k|v z4YG3M^Sxo6rMo)=#nI(bFxe3E)FT^$$LISnoq7bff(J`KnxPkFfS!E?0>s{YzAxL0 zA84lon5Oo`ROs0UyYl(|95;TTB}AY+Xp*0SWL_Q154J`Dd^b?Zxe4VhpWhy__G-x(;KX^K$|D^SCg?}<=rKHnOu3ZaPu4UMpYKrlR5cMfDCMh|{F zAor%pjZ9F7IIQmO@WMO41CWQ%WRvMWLbT1Bg>3mwKqG0I(by2nv>z~W@dz&vZ;8Cz z^@zn9xb@&0x^EjUk{-D^AJl4d+P8AHv2ktREx51v3l3_ZR|q#k=-Y*F5MjHrQp-3v z$pT6jXv=8ylM-a*5j#>fPAVNcG^Udcgc8qds|%-C z$d)}al4HZQL>9qdsD2L&o%_OENuRDZ<;X^+Ju+WCW#N`Q?GImHFm&#B*MHr!?yE_; zO6k14zaCt>_-Kumaq+=NXwVZK+?bg!wAvya#s2X6#fw*EHPExm3*bQp?%1VT?b&D5 z(6e=A_fB1b-VZ&ylVTS8w0Ge*XB*mBQ1v-s#{u z%JM@=@%=kRx9=6dfWRVsyM{$MP51Zzutw-T#K8Z)MyLkD!t@#;;&i)O2*VP1kr43^ zTm+m1mIpjHXF$@cj zSVth@ZfpYU0>s$?rWYYWJoS_ww-^>8F)HuzFig;kk*dD3)?pL1gXKuXc`y+ev0*t9 z4Cy5+f{7Yf$6#+-j)t`bvJ9lph&N3T8;S7$(69aBt^bu&X`U5{SECy*M2 q)~y?d*3pZG*t&J&*gAUFG`P+&2G`-c5ub^!>(HZ5qU*J^C;czU!@aox literal 0 HcmV?d00001 diff --git a/assets/java-yt.png b/assets/java-yt.png new file mode 100644 index 0000000000000000000000000000000000000000..5bc1fada0c118a8c111dbfb09d039df6426adad4 GIT binary patch literal 4345 zcmcIo2~-o;8V>s+NI+1EqC-T);*d-dvH?O!ghWIULlLRyB$<#rNG2wM5EMZ~MT-dP zLqMsrxZ~DhRS+x+MMS6~?xMxLh(JM~Yweq`)xM+E_xhT1X6DYFfBo+F|M#A(37r*W zZRuo*!{My?JZ>2FB3DKw|3T-MtCP7Rhi9v)YAPHiTXe=)}F!&>2-c(`7Dt7^8dN1f(YT>i4jsxDAY+gL?h!JD7}ct$=)Dap zAY533_!7t@G6a(7AVe2HUMvcOC!K`=AaB3IO=iIW&k# zqk&{ks6X705Efsd*1!r8!sq%Duv|T5GBJxRBGX|Q7J?Eol@5|2st^>4M3@>`C=yD9 z5RHb2hV;3pC|=JWz5YNciBS<|?Hvqgh~R12$cd-m~@Ct5<^~O z5p~GgY?TbFW;pI$tNN(K`lzS~NkkG+LAsE{1Zfb}3uKV!3=l>jFPfM{hZrP8Uo-tQ zWbtHbY>jn;RX7(}JUEJz0sYKl!6JP{`4U8WHXvfc;I!<0czlZIL4B>%s3HMTy%W9?R>4>!LsV*Cf<%SNfnmk~8Wez)$~c(_)+bI( zP>2Vc#qd%QKIlgcC;T}?Oe%#*6O)-Bg9ej9GKES5g$$Ym6iUQiBq~G^!a`&S;`c#B zC9%lEh4jBbGzh;)3M*m|Y#Si{m1Gz~CIym+K_-mdgc2+nh7dupn#Y(=B_lLC^ykUE zTk3yvGNO+%;3JE!=fyBdJ`9=|QOVxnz`Hyf4gu(A-2cblM;Z5NO=1Ml1cBm?!;*}sdi-q&-OpU6RMTVr7zcen@tSKV^ZKl)d@uD);dC;rY^ zWoQaJ0O^OrCok+}`0R!#uu4^7C$o|14x@26(+WP9Es)-NQeY7$nC@7=D^+D&^d#DU z-@gn62L#^$;_fz8?)cX4#_iaD<7nd~z%H~FcR}j0`b+jH+x?CLpNuej{MFN=SIhu@ z!4(JaLYbfAOM`=>UcGGUT+(RRcJyF*aOP0y42ZZ&%v;CfT=Yf`!X z1i&`ioM&7LvP;L4(rVLISs8$zS+h2*FUYz=Y(JjK559a?*XP`u`%kzs?D7|!&cwpi zPAi?#uRt5>Q490v`0s00x8s6CZ}jvnYqi*9X5tcN-4W3`jppXO<+?wwHF^0WGyc_@ zcD&Qgu<)WQc2ULw3o_|n>rw&ZLK8|3->m5Ho1fT;J6vKXE$`7S-cx0*XoN=H#-MVaB*DiM6OVbrT%Bn0MOH-p?_C(@+FMQ|6Gdl)5;g3bn&a7cmOAmzymc|>A zv@!=?Rgq2N%soPRT$q3E5zA71Om7P_m2TPn_-$Y^wKeZjXlw^@^n9d-T`r!xkDY!u z&uF_e`{{}E_2dkvK9ccT+t}AR_SrVqtcgN%8j>o3Y zUfr5W)xPL83JZALM>Da_irs8*x#={wYDwg}v@NTQC)8SB1f(qq-0m|yeTyEr6i~_w z7fPKs-^uya#lSY}c9zk(%a*3>!YOrT?T~fN!}`;Ya$LKQ=-jCtNi=$McbNa)087HS z)gIfY{W`@jLts_XT#YZmQ_Bo9)t(IV_$Y>dN5}UY;XCYBsYaV{vi>R6qr{(ZSKzVJ zo3A+>@x-!4^X%-Cd$h@Y2PYLSMW{jCAD9!yxqev`eq^kVjH4?NC9j#yS(|&wX&ZjY zVxK7{u5k^~Xed;II*orGwd(HDXxY8f`#*Eev729c>gb!m!}+_Sw+DAUd0tlYrq2~R z&v;#$=vrn|>n5K}T?!->AH6*)`hhiZ?rr~~BXcczR~OFNP4BRpVs-X)^`(jPPN5bf z?TR=5kYaVACpys0XWMJCk2m5_)>vRTc`9F}vYuQ0xhd%i@rgD|N(EEn6ddu5-OFu3b}i2%=1= zc8p2CTk?uxW70ACYwsQ-lb^j#=cn4WEj{M=dEVIzdo+PCl8_^qCwTY_rBx4 z>a$BaqbzOl>GC6w&Qydhw+~5b8^f}9PwBOE&oAFvsNPw&sywYJTiABGBb;V-VgqIM zBv#dPVu|5~8P&au+9ssYYuP8pYIbo9?p%mp4(2n@^%&Gub~Su;>!!=WJ>Pn5<9gO-22`{lZO`*&BpG3`6K-ykxV zvaxAdKtpsM>$v^sdthq*%iz4t)amz+CS4mBQXakFDg5j$H1P^$>{T}!KEG+YeL_T| zKlkV}uynHH8UOV1?W$|Djpu)3{><&Si#79K%{^66W@t98wz*z?yVYh{*S8%nbt9Z_ zxQUZ*{#a2tU;MK?K$P-@>cEvvH`xwrcQYm%9y7^4E@f|W=S9tssY6C(ZoKj3jRw^t zV9R3jMrY&3jFx5YkqT{QgsLmRZOg*1s*W@|e ztmKvBxC-rOi_b^-oHNNpz0+#vn19X;`cVo@Yn6765M~FAE#qW2oA+9!mDPMR_GY3i`P{o7C26~aAXvLS47ZpTNv59)HzMvpTp&>MwP+yXYsi`D89umduZko;R zJ`W1}JuUy4`Oojie|FiKp`oFnp`oEcC_6Cju}#~MU{KJHeu;i911lZ$2`*bZ$VI^g ziHLd3X_;Sro{^Xi6Xt3+5^33Qx9A>>2!=3(Vf2-mumB5~!dcNYCIufD_eCJCH)vfW zai3AatJqt=)>3>bcsQIinb(+WBm9}}N^te5I=$CXuE4O>_jQ^eq7W-OS&ey1>xyc#Y{0HtId+og-)1ng)Qgh&Eap|Dvqt`A@BN(ko=1~o}95rMfkm*+3@wpj2-68ceSNN!KD?= zmOoor<)`VD3cPosVxn~jeoTk*Dw4aoFU-s&2Y2!3Vx=^fBylDk$}^Jbv?&%ZR2p88 zjK;i;RkezAgB*=nBcGeWxo+qw$+=aHYseT0B!V})qp1|H2am9-h7acy_yoieiVA$D-5-Im=exB)wHy_JLPtLj&ayhH4^_kH42 zsYC3IhzD%7WXO_13}E1&>xG~t(W~Y1HG>j=Xj#m?R)}UrXUkqIG&D3cG&D5eFXZ&M U$p1FVj{{H^)&Q53&FBdGH~Lx3m5o+7|uhx0F&K=m>=R{q)6K^o5D2=U3*i z%HQTbSTnT7;0oiLc(ag{8LJ>wiJ;wes>creX47+Hw_(lQdw0$RQ)_gk?+*T!tzocG zLwHrBP+7cV=!|rMg7%${bx%)xKuOBJhaVUu;ms1ic4Ux}D|lmG+r}S~0=2Mn*OoRH zYS~LhVZMiz)UvJNSpj|3ed+yfAl(12Kj993N|14Nb_(M}CgJRPlMFjO7N%c(Kd|wS!_x|5}&)S}>_%6@C zWt*Bi8ylj_{P*HhIKFfB7 zC`ODuQt=sOX+EdP$znxzi5teQo=51(+H|N6 z1N+q7DNO5A3(M(g&nO;4TDs9M-9!iDjxu}+wD2&>dD7utz8=0ezD1;GR zgsxY2b!bYBk!lnpRHs+gnbv~(LAaufH2^dT^Go*?pb$;vXj`KhiAmiS72F_9*>+nEwZ9L9&y&F&DR*y z;_VFzYQk`MLSrm9+p&lck+D4Okv=h7r&TZWhN6Lx$`9(1FXaTl;}1CdP@Z`N?++KD zmepJEUNzwqYSEq?jz%760VCfQMVBeh<}U`G-&<(*Q)$sXYym8o2v z=9W{?1jCZ4Lo^B2jF{VEUtL2ZvmQp;1=;ckFw5^%>?)Qa-F<4#%Znq;#pCI#^)kcO zNlfZHB{I27m^d>2-c$LAD{o))C_ z=Y+!SQs#F0_L!-Siv}X#LImd(y|>MgX_-287Rn2x!}YU|H~#v5w|8(8XZP~KQ3(PWkF&R?jA4^PC0%J^gE zPY9VRZ4}NBn+$zUIZ-COA89w~k&B_rwxI^{7vD5$%`Ko>t4RAH(*>91Tdh^&IkFY; zT0mf}`MxnaJmtWA2Ds+SZ>i6WyDhS&*{AoX<3l9{?;6yt`MXd-ez`m2JR8(zqH{y} zE92gLgZVvU)MLUHbyWyGbzfn&g_IDH6>FNrbRIcWjm+UUp>Edni(3Ux&}TOsK#aQY z!Wtwo{rvSC$;Z6A&u9CWhztSrjn3^6aRf+Pn*Az_rn)L z(&L~W9)|y{A`H?sHe~Wxxk3RD?G7F;in+Aq*43cTyvN2u2Z{>I#xCESon)VOI~0w~ zD&M*72kQg@nNNSn4QY-39MG|dG=b~SX#khw>9b<5DLt+|?T7|ys~g$yh*s;(MbA)$Cgx{^kS^2`A??uO#3 zp9)!l14ebJ$l&`!|wcds4ZLG0qD7{*X6e3AKVjYnbUF<&fz*42nt}B(*yoF67;0Z zj6be5cSnWiP85qXG|rnfZyV1YsFl$Rcuk{e%|$(?LW5W23Dl(^CA{)ICp6qPYzjg2 zOt@{r^p*L_mU`*p8v(YzTO{G~<>gll%_z5STJe@6I%D}g`&S5O+uA^i!}4O08o~@w z`?%x{d!E3_0i1FgWR-`LOa)vECsl?C8PT4L@PawjJeKRIE5ftvwchw;K0D#olwc=?^?4kLto8(SJqt% zM|5QxM%-#Ukd@f{ob(s=OE6MluDIeD)Q;Ag^{F`4Ya5%4l9PoZpB_g{==a;XSwnFO zPH0mi0WWUlm_-Y>vp-)ZgxMw#4q@9`H2FYK;oW;iCmD5<)A-LDvHUjn++&X^(+;hb zYMQ9M6d6e$9>C*|?TTx4Mw@n?mw|4N_5{CL$D+so{n=_;1EIu!%oc-iCAOXygZnVN z1HAKwLpv1U;xYg5IbFr)c_5Qo?# zChV;UN%nLQreA#D7gsR?A`pLcHkxWqgZV<>D`Rnxic!!u~dJE8Z#Nw1J-_h{j0!u3WY6)rUn5?Yd- zggfd8>49t1=!q%&NgC;o`20b+{Oji_ z`zSxUN>sn4fQD|0;%v=amy59xJGo#x^4rSjqC5qjt4W1&@hu0|zRt77`dwC&QQ$O# z22o&4ns!yaZyD*Y<+q!7z5Z%<>o|vMPwCqXYC_ZIo+vQV3H`Adu--DBTqte3*+%;v zd8h1ePw5FG4BCyi^5*CLumJzL@-eN(7cX9oYdO$}Li+W0?C@nqBE#(#es~+KT|jFG zC_$1hLC4)hl%^nk3?`iADe9_&4ZhVt^p!`%?l!pEa$vv9CA3>;?Cu%@_@0*Ib%=k% z&{Y}?dg$R6+}p)I%C<#{mAsBbYNf*cF$seUc)hxZ5>nlf$ePhR5JZTE8DvpNwLvf}>!rJrddLlHe%Ucm@3wFD}vz*C&7n z1-ujBKdJ9(d;`cCh4k}^vsMvc^H@EkUq{D|#(vQKM8LK_Nmh%UH;OyU#($2kxLi>WyoR!d-o+V^f0hm&iI`zfSFojWf9`B|-Y6;(?d;U`tSsv!BO8O3G_$L2{8(eTL?lbbY!ne@050IAJ#%A%15mP8mfZzYVaq)_#85Zr28G8HG z$`PyMiv&99tWfIPv+@Ygf%kG}j!hi07n1<9I|~49f9HyyBbq? zM-0ei2KMpxWmC$XJD_nWiRobuq*U^0p^;51X}t-Fy9Y_^NUN-M0IH1vS77Wkc6|l*-FZK1~!hBn3ei{=^p2rbTGH|Qmt9U(mH91+_ zk#hMk5a+>k= z=3ZK`7kJw8-!D&r4bqMCn&;+VuQhq*OadS|rm7>B3o@YFA*)NOmg|m`mMAy1g0z!n ztgJK&@TAo0tsZmpYk0lG@;)XYA%iM51K(H|P zuCYne9qq%QWLC99UapuDVKYronMD*UwT%0E)F9snsOn#$W#9c1m9wK>n5?Z@V;33l;gJ$g5FMB%)l}Uw)xFkTc zOk&bWp_YeStpMSeQCoj*;_e$UfI#f*AWQ-`xDGS`>KIXA&11KH)E!J&Sw@{Zj3d~w z3d*vS2EL-~M-SI+pBKPYMBf9!_`sR*bf8h!VaJCM58;}9JlAz zabDZEKOK~3RIX?v4AX#KVKAih>BRUORHFylbX@X|24hPq7Rzh}$HUX6P69Q)E)>^Z zzWpjI-TXb+Dybf%ffvqKoQ1-OoAPfpBQSPc~MaL1k`alG`jIi1{TFtDaD{T+2ZSdSW>pC__=~Hxg8%<>|NRL~*!JMbV z-Nq=(q{PJC=wyM{=f?gtqkXdNYdS0Ex?S#4EaWKJ*3GYV>AS!Jhm~SqxD6%XKPk() z9s+Ia+%^Qb)KmD_rA&!uK<8`E2*JFc=AHp34z8Ck#5t62pV@vF-AMX#`Q0Wy)HtfT zjP#T14WNkw8T>5vul+7_$*2aSw9y3<8V6=$anr!nu9_6kw31pt>L3La^o!E*h~nkg z>2(ZR8O?{;M{!5N7?8_ss-j|(P;*OX?kxjj+^e{`eL&3#oxfhbEsny-QO@ykJV+M= z!ku9O?vn8rJEX=K?`VK@lECX@85+Ich8drr!90yEUx@r1?WtmWt4=^J?n? zdvaA0YAj0v^+Qy7gfXhdDb}DwEb-h&Q7J({($;&c$eWsoTCZa#AmhTk2`?BNdV@YK zOPp={frx!8lG9bEinOVPU|PHFg5t8~zZgw} zmNzJM@-#P_+39RC-vUHo;J~y>4ge+M6mFSE_=cgnD&o=ZI%)`2g;LJ;e^nI!twjc0 zRNASMIHL%ymDi8H*xFBVvJC!NJZ>fYnA(>x1bmeP_|vUZ%?7KwyQEr(6k2fQOEtj)oq82MS^IC1xf2 zSKqR!&LW_m6^E*->zmq$nQ=;=Tgp8p0tF6ETwd&-1Ep2M zX*r4t6BAPj^zTYBr3bhI@ADLSUu*`)P6Ps6`gb^#7<5eu?NNz8l%f=TelEN`MRMBMaU9hj?oE2t_GS_l*dKs73DgQmM6`pXYJ zO2P}gUrtCbs?Y5vx!09&3Q?8UK#A{ACJbcHcKQ%yYEp+@9Z?fa^NF?Hast)pH#tk) z5y1NeO$F6(Y{`Kc>kq63s~B2(-JGohAkM*XBntMRjj9P<0Wu;zxmex<&d#^*KPIEd zUdlbjQ(2sA0I!i|zokaIk7W%2a7RRgsZD$}4PmA9jT2IFTz}ivh$rsGj>R-I)r?KBqTTQ>&`)EUzfe(ocg!mq-t`;adYu4<3qrLIv1)=>FMC#ePidQA5iqz$bTA zlWaaEq7>4@F4oW9*C2aua*AWUm}Wo+OKkF=M&|%n--Zy zbp>0)@Ezf3M;O2*VmNzc6jMh{m^Pal{ggzra7J^BCbNspX#jxc!O?bbvO7`yV>!6F zPZ=(~*=p{#uUIai82}LXQ_AwF^YT*_uN=;Mb{1p>rjF-HEw9hsCYO`)3jj)B zHSv%arsqY0+W?9uLdKnET%p?l8Mky~J}TxqGU(e^t4mIG62#uQS5sRWEbPcwe@`0B zb6$R>GO9+7G5=d0XK0a2h=3=`#&Vr3@@AurU3?-MPV`i~{!U0jb&vc9MsKK$sy1jB zG6VWZD9_(0`*E}%YGV}6u`=N|&hja2W?Fi#F#5waki-og6R@>rr_C+Z!fu}@UxjsS z`=l_T*Zn;oa9C^wG4|*0<>T8SqNfV=)nea>jLV3lKE%|M{oPb`gapPbLyBQI(8H>k z1+O!{;r{PKufXyh&H;B$rm70j@F|TkO2`itvMzH{C5oZ>NDFm6`$5A6v~e-OdibuD zC}ypKrQcAf{pFP&C{N-u;^R`Rk@M zqs~7ao*2z0c|6c$(B}xn(uHLzX9wDg9^M{@k>EWQ{8t@s%h7sy8%_@E z8;Q*G0BE|Vti8(py}Co!Cuui&M5)2JI}Do05{}x$&N7 ztXYhot>ygQWddGFi?|oyv*gDYQ^M5kOdiZC+Ga&xr@jW~xWW26t2A}Q^N#?`qEW_Z zu#|H(lEfEcPWqS}!h|~cYrnBA!#;94Nu-lBM9;a*--)v?$%d+`nK9F9mY443Jx3B_ zFZY#{Z@uCD9-3kOM<(6o_K>AzcIbOfKKDCS(M&Lt{_2LFq3F3*kE}F{>r!|Wc_qts zBqi)f;YhjS-HucH|1Vy}EtKm21bpH|{|oSc!SDaY13k9AtF9G2Hd;7`6VXxU9Dc7n IgZtxu0qYuu*8l(j literal 0 HcmV?d00001 From 911ada3139a3bbb3a61305ffb2ece2595b2fad2f Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 17 Jul 2021 15:44:27 +0530 Subject: [PATCH 119/947] adds java yt icon --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d26b071..6c9ac84 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,9 @@ 🔒 = Subscription Content ## Problems -| #Number | Name | Difficulty | Solution | Youtube | +| # | Name | Difficulty | Solution | Youtube | |:--------:|------|:----------:|:--------:|:----------------------:| -| 1 | [Two Sum](https://leetcode.com/problems/two-sum/) | Easy | [![Java](assets/java.png)](src/TwoSum.java) [![Python]()](python/two_sum.py) | [![java-yt](assets/java-yt.png)]() | +| 1 | [Two Sum](https://leetcode.com/problems/two-sum/) | Easy | [![Java](assets/java.png)](src/TwoSum.java) [![Python](assets/python.png)](python/two_sum.py) | [![java-yt](assets/java-yt.png)]() | | 7 | [Reverse Integer](https://leetcode.com/problems/reverse-integer/) | Easy | [![Java](assets/java.png)](src/ReverseInteger.java) [![Python](assets/python.png)](python/reverse_integer.py) | | 9 | [PalindromeNumber](https://leetcode.com/problems/palindrome-number/) | Easy | [![Java](assets/java.png)](src/PalindromeNumber.java) [![Python](assets/python.png)](python/palindrome_number.py) | | 13 | [Roman To Integer](https://leetcode.com/problems/roman-to-integer/) | Easy | [![Java](assets/java.png)](src/RomanToInteger.java) [![Python](assets/python.png)](python/roman_to_integer.py) | From 9309ef006812f1fcdc9d2f0daeaae761af001635 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 17 Jul 2021 15:44:59 +0530 Subject: [PATCH 120/947] adds java yt icon --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6c9ac84..47d6610 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ ## Problems | # | Name | Difficulty | Solution | Youtube | |:--------:|------|:----------:|:--------:|:----------------------:| -| 1 | [Two Sum](https://leetcode.com/problems/two-sum/) | Easy | [![Java](assets/java.png)](src/TwoSum.java) [![Python](assets/python.png)](python/two_sum.py) | [![java-yt](assets/java-yt.png)]() | +| 1 | [Two Sum](https://leetcode.com/problems/two-sum/) | Easy | [![Java](assets/java.png)](src/TwoSum.java) [![Python](assets/python.png)](python/two_sum.py) | [![java-yt](assets/java-yt.png)]() [![java-yt](assets/java-yt.png)]() | | 7 | [Reverse Integer](https://leetcode.com/problems/reverse-integer/) | Easy | [![Java](assets/java.png)](src/ReverseInteger.java) [![Python](assets/python.png)](python/reverse_integer.py) | | 9 | [PalindromeNumber](https://leetcode.com/problems/palindrome-number/) | Easy | [![Java](assets/java.png)](src/PalindromeNumber.java) [![Python](assets/python.png)](python/palindrome_number.py) | | 13 | [Roman To Integer](https://leetcode.com/problems/roman-to-integer/) | Easy | [![Java](assets/java.png)](src/RomanToInteger.java) [![Python](assets/python.png)](python/roman_to_integer.py) | From 67c32e3e8903ee7dc9fde382349cdf5a209a53da Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 17 Jul 2021 15:46:50 +0530 Subject: [PATCH 121/947] adds java yt icon --- assets/java-yt-icon.psd | Bin 35596 -> 39022 bytes assets/java-yt.png | Bin 4345 -> 4342 bytes assets/yt-45.png | Bin 0 -> 797 bytes 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 assets/yt-45.png diff --git a/assets/java-yt-icon.psd b/assets/java-yt-icon.psd index 5bf3f411eb58e8eea884b6529745a9f8b12399d4..dca61263ad1845ab27b6e0723e99d97083953dc0 100644 GIT binary patch delta 6805 zcmd@&XIN9&w)-R@ks>IH0@74$3}9%X$Vmc00kNP62ny1Iii(0LiX*``Vn;LA;aac^ z>R2cv*gz#V7!^SoESGUaDV7mXKw3i1x$B$+)Vc58Z@%~4_v__+d+*iu+H0@9)-Kt( zpV5-f$QX%D`+1ZFlf`qh=Sin9JypO?rouAPHAd{>=wNRX>EP&K6Y16-`+Gq*%PF@Jb7wR-GG8qP%Ah5)8Zd>&i6|CjgT(LY`C&}KJ%ba+Stvx_Pcs+xcOS1 zSRx=Fez<;d?vl4gUWqSDl^>#KDh*!We{}uQ#nilpBfmQxkuTM*2oiv0S$n!T$_cnY zh7{*WRCAx$Y&v7Zqpgy;MRHse@IG&yss7l|XKRQm&g{26O8WSk~}Z8 zcJ}%4rRDdEN0mOFxA<`jmoFVGC(%=@^Kk{*TKRGL!>+$)XG?Ab_mn(MiQ&Hb!FJ39 z!-kGvy`S!t{B)nc@W3A2dPQ26*4DvCj=OYkopz*4Z{pzAu&34Yw2LIuFC6)p?8etP zm-s5yw>|7s^}L_o-?(_Gru4UE4Z-scF%MtZDc9k@Nz85#cGZn?^ZPijHLuI$a!Jb2 z4qwZCPuB*Mk3Qv|-O@=MPPG`BdttL<7IW(rsq*O6780HPJ#Oo;65XfXs~xYd?`R3n z+Lu$Fm{H+jSt<K~)Ld>(H5IKP;mw@UZ#VUMd4Qoh4mY$Y}C*5wH9t}oO+ys-1E zx3qz6eJI-1{CMOPe$$wC***K1H>vh3>pC0ndlBC!CTN_2wieAjKeWbVC*@$u8!^sW>Yn5B2Q)_Om_L?XUb`I&RcEebu~ zld`qRXM6;AbDk;wCbv)7KVy2(4}$U4zPSgiQu*8j-MsZZAq%pvoLfR{u^~}Tj$XtR z&xD7!{npNy)gcKAvA=0MzvphuhB9*tmzb!e-FAYR9Y5FKa-IBkpTBb4j?_IH%j?mcoBmudk4MhXWcqrD0MUs$aK>#DPn#woq1Y!W(LSBF%9YXxj#x$ z4>t;ES^uTeVh~~`tymg84dj`YvCd-HQDPlz?0DiB8z-(KY%Sa3GFbWF6p z7&_4TPwfHJAPgZ?)K5qmM77>&s`k&g4^2iwO;wA8K2lORyx>fPJ~nKMst?7Py>L-d z%<@%H!YOI{=Kn0QRY?o^>h=psiX!|!Q zUJCQ{jz!K$jAEd;pjhMpD`tmyG{pv1jtlE&541>tqM%STJ1CJrcSh0BFBeZxS^$Pz-x_Y%~8G6=gJw8aPA2D7P+5dIb1sM_6|Br)dTQv8}O!E1hNz%&b^!~gX zAbmYI4`Wk%0W0)BE~bodfiv7LjfU9=5X4EgRH>*#9Z>SP~n<0y7UkbzlD2 z14eNpVN|L&7h*pWG&uughaw^7M`ANnQ=-FGJuMnmPwhX_)zhS9)KiseM{xhkDhswn zR5H!J_B`y!hG-blL0WJuz$aZ1GeSZ`G_D1lVaTu>ahN7|f7_eR`8GK&)Yo+c zvl|hJjS04#yj`bgA=!#ow@+^2V+0}*Hso?0$-F!SHhF{t6V(0)hdPjky=l4&Ei-|ZH%1)b z>ZnwGP^&Ii4|N9GzM=Urlsjcy5g2y``^scuBFu`v`Q)uva%xs}>REvg7{)F>A&Zk! zzy~SdgQ;#N-~)t7Uy8>_KZp$^HRS*H1Jf+fKzb2ahz;KWaJ(*1^q}th^k__n=Bs41 zfHDT$EkeCG7AO%a`N&<)C*4{6NdnhECC=g_5uzq1LiPO!61~J3G`SXMz%}AIPP&us zFL07i@}YKb!x8^I4vFd8jx&~B4`^1yta!33%ku+{+>odpNAU!SHKYRSP9eP{c3%=s zb%heIAQ_6YKA(Vx1QfT2WVG%Tbl@tii$v!-zvMOV0Nz*qCVkc#Mk(zdu|D}DjwVs2 z^_wH44PAP9rUWb%Qqq6GT zJ_C1mC-|7K-<7aVjITawrL^D*rVZ;Qp|VH^J_@DsiT#x*qXvEXwL#?kf!Yv5aK^L= zT9%Ofl*VZR2noTpzXg7vL2zvGH?1@XUX}0FYo}rGXwz~=2MvQi_fgO+Bn0xCST&gz z*HwvATC7xBKzGeFO84gh8T{jhlnInUUz%7`Fm~|(Z7DZtn6p;7YNuvbEnPgt3t)~V z?=Nip1?!Vev8C}|>|o~W{*Hg~uBi3JCDazJK=EiHLM!4IT2McgHB3|Kk4bAJHh|d- zU_*XXnc5vAa`<-i3r_9o=BkwV`5AWADD>``YVV1?L2do}{rnc5{|Wa=F5BAyZD=x?RJt zziSt9-a0fq!}5-fLutmclY0+Y9n2W+Sn*8M`3rIWmo<~$q&YP>{;K$XyLRo_Q)NYk zA)?jqZnnKXB5GdIF}Nu%XlnAY2XgL#?8e3VGTjqZp0d_>!ybeOTV(k^bqshg*mxJ# zKJAT3Z7lKAnGIQ~mle5^6@w!OMW0Gow7+8ZkcyBreA$-Y8s)4)Go2v6%f34X#n#+= zCFS-Srz{sf;9W3wdt7=fBvd=$Q*(0I)rkui4{rH%>)A5N+KmSF53O^gn%1vx%Z=TQHom$q$q1RClzih> zvQt!0XxS{8=f5$y@@1^~x2bvIqhF6bY$2L)?c%mP^H)zMuW=oAHR#3kqJ2pb?;h*y z4BxaDn|q&a9c0;(ICDqBdHcKiR(XkGTdQ%yqB(0`-i!{JwvWd?)S0sKC!dnT-#G_t z56>+RWp)OJfAl?FnDl%TyX;1ptt98Syrt4siyXV~VFr0`pY1m<{xtMgpRxBw%{g$Y z{NqjILSO9+OBe0zd&e)>O|Wu(Q=OmifqOy9a@(#bjU`rP){SVKkgsd)|JL?&a^~}l zqY2;tF4R8$tZYd2=+mM>BL6oTg&Qp^Ys1a%h@!Km4D0P|Qw14Mf{L;H%Pgy~L0bzr z>$Wol)aIl*&s7J99vTYx2xN-Pkr}kcP|V;nh1L?j;Q$-b7)3RdK3qTMPdcbWN2P<3 z_^gA{XYwZvHnN9g6O{)x#03ajaJFzx+=c@WiEdI(Vy!FdaBO93 z52+wAB7r&>aXf*L1Bxo^;0Pgb^oYhX0rLbblg3i(aZE^|>u59vjyE{$7!rYqB1X_e zzfbg$*?}_!B9VZ=vB`vj>?M)B@4V{9HH9LP2afXvf_F5lwf`)Y<66M;#08!rAzn)} z-}arY;RLS3_XIBALnH!wAJXhvU`yb%)q&F%r~2}t;)6B6(CnwGvlnaKO^9HUpjL^a zn>6bY#p)&pe4vcsgRQ{1{$(f4<{d!Aao_{%ZvSwfM-$@IkbDUYS533~jSW-cn1_hK z8J;2!;J&1}ee7+o_zra{s3oCX3Wqy^YY1lqhWdLEIFpZi zz#_4xUSGednvhUJ^kOJ+Lysu2IB>G3r%>qW z4C1C4*PkmEM}$b`hJ? z!;(23?YJ)Af2u&}H771@XC*_n5Hn-b@>`W8c8wrNsoUn_zC7ryzjNWl_vxE@lR2Bx|90YHX+y6n4`eAJ zlT2AHh|Mya6q0g7l?P4UbqMorQsseHJz_BtnyktLSsg+{;m@U8bX2dYM;PN9K$B@S z5Kv<~Kxfma!zZ{nv>^#&kkdFI+R{Y*PxQs612OfTc!LRqX{i#SyIp;<5Z7n(?^&CZ#=Lr_YJ2WO&1O4nIklU$CK#5aAh>R-&QLE4Zy}bFcHI+Hxk%S zXm;O3Yo;j>hh=Sq&=B4j;5O3Seh>8^Hq(-Yba_L7*G}gGgw!VJ>9*om&bztl@Hr=}J3f zS_Nx014;6!td%COX-3*6p7RppVq+tMJ;n_r5GR==D`j0Y_eK+9*qvS=M*}RzKxmLH zG6-BM7bZ6&{Y?^??DY1u?YsV7D7(JQm*_6N+ePO>lXnYZ4hYzutCVS8JDNHppsDlG z%U)G3+*lXlZl=+W2D0bzIRlNxO$y(AgCM)*bSgBKT{^ixeM@ihz%A*yGTF_F$5r=l z$R2#6Q{ippt^4)OcjYq1{n{QSi5isBq3M?;m8cT6|BsK=HU$3sm&a;1lB*u8*ySNT zNP#fwwTcyCa)7D#Dmwa9N%h63hpmhJ_l(i(>_1y|{Z=c!VrMD~m`AiqwUr2Wi5?WkG3j zZD>$$QJB{b{!LhU>E`D))tjnnNrW&16+?|k4n{6V6% zwr<`z?e>v=odF@%({=Vfn|prRtGZNLtxsv6yWL_axYITi=Uon4O>4wxQ`hLF>kVlZ%eM`cCVkV-t(K9P~Bk6Sf_AWw6e0JoU%zTZ@#Mg2kzO7q>NT z@J*>RFg`zQjX#~mBz$E$_|`?XUr`1J5eB9$Ey4KUTjie3eXEO()_CV#NSGM7WNG*1 z+41H>@48;{n{Uk7=C3b%QkZvOF5Bh$c}IH5#Oxn5+{KovZ##apu1*m9eBZL;PR;Qj zS4ACMWZ2Yl{RivW;N7PWe`mUNE1sF&dFqtNzsXZ+Sg>(JMqAsv19$CluQ=25_MZ=^ z-nr{DRHwdjJm54Nc27DhMBLPOW!XpOtEp+TFAbhV*Q~iVB1P=<$-$n`%AXp z)Sdqv;CJ}K!?_0^eDY4#IRo?Ur?q-}uS8W|b=-;1{Z{%`E%zC}=qLw;YNcPMrOrC- zjMism)KE)e=w?I2U$T{J}iy;mdk`o8^ly?%w%X6Zm@GhGi!LT|Td#(op&I z%FeU<{+ZYMRY!TI{g(H4f7nyrP;@k9*NBSrdsi}+SPJ9H8+Y!xd)MBrsq5yZP1Z@} z|ET_D`c3P#W5I7Zob;DHYU{UPgsaahW$#*T?KQH&MMZxdv344h z>^o+Q`^8~9tW&%gKXFGD2Rlm&3r+iHgi=EE-kMn)JA5yI?-7p0NOHg;!7>U1dJ4c_zffON1VGPlPOt4Q#U7^+chw@Lm(aG5D6Lxf+(ybL5EZ*dLkUskV->T24P6?G9l=lRO}Iotue@t zgmB}9B+qyqay8hN;}~fu6NDuS+cKnNC>@S(5X$I~I|eBY^5hVKQsLMRL4F9z=}dw1 z{HZB6mD6+HOM7M)p>4MQF5hN1k+F?q^jsJ+LvY*gcD1?mH&gwOA&Jbye3O4lAn(qt zBJUTM1s7}}c!4uG8uPOU8SLQYSBm@55pgdV*ag!5ugA|?kXukt!jwr%3RdUpW{wZ) z*99!tiR3G{9=+OW=IlDI9ND^3PO*5jQbSJP{(yRiNqzQp=G9L2gGPGNl)&SPyR^+Up`Bj_18 zfczt*R|OfNoQ#%FMotC=q6#wQAWGCo6rf-uev5b&r!)vUqUHf7QS%f2z}rU2R(?`> z#q!KH8QO-va1D%`pJlDylvORWjLWE!H zCbO8e*TA{d4a|)mtv;q_jv`EPtt*ECdHQI8GrWCwMG*(eq z8N%9qLL?x$hZD7JR3RUw zAlb@M*A}%Au_qjLdPY0)Ey(ZUL|xm|oiDZc9z?8zHh`j6f1#5w^y6NWw&J9}D$`p< zo8C<*fV+pUd8?uX3n@@uLqnfgkN!~Jpv8)4Ku1w3#Xac< z=uZyaiVnrTqL*HN75G)**Tw0Dudt*q$=AV)ZyQjK(ne?l(dfI$O<-sP$!LzN3Tj3c zj7A@KmwB`h8r|?HNBo%3=-=~n8zIqgCckz<-J_=fs`m zvqm$X4n7LqXTKP~DIDsWF-z&=Ij-&r*T~s@G1=evpzvRYc23$>UwiD(?$Xj?W}URS zv~>5Os;5l-^R%6p{YcM!8SDAq9MAQhDOr5h^<&`ox_%agGzD$U=__Xza}Ev zgtMT77OB)cx0G<#TWse-7cEw))hYz?3Gg8w^1?A;rJbVH>KK|AJP0)or`h;^hoxnrb9W8_D1WFSi z>61j{(l{onl+YW2R#q*cm4dQUdJiW(HBPOf4Kyl?o#qnAriT;i5v`7o7Bh$PN*MI$<}NX^DE$)R}Lx)5TNX7>_=ZtkO2~5XBf0&9o?f{xmDi#WA$#E$v#C z-%1AZLg?eeBpGiT^_R8T#$6k0`N(*5;mF?7g52CJMkme6U0zUDar9D)5E-?rG~-7( zn!(QLwRp{{S|KtT#@+<#Pd7+pv;;H&<=0FiBdZ=DM~Dp1+jw>E0m@5=jC;56?%oY> zhpf_x+j##Ojm;`yWp-HjLmR7sp~x&JGWiyAf_H$(O*R6#xrFyHU`ACFD63C{96Y4QQ?gubPE_cScA_zE5FvA7^Tlni7872l% zusi_acmnrwLJ!zW0(}77<--x4N#N(sdkS{qVG`&ocke;_wFI>Jn+0dLDa+TtJp{*h zgdsjGNF>vCnjVqp5Y~wWZx2&V&3i)!dbqd@7&=<^hGw2U46QoZO~T;hBcS>kJ8MLy z6%N?@cugB&-!p@gZ|q$CLY;2@te6ol-5{y0>Eigvq!=$Vh(aq;tU&n>$2(SR&3O_Y z*=FefVNFfN+WfVJW#80PWl6yENNpDhkCq|LAeO$l_5f4kaO|_ZM0fDre6@#!#|=d@ z^tGF-w0H4z1P2+qYSK+1JkG94pYWQC1za*}DpxOAxpqfY&A=}=oW)&@;qmzA@As9h zS&^Hg`*{ENrqcCCj47K=8ruKQwZ9##|Kr+kg>K>6Pn`;e#TY6n?Dry z@OLBI<)1-XNB{^$k^n-HJb+LJk_-@%Bm{&aNdciqVn8U891w~m2!tX@!gK23bF_|7 ze2+7PB1r?G_>n6J#m`pGfB`i`6{v?3SYBCFOw!(gDK65OOh_uZv4qAfMsk+(Cl^0H zu@JR#Cs^KQOfE#7*Zp~#>c{67U2B{f-bs9hLDiy@(2c)l7!1pqOJtN4+QE%v7|wi( RQC9WPYOdOAHdbz_{4YeDKWG2| diff --git a/assets/java-yt.png b/assets/java-yt.png index 5bc1fada0c118a8c111dbfb09d039df6426adad4..07d061d8512cea545c5b592d41fdd4d2b55e8a50 100644 GIT binary patch delta 2006 zcma)$Yd8~%1IEY3W^O~W%w;o7%gWfsT*|WC%B2e(cQdyRIz`09m`j%1Tq=o)dFks#roW5q9g(^x!JeDG4=yZ0?><(3~-#Ls8R|b(}T@tXTYQ=#bH%ky_CwGF; ztHyln@p#idF#109yc@LS?WP7RTRmePstv^u%cd#nl;P5!)J7gMxooTM&6=iQQ>oy^ zs-`%HTJ)8gChJ0hf%ao75M7Sk!FoUTGVxD zSr=SBlk7I6mGy0T+s?xFIJkKVO|QxXY^WyW3KrHn3tpg9Be*sXO51js4$lCUAhzh+ zc`v$nd?P_zZA=E)13Ki`Wdf)iE?T+Njxm=D>(M@Hpe=I|JnMae0WR|#WlD_sOMShs z_cX+Q&61GrWEB)eU|UG``_kZ^-kF8Hx_fkUsEL<)-o{(Xd44_j9;EFUa|7`gLg-t%s}eZ+`wMsn!?b1 zQ0cVrsb&d&YawD$^7Tm`eQWjp%b*y9*w(#vTfBGc$Bx;)DJUpc-4*uC6tVC;*UVx1 zj?9mSvsu^fPrlH1zn^zWCuj&MSnpj%0L((a(T5(Z5np2;PP@-m9En>md0YW+uJM}dkp zkoe)9^`T%jD%%^KWU#cI|8FE|lyG6D9rcr&2ek=e^DBb!HN|__P;4a&*R43ZF&jSS z^Ayl_)SxT-ScX93dz{r7zG(qB>FEN*e++7)y1=y1N}gM;j|$ZFzr&O>`;3z|SqZdEXK`0{=5Xp*p3W1EW84 zEEUL*Uxr}o>s`0W_*d}QOh?s4hoq3>T#p+MDH+5*uCGwGK^IDavkdB=*eD0Jv-DRZ z+`!lN{^a`lrt{-;PD~C2B6hgD=gc-#aMQ85nCgLP^FL>+TQEnm<5HQL%$~>p z;_4Jm(0$A{Im0ooKB9sIE!bt3vS&z1u%ede>+h!3Jeka@Q@iOc4{|)~MWIm>-QH5p z3^OU)pvcSb+?+&b&txOrUzaD;pjLnA^eT3nWDdlng{6wIk2uoJe54B;O)cEf<3XaD zx^hoaEZh6BlcQTCHiv7woqjwA0P+1V?6`!pjaSN5L|MggJ-R*9OM;HXV?i zU|T1@$G$|)T?O9VrX^RI(QzEarf?2J9)l+fFR9b+6b8p>vOeWCsLXzNzNBP&*ZCDp zXaO2eOMOn|+~WUc!CER)R-+7lnz=qd<5ki2*Ts1F!}*9-Ypt|L^_F_fES{eBwcNGH z+Tp95+=2~zvG9k$b$M}a*CS1ot#XQ5if)Xpq+1gGsP1Vw2Ori~?SS{qHmNl=>Q$lL zw^uK?uPZn5QtczridAo4UcyeHZl)w2rrDMzJC8#iC*3^ExHWPRMB5eXjMkbg+S*~e zdwImbX=QWQrFA!Do)6^srXwR@4~wvB8>@G#r`0c5WRdlO0yB2{ItH>94YEqXs-zB@ zi=UipDotEno2nI>CzQulApSc0dnG@+6jpAZimY*>Xzg)V5`O~6Jw^tH9ThGB_GNd< Kky>}sm-RoTLV`m8 delta 2009 zcma)$Yar7L1IDq`Eq{Y7)oIV{1OK;d$^ zJe)6qM8Og8Bp#0E?M=oJ2t03|FAq;9^Svc6Kzp#}WM8~5(c1^-%Qg4K;rS#p9FI>T z;)qlVo?zyKHz#JSq|I>w}|me}U&qBI7K0d_E3O`87r&@W~WBUlI$` z`DKs~bCbj=Ye-H(*Z-Tz|7*qn?Zrc-57?Zfu~k7qxyhbEXZyWgC{zh#AJXipNC*R$ zEO2PI{#Ih&X5Yp5EKP;w?i{(l<3`OyW4}H|&ACfq$j{`$NqPsmMw4xo>Z*Q+YaP{@zK1GEU06?WB zFlf6lXfcchF2~W!cbbX1L@97Z+;+tN?8}9jW2Vy&)9oEcX9TM{E4hDgn_Wkb+s?-n zU(ia{N*cpw_k^gxIFXOrFH9>qI!`RG#*e7vKp}dr2)X;nL9&5P(JLBjM3{IQYCqmS zjnbNQbt@TD^90+RN~c^EBwzq=F@%_94=t(N_=_HMLoYx-aaj;r)rts~MZ($9S+8OQ z^JjNe3dCsaB0Yay`MlNH)=Vo^Wzgp;57dF7`_?Sz1Fjb80q1CXJDpTs>&7gP1erzq zYp_~NkTHj=ctL@#wA=>Oa@3g>88v~Tx-|EbDI|^LziBof!xPuV7_X9#o}*15c=@_W{Qsw&fqjk}@Kctrb$p3aY1*rf)65lJ3PrVK8*(yDD#ckQ@fa{b^x z#@4B9c-deZstiSvDy4_-vw%f#P+O8S4$xTc9h&uNL zRawN>zJ*z`;p!dz;&XhG9pg``?hfq961N6zD}P%-8Q?8UJ8F9|_l4FqR9vW)F$5df z%L#GDmxXBUT=PtsImhvz?X20Zlcjc|xubD|SyxcOx$d~QuqJKaSjFO>Tl^@G!Ag-` z20@0TbC}rD#y49y?-8cQ-q1=Kj;XT7y<93Oa=0B<-M@8&sBBg%&HEF84=r<; z23FU800b*bzJ|2FP|0wweRNX6^5k_S13=bIwrd1=GRf(CUv0LPUX!^695xe^feh=A z99ypdh*99ao7=*+b(s41o*f;5{v`KKS5KpFh8t*HsmFHK4S^n0nFvc+5B*b@T8w3! z)`;BlUfV}us6OUWyA+WO+=Jyp@Dq@ae6PnrPd zM0Kawscrk!jer$Zqk{S?#o;%lDfOZOF>k6c>E7Xr;L3$FH8GC( z{+Fi`P>|`?>{K0giqg%^kHV$hRxbhKk)Gqb3y~4`@65IKn>qzI{ciqkA*dMNE%drI zmu>W65=?Kg9BwHOnM~eK@WBf_JqF~LB=oMldlUl=}Z{-2q&L4HJ|YL6lCKK91puamNQA$ zxL9dnsPq6Le&|QfF=BZ-_=h`fNtaBVoahbvh$#w%_3ME9Q)Tf+9>LM+?qQ2I21UE= z_|fpoMM7uh867$-nN_gbV4VtREd_}~7Y$t)nZo29jNs_)q0c?7o0gl05yl^fGkmXu8GCi zH?<54D}r=@y!wvyOXXu+kRBVXz)-%W$L_73xQx^n700#i?FwGp}Z zL%O?%iG(-rcDZ|yDzoLhMNl73Y5THCIVguq7!!~D(hBwADIq$k9tz{81%_wviG2?p zJv6zcGm-lYq6@wI-q&NEfWgL0G32*LXt%VclqOM7)G`fBXT^z7*X+#LAN!I^Bu%mk^ShGmbTFJi(nRz)#s_EFE!mrpLI>NYZ Hb6WI2QF44@ diff --git a/assets/yt-45.png b/assets/yt-45.png new file mode 100644 index 0000000000000000000000000000000000000000..eaaf408cb399c459b47ce2bb1e888cb14e5a3925 GIT binary patch literal 797 zcmV+&1LFLNP)I?6j2<&KX2A`Ma3*Ll2Wkj)S*kKVvQ)YpranDlYc-8 z9lC{e@)BVYc*zcB*pEvGK{g9Sty2(1)FI5UNFg$_U2s=-UWeUiemOhyW?DVW2j=j; zyWj78<}veT-WMVwA|fKTGQw|y>?X!{n$T$h>WjyAbZXIv1GNrmX>`_r-)Jn8=O+~` zlVhH}EQ-hELy?vsNYV~;0Ifhv@n`}n{G6l&>%ceQ3osANAxJUBv;gT@TArYR9QT3F z5as-mqLTCCIX|pFXx4xPL5>G(t}s9+Sw^M9#M%Nf$uVHEELvWWB*hFf#*l5Mk(?@< zkQX%0*hBWn{<6q;MdyGuB92npF{0%^%3l9R!VoF&H6B! zq~&Q6zz(I-LcsBE82JD_S0J8H*ECbj5gLsF^GxR)-)8=(s)3$ Date: Sat, 17 Jul 2021 15:48:36 +0530 Subject: [PATCH 122/947] adds java yt icon --- README.md | 2 +- assets/python-yt-icon.psd | Bin 0 -> 32515 bytes assets/python-yt.png | Bin 0 -> 4085 bytes 3 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 assets/python-yt-icon.psd create mode 100644 assets/python-yt.png diff --git a/README.md b/README.md index 47d6610..9a7c337 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ ## Problems | # | Name | Difficulty | Solution | Youtube | |:--------:|------|:----------:|:--------:|:----------------------:| -| 1 | [Two Sum](https://leetcode.com/problems/two-sum/) | Easy | [![Java](assets/java.png)](src/TwoSum.java) [![Python](assets/python.png)](python/two_sum.py) | [![java-yt](assets/java-yt.png)]() [![java-yt](assets/java-yt.png)]() | +| 1 | [Two Sum](https://leetcode.com/problems/two-sum/) | Easy | [![Java](assets/java.png)](src/TwoSum.java) [![Python](assets/python.png)](python/two_sum.py) | [![java-yt](assets/java-yt.png)]() [![java-yt](assets/python-yt.png)]() | | 7 | [Reverse Integer](https://leetcode.com/problems/reverse-integer/) | Easy | [![Java](assets/java.png)](src/ReverseInteger.java) [![Python](assets/python.png)](python/reverse_integer.py) | | 9 | [PalindromeNumber](https://leetcode.com/problems/palindrome-number/) | Easy | [![Java](assets/java.png)](src/PalindromeNumber.java) [![Python](assets/python.png)](python/palindrome_number.py) | | 13 | [Roman To Integer](https://leetcode.com/problems/roman-to-integer/) | Easy | [![Java](assets/java.png)](src/RomanToInteger.java) [![Python](assets/python.png)](python/roman_to_integer.py) | diff --git a/assets/python-yt-icon.psd b/assets/python-yt-icon.psd new file mode 100644 index 0000000000000000000000000000000000000000..6a308468d18d1eb32bfadb02739becf9f25611d4 GIT binary patch literal 32515 zcmeHwcR*7~xA@$2dKEiH#4f!fp$G`5C<1m}4M~7#NMaJ2z3ZyGu4S#Ou4Q#Ct7}&f z1T0vwm$i57V!=Ym{hgVF5Y*j|_ulut-}{3J_ukXy%*>f`@0_`F@$VLwfGDI3EV#Ik zgNK+pQooV@-C|-{Z3$+rqt%`X&l%$Z9fLx$ltR%ciH4sfNs-D0POozhIq{`pfztq= zSoc_ExFl5?Jw_!-7}GmZG-i}2K5{eZ`l0bkl z+0BVhL^PuWPGOkA9~c|Q4_Bxpd>>a|7mGnXZ{$t_oF(n@2zZsPT03 z^mG9U7j?E=Bg}G{^ttv@`P$LQUbocadarbla z@JsaY3G{|P@6PT%fnM%LN_3K6=!jK_rODaf(%~QI?qRIMNb*Y^(456Wjj&!?jAf1V zh(&?P3RRj=6D(9JWm1t4w>`HExme$#3{@NCRx4^0-@p$HSI879$gCvTE6D9zH7ghG^#y9TJ% zjUr-&2-MdWFUeQz;UC}yn!VlqUA+Ch#V!F7?_?LTr^GwSQ^y})Zp9ysOjiUd38kwmQ`9F1Dohl;r_e#`?WKE_}B?(J` z7V<9#6`jhualX_Yu9LWR)U~FHIAsNZge26uw5m z|CghMuDC`z{uj%t7H0g<+FSjGkN;tNGal&wKee~ozA8!;%2OobV7HoXT0^K`wdope z-SMMlO!{KH(TN&8>F6G#NXv)kD0qZ(Gd#n6)ej6~#lI8yvWWjq-3DC^i5N^#AE3cp z^|6vcromhWQ`84&Fjsx7WRPhvm%$YE0UFFzA1fJT8q8%dMSXw@8!CdvRl0l}yTn1Cr2WT)?eXL}VX)u?;6!ifb%vB#N8DtvFWiUm3fCh8b$4Um7 z26GuqQ6HeeT=lV%L8if622<1rXfRiOtYnaBFqgp;^#K~pRUa!EWE#w6FhzZU26NTN zN(Pw*a~VugAE3cp^|6vcromhWQ`84&Fjsx7WRPhvm%$YE0UFFzA1fJT8q8%dMSXyO zG?!`Zu1JX-wnApYo<~G>O$L%(l#k$ycU9_kV45jaQn{v2x<;9<0U{fV#Hlq2Nw5iy zNW{oB5{W!L4Kpx|ui-Kk#;r))1ZftQ=qAEyZjY`~y?4wizzcH2!S8C)ng@8gPsSHSbiaOSSgsbG? zwTN6(i}Xs8sSTXoDVhue5}788Fd$&ZTGib|qf+#S&{+w=Cbw|N4cQJGFXr>biu9yV z#a*035~5V{uV~$5U(0nEHNV<^3+YC(J0bn3VDh?ig^tOXTgYWQA3ZHrlcA(%xV~rH-kLx zE6kU=JfLW}Qt;DXNk3{wc$WG^;Sw?lk@m)XMQ9f0i7KI74I7&za#6OfB{m`)M>t!c zL}=|oBu8p!<3fNX0E>ph zHz8*@>9n-h?W#7#DUd*sGM5uL8o4DW14jmDj*hFRtXa0)K=A|)g$Bd9Mh54bB73>@ z6r%GJ(Exp!{$^l4!TfKs=>G|i*n%XD7>JaP#UN;{<=hF*pmbb3M&Pnwi?B#+9--*R z4Mr%8BXH=gj_VQR@QKJa!w@qBPP(#Vv}RvB9#peoL~}vjNM|D**Z5ph55}>K`6OF) z2!QCbhRO1D86J6Y5jn6QTrO6BF`|ex9>60R#@*1+)`9p%UqRh!`xG%sd~KJ(I7baz zfFRiPRaCX=Sr-1)3@g^#WwL&>>fNwP4V4D}{> zALlp3``3``ikl^+kgeH9#ODb0|p!ui4eH8BqA2?_*pIZXW z-vs&}G<2azt&C0RjvqV_>=x(aZR0vkI2${lq$HPQgI;c zC5G=Y06Yy~S*Avb={VQ+Nuw~#z+KK>1sMdm35HX2a2Fz@gF`VaPLo3eXW%?5#c5&; z9|3q)Mmlcz%w7P`$dF1h0loyVvn)ML3NRjD?b9Se=!`6EGiQxNlnSsrz~-vNc(^08 zf)L`Frx?LWMz982AjqO{g)*De3BQA=BOg9S;m?njWXdEOjY}MSV?(GC!xu2pltMY& zr*vh;v5@UoTk;86clt-Bk=#FlxNdd)cYR5nQ4XhTX|*wHX^OQlD#N{u`BN<|X&FNM zrX$qkdM(ZQS9pY-hS1)#M&)t9?ZxQh98!tM6&utL{-uCH^6vqo^jvXzhR+%BBXnJu zk6X0}zLt=#;=^-a418)^)l%X^96(kv?|rL zdw_vY&UH?Vd4Mw1QgT~B;qi%lQMxKaC&I!PHZnz4$R0ICj;Ial0C#9l^ynR7p`3m$IPjsHRjasx8%-@}&H!U@DU8Ma5Hts1Z~OC8yGb6flVQ%VXS8IrW4JN=8DWf`j6}vTMhaszV+>;& z<449)##+W!#$HAt;}qjE<1XVlqnwGDW=scWYo-g+pBc{V!yL>^W~!JIn6sISnQNKb zm^sX1=0)aR<_qR$7KdfW;>U0Knrek>7dG;0EDE^9gKch+9k5!OZ4Jysb@%eG** zV0UH*vSZi-*(vNy_6+u7_6GJI_EGj__9ONO4u|8wY0vTFL~{mlMsmh-=5khYwsQ(N z=Q$5JOcfXJKK{&LY%e zu!Y9rM~h7shb?Yfe6qB&bhV7J6kATTTw%G_@`B|nD-)}>R$*4(S&gw;Y_-ektknx^ z6YF-?;nqUy3DzsD4_IHdF1N9>@v!M*lV&s5X0y!+ngP1YX}i;{Hl}U-+a$MH)TXFSnR6@WSm$xhTb!@AHEHYLHnr`Nw#98f zwrk&RK)adk_O*M`zDfI-_G8*_X@9eWMTd|MqdTnaaH%7wqkqRy9anZd*NM@|r&DUD z6`js@W_0%LEbY9q^Z739E&*NSUDkHF>SFE^=91yE#pRx>gKIC>DX#lmU%5HE4R)LF zR_vyA_i>lGuXn%UVe8SuV~R(P$6L=%o+8f`o|n8Vyt;c$^xE(B#=En(#Cw(ZH6J^l zSf80bMLyNOe!eQ-ZN5+aoc%`l{o;4k-`+pYf3E-W0CqsPfQbPI13m}(25JI#2EOj< z(sfkV&0U`awGWa6tq*!2a1sawYXogL`})oo9=kKuvgkyGDZ}$DW(DQ~Ur~Rn z{zLn3>i=;-#DE0@?hbStIDX)%LCpq92kjrs9o&ELhQZ}SB8U7u55Y^vKmCKaT1%YU3zcHbAyLjh8ke?SR}? zK1zN>;i$+`oL6>M&QRVR9XR^u(PgThstsyNJxsk{V-F8gr_(#6Pfx#>5uC9i<5On; z%w1VFS@NvY*`2b#&n_L)eavrTSz|?Gi^jDcH+kH>@nPfFOrRztO(>e!X5zGok0wP; z`hBwLHIYTw$>ddY)SI=V2lFlmm-s}5i z-)m=!XP=zoK4L<=m@}I8E51Ie_0-FV67CcxO zyKwI!{-W87-v2!O=M#&)7q4Dox+Hzc-KD*j?qBA-?5AZ_%Tt$MUeRsE_Fr23^8GI# zSBh6&SQWZz+v=99=d7;yRr>3-HBoE!u5Gt=@jA}BjCGIK_g`Q9oBwZ{HZhmf1t;KqMWWddvaZKHy&(#a7A9D zym|Si`P1_0Lt_q=7bpu}6s8nDC>maL38MY)uC7KUK3w?@|WzdH`g<+SKgR(lYMjcE$ds0Z@0L;_D;t;+wc0`&AS(I z@AUnI`!^nl9z1`jepvNr+GC5yi%VOTZhGSRgiZG7+jzNkE|{Pu^m50xKhe`@;a_s{;Hiz^0HlvZX| zajTYAcdX9Q_SD{_(`cH^HSEdL0Dc%?6C6K5BX$&=@bd(o?&4z>xCfsAy)$ZpDEb=x z5}A|FgAEUl1^gAVBp4D;0$GZ_fuF(Juo!GEhsS1`djZpi z$!cxu!4B&yv~wCg*^^^Gf6b0=ZJZm$7bbamtEQX}=eAvtPwT+cI?SBkb?|vt7w)?~Bk!j@ANJjyjmt*Ab?~=(H@IJK(W)6u%aqHa z6}^|VFPnR?#A8u!_sPy?SE8nudoNko;^yH^`G?<(J(SmV%#5)<$+3TY5*+^Yd&q_P zH1eHzER9Adp3-P_tNRn5^x5is@T}c)x53ADY_CjsIjZ;8-LF{_p5A%&-JB0O+M^%t zlucOjN2?Pzo^@_=;F@^aL(1{meUFeGznvcE=4!rw^vS+$f@b)i*31tIUZb_6&piz} z#?1TVQs%Jw(8ZxsUQ9g3PLVfSIeEv%(x;Gi{QgJN&(bI-MQc^vByVEj@yZ{YX%A@^ zt++mZz|(<(p1%ej%$a(>^kvrhm*-c9J-2(_`0|7E8P{FYmVRh5!r3h3<)O3MT>G5N zD|5ySh{yRb)KEGY2wm$l5VNes#;&!8d8m+AS#sAO>8aX=N zf4O6xyXBViAcEkf3r&uppvF(jkKu!-FjR+*Q~FAkaNxn=a! z-PZToYZq*}pxyHD9`|8-;M8Hc7q_jmT-EZqT=dJWL(BGzvE6t{d+LeR?$dqtDLhxK zXj#>D>Cscx9;d(W*}m~wuX&aWPE`c;%2t)G4w>ra=^U`MsBf{QrTNaIu5O8=%id^d zwAt0wFJ{fzRw+I{uedXQ(p)}sYlqbGM;h&Hwr^hC!Qk{CDEXa=7|q!o6;m(zHXgMr zYsT5qv>PvP?HSo6f5^{|*3EJLt;_H+{%^Z`G~GXAKaCF2C}4@}&{F5Hrv6!L<#9n1 zeHYP){!8b#X-$Th0dOYcjTH(*Vp!@)0=G9GCUU6&Yv525NC{&0|3ZQf(=>N-;9;7K z+fFzQ$}=_=bpn8gxRfnfKEa-QL^UJJT6nNaqM94vkyHo03b#Rdk>&GQ00qanwrr|WA;UH@RqI5O!kOA%uhc%|d0kQDM zV)55C^%N7xr9_n|O_SgiyRd6PTNY=1en9e(oTb7|8^`@JGy;MH99`gW(Odl&EJO)# zIt)8(b%q_zS*_L0BCrI6dRv{N%+{nT6O$!J$ z!3vAT!3P+XuplahZyMHR+ke6Cqe+#hzK|g)#Va(h#8R`Q+ealQO+H#RMh+=`YfZ&c zBonID-DL`)2Cv0}6z-G=uP%L|pR6!_NyDp5m=+o~2}dIVuQYu@2GYsvzaoZ!=> zLK)!$3wj|83Sf|a^6s)WutcsG$7B@Rz8?vpe)_9XvHsKi{wj^=TX`ZG`^L$T*P1+k zd95kK-(B@(tEsv#uey;qL4o@pXOddcD*`fstFG3#H4BzDID0W-xkkU()fV}~80!sZ zFL)Qk2kr+ha3rGupt-;!Lo!@F0SW-BAMypr9jN{Q`2sx&Xd<`<02K$0QUsSV@NuhgTJhaFb;Gz0?Gaq;3nXF$Zp9Ch)EeUhY)XGj1Jz5jQ$nUc(f!}4*>vK}cynB0Kl3M4DA`XZ4ok*Ja<>sNz$r1$E_ zOakl2O#;b8Z;}XQc$r%FjtS=AXV{vjZ^Pr6 zeprHsfF|(lZ4T>zJj0Iz&%|H{-FN=4VAP<5pt|F&ckDRKL*bU=&mlOb4-oyM_ex z`-G~|0|5%IhQgrmy8;HhjzOb40tT5h-x83z54tU&f+68xxMKP{i11v1%luBjNXt)n ziQ$-c0+yWqxT@Q00SZLnAS2h()WZpY24SR%rcQnL7GlC7ucR53TcY0s3x#0jXPWV5 zen`1Mhkc~c)(^(KmvewuCtlZDrNgjNLxK-7%LK4OZk(G?l26(GJ|v%p-0RAN%T>30 zV2GeQ0&ou*3WG$REisKvaMwcj z-&W9QWCf}~yr`4U-o1NzUBjwCU|`3nq!Hn*NK3RQuZ&p3D~{I42JDZ!KGXuVJQJfI zZin!L;gns)VngeN*H5+JnCl6ZgD6fli)MZX)T5e)wHGEs%LFpBia}G9=>{T#s)0}e zOC6|n70m+IDU+!MN+nQQovEVPn8IRIQPm)^8JZp7T2O#MibB6u(r|OB0<~3uErKS1 z-a|ykgOzjzNLIiba!^oEhESC`!?g3Y3c3;mV=7;u_n+x1a2m#G-+};Ee&!9_y8y5% z0DzQXLKzIpOz=t?0HuzC&@v1_q$RJhLvisdd@d#Dv#%hwQk|KB1Dvz6#%E_{%6~Wl zF$`q*Z%CP$8QJ5N(~lBz79r@)W0b=s8w+d6S(zD_F<#nj`0>0NGN{gkKYW_9>*zr} zIV&?=N6XAm{du-9_XABU)LEHX_zzAXt=@97@X&>8*G2<5GgFr!T&2IBE-cDDa9}Ks zZU|YU)}1aaEIM?cMlKzPjMN`b6%`idAHPi!%S<0V28WEP`+!=QbC%Xg%jX};g^*KN zTu@6+AGhqxu_HJf1|n8+7nfq1|C~z%*Pn_Ca=>Ppv$~AGT1zfEn1AdT)-79Ef~f@s z1%(F>7UiEgd89ZUvZ5mwLCCvuDRErf!jd)KaA_l%I$>%k2A0M*-CbM4fZIhI+VQe{Sx9yxe{J zfxN32$OVOmi}H&KcJ1E1_s<=Bb|X|=lzR{dD0E)I(w&D6UYG>~xPhFX2jSqsy!`7c z2>Ec%K};bb|ImRw`=X$+qT<6jItmdl*p)LMcRd3c;^R=Xts{eHAm`@g=jUU_Uy+E% zgPHDeqQpSH8jHAGHj8zvs5ZsCyxcp9K<06|x&(<{I2Hft%7E9KcqX|zN1 zG65=wrK1*{*o#Bqx|VD#%t3^ldu^6QBL@eE#_))#BjZx!ABOiVNuYp8l;C{q{uoT8 z2u;Vpk3&&d_cbwOwl=WA36p;)Kku3dlR0cQo5O;IT#88n`B3g11(AlA zxVTKj;W7w0|Je0DHL6Wu9AfLpMVI>ORdYB%hB1stpNvO5C^6O!2k6(6n zja&hfBiJ>9|5FVPSSk3371-hNwU-K0|BW+}@8fz$S(r961+5k_(Gl@*ZG#VD1INF1 z4FZId)H5mq?qBfxHE-iW?7xnQ2umC|{pFG&vtotz#S@?3D7}9n?!f|k$4k)*JGg}} zZ928@+y%*H8+v_z%xA`e1q;F)orCrt>|piq#Bc5w-7QWs4-D_-i%W^b0ok zj`8h#Em^y{#q(26AI#?NdHOP9Emt*r;1F5lwyZ~~Lk?0uH$t=8O`3DMm!nPVl3|$%dgJNO6 z^yj@te>}N$^~bTz)SPQa0_QPL9URwMlD#PIhsKW2OGtpHrA1$n4 zM@){XW=xsjv>?cacX(C6yvbwpeU7{@=d-e=JPBG>QYwooDJ>X0NHN!U?B}4iV@ywd zJ~(=Y{kHrKPU&uAmE(oiLMn68WGkg}eP@j{8PR22S=!pSCdK)0-=B%T^=8zI-{O|o zrZrbKyZngV{+c+kQ%vJ#w_ACgOYnbszTF`h~Ms$;oug96~ZSme=Ldg6w z+xf#Z&R1tle_GyX_z>>AqS5UqwY)8HH@WaOeskcR^1Y8IR@+su@B46%yUUz$hlLma zdq-^RHew2Z1jjTI^y5h+MljqxRy_(pbKSZn5%I)y5iBM`+#^8wdQ2cYs`{(c@^5-5 z@G2@hO*qov#Kk#ag9FzHyqyh$;7uB#oLk)`#_0x$L4(sT|N{n>kB*1ZO z_;-WW6i_4_AjE9}g{DihL`N(KA}GTnYteI7xxiCWJP17cev4O;&$f|Wii5mGhI zviPehWZem6T?|jF@Z`$^>fH|f0TzJc$9+7-)J-!@>P|Ahz;r$(JTcWx4s0N{9sKN3 zGxBqU_s#jp367>PxoZKxmN2Dj33q|U`iUL(IhcK+73cAvH8%$xEs16)(A<>hZ3>!O zAZLSS?8ErinoU7Qm;1VBGovXE=2#nPCX-RbxJ1|Y_kd-wt&KuUjINk5}ai#;7|Y#KFd+O(Ms5S1?~>E|@{%&8paLsQ;k1pN;4AUr23t-zS3 zlELGJ^z0GcBkh5fP=>*TDEM`CRTZlKj3tCH8*=>k27^-poKr!-{Qz!#ia~Z+TX@1b zTL!7KP6u(&#WMOS%`CrM@~P|}ZBtHjtDjvg&fT_tP1REFn)Taqi!VK^E~hJLj`r;G z$s-d&UkNy&i6bX3Kc}svVdnfseP2MS-&D~sSJsZcE1*Ves{ux5Zwt_Q0xbn-DS;*c zG?qYO@CyaM5TFqR>-nDem|h8}NSMIG+d&mZj;2?H^2Xq70^iRaLV9BCaymyycQDD| zcsfpKS9Q)O9yp)Ed&VdB>0Tv3MTB!6b3W0G>IItWOonDiuvUQbjpHz1PRmTM%B05h z19PPOklSd_neG;JFz?$Wk zaP?y$tLWg7PjoqLRsHlNa#9J>x0Q>g0@FQV=vD(Z!pk4%Um)a4Fx&UUJNODwrn(OC>7Cwf_Zp$6q_MnshxG2kGK4M@(mhPV z9>31u(kmpS%b28dA3_5A2<;@MeWrQfMznYB9@EvK3ZdNs7SsnWljnFB`h#`#qvCxV7SEcVnK^bB%%G>pv|RI+{(ioGUT!X) zy^fO(@%BvqwUZmQT%PL10mchYD2PC?0EA`{2o|5v9|VHsC%A)PIo$#j z_6h42p$J44q6kD5qX0u)8S$GXW@Z1|S%KGi`9ua&BU`F)8pZ>@>y((Jfg$B#z^9WLC3S yHEY(q*Wg56yYNdV@-xK#mKXWy*IwjD#$IGVYQ4yhYQ4x0>v)kL)OwLGq5lWb)=PQ- literal 0 HcmV?d00001 diff --git a/assets/python-yt.png b/assets/python-yt.png new file mode 100644 index 0000000000000000000000000000000000000000..392ba92eb3c1a085718d5ec1415495ce80a4d2e9 GIT binary patch literal 4085 zcmcgv30M=?7LJHkMJj@VT90UC{iN(0wgX07x3h;T`0igI3I9#l^)j<2X!87sWzEBH9O=#b!ga1*BiDF`)5~M(^0~K}zT`9jP^tlm;+) zL={wwK?2f9ds9$r&2BaNKALF4Sn;Tqg)m`LNsS zv#nM|87RGqdV_28?LP#dsg=vkFkUT@=v$3(Osu4I zYLsS+RHIP@ORI?j0rMJ&J*j9)M+c_Sab6vld3pxwC?y$9-_Qs7%mQRyo_s{a=R<5J z(gRm67t1ty1FFFYnN$MOxiU!-7mHAZQh*XX2vKkd2u8VFNTKAx5CRKCJQ%|X7%|V6 zQdo>hKc@M;rG!%$?c;ZN3cf<1K$HTArzBvAhj9r=$R?B!7eRP@gb)gGWiNR&nmIa> zu4Xj)Rj(#gIPFo$!7(8hhanLLBM`yiav&NRAL3&IA`UtDHD2CV zg~7zKzO!f&=uw^+#Y`0?0Wp&r2psGiCSSwHJ4NoBAEzQ{r+=Z6-spNtX^2C0ghv$3 z-CI@2dLwvB6HDk`fv-h%DBZ{ion8Veb(9(~D+Vx70IJnSlNf4BoE59V`n8tl@O1|RX_?MM+gyoR3st<7_8va`tL>ghGc#(_5X1) z*jp9wmPI$|!Yqhs?MILnD}))=Up{OKi0%_$2Irhf2&*e#i#ym*ERKxp2T0-tMm`i8z9rEdFMr6 znD=gkhOSf{y)%2F@}13K3_2#0dW3|YZOB#!hRhpNwrf?y_Htxn^Pq?sovB>jR{4xe zpe>aH0y&mBsx7(B1FTd_@`RPGr@4EduDNQN|8VKh(`PO+nN!y#63HX^?VyaEGe3i~ z;YC8@oyF?Rl9ScUy3*|DR|r<^&dyuwYu##Z4;+x2U|pZy*zKinvBVhuuq1)5h9_3DaKxV-^eV(;RbKEc3_@S4>lpp9*pJ$&q z^Zn)_54!P5tGC6wOX`w3?`Cj8l}$u+>yg_HiczkvX~%qSwobCTRX(@Kv09LMEZ?$m zoFVU;OQ7z| z(D75EN<%AK<9~Isn|$n2<|q4;zMrz?S?RRET%&Qn+udyAKZ5BeIhy?7v|AgS$RhA^q8^yfWg8=z(5AB2=h?n<)3{tc9*Y9Ra5OJ*8ZQuqAJiL za>rAlpY85LG2S!V&n4yZW&|$jsypsHZ5t~l{r$GDj5e)>KLr|>eK5Et!*gfEgSGCv z!rQAY4E0+Nd>(Kz+ekUC`fh^D<{KLl2M#9!kNaL~xsu8%j`Uw?eB4n{S?PAI?!^x> zd0BAwwq;WlHhaGN*8Zu5L-W?6ESJuCwTC@b+l|J9U;ET&J?>`L;+u4Z>A@pYONzrc z{m`-mp4PzoslK_uXcRndt(y6RCNWM8vG+ci8vwMYE6{?hpNf`zAJD4*z6nfcwZ1t?{e0Fm{ z<+@)MEy`*f!Tq)Ez4-B)YrvF3UB&Jx1Df_r?DgG(492oG2X_^IW^LahfD=Y6*t`lH z@k`^m@+XVOq?Lr@s`h~9u9!LtyCcd2r6eaaTb>`f>`xW zNfhr#t+3#YhtL-52~>DEEc+^ zTyI)u%ywKAx;Q2H;$*i3{RO!!j-@V0iX|tUVgH2rofpr(>g;`ax8NLBb9?;unuX0_ z!k5?Eov9&KAxB%07`vq@u?}R3ATPL(y6qq305+YyK4$Dm+fk4FLaKZt_e|IF zb|w|Kj429>tK72h`Jv9@W%r?u_w#G>AD)ojOdh#z@$vBoEP{?-dvCT=@VPM!?h80E z?5KsctvAU+r=9x8d(!@McSHUUE!p z35zT^KGEjJ331Mqw7Tk#7CS?6Pwo~;91gj`QP&2o=Rz8f?8$kS+a67DI2<8L+%nrv zpX@F`Pt^$ZiAmv+H&(9kp64{~iwD}&rieM;-Qqc|$v*6QGM+#B8lztS)xJdM=VA^Q7SIzMt@mSoZqrf>Yr0rQW z(*g@8u4i@C&;7E?(&_es+%LRbMwNUh7g@J9t{+;uc~UjItYgs8UnXhtUKX7%$8$G1 z&I~+1U6+w`s)?v;uSeIOO*FWBI^f z_oN~1X|0Ekl$8$od94>2VAn9@g>6Ma@ZRQu9k!Q09(ibq&k?RqW@pB&k-E;{8cvP= g)`^6tle}Is3WF4FHyRuqO@GW~UIEervmz7!1* Date: Sat, 17 Jul 2021 15:50:32 +0530 Subject: [PATCH 123/947] adds #7 on youtube --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9a7c337..7c61c20 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,8 @@ ## Problems | # | Name | Difficulty | Solution | Youtube | |:--------:|------|:----------:|:--------:|:----------------------:| -| 1 | [Two Sum](https://leetcode.com/problems/two-sum/) | Easy | [![Java](assets/java.png)](src/TwoSum.java) [![Python](assets/python.png)](python/two_sum.py) | [![java-yt](assets/java-yt.png)]() [![java-yt](assets/python-yt.png)]() | -| 7 | [Reverse Integer](https://leetcode.com/problems/reverse-integer/) | Easy | [![Java](assets/java.png)](src/ReverseInteger.java) [![Python](assets/python.png)](python/reverse_integer.py) | +| 1 | [Two Sum](https://leetcode.com/problems/two-sum/) | Easy | [![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) | +| 7 | [Reverse Integer](https://leetcode.com/problems/reverse-integer/) | Easy | [![Java](assets/java.png)](src/ReverseInteger.java) [![Python](assets/python.png)](python/reverse_integer.py) | [![java-yt](assets/java-yt.png)](https://youtu.be/7bOhyl5lWjI) [![python-yt](assets/python-yt.png)](https://youtu.be/lmLG30TLcSg) | | 9 | [PalindromeNumber](https://leetcode.com/problems/palindrome-number/) | Easy | [![Java](assets/java.png)](src/PalindromeNumber.java) [![Python](assets/python.png)](python/palindrome_number.py) | | 13 | [Roman To Integer](https://leetcode.com/problems/roman-to-integer/) | Easy | [![Java](assets/java.png)](src/RomanToInteger.java) [![Python](assets/python.png)](python/roman_to_integer.py) | | 14 | [Longest Common Prefix](https://leetcode.com/problems/longest-common-prefix/) | Easy | [![Java](assets/java.png)](src/LongestCommonPrefix.java) [![Python](assets/python.png)](python/longest_common_prefix.py) | From 10aee2fa9f1f33eed55ad63295cd8ca859670703 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 17 Jul 2021 16:12:37 +0530 Subject: [PATCH 124/947] solves fibonacci number --- README.md | 2 +- python/fibonacci_number.py | 6 ++++++ src/FibonacciNumber.java | 11 +++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 python/fibonacci_number.py create mode 100644 src/FibonacciNumber.java diff --git a/README.md b/README.md index 7c61c20..5a6e107 100644 --- a/README.md +++ b/README.md @@ -136,7 +136,7 @@ | 504 | [Base 7](https://leetcode.com/problems/base-7) | Easy | [![Java](assets/java.png)](src/Base7.java) [![Python](assets/python.png)](python/base_7.py) | | 506 | [Relative Ranks](https://leetcode.com/problems/relative-ranks) | Easy | [![Java](assets/java.png)](src/RelativeRanks.java) [![Python](assets/python.png)](python/relative_ranks.py) | | 507 | [Perfect Number](https://leetcode.com/problems/perfect-number) | Easy | [![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) | Easy | | +| 509 | [Fibonacci Number](https://leetcode.com/problems/fibonacci-number) | Easy | [![Java](assets/java.png)](src/FibonacciNumber.java) [![Python](assets/python.png)](python/fibonacci_number.py) | | 520 | [Detect Capital](https://leetcode.com/problems/detect-capital) | Easy | | | 521 | [Longest Uncommon Subsequence I](https://leetcode.com/problems/longest-uncommon-subsequence-i) | Easy | | | 530 | [Minimum Absolute Difference in BST](https://leetcode.com/problems/minimum-absolute-difference-in-bst) | Easy | | diff --git a/python/fibonacci_number.py b/python/fibonacci_number.py new file mode 100644 index 0000000..a602ef8 --- /dev/null +++ b/python/fibonacci_number.py @@ -0,0 +1,6 @@ +class Solution: + def fib(self, n: int) -> int: + prev, current = 0, 1 + for i in range(n): + prev, current = current, prev + current + return prev diff --git a/src/FibonacciNumber.java b/src/FibonacciNumber.java new file mode 100644 index 0000000..b8970ba --- /dev/null +++ b/src/FibonacciNumber.java @@ -0,0 +1,11 @@ +public class FibonacciNumber { + public int fib(int n) { + int previous = 0, current = 1, temp1; + for (int i = 0 ; i < n ; i++) { + temp1 = current; + current = previous + current; + previous = temp1; + } + return previous; + } +} From 4f583168b46fbf9953bd0dd4b86bc515f7d15bd4 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 17 Jul 2021 16:41:40 +0530 Subject: [PATCH 125/947] solves detect capital --- README.md | 2 +- python/detect_capital.py | 9 +++++++++ src/DetectCapital.java | 27 +++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 python/detect_capital.py create mode 100644 src/DetectCapital.java diff --git a/README.md b/README.md index 5a6e107..7f61d46 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,7 @@ | 506 | [Relative Ranks](https://leetcode.com/problems/relative-ranks) | Easy | [![Java](assets/java.png)](src/RelativeRanks.java) [![Python](assets/python.png)](python/relative_ranks.py) | | 507 | [Perfect Number](https://leetcode.com/problems/perfect-number) | Easy | [![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) | Easy | [![Java](assets/java.png)](src/FibonacciNumber.java) [![Python](assets/python.png)](python/fibonacci_number.py) | -| 520 | [Detect Capital](https://leetcode.com/problems/detect-capital) | Easy | | +| 520 | [Detect Capital](https://leetcode.com/problems/detect-capital) | Easy | [![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) | Easy | | | 530 | [Minimum Absolute Difference in BST](https://leetcode.com/problems/minimum-absolute-difference-in-bst) | Easy | | | 532 | [K - Diff Pairs in Array](https://leetcode.com/problems/k-diff-pairs-in-an-array) | Easy | | diff --git a/python/detect_capital.py b/python/detect_capital.py new file mode 100644 index 0000000..5d1323a --- /dev/null +++ b/python/detect_capital.py @@ -0,0 +1,9 @@ +class Solution: + def detectCapitalUse(self, word: str) -> bool: + return word.isupper() or word.islower() or word[0].isupper() and self.isLower(word, 1) + + def isLower(self, word: str, start: int) -> bool: + for index in range(start, len(word)): + if word[index].isupper(): + return False + return True diff --git a/src/DetectCapital.java b/src/DetectCapital.java new file mode 100644 index 0000000..9bf8de4 --- /dev/null +++ b/src/DetectCapital.java @@ -0,0 +1,27 @@ +public class DetectCapital { + public boolean detectCapitalUse(String word) { + return isAllCaps(word) || isAllLowerCase(word, 0) || firstCharIsCapital(word); + } + + private boolean isAllCaps(String string) { + for (int index = 0 ; index < string.length() ; index++) { + if (Character.isLowerCase(string.charAt(index))) { + return false; + } + } + return true; + } + + private boolean isAllLowerCase(String string, int start) { + for (int index = start ; index < string.length() ; index++) { + if (Character.isUpperCase(string.charAt(index))) { + return false; + } + } + return true; + } + + private boolean firstCharIsCapital(String string) { + return Character.isUpperCase(string.charAt(0)) && isAllLowerCase(string, 1); + } +} From 68aacea629f6c74267884986d6fd41193339d3e7 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 17 Jul 2021 16:48:59 +0530 Subject: [PATCH 126/947] solves longest uncommon subsequence --- README.md | 2 +- python/longest_uncommon_subsequence_I.py | 4 ++++ src/LongestUncommonSubsequenceI.java | 6 ++++++ 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 python/longest_uncommon_subsequence_I.py create mode 100644 src/LongestUncommonSubsequenceI.java diff --git a/README.md b/README.md index 7f61d46..b5f671c 100644 --- a/README.md +++ b/README.md @@ -138,7 +138,7 @@ | 507 | [Perfect Number](https://leetcode.com/problems/perfect-number) | Easy | [![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) | Easy | [![Java](assets/java.png)](src/FibonacciNumber.java) [![Python](assets/python.png)](python/fibonacci_number.py) | | 520 | [Detect Capital](https://leetcode.com/problems/detect-capital) | Easy | [![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) | Easy | | +| 521 | [Longest Uncommon Subsequence I](https://leetcode.com/problems/longest-uncommon-subsequence-i) | Easy | [![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) | Easy | | | 532 | [K - Diff Pairs in Array](https://leetcode.com/problems/k-diff-pairs-in-an-array) | Easy | | | 538 | [Convert BST to Greater Tree](https://leetcode.com/problems/convert-bst-to-greater-tree) | Easy | | diff --git a/python/longest_uncommon_subsequence_I.py b/python/longest_uncommon_subsequence_I.py new file mode 100644 index 0000000..b107546 --- /dev/null +++ b/python/longest_uncommon_subsequence_I.py @@ -0,0 +1,4 @@ +class Solution: + def findLUSlength(self, a: str, b: str) -> int: + if a == b: return -1 + return max(len(a), len(b)) diff --git a/src/LongestUncommonSubsequenceI.java b/src/LongestUncommonSubsequenceI.java new file mode 100644 index 0000000..6d04e51 --- /dev/null +++ b/src/LongestUncommonSubsequenceI.java @@ -0,0 +1,6 @@ +public class LongestUncommonSubsequenceI { + public int findLUSlength(String a, String b) { + if (a.equals(b)) return -1; + return Math.max(a.length(), b.length()); + } +} From 4c64374197170ed1095bf5a5cb3fc4f7c0b1ce9f Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 17 Jul 2021 17:19:52 +0530 Subject: [PATCH 127/947] solves 783 and 530 --- README.md | 4 +-- python/minimum_absolute_difference_in_bst.py | 21 +++++++++++++++ python/minimum_distance_between_bst_nodes.py | 22 +++++++++++++++ src/MinimumAbsoluteDifferenceInBST.java | 15 +++++++++++ src/MinimumDistanceBetweenBSTNodes.java | 28 ++++++++++++++++++++ 5 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 python/minimum_absolute_difference_in_bst.py create mode 100644 python/minimum_distance_between_bst_nodes.py create mode 100644 src/MinimumAbsoluteDifferenceInBST.java create mode 100644 src/MinimumDistanceBetweenBSTNodes.java diff --git a/README.md b/README.md index b5f671c..297e636 100644 --- a/README.md +++ b/README.md @@ -139,7 +139,7 @@ | 509 | [Fibonacci Number](https://leetcode.com/problems/fibonacci-number) | Easy | [![Java](assets/java.png)](src/FibonacciNumber.java) [![Python](assets/python.png)](python/fibonacci_number.py) | | 520 | [Detect Capital](https://leetcode.com/problems/detect-capital) | Easy | [![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) | Easy | [![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) | Easy | | +| 530 | [Minimum Absolute Difference in BST](https://leetcode.com/problems/minimum-absolute-difference-in-bst) | Easy | [![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) | Easy | | | 538 | [Convert BST to Greater Tree](https://leetcode.com/problems/convert-bst-to-greater-tree) | Easy | | | 541 | [Reverse String II](https://leetcode.com/problems/reverse-string-ii) | Easy | | @@ -205,7 +205,7 @@ | 762 | [Prime Number of Set Bits in Primary Representation](https://leetcode.com/problems/prime-number-of-set-bits-in-binary-representation) | Easy | | | 766 | [Toeplitz Matrix](https://leetcode.com/problems/toeplitz-matrix) | Easy | | | 771 | [Jewels and Stones](https://leetcode.com/problems/jewels-and-stones) | Easy | | -| 783 | [Minimum Distance Between BST Nodes](https://leetcode.com/problems/minimum-distance-between-bst-nodes) | Easy | | +| 783 | [Minimum Distance Between BST Nodes](https://leetcode.com/problems/minimum-distance-between-bst-nodes) | Easy | [![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) | Easy | | | 796 | [Rotate String](https://leetcode.com/problems/rotate-string) | Easy | | | 800 | [Similar RGB Color](https://leetcode.com/problems/similar-rgb-color) | Easy | | diff --git a/python/minimum_absolute_difference_in_bst.py b/python/minimum_absolute_difference_in_bst.py new file mode 100644 index 0000000..3f216b4 --- /dev/null +++ b/python/minimum_absolute_difference_in_bst.py @@ -0,0 +1,21 @@ +# Definition for a binary tree node. +class TreeNode: + def __init__(self, val=0, left=None, right=None): + self.val = val + self.left = left + self.right = right + +class Solution: + def __init__(self): + self.infinity = float('inf') + self.result = self.infinity + + def computeMinimumAbsDifference(self, root: TreeNode, left: float, right: float): + if root is None: return + self.result = min(self.result, root.val - left, right- root.val) + self.computeMinimumAbsDifference(root.left, left, root.val) + self.computeMinimumAbsDifference(root.right, root.val, right) + + def getMinimumDifference(self, root: TreeNode) -> int: + self.computeMinimumAbsDifference(root, -self.infinity, self.infinity) + return int(self.result) diff --git a/python/minimum_distance_between_bst_nodes.py b/python/minimum_distance_between_bst_nodes.py new file mode 100644 index 0000000..0cc5736 --- /dev/null +++ b/python/minimum_distance_between_bst_nodes.py @@ -0,0 +1,22 @@ +# Definition for a binary tree node. +class TreeNode: + def __init__(self, val=0, left=None, right=None): + self.val = val + self.left = left + self.right = right + + +class Solution: + def __init__(self): + self.infinity = float('inf') + self.result = self.infinity + + def computeMinimumAbsDifference(self, root: TreeNode, left: float, right: float): + if root is None: return + self.result = min(self.result, root.val - left, right- root.val) + self.computeMinimumAbsDifference(root.left, left, root.val) + self.computeMinimumAbsDifference(root.right, root.val, right) + + def minDiffInBST(self, root: TreeNode) -> int: + self.computeMinimumAbsDifference(root, -self.infinity, self.infinity) + return int(self.result) diff --git a/src/MinimumAbsoluteDifferenceInBST.java b/src/MinimumAbsoluteDifferenceInBST.java new file mode 100644 index 0000000..5f59331 --- /dev/null +++ b/src/MinimumAbsoluteDifferenceInBST.java @@ -0,0 +1,15 @@ +public class MinimumAbsoluteDifferenceInBST { + long result = Integer.MAX_VALUE; + + public int getMinimumDifference(TreeNode root) { + computeMinAbsoluteDifference(root, Integer.MIN_VALUE, Integer.MAX_VALUE); + return (int) result; + } + + public void computeMinAbsoluteDifference(TreeNode root, long left, long right) { + if (root == null) return; + result = Math.min(result, Math.min(root.val - left, right - root.val)); + computeMinAbsoluteDifference(root.left, left, root.val); + computeMinAbsoluteDifference(root.right, root.val, right); + } +} diff --git a/src/MinimumDistanceBetweenBSTNodes.java b/src/MinimumDistanceBetweenBSTNodes.java new file mode 100644 index 0000000..ce8fe6c --- /dev/null +++ b/src/MinimumDistanceBetweenBSTNodes.java @@ -0,0 +1,28 @@ +class TreeNode { + int val; + TreeNode left; + TreeNode right; + TreeNode() {} + TreeNode(int val) { this.val = val; } + TreeNode(int val, TreeNode left, TreeNode right) { + this.val = val; + this.left = left; + this.right = right; + } +} + +public class MinimumDistanceBetweenBSTNodes { + long result = Integer.MAX_VALUE; + + public int minDiffInBST(TreeNode root) { + computeMinAbsoluteDifference(root, Integer.MIN_VALUE, Integer.MAX_VALUE); + return (int) result; + } + + public void computeMinAbsoluteDifference(TreeNode root, long left, long right) { + if (root == null) return; + result = Math.min(result, Math.min(root.val - left, right - root.val)); + computeMinAbsoluteDifference(root.left, left, root.val); + computeMinAbsoluteDifference(root.right, root.val, right); + } +} From 4c4b62f2d69314be345860d739e811ee68f05754 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 17 Jul 2021 18:04:52 +0530 Subject: [PATCH 128/947] solves k diff pair inan array --- README.md | 2 +- python/k_dif_pairs_in_an_array.py | 20 ++++++++++++++++++++ src/KDiffPairsInAnArray.java | 29 +++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 python/k_dif_pairs_in_an_array.py create mode 100644 src/KDiffPairsInAnArray.java diff --git a/README.md b/README.md index 297e636..09e4de0 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,7 @@ | 520 | [Detect Capital](https://leetcode.com/problems/detect-capital) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | | +| 532 | [K - Diff Pairs in Array](https://leetcode.com/problems/k-diff-pairs-in-an-array) | Easy | [![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) | Easy | | | 541 | [Reverse String II](https://leetcode.com/problems/reverse-string-ii) | Easy | | | 543 | [Diameter of Binary Tree](https://leetcode.com/problems/diameter-of-binary-tree) | Easy | | diff --git a/python/k_dif_pairs_in_an_array.py b/python/k_dif_pairs_in_an_array.py new file mode 100644 index 0000000..ece3056 --- /dev/null +++ b/python/k_dif_pairs_in_an_array.py @@ -0,0 +1,20 @@ +from typing import List + + +class Solution: + def findPairs(self, nums: List[int], k: int) -> int: + pairs = 0 + if k == 0: + frequencies = {} + for number in nums: + frequencies[number] = frequencies.get(number, 0) + 1 + for frequency in frequencies.values(): + pairs += 1 if frequency > 1 else 0 + else: + numbers = set() + for number in nums: + if number not in numbers: + pairs += 1 if (number - k) in numbers else 0 + pairs += 1 if (number + k) in numbers else 0 + numbers.add(number) + return pairs diff --git a/src/KDiffPairsInAnArray.java b/src/KDiffPairsInAnArray.java new file mode 100644 index 0000000..5d56213 --- /dev/null +++ b/src/KDiffPairsInAnArray.java @@ -0,0 +1,29 @@ +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public class KDiffPairsInAnArray { + public int findPairs(int[] nums, int k) { + int pairs= 0; + if (k == 0) { + Map frequencies = new HashMap<>(); + for (int number : nums) { + frequencies.put(number, frequencies.getOrDefault(number, 0) + 1); + } + for (int frequency : frequencies.values()) { + pairs += frequency > 1 ? 1 : 0; + } + } else { + Set numbers = new HashSet<>(); + for (int number : nums) { + if (!numbers.contains(number)) { + pairs += numbers.contains(number - k) ? 1 : 0; + pairs += numbers.contains(number + k) ? 1 : 0; + numbers.add(number); + } + } + } + return pairs; + } +} From 82da3a17026134b94bd33966b234ab0f56edb14f Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 18 Jul 2021 01:23:22 +0530 Subject: [PATCH 129/947] solves bst to greater tree --- README.md | 2 +- python/convert_bst_to_greater_tree.py | 22 ++++++++++++++++++++++ src/ConvertBSTToGreaterTree.java | 15 +++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 python/convert_bst_to_greater_tree.py create mode 100644 src/ConvertBSTToGreaterTree.java diff --git a/README.md b/README.md index 09e4de0..37fec23 100644 --- a/README.md +++ b/README.md @@ -141,7 +141,7 @@ | 521 | [Longest Uncommon Subsequence I](https://leetcode.com/problems/longest-uncommon-subsequence-i) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | | +| 538 | [Convert BST to Greater Tree](https://leetcode.com/problems/convert-bst-to-greater-tree) | Easy | [![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) | Easy | | | 543 | [Diameter of Binary Tree](https://leetcode.com/problems/diameter-of-binary-tree) | Easy | | | 551 | [Student Attendance Record I](https://leetcode.com/problems/student-attendance-record-i) | Easy | | diff --git a/python/convert_bst_to_greater_tree.py b/python/convert_bst_to_greater_tree.py new file mode 100644 index 0000000..0ddffee --- /dev/null +++ b/python/convert_bst_to_greater_tree.py @@ -0,0 +1,22 @@ +# Definition for a binary tree node. +class TreeNode: + def __init__(self, val=0, left=None, right=None): + self.val = val + self.left = left + self.right = right + + +class Solution: + def __init__(self): + self.value = 0 + + def computeGreaterTree(self, root: TreeNode): + if root is None: return + self.computeGreaterTree(root.right) + root.val += self.value + self.value = root.val + self.computeGreaterTree(root.left) + + def convertBST(self, root: TreeNode) -> TreeNode: + self.computeGreaterTree(root) + return root diff --git a/src/ConvertBSTToGreaterTree.java b/src/ConvertBSTToGreaterTree.java new file mode 100644 index 0000000..005ef91 --- /dev/null +++ b/src/ConvertBSTToGreaterTree.java @@ -0,0 +1,15 @@ +public class ConvertBSTToGreaterTree { + int value = 0; + + public TreeNode convertBST(TreeNode root) { + computeGreaterTree(root); + return root; + } + + private void computeGreaterTree(TreeNode root) { + if (root == null) return; + computeGreaterTree(root.right); + root.val += value; + computeGreaterTree(root.left); + } +} From c8c2649ca6df1363dbe64346cf0d735bfd3bde7f Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 18 Jul 2021 22:44:17 +0530 Subject: [PATCH 130/947] solves reverse string ii --- README.md | 2 +- python/reverse_string_ii.py | 15 +++++++++++++++ src/ReverseStringII.java | 16 ++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 python/reverse_string_ii.py create mode 100644 src/ReverseStringII.java diff --git a/README.md b/README.md index 37fec23..bf17911 100644 --- a/README.md +++ b/README.md @@ -142,7 +142,7 @@ | 530 | [Minimum Absolute Difference in BST](https://leetcode.com/problems/minimum-absolute-difference-in-bst) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | | +| 541 | [Reverse String II](https://leetcode.com/problems/reverse-string-ii) | Easy | [![Java](assets/java.png)](srcReverseStringII.java/) [![Python](assets/python.png)](python/reverse_string_ii.py) | | 543 | [Diameter of Binary Tree](https://leetcode.com/problems/diameter-of-binary-tree) | Easy | | | 551 | [Student Attendance Record I](https://leetcode.com/problems/student-attendance-record-i) | Easy | | | 557 | [Reverse Words in a String III](https://leetcode.com/problems/reverse-words-in-a-string-iii) | Easy | | diff --git a/python/reverse_string_ii.py b/python/reverse_string_ii.py new file mode 100644 index 0000000..abc1a1b --- /dev/null +++ b/python/reverse_string_ii.py @@ -0,0 +1,15 @@ +class Solution: + def reverseStr(self, s: str, k: int) -> str: + result = '' + index = 0 + while index < len(s): + reverse_len = min(k, len(s) - index) + for i in range(index + reverse_len - 1, index - 1, -1): + result += s[i] + index += k + for i in range(index, index + k): + if i >= len(s): + break + result += s[i] + index += k + return result diff --git a/src/ReverseStringII.java b/src/ReverseStringII.java new file mode 100644 index 0000000..8c597cf --- /dev/null +++ b/src/ReverseStringII.java @@ -0,0 +1,16 @@ +public class ReverseStringII { + public String reverseStr(String s, int k) { + StringBuilder result = new StringBuilder(); + for (int index = 0 ; index < s.length() ; ) { + for (int j = 0, reverseLength = Math.min(k, s.length() - index); j < reverseLength ; j++) { + result.append(s.charAt(index + reverseLength - j - 1)); + } + index += k; + for (int j = 0 ; j < k && index + j < s.length() ; j++) { + result.append(s.charAt(index + j)); + } + index += k; + } + return result.toString(); + } +} From 825a427002b0f5341ef6798ca8d1780dd0ef5777 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 18 Jul 2021 22:45:07 +0530 Subject: [PATCH 131/947] updates problems solved count --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bf17911..4f19937 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-112/571-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-112/1571-1abc9c.svg) -![problems-solved-python](https://img.shields.io/badge/Python-112/1571-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-120/571-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-120/1571-1abc9c.svg) +![problems-solved-python](https://img.shields.io/badge/Python-120/1571-1abc9c.svg) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md) 🔒 = Subscription Content From 27c3f0434aa6bd82d6458e46abccc480311fee69 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 18 Jul 2021 22:58:33 +0530 Subject: [PATCH 132/947] solves diamter of binary tree --- README.md | 4 ++-- python/diameter_of_binary_tree.py | 22 ++++++++++++++++++++++ src/DiameterOfBinaryTree.java | 16 ++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 python/diameter_of_binary_tree.py create mode 100644 src/DiameterOfBinaryTree.java diff --git a/README.md b/README.md index 4f19937..247e0a7 100644 --- a/README.md +++ b/README.md @@ -142,8 +142,8 @@ | 530 | [Minimum Absolute Difference in BST](https://leetcode.com/problems/minimum-absolute-difference-in-bst) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | [![Java](assets/java.png)](srcReverseStringII.java/) [![Python](assets/python.png)](python/reverse_string_ii.py) | -| 543 | [Diameter of Binary Tree](https://leetcode.com/problems/diameter-of-binary-tree) | Easy | | +| 541 | [Reverse String II](https://leetcode.com/problems/reverse-string-ii) | Easy | [![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) | Easy | [![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) | Easy | | | 557 | [Reverse Words in a String III](https://leetcode.com/problems/reverse-words-in-a-string-iii) | Easy | | | 559 | [Maximum Depth of N-Ary Tree](https://leetcode.com/problems/maximum-depth-of-n-ary-tree) | Easy | | diff --git a/python/diameter_of_binary_tree.py b/python/diameter_of_binary_tree.py new file mode 100644 index 0000000..bbc6f05 --- /dev/null +++ b/python/diameter_of_binary_tree.py @@ -0,0 +1,22 @@ +# Definition for a binary tree node. +class TreeNode: + def __init__(self, val=0, left=None, right=None): + self.val = val + self.left = left + self.right = right + + +class Solution: + def __init__(self): + self.diameter = 0 + + def computerDiameterOfBinaryTree(self, root: TreeNode) -> int: + if root is None: return 0 + leftHeight = self.computerDiameterOfBinaryTree(root.left) + rightHeight = self.computerDiameterOfBinaryTree(root.right) + self.diameter = max(self.diameter, leftHeight + rightHeight) + return 1 + max(leftHeight, rightHeight) + + def diameterOfBinaryTree(self, root: TreeNode) -> int: + self.computerDiameterOfBinaryTree(root) + return self.diameter diff --git a/src/DiameterOfBinaryTree.java b/src/DiameterOfBinaryTree.java new file mode 100644 index 0000000..e86402e --- /dev/null +++ b/src/DiameterOfBinaryTree.java @@ -0,0 +1,16 @@ +public class DiameterOfBinaryTree { + int diameter = 0; + + public int diameterOfBinaryTree(TreeNode root) { + computerDiameterOfBinaryTree(root); + return diameter; + } + + private int computerDiameterOfBinaryTree(TreeNode root) { + if (root == null) return 0; + int leftHeight = computerDiameterOfBinaryTree(root.left); + int rightHeight = computerDiameterOfBinaryTree(root.right); + diameter = Math.max(diameter, leftHeight + rightHeight); + return 1 + Math.max(leftHeight, rightHeight); + } +} From 72671dae9b5716955c61415273b73466d89a4cb0 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 19 Jul 2021 01:11:31 +0530 Subject: [PATCH 133/947] solves student attendancerecord I --- README.md | 2 +- python/student_attendance_record_I.py | 11 +++++++++++ src/StudentAttendanceRecordI.java | 17 +++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 python/student_attendance_record_I.py create mode 100644 src/StudentAttendanceRecordI.java diff --git a/README.md b/README.md index 247e0a7..3d43323 100644 --- a/README.md +++ b/README.md @@ -144,7 +144,7 @@ | 538 | [Convert BST to Greater Tree](https://leetcode.com/problems/convert-bst-to-greater-tree) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | | +| 551 | [Student Attendance Record I](https://leetcode.com/problems/student-attendance-record-i) | Easy | [![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) | Easy | | | 559 | [Maximum Depth of N-Ary Tree](https://leetcode.com/problems/maximum-depth-of-n-ary-tree) | Easy | | | 561 | [Array Partition I](https://leetcode.com/problems/array-partition-i) | Easy | | diff --git a/python/student_attendance_record_I.py b/python/student_attendance_record_I.py new file mode 100644 index 0000000..12f7a87 --- /dev/null +++ b/python/student_attendance_record_I.py @@ -0,0 +1,11 @@ +class Solution: + def checkRecord(self, s: str) -> bool: + consecutiveLate, absent = 0, 0 + for character in s: + if character == 'L': + consecutiveLate += 1 + else: + if character == 'A': absent += 1 + consecutiveLate = 0 + if consecutiveLate >= 3 or absent >= 2: return False + return True diff --git a/src/StudentAttendanceRecordI.java b/src/StudentAttendanceRecordI.java new file mode 100644 index 0000000..5d0cd97 --- /dev/null +++ b/src/StudentAttendanceRecordI.java @@ -0,0 +1,17 @@ +public class StudentAttendanceRecordI { + public boolean checkRecord(String s) { + int consecutiveLate = 0, absentees = 0; + for (int index = 0 ; index < s.length() ; index++) { + if (s.charAt(index) == 'L') { + consecutiveLate++; + } else { + if (s.charAt(index) == 'A') absentees++; + consecutiveLate = 0; + } + if (absentees >= 2 || consecutiveLate >= 3) { + return false; + } + } + return true; + } +} From e74dfac82e8de6b641418a8ed4654a95dc8d163f Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 19 Jul 2021 01:23:14 +0530 Subject: [PATCH 134/947] solves reverse words in string iii --- README.md | 2 +- python/reverse_words_in_string_iii.py | 6 ++++++ src/ReverseWordsInStringIII.java | 15 +++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 python/reverse_words_in_string_iii.py create mode 100644 src/ReverseWordsInStringIII.java diff --git a/README.md b/README.md index 3d43323..2501f08 100644 --- a/README.md +++ b/README.md @@ -145,7 +145,7 @@ | 541 | [Reverse String II](https://leetcode.com/problems/reverse-string-ii) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | | +| 557 | [Reverse Words in a String III](https://leetcode.com/problems/reverse-words-in-a-string-iii) | Easy | [![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) | Easy | | | 561 | [Array Partition I](https://leetcode.com/problems/array-partition-i) | Easy | | | 563 | [Binary Tree Tilt](https://leetcode.com/problems/binary-tree-tilt) | Easy | | diff --git a/python/reverse_words_in_string_iii.py b/python/reverse_words_in_string_iii.py new file mode 100644 index 0000000..a73d252 --- /dev/null +++ b/python/reverse_words_in_string_iii.py @@ -0,0 +1,6 @@ +class Solution: + def reverseWords(self, s: str) -> str: + result = '' + for word in s.split(): + result += word[::-1] + ' ' + return result[:-1] diff --git a/src/ReverseWordsInStringIII.java b/src/ReverseWordsInStringIII.java new file mode 100644 index 0000000..dff133e --- /dev/null +++ b/src/ReverseWordsInStringIII.java @@ -0,0 +1,15 @@ +public class ReverseWordsInStringIII { + public String reverseWords(String s) { + StringBuilder result = new StringBuilder(), buffer = new StringBuilder(); + for (int index = 0 ; index < s.length() ; index++) { + if (s.charAt(index) == ' ') { + result.append(result.length() == 0 ? "" : ' ').append(buffer.reverse()); + buffer = new StringBuilder(); + } else { + buffer.append(s.charAt(index)); + } + } + result.append(result.length() == 0 ? "" : ' ').append(buffer.reverse()); + return result.toString(); + } +} From 96231cdc7d93327a9aac1de8d64c3848cd5518d8 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 19 Jul 2021 01:29:28 +0530 Subject: [PATCH 135/947] solves max depth of n ary tree --- README.md | 2 +- python/maximum_depth_of_n_ary_tree.py | 14 ++++++++++++++ src/MaximumDepthOfNAryTree.java | 28 +++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 python/maximum_depth_of_n_ary_tree.py create mode 100644 src/MaximumDepthOfNAryTree.java diff --git a/README.md b/README.md index 2501f08..a3cb194 100644 --- a/README.md +++ b/README.md @@ -146,7 +146,7 @@ | 543 | [Diameter of Binary Tree](https://leetcode.com/problems/diameter-of-binary-tree) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | | +| 559 | [Maximum Depth of N-Ary Tree](https://leetcode.com/problems/maximum-depth-of-n-ary-tree) | Easy | [![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) | Easy | | | 563 | [Binary Tree Tilt](https://leetcode.com/problems/binary-tree-tilt) | Easy | | | 566 | [Reshape The Matrix](https://leetcode.com/problems/reshape-the-matrix) | Easy | | diff --git a/python/maximum_depth_of_n_ary_tree.py b/python/maximum_depth_of_n_ary_tree.py new file mode 100644 index 0000000..d084998 --- /dev/null +++ b/python/maximum_depth_of_n_ary_tree.py @@ -0,0 +1,14 @@ +# Definition for a Node. +class Node: + def __init__(self, val=None, children=None): + self.val = val + self.children = children + + +class Solution: + def maxDepth(self, root: Node) -> int: + if root is None: return 0 + max_depth = 0 + for child in root.children: + max_depth = max(max_depth, self.maxDepth(child)) + return 1 + max_depth diff --git a/src/MaximumDepthOfNAryTree.java b/src/MaximumDepthOfNAryTree.java new file mode 100644 index 0000000..227c76d --- /dev/null +++ b/src/MaximumDepthOfNAryTree.java @@ -0,0 +1,28 @@ +import java.util.List; + +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 class MaximumDepthOfNAryTree { + public int maxDepth(Node root) { + if (root == null) return 0; + int maxDepth = 0; + for (Node child : root.children) { + maxDepth = Math.max(maxDepth, maxDepth(child)); + } + return 1 + maxDepth; + } +} From a2233ea07c6753ba30b956eafb45db46430e8bda Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 19 Jul 2021 01:36:29 +0530 Subject: [PATCH 136/947] solves array partition I --- README.md | 2 +- python/array_partiton_I.py | 10 ++++++++++ src/ArrayPartitionI.java | 12 ++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 python/array_partiton_I.py create mode 100644 src/ArrayPartitionI.java diff --git a/README.md b/README.md index a3cb194..710973b 100644 --- a/README.md +++ b/README.md @@ -147,7 +147,7 @@ | 551 | [Student Attendance Record I](https://leetcode.com/problems/student-attendance-record-i) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | | +| 561 | [Array Partition I](https://leetcode.com/problems/array-partition-i) | Easy | [![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) | Easy | | | 566 | [Reshape The Matrix](https://leetcode.com/problems/reshape-the-matrix) | Easy | | | 572 | [Subtree of Another Tree](https://leetcode.com/problems/subtree-of-another-tree) | Easy | | diff --git a/python/array_partiton_I.py b/python/array_partiton_I.py new file mode 100644 index 0000000..492f8a5 --- /dev/null +++ b/python/array_partiton_I.py @@ -0,0 +1,10 @@ +from typing import List + + +class Solution: + def arrayPairSum(self, nums: List[int]) -> int: + nums.sort() + result = 0 + for i in range(0, len(nums) // 2): + result += min(nums[2 * i], nums[2 * i + 1]) + return result diff --git a/src/ArrayPartitionI.java b/src/ArrayPartitionI.java new file mode 100644 index 0000000..d4506a9 --- /dev/null +++ b/src/ArrayPartitionI.java @@ -0,0 +1,12 @@ +import java.util.Arrays; + +public class ArrayPartitionI { + public int arrayPairSum(int[] nums) { + Arrays.sort(nums); + int result = 0; + for (int index = 0 ; index < nums.length ; index += 2) { + result += Math.min(nums[index], nums[index + 1]); + } + return result; + } +} From 77c0df9062311120ae5b1d735a78b8d7355ac7ef Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 19 Jul 2021 01:43:30 +0530 Subject: [PATCH 137/947] solves binary tree tilt --- README.md | 2 +- python/binary_tree_tilt.py | 21 +++++++++++++++++++++ src/BinaryTreeTilt.java | 16 ++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 python/binary_tree_tilt.py create mode 100644 src/BinaryTreeTilt.java diff --git a/README.md b/README.md index 710973b..e9076c4 100644 --- a/README.md +++ b/README.md @@ -148,7 +148,7 @@ | 557 | [Reverse Words in a String III](https://leetcode.com/problems/reverse-words-in-a-string-iii) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | | +| 563 | [Binary Tree Tilt](https://leetcode.com/problems/binary-tree-tilt) | Easy | [![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) | Easy | | | 572 | [Subtree of Another Tree](https://leetcode.com/problems/subtree-of-another-tree) | Easy | | | 575 | [Distribute Candies](https://leetcode.com/problems/distribute-candies) | Easy | | diff --git a/python/binary_tree_tilt.py b/python/binary_tree_tilt.py new file mode 100644 index 0000000..89d5f23 --- /dev/null +++ b/python/binary_tree_tilt.py @@ -0,0 +1,21 @@ +# Definition for a binary tree node. +class TreeNode: + def __init__(self, val=0, left=None, right=None): + self.val = val + self.left = left + self.right = right + + +class Solution: + def __init__(self): + self.sumTilts = 0 + + def computeTilts(self, root: TreeNode) -> int: + if root is None: return 0 + leftSum, rightSum = self.computeTilts(root.left), self.computeTilts(root.right) + self.sumTilts += abs(leftSum - rightSum) + return leftSum + rightSum + root.val + + def findTilt(self, root: TreeNode) -> int: + self.computeTilts(root) + return self.sumTilts diff --git a/src/BinaryTreeTilt.java b/src/BinaryTreeTilt.java new file mode 100644 index 0000000..daa4b77 --- /dev/null +++ b/src/BinaryTreeTilt.java @@ -0,0 +1,16 @@ +public class BinaryTreeTilt { + public int sumTilts = 0; + + public int findTilt(TreeNode root) { + computeTilt(root); + return sumTilts; + } + + private int computeTilt(TreeNode root) { + if (root == null) return 0; + int leftSum = computeTilt(root.left); + int rightSum = computeTilt(root.right); + sumTilts += Math.abs(leftSum - rightSum); + return leftSum + rightSum + root.val; + } +} From 0108d7e536165b848bf447627075eaf6330af828 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 19 Jul 2021 02:00:45 +0530 Subject: [PATCH 138/947] solves reshape the matrix --- README.md | 2 +- python/reshape_the_matrix.py | 13 +++++++++++++ src/ReshapeTheMatrix.java | 13 +++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 python/reshape_the_matrix.py create mode 100644 src/ReshapeTheMatrix.java diff --git a/README.md b/README.md index e9076c4..c7264e8 100644 --- a/README.md +++ b/README.md @@ -149,7 +149,7 @@ | 559 | [Maximum Depth of N-Ary Tree](https://leetcode.com/problems/maximum-depth-of-n-ary-tree) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | | +| 566 | [Reshape The Matrix](https://leetcode.com/problems/reshape-the-matrix) | Easy | [![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) | Easy | | | 575 | [Distribute Candies](https://leetcode.com/problems/distribute-candies) | Easy | | | 581 | [Shortest Unsorted Continuous Subarray](https://leetcode.com/problems/shortest-unsorted-continuous-subarray) | Easy | | diff --git a/python/reshape_the_matrix.py b/python/reshape_the_matrix.py new file mode 100644 index 0000000..9edd722 --- /dev/null +++ b/python/reshape_the_matrix.py @@ -0,0 +1,13 @@ +from typing import List + + +class Solution: + def matrixReshape(self, mat: List[List[int]], r: int, c: int) -> List[List[int]]: + if r * c != len(mat) * len(mat[0]) or (r == len(mat) and c == len(mat[0])): return mat + result = [[0] * c for _ in range(r)] + k = 0 + for i in range(len(mat)): + for j in range(len(mat[0])): + result[k // c][k % c] = mat[i][j] + k += 1 + return result diff --git a/src/ReshapeTheMatrix.java b/src/ReshapeTheMatrix.java new file mode 100644 index 0000000..3f07791 --- /dev/null +++ b/src/ReshapeTheMatrix.java @@ -0,0 +1,13 @@ +public class ReshapeTheMatrix { + public int[][] matrixReshape(int[][] mat, int r, int c) { + if (r * c != mat.length * mat[0].length || (mat.length == r && mat[0].length == c)) return mat; + + int[][] result = new int[r][c]; + for (int i = 0, k = 0 ; i < mat.length ; i++) { + for (int j = 0 ; j < mat[0].length ; j++, k++) { + result[k / c][k % c] = mat[i][j]; + } + } + return result; + } +} From 94c76241b9de1ed0ac74411be24b858447744418 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 19 Jul 2021 12:05:54 +0530 Subject: [PATCH 139/947] adds palindrome number youtube videos --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c7264e8..625d994 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,8 @@ |:--------:|------|:----------:|:--------:|:----------------------:| | 1 | [Two Sum](https://leetcode.com/problems/two-sum/) | Easy | [![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) | | 7 | [Reverse Integer](https://leetcode.com/problems/reverse-integer/) | Easy | [![Java](assets/java.png)](src/ReverseInteger.java) [![Python](assets/python.png)](python/reverse_integer.py) | [![java-yt](assets/java-yt.png)](https://youtu.be/7bOhyl5lWjI) [![python-yt](assets/python-yt.png)](https://youtu.be/lmLG30TLcSg) | -| 9 | [PalindromeNumber](https://leetcode.com/problems/palindrome-number/) | Easy | [![Java](assets/java.png)](src/PalindromeNumber.java) [![Python](assets/python.png)](python/palindrome_number.py) | -| 13 | [Roman To Integer](https://leetcode.com/problems/roman-to-integer/) | Easy | [![Java](assets/java.png)](src/RomanToInteger.java) [![Python](assets/python.png)](python/roman_to_integer.py) | +| 9 | [PalindromeNumber](https://leetcode.com/problems/palindrome-number/) | Easy | [![Java](assets/java.png)](src/PalindromeNumber.java) [![Python](assets/python.png)](python/palindrome_number.py) | | +| 13 | [Roman To Integer](https://leetcode.com/problems/roman-to-integer/) | Easy | [![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/) | Easy | [![Java](assets/java.png)](src/LongestCommonPrefix.java) [![Python](assets/python.png)](python/longest_common_prefix.py) | | 20 | [ValidParentheses](https://leetcode.com/problems/valid-parentheses/) | Easy | [![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/) | Easy | [![Java](assets/java.png)](src/Merge2SortedLists.java) [![Python](assets/python.png)](python/merge_2_sorted_lists.py) | From ccd8c3f0841206b63f790a10bf88d0c5bd7e6182 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Tue, 20 Jul 2021 15:45:44 +0530 Subject: [PATCH 140/947] solves subtree of another tree --- README.md | 2 +- python/subtree_of_another_tree.py | 18 ++++++++++++++++++ src/SubtreeOfAnotherTree.java | 15 +++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 python/subtree_of_another_tree.py create mode 100644 src/SubtreeOfAnotherTree.java diff --git a/README.md b/README.md index 625d994..c9a314d 100644 --- a/README.md +++ b/README.md @@ -150,7 +150,7 @@ | 561 | [Array Partition I](https://leetcode.com/problems/array-partition-i) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | | +| 572 | [Subtree of Another Tree](https://leetcode.com/problems/subtree-of-another-tree) | Easy | [![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) | Easy | | | 581 | [Shortest Unsorted Continuous Subarray](https://leetcode.com/problems/shortest-unsorted-continuous-subarray) | Easy | | | 589 | [N-Ary Tree Preorder Traversal](https://leetcode.com/problems/n-ary-tree-preorder-traversal) | Easy | | diff --git a/python/subtree_of_another_tree.py b/python/subtree_of_another_tree.py new file mode 100644 index 0000000..0c48fef --- /dev/null +++ b/python/subtree_of_another_tree.py @@ -0,0 +1,18 @@ +# Definition for a binary tree node. +class TreeNode: + def __init__(self, val=0, left=None, right=None): + self.val = val + self.left = left + self.right = right + + +class Solution: + def areSame(self, root1: TreeNode, root2: TreeNode) -> bool: + if root1 is None and root2 is None: return True + if root1 is None or root2 is None: return False + return root1.val == root2.val and self.areSame(root1.left, root2.left) and self.areSame(root1.right, root2.right) + + def isSubtree(self, root: TreeNode, subRoot: TreeNode) -> bool: + if root is None: return False + if root.val == subRoot.val and self.areSame(root, subRoot): return True + return self.isSubtree(root.left, subRoot) or self.isSubtree(root.right, subRoot) diff --git a/src/SubtreeOfAnotherTree.java b/src/SubtreeOfAnotherTree.java new file mode 100644 index 0000000..84ad7b5 --- /dev/null +++ b/src/SubtreeOfAnotherTree.java @@ -0,0 +1,15 @@ +public class SubtreeOfAnotherTree { + public boolean isSubtree(TreeNode root, TreeNode subRoot) { + if (root == null) return false; + if (root.val == subRoot.val && areSame(root, subRoot)) { + return true; + } + return isSubtree(root.left, subRoot) || isSubtree(root.right, subRoot); + } + + private boolean areSame(TreeNode root, TreeNode subTree) { + if (subTree == null && root == null) return true; + if (root == null || subTree == null) return false; + return root.val == subTree.val && areSame(root.left, subTree.left) && areSame(root.right, subTree.right); + } +} From 7aacd93b0b3f16d90f5c87c936a5953f61c629e5 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Tue, 20 Jul 2021 15:52:34 +0530 Subject: [PATCH 141/947] solves distribute candies --- README.md | 2 +- python/distribute_candies.py | 6 ++++++ src/DistributeCandies.java | 13 +++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 python/distribute_candies.py create mode 100644 src/DistributeCandies.java diff --git a/README.md b/README.md index c9a314d..c2d3e5c 100644 --- a/README.md +++ b/README.md @@ -151,7 +151,7 @@ | 563 | [Binary Tree Tilt](https://leetcode.com/problems/binary-tree-tilt) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | | +| 575 | [Distribute Candies](https://leetcode.com/problems/distribute-candies) | Easy | [![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) | Easy | | | 589 | [N-Ary Tree Preorder Traversal](https://leetcode.com/problems/n-ary-tree-preorder-traversal) | Easy | | | 590 | [N-Ary Tree Postorder Traversal](https://leetcode.com/problems/n-ary-tree-postorder-traversal) | Easy | | diff --git a/python/distribute_candies.py b/python/distribute_candies.py new file mode 100644 index 0000000..dd77d40 --- /dev/null +++ b/python/distribute_candies.py @@ -0,0 +1,6 @@ +from typing import List + + +class Solution: + def distributeCandies(self, candyType: List[int]) -> int: + return min(len(candyType) // 2, len(set(candyType))) diff --git a/src/DistributeCandies.java b/src/DistributeCandies.java new file mode 100644 index 0000000..8f157ab --- /dev/null +++ b/src/DistributeCandies.java @@ -0,0 +1,13 @@ +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +public class DistributeCandies { + public int distributeCandies(int[] candyType) { + Set candyTypes = new HashSet<>(); + for (int type : candyType) { + candyTypes.add(type); + } + return Math.min(candyType.length / 2, candyTypes.size()); + } +} From fc01d34f851e16febb524de7cc93e069ba6b6a7c Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 23 Jul 2021 17:38:33 +0530 Subject: [PATCH 142/947] solves maximum unsorted subarray --- README.md | 2 +- python/shortest_continuous_unsorted_subarray.py | 12 ++++++++++++ src/ShortestUnsortedContinuousSubarray.java | 12 ++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 python/shortest_continuous_unsorted_subarray.py create mode 100644 src/ShortestUnsortedContinuousSubarray.java diff --git a/README.md b/README.md index c2d3e5c..3ec44e3 100644 --- a/README.md +++ b/README.md @@ -152,7 +152,7 @@ | 566 | [Reshape The Matrix](https://leetcode.com/problems/reshape-the-matrix) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | | +| 581 | [Shortest Unsorted Continuous Subarray](https://leetcode.com/problems/shortest-unsorted-continuous-subarray) | Medium | [![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) | Easy | | | 590 | [N-Ary Tree Postorder Traversal](https://leetcode.com/problems/n-ary-tree-postorder-traversal) | Easy | | | 594 | [Longest Harmonious Subsequence](https://leetcode.com/problems/longest-harmonious-subsequence) | Easy | | diff --git a/python/shortest_continuous_unsorted_subarray.py b/python/shortest_continuous_unsorted_subarray.py new file mode 100644 index 0000000..d8dc001 --- /dev/null +++ b/python/shortest_continuous_unsorted_subarray.py @@ -0,0 +1,12 @@ +from typing import List + + +class Solution: + def findUnsortedSubarray(self, array: List[int]) -> int: + l, r, maximum, minimum = len(array), 0, array[0], array[-1] + for index, value in enumerate(array): + if value < maximum: r = index + 1 + else: maximum = value + if array[len(array) - index - 1] > minimum: l = len(array) - 2 - index + else: minimum = array[len(array) - index - 1] + return max(0, r - l - 1) diff --git a/src/ShortestUnsortedContinuousSubarray.java b/src/ShortestUnsortedContinuousSubarray.java new file mode 100644 index 0000000..0ca2675 --- /dev/null +++ b/src/ShortestUnsortedContinuousSubarray.java @@ -0,0 +1,12 @@ +public class ShortestUnsortedContinuousSubarray { + public int findUnsortedSubarray(int[] nums) { + int n = nums.length, l = n, r = 0, max = nums[0], min = nums[n - 1]; + for (int i = 1; i < n; i++) { + if (nums[i] < max) r = i + 1; + else max = nums[i]; + if (nums[n - 1 - i] > min) l = n - 1 - i - 1; + else min = nums[n - 1 - i]; + } + return Math.max(0, r - l - 1); + } +} From 3a67a61f8372e1957f21fc202d112e493499c331 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 23 Jul 2021 17:46:47 +0530 Subject: [PATCH 143/947] solves n ary tree preorder traversal --- README.md | 2 +- python/n_ary_tree_preorder_traversal.py | 23 +++++++++++++++++++++++ src/NArayTreePreOrderTraversal.java | 19 +++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 python/n_ary_tree_preorder_traversal.py create mode 100644 src/NArayTreePreOrderTraversal.java diff --git a/README.md b/README.md index 3ec44e3..a9852d2 100644 --- a/README.md +++ b/README.md @@ -153,7 +153,7 @@ | 572 | [Subtree of Another Tree](https://leetcode.com/problems/subtree-of-another-tree) | Easy | [![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) | Easy | [![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) | Medium | [![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) | Easy | | +| 589 | [N-Ary Tree Preorder Traversal](https://leetcode.com/problems/n-ary-tree-preorder-traversal) | Easy | [![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) | Easy | | | 594 | [Longest Harmonious Subsequence](https://leetcode.com/problems/longest-harmonious-subsequence) | Easy | | | 598 | [Range Addition II](https://leetcode.com/problems/range-addition-ii) | Easy | | diff --git a/python/n_ary_tree_preorder_traversal.py b/python/n_ary_tree_preorder_traversal.py new file mode 100644 index 0000000..0426b50 --- /dev/null +++ b/python/n_ary_tree_preorder_traversal.py @@ -0,0 +1,23 @@ +# Definition for a Node. +from typing import List + + +class Node: + def __init__(self, val=None, children=None): + self.val = val + self.children = children + + +class Solution: + def __init__(self): + self.result = [] + + def preorderTraversal(self, root: Node) -> None: + if root is None: return None + self.result.append(root.val) + for child in root.children: + self.preorderTraversal(child) + + def preorder(self, root: Node) -> List[int]: + self.preorderTraversal(root) + return self.result diff --git a/src/NArayTreePreOrderTraversal.java b/src/NArayTreePreOrderTraversal.java new file mode 100644 index 0000000..c689bd7 --- /dev/null +++ b/src/NArayTreePreOrderTraversal.java @@ -0,0 +1,19 @@ +import java.util.ArrayList; +import java.util.List; + +public class NArayTreePreOrderTraversal { + List result = new ArrayList<>(); + + public List preorder(Node root) { + preorderTraversal(root); + return result; + } + + private void preorderTraversal(Node root) { + if (root == null) return; + result.add(root.val); + for (Node child :root.children) { + preorderTraversal(child); + } + } +} From ad1d7daf1a97e0a97af4e1f9b45ad92144eabb29 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 23 Jul 2021 17:53:54 +0530 Subject: [PATCH 144/947] solves n ary post order traversal --- README.md | 2 +- python/n_ary_tree_postorder_traversal.py | 23 +++++++++++++++++++++++ src/NAryTreePostorderTraversal.java | 19 +++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 python/n_ary_tree_postorder_traversal.py create mode 100644 src/NAryTreePostorderTraversal.java diff --git a/README.md b/README.md index a9852d2..eb4c05c 100644 --- a/README.md +++ b/README.md @@ -154,7 +154,7 @@ | 575 | [Distribute Candies](https://leetcode.com/problems/distribute-candies) | Easy | [![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) | Medium | [![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) | Easy | [![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) | Easy | | +| 590 | [N-Ary Tree Postorder Traversal](https://leetcode.com/problems/n-ary-tree-postorder-traversal) | Easy | [![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) | Easy | | | 598 | [Range Addition II](https://leetcode.com/problems/range-addition-ii) | Easy | | | 599 | [Minimum Index Sum of 2 Lists](https://leetcode.com/problems/minimum-index-sum-of-two-lists) | Easy | | diff --git a/python/n_ary_tree_postorder_traversal.py b/python/n_ary_tree_postorder_traversal.py new file mode 100644 index 0000000..bc7f82a --- /dev/null +++ b/python/n_ary_tree_postorder_traversal.py @@ -0,0 +1,23 @@ +# Definition for a Node. +from typing import List + + +class Node: + def __init__(self, val=None, children=None): + self.val = val + self.children = children + + +class Solution: + def __init__(self): + self.result = [] + + def postorderTraversal(self, root: Node) -> None: + if root is None: return None + for child in root.children: + self.postorderTraversal(child) + self.result.append(root.val) + + def postorder(self, root: Node) -> List[int]: + self.postorderTraversal(root) + return self.result diff --git a/src/NAryTreePostorderTraversal.java b/src/NAryTreePostorderTraversal.java new file mode 100644 index 0000000..66f3ae0 --- /dev/null +++ b/src/NAryTreePostorderTraversal.java @@ -0,0 +1,19 @@ +import java.util.ArrayList; +import java.util.List; + +public class NAryTreePostorderTraversal { + List result = new ArrayList<>(); + + public List postorder(Node root) { + postorderTraversal(root); + return result; + } + + private void postorderTraversal(Node root) { + if (root == null) return; + for (Node child : root.children) { + postorderTraversal(child); + } + result.add(root.val); + } +} From e44cd7504492104ef05954dd75f27eb3980b63b7 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 23 Jul 2021 18:54:56 +0530 Subject: [PATCH 145/947] solves logest common harmonious subsequence --- README.md | 2 +- python/longest_harmonious_subequence.py | 15 ++++++++++++++ src/LongestHarmoniousSubsequence.java | 26 +++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 python/longest_harmonious_subequence.py create mode 100644 src/LongestHarmoniousSubsequence.java diff --git a/README.md b/README.md index eb4c05c..7a699d1 100644 --- a/README.md +++ b/README.md @@ -155,7 +155,7 @@ | 581 | [Shortest Unsorted Continuous Subarray](https://leetcode.com/problems/shortest-unsorted-continuous-subarray) | Medium | [![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) | Easy | [![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) | Easy | [![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) | Easy | | +| 594 | [Longest Harmonious Subsequence](https://leetcode.com/problems/longest-harmonious-subsequence) | Easy | [![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) | Easy | | | 599 | [Minimum Index Sum of 2 Lists](https://leetcode.com/problems/minimum-index-sum-of-two-lists) | Easy | | | 604 | [Design Compressed String Iterator](https://leetcode.com/problems/design-compressed-string-iterator) | Easy | | diff --git a/python/longest_harmonious_subequence.py b/python/longest_harmonious_subequence.py new file mode 100644 index 0000000..ae57947 --- /dev/null +++ b/python/longest_harmonious_subequence.py @@ -0,0 +1,15 @@ +from collections import Counter +from typing import List + + +class Solution: + def findLHS(self, array: List[int]) -> int: + frequencies = Counter(array) + result = 0 + for value, frequency in frequencies.items(): + result = max( + result, + frequencies.get(value - 1) + frequency if value - 1 in frequencies else 0, + frequencies.get(value + 1) + frequency if value + 1 in frequencies else 0 + ) + return result diff --git a/src/LongestHarmoniousSubsequence.java b/src/LongestHarmoniousSubsequence.java new file mode 100644 index 0000000..5dfa15b --- /dev/null +++ b/src/LongestHarmoniousSubsequence.java @@ -0,0 +1,26 @@ +import java.util.HashMap; +import java.util.Map; + +public class LongestHarmoniousSubsequence { + public int findLHS(int[] array) { + Map frequencies = getFrequencies(array); + int value, frequency, result = 0; + for (Map.Entry entry : frequencies.entrySet()) { + value = entry.getKey(); + frequency = entry.getValue(); + result = Math.max(result, Math.max( + frequencies.containsKey(value - 1) ? frequency + frequencies.get(value - 1) : 0, + frequencies.containsKey(value + 1) ? frequency + frequencies.get(value + 1) : 0 + )); + } + return result; + } + + private Map getFrequencies(int[] array) { + Map frequencies = new HashMap<>(); + for (int element : array) { + frequencies.put(element, frequencies.getOrDefault(element, 0) + 1); + } + return frequencies; + } +} From d19f8da9fbc2e18a4f618482976e25daae1385ac Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 23 Jul 2021 19:34:22 +0530 Subject: [PATCH 146/947] solves range addition II --- README.md | 2 +- python/range_addition_ii.py | 9 +++++++++ src/RangeAdditionII.java | 9 +++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 python/range_addition_ii.py create mode 100644 src/RangeAdditionII.java diff --git a/README.md b/README.md index 7a699d1..6147a47 100644 --- a/README.md +++ b/README.md @@ -156,7 +156,7 @@ | 589 | [N-Ary Tree Preorder Traversal](https://leetcode.com/problems/n-ary-tree-preorder-traversal) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | | +| 598 | [Range Addition II](https://leetcode.com/problems/range-addition-ii) | Easy | [![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) | Easy | | | 604 | [Design Compressed String Iterator](https://leetcode.com/problems/design-compressed-string-iterator) | Easy | | | 605 | [Can Place Flowers](https://leetcode.com/problems/can-place-flowers) | Easy | | diff --git a/python/range_addition_ii.py b/python/range_addition_ii.py new file mode 100644 index 0000000..41cf38c --- /dev/null +++ b/python/range_addition_ii.py @@ -0,0 +1,9 @@ +from typing import List + + +class Solution: + def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int: + for operation in ops: + m = min(m, operation[0]) + n = min(n, operation[0]) + return m * n diff --git a/src/RangeAdditionII.java b/src/RangeAdditionII.java new file mode 100644 index 0000000..745e201 --- /dev/null +++ b/src/RangeAdditionII.java @@ -0,0 +1,9 @@ +public class RangeAdditionII { + public int maxCount(int m, int n, int[][] operations) { + for (int[] operation : operations) { + m = Math.min(m, operation[0]); + n = Math.min(n, operation[1]); + } + return m * n; + } +} From 099822a6ccb061c1d6a971cedcd550493be76894 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 23 Jul 2021 19:52:02 +0530 Subject: [PATCH 147/947] solves minimum index of 2 lists --- README.md | 2 +- python/minimum_index_sum_of_two_lists.py | 17 ++++++++++ src/MinimumIndexSumOfTwoLists.java | 40 ++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 python/minimum_index_sum_of_two_lists.py create mode 100644 src/MinimumIndexSumOfTwoLists.java diff --git a/README.md b/README.md index 6147a47..2d72c25 100644 --- a/README.md +++ b/README.md @@ -157,7 +157,7 @@ | 590 | [N-Ary Tree Postorder Traversal](https://leetcode.com/problems/n-ary-tree-postorder-traversal) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | | +| 599 | [Minimum Index Sum of 2 Lists](https://leetcode.com/problems/minimum-index-sum-of-two-lists) | Easy | [![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) | Easy | | | 605 | [Can Place Flowers](https://leetcode.com/problems/can-place-flowers) | Easy | | | 606 | [Construct String from Binary Tree](https://leetcode.com/problems/construct-string-from-binary-tree) | Easy | | diff --git a/python/minimum_index_sum_of_two_lists.py b/python/minimum_index_sum_of_two_lists.py new file mode 100644 index 0000000..d58b523 --- /dev/null +++ b/python/minimum_index_sum_of_two_lists.py @@ -0,0 +1,17 @@ +from typing import List + + +class Solution: + def findRestaurant(self, list1: List[str], list2: List[str]) -> List[str]: + restaurant1_2_indices = {} + index_sum = float('inf') + result = [] + for index, restaurant in enumerate(list1): + restaurant1_2_indices[restaurant] = index + for index, restaurant in enumerate(list2): + if index + restaurant1_2_indices.get(restaurant, float('inf')) < index_sum: + index_sum = index + restaurant1_2_indices[restaurant] + result = [restaurant] + elif index + restaurant1_2_indices.get(restaurant, float('inf')) == index_sum: + result.append(restaurant) + return result diff --git a/src/MinimumIndexSumOfTwoLists.java b/src/MinimumIndexSumOfTwoLists.java new file mode 100644 index 0000000..169f756 --- /dev/null +++ b/src/MinimumIndexSumOfTwoLists.java @@ -0,0 +1,40 @@ +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class MinimumIndexSumOfTwoLists { + public String[] findRestaurant(String[] list1, String[] list2) { + int indexSum = Integer.MAX_VALUE; + List result = new ArrayList<>(); + Map restaurantIndices = getValueToIndexMap(list1); + for (int index = 0 ; index < list2.length ; index++) { + if (restaurantIndices.containsKey(list2[index])) { + if (index + restaurantIndices.get(list2[index]) < indexSum) { + result.clear(); + result.add(list2[index]); + indexSum = index + restaurantIndices.get(list2[index]); + } else if(index + restaurantIndices.get(list2[index]) == indexSum) { + result.add(list2[index]); + } + } + } + return toArray(result); + } + + private String[] toArray(List strings) { + String[] result = new String[strings.size()]; + for (int index = 0 ; index < result.length ; index++) { + result[index] = strings.get(index); + } + return result; + } + + private Map getValueToIndexMap(String[] array) { + Map result = new HashMap<>(); + for (int index = 0 ; index < array.length ; index++) { + result.put(array[index], index); + } + return result; + } +} From f62e06867c32be514cc31991e8ff5b51f307f812 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 23 Jul 2021 19:53:07 +0530 Subject: [PATCH 148/947] adds premium cintent logo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2d72c25..bffdd65 100644 --- a/README.md +++ b/README.md @@ -158,7 +158,7 @@ | 594 | [Longest Harmonious Subsequence](https://leetcode.com/problems/longest-harmonious-subsequence) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | | +| 604 | 🔒 [Design Compressed String Iterator](https://leetcode.com/problems/design-compressed-string-iterator) | Easy | | | 605 | [Can Place Flowers](https://leetcode.com/problems/can-place-flowers) | Easy | | | 606 | [Construct String from Binary Tree](https://leetcode.com/problems/construct-string-from-binary-tree) | Easy | | | 617 | [Merge Two Binary Trees](https://leetcode.com/problems/merge-two-binary-trees) | Easy | | From 1b58ebee76829f3f159db38cc1dd001ce2289cb5 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 28 Jul 2021 12:23:20 +0530 Subject: [PATCH 149/947] removes difficulty tags --- README.md | 736 +++++++++++++++++++++++++++--------------------------- 1 file changed, 368 insertions(+), 368 deletions(-) diff --git a/README.md b/README.md index bffdd65..5d59423 100644 --- a/README.md +++ b/README.md @@ -8,376 +8,376 @@ 🔒 = Subscription Content ## Problems -| # | Name | Difficulty | Solution | Youtube | -|:--------:|------|:----------:|:--------:|:----------------------:| -| 1 | [Two Sum](https://leetcode.com/problems/two-sum/) | Easy | [![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) | -| 7 | [Reverse Integer](https://leetcode.com/problems/reverse-integer/) | Easy | [![Java](assets/java.png)](src/ReverseInteger.java) [![Python](assets/python.png)](python/reverse_integer.py) | [![java-yt](assets/java-yt.png)](https://youtu.be/7bOhyl5lWjI) [![python-yt](assets/python-yt.png)](https://youtu.be/lmLG30TLcSg) | -| 9 | [PalindromeNumber](https://leetcode.com/problems/palindrome-number/) | Easy | [![Java](assets/java.png)](src/PalindromeNumber.java) [![Python](assets/python.png)](python/palindrome_number.py) | | -| 13 | [Roman To Integer](https://leetcode.com/problems/roman-to-integer/) | Easy | [![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/) | Easy | [![Java](assets/java.png)](src/LongestCommonPrefix.java) [![Python](assets/python.png)](python/longest_common_prefix.py) | -| 20 | [ValidParentheses](https://leetcode.com/problems/valid-parentheses/) | Easy | [![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/) | Easy | [![Java](assets/java.png)](src/Merge2SortedLists.java) [![Python](assets/python.png)](python/merge_2_sorted_lists.py) | -| 26 | [Remove Duplicates From Sorted Array](https://leetcode.com/problems/remove-duplicates-from-sorted-array/) | Easy | [![Java](assets/java.png)](src/RemoveDuplicatesFromSortedArray.java) [![Python](assets/python.png)](python/remove_duplicates_from_sorted_array.py) | -| 27 | [Remove Element](https://leetcode.com/problems/remove-element/) | Easy | [![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) | Easy | [![Java](assets/java.png)](src/NeedleInHaystack.java) [![Python](assets/python.png)](python/needle_in_haystack.py) | -| 35 | [Search Inserted Position](https://leetcode.com/problems/search-insert-position/) | Easy | [![Java](assets/java.png)](src/SearchInsertPosition.java) [![Python](assets/python.png)](python/search_insert_position.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) | +| 7 | [Reverse Integer](https://leetcode.com/problems/reverse-integer/) | [![Java](assets/java.png)](src/ReverseInteger.java) [![Python](assets/python.png)](python/reverse_integer.py) | [![java-yt](assets/java-yt.png)](https://youtu.be/7bOhyl5lWjI) [![python-yt](assets/python-yt.png)](https://youtu.be/lmLG30TLcSg) | +| 9 | [PalindromeNumber](https://leetcode.com/problems/palindrome-number/) | [![Java](assets/java.png)](src/PalindromeNumber.java) [![Python](assets/python.png)](python/palindrome_number.py) | | +| 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) | +| 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) | +| 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) | +| 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) | +| 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) | | 38 | [Count and Say](https://leetcode.com/problems/count-and-say) | Medium | [![Java](assets/java.png)](src/CountAndSay.java) [![Python](assets/python.png)](python/count_and_say.py) | -| 53 | [Maximum SubArray](https://leetcode.com/problems/maximum-subarray) | Easy | [![Java](assets/java.png)](src/MaximumSubArray.java) [![Python](assets/python.png)](python/maximum_sum_subarray.py) | -| 58 | [Length of Last Word](https://leetcode.com/problems/length-of-last-word) | Easy | [![Java](assets/java.png)](src/LengthOfLastWord.java) [![Python](assets/python.png)](python/length_of_last_word.py) | -| 66 | [Plus One](https://leetcode.com/problems/plus-one) | Easy | [![Java](assets/java.png)](src/PlusOne.java) [![Python](assets/python.png)](python/plus_one.py) | -| 67 | [Add Binary](https://leetcode.com/problems/add-binary) | Easy | [![Java](assets/java.png)](src/AddBinary.java) [![Python](assets/python.png)](python/add_binary.py) | -| 69 | [Sqrt(x)](https://leetcode.com/problems/sqrtx) | Easy | [![Java](assets/java.png)](src/Sqrtx.java) [![Python](assets/python.png)](python/sqrt.py) | -| 70 | [Climbing Stairs](https://leetcode.com/problems/climbing-stairs) | Easy | [![Java](assets/java.png)](src/ClimbingStairs.java) [![Python](assets/python.png)](python/climbing_stairs.py) | -| 83 | [Remove Duplicates from Sorted List](https://leetcode.com/problems/remove-duplicates-from-sorted-list) | Easy | [![Java](assets/java.png)](src/RemoveDuplicatesFromSortedList.java) [![Python](assets/python.png)](python/remove_duplicates_from_linked_list.py) | -| 88 | [Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array) | Easy | [![Java](assets/java.png)](src/MergeSortedArray.java) [![Python](assets/python.png)](python/merge_sorted_array.py) | -| 100 | [Same Tree](https://leetcode.com/problems/same-tree) | Easy | [![Java](assets/java.png)](src/SameTree.java) [![Python](assets/python.png)](python/same_tree.py) | -| 101 | [Symmetric Tree](https://leetcode.com/problems/symmetric-tree) | Easy | [![Java](assets/java.png)](src/SymmetricTree.java) [![Python](assets/python.png)](python/symmetric_tree.py) | -| 104 | [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree) | Easy | [![Java](assets/java.png)](src/MaximumDepthOfBinaryTree.java) [![Python](assets/python.png)](python/maximum_depth_of_binary_tree.py) | -| 107 | [Binary Tree Level Order Traversal II](https://leetcode.com/problems/binary-tree-level-order-traversal-ii) | Easy | [![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) | Easy | [![Java](assets/java.png)](src/ConvertSortedArrayToBinarySearchTree.java) [![Python](assets/python.png)](python/converted_sorted_array_to_binary_search_tree.py) | -| 110 | [Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree) | Easy | [![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) | Easy | [![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) | Easy | [![Java](assets/java.png)](src/PathSum.java) [![Python](assets/python.png)](python/path_sum.py) | -| 118 | [Pascal's Triangle](https://leetcode.com/problems/pascals-triangle) | Easy | [![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) | Easy | [![Java](assets/java.png)](src/PascalsTriangleII.java) [![Python](assets/python.png)](python/pascals_triangle_ii.py) | -| 121 | [Best Time to Buy and Sell Stocks](https://leetcode.com/problems/best-time-to-buy-and-sell-stock) | Easy | [![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) | Easy | [![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) | Easy | [![Java](assets/java.png)](src/ValidPalindrome.java) [![Python](assets/python.png)](python/valid_palindrome.py) | -| 136 | [Single Number](https://leetcode.com/problems/single-number) | Easy | [![Java](assets/java.png)](src/SingleNumber.java) [![Python](assets/python.png)](python/single_number.py) | -| 141 | [Linked List Cycle](https://leetcode.com/problems/linked-list-cycle) | Easy | [![Java](assets/java.png)](src/LinkedListCycle.java) [![Python](assets/python.png)](python/linked_list_cycle.py) | -| 155 | [Min Stack](https://leetcode.com/problems/min-stack) | Easy | [![Java](assets/java.png)](src/MinStack.java) [![Python](assets/python.png)](python/min_stack.py) | -| 157 | [Read N Characters Given Read4](https://leetcode.com/problems/read-n-characters-given-read4) | Easy | | -| 160 | [Intersection of Two Linked Lists](https://leetcode.com/problems/intersection-of-two-linked-lists) | Easy | [![Java](assets/java.png)](src/IntersectionOf2LinkedLists.java) [![Python](assets/python.png)](python/intersecction_of_two_linked_lists.py) | -| 167 | [Two Sum II - Input Array is Sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | | -| 171 | [Excel Sheet Column Number](https://leetcode.com/problems/excel-sheet-column-number) | Easy | [![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) | Easy | [![Java](assets/java.png)](src/FactorialTrailingZeros.java) [![Python](assets/python.png)](python/factorial_trailing_zeroes.py) | -| 189 | [Rotate Array](https://leetcode.com/problems/rotate-array) | Easy | [![Java](assets/java.png)](src/RotateArray.java) [![Python](assets/python.png)](python/rotate_array.py) | -| 190 | [Reverse Bits](https://leetcode.com/problems/reverse-bits) | Easy | [![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) | Easy | [![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) | Easy | [![Java](assets/java.png)](src/HouseRobber.java) [![Python](assets/python.png)](python/house_robber.py) | -| 202 | [Happy Number](https://leetcode.com/problems/happy-number) | Easy | [![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) | Easy | [![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) | Easy | [![Java](assets/java.png)](src/CountPrimes.java) [![Python](assets/python.png)](python/count_primes.py) | -| 205 | [Isomorphic Strings](https://leetcode.com/problems/isomorphic-strings) | Easy | [![Java](assets/java.png)](src/IsomorphicStrings.java) [![Python](assets/python.png)](python/isomorphic_strings.py) | -| 206 | [Reverse Linked Lists](https://leetcode.com/problems/reverse-linked-list) | Easy | [![Java](assets/java.png)](src/ReverseLinkedList.java) [![Python](assets/python.png)](python/reverse_linked_list.py) | -| 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate) | Easy | [![Java](assets/java.png)](src/ContainsDuplicate.java) [![Python](assets/python.png)](python/contains_duplicate.py) | -| 219 | [Contains Duplicate II](https://leetcode.com/problems/contains-duplicate-ii) | Easy | [![Java](assets/java.png)](src/ContainsDuplicateII.java) [![Python](assets/python.png)](python/contains_duplicate_ii.py) | -| 225 | [Implement Stack using Queues](https://leetcode.com/problems/implement-stack-using-queues) | Easy | [![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) | Easy | [![Java](assets/java.png)](src/InvertBinaryTree.java) [![Python](assets/python.png)](python/invert_binary_tree.py) | -| 231 | [Power of Two](https://leetcode.com/problems/power-of-two) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | [![Java](assets/java.png)](src/LowestCommonAncestorOfBinarySearchTree.java) [![Python](assets/python.png)](python/lowest_common_ancestor_of_bst.py) | -| 237 | [Delete a Node In A Linked List](https://leetcode.com/problems/delete-node-in-a-linked-list) | Easy | [![Java](assets/java.png)](src/DeleteANodeInLinkedList.java) [![Python](assets/python.png)](python/delete_node_in_linked_list.py) | -| 242 | [Valid Anagram](https://leetcode.com/problems/valid-anagram) | Easy | [![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) | Easy | | -| 246 | 🔒 [Strobogramatic Number](https://leetcode.com/problems/strobogrammatic-number) | Easy | | -| 252 | 🔒 [Meeting Rooms](https://leetcode.com/problems/meeting-rooms) | Easy | | -| 256 | 🔒 [Paint House](https://leetcode.com/problems/paint-house) | Easy | | -| 257 | [Binary Tree Paths](https://leetcode.com/problems/binary-tree-paths) | Easy | [![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) | Easy | [![Java](assets/java.png)](src/AddDigits.java) [![Python](assets/python.png)](python/add_digits.py) | -| 263 | [Ugly Number](https://leetcode.com/problems/ugly-number) | Easy | [![Java](assets/java.png)](src/UglyNumber.java) [![Python](assets/python.png)](python/ugly_number.py) | -| 266 | 🔒 [Palindrome Permutation](https://leetcode.com/problems/palindrome-permutation) | Easy | | -| 268 | [Missing Number](https://leetcode.com/problems/missing-number) | Easy | [![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) | Easy | | -| 276 | 🔒 [Paint Fence](https://leetcode.com/problems/paint-fence) | Easy | | -| 278 | [First Bad Version](https://leetcode.com/problems/first-bad-version) | Easy | [![Java](assets/java.png)](src/FirstBadVersion.java) [![Python](assets/python.png)](python/first_bad_version.py) | -| 283 | [Move Zeroes](https://leetcode.com/problems/move-zeroes) | Easy | [![Java](assets/java.png)](src/MoveZeros.java) [![Python](assets/python.png)](python/move_zeroes.py) | -| 290 | [Word Pattern](https://leetcode.com/problems/word-pattern) | Easy | [![Java](assets/java.png)](src/WordPattern.java) [![Python](assets/python.png)](python/word_pattern.py) | -| 292 | [Nim Game](https://leetcode.com/problems/nim-game) | Easy | [![Java](assets/java.png)](src/NimGame.java) [![Python](assets/python.png)](python/nim_game.py) | -| 293 | 🔒 [Flip Game](https://leetcode.com/problems/flip-game) | Easy | | -| 299 | [Bulls and Cows](https://leetcode.com/problems/bulls-and-cows) | Easy | [![Java](assets/java.png)](src/BullsAndCows.java) [![Python](assets/python.png)](python/bulls_and_cows.py) | -| 303 | [Range Sum Query - Immutable](https://leetcode.com/problems/range-sum-query-immutable) | Easy | [![Java](assets/java.png)](src/RangeSumQueryImmutable.java) [![Python](assets/python.png)](python/range_sum_query_immutable.py) | -| 326 | [Power of Three](https://leetcode.com/problems/power-of-three) | Easy | [![Java](assets/java.png)](src/PowerOfThree.java) [![Python](assets/python.png)](python/power_of_three.py) | -| 339 | 🔒 [Nested List Weight Sum](https://leetcode.com/problems/nested-list-weight-sum) | Easy | | -| 342 | [Power of Four](https://leetcode.com/problems/power-of-four) | Easy | [![Java](assets/java.png)](src/PowerOf4.java) [![Python](assets/python.png)](python/power_of_four.py) | -| 344 | [Reverse A String](https://leetcode.com/problems/reverse-string) | Easy | [![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) | Easy | [![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) | Easy | | -| 349 | [Intersection of 2 Arrays](https://leetcode.com/problems/intersection-of-two-arrays) | Easy | [![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) | Easy | [![Java](assets/java.png)](src/IntersectionOfTwoArraysII.java) [![Python](assets/python.png)](python/intersection_of_2_arrays_II.py) | -| 359 | 🔒 [Logger Rate Limiter](https://leetcode.com/problems/logger-rate-limiter) | Easy | | -| 367 | [Valid Perfect Square](https://leetcode.com/problems/valid-perfect-square) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | [![Java](assets/java.png)](src/IsSubsequence.java) [![Python](assets/python.png)](python/is_subsequence.py) | -| 401 | [Binary Watch](https://leetcode.com/problems/binary-watch) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | | -| 409 | [Longest Palindrome](https://leetcode.com/problems/longest-palindrome) | Easy | [![Java](assets/java.png)](src/LongestPalindrome.java) [![Python](assets/python.png)](python/longest_palindrome.py) | -| 412 | [Fizz Buzz](https://leetcode.com/problems/fizz-buzz) | Easy | [![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) | Easy | [![Java](assets/java.png)](src/ThirdMaximumNumber.java) [![Python](assets/python.png)](python/fizz_buzz.py) | -| 415 | [Add Strings](https://leetcode.com/problems/add-strings) | Easy | [![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) | Easy | | -| 434 | [Number of Segments in a String](https://leetcode.com/problems/number-of-segments-in-a-string) | Easy | [![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) | Easy | [![Java](assets/java.png)](src/ArrangingCoins.java) [![Python](assets/python.png)](python/arranging_coins.py) | +| 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) | +| 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) | +| 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) | +| 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) | +| 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) | +| 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) | +| 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) | +| 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) | +| 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) | +| 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) | +| 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) | +| 136 | [Single Number](https://leetcode.com/problems/single-number) | [![Java](assets/java.png)](src/SingleNumber.java) [![Python](assets/python.png)](python/single_number.py) | +| 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) | +| 155 | [Min Stack](https://leetcode.com/problems/min-stack) | [![Java](assets/java.png)](src/MinStack.java) [![Python](assets/python.png)](python/min_stack.py) | +| 157 | [Read N Characters Given Read4](https://leetcode.com/problems/read-n-characters-given-read4) | | +| 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) | +| 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) | +| 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) | +| 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 Lists](https://leetcode.com/problems/reverse-linked-list) | [![Java](assets/java.png)](src/ReverseLinkedList.java) [![Python](assets/python.png)](python/reverse_linked_list.py) | +| 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate) | [![Java](assets/java.png)](src/ContainsDuplicate.java) [![Python](assets/python.png)](python/contains_duplicate.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) | +| 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) | +| 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) | +| 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) | +| 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) | | +| 246 | 🔒 [Strobogramatic Number](https://leetcode.com/problems/strobogrammatic-number) | | +| 252 | 🔒 [Meeting Rooms](https://leetcode.com/problems/meeting-rooms) | | +| 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) | +| 263 | [Ugly Number](https://leetcode.com/problems/ugly-number) | [![Java](assets/java.png)](src/UglyNumber.java) [![Python](assets/python.png)](python/ugly_number.py) | +| 266 | 🔒 [Palindrome Permutation](https://leetcode.com/problems/palindrome-permutation) | | +| 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) | | +| 276 | 🔒 [Paint Fence](https://leetcode.com/problems/paint-fence) | | +| 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) | +| 283 | [Move Zeroes](https://leetcode.com/problems/move-zeroes) | [![Java](assets/java.png)](src/MoveZeros.java) [![Python](assets/python.png)](python/move_zeroes.py) | +| 290 | [Word Pattern](https://leetcode.com/problems/word-pattern) | [![Java](assets/java.png)](src/WordPattern.java) [![Python](assets/python.png)](python/word_pattern.py) | +| 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) | | +| 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) | +| 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) | +| 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) | +| 339 | 🔒 [Nested List Weight Sum](https://leetcode.com/problems/nested-list-weight-sum) | | +| 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) | +| 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) | | +| 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) | +| 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) | | +| 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) | Medium | [![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) | Medium | [![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) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | [![Java](assets/java.png)](src/HammingDistance.java) [![Python](assets/python.png)](python/hamming_distance.py) | -| 463 | [Island Perimeter](https://leetcode.com/problems/island-perimeter) | Easy | [![Java](assets/java.png)](src/IslandPerimeter.java) [![Python](assets/python.png)](python/island_perimeter.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) | Medium | [![Java](assets/java.png)](src/Heaters.java) [![Python](assets/python.png)](python/heaters.py) | -| 476 | [Number Complement](https://leetcode.com/problems/number-complement) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | [![Java](assets/java.png)](src/ConstructTheRectangle.java) [![Python](assets/python.png)](python/construct_the_rectangle.py) | -| 496 | [Next Greater Element I](https://leetcode.com/problems/next-greater-element-i) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | [![Java](assets/java.png)](src/Base7.java) [![Python](assets/python.png)](python/base_7.py) | -| 506 | [Relative Ranks](https://leetcode.com/problems/relative-ranks) | Easy | [![Java](assets/java.png)](src/RelativeRanks.java) [![Python](assets/python.png)](python/relative_ranks.py) | -| 507 | [Perfect Number](https://leetcode.com/problems/perfect-number) | Easy | [![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) | Easy | [![Java](assets/java.png)](src/FibonacciNumber.java) [![Python](assets/python.png)](python/fibonacci_number.py) | -| 520 | [Detect Capital](https://leetcode.com/problems/detect-capital) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | [![Java](assets/java.png)](src/DistributeCandies.java) [![Python](assets/python.png)](python/distribute_candies.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) | +| 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) | Medium | [![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) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | [![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) | Easy | | -| 605 | [Can Place Flowers](https://leetcode.com/problems/can-place-flowers) | Easy | | -| 606 | [Construct String from Binary Tree](https://leetcode.com/problems/construct-string-from-binary-tree) | Easy | | -| 617 | [Merge Two Binary Trees](https://leetcode.com/problems/merge-two-binary-trees) | Easy | | -| 624 | [Maximum Distance in Arrays](https://leetcode.com/problems/maximum-distance-in-arrays) | Easy | | -| 628 | [Maximum Product of Three Numbers](https://leetcode.com/problems/maximum-product-of-three-numbers) | Easy | | -| 633 | [Sum Square Numbers](https://leetcode.com/problems/sum-of-square-numbers) | Easy | | -| 637 | [Average of Levels in Binary Tree](https://leetcode.com/problems/average-of-levels-in-binary-tree) | Easy | | -| 643 | [Maximum Average SubArray I](https://leetcode.com/problems/maximum-average-subarray-i) | Easy | | -| 645 | [Set Mismatch](https://leetcode.com/problems/set-mismatch) | Easy | | -| 653 | [Two Sum IV - Input is a BST](https://leetcode.com/problems/two-sum-iv-input-is-a-bst) | Easy | | -| 657 | [Robot Return to Origin](https://leetcode.com/problems/robot-return-to-origin) | Easy | | -| 661 | [Image Smoother](https://leetcode.com/problems/image-smoother) | Easy | | -| 665 | [Non Deceasing Array](https://leetcode.com/problems/non-decreasing-array) | Easy | | -| 669 | [Trim a Binary Search Tree](https://leetcode.com/problems/trim-a-binary-search-tree) | Easy | | -| 671 | [Second Minimum Node in Binary Tree](https://leetcode.com/problems/second-minimum-node-in-a-binary-tree) | Easy | | -| 674 | [Longest Continuous Increasing Subsequence](https://leetcode.com/problems/longest-continuous-increasing-subsequence) | Easy | | -| 680 | [Valid Palindrome II](https://leetcode.com/problems/valid-palindrome-ii) | Easy | | -| 682 | [Baseball Game](https://leetcode.com/problems/baseball-game) | Easy | | -| 686 | [Repeated String Match](https://leetcode.com/problems/repeated-string-match) | Easy | | -| 687 | [Longest Univalue Path](https://leetcode.com/problems/longest-univalue-path) | Easy | | -| 690 | [Employee Importance](https://leetcode.com/problems/employee-importance) | Easy | | -| 693 | [Binary Number with Alternating Bits](https://leetcode.com/problems/binary-number-with-alternating-bits) | Easy | | -| 696 | [Count Binary Substrings](https://leetcode.com/problems/count-binary-substrings) | Easy | | -| 697 | [Degree of an Array](https://leetcode.com/problems/degree-of-an-array) | Easy | | -| 700 | [Search in a Binary Search Tree](https://leetcode.com/problems/search-in-a-binary-search-tree) | Easy | | -| 703 | [Kth Largest Element in a Stream](https://leetcode.com/problems/kth-largest-element-in-a-stream) | Easy | | -| 704 | [Binary Search](https://leetcode.com/problems/binary-search) | Easy | | -| 705 | [Design HashSet](https://leetcode.com/problems/design-hashset) | Easy | | -| 706 | [Design HashMap](https://leetcode.com/problems/design-hashmap) | Easy | | -| 709 | [To Lower Case](https://leetcode.com/problems/to-lower-case) | Easy | | -| 716 | [Max Stack](https://leetcode.com/problems/max-stack) | Easy | | -| 717 | [1-bit and 2-bit Characters](https://leetcode.com/problems/1-bit-and-2-bit-characters) | Easy | | -| 720 | [Longest Word in Dictionary](https://leetcode.com/problems/longest-word-in-dictionary) | Easy | | -| 724 | [Find Pivot Index](https://leetcode.com/problems/find-pivot-index) | Easy | | -| 728 | [Self Dividing Numbers](https://leetcode.com/problems/self-dividing-numbers) | Easy | | -| 733 | [Flood Fill](https://leetcode.com/problems/flood-fill) | Easy | | -| 734 | [Sentence Similarity](https://leetcode.com/problems/sentence-similarity) | Easy | | -| 744 | [Find Smallest Letter Greater Than Target](https://leetcode.com/problems/find-smallest-letter-greater-than-target) | Easy | | -| 746 | [Min Cost Climbing Stairs](https://leetcode.com/problems/min-cost-climbing-stairs) | Easy | | -| 747 | [Largest Number at least twize of Others](https://leetcode.com/problems/largest-number-at-least-twice-of-others) | Easy | | -| 748 | [Shortest Completing Word](https://leetcode.com/problems/shortest-completing-word) | Easy | | -| 758 | [Bold Words in String](https://leetcode.com/problems/bold-words-in-string) | Easy | | -| 760 | [Find Anagram Mappings](https://leetcode.com/problems/find-anagram-mappings) | Easy | | -| 762 | [Prime Number of Set Bits in Primary Representation](https://leetcode.com/problems/prime-number-of-set-bits-in-binary-representation) | Easy | | -| 766 | [Toeplitz Matrix](https://leetcode.com/problems/toeplitz-matrix) | Easy | | -| 771 | [Jewels and Stones](https://leetcode.com/problems/jewels-and-stones) | Easy | | -| 783 | [Minimum Distance Between BST Nodes](https://leetcode.com/problems/minimum-distance-between-bst-nodes) | Easy | [![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) | Easy | | -| 796 | [Rotate String](https://leetcode.com/problems/rotate-string) | Easy | | -| 800 | [Similar RGB Color](https://leetcode.com/problems/similar-rgb-color) | Easy | | -| 804 | [Unique Morse Code Words](https://leetcode.com/problems/unique-morse-code-words) | Easy | | -| 806 | [Number of Lines to Write String](https://leetcode.com/problems/number-of-lines-to-write-string) | Easy | | -| 811 | [Subdomain Visit Count](https://leetcode.com/problems/subdomain-visit-count) | Easy | | -| 812 | [Largest Triangle Area](https://leetcode.com/problems/largest-triangle-area) | Easy | | -| 819 | [Most Common Word](https://leetcode.com/problems/most-common-word) | Easy | | -| 821 | [Shortest Distance to Character](https://leetcode.com/problems/shortest-distance-to-a-character) | Easy | | -| 824 | [Goat Latin](https://leetcode.com/problems/goat-latin) | Easy | | -| 830 | [Positions of Large Groups](https://leetcode.com/problems/positions-of-large-groups) | Easy | | -| 832 | [Flipping an Image](https://leetcode.com/problems/flipping-an-image) | Easy | | -| 836 | [Rectangle Overlap](https://leetcode.com/problems/rectangle-overlap) | Easy | | -| 840 | [Magic Squares in Grid](https://leetcode.com/problems/magic-squares-in-grid) | Easy | | -| 844 | [Backspace String Compare](https://leetcode.com/problems/backspace-string-compare) | Easy | | -| 849 | [Maximize Distance to Closest Person](https://leetcode.com/problems/maximize-distance-to-closest-person) | Easy | | -| 852 | [Peak Index in Mountain Array](https://leetcode.com/problems/peak-index-in-a-mountain-array) | Easy | | -| 859 | [Buddy Strings](https://leetcode.com/problems/buddy-strings) | Easy | | -| 860 | [Lemonade Change](https://leetcode.com/problems/lemonade-change) | Easy | | -| 867 | [Transpose Matrix](https://leetcode.com/problems/transpose-matrix) | Easy | | -| 868 | [Binary Gap](https://leetcode.com/problems/binary-gap) | Easy | | -| 872 | [Leaf-Similar Trees](https://leetcode.com/problems/leaf-similar-trees) | Easy | | -| 874 | [Walking Robot Simulation](https://leetcode.com/problems/walking-robot-simulation) | Easy | | -| 876 | [Middle of the Linked List](https://leetcode.com/problems/middle-of-the-linked-list) | Easy | | -| 883 | [Projection Area of 3D Shapes](https://leetcode.com/problems/projection-area-of-3d-shapes) | Easy | | -| 884 | [Uncommon Words from 2 Sentences](https://leetcode.com/problems/uncommon-words-from-two-sentences) | Easy | | -| 888 | [Fair Candy Swap](https://leetcode.com/problems/fair-candy-swap) | Easy | | -| 892 | [Surface Area of 3D Shapes](https://leetcode.com/problems/surface-area-of-3d-shapes) | Easy | | -| 893 | [Groups of Special Equivalent Strings](https://leetcode.com/problems/groups-of-special-equivalent-strings) | Easy | | -| 896 | [Monotonic Array](https://leetcode.com/problems/monotonic-array) | Easy | | -| 897 | [Increasing Order Search Tree](https://leetcode.com/problems/increasing-order-search-tree) | Easy | | -| 905 | [Sort Array by Parity](https://leetcode.com/problems/sort-array-by-parity) | Easy | | -| 908 | [Smallest Range I](https://leetcode.com/problems/smallest-range-i) | Easy | | -| 914 | [X of a kind in a Deck of Cards](https://leetcode.com/problems/x-of-a-kind-in-a-deck-of-cards) | Easy | | -| 917 | [Reverse Only Letters](https://leetcode.com/problems/reverse-only-letters) | Easy | | -| 922 | [Sort Array by Parity II](https://leetcode.com/problems/sort-array-by-parity-ii) | Easy | | -| 925 | [Long Pressed Name](https://leetcode.com/problems/long-pressed-name) | Easy | | -| 929 | [Unique Email Addresses](https://leetcode.com/problems/unique-email-addresses) | Easy | | -| 933 | [Number of Recent Calls](https://leetcode.com/problems/number-of-recent-calls) | Easy | | -| 937 | [Reorder Data In Log Files](https://leetcode.com/problems/reorder-data-in-log-files) | Easy | | -| 938 | [Range Sum of BST](https://leetcode.com/problems/range-sum-of-bst) | Easy | | -| 941 | [Valid Mountain Array](https://leetcode.com/problems/valid-mountain-array) | Easy | | -| 942 | [DI String Match](https://leetcode.com/problems/di-string-match) | Easy | | -| 944 | [Delete Columns to Make Sorted](https://leetcode.com/problems/delete-columns-to-make-sorted) | Easy | | -| 949 | [Largest Time for Given Digits](https://leetcode.com/problems/largest-time-for-given-digits) | Easy | | -| 953 | [Verifying an Alien Dictionary](https://leetcode.com/problems/verifying-an-alien-dictionary) | Easy | | -| 961 | [N-Repeated Elements in Size 2N Array](https://leetcode.com/problems/n-repeated-element-in-size-2n-array) | Easy | | -| 965 | [Univalued Binary Tree](https://leetcode.com/problems/univalued-binary-tree) | Easy | | -| 970 | [Powerful Integers](https://leetcode.com/problems/powerful-integers) | Easy | | -| 976 | [Largest Perimeter Triangle](https://leetcode.com/problems/largest-perimeter-triangle) | Easy | | -| 977 | [Squares of a Sorted Array](https://leetcode.com/problems/squares-of-a-sorted-array) | Easy | | -| 985 | [Sum of Even Numbers after Queries](https://leetcode.com/problems/sum-of-even-numbers-after-queries) | Easy | | -| 989 | [Add to Array Form of Integer](https://leetcode.com/problems/add-to-array-form-of-integer) | Easy | | -| 993 | [Cousins in Binary Tree](https://leetcode.com/problems/cousins-in-binary-tree) | Easy | | -| 997 | [Find the Town Judge](https://leetcode.com/problems/find-the-town-judge) | Easy | | -| 999 | [Available Captures for Rook](https://leetcode.com/problems/available-captures-for-rook) | Easy | | -| 1002 | [Find Common Characters](https://leetcode.com/problems/find-common-characters) | Easy | | -| 1005 | [Maximize Sum of Array After K Negations](https://leetcode.com/problems/maximize-sum-of-array-after-k-negations) | Easy | | -| 1009 | [Complement of Base 10 Integer](https://leetcode.com/problems/complement-of-base-10-integer) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.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) | Easy | | -| 1013 | [Partition Array into Three Parts with equal Sum](https://leetcode.com/problems/partition-array-into-three-parts-with-equal-sum) | Easy | | -| 1018 | [Binary Prefix Divisible by 5](https://leetcode.com/problems/binary-prefix-divisible-by-5) | Easy | | -| 1021 | [Remove Outermost Parenthesis](https://leetcode.com/problems/remove-outermost-parentheses) | Easy | | -| 1022 | [Sum of Root to Leaf Binary Numbers](https://leetcode.com/problems/sum-of-root-to-leaf-binary-numbers) | Easy | | -| 1025 | [Divisor Game](https://leetcode.com/problems/divisor-game) | Easy | | -| 1029 | [Two City Scheduling](https://leetcode.com/problems/two-city-scheduling) | Easy | | -| 1030 | [Matrix Cells in Distance Order](https://leetcode.com/problems/matrix-cells-in-distance-order) | Easy | | -| 1033 | [Moving Stones Until Consecutive](https://leetcode.com/problems/moving-stones-until-consecutive) | Easy | | -| 1037 | [Valid Boomerang](https://leetcode.com/problems/valid-boomerang) | Easy | | -| 1042 | [Flower Planting with no Adjacent](https://leetcode.com/problems/flower-planting-with-no-adjacent) | Easy | | -| 1046 | [Last Stone Weight](https://leetcode.com/problems/last-stone-weight) | Easy | | -| 1047 | [Remove All adjacent Duplicates in String](https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string) | Easy | | -| 1051 | [Height Checker](https://leetcode.com/problems/height-checker) | Easy | | -| 1056 | [Confusing Number](https://leetcode.com/problems/confusing-number) | Easy | | -| 1064 | [Fixed Point](https://leetcode.com/problems/fixed-point) | Easy | | -| 1065 | [Index Pairs of a String](https://leetcode.com/problems/index-pairs-of-a-string) | Easy | | -| 1071 | [Greatest Common Divisors of Strings](https://leetcode.com/problems/greatest-common-divisor-of-strings) | Easy | | -| 1078 | [Occurrence After Bigram](https://leetcode.com/problems/occurrences-after-bigram) | Easy | | -| 1085 | [Sum of Digits in Minimum Number](https://leetcode.com/problems/sum-of-digits-in-the-minimum-number) | Easy | | -| 1086 | [High Five](https://leetcode.com/problems/high-five) | Easy | | -| 1089 | [Duplicate Zeroes](https://leetcode.com/problems/duplicate-zeros) | Easy | | -| 1099 | [Two Sum Less Than K](https://leetcode.com/problems/two-sum-less-than-k) | Easy | | -| 1103 | [Distribute Candies to People](https://leetcode.com/problems/distribute-candies-to-people) | Easy | | -| 1108 | [Defanging an IP Address](https://leetcode.com/problems/defanging-an-ip-address) | Easy | | -| 1118 | [Number of Days in a Month](https://leetcode.com/problems/number-of-days-in-a-month) | Easy | | -| 1119 | [Remove Vowels From String](https://leetcode.com/problems/remove-vowels-from-a-string) | Easy | | -| 1122 | [Relative Sort Array](https://leetcode.com/problems/relative-sort-array) | Easy | | -| 1128 | [Number of Equivalent Domino Pairs](https://leetcode.com/problems/number-of-equivalent-domino-pairs) | Easy | | -| 1133 | [Largest Unique Number](https://leetcode.com/problems/largest-unique-number) | Easy | | -| 1134 | [Armstrong Number](https://leetcode.com/problems/armstrong-number) | Easy | | -| 1137 | [Nth Tribonacci Number]() | Easy | | -| 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) | Easy | | -| 1154 | [Day of The Year](https://leetcode.com/problems/day-of-the-year) | Easy | | -| 1160 | [Find Words That Can Be Formed By Characters](https://leetcode.com/problems/find-words-that-can-be-formed-by-characters) | Easy | | -| 1165 | [Single Row Keyboard](https://leetcode.com/problems/single-row-keyboard) | Easy | | -| 1170 | [Compare Strings By Frequency of the Smallest Character](https://leetcode.com/problems/compare-strings-by-frequency-of-the-smallest-character) | Easy | | -| 1175 | [Prime Arrangements](https://leetcode.com/problems/prime-arrangements) | Easy | | -| 1176 | [Diet Plan Performance](https://leetcode.com/problems/diet-plan-performance) | Easy | | -| 1180 | [Count Substrings with only one Distinct Letter](https://leetcode.com/problems/count-substrings-with-only-one-distinct-letter) | Easy | | -| 1184 | [Distance Between Bus Stops](https://leetcode.com/problems/distance-between-bus-stops) | Easy | | -| 1185 | [Day of the Week](https://leetcode.com/problems/day-of-the-week) | Easy | | -| 1189 | [Maximum Number of Balloons](https://leetcode.com/problems/maximum-number-of-balloons) | Easy | | -| 1196 | [How Many Apples Can You Put into the Basket](https://leetcode.com/problems/how-many-apples-can-you-put-into-the-basket) | Easy | | -| 1200 | [Minimum Absolute Difference](https://leetcode.com/problems/minimum-absolute-difference) | Easy | | -| 1207 | [Unique Number of Occurrences](https://leetcode.com/problems/unique-number-of-occurrences) | Easy | | -| 1213 | [Intersection of Three Sorted Arrays](https://leetcode.com/problems/intersection-of-three-sorted-arrays) | Easy | | -| 1217 | [Play With Chips](https://leetcode.com/problems/play-with-chips) | Easy | | -| 1221 | [Split A String In Balanced Strings](https://leetcode.com/problems/split-a-string-in-balanced-strings) | Easy | | -| 1228 | [Missing A Number In Arithmetic Progression](https://leetcode.com/problems/missing-number-in-arithmetic-progression) | Easy | | -| 1232 | [Check If It Is A Straight Line](https://leetcode.com/problems/check-if-it-is-a-straight-line) | Easy | | -| 1237 | [Find Positive Integer Solutions for a Given Equation](https://leetcode.com/problems/find-positive-integer-solution-for-a-given-equation) | Easy | | -| 1243 | [Array Transformation](https://leetcode.com/problems/array-transformation) | Easy | | -| 1252 | [Cells With Odd Values In Matrix](https://leetcode.com/problems/cells-with-odd-values-in-a-matrix) | Easy | | -| 1260 | [Shift 2D Grid](https://leetcode.com/problems/shift-2d-grid) | Easy | | -| 1266 | [Minimum Time Visiting All Points](https://leetcode.com/problems/minimum-time-visiting-all-points) | Easy | | -| 1271 | [Hexspeak](https://leetcode.com/problems/hexspeak) | Easy | | -| 1275 | [Find Winner On a Tic Tac Toe Game](https://leetcode.com/problems/find-winner-on-a-tic-tac-toe-game) | Easy | | -| 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) | Easy | | -| 1287 | [Element Appearing More Than 25% in Sorted Array](https://leetcode.com/problems/element-appearing-more-than-25-in-sorted-array) | Easy | | -| 1290 | [Convert Binary Number In A Linked List to Integer](https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer) | Easy | | -| 1295 | [Find Numbers With Even Numbers of Digits](https://leetcode.com/problems/find-numbers-with-even-number-of-digits) | Easy | | -| 1299 | [Replace Elements With Greatest Element on Right Side](https://leetcode.com/problems/replace-elements-with-greatest-element-on-right-side) | Easy | | -| 1304 | [Find N Unique Integers Sum Up To Zero](https://leetcode.com/problems/find-n-unique-integers-sum-up-to-zero) | Easy | | -| 1309 | [Decrypt String From Alphabet To Integer Mapping](https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping) | Easy | | -| 1313 | [Decompress Run-Length Encoded Strings](https://leetcode.com/problems/decompress-run-length-encoded-list) | Easy | | -| 1317 | [Convert Integer to Sum Of Two Non-Zero Integers](https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers) | Easy | | -| 1323 | [Maximum 69 Number](https://leetcode.com/problems/maximum-69-number) | Easy | | -| 1331 | [Rank Transform of An Array](https://leetcode.com/problems/rank-transform-of-an-array) | Easy | | -| 1332 | [Remove Palindromic Subsequences](https://leetcode.com/problems/remove-palindromic-subsequences) | Easy | | -| 1337 | [The K Weakest Rows In A Matrix](https://leetcode.com/problems/the-k-weakest-rows-in-a-matrix) | Easy | | -| 1342 | [Number of Steps to Reduce a Number to Zero](https://leetcode.com/problems/number-of-steps-to-reduce-a-number-to-zero) | Easy | | -| 1346 | [Check if N and It's Double Exist](https://leetcode.com/problems/check-if-n-and-its-double-exist) | Easy | | -| 1351 | [Count Negative Numbers In A Sorted Matrix](https://leetcode.com/problems/count-negative-numbers-in-a-sorted-matrix) | Easy | | -| 1356 | [Sort Integers by Number of 1 Bits](https://leetcode.com/problems/sort-integers-by-the-number-of-1-bits) | Easy | | -| 1360 | [Number of Days Between Two Dates](https://leetcode.com/problems/number-of-days-between-two-dates) | Easy | | -| 1365 | [How Many Numbers Are Smaller Than Current Number](https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number) | Easy | | -| 1370 | [Increasing Decreasing String](https://leetcode.com/problems/increasing-decreasing-string) | Easy | | -| 1374 | [Generate A String With Characters That Have Odd Count](https://leetcode.com/problems/generate-a-string-with-characters-that-have-odd-counts) | Easy | | -| 1380 | [Lucky Numbers In A Matrix](https://leetcode.com/problems/lucky-numbers-in-a-matrix) | Easy | | -| 1385 | [Find The Distance Value Between 2 Arrays](https://leetcode.com/problems/find-the-distance-value-between-two-arrays) | Easy | | -| 1389 | [Create Target Array in Given Order](https://leetcode.com/problems/create-target-array-in-the-given-order) | Easy | | -| 1394 | [Find Lucky Integer In An Array](https://leetcode.com/problems/find-lucky-integer-in-an-array) | Easy | | -| 1399 | [Count Largest Group](https://leetcode.com/problems/count-largest-group) | Easy | | -| 1403 | [Minimum Subsequence in Non-Increasing Order](https://leetcode.com/problems/minimum-subsequence-in-non-increasing-order) | Easy | | -| 1408 | [String Matching In An Array](https://leetcode.com/problems/string-matching-in-an-array) | Easy | | -| 1413 | [Minimum Value To Get Positive Step By Step Sum](https://leetcode.com/problems/minimum-value-to-get-positive-step-by-step-sum) | Easy | | -| 1417 | [Reformat The String](https://leetcode.com/problems/reformat-the-string) | Easy | | -| 1422 | [Maximum Score After Splitting A String](https://leetcode.com/problems/maximum-score-after-splitting-a-string) | Easy | | -| 1426 | [Counting Elements](https://leetcode.com/problems/counting-elements) | Easy | | -| 1427 | [Performing String Shifts](https://leetcode.com/problems/perform-string-shifts) | Easy | | -| 1431 | [Kids With The Greatest Number Of Candies](https://leetcode.com/problems/kids-with-the-greatest-number-of-candies) | Easy | | -| 1436 | [Destination City](https://leetcode.com/problems/destination-city) | Easy | | -| 1441 | [Build An Array With Stack Operation](https://leetcode.com/problems/build-an-array-with-stack-operations) | Easy | | -| 1446 | [Consecutive Characters](https://leetcode.com/problems/consecutive-characters) | Easy | | -| 1450 | [Number of Students Doing Homework at Given Time](https://leetcode.com/problems/number-of-students-doing-homework-at-a-given-time) | Easy | | -| 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) | Easy | | -| 1460 | [Make 2 Arrays Equal by Reversing Sub Arrays](https://leetcode.com/problems/make-two-arrays-equal-by-reversing-sub-arrays) | Easy | | -| 1464 | [Maximum Product of 2 Elements in Array](https://leetcode.com/problems/maximum-product-of-two-elements-in-an-array) | Easy | | -| 1469 | [Find All Lonely Nodes](https://leetcode.com/problems/find-all-the-lonely-nodes) | Easy | | -| 1470 | [Shuffle The Array](https://leetcode.com/problems/shuffle-the-array) | Easy | | -| 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) | Easy | | -| 1475 | [Final Prices With Special Discount in a Shop](https://leetcode.com/problems/final-prices-with-a-special-discount-in-a-shop) | Easy | | -| 1480 | [Running Sum of 1D Array](https://leetcode.com/problems/running-sum-of-1d-array) | Easy | | -| 1486 | [XOR Operations in An Array](https://leetcode.com/problems/xor-operation-in-an-array) | Easy | | -| 1491 | [Average Salary Excluding the Minimum and Maximum Salary](https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary) | Easy | | -| 1496 | [Path Crossing](https://leetcode.com/problems/path-crossing) | Easy | | -| 1502 | [Can Make Arithmetic Progression From Sequence](https://leetcode.com/problems/can-make-arithmetic-progression-from-sequence) | Easy | | -| 1507 | [Reformat Date](https://leetcode.com/problems/reformat-date) | Easy | | -| 1512 | [Number of Good Pairs](https://leetcode.com/problems/number-of-good-pairs) | Easy | | -| 1518 | [Water Bottles](https://leetcode.com/problems/water-bottles) | Easy | | -| 1523 | [Count Odd Numbers In Interval Range](https://leetcode.com/problems/count-odd-numbers-in-an-interval-range) | Easy | | -| 1528 | [Shuffle Strings](https://leetcode.com/problems/shuffle-string) | Easy | | -| 1534 | [Count Good Triplets](https://leetcode.com/problems/count-good-triplets) | Easy | | -| 1539 | [Kth Missing Positive Number](https://leetcode.com/problems/kth-missing-positive-number) | Easy | | -| 1544 | [Make The String Great](https://leetcode.com/problems/make-the-string-great) | Easy | | +| 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) | | +| 606 | [Construct String from Binary Tree](https://leetcode.com/problems/construct-string-from-binary-tree) | | +| 617 | [Merge Two Binary Trees](https://leetcode.com/problems/merge-two-binary-trees) | | +| 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) | | +| 633 | [Sum Square Numbers](https://leetcode.com/problems/sum-of-square-numbers) | | +| 637 | [Average of Levels in Binary Tree](https://leetcode.com/problems/average-of-levels-in-binary-tree) | | +| 643 | [Maximum Average SubArray I](https://leetcode.com/problems/maximum-average-subarray-i) | | +| 645 | [Set Mismatch](https://leetcode.com/problems/set-mismatch) | | +| 653 | [Two Sum IV - Input is a BST](https://leetcode.com/problems/two-sum-iv-input-is-a-bst) | | +| 657 | [Robot Return to Origin](https://leetcode.com/problems/robot-return-to-origin) | | +| 661 | [Image Smoother](https://leetcode.com/problems/image-smoother) | | +| 665 | [Non Deceasing Array](https://leetcode.com/problems/non-decreasing-array) | | +| 669 | [Trim a Binary Search Tree](https://leetcode.com/problems/trim-a-binary-search-tree) | | +| 671 | [Second Minimum Node in Binary Tree](https://leetcode.com/problems/second-minimum-node-in-a-binary-tree) | | +| 674 | [Longest Continuous Increasing Subsequence](https://leetcode.com/problems/longest-continuous-increasing-subsequence) | | +| 680 | [Valid Palindrome II](https://leetcode.com/problems/valid-palindrome-ii) | | +| 682 | [Baseball Game](https://leetcode.com/problems/baseball-game) | | +| 686 | [Repeated String Match](https://leetcode.com/problems/repeated-string-match) | | +| 687 | [Longest Univalue Path](https://leetcode.com/problems/longest-univalue-path) | | +| 690 | [Employee Importance](https://leetcode.com/problems/employee-importance) | | +| 693 | [Binary Number with Alternating Bits](https://leetcode.com/problems/binary-number-with-alternating-bits) | | +| 696 | [Count Binary Substrings](https://leetcode.com/problems/count-binary-substrings) | | +| 697 | [Degree of an Array](https://leetcode.com/problems/degree-of-an-array) | | +| 700 | [Search in a Binary Search Tree](https://leetcode.com/problems/search-in-a-binary-search-tree) | | +| 703 | [Kth Largest Element in a Stream](https://leetcode.com/problems/kth-largest-element-in-a-stream) | | +| 704 | [Binary Search](https://leetcode.com/problems/binary-search) | | +| 705 | [Design HashSet](https://leetcode.com/problems/design-hashset) | | +| 706 | [Design HashMap](https://leetcode.com/problems/design-hashmap) | | +| 709 | [To Lower Case](https://leetcode.com/problems/to-lower-case) | | +| 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) | | +| 720 | [Longest Word in Dictionary](https://leetcode.com/problems/longest-word-in-dictionary) | | +| 724 | [Find Pivot Index](https://leetcode.com/problems/find-pivot-index) | | +| 728 | [Self Dividing Numbers](https://leetcode.com/problems/self-dividing-numbers) | | +| 733 | [Flood Fill](https://leetcode.com/problems/flood-fill) | | +| 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) | | +| 746 | [Min Cost Climbing Stairs](https://leetcode.com/problems/min-cost-climbing-stairs) | | +| 747 | [Largest Number at least twize of Others](https://leetcode.com/problems/largest-number-at-least-twice-of-others) | | +| 748 | [Shortest Completing Word](https://leetcode.com/problems/shortest-completing-word) | | +| 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) | | +| 766 | [Toeplitz Matrix](https://leetcode.com/problems/toeplitz-matrix) | | +| 771 | [Jewels and Stones](https://leetcode.com/problems/jewels-and-stones) | | +| 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) | | +| 800 | [Similar RGB Color](https://leetcode.com/problems/similar-rgb-color) | | +| 804 | [Unique Morse Code Words](https://leetcode.com/problems/unique-morse-code-words) | | +| 806 | [Number of Lines to Write String](https://leetcode.com/problems/number-of-lines-to-write-string) | | +| 811 | [Subdomain Visit Count](https://leetcode.com/problems/subdomain-visit-count) | | +| 812 | [Largest Triangle Area](https://leetcode.com/problems/largest-triangle-area) | | +| 819 | [Most Common Word](https://leetcode.com/problems/most-common-word) | | +| 821 | [Shortest Distance to Character](https://leetcode.com/problems/shortest-distance-to-a-character) | | +| 824 | [Goat Latin](https://leetcode.com/problems/goat-latin) | | +| 830 | [Positions of Large Groups](https://leetcode.com/problems/positions-of-large-groups) | | +| 832 | [Flipping an Image](https://leetcode.com/problems/flipping-an-image) | | +| 836 | [Rectangle Overlap](https://leetcode.com/problems/rectangle-overlap) | | +| 840 | [Magic Squares in Grid](https://leetcode.com/problems/magic-squares-in-grid) | | +| 844 | [Backspace String Compare](https://leetcode.com/problems/backspace-string-compare) | | +| 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) | | +| 859 | [Buddy Strings](https://leetcode.com/problems/buddy-strings) | | +| 860 | [Lemonade Change](https://leetcode.com/problems/lemonade-change) | | +| 867 | [Transpose Matrix](https://leetcode.com/problems/transpose-matrix) | | +| 868 | [Binary Gap](https://leetcode.com/problems/binary-gap) | | +| 872 | [Leaf-Similar Trees](https://leetcode.com/problems/leaf-similar-trees) | | +| 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) | | +| 883 | [Projection Area of 3D Shapes](https://leetcode.com/problems/projection-area-of-3d-shapes) | | +| 884 | [Uncommon Words from 2 Sentences](https://leetcode.com/problems/uncommon-words-from-two-sentences) | | +| 888 | [Fair Candy Swap](https://leetcode.com/problems/fair-candy-swap) | | +| 892 | [Surface Area of 3D Shapes](https://leetcode.com/problems/surface-area-of-3d-shapes) | | +| 893 | [Groups of Special Equivalent Strings](https://leetcode.com/problems/groups-of-special-equivalent-strings) | | +| 896 | [Monotonic Array](https://leetcode.com/problems/monotonic-array) | | +| 897 | [Increasing Order Search Tree](https://leetcode.com/problems/increasing-order-search-tree) | | +| 905 | [Sort Array by Parity](https://leetcode.com/problems/sort-array-by-parity) | | +| 908 | [Smallest Range I](https://leetcode.com/problems/smallest-range-i) | | +| 914 | [X of a kind in a Deck of Cards](https://leetcode.com/problems/x-of-a-kind-in-a-deck-of-cards) | | +| 917 | [Reverse Only Letters](https://leetcode.com/problems/reverse-only-letters) | | +| 922 | [Sort Array by Parity II](https://leetcode.com/problems/sort-array-by-parity-ii) | | +| 925 | [Long Pressed Name](https://leetcode.com/problems/long-pressed-name) | | +| 929 | [Unique Email Addresses](https://leetcode.com/problems/unique-email-addresses) | | +| 933 | [Number of Recent Calls](https://leetcode.com/problems/number-of-recent-calls) | | +| 937 | [Reorder Data In Log Files](https://leetcode.com/problems/reorder-data-in-log-files) | | +| 938 | [Range Sum of BST](https://leetcode.com/problems/range-sum-of-bst) | | +| 941 | [Valid Mountain Array](https://leetcode.com/problems/valid-mountain-array) | | +| 942 | [DI String Match](https://leetcode.com/problems/di-string-match) | | +| 944 | [Delete Columns to Make Sorted](https://leetcode.com/problems/delete-columns-to-make-sorted) | | +| 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) | | +| 961 | [N-Repeated Elements in Size 2N Array](https://leetcode.com/problems/n-repeated-element-in-size-2n-array) | | +| 965 | [Univalued Binary Tree](https://leetcode.com/problems/univalued-binary-tree) | | +| 970 | [Powerful Integers](https://leetcode.com/problems/powerful-integers) | | +| 976 | [Largest Perimeter Triangle](https://leetcode.com/problems/largest-perimeter-triangle) | | +| 977 | [Squares of a Sorted Array](https://leetcode.com/problems/squares-of-a-sorted-array) | | +| 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) | | +| 993 | [Cousins in Binary Tree](https://leetcode.com/problems/cousins-in-binary-tree) | | +| 997 | [Find the Town Judge](https://leetcode.com/problems/find-the-town-judge) | | +| 999 | [Available Captures for Rook](https://leetcode.com/problems/available-captures-for-rook) | | +| 1002 | [Find Common Characters](https://leetcode.com/problems/find-common-characters) | | +| 1005 | [Maximize Sum of Array After K Negations](https://leetcode.com/problems/maximize-sum-of-array-after-k-negations) | | +| 1009 | [Complement of Base 10 Integer](https://leetcode.com/problems/complement-of-base-10-integer) | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.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) | | +| 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) | | +| 1021 | [Remove Outermost Parenthesis](https://leetcode.com/problems/remove-outermost-parentheses) | | +| 1022 | [Sum of Root to Leaf Binary Numbers](https://leetcode.com/problems/sum-of-root-to-leaf-binary-numbers) | | +| 1025 | [Divisor Game](https://leetcode.com/problems/divisor-game) | | +| 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) | | +| 1033 | [Moving Stones Until Consecutive](https://leetcode.com/problems/moving-stones-until-consecutive) | | +| 1037 | [Valid Boomerang](https://leetcode.com/problems/valid-boomerang) | | +| 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) | | +| 1047 | [Remove All adjacent Duplicates in String](https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string) | | +| 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) | | +| 1078 | [Occurrence After Bigram](https://leetcode.com/problems/occurrences-after-bigram) | | +| 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) | | +| 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) | | +| 1108 | [Defanging an IP Address](https://leetcode.com/problems/defanging-an-ip-address) | | +| 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) | | +| 1128 | [Number of Equivalent Domino Pairs](https://leetcode.com/problems/number-of-equivalent-domino-pairs) | | +| 1133 | [Largest Unique Number](https://leetcode.com/problems/largest-unique-number) | | +| 1134 | [Armstrong Number](https://leetcode.com/problems/armstrong-number) | | +| 1137 | [Nth Tribonacci Number]() | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 1185 | [Day of the Week](https://leetcode.com/problems/day-of-the-week) | | +| 1189 | [Maximum Number of Balloons](https://leetcode.com/problems/maximum-number-of-balloons) | | +| 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) | | +| 1207 | [Unique Number of Occurrences](https://leetcode.com/problems/unique-number-of-occurrences) | | +| 1213 | [Intersection of Three Sorted Arrays](https://leetcode.com/problems/intersection-of-three-sorted-arrays) | | +| 1217 | [Play With Chips](https://leetcode.com/problems/play-with-chips) | | +| 1221 | [Split A String In Balanced Strings](https://leetcode.com/problems/split-a-string-in-balanced-strings) | | +| 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) | | +| 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) | | +| 1252 | [Cells With Odd Values In Matrix](https://leetcode.com/problems/cells-with-odd-values-in-a-matrix) | | +| 1260 | [Shift 2D Grid](https://leetcode.com/problems/shift-2d-grid) | | +| 1266 | [Minimum Time Visiting All Points](https://leetcode.com/problems/minimum-time-visiting-all-points) | | +| 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) | | +| 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) | | +| 1287 | [Element Appearing More Than 25% in Sorted Array](https://leetcode.com/problems/element-appearing-more-than-25-in-sorted-array) | | +| 1290 | [Convert Binary Number In A Linked List to Integer](https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer) | | +| 1295 | [Find Numbers With Even Numbers of Digits](https://leetcode.com/problems/find-numbers-with-even-number-of-digits) | | +| 1299 | [Replace Elements With Greatest Element on Right Side](https://leetcode.com/problems/replace-elements-with-greatest-element-on-right-side) | | +| 1304 | [Find N Unique Integers Sum Up To Zero](https://leetcode.com/problems/find-n-unique-integers-sum-up-to-zero) | | +| 1309 | [Decrypt String From Alphabet To Integer Mapping](https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping) | | +| 1313 | [Decompress Run-Length Encoded Strings](https://leetcode.com/problems/decompress-run-length-encoded-list) | | +| 1317 | [Convert Integer to Sum Of Two Non-Zero Integers](https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers) | | +| 1323 | [Maximum 69 Number](https://leetcode.com/problems/maximum-69-number) | | +| 1331 | [Rank Transform of An Array](https://leetcode.com/problems/rank-transform-of-an-array) | | +| 1332 | [Remove Palindromic Subsequences](https://leetcode.com/problems/remove-palindromic-subsequences) | | +| 1337 | [The K Weakest Rows In A Matrix](https://leetcode.com/problems/the-k-weakest-rows-in-a-matrix) | | +| 1342 | [Number of Steps to Reduce a Number to Zero](https://leetcode.com/problems/number-of-steps-to-reduce-a-number-to-zero) | | +| 1346 | [Check if N and It's Double Exist](https://leetcode.com/problems/check-if-n-and-its-double-exist) | | +| 1351 | [Count Negative Numbers In A Sorted Matrix](https://leetcode.com/problems/count-negative-numbers-in-a-sorted-matrix) | | +| 1356 | [Sort Integers by Number of 1 Bits](https://leetcode.com/problems/sort-integers-by-the-number-of-1-bits) | | +| 1360 | [Number of Days Between Two Dates](https://leetcode.com/problems/number-of-days-between-two-dates) | | +| 1365 | [How Many Numbers Are Smaller Than Current Number](https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number) | | +| 1370 | [Increasing Decreasing String](https://leetcode.com/problems/increasing-decreasing-string) | | +| 1374 | [Generate A String With Characters That Have Odd Count](https://leetcode.com/problems/generate-a-string-with-characters-that-have-odd-counts) | | +| 1380 | [Lucky Numbers In A Matrix](https://leetcode.com/problems/lucky-numbers-in-a-matrix) | | +| 1385 | [Find The Distance Value Between 2 Arrays](https://leetcode.com/problems/find-the-distance-value-between-two-arrays) | | +| 1389 | [Create Target Array in Given Order](https://leetcode.com/problems/create-target-array-in-the-given-order) | | +| 1394 | [Find Lucky Integer In An Array](https://leetcode.com/problems/find-lucky-integer-in-an-array) | | +| 1399 | [Count Largest Group](https://leetcode.com/problems/count-largest-group) | | +| 1403 | [Minimum Subsequence in Non-Increasing Order](https://leetcode.com/problems/minimum-subsequence-in-non-increasing-order) | | +| 1408 | [String Matching In An Array](https://leetcode.com/problems/string-matching-in-an-array) | | +| 1413 | [Minimum Value To Get Positive Step By Step Sum](https://leetcode.com/problems/minimum-value-to-get-positive-step-by-step-sum) | | +| 1417 | [Reformat The String](https://leetcode.com/problems/reformat-the-string) | | +| 1422 | [Maximum Score After Splitting A String](https://leetcode.com/problems/maximum-score-after-splitting-a-string) | | +| 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) | | +| 1436 | [Destination City](https://leetcode.com/problems/destination-city) | | +| 1441 | [Build An Array With Stack Operation](https://leetcode.com/problems/build-an-array-with-stack-operations) | | +| 1446 | [Consecutive Characters](https://leetcode.com/problems/consecutive-characters) | | +| 1450 | [Number of Students Doing Homework at Given Time](https://leetcode.com/problems/number-of-students-doing-homework-at-a-given-time) | | +| 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) | | +| 1460 | [Make 2 Arrays Equal by Reversing Sub Arrays](https://leetcode.com/problems/make-two-arrays-equal-by-reversing-sub-arrays) | | +| 1464 | [Maximum Product of 2 Elements in Array](https://leetcode.com/problems/maximum-product-of-two-elements-in-an-array) | | +| 1469 | [Find All Lonely Nodes](https://leetcode.com/problems/find-all-the-lonely-nodes) | | +| 1470 | [Shuffle The Array](https://leetcode.com/problems/shuffle-the-array) | | +| 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) | | +| 1480 | [Running Sum of 1D Array](https://leetcode.com/problems/running-sum-of-1d-array) | | +| 1486 | [XOR Operations in An Array](https://leetcode.com/problems/xor-operation-in-an-array) | | +| 1491 | [Average Salary Excluding the Minimum and Maximum Salary](https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary) | | +| 1496 | [Path Crossing](https://leetcode.com/problems/path-crossing) | | +| 1502 | [Can Make Arithmetic Progression From Sequence](https://leetcode.com/problems/can-make-arithmetic-progression-from-sequence) | | +| 1507 | [Reformat Date](https://leetcode.com/problems/reformat-date) | | +| 1512 | [Number of Good Pairs](https://leetcode.com/problems/number-of-good-pairs) | | +| 1518 | [Water Bottles](https://leetcode.com/problems/water-bottles) | | +| 1523 | [Count Odd Numbers In Interval Range](https://leetcode.com/problems/count-odd-numbers-in-an-interval-range) | | +| 1528 | [Shuffle Strings](https://leetcode.com/problems/shuffle-string) | | +| 1534 | [Count Good Triplets](https://leetcode.com/problems/count-good-triplets) | | +| 1539 | [Kth Missing Positive Number](https://leetcode.com/problems/kth-missing-positive-number) | | +| 1544 | [Make The String Great](https://leetcode.com/problems/make-the-string-great) | | From e0e9d7285ca0435b2d47c154de7dc6aa7f2926c7 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 28 Jul 2021 12:24:01 +0530 Subject: [PATCH 150/947] removes difficulty tags --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 5d59423..e3e05c7 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,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) | | 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) | -| 38 | [Count and Say](https://leetcode.com/problems/count-and-say) | Medium | [![Java](assets/java.png)](src/CountAndSay.java) [![Python](assets/python.png)](python/count_and_say.py) | +| 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) | | 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) | | 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) | | 66 | [Plus One](https://leetcode.com/problems/plus-one) | [![Java](assets/java.png)](src/PlusOne.java) [![Python](assets/python.png)](python/plus_one.py) | @@ -117,15 +117,15 @@ | 422 | 🔒 [Valid Word Square](https://leetcode.com/problems/valid-word-square) | | | 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) | Medium | [![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) | Medium | [![Java](assets/java.png)](src/NumberOfBoomerangs.java) [![Python](assets/python.png)](python/number_of_boomerangs.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) | Medium | [![Java](assets/java.png)](src/Heaters.java) [![Python](assets/python.png)](python/heaters.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) | @@ -152,7 +152,7 @@ | 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) | Medium | [![Java](assets/java.png)](src/ShortestUnsortedContinuousSubarray.java) [![Python](assets/python.png)](python/shortest_continuous_unsorted_subarray.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) | From 762c21872864cd88bbad7d85a1e3619fcdda9b9a Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 29 Jul 2021 16:33:32 +0530 Subject: [PATCH 151/947] solves can place flowers --- README.md | 2 +- python/can_place_flowers.py | 14 ++++++++++++++ src/CanPlaceFlowers.java | 16 ++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 python/can_place_flowers.py create mode 100644 src/CanPlaceFlowers.java diff --git a/README.md b/README.md index e3e05c7..5f2f706 100644 --- a/README.md +++ b/README.md @@ -159,7 +159,7 @@ | 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) | | +| 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) | | | 617 | [Merge Two Binary Trees](https://leetcode.com/problems/merge-two-binary-trees) | | | 624 | [Maximum Distance in Arrays](https://leetcode.com/problems/maximum-distance-in-arrays) | | diff --git a/python/can_place_flowers.py b/python/can_place_flowers.py new file mode 100644 index 0000000..03865bd --- /dev/null +++ b/python/can_place_flowers.py @@ -0,0 +1,14 @@ +from typing import List + + +class Solution: + def flowerBedCapacity(self, flowerbed: List[int]) -> int: + capacity = 0 + for index, value in enumerate(flowerbed): + if value != 1 and (index == 0 or flowerbed[index - 1] == 0) and (index == len(flowerbed) - 1 or flowerbed[index + 1] == 0): + capacity += 1 + flowerbed[index] = 1 + return capacity + + def canPlaceFlowers(self, flowerbed: List[int], n: int) -> bool: + return self.flowerBedCapacity(flowerbed) >= n diff --git a/src/CanPlaceFlowers.java b/src/CanPlaceFlowers.java new file mode 100644 index 0000000..e752b79 --- /dev/null +++ b/src/CanPlaceFlowers.java @@ -0,0 +1,16 @@ +public class CanPlaceFlowers { + public boolean canPlaceFlowers(int[] flowerbed, int n) { + return flowersCapacity(flowerbed) >= n; + } + + private int flowersCapacity(int[] flowerbed) { + int capacity = 0; + for (int index = 0 ; index < flowerbed.length ; index++) { + if ((flowerbed[index] != 1) && (index == 0 || flowerbed[index - 1] == 0) && (index == flowerbed.length - 1 || flowerbed[index + 1] == 0)) { + capacity++; + flowerbed[index] = 1; + } + } + return capacity; + } +} From 253615147fb06955f44a75c756aa37c0f58afbdf Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 30 Jul 2021 23:54:21 +0530 Subject: [PATCH 152/947] solves consruct string from binary tree --- README.md | 2 +- python/construct_string_from_binary_tree.py | 14 ++++++++++++++ src/ConstructStringFromBinaryTree.java | 8 ++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 python/construct_string_from_binary_tree.py create mode 100644 src/ConstructStringFromBinaryTree.java diff --git a/README.md b/README.md index 5f2f706..0e6e1c3 100644 --- a/README.md +++ b/README.md @@ -160,7 +160,7 @@ | 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) | | +| 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) | | | 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) | | diff --git a/python/construct_string_from_binary_tree.py b/python/construct_string_from_binary_tree.py new file mode 100644 index 0000000..c7a5683 --- /dev/null +++ b/python/construct_string_from_binary_tree.py @@ -0,0 +1,14 @@ +# Definition for a binary tree node. +class TreeNode: + def __init__(self, val=0, left=None, right=None): + self.val = val + self.left = left + self.right = right + + +class Solution: + def tree2str(self, root: TreeNode) -> str: + if root is None: return '' + if root.left is None and root.right is None: return f'{root.val}' + if root.right is None: return f'{root.val}({self.tree2str(root.left)})' + return f'{root.val}({self.tree2str(root.left)})({self.tree2str(root.right)})' diff --git a/src/ConstructStringFromBinaryTree.java b/src/ConstructStringFromBinaryTree.java new file mode 100644 index 0000000..33f6904 --- /dev/null +++ b/src/ConstructStringFromBinaryTree.java @@ -0,0 +1,8 @@ +public class ConstructStringFromBinaryTree { + public String tree2str(TreeNode root) { + if (root == null) return ""; + if (root.left == null && root.right == null) return root.val + ""; + return root.val + "(" + tree2str(root.left) + ")" + + (root.right == null ? "" : "(" + tree2str(root.right) + ")"); + } +} From fc4085c0f751512264cbcb2980d1768bcb713f50 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 31 Jul 2021 00:15:31 +0530 Subject: [PATCH 153/947] solves merge two binary trees --- README.md | 4 ++-- python/merge_two_binary_trees.py | 16 ++++++++++++++++ src/MergeTwoBinaryTrees.java | 25 +++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 python/merge_two_binary_trees.py create mode 100644 src/MergeTwoBinaryTrees.java diff --git a/README.md b/README.md index 0e6e1c3..07468dc 100644 --- a/README.md +++ b/README.md @@ -160,8 +160,8 @@ | 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) | | +| 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) | | | 633 | [Sum Square Numbers](https://leetcode.com/problems/sum-of-square-numbers) | | diff --git a/python/merge_two_binary_trees.py b/python/merge_two_binary_trees.py new file mode 100644 index 0000000..01bfbed --- /dev/null +++ b/python/merge_two_binary_trees.py @@ -0,0 +1,16 @@ +# Definition for a binary tree node. +class TreeNode: + def __init__(self, val=0, left=None, right=None): + self.val = val + self.left = left + self.right = right + + +class Solution: + def mergeTrees(self, root1: TreeNode, root2: TreeNode) -> TreeNode: + if root1 is None: return root2 + if root2 is None: return root1 + root1.val += root2.val + root1.left = self.mergeTrees(root1.left, root2.left) + root1.right = self.mergeTrees(root1.right, root2.right) + return root1 diff --git a/src/MergeTwoBinaryTrees.java b/src/MergeTwoBinaryTrees.java new file mode 100644 index 0000000..8e26b21 --- /dev/null +++ b/src/MergeTwoBinaryTrees.java @@ -0,0 +1,25 @@ +public class MergeTwoBinaryTrees { + public TreeNode mergeTrees(TreeNode root1, TreeNode root2) { + if (root1 == null) return root2; + if (root2 == null) return root1; + root1.val += root2.val; + root1.left = mergeTrees(root1.left, root2.left); + root1.right = mergeTrees(root1.right, root2.right); + return root1; + } + + private void mergeTrees(TreeNode result, TreeNode root1, TreeNode root2) { + if (root1 == null && root2 == null) return; + if (root1 == null) result.val = root2.val; + else if (root2 == null) result.val = root1.val; + else result.val = root1.val + root2.val; + if ((root1 != null && root1.left != null) || (root2 != null && root2.left != null)) { + result.left = new TreeNode(); + mergeTrees(result.left, root1 == null ? null : root1.left, root2 == null ? null : root2.left); + } + if ((root1 != null && root1.right != null) || (root2 != null && root2.right != null)) { + result.right = new TreeNode(); + mergeTrees(result.right, root1 == null ? null : root1.right, root2 == null ? null : root2.right); + } + } +} From e88b27a767ddedea4882152daa9c0640161459d4 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 31 Jul 2021 00:17:06 +0530 Subject: [PATCH 154/947] adds premium logo in front of problem --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 07468dc..d3fd50c 100644 --- a/README.md +++ b/README.md @@ -162,7 +162,7 @@ | 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) | | +| 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) | | | 633 | [Sum Square Numbers](https://leetcode.com/problems/sum-of-square-numbers) | | | 637 | [Average of Levels in Binary Tree](https://leetcode.com/problems/average-of-levels-in-binary-tree) | | From 96bbe467aaf442dbf7ecef4cffc86119cf0e79e9 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 31 Jul 2021 00:36:52 +0530 Subject: [PATCH 155/947] solves maximum product of three numbers --- README.md | 2 +- python/maximum_product_of_three_numbers.py | 24 +++++++++++++++++++ src/MaximumProductOfThreeNumbers.java | 28 ++++++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 python/maximum_product_of_three_numbers.py create mode 100644 src/MaximumProductOfThreeNumbers.java diff --git a/README.md b/README.md index d3fd50c..92b392a 100644 --- a/README.md +++ b/README.md @@ -163,7 +163,7 @@ | 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) | | +| 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) | | | 637 | [Average of Levels in Binary Tree](https://leetcode.com/problems/average-of-levels-in-binary-tree) | | | 643 | [Maximum Average SubArray I](https://leetcode.com/problems/maximum-average-subarray-i) | | diff --git a/python/maximum_product_of_three_numbers.py b/python/maximum_product_of_three_numbers.py new file mode 100644 index 0000000..50cb201 --- /dev/null +++ b/python/maximum_product_of_three_numbers.py @@ -0,0 +1,24 @@ +from typing import List + + +class Solution: + def maximumProduct(self, array: List[int]) -> int: + positive_1, positive_2, positive_3 = (-float('inf'), ) * 3 + negative_1, negative_2 = (float('inf'), ) * 2 + for number in array: + if number > positive_1: + positive_3 = positive_2 + positive_2 = positive_1 + positive_1 = number + elif number > positive_2: + positive_3 = positive_2 + positive_2 = number + elif number > positive_3: + positive_3 = number + if number < negative_1: + negative_2 = negative_1 + negative_1 = number + elif number < negative_2: + negative_2 = number + + return max(positive_1 * positive_2 * positive_3, negative_1 * negative_2 * positive_1) diff --git a/src/MaximumProductOfThreeNumbers.java b/src/MaximumProductOfThreeNumbers.java new file mode 100644 index 0000000..8ff75b8 --- /dev/null +++ b/src/MaximumProductOfThreeNumbers.java @@ -0,0 +1,28 @@ +public class MaximumProductOfThreeNumbers { + public int maximumProduct(int[] numbers) { + int positive1 = Integer.MIN_VALUE, positive2 = Integer.MIN_VALUE, positive3 = Integer.MIN_VALUE, + negative1 = Integer.MAX_VALUE, + negative2 = Integer.MAX_VALUE; + + for (int number : numbers) { + if (number > positive1) { + positive3 = positive2; + positive2 = positive1; + positive1= number; + } else if (number > positive2) { + positive3 = positive2; + positive2 = number; + } else if (number> positive3) { + positive3 = number; + } + if (number < negative2) { + negative1 = negative2; + negative2 = number; + } else if (number < negative1) { + negative1 = number; + } + } + + return Math.max(positive1 * positive2 * positive3, negative1 * negative2 * positive1); + } +} From e561589e5711a484fafc1604f60d177412bdb07c Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 31 Jul 2021 01:12:38 +0530 Subject: [PATCH 156/947] solves sum of square of numbers --- README.md | 2 +- python/sum_of_squares_numbers.py | 12 ++++++++++++ src/SumOfSquareNumbers.java | 16 ++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 python/sum_of_squares_numbers.py create mode 100644 src/SumOfSquareNumbers.java diff --git a/README.md b/README.md index 92b392a..d0e0030 100644 --- a/README.md +++ b/README.md @@ -164,7 +164,7 @@ | 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) | | +| 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) | | | 643 | [Maximum Average SubArray I](https://leetcode.com/problems/maximum-average-subarray-i) | | | 645 | [Set Mismatch](https://leetcode.com/problems/set-mismatch) | | diff --git a/python/sum_of_squares_numbers.py b/python/sum_of_squares_numbers.py new file mode 100644 index 0000000..5a66c95 --- /dev/null +++ b/python/sum_of_squares_numbers.py @@ -0,0 +1,12 @@ +class Solution: + def judgeSquareSum(self, c: int) -> bool: + i = 2 + while i * i <= c: + if c % i == 0: + count = 0 + while c % i == 0: + count += 1 + c //= i + if i % 4 == 3 and count % 2 == 1: return False + i += 1 + return c % 4 != 3 diff --git a/src/SumOfSquareNumbers.java b/src/SumOfSquareNumbers.java new file mode 100644 index 0000000..a663337 --- /dev/null +++ b/src/SumOfSquareNumbers.java @@ -0,0 +1,16 @@ +public class SumOfSquareNumbers { + public boolean judgeSquareSum(int c) { + int count; + for (int i = 2 ; i * i <= c ; i++) { + if (c % i == 0) { + count = 0; + while (c % i == 0) { + c /= i; + count++; + } + if (i % 4 == 3 && count % 2 == 1) return false; + } + } + return true; + } +} From bb7ed26f805a3ab72e2d60a4aa726abfe0ce213d Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 2 Aug 2021 15:14:05 +0200 Subject: [PATCH 157/947] solves maximum average subarray I --- README.md | 2 +- python/maximum_average_subarray_I.py | 11 +++++++++++ src/MaximumAverageSubArrayI.java | 14 ++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 python/maximum_average_subarray_I.py create mode 100644 src/MaximumAverageSubArrayI.java diff --git a/README.md b/README.md index d0e0030..03fce7e 100644 --- a/README.md +++ b/README.md @@ -166,7 +166,7 @@ | 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) | | -| 643 | [Maximum Average SubArray I](https://leetcode.com/problems/maximum-average-subarray-i) | | +| 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) | | | 653 | [Two Sum IV - Input is a BST](https://leetcode.com/problems/two-sum-iv-input-is-a-bst) | | | 657 | [Robot Return to Origin](https://leetcode.com/problems/robot-return-to-origin) | | diff --git a/python/maximum_average_subarray_I.py b/python/maximum_average_subarray_I.py new file mode 100644 index 0000000..7af6ab8 --- /dev/null +++ b/python/maximum_average_subarray_I.py @@ -0,0 +1,11 @@ +from typing import List + + +class Solution: + def findMaxAverage(self, nums: List[int], k: int) -> float: + moving_sum = sum(nums[i] for i in range(k)) + result = moving_sum + for i in range(len(nums) - k): + moving_sum += nums[k + i] - nums[i] + result = max(result, moving_sum) + return result / k diff --git a/src/MaximumAverageSubArrayI.java b/src/MaximumAverageSubArrayI.java new file mode 100644 index 0000000..5804dd2 --- /dev/null +++ b/src/MaximumAverageSubArrayI.java @@ -0,0 +1,14 @@ +public class MaximumAverageSubArrayI { + public double findMaxAverage(int[] numbers, int k) { + long sum = 0; + for (int i = 0 ; i < k ; i++) { + sum += numbers[i]; + } + double maxSum = sum; + for (int index = 0 ; index < numbers.length - k ; index++) { + sum += numbers[index + k] - numbers[index]; + maxSum = Math.max(maxSum, sum); + } + return maxSum / k; + } +} From b3afefe495fc9f49f9f81e8424e7723f6cb3796e Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 2 Aug 2021 15:32:23 +0200 Subject: [PATCH 158/947] solves set mismatch --- README.md | 2 +- python/set_mismatch.py | 14 ++++++++++++++ src/SetMismatch.java | 16 ++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 python/set_mismatch.py create mode 100644 src/SetMismatch.java diff --git a/README.md b/README.md index 03fce7e..b1c6fa0 100644 --- a/README.md +++ b/README.md @@ -167,7 +167,7 @@ | 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) | | | 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) | | +| 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) | | | 657 | [Robot Return to Origin](https://leetcode.com/problems/robot-return-to-origin) | | | 661 | [Image Smoother](https://leetcode.com/problems/image-smoother) | | diff --git a/python/set_mismatch.py b/python/set_mismatch.py new file mode 100644 index 0000000..01b60dc --- /dev/null +++ b/python/set_mismatch.py @@ -0,0 +1,14 @@ +from typing import List + + +class Solution: + def findErrorNums(self, nums: List[int]) -> List[int]: + repeated, missing = 0, 0 + for number in nums: + if nums[abs(number) - 1] < 0: repeated = number + else: nums[abs(number) - 1] *= -1 + for index in range(len(nums)): + if nums[index] > 0: + missing = index + 1 + break + return [abs(repeated), missing] diff --git a/src/SetMismatch.java b/src/SetMismatch.java new file mode 100644 index 0000000..d378ef5 --- /dev/null +++ b/src/SetMismatch.java @@ -0,0 +1,16 @@ +public class SetMismatch { + public int[] findErrorNums(int[] array) { + int repeated = 0, missing = 0; + for (int number : array) { + if (array[Math.abs(number) - 1] < 0) repeated = number; + else array[Math.abs(number) - 1] *= -1; + } + for (int index = 0 ; index < array.length ; index++) { + if (array[index] > 0) { + missing = index + 1; + break; + } + } + return new int[] {Math.abs(repeated), missing}; + } +} From 2578ae8487de5ac82b910ff5c5f67da367d542af Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 2 Aug 2021 15:57:44 +0200 Subject: [PATCH 159/947] solves two sum iv --- README.md | 8 ++++---- python/two_sum_iv.py | 17 +++++++++++++++++ src/TwoSumIVInputIsABST.java | 26 ++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 python/two_sum_iv.py create mode 100644 src/TwoSumIVInputIsABST.java diff --git a/README.md b/README.md index b1c6fa0..3ec5948 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-120/571-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-120/1571-1abc9c.svg) -![problems-solved-python](https://img.shields.io/badge/Python-120/1571-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-143/571-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-143/1571-1abc9c.svg) +![problems-solved-python](https://img.shields.io/badge/Python-143/1571-1abc9c.svg) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md) 🔒 = Subscription Content @@ -168,7 +168,7 @@ | 637 | [Average of Levels in Binary Tree](https://leetcode.com/problems/average-of-levels-in-binary-tree) | | | 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) | | +| 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) | | | 661 | [Image Smoother](https://leetcode.com/problems/image-smoother) | | | 665 | [Non Deceasing Array](https://leetcode.com/problems/non-decreasing-array) | | diff --git a/python/two_sum_iv.py b/python/two_sum_iv.py new file mode 100644 index 0000000..69769ed --- /dev/null +++ b/python/two_sum_iv.py @@ -0,0 +1,17 @@ +# Definition for a binary tree node. +class TreeNode: + def __init__(self, val=0, left=None, right=None): + self.val = val + self.left = left + self.right = right + + +class Solution: + def __init__(self): + self.elements = set() + + def findTarget(self, root: TreeNode, k: int) -> bool: + if root is None: return False + if k - root.val in self.elements: return True + self.elements.add(root.val) + return self.findTarget(root.left, k) or self.findTarget(root.right, k) diff --git a/src/TwoSumIVInputIsABST.java b/src/TwoSumIVInputIsABST.java new file mode 100644 index 0000000..8a5b144 --- /dev/null +++ b/src/TwoSumIVInputIsABST.java @@ -0,0 +1,26 @@ +import java.util.HashSet; +import java.util.Set; + +class TreeNode { + int val; + TreeNode left; + TreeNode right; + TreeNode() {} + TreeNode(int val) { this.val = val; } + TreeNode(int val, TreeNode left, TreeNode right) { + this.val = val; + this.left = left; + this.right = right; + } +} + +public class TwoSumIVInputIsABST { + Set elements = new HashSet<>(); + + public boolean findTarget(TreeNode root, int k) { + if (root == null) return false; + if (elements.contains(k - root.val)) return true; + elements.add(root.val); + return findTarget(root.left, k) || findTarget(root.right, k); + } +} From cb2daefd60b85dac9e2fcc5b7a02c2bddaff97f5 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 2 Aug 2021 16:08:46 +0200 Subject: [PATCH 160/947] solves robot return to origin --- README.md | 2 +- python/robot_return_to_origin.py | 9 +++++++++ src/RobotReturnToOrigin.java | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 python/robot_return_to_origin.py create mode 100644 src/RobotReturnToOrigin.java diff --git a/README.md b/README.md index 3ec5948..f152455 100644 --- a/README.md +++ b/README.md @@ -169,7 +169,7 @@ | 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) | | +| 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) | | | 665 | [Non Deceasing Array](https://leetcode.com/problems/non-decreasing-array) | | | 669 | [Trim a Binary Search Tree](https://leetcode.com/problems/trim-a-binary-search-tree) | | diff --git a/python/robot_return_to_origin.py b/python/robot_return_to_origin.py new file mode 100644 index 0000000..8c111be --- /dev/null +++ b/python/robot_return_to_origin.py @@ -0,0 +1,9 @@ +class Solution: + def judgeCircle(self, moves: str) -> bool: + vertical, horizontal = 0, 0 + for move in moves: + if move == 'U': vertical += 1 + elif move == 'D': vertical -= 1 + elif move == 'R': horizontal += 1 + elif move == 'L': horizontal -= 1 + return vertical == 0 and horizontal == 0 diff --git a/src/RobotReturnToOrigin.java b/src/RobotReturnToOrigin.java new file mode 100644 index 0000000..1a703b2 --- /dev/null +++ b/src/RobotReturnToOrigin.java @@ -0,0 +1,14 @@ +public class RobotReturnToOrigin { + public boolean judgeCircle(String moves) { + int vertical = 0, horizontal = 0; + for (int index = 0 ; index < moves.length() ; index++) { + switch (moves.charAt(index)) { + case 'U' -> vertical++; + case 'R' -> horizontal++; + case 'D' -> vertical--; + case 'L' -> horizontal--; + } + } + return vertical == 0 && horizontal == 0; + } +} From f1e25ecc0250bc48afc55dabc0eea5596c706120 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 2 Aug 2021 16:42:46 +0200 Subject: [PATCH 161/947] solves image smoother --- README.md | 2 +- python/image_smoother.py | 16 ++++++++++++++++ src/ImageSmoother.java | 18 ++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 python/image_smoother.py create mode 100644 src/ImageSmoother.java diff --git a/README.md b/README.md index f152455..5c15f81 100644 --- a/README.md +++ b/README.md @@ -170,7 +170,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) | -| 661 | [Image Smoother](https://leetcode.com/problems/image-smoother) | | +| 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) | | | 669 | [Trim a Binary Search Tree](https://leetcode.com/problems/trim-a-binary-search-tree) | | | 671 | [Second Minimum Node in Binary Tree](https://leetcode.com/problems/second-minimum-node-in-a-binary-tree) | | diff --git a/python/image_smoother.py b/python/image_smoother.py new file mode 100644 index 0000000..8cbd41b --- /dev/null +++ b/python/image_smoother.py @@ -0,0 +1,16 @@ +from typing import List + + +class Solution: + def imageSmoother(self, img: List[List[int]]) -> List[List[int]]: + rows, columns = len(img), len(img[0]) + result = [[0 for i in range(columns)] for j in range(rows)] + for row in range(rows): + for column in range(columns): + k_sum, count = 0, 0 + for k_row in range(row if row == 0 else row - 1, (row if row == rows - 1 else row + 1) + 1): + for k_column in range(column if column == 0 else column - 1, (column if column == columns - 1 else column + 1) + 1): + k_sum += img[k_row][k_column] + count += 1 + result[row][column] = k_sum // count + return result diff --git a/src/ImageSmoother.java b/src/ImageSmoother.java new file mode 100644 index 0000000..e77308a --- /dev/null +++ b/src/ImageSmoother.java @@ -0,0 +1,18 @@ +public class ImageSmoother { + public int[][] imageSmoother(int[][] img) { + int[][] result = new int[img.length][img[0].length]; + int sum, count, rows = img.length, columns = img[0].length; + for (int row = 0 ; row < rows; row++) { + for (int column = 0 ; column < columns ; column++) { + sum = count = 0; + for (int k_row = row == 0 ? row : row - 1 ; k_row <= (row == rows - 1 ? row : row + 1) ; k_row++) { + for (int k_column = column == 0 ? column : column - 1 ; k_column <= (column == columns - 1 ? column : column + 1) ; k_column++, count++) { + sum += img[k_row][k_column]; + } + } + result[row][column] = sum / count; + } + } + return result; + } +} From 867286a29c586a87ea7b2e2dc77d7fa9a113f27e Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Tue, 3 Aug 2021 16:11:29 +0200 Subject: [PATCH 162/947] solves average of levels in binary tree --- README.md | 8 +++++++- src/AverageLevelsOfBinaryTree.java | 32 ++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/AverageLevelsOfBinaryTree.java diff --git a/README.md b/README.md index 5c15f81..33b5806 100644 --- a/README.md +++ b/README.md @@ -165,12 +165,18 @@ | 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) | | +| 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/) | 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) | +| 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/) | +| 643 | [Maximum Average SubArray I](https://leetcode.com/problems/maximum-average-subarray-i) | | +| 645 | [Set Mismatch](https://leetcode.com/problems/set-mismatch) | | +| 653 | [Two Sum IV - Input is a BST](https://leetcode.com/problems/two-sum-iv-input-is-a-bst) | | +| 657 | [Robot Return to Origin](https://leetcode.com/problems/robot-return-to-origin) | | +| 661 | [Image Smoother](https://leetcode.com/problems/image-smoother) | | | 665 | [Non Deceasing Array](https://leetcode.com/problems/non-decreasing-array) | | | 669 | [Trim a Binary Search Tree](https://leetcode.com/problems/trim-a-binary-search-tree) | | | 671 | [Second Minimum Node in Binary Tree](https://leetcode.com/problems/second-minimum-node-in-a-binary-tree) | | diff --git a/src/AverageLevelsOfBinaryTree.java b/src/AverageLevelsOfBinaryTree.java new file mode 100644 index 0000000..7b9e70f --- /dev/null +++ b/src/AverageLevelsOfBinaryTree.java @@ -0,0 +1,32 @@ +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; + +public class AverageLevelsOfBinaryTree { + public List averageOfLevels(TreeNode root) { + Queue queue = new LinkedList<>(); + queue.add(root); + queue.add(null); + int count = 0; + List result = new ArrayList<>(); + result.add(0.0); + while (!queue.isEmpty()) { + TreeNode current = queue.poll(); + if (current == null && queue.isEmpty()) break; + if (current == null) { + queue.add(null); + result.set(result.size() - 1, result.get(result.size() - 1) / count); + result.add(0.0); + count = 0; + continue; + } + count++; + if (current.left != null) queue.add(current.left); + if (current.right != null) queue.add(current.right); + result.set(result.size() - 1, result.get(result.size() - 1) + current.val); + } + result.set(result.size() - 1, result.get(result.size() - 1) / count); + return result; + } +} From 225d071e6a48c829b7544fec03cef83afcb5c48b Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Tue, 3 Aug 2021 16:18:05 +0200 Subject: [PATCH 163/947] solves average levels of binary tree in python --- README.md | 2 +- python/average_levels_of_binary_tree.py | 34 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 python/average_levels_of_binary_tree.py diff --git a/README.md b/README.md index 33b5806..5edcfe4 100644 --- a/README.md +++ b/README.md @@ -165,7 +165,7 @@ | 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/) +| 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) | diff --git a/python/average_levels_of_binary_tree.py b/python/average_levels_of_binary_tree.py new file mode 100644 index 0000000..894122b --- /dev/null +++ b/python/average_levels_of_binary_tree.py @@ -0,0 +1,34 @@ +# Definition for a binary tree node. +from typing import List +from collections import deque + + +class TreeNode: + def __init__(self, val=0, left=None, right=None): + self.val = val + self.left = left + self.right = right + + +class Solution: + def averageOfLevels(self, root: TreeNode) -> List[float]: + result = [0] + queue = deque() + queue.append(root) + queue.append(None) + count = 0 + while queue: + current = queue.popleft() + if current is None and len(queue) == 0: break + if current is None: + queue.append(None) + result[-1] /= count + result.append(0) + count = 0 + continue + count += 1 + if current.left is not None: queue.append(current.left) + if current.right is not None: queue.append(current.right) + result[-1] += current.val + result[-1] /= count + return result From 2a830bc560282ab6ec11ffca04ff08fc5e89b40e Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Tue, 3 Aug 2021 16:21:52 +0200 Subject: [PATCH 164/947] fixes readme fil --- README.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/README.md b/README.md index 5edcfe4..152b677 100644 --- a/README.md +++ b/README.md @@ -171,12 +171,6 @@ | 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) | -| 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/) | -| 643 | [Maximum Average SubArray I](https://leetcode.com/problems/maximum-average-subarray-i) | | -| 645 | [Set Mismatch](https://leetcode.com/problems/set-mismatch) | | -| 653 | [Two Sum IV - Input is a BST](https://leetcode.com/problems/two-sum-iv-input-is-a-bst) | | -| 657 | [Robot Return to Origin](https://leetcode.com/problems/robot-return-to-origin) | | -| 661 | [Image Smoother](https://leetcode.com/problems/image-smoother) | | | 665 | [Non Deceasing Array](https://leetcode.com/problems/non-decreasing-array) | | | 669 | [Trim a Binary Search Tree](https://leetcode.com/problems/trim-a-binary-search-tree) | | | 671 | [Second Minimum Node in Binary Tree](https://leetcode.com/problems/second-minimum-node-in-a-binary-tree) | | From ebcf450a99e7a2b87fd852e22b0ebe8103d27772 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Tue, 3 Aug 2021 16:36:54 +0200 Subject: [PATCH 165/947] solves non decreasing array --- README.md | 2 +- python/non_decreasing_array.py | 13 +++++++++++++ src/NonDecreasingArray.java | 15 +++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 python/non_decreasing_array.py create mode 100644 src/NonDecreasingArray.java diff --git a/README.md b/README.md index 152b677..2ab8699 100644 --- a/README.md +++ b/README.md @@ -171,7 +171,7 @@ | 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) | | +| 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) | | | 671 | [Second Minimum Node in Binary Tree](https://leetcode.com/problems/second-minimum-node-in-a-binary-tree) | | | 674 | [Longest Continuous Increasing Subsequence](https://leetcode.com/problems/longest-continuous-increasing-subsequence) | | diff --git a/python/non_decreasing_array.py b/python/non_decreasing_array.py new file mode 100644 index 0000000..cdaaf60 --- /dev/null +++ b/python/non_decreasing_array.py @@ -0,0 +1,13 @@ +from typing import List + + +class Solution: + def checkPossibility(self, nums: List[int]) -> bool: + handled_decreasing = False + for index in range(len(nums) - 1): + if nums[index] > nums[index + 1]: + if handled_decreasing: return False + handled_decreasing = True + if index - 1 >= 0 and nums[index - 1] > nums[index + 1] and index + 2 < len(nums) and nums[index] > nums[index + 2]: + return False + return True diff --git a/src/NonDecreasingArray.java b/src/NonDecreasingArray.java new file mode 100644 index 0000000..ec20cbd --- /dev/null +++ b/src/NonDecreasingArray.java @@ -0,0 +1,15 @@ +public class NonDecreasingArray { + public boolean checkPossibility(int[] array) { + boolean handledDecreasing = false; + for (int index = 0 ; index < array.length - 1 ; index++) { + if (array[index] > array[index + 1]) { + if (handledDecreasing) return false; + handledDecreasing = true; + if ((index - 1 >= 0 && array[index - 1] > array[index + 1]) && (index + 2 < array.length && array[index] > array[index + 2])) { + return false; + } + } + } + return true; + } +} From 77b1dedf7fdd607e4f8778e3bd708c6f3a9a4603 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Tue, 3 Aug 2021 16:46:14 +0200 Subject: [PATCH 166/947] solves trim a binary search tree --- README.md | 2 +- python/trim_a_binary_search_tree.py | 16 ++++++++++++++++ src/TrimABinarySearchTree.java | 10 ++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 python/trim_a_binary_search_tree.py create mode 100644 src/TrimABinarySearchTree.java diff --git a/README.md b/README.md index 2ab8699..a40c6a1 100644 --- a/README.md +++ b/README.md @@ -172,7 +172,7 @@ | 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) | | +| 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) | | | 674 | [Longest Continuous Increasing Subsequence](https://leetcode.com/problems/longest-continuous-increasing-subsequence) | | | 680 | [Valid Palindrome II](https://leetcode.com/problems/valid-palindrome-ii) | | diff --git a/python/trim_a_binary_search_tree.py b/python/trim_a_binary_search_tree.py new file mode 100644 index 0000000..d205d52 --- /dev/null +++ b/python/trim_a_binary_search_tree.py @@ -0,0 +1,16 @@ +# Definition for a binary tree node. +class TreeNode: + def __init__(self, val=0, left=None, right=None): + self.val = val + self.left = left + self.right = right + + +class Solution: + def trimBST(self, root: TreeNode, low: int, high: int) -> TreeNode: + if root is None: return None + if root.val < low: return self.trimBST(root.right, low, high) + if root.val > high: return self.trimBST(root.left, low, high) + root.left = self.trimBST(root.left, low, high) + root.right = self.trimBST(root.right, low, high) + return root diff --git a/src/TrimABinarySearchTree.java b/src/TrimABinarySearchTree.java new file mode 100644 index 0000000..7dd264a --- /dev/null +++ b/src/TrimABinarySearchTree.java @@ -0,0 +1,10 @@ +public class TrimABinarySearchTree { + public TreeNode trimBST(TreeNode root, int low, int high) { + if (root == null) return null; + if (root.val < low) return trimBST(root.right, low, high); + if (root.val > high) return trimBST(root.left, low, high); + root.left = trimBST(root.left, low, high); + root.right = trimBST(root.right, low, high); + return root; + } +} From 33026f8ed2de1a870879186dc8e40f4bdbbaf2d9 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 6 Aug 2021 17:04:24 +0200 Subject: [PATCH 167/947] solves non decreasing array --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a40c6a1..d02cfea 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-143/571-1f425f.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-143/1571-1f425f.svg) ![problems-solved-java](https://img.shields.io/badge/Java-143/1571-1abc9c.svg) ![problems-solved-python](https://img.shields.io/badge/Python-143/1571-1abc9c.svg) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md) From 41f132c702d1094bccbb6eeaba20fd403e24e7f4 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 6 Aug 2021 17:33:02 +0200 Subject: [PATCH 168/947] solves second minimum in bst --- README.md | 2 +- python/second_minimum_node_in_binary_tree.py | 30 +++++++++++++++++ src/SecondMinimumNodeInBinaryTree.java | 35 ++++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 python/second_minimum_node_in_binary_tree.py create mode 100644 src/SecondMinimumNodeInBinaryTree.java diff --git a/README.md b/README.md index d02cfea..5da9efa 100644 --- a/README.md +++ b/README.md @@ -173,7 +173,7 @@ | 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) | | +| 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) | | | 680 | [Valid Palindrome II](https://leetcode.com/problems/valid-palindrome-ii) | | | 682 | [Baseball Game](https://leetcode.com/problems/baseball-game) | | diff --git a/python/second_minimum_node_in_binary_tree.py b/python/second_minimum_node_in_binary_tree.py new file mode 100644 index 0000000..242fcfc --- /dev/null +++ b/python/second_minimum_node_in_binary_tree.py @@ -0,0 +1,30 @@ +from heapq import heappop, heappush + +# Definition for a binary tree node. +class TreeNode: + def __init__(self, val=0, left=None, right=None): + self.val = val + self.left = left + self.right = right + + +class Solution: + def addNodesToSet(self, root: TreeNode, elements: set) -> None: + if root is None: return + elements.add(root.val) + self.addNodesToSet(root.left, elements) + self.addNodesToSet(root.right, elements) + + def unique_elements(self, root: TreeNode) -> set: + elements = set() + self.addNodesToSet(root, elements) + return elements + + def findSecondMinimumValue(self, root: TreeNode) -> int: + elements = self.unique_elements(root) + if len(elements) < 2: return -1 + heap = [] + for element in elements: + heappush(heap, element) + heappop(heap) + return heappop(heap) diff --git a/src/SecondMinimumNodeInBinaryTree.java b/src/SecondMinimumNodeInBinaryTree.java new file mode 100644 index 0000000..b97b04d --- /dev/null +++ b/src/SecondMinimumNodeInBinaryTree.java @@ -0,0 +1,35 @@ +import java.util.HashSet; +import java.util.PriorityQueue; +import java.util.Queue; +import java.util.Set; + +public class SecondMinimumNodeInBinaryTree { + public int findSecondMinimumValue(TreeNode root) { + Set elements = treeToSet(root); + if (elements.size() < 2) return -1; + Queue queue = setToMinHeap(elements); + queue.poll(); + return queue.peek(); + } + + private static Set treeToSet(TreeNode root) { + Set result = new HashSet<>(); + addTreeNodesToSet(root, result); + return result; + } + + private static void addTreeNodesToSet(TreeNode root, Set set) { + if (root == null) return; + set.add(root.val); + addTreeNodesToSet(root.left, set); + addTreeNodesToSet(root.right, set); + } + + private static Queue setToMinHeap(Set elements) { + Queue queue = new PriorityQueue<>(); + for (int element : elements) { + queue.add(element); + } + return queue; + } +} From b8a4ba925cc009e2ad6c88c26b73a2190e7570e0 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 6 Aug 2021 17:33:23 +0200 Subject: [PATCH 169/947] solves second minimum in bst --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5da9efa..3f919f2 100644 --- a/README.md +++ b/README.md @@ -173,7 +173,7 @@ | 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 | +| 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) | | | 680 | [Valid Palindrome II](https://leetcode.com/problems/valid-palindrome-ii) | | | 682 | [Baseball Game](https://leetcode.com/problems/baseball-game) | | From 36c452c04cebe32e993151118b73862a6fad5105 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 6 Aug 2021 17:39:36 +0200 Subject: [PATCH 170/947] solves longest increasing sub sequence --- README.md | 2 +- .../longest_continuous_increasing_subsequence.py | 13 +++++++++++++ src/LongestContinuousIncreasingSubsequence.java | 14 ++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 python/longest_continuous_increasing_subsequence.py create mode 100644 src/LongestContinuousIncreasingSubsequence.java diff --git a/README.md b/README.md index 3f919f2..4e28dad 100644 --- a/README.md +++ b/README.md @@ -174,7 +174,7 @@ | 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) | | +| 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/) | | 680 | [Valid Palindrome II](https://leetcode.com/problems/valid-palindrome-ii) | | | 682 | [Baseball Game](https://leetcode.com/problems/baseball-game) | | | 686 | [Repeated String Match](https://leetcode.com/problems/repeated-string-match) | | diff --git a/python/longest_continuous_increasing_subsequence.py b/python/longest_continuous_increasing_subsequence.py new file mode 100644 index 0000000..ada7bf6 --- /dev/null +++ b/python/longest_continuous_increasing_subsequence.py @@ -0,0 +1,13 @@ +from typing import List + + +class Solution: + def findLengthOfLCIS(self, nums: List[int]) -> int: + current, result = 1, 1 + for index in range(1, len(nums)): + if nums[index] > nums[index - 1]: + current += 1 + result = max(result, current) + else: + current = 1 + return result diff --git a/src/LongestContinuousIncreasingSubsequence.java b/src/LongestContinuousIncreasingSubsequence.java new file mode 100644 index 0000000..ce79c46 --- /dev/null +++ b/src/LongestContinuousIncreasingSubsequence.java @@ -0,0 +1,14 @@ +public class LongestContinuousIncreasingSubsequence { + public int findLengthOfLCIS(int[] nums) { + int result = 1, current = 1; + for (int index = 1 ; index < nums.length ; index++) { + if (nums[index] > nums[index - 1]) { + current++; + result = Math.max(result, current); + } else { + current = 1; + } + } + return result; + } +} From 896b9de7f6180882086fa378636cefbe1f254b3f Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 10 Aug 2021 13:30:02 +0200 Subject: [PATCH 171/947] solves valid pallindrome ii --- README.md | 4 ++-- python/valid_pallindrome_ii.py | 17 +++++++++++++++++ src/ValidPalindromeII.java | 19 +++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 python/valid_pallindrome_ii.py create mode 100644 src/ValidPalindromeII.java diff --git a/README.md b/README.md index 4e28dad..38e6ca2 100644 --- a/README.md +++ b/README.md @@ -174,8 +174,8 @@ | 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/) | -| 680 | [Valid Palindrome II](https://leetcode.com/problems/valid-palindrome-ii) | | +| 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) | | | 686 | [Repeated String Match](https://leetcode.com/problems/repeated-string-match) | | | 687 | [Longest Univalue Path](https://leetcode.com/problems/longest-univalue-path) | | diff --git a/python/valid_pallindrome_ii.py b/python/valid_pallindrome_ii.py new file mode 100644 index 0000000..d6df738 --- /dev/null +++ b/python/valid_pallindrome_ii.py @@ -0,0 +1,17 @@ +class Solution: + def isPalindrome(self, s: str, left: int, right: int) -> bool: + while left < right: + if s[left] != s[right]: return False + left += 1 + right -= 1 + return True + + def validPalindrome(self, s: str) -> bool: + left, right = 0, len(s) - 1 + while left < right: + if s[left] != s[right]: + if self.isPalindrome(s, left + 1, right): return True + return self.isPalindrome(s, left, right - 1) + left += 1 + right -= 1 + return True \ No newline at end of file diff --git a/src/ValidPalindromeII.java b/src/ValidPalindromeII.java new file mode 100644 index 0000000..0d31d3c --- /dev/null +++ b/src/ValidPalindromeII.java @@ -0,0 +1,19 @@ +public class ValidPalindromeII { + public boolean validPalindrome(String s) { + for (int left = 0, right = s.length() - 1; left < right ; left++, right--) { + if (s.charAt(left) != s.charAt(right)) { + if (isValidPalindrome(s, left + 1, right)) return true; + return isValidPalindrome(s, left, right + 1); + } + } + return true; + } + + private boolean isValidPalindrome(String string, int left, int right) { + if (left >= string.length() || right <= 0) return false; + for ( ; left < right ; left++, right--) { + if (string.charAt(left) != string.charAt(right)) return false; + } + return true; + } +} From 3e2e46d9d6a415a1d094284daea3f6cdad8ff027 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 10 Aug 2021 14:15:29 +0200 Subject: [PATCH 172/947] solves baseball game --- README.md | 2 +- python/baseball_game.py | 16 ++++++++++++++++ src/BaseballGame.java | 28 ++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 python/baseball_game.py create mode 100644 src/BaseballGame.java diff --git a/README.md b/README.md index 38e6ca2..be27d93 100644 --- a/README.md +++ b/README.md @@ -176,7 +176,7 @@ | 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) | | +| 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) | | | 690 | [Employee Importance](https://leetcode.com/problems/employee-importance) | | diff --git a/python/baseball_game.py b/python/baseball_game.py new file mode 100644 index 0000000..2b048ea --- /dev/null +++ b/python/baseball_game.py @@ -0,0 +1,16 @@ +from typing import List +from collections import deque + +class Solution: + def calPoints(self, ops: List[str]) -> int: + items = deque() + for operation in ops: + if operation == '+': + items.append(items[len(items) - 1] + items[len(items) - 2]) + elif operation == 'D': + items.append(items[len(items) - 1] * 2) + elif operation == 'C': + items.pop() + else: + items.append(int(operation)) + return sum(items) diff --git a/src/BaseballGame.java b/src/BaseballGame.java new file mode 100644 index 0000000..f5a7209 --- /dev/null +++ b/src/BaseballGame.java @@ -0,0 +1,28 @@ +import java.util.LinkedList; +import java.util.List; + +public class BaseballGame { + public int calPoints(String[] ops) { + List queue = new LinkedList<>(); + for (String operation : ops) { + if (operation.equals("+")) { + queue.add(queue.get(queue.size() - 1) + queue.get(queue.size() - 2)); + } else if (operation.equals("D")) { + queue.add(queue.get(queue.size() - 1) * 2); + } else if (operation.equals("C")) { + queue.remove(queue.size() - 1); + } else { + queue.add(Integer.valueOf(operation)); + } + } + return sum(queue); + } + + private int sum(List list) { + int sum = 0; + for (int element : list) { + sum += element; + } + return sum; + } +} From c4321ef2f9e2954c336587bf7c4e1196a18d7ff9 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 17 Nov 2021 23:54:31 +0100 Subject: [PATCH 173/947] Updates second minimum node in binary tree --- src/SecondMinimumNodeInBinaryTree.java | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/SecondMinimumNodeInBinaryTree.java b/src/SecondMinimumNodeInBinaryTree.java index b97b04d..6aa57bf 100644 --- a/src/SecondMinimumNodeInBinaryTree.java +++ b/src/SecondMinimumNodeInBinaryTree.java @@ -7,7 +7,7 @@ public class SecondMinimumNodeInBinaryTree { public int findSecondMinimumValue(TreeNode root) { Set elements = treeToSet(root); if (elements.size() < 2) return -1; - Queue queue = setToMinHeap(elements); + Queue queue = new PriorityQueue<>(elements); queue.poll(); return queue.peek(); } @@ -24,12 +24,4 @@ private static void addTreeNodesToSet(TreeNode root, Set set) { addTreeNodesToSet(root.left, set); addTreeNodesToSet(root.right, set); } - - private static Queue setToMinHeap(Set elements) { - Queue queue = new PriorityQueue<>(); - for (int element : elements) { - queue.add(element); - } - return queue; - } } From 7e51b4f7c9108b95409fed46877c2143e2b95e42 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 19 Nov 2021 17:14:32 +0100 Subject: [PATCH 174/947] adds link to cp in readme --- README.md | 1 + src/RepeatedStringMatch.java | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 src/RepeatedStringMatch.java diff --git a/README.md b/README.md index be27d93..f5dd101 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ ![problems-solved-java](https://img.shields.io/badge/Java-143/1571-1abc9c.svg) ![problems-solved-python](https://img.shields.io/badge/Python-143/1571-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 diff --git a/src/RepeatedStringMatch.java b/src/RepeatedStringMatch.java new file mode 100644 index 0000000..53b7dc5 --- /dev/null +++ b/src/RepeatedStringMatch.java @@ -0,0 +1,36 @@ +public class RepeatedStringMatch { + public int repeatedStringMatch(String a, String b) { + Pair result = canBeRepeatedForSubstring(a, b); + if (!result.canBeRepeated) return -1; + return (int) Math.ceil(1 + (double) (a.length() + result.startIndex - b.length()) / b.length()); + } + + private Pair canBeRepeatedForSubstring(String a, String b) { + boolean checking = false; + char firstChar = a.charAt(0); + int startIndex; + for (int j = 0 ; j < b.length() ; j++) { + if (firstChar == b.charAt(j)) { + int i = 0; + startIndex = j; + for ( ; i < a.length() ; i++, j = (j + 1) % b.length()) { + if (a.charAt(i) != b.charAt(j)) { + break; + } + } + if (i == a.length()) return new Pair(startIndex, true); + } + } + return new Pair(0, false); + } + + private static class Pair { + private final int startIndex; + private final boolean canBeRepeated; + + Pair(final int startIndex, final boolean canBeRepeated) { + this.startIndex = startIndex; + this.canBeRepeated = canBeRepeated; + } + } +} From 5287d6a34c7a4de1e0689df0334527ab781f6a4c Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 22 Nov 2021 00:34:45 +0100 Subject: [PATCH 175/947] solves ranges summary --- README.md | 7 ++++--- python/summary_ranges.py | 18 ++++++++++++++++++ src/RobotReturnToOrigin.java | 8 ++++---- src/SummaryRanges.java | 23 +++++++++++++++++++++++ src/TwoSumIVInputIsABST.java | 12 ------------ 5 files changed, 49 insertions(+), 19 deletions(-) create mode 100644 python/summary_ranges.py create mode 100644 src/SummaryRanges.java diff --git a/README.md b/README.md index f5dd101..9a91ea5 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-143/1571-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-143/1571-1abc9c.svg) -![problems-solved-python](https://img.shields.io/badge/Python-143/1571-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-161/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-161/2081-1abc9c.svg) +![problems-solved-python](https://img.shields.io/badge/Python-161/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) @@ -68,6 +68,7 @@ | 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) | | 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) | +| 226 | [Summary Ranges](https://leetcode.com/problems/summary-ranges/) | [![Java](assets/java.png)](src/SummaryRanges.java) [![Python](assets/python.png)](python/summary_ranges.py) | | 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) | diff --git a/python/summary_ranges.py b/python/summary_ranges.py new file mode 100644 index 0000000..9adb1c9 --- /dev/null +++ b/python/summary_ranges.py @@ -0,0 +1,18 @@ +from typing import List + + +class Solution: + def getRangeString(self, start: int, end: int) -> str: + return f'{start}' if start == end else f'{start}->{end}' + + def summaryRanges(self, array: List[int]) -> List[str]: + if len(array) == 0: return [] + result = [] + startIndex, index = 0, 1 + while index < len(array): + if array[index] > array[startIndex] + (index - startIndex): + result.append(self.getRangeString(array[startIndex], array[index - 1])) + startIndex = index + index += 1 + result.append(self.getRangeString(array[startIndex], array[len(array) - 1])) + return result diff --git a/src/RobotReturnToOrigin.java b/src/RobotReturnToOrigin.java index 1a703b2..5c8aecf 100644 --- a/src/RobotReturnToOrigin.java +++ b/src/RobotReturnToOrigin.java @@ -3,10 +3,10 @@ public boolean judgeCircle(String moves) { int vertical = 0, horizontal = 0; for (int index = 0 ; index < moves.length() ; index++) { switch (moves.charAt(index)) { - case 'U' -> vertical++; - case 'R' -> horizontal++; - case 'D' -> vertical--; - case 'L' -> horizontal--; + case 'U': vertical++; break; + case 'R': horizontal++; break; + case 'D': vertical--; break; + case 'L': horizontal--; break; } } return vertical == 0 && horizontal == 0; diff --git a/src/SummaryRanges.java b/src/SummaryRanges.java new file mode 100644 index 0000000..b643e4c --- /dev/null +++ b/src/SummaryRanges.java @@ -0,0 +1,23 @@ +import java.util.ArrayList; +import java.util.List; + +public class SummaryRanges { + + private String getRangeString(int start, int end) { + return end == start ? start + "" : start + "->" + end; + } + + public List summaryRanges(int[] array) { + if (array.length == 0) return new ArrayList<>(); + List result = new ArrayList<>(); + int startIndex = 0; + for (int index = 1 ; index < array.length ; index++) { + if (array[index] > array[startIndex] + (index - startIndex)) { + result.add(getRangeString(array[startIndex], array[index - 1])); + startIndex = index; + } + } + result.add(getRangeString(array[startIndex], array[array.length - 1])); + return result; + } +} diff --git a/src/TwoSumIVInputIsABST.java b/src/TwoSumIVInputIsABST.java index 8a5b144..c3c7875 100644 --- a/src/TwoSumIVInputIsABST.java +++ b/src/TwoSumIVInputIsABST.java @@ -1,18 +1,6 @@ import java.util.HashSet; import java.util.Set; -class TreeNode { - int val; - TreeNode left; - TreeNode right; - TreeNode() {} - TreeNode(int val) { this.val = val; } - TreeNode(int val, TreeNode left, TreeNode right) { - this.val = val; - this.left = left; - this.right = right; - } -} public class TwoSumIVInputIsABST { Set elements = new HashSet<>(); From 16ef2d05d76ec53d142247ae04dc1cc1e7e1e0ed Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 22 Nov 2021 15:29:59 +0100 Subject: [PATCH 176/947] solves counting bits --- README.md | 7 ++++--- python/counting_bits.py | 15 +++++++++++++++ src/CountingBits.java | 12 ++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 python/counting_bits.py create mode 100644 src/CountingBits.java diff --git a/README.md b/README.md index 9a91ea5..7d0b864 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-161/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-161/2081-1abc9c.svg) -![problems-solved-python](https://img.shields.io/badge/Python-161/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-162/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-162/2081-1abc9c.svg) +![problems-solved-python](https://img.shields.io/badge/Python-162/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) @@ -94,6 +94,7 @@ | 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) | | 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) | | 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) | +| 326 | [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) | | | 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) | | 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) | diff --git a/python/counting_bits.py b/python/counting_bits.py new file mode 100644 index 0000000..25add66 --- /dev/null +++ b/python/counting_bits.py @@ -0,0 +1,15 @@ +from typing import List + + +class Solution: + def countBits(self, n: int) -> List[int]: + result = [0] * (n + 1) + if len(result) > 1: result[1] = 1 + i, k = 0, 2 + while k < len(result): + i = 0 + while i < k and i + k < len(result): + result[i + k] = 1 + result[i] + i += 1 + k *= 2 + return result diff --git a/src/CountingBits.java b/src/CountingBits.java new file mode 100644 index 0000000..b2c7825 --- /dev/null +++ b/src/CountingBits.java @@ -0,0 +1,12 @@ +public class CountingBits { + public static int[] countBits(int n) { + int[] result = new int[n + 1]; + if (result.length > 1) result[1] = 1; + for (int k = 2 ; k < result.length ; k *= 2) { + for (int i = 0 ; i < k && i + k < result.length; i++) { + result[k + i] = 1 + result[i]; + } + } + return result; + } +} From 797ac30e1e9102afb20bbf77f9f02837024d82b1 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 22 Nov 2021 18:53:00 +0100 Subject: [PATCH 177/947] solves teemo attacking --- README.md | 7 ++++--- python/teemo_attacking.py | 15 +++++++++++++++ src/TeemoAttacking.java | 14 ++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 python/teemo_attacking.py create mode 100644 src/TeemoAttacking.java diff --git a/README.md b/README.md index 7d0b864..3428de9 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-162/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-162/2081-1abc9c.svg) -![problems-solved-python](https://img.shields.io/badge/Python-162/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-163/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-163/2081-1abc9c.svg) +![problems-solved-python](https://img.shields.io/badge/Python-163/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) @@ -133,6 +133,7 @@ | 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) | diff --git a/python/teemo_attacking.py b/python/teemo_attacking.py new file mode 100644 index 0000000..bfdecf5 --- /dev/null +++ b/python/teemo_attacking.py @@ -0,0 +1,15 @@ +from typing import List + + +class Solution: + def findPoisonedDuration(self, timeSeries: List[int], duration: int) -> int: + poisonDuration = 0 + index, current = 0, timeSeries[0] - 1 + while index < len(timeSeries): + poisonDuration += duration - (current - timeSeries[index] + 1) + current = max( + timeSeries[index] + duration - 1, + timeSeries[index + 1] - 1 if index < len(timeSeries) - 1 else 0 + ) + index += 1 + return poisonDuration diff --git a/src/TeemoAttacking.java b/src/TeemoAttacking.java new file mode 100644 index 0000000..88322c4 --- /dev/null +++ b/src/TeemoAttacking.java @@ -0,0 +1,14 @@ +public class TeemoAttacking { + public static void main(String[] args) { + System.out.println(findPoisonedDuration(new int[] {1, 2}, 2)); + } + + public static int findPoisonedDuration(int[] timeSeries, int duration) { + int poisonDuration = 0; + for (int i = 0, current = timeSeries[0] - 1 ; i < timeSeries.length; i++) { + poisonDuration += duration - Math.max(0, Math.max(current, timeSeries[i] - 1) - timeSeries[i] + 1); + current = timeSeries[i] + duration - 1; + } + return poisonDuration; + } +} From e900efcec14a13e19983b02101a2ee43af6821e2 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 22 Nov 2021 19:02:22 +0100 Subject: [PATCH 178/947] solves binary tree inorder traversal --- README.md | 1 + python/binary_tree_inorder_traversal.py | 23 +++++++++++++++++++++++ src/BinaryTreeInorderTraversal.java | 17 +++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 python/binary_tree_inorder_traversal.py create mode 100644 src/BinaryTreeInorderTraversal.java diff --git a/README.md b/README.md index 3428de9..9dcfc78 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ | 70 | [Climbing Stairs](https://leetcode.com/problems/climbing-stairs) | [![Java](assets/java.png)](src/ClimbingStairs.java) [![Python](assets/python.png)](python/climbing_stairs.py) | | 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) | | 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) | +| 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) | | 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) | | 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) | diff --git a/python/binary_tree_inorder_traversal.py b/python/binary_tree_inorder_traversal.py new file mode 100644 index 0000000..4c18454 --- /dev/null +++ b/python/binary_tree_inorder_traversal.py @@ -0,0 +1,23 @@ +from typing import Optional, List + + +# Definition for a binary tree node. +class TreeNode: + def __init__(self, val=0, left=None, right=None): + self.val = val + self.left = left + self.right = right + + + +class Solution: + def _inorder_traversal(self, root: TreeNode, list: List[int]) -> None: + if root == None: return + self._inorder_traversal(root.left, list) + list.append(root.val) + self._inorder_traversal(root.right, list) + + def inorderTraversal(self, root: Optional[TreeNode]) -> List[int]: + result = [] + self._inorder_traversal(root, result) + return result diff --git a/src/BinaryTreeInorderTraversal.java b/src/BinaryTreeInorderTraversal.java new file mode 100644 index 0000000..2b30d4f --- /dev/null +++ b/src/BinaryTreeInorderTraversal.java @@ -0,0 +1,17 @@ +import java.util.ArrayList; +import java.util.List; + +public class BinaryTreeInorderTraversal { + public List inorderTraversal(TreeNode root) { + List result = new ArrayList<>(); + inorderTraversal(root, result); + return result; + } + + private void inorderTraversal(TreeNode root, List list) { + if (root == null) return; + inorderTraversal(root.left, list); + list.add(root.val); + inorderTraversal(root.right, list); + } +} From 4b2e6efd274c76fa2bb1504b47c43a7c6f3ecf98 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 22 Nov 2021 19:08:18 +0100 Subject: [PATCH 179/947] solves pre order traversal in binary tree --- README.md | 7 ++++--- python/binary_tree_preorder_traversal.py | 22 ++++++++++++++++++++++ src/BinaryTreePreOrderTraversal.java | 17 +++++++++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 python/binary_tree_preorder_traversal.py create mode 100644 src/BinaryTreePreOrderTraversal.java diff --git a/README.md b/README.md index 9dcfc78..e79cc67 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-163/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-163/2081-1abc9c.svg) -![problems-solved-python](https://img.shields.io/badge/Python-163/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-165/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-165/2081-1abc9c.svg) +![problems-solved-python](https://img.shields.io/badge/Python-165/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) @@ -47,6 +47,7 @@ | 125 | [Valid Palindrome](https://leetcode.com/problems/valid-palindrome) | [![Java](assets/java.png)](src/ValidPalindrome.java) [![Python](assets/python.png)](python/valid_palindrome.py) | | 136 | [Single Number](https://leetcode.com/problems/single-number) | [![Java](assets/java.png)](src/SingleNumber.java) [![Python](assets/python.png)](python/single_number.py) | | 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) | +| 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) | | 155 | [Min Stack](https://leetcode.com/problems/min-stack) | [![Java](assets/java.png)](src/MinStack.java) [![Python](assets/python.png)](python/min_stack.py) | | 157 | [Read N Characters Given Read4](https://leetcode.com/problems/read-n-characters-given-read4) | | | 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) | diff --git a/python/binary_tree_preorder_traversal.py b/python/binary_tree_preorder_traversal.py new file mode 100644 index 0000000..9db1c32 --- /dev/null +++ b/python/binary_tree_preorder_traversal.py @@ -0,0 +1,22 @@ +# Definition for a binary tree node. +from typing import Optional, List + + +class TreeNode: + def __init__(self, val=0, left=None, right=None): + self.val = val + self.left = left + self.right = right + + +class Solution: + def _preorder_traversal(self, root: Optional[TreeNode], list: List[int]) -> None: + if root is None: return + list.append(root.val) + self._preorder_traversal(root.left, list) + self._preorder_traversal(root.right, list) + + def preorderTraversal(self, root: Optional[TreeNode]) -> List[int]: + result = [] + self._preorder_traversal(root, result) + return result diff --git a/src/BinaryTreePreOrderTraversal.java b/src/BinaryTreePreOrderTraversal.java new file mode 100644 index 0000000..232f7cd --- /dev/null +++ b/src/BinaryTreePreOrderTraversal.java @@ -0,0 +1,17 @@ +import java.util.ArrayList; +import java.util.List; + +public class BinaryTreePreOrderTraversal { + public List preorderTraversal(TreeNode root) { + List result = new ArrayList<>(); + preorderTraversal(root, result); + return result; + } + + private void preorderTraversal(TreeNode root, List list) { + if (root == null) return; + list.add(root.val); + preorderTraversal(root.left, list); + preorderTraversal(root.right, list); + } +} From d7da0acae02bf7ac6d29a2bd670c2ff1da602068 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 22 Nov 2021 19:12:55 +0100 Subject: [PATCH 180/947] solves binary tree post order traversal --- README.md | 3 ++- python/binary_tree_postorder_traversal.py | 22 ++++++++++++++++++++++ src/BinaryTreePostorderTraversal.java | 17 +++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 python/binary_tree_postorder_traversal.py create mode 100644 src/BinaryTreePostorderTraversal.java diff --git a/README.md b/README.md index e79cc67..afbacfd 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,8 @@ | 125 | [Valid Palindrome](https://leetcode.com/problems/valid-palindrome) | [![Java](assets/java.png)](src/ValidPalindrome.java) [![Python](assets/python.png)](python/valid_palindrome.py) | | 136 | [Single Number](https://leetcode.com/problems/single-number) | [![Java](assets/java.png)](src/SingleNumber.java) [![Python](assets/python.png)](python/single_number.py) | | 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) | -| 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) | +| 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) | | 155 | [Min Stack](https://leetcode.com/problems/min-stack) | [![Java](assets/java.png)](src/MinStack.java) [![Python](assets/python.png)](python/min_stack.py) | | 157 | [Read N Characters Given Read4](https://leetcode.com/problems/read-n-characters-given-read4) | | | 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) | diff --git a/python/binary_tree_postorder_traversal.py b/python/binary_tree_postorder_traversal.py new file mode 100644 index 0000000..2eb5392 --- /dev/null +++ b/python/binary_tree_postorder_traversal.py @@ -0,0 +1,22 @@ +# Definition for a binary tree node. +from typing import Optional, List + + +class TreeNode: + def __init__(self, val=0, left=None, right=None): + self.val = val + self.left = left + self.right = right + + +class Solution: + def _postorder_traversal(self, root: Optional[TreeNode], list: List[int]) -> None: + if root is None: return + self._postorder_traversal(root.left, list) + self._postorder_traversal(root.right, list) + list.append(root.val) + + def postorderTraversal(self, root: Optional[TreeNode]) -> List[int]: + result = [] + self._postorder_traversal(root, result) + return result diff --git a/src/BinaryTreePostorderTraversal.java b/src/BinaryTreePostorderTraversal.java new file mode 100644 index 0000000..5672d1e --- /dev/null +++ b/src/BinaryTreePostorderTraversal.java @@ -0,0 +1,17 @@ +import java.util.ArrayList; +import java.util.List; + +public class BinaryTreePostorderTraversal { + public List postorderTraversal(TreeNode root) { + List result = new ArrayList<>(); + postorderTraversal(root, result); + return result; + } + + private void postorderTraversal(TreeNode root, List list) { + if (root == null) return; + postorderTraversal(root.left, list); + postorderTraversal(root.right, list); + list.add(root.val); + } +} From 3a43d0b9b5c09b0a93804b6c20cffd51b9e54a36 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 22 Nov 2021 19:25:51 +0100 Subject: [PATCH 181/947] solves binary numbr with alternatng bits --- README.md | 8 ++++---- python/binary_number_with_alternating_bits.py | 9 +++++++++ src/BinaryNumberWithAlternatingBits.java | 12 ++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 python/binary_number_with_alternating_bits.py create mode 100644 src/BinaryNumberWithAlternatingBits.java diff --git a/README.md b/README.md index afbacfd..d5b2342 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-165/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-165/2081-1abc9c.svg) -![problems-solved-python](https://img.shields.io/badge/Python-165/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-167/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-167/2081-1abc9c.svg) +![problems-solved-python](https://img.shields.io/badge/Python-167/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) @@ -187,7 +187,7 @@ | 686 | [Repeated String Match](https://leetcode.com/problems/repeated-string-match) | | | 687 | [Longest Univalue Path](https://leetcode.com/problems/longest-univalue-path) | | | 690 | [Employee Importance](https://leetcode.com/problems/employee-importance) | | -| 693 | [Binary Number with Alternating Bits](https://leetcode.com/problems/binary-number-with-alternating-bits) | | +| 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) | | | 697 | [Degree of an Array](https://leetcode.com/problems/degree-of-an-array) | | | 700 | [Search in a Binary Search Tree](https://leetcode.com/problems/search-in-a-binary-search-tree) | | diff --git a/python/binary_number_with_alternating_bits.py b/python/binary_number_with_alternating_bits.py new file mode 100644 index 0000000..0178b7d --- /dev/null +++ b/python/binary_number_with_alternating_bits.py @@ -0,0 +1,9 @@ +class Solution: + def hasAlternatingBits(self, n: int) -> bool: + lastDigit = n % 2 + while n > 0: + n //= 2 + current = n % 2 + if lastDigit == current: return False + lastDigit = current + return True diff --git a/src/BinaryNumberWithAlternatingBits.java b/src/BinaryNumberWithAlternatingBits.java new file mode 100644 index 0000000..e1098c6 --- /dev/null +++ b/src/BinaryNumberWithAlternatingBits.java @@ -0,0 +1,12 @@ +public class BinaryNumberWithAlternatingBits { + public boolean hasAlternatingBits(int number) { + int lastDigit = number % 2, current; + while (number > 0) { + number >>= 1; + current = number % 2; + if (lastDigit == current) return false; + lastDigit = current; + } + return true; + } +} From 654791c4089fbbb8f59a66943dd6210b3eb7b5be Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Tue, 23 Nov 2021 00:17:01 +0100 Subject: [PATCH 182/947] solves binary substing --- README.md | 8 ++++---- python/count_binary_substrings.py | 11 +++++++++++ src/CountBinarySubstrings.java | 13 +++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 python/count_binary_substrings.py create mode 100644 src/CountBinarySubstrings.java diff --git a/README.md b/README.md index d5b2342..0fe1bf2 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-167/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-167/2081-1abc9c.svg) -![problems-solved-python](https://img.shields.io/badge/Python-167/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-168/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-168/2081-1abc9c.svg) +![problems-solved-python](https://img.shields.io/badge/Python-168/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) @@ -188,7 +188,7 @@ | 687 | [Longest Univalue Path](https://leetcode.com/problems/longest-univalue-path) | | | 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) | | +| 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) | | | 700 | [Search in a Binary Search Tree](https://leetcode.com/problems/search-in-a-binary-search-tree) | | | 703 | [Kth Largest Element in a Stream](https://leetcode.com/problems/kth-largest-element-in-a-stream) | | diff --git a/python/count_binary_substrings.py b/python/count_binary_substrings.py new file mode 100644 index 0000000..d0b07bb --- /dev/null +++ b/python/count_binary_substrings.py @@ -0,0 +1,11 @@ +class Solution: + def countBinarySubstrings(self, s: str) -> int: + binarySubstrings, previous, current = 0, 0, 1 + index = 1 + while index < len(s): + if s[index - 1] != s[index]: + binarySubstrings += min(previous, current) + previous, current = current, 1 + else: current += 1 + index += 1 + return binarySubstrings + min(previous, current) diff --git a/src/CountBinarySubstrings.java b/src/CountBinarySubstrings.java new file mode 100644 index 0000000..3934446 --- /dev/null +++ b/src/CountBinarySubstrings.java @@ -0,0 +1,13 @@ +public class CountBinarySubstrings { + public int countBinarySubstrings(String string) { + int binarySubStrings = 0, prev = 0, current = 1; + for (int index = 1 ; index < string.length() ; index++) { + if (string.charAt(index - 1) != string.charAt(index)) { + binarySubStrings += Math.min(prev, current); + prev = current; + current = 1; + } else current++; + } + return binarySubStrings + Math.min(prev, current); + } +} From 51d921caad99a40a9374035ebbdbc8d19f2645b2 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Tue, 23 Nov 2021 00:35:10 +0100 Subject: [PATCH 183/947] solves degree of array --- README.md | 8 +++---- python/degree_of_an_array.py | 25 ++++++++++++++++++++ src/DegreeOfAnArray.java | 45 ++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 python/degree_of_an_array.py create mode 100644 src/DegreeOfAnArray.java diff --git a/README.md b/README.md index 0fe1bf2..154ce86 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-168/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-168/2081-1abc9c.svg) -![problems-solved-python](https://img.shields.io/badge/Python-168/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-169/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-169/2081-1abc9c.svg) +![problems-solved-python](https://img.shields.io/badge/Python-169/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) @@ -189,7 +189,7 @@ | 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) | | +| 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) | | | 703 | [Kth Largest Element in a Stream](https://leetcode.com/problems/kth-largest-element-in-a-stream) | | | 704 | [Binary Search](https://leetcode.com/problems/binary-search) | | diff --git a/python/degree_of_an_array.py b/python/degree_of_an_array.py new file mode 100644 index 0000000..88b7b48 --- /dev/null +++ b/python/degree_of_an_array.py @@ -0,0 +1,25 @@ +from collections import Counter +from typing import List, Dict + + +class Solution: + def getLeftPosition(self, array: List[int]) -> Dict[int, int]: + positions = {} + for index, element in enumerate(array): + if element not in positions: + positions[element] = index + return positions + + def getRightPosition(self, array: List[int]) -> Dict[int, int]: + return {number : index for index, number in enumerate(array)} + + def findShortestSubArray(self, numbers: List[int]) -> int: + frequencies = Counter(numbers) + leftMost = self.getLeftPosition(numbers) + rightMost = self.getRightPosition(numbers) + maxFrequency = max(frequencies.values()) + result = float('inf') + for number, frequency in frequencies.items(): + if frequency == maxFrequency: + result = min(result, rightMost[number] - leftMost[number] + 1) + return result diff --git a/src/DegreeOfAnArray.java b/src/DegreeOfAnArray.java new file mode 100644 index 0000000..0e62f4d --- /dev/null +++ b/src/DegreeOfAnArray.java @@ -0,0 +1,45 @@ +import java.util.HashMap; +import java.util.Map; + +public class DegreeOfAnArray { + public int findShortestSubArray(int[] numbers) { + Map frequencies = getFrequencies(numbers); + Map leftMostPosition = getLeftMostPositionOf(numbers); + Map rightMostPosition = getRightMostPositionOf(numbers); + int maxFrequency = frequencies.values().stream().max(Integer::compareTo).get(); + int result = Integer.MAX_VALUE, element = 0; + for (Map.Entry entry : frequencies.entrySet()) { + if (entry.getValue() == maxFrequency) { + element = entry.getKey(); + result = Math.min(result, rightMostPosition.get(element) - leftMostPosition.get(element) + 1); + } + } + return result; + } + + private Map getFrequencies(int[] array) { + Map result = new HashMap<>(); + for (int element : array) { + result.put(element, result.getOrDefault(element, 0) + 1); + } + return result; + } + + private Map getLeftMostPositionOf(int[] array) { + Map result = new HashMap<>(); + for (int index = 0 ; index < array.length ; index++) { + if (!result.containsKey(array[index])) { + result.put(array[index], index); + } + } + return result; + } + + private Map getRightMostPositionOf(int[] array) { + Map result = new HashMap<>(); + for (int index = 0 ; index < array.length ; index++) { + result.put(array[index], index); + } + return result; + } +} From 5f053ae87c31a853f22fa12fbb0359468299e319 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Tue, 23 Nov 2021 00:41:07 +0100 Subject: [PATCH 184/947] solves search in bnary search tree --- README.md | 8 ++++---- python/search_in_binary_search_tree.py | 15 +++++++++++++++ src/SearchInBinarySearchTree.java | 6 ++++++ 3 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 python/search_in_binary_search_tree.py create mode 100644 src/SearchInBinarySearchTree.java diff --git a/README.md b/README.md index 154ce86..a5e397e 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-169/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-169/2081-1abc9c.svg) -![problems-solved-python](https://img.shields.io/badge/Python-169/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-170/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-170/2081-1abc9c.svg) +![problems-solved-python](https://img.shields.io/badge/Python-170/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) @@ -190,7 +190,7 @@ | 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) | | +| 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) | | | 704 | [Binary Search](https://leetcode.com/problems/binary-search) | | | 705 | [Design HashSet](https://leetcode.com/problems/design-hashset) | | diff --git a/python/search_in_binary_search_tree.py b/python/search_in_binary_search_tree.py new file mode 100644 index 0000000..288ba8f --- /dev/null +++ b/python/search_in_binary_search_tree.py @@ -0,0 +1,15 @@ +# Definition for a binary tree node. +from typing import Optional + + +class TreeNode: + def __init__(self, val=0, left=None, right=None): + self.val = val + self.left = left + self.right = right + + +class Solution: + def searchBST(self, root: Optional[TreeNode], val: int) -> Optional[TreeNode]: + if root is None or root.val == val: return root + return self.searchBST(root.right, val) if root.val < val else self.searchBST(root.left, val) diff --git a/src/SearchInBinarySearchTree.java b/src/SearchInBinarySearchTree.java new file mode 100644 index 0000000..c36517a --- /dev/null +++ b/src/SearchInBinarySearchTree.java @@ -0,0 +1,6 @@ +public class SearchInBinarySearchTree { + public TreeNode searchBST(TreeNode root, int val) { + if (root == null || root.val == val) return root; + return root.val < val ? searchBST(root.right, val) : searchBST(root.left, val); + } +} From 043e29b1336f86f24e5e1e84eea3760b341500f0 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 23 Nov 2021 15:02:42 +0100 Subject: [PATCH 185/947] solves kth largets element in stream --- README.md | 8 +++---- python/k_th_largest_element_in_a_stream.py | 18 ++++++++++++++ src/KthLargestElementInAStream.java | 28 ++++++++++++++++++++++ 3 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 python/k_th_largest_element_in_a_stream.py create mode 100644 src/KthLargestElementInAStream.java diff --git a/README.md b/README.md index a5e397e..3b4b1e7 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-170/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-170/2081-1abc9c.svg) -![problems-solved-python](https://img.shields.io/badge/Python-170/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-171/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-171/2081-1abc9c.svg) +![problems-solved-python](https://img.shields.io/badge/Python-171/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) @@ -191,7 +191,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) | -| 703 | [Kth Largest Element in a Stream](https://leetcode.com/problems/kth-largest-element-in-a-stream) | | +| 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) | | | 705 | [Design HashSet](https://leetcode.com/problems/design-hashset) | | | 706 | [Design HashMap](https://leetcode.com/problems/design-hashmap) | | diff --git a/python/k_th_largest_element_in_a_stream.py b/python/k_th_largest_element_in_a_stream.py new file mode 100644 index 0000000..a0a3828 --- /dev/null +++ b/python/k_th_largest_element_in_a_stream.py @@ -0,0 +1,18 @@ +import heapq +from typing import List + + +class KthLargest: + def __init__(self, k: int, nums: List[int]): + self.heap = [] + self.heap_size = k + for element in nums: + heapq.heappush(self.heap, element) + while len(self.heap) > self.heap_size: + heapq.heappop(self.heap) + + def add(self, val: int) -> int: + heapq.heappush(self.heap, val) + while len(self.heap) > self.heap_size: + heapq.heappop(self.heap) + return self.heap[0] diff --git a/src/KthLargestElementInAStream.java b/src/KthLargestElementInAStream.java new file mode 100644 index 0000000..dbe77bb --- /dev/null +++ b/src/KthLargestElementInAStream.java @@ -0,0 +1,28 @@ +import java.util.PriorityQueue; +import java.util.Queue; + +public class KthLargestElementInAStream { + class KthLargest { + + private final Queue heap = new PriorityQueue<>(); + private final int heapSize; + + public KthLargest(int k, int[] nums) { + heapSize = k; + for (int element : nums) { + heap.add(element); + } + while (heap.size() > heapSize) { + heap.poll(); + } + } + + public int add(int val) { + heap.add(val); + while (heap.size() > heapSize) { + heap.poll(); + } + return heap.peek(); + } + } +} From fdcfb0770610c3b21076892647e9712fecc64837 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 23 Nov 2021 15:18:40 +0100 Subject: [PATCH 186/947] solves binary search --- README.md | 8 ++++---- python/binary_search.py | 12 ++++++++++++ src/BinarySearch.java | 13 +++++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 python/binary_search.py create mode 100644 src/BinarySearch.java diff --git a/README.md b/README.md index 3b4b1e7..fd9e7f5 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-171/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-171/2081-1abc9c.svg) -![problems-solved-python](https://img.shields.io/badge/Python-171/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-172/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-172/2081-1abc9c.svg) +![problems-solved-python](https://img.shields.io/badge/Python-172/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) @@ -192,7 +192,7 @@ | 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) | | +| 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) | | | 706 | [Design HashMap](https://leetcode.com/problems/design-hashmap) | | | 709 | [To Lower Case](https://leetcode.com/problems/to-lower-case) | | diff --git a/python/binary_search.py b/python/binary_search.py new file mode 100644 index 0000000..6596f53 --- /dev/null +++ b/python/binary_search.py @@ -0,0 +1,12 @@ +from typing import List + + +class Solution: + def search(self, array: List[int], target: int) -> int: + left, right = 0, len(array) - 1 + while left <= right: + middle = left + (right - left) // 2 + if array[middle] == target: return middle + elif array[middle] > target: right = middle - 1 + else: left = middle + 1 + return -1 diff --git a/src/BinarySearch.java b/src/BinarySearch.java new file mode 100644 index 0000000..8ce598e --- /dev/null +++ b/src/BinarySearch.java @@ -0,0 +1,13 @@ +public class BinarySearch { + public int search(int[] array, int val) { + int left = 0, right = array.length - 1, middle; + while (left <= right) { + middle = left + (right - left) / 2; + if (array[middle] == val) return middle; + else if (array[middle] > val) right = middle - 1; + else left = middle + 1; + } + + return -1; + } +} From 413303106a0649d1707e995b8feaac7319766322 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 23 Nov 2021 16:05:13 +0100 Subject: [PATCH 187/947] solves design hash set --- README.md | 8 ++--- python/design_hash_set.py | 32 ++++++++++++++++++++ src/DesignHashSet.java | 61 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 python/design_hash_set.py create mode 100644 src/DesignHashSet.java diff --git a/README.md b/README.md index fd9e7f5..43e9490 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-172/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-172/2081-1abc9c.svg) -![problems-solved-python](https://img.shields.io/badge/Python-172/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-173/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-173/2081-1abc9c.svg) +![problems-solved-python](https://img.shields.io/badge/Python-173/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) @@ -193,7 +193,7 @@ | 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) | | +| 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) | | | 709 | [To Lower Case](https://leetcode.com/problems/to-lower-case) | | | 716 | [Max Stack](https://leetcode.com/problems/max-stack) | | diff --git a/python/design_hash_set.py b/python/design_hash_set.py new file mode 100644 index 0000000..452bfb1 --- /dev/null +++ b/python/design_hash_set.py @@ -0,0 +1,32 @@ +class Bucket: + def __init__(self): + self.list = [] + + def contains(self, element: int) -> bool: + return element in self.list + + def add(self, element: int) -> None: + self.list.append(element) + + def remove(self, element: int) -> None: + if self.contains(element): + self.list.remove(element) + + +class MyHashSet: + def __init__(self): + self._initial_size = 100 + self.size = 0 + self.buckets = [Bucket() for _ in range(self._initial_size)] + + def add(self, key: int) -> None: + hashCode = key % len(self.buckets) + if not self.buckets[hashCode].contains(key): + self.buckets[hashCode].add(key) + self.size += 1 + + def remove(self, key: int) -> None: + self.buckets[key % len(self.buckets)].remove(key) + + def contains(self, key: int) -> bool: + return self.buckets[key % len(self.buckets)].contains(key) diff --git a/src/DesignHashSet.java b/src/DesignHashSet.java new file mode 100644 index 0000000..c44c94a --- /dev/null +++ b/src/DesignHashSet.java @@ -0,0 +1,61 @@ +import java.util.LinkedList; +import java.util.Queue; + +public class DesignHashSet { + class MyHashSet { + + private static final int INITIAL_SIZE = 100; + private final Bucket[] buckets; + private int size = 0; + + public MyHashSet() { + this.buckets = new Bucket[INITIAL_SIZE]; + initializeBuckets(); + } + + public MyHashSet(int initialSize) { + this.buckets = new Bucket[initialSize]; + initializeBuckets(); + } + + public void add(int element) { + int hash = element % buckets.length; + if (!buckets[hash].contains(element)) { + buckets[hash].add(element); + this.size++; + } + } + + public void remove(int element) { + buckets[element % buckets.length].remove(element); + } + + public boolean contains(int element) { + return buckets[element % buckets.length].contains(element); + } + + private void initializeBuckets() { + for (int index = 0 ; index < buckets.length ; index++) { + buckets[index] = new Bucket(); + } + } + + private static class Bucket { + Queue list = new LinkedList<>(); + + public boolean contains(int element) { + return list.contains(element); + } + + public void add(int element) { + if (!this.contains(element)) { + list.add(element); + } + } + + public void remove(int element) { + list.remove(element); + } + } + } +} From 4344ba96e9acd9ea800c62e8e4833c2eb041ecc7 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Tue, 23 Nov 2021 21:48:58 +0100 Subject: [PATCH 188/947] solves design hash map --- README.md | 8 ++-- python/design_hash_map.py | 52 +++++++++++++++++++++++++ src/DesignHashMap.java | 81 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+), 4 deletions(-) create mode 100644 python/design_hash_map.py create mode 100644 src/DesignHashMap.java diff --git a/README.md b/README.md index 43e9490..d4c53fb 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-173/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-173/2081-1abc9c.svg) -![problems-solved-python](https://img.shields.io/badge/Python-173/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-174/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-174/2081-1abc9c.svg) +![problems-solved-python](https://img.shields.io/badge/Python-174/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) @@ -194,7 +194,7 @@ | 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) | | +| 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) | | | 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) | | diff --git a/python/design_hash_map.py b/python/design_hash_map.py new file mode 100644 index 0000000..7a2f55a --- /dev/null +++ b/python/design_hash_map.py @@ -0,0 +1,52 @@ +class Bucket: + def __init__(self): + self.list = [] + + def __str__(self): + return self.list.__str__() + + def contains(self, key: int) -> bool: + for listKey, value in self.list: + if key == listKey: + return True + return False + + def put(self, key: int, value: int) -> None: + changed = False + for index, (listKey, _) in enumerate(self.list): + if listKey == key: + self.list[index] = (key, value) + changed = True + break + if not changed: + self.list.append((key, value)) + + def remove(self, key: int) -> None: + if self.contains(key): + self.list.remove((key, self.get(key))) + + def get(self, key: int) -> int: + if self.contains(key): + for listKey, value in self.list: + if listKey == key: + return value + return -1 + + +class MyHashMap: + + def __init__(self): + self.initial_size = 100 + self.buckets = [Bucket() for _ in range(self.initial_size)] + + def _hashCode(self, number: int) -> int: + return number % len(self.buckets) + + def put(self, key: int, value: int) -> None: + self.buckets[self._hashCode(key)].put(key, value) + + def get(self, key: int) -> int: + return self.buckets[self._hashCode(key)].get(key) + + def remove(self, key: int) -> None: + self.buckets[self._hashCode(key)].remove(key) diff --git a/src/DesignHashMap.java b/src/DesignHashMap.java new file mode 100644 index 0000000..a7824b1 --- /dev/null +++ b/src/DesignHashMap.java @@ -0,0 +1,81 @@ +import java.util.LinkedList; +import java.util.Objects; +import java.util.Queue; + +public class DesignHashMap { + class MyHashMap { + + private final int initialSize = 100; + private final Bucket[] buckets = new Bucket[initialSize]; + + public MyHashMap() { + for (int index = 0 ; index < buckets.length ; index++) { + buckets[index] = new Bucket(); + } + } + + public void put(int key, int value) { + int hashCode = key % buckets.length; + buckets[hashCode].put(key, value); + } + + public int get(int key) { + return buckets[key % buckets.length].get(key); + } + + public void remove(int key) { + buckets[key % buckets.length].remove(key); + } + + private class Bucket { + Queue list = new LinkedList<>(); + + + public boolean contains(int element) { + return list.stream().anyMatch(pair -> pair.key == element); + } + + public void put(int key, int value) { + if (contains(key)) { + Pair match = list.stream().filter(pair -> pair.key == key).findFirst().get(); + match.value = value; + } else { + list.add(new Pair(key, value)); + } + } + + public int get(int key) { + return contains(key) ? list.stream().filter(pair -> pair.key == key).findFirst().get().value : -1; + } + + public void remove(int key) { + if (contains(key)) { + list.remove(new Pair(key, get(key))); + } + } + } + + private class Pair { + private final int key; + private int value; + + Pair(int key, int value) { + this.key = key; + this.value = value; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Pair pair = (Pair) o; + return key == pair.key && value == pair.value; + } + + @Override + public int hashCode() { + return Objects.hash(key, value); + } + } + } +} From 166b7da115805907e8c931993dabd4e65cd09162 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Tue, 23 Nov 2021 22:02:10 +0100 Subject: [PATCH 189/947] solves to lower case --- README.md | 8 ++++---- python/to_lower_case.py | 15 +++++++++++++++ src/DesignHashSet.java | 2 +- src/ToLowerCase.java | 25 +++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 python/to_lower_case.py create mode 100644 src/ToLowerCase.java diff --git a/README.md b/README.md index d4c53fb..b1fa959 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-174/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-174/2081-1abc9c.svg) -![problems-solved-python](https://img.shields.io/badge/Python-174/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-175/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-175/2081-1abc9c.svg) +![problems-solved-python](https://img.shields.io/badge/Python-175 /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) @@ -195,7 +195,7 @@ | 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) | | +| 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) | | | 720 | [Longest Word in Dictionary](https://leetcode.com/problems/longest-word-in-dictionary) | | diff --git a/python/to_lower_case.py b/python/to_lower_case.py new file mode 100644 index 0000000..235db06 --- /dev/null +++ b/python/to_lower_case.py @@ -0,0 +1,15 @@ +class Solution: + def isAlphabet(self, character: str) -> bool: + return self.isUpperCase(character) or self.isLowerCase(character) + + def isUpperCase(self, character: str) -> bool: + return 65 <= ord(character) <= 90 + + def isLowerCase(self, character: str) -> bool: + return 97 <= ord(character) <= 122 + + def toLowerCase(self, s: str) -> str: + result = '' + for character in s: + result += chr(ord(character) + 32) if self.isAlphabet(character) and self.isUpperCase(character) else character + return result diff --git a/src/DesignHashSet.java b/src/DesignHashSet.java index c44c94a..3642db4 100644 --- a/src/DesignHashSet.java +++ b/src/DesignHashSet.java @@ -40,7 +40,7 @@ private void initializeBuckets() { } } - private static class Bucket { + private class Bucket { Queue list = new LinkedList<>(); public boolean contains(int element) { diff --git a/src/ToLowerCase.java b/src/ToLowerCase.java new file mode 100644 index 0000000..362a083 --- /dev/null +++ b/src/ToLowerCase.java @@ -0,0 +1,25 @@ +public class ToLowerCase { + public String toLowerCase(String s) { + StringBuilder result = new StringBuilder(); + for (int index = 0 ; index < s.length() ; index++) { + result.append(toLowerCase(s.charAt(index))); + } + return result.toString(); + } + + private char toLowerCase(char character) { + return isUpperCase(character) && isAlphabet(character) ? (char) (character + 32) : character; + } + + private boolean isAlphabet(char character) { + return isUpperCase(character) || isLowerCase(character); + } + + private boolean isLowerCase(char character) { + return 97 <= character && character <= 122; + } + + private boolean isUpperCase(char character) { + return 65 <= character && character <= 90; + } +} From 4ece22c5838fc1c2160d6522b2964b9310957aed Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 24 Nov 2021 01:22:45 +0100 Subject: [PATCH 190/947] solves to lower case --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b1fa959..c1d3faa 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ![problems-solved](https://img.shields.io/badge/Problems%20Solved-175/2081-1f425f.svg) ![problems-solved-java](https://img.shields.io/badge/Java-175/2081-1abc9c.svg) -![problems-solved-python](https://img.shields.io/badge/Python-175 /2081-1abc9c.svg) +![problems-solved-python](https://img.shields.io/badge/Python-175/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) From 3f2325154dbd15407f6f83bacbcb47828e2ccdb7 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 24 Nov 2021 12:54:56 +0100 Subject: [PATCH 191/947] solves one bit and two bit array --- README.md | 8 ++++---- python/one_bit_and_two_bit_characters.py | 11 +++++++++++ src/OneBitAndTwoBitCharacters.java | 12 ++++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 python/one_bit_and_two_bit_characters.py create mode 100644 src/OneBitAndTwoBitCharacters.java diff --git a/README.md b/README.md index c1d3faa..e3ec47d 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-175/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-175/2081-1abc9c.svg) -![problems-solved-python](https://img.shields.io/badge/Python-175/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-176/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-176/2081-1abc9c.svg) +![problems-solved-python](https://img.shields.io/badge/Python-176/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) @@ -197,7 +197,7 @@ | 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) | | +| 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) | | 720 | [Longest Word in Dictionary](https://leetcode.com/problems/longest-word-in-dictionary) | | | 724 | [Find Pivot Index](https://leetcode.com/problems/find-pivot-index) | | | 728 | [Self Dividing Numbers](https://leetcode.com/problems/self-dividing-numbers) | | diff --git a/python/one_bit_and_two_bit_characters.py b/python/one_bit_and_two_bit_characters.py new file mode 100644 index 0000000..a0adf0f --- /dev/null +++ b/python/one_bit_and_two_bit_characters.py @@ -0,0 +1,11 @@ +from typing import List + + +class Solution: + def isOneBitCharacter(self, bits: List[int]) -> bool: + count = 0 + index = len(bits) - 2 + while index >= 0 and bits[index] != 0: + if bits[index] == 1: count += 1 + index -= 1 + return count % 2 == 0 diff --git a/src/OneBitAndTwoBitCharacters.java b/src/OneBitAndTwoBitCharacters.java new file mode 100644 index 0000000..d512f34 --- /dev/null +++ b/src/OneBitAndTwoBitCharacters.java @@ -0,0 +1,12 @@ +public class OneBitAndTwoBitCharacters { + public boolean isOneBitCharacter(int[] bits) { + for (int index = 0 ; index < bits.length ; index++) { + if (bits[index] == 1) { + index++; + } else if (bits[index] == 0 && index == bits.length - 1) { + return true; + } + } + return false; + } +} From 8ff3ea202bda4a29a70a8127de5e0b76fac6d89a Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 24 Nov 2021 13:02:52 +0100 Subject: [PATCH 192/947] solves find pivot index --- README.md | 2 +- python/find_pivot_index.py | 14 ++++++++++++++ src/FindPivotIndex.java | 15 +++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 python/find_pivot_index.py create mode 100644 src/FindPivotIndex.java diff --git a/README.md b/README.md index e3ec47d..f981bbb 100644 --- a/README.md +++ b/README.md @@ -199,7 +199,7 @@ | 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) | | 720 | [Longest Word in Dictionary](https://leetcode.com/problems/longest-word-in-dictionary) | | -| 724 | [Find Pivot Index](https://leetcode.com/problems/find-pivot-index) | | +| 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) | | | 733 | [Flood Fill](https://leetcode.com/problems/flood-fill) | | | 734 | [Sentence Similarity](https://leetcode.com/problems/sentence-similarity) | | diff --git a/python/find_pivot_index.py b/python/find_pivot_index.py new file mode 100644 index 0000000..4f19ddc --- /dev/null +++ b/python/find_pivot_index.py @@ -0,0 +1,14 @@ +from typing import List + + +class Solution: + def pivotIndex(self, nums: List[int]) -> int: + leftSum, rightSum = 0, sum(nums) + index = 0 + while index < len(nums): + leftSum += nums[index - 1] if index - 1 >= 0 else 0 + rightSum -= nums[index] + if leftSum == rightSum: + return index + index += 1 + return -1 diff --git a/src/FindPivotIndex.java b/src/FindPivotIndex.java new file mode 100644 index 0000000..3c5b97e --- /dev/null +++ b/src/FindPivotIndex.java @@ -0,0 +1,15 @@ +import java.util.Arrays; + +public class FindPivotIndex { + public int pivotIndex(int[] array) { + int sum = Arrays.stream(array).sum(); + for (int index = 0, leftSum = 0 ; index < array.length ; index++) { + leftSum += index - 1 >= 0 ? array[index - 1] : 0; + sum -= array[index]; + if (leftSum == sum) { + return index; + } + } + return -1; + } +} From b28569d3de8d178900a2b4ad1462df43f1e405ed Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 24 Nov 2021 13:03:05 +0100 Subject: [PATCH 193/947] solves find pivot index --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f981bbb..e5389b5 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-176/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-176/2081-1abc9c.svg) -![problems-solved-python](https://img.shields.io/badge/Python-176/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-177/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-177/2081-1abc9c.svg) +![problems-solved-python](https://img.shields.io/badge/Python-177/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) From a750a6b4089d9183fa61b1411b4ea22c7e81b896 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 24 Nov 2021 22:29:20 +0100 Subject: [PATCH 194/947] solves self dividing numbers --- README.md | 8 ++++---- python/self_dividing_number.py | 17 +++++++++++++++++ src/SelfDividingNumbers.java | 24 ++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 python/self_dividing_number.py create mode 100644 src/SelfDividingNumbers.java diff --git a/README.md b/README.md index e5389b5..3a73f61 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-177/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-177/2081-1abc9c.svg) -![problems-solved-python](https://img.shields.io/badge/Python-177/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-178/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-178/2081-1abc9c.svg) +![problems-solved-python](https://img.shields.io/badge/Python-178/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) @@ -200,7 +200,7 @@ | 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) | | 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) | | +| 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) | | | 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) | | diff --git a/python/self_dividing_number.py b/python/self_dividing_number.py new file mode 100644 index 0000000..ca3eec6 --- /dev/null +++ b/python/self_dividing_number.py @@ -0,0 +1,17 @@ +from typing import List + + +class Solution: + def isSelfDividing(self, number: int) -> bool: + for digit in str(number): + digit = int(digit) + if digit == 0 or number % digit != 0: + return False + return True + + def selfDividingNumbers(self, left: int, right: int) -> List[int]: + result = [] + for number in range(left, right + 1): + if self.isSelfDividing(number): + result.append(number) + return result diff --git a/src/SelfDividingNumbers.java b/src/SelfDividingNumbers.java new file mode 100644 index 0000000..4c05b36 --- /dev/null +++ b/src/SelfDividingNumbers.java @@ -0,0 +1,24 @@ +import java.util.ArrayList; +import java.util.List; + +public class SelfDividingNumbers { + public List selfDividingNumbers(int left, int right) { + List result = new ArrayList<>(); + for(int number = left ; number <= right ; number++) { + if (isSefDividing(number)) { + result.add(number); + } + } + return result; + } + + private boolean isSefDividing(int number) { + int original = number, digit; + while (number > 0) { + digit = number % 10; + if (digit == 0 || original % digit != 0) return false; + number /= 10; + } + return true; + } +} From 40ceaa2252d34fd4662896405b395a05c010eec6 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 24 Nov 2021 22:49:37 +0100 Subject: [PATCH 195/947] solves flood fil --- README.md | 2 +- python/flood_fill.py | 22 ++++++++++++++++++++++ src/FloodFill.java | 25 +++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 python/flood_fill.py create mode 100644 src/FloodFill.java diff --git a/README.md b/README.md index 3a73f61..dcdeb6e 100644 --- a/README.md +++ b/README.md @@ -201,7 +201,7 @@ | 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) | | +| 733 | [Flood Fill](https://leetcode.com/problems/flood-fill) | [![Java](assets/java.png)](src/FloodFill.java) [![Python](assets/python.png)](python/) | | 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) | | | 746 | [Min Cost Climbing Stairs](https://leetcode.com/problems/min-cost-climbing-stairs) | | diff --git a/python/flood_fill.py b/python/flood_fill.py new file mode 100644 index 0000000..c61646a --- /dev/null +++ b/python/flood_fill.py @@ -0,0 +1,22 @@ +from typing import List + + +class Solution: + + def floodFill(self, image: List[List[int]], sr: int, sc: int, newColor: int) -> List[List[int]]: + self.image = image + self.height = len(image) + self.width = len(image[0]) + self.newColor = newColor + if image[sr][sc] != newColor: + self.oldColor = image[sr][sc] + self.colorPixel(row=sr, column=sc) + return image + + def colorPixel(self, row: int, column: int) -> None: + if self.image[row][column] != self.newColor: + self.image[row][column] = self.newColor + if row - 1 >= 0 and self.image[row - 1][column] == self.oldColor: self.colorPixel(row - 1, column) + if column + 1 < self.width and self.image[row][column + 1] == self.oldColor: self.colorPixel(row, column + 1) + if row + 1 < self.height and self.image[row + 1][column] == self.oldColor: self.colorPixel(row + 1, column) + if column - 1 >= 0 and self.image[row][column - 1] == self.oldColor: self.colorPixel(row, column - 1) diff --git a/src/FloodFill.java b/src/FloodFill.java new file mode 100644 index 0000000..f3ef210 --- /dev/null +++ b/src/FloodFill.java @@ -0,0 +1,25 @@ +public class FloodFill { + private int[][] image; + private int height; + private int width; + + public int[][] floodFill(int[][] image, int sr, int sc, int newColor) { + this.image = image; + height = image.length; + width = image[0].length; + if (image[sr][sc] != newColor) { + colorPixel(sr, sc, image[sr][sc], newColor); + } + return image; + } + + private void colorPixel(int row, int col, int oldColor, int newColor) { + if (image[row][col] != newColor) { + image[row][col] = newColor; + if (row - 1 >= 0 && image[row - 1][col] == oldColor) colorPixel(row - 1, col, oldColor, newColor); + if (col + 1 < width && image[row][col + 1] == oldColor) colorPixel(row, col + 1, oldColor, newColor); + if (row + 1 < height && image[row + 1][col] == oldColor) colorPixel(row + 1, col, oldColor, newColor); + if (col - 1 >= 0 && image[row][col - 1] == oldColor) colorPixel(row, col - 1, oldColor, newColor); + } + } +} From cc96000cdfe0cc18ded6d92e0cc33aafb2f74dc8 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 24 Nov 2021 23:20:16 +0100 Subject: [PATCH 196/947] solves smallest letter greater than --- python/find_smallest_letter_greater_than.py | 11 +++++++++++ src/FindSmallestLetterGreaterThanTarget.java | 11 +++++++++++ 2 files changed, 22 insertions(+) create mode 100644 python/find_smallest_letter_greater_than.py create mode 100644 src/FindSmallestLetterGreaterThanTarget.java diff --git a/python/find_smallest_letter_greater_than.py b/python/find_smallest_letter_greater_than.py new file mode 100644 index 0000000..75d31cc --- /dev/null +++ b/python/find_smallest_letter_greater_than.py @@ -0,0 +1,11 @@ +from typing import List + + +class Solution: + def nextGreatestLetter(self, letters: List[str], target: str) -> str: + left, right = 0, len(letters) - 1 + while left <= right: + middle = left + (right - left) // 2 + if letters[middle] <= target: left = middle + 1 + else: right = middle - 1 + return letters[left % len(letters)] diff --git a/src/FindSmallestLetterGreaterThanTarget.java b/src/FindSmallestLetterGreaterThanTarget.java new file mode 100644 index 0000000..f364665 --- /dev/null +++ b/src/FindSmallestLetterGreaterThanTarget.java @@ -0,0 +1,11 @@ +public class FindSmallestLetterGreaterThanTarget { + public char nextGreatestLetter(char[] letters, char target) { + int left = 0, right = letters.length - 1, middle; + while (left <= right) { + middle = left + (right - left) / 2; + if (letters[middle] <= target) left = middle + 1; + else right = middle - 1; + } + return letters[left % letters.length]; + } +} From beadc5e3f9b05981ae9477147c9d534826f41287 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 24 Nov 2021 23:29:52 +0100 Subject: [PATCH 197/947] solves min cost climbing stairs --- README.md | 12 ++++++------ python/min_cost_climbing_stairs.py | 11 +++++++++++ src/MinCostClimbingStairs.java | 11 +++++++++++ 3 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 python/min_cost_climbing_stairs.py create mode 100644 src/MinCostClimbingStairs.java diff --git a/README.md b/README.md index dcdeb6e..5563d56 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-178/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-178/2081-1abc9c.svg) -![problems-solved-python](https://img.shields.io/badge/Python-178/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-181/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-181/2081-1abc9c.svg) +![problems-solved-python](https://img.shields.io/badge/Python-181/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) @@ -201,10 +201,10 @@ | 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/) | +| 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) | | -| 744 | [Find Smallest Letter Greater Than Target](https://leetcode.com/problems/find-smallest-letter-greater-than-target) | | -| 746 | [Min Cost Climbing Stairs](https://leetcode.com/problems/min-cost-climbing-stairs) | | +| 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 twize of Others](https://leetcode.com/problems/largest-number-at-least-twice-of-others) | | | 748 | [Shortest Completing Word](https://leetcode.com/problems/shortest-completing-word) | | | 758 | [Bold Words in String](https://leetcode.com/problems/bold-words-in-string) | | diff --git a/python/min_cost_climbing_stairs.py b/python/min_cost_climbing_stairs.py new file mode 100644 index 0000000..5ce9a1e --- /dev/null +++ b/python/min_cost_climbing_stairs.py @@ -0,0 +1,11 @@ +from typing import List + + +class Solution: + def minCostClimbingStairs(self, cost: List[int]) -> int: + previousCost, currentCost = cost[0], cost[1] + index = 2 + while index < len(cost): + previousCost, currentCost = currentCost, min(previousCost, currentCost) + cost[index] + index += 1 + return min(previousCost, currentCost) diff --git a/src/MinCostClimbingStairs.java b/src/MinCostClimbingStairs.java new file mode 100644 index 0000000..c68c397 --- /dev/null +++ b/src/MinCostClimbingStairs.java @@ -0,0 +1,11 @@ +public class MinCostClimbingStairs { + public int minCostClimbingStairs(int[] cost) { + int currentCost = cost[1], previousCost = cost[0], temp; + for (int index = 2 ; index < cost.length ; index++) { + temp = currentCost; + currentCost = Math.min(currentCost, previousCost) + cost[index]; + previousCost = temp; + } + return Math.min(previousCost, currentCost); + } +} From e15ed9f54db86cc3b4b7294d86d3f59059e86f9c Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 24 Nov 2021 23:40:01 +0100 Subject: [PATCH 198/947] solves largest number at least twice of each other --- README.md | 8 +++---- ...largest_number_at_least_twice_of_others.py | 18 +++++++++++++++ src/LargestNumberAtLeastTwiceOfOthers.java | 22 +++++++++++++++++++ 3 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 python/largest_number_at_least_twice_of_others.py create mode 100644 src/LargestNumberAtLeastTwiceOfOthers.java diff --git a/README.md b/README.md index 5563d56..df3c98b 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-181/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-181/2081-1abc9c.svg) -![problems-solved-python](https://img.shields.io/badge/Python-181/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-182/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-182/2081-1abc9c.svg) +![problems-solved-python](https://img.shields.io/badge/Python-182/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) @@ -205,7 +205,7 @@ | 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 twize of Others](https://leetcode.com/problems/largest-number-at-least-twice-of-others) | | +| 747 | [Largest Number at least twize 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) | | | 758 | [Bold Words in String](https://leetcode.com/problems/bold-words-in-string) | | | 760 | [Find Anagram Mappings](https://leetcode.com/problems/find-anagram-mappings) | | diff --git a/python/largest_number_at_least_twice_of_others.py b/python/largest_number_at_least_twice_of_others.py new file mode 100644 index 0000000..e053492 --- /dev/null +++ b/python/largest_number_at_least_twice_of_others.py @@ -0,0 +1,18 @@ +from typing import List, Tuple + + +class Solution: + def dominantIndex(self, nums: List[int]) -> int: + largest, largestIndex = self.getMax(nums) + for number in nums: + if number != largest and 2 * number > largest: + return -1 + return largestIndex + + def getMax(self, array: List[int]) -> Tuple[int, int]: + largest, largestIndex = -float('inf'), -1 + for index, element in enumerate(array): + if element > largest: + largest = element + largestIndex = index + return largest, largestIndex diff --git a/src/LargestNumberAtLeastTwiceOfOthers.java b/src/LargestNumberAtLeastTwiceOfOthers.java new file mode 100644 index 0000000..c6279e6 --- /dev/null +++ b/src/LargestNumberAtLeastTwiceOfOthers.java @@ -0,0 +1,22 @@ +public class LargestNumberAtLeastTwiceOfOthers { + public int dominantIndex(int[] nums) { + int largestIndex = largestIndex(nums), largest = nums[largestIndex]; + for (int number : nums) { + if (number != largest && 2 * number > largest) { + return -1; + } + } + return largestIndex; + } + + private int largestIndex(int[] array) { + int largest = Integer.MIN_VALUE, largestIndex = -1; + for (int index = 0 ; index < array.length ; index++) { + if (array[index] > largest) { + largest = array[index]; + largestIndex = index; + } + } + return largestIndex; + } +} From acf1afbc254e02ab3247cd6031a42b5ca9b69f5c Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 25 Nov 2021 00:36:45 +0100 Subject: [PATCH 199/947] solves shortest completing word --- README.md | 8 +++---- python/shortest_completing_word.py | 31 +++++++++++++++++++++++++ src/ShortestCompletingWord.java | 37 ++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 python/shortest_completing_word.py create mode 100644 src/ShortestCompletingWord.java diff --git a/README.md b/README.md index df3c98b..a5520bf 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-182/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-182/2081-1abc9c.svg) -![problems-solved-python](https://img.shields.io/badge/Python-182/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-183/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-183/2081-1abc9c.svg) +![problems-solved-python](https://img.shields.io/badge/Python-183/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) @@ -206,7 +206,7 @@ | 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 twize 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) | | +| 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) | | diff --git a/python/shortest_completing_word.py b/python/shortest_completing_word.py new file mode 100644 index 0000000..273670d --- /dev/null +++ b/python/shortest_completing_word.py @@ -0,0 +1,31 @@ +from typing import List + + +class Solution: + def __init__(self): + self.primes = [ + 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, + 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101 + ] + + def shortestCompletingWord(self, licensePlate: str, words: List[str]) -> str: + licenseHash = self.getHash(licensePlate) + resultIndex, shortestLen = -1, float('inf') + for index, word in enumerate(words): + if len(word) < shortestLen and self.coversAllChars(word, licenseHash): + resultIndex = index + shortestLen = len(word) + return words[resultIndex] + + def getHash(self, string: str) -> int: + result = 1 + for char in string.lower(): + if char.isalpha(): + result *= self.primes[ord(char) - ord('a')] + return result + + def coversAllChars(self, word: str, hash: int) -> bool: + result = 1 + for character in word: + result = (result * self.primes[ord(character) - ord('a')]) % hash + return result == 0 diff --git a/src/ShortestCompletingWord.java b/src/ShortestCompletingWord.java new file mode 100644 index 0000000..3d8349e --- /dev/null +++ b/src/ShortestCompletingWord.java @@ -0,0 +1,37 @@ +public class ShortestCompletingWord { + private final int[] primes = { + 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, + 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101 + }; + + public String shortestCompletingWord(String licensePlate, String[] words) { + long licenseHash = getHash(licensePlate); + int shortestCompletingWordLen = Integer.MAX_VALUE; + int shortestWordIndex = -1; + for (int index = 0 ; index < words.length ; index++) { + if (words[index].length() < shortestCompletingWordLen && containsAllChars(words[index], licenseHash)) { + shortestCompletingWordLen = words[index].length(); + shortestWordIndex = index; + } + } + return words[shortestWordIndex]; + } + + private long getHash(String string) { + long result = 1; + for (char character : string.toLowerCase().toCharArray()) { + if (Character.isAlphabetic(character)) { + result *= primes[character - 'a']; + } + } + return result; + } + + private boolean containsAllChars(String word, long hash) { + long result = 1; + for (char character : word.toCharArray()){ + result = (result * primes[character - 'a']) % hash; + } + return result == 0; + } +} From ddd0c4e5b0412c202628f0a05e3127029ada2a50 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 25 Nov 2021 14:36:28 +0100 Subject: [PATCH 200/947] solves prime number of set bits in binary representation --- README.md | 2 +- ...er_of_set_bits_in_binary_representation.py | 22 +++++++++++++++++ ...NumberOfSetBitsInBinaryRepresentation.java | 24 +++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 python/prime_number_of_set_bits_in_binary_representation.py create mode 100644 src/PrimeNumberOfSetBitsInBinaryRepresentation.java diff --git a/README.md b/README.md index a5520bf..dc2a4b0 100644 --- a/README.md +++ b/README.md @@ -209,7 +209,7 @@ | 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) | | +| 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) | | | 771 | [Jewels and Stones](https://leetcode.com/problems/jewels-and-stones) | | | 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) | diff --git a/python/prime_number_of_set_bits_in_binary_representation.py b/python/prime_number_of_set_bits_in_binary_representation.py new file mode 100644 index 0000000..1be06d6 --- /dev/null +++ b/python/prime_number_of_set_bits_in_binary_representation.py @@ -0,0 +1,22 @@ +class Solution: + def __init__(self): + self.isPrime = [ + 0, 0, 1, 1, 0, 1, 0, + 1, 0, 0, 0, 1, 0, + 1, 0, 0, 0, 1, 0, + 1, 0, 0, 0, 1, 0 + ] + + def countPrimeSetBits(self, left: int, right: int) -> int: + primeSetBits = 0 + for number in range(left, right + 1): + if self.isPrime[self.setBits(number)] == 1: + primeSetBits += 1 + return primeSetBits + + def setBits(self, number: int) -> int: + result = 0 + while number > 0: + result += number & 1 + number >>= 1 + return result diff --git a/src/PrimeNumberOfSetBitsInBinaryRepresentation.java b/src/PrimeNumberOfSetBitsInBinaryRepresentation.java new file mode 100644 index 0000000..086b112 --- /dev/null +++ b/src/PrimeNumberOfSetBitsInBinaryRepresentation.java @@ -0,0 +1,24 @@ +public class PrimeNumberOfSetBitsInBinaryRepresentation { + private final byte[] isPrime = new byte[] {0, 0, 1, 1, 0, 1, 0, + 1, 0, 0, 0, 1, 0, + 1, 0, 0, 0, 1, 0, + 1, 0, 0, 0, 1, 0 + }; + + public int countPrimeSetBits(int left, int right) { + int primeSetBits = 0; + for (int number = left ; number <= right ; number++) { + if (isPrime[setBits(number)] == 1) primeSetBits++; + } + return primeSetBits; + } + + private int setBits(int number) { + int setBits = 0; + while (number > 0) { + setBits += number & 1; + number >>= 1; + } + return setBits; + } +} From ffd360444ef3a9a8a018946f801e081098d9acf2 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 25 Nov 2021 14:56:50 +0100 Subject: [PATCH 201/947] solves toepitz matrix --- README.md | 8 ++++---- python/toeplitz_matrix.py | 21 +++++++++++++++++++++ src/ToeplitzMatrix.java | 19 +++++++++++++++++++ 3 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 python/toeplitz_matrix.py create mode 100644 src/ToeplitzMatrix.java diff --git a/README.md b/README.md index dc2a4b0..b4a8133 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-183/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-183/2081-1abc9c.svg) -![problems-solved-python](https://img.shields.io/badge/Python-183/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-185/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-185/2081-1abc9c.svg) +![problems-solved-python](https://img.shields.io/badge/Python-185/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) @@ -210,7 +210,7 @@ | 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) | | +| 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) | | | 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) | | diff --git a/python/toeplitz_matrix.py b/python/toeplitz_matrix.py new file mode 100644 index 0000000..c227ca9 --- /dev/null +++ b/python/toeplitz_matrix.py @@ -0,0 +1,21 @@ +from typing import List + + +class Solution: + def isToeplitzMatrix(self, matrix: List[List[int]]) -> bool: + columns, rows = len(matrix[0]), len(matrix) + for column in range(columns - 1): + current = matrix[0][column] + for row in range(1, rows): + if column + row >= columns: + break + if matrix[row][column + row] != current: + return False + for row in range(1, rows - 1): + current = matrix[row][0] + for column in range(1, columns): + if row + column >= rows: + break + if matrix[row + column][column] != current: + return False + return True diff --git a/src/ToeplitzMatrix.java b/src/ToeplitzMatrix.java new file mode 100644 index 0000000..5b5b523 --- /dev/null +++ b/src/ToeplitzMatrix.java @@ -0,0 +1,19 @@ +public class ToeplitzMatrix { + public boolean isToeplitzMatrix(int[][] matrix) { + final int rows = matrix.length, columns = matrix[0].length; + int current; + for (int column = 0 ; column < columns ; column++) { + current = matrix[0][column]; + for (int row = 1 ; row < rows && column + row < columns ; row++) { + if (matrix[row][column + row] != current) return false; + } + } + for (int row = 1 ; row < rows - 1 ; row++) { + current = matrix[row][0]; + for (int column = 1 ; column < columns && row + column < rows ; column++) { + if (matrix[row + column][column] != current) return false; + } + } + return true; + } +} From 147edd4e5f12df3816e07af3166359aa23fe101f Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 25 Nov 2021 15:05:18 +0100 Subject: [PATCH 202/947] solves jewels and stons --- README.md | 4 ++-- python/jewels_and_stones.py | 8 ++++++++ src/JewelsAndStones.java | 23 +++++++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 python/jewels_and_stones.py create mode 100644 src/JewelsAndStones.java diff --git a/README.md b/README.md index b4a8133..09e848f 100644 --- a/README.md +++ b/README.md @@ -205,13 +205,13 @@ | 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 twize 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) | +| 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) | | +| 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) | | diff --git a/python/jewels_and_stones.py b/python/jewels_and_stones.py new file mode 100644 index 0000000..cb5954c --- /dev/null +++ b/python/jewels_and_stones.py @@ -0,0 +1,8 @@ +class Solution: + def numJewelsInStones(self, jewels: str, stones: str) -> int: + jewelTypes = set(jewels) + result = 0 + for stone in stones: + if stone in jewelTypes: + result += 1 + return result diff --git a/src/JewelsAndStones.java b/src/JewelsAndStones.java new file mode 100644 index 0000000..045387c --- /dev/null +++ b/src/JewelsAndStones.java @@ -0,0 +1,23 @@ +import java.util.HashSet; +import java.util.Set; + +public class JewelsAndStones { + public int numJewelsInStones(String jewels, String stones) { + Set jewelTypes = toSet(jewels); + int totalJewels = 0; + for (char stone : stones.toCharArray()) { + if (jewelTypes.contains(stone)) { + totalJewels++; + } + } + return totalJewels; + } + + private Set toSet(String string) { + Set set = new HashSet<>(); + for (char character : string.toCharArray()) { + set.add(character); + } + return set; + } +} From f495ca2dacd2fa8e4bb76a5faa6d40c19a162865 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 25 Nov 2021 18:49:00 +0100 Subject: [PATCH 203/947] solves rotate string --- README.md | 2 +- src/RotateString.java | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/RotateString.java diff --git a/README.md b/README.md index 09e848f..092aae5 100644 --- a/README.md +++ b/README.md @@ -214,7 +214,7 @@ | 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) | | +| 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) | | | 806 | [Number of Lines to Write String](https://leetcode.com/problems/number-of-lines-to-write-string) | | diff --git a/src/RotateString.java b/src/RotateString.java new file mode 100644 index 0000000..44e9634 --- /dev/null +++ b/src/RotateString.java @@ -0,0 +1,41 @@ +public class RotateString { + public boolean rotateString(String s, String goal) { + if (s.length() != goal.length()) return false; + if (s.equals(goal) || s.length() == 0) return true; + return patternExists(s + s, goal); + } + + private boolean patternExists(String string, String pattern) { + return kmpIndex(string, pattern) != -1; + } + + private int kmpIndex(String string, String pattern) { + int[] patternPrefix = patternPrefixArray(pattern); + for (int t = 0, p = 0 ; t < string.length() && p < pattern.length() ; ) { + if (string.charAt(t) == pattern.charAt(p)) { + if (p == pattern.length() - 1) return t - p; + p++; + t++; + } else if (p != 0) { + p = patternPrefix[p - 1]; + } else { + t++; + } + } + return -1; + } + + private int[] patternPrefixArray(String pattern) { + int[] patternPrefix = new int[pattern.length()]; + for (int j = 0, i = 1 ; i < pattern.length() && j < pattern.length() ; ) { + if (pattern.charAt(j) == pattern.charAt(i)) { + patternPrefix[i++] = j++ + 1; + } else if (j == 0) { + patternPrefix[i++] = 0; + } else { + j = patternPrefix[j - 1]; + } + } + return patternPrefix; + } +} From ccaf06ba3c330aaafdade90b875be6586fd51f2a Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 25 Nov 2021 18:49:36 +0100 Subject: [PATCH 204/947] solves rotate string --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 092aae5..f73cbb9 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-185/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-185/2081-1abc9c.svg) -![problems-solved-python](https://img.shields.io/badge/Python-185/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-187/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-187/2081-1abc9c.svg) +![problems-solved-python](https://img.shields.io/badge/Python-186/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) From 8d6ccf922a99de70bdfa2f55ff334bec730f0081 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 25 Nov 2021 18:52:39 +0100 Subject: [PATCH 205/947] solves rotate string --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f73cbb9..4d4ee44 100644 --- a/README.md +++ b/README.md @@ -196,7 +196,7 @@ | 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) | | +| 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) | | 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) | From fb7def1cdbebb99cae5639b91e4e916a320da733 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 25 Nov 2021 19:00:26 +0100 Subject: [PATCH 206/947] solves unique morse code mappings --- README.md | 6 +++--- src/UniqueMorseCodeWords.java | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 src/UniqueMorseCodeWords.java diff --git a/README.md b/README.md index 4d4ee44..7119cc8 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-187/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-187/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-188/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-188/2081-1abc9c.svg) ![problems-solved-python](https://img.shields.io/badge/Python-186/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) @@ -216,7 +216,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) | | 800 | [Similar RGB Color](https://leetcode.com/problems/similar-rgb-color) | | -| 804 | [Unique Morse Code Words](https://leetcode.com/problems/unique-morse-code-words) | | +| 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) | | | 811 | [Subdomain Visit Count](https://leetcode.com/problems/subdomain-visit-count) | | | 812 | [Largest Triangle Area](https://leetcode.com/problems/largest-triangle-area) | | diff --git a/src/UniqueMorseCodeWords.java b/src/UniqueMorseCodeWords.java new file mode 100644 index 0000000..c10557d --- /dev/null +++ b/src/UniqueMorseCodeWords.java @@ -0,0 +1,32 @@ +import java.util.HashSet; +import java.util.Set; + +public class UniqueMorseCodeWords { + private final String[] morseCodeMapping = new String[] { + ".-","-...","-.-.","-..",".","..-.", + "--.","....","..",".---","-.-",".-..", + "--","-.","---",".--.","--.-",".-.", + "...","-","..-","...-",".--","-..-", + "-.--","--.." + }; + + public int uniqueMorseRepresentations(String[] words) { + Set transformations = new HashSet<>(); + for (String word : words) { + transformations.add(morseValue(word)); + } + return transformations.size(); + } + + private String morseValue(String word) { + StringBuilder result = new StringBuilder(); + for (char character : word.toCharArray()) { + result.append(morseValue(character)); + } + return result.toString(); + } + + private String morseValue(char character) { + return morseCodeMapping[character - 'a']; + } +} From 08589b1da5a6f60788fb5c07133c66f0cda418df Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 26 Nov 2021 01:18:10 +0100 Subject: [PATCH 207/947] solves number of lines to write string --- README.md | 6 +++--- src/NumberOfLinesToWriteInString.java | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 src/NumberOfLinesToWriteInString.java diff --git a/README.md b/README.md index 7119cc8..3d73448 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-188/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-188/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-189/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-189/2081-1abc9c.svg) ![problems-solved-python](https://img.shields.io/badge/Python-186/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) @@ -217,7 +217,7 @@ | 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) | | +| 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) | | | 819 | [Most Common Word](https://leetcode.com/problems/most-common-word) | | diff --git a/src/NumberOfLinesToWriteInString.java b/src/NumberOfLinesToWriteInString.java new file mode 100644 index 0000000..9d00849 --- /dev/null +++ b/src/NumberOfLinesToWriteInString.java @@ -0,0 +1,14 @@ +public class NumberOfLinesToWriteInString { + public int[] numberOfLines(int[] widths, String string) { + int lines = 1, width = 0; + for (char character : string.toCharArray()) { + if (width + widths[character - 'a'] <= 100) { + width += widths[character - 'a']; + } else { + lines++; + width = widths[character - 'a']; + } + } + return new int[] {lines, width}; + } +} From d9e2d456601d05d4c928946fc821cf25a493701a Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 26 Nov 2021 01:35:50 +0100 Subject: [PATCH 208/947] solves largest triangle area --- README.md | 6 +++--- src/LargestTriangleArea.java | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 src/LargestTriangleArea.java diff --git a/README.md b/README.md index 3d73448..34218e0 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-189/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-189/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-190/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-190/2081-1abc9c.svg) ![problems-solved-python](https://img.shields.io/badge/Python-186/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) @@ -219,7 +219,7 @@ | 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) | | +| 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) | | | 821 | [Shortest Distance to Character](https://leetcode.com/problems/shortest-distance-to-a-character) | | | 824 | [Goat Latin](https://leetcode.com/problems/goat-latin) | | diff --git a/src/LargestTriangleArea.java b/src/LargestTriangleArea.java new file mode 100644 index 0000000..3711881 --- /dev/null +++ b/src/LargestTriangleArea.java @@ -0,0 +1,19 @@ +public class LargestTriangleArea { + public double largestTriangleArea(int[][] points) { + double result = 0; + for (int i = 0 ; i < points.length ; i++) { + for (int j = i + 1 ; j < points.length ; j++) { + for (int k = j + 1 ; k < points.length ; k++) { + result = Math.max(result, triangleArea(points[i], points[j], points[k])); + } + } + } + return result; + } + + private double triangleArea(int[] p1, int[] p2, int[] p3) { + return 0.5 * Math.abs( + p1[0] * p2[1] + p2[0] * p3[1] + p3[0] * p1[1]- p2[0] * p1[1] - p3[0] * p2[1] - p1[0] * p3[1] + ); + } +} From cefc669511e720776389b9981a583cfc49e40833 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 26 Nov 2021 01:52:12 +0100 Subject: [PATCH 209/947] solves most common word --- README.md | 6 +++--- src/MostCommonWord.java | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 src/MostCommonWord.java diff --git a/README.md b/README.md index 34218e0..4871d76 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-190/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-190/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-191/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-191/2081-1abc9c.svg) ![problems-solved-python](https://img.shields.io/badge/Python-186/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) @@ -220,7 +220,7 @@ | 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) | | +| 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) | | | 824 | [Goat Latin](https://leetcode.com/problems/goat-latin) | | | 830 | [Positions of Large Groups](https://leetcode.com/problems/positions-of-large-groups) | | diff --git a/src/MostCommonWord.java b/src/MostCommonWord.java new file mode 100644 index 0000000..1d312f2 --- /dev/null +++ b/src/MostCommonWord.java @@ -0,0 +1,22 @@ +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public class MostCommonWord { + public String mostCommonWord(String paragraph, String[] banned) { + String text = paragraph.replaceAll("[^a-zA-Z0-9 ]", " ").toLowerCase(); + Set bannedWords = new HashSet<>(Arrays.asList(banned)); + Map wordFrequencies = new HashMap<>(); + + for (String word : text.split("\\s+")) { + if (!bannedWords.contains(word)) { + wordFrequencies.put(word, wordFrequencies.getOrDefault(word, 0) + 1); + } + } + + return Collections.max(wordFrequencies.entrySet(), Map.Entry.comparingByValue()).getKey(); + } +} From 64bc96bc988a5cd87cda5208111f350dda18cb03 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 26 Nov 2021 10:45:30 +0100 Subject: [PATCH 210/947] solves shortest distance to word --- README.md | 2 +- src/ShortestDistanceToACharacter.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/ShortestDistanceToACharacter.java diff --git a/README.md b/README.md index 4871d76..9fb278e 100644 --- a/README.md +++ b/README.md @@ -221,7 +221,7 @@ | 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) | | +| 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) | | | 830 | [Positions of Large Groups](https://leetcode.com/problems/positions-of-large-groups) | | | 832 | [Flipping an Image](https://leetcode.com/problems/flipping-an-image) | | diff --git a/src/ShortestDistanceToACharacter.java b/src/ShortestDistanceToACharacter.java new file mode 100644 index 0000000..4f7b682 --- /dev/null +++ b/src/ShortestDistanceToACharacter.java @@ -0,0 +1,16 @@ +public class ShortestDistanceToACharacter { + public int[] shortestToChar(String string, char c) { + int[] answer = new int[string.length()]; + for (int i = 0, l = Integer.MIN_VALUE ; i < string.length() ; i++) { + if (string.charAt(i) == c) l = i; + answer[i] = l == Integer.MIN_VALUE ? Integer.MAX_VALUE : i - l; + } + + for (int i = string.length() - 1, r = Integer.MAX_VALUE ; i >= 0 ; i--) { + if (string.charAt(i) == c) r = i; + answer[i] = Math.min(answer[i], r - i); + } + + return answer; + } +} From 7b3b774597465d51658693383ded74acc8dc4ca4 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 26 Nov 2021 15:59:54 +0100 Subject: [PATCH 211/947] solves goat latin --- README.md | 6 +++--- src/GoatLatin.java | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 src/GoatLatin.java diff --git a/README.md b/README.md index 9fb278e..01d82d6 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-191/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-191/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-192/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-192/2081-1abc9c.svg) ![problems-solved-python](https://img.shields.io/badge/Python-186/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) @@ -222,7 +222,7 @@ | 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) | | +| 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) | | | 832 | [Flipping an Image](https://leetcode.com/problems/flipping-an-image) | | | 836 | [Rectangle Overlap](https://leetcode.com/problems/rectangle-overlap) | | diff --git a/src/GoatLatin.java b/src/GoatLatin.java new file mode 100644 index 0000000..f4b89ca --- /dev/null +++ b/src/GoatLatin.java @@ -0,0 +1,52 @@ +import java.util.Set; + +public class GoatLatin { + private static final Set VOWELS = Set.of('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'); + + public String toGoatLatin(String sentence) { + StringBuilder result = new StringBuilder(), word = new StringBuilder(); + char firstLetter = ' '; + int wordCount = 1; + boolean vowelWord = false, newWord = true; + for (int index = 0 ; index < sentence.length() ; index++) { + if (newWord) { + if (index == sentence.length() - 1) { + result.append(toGoatLatin(wordCount, new StringBuilder(), + false, sentence.charAt(index))); + break; + } + if (isVowel(sentence.charAt(index))) { + vowelWord = true; + word.append(sentence.charAt(index)); + } else { + vowelWord = false; + firstLetter = sentence.charAt(index); + } + + newWord = false; + } else if (sentence.charAt(index) == ' ' || index == sentence.length() - 1) { + newWord = true; + if (index == sentence.length() - 1) word.append(sentence.charAt(index)); + result.append(toGoatLatin(wordCount, word, vowelWord, firstLetter)); + word = new StringBuilder(); + wordCount++; + } else { + word.append(sentence.charAt(index)); + } + } + return result.toString(); + } + + private StringBuilder toGoatLatin(int wordCount, StringBuilder word, boolean vowelWord, char firstLetter) { + return new StringBuilder() + .append(wordCount == 1 ? "" : ' ') + .append(word) + .append(vowelWord ? "" : firstLetter) + .append("ma") + .append("a".repeat(wordCount)); + } + + private boolean isVowel(char character) { + return VOWELS.contains(character); + } +} From 40a39a1cfa86eb24396fb9b76066576a87556654 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 26 Nov 2021 16:15:58 +0100 Subject: [PATCH 212/947] solves positions of large groups --- README.md | 6 +++--- src/PositionsOfLargeGroups.java | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 src/PositionsOfLargeGroups.java diff --git a/README.md b/README.md index 01d82d6..c73bb4b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-192/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-192/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-193/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-193/2081-1abc9c.svg) ![problems-solved-python](https://img.shields.io/badge/Python-186/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) @@ -223,7 +223,7 @@ | 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) | | +| 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) | | | 836 | [Rectangle Overlap](https://leetcode.com/problems/rectangle-overlap) | | | 840 | [Magic Squares in Grid](https://leetcode.com/problems/magic-squares-in-grid) | | diff --git a/src/PositionsOfLargeGroups.java b/src/PositionsOfLargeGroups.java new file mode 100644 index 0000000..a22c65f --- /dev/null +++ b/src/PositionsOfLargeGroups.java @@ -0,0 +1,19 @@ +import java.util.ArrayList; +import java.util.List; + +public class PositionsOfLargeGroups { + public List> largeGroupPositions(String s) { + List> result = new ArrayList<>(); + char current = s.charAt(0); + int start = 0; + for (int index = 1 ; index < s.length() ; index++) { + if (s.charAt(index) != current) { + if (index - start >= 3) result.add(List.of(start, index - 1)); + start = index; + current = s.charAt(index); + } + } + if (s.length() - start >= 3) result.add(List.of(start, s.length() - 1)); + return result; + } +} From a34b107d23cae4eb106f872a096e507337cc171c Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 26 Nov 2021 16:23:38 +0100 Subject: [PATCH 213/947] solves flipping an image --- README.md | 6 +++--- src/FlippingAnImage.java | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 src/FlippingAnImage.java diff --git a/README.md b/README.md index c73bb4b..8eeedd2 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-193/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-193/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-194/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-194/2081-1abc9c.svg) ![problems-solved-python](https://img.shields.io/badge/Python-186/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) @@ -224,7 +224,7 @@ | 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) | | +| 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) | | | 840 | [Magic Squares in Grid](https://leetcode.com/problems/magic-squares-in-grid) | | | 844 | [Backspace String Compare](https://leetcode.com/problems/backspace-string-compare) | | diff --git a/src/FlippingAnImage.java b/src/FlippingAnImage.java new file mode 100644 index 0000000..8108fab --- /dev/null +++ b/src/FlippingAnImage.java @@ -0,0 +1,16 @@ +public class FlippingAnImage { + public int[][] flipAndInvertImage(int[][] image) { + final int rows = image.length, columns = image[0].length; + int temp; + + for (int row = 0 ; row < rows ; row++) { + for (int column = 0 ; column < (columns + 1) / 2 ; column++) { + temp = image[row][column] ^ 1; + image[row][column] = image[row][columns - column - 1] ^ 1; + image[row][columns - column - 1] = temp; + } + } + + return image; + } +} From 1fc4ec09fc1a6607faa61a2a4383047962835d69 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 26 Nov 2021 17:19:18 +0100 Subject: [PATCH 214/947] solve srectangle overlap --- README.md | 6 +++--- src/RectangleOverlap.java | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 src/RectangleOverlap.java diff --git a/README.md b/README.md index 8eeedd2..edbe042 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-194/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-194/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-195/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-195/2081-1abc9c.svg) ![problems-solved-python](https://img.shields.io/badge/Python-186/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) @@ -225,7 +225,7 @@ | 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) | | +| 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) | | | 849 | [Maximize Distance to Closest Person](https://leetcode.com/problems/maximize-distance-to-closest-person) | | diff --git a/src/RectangleOverlap.java b/src/RectangleOverlap.java new file mode 100644 index 0000000..2dc3770 --- /dev/null +++ b/src/RectangleOverlap.java @@ -0,0 +1,27 @@ +public class RectangleOverlap { + public boolean isRectangleOverlap(int[] rec1, int[] rec2) { + Rectangle rectangle1 = new Rectangle(rec1); + Rectangle rectangle2 = new Rectangle(rec2); + return hasXIntersection(rectangle1, rectangle2) && hasYIntersection(rectangle1, rectangle2); + } + + private boolean hasXIntersection(Rectangle rec1, Rectangle rec2) { + return (rec1.x1 <= rec2.x1 && rec2.x1 < rec1.x2) + || (rec2.x1 < rec1.x1 && rec1.x1 < rec2.x2); + } + + private boolean hasYIntersection(Rectangle rec1, Rectangle rec2) { + return (rec1.y1 <= rec2.y1 && rec2.y1 < rec1.y2) + || (rec2.y1 < rec1.y1 && rec1.y1 < rec2.y2); + } + + private static class Rectangle { + private final int x1, x2, y1, y2; + Rectangle(int[] points) { + this.x1 = points[0]; + this.y1 = points[1]; + this.x2 = points[2]; + this.y2 = points[3]; + } + } +} From 3028683568a76dea44b81cb81b67f53fa9d3ed6d Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 28 Nov 2021 00:26:58 +0100 Subject: [PATCH 215/947] solves backspace string compare --- README.md | 2 +- src/BackspaceStringCompare.java | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 src/BackspaceStringCompare.java diff --git a/README.md b/README.md index edbe042..070661c 100644 --- a/README.md +++ b/README.md @@ -227,7 +227,7 @@ | 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) | | +| 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) | | | 859 | [Buddy Strings](https://leetcode.com/problems/buddy-strings) | | diff --git a/src/BackspaceStringCompare.java b/src/BackspaceStringCompare.java new file mode 100644 index 0000000..a537593 --- /dev/null +++ b/src/BackspaceStringCompare.java @@ -0,0 +1,23 @@ +public class BackspaceStringCompare { + public boolean backspaceCompare(String s, String t) { + int i = nextCharIndex(s, s.length()), j = nextCharIndex(t, t.length()); + while (i >= 0 && j >= 0) { + if (s.charAt(i) != t.charAt(j)) return false; + i = nextCharIndex(s, i); + j = nextCharIndex(t, j); + } + return i == -1 && j == -1; + } + + private int nextCharIndex(String string, int currentIndex) { + for (int buffer = 0 ; buffer >= 0 ; currentIndex--) { + if (currentIndex == 0) { + currentIndex = -1; + break; + } + if (string.charAt(currentIndex - 1) == '#') buffer++; + else buffer--; + } + return currentIndex; + } +} From ca25a97a0d301e8c108252963255a4240d53dc43 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 28 Nov 2021 00:30:50 +0100 Subject: [PATCH 216/947] solves peak index in mountain array --- README.md | 2 +- src/PeakIndexInMountainArray.java | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 src/PeakIndexInMountainArray.java diff --git a/README.md b/README.md index 070661c..e805f38 100644 --- a/README.md +++ b/README.md @@ -229,7 +229,7 @@ | 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) | | +| 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) | | | 860 | [Lemonade Change](https://leetcode.com/problems/lemonade-change) | | | 867 | [Transpose Matrix](https://leetcode.com/problems/transpose-matrix) | | diff --git a/src/PeakIndexInMountainArray.java b/src/PeakIndexInMountainArray.java new file mode 100644 index 0000000..ef629c4 --- /dev/null +++ b/src/PeakIndexInMountainArray.java @@ -0,0 +1,8 @@ +public class PeakIndexInMountainArray { + public int peakIndexInMountainArray(int[] arr) { + for (int index = 1 ; index < arr.length ; index++) { + if (arr[index] < arr[index - 1]) return index - 1; + } + return -1; + } +} From 59056485ff0b29167542badbaa210f8c4c0f5ea3 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 28 Nov 2021 00:50:11 +0100 Subject: [PATCH 217/947] solves buddy strings --- README.md | 2 +- src/BuddyStrings.java | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/BuddyStrings.java diff --git a/README.md b/README.md index e805f38..5836a37 100644 --- a/README.md +++ b/README.md @@ -230,7 +230,7 @@ | 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) | | +| 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) | | | 867 | [Transpose Matrix](https://leetcode.com/problems/transpose-matrix) | | | 868 | [Binary Gap](https://leetcode.com/problems/binary-gap) | | diff --git a/src/BuddyStrings.java b/src/BuddyStrings.java new file mode 100644 index 0000000..25e5562 --- /dev/null +++ b/src/BuddyStrings.java @@ -0,0 +1,30 @@ +import java.util.Arrays; + +public class BuddyStrings { + public boolean buddyStrings(String s, String goal) { + if (s.length() != goal.length()) return false; + final int[] characterFrequencies = new int[26]; + final int[] need = new int[26]; + int differences = 0; + char c; + for (int index = 0 ; index < s.length() ; index++) { + c = s.charAt(index); + characterFrequencies[c - 'a']++; + if (c != goal.charAt(index)) { + differences++; + need[goal.charAt(index) - 'a']++; + need[c - 'a']--; + } + } + if (differences == 1 || differences > 2) return false; + if (differences == 0 && oneCharOccurrsMoreThanOnce(characterFrequencies)) return true; + return differences == 2 && Arrays.stream(need).allMatch(val -> val == 0); + } + + private boolean oneCharOccurrsMoreThanOnce(int[] frequencies) { + for (int frequency : frequencies) { + if (frequency > 1) return true; + } + return false; + } +} From 0d51a1e288113ed7a2efa59dbfa0d3e999ac0347 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 28 Nov 2021 17:12:04 +0100 Subject: [PATCH 218/947] solves lemonade change --- README.md | 2 +- src/LemonadeChange.java | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/LemonadeChange.java diff --git a/README.md b/README.md index 5836a37..49bf200 100644 --- a/README.md +++ b/README.md @@ -231,7 +231,7 @@ | 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) | | +| 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) | | | 868 | [Binary Gap](https://leetcode.com/problems/binary-gap) | | | 872 | [Leaf-Similar Trees](https://leetcode.com/problems/leaf-similar-trees) | | diff --git a/src/LemonadeChange.java b/src/LemonadeChange.java new file mode 100644 index 0000000..d339997 --- /dev/null +++ b/src/LemonadeChange.java @@ -0,0 +1,20 @@ +public class LemonadeChange { + public boolean lemonadeChange(int[] bills) { + int fives = 0, tenners = 0, twenties = 0; + for (int i = 0 ; i < bills.length && fives >= 0 && tenners >= 0 && twenties >= 0 ; i++) { + if (bills[i] == 20) { + if (tenners > 0) { + tenners--; + fives--; + } else { + fives -= 3; + } + twenties++; + } else if (bills[i] == 10) { + fives--; + tenners++; + } else fives++; + } + return fives >=0 && tenners >= 0 && twenties >= 0; + } +} From 7028b0e4bdc7c8a816d86b6ef8e4e393c4f2224a Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 28 Nov 2021 17:19:38 +0100 Subject: [PATCH 219/947] solves transpose matrix --- README.md | 2 +- src/TransposeMatrix.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/TransposeMatrix.java diff --git a/README.md b/README.md index 49bf200..b82467f 100644 --- a/README.md +++ b/README.md @@ -232,7 +232,7 @@ | 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) | | +| 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) | | | 872 | [Leaf-Similar Trees](https://leetcode.com/problems/leaf-similar-trees) | | | 874 | [Walking Robot Simulation](https://leetcode.com/problems/walking-robot-simulation) | | diff --git a/src/TransposeMatrix.java b/src/TransposeMatrix.java new file mode 100644 index 0000000..96a84d8 --- /dev/null +++ b/src/TransposeMatrix.java @@ -0,0 +1,14 @@ +public class TransposeMatrix { + public int[][] transpose(int[][] matrix) { + final int rows = matrix.length, columns = matrix[0].length; + final int[][] result = new int[columns][rows]; + + for (int row = 0 ; row < rows ; row++) { + for (int column = 0 ; column < columns ; column++) { + result[column][row] = matrix[row][column]; + } + } + + return result; + } +} From e6db9248c626ad059a1566e7c70e85a31049780d Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 28 Nov 2021 17:27:19 +0100 Subject: [PATCH 220/947] solves binary gap --- README.md | 2 +- src/BinaryGap.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/BinaryGap.java diff --git a/README.md b/README.md index b82467f..0fd8cb4 100644 --- a/README.md +++ b/README.md @@ -233,7 +233,7 @@ | 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) | | +| 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) | | | 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) | | diff --git a/src/BinaryGap.java b/src/BinaryGap.java new file mode 100644 index 0000000..cc2502d --- /dev/null +++ b/src/BinaryGap.java @@ -0,0 +1,15 @@ +public class BinaryGap { + public int binaryGap(int n) { + int result = Integer.MIN_VALUE, index = 0, prev = -1; + while (n > 0) { + if ((n & 1) == 1) { + if (prev == -1) prev = index; + result = Math.max(result, index - prev); + prev = index; + } + n >>= 1; + index++; + } + return result; + } +} From 769c90d01763f80d86b8b018071cb4995354d000 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 28 Nov 2021 17:32:57 +0100 Subject: [PATCH 221/947] solves leaf similar tree --- README.md | 2 +- src/LeafSimilarTrees.java | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/LeafSimilarTrees.java diff --git a/README.md b/README.md index 0fd8cb4..6416291 100644 --- a/README.md +++ b/README.md @@ -234,7 +234,7 @@ | 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) | | +| 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) | | | 883 | [Projection Area of 3D Shapes](https://leetcode.com/problems/projection-area-of-3d-shapes) | | diff --git a/src/LeafSimilarTrees.java b/src/LeafSimilarTrees.java new file mode 100644 index 0000000..d91ee81 --- /dev/null +++ b/src/LeafSimilarTrees.java @@ -0,0 +1,26 @@ +import java.util.ArrayList; +import java.util.List; + +public class LeafSimilarTrees { + public boolean leafSimilar(TreeNode root1, TreeNode root2) { + List leafSequence1 = getLeafSequence(root1); + List leafSequence2 = getLeafSequence(root2); + return leafSequence1.equals(leafSequence2); + } + + private List getLeafSequence(TreeNode root) { + List result = new ArrayList<>(); + getLeafSequence(root, result); + return result; + } + + private void getLeafSequence(TreeNode root, List leafNodes) { + if (root == null) return; + if (root.left == null && root.right == null) { + leafNodes.add(root.val); + return; + } + getLeafSequence(root.left, leafNodes); + getLeafSequence(root.right, leafNodes); + } +} From 9d50c3711452b5f069ddb60f9b66687eb1b227a0 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 28 Nov 2021 17:39:39 +0100 Subject: [PATCH 222/947] solves middle of the linkedList --- README.md | 2 +- src/MiddleOfTheLinkedList.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/MiddleOfTheLinkedList.java diff --git a/README.md b/README.md index 6416291..94adbea 100644 --- a/README.md +++ b/README.md @@ -236,7 +236,7 @@ | 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) | | +| 876 | [Middle of the Linked List](https://leetcode.com/problems/middle-of-the-linked-list) | [![Java](assets/java.png)](src/MiddleOfTheLinkedList.java) | | 883 | [Projection Area of 3D Shapes](https://leetcode.com/problems/projection-area-of-3d-shapes) | | | 884 | [Uncommon Words from 2 Sentences](https://leetcode.com/problems/uncommon-words-from-two-sentences) | | | 888 | [Fair Candy Swap](https://leetcode.com/problems/fair-candy-swap) | | diff --git a/src/MiddleOfTheLinkedList.java b/src/MiddleOfTheLinkedList.java new file mode 100644 index 0000000..888368c --- /dev/null +++ b/src/MiddleOfTheLinkedList.java @@ -0,0 +1,18 @@ +public class MiddleOfTheLinkedList { + public static class ListNode { + int val; + ListNode next; + ListNode() {} + ListNode(int val) { this.val = val; } + ListNode(int val, ListNode next) { this.val = val; this.next = next; } + } + + public ListNode middleNode(ListNode head) { + ListNode slow = head, fast = head; + while (fast != null && fast.next != null) { + slow = slow.next; + fast = fast.next.next; + } + return slow; + } +} From abc295e65f39d5d65e2b47c053b066ecbb307958 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 28 Nov 2021 18:17:28 +0100 Subject: [PATCH 223/947] solves projection area of 3d shapes --- README.md | 2 +- src/ProjectionAreaOf3DShapes.java | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/ProjectionAreaOf3DShapes.java diff --git a/README.md b/README.md index 94adbea..a219d63 100644 --- a/README.md +++ b/README.md @@ -237,7 +237,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) | -| 883 | [Projection Area of 3D Shapes](https://leetcode.com/problems/projection-area-of-3d-shapes) | | +| 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) | | | 888 | [Fair Candy Swap](https://leetcode.com/problems/fair-candy-swap) | | | 892 | [Surface Area of 3D Shapes](https://leetcode.com/problems/surface-area-of-3d-shapes) | | diff --git a/src/ProjectionAreaOf3DShapes.java b/src/ProjectionAreaOf3DShapes.java new file mode 100644 index 0000000..9060059 --- /dev/null +++ b/src/ProjectionAreaOf3DShapes.java @@ -0,0 +1,29 @@ +import java.util.Arrays; + +public class ProjectionAreaOf3DShapes { + public int projectionArea(int[][] grid) { + int area = 0; + final int n = grid.length; + + // z axis + for (int row = 0 ; row < n ; row++) { + for(int column = 0 ; column < n ; column++) { + area += grid[row][column] > 0 ? 1 : 0; + } + } + + // x axis + for (int[] row : grid) { + area += Arrays.stream(row).max().getAsInt(); + } + + // y axis + for (int column = 0 ; column < n ; column++) { + int columnMax = 0; + for (int row = 0 ; row < n ; row++) columnMax = Math.max(columnMax, grid[row][column]); + area += columnMax; + } + + return area; + } +} From a7eaedd4f96f5307a5f00634f5fde6e13724f2d4 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 28 Nov 2021 18:31:51 +0100 Subject: [PATCH 224/947] solves uncommon words from two sentences --- README.md | 6 ++--- src/UncommonWordsFromTwoSentences.java | 35 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 src/UncommonWordsFromTwoSentences.java diff --git a/README.md b/README.md index a219d63..489c9c2 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-195/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-195/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-206/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-206/2081-1abc9c.svg) ![problems-solved-python](https://img.shields.io/badge/Python-186/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) @@ -238,7 +238,7 @@ | 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) | | 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) | | +| 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) | | | 892 | [Surface Area of 3D Shapes](https://leetcode.com/problems/surface-area-of-3d-shapes) | | | 893 | [Groups of Special Equivalent Strings](https://leetcode.com/problems/groups-of-special-equivalent-strings) | | diff --git a/src/UncommonWordsFromTwoSentences.java b/src/UncommonWordsFromTwoSentences.java new file mode 100644 index 0000000..4879157 --- /dev/null +++ b/src/UncommonWordsFromTwoSentences.java @@ -0,0 +1,35 @@ +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class UncommonWordsFromTwoSentences { + public String[] uncommonFromSentences(String s1, String s2) { + final Map sentence1Words = getWordFrequencies(s1); + final Map sentence2Words = getWordFrequencies(s2); + final List result = new ArrayList<>(); + for (Map.Entry entry : sentence1Words.entrySet()) { + if (entry.getValue() == 1 && !sentence2Words.containsKey(entry.getKey())) result.add(entry.getKey()); + } + for (Map.Entry entry : sentence2Words.entrySet()) { + if (entry.getValue() == 1 && !sentence1Words.containsKey(entry.getKey())) result.add(entry.getKey()); + } + return result.toArray(new String[] {}); + } + + private Map getWordFrequencies(String string) { + final Map map = new HashMap<>(); + StringBuilder word =new StringBuilder(); + String s; + for (int index = 0 ; index < string.length() ; index++) { + if (string.charAt(index) == ' ') { + s = word.toString(); + map.put(s, map.getOrDefault(s, 0) + 1); + word = new StringBuilder(); + } else word.append(string.charAt(index)); + } + s = word.toString(); + map.put(s, map.getOrDefault(s, 0) + 1); + return map; + } +} From 568fe5f80c3f612c54a8232083d9963d04335cc9 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 28 Nov 2021 18:46:02 +0100 Subject: [PATCH 225/947] solves fair candy swap --- README.md | 2 +- src/FairCandySwap.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/FairCandySwap.java diff --git a/README.md b/README.md index 489c9c2..8bc398b 100644 --- a/README.md +++ b/README.md @@ -239,7 +239,7 @@ | 876 | [Middle of the Linked List](https://leetcode.com/problems/middle-of-the-linked-list) | [![Java](assets/java.png)](src/MiddleOfTheLinkedList.java) | | 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) | | +| 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) | | | 893 | [Groups of Special Equivalent Strings](https://leetcode.com/problems/groups-of-special-equivalent-strings) | | | 896 | [Monotonic Array](https://leetcode.com/problems/monotonic-array) | | diff --git a/src/FairCandySwap.java b/src/FairCandySwap.java new file mode 100644 index 0000000..bc2f223 --- /dev/null +++ b/src/FairCandySwap.java @@ -0,0 +1,16 @@ +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +public class FairCandySwap { + public int[] fairCandySwap(int[] aliceSizes, int[] bobSizes) { + final int difference = Arrays.stream(aliceSizes).sum() - Arrays.stream(bobSizes).sum(); + final int required = difference / 2; + Set bobCandies = new HashSet<>(); + for (int candy : bobSizes) bobCandies.add(candy); + for (int candy : aliceSizes) { + if (bobCandies.contains(candy - required)) return new int[] {candy, candy - required}; + } + return new int[] {}; + } +} From 02e7084bdc34967a2835dcbbf9e41d86286ee709 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 28 Nov 2021 18:59:28 +0100 Subject: [PATCH 226/947] solves surface area of 3d shapes --- README.md | 2 +- src/SurfaceAreaOf3DShapes.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/SurfaceAreaOf3DShapes.java diff --git a/README.md b/README.md index 8bc398b..7ad9f7f 100644 --- a/README.md +++ b/README.md @@ -240,7 +240,7 @@ | 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) | | +| 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) | | | 897 | [Increasing Order Search Tree](https://leetcode.com/problems/increasing-order-search-tree) | | diff --git a/src/SurfaceAreaOf3DShapes.java b/src/SurfaceAreaOf3DShapes.java new file mode 100644 index 0000000..d68b1c6 --- /dev/null +++ b/src/SurfaceAreaOf3DShapes.java @@ -0,0 +1,16 @@ +public class SurfaceAreaOf3DShapes { + public int surfaceArea(int[][] grid) { + final int rows = grid.length, columns = grid[0].length; + int surfaceArea = 0; + for (int row = 0 ; row < rows ; row++) { + for (int column = 0 ; column < columns ; column++) { + surfaceArea += (grid[row][column] > 0 ? 2 : 0) + + (column + 1 < columns ? Math.abs(grid[row][column] - grid[row][column + 1]) : grid[row][column]) + + (row + 1 < rows ? Math.abs(grid[row][column] - grid[row + 1][column]) : grid[row][column]) + + (row == 0 ? grid[row][column] : 0) + + (column == 0 ? grid[row][column] : 0); + } + } + return surfaceArea; + } +} From e3f766a46b2c02afc34c621c5d50c844e9f16ec3 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 28 Nov 2021 19:02:31 +0100 Subject: [PATCH 227/947] solves monotonic array --- README.md | 2 +- src/MonotonicArray.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/MonotonicArray.java diff --git a/README.md b/README.md index 7ad9f7f..9f0f082 100644 --- a/README.md +++ b/README.md @@ -242,7 +242,7 @@ | 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) | | +| 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) | | | 905 | [Sort Array by Parity](https://leetcode.com/problems/sort-array-by-parity) | | | 908 | [Smallest Range I](https://leetcode.com/problems/smallest-range-i) | | diff --git a/src/MonotonicArray.java b/src/MonotonicArray.java new file mode 100644 index 0000000..3d20cc2 --- /dev/null +++ b/src/MonotonicArray.java @@ -0,0 +1,19 @@ +public class MonotonicArray { + public boolean isMonotonic(int[] nums) { + return isMonotonicIncreasing(nums) || isMonotonicDecreasing(nums); + } + + private boolean isMonotonicIncreasing(int[] array) { + for (int i = 1 ; i < array.length ; i++) { + if (array[i] < array[i - 1]) return false; + } + return true; + } + + private boolean isMonotonicDecreasing(int[] array) { + for (int i = 1 ; i < array.length ; i++) { + if (array[i] > array[i - 1]) return false; + } + return true; + } +} From 4c10c787a10bf4b7a082bad05a0d09dbd26dd482 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 28 Nov 2021 19:26:32 +0100 Subject: [PATCH 228/947] solves increasig bst --- README.md | 2 +- src/IncreasingOrderSearchTree.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/IncreasingOrderSearchTree.java diff --git a/README.md b/README.md index 9f0f082..3556b36 100644 --- a/README.md +++ b/README.md @@ -243,7 +243,7 @@ | 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) | | +| 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) | | | 914 | [X of a kind in a Deck of Cards](https://leetcode.com/problems/x-of-a-kind-in-a-deck-of-cards) | | diff --git a/src/IncreasingOrderSearchTree.java b/src/IncreasingOrderSearchTree.java new file mode 100644 index 0000000..1579739 --- /dev/null +++ b/src/IncreasingOrderSearchTree.java @@ -0,0 +1,19 @@ +public class IncreasingOrderSearchTree { + TreeNode current; + + public TreeNode increasingBST(TreeNode root) { + if (root == null) return null; + TreeNode result = new TreeNode(); + current = result; + inOrderTraversal(root); + return result.right; + } + + private void inOrderTraversal(TreeNode root) { + if (root == null) return; + inOrderTraversal(root.left); + current.right = new TreeNode(root.val); + current = current.right; + inOrderTraversal(root.right); + } +} From 8997f68863fca729acc3fcbadb7c1f156e0c4bfd Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 28 Nov 2021 23:21:18 +0100 Subject: [PATCH 229/947] solves smallest range I --- README.md | 2 +- src/SmallestRangeI.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 src/SmallestRangeI.java diff --git a/README.md b/README.md index 3556b36..4b97f37 100644 --- a/README.md +++ b/README.md @@ -245,7 +245,7 @@ | 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) | | +| 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) | | | 917 | [Reverse Only Letters](https://leetcode.com/problems/reverse-only-letters) | | | 922 | [Sort Array by Parity II](https://leetcode.com/problems/sort-array-by-parity-ii) | | diff --git a/src/SmallestRangeI.java b/src/SmallestRangeI.java new file mode 100644 index 0000000..7bce761 --- /dev/null +++ b/src/SmallestRangeI.java @@ -0,0 +1,10 @@ +import java.util.Arrays; + +public class SmallestRangeI { + public int smallestRangeI(int[] nums, int k) { + return Math.max( + 0, + Arrays.stream(nums).max().getAsInt() - Arrays.stream(nums).min().getAsInt() - 2 * k + ); + } +} From f613d9bebe91e3c96e79ea7b60213014a4a772b7 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 28 Nov 2021 23:41:25 +0100 Subject: [PATCH 230/947] solves x of a kind in a deck of cards --- README.md | 2 +- src/XOfAKindInADeckOfCards.java | 37 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/XOfAKindInADeckOfCards.java diff --git a/README.md b/README.md index 4b97f37..ce791d9 100644 --- a/README.md +++ b/README.md @@ -246,7 +246,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) | -| 914 | [X of a kind in a Deck of Cards](https://leetcode.com/problems/x-of-a-kind-in-a-deck-of-cards) | | +| 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) | | | 922 | [Sort Array by Parity II](https://leetcode.com/problems/sort-array-by-parity-ii) | | | 925 | [Long Pressed Name](https://leetcode.com/problems/long-pressed-name) | | diff --git a/src/XOfAKindInADeckOfCards.java b/src/XOfAKindInADeckOfCards.java new file mode 100644 index 0000000..cf7c23b --- /dev/null +++ b/src/XOfAKindInADeckOfCards.java @@ -0,0 +1,37 @@ +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public class XOfAKindInADeckOfCards { + public boolean hasGroupsSizeX(int[] deck) { + if (deck.length == 1) return false; + Map cards = getFrequencies(deck); + Set frequencies = new HashSet<>(cards.values()); + if (frequencies.size() == 1 && cards.get(deck[0]) >= 2) return true; + return gcd(frequencies) > 1; + } + + private int gcd(Collection collection) { + int gcd = 0; + boolean firstTime = true; + for (int value : collection) { + gcd = firstTime ? value : gcd(gcd, value); + firstTime = false; + } + return gcd; + } + + private int gcd(int a, int b) { + return b == 0 ? a : gcd(b, a % b); + } + + private Map getFrequencies(int[] array) { + Map result = new HashMap<>(); + for (int val : array) { + result.put(val, result.getOrDefault(val, 0) + 1); + } + return result; + } +} From 2fc5fb258da11bf74b72c72d10c2c0873efe8b1c Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 28 Nov 2021 23:55:05 +0100 Subject: [PATCH 231/947] solves reverse only letters --- README.md | 2 +- src/ReverseOnlyLetters.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/ReverseOnlyLetters.java diff --git a/README.md b/README.md index ce791d9..ce3cb93 100644 --- a/README.md +++ b/README.md @@ -247,7 +247,7 @@ | 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) | | +| 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) | | | 925 | [Long Pressed Name](https://leetcode.com/problems/long-pressed-name) | | | 929 | [Unique Email Addresses](https://leetcode.com/problems/unique-email-addresses) | | diff --git a/src/ReverseOnlyLetters.java b/src/ReverseOnlyLetters.java new file mode 100644 index 0000000..f594b38 --- /dev/null +++ b/src/ReverseOnlyLetters.java @@ -0,0 +1,16 @@ +public class ReverseOnlyLetters { + public static String reverseOnlyLetters(String s) { + StringBuilder result = new StringBuilder(); + int tail = s.length() - 1; + while (tail >= 0 && !Character.isAlphabetic(s.charAt(tail))) tail--; + + for (int head = 0 ; head < s.length() ; head++) { + if (Character.isAlphabetic(s.charAt(head))) { + result.append(s.charAt(tail--)); + while (tail >=0 && !Character.isAlphabetic(s.charAt(tail))) tail--; + } else result.append(s.charAt(head)); + } + + return result.toString(); + } +} From 4fa13fa534842668b5a56b666645e9f2204477a9 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 29 Nov 2021 00:28:27 +0100 Subject: [PATCH 232/947] solves sort by parity II --- src/SortArrayByParityII.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/SortArrayByParityII.java diff --git a/src/SortArrayByParityII.java b/src/SortArrayByParityII.java new file mode 100644 index 0000000..2cc41b5 --- /dev/null +++ b/src/SortArrayByParityII.java @@ -0,0 +1,17 @@ +public class SortArrayByParityII { + public static int[] sortArrayByParityII(int[] array) { + for (int i = 0, j = 1; i < array.length ; i += 2) { + if ((array[i] & 1) == 1) { + while (j < array.length && ((array[j] & 1) == 1)) j += 2; + swap(array, i, j); + } + } + return array; + } + + private static void swap(int[] array, int i, int j) { + int temp = array[i]; + array[i] = array[j]; + array[j] = temp; + } +} From ef6b5cbd9f585560ea15687f76b5f30f8ae5ad2e Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 29 Nov 2021 00:46:04 +0100 Subject: [PATCH 233/947] solves long pressed name --- README.md | 4 ++-- src/LongPressedName.java | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 src/LongPressedName.java diff --git a/README.md b/README.md index ce3cb93..0140a20 100644 --- a/README.md +++ b/README.md @@ -248,8 +248,8 @@ | 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) | | -| 925 | [Long Pressed Name](https://leetcode.com/problems/long-pressed-name) | | +| 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) | | | 933 | [Number of Recent Calls](https://leetcode.com/problems/number-of-recent-calls) | | | 937 | [Reorder Data In Log Files](https://leetcode.com/problems/reorder-data-in-log-files) | | diff --git a/src/LongPressedName.java b/src/LongPressedName.java new file mode 100644 index 0000000..82ccf53 --- /dev/null +++ b/src/LongPressedName.java @@ -0,0 +1,21 @@ +public class LongPressedName { + public boolean isLongPressedName(String name, String typed) { + char current = name.charAt(0); + for (int i = 0, j = 0, freq = 0, typedFreq = 0 ; i < name.length() && j < typed.length() ; ) { + while (i < name.length() && name.charAt(i) == current) { + i++; + freq++; + } + while (j < typed.length() && typed.charAt(j) == current) { + j++; + typedFreq++; + } + if (typedFreq < freq) return false; + if (i == name.length() && j < typed.length()) return false; + if (j == typed.length() && i < name.length()) return false; + current = i >= name.length() ? ' ' : name.charAt(i); + freq = typedFreq = 0; + } + return true; + } +} From 1cd3a33432c8e98b07deff409d44480906cdee4d Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 29 Nov 2021 01:01:11 +0100 Subject: [PATCH 234/947] solves unique email address --- README.md | 6 +++--- src/UniqueEmailAddresses.java | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 src/UniqueEmailAddresses.java diff --git a/README.md b/README.md index 0140a20..b52dfd2 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-206/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-206/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-215/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-215/2081-1abc9c.svg) ![problems-solved-python](https://img.shields.io/badge/Python-186/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) @@ -250,7 +250,7 @@ | 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) | | +| 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) | | | 937 | [Reorder Data In Log Files](https://leetcode.com/problems/reorder-data-in-log-files) | | | 938 | [Range Sum of BST](https://leetcode.com/problems/range-sum-of-bst) | | diff --git a/src/UniqueEmailAddresses.java b/src/UniqueEmailAddresses.java new file mode 100644 index 0000000..91ecbf2 --- /dev/null +++ b/src/UniqueEmailAddresses.java @@ -0,0 +1,27 @@ +import java.util.HashSet; +import java.util.Set; + +public class UniqueEmailAddresses { + public int numUniqueEmails(String[] emails) { + Set uniqueEmails = new HashSet<>(); + for (String emailAddress : emails) { + uniqueEmails.add(getActualEmailAddress(emailAddress)); + } + return uniqueEmails.size(); + } + + private static String getActualEmailAddress(String email) { + StringBuilder result = new StringBuilder(); + for (int index = 0 ; index < email.length() ; index++) { + if (email.charAt(index) == '+') { + while (email.charAt(index) != '@') index++; + result.append(email.substring(index)); + break; + } else if (email.charAt(index) == '@') { + result.append(email.substring(index)); + break; + } else if (email.charAt(index) != '.') result.append(email.charAt(index)); + } + return result.toString(); + } +} From bfa43a475624f846e79b74cd3ba189d26933120e Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 29 Nov 2021 14:21:15 +0100 Subject: [PATCH 235/947] solves Number Of Recent Calls --- README.md | 2 +- src/NumberOfRecentCalls.java | 32 ++++++++++++++++++++++++++++++++ src/TeemoAttacking.java | 6 +----- 3 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 src/NumberOfRecentCalls.java diff --git a/README.md b/README.md index b52dfd2..e033cd5 100644 --- a/README.md +++ b/README.md @@ -251,7 +251,7 @@ | 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) | | +| 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) | | | 938 | [Range Sum of BST](https://leetcode.com/problems/range-sum-of-bst) | | | 941 | [Valid Mountain Array](https://leetcode.com/problems/valid-mountain-array) | | diff --git a/src/NumberOfRecentCalls.java b/src/NumberOfRecentCalls.java new file mode 100644 index 0000000..6ef8da0 --- /dev/null +++ b/src/NumberOfRecentCalls.java @@ -0,0 +1,32 @@ +public class NumberOfRecentCalls { + class RecentCounter { + private Node head; + private Node tail; + private int size = 0; + + public int ping(int t) { + size++; + if (head == null) { + head = new Node(t); + tail = head; + } else { + tail.next = new Node(t); + tail = tail.next; + } + while (head.val < t - 3000) { + head = head.next; + size--; + } + return size; + } + + private class Node { + int val; + Node next; + + Node(final int val) { + this.val = val; + } + } + } +} diff --git a/src/TeemoAttacking.java b/src/TeemoAttacking.java index 88322c4..90d6a7e 100644 --- a/src/TeemoAttacking.java +++ b/src/TeemoAttacking.java @@ -1,9 +1,5 @@ public class TeemoAttacking { - public static void main(String[] args) { - System.out.println(findPoisonedDuration(new int[] {1, 2}, 2)); - } - - public static int findPoisonedDuration(int[] timeSeries, int duration) { + public int findPoisonedDuration(int[] timeSeries, int duration) { int poisonDuration = 0; for (int i = 0, current = timeSeries[0] - 1 ; i < timeSeries.length; i++) { poisonDuration += duration - Math.max(0, Math.max(current, timeSeries[i] - 1) - timeSeries[i] + 1); From 69890f553d9bbbae6dda27c24b5c3fe6f877c78c Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 29 Nov 2021 14:46:01 +0100 Subject: [PATCH 236/947] solves reorder data in log files --- README.md | 2 +- src/ReorderDataInLogFiles.java | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/ReorderDataInLogFiles.java diff --git a/README.md b/README.md index e033cd5..f40758e 100644 --- a/README.md +++ b/README.md @@ -252,7 +252,7 @@ | 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) | | +| 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) | | | 941 | [Valid Mountain Array](https://leetcode.com/problems/valid-mountain-array) | | | 942 | [DI String Match](https://leetcode.com/problems/di-string-match) | | diff --git a/src/ReorderDataInLogFiles.java b/src/ReorderDataInLogFiles.java new file mode 100644 index 0000000..079b47d --- /dev/null +++ b/src/ReorderDataInLogFiles.java @@ -0,0 +1,33 @@ +import java.util.Arrays; + +public class ReorderDataInLogFiles { + public String[] reorderLogFiles(String[] logs) { + Arrays.sort(logs, (log1, log2) -> { + String[] split1 = log1.split(" ", 2); + String[] split2 = log2.split(" ", 2); + + boolean isDigit1 = Character.isDigit(split1[1].charAt(0)); + boolean isDigit2 = Character.isDigit(split2[1].charAt(0)); + + // case 1). both logs are letter-logs + if (!isDigit1 && !isDigit2) { + // first compare the content + int cmp = split1[1].compareTo(split2[1]); + if (cmp != 0) return cmp; + // logs of same content, compare the identifiers + return split1[0].compareTo(split2[0]); + } + + // case 2). one of logs is digit-log + if (!isDigit1) + // the letter-log comes before digit-logs + return -1; + else if (!isDigit2) + return 1; + else + // case 3). both logs are digit-log + return 0; + }); + return logs; + } +} From 5ffa62fba63dcb158e6ea38542120e54f79e1d42 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 29 Nov 2021 15:11:50 +0100 Subject: [PATCH 237/947] solves range sum of bst --- README.md | 2 +- src/RangeSumOfBST.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 src/RangeSumOfBST.java diff --git a/README.md b/README.md index f40758e..7963256 100644 --- a/README.md +++ b/README.md @@ -253,7 +253,7 @@ | 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) | | +| 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) | | | 942 | [DI String Match](https://leetcode.com/problems/di-string-match) | | | 944 | [Delete Columns to Make Sorted](https://leetcode.com/problems/delete-columns-to-make-sorted) | | diff --git a/src/RangeSumOfBST.java b/src/RangeSumOfBST.java new file mode 100644 index 0000000..b4fdd42 --- /dev/null +++ b/src/RangeSumOfBST.java @@ -0,0 +1,10 @@ +public class RangeSumOfBST { + public int rangeSumBST(TreeNode root, int low, int high) { + if (root == null) return 0; + if (low <= root.val && root.val <= high) { + return root.val + rangeSumBST(root.left, low, high) + rangeSumBST(root.right, low, high); + } + if (root.val < low) return rangeSumBST(root.right, low, high); + return rangeSumBST(root.left, low, high); + } +} From 528d448b87d9f14d468166021c67946c366d619c Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 29 Nov 2021 15:21:10 +0100 Subject: [PATCH 238/947] solves di string match --- README.md | 6 +++--- src/DIStringMatch.java | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 src/DIStringMatch.java diff --git a/README.md b/README.md index 7963256..788516b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-215/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-215/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-220/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-220/2081-1abc9c.svg) ![problems-solved-python](https://img.shields.io/badge/Python-186/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) @@ -255,7 +255,7 @@ | 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) | | -| 942 | [DI String Match](https://leetcode.com/problems/di-string-match) | | +| 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) | | | 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) | | diff --git a/src/DIStringMatch.java b/src/DIStringMatch.java new file mode 100644 index 0000000..a166522 --- /dev/null +++ b/src/DIStringMatch.java @@ -0,0 +1,14 @@ +public class DIStringMatch { + public int[] diStringMatch(String s) { + int[] result = new int[s.length() + 1]; + int current = 0; + for (int i = 0 ; i < s.length() ; i++) { + if (s.charAt(i) == 'I') result[i] = current++; + } + result[result.length - 1] = current++; + for (int i = s.length() - 1 ; i >= 0 ; i--) { + if (s.charAt(i) == 'D') result[i] = current++; + } + return result; + } +} From aaffb4f0a7a4cb027f56016ebafb8fb8181781c3 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 29 Nov 2021 15:25:38 +0100 Subject: [PATCH 239/947] solves valid mountain array --- README.md | 2 +- python/valid_mountain_array.py | 16 ++++++++++++++++ src/ValidMountainArray.java | 15 +++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 python/valid_mountain_array.py create mode 100644 src/ValidMountainArray.java diff --git a/README.md b/README.md index 788516b..ac300af 100644 --- a/README.md +++ b/README.md @@ -254,7 +254,7 @@ | 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) | | +| 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) | | | 949 | [Largest Time for Given Digits](https://leetcode.com/problems/largest-time-for-given-digits) | | diff --git a/python/valid_mountain_array.py b/python/valid_mountain_array.py new file mode 100644 index 0000000..e51a26a --- /dev/null +++ b/python/valid_mountain_array.py @@ -0,0 +1,16 @@ +from typing import List + + +class Solution: + def validMountainArray(self, numbers: List[int]) -> bool: + isIncreasing = True + index = 1 + while index < len(numbers): + if numbers[index] == numbers[index - 1]: return False + if numbers[index] < numbers[index - 1] and isIncreasing: + if index == 1: return False + isIncreasing = False + if numbers[index] > numbers[index - 1] and not isIncreasing: + return False + index += 1 + return not isIncreasing diff --git a/src/ValidMountainArray.java b/src/ValidMountainArray.java new file mode 100644 index 0000000..1cffcc6 --- /dev/null +++ b/src/ValidMountainArray.java @@ -0,0 +1,15 @@ +public class ValidMountainArray { + public boolean validMountainArray(int[] arr) { + boolean isIncreasing = true; + for (int index = 1 ; index < arr.length ; index++) { + if (arr[index] == arr[index - 1]) return false; + if (arr[index] < arr[index - 1] && isIncreasing) { + if (index == 1) return false; + isIncreasing = false; + } else if (arr[index] > arr[index - 1] && !isIncreasing) { + return false; + } + } + return !isIncreasing; + } +} From 37f090945445e8dd478f48ae59dbce99c215b1b2 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 29 Nov 2021 15:38:48 +0100 Subject: [PATCH 240/947] solves delete columns to make sorted --- README.md | 2 +- src/DeleteColumnsToMakeSorted.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/DeleteColumnsToMakeSorted.java diff --git a/README.md b/README.md index ac300af..4e99566 100644 --- a/README.md +++ b/README.md @@ -256,7 +256,7 @@ | 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) | | +| 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) | | | 961 | [N-Repeated Elements in Size 2N Array](https://leetcode.com/problems/n-repeated-element-in-size-2n-array) | | diff --git a/src/DeleteColumnsToMakeSorted.java b/src/DeleteColumnsToMakeSorted.java new file mode 100644 index 0000000..742829d --- /dev/null +++ b/src/DeleteColumnsToMakeSorted.java @@ -0,0 +1,17 @@ +public class DeleteColumnsToMakeSorted { + public int minDeletionSize(String[] strings) { + final int columns = strings[0].length(); + int deletions = 0; + for (int column = 0 ; column < columns ; column++) { + if (!isSorted(strings, column)) deletions++; + } + return deletions; + } + + private boolean isSorted(String[] strings, int column) { + for (int row = 1 ; row < strings.length ; row++) { + if (strings[row].charAt(column) < strings[row - 1].charAt(column)) return false; + } + return true; + } +} From bc0e12e4f37c4abfa996c60e93b6bf4473211045 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 29 Nov 2021 16:38:09 +0100 Subject: [PATCH 241/947] solves alien language dictionary --- README.md | 2 +- src/VerifyAnAlienDictionary.java | 33 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/VerifyAnAlienDictionary.java diff --git a/README.md b/README.md index 4e99566..2185ac4 100644 --- a/README.md +++ b/README.md @@ -258,7 +258,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) | | -| 953 | [Verifying an Alien Dictionary](https://leetcode.com/problems/verifying-an-alien-dictionary) | | +| 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) | | | 965 | [Univalued Binary Tree](https://leetcode.com/problems/univalued-binary-tree) | | | 970 | [Powerful Integers](https://leetcode.com/problems/powerful-integers) | | diff --git a/src/VerifyAnAlienDictionary.java b/src/VerifyAnAlienDictionary.java new file mode 100644 index 0000000..4690407 --- /dev/null +++ b/src/VerifyAnAlienDictionary.java @@ -0,0 +1,33 @@ +import java.util.Comparator; + +public class VerifyAnAlienDictionary { + public boolean isAlienSorted(String[] words, String order) { + AlienLanguageComparator alienLanguageComparator = new AlienLanguageComparator(order); + for (int i = 1 ; i < words.length ; i++) { + if (alienLanguageComparator.compare(words[i - 1], words[i]) > 0) { + return false; + } + } + return true; + } + + private static class AlienLanguageComparator implements Comparator { + final int[] characterOrder = new int[26]; + + AlienLanguageComparator(String order) { + for (int index = 0 ; index < 26 ; index++) { + characterOrder[order.charAt(index) - 'a'] = index; + } + } + + @Override + public int compare(String s1, String s2) { + if (s1.length() == s2.length() && s1.equals(s2)) return 0; + for (int i = 0, j = 0 ; i < s1.length() && j < s2.length() ; i++, j++) { + if (characterOrder[s1.charAt(i) - 'a'] < characterOrder[s2.charAt(j) - 'a']) return -1; + else if (characterOrder[s1.charAt(i) - 'a'] > characterOrder[s2.charAt(j) - 'a']) return 1; + } + return s1.length() - s2.length(); + } + } +} From f69a624ab7b56a96c0d8d79a3214b9a91ce81039 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 29 Nov 2021 20:10:43 +0100 Subject: [PATCH 242/947] solves n repeated elements in size n array --- README.md | 2 +- src/NRepeatedElementInSizeNArray.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 src/NRepeatedElementInSizeNArray.java diff --git a/README.md b/README.md index 2185ac4..c68f187 100644 --- a/README.md +++ b/README.md @@ -259,7 +259,7 @@ | 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) | | +| 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) | | | 970 | [Powerful Integers](https://leetcode.com/problems/powerful-integers) | | | 976 | [Largest Perimeter Triangle](https://leetcode.com/problems/largest-perimeter-triangle) | | diff --git a/src/NRepeatedElementInSizeNArray.java b/src/NRepeatedElementInSizeNArray.java new file mode 100644 index 0000000..44f2764 --- /dev/null +++ b/src/NRepeatedElementInSizeNArray.java @@ -0,0 +1,10 @@ +public class NRepeatedElementInSizeNArray { + public int repeatedNTimes(int[] nums) { + for (int k = 1 ; k < 4 ; k++) { + for (int i = 0 ; i < nums.length - k ; i++) { + if (nums[i] == nums[i + k]) return nums[i]; + } + } + return -1; + } +} From 2de43ca498e525921b894313e78c8453a6b6f971 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 29 Nov 2021 20:11:35 +0100 Subject: [PATCH 243/947] solves n repeated elements in size n array --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c68f187..6d52847 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-220/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-220/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-223/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-223/2081-1abc9c.svg) ![problems-solved-python](https://img.shields.io/badge/Python-186/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) From 2e9d13a38fbfbfab24460ed35a0844f951d8a9ce Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 30 Nov 2021 09:21:25 +0100 Subject: [PATCH 244/947] solves univalues binary tree --- README.md | 2 +- src/UnivaluedBinaryTree.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/UnivaluedBinaryTree.java diff --git a/README.md b/README.md index 6d52847..fef651e 100644 --- a/README.md +++ b/README.md @@ -260,7 +260,7 @@ | 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) | | +| 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) | | | 977 | [Squares of a Sorted Array](https://leetcode.com/problems/squares-of-a-sorted-array) | | diff --git a/src/UnivaluedBinaryTree.java b/src/UnivaluedBinaryTree.java new file mode 100644 index 0000000..c120c0d --- /dev/null +++ b/src/UnivaluedBinaryTree.java @@ -0,0 +1,14 @@ +public class UnivaluedBinaryTree { + private int val; + + public boolean isUnivalTree(TreeNode root) { + val = root.val; + return isUnival(root); + } + + private boolean isUnival(TreeNode root) { + if (root == null) return true; + if (root.val != val) return false; + return isUnival(root.left) && isUnival(root.right); + } +} From 7aba7c0baaf318543602cd952abc8b5ed1750740 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 30 Nov 2021 09:42:16 +0100 Subject: [PATCH 245/947] solves largest perimeter triangle --- README.md | 2 +- src/LargestPerimeterTriangle.java | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/LargestPerimeterTriangle.java diff --git a/README.md b/README.md index fef651e..4d30713 100644 --- a/README.md +++ b/README.md @@ -262,7 +262,7 @@ | 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) | | +| 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) | | | 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) | | diff --git a/src/LargestPerimeterTriangle.java b/src/LargestPerimeterTriangle.java new file mode 100644 index 0000000..b2e8602 --- /dev/null +++ b/src/LargestPerimeterTriangle.java @@ -0,0 +1,11 @@ +import java.util.Arrays; + +public class LargestPerimeterTriangle { + public int largestPerimeter(int[] nums) { + Arrays.sort(nums); + for (int i = nums.length - 1 ; i >= 2 ; i--) { + if (nums[i - 2] + nums[i - 1] > nums[i]) return nums[i - 2] + nums[i - 1] + nums[i]; + } + return 0; + } +} From f11123d75397777e2958ac9be7b39fa161b7d455 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 30 Nov 2021 09:59:39 +0100 Subject: [PATCH 246/947] solves add to array form of integer --- README.md | 2 +- src/AddToArrayFormOfInteger.java | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/AddToArrayFormOfInteger.java diff --git a/README.md b/README.md index 4d30713..129bf06 100644 --- a/README.md +++ b/README.md @@ -265,7 +265,7 @@ | 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) | | | 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) | | +| 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) | | | 997 | [Find the Town Judge](https://leetcode.com/problems/find-the-town-judge) | | | 999 | [Available Captures for Rook](https://leetcode.com/problems/available-captures-for-rook) | | diff --git a/src/AddToArrayFormOfInteger.java b/src/AddToArrayFormOfInteger.java new file mode 100644 index 0000000..b571ec8 --- /dev/null +++ b/src/AddToArrayFormOfInteger.java @@ -0,0 +1,22 @@ +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class AddToArrayFormOfInteger { + public List addToArrayForm(int[] num, int k) { + List result = new ArrayList<>(); + int sum; + for (int i = num.length - 1, carry = 0 ; i >= 0 || carry > 0 || k > 0 ; i--, k /= 10) { + sum = get(num, i) + carry + k % 10; + result.add(sum % 10); + carry = sum / 10; + } + Collections.reverse(result); + return result; + } + + private int get(int[] array, int index) { + if (index < 0) return 0; + return array[index]; + } +} From ee96abf82f502ae927108f832385c601313ce686 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 30 Nov 2021 10:25:37 +0100 Subject: [PATCH 247/947] solves cousins in binary tre --- README.md | 2 +- src/CousinsInBinaryTree.java | 40 ++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/CousinsInBinaryTree.java diff --git a/README.md b/README.md index 129bf06..fddc03a 100644 --- a/README.md +++ b/README.md @@ -266,7 +266,7 @@ | 977 | [Squares of a Sorted Array](https://leetcode.com/problems/squares-of-a-sorted-array) | | | 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) | | +| 993 | [Cousins in Binary Tree](https://leetcode.com/problems/cousins-in-binary-tree) | [![Java](assets/java.png)](src/CousinsInBinaryTree.java) | | 997 | [Find the Town Judge](https://leetcode.com/problems/find-the-town-judge) | | | 999 | [Available Captures for Rook](https://leetcode.com/problems/available-captures-for-rook) | | | 1002 | [Find Common Characters](https://leetcode.com/problems/find-common-characters) | | diff --git a/src/CousinsInBinaryTree.java b/src/CousinsInBinaryTree.java new file mode 100644 index 0000000..4c72704 --- /dev/null +++ b/src/CousinsInBinaryTree.java @@ -0,0 +1,40 @@ +public class CousinsInBinaryTree { + + public boolean isCousins(TreeNode root, int x, int y) { + NodeInfo X = getNodeInfo(root, x); + NodeInfo Y = getNodeInfo(root, y); + return X.depth == Y.depth && X.parent != Y.parent; + } + + private NodeInfo getNodeInfo(TreeNode root, int val) { + if (root == null) return null; + if (root.val == val) return new NodeInfo(null, 0); + if (val(root.left) == val || val(root.right) == val) return new NodeInfo(root, 1); + NodeInfo left = getNodeInfo(root.left, val); + NodeInfo right = getNodeInfo(root.right, val); + if (left != null) { + left.depth++; + return left; + } + if (right != null) { + right.depth++; + return right; + } + return null; + } + + private int val(TreeNode root) { + if (root == null) return 0; + return root.val; + } + + private static class NodeInfo { + TreeNode parent; + int depth; + + NodeInfo(final TreeNode parent, final int depth) { + this.parent = parent; + this.depth = depth; + } + } +} From 43784685eb3298a15de42ba12e26d738dbaea95d Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 30 Nov 2021 11:16:54 +0100 Subject: [PATCH 248/947] solves fidn the town judge --- README.md | 2 +- src/FindTheTownJudge.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/FindTheTownJudge.java diff --git a/README.md b/README.md index fddc03a..c5c8b03 100644 --- a/README.md +++ b/README.md @@ -267,7 +267,7 @@ | 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) | -| 997 | [Find the Town Judge](https://leetcode.com/problems/find-the-town-judge) | | +| 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) | | | 1002 | [Find Common Characters](https://leetcode.com/problems/find-common-characters) | | | 1005 | [Maximize Sum of Array After K Negations](https://leetcode.com/problems/maximize-sum-of-array-after-k-negations) | | diff --git a/src/FindTheTownJudge.java b/src/FindTheTownJudge.java new file mode 100644 index 0000000..26d260c --- /dev/null +++ b/src/FindTheTownJudge.java @@ -0,0 +1,18 @@ +import java.util.HashMap; +import java.util.Map; + +public class FindTheTownJudge { + public int findJudge(int n, int[][] trust) { + Map inDegreeTrust = new HashMap<>(); + Map outDegreeTrust = new HashMap<>(); + for (int[] person : trust) { + inDegreeTrust.put(person[1], inDegreeTrust.getOrDefault(person[1], 0) + 1); + outDegreeTrust.put(person[0], inDegreeTrust.getOrDefault(person[0], 0) + 1); + } + for (int i = 1 ; i <= n ; i++) { + if (outDegreeTrust.getOrDefault(i, 0) == 0 && inDegreeTrust.getOrDefault(i, 0) == n - 1) + return i; + } + return -1; + } +} From 742c396dbba6c287e9b129be4a83a29cbc3efbab Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 30 Nov 2021 11:30:37 +0100 Subject: [PATCH 249/947] solves rook captures --- README.md | 2 +- src/AvailableCapturesForRook.java | 64 +++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 src/AvailableCapturesForRook.java diff --git a/README.md b/README.md index c5c8b03..44d9067 100644 --- a/README.md +++ b/README.md @@ -268,7 +268,7 @@ | 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) | | 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) | | +| 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) | | | 1005 | [Maximize Sum of Array After K Negations](https://leetcode.com/problems/maximize-sum-of-array-after-k-negations) | | | 1009 | [Complement of Base 10 Integer](https://leetcode.com/problems/complement-of-base-10-integer) | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/NumberComplement.java) | diff --git a/src/AvailableCapturesForRook.java b/src/AvailableCapturesForRook.java new file mode 100644 index 0000000..a5142c1 --- /dev/null +++ b/src/AvailableCapturesForRook.java @@ -0,0 +1,64 @@ +public class AvailableCapturesForRook { + private static final class Position { + private final int row; + private final int column; + + private Position(int row, int column) { + this.row = row; + this.column = column; + } + } + + private static final char ROOK = 'R'; + private static final char BISHOP = 'B'; + private static final char PAWN = 'p'; + + public int numRookCaptures(char[][] board) { + Position rookPosition = getPosition(board, ROOK); + return (canCapturePawnInNorth(board, rookPosition) ? 1 : 0) + + (canCapturePawnInWest(board, rookPosition) ? 1 : 0) + + (canCapturePawnInSouth(board, rookPosition) ? 1 : 0) + + (canCapturePawnInEast(board, rookPosition) ? 1 : 0); + } + + private Position getPosition(char[][] board, char piece) { + for (int row = 0 ; row < board.length ; row++) { + for (int column = 0 ; column < board[0].length ; column++) { + if (board[row][column] == piece) return new Position(row, column); + } + } + return null; + } + + private boolean canCapturePawnInNorth(char[][] board, Position rookPosition) { + for (int row = rookPosition.row - 1 ; row >= 0 ; row--) { + if (board[row][rookPosition.column] == BISHOP) return false; + if (board[row][rookPosition.column] == PAWN) return true; + } + return false; + } + + private boolean canCapturePawnInSouth(char[][] board, Position rookPosition) { + for (int row = rookPosition.row + 1 ; row < board.length ; row++) { + if (board[row][rookPosition.column] == BISHOP) return false; + if (board[row][rookPosition.column] == PAWN) return true; + } + return false; + } + + private boolean canCapturePawnInWest(char[][] board, Position rookPosition) { + for (int column = rookPosition.column + 1 ; column < board[0].length ; column++) { + if (board[rookPosition.row][column] == BISHOP) return false; + if (board[rookPosition.row][column] == PAWN) return true; + } + return false; + } + + private boolean canCapturePawnInEast(char[][] board, Position rookPosition) { + for (int column = rookPosition.column - 1 ; column >= 0 ; column--) { + if (board[rookPosition.row][column] == BISHOP) return false; + if (board[rookPosition.row][column] == PAWN) return true; + } + return false; + } +} From 412ec9d1183ac91ace3414b74f228ea7758d93cf Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 30 Nov 2021 11:45:36 +0100 Subject: [PATCH 250/947] solves find common characters --- README.md | 2 +- src/FindCommonCharacters.java | 38 +++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/FindCommonCharacters.java diff --git a/README.md b/README.md index 44d9067..a331886 100644 --- a/README.md +++ b/README.md @@ -269,7 +269,7 @@ | 993 | [Cousins in Binary Tree](https://leetcode.com/problems/cousins-in-binary-tree) | [![Java](assets/java.png)](src/CousinsInBinaryTree.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) | | +| 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) | | | 1009 | [Complement of Base 10 Integer](https://leetcode.com/problems/complement-of-base-10-integer) | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.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) | | diff --git a/src/FindCommonCharacters.java b/src/FindCommonCharacters.java new file mode 100644 index 0000000..1fb2e71 --- /dev/null +++ b/src/FindCommonCharacters.java @@ -0,0 +1,38 @@ +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class FindCommonCharacters { + public List commonChars(String[] words) { + Map commonChars = getCharsFrequency(words[0]); + Map wordChars; + for (int i = 1 ; i < words.length ; i++) { + wordChars = getCharsFrequency(words[i]); + for (char letter : commonChars.keySet()) { + commonChars.put(letter, Math.min(commonChars.get(letter), wordChars.getOrDefault(letter, 0))); + } + } + return toList(commonChars); + } + + private List toList(Map characters) { + List result = new ArrayList<>(); + for (Map.Entry entry : characters.entrySet()) { + if (entry.getValue() > 0) { + for (int i = 0 ; i < entry.getValue() ; i++) result.add(entry.getKey() + ""); + } + } + return result; + } + + private Map getCharsFrequency(String string) { + Map result = new HashMap<>(); + char character; + for (int index = 0 ; index < string.length() ; index++) { + character = string.charAt(index); + result.put(character, result.getOrDefault(character, 0) + 1); + } + return result; + } +} From b7929f72f61a6ed03c47d9b1dc7ba16e233a4d8f Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Wed, 1 Dec 2021 19:10:16 +0100 Subject: [PATCH 251/947] solves maximize sum of array in java --- README.md | 2 +- src/MaximizeSumOfArrayAfterKNegations.java | 26 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/MaximizeSumOfArrayAfterKNegations.java diff --git a/README.md b/README.md index a331886..083ba50 100644 --- a/README.md +++ b/README.md @@ -270,7 +270,7 @@ | 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) | | +| 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](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.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) | | | 1013 | [Partition Array into Three Parts with equal Sum](https://leetcode.com/problems/partition-array-into-three-parts-with-equal-sum) | | diff --git a/src/MaximizeSumOfArrayAfterKNegations.java b/src/MaximizeSumOfArrayAfterKNegations.java new file mode 100644 index 0000000..d0b2850 --- /dev/null +++ b/src/MaximizeSumOfArrayAfterKNegations.java @@ -0,0 +1,26 @@ +import java.util.Arrays; + +public class MaximizeSumOfArrayAfterKNegations { + public int largestSumAfterKNegations(int[] nums, int k) { + Arrays.sort(nums); + int sum = 0, index = 0; + for ( ; index < nums.length && k > 0 ; index++) { + if (nums[index] < 0) { + sum -= nums[index]; + k--; + } else break; + } + if ((k & 1) == 1) { + if (index < nums.length) { + if (index == 0) sum -= nums[index]; + else if (-nums[index - 1] < nums[index]) sum += 2 * nums[index - 1] + nums[index]; + else sum -= nums[index]; + index++; + } else return sum + 2 * nums[nums.length - 1]; + } + for ( ; index < nums.length ; index++) { + sum += nums[index]; + } + return sum; + } +} From cddda4b6aa05282bfc022ad7ef4b6e3eb428ff80 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 1 Dec 2021 23:20:22 +0100 Subject: [PATCH 252/947] solves partition array into thre parts --- README.md | 8 ++++---- ...artitionArrayIntoThreePartsWithEqualSum.java | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 src/PartitionArrayIntoThreePartsWithEqualSum.java diff --git a/README.md b/README.md index 083ba50..d83b367 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-223/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-223/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-231/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-231/2081-1abc9c.svg) ![problems-solved-python](https://img.shields.io/badge/Python-186/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) @@ -271,8 +271,8 @@ | 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](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.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) | | +| 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) | | | 1021 | [Remove Outermost Parenthesis](https://leetcode.com/problems/remove-outermost-parentheses) | | diff --git a/src/PartitionArrayIntoThreePartsWithEqualSum.java b/src/PartitionArrayIntoThreePartsWithEqualSum.java new file mode 100644 index 0000000..7bdba86 --- /dev/null +++ b/src/PartitionArrayIntoThreePartsWithEqualSum.java @@ -0,0 +1,17 @@ +import java.util.Arrays; + +public class PartitionArrayIntoThreePartsWithEqualSum { + public boolean canThreePartsEqualSum(int[] array) { + final int totalSum = Arrays.stream(array).sum(); + if (totalSum % 3 != 0) return false; + int count = 0; + for (int index = 0, sum = 0; index < array.length - 1 ; index++) { + sum += array[index]; + if (sum == totalSum / 3) { + count++; + sum = 0; + } + } + return count >= 2; + } +} From 45a5f1d14aeb74782a69dee19f91657439197ac8 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 1 Dec 2021 23:48:31 +0100 Subject: [PATCH 253/947] solves binary prefix divisible by 5 --- README.md | 758 +++++++++++++++--------------- src/BinaryPrefixDivisibleBy5.java | 23 + 2 files changed, 402 insertions(+), 379 deletions(-) create mode 100644 src/BinaryPrefixDivisibleBy5.java diff --git a/README.md b/README.md index d83b367..84de20b 100644 --- a/README.md +++ b/README.md @@ -9,382 +9,382 @@ 🔒 = 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) | -| 7 | [Reverse Integer](https://leetcode.com/problems/reverse-integer/) | [![Java](assets/java.png)](src/ReverseInteger.java) [![Python](assets/python.png)](python/reverse_integer.py) | [![java-yt](assets/java-yt.png)](https://youtu.be/7bOhyl5lWjI) [![python-yt](assets/python-yt.png)](https://youtu.be/lmLG30TLcSg) | -| 9 | [PalindromeNumber](https://leetcode.com/problems/palindrome-number/) | [![Java](assets/java.png)](src/PalindromeNumber.java) [![Python](assets/python.png)](python/palindrome_number.py) | | -| 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) | -| 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) | -| 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) | -| 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) | -| 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) | -| 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) | -| 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) | -| 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) | -| 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) | -| 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) | -| 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) | -| 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) | -| 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) | -| 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) | -| 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) | -| 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) | -| 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) | -| 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) | -| 136 | [Single Number](https://leetcode.com/problems/single-number) | [![Java](assets/java.png)](src/SingleNumber.java) [![Python](assets/python.png)](python/single_number.py) | -| 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) | -| 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) | -| 155 | [Min Stack](https://leetcode.com/problems/min-stack) | [![Java](assets/java.png)](src/MinStack.java) [![Python](assets/python.png)](python/min_stack.py) | -| 157 | [Read N Characters Given Read4](https://leetcode.com/problems/read-n-characters-given-read4) | | -| 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) | -| 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) | -| 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) | -| 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 Lists](https://leetcode.com/problems/reverse-linked-list) | [![Java](assets/java.png)](src/ReverseLinkedList.java) [![Python](assets/python.png)](python/reverse_linked_list.py) | -| 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate) | [![Java](assets/java.png)](src/ContainsDuplicate.java) [![Python](assets/python.png)](python/contains_duplicate.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) | -| 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) | -| 226 | [Summary Ranges](https://leetcode.com/problems/summary-ranges/) | [![Java](assets/java.png)](src/SummaryRanges.java) [![Python](assets/python.png)](python/summary_ranges.py) | -| 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) | -| 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) | -| 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) | | -| 246 | 🔒 [Strobogramatic Number](https://leetcode.com/problems/strobogrammatic-number) | | -| 252 | 🔒 [Meeting Rooms](https://leetcode.com/problems/meeting-rooms) | | -| 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) | -| 263 | [Ugly Number](https://leetcode.com/problems/ugly-number) | [![Java](assets/java.png)](src/UglyNumber.java) [![Python](assets/python.png)](python/ugly_number.py) | -| 266 | 🔒 [Palindrome Permutation](https://leetcode.com/problems/palindrome-permutation) | | -| 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) | | -| 276 | 🔒 [Paint Fence](https://leetcode.com/problems/paint-fence) | | -| 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) | -| 283 | [Move Zeroes](https://leetcode.com/problems/move-zeroes) | [![Java](assets/java.png)](src/MoveZeros.java) [![Python](assets/python.png)](python/move_zeroes.py) | -| 290 | [Word Pattern](https://leetcode.com/problems/word-pattern) | [![Java](assets/java.png)](src/WordPattern.java) [![Python](assets/python.png)](python/word_pattern.py) | -| 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) | | -| 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) | -| 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) | -| 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) | -| 326 | [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) | | -| 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) | -| 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) | | -| 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) | -| 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) | | -| 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) | | -| 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) | -| 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) | -| 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) | -| 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) | | -| 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) | -| 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) | | -| 1021 | [Remove Outermost Parenthesis](https://leetcode.com/problems/remove-outermost-parentheses) | | -| 1022 | [Sum of Root to Leaf Binary Numbers](https://leetcode.com/problems/sum-of-root-to-leaf-binary-numbers) | | -| 1025 | [Divisor Game](https://leetcode.com/problems/divisor-game) | | -| 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) | | -| 1033 | [Moving Stones Until Consecutive](https://leetcode.com/problems/moving-stones-until-consecutive) | | -| 1037 | [Valid Boomerang](https://leetcode.com/problems/valid-boomerang) | | -| 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) | | -| 1047 | [Remove All adjacent Duplicates in String](https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string) | | -| 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) | | -| 1078 | [Occurrence After Bigram](https://leetcode.com/problems/occurrences-after-bigram) | | -| 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) | | -| 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) | | -| 1108 | [Defanging an IP Address](https://leetcode.com/problems/defanging-an-ip-address) | | -| 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) | | -| 1128 | [Number of Equivalent Domino Pairs](https://leetcode.com/problems/number-of-equivalent-domino-pairs) | | -| 1133 | [Largest Unique Number](https://leetcode.com/problems/largest-unique-number) | | -| 1134 | [Armstrong Number](https://leetcode.com/problems/armstrong-number) | | -| 1137 | [Nth Tribonacci Number]() | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 1185 | [Day of the Week](https://leetcode.com/problems/day-of-the-week) | | -| 1189 | [Maximum Number of Balloons](https://leetcode.com/problems/maximum-number-of-balloons) | | -| 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) | | -| 1207 | [Unique Number of Occurrences](https://leetcode.com/problems/unique-number-of-occurrences) | | -| 1213 | [Intersection of Three Sorted Arrays](https://leetcode.com/problems/intersection-of-three-sorted-arrays) | | -| 1217 | [Play With Chips](https://leetcode.com/problems/play-with-chips) | | -| 1221 | [Split A String In Balanced Strings](https://leetcode.com/problems/split-a-string-in-balanced-strings) | | -| 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) | | -| 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) | | -| 1252 | [Cells With Odd Values In Matrix](https://leetcode.com/problems/cells-with-odd-values-in-a-matrix) | | -| 1260 | [Shift 2D Grid](https://leetcode.com/problems/shift-2d-grid) | | -| 1266 | [Minimum Time Visiting All Points](https://leetcode.com/problems/minimum-time-visiting-all-points) | | -| 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) | | -| 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) | | -| 1287 | [Element Appearing More Than 25% in Sorted Array](https://leetcode.com/problems/element-appearing-more-than-25-in-sorted-array) | | -| 1290 | [Convert Binary Number In A Linked List to Integer](https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer) | | -| 1295 | [Find Numbers With Even Numbers of Digits](https://leetcode.com/problems/find-numbers-with-even-number-of-digits) | | -| 1299 | [Replace Elements With Greatest Element on Right Side](https://leetcode.com/problems/replace-elements-with-greatest-element-on-right-side) | | -| 1304 | [Find N Unique Integers Sum Up To Zero](https://leetcode.com/problems/find-n-unique-integers-sum-up-to-zero) | | -| 1309 | [Decrypt String From Alphabet To Integer Mapping](https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping) | | -| 1313 | [Decompress Run-Length Encoded Strings](https://leetcode.com/problems/decompress-run-length-encoded-list) | | -| 1317 | [Convert Integer to Sum Of Two Non-Zero Integers](https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers) | | -| 1323 | [Maximum 69 Number](https://leetcode.com/problems/maximum-69-number) | | -| 1331 | [Rank Transform of An Array](https://leetcode.com/problems/rank-transform-of-an-array) | | -| 1332 | [Remove Palindromic Subsequences](https://leetcode.com/problems/remove-palindromic-subsequences) | | -| 1337 | [The K Weakest Rows In A Matrix](https://leetcode.com/problems/the-k-weakest-rows-in-a-matrix) | | -| 1342 | [Number of Steps to Reduce a Number to Zero](https://leetcode.com/problems/number-of-steps-to-reduce-a-number-to-zero) | | -| 1346 | [Check if N and It's Double Exist](https://leetcode.com/problems/check-if-n-and-its-double-exist) | | -| 1351 | [Count Negative Numbers In A Sorted Matrix](https://leetcode.com/problems/count-negative-numbers-in-a-sorted-matrix) | | -| 1356 | [Sort Integers by Number of 1 Bits](https://leetcode.com/problems/sort-integers-by-the-number-of-1-bits) | | -| 1360 | [Number of Days Between Two Dates](https://leetcode.com/problems/number-of-days-between-two-dates) | | -| 1365 | [How Many Numbers Are Smaller Than Current Number](https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number) | | -| 1370 | [Increasing Decreasing String](https://leetcode.com/problems/increasing-decreasing-string) | | -| 1374 | [Generate A String With Characters That Have Odd Count](https://leetcode.com/problems/generate-a-string-with-characters-that-have-odd-counts) | | -| 1380 | [Lucky Numbers In A Matrix](https://leetcode.com/problems/lucky-numbers-in-a-matrix) | | -| 1385 | [Find The Distance Value Between 2 Arrays](https://leetcode.com/problems/find-the-distance-value-between-two-arrays) | | -| 1389 | [Create Target Array in Given Order](https://leetcode.com/problems/create-target-array-in-the-given-order) | | -| 1394 | [Find Lucky Integer In An Array](https://leetcode.com/problems/find-lucky-integer-in-an-array) | | -| 1399 | [Count Largest Group](https://leetcode.com/problems/count-largest-group) | | -| 1403 | [Minimum Subsequence in Non-Increasing Order](https://leetcode.com/problems/minimum-subsequence-in-non-increasing-order) | | -| 1408 | [String Matching In An Array](https://leetcode.com/problems/string-matching-in-an-array) | | -| 1413 | [Minimum Value To Get Positive Step By Step Sum](https://leetcode.com/problems/minimum-value-to-get-positive-step-by-step-sum) | | -| 1417 | [Reformat The String](https://leetcode.com/problems/reformat-the-string) | | -| 1422 | [Maximum Score After Splitting A String](https://leetcode.com/problems/maximum-score-after-splitting-a-string) | | -| 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) | | -| 1436 | [Destination City](https://leetcode.com/problems/destination-city) | | -| 1441 | [Build An Array With Stack Operation](https://leetcode.com/problems/build-an-array-with-stack-operations) | | -| 1446 | [Consecutive Characters](https://leetcode.com/problems/consecutive-characters) | | -| 1450 | [Number of Students Doing Homework at Given Time](https://leetcode.com/problems/number-of-students-doing-homework-at-a-given-time) | | -| 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) | | -| 1460 | [Make 2 Arrays Equal by Reversing Sub Arrays](https://leetcode.com/problems/make-two-arrays-equal-by-reversing-sub-arrays) | | -| 1464 | [Maximum Product of 2 Elements in Array](https://leetcode.com/problems/maximum-product-of-two-elements-in-an-array) | | -| 1469 | [Find All Lonely Nodes](https://leetcode.com/problems/find-all-the-lonely-nodes) | | -| 1470 | [Shuffle The Array](https://leetcode.com/problems/shuffle-the-array) | | -| 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) | | -| 1480 | [Running Sum of 1D Array](https://leetcode.com/problems/running-sum-of-1d-array) | | -| 1486 | [XOR Operations in An Array](https://leetcode.com/problems/xor-operation-in-an-array) | | -| 1491 | [Average Salary Excluding the Minimum and Maximum Salary](https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary) | | -| 1496 | [Path Crossing](https://leetcode.com/problems/path-crossing) | | -| 1502 | [Can Make Arithmetic Progression From Sequence](https://leetcode.com/problems/can-make-arithmetic-progression-from-sequence) | | -| 1507 | [Reformat Date](https://leetcode.com/problems/reformat-date) | | -| 1512 | [Number of Good Pairs](https://leetcode.com/problems/number-of-good-pairs) | | -| 1518 | [Water Bottles](https://leetcode.com/problems/water-bottles) | | -| 1523 | [Count Odd Numbers In Interval Range](https://leetcode.com/problems/count-odd-numbers-in-an-interval-range) | | -| 1528 | [Shuffle Strings](https://leetcode.com/problems/shuffle-string) | | -| 1534 | [Count Good Triplets](https://leetcode.com/problems/count-good-triplets) | | -| 1539 | [Kth Missing Positive Number](https://leetcode.com/problems/kth-missing-positive-number) | | -| 1544 | [Make The String Great](https://leetcode.com/problems/make-the-string-great) | | +| # | 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) | +| 7 | [Reverse Integer](https://leetcode.com/problems/reverse-integer/) | [![Java](assets/java.png)](src/ReverseInteger.java) [![Python](assets/python.png)](python/reverse_integer.py) | [![java-yt](assets/java-yt.png)](https://youtu.be/7bOhyl5lWjI) [![python-yt](assets/python-yt.png)](https://youtu.be/lmLG30TLcSg) | +| 9 | [PalindromeNumber](https://leetcode.com/problems/palindrome-number/) | [![Java](assets/java.png)](src/PalindromeNumber.java) [![Python](assets/python.png)](python/palindrome_number.py) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 136 | [Single Number](https://leetcode.com/problems/single-number) | [![Java](assets/java.png)](src/SingleNumber.java) [![Python](assets/python.png)](python/single_number.py) | | +| 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) | | +| 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) | | +| 155 | [Min Stack](https://leetcode.com/problems/min-stack) | [![Java](assets/java.png)](src/MinStack.java) [![Python](assets/python.png)](python/min_stack.py) | | +| 157 | [Read N Characters Given Read4](https://leetcode.com/problems/read-n-characters-given-read4) | | | +| 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) | | +| 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) | | +| 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) | | +| 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 Lists](https://leetcode.com/problems/reverse-linked-list) | [![Java](assets/java.png)](src/ReverseLinkedList.java) [![Python](assets/python.png)](python/reverse_linked_list.py) | | +| 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate) | [![Java](assets/java.png)](src/ContainsDuplicate.java) [![Python](assets/python.png)](python/contains_duplicate.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) | | +| 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) | | +| 226 | [Summary Ranges](https://leetcode.com/problems/summary-ranges/) | [![Java](assets/java.png)](src/SummaryRanges.java) [![Python](assets/python.png)](python/summary_ranges.py) | | +| 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) | | +| 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) | | +| 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) | | | +| 246 | 🔒 [Strobogramatic Number](https://leetcode.com/problems/strobogrammatic-number) | | | +| 252 | 🔒 [Meeting Rooms](https://leetcode.com/problems/meeting-rooms) | | | +| 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) | | +| 263 | [Ugly Number](https://leetcode.com/problems/ugly-number) | [![Java](assets/java.png)](src/UglyNumber.java) [![Python](assets/python.png)](python/ugly_number.py) | | +| 266 | 🔒 [Palindrome Permutation](https://leetcode.com/problems/palindrome-permutation) | | | +| 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) | | | +| 276 | 🔒 [Paint Fence](https://leetcode.com/problems/paint-fence) | | | +| 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) | | +| 283 | [Move Zeroes](https://leetcode.com/problems/move-zeroes) | [![Java](assets/java.png)](src/MoveZeros.java) [![Python](assets/python.png)](python/move_zeroes.py) | | +| 290 | [Word Pattern](https://leetcode.com/problems/word-pattern) | [![Java](assets/java.png)](src/WordPattern.java) [![Python](assets/python.png)](python/word_pattern.py) | | +| 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) | | | +| 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) | | +| 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) | | +| 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) | | +| 326 | [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) | | | +| 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) | | +| 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) | | | +| 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) | | +| 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) | | | +| 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) | | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | | +| 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) | | +| 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) | | +| 1021 | [Remove Outermost Parenthesis](https://leetcode.com/problems/remove-outermost-parentheses) | | | +| 1022 | [Sum of Root to Leaf Binary Numbers](https://leetcode.com/problems/sum-of-root-to-leaf-binary-numbers) | | | +| 1025 | [Divisor Game](https://leetcode.com/problems/divisor-game) | | | +| 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) | | | +| 1033 | [Moving Stones Until Consecutive](https://leetcode.com/problems/moving-stones-until-consecutive) | | | +| 1037 | [Valid Boomerang](https://leetcode.com/problems/valid-boomerang) | | | +| 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) | | | +| 1047 | [Remove All adjacent Duplicates in String](https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string) | | | +| 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) | | | +| 1078 | [Occurrence After Bigram](https://leetcode.com/problems/occurrences-after-bigram) | | | +| 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) | | | +| 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) | | | +| 1108 | [Defanging an IP Address](https://leetcode.com/problems/defanging-an-ip-address) | | | +| 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) | | | +| 1128 | [Number of Equivalent Domino Pairs](https://leetcode.com/problems/number-of-equivalent-domino-pairs) | | | +| 1133 | [Largest Unique Number](https://leetcode.com/problems/largest-unique-number) | | | +| 1134 | [Armstrong Number](https://leetcode.com/problems/armstrong-number) | | | +| 1137 | [Nth Tribonacci Number]() | | | +| 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) | | | +| 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) | | | +| 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) | | | +| 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) | | | +| 1185 | [Day of the Week](https://leetcode.com/problems/day-of-the-week) | | | +| 1189 | [Maximum Number of Balloons](https://leetcode.com/problems/maximum-number-of-balloons) | | | +| 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) | | | +| 1207 | [Unique Number of Occurrences](https://leetcode.com/problems/unique-number-of-occurrences) | | | +| 1213 | [Intersection of Three Sorted Arrays](https://leetcode.com/problems/intersection-of-three-sorted-arrays) | | | +| 1217 | [Play With Chips](https://leetcode.com/problems/play-with-chips) | | | +| 1221 | [Split A String In Balanced Strings](https://leetcode.com/problems/split-a-string-in-balanced-strings) | | | +| 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) | | | +| 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) | | | +| 1252 | [Cells With Odd Values In Matrix](https://leetcode.com/problems/cells-with-odd-values-in-a-matrix) | | | +| 1260 | [Shift 2D Grid](https://leetcode.com/problems/shift-2d-grid) | | | +| 1266 | [Minimum Time Visiting All Points](https://leetcode.com/problems/minimum-time-visiting-all-points) | | | +| 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) | | | +| 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) | | | +| 1287 | [Element Appearing More Than 25% in Sorted Array](https://leetcode.com/problems/element-appearing-more-than-25-in-sorted-array) | | | +| 1290 | [Convert Binary Number In A Linked List to Integer](https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer) | | | +| 1295 | [Find Numbers With Even Numbers of Digits](https://leetcode.com/problems/find-numbers-with-even-number-of-digits) | | | +| 1299 | [Replace Elements With Greatest Element on Right Side](https://leetcode.com/problems/replace-elements-with-greatest-element-on-right-side) | | | +| 1304 | [Find N Unique Integers Sum Up To Zero](https://leetcode.com/problems/find-n-unique-integers-sum-up-to-zero) | | | +| 1309 | [Decrypt String From Alphabet To Integer Mapping](https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping) | | | +| 1313 | [Decompress Run-Length Encoded Strings](https://leetcode.com/problems/decompress-run-length-encoded-list) | | | +| 1317 | [Convert Integer to Sum Of Two Non-Zero Integers](https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers) | | | +| 1323 | [Maximum 69 Number](https://leetcode.com/problems/maximum-69-number) | | | +| 1331 | [Rank Transform of An Array](https://leetcode.com/problems/rank-transform-of-an-array) | | | +| 1332 | [Remove Palindromic Subsequences](https://leetcode.com/problems/remove-palindromic-subsequences) | | | +| 1337 | [The K Weakest Rows In A Matrix](https://leetcode.com/problems/the-k-weakest-rows-in-a-matrix) | | | +| 1342 | [Number of Steps to Reduce a Number to Zero](https://leetcode.com/problems/number-of-steps-to-reduce-a-number-to-zero) | | | +| 1346 | [Check if N and It's Double Exist](https://leetcode.com/problems/check-if-n-and-its-double-exist) | | | +| 1351 | [Count Negative Numbers In A Sorted Matrix](https://leetcode.com/problems/count-negative-numbers-in-a-sorted-matrix) | | | +| 1356 | [Sort Integers by Number of 1 Bits](https://leetcode.com/problems/sort-integers-by-the-number-of-1-bits) | | | +| 1360 | [Number of Days Between Two Dates](https://leetcode.com/problems/number-of-days-between-two-dates) | | | +| 1365 | [How Many Numbers Are Smaller Than Current Number](https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number) | | | +| 1370 | [Increasing Decreasing String](https://leetcode.com/problems/increasing-decreasing-string) | | | +| 1374 | [Generate A String With Characters That Have Odd Count](https://leetcode.com/problems/generate-a-string-with-characters-that-have-odd-counts) | | | +| 1380 | [Lucky Numbers In A Matrix](https://leetcode.com/problems/lucky-numbers-in-a-matrix) | | | +| 1385 | [Find The Distance Value Between 2 Arrays](https://leetcode.com/problems/find-the-distance-value-between-two-arrays) | | | +| 1389 | [Create Target Array in Given Order](https://leetcode.com/problems/create-target-array-in-the-given-order) | | | +| 1394 | [Find Lucky Integer In An Array](https://leetcode.com/problems/find-lucky-integer-in-an-array) | | | +| 1399 | [Count Largest Group](https://leetcode.com/problems/count-largest-group) | | | +| 1403 | [Minimum Subsequence in Non-Increasing Order](https://leetcode.com/problems/minimum-subsequence-in-non-increasing-order) | | | +| 1408 | [String Matching In An Array](https://leetcode.com/problems/string-matching-in-an-array) | | | +| 1413 | [Minimum Value To Get Positive Step By Step Sum](https://leetcode.com/problems/minimum-value-to-get-positive-step-by-step-sum) | | | +| 1417 | [Reformat The String](https://leetcode.com/problems/reformat-the-string) | | | +| 1422 | [Maximum Score After Splitting A String](https://leetcode.com/problems/maximum-score-after-splitting-a-string) | | | +| 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) | | | +| 1436 | [Destination City](https://leetcode.com/problems/destination-city) | | | +| 1441 | [Build An Array With Stack Operation](https://leetcode.com/problems/build-an-array-with-stack-operations) | | | +| 1446 | [Consecutive Characters](https://leetcode.com/problems/consecutive-characters) | | | +| 1450 | [Number of Students Doing Homework at Given Time](https://leetcode.com/problems/number-of-students-doing-homework-at-a-given-time) | | | +| 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) | | | +| 1460 | [Make 2 Arrays Equal by Reversing Sub Arrays](https://leetcode.com/problems/make-two-arrays-equal-by-reversing-sub-arrays) | | | +| 1464 | [Maximum Product of 2 Elements in Array](https://leetcode.com/problems/maximum-product-of-two-elements-in-an-array) | | | +| 1469 | [Find All Lonely Nodes](https://leetcode.com/problems/find-all-the-lonely-nodes) | | | +| 1470 | [Shuffle The Array](https://leetcode.com/problems/shuffle-the-array) | | | +| 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) | | | +| 1480 | [Running Sum of 1D Array](https://leetcode.com/problems/running-sum-of-1d-array) | | | +| 1486 | [XOR Operations in An Array](https://leetcode.com/problems/xor-operation-in-an-array) | | | +| 1491 | [Average Salary Excluding the Minimum and Maximum Salary](https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary) | | | +| 1496 | [Path Crossing](https://leetcode.com/problems/path-crossing) | | | +| 1502 | [Can Make Arithmetic Progression From Sequence](https://leetcode.com/problems/can-make-arithmetic-progression-from-sequence) | | | +| 1507 | [Reformat Date](https://leetcode.com/problems/reformat-date) | | | +| 1512 | [Number of Good Pairs](https://leetcode.com/problems/number-of-good-pairs) | | | +| 1518 | [Water Bottles](https://leetcode.com/problems/water-bottles) | | | +| 1523 | [Count Odd Numbers In Interval Range](https://leetcode.com/problems/count-odd-numbers-in-an-interval-range) | | | +| 1528 | [Shuffle Strings](https://leetcode.com/problems/shuffle-string) | | | +| 1534 | [Count Good Triplets](https://leetcode.com/problems/count-good-triplets) | | | +| 1539 | [Kth Missing Positive Number](https://leetcode.com/problems/kth-missing-positive-number) | | | +| 1544 | [Make The String Great](https://leetcode.com/problems/make-the-string-great) | | | diff --git a/src/BinaryPrefixDivisibleBy5.java b/src/BinaryPrefixDivisibleBy5.java new file mode 100644 index 0000000..d70c01d --- /dev/null +++ b/src/BinaryPrefixDivisibleBy5.java @@ -0,0 +1,23 @@ +import java.util.ArrayList; +import java.util.List; + +public class BinaryPrefixDivisibleBy5 { + private static final int[][] stateFlow = { + {0, 1}, + {2, 3}, + {4, 0}, + {1, 2}, + {3, 4} + }; + + public List prefixesDivBy5(int[] binaryArray) { + final List result = new ArrayList<>(); + int state = binaryArray[0]; + for (int index = 0 ; index < binaryArray.length - 1 ; index++) { + result.add(state == 0); + state = stateFlow[state][binaryArray[index + 1]]; + } + result.add(state == 0); + return result; + } +} From 87975d30cffa5dd35476b352dacd95d462dba5d6 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 2 Dec 2021 00:01:44 +0100 Subject: [PATCH 254/947] solves remove outermost parantheses --- README.md | 2 +- src/RemoveOutermostParentheses.java | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/RemoveOutermostParentheses.java diff --git a/README.md b/README.md index 84de20b..d1a6230 100644 --- a/README.md +++ b/README.md @@ -275,7 +275,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) | | -| 1021 | [Remove Outermost Parenthesis](https://leetcode.com/problems/remove-outermost-parentheses) | | | +| 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) | | | | 1025 | [Divisor Game](https://leetcode.com/problems/divisor-game) | | | | 1029 | [Two City Scheduling](https://leetcode.com/problems/two-city-scheduling) | | | diff --git a/src/RemoveOutermostParentheses.java b/src/RemoveOutermostParentheses.java new file mode 100644 index 0000000..569c221 --- /dev/null +++ b/src/RemoveOutermostParentheses.java @@ -0,0 +1,13 @@ +public class RemoveOutermostParentheses { + public String removeOuterParentheses(String s) { + StringBuilder result = new StringBuilder(); + for (int index = 0, level = 0 ; index < s.length() ; index++) { + if (level != 0 && (level != -1 || s.charAt(index) != ')')) { + result.append(s.charAt(index)); + } + if (s.charAt(index) == '(') level--; + else level++; + } + return result.toString(); + } +} From 17c876e18226fc18a5ef1ebeb2d9f81ea9c1ca2c Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 2 Dec 2021 00:12:25 +0100 Subject: [PATCH 255/947] solves sum of root to leaf binary numbers --- README.md | 2 +- src/SumOfRootToLeafBinaryNumbers.java | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/SumOfRootToLeafBinaryNumbers.java diff --git a/README.md b/README.md index d1a6230..6a561b8 100644 --- a/README.md +++ b/README.md @@ -276,7 +276,7 @@ | 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) | | | 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) | | | +| 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) | | | | 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) | | | diff --git a/src/SumOfRootToLeafBinaryNumbers.java b/src/SumOfRootToLeafBinaryNumbers.java new file mode 100644 index 0000000..5abc300 --- /dev/null +++ b/src/SumOfRootToLeafBinaryNumbers.java @@ -0,0 +1,11 @@ +public class SumOfRootToLeafBinaryNumbers { + public int sumRootToLeaf(TreeNode root) { + return sumRootToLeaf(root, 0); + } + + private int sumRootToLeaf(TreeNode root, int sum) { + if (root == null) return 0; + if (root.left == null && root.right == null) return sum + root.val; + return sumRootToLeaf(root.left, (sum + root.val) << 1) + sumRootToLeaf(root.right, (sum + root.val) << 1); + } +} From 646e705592e1ce66c0aad0189c133a29a947a631 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 2 Dec 2021 00:24:17 +0100 Subject: [PATCH 256/947] solves divisor game --- README.md | 2 +- src/DivisorGame.java | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 src/DivisorGame.java diff --git a/README.md b/README.md index 6a561b8..e883f51 100644 --- a/README.md +++ b/README.md @@ -277,7 +277,7 @@ | 1018 | [Binary Prefix Divisible by 5](https://leetcode.com/problems/binary-prefix-divisible-by-5) | [![Java](assets/java.png)](src/BinaryPrefixDivisibleBy5.java) | | | 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) | | | +| 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) | | | | 1033 | [Moving Stones Until Consecutive](https://leetcode.com/problems/moving-stones-until-consecutive) | | | diff --git a/src/DivisorGame.java b/src/DivisorGame.java new file mode 100644 index 0000000..d21f85c --- /dev/null +++ b/src/DivisorGame.java @@ -0,0 +1,5 @@ +public class DivisorGame { + public boolean divisorGame(int n) { + return (n & 1) == 0; + } +} From 84097c06ec7e17216afd2261d9e78ebab685642e Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 2 Dec 2021 00:43:03 +0100 Subject: [PATCH 257/947] solves matrix cells in distance order --- README.md | 2 +- src/MatrixCellsInDistanceOrder.java | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/MatrixCellsInDistanceOrder.java diff --git a/README.md b/README.md index e883f51..5df356d 100644 --- a/README.md +++ b/README.md @@ -279,7 +279,7 @@ | 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) | | | +| 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) | | | | 1042 | [Flower Planting with no Adjacent](https://leetcode.com/problems/flower-planting-with-no-adjacent) | | | diff --git a/src/MatrixCellsInDistanceOrder.java b/src/MatrixCellsInDistanceOrder.java new file mode 100644 index 0000000..536c583 --- /dev/null +++ b/src/MatrixCellsInDistanceOrder.java @@ -0,0 +1,26 @@ +import java.util.LinkedList; +import java.util.Queue; + +public class MatrixCellsInDistanceOrder { + public int[][] allCellsDistOrder(final int rows, final int columns, int rCenter, int cCenter) { + int[][] result = new int[rows * columns][2]; + final Queue positions = new LinkedList<>(); + final boolean[][] visited = new boolean[rows][columns]; + positions.add(new int[] {rCenter, cCenter}); + int k = 0, row, column; + while (!positions.isEmpty()) { + int[] position = positions.poll(); + row = position[0]; + column = position[1]; + if (row < 0 || row >= rows || column < 0 || column >= columns) continue; + if (visited[row][column]) continue; + visited[row][column] = true; + result[k++] = position; + positions.add(new int[] {row - 1, column}); + positions.add(new int[] {row, column + 1}); + positions.add(new int[] {row + 1, column}); + positions.add(new int[] {row, column - 1}); + } + return result; + } +} From 62818b9e3f6b006a7c91001fcaea3b47e2bd531e Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 2 Dec 2021 01:02:00 +0100 Subject: [PATCH 258/947] solves valid boomerang --- README.md | 2 +- src/ValidBoomerang.java | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/ValidBoomerang.java diff --git a/README.md b/README.md index 5df356d..3008c31 100644 --- a/README.md +++ b/README.md @@ -280,7 +280,7 @@ | 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) | | | +| 1033 | [Moving Stones Until Consecutive](https://leetcode.com/problems/moving-stones-until-consecutive) | [![Java](assets/java.png)](src/ValidBoomerang.java) | | | 1037 | [Valid Boomerang](https://leetcode.com/problems/valid-boomerang) | | | | 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) | | | diff --git a/src/ValidBoomerang.java b/src/ValidBoomerang.java new file mode 100644 index 0000000..3a0a00f --- /dev/null +++ b/src/ValidBoomerang.java @@ -0,0 +1,40 @@ +import java.util.Objects; + +public class ValidBoomerang { + public boolean isBoomerang(int[][] points) { + Position p1 = Position.from(points[0]); + Position p2 = Position.from(points[1]); + Position p3 = Position.from(points[2]); + if (p1.equals(p2) || p2.equals(p3) || p3.equals(p1)) return false; + if (p1.x == p2.x) return p3.x != p2.x; + if (p2.x == p3.x) return true; + return (p2.y - p1.y) * (p3.x - p2.x) != (p3.y - p2.y) * (p2.x - p1.x); + } + + private final static class Position { + private final int x; + private final int y; + + private static Position from(int[] array){ + return new Position(array[0], array[1]); + } + + Position(int x, int y) { + this.x = x; + this.y = y; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Position position = (Position) o; + return x == position.x && y == position.y; + } + + @Override + public int hashCode() { + return Objects.hash(x, y); + } + } +} From d104b2203770539461746f4a9397dff1b142d35f Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 2 Dec 2021 17:50:02 +0100 Subject: [PATCH 259/947] solves last stone weight --- README.md | 6 +++--- src/LastStoneWeight.java | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 src/LastStoneWeight.java diff --git a/README.md b/README.md index 3008c31..6e0c57f 100644 --- a/README.md +++ b/README.md @@ -280,10 +280,10 @@ | 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) | [![Java](assets/java.png)](src/ValidBoomerang.java) | | -| 1037 | [Valid Boomerang](https://leetcode.com/problems/valid-boomerang) | | | +| 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) | | | +| 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) | | | | 1051 | [Height Checker](https://leetcode.com/problems/height-checker) | | | | 1056 | [Confusing Number](https://leetcode.com/problems/confusing-number) | | | diff --git a/src/LastStoneWeight.java b/src/LastStoneWeight.java new file mode 100644 index 0000000..b5eb6ba --- /dev/null +++ b/src/LastStoneWeight.java @@ -0,0 +1,19 @@ +import java.util.Comparator; +import java.util.PriorityQueue; +import java.util.Queue; + +public class LastStoneWeight { + public int lastStoneWeight(int[] stones) { + Queue maxHeap = new PriorityQueue<>(Comparator.reverseOrder()); + for (int stone : stones) maxHeap.add(stone); + int stone1, stone2; + while (maxHeap.size() > 1) { + stone1 = maxHeap.poll(); + stone2 = maxHeap.poll(); + if (stone1 != stone2) { + maxHeap.add(Math.abs(stone1 - stone2)); + } + } + return maxHeap.isEmpty() ? 0 : maxHeap.peek(); + } +} From 1a84236962e4d1a678507f46563b966964f2bdd1 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 2 Dec 2021 18:29:03 +0100 Subject: [PATCH 260/947] solve sremove all adjacent duplicats in a string --- README.md | 2 +- src/RemoveAllAdjacentDuplicatesInAString.java | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/RemoveAllAdjacentDuplicatesInAString.java diff --git a/README.md b/README.md index 6e0c57f..626ec9f 100644 --- a/README.md +++ b/README.md @@ -284,7 +284,7 @@ | 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) | | | +| 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) | | | diff --git a/src/RemoveAllAdjacentDuplicatesInAString.java b/src/RemoveAllAdjacentDuplicatesInAString.java new file mode 100644 index 0000000..6b44e50 --- /dev/null +++ b/src/RemoveAllAdjacentDuplicatesInAString.java @@ -0,0 +1,29 @@ +import java.util.Stack; + +public class RemoveAllAdjacentDuplicatesInAString { + + public String removeDuplicates(String s) { + final Stack stack = new Stack<>(); + int k, count = 0; + stack.push(s.charAt(0)); + for (int index = 1 ; index < s.length() ; index = k + 1, count = 0) { + for (k = index ; k + 1 < s.length() && s.charAt(k + 1) == s.charAt(k) ; k++); + if (!stack.isEmpty() && stack.peek() == s.charAt(k)) { + for (count = 0 ; !stack.isEmpty() && stack.peek() == s.charAt(k) ; count++) { + stack.pop(); + } + } + if (((k - index + 1 + count) & 1) == 1) stack.push(s.charAt(k)); + } + StringBuilder result = getCharactersFrom(stack); + return result.reverse().toString(); + } + + private StringBuilder getCharactersFrom(Stack stack) { + StringBuilder result = new StringBuilder(); + while (!stack.isEmpty()) { + result.append(stack.pop()); + } + return result; + } +} From 2f58f9df10b8c7e7f7427fc96d359383fd2dbf1a Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 2 Dec 2021 18:32:31 +0100 Subject: [PATCH 261/947] adds premium content logo --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 626ec9f..86939ff 100644 --- a/README.md +++ b/README.md @@ -286,9 +286,9 @@ | 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) | | | +| 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) | | | | 1078 | [Occurrence After Bigram](https://leetcode.com/problems/occurrences-after-bigram) | | | | 1085 | [Sum of Digits in Minimum Number](https://leetcode.com/problems/sum-of-digits-in-the-minimum-number) | | | From 57d93d53e76c0608f7a7df762aef1fed39a0c46e Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 6 Dec 2021 18:58:34 +0100 Subject: [PATCH 262/947] solves gcd of strings --- README.md | 2 +- src/GreatestCommonDivisorOfStrings.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/GreatestCommonDivisorOfStrings.java diff --git a/README.md b/README.md index 86939ff..914632b 100644 --- a/README.md +++ b/README.md @@ -289,7 +289,7 @@ | 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) | | | +| 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) | | | | 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) | | | diff --git a/src/GreatestCommonDivisorOfStrings.java b/src/GreatestCommonDivisorOfStrings.java new file mode 100644 index 0000000..bc73865 --- /dev/null +++ b/src/GreatestCommonDivisorOfStrings.java @@ -0,0 +1,17 @@ +public class GreatestCommonDivisorOfStrings { + public String gcdOfStrings(String str1, String str2) { + if (!patternExist(str1, str2)) return ""; + return str1.substring(0, gcd(str1.length(), str2.length())); + } + + private boolean patternExist(String str1, String str2) { + for (int i = 0, j = 0 ; i < str1.length() ; i++, j = (j + 1) % str2.length()) { + if (str1.charAt(i) != str2.charAt(j)) return false; + } + return true; + } + + private int gcd(int a, int b) { + return b == 0 ? a : gcd(b, a % b); + } +} From 08cb786ce0a93e7b25b9eb636d4d52c76cdcbeae Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Tue, 7 Dec 2021 00:49:46 +0100 Subject: [PATCH 263/947] solves occurrences afte bigram --- README.md | 16 ++++++++-------- src/OccurrencesAfterBigram.java | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 src/OccurrencesAfterBigram.java diff --git a/README.md b/README.md index 914632b..8ee8d47 100644 --- a/README.md +++ b/README.md @@ -281,16 +281,16 @@ | 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) | | +| 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) | | +| 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) | | | +| 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) | | | diff --git a/src/OccurrencesAfterBigram.java b/src/OccurrencesAfterBigram.java new file mode 100644 index 0000000..d089210 --- /dev/null +++ b/src/OccurrencesAfterBigram.java @@ -0,0 +1,33 @@ +import java.util.ArrayList; +import java.util.List; + +public class OccurrencesAfterBigram { + public String[] findOcurrences(String text, String first, String second) { + List result = new ArrayList<>(); + for (int fromIndex = 0 ; fromIndex < text.length() ; fromIndex += first.length() + 1) { + fromIndex = text.indexOf(first, fromIndex); + if (fromIndex == -1) break; + if (areEqual(text, fromIndex + first.length() + 1, second) + && fromIndex + first.length() + second.length() + 2 < text.length()) { + result.add(nextWord(text, fromIndex + first.length() + second.length() + 2)); + } + } + return result.toArray(new String[0]); + } + + private boolean areEqual(String text, int fromIndex, String pattern) { + if (pattern.length() > text.length() - fromIndex) return false; + for (int index = fromIndex ; index < text.length() && index - fromIndex < pattern.length() ; index++) { + if (text.charAt(index) != pattern.charAt(index - fromIndex)) return false; + } + return true; + } + + private String nextWord(String text, int startIndex) { + StringBuilder result = new StringBuilder(); + for (int index = startIndex ; index < text.length() && text.charAt(index) != ' ' ; index++) { + result.append(text.charAt(index)); + } + return result.toString(); + } +} From bf77eab9fb1ff0758d9f0a1d80014033f0acaaa7 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Tue, 7 Dec 2021 01:08:00 +0100 Subject: [PATCH 264/947] solves duplicate zeros --- README.md | 6 +++--- src/DuplicateZeros.java | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 src/DuplicateZeros.java diff --git a/README.md b/README.md index 8ee8d47..d5f5174 100644 --- a/README.md +++ b/README.md @@ -291,9 +291,9 @@ | 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) | | | +| 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) | | | | 1108 | [Defanging an IP Address](https://leetcode.com/problems/defanging-an-ip-address) | | | diff --git a/src/DuplicateZeros.java b/src/DuplicateZeros.java new file mode 100644 index 0000000..a897f9e --- /dev/null +++ b/src/DuplicateZeros.java @@ -0,0 +1,21 @@ +public class DuplicateZeros { + public void duplicateZeros(int[] array) { + int removals = 0, k = array.length - 1; + for (int i = 0 ; i < array.length - removals ; i++) { + if (array[i] == 0) { + if (i == array.length - 1 - removals) { + array[k--] = 0; + } + removals++; + } + } + for (int i = array.length - 1 - removals ; i >= 0 ; i--, k--) { + if (array[i] == 0) { + array[k] = array[k - 1] = 0; + k--; + } else { + array[k] = array[i]; + } + } + } +} From 6bfe8de18320515ef1e3a2e412ac03ae59f9d163 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Tue, 7 Dec 2021 01:50:13 +0100 Subject: [PATCH 265/947] solves distribute candeis to people --- README.md | 4 ++-- src/DistributeCandiesToPeople.java | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 src/DistributeCandiesToPeople.java diff --git a/README.md b/README.md index d5f5174..cbf1bbf 100644 --- a/README.md +++ b/README.md @@ -294,8 +294,8 @@ | 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) | | | +| 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) | | | | 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) | | | diff --git a/src/DistributeCandiesToPeople.java b/src/DistributeCandiesToPeople.java new file mode 100644 index 0000000..e26ca49 --- /dev/null +++ b/src/DistributeCandiesToPeople.java @@ -0,0 +1,10 @@ +public class DistributeCandiesToPeople { + public int[] distributeCandies(int candies, int people) { + final int[] result = new int[people]; + for (int i = 0, k = 1 ; candies > 0 ; k++, i = (i + 1) % people) { + result[i] += Math.min(candies, k); + candies -= Math.min(candies, k); + } + return result; + } +} From 1df80957e72c37fc87985b5d3aa4e0bfd8dff2ed Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Tue, 7 Dec 2021 01:53:26 +0100 Subject: [PATCH 266/947] slves defanging an ip address --- README.md | 2 +- src/DefangingAnIPAddress.java | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/DefangingAnIPAddress.java diff --git a/README.md b/README.md index cbf1bbf..c2ab6a4 100644 --- a/README.md +++ b/README.md @@ -296,7 +296,7 @@ | 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) | | | +| 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) | | | diff --git a/src/DefangingAnIPAddress.java b/src/DefangingAnIPAddress.java new file mode 100644 index 0000000..32262a7 --- /dev/null +++ b/src/DefangingAnIPAddress.java @@ -0,0 +1,9 @@ +public class DefangingAnIPAddress { + public String defangIPaddr(String address) { + StringBuilder result = new StringBuilder(); + for (int i = 0 ; i < address.length() ; i++) { + result.append(address.charAt(i) == '.' ? "[.]" : address.charAt(i)); + } + return result.toString(); + } +} From 4ce92b116653ab05ebfb4794652c32dcd29ef49c Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 7 Dec 2021 21:45:55 +0100 Subject: [PATCH 267/947] solves number of equivalent domino pairs --- README.md | 2 +- src/NumberOfEquivalentDominoPairs.java | 37 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/NumberOfEquivalentDominoPairs.java diff --git a/README.md b/README.md index c2ab6a4..772e77f 100644 --- a/README.md +++ b/README.md @@ -300,7 +300,7 @@ | 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) | | | -| 1128 | [Number of Equivalent Domino Pairs](https://leetcode.com/problems/number-of-equivalent-domino-pairs) | | | +| 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]() | | | diff --git a/src/NumberOfEquivalentDominoPairs.java b/src/NumberOfEquivalentDominoPairs.java new file mode 100644 index 0000000..a999005 --- /dev/null +++ b/src/NumberOfEquivalentDominoPairs.java @@ -0,0 +1,37 @@ +import java.util.HashMap; +import java.util.Map; + +public class NumberOfEquivalentDominoPairs { + private static class Domino { + private final int number; + + Domino(int[] array) { + number = Math.min(array[0], array[1]) * 10 + Math.max(array[0], array[1]); + } + + @Override + public boolean equals(Object o) { + Domino domino = (Domino) o; + return number == domino.number; + } + + @Override + public int hashCode() { + return number; + } + } + + public int numEquivDominoPairs(int[][] dominoes) { + final Map dominoesFrequencies = new HashMap<>(); + Domino d; + for (int[] domino : dominoes) { + d = new Domino(domino); + dominoesFrequencies.put(d, dominoesFrequencies.getOrDefault(d, 0) + 1); + } + int equivalentPairs = 0; + for (int frequency : dominoesFrequencies.values()) { + equivalentPairs += (frequency * (frequency - 1)) / 2; + } + return equivalentPairs; + } +} From 756e1ce5d641a0ad9f4558a5c77605826e83cd9c Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Wed, 8 Dec 2021 13:58:50 +0100 Subject: [PATCH 268/947] solves nth tribonnnaci number --- README.md | 10 +++++----- src/NthTribonacciNumber.java | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 src/NthTribonacciNumber.java diff --git a/README.md b/README.md index 772e77f..01eebba 100644 --- a/README.md +++ b/README.md @@ -297,13 +297,13 @@ | 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) | | | +| 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) | | | | 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]() | | | +| 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) | | | 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) | | | | 1160 | [Find Words That Can Be Formed By Characters](https://leetcode.com/problems/find-words-that-can-be-formed-by-characters) | | | diff --git a/src/NthTribonacciNumber.java b/src/NthTribonacciNumber.java new file mode 100644 index 0000000..c3b781d --- /dev/null +++ b/src/NthTribonacciNumber.java @@ -0,0 +1,15 @@ +public class NthTribonacciNumber { + public int tribonacci(int n) { + if (n == 0) return 0; + if (n <= 2) return 1; + int a = 0, b = 1, c = 1, temp; + while (n - 2 > 0) { + temp = c; + c = a + b + c; + a = b; + b = temp; + n--; + } + return c; + } +} From 2a68a8f279600bb6860dba64dd81eeaf8b20cb71 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Wed, 8 Dec 2021 14:17:32 +0100 Subject: [PATCH 269/947] solves day of the year --- README.md | 2 +- src/DayOfTheYear.java | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/DayOfTheYear.java diff --git a/README.md b/README.md index 01eebba..bb22fc6 100644 --- a/README.md +++ b/README.md @@ -305,7 +305,7 @@ | 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) | | | 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) | | | +| 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) | | | | 1170 | [Compare Strings By Frequency of the Smallest Character](https://leetcode.com/problems/compare-strings-by-frequency-of-the-smallest-character) | | | diff --git a/src/DayOfTheYear.java b/src/DayOfTheYear.java new file mode 100644 index 0000000..860b8f1 --- /dev/null +++ b/src/DayOfTheYear.java @@ -0,0 +1,26 @@ +public class DayOfTheYear { + private static final int[] DAYS_UPTO_MONTH_IN_STD_YEAR = { + 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 + }; + + private static final int[] DAYS_UPTO_MONTH_IN_LEAP_YEAR = { + 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 + }; + + public int dayOfYear(String date) { + String[] dateParts = date.split("-"); + final int year = Integer.parseInt(dateParts[0]); + final int month = Integer.parseInt(dateParts[1]); + final int day = Integer.parseInt(dateParts[2]); + if (isLeapYear(year)) { + return DAYS_UPTO_MONTH_IN_LEAP_YEAR[month - 1] + day; + } + return DAYS_UPTO_MONTH_IN_STD_YEAR[month - 1] + day; + } + + private boolean isLeapYear(int year) { + if (year % 400 == 0) return true; + if (year % 100 == 0) return false; + return year % 4 == 0; + } +} From c4688c86fa96ffc17c3528274cffeb5daf347eec Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Wed, 8 Dec 2021 14:27:05 +0100 Subject: [PATCH 270/947] solves find words that can be formed by characters --- README.md | 6 ++-- src/FindWordsThatCanBeFormedByCharacters.java | 32 +++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 src/FindWordsThatCanBeFormedByCharacters.java diff --git a/README.md b/README.md index bb22fc6..3f055a3 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-231/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-231/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-248/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-248/2081-1abc9c.svg) ![problems-solved-python](https://img.shields.io/badge/Python-186/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) @@ -307,7 +307,7 @@ | 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) | | | +| 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) | | | | 1176 | [Diet Plan Performance](https://leetcode.com/problems/diet-plan-performance) | | | diff --git a/src/FindWordsThatCanBeFormedByCharacters.java b/src/FindWordsThatCanBeFormedByCharacters.java new file mode 100644 index 0000000..1fc9867 --- /dev/null +++ b/src/FindWordsThatCanBeFormedByCharacters.java @@ -0,0 +1,32 @@ +import java.util.HashMap; +import java.util.Map; + +public class FindWordsThatCanBeFormedByCharacters { + public int countCharacters(String[] words, String chars) { + final Map characterFrequencies = getCharFrequencies(chars); + int result = 0; + for (String word : words) { + if (word.length() > chars.length()) continue; + Map wordCharFrequencies = getCharFrequencies(word); + if (canBeFormedBy(wordCharFrequencies, characterFrequencies)) { + result += word.length(); + } + } + return result; + } + + private Map getCharFrequencies(String string) { + Map frequencies = new HashMap<>(); + for (int index = 0 ; index < string.length() ; index++) { + frequencies.put(string.charAt(index), frequencies.getOrDefault(string.charAt(index), 0) + 1); + } + return frequencies; + } + + private boolean canBeFormedBy(Map frequencies1, Map frequencies2) { + for (Map.Entry entry : frequencies1.entrySet()) { + if (frequencies2.getOrDefault(entry.getKey(), 0) < entry.getValue()) return false; + } + return true; + } +} From f55f949e2c5a462519dcb2c649c9d42483cbb8a5 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Wed, 8 Dec 2021 17:00:46 +0100 Subject: [PATCH 271/947] solves prime arrangements --- README.md | 2 +- src/PrimeArrangements.java | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 src/PrimeArrangements.java diff --git a/README.md b/README.md index 3f055a3..23440bf 100644 --- a/README.md +++ b/README.md @@ -309,7 +309,7 @@ | 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) | | | +| 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) | | | diff --git a/src/PrimeArrangements.java b/src/PrimeArrangements.java new file mode 100644 index 0000000..c6c0d3b --- /dev/null +++ b/src/PrimeArrangements.java @@ -0,0 +1,36 @@ +public class PrimeArrangements { + private static final int[] PRIME_DENSITY = { + 0, 1, 2, 2, 3, 3, 4, 4, 4, 4, + 5, 5, 6, 6, 6, 6, 7, 7, 8, 8, + 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, + 11, 11, 11, 11, 11, 11, 12, 12, + 12, 12, 13, 13, 14, 14, 14, 14, + 15, 15, 15, 15, 15, 15, 16, 16, + 16, 16, 16, 16, 17, 17, 18, 18, + 18, 18, 18, 18, 19, 19, 19, 19, + 20, 20, 21, 21, 21, 21, 21, 21, + 22, 22, 22, 22, 23, 23, 23, 23, + 23, 23, 24, 24, 24, 24, 24, 24, + 24, 24, 25, 25, 25, 25 + }; + + private static final int MOD = 1000_000_007; + + public int numPrimeArrangements(int n) { + final int primeNumbers = PRIME_DENSITY[n - 1]; + return factorialMod(primeNumbers, factorialMod(n - primeNumbers)) % MOD; + } + + private int factorialMod(long number, final long start) { + long result = start; + while (number > 1) { + result = (result * number) % MOD; + number--; + } + return (int) result; + } + + private int factorialMod(int number) { + return factorialMod(number, 1); + } +} From 12fea5bba1a2f55f722a3dc89350dcf2285d538c Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Wed, 8 Dec 2021 17:08:11 +0100 Subject: [PATCH 272/947] solves distance between bus stops --- README.md | 2 +- src/DistanceBetweenBusStops.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/DistanceBetweenBusStops.java diff --git a/README.md b/README.md index 23440bf..00863a5 100644 --- a/README.md +++ b/README.md @@ -312,7 +312,7 @@ | 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) | | | +| 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) | | | | 1189 | [Maximum Number of Balloons](https://leetcode.com/problems/maximum-number-of-balloons) | | | | 1196 | [How Many Apples Can You Put into the Basket](https://leetcode.com/problems/how-many-apples-can-you-put-into-the-basket) | | | diff --git a/src/DistanceBetweenBusStops.java b/src/DistanceBetweenBusStops.java new file mode 100644 index 0000000..023bafb --- /dev/null +++ b/src/DistanceBetweenBusStops.java @@ -0,0 +1,17 @@ +import java.util.Arrays; + +public class DistanceBetweenBusStops { + public int distanceBetweenBusStops(int[] distance, int start, int destination) { + final int totalDistance = Arrays.stream(distance).sum(); + final int path1 = getDistance(distance, start, destination); + return Math.min(path1, totalDistance - path1); + } + + private int getDistance(int[] distances, int start, int end) { + int distance = 0; + for (int i = start ; i != end ; i = (i + 1) % distances.length) { + distance += distances[i]; + } + return distance; + } +} From 6d40e1f36dd7831eec20e6da8aab33481e77472b Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Wed, 8 Dec 2021 18:10:06 +0100 Subject: [PATCH 273/947] solves maximum number of balloons --- README.md | 8 ++++---- src/DayOfWeek.java | 16 ++++++++++++++++ src/MaximumNumberOfBalloons.java | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 src/DayOfWeek.java create mode 100644 src/MaximumNumberOfBalloons.java diff --git a/README.md b/README.md index 00863a5..110efc6 100644 --- a/README.md +++ b/README.md @@ -310,11 +310,11 @@ | 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) | | | +| 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) | | | -| 1189 | [Maximum Number of Balloons](https://leetcode.com/problems/maximum-number-of-balloons) | | | +| 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) | | | | 1207 | [Unique Number of Occurrences](https://leetcode.com/problems/unique-number-of-occurrences) | | | diff --git a/src/DayOfWeek.java b/src/DayOfWeek.java new file mode 100644 index 0000000..4ee1316 --- /dev/null +++ b/src/DayOfWeek.java @@ -0,0 +1,16 @@ +import java.time.LocalDate; + +public class DayOfWeek { + public String dayOfTheWeek(int day, int month, int year) { + LocalDate date = LocalDate.of(year, month, day); + return switch (date.getDayOfWeek()) { + case MONDAY -> "Monday"; + case TUESDAY -> "Tuesday"; + case WEDNESDAY -> "Wednesday"; + case THURSDAY -> "Thursday"; + case FRIDAY -> "Friday"; + case SATURDAY -> "Saturday"; + case SUNDAY -> "Sunday"; + }; + } +} diff --git a/src/MaximumNumberOfBalloons.java b/src/MaximumNumberOfBalloons.java new file mode 100644 index 0000000..3aab7db --- /dev/null +++ b/src/MaximumNumberOfBalloons.java @@ -0,0 +1,32 @@ +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +public class MaximumNumberOfBalloons { + private static final Set BALLOON_CHARACTERS = Set.of('b', 'a', 'l', 'o', 'n'); + private static final Set BALLOON_DOUBLE_LETTERS = Set.of('l', 'o'); + + public int maxNumberOfBalloons(String text) { + Map frequencies = getCharacterFrequencies(text); + int result = Integer.MAX_VALUE; + for (char character : BALLOON_CHARACTERS) { + result = Math.min(result, frequencies.getOrDefault(character, 0)); + } + return result; + } + + private Map getCharacterFrequencies(String string) { + final Map frequencies = new HashMap<>(); + char character; + for (int i = 0 ; i < string.length() ; i++) { + character = string.charAt(i); + if (BALLOON_CHARACTERS.contains(character)) { + frequencies.put(character, frequencies.getOrDefault(character, 0) + 1); + } + } + for (char letter : BALLOON_DOUBLE_LETTERS) { + frequencies.put(letter, frequencies.getOrDefault(letter, 0) / 2); + } + return frequencies; + } +} From f21a066f74e1e4525290b2d3feb3d1117693a3d3 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Wed, 8 Dec 2021 19:22:03 +0100 Subject: [PATCH 274/947] solves minimum absolute difference --- README.md | 4 ++-- src/MinimumAbsoluteDifference.java | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 src/MinimumAbsoluteDifference.java diff --git a/README.md b/README.md index 110efc6..c9dd049 100644 --- a/README.md +++ b/README.md @@ -315,8 +315,8 @@ | 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) | | | +| 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) | | | 1207 | [Unique Number of Occurrences](https://leetcode.com/problems/unique-number-of-occurrences) | | | | 1213 | [Intersection of Three Sorted Arrays](https://leetcode.com/problems/intersection-of-three-sorted-arrays) | | | | 1217 | [Play With Chips](https://leetcode.com/problems/play-with-chips) | | | diff --git a/src/MinimumAbsoluteDifference.java b/src/MinimumAbsoluteDifference.java new file mode 100644 index 0000000..4c871d5 --- /dev/null +++ b/src/MinimumAbsoluteDifference.java @@ -0,0 +1,21 @@ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class MinimumAbsoluteDifference { + public List> minimumAbsDifference(int[] array) { + List> result = new ArrayList<>(); + Arrays.sort(array); + long minAbsDifference = Long.MAX_VALUE; + for (int i = 0 ; i < array.length - 1 ; i++) { + if (array[i + 1] - array[i] < minAbsDifference) { + minAbsDifference = array[i + 1] - array[i]; + result = new ArrayList<>(); + result.add(List.of(array[i], array[i + 1])); + } else if (array[i + 1] - array[i] == minAbsDifference) { + result.add(List.of(array[i], array[i + 1])); + } + } + return result; + } +} From 2cb5e68122dcbfea94e899f8d7c3fecae044c786 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Wed, 8 Dec 2021 19:27:44 +0100 Subject: [PATCH 275/947] solves unique number of occurrences --- README.md | 2 +- src/UniqueNumberOfOccurrences.java | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/UniqueNumberOfOccurrences.java diff --git a/README.md b/README.md index c9dd049..eef9694 100644 --- a/README.md +++ b/README.md @@ -317,7 +317,7 @@ | 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) | | -| 1207 | [Unique Number of Occurrences](https://leetcode.com/problems/unique-number-of-occurrences) | | | +| 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 | [Play With Chips](https://leetcode.com/problems/play-with-chips) | | | | 1221 | [Split A String In Balanced Strings](https://leetcode.com/problems/split-a-string-in-balanced-strings) | | | diff --git a/src/UniqueNumberOfOccurrences.java b/src/UniqueNumberOfOccurrences.java new file mode 100644 index 0000000..9051d19 --- /dev/null +++ b/src/UniqueNumberOfOccurrences.java @@ -0,0 +1,29 @@ +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public class UniqueNumberOfOccurrences { + public boolean uniqueOccurrences(int[] array) { + Map frequencies = getFrequencies(array); + return areUnique(frequencies.values()); + } + + private Map getFrequencies(int[] array) { + Map frequencies = new HashMap<>(); + for (int element : array) { + frequencies.put(element, frequencies.getOrDefault(element, 0) + 1); + } + return frequencies; + } + + private boolean areUnique(Collection numbers) { + Set values = new HashSet<>(); + for (int number : numbers) { + if (values.contains(number)) return false; + values.add(number); + } + return true; + } +} From 9badb0b01bf68ad563d7b41eeb88a50787e2f1ca Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Wed, 8 Dec 2021 19:39:04 +0100 Subject: [PATCH 276/947] solves minimum cost to move chips to same position --- README.md | 4 ++-- src/MinimumCostToMoveChipsToTheSamePosition.java | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 src/MinimumCostToMoveChipsToTheSamePosition.java diff --git a/README.md b/README.md index eef9694..a834a5a 100644 --- a/README.md +++ b/README.md @@ -318,8 +318,8 @@ | 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) | | | 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 | [Play With Chips](https://leetcode.com/problems/play-with-chips) | | | +| 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) | | | | 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) | | | diff --git a/src/MinimumCostToMoveChipsToTheSamePosition.java b/src/MinimumCostToMoveChipsToTheSamePosition.java new file mode 100644 index 0000000..45dba0e --- /dev/null +++ b/src/MinimumCostToMoveChipsToTheSamePosition.java @@ -0,0 +1,9 @@ +public class MinimumCostToMoveChipsToTheSamePosition { + public int minCostToMoveChips(int[] positions) { + int evenPositionChips = 0; + for (int position : positions) { + if (position % 2 == 0) evenPositionChips++; + } + return Math.min(evenPositionChips, positions.length - evenPositionChips); + } +} From 873ecf79569d8bc109f48e1a4f71e4e3ea98a4ac Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 8 Dec 2021 22:40:30 +0100 Subject: [PATCH 277/947] solves relative sort array --- README.md | 2 +- src/RelativeSortArray.java | 40 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/RelativeSortArray.java diff --git a/README.md b/README.md index a834a5a..a2924d4 100644 --- a/README.md +++ b/README.md @@ -299,7 +299,7 @@ | 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) | | | +| 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) | | | diff --git a/src/RelativeSortArray.java b/src/RelativeSortArray.java new file mode 100644 index 0000000..fd81a9d --- /dev/null +++ b/src/RelativeSortArray.java @@ -0,0 +1,40 @@ +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +public class RelativeSortArray { + public int[] relativeSortArray(int[] arr1, int[] arr2) { + final Map elementWeight = new HashMap<>(); + for (int i = 0 ; i < arr2.length ; i++) elementWeight.put(arr2[i], i); + Integer[] array = arrayFrom(arr1); + Arrays.sort(array, (o1, o2) -> { + if (elementWeight.containsKey(o1) && elementWeight.containsKey(o2)) { + return elementWeight.get(o1) - elementWeight.get(o2); + } + if (elementWeight.containsKey(o1)) { + return -1; + } + if (elementWeight.containsKey(o2)) { + return 1; + } + return Integer.compare(o1, o2); + }); + return toIntArray(array); + } + + private Integer[] arrayFrom(int[] array) { + Integer[] result = new Integer[array.length]; + for (int index = 0 ; index < array.length ; index++) { + result[index] = array[index]; + } + return result; + } + + private int[] toIntArray(Integer[] array) { + int[] result = new int[array.length]; + for (int index = 0 ; index < array.length ; index++) { + result[index] = array[index]; + } + return result; + } +} From c9219a559e1b24da25fbc96fb1ea68aafbbba060 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 8 Dec 2021 22:44:41 +0100 Subject: [PATCH 278/947] solves split a string into balanced sub strings --- README.md | 2 +- src/SplitAStringInBalancedStrings.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 src/SplitAStringInBalancedStrings.java diff --git a/README.md b/README.md index a2924d4..5aefa0c 100644 --- a/README.md +++ b/README.md @@ -320,7 +320,7 @@ | 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) | | | +| 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) | | | | 1237 | [Find Positive Integer Solutions for a Given Equation](https://leetcode.com/problems/find-positive-integer-solution-for-a-given-equation) | | | diff --git a/src/SplitAStringInBalancedStrings.java b/src/SplitAStringInBalancedStrings.java new file mode 100644 index 0000000..5361cf5 --- /dev/null +++ b/src/SplitAStringInBalancedStrings.java @@ -0,0 +1,10 @@ +public class SplitAStringInBalancedStrings { + public int balancedStringSplit(String s) { + int balancedSubStrings = 0; + for (int i = 0, current = 0 ; i < s.length() ; i++) { + current += s.charAt(i) == 'L' ? -1 : 1; + if (current == 0) balancedSubStrings++; + } + return balancedSubStrings; + } +} From 056bc56c4ce49a1f9b81f44af62b0fbc482917dc Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 8 Dec 2021 22:52:49 +0100 Subject: [PATCH 279/947] solves check if is on straight line --- README.md | 4 ++-- src/CheckIfItIsASStraightLine.java | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 src/CheckIfItIsASStraightLine.java diff --git a/README.md b/README.md index 5aefa0c..23376ad 100644 --- a/README.md +++ b/README.md @@ -321,8 +321,8 @@ | 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) | | | +| 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) | | | | 1252 | [Cells With Odd Values In Matrix](https://leetcode.com/problems/cells-with-odd-values-in-a-matrix) | | | diff --git a/src/CheckIfItIsASStraightLine.java b/src/CheckIfItIsASStraightLine.java new file mode 100644 index 0000000..a52ba25 --- /dev/null +++ b/src/CheckIfItIsASStraightLine.java @@ -0,0 +1,16 @@ +public class CheckIfItIsASStraightLine { + public boolean checkStraightLine(int[][] coordinates) { + for (int i = 0 ; i < coordinates.length - 2 ; i++) { + if (!isOnStraightLine(coordinates[i], coordinates[i + 1], coordinates[i + 2])) { + return false; + } + } + return true; + } + + private boolean isOnStraightLine(int[] p1, int[] p2, int[] p3) { + if (p1[0] == p2[0] && p2[0] == p3[0]) return true; + if (p1[1] == p2[1] && p2[1] == p3[1]) return true; + return (p2[1] - p1[1]) * (p3[0] - p2[0]) == (p3[1] - p2[1]) * (p2[0] - p1[0]); + } +} From 6d4a8d4e92632ea0d3665e72c2390fbe9a211844 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 8 Dec 2021 23:05:04 +0100 Subject: [PATCH 280/947] solves cells with odd values in matrix --- README.md | 4 ++-- src/CellsWithOddValuesInMatrix.java | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 src/CellsWithOddValuesInMatrix.java diff --git a/README.md b/README.md index 23376ad..7eab4ea 100644 --- a/README.md +++ b/README.md @@ -324,8 +324,8 @@ | 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) | | | -| 1252 | [Cells With Odd Values In Matrix](https://leetcode.com/problems/cells-with-odd-values-in-a-matrix) | | | +| 1243 | 🔒 [Array Transformation](https://leetcode.com/problems/array-transformation) | | | +| 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) | | | 1260 | [Shift 2D Grid](https://leetcode.com/problems/shift-2d-grid) | | | | 1266 | [Minimum Time Visiting All Points](https://leetcode.com/problems/minimum-time-visiting-all-points) | | | | 1271 | [Hexspeak](https://leetcode.com/problems/hexspeak) | | | diff --git a/src/CellsWithOddValuesInMatrix.java b/src/CellsWithOddValuesInMatrix.java new file mode 100644 index 0000000..8a94e7a --- /dev/null +++ b/src/CellsWithOddValuesInMatrix.java @@ -0,0 +1,22 @@ +public class CellsWithOddValuesInMatrix { + public int oddCells(int m, int n, int[][] operations) { + final byte[] rowState = new byte[m]; + final byte[] columnState = new byte[n]; + for (int[] operation : operations) { + rowState[operation[0]] ^= 1; + columnState[operation[1]] ^= 1; + } + int oddElements = 0; + final int shiftedColumns = sum(columnState); + for (int row : rowState) { + oddElements += row == 0 ? shiftedColumns : n - shiftedColumns; + } + return oddElements; + } + + private int sum(byte[] array) { + int sum = 0; + for (byte element : array) sum += element; + return sum; + } +} From c578c91f1642ec554ade00e1336d79de67e2a197 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 8 Dec 2021 23:50:32 +0100 Subject: [PATCH 281/947] solves shift 2d grid --- README.md | 2 +- src/Shift2DGrid.java | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/Shift2DGrid.java diff --git a/README.md b/README.md index 7eab4ea..193f898 100644 --- a/README.md +++ b/README.md @@ -326,7 +326,7 @@ | 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) | | | | 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) | | -| 1260 | [Shift 2D Grid](https://leetcode.com/problems/shift-2d-grid) | | | +| 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) | | | | 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) | | | diff --git a/src/Shift2DGrid.java b/src/Shift2DGrid.java new file mode 100644 index 0000000..c5bf06e --- /dev/null +++ b/src/Shift2DGrid.java @@ -0,0 +1,34 @@ +import java.util.ArrayList; +import java.util.List; + +public class Shift2DGrid { + public static List> shiftGrid(int[][] grid, int k) { + final int rows = grid.length, columns = grid[0].length; + final List> result = getGrid(rows, columns); + final int rowOperations = k / columns; + for (int column = 0 ; column < columns ; column++) { + int rowShifts = (rowOperations + (k - columns * rowOperations - 1 >= column ? 1 : 0)) % rows; + int columnIndex = (columns + column - (k % columns)) % columns; + for (int row = 0 ; row < rows ; row++) { + result.get(row).set(column, grid[(rows + row - rowShifts) % rows][columnIndex]); + } + } + return result; + } + + private static List> getGrid(int rows, int columns) { + List> result = new ArrayList<>(rows); + for (int row = 0 ; row < rows ; row++) { + result.add(getList(columns)); + } + return result; + } + + private static List getList(int size) { + List result = new ArrayList<>(); + for (int i = 0 ; i < size ; i++) { + result.add(0); + } + return result; + } +} From c003d4d97ac6d465bdea2ead9aeab0c441dc506d Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 8 Dec 2021 23:59:31 +0100 Subject: [PATCH 282/947] minimum time visiting all points --- README.md | 2 +- src/MinimumTimeVisitingAllPoints.java | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 src/MinimumTimeVisitingAllPoints.java diff --git a/README.md b/README.md index 193f898..02b08b0 100644 --- a/README.md +++ b/README.md @@ -327,7 +327,7 @@ | 1243 | 🔒 [Array Transformation](https://leetcode.com/problems/array-transformation) | | | | 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) | | | 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) | | | +| 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) | | | | 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) | | | diff --git a/src/MinimumTimeVisitingAllPoints.java b/src/MinimumTimeVisitingAllPoints.java new file mode 100644 index 0000000..ae1e8ba --- /dev/null +++ b/src/MinimumTimeVisitingAllPoints.java @@ -0,0 +1,12 @@ +public class MinimumTimeVisitingAllPoints { + public int minTimeToVisitAllPoints(int[][] points) { + int minTime = 0; + for (int index = 0 ; index < points.length - 1 ; index++) { + minTime += Math.max( + Math.abs(points[index + 1][1] - points[index][1]), + Math.abs(points[index + 1][0] - points[index][0]) + ); + } + return minTime; + } +} From 60a0a670aefab368105c9b2afc1e0b5a98dcae65 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 9 Dec 2021 00:16:15 +0100 Subject: [PATCH 283/947] find winner on a tic tac toe game --- README.md | 4 ++-- src/FindWinnerOnATicTacToeGame.java | 34 +++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 src/FindWinnerOnATicTacToeGame.java diff --git a/README.md b/README.md index 02b08b0..bca3d85 100644 --- a/README.md +++ b/README.md @@ -328,8 +328,8 @@ | 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) | | | 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) | | | +| 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) | | | | 1287 | [Element Appearing More Than 25% in Sorted Array](https://leetcode.com/problems/element-appearing-more-than-25-in-sorted-array) | | | | 1290 | [Convert Binary Number In A Linked List to Integer](https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer) | | | diff --git a/src/FindWinnerOnATicTacToeGame.java b/src/FindWinnerOnATicTacToeGame.java new file mode 100644 index 0000000..c86b61a --- /dev/null +++ b/src/FindWinnerOnATicTacToeGame.java @@ -0,0 +1,34 @@ +public class FindWinnerOnATicTacToeGame { + public String tictactoe(int[][] moves) { + String winner = getWinnerInTicTacToe(moves); + if ("".equals(winner)) return moves.length == 9 ? "Draw" : "Pending"; + return winner; + } + + private String getWinnerInTicTacToe(int[][] moves) { + final int[] rows = new int[3], columns = new int[3]; + int d1 = 0, d2 = 0, k = 1; + for (int[] move : moves) { + rows[move[0]] += k; + columns[move[1]] += k; + if (move[0] == move[1]) d1 += k; + if (move[0] == 2 - move[1]) d2 += k; + k *= -1; + } + String result = winnerCheckInArray(rows); + if (!"".equals(result)) return result; + result = winnerCheckInArray(columns); + if (!"".equals(result)) return result; + if (d1 == 3 || d2 == 3) return "A"; + if (d1 == -3 || d2 == -3) return "B"; + return ""; + } + + private String winnerCheckInArray(int[] array) { + for (int element : array) { + if (element == 3) return "A"; + if (element == -3) return "B"; + } + return ""; + } +} From 228d5295584c938dac42b2f2a5152293ca0d29d1 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 9 Dec 2021 00:21:35 +0100 Subject: [PATCH 284/947] solves subtract the product and sum of digits of an integer --- README.md | 2 +- src/SubtractTheProductAndSumOfDigitsOfAnInteger.java | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 src/SubtractTheProductAndSumOfDigitsOfAnInteger.java diff --git a/README.md b/README.md index bca3d85..31c6639 100644 --- a/README.md +++ b/README.md @@ -330,7 +330,7 @@ | 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) | | | +| 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) | | | | 1290 | [Convert Binary Number In A Linked List to Integer](https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer) | | | | 1295 | [Find Numbers With Even Numbers of Digits](https://leetcode.com/problems/find-numbers-with-even-number-of-digits) | | | diff --git a/src/SubtractTheProductAndSumOfDigitsOfAnInteger.java b/src/SubtractTheProductAndSumOfDigitsOfAnInteger.java new file mode 100644 index 0000000..87d2b31 --- /dev/null +++ b/src/SubtractTheProductAndSumOfDigitsOfAnInteger.java @@ -0,0 +1,12 @@ +public class SubtractTheProductAndSumOfDigitsOfAnInteger { + public int subtractProductAndSum(int n) { + int product= 1, sum = 0, digit; + while (n > 0) { + digit = n % 10; + product *= digit; + sum += digit; + n /= 10; + } + return product - sum; + } +} From 2bed37d70952eb4d960ec283cdc1256dfde61a73 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 9 Dec 2021 00:40:10 +0100 Subject: [PATCH 285/947] solves element appearing more than 25% in sorted array --- README.md | 2 +- ...mentAppearingMoreThan25PercentInSortedArray.java | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/ElementAppearingMoreThan25PercentInSortedArray.java diff --git a/README.md b/README.md index 31c6639..80ffb5f 100644 --- a/README.md +++ b/README.md @@ -331,7 +331,7 @@ | 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) | | | +| 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) | | | | 1295 | [Find Numbers With Even Numbers of Digits](https://leetcode.com/problems/find-numbers-with-even-number-of-digits) | | | | 1299 | [Replace Elements With Greatest Element on Right Side](https://leetcode.com/problems/replace-elements-with-greatest-element-on-right-side) | | | diff --git a/src/ElementAppearingMoreThan25PercentInSortedArray.java b/src/ElementAppearingMoreThan25PercentInSortedArray.java new file mode 100644 index 0000000..1edf61b --- /dev/null +++ b/src/ElementAppearingMoreThan25PercentInSortedArray.java @@ -0,0 +1,13 @@ +public class ElementAppearingMoreThan25PercentInSortedArray { + public int findSpecialInteger(int[] array) { + if (array.length <= 3) return array[0]; + final int specialIntegerFrequency = array.length / 4 + 1; + for (int i = 1, current = 1 ; i < array.length ; i++) { + if (array[i] ==array[i - 1]) current++; + else current = 1; + + if (current >= specialIntegerFrequency) return array[i]; + } + return -1; + } +} From 7b03e7f4fa28947e9d9ce22c7475d059c99e4e59 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 9 Dec 2021 00:43:53 +0100 Subject: [PATCH 286/947] solves convert binary number in linked list ti integer --- README.md | 2 +- ...vertBinaryNumberInLinkedListToInteger.java | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/ConvertBinaryNumberInLinkedListToInteger.java diff --git a/README.md b/README.md index 80ffb5f..7525dfe 100644 --- a/README.md +++ b/README.md @@ -332,7 +332,7 @@ | 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) | | | +| 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) | | | | 1299 | [Replace Elements With Greatest Element on Right Side](https://leetcode.com/problems/replace-elements-with-greatest-element-on-right-side) | | | | 1304 | [Find N Unique Integers Sum Up To Zero](https://leetcode.com/problems/find-n-unique-integers-sum-up-to-zero) | | | diff --git a/src/ConvertBinaryNumberInLinkedListToInteger.java b/src/ConvertBinaryNumberInLinkedListToInteger.java new file mode 100644 index 0000000..17a6f31 --- /dev/null +++ b/src/ConvertBinaryNumberInLinkedListToInteger.java @@ -0,0 +1,20 @@ +public class ConvertBinaryNumberInLinkedListToInteger { + public int getDecimalValue(ListNode head) { + int value = 0; + while (head != null) { + value <<= 1; + value += head.val; + head = head.next; + } + return value; + } + + + private static class ListNode { + int val; + ListNode next; + ListNode() {}; + ListNode(int val) { this.val = val; } + ListNode(int val, ListNode next) { this.val = val; this.next = next; } + } +} From 470559581a375a187d1cee150fbc0e8563ea2d03 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 9 Dec 2021 00:48:49 +0100 Subject: [PATCH 287/947] solves find n unique integers sum up to zero --- README.md | 2 +- src/FindNUniqueIntegersSumUpToZero.java | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/FindNUniqueIntegersSumUpToZero.java diff --git a/README.md b/README.md index 7525dfe..051f99b 100644 --- a/README.md +++ b/README.md @@ -335,7 +335,7 @@ | 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) | | | | 1299 | [Replace Elements With Greatest Element on Right Side](https://leetcode.com/problems/replace-elements-with-greatest-element-on-right-side) | | | -| 1304 | [Find N Unique Integers Sum Up To Zero](https://leetcode.com/problems/find-n-unique-integers-sum-up-to-zero) | | | +| 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) | | | | 1313 | [Decompress Run-Length Encoded Strings](https://leetcode.com/problems/decompress-run-length-encoded-list) | | | | 1317 | [Convert Integer to Sum Of Two Non-Zero Integers](https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers) | | | diff --git a/src/FindNUniqueIntegersSumUpToZero.java b/src/FindNUniqueIntegersSumUpToZero.java new file mode 100644 index 0000000..0e8acda --- /dev/null +++ b/src/FindNUniqueIntegersSumUpToZero.java @@ -0,0 +1,11 @@ +public class FindNUniqueIntegersSumUpToZero { + public int[] sumZero(int n) { + final int[] result = new int[n]; + for (int i = 0, k = 1 ; i + 1 < result.length ; i += 2, k++) { + result[i] = k; + result[i + 1] = -k; + } + if ((n & 1) == 1) result[n - 1] = 0; + return result; + } +} From 9a111351d5f82307d4e30b04506485d62bc8a175 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 9 Dec 2021 00:58:46 +0100 Subject: [PATCH 288/947] solves greatest elementon right hand side --- README.md | 758 +++++++++--------- ...find_numbers_with_even_number_of_digits.py | 19 + ...ith_greatest_element_on_right_hand_side.py | 13 + src/FindNumbersWithEvenNumbersOfDigits.java | 19 + ...ElementWithGreatestElementOnRightSide.java | 11 + 5 files changed, 441 insertions(+), 379 deletions(-) create mode 100644 python/find_numbers_with_even_number_of_digits.py create mode 100644 python/replace_element_with_greatest_element_on_right_hand_side.py create mode 100644 src/FindNumbersWithEvenNumbersOfDigits.java create mode 100644 src/ReplaceElementWithGreatestElementOnRightSide.java diff --git a/README.md b/README.md index 051f99b..0cbebb3 100644 --- a/README.md +++ b/README.md @@ -9,382 +9,382 @@ 🔒 = 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) | -| 7 | [Reverse Integer](https://leetcode.com/problems/reverse-integer/) | [![Java](assets/java.png)](src/ReverseInteger.java) [![Python](assets/python.png)](python/reverse_integer.py) | [![java-yt](assets/java-yt.png)](https://youtu.be/7bOhyl5lWjI) [![python-yt](assets/python-yt.png)](https://youtu.be/lmLG30TLcSg) | -| 9 | [PalindromeNumber](https://leetcode.com/problems/palindrome-number/) | [![Java](assets/java.png)](src/PalindromeNumber.java) [![Python](assets/python.png)](python/palindrome_number.py) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 136 | [Single Number](https://leetcode.com/problems/single-number) | [![Java](assets/java.png)](src/SingleNumber.java) [![Python](assets/python.png)](python/single_number.py) | | -| 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) | | -| 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) | | -| 155 | [Min Stack](https://leetcode.com/problems/min-stack) | [![Java](assets/java.png)](src/MinStack.java) [![Python](assets/python.png)](python/min_stack.py) | | -| 157 | [Read N Characters Given Read4](https://leetcode.com/problems/read-n-characters-given-read4) | | | -| 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) | | -| 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) | | -| 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) | | -| 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 Lists](https://leetcode.com/problems/reverse-linked-list) | [![Java](assets/java.png)](src/ReverseLinkedList.java) [![Python](assets/python.png)](python/reverse_linked_list.py) | | -| 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate) | [![Java](assets/java.png)](src/ContainsDuplicate.java) [![Python](assets/python.png)](python/contains_duplicate.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) | | -| 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) | | -| 226 | [Summary Ranges](https://leetcode.com/problems/summary-ranges/) | [![Java](assets/java.png)](src/SummaryRanges.java) [![Python](assets/python.png)](python/summary_ranges.py) | | -| 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) | | -| 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) | | -| 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) | | | -| 246 | 🔒 [Strobogramatic Number](https://leetcode.com/problems/strobogrammatic-number) | | | -| 252 | 🔒 [Meeting Rooms](https://leetcode.com/problems/meeting-rooms) | | | -| 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) | | -| 263 | [Ugly Number](https://leetcode.com/problems/ugly-number) | [![Java](assets/java.png)](src/UglyNumber.java) [![Python](assets/python.png)](python/ugly_number.py) | | -| 266 | 🔒 [Palindrome Permutation](https://leetcode.com/problems/palindrome-permutation) | | | -| 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) | | | -| 276 | 🔒 [Paint Fence](https://leetcode.com/problems/paint-fence) | | | -| 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) | | -| 283 | [Move Zeroes](https://leetcode.com/problems/move-zeroes) | [![Java](assets/java.png)](src/MoveZeros.java) [![Python](assets/python.png)](python/move_zeroes.py) | | -| 290 | [Word Pattern](https://leetcode.com/problems/word-pattern) | [![Java](assets/java.png)](src/WordPattern.java) [![Python](assets/python.png)](python/word_pattern.py) | | -| 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) | | | -| 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) | | -| 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) | | -| 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) | | -| 326 | [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) | | | -| 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) | | -| 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) | | | -| 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) | | -| 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) | | | -| 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) | | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | | -| 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) | | -| 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) | | | -| 1299 | [Replace Elements With Greatest Element on Right Side](https://leetcode.com/problems/replace-elements-with-greatest-element-on-right-side) | | | -| 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) | | | -| 1313 | [Decompress Run-Length Encoded Strings](https://leetcode.com/problems/decompress-run-length-encoded-list) | | | -| 1317 | [Convert Integer to Sum Of Two Non-Zero Integers](https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers) | | | -| 1323 | [Maximum 69 Number](https://leetcode.com/problems/maximum-69-number) | | | -| 1331 | [Rank Transform of An Array](https://leetcode.com/problems/rank-transform-of-an-array) | | | -| 1332 | [Remove Palindromic Subsequences](https://leetcode.com/problems/remove-palindromic-subsequences) | | | -| 1337 | [The K Weakest Rows In A Matrix](https://leetcode.com/problems/the-k-weakest-rows-in-a-matrix) | | | -| 1342 | [Number of Steps to Reduce a Number to Zero](https://leetcode.com/problems/number-of-steps-to-reduce-a-number-to-zero) | | | -| 1346 | [Check if N and It's Double Exist](https://leetcode.com/problems/check-if-n-and-its-double-exist) | | | -| 1351 | [Count Negative Numbers In A Sorted Matrix](https://leetcode.com/problems/count-negative-numbers-in-a-sorted-matrix) | | | -| 1356 | [Sort Integers by Number of 1 Bits](https://leetcode.com/problems/sort-integers-by-the-number-of-1-bits) | | | -| 1360 | [Number of Days Between Two Dates](https://leetcode.com/problems/number-of-days-between-two-dates) | | | -| 1365 | [How Many Numbers Are Smaller Than Current Number](https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number) | | | -| 1370 | [Increasing Decreasing String](https://leetcode.com/problems/increasing-decreasing-string) | | | -| 1374 | [Generate A String With Characters That Have Odd Count](https://leetcode.com/problems/generate-a-string-with-characters-that-have-odd-counts) | | | -| 1380 | [Lucky Numbers In A Matrix](https://leetcode.com/problems/lucky-numbers-in-a-matrix) | | | -| 1385 | [Find The Distance Value Between 2 Arrays](https://leetcode.com/problems/find-the-distance-value-between-two-arrays) | | | -| 1389 | [Create Target Array in Given Order](https://leetcode.com/problems/create-target-array-in-the-given-order) | | | -| 1394 | [Find Lucky Integer In An Array](https://leetcode.com/problems/find-lucky-integer-in-an-array) | | | -| 1399 | [Count Largest Group](https://leetcode.com/problems/count-largest-group) | | | -| 1403 | [Minimum Subsequence in Non-Increasing Order](https://leetcode.com/problems/minimum-subsequence-in-non-increasing-order) | | | -| 1408 | [String Matching In An Array](https://leetcode.com/problems/string-matching-in-an-array) | | | -| 1413 | [Minimum Value To Get Positive Step By Step Sum](https://leetcode.com/problems/minimum-value-to-get-positive-step-by-step-sum) | | | -| 1417 | [Reformat The String](https://leetcode.com/problems/reformat-the-string) | | | -| 1422 | [Maximum Score After Splitting A String](https://leetcode.com/problems/maximum-score-after-splitting-a-string) | | | -| 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) | | | -| 1436 | [Destination City](https://leetcode.com/problems/destination-city) | | | -| 1441 | [Build An Array With Stack Operation](https://leetcode.com/problems/build-an-array-with-stack-operations) | | | -| 1446 | [Consecutive Characters](https://leetcode.com/problems/consecutive-characters) | | | -| 1450 | [Number of Students Doing Homework at Given Time](https://leetcode.com/problems/number-of-students-doing-homework-at-a-given-time) | | | -| 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) | | | -| 1460 | [Make 2 Arrays Equal by Reversing Sub Arrays](https://leetcode.com/problems/make-two-arrays-equal-by-reversing-sub-arrays) | | | -| 1464 | [Maximum Product of 2 Elements in Array](https://leetcode.com/problems/maximum-product-of-two-elements-in-an-array) | | | -| 1469 | [Find All Lonely Nodes](https://leetcode.com/problems/find-all-the-lonely-nodes) | | | -| 1470 | [Shuffle The Array](https://leetcode.com/problems/shuffle-the-array) | | | -| 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) | | | -| 1480 | [Running Sum of 1D Array](https://leetcode.com/problems/running-sum-of-1d-array) | | | -| 1486 | [XOR Operations in An Array](https://leetcode.com/problems/xor-operation-in-an-array) | | | -| 1491 | [Average Salary Excluding the Minimum and Maximum Salary](https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary) | | | -| 1496 | [Path Crossing](https://leetcode.com/problems/path-crossing) | | | -| 1502 | [Can Make Arithmetic Progression From Sequence](https://leetcode.com/problems/can-make-arithmetic-progression-from-sequence) | | | -| 1507 | [Reformat Date](https://leetcode.com/problems/reformat-date) | | | -| 1512 | [Number of Good Pairs](https://leetcode.com/problems/number-of-good-pairs) | | | -| 1518 | [Water Bottles](https://leetcode.com/problems/water-bottles) | | | -| 1523 | [Count Odd Numbers In Interval Range](https://leetcode.com/problems/count-odd-numbers-in-an-interval-range) | | | -| 1528 | [Shuffle Strings](https://leetcode.com/problems/shuffle-string) | | | -| 1534 | [Count Good Triplets](https://leetcode.com/problems/count-good-triplets) | | | -| 1539 | [Kth Missing Positive Number](https://leetcode.com/problems/kth-missing-positive-number) | | | -| 1544 | [Make The String Great](https://leetcode.com/problems/make-the-string-great) | | | +| # | 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) | +| 7 | [Reverse Integer](https://leetcode.com/problems/reverse-integer/) | [![Java](assets/java.png)](src/ReverseInteger.java) [![Python](assets/python.png)](python/reverse_integer.py) | [![java-yt](assets/java-yt.png)](https://youtu.be/7bOhyl5lWjI) [![python-yt](assets/python-yt.png)](https://youtu.be/lmLG30TLcSg) | +| 9 | [PalindromeNumber](https://leetcode.com/problems/palindrome-number/) | [![Java](assets/java.png)](src/PalindromeNumber.java) [![Python](assets/python.png)](python/palindrome_number.py) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 136 | [Single Number](https://leetcode.com/problems/single-number) | [![Java](assets/java.png)](src/SingleNumber.java) [![Python](assets/python.png)](python/single_number.py) | | +| 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) | | +| 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) | | +| 155 | [Min Stack](https://leetcode.com/problems/min-stack) | [![Java](assets/java.png)](src/MinStack.java) [![Python](assets/python.png)](python/min_stack.py) | | +| 157 | [Read N Characters Given Read4](https://leetcode.com/problems/read-n-characters-given-read4) | | | +| 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) | | +| 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) | | +| 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) | | +| 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 Lists](https://leetcode.com/problems/reverse-linked-list) | [![Java](assets/java.png)](src/ReverseLinkedList.java) [![Python](assets/python.png)](python/reverse_linked_list.py) | | +| 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate) | [![Java](assets/java.png)](src/ContainsDuplicate.java) [![Python](assets/python.png)](python/contains_duplicate.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) | | +| 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) | | +| 226 | [Summary Ranges](https://leetcode.com/problems/summary-ranges/) | [![Java](assets/java.png)](src/SummaryRanges.java) [![Python](assets/python.png)](python/summary_ranges.py) | | +| 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) | | +| 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) | | +| 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) | | | +| 246 | 🔒 [Strobogramatic Number](https://leetcode.com/problems/strobogrammatic-number) | | | +| 252 | 🔒 [Meeting Rooms](https://leetcode.com/problems/meeting-rooms) | | | +| 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) | | +| 263 | [Ugly Number](https://leetcode.com/problems/ugly-number) | [![Java](assets/java.png)](src/UglyNumber.java) [![Python](assets/python.png)](python/ugly_number.py) | | +| 266 | 🔒 [Palindrome Permutation](https://leetcode.com/problems/palindrome-permutation) | | | +| 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) | | | +| 276 | 🔒 [Paint Fence](https://leetcode.com/problems/paint-fence) | | | +| 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) | | +| 283 | [Move Zeroes](https://leetcode.com/problems/move-zeroes) | [![Java](assets/java.png)](src/MoveZeros.java) [![Python](assets/python.png)](python/move_zeroes.py) | | +| 290 | [Word Pattern](https://leetcode.com/problems/word-pattern) | [![Java](assets/java.png)](src/WordPattern.java) [![Python](assets/python.png)](python/word_pattern.py) | | +| 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) | | | +| 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) | | +| 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) | | +| 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) | | +| 326 | [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) | | | +| 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) | | +| 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) | | | +| 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) | | +| 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) | | | +| 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) | | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | | +| 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) | | +| 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) | | | +| 1313 | [Decompress Run-Length Encoded Strings](https://leetcode.com/problems/decompress-run-length-encoded-list) | | | +| 1317 | [Convert Integer to Sum Of Two Non-Zero Integers](https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers) | | | +| 1323 | [Maximum 69 Number](https://leetcode.com/problems/maximum-69-number) | | | +| 1331 | [Rank Transform of An Array](https://leetcode.com/problems/rank-transform-of-an-array) | | | +| 1332 | [Remove Palindromic Subsequences](https://leetcode.com/problems/remove-palindromic-subsequences) | | | +| 1337 | [The K Weakest Rows In A Matrix](https://leetcode.com/problems/the-k-weakest-rows-in-a-matrix) | | | +| 1342 | [Number of Steps to Reduce a Number to Zero](https://leetcode.com/problems/number-of-steps-to-reduce-a-number-to-zero) | | | +| 1346 | [Check if N and It's Double Exist](https://leetcode.com/problems/check-if-n-and-its-double-exist) | | | +| 1351 | [Count Negative Numbers In A Sorted Matrix](https://leetcode.com/problems/count-negative-numbers-in-a-sorted-matrix) | | | +| 1356 | [Sort Integers by Number of 1 Bits](https://leetcode.com/problems/sort-integers-by-the-number-of-1-bits) | | | +| 1360 | [Number of Days Between Two Dates](https://leetcode.com/problems/number-of-days-between-two-dates) | | | +| 1365 | [How Many Numbers Are Smaller Than Current Number](https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number) | | | +| 1370 | [Increasing Decreasing String](https://leetcode.com/problems/increasing-decreasing-string) | | | +| 1374 | [Generate A String With Characters That Have Odd Count](https://leetcode.com/problems/generate-a-string-with-characters-that-have-odd-counts) | | | +| 1380 | [Lucky Numbers In A Matrix](https://leetcode.com/problems/lucky-numbers-in-a-matrix) | | | +| 1385 | [Find The Distance Value Between 2 Arrays](https://leetcode.com/problems/find-the-distance-value-between-two-arrays) | | | +| 1389 | [Create Target Array in Given Order](https://leetcode.com/problems/create-target-array-in-the-given-order) | | | +| 1394 | [Find Lucky Integer In An Array](https://leetcode.com/problems/find-lucky-integer-in-an-array) | | | +| 1399 | [Count Largest Group](https://leetcode.com/problems/count-largest-group) | | | +| 1403 | [Minimum Subsequence in Non-Increasing Order](https://leetcode.com/problems/minimum-subsequence-in-non-increasing-order) | | | +| 1408 | [String Matching In An Array](https://leetcode.com/problems/string-matching-in-an-array) | | | +| 1413 | [Minimum Value To Get Positive Step By Step Sum](https://leetcode.com/problems/minimum-value-to-get-positive-step-by-step-sum) | | | +| 1417 | [Reformat The String](https://leetcode.com/problems/reformat-the-string) | | | +| 1422 | [Maximum Score After Splitting A String](https://leetcode.com/problems/maximum-score-after-splitting-a-string) | | | +| 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) | | | +| 1436 | [Destination City](https://leetcode.com/problems/destination-city) | | | +| 1441 | [Build An Array With Stack Operation](https://leetcode.com/problems/build-an-array-with-stack-operations) | | | +| 1446 | [Consecutive Characters](https://leetcode.com/problems/consecutive-characters) | | | +| 1450 | [Number of Students Doing Homework at Given Time](https://leetcode.com/problems/number-of-students-doing-homework-at-a-given-time) | | | +| 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) | | | +| 1460 | [Make 2 Arrays Equal by Reversing Sub Arrays](https://leetcode.com/problems/make-two-arrays-equal-by-reversing-sub-arrays) | | | +| 1464 | [Maximum Product of 2 Elements in Array](https://leetcode.com/problems/maximum-product-of-two-elements-in-an-array) | | | +| 1469 | [Find All Lonely Nodes](https://leetcode.com/problems/find-all-the-lonely-nodes) | | | +| 1470 | [Shuffle The Array](https://leetcode.com/problems/shuffle-the-array) | | | +| 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) | | | +| 1480 | [Running Sum of 1D Array](https://leetcode.com/problems/running-sum-of-1d-array) | | | +| 1486 | [XOR Operations in An Array](https://leetcode.com/problems/xor-operation-in-an-array) | | | +| 1491 | [Average Salary Excluding the Minimum and Maximum Salary](https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary) | | | +| 1496 | [Path Crossing](https://leetcode.com/problems/path-crossing) | | | +| 1502 | [Can Make Arithmetic Progression From Sequence](https://leetcode.com/problems/can-make-arithmetic-progression-from-sequence) | | | +| 1507 | [Reformat Date](https://leetcode.com/problems/reformat-date) | | | +| 1512 | [Number of Good Pairs](https://leetcode.com/problems/number-of-good-pairs) | | | +| 1518 | [Water Bottles](https://leetcode.com/problems/water-bottles) | | | +| 1523 | [Count Odd Numbers In Interval Range](https://leetcode.com/problems/count-odd-numbers-in-an-interval-range) | | | +| 1528 | [Shuffle Strings](https://leetcode.com/problems/shuffle-string) | | | +| 1534 | [Count Good Triplets](https://leetcode.com/problems/count-good-triplets) | | | +| 1539 | [Kth Missing Positive Number](https://leetcode.com/problems/kth-missing-positive-number) | | | +| 1544 | [Make The String Great](https://leetcode.com/problems/make-the-string-great) | | | diff --git a/python/find_numbers_with_even_number_of_digits.py b/python/find_numbers_with_even_number_of_digits.py new file mode 100644 index 0000000..7c9b4a6 --- /dev/null +++ b/python/find_numbers_with_even_number_of_digits.py @@ -0,0 +1,19 @@ +from typing import List + + +class Solution: + def findNumbers(self, nums: List[int]) -> int: + evenDigitNumbers = 0 + for number in nums: + if self.numberOfDigits(number) % 2 == 0: + evenDigitNumbers += 1 + return evenDigitNumbers + + def numberOfDigits(self, number: int) -> int: + if number == 0: + return 1 + digits = 0 + while number != 0: + number //= 10 + digits += 1 + return digits diff --git a/python/replace_element_with_greatest_element_on_right_hand_side.py b/python/replace_element_with_greatest_element_on_right_hand_side.py new file mode 100644 index 0000000..2335259 --- /dev/null +++ b/python/replace_element_with_greatest_element_on_right_hand_side.py @@ -0,0 +1,13 @@ +from typing import List + + +class Solution: + def replaceElements(self, array: List[int]) -> List[int]: + result = [0] * len(array) + result[len(result) - 1] = -1 + index, greatest = len(array) - 2, array[len(array) - 1] + while index >= 0: + result[index] = greatest + greatest = max(greatest, array[index]) + index -= 1 + return result diff --git a/src/FindNumbersWithEvenNumbersOfDigits.java b/src/FindNumbersWithEvenNumbersOfDigits.java new file mode 100644 index 0000000..a8831bf --- /dev/null +++ b/src/FindNumbersWithEvenNumbersOfDigits.java @@ -0,0 +1,19 @@ +public class FindNumbersWithEvenNumbersOfDigits { + public int findNumbers(int[] array) { + int evenDigitNumbers = 0; + for (int number : array) { + if (numberOfDigits(number) % 2 == 0) evenDigitNumbers++; + } + return evenDigitNumbers; + } + + private int numberOfDigits(int number) { + if (number == 0) return 1; + int digits = 0; + while (number != 0) { + number /= 10; + digits++; + } + return digits; + } +} diff --git a/src/ReplaceElementWithGreatestElementOnRightSide.java b/src/ReplaceElementWithGreatestElementOnRightSide.java new file mode 100644 index 0000000..f81a86e --- /dev/null +++ b/src/ReplaceElementWithGreatestElementOnRightSide.java @@ -0,0 +1,11 @@ +public class ReplaceElementWithGreatestElementOnRightSide { + public int[] replaceElements(int[] array) { + int[] result = new int[array.length]; + result[result.length - 1] = -1; + for (int index = array.length - 2, max = array[array.length - 1]; index >= 0 ; index--) { + result[index] = max; + max = Math.max(max, array[index]); + } + return result; + } +} From 2b82db856d3dce5937284c89e0624e987e055b60 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 9 Dec 2021 01:00:38 +0100 Subject: [PATCH 289/947] updates stats --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0cbebb3..7da4d45 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-248/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-248/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-266/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-266/2081-1abc9c.svg) ![problems-solved-python](https://img.shields.io/badge/Python-186/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) From f9302f75428f2f56c16f9aeb2dce62d69c432820 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 9 Dec 2021 10:28:32 +0100 Subject: [PATCH 290/947] solves decrypt string from alphabet to integer mapping --- README.md | 2 +- ...yptStringFromAlphabetToIntegerMapping.java | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 src/DecryptStringFromAlphabetToIntegerMapping.java diff --git a/README.md b/README.md index 7da4d45..4aa5126 100644 --- a/README.md +++ b/README.md @@ -336,7 +336,7 @@ | 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) | | | +| 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) | | | | 1317 | [Convert Integer to Sum Of Two Non-Zero Integers](https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers) | | | | 1323 | [Maximum 69 Number](https://leetcode.com/problems/maximum-69-number) | | | diff --git a/src/DecryptStringFromAlphabetToIntegerMapping.java b/src/DecryptStringFromAlphabetToIntegerMapping.java new file mode 100644 index 0000000..9a3323c --- /dev/null +++ b/src/DecryptStringFromAlphabetToIntegerMapping.java @@ -0,0 +1,36 @@ +import java.util.LinkedList; +import java.util.Queue; + +public class DecryptStringFromAlphabetToIntegerMapping { + public String freqAlphabets(String s) { + final StringBuilder result = new StringBuilder(); + final Queue queue = new LinkedList<>(); + for (int index = 0 ; index < s.length() ; index++) { + if (queue.size() == 2) { + if (s.charAt(index) == '#') { + result.append(numberToChar(queue.poll(), queue.poll())); + continue; + } else { + result.append(numberToChar(queue.poll())); + } + } + queue.add(s.charAt(index)); + } + while (!queue.isEmpty()) { + result.append(numberToChar(queue.poll())); + } + return result.toString(); + } + + private char numberToChar(char a, char b) { + return numberToChar(10 * (a - '0') + (b - '0')); + } + + private char numberToChar(char digit) { + return numberToChar(digit - '0'); + } + + private char numberToChar(int digit) { + return (char) (digit + 'a' - 1); + } +} From f13fd31e2d2a0531305601c0f5a84c8a165d2548 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 9 Dec 2021 10:33:42 +0100 Subject: [PATCH 291/947] solves decompressrun length encoded list --- README.md | 2 +- src/DecompressRunLengthEncodedList.java | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/DecompressRunLengthEncodedList.java diff --git a/README.md b/README.md index 4aa5126..912faff 100644 --- a/README.md +++ b/README.md @@ -337,7 +337,7 @@ | 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) | | | +| 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) | | | | 1323 | [Maximum 69 Number](https://leetcode.com/problems/maximum-69-number) | | | | 1331 | [Rank Transform of An Array](https://leetcode.com/problems/rank-transform-of-an-array) | | | diff --git a/src/DecompressRunLengthEncodedList.java b/src/DecompressRunLengthEncodedList.java new file mode 100644 index 0000000..964a5bc --- /dev/null +++ b/src/DecompressRunLengthEncodedList.java @@ -0,0 +1,20 @@ +public class DecompressRunLengthEncodedList { + public int[] decompressRLElist(int[] nums) { + final int totalElements = sumOfFrequency(nums); + final int[] result = new int[totalElements]; + for (int i = 1, k = 0; i < nums.length ; i += 2) { + for (int j = 0 ; j < nums[i - 1] ; j++) { + result[k++] = nums[i]; + } + } + return result; + } + + private int sumOfFrequency(int[] array) { + int sum = 0; + for (int i = 0 ; i < array.length ; i += 2) { + sum += array[i]; + } + return sum; + } +} From 0509ac60580247d15f81534afc2688b1a3e234b6 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 9 Dec 2021 10:40:54 +0100 Subject: [PATCH 292/947] solves convert integer to the sum of two no zero integers --- README.md | 4 ++-- ...vertIntegerToTheSumOfTwoNoZeroIntegers.java | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 src/ConvertIntegerToTheSumOfTwoNoZeroIntegers.java diff --git a/README.md b/README.md index 912faff..47dd4c6 100644 --- a/README.md +++ b/README.md @@ -337,8 +337,8 @@ | 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) | | | +| 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) | | | 1323 | [Maximum 69 Number](https://leetcode.com/problems/maximum-69-number) | | | | 1331 | [Rank Transform of An Array](https://leetcode.com/problems/rank-transform-of-an-array) | | | | 1332 | [Remove Palindromic Subsequences](https://leetcode.com/problems/remove-palindromic-subsequences) | | | diff --git a/src/ConvertIntegerToTheSumOfTwoNoZeroIntegers.java b/src/ConvertIntegerToTheSumOfTwoNoZeroIntegers.java new file mode 100644 index 0000000..9d5aa3f --- /dev/null +++ b/src/ConvertIntegerToTheSumOfTwoNoZeroIntegers.java @@ -0,0 +1,18 @@ +public class ConvertIntegerToTheSumOfTwoNoZeroIntegers { + public int[] getNoZeroIntegers(int n) { + for (int i = 1 ; i <= n / 2 ; i++) { + if (isNonZeroInteger(i) && isNonZeroInteger(n - i)) { + return new int[] {i, n - i}; + } + } + return new int[0]; + } + + private boolean isNonZeroInteger(int n) { + while (n > 0) { + if (n % 10 == 0) return false; + n /= 10; + } + return true; + } +} From 70713241bb2489e7e2e28ad4c69bb47725b3cf33 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 9 Dec 2021 10:47:17 +0100 Subject: [PATCH 293/947] solves maximum number 69 --- README.md | 2 +- src/Maximum69Number.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/Maximum69Number.java diff --git a/README.md b/README.md index 47dd4c6..dcc818b 100644 --- a/README.md +++ b/README.md @@ -339,7 +339,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) | | -| 1323 | [Maximum 69 Number](https://leetcode.com/problems/maximum-69-number) | | | +| 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) | | | | 1332 | [Remove Palindromic Subsequences](https://leetcode.com/problems/remove-palindromic-subsequences) | | | | 1337 | [The K Weakest Rows In A Matrix](https://leetcode.com/problems/the-k-weakest-rows-in-a-matrix) | | | diff --git a/src/Maximum69Number.java b/src/Maximum69Number.java new file mode 100644 index 0000000..c28749f --- /dev/null +++ b/src/Maximum69Number.java @@ -0,0 +1,19 @@ +public class Maximum69Number { + public int maximum69Number (int num) { + int result = 0; + int divisor = 10_000; + boolean changed = false; + while (num > 0) { + result *= 10; + if (!changed && num / divisor == 6) { + result += 9; + changed = true; + } else { + result += num / divisor; + } + num -= (num / divisor) * divisor; + divisor /= 10; + } + return result; + } +} From a9a5603c329ce4c763c91e38b80867d97d3a149c Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 9 Dec 2021 12:04:52 +0100 Subject: [PATCH 294/947] solves remove palindromic sub sequences --- README.md | 4 ++-- src/RankTransformOfArray.java | 26 ++++++++++++++++++++++++++ src/RemovePalindromicSubSequences.java | 12 ++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 src/RankTransformOfArray.java create mode 100644 src/RemovePalindromicSubSequences.java diff --git a/README.md b/README.md index dcc818b..7c43fc7 100644 --- a/README.md +++ b/README.md @@ -340,8 +340,8 @@ | 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) | | | 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) | | | -| 1332 | [Remove Palindromic Subsequences](https://leetcode.com/problems/remove-palindromic-subsequences) | | | +| 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) | | | | 1342 | [Number of Steps to Reduce a Number to Zero](https://leetcode.com/problems/number-of-steps-to-reduce-a-number-to-zero) | | | | 1346 | [Check if N and It's Double Exist](https://leetcode.com/problems/check-if-n-and-its-double-exist) | | | diff --git a/src/RankTransformOfArray.java b/src/RankTransformOfArray.java new file mode 100644 index 0000000..02f502a --- /dev/null +++ b/src/RankTransformOfArray.java @@ -0,0 +1,26 @@ +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +public class RankTransformOfArray { + public int[] arrayRankTransform(int[] array) { + final Map elementRank = getElementRanks(array); + final int[] result = new int[array.length]; + for (int index = 0 ; index < array.length ; index++) { + result[index] = elementRank.get(array[index]); + } + return result; + } + + private Map getElementRanks(int[] array) { + final int[] sorted = array.clone(); + Arrays.sort(sorted); + final Map result = new HashMap<>(); + for (int i = 0, rank = 1 ; i < sorted.length ; i++) { + if (!result.containsKey(sorted[i])) { + result.put(sorted[i], rank++); + } + } + return result; + } +} diff --git a/src/RemovePalindromicSubSequences.java b/src/RemovePalindromicSubSequences.java new file mode 100644 index 0000000..7ce5a40 --- /dev/null +++ b/src/RemovePalindromicSubSequences.java @@ -0,0 +1,12 @@ +public class RemovePalindromicSubSequences { + public int removePalindromeSub(String s) { + return isPalindrome(s) ? 1 : 2; + } + + private boolean isPalindrome(String s) { + for (int i = 0 ; i < s.length() / 2 ; i++) { + if (s.charAt(i) != s.charAt(s.length() - 1 - i)) return false; + } + return true; + } +} From f0473ad63a948c185dea1f55a7f53affa73d2271 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 9 Dec 2021 12:11:57 +0100 Subject: [PATCH 295/947] a --- src/TheKWeakestRowsInAMatrix.java | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/TheKWeakestRowsInAMatrix.java diff --git a/src/TheKWeakestRowsInAMatrix.java b/src/TheKWeakestRowsInAMatrix.java new file mode 100644 index 0000000..9027878 --- /dev/null +++ b/src/TheKWeakestRowsInAMatrix.java @@ -0,0 +1,26 @@ +import java.util.PriorityQueue; +import java.util.Queue; + +public class TheKWeakestRowsInAMatrix { + public int[] kWeakestRows(int[][] mat, int k) { + Queue minHeap = new PriorityQueue<>(); + for (int[] row: mat) { + minHeap.add() + } + } + + private record Row(int index, int soldiers) implements Comparable { + + @Override + public int compareTo(Row other) { + if (this.soldiers == other.soldiers) { + return Integer.compare(this.index, other.index); + } + return Integer.compare(this.soldiers, other.soldiers); + } + + private static Row from(int[] row, int index) { + for (int) + } + } +} From 82ea40b070316e56602e9599ff1dc85dd11b9b75 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 9 Dec 2021 12:57:04 +0100 Subject: [PATCH 296/947] solves k weakest rows in a matrix --- README.md | 2 +- src/TheKWeakestRowsInAMatrix.java | 26 +++++++++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 7c43fc7..1fd96c9 100644 --- a/README.md +++ b/README.md @@ -342,7 +342,7 @@ | 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) | | | +| 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) | | | | 1346 | [Check if N and It's Double Exist](https://leetcode.com/problems/check-if-n-and-its-double-exist) | | | | 1351 | [Count Negative Numbers In A Sorted Matrix](https://leetcode.com/problems/count-negative-numbers-in-a-sorted-matrix) | | | diff --git a/src/TheKWeakestRowsInAMatrix.java b/src/TheKWeakestRowsInAMatrix.java index 9027878..da67da4 100644 --- a/src/TheKWeakestRowsInAMatrix.java +++ b/src/TheKWeakestRowsInAMatrix.java @@ -3,13 +3,25 @@ public class TheKWeakestRowsInAMatrix { public int[] kWeakestRows(int[][] mat, int k) { - Queue minHeap = new PriorityQueue<>(); - for (int[] row: mat) { - minHeap.add() + final Queue minHeap = new PriorityQueue<>(); + for (int index = 0 ; index < mat.length ; index++) { + minHeap.add(Row.from(mat[index], index)); } + final int[] result = new int[k]; + for (int i = 0 ; i < result.length ; i++) { + result[i] = minHeap.poll().index; + } + return result; } - private record Row(int index, int soldiers) implements Comparable { + private static final class Row implements Comparable { + private final int index; + private final int soldiers; + + private Row(int index, int soldiers) { + this.index = index; + this.soldiers = soldiers; + } @Override public int compareTo(Row other) { @@ -20,7 +32,11 @@ public int compareTo(Row other) { } private static Row from(int[] row, int index) { - for (int) + int soldiers = 0; + for (int i = 0; i < row.length && row[i] == 1; i++) { + soldiers++; + } + return new Row(index, soldiers); } } } From 19a314cbf7681c4a8b591c607fb555b431727bf9 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 9 Dec 2021 13:03:29 +0100 Subject: [PATCH 297/947] solves number of steps to reduce a nuimber to zero --- README.md | 6 +++--- src/NumberOfStepsToReduceANumberToZero.java | 11 +++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 src/NumberOfStepsToReduceANumberToZero.java diff --git a/README.md b/README.md index 1fd96c9..22b75d3 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-266/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-266/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-273/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-273/2081-1abc9c.svg) ![problems-solved-python](https://img.shields.io/badge/Python-186/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) @@ -343,7 +343,7 @@ | 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) | | | +| 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) | | | | 1351 | [Count Negative Numbers In A Sorted Matrix](https://leetcode.com/problems/count-negative-numbers-in-a-sorted-matrix) | | | | 1356 | [Sort Integers by Number of 1 Bits](https://leetcode.com/problems/sort-integers-by-the-number-of-1-bits) | | | diff --git a/src/NumberOfStepsToReduceANumberToZero.java b/src/NumberOfStepsToReduceANumberToZero.java new file mode 100644 index 0000000..3402b00 --- /dev/null +++ b/src/NumberOfStepsToReduceANumberToZero.java @@ -0,0 +1,11 @@ +public class NumberOfStepsToReduceANumberToZero { + public int numberOfSteps(int num) { + int steps = 0; + while (num > 0) { + steps++; + if ((num & 1) == 0) num >>= 1; + else num -= 1; + } + return steps; + } +} From bdbde9c8082e30f22317efeffe4285b0aba65ecb Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 9 Dec 2021 13:07:33 +0100 Subject: [PATCH 298/947] solves check n and its double exists --- README.md | 2 +- python/check_if_n_and_its_double_exist.py | 11 +++++++++++ src/CheckIfNAndItsDoubleExist.java | 15 +++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 python/check_if_n_and_its_double_exist.py create mode 100644 src/CheckIfNAndItsDoubleExist.java diff --git a/README.md b/README.md index 22b75d3..f0d7cde 100644 --- a/README.md +++ b/README.md @@ -344,7 +344,7 @@ | 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) | | | +| 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) | | | | 1356 | [Sort Integers by Number of 1 Bits](https://leetcode.com/problems/sort-integers-by-the-number-of-1-bits) | | | | 1360 | [Number of Days Between Two Dates](https://leetcode.com/problems/number-of-days-between-two-dates) | | | diff --git a/python/check_if_n_and_its_double_exist.py b/python/check_if_n_and_its_double_exist.py new file mode 100644 index 0000000..0a677c8 --- /dev/null +++ b/python/check_if_n_and_its_double_exist.py @@ -0,0 +1,11 @@ +from typing import List + + +class Solution: + def checkIfExist(self, arr: List[int]) -> bool: + elements = set() + for number in arr: + if 2 * number in elements or (number % 2 == 0 and number // 2 in elements): + return True + elements.add(number) + return False diff --git a/src/CheckIfNAndItsDoubleExist.java b/src/CheckIfNAndItsDoubleExist.java new file mode 100644 index 0000000..e7306ea --- /dev/null +++ b/src/CheckIfNAndItsDoubleExist.java @@ -0,0 +1,15 @@ +import java.util.HashSet; +import java.util.Set; + +public class CheckIfNAndItsDoubleExist { + public boolean checkIfExist(int[] array) { + Set elements = new HashSet<>(); + for(int element : array) { + if (elements.contains(element * 2) || (element % 2 == 0 && elements.contains(element / 2))) { + return true; + } + elements.add(element); + } + return false; + } +} From 4b8cb65c49dbb9a9c74355cf33ccc1e9257ba3ac Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 9 Dec 2021 17:59:36 +0100 Subject: [PATCH 299/947] solves count negative number in sorted matrix --- README.md | 2 +- src/CountNegativeNumbersInSortedMatrix.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/CountNegativeNumbersInSortedMatrix.java diff --git a/README.md b/README.md index f0d7cde..fdc7a9e 100644 --- a/README.md +++ b/README.md @@ -345,7 +345,7 @@ | 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) | | | +| 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) | | | | 1360 | [Number of Days Between Two Dates](https://leetcode.com/problems/number-of-days-between-two-dates) | | | | 1365 | [How Many Numbers Are Smaller Than Current Number](https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number) | | | diff --git a/src/CountNegativeNumbersInSortedMatrix.java b/src/CountNegativeNumbersInSortedMatrix.java new file mode 100644 index 0000000..cad7784 --- /dev/null +++ b/src/CountNegativeNumbersInSortedMatrix.java @@ -0,0 +1,17 @@ +public class CountNegativeNumbersInSortedMatrix { + public int countNegatives(int[][] grid) { + final int rows = grid.length, columns = grid[0].length; + int negativeNumbers = 0, negativeColumnIndex = columns; + for (int[] row : grid) { + negativeNumbers += columns; + for (int column = 0 ; column < negativeColumnIndex ; column++) { + if (row[column] < 0) { + negativeColumnIndex = column; + break; + } + negativeNumbers--; + } + } + return negativeNumbers; + } +} From a4e1a104058d5533db9ce246e155ef3c33b36804 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 9 Dec 2021 18:20:09 +0100 Subject: [PATCH 300/947] solves sort integers by number of 1 bits --- README.md | 2 +- src/SortIntegersByTheNumberOf1Bits.java | 31 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/SortIntegersByTheNumberOf1Bits.java diff --git a/README.md b/README.md index fdc7a9e..4a7fc61 100644 --- a/README.md +++ b/README.md @@ -346,7 +346,7 @@ | 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) | | | +| 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) | | | | 1365 | [How Many Numbers Are Smaller Than Current Number](https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number) | | | | 1370 | [Increasing Decreasing String](https://leetcode.com/problems/increasing-decreasing-string) | | | diff --git a/src/SortIntegersByTheNumberOf1Bits.java b/src/SortIntegersByTheNumberOf1Bits.java new file mode 100644 index 0000000..3485fc5 --- /dev/null +++ b/src/SortIntegersByTheNumberOf1Bits.java @@ -0,0 +1,31 @@ +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +public class SortIntegersByTheNumberOf1Bits { + public int[] sortByBits(int[] array) { + List sorted = Arrays.stream(array).boxed().sorted((a, b) -> { + final int setBits1 = setBits(a), setBits2 = setBits(b); + if (setBits1 == setBits2) return Integer.compare(a, b); + return Integer.compare(setBits1, setBits2); + }).collect(Collectors.toList()); + return toArray(sorted); + } + + private int[] toArray(List array) { + final int[] result = new int[array.size()]; + for (int index = 0 ; index < result.length ; index++) { + result[index] = array.get(index); + } + return result; + } + + private int setBits(int number) { + int setBits = 0; + while (number > 0) { + setBits += number & 1; + number >>= 1; + } + return setBits; + } +} From f122cd618a36fb15b232f628f1e1c934c142f964 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 9 Dec 2021 23:42:47 +0100 Subject: [PATCH 301/947] solves number of days between dates --- README.md | 2 +- src/NumberOfDaysBetweenTwoDates.java | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 src/NumberOfDaysBetweenTwoDates.java diff --git a/README.md b/README.md index 4a7fc61..aa13b7c 100644 --- a/README.md +++ b/README.md @@ -347,7 +347,7 @@ | 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) | | | +| 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) | | | | 1370 | [Increasing Decreasing String](https://leetcode.com/problems/increasing-decreasing-string) | | | | 1374 | [Generate A String With Characters That Have Odd Count](https://leetcode.com/problems/generate-a-string-with-characters-that-have-odd-counts) | | | diff --git a/src/NumberOfDaysBetweenTwoDates.java b/src/NumberOfDaysBetweenTwoDates.java new file mode 100644 index 0000000..d36f229 --- /dev/null +++ b/src/NumberOfDaysBetweenTwoDates.java @@ -0,0 +1,21 @@ +import java.time.LocalDate; + +import static java.time.temporal.ChronoUnit.DAYS; + +public class NumberOfDaysBetweenTwoDates { + public int daysBetweenDates(String date1, String date2) { + final String[] dateParts1 = date1.split("-"); + final String[] dateParts2 = date2.split("-"); + final LocalDate d1 = LocalDate.of( + Integer.parseInt(dateParts1[0]), + Integer.parseInt(dateParts1[1]), + Integer.parseInt(dateParts1[2]) + ); + final LocalDate d2 = LocalDate.of( + Integer.parseInt(dateParts2[0]), + Integer.parseInt(dateParts2[1]), + Integer.parseInt(dateParts2[2]) + ); + return (int) Math.abs(DAYS.between(d1, d2)); + } +} From eb341fcafb440a3ff1c5d1a50f95b4330059f26b Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 9 Dec 2021 23:52:43 +0100 Subject: [PATCH 302/947] solves how many numbers are smaller than current number --- README.md | 2 +- ...anyNumbersAreSmallerThanCurrentNumber.java | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/HowManyNumbersAreSmallerThanCurrentNumber.java diff --git a/README.md b/README.md index aa13b7c..0955476 100644 --- a/README.md +++ b/README.md @@ -348,7 +348,7 @@ | 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) | | | +| 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) | | | | 1374 | [Generate A String With Characters That Have Odd Count](https://leetcode.com/problems/generate-a-string-with-characters-that-have-odd-counts) | | | | 1380 | [Lucky Numbers In A Matrix](https://leetcode.com/problems/lucky-numbers-in-a-matrix) | | | diff --git a/src/HowManyNumbersAreSmallerThanCurrentNumber.java b/src/HowManyNumbersAreSmallerThanCurrentNumber.java new file mode 100644 index 0000000..ce51557 --- /dev/null +++ b/src/HowManyNumbersAreSmallerThanCurrentNumber.java @@ -0,0 +1,27 @@ +public class HowManyNumbersAreSmallerThanCurrentNumber { + public int[] smallerNumbersThanCurrent(int[] nums) { + final int[] elementsFrequency = getElementsFrequency(nums); + final int[] elementsSmallerThan = countSmallerThan(elementsFrequency); + final int[] result = new int[nums.length]; + for (int i = 0 ; i < nums.length ; i++) { + result[i] = elementsSmallerThan[nums[i]]; + } + return result; + } + + private int[] getElementsFrequency(int[] array) { + final int[] frequency = new int[101]; + for (int element : array) { + frequency[element]++; + } + return frequency; + } + + private int[] countSmallerThan(int[] frequency) { + final int[] smallerThan = new int[101]; + for (int i = 1 ; i < 101 ; i++) { + smallerThan[i] = smallerThan[i - 1] + frequency[i - 1]; + } + return smallerThan; + } +} From 210c00b12ea71cf38a0ec7854a25e57ea0114129 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 10 Dec 2021 00:36:16 +0100 Subject: [PATCH 303/947] solves increasing decreasing string --- README.md | 2 +- src/IncreasingDecreasingString.java | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/IncreasingDecreasingString.java diff --git a/README.md b/README.md index 0955476..8d0505e 100644 --- a/README.md +++ b/README.md @@ -349,7 +349,7 @@ | 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) | | | +| 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) | | | | 1380 | [Lucky Numbers In A Matrix](https://leetcode.com/problems/lucky-numbers-in-a-matrix) | | | | 1385 | [Find The Distance Value Between 2 Arrays](https://leetcode.com/problems/find-the-distance-value-between-two-arrays) | | | diff --git a/src/IncreasingDecreasingString.java b/src/IncreasingDecreasingString.java new file mode 100644 index 0000000..d3ee300 --- /dev/null +++ b/src/IncreasingDecreasingString.java @@ -0,0 +1,29 @@ +public class IncreasingDecreasingString { + public String sortString(String s) { + final int[] frequency = getFrequency(s); + final StringBuilder result = new StringBuilder(); + while (result.length() < s.length()) { + for (int i = 0 ; i < frequency.length ; i++) { + if (frequency[i] > 0) { + result.append((char) ('a' + i)); + frequency[i]--; + } + } + for (int i = frequency.length - 1 ; i >= 0 ; i--) { + if (frequency[i] > 0) { + result.append((char) ('a' + i)); + frequency[i]--; + } + } + } + return result.toString(); + } + + private int[] getFrequency(String string) { + final int[] frequencies = new int[26]; + for (int i = 0 ; i < string.length() ; i++) { + frequencies[string.charAt(i) - 'a']++; + } + return frequencies; + } +} From 609a35e9d48d53df0e2373451b17369756bbb5ee Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 10 Dec 2021 00:41:41 +0100 Subject: [PATCH 304/947] solves generate a string with characters that have odd counts --- README.md | 2 +- src/GenerateAStringWithCharactersThatHaveOddCounts.java | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 src/GenerateAStringWithCharactersThatHaveOddCounts.java diff --git a/README.md b/README.md index 8d0505e..ce5e070 100644 --- a/README.md +++ b/README.md @@ -350,7 +350,7 @@ | 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) | | | +| 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) | | | 1380 | [Lucky Numbers In A Matrix](https://leetcode.com/problems/lucky-numbers-in-a-matrix) | | | | 1385 | [Find The Distance Value Between 2 Arrays](https://leetcode.com/problems/find-the-distance-value-between-two-arrays) | | | | 1389 | [Create Target Array in Given Order](https://leetcode.com/problems/create-target-array-in-the-given-order) | | | diff --git a/src/GenerateAStringWithCharactersThatHaveOddCounts.java b/src/GenerateAStringWithCharactersThatHaveOddCounts.java new file mode 100644 index 0000000..a7c91b5 --- /dev/null +++ b/src/GenerateAStringWithCharactersThatHaveOddCounts.java @@ -0,0 +1,7 @@ +public class GenerateAStringWithCharactersThatHaveOddCounts { + public String generateTheString(int n) { + if ((n & 1) == 0) { + return "a".repeat(n - 1) + "b"; + } return "a".repeat(n); + } +} From d548f61d6c67b13cd3b9c6c11be84ce49d1bbf11 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 10 Dec 2021 00:58:42 +0100 Subject: [PATCH 305/947] solves lucky numbers in a matrix --- README.md | 2 +- src/LuckyNumbersInAMatrix.java | 49 ++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 src/LuckyNumbersInAMatrix.java diff --git a/README.md b/README.md index ce5e070..cd94a96 100644 --- a/README.md +++ b/README.md @@ -351,7 +351,7 @@ | 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) | | -| 1380 | [Lucky Numbers In A Matrix](https://leetcode.com/problems/lucky-numbers-in-a-matrix) | | | +| 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) | | | | 1389 | [Create Target Array in Given Order](https://leetcode.com/problems/create-target-array-in-the-given-order) | | | | 1394 | [Find Lucky Integer In An Array](https://leetcode.com/problems/find-lucky-integer-in-an-array) | | | diff --git a/src/LuckyNumbersInAMatrix.java b/src/LuckyNumbersInAMatrix.java new file mode 100644 index 0000000..e26e5a7 --- /dev/null +++ b/src/LuckyNumbersInAMatrix.java @@ -0,0 +1,49 @@ +import java.util.ArrayList; +import java.util.List; + +public class LuckyNumbersInAMatrix { + public List luckyNumbers (int[][] matrix) { + final int rows = matrix.length, columns = matrix[0].length; + final List luckyNumbers = new ArrayList<>(); + int[] columnMax = getMaxOfColumns(matrix); + for (int row = 0 ; row < rows ; row++) { + RowMin rowMin = RowMin.from(matrix[row]); + if (rowMin.min == columnMax[rowMin.index]) { + luckyNumbers.add(rowMin.min); + } + } + return luckyNumbers; + } + + private static final class RowMin { + private final int index; + private final int min; + + private RowMin(int index, int min) { + this.index = index; + this.min = min; + } + + private static RowMin from(int[] row) { + int minIndex = 0, min = row[0]; + for (int i = 1; i < row.length; i++) { + if (row[i] < min) { + minIndex = i; + min = row[i]; + } + } + return new RowMin(minIndex, min); + } + } + + private int[] getMaxOfColumns(int[][] grid) { + final int rows = grid.length, columns = grid[0].length; + final int[] columnsMax = new int[columns]; + for (int[] row : grid) { + for (int column = 0 ; column < columns ; column++) { + columnsMax[column] = Math.max(columnsMax[column], row[column]); + } + } + return columnsMax; + } +} From ba2d38e9c30f9a2f1a88056dbe3cc860bc792e80 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 12 Dec 2021 20:45:12 +0100 Subject: [PATCH 306/947] solves find teh values between two arrays --- README.md | 2 +- ...FindTheDistanceValuesBetweenTwoArrays.java | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/FindTheDistanceValuesBetweenTwoArrays.java diff --git a/README.md b/README.md index cd94a96..8775569 100644 --- a/README.md +++ b/README.md @@ -352,7 +352,7 @@ | 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) | | | 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) | | | +| 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) | | | | 1394 | [Find Lucky Integer In An Array](https://leetcode.com/problems/find-lucky-integer-in-an-array) | | | | 1399 | [Count Largest Group](https://leetcode.com/problems/count-largest-group) | | | diff --git a/src/FindTheDistanceValuesBetweenTwoArrays.java b/src/FindTheDistanceValuesBetweenTwoArrays.java new file mode 100644 index 0000000..46617a2 --- /dev/null +++ b/src/FindTheDistanceValuesBetweenTwoArrays.java @@ -0,0 +1,32 @@ +import java.util.TreeSet; + +public class FindTheDistanceValuesBetweenTwoArrays { + public int findTheDistanceValue(int[] arr1, int[] arr2, int d) { + TreeSet set = new TreeSet<>(); + for (int number : arr2) { + set.add(number); + } + int distanceValue = 0; + for (int number : arr1) { + if (smallerOrEqual(set, number) < number - d && largerOrEqual(set, number) > number + d) { + distanceValue++; + } + } + return distanceValue; + } + + private int smallerOrEqual(TreeSet set, int number) { + if (set.contains(number)) return number; + return valIfNull(set.lower(number), Integer.MIN_VALUE); + } + + private int largerOrEqual(TreeSet set, int number) { + if (set.contains(number)) return number; + return valIfNull(set.higher(number), Integer.MAX_VALUE); + } + + private int valIfNull(Integer value, int defaultValue) { + if (value == null) return defaultValue; + return value; + } +} From e6b76de5a219e49e8ca52f5fffb2631c91604127 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 13 Dec 2021 09:27:14 +0100 Subject: [PATCH 307/947] updates stats --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8775569..700d60b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-273/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-273/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-282/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-282/2081-1abc9c.svg) ![problems-solved-python](https://img.shields.io/badge/Python-186/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) From 89155efe369c14b1c7e3988343b7c3fffa3d231b Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Wed, 15 Dec 2021 15:56:28 +0100 Subject: [PATCH 308/947] solves create target array in given order --- README.md | 2 +- src/CreateTargetArrayInGivenOrder.java | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/CreateTargetArrayInGivenOrder.java diff --git a/README.md b/README.md index 700d60b..165919e 100644 --- a/README.md +++ b/README.md @@ -356,7 +356,7 @@ | 1389 | [Create Target Array in Given Order](https://leetcode.com/problems/create-target-array-in-the-given-order) | | | | 1394 | [Find Lucky Integer In An Array](https://leetcode.com/problems/find-lucky-integer-in-an-array) | | | | 1399 | [Count Largest Group](https://leetcode.com/problems/count-largest-group) | | | -| 1403 | [Minimum Subsequence in Non-Increasing Order](https://leetcode.com/problems/minimum-subsequence-in-non-increasing-order) | | | +| 1403 | [Minimum Subsequence in Non-Increasing Order](https://leetcode.com/problems/minimum-subsequence-in-non-increasing-order) | [![Java](assets/java.png)](src/CreateTargetArrayInGivenOrder.java) | | | 1408 | [String Matching In An Array](https://leetcode.com/problems/string-matching-in-an-array) | | | | 1413 | [Minimum Value To Get Positive Step By Step Sum](https://leetcode.com/problems/minimum-value-to-get-positive-step-by-step-sum) | | | | 1417 | [Reformat The String](https://leetcode.com/problems/reformat-the-string) | | | diff --git a/src/CreateTargetArrayInGivenOrder.java b/src/CreateTargetArrayInGivenOrder.java new file mode 100644 index 0000000..d8fe8bb --- /dev/null +++ b/src/CreateTargetArrayInGivenOrder.java @@ -0,0 +1,20 @@ +import java.util.ArrayList; +import java.util.List; + +public class CreateTargetArrayInGivenOrder { + public int[] createTargetArray(int[] nums, int[] index) { + List result = new ArrayList<>(); + for (int i = 0 ; i < index.length ; i++) { + result.add(index[i], nums[i]); + } + return toArray(result); + } + + private int[] toArray(List list) { + int[] array = new int[list.size()]; + for (int index = 0 ; index < array.length ; index++) { + array[index] = list.get(index); + } + return array; + } +} From a824885566790cb05c65277a4037962598eaf433 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Wed, 15 Dec 2021 15:58:19 +0100 Subject: [PATCH 309/947] solves create target array in given order --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 165919e..65a7be0 100644 --- a/README.md +++ b/README.md @@ -353,10 +353,10 @@ | 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) | | | 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) | | | +| 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) | | | | 1399 | [Count Largest Group](https://leetcode.com/problems/count-largest-group) | | | -| 1403 | [Minimum Subsequence in Non-Increasing Order](https://leetcode.com/problems/minimum-subsequence-in-non-increasing-order) | [![Java](assets/java.png)](src/CreateTargetArrayInGivenOrder.java) | | +| 1403 | [Minimum Subsequence in Non-Increasing Order](https://leetcode.com/problems/minimum-subsequence-in-non-increasing-order) | | | | 1408 | [String Matching In An Array](https://leetcode.com/problems/string-matching-in-an-array) | | | | 1413 | [Minimum Value To Get Positive Step By Step Sum](https://leetcode.com/problems/minimum-value-to-get-positive-step-by-step-sum) | | | | 1417 | [Reformat The String](https://leetcode.com/problems/reformat-the-string) | | | From 232a23b8f12212cd66f69cc3e277ba2320ee3c29 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 15 Dec 2021 20:25:19 +0100 Subject: [PATCH 310/947] solves find the luckt number ina n array --- README.md | 2 +- src/FindTheLuckyIntegerInAnArray.java | 32 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/FindTheLuckyIntegerInAnArray.java diff --git a/README.md b/README.md index 65a7be0..646f22e 100644 --- a/README.md +++ b/README.md @@ -354,7 +354,7 @@ | 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) | | | +| 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) | | | | 1403 | [Minimum Subsequence in Non-Increasing Order](https://leetcode.com/problems/minimum-subsequence-in-non-increasing-order) | | | | 1408 | [String Matching In An Array](https://leetcode.com/problems/string-matching-in-an-array) | | | diff --git a/src/FindTheLuckyIntegerInAnArray.java b/src/FindTheLuckyIntegerInAnArray.java new file mode 100644 index 0000000..9ec28b1 --- /dev/null +++ b/src/FindTheLuckyIntegerInAnArray.java @@ -0,0 +1,32 @@ +import java.util.Comparator; +import java.util.HashMap; +import java.util.Map; +import java.util.PriorityQueue; +import java.util.Queue; + +public class FindTheLuckyIntegerInAnArray { + public int findLucky(int[] array) { + Map frequencies = getFrequencies(array); + Queue luckyIntegers = getLuckyIntegers(frequencies); + if (luckyIntegers.isEmpty()) return -1; + return luckyIntegers.poll(); + } + + private Map getFrequencies(int[] array) { + Map frequencies = new HashMap<>(); + for (int element : array) { + frequencies.put(element, frequencies.getOrDefault(element, 0) + 1); + } + return frequencies; + } + + private Queue getLuckyIntegers(Map frequencies){ + Queue luckyNumbers = new PriorityQueue<>(Comparator.reverseOrder()); + for (Map.Entry entry : frequencies.entrySet()) { + if (entry.getKey() == entry.getValue()) { + luckyNumbers.add(entry.getValue()); + } + } + return luckyNumbers; + } +} From a0d93cb2d1e01e756b1f2d27722171b17032c771 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 15 Dec 2021 20:36:51 +0100 Subject: [PATCH 311/947] solves count largest grop --- README.md | 2 +- src/CountLargestGroup.java | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 src/CountLargestGroup.java diff --git a/README.md b/README.md index 646f22e..accd5a1 100644 --- a/README.md +++ b/README.md @@ -355,7 +355,7 @@ | 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) | | | +| 1399 | [Count Largest Group](https://leetcode.com/problems/count-largest-group) | [![Java](assets/java.png)](src/CountLargestGroup.java) | | | 1403 | [Minimum Subsequence in Non-Increasing Order](https://leetcode.com/problems/minimum-subsequence-in-non-increasing-order) | | | | 1408 | [String Matching In An Array](https://leetcode.com/problems/string-matching-in-an-array) | | | | 1413 | [Minimum Value To Get Positive Step By Step Sum](https://leetcode.com/problems/minimum-value-to-get-positive-step-by-step-sum) | | | diff --git a/src/CountLargestGroup.java b/src/CountLargestGroup.java new file mode 100644 index 0000000..70c940f --- /dev/null +++ b/src/CountLargestGroup.java @@ -0,0 +1,36 @@ +import java.util.HashMap; +import java.util.Map; + +public class CountLargestGroup { + public int countLargestGroup(int n) { + Map sumOfDigitsFrequencies = getFrequenciesOfSumOfDigits(n); + int largestGroupSize = 0, largestGroupFrequency = 0; + for (int groupSize : sumOfDigitsFrequencies.values()) { + if (groupSize > largestGroupSize) { + largestGroupSize = groupSize; + largestGroupFrequency = 1; + } else if (largestGroupSize == groupSize) { + largestGroupFrequency++; + } + } + return largestGroupFrequency; + } + + private Map getFrequenciesOfSumOfDigits(int N) { + Map frequencies = new HashMap<>(); + for (int number = 1 ; number <= N ; number++) { + int sumOfDigits = sumOfDigits(number); + frequencies.put(sumOfDigits, frequencies.getOrDefault(sumOfDigits, 0) + 1); + } + return frequencies; + } + + private int sumOfDigits(int number) { + int sum = 0; + while (number > 0) { + sum += number % 10; + number /= 10; + } + return sum; + } +} From 05c3b7c3593f38368537fbf5b21ce13b8c0d4d4d Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 15 Dec 2021 20:44:55 +0100 Subject: [PATCH 312/947] solves minimum subsequence in non increasing order --- README.md | 2 +- ...MinimumSubSequenceInNonIncreasingOrder.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/MinimumSubSequenceInNonIncreasingOrder.java diff --git a/README.md b/README.md index accd5a1..8e06e93 100644 --- a/README.md +++ b/README.md @@ -356,7 +356,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) | | -| 1403 | [Minimum Subsequence in Non-Increasing Order](https://leetcode.com/problems/minimum-subsequence-in-non-increasing-order) | | | +| 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) | | | | 1413 | [Minimum Value To Get Positive Step By Step Sum](https://leetcode.com/problems/minimum-value-to-get-positive-step-by-step-sum) | | | | 1417 | [Reformat The String](https://leetcode.com/problems/reformat-the-string) | | | diff --git a/src/MinimumSubSequenceInNonIncreasingOrder.java b/src/MinimumSubSequenceInNonIncreasingOrder.java new file mode 100644 index 0000000..f277f8c --- /dev/null +++ b/src/MinimumSubSequenceInNonIncreasingOrder.java @@ -0,0 +1,18 @@ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class MinimumSubSequenceInNonIncreasingOrder { + public List minSubsequence(int[] array) { + Arrays.sort(array); + final int sum = Arrays.stream(array).sum(); + final List result = new ArrayList<>(); + result.add(array[array.length - 1]); + for (int index = array.length - 2, current = array[array.length - 1] ; index >= 0 ; index--) { + if (current > sum - current) break; + current += array[index]; + result.add(array[index]); + } + return result; + } +} From df9fc4fcc96446f3037235633c508fe7082c335f Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 15 Dec 2021 20:52:37 +0100 Subject: [PATCH 313/947] solves string matching in an array --- README.md | 2 +- src/StringMatchingInAnArray.java | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/StringMatchingInAnArray.java diff --git a/README.md b/README.md index 8e06e93..5a7cbe8 100644 --- a/README.md +++ b/README.md @@ -357,7 +357,7 @@ | 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) | | | 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) | | | +| 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) | | | | 1417 | [Reformat The String](https://leetcode.com/problems/reformat-the-string) | | | | 1422 | [Maximum Score After Splitting A String](https://leetcode.com/problems/maximum-score-after-splitting-a-string) | | | diff --git a/src/StringMatchingInAnArray.java b/src/StringMatchingInAnArray.java new file mode 100644 index 0000000..a59d43d --- /dev/null +++ b/src/StringMatchingInAnArray.java @@ -0,0 +1,24 @@ +import java.util.ArrayList; +import java.util.List; + +public class StringMatchingInAnArray { + public List stringMatching(String[] words) { + final List result = new ArrayList<>(); + for (int i = 0 ; i < words.length ; i++) { + for (int j = 0 ; j < words.length ; j++) { + if(i == j) continue; + if (isSubString(words[i], words[j])) { + result.add(words[i]); + break; + } + } + } + return result; + } + + private boolean isSubString(String pattern, String text) { + if (pattern.length() > text.length()) return false; + if (pattern.length() == text.length()) return pattern.equals(text); + return text.contains(pattern); + } +} From 437cc5314a50cecb46a422f52efbc347e32f2631 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 15 Dec 2021 21:24:49 +0100 Subject: [PATCH 314/947] solves minimum value to get to positive step sum --- README.md | 2 +- src/MinimumValueToGetPositiveStepByStepSum.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/MinimumValueToGetPositiveStepByStepSum.java diff --git a/README.md b/README.md index 5a7cbe8..9293354 100644 --- a/README.md +++ b/README.md @@ -358,7 +358,7 @@ | 1399 | [Count Largest Group](https://leetcode.com/problems/count-largest-group) | [![Java](assets/java.png)](src/CountLargestGroup.java) | | | 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) | | | +| 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) | | | | 1422 | [Maximum Score After Splitting A String](https://leetcode.com/problems/maximum-score-after-splitting-a-string) | | | | 1426 | [Counting Elements](https://leetcode.com/problems/counting-elements) | | | diff --git a/src/MinimumValueToGetPositiveStepByStepSum.java b/src/MinimumValueToGetPositiveStepByStepSum.java new file mode 100644 index 0000000..63e882c --- /dev/null +++ b/src/MinimumValueToGetPositiveStepByStepSum.java @@ -0,0 +1,15 @@ +public class MinimumValueToGetPositiveStepByStepSum { + public int minStartValue(int[] array) { + int lowestPoint =getLowestPoint(array); + return 1 - Math.min(0, lowestPoint); + } + + private int getLowestPoint(int[] array) { + int lowestPoint = 0, sum = 0; + for (int element : array) { + sum += element; + if (sum < lowestPoint) lowestPoint = sum; + } + return lowestPoint; + } +} From d8a77f2c5d4d1309592817e5dade997250d515b7 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 16 Dec 2021 00:09:34 +0100 Subject: [PATCH 315/947] solves reformat the string --- README.md | 2 +- src/ReformatTheString.java | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/ReformatTheString.java diff --git a/README.md b/README.md index 9293354..accf1f0 100644 --- a/README.md +++ b/README.md @@ -359,7 +359,7 @@ | 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) | | | +| 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) | | | | 1426 | [Counting Elements](https://leetcode.com/problems/counting-elements) | | | | 1427 | [Performing String Shifts](https://leetcode.com/problems/perform-string-shifts) | | | diff --git a/src/ReformatTheString.java b/src/ReformatTheString.java new file mode 100644 index 0000000..d0a7d6d --- /dev/null +++ b/src/ReformatTheString.java @@ -0,0 +1,22 @@ +import java.util.LinkedList; +import java.util.Queue; + +public class ReformatTheString { + public String reformat(String s) { + Queue digits = new LinkedList<>(); + Queue alphabets = new LinkedList<>(); + for (int index = 0 ; index < s.length() ; index++) { + if (Character.isAlphabetic(s.charAt(index))) { + alphabets.add(s.charAt(index)); + } else digits.add(s.charAt(index)); + } + if (Math.abs(digits.size() - alphabets.size()) > 1) return ""; + StringBuilder result = new StringBuilder(); + result.append(alphabets.size() > digits.size() ? alphabets.poll() : ""); + while (!digits.isEmpty() && !alphabets.isEmpty()) { + result.append(digits.poll()).append(alphabets.poll()); + } + result.append(!digits.isEmpty() ? digits.poll() : ""); + return result.toString(); + } +} From 45e55efda88b585343d12a5842eb5d4d32d1b9cb Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 16 Dec 2021 00:16:53 +0100 Subject: [PATCH 316/947] solves maximum score after splitting a string --- README.md | 2 +- src/MaximumScoreAfterSplittingAString.java | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/MaximumScoreAfterSplittingAString.java diff --git a/README.md b/README.md index accf1f0..d8bb4f7 100644 --- a/README.md +++ b/README.md @@ -360,7 +360,7 @@ | 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) | | | +| 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) | | | diff --git a/src/MaximumScoreAfterSplittingAString.java b/src/MaximumScoreAfterSplittingAString.java new file mode 100644 index 0000000..86bc4a1 --- /dev/null +++ b/src/MaximumScoreAfterSplittingAString.java @@ -0,0 +1,20 @@ +public class MaximumScoreAfterSplittingAString { + public int maxScore(String s) { + final int ones = getFrequency(s, '1'); + int score = 0; + for (int index = 0, left = 0, right = ones ; index < s.length() - 1 ; index++) { + left += s.charAt(index) == '0' ? 1 : 0; + right -= s.charAt(index) == '0' ? 0 : 1; + score = Math.max(score, left + right); + } + return score; + } + + private int getFrequency(String s, char character) { + int frequency = 0; + for (int index = 0 ; index < s.length() ; index++) { + if (s.charAt(index) == character) frequency++; + } + return frequency; + } +} From bfeb895a3f020804beb600e5b9d93252f655379c Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 16 Dec 2021 00:21:23 +0100 Subject: [PATCH 317/947] solves kids with the greatest numberof candies --- README.md | 6 +++--- src/KidsWithTheGreatestNumberOfCandies.java | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 src/KidsWithTheGreatestNumberOfCandies.java diff --git a/README.md b/README.md index d8bb4f7..897247e 100644 --- a/README.md +++ b/README.md @@ -361,9 +361,9 @@ | 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) | | | +| 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) | | | | 1441 | [Build An Array With Stack Operation](https://leetcode.com/problems/build-an-array-with-stack-operations) | | | | 1446 | [Consecutive Characters](https://leetcode.com/problems/consecutive-characters) | | | diff --git a/src/KidsWithTheGreatestNumberOfCandies.java b/src/KidsWithTheGreatestNumberOfCandies.java new file mode 100644 index 0000000..62f39c1 --- /dev/null +++ b/src/KidsWithTheGreatestNumberOfCandies.java @@ -0,0 +1,14 @@ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class KidsWithTheGreatestNumberOfCandies { + public List kidsWithCandies(int[] candies, int extraCandies) { + final List result = new ArrayList<>(); + final int maxCandies = Arrays.stream(candies).max().getAsInt(); + for (int person : candies) { + result.add(person + extraCandies >= maxCandies); + } + return result; + } +} From f163258c982564f015ed2163af5c13c0ab2b779d Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 16 Dec 2021 00:26:40 +0100 Subject: [PATCH 318/947] solves destination city --- README.md | 2 +- src/DestinationCity.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/DestinationCity.java diff --git a/README.md b/README.md index 897247e..fcdde7c 100644 --- a/README.md +++ b/README.md @@ -364,7 +364,7 @@ | 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) | | | +| 1436 | [Destination City](https://leetcode.com/problems/destination-city) | [![Java](assets/java.png)](src/DestinationCity.java) | | | 1441 | [Build An Array With Stack Operation](https://leetcode.com/problems/build-an-array-with-stack-operations) | | | | 1446 | [Consecutive Characters](https://leetcode.com/problems/consecutive-characters) | | | | 1450 | [Number of Students Doing Homework at Given Time](https://leetcode.com/problems/number-of-students-doing-homework-at-a-given-time) | | | diff --git a/src/DestinationCity.java b/src/DestinationCity.java new file mode 100644 index 0000000..d9b8a31 --- /dev/null +++ b/src/DestinationCity.java @@ -0,0 +1,19 @@ +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class DestinationCity { + public String destCity(List> paths) { + final Set cities = new HashSet<>(); + final Set departureCities = new HashSet<>(); + for (List path : paths) { + cities.add(path.get(0)); + cities.add(path.get(1)); + departureCities.add(path.get(0)); + } + for (String city : cities) { + if (!departureCities.contains(city)) return city; + } + return null; + } +} From a69de4a5da42438d37273a145ad4a0db4a3f052c Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 16 Dec 2021 00:34:09 +0100 Subject: [PATCH 319/947] solves check if all 1s are at leastk places away --- README.md | 1 + src/CheckIfAll1sAreAtLeastKPlacesAway.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 src/CheckIfAll1sAreAtLeastKPlacesAway.java diff --git a/README.md b/README.md index fcdde7c..df800cf 100644 --- a/README.md +++ b/README.md @@ -365,6 +365,7 @@ | 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) | | | | 1446 | [Consecutive Characters](https://leetcode.com/problems/consecutive-characters) | | | | 1450 | [Number of Students Doing Homework at Given Time](https://leetcode.com/problems/number-of-students-doing-homework-at-a-given-time) | | | diff --git a/src/CheckIfAll1sAreAtLeastKPlacesAway.java b/src/CheckIfAll1sAreAtLeastKPlacesAway.java new file mode 100644 index 0000000..d5e1696 --- /dev/null +++ b/src/CheckIfAll1sAreAtLeastKPlacesAway.java @@ -0,0 +1,14 @@ +public class CheckIfAll1sAreAtLeastKPlacesAway { + public boolean kLengthApart(int[] nums, int k) { + int index = 0; + while (index < nums.length && nums[index] != 1) index++; + index++; + for ( int distance = 0 ; index < nums.length ; index++) { + if (nums[index] == 1) { + if (distance < k) return false; + distance = 0; + } else distance++; + } + return true; + } +} From ee0832d63188d342f677fb7140c72d5b5c0ebb57 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 16 Dec 2021 00:44:43 +0100 Subject: [PATCH 320/947] solves build an array with stack operations --- README.md | 2 +- src/BuildAnArrayWithStackOperations.java | 28 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/BuildAnArrayWithStackOperations.java diff --git a/README.md b/README.md index df800cf..b33672d 100644 --- a/README.md +++ b/README.md @@ -366,7 +366,7 @@ | 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) | | | +| 1441 | [Build An Array With Stack Operation](https://leetcode.com/problems/build-an-array-with-stack-operations) | [![Java](assets/java.png)](src/BuildAnArrayWithStackOperations.java) | | | 1446 | [Consecutive Characters](https://leetcode.com/problems/consecutive-characters) | | | | 1450 | [Number of Students Doing Homework at Given Time](https://leetcode.com/problems/number-of-students-doing-homework-at-a-given-time) | | | | 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) | | | diff --git a/src/BuildAnArrayWithStackOperations.java b/src/BuildAnArrayWithStackOperations.java new file mode 100644 index 0000000..47e89ef --- /dev/null +++ b/src/BuildAnArrayWithStackOperations.java @@ -0,0 +1,28 @@ +import java.util.ArrayList; +import java.util.List; + +public class BuildAnArrayWithStackOperations { + private static final String PUSH = "Push"; + private static final String POP = "Pop"; + + public List buildArray(int[] target, int n) { + List result = new ArrayList<>(); + for (int index = 0, lastNumber = 0 ; index < target.length ; index++) { + popKNumbers(result, target[index] - 1 - lastNumber); + pushCurrentNumber(result); + lastNumber = target[index]; + } + return result; + } + + private void popKNumbers(List list, int k) { + while (k-- > 0) { + list.add(PUSH); + list.add(POP); + } + } + + private void pushCurrentNumber(List list) { + list.add(PUSH); + } +} From baa66bcb0919a4aa64f265e9362a3a3050b5d71b Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 16 Dec 2021 00:50:17 +0100 Subject: [PATCH 321/947] solves consecutive chacters --- README.md | 2 +- src/ConsecutiveCharacters.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/ConsecutiveCharacters.java diff --git a/README.md b/README.md index b33672d..e1c8cde 100644 --- a/README.md +++ b/README.md @@ -367,7 +367,7 @@ | 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) | | -| 1446 | [Consecutive Characters](https://leetcode.com/problems/consecutive-characters) | | | +| 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) | | | | 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) | | | | 1460 | [Make 2 Arrays Equal by Reversing Sub Arrays](https://leetcode.com/problems/make-two-arrays-equal-by-reversing-sub-arrays) | | | diff --git a/src/ConsecutiveCharacters.java b/src/ConsecutiveCharacters.java new file mode 100644 index 0000000..98f7154 --- /dev/null +++ b/src/ConsecutiveCharacters.java @@ -0,0 +1,15 @@ +public class ConsecutiveCharacters { + public int maxPower(String s) { + int power = 1; + char current = s.charAt(0); + for (int index = 1, frequency = 1 ; index < s.length() ; index++) { + if (s.charAt(index) == current) frequency++; + else { + current = s.charAt(index); + frequency = 1; + } + power = Math.max(power, frequency); + } + return power; + } +} From 48003bc07089b6cef9af7b43568e6523ceca7cea Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 16 Dec 2021 00:54:26 +0100 Subject: [PATCH 322/947] solves number of students doing homework at given time --- README.md | 2 +- src/NumberOfStudentsDoingHomeworkAtGivenTime.java | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/NumberOfStudentsDoingHomeworkAtGivenTime.java diff --git a/README.md b/README.md index e1c8cde..d417657 100644 --- a/README.md +++ b/README.md @@ -368,7 +368,7 @@ | 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) | | | 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) | | | +| 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) | | | | 1460 | [Make 2 Arrays Equal by Reversing Sub Arrays](https://leetcode.com/problems/make-two-arrays-equal-by-reversing-sub-arrays) | | | | 1464 | [Maximum Product of 2 Elements in Array](https://leetcode.com/problems/maximum-product-of-two-elements-in-an-array) | | | diff --git a/src/NumberOfStudentsDoingHomeworkAtGivenTime.java b/src/NumberOfStudentsDoingHomeworkAtGivenTime.java new file mode 100644 index 0000000..0cb000a --- /dev/null +++ b/src/NumberOfStudentsDoingHomeworkAtGivenTime.java @@ -0,0 +1,11 @@ +public class NumberOfStudentsDoingHomeworkAtGivenTime { + public int busyStudent(int[] startTime, int[] endTime, int queryTime) { + int students = 0; + for (int index = 0 ; index < startTime.length ; index++) { + if (startTime[index] <= queryTime && queryTime <= endTime[index]) { + students++; + } + } + return students; + } +} From 31b8ecf661b58cd8e6199187bca1c4655d52ce37 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 16 Dec 2021 16:57:32 +0100 Subject: [PATCH 323/947] solves check if work occurs as prefix of any word in sentence --- README.md | 2 +- ...rdOccursAsAPrefixOfAnyWordInASentence.java | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 src/CheckIfAWordOccursAsAPrefixOfAnyWordInASentence.java diff --git a/README.md b/README.md index d417657..0df06db 100644 --- a/README.md +++ b/README.md @@ -369,7 +369,7 @@ | 1441 | [Build An Array With Stack Operation](https://leetcode.com/problems/build-an-array-with-stack-operations) | [![Java](assets/java.png)](src/BuildAnArrayWithStackOperations.java) | | | 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) | | | +| 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) | | | | 1464 | [Maximum Product of 2 Elements in Array](https://leetcode.com/problems/maximum-product-of-two-elements-in-an-array) | | | | 1469 | [Find All Lonely Nodes](https://leetcode.com/problems/find-all-the-lonely-nodes) | | | diff --git a/src/CheckIfAWordOccursAsAPrefixOfAnyWordInASentence.java b/src/CheckIfAWordOccursAsAPrefixOfAnyWordInASentence.java new file mode 100644 index 0000000..9ef9ec0 --- /dev/null +++ b/src/CheckIfAWordOccursAsAPrefixOfAnyWordInASentence.java @@ -0,0 +1,21 @@ +public class CheckIfAWordOccursAsAPrefixOfAnyWordInASentence { + public int isPrefixOfWord(String sentence, String searchWord) { + int matchIndex = -1; + do { + matchIndex = sentence.indexOf(searchWord, matchIndex + 1); + if (matchIndex == -1) return -1; + if (matchIndex == 0 || sentence.charAt(matchIndex - 1) == ' ') { + return spacesUpto(sentence, matchIndex) + 1; + } + } while (matchIndex < sentence.length()); + return -1; + } + + private static int spacesUpto(String string, int endIndex) { + int spaces = 0; + for (int index = 0 ; index < endIndex ; index++) { + if (string.charAt(index) == ' ') spaces++; + } + return spaces; + } +} From b7fc421f8685c118b0a7987bbf798876666536a6 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 16 Dec 2021 17:02:28 +0100 Subject: [PATCH 324/947] solves make two arrays equal by reversing sub arrays --- README.md | 2 +- ...MakeTwoArraysEqualByReversingSubArrays.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/MakeTwoArraysEqualByReversingSubArrays.java diff --git a/README.md b/README.md index 0df06db..581a978 100644 --- a/README.md +++ b/README.md @@ -370,7 +370,7 @@ | 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) | | | +| 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) | | | | 1469 | [Find All Lonely Nodes](https://leetcode.com/problems/find-all-the-lonely-nodes) | | | | 1470 | [Shuffle The Array](https://leetcode.com/problems/shuffle-the-array) | | | diff --git a/src/MakeTwoArraysEqualByReversingSubArrays.java b/src/MakeTwoArraysEqualByReversingSubArrays.java new file mode 100644 index 0000000..cc3d377 --- /dev/null +++ b/src/MakeTwoArraysEqualByReversingSubArrays.java @@ -0,0 +1,18 @@ +import java.util.HashMap; +import java.util.Map; + +public class MakeTwoArraysEqualByReversingSubArrays { + public boolean canBeEqual(int[] target, int[] array) { + Map targetFrequencies = getFrequencies(target); + Map arrayFrequencies = getFrequencies(array); + return targetFrequencies.equals(arrayFrequencies); + } + + private Map getFrequencies(int[] array) { + Map frequencies = new HashMap<>(); + for (int element : array) { + frequencies.put(element, frequencies.getOrDefault(element, 0) + 1); + } + return frequencies; + } +} From 4576cd2aeb213cb13a3e5e29685f02d0a32f5b72 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 16 Dec 2021 17:07:32 +0100 Subject: [PATCH 325/947] solves maximum product of two elements in a array --- README.md | 2 +- src/MaximumProductOfTwoElementsInArray.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/MaximumProductOfTwoElementsInArray.java diff --git a/README.md b/README.md index 581a978..a0e5a10 100644 --- a/README.md +++ b/README.md @@ -371,7 +371,7 @@ | 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) | | | +| 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) | | | | 1470 | [Shuffle The Array](https://leetcode.com/problems/shuffle-the-array) | | | | 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) | | | diff --git a/src/MaximumProductOfTwoElementsInArray.java b/src/MaximumProductOfTwoElementsInArray.java new file mode 100644 index 0000000..01c15a8 --- /dev/null +++ b/src/MaximumProductOfTwoElementsInArray.java @@ -0,0 +1,14 @@ +public class MaximumProductOfTwoElementsInArray { + public int maxProduct(int[] array) { + int max = array[0], secondMax = Integer.MIN_VALUE; + for (int index = 1 ; index < array.length ; index++) { + if (array[index] > max) { + secondMax = max; + max = array[index]; + } else if (array[index] > secondMax) { + secondMax = array[index]; + } + } + return (max - 1) * (secondMax - 1) ; + } +} From 9802d271496182faa9d859760c62f242ff2e6c68 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 16 Dec 2021 17:25:18 +0100 Subject: [PATCH 326/947] solve sshuffle the array --- README.md | 6 +++--- src/ShuffleTheArray.java | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 src/ShuffleTheArray.java diff --git a/README.md b/README.md index a0e5a10..64fb9da 100644 --- a/README.md +++ b/README.md @@ -149,7 +149,7 @@ | 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) | | +| 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) | | @@ -372,8 +372,8 @@ | 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) | | | -| 1470 | [Shuffle The Array](https://leetcode.com/problems/shuffle-the-array) | | | +| 1469 | 🔒 [Find All Lonely Nodes](https://leetcode.com/problems/find-all-the-lonely-nodes) | | | +| 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) | | | | 1480 | [Running Sum of 1D Array](https://leetcode.com/problems/running-sum-of-1d-array) | | | diff --git a/src/ShuffleTheArray.java b/src/ShuffleTheArray.java new file mode 100644 index 0000000..1c78df6 --- /dev/null +++ b/src/ShuffleTheArray.java @@ -0,0 +1,10 @@ +public class ShuffleTheArray { + public int[] shuffle(int[] nums, int n) { + final int[] result = new int[nums.length]; + for (int i = 0 ; i < nums.length / 2 ; i++) { + result[2 * i] = nums[i]; + result[2 * i + 1] = nums[nums.length / 2 + i]; + } + return result; + } +} From 4bbf1cf5ed3e6ee3cf1f00a72918c369ddd5429f Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 16 Dec 2021 21:19:22 +0100 Subject: [PATCH 327/947] solves final prices with a special discount in a shop --- README.md | 2 +- ...inalPricesWithASpecialDiscountInAShop.java | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/FinalPricesWithASpecialDiscountInAShop.java diff --git a/README.md b/README.md index 64fb9da..9f92cce 100644 --- a/README.md +++ b/README.md @@ -375,7 +375,7 @@ | 1469 | 🔒 [Find All Lonely Nodes](https://leetcode.com/problems/find-all-the-lonely-nodes) | | | | 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) | | | +| 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) | | | | 1486 | [XOR Operations in An Array](https://leetcode.com/problems/xor-operation-in-an-array) | | | | 1491 | [Average Salary Excluding the Minimum and Maximum Salary](https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary) | | | diff --git a/src/FinalPricesWithASpecialDiscountInAShop.java b/src/FinalPricesWithASpecialDiscountInAShop.java new file mode 100644 index 0000000..f3eb4ae --- /dev/null +++ b/src/FinalPricesWithASpecialDiscountInAShop.java @@ -0,0 +1,26 @@ +import java.util.Stack; + +public class FinalPricesWithASpecialDiscountInAShop { + public int[] finalPrices(int[] prices) { + final Stack stack = new Stack<>(); + for (int index = 0 ; index < prices.length ; index++) { + int price = prices[index]; + while (!stack.isEmpty() && stack.peek().price >= price) { + Price top = stack.pop(); + prices[top.index] = top.price - price; + } + stack.push(new Price(price, index)); + } + return prices; + } + + private static final class Price { + private final int price; + private final int index; + + private Price(int price, int index) { + this.price = price; + this.index = index; + } + } +} From 5d794bba46f9bfe6103aad419fd59e2cda8c8c9f Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 16 Dec 2021 21:22:09 +0100 Subject: [PATCH 328/947] solves running sum of 1d array --- README.md | 2 +- src/RunningSumOf1DArray.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 src/RunningSumOf1DArray.java diff --git a/README.md b/README.md index 9f92cce..69eaea1 100644 --- a/README.md +++ b/README.md @@ -376,7 +376,7 @@ | 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) | | -| 1480 | [Running Sum of 1D Array](https://leetcode.com/problems/running-sum-of-1d-array) | | | +| 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) | | | | 1491 | [Average Salary Excluding the Minimum and Maximum Salary](https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary) | | | | 1496 | [Path Crossing](https://leetcode.com/problems/path-crossing) | | | diff --git a/src/RunningSumOf1DArray.java b/src/RunningSumOf1DArray.java new file mode 100644 index 0000000..92ee285 --- /dev/null +++ b/src/RunningSumOf1DArray.java @@ -0,0 +1,10 @@ +public class RunningSumOf1DArray { + public int[] runningSum(int[] nums) { + final int[] sum = new int[nums.length]; + sum[0] = nums[0]; + for (int index = 1 ; index < nums.length ; index++) { + sum[index] = nums[index] + sum[index - 1]; + } + return sum; + } +} From c3817093de57f926893c6c1e9960bc00338078ec Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 16 Dec 2021 21:39:51 +0100 Subject: [PATCH 329/947] solves xor operations in an array --- README.md | 2 +- src/XOROperationInAnArray.java | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/XOROperationInAnArray.java diff --git a/README.md b/README.md index 69eaea1..deb4a6c 100644 --- a/README.md +++ b/README.md @@ -377,7 +377,7 @@ | 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) | | | +| 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) | | | | 1496 | [Path Crossing](https://leetcode.com/problems/path-crossing) | | | | 1502 | [Can Make Arithmetic Progression From Sequence](https://leetcode.com/problems/can-make-arithmetic-progression-from-sequence) | | | diff --git a/src/XOROperationInAnArray.java b/src/XOROperationInAnArray.java new file mode 100644 index 0000000..a7ab98a --- /dev/null +++ b/src/XOROperationInAnArray.java @@ -0,0 +1,9 @@ +public class XOROperationInAnArray { + public int xorOperation(int n, int start) { + int result = 0; + for (int i = 0 ; i < n ; i++) { + result ^= start + 2 * i; + } + return result; + } +} From 150edd2e8c8ed454fbc137a3f01f67a8aa9662eb Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 16 Dec 2021 21:46:25 +0100 Subject: [PATCH 330/947] solves average salary excluding the minimum and maximum --- README.md | 2 +- ...SalaryExcludingTheMinimumAndMaximumSalary.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/AverageSalaryExcludingTheMinimumAndMaximumSalary.java diff --git a/README.md b/README.md index deb4a6c..948ec77 100644 --- a/README.md +++ b/README.md @@ -378,7 +378,7 @@ | 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) | | | +| 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) | | | | 1502 | [Can Make Arithmetic Progression From Sequence](https://leetcode.com/problems/can-make-arithmetic-progression-from-sequence) | | | | 1507 | [Reformat Date](https://leetcode.com/problems/reformat-date) | | | diff --git a/src/AverageSalaryExcludingTheMinimumAndMaximumSalary.java b/src/AverageSalaryExcludingTheMinimumAndMaximumSalary.java new file mode 100644 index 0000000..86c8564 --- /dev/null +++ b/src/AverageSalaryExcludingTheMinimumAndMaximumSalary.java @@ -0,0 +1,15 @@ +import java.util.Arrays; +import java.util.Set; + +public class AverageSalaryExcludingTheMinimumAndMaximumSalary { + public double average(int[] salaries) { + final int maxSalary = Arrays.stream(salaries).max().getAsInt(); + final int minSalary = Arrays.stream(salaries).min().getAsInt(); + final Set exclude = Set.of(minSalary, maxSalary); + int sumSalary = 0; + for (int salary : salaries) { + if (!exclude.contains(salary)) sumSalary += salary; + } + return (double) sumSalary / (salaries.length - 2); + } +} From 21adf34929caa5f509fa801e7c62fdc1c14507fc Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 16 Dec 2021 21:54:38 +0100 Subject: [PATCH 331/947] solves path crossing --- README.md | 6 +++--- src/PathCrossing.java | 46 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 src/PathCrossing.java diff --git a/README.md b/README.md index 948ec77..03d6a6d 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-282/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-282/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-304/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-304/2081-1abc9c.svg) ![problems-solved-python](https://img.shields.io/badge/Python-186/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) @@ -379,7 +379,7 @@ | 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) | | | +| 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) | | | | 1507 | [Reformat Date](https://leetcode.com/problems/reformat-date) | | | | 1512 | [Number of Good Pairs](https://leetcode.com/problems/number-of-good-pairs) | | | diff --git a/src/PathCrossing.java b/src/PathCrossing.java new file mode 100644 index 0000000..af5a161 --- /dev/null +++ b/src/PathCrossing.java @@ -0,0 +1,46 @@ +import java.util.HashSet; +import java.util.Objects; +import java.util.Set; + +public class PathCrossing { + public boolean isPathCrossing(String path) { + Set visitedPoints = new HashSet<>(); + visitedPoints.add(new Point(0, 0)); + for (int index = 0, x = 0, y = 0 ; index < path.length() ; index++) { + switch (path.charAt(index)) { + case 'N' -> y++; + case 'E' -> x++; + case 'S' -> y--; + case 'W' -> x--; + } + Point newPosition = new Point(x, y); + if (visitedPoints.contains(newPosition)) return true; + visitedPoints.add(newPosition); + } + return false; + } + + private static final class Point { + private final int x; + private final int y; + + private Point(int x, int y) { + this.x = x; + this.y = y; + } + + @Override + public boolean equals(Object obj) { + if (obj == this) return true; + if (obj == null || obj.getClass() != this.getClass()) return false; + var that = (Point) obj; + return this.x == that.x && + this.y == that.y; + } + + @Override + public int hashCode() { + return Objects.hash(x, y); + } + } +} From 103e89685c72045cd07b9633f615afdf7ba086cc Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 16 Dec 2021 22:14:47 +0100 Subject: [PATCH 332/947] solves can make arithmetic progression from sequence --- README.md | 2 +- ...MakeArithmeticProgressionFromSequence.java | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/CanMakeArithmeticProgressionFromSequence.java diff --git a/README.md b/README.md index 03d6a6d..4fba1ff 100644 --- a/README.md +++ b/README.md @@ -380,7 +380,7 @@ | 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) | | | +| 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) | | | | 1512 | [Number of Good Pairs](https://leetcode.com/problems/number-of-good-pairs) | | | | 1518 | [Water Bottles](https://leetcode.com/problems/water-bottles) | | | diff --git a/src/CanMakeArithmeticProgressionFromSequence.java b/src/CanMakeArithmeticProgressionFromSequence.java new file mode 100644 index 0000000..31ea161 --- /dev/null +++ b/src/CanMakeArithmeticProgressionFromSequence.java @@ -0,0 +1,24 @@ +// https://leetcode.com/problems/can-make-arithmetic-progression-from-sequence/ +// T: O(n) +// S: O(n) + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +public class CanMakeArithmeticProgressionFromSequence { + public boolean canMakeArithmeticProgression(int[] array) { + final int a = Arrays.stream(array).min().getAsInt(); + final int l = Arrays.stream(array).max().getAsInt(); + if (a == l) return true; + if ((l - a) % (array.length - 1) != 0) return false; + final int d = (l - a) / (array.length - 1); + Set elements = new HashSet<>(); + for (int number : array) { + if (elements.contains(number)) return false; + if ((number - a) % d != 0)return false; + elements.add(number); + } + return true; + } +} From de4b97499dfcd47f4fc5ae4895698920716df5e7 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 16 Dec 2021 22:25:38 +0100 Subject: [PATCH 333/947] solves reformat date --- README.md | 2 +- src/ReformatDate.java | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/ReformatDate.java diff --git a/README.md b/README.md index 4fba1ff..ec863ee 100644 --- a/README.md +++ b/README.md @@ -381,7 +381,7 @@ | 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) | | | +| 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) | | | | 1518 | [Water Bottles](https://leetcode.com/problems/water-bottles) | | | | 1523 | [Count Odd Numbers In Interval Range](https://leetcode.com/problems/count-odd-numbers-in-an-interval-range) | | | diff --git a/src/ReformatDate.java b/src/ReformatDate.java new file mode 100644 index 0000000..aaa59b9 --- /dev/null +++ b/src/ReformatDate.java @@ -0,0 +1,35 @@ +public class ReformatDate { + public String reformatDate(String date) { + final String[] parts = date.split(" "); + return new StringBuilder(parts[2]) + .append('-') + .append(getMonth(parts[1])) + .append('-') + .append(getDay(parts[0])) + .toString(); + } + + private String getMonth(String month) { + return switch (month) { + case "Jan" -> "01"; + case "Feb" -> "02"; + case "Mar" -> "03"; + case "Apr" -> "04"; + case "May" -> "05"; + case "Jun" -> "06"; + case "Jul" -> "07"; + case "Aug" -> "08"; + case "Sep" -> "09"; + case "Oct" -> "10"; + case "Nov" -> "11"; + case "Dec" -> "12"; + default -> ""; + }; + } + + private String getDay(String string) { + if (string.length() == 3) { + return '0' + string.substring(0, 1); + } return string.substring(0, 2); + } +} From aafcf58e99e96558bfca04ada6a2e9d813edba48 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 16 Dec 2021 22:42:02 +0100 Subject: [PATCH 334/947] solves number of good pairs --- README.md | 2 +- src/NumberOfGoodPairs.java | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/NumberOfGoodPairs.java diff --git a/README.md b/README.md index ec863ee..273a74a 100644 --- a/README.md +++ b/README.md @@ -382,7 +382,7 @@ | 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) | | | +| 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) | | | | 1523 | [Count Odd Numbers In Interval Range](https://leetcode.com/problems/count-odd-numbers-in-an-interval-range) | | | | 1528 | [Shuffle Strings](https://leetcode.com/problems/shuffle-string) | | | diff --git a/src/NumberOfGoodPairs.java b/src/NumberOfGoodPairs.java new file mode 100644 index 0000000..e4d4f96 --- /dev/null +++ b/src/NumberOfGoodPairs.java @@ -0,0 +1,29 @@ +// https://leetcode.com/problems/number-of-good-pairs +// T: O(n) +// S: O(n) + +import java.util.HashMap; +import java.util.Map; + +public class NumberOfGoodPairs { + public int numIdenticalPairs(int[] nums) { + Map frequencies = getFrequencies(nums); + int goodPairs = 0; + for (int frequency : frequencies.values()) { + goodPairs += nC2(frequency); + } + return goodPairs; + } + + private int nC2(int x) { + return (x * (x - 1)) / 2; + } + + private Map getFrequencies(int[] array) { + final Map frequencies = new HashMap<>(); + for (int element : array) { + frequencies.put(element, frequencies.getOrDefault(element, 0) + 1); + } + return frequencies; + } +} From 3772606f81438b0b3cf6d8ca44f77e550721bcd8 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 16 Dec 2021 22:50:45 +0100 Subject: [PATCH 335/947] solves water bottles --- README.md | 2 +- src/WaterBottles.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 src/WaterBottles.java diff --git a/README.md b/README.md index 273a74a..c2a1ccd 100644 --- a/README.md +++ b/README.md @@ -383,7 +383,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) | | -| 1518 | [Water Bottles](https://leetcode.com/problems/water-bottles) | | | +| 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) | | | | 1528 | [Shuffle Strings](https://leetcode.com/problems/shuffle-string) | | | | 1534 | [Count Good Triplets](https://leetcode.com/problems/count-good-triplets) | | | diff --git a/src/WaterBottles.java b/src/WaterBottles.java new file mode 100644 index 0000000..1534cd5 --- /dev/null +++ b/src/WaterBottles.java @@ -0,0 +1,10 @@ +public class WaterBottles { + public int numWaterBottles(int numBottles, int numExchange) { + int drink = numBottles; + while (numBottles >= numExchange) { + drink += numBottles / numExchange; + numBottles = numBottles % numExchange + numBottles / numExchange; + } + return drink; + } +} From 2c340310110eb2da2afaad8fa0a25d2e61611af2 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 16 Dec 2021 22:55:01 +0100 Subject: [PATCH 336/947] solves count odd numbers in interval range --- README.md | 2 +- src/CountOddNumbersInIntervalRange.java | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 src/CountOddNumbersInIntervalRange.java diff --git a/README.md b/README.md index c2a1ccd..778a148 100644 --- a/README.md +++ b/README.md @@ -384,7 +384,7 @@ | 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) | | | +| 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) | | | | 1534 | [Count Good Triplets](https://leetcode.com/problems/count-good-triplets) | | | | 1539 | [Kth Missing Positive Number](https://leetcode.com/problems/kth-missing-positive-number) | | | diff --git a/src/CountOddNumbersInIntervalRange.java b/src/CountOddNumbersInIntervalRange.java new file mode 100644 index 0000000..56fadc0 --- /dev/null +++ b/src/CountOddNumbersInIntervalRange.java @@ -0,0 +1,7 @@ +public class CountOddNumbersInIntervalRange { + public int countOdds(int low, int high) { + final int count = high - low + 1; + if ((count & 1) == 0) return count / 2; + return count / 2 + (low & 1); + } +} From b6a7f8d86336cb61658284b1e4463cbbd2d2ae2e Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 16 Dec 2021 22:58:34 +0100 Subject: [PATCH 337/947] solves shuffle string --- README.md | 2 +- src/ShuffleString.java | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/ShuffleString.java diff --git a/README.md b/README.md index 778a148..f78672b 100644 --- a/README.md +++ b/README.md @@ -385,7 +385,7 @@ | 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) | | | +| 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) | | | | 1539 | [Kth Missing Positive Number](https://leetcode.com/problems/kth-missing-positive-number) | | | | 1544 | [Make The String Great](https://leetcode.com/problems/make-the-string-great) | | | diff --git a/src/ShuffleString.java b/src/ShuffleString.java new file mode 100644 index 0000000..4c3a13e --- /dev/null +++ b/src/ShuffleString.java @@ -0,0 +1,9 @@ +public class ShuffleString { + public String restoreString(String s, int[] indices) { + final char[] result = new char[indices.length]; + for (int i = 0 ; i < s.length() ; i++) { + result[indices[i]] = s.charAt(i); + } + return String.valueOf(result); + } +} From 32b45fd38217479144c2852c06e6060c614cb02e Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 16 Dec 2021 23:08:58 +0100 Subject: [PATCH 338/947] solves count good tripets --- README.md | 2 +- src/CountGoodTriplets.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/CountGoodTriplets.java diff --git a/README.md b/README.md index f78672b..bf081d0 100644 --- a/README.md +++ b/README.md @@ -386,6 +386,6 @@ | 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) | | | +| 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) | | | | 1544 | [Make The String Great](https://leetcode.com/problems/make-the-string-great) | | | diff --git a/src/CountGoodTriplets.java b/src/CountGoodTriplets.java new file mode 100644 index 0000000..475c29d --- /dev/null +++ b/src/CountGoodTriplets.java @@ -0,0 +1,19 @@ +// https://leetcode.com/problems/count-good-triplets +// T: O(n^3) +// S: O(1) + +public class CountGoodTriplets { + public int countGoodTriplets(int[] arr, int a, int b, int c) { + int goodTriplets = 0; + for (int i = 0 ; i < arr.length ; i++) { + for (int j = i + 1 ; j < arr.length ; j++) { + for (int k = j + 1 ; k < arr.length ; k++) { + if (Math.abs(arr[i] - arr[j]) <= a && Math.abs(arr[j] - arr[k]) <= b && Math.abs(arr[i] - arr[k]) <= c) { + goodTriplets++; + } + } + } + } + return goodTriplets; + } +} From 6be6442a20b593be2d5c10b0a5eb04f775b8eba3 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 16 Dec 2021 23:23:13 +0100 Subject: [PATCH 339/947] solves kth missing positive number --- README.md | 2 +- src/KthMissingPositiveNumber.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/KthMissingPositiveNumber.java diff --git a/README.md b/README.md index bf081d0..52aafaf 100644 --- a/README.md +++ b/README.md @@ -387,5 +387,5 @@ | 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) | | | +| 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) | | | diff --git a/src/KthMissingPositiveNumber.java b/src/KthMissingPositiveNumber.java new file mode 100644 index 0000000..d7dad8e --- /dev/null +++ b/src/KthMissingPositiveNumber.java @@ -0,0 +1,19 @@ +// https://leetcode.com/problems/kth-missing-positive-number +// T: O(n) +// S: O(1) + +public class KthMissingPositiveNumber { + public int findKthPositive(int[] arr, int k) { + int pointer = 1, missing = 0; + for (int index = 0, current = arr[index]; missing < k ; ) { + if (pointer < current) { + missing++; + } else { + index++; + current = index == arr.length ? Integer.MAX_VALUE : arr[index]; + } + pointer++; + } + return pointer - 1; + } +} From 49e9239d55b03e3fb11b5de983f2ee98cb59c3b3 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 16 Dec 2021 23:30:40 +0100 Subject: [PATCH 340/947] solves --- README.md | 2 +- src/MakeTheStringGreat.java | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/MakeTheStringGreat.java diff --git a/README.md b/README.md index 52aafaf..7df2dab 100644 --- a/README.md +++ b/README.md @@ -388,4 +388,4 @@ | 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) | | | +| 1544 | [Make The String Great](https://leetcode.com/problems/make-the-string-great) | [![Java](assets/java.png)](src/MakeTheStringGreat.java) | | diff --git a/src/MakeTheStringGreat.java b/src/MakeTheStringGreat.java new file mode 100644 index 0000000..c64272c --- /dev/null +++ b/src/MakeTheStringGreat.java @@ -0,0 +1,28 @@ +// https://leetcode.com/problems/make-the-string-great +// T: O(N) +// S: O(N) + +import java.util.Stack; + +public class MakeTheStringGreat { + public String makeGood(String s) { + final Stack characters = new Stack<>(); + for (int index = 0 ; index < s.length() ; index++) { + char c = s.charAt(index); + if (!characters.isEmpty() && c == inverse(characters.peek())) { + characters.pop(); + } else characters.push(c); + } + return toStringBuilder(characters).reverse().toString(); + } + + private StringBuilder toStringBuilder(Stack stack) { + StringBuilder result = new StringBuilder(); + while (!stack.isEmpty()) result.append(stack.pop()); + return result; + } + + private char inverse(char c) { + return Character.isUpperCase(c) ? Character.toLowerCase(c) : Character.toUpperCase(c); + } +} From 253009433efd529d284a8bd20a873913d76bea2f Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 16 Dec 2021 23:31:14 +0100 Subject: [PATCH 341/947] updates stats --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7df2dab..953aba8 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-304/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-304/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-314/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-314/2081-1abc9c.svg) ![problems-solved-python](https://img.shields.io/badge/Python-186/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) From 85f857fb5f42249ea258a55ceee40bd6d20a9ba5 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 17 Dec 2021 13:23:06 +0100 Subject: [PATCH 342/947] solvesthree consecutive odds --- README.md | 1 + src/ThreeConsecutiveOdds.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 src/ThreeConsecutiveOdds.java diff --git a/README.md b/README.md index 953aba8..f0fe136 100644 --- a/README.md +++ b/README.md @@ -389,3 +389,4 @@ | 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) | | diff --git a/src/ThreeConsecutiveOdds.java b/src/ThreeConsecutiveOdds.java new file mode 100644 index 0000000..8ba79e7 --- /dev/null +++ b/src/ThreeConsecutiveOdds.java @@ -0,0 +1,14 @@ +public class ThreeConsecutiveOdds { + public boolean threeConsecutiveOdds(int[] array) { + for (int i = 0 ; i < array.length - 2 ; i++) { + if (isOdd(array[i]) && isOdd(array[i + 1]) && isOdd(array[i + 2])) { + return true; + } + } + return false; + } + + private boolean isOdd(int x) { + return (x & 1) == 1; + } +} From 6be460f55fddf921d0cc51596b9bffddcd5559e8 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 17 Dec 2021 13:34:23 +0100 Subject: [PATCH 343/947] solves thousand seperator --- README.md | 1 + src/ThousandSeparator.java | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/ThousandSeparator.java diff --git a/README.md b/README.md index f0fe136..11dbd83 100644 --- a/README.md +++ b/README.md @@ -390,3 +390,4 @@ | 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) | | diff --git a/src/ThousandSeparator.java b/src/ThousandSeparator.java new file mode 100644 index 0000000..adabd18 --- /dev/null +++ b/src/ThousandSeparator.java @@ -0,0 +1,25 @@ +import java.util.LinkedList; + +public class ThousandSeparator { + public String thousandSeparator(int n) { + final LinkedList list = getDigits(n); + final StringBuilder result = new StringBuilder(); + for (int i = 3 ; !list.isEmpty() ; i = (i + 1) % 3) { + if (i == 0) result.append('.'); + result.append(list.pop()); + } + return result.reverse().toString(); + } + + private LinkedList getDigits(int number) { + final LinkedList result = new LinkedList<>(); + if (number == 0) { + result.add(0); + } + while (number > 0) { + result.add(number % 10); + number /= 10; + } + return result; + } +} From 592e9d57bb2ab11c1cec804a23d355512bac7721 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 17 Dec 2021 13:55:12 +0100 Subject: [PATCH 344/947] solves most visited sector in circular track --- README.md | 1 + src/MostVisitedSectorInACircularTrack.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 src/MostVisitedSectorInACircularTrack.java diff --git a/README.md b/README.md index 11dbd83..9257d50 100644 --- a/README.md +++ b/README.md @@ -391,3 +391,4 @@ | 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) | | diff --git a/src/MostVisitedSectorInACircularTrack.java b/src/MostVisitedSectorInACircularTrack.java new file mode 100644 index 0000000..d644af2 --- /dev/null +++ b/src/MostVisitedSectorInACircularTrack.java @@ -0,0 +1,18 @@ +import java.util.ArrayList; +import java.util.List; + +public class MostVisitedSectorInACircularTrack { + public List mostVisited(int n, int[] rounds) { + final int start = rounds[0], end = rounds[rounds.length - 1]; + final List result = new ArrayList<>(); + if (start <= end) { + for (int i = start ; i <= end ; i++) { + result.add(i); + } + return result; + } + for (int i = 1; i <= end ; i++) result.add(i); + for (int i = start ; i <= n ; i++) result.add(i); + return result; + } +} From 1cae44ce3793979a37c523fc6b4551d6a2123e23 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 17 Dec 2021 14:23:33 +0100 Subject: [PATCH 345/947] solves detect pattern of length m repeated k or more times --- README.md | 1 + ...tPatternOfLengthMRepeatedKOrMoreTimes.java | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/DetectPatternOfLengthMRepeatedKOrMoreTimes.java diff --git a/README.md b/README.md index 9257d50..d2e6338 100644 --- a/README.md +++ b/README.md @@ -392,3 +392,4 @@ | 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) | | diff --git a/src/DetectPatternOfLengthMRepeatedKOrMoreTimes.java b/src/DetectPatternOfLengthMRepeatedKOrMoreTimes.java new file mode 100644 index 0000000..b65af17 --- /dev/null +++ b/src/DetectPatternOfLengthMRepeatedKOrMoreTimes.java @@ -0,0 +1,35 @@ +// https://leetcode.com/problems/detect-pattern-of-length-m-repeated-k-or-more-times +// T: O(nm^2k) +// s: O(1) + +public class DetectPatternOfLengthMRepeatedKOrMoreTimes { + public boolean containsPattern(int[] arr, int m, int k) { + if (m * k > arr.length || m > arr.length) return false; + if (k == 1) return true; + + for (int i = 0 ; i < arr.length - m * k + 1 ; i++) { + if (consistsOfPattern(arr, i, m, k)) { + return true; + } + } + return false; + } + + private boolean consistsOfPattern(int[] array, int startIndex, int patternLen, int k) { + for (int j = startIndex + patternLen ; j <= startIndex + (k - 1) * patternLen ; j += patternLen) { + if (!arrayIsSame(array, startIndex, j, patternLen)) { + return false; + } + } + return true; + } + + private boolean arrayIsSame(int[] array, int i, int j, int patternLen) { + for (int k = 0 ; k < patternLen ; k++) { + if (array[i + k] != array[j + k]) { + return false; + } + } + return true; + } +} From 8d9d2d79f7e9c3aef4c162cf8a3c7f2e34e3e75e Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 17 Dec 2021 14:30:45 +0100 Subject: [PATCH 346/947] solves matrix diagonal sum --- README.md | 1 + src/MatrixDiagonalSum.java | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 src/MatrixDiagonalSum.java diff --git a/README.md b/README.md index d2e6338..074061f 100644 --- a/README.md +++ b/README.md @@ -393,3 +393,4 @@ | 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) | | diff --git a/src/MatrixDiagonalSum.java b/src/MatrixDiagonalSum.java new file mode 100644 index 0000000..e9c65da --- /dev/null +++ b/src/MatrixDiagonalSum.java @@ -0,0 +1,26 @@ +// https://leetcode.com/problems/matrix-diagonal-sum +// T: O(N) +// S: O(1) + +public class MatrixDiagonalSum { + public int diagonalSum(int[][] matrix) { + return sumPrimaryDiagonal(matrix) + sumSecondaryDiagonal(matrix) - + ((matrix.length & 1) == 1 ? matrix[matrix.length / 2][matrix.length / 2] : 0); + } + + private int sumPrimaryDiagonal(int[][] matrix) { + int sum = 0; + for (int i = 0 ; i < matrix.length ; i++) { + sum += matrix[i][i]; + } + return sum; + } + + private int sumSecondaryDiagonal(int[][] matrix) { + int sum = 0; + for (int i = 0 ; i < matrix.length ; i++) { + sum += matrix[i][matrix.length - 1 - i]; + } + return sum; + } +} From 06c20b1da3ecfc1ace504d4127527fbd33ae01a1 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 17 Dec 2021 14:43:12 +0100 Subject: [PATCH 347/947] solves replace all to avoid consecutive repeating characters --- README.md | 1 + ...ToAvoidConsecutiveRepeatingCharacters.java | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 src/ReplaceAllToAvoidConsecutiveRepeatingCharacters.java diff --git a/README.md b/README.md index 074061f..6bedd29 100644 --- a/README.md +++ b/README.md @@ -394,3 +394,4 @@ | 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) | | diff --git a/src/ReplaceAllToAvoidConsecutiveRepeatingCharacters.java b/src/ReplaceAllToAvoidConsecutiveRepeatingCharacters.java new file mode 100644 index 0000000..e494fdf --- /dev/null +++ b/src/ReplaceAllToAvoidConsecutiveRepeatingCharacters.java @@ -0,0 +1,30 @@ +// https://leetcode.com/problems/replace-all-s-to-avoid-consecutive-repeating-characters/submissions +// T:(n) +// S: O(n) + +public class ReplaceAllToAvoidConsecutiveRepeatingCharacters { + private static final Character QUESTION_MARK = '?'; + + public String modifyString(String s) { + final StringBuilder result = new StringBuilder(); + char last = QUESTION_MARK; + for (int index = 0 ; index < s.length() ; index++) { + char c = s.charAt(index); + if (c == QUESTION_MARK) { + char left = get(s, index - 1); + if (left == QUESTION_MARK) left = last; + final char right = get(s, index + 1); + c = 'a'; + while (c == left || c == right) c++; + last = c; + } + result.append(c); + } + return result.toString(); + } + + private char get(String string, int index) { + if (index < 0 || index >= string.length()) return QUESTION_MARK; + return string.charAt(index); + } +} From fcd2d1fd405ae54258c4ee7010cd0941315dfb40 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 17 Dec 2021 15:00:45 +0100 Subject: [PATCH 348/947] solves special position in inary matrix --- README.md | 1 + src/SpecialPositionInABinaryMatrix.java | 51 +++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 src/SpecialPositionInABinaryMatrix.java diff --git a/README.md b/README.md index 6bedd29..1e91ad4 100644 --- a/README.md +++ b/README.md @@ -395,3 +395,4 @@ | 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) | | diff --git a/src/SpecialPositionInABinaryMatrix.java b/src/SpecialPositionInABinaryMatrix.java new file mode 100644 index 0000000..223e1bf --- /dev/null +++ b/src/SpecialPositionInABinaryMatrix.java @@ -0,0 +1,51 @@ +// https://leetcode.com/problems/special-positions-in-a-binary-matrix +// T: O(n * m) +// S: O(n + m) + +import java.util.Arrays; + +public class SpecialPositionInABinaryMatrix { + public int numSpecial(int[][] matrix) { + final int[] rowSum = getRowSum(matrix); + final ColumnSumData columnSumData = getColumnSum(matrix); + final int[] columnSumOneRowIndex = columnSumData.oneIndex; + final int[] columnSum = columnSumData.sum; + int specialPositions = 0; + for (int i = 0 ; i < columnSum.length ; i++) { + if (columnSum[i] == 1 && rowSum[columnSumOneRowIndex[i]] == 1) { + specialPositions++; + } + } + return specialPositions; + } + + private int[] getRowSum(int[][] matrix) { + final int[] sum = new int[matrix.length]; + for (int i = 0 ; i < sum.length ; i++) { + sum[i] = Arrays.stream(matrix[i]).sum(); + } + return sum; + } + + private ColumnSumData getColumnSum(int[][] matrix) { + final int[] sum = new int[matrix[0].length]; + final int[] indexes = new int[sum.length]; + for (int i = 0 ; i < sum.length ; i++) { + for (int row = 0 , index = 0 ; row < matrix.length ; row++) { + sum[i] += matrix[row][i]; + if (matrix[row][i] == 1) indexes[i] = row; + } + } + return new ColumnSumData(sum, indexes); + } + + private static final class ColumnSumData { + private final int[] sum; + private final int[] oneIndex; + + private ColumnSumData(int[] sum, int[] oneIndex) { + this.sum = sum; + this.oneIndex = oneIndex; + } + } +} From 17f0d4d218d347e3f94b84a3a17ade0458d57a20 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 17 Dec 2021 17:29:12 +0100 Subject: [PATCH 349/947] solves sum of all odd length sub arrays --- README.md | 3 ++- src/SumOfAllOddLengthSubArrays.java | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 src/SumOfAllOddLengthSubArrays.java diff --git a/README.md b/README.md index 1e91ad4..89910b5 100644 --- a/README.md +++ b/README.md @@ -395,4 +395,5 @@ | 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) | | +| 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) | | diff --git a/src/SumOfAllOddLengthSubArrays.java b/src/SumOfAllOddLengthSubArrays.java new file mode 100644 index 0000000..acb44dc --- /dev/null +++ b/src/SumOfAllOddLengthSubArrays.java @@ -0,0 +1,9 @@ +public class SumOfAllOddLengthSubArrays { + public int sumOddLengthSubarrays(int[] array) { + int sum = 0; + for (int index = 0 ; index < array.length ; index++) { + sum += (((array.length - index) * (index + 1) + 1) / 2) * array[index]; + } + return sum; + } +} From 3ac506f29ea1aca8118398a3886e5f2d68f5d519 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 17 Dec 2021 17:43:04 +0100 Subject: [PATCH 350/947] solves rearange spaces between words --- README.md | 1 + src/RearrangeSpacesBetweenWords.java | 40 ++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 src/RearrangeSpacesBetweenWords.java diff --git a/README.md b/README.md index 89910b5..9eff16e 100644 --- a/README.md +++ b/README.md @@ -397,3 +397,4 @@ | 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) | | diff --git a/src/RearrangeSpacesBetweenWords.java b/src/RearrangeSpacesBetweenWords.java new file mode 100644 index 0000000..ed4e482 --- /dev/null +++ b/src/RearrangeSpacesBetweenWords.java @@ -0,0 +1,40 @@ +import java.util.ArrayList; +import java.util.List; + +public class RearrangeSpacesBetweenWords { + public String reorderSpaces(String text) { + final int totalSpaces = countSpaces(text); + final List words = getWords(text); + final int spaces = words.size() > 1 ? totalSpaces / (words.size() - 1) : 0; + final int extraSpaces = words.size() > 1 ? totalSpaces % (words.size() - 1) : totalSpaces; + final StringBuilder result = new StringBuilder(); + final String spacesAfterWord = " ".repeat(spaces); + for (int i = 0 ; i < words.size() ; i++) { + result.append(words.get(i)).append(i != words.size() -1 ? spacesAfterWord : ""); + } + return result.append(" ".repeat(extraSpaces)).toString(); + } + + private int countSpaces(String s) { + int spaces = 0; + for (int i = 0 ; i < s.length() ; i++) { + if (s.charAt(i) == ' ') spaces++; + } + return spaces; + } + + private List getWords(String string) { + final List words = new ArrayList<>(); + StringBuilder word = new StringBuilder(); + for (int i = 0 ; i < string.length() ; i++) { + if (string.charAt(i) == ' ') { + if (word.length() > 0) words.add(word); + word = new StringBuilder(); + } else { + word.append(string.charAt(i)); + } + } + if (word.length() > 0) words.add(word); + return words; + } +} From 23cf7df3f0d9815d0d9a0f870f4cd114dad337d4 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 17 Dec 2021 17:50:13 +0100 Subject: [PATCH 351/947] solves crawler log folder --- README.md | 1 + src/CrawlerLogFolder.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 src/CrawlerLogFolder.java diff --git a/README.md b/README.md index 9eff16e..5cf4031 100644 --- a/README.md +++ b/README.md @@ -398,3 +398,4 @@ | 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) | | diff --git a/src/CrawlerLogFolder.java b/src/CrawlerLogFolder.java new file mode 100644 index 0000000..4d2f168 --- /dev/null +++ b/src/CrawlerLogFolder.java @@ -0,0 +1,16 @@ +public class CrawlerLogFolder { + private static final String GO_UP = "../"; + private static final String REMAIN_WHERE_YOU_ARE = "./"; + + public int minOperations(String[] logs) { + int level = 0; + for (String log : logs) { + if (GO_UP.equals(log)) { + level = Math.max(0, level - 1); + } else if (!REMAIN_WHERE_YOU_ARE.equals(log)){ + level++; + } + } + return level; + } +} From 8add1742dffb79455148cd3f11ff9237ae05189a Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 17 Dec 2021 18:29:44 +0100 Subject: [PATCH 352/947] solves design car parking system --- README.md | 1 + src/DesignParkingSystem.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 src/DesignParkingSystem.java diff --git a/README.md b/README.md index 5cf4031..8da8924 100644 --- a/README.md +++ b/README.md @@ -399,3 +399,4 @@ | 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) | | +| 1603 | [Design Parking System](https://leetcode.com/problems/design-parking-system) | [![Java](assets/java.png)](src/DesignParkingSystem.java) | | diff --git a/src/DesignParkingSystem.java b/src/DesignParkingSystem.java new file mode 100644 index 0000000..152f1fb --- /dev/null +++ b/src/DesignParkingSystem.java @@ -0,0 +1,19 @@ +public class DesignParkingSystem { + class ParkingSystem { + private final int[] carSpots = new int[3]; + + public ParkingSystem(int big, int medium, int small) { + this.carSpots[0] = big; + this.carSpots[1] = medium; + this.carSpots[2] = small; + } + + public boolean addCar(int carType) { + if (carSpots[carType - 1] > 0) { + carSpots[carType - 1]--; + return true; + } + return false; + } + } +} From 3697c236d9991c6e8ed8caf4e6377506fef97dda Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 17 Dec 2021 18:38:43 +0100 Subject: [PATCH 353/947] solves maximum nesting depth of the parentheses --- README.md | 1 + src/MaximumNestingDepthOfTheParentheses.java | 11 +++++++++++ src/SpecialArrayWithXElementsGreaterThanEqualToX.java | 5 +++++ 3 files changed, 17 insertions(+) create mode 100644 src/MaximumNestingDepthOfTheParentheses.java create mode 100644 src/SpecialArrayWithXElementsGreaterThanEqualToX.java diff --git a/README.md b/README.md index 8da8924..2b4bb81 100644 --- a/README.md +++ b/README.md @@ -400,3 +400,4 @@ | 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) | | | 1603 | [Design Parking System](https://leetcode.com/problems/design-parking-system) | [![Java](assets/java.png)](src/DesignParkingSystem.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) | | diff --git a/src/MaximumNestingDepthOfTheParentheses.java b/src/MaximumNestingDepthOfTheParentheses.java new file mode 100644 index 0000000..98178ac --- /dev/null +++ b/src/MaximumNestingDepthOfTheParentheses.java @@ -0,0 +1,11 @@ +public class MaximumNestingDepthOfTheParentheses { + public int maxDepth(String s) { + int nestingDepth = 0, maximumNestingDepth = 0; + for (int index = 0 ; index < s.length() ; index++) { + if (s.charAt(index) == '(') nestingDepth++; + else if (s.charAt(index) == ')') nestingDepth--; + maximumNestingDepth = Math.max(nestingDepth, maximumNestingDepth); + } + return maximumNestingDepth; + } +} diff --git a/src/SpecialArrayWithXElementsGreaterThanEqualToX.java b/src/SpecialArrayWithXElementsGreaterThanEqualToX.java new file mode 100644 index 0000000..36cfc4d --- /dev/null +++ b/src/SpecialArrayWithXElementsGreaterThanEqualToX.java @@ -0,0 +1,5 @@ +public class SpecialArrayWithXElementsGreaterThanEqualToX { + public int specialArray(int[] array) { + + } +} From f2882f1dcbdd7f3312299e89ff6be0297a1e4deb Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 17 Dec 2021 22:37:15 +0100 Subject: [PATCH 354/947] solves special array with elements greater then equal to x --- README.md | 5 +++-- ...cialArrayWithXElementsGreaterThanEqualToX.java | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2b4bb81..b034faf 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-314/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-314/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-326/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-326/2081-1abc9c.svg) ![problems-solved-python](https://img.shields.io/badge/Python-186/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) @@ -400,4 +400,5 @@ | 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) | | | 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) | | diff --git a/src/SpecialArrayWithXElementsGreaterThanEqualToX.java b/src/SpecialArrayWithXElementsGreaterThanEqualToX.java index 36cfc4d..14e113a 100644 --- a/src/SpecialArrayWithXElementsGreaterThanEqualToX.java +++ b/src/SpecialArrayWithXElementsGreaterThanEqualToX.java @@ -1,5 +1,20 @@ +import java.util.Arrays; + public class SpecialArrayWithXElementsGreaterThanEqualToX { public int specialArray(int[] array) { + Arrays.sort(array); + int index = lastUniqueElementIndex(array); + for (int pointer = array[index] ; array.length - index <= pointer ; ) { + if (pointer == array.length - index) return pointer; + pointer--; + while (index > 0 && array[index - 1] >= pointer) index--; + } + return -1; + } + private int lastUniqueElementIndex(int[] array) { + int index = array.length - 1; + while (index - 1 >= 0 && array[index - 1] == array[index]) index--; + return index; } } From 88d9b6ee830a143ec1bf5cdc0a33bc5f578ced39 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 17 Dec 2021 22:45:48 +0100 Subject: [PATCH 355/947] solves mean of array after removing some elements --- README.md | 1 + src/MeanOfArrayAfterRemovingSomeElements.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 src/MeanOfArrayAfterRemovingSomeElements.java diff --git a/README.md b/README.md index b034faf..0973dab 100644 --- a/README.md +++ b/README.md @@ -402,3 +402,4 @@ | 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) | | diff --git a/src/MeanOfArrayAfterRemovingSomeElements.java b/src/MeanOfArrayAfterRemovingSomeElements.java new file mode 100644 index 0000000..3277a7f --- /dev/null +++ b/src/MeanOfArrayAfterRemovingSomeElements.java @@ -0,0 +1,18 @@ +// https://leetcode.com/problems/mean-of-array-after-removing-some-elements +// T: O(nlog(n)) +// S: O(1) + +import java.util.Arrays; + +public class MeanOfArrayAfterRemovingSomeElements { + public double trimMean(int[] arr) { + Arrays.sort(arr); + int sum = 0; + final int startIndex = arr.length / 20; + final int endIndex = arr.length - startIndex; + for (int index = startIndex ; index < endIndex; index++) { + sum += arr[index]; + } + return (double) sum / (endIndex - startIndex); + } +} From d9fb73188ed88001c0ca56fd56dedd5f66d20f45 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 17 Dec 2021 23:21:11 +0100 Subject: [PATCH 356/947] adds entries in the readme table --- README.md | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/README.md b/README.md index 0973dab..1eeed81 100644 --- a/README.md +++ b/README.md @@ -403,3 +403,62 @@ | 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) | | | +| 1629 | [Slowest Key](https://leetcode.com/problems/slowest-key) | | | +| 1636 | [Sort Array by Increasing Frequency](https://leetcode.com/problems/sort-array-by-increasing-frequency) | | | +| 1640 | [Check Array Formation Through Concatenation](https://leetcode.com/problems/check-array-formation-through-concatenation) | | | +| 1646 | [Get Maximum in Generated Array](https://leetcode.com/problems/get-maximum-in-generated-array) | | | +| 1652 | [Defuse the Bomb](https://leetcode.com/problems/defuse-the-bomb) | | | +| 1656 | [Design an Ordered Stream](https://leetcode.com/problems/design-an-ordered-stream) | | | +| 1662 | [Check If Two String Arrays are Equivalent](https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent) | | | +| 1668 | [Maximum Repeating Substring](https://leetcode.com/problems/maximum-repeating-substring) | | | +| 1672 | [Richest Customer Wealth](https://leetcode.com/problems/richest-customer-wealth) | | | +| 1678 | [Goal Parser Interpretation](https://leetcode.com/problems/goal-parser-interpretation) | | | +| 1684 | [Count the Number of Consistent Strings](https://leetcode.com/problems/count-the-number-of-consistent-strings) | | | +| 1688 | [Count of Matches in Tournament](https://leetcode.com/problems/count-of-matches-in-tournament) | | | +| 1694 | [Reformat Phone Number](https://leetcode.com/problems/reformat-phone-number) | | | +| 1700 | [Number of Students Unable to Eat Lunch](https://leetcode.com/problems/number-of-students-unable-to-eat-lunch) | | | +| 1704 | [Determine if String Halves Are Alike](https://leetcode.com/problems/determine-if-string-halves-are-alike) | | | +| 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/) | | | +| 1716 | [Calculate Money in Leetcode Bank](https://leetcode.com/problems/calculate-money-in-leetcode-bank) | | | +| 1720 | [Decode XORed Array](https://leetcode.com/problems/decode-xored-array) | | | +| 1725 | [Number Of Rectangles That Can Form The Largest Square](https://leetcode.com/problems/number-of-rectangles-that-can-form-the-largest-square) | | | +| 1732 | [Find the Highest Altitude](https://leetcode.com/problems/find-the-highest-altitude) | | | +| 1736 | [Latest Time by Replacing Hidden Digits](https://leetcode.com/problems/latest-time-by-replacing-hidden-digits) | | | +| 1742 | [Maximum Number of Balls in a Box](https://leetcode.com/problems/maximum-number-of-balls-in-a-box) | | | +| 1748 | [Sum of Unique Elements](https://leetcode.com/problems/sum-of-unique-elements) | | | +| 1752 | [Check if Array Is Sorted and Rotated](https://leetcode.com/problems/check-if-array-is-sorted-and-rotated) | | | +| 1758 | [Minimum Changes To Make Alternating Binary String](https://leetcode.com/problems/minimum-changes-to-make-alternating-binary-string) | | | +| 1763 | [Longest Nice Substring](https://leetcode.com/problems/longest-nice-substring) | | | +| 1768 | [Merge Strings Alternately](https://leetcode.com/problems/merge-strings-alternately) | | | +| 1773 | [Count Items Matching a Rule](https://leetcode.com/problems/count-items-matching-a-rule) | | | +| 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) | | | +| 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) | | | +| 1790 | [Check if One String Swap Can Make Strings Equal](https://leetcode.com/problems/check-if-one-string-swap-can-make-strings-equal) | | | +| 1791 | [Find Center of Star Graph](https://leetcode.com/problems/find-center-of-star-graph) | | | +| 1796 | [Second Largest Digit in a String](https://leetcode.com/problems/second-largest-digit-in-a-string) | | | +| 1800 | [Maximum Ascending Subarray Sum](https://leetcode.com/problems/maximum-ascending-subarray-sum) | | | +| 1805 | [Number of Different Integers in a String](https://leetcode.com/problems/number-of-different-integers-in-a-string) | | | +| 1812 | [Determine Color of a Chessboard Square](https://leetcode.com/problems/determine-color-of-a-chessboard-square) | | | +| 1816 | [Truncate Sentence](https://leetcode.com/problems/truncate-sentence) | | | +| 1822 | [Sign of the Product of an Array](https://leetcode.com/problems/sign-of-the-product-of-an-array) | | | +| 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) | | | +| 1832 | [Check if the Sentence Is Pangram](https://leetcode.com/problems/check-if-the-sentence-is-pangram) | | | +| 1837 | [Sum of Digits in Base K](https://leetcode.com/problems/sum-of-digits-in-base-k) | | | +| 1844 | [Replace All Digits with Characters](https://leetcode.com/problems/replace-all-digits-with-characters) | | | +| 1848 | [Minimum Distance to the Target Element](https://leetcode.com/problems/minimum-distance-to-the-target-element) | | | +| 1854 | [Maximum Population Year](https://leetcode.com/problems/maximum-population-year) | | | +| 1859 | [Sorting the Sentence](https://leetcode.com/problems/sorting-the-sentence) | | | +| 1863 | [Sum of All Subset XOR Totals](https://leetcode.com/problems/sum-of-all-subset-xor-totals) | | | +| 1869 | [Longer Contiguous Segments of Ones than Zeros](https://leetcode.com/problems/longer-contiguous-segments-of-ones-than-zeros) | | | +| 1624 | []() | | | +| 1624 | []() | | | +| 1624 | []() | | | +| 1624 | []() | | | +| 1624 | []() | | | +| 1624 | []() | | | +| 1624 | []() | | | +| 1624 | []() | | | +| 1624 | []() | | | From ca3d4562e65fc9f222fd2b4c562ba45750d46960 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 18 Dec 2021 00:06:16 +0100 Subject: [PATCH 357/947] updates table in readme --- README.md | 943 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 490 insertions(+), 453 deletions(-) diff --git a/README.md b/README.md index 1eeed81..32b8189 100644 --- a/README.md +++ b/README.md @@ -9,456 +9,493 @@ 🔒 = 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) | -| 7 | [Reverse Integer](https://leetcode.com/problems/reverse-integer/) | [![Java](assets/java.png)](src/ReverseInteger.java) [![Python](assets/python.png)](python/reverse_integer.py) | [![java-yt](assets/java-yt.png)](https://youtu.be/7bOhyl5lWjI) [![python-yt](assets/python-yt.png)](https://youtu.be/lmLG30TLcSg) | -| 9 | [PalindromeNumber](https://leetcode.com/problems/palindrome-number/) | [![Java](assets/java.png)](src/PalindromeNumber.java) [![Python](assets/python.png)](python/palindrome_number.py) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 136 | [Single Number](https://leetcode.com/problems/single-number) | [![Java](assets/java.png)](src/SingleNumber.java) [![Python](assets/python.png)](python/single_number.py) | | -| 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) | | -| 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) | | -| 155 | [Min Stack](https://leetcode.com/problems/min-stack) | [![Java](assets/java.png)](src/MinStack.java) [![Python](assets/python.png)](python/min_stack.py) | | -| 157 | [Read N Characters Given Read4](https://leetcode.com/problems/read-n-characters-given-read4) | | | -| 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) | | -| 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) | | -| 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) | | -| 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 Lists](https://leetcode.com/problems/reverse-linked-list) | [![Java](assets/java.png)](src/ReverseLinkedList.java) [![Python](assets/python.png)](python/reverse_linked_list.py) | | -| 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate) | [![Java](assets/java.png)](src/ContainsDuplicate.java) [![Python](assets/python.png)](python/contains_duplicate.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) | | -| 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) | | -| 226 | [Summary Ranges](https://leetcode.com/problems/summary-ranges/) | [![Java](assets/java.png)](src/SummaryRanges.java) [![Python](assets/python.png)](python/summary_ranges.py) | | -| 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) | | -| 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) | | -| 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) | | | -| 246 | 🔒 [Strobogramatic Number](https://leetcode.com/problems/strobogrammatic-number) | | | -| 252 | 🔒 [Meeting Rooms](https://leetcode.com/problems/meeting-rooms) | | | -| 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) | | -| 263 | [Ugly Number](https://leetcode.com/problems/ugly-number) | [![Java](assets/java.png)](src/UglyNumber.java) [![Python](assets/python.png)](python/ugly_number.py) | | -| 266 | 🔒 [Palindrome Permutation](https://leetcode.com/problems/palindrome-permutation) | | | -| 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) | | | -| 276 | 🔒 [Paint Fence](https://leetcode.com/problems/paint-fence) | | | -| 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) | | -| 283 | [Move Zeroes](https://leetcode.com/problems/move-zeroes) | [![Java](assets/java.png)](src/MoveZeros.java) [![Python](assets/python.png)](python/move_zeroes.py) | | -| 290 | [Word Pattern](https://leetcode.com/problems/word-pattern) | [![Java](assets/java.png)](src/WordPattern.java) [![Python](assets/python.png)](python/word_pattern.py) | | -| 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) | | | -| 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) | | -| 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) | | -| 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) | | -| 326 | [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) | | | -| 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) | | -| 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) | | | -| 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) | | -| 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) | | | -| 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) | | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | | -| 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) | | -| 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) | | -| 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) | | | -| 1629 | [Slowest Key](https://leetcode.com/problems/slowest-key) | | | -| 1636 | [Sort Array by Increasing Frequency](https://leetcode.com/problems/sort-array-by-increasing-frequency) | | | -| 1640 | [Check Array Formation Through Concatenation](https://leetcode.com/problems/check-array-formation-through-concatenation) | | | -| 1646 | [Get Maximum in Generated Array](https://leetcode.com/problems/get-maximum-in-generated-array) | | | -| 1652 | [Defuse the Bomb](https://leetcode.com/problems/defuse-the-bomb) | | | -| 1656 | [Design an Ordered Stream](https://leetcode.com/problems/design-an-ordered-stream) | | | -| 1662 | [Check If Two String Arrays are Equivalent](https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent) | | | -| 1668 | [Maximum Repeating Substring](https://leetcode.com/problems/maximum-repeating-substring) | | | -| 1672 | [Richest Customer Wealth](https://leetcode.com/problems/richest-customer-wealth) | | | -| 1678 | [Goal Parser Interpretation](https://leetcode.com/problems/goal-parser-interpretation) | | | -| 1684 | [Count the Number of Consistent Strings](https://leetcode.com/problems/count-the-number-of-consistent-strings) | | | -| 1688 | [Count of Matches in Tournament](https://leetcode.com/problems/count-of-matches-in-tournament) | | | -| 1694 | [Reformat Phone Number](https://leetcode.com/problems/reformat-phone-number) | | | -| 1700 | [Number of Students Unable to Eat Lunch](https://leetcode.com/problems/number-of-students-unable-to-eat-lunch) | | | -| 1704 | [Determine if String Halves Are Alike](https://leetcode.com/problems/determine-if-string-halves-are-alike) | | | -| 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/) | | | -| 1716 | [Calculate Money in Leetcode Bank](https://leetcode.com/problems/calculate-money-in-leetcode-bank) | | | -| 1720 | [Decode XORed Array](https://leetcode.com/problems/decode-xored-array) | | | -| 1725 | [Number Of Rectangles That Can Form The Largest Square](https://leetcode.com/problems/number-of-rectangles-that-can-form-the-largest-square) | | | -| 1732 | [Find the Highest Altitude](https://leetcode.com/problems/find-the-highest-altitude) | | | -| 1736 | [Latest Time by Replacing Hidden Digits](https://leetcode.com/problems/latest-time-by-replacing-hidden-digits) | | | -| 1742 | [Maximum Number of Balls in a Box](https://leetcode.com/problems/maximum-number-of-balls-in-a-box) | | | -| 1748 | [Sum of Unique Elements](https://leetcode.com/problems/sum-of-unique-elements) | | | -| 1752 | [Check if Array Is Sorted and Rotated](https://leetcode.com/problems/check-if-array-is-sorted-and-rotated) | | | -| 1758 | [Minimum Changes To Make Alternating Binary String](https://leetcode.com/problems/minimum-changes-to-make-alternating-binary-string) | | | -| 1763 | [Longest Nice Substring](https://leetcode.com/problems/longest-nice-substring) | | | -| 1768 | [Merge Strings Alternately](https://leetcode.com/problems/merge-strings-alternately) | | | -| 1773 | [Count Items Matching a Rule](https://leetcode.com/problems/count-items-matching-a-rule) | | | -| 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) | | | -| 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) | | | -| 1790 | [Check if One String Swap Can Make Strings Equal](https://leetcode.com/problems/check-if-one-string-swap-can-make-strings-equal) | | | -| 1791 | [Find Center of Star Graph](https://leetcode.com/problems/find-center-of-star-graph) | | | -| 1796 | [Second Largest Digit in a String](https://leetcode.com/problems/second-largest-digit-in-a-string) | | | -| 1800 | [Maximum Ascending Subarray Sum](https://leetcode.com/problems/maximum-ascending-subarray-sum) | | | -| 1805 | [Number of Different Integers in a String](https://leetcode.com/problems/number-of-different-integers-in-a-string) | | | -| 1812 | [Determine Color of a Chessboard Square](https://leetcode.com/problems/determine-color-of-a-chessboard-square) | | | -| 1816 | [Truncate Sentence](https://leetcode.com/problems/truncate-sentence) | | | -| 1822 | [Sign of the Product of an Array](https://leetcode.com/problems/sign-of-the-product-of-an-array) | | | -| 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) | | | -| 1832 | [Check if the Sentence Is Pangram](https://leetcode.com/problems/check-if-the-sentence-is-pangram) | | | -| 1837 | [Sum of Digits in Base K](https://leetcode.com/problems/sum-of-digits-in-base-k) | | | -| 1844 | [Replace All Digits with Characters](https://leetcode.com/problems/replace-all-digits-with-characters) | | | -| 1848 | [Minimum Distance to the Target Element](https://leetcode.com/problems/minimum-distance-to-the-target-element) | | | -| 1854 | [Maximum Population Year](https://leetcode.com/problems/maximum-population-year) | | | -| 1859 | [Sorting the Sentence](https://leetcode.com/problems/sorting-the-sentence) | | | -| 1863 | [Sum of All Subset XOR Totals](https://leetcode.com/problems/sum-of-all-subset-xor-totals) | | | -| 1869 | [Longer Contiguous Segments of Ones than Zeros](https://leetcode.com/problems/longer-contiguous-segments-of-ones-than-zeros) | | | -| 1624 | []() | | | -| 1624 | []() | | | -| 1624 | []() | | | -| 1624 | []() | | | -| 1624 | []() | | | -| 1624 | []() | | | -| 1624 | []() | | | -| 1624 | []() | | | -| 1624 | []() | | | +| # | 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) | +| 7 | [Reverse Integer](https://leetcode.com/problems/reverse-integer/) | [![Java](assets/java.png)](src/ReverseInteger.java) [![Python](assets/python.png)](python/reverse_integer.py) | [![java-yt](assets/java-yt.png)](https://youtu.be/7bOhyl5lWjI) [![python-yt](assets/python-yt.png)](https://youtu.be/lmLG30TLcSg) | +| 9 | [PalindromeNumber](https://leetcode.com/problems/palindrome-number/) | [![Java](assets/java.png)](src/PalindromeNumber.java) [![Python](assets/python.png)](python/palindrome_number.py) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 136 | [Single Number](https://leetcode.com/problems/single-number) | [![Java](assets/java.png)](src/SingleNumber.java) [![Python](assets/python.png)](python/single_number.py) | | +| 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) | | +| 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) | | +| 155 | [Min Stack](https://leetcode.com/problems/min-stack) | [![Java](assets/java.png)](src/MinStack.java) [![Python](assets/python.png)](python/min_stack.py) | | +| 157 | [Read N Characters Given Read4](https://leetcode.com/problems/read-n-characters-given-read4) | | | +| 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) | | +| 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) | | +| 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) | | +| 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 Lists](https://leetcode.com/problems/reverse-linked-list) | [![Java](assets/java.png)](src/ReverseLinkedList.java) [![Python](assets/python.png)](python/reverse_linked_list.py) | | +| 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate) | [![Java](assets/java.png)](src/ContainsDuplicate.java) [![Python](assets/python.png)](python/contains_duplicate.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) | | +| 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) | | +| 226 | [Summary Ranges](https://leetcode.com/problems/summary-ranges/) | [![Java](assets/java.png)](src/SummaryRanges.java) [![Python](assets/python.png)](python/summary_ranges.py) | | +| 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) | | +| 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) | | +| 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) | | | +| 246 | 🔒 [Strobogramatic Number](https://leetcode.com/problems/strobogrammatic-number) | | | +| 252 | 🔒 [Meeting Rooms](https://leetcode.com/problems/meeting-rooms) | | | +| 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) | | +| 263 | [Ugly Number](https://leetcode.com/problems/ugly-number) | [![Java](assets/java.png)](src/UglyNumber.java) [![Python](assets/python.png)](python/ugly_number.py) | | +| 266 | 🔒 [Palindrome Permutation](https://leetcode.com/problems/palindrome-permutation) | | | +| 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) | | | +| 276 | 🔒 [Paint Fence](https://leetcode.com/problems/paint-fence) | | | +| 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) | | +| 283 | [Move Zeroes](https://leetcode.com/problems/move-zeroes) | [![Java](assets/java.png)](src/MoveZeros.java) [![Python](assets/python.png)](python/move_zeroes.py) | | +| 290 | [Word Pattern](https://leetcode.com/problems/word-pattern) | [![Java](assets/java.png)](src/WordPattern.java) [![Python](assets/python.png)](python/word_pattern.py) | | +| 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) | | | +| 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) | | +| 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) | | +| 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) | | +| 326 | [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) | | | +| 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) | | +| 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) | | | +| 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) | | +| 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) | | | +| 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) | | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | | +| 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) | | +| 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) | | +| 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) | | | +| 1629 | [Slowest Key](https://leetcode.com/problems/slowest-key) | | | +| 1636 | [Sort Array by Increasing Frequency](https://leetcode.com/problems/sort-array-by-increasing-frequency) | | | +| 1640 | [Check Array Formation Through Concatenation](https://leetcode.com/problems/check-array-formation-through-concatenation) | | | +| 1646 | [Get Maximum in Generated Array](https://leetcode.com/problems/get-maximum-in-generated-array) | | | +| 1652 | [Defuse the Bomb](https://leetcode.com/problems/defuse-the-bomb) | | | +| 1656 | [Design an Ordered Stream](https://leetcode.com/problems/design-an-ordered-stream) | | | +| 1662 | [Check If Two String Arrays are Equivalent](https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent) | | | +| 1668 | [Maximum Repeating Substring](https://leetcode.com/problems/maximum-repeating-substring) | | | +| 1672 | [Richest Customer Wealth](https://leetcode.com/problems/richest-customer-wealth) | | | +| 1678 | [Goal Parser Interpretation](https://leetcode.com/problems/goal-parser-interpretation) | | | +| 1684 | [Count the Number of Consistent Strings](https://leetcode.com/problems/count-the-number-of-consistent-strings) | | | +| 1688 | [Count of Matches in Tournament](https://leetcode.com/problems/count-of-matches-in-tournament) | | | +| 1694 | [Reformat Phone Number](https://leetcode.com/problems/reformat-phone-number) | | | +| 1700 | [Number of Students Unable to Eat Lunch](https://leetcode.com/problems/number-of-students-unable-to-eat-lunch) | | | +| 1704 | [Determine if String Halves Are Alike](https://leetcode.com/problems/determine-if-string-halves-are-alike) | | | +| 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/) | | | +| 1716 | [Calculate Money in Leetcode Bank](https://leetcode.com/problems/calculate-money-in-leetcode-bank) | | | +| 1720 | [Decode XORed Array](https://leetcode.com/problems/decode-xored-array) | | | +| 1725 | [Number Of Rectangles That Can Form The Largest Square](https://leetcode.com/problems/number-of-rectangles-that-can-form-the-largest-square) | | | +| 1732 | [Find the Highest Altitude](https://leetcode.com/problems/find-the-highest-altitude) | | | +| 1736 | [Latest Time by Replacing Hidden Digits](https://leetcode.com/problems/latest-time-by-replacing-hidden-digits) | | | +| 1742 | [Maximum Number of Balls in a Box](https://leetcode.com/problems/maximum-number-of-balls-in-a-box) | | | +| 1748 | [Sum of Unique Elements](https://leetcode.com/problems/sum-of-unique-elements) | | | +| 1752 | [Check if Array Is Sorted and Rotated](https://leetcode.com/problems/check-if-array-is-sorted-and-rotated) | | | +| 1758 | [Minimum Changes To Make Alternating Binary String](https://leetcode.com/problems/minimum-changes-to-make-alternating-binary-string) | | | +| 1763 | [Longest Nice Substring](https://leetcode.com/problems/longest-nice-substring) | | | +| 1768 | [Merge Strings Alternately](https://leetcode.com/problems/merge-strings-alternately) | | | +| 1773 | [Count Items Matching a Rule](https://leetcode.com/problems/count-items-matching-a-rule) | | | +| 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) | | | +| 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) | | | +| 1790 | [Check if One String Swap Can Make Strings Equal](https://leetcode.com/problems/check-if-one-string-swap-can-make-strings-equal) | | | +| 1791 | [Find Center of Star Graph](https://leetcode.com/problems/find-center-of-star-graph) | | | +| 1796 | [Second Largest Digit in a String](https://leetcode.com/problems/second-largest-digit-in-a-string) | | | +| 1800 | [Maximum Ascending Subarray Sum](https://leetcode.com/problems/maximum-ascending-subarray-sum) | | | +| 1805 | [Number of Different Integers in a String](https://leetcode.com/problems/number-of-different-integers-in-a-string) | | | +| 1812 | [Determine Color of a Chessboard Square](https://leetcode.com/problems/determine-color-of-a-chessboard-square) | | | +| 1816 | [Truncate Sentence](https://leetcode.com/problems/truncate-sentence) | | | +| 1822 | [Sign of the Product of an Array](https://leetcode.com/problems/sign-of-the-product-of-an-array) | | | +| 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) | | | +| 1832 | [Check if the Sentence Is Pangram](https://leetcode.com/problems/check-if-the-sentence-is-pangram) | | | +| 1837 | [Sum of Digits in Base K](https://leetcode.com/problems/sum-of-digits-in-base-k) | | | +| 1844 | [Replace All Digits with Characters](https://leetcode.com/problems/replace-all-digits-with-characters) | | | +| 1848 | [Minimum Distance to the Target Element](https://leetcode.com/problems/minimum-distance-to-the-target-element) | | | +| 1854 | [Maximum Population Year](https://leetcode.com/problems/maximum-population-year) | | | +| 1859 | [Sorting the Sentence](https://leetcode.com/problems/sorting-the-sentence) | | | +| 1863 | [Sum of All Subset XOR Totals](https://leetcode.com/problems/sum-of-all-subset-xor-totals) | | | +| 1869 | [Longer Contiguous Segments of Ones than Zeros](https://leetcode.com/problems/longer-contiguous-segments-of-ones-than-zeros) | | | +| 1876 | [Substrings of Size Three with Distinct Characters](https://leetcode.com/problems/substrings-of-size-three-with-distinct-characters) | | | +| 1880 | [Check if Word Equals Summation of Two Words](https://leetcode.com/problems/check-if-word-equals-summation-of-two-words) | | | +| 1886 | [Determine Whether Matrix Can Be Obtained By Rotation](https://leetcode.com/problems/determine-whether-matrix-can-be-obtained-by-rotation) | | | +| 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) | | | +| 1897 | [Redistribute Characters to Make All Strings Equal](https://leetcode.com/problems/redistribute-characters-to-make-all-strings-equal) | | | +| 1903 | [Largest Odd Number in String](https://leetcode.com/problems/largest-odd-number-in-string) | | | +| 1909 | [Remove One Element to Make the Array Strictly Increasing](https://leetcode.com/problems/remove-one-element-to-make-the-array-strictly-increasing) | | | +| 1913 | [Maximum Product Difference Between Two Pairs](https://leetcode.com/problems/maximum-product-difference-between-two-pairs) | | | +| 1920 | [Build Array from Permutation](https://leetcode.com/problems/build-array-from-permutation) | | | +| 1925 | [Count Square Sum Triples](https://leetcode.com/problems/count-square-sum-triples) | | | +| 1929 | [Concatenation of Array](https://leetcode.com/problems/concatenation-of-array) | | | +| 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) | | | +| 1941 | [Check if All Characters Have Equal Number of Occurrences](https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences) | | | +| 1945 | [Sum of Digits of String After Convert](https://leetcode.com/problems/sum-of-digits-of-string-after-convert) | | | +| 1952 | [Three Divisors](https://leetcode.com/problems/three-divisors) | | | +| 1957 | [Delete Characters to Make Fancy String](https://leetcode.com/problems/delete-characters-to-make-fancy-string) | | | +| 1961 | [Check If String Is a Prefix of Array](https://leetcode.com/problems/check-if-string-is-a-prefix-of-array) | | | +| 1967 | [Number of Strings That Appear as Substrings in Word](https://leetcode.com/problems/number-of-strings-that-appear-as-substrings-in-word) | | | +| 1971 | [Find if Path Exists in Graph](https://leetcode.com/problems/find-if-path-exists-in-graph) | | | +| 1974 | [Minimum Time to Type Word Using Special Typewriter](https://leetcode.com/problems/minimum-time-to-type-word-using-special-typewriter) | | | +| 1979 | [Find Greatest Common Divisor of Array](https://leetcode.com/problems/find-greatest-common-divisor-of-array) | | | +| 1984 | [Minimum Difference Between Highest and Lowest of K Scores](https://leetcode.com/problems/minimum-difference-between-highest-and-lowest-of-k-scores) | | | +| 1991 | [Find the Middle Index in Array](https://leetcode.com/problems/find-the-middle-index-in-array) | | | +| 1995 | [Count Special Quadruplets](https://leetcode.com/problems/count-special-quadruplets) | | | +| 2000 | [Reverse Prefix of Word](https://leetcode.com/problems/reverse-prefix-of-word) | | | +| 2006 | [Count Number of Pairs With Absolute Difference K](https://leetcode.com/problems/count-number-of-pairs-with-absolute-difference-k) | | | +| 2011 | [Final Value of Variable After Performing Operations](https://leetcode.com/problems/final-value-of-variable-after-performing-operations) | | | +| 2016 | [Maximum Difference Between Increasing Elements](https://leetcode.com/problems/maximum-difference-between-increasing-elements) | | | +| 2022 | [Convert 1D Array Into 2D Array](https://leetcode.com/problems/convert-1d-array-into-2d-array) | | | +| 2027 | [Minimum Moves to Convert String](https://leetcode.com/problems/minimum-moves-to-convert-string) | | | +| 2032 | [Two Out of Three](https://leetcode.com/problems/two-out-of-three) | | | +| 2037 | [Minimum Number of Moves to Seat Everyone](https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone) | | | +| 2042 | [Check if Numbers Are Ascending in a Sentence](https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence) | | | +| 2047 | [Number of Valid Words in a Sentence](https://leetcode.com/problems/number-of-valid-words-in-a-sentence) | | | +| 2053 | [Kth Distinct String in an Array](https://leetcode.com/problems/kth-distinct-string-in-an-array) | | | +| 2057 | [Smallest Index With Equal Value](https://leetcode.com/problems/smallest-index-with-equal-value) | | | +| 2062 | [Count Vowel Substrings of a String](https://leetcode.com/problems/count-vowel-substrings-of-a-string) | | | +| 2068 | [Check Whether Two Strings are Almost Equivalent](https://leetcode.com/problems/check-whether-two-strings-are-almost-equivalent) | | | +| 2073 | [Time Needed to Buy Tickets](https://leetcode.com/problems/time-needed-to-buy-tickets) | | | +| 2078 | [Two Furthest Houses With Different Colors](https://leetcode.com/problems/two-furthest-houses-with-different-colors) | | | +| 2085 | [Count Common Words With One Occurrence](https://leetcode.com/problems/count-common-words-with-one-occurrence) | | | +| 2089 | [Find Target Indices After Sorting Array](https://leetcode.com/problems/find-target-indices-after-sorting-array) | | | +| 2094 | [Finding 3-Digit Even Numbers](https://leetcode.com/problems/finding-3-digit-even-numbers) | | | +| 2099 | [Find Subsequence of Length K With the Largest Sum](https://leetcode.com/problems/find-subsequence-of-length-k-with-the-largest-sum) | | | +| 2103 | [Rings and Rods](https://leetcode.com/problems/rings-and-rods) | | | From 32e53b5a1e1e653d62d578df3b86bc62f2ce7969 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 18 Dec 2021 21:27:13 +0100 Subject: [PATCH 358/947] solves largest substring between two equal characters --- README.md | 6 +++--- ...rgestSubStringBetweenTwoEqualCharacters.java | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 src/LargestSubStringBetweenTwoEqualCharacters.java diff --git a/README.md b/README.md index 32b8189..bd43969 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-326/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-326/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-328/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-328/2081-1abc9c.svg) ![problems-solved-python](https://img.shields.io/badge/Python-186/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) @@ -403,7 +403,7 @@ | 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) | | | +| 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) | | | | 1636 | [Sort Array by Increasing Frequency](https://leetcode.com/problems/sort-array-by-increasing-frequency) | | | | 1640 | [Check Array Formation Through Concatenation](https://leetcode.com/problems/check-array-formation-through-concatenation) | | | diff --git a/src/LargestSubStringBetweenTwoEqualCharacters.java b/src/LargestSubStringBetweenTwoEqualCharacters.java new file mode 100644 index 0000000..c9e2601 --- /dev/null +++ b/src/LargestSubStringBetweenTwoEqualCharacters.java @@ -0,0 +1,17 @@ +import java.util.HashMap; +import java.util.Map; + +public class LargestSubStringBetweenTwoEqualCharacters { + public int maxLengthBetweenEqualCharacters(String s) { + int maxLength = -1; + final Map lastIndex = new HashMap<>(); + for (int i = 0 ; i < s.length() ; i++) { + if (lastIndex.containsKey(s.charAt(i))) { + maxLength = Math.max(maxLength, i - lastIndex.get(s.charAt(i)) - 1); + } else { + lastIndex.put(s.charAt(i), i); + } + } + return maxLength; + } +} From cc954d5c66046a25604591fdafe16f644d1b69a1 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 19 Dec 2021 17:33:55 +0100 Subject: [PATCH 359/947] solves slowest key --- README.md | 2 +- src/SlowestKey.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/SlowestKey.java diff --git a/README.md b/README.md index bd43969..7611e59 100644 --- a/README.md +++ b/README.md @@ -404,7 +404,7 @@ | 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) | | | +| 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) | | | | 1640 | [Check Array Formation Through Concatenation](https://leetcode.com/problems/check-array-formation-through-concatenation) | | | | 1646 | [Get Maximum in Generated Array](https://leetcode.com/problems/get-maximum-in-generated-array) | | | diff --git a/src/SlowestKey.java b/src/SlowestKey.java new file mode 100644 index 0000000..8aac92d --- /dev/null +++ b/src/SlowestKey.java @@ -0,0 +1,15 @@ +public class SlowestKey { + public char slowestKey(int[] releaseTimes, String keysPressed) { + char slowestKey = keysPressed.charAt(0); + int longestDuration = releaseTimes[0]; + for (int index = 1 ; index < keysPressed.length() ; index++) { + if (releaseTimes[index] - releaseTimes[index - 1] > longestDuration) { + longestDuration = releaseTimes[index] - releaseTimes[index - 1]; + slowestKey = keysPressed.charAt(index); + } else if (releaseTimes[index] - releaseTimes[index - 1] == longestDuration) { + slowestKey = (char) Math.max(slowestKey, keysPressed.charAt(index)); + } + } + return slowestKey; + } +} From d8db1eb668e2a58dc472f3afed027708f3e87734 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 19 Dec 2021 17:42:41 +0100 Subject: [PATCH 360/947] solves sort array by incresing frequency --- README.md | 2 +- src/SortArrayByIncreasingFrequency.java | 32 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/SortArrayByIncreasingFrequency.java diff --git a/README.md b/README.md index 7611e59..794c71d 100644 --- a/README.md +++ b/README.md @@ -405,7 +405,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) | | -| 1636 | [Sort Array by Increasing Frequency](https://leetcode.com/problems/sort-array-by-increasing-frequency) | | | +| 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) | | | | 1646 | [Get Maximum in Generated Array](https://leetcode.com/problems/get-maximum-in-generated-array) | | | | 1652 | [Defuse the Bomb](https://leetcode.com/problems/defuse-the-bomb) | | | diff --git a/src/SortArrayByIncreasingFrequency.java b/src/SortArrayByIncreasingFrequency.java new file mode 100644 index 0000000..c35aa26 --- /dev/null +++ b/src/SortArrayByIncreasingFrequency.java @@ -0,0 +1,32 @@ +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +public class SortArrayByIncreasingFrequency { + public int[] frequencySort(int[] array) { + Map frequencies = getFrequencies(array); + + return toArray(Arrays.stream(array).boxed().sorted((a, b) -> { + if (frequencies.get(a).equals(frequencies.get(b))) return b - a; + return frequencies.get(a) - frequencies.get(b); + }).collect(Collectors.toList())); + } + + private Map getFrequencies(int[] array) { + final Map frequencies = new HashMap<>(); + for (int element : array) { + frequencies.put(element, frequencies.getOrDefault(element, 0) + 1); + } + return frequencies; + } + + 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; + } +} From 7f1822994654d37c3e6ad2449c4f8a6c04f3c74e Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 19 Dec 2021 18:21:33 +0100 Subject: [PATCH 361/947] solves check array formation through concatenation --- README.md | 2 +- ...eckArrayFormationThroughConcatenation.java | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/CheckArrayFormationThroughConcatenation.java diff --git a/README.md b/README.md index 794c71d..eaf5734 100644 --- a/README.md +++ b/README.md @@ -406,7 +406,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) | | -| 1640 | [Check Array Formation Through Concatenation](https://leetcode.com/problems/check-array-formation-through-concatenation) | | | +| 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) | | | | 1652 | [Defuse the Bomb](https://leetcode.com/problems/defuse-the-bomb) | | | | 1656 | [Design an Ordered Stream](https://leetcode.com/problems/design-an-ordered-stream) | | | diff --git a/src/CheckArrayFormationThroughConcatenation.java b/src/CheckArrayFormationThroughConcatenation.java new file mode 100644 index 0000000..b3ac07b --- /dev/null +++ b/src/CheckArrayFormationThroughConcatenation.java @@ -0,0 +1,24 @@ +import java.util.HashMap; +import java.util.Map; + +public class CheckArrayFormationThroughConcatenation { + public boolean canFormArray(int[] arr, int[][] pieces) { + final Map positions = getPositions(arr); + for (int[] piece : pieces) { + if (!positions.containsKey(piece[0])) return false; + if (positions.get(piece[0]) + piece.length > arr.length) return false; + for (int i = 0, j = positions.get(piece[0]); i < piece.length ; i++, j++) { + if (piece[i] != arr[j]) return false; + } + } + return true; + } + + private Map getPositions(int[] array) { + final Map positions = new HashMap<>(); + for (int index = 0 ; index < array.length ; index++) { + positions.put(array[index], index); + } + return positions; + } +} From 5a11efe364cdf0680d6723257b89724ed569a3ae Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 19 Dec 2021 18:42:20 +0100 Subject: [PATCH 362/947] solves get maximum in generted array --- README.md | 2 +- src/GetMaximumInGeneratedArray.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/GetMaximumInGeneratedArray.java diff --git a/README.md b/README.md index eaf5734..eb8e179 100644 --- a/README.md +++ b/README.md @@ -407,7 +407,7 @@ | 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) | | | +| 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) | | | | 1656 | [Design an Ordered Stream](https://leetcode.com/problems/design-an-ordered-stream) | | | | 1662 | [Check If Two String Arrays are Equivalent](https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent) | | | diff --git a/src/GetMaximumInGeneratedArray.java b/src/GetMaximumInGeneratedArray.java new file mode 100644 index 0000000..7ae1d14 --- /dev/null +++ b/src/GetMaximumInGeneratedArray.java @@ -0,0 +1,15 @@ +import java.util.Arrays; + +public class GetMaximumInGeneratedArray { + public int getMaximumGenerated(int n) { + if (n == 0) return 0; + final int[] array = new int[n + 1]; + array[0] = 0; + array[1] = 1; + for (int index = 2 ; index < array.length ; index++) { + if ((index & 1) == 0) array[index] = array[index / 2]; + else array[index] = array[index / 2] + array[index - index / 2]; + } + return Arrays.stream(array).max().getAsInt(); + } +} From cd4e1f66edcad5c8e3169a78ab597ac728a15431 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 19 Dec 2021 19:24:51 +0100 Subject: [PATCH 363/947] solves defuse the bomb --- README.md | 2 +- src/DefuseTheBomb.java | 56 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/DefuseTheBomb.java diff --git a/README.md b/README.md index eb8e179..151a896 100644 --- a/README.md +++ b/README.md @@ -408,7 +408,7 @@ | 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) | | | +| 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) | | | | 1662 | [Check If Two String Arrays are Equivalent](https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent) | | | | 1668 | [Maximum Repeating Substring](https://leetcode.com/problems/maximum-repeating-substring) | | | diff --git a/src/DefuseTheBomb.java b/src/DefuseTheBomb.java new file mode 100644 index 0000000..45c0ba4 --- /dev/null +++ b/src/DefuseTheBomb.java @@ -0,0 +1,56 @@ +public class DefuseTheBomb { + public int[] decrypt(int[] code, int k) { + if (k == 0) return new int[code.length]; + final Code codeData = new Code(code); + final int[] result = new int[code.length]; + if (k > 0) { + for (int index = 0 ; index < result.length ; index++) { + result[index] = codeData.getSlice(index + 1, index + k); + } + } else { + for (int index = 0 ; index < result.length ; index++) { + result[index] = codeData.getSlice(index + k, index - 1); + } + } + return result; + } + + private static final class Code { + private final int[] sum; + private final int codeSum; + + Code(int[] code) { + this.sum = computeSum(code); + this.codeSum = sum[sum.length - 1]; + } + + private int[] computeSum(int[] array) { + final int[] sum = new int[array.length]; + sum[0] = array[0]; + for (int index = 1 ; index < array.length ; index++) { + sum[index] = sum[index - 1] + array[index]; + } + return sum; + } + + private int getIndex(int index) { + return (index + sum.length) % sum.length; + } + + private int getSlice(int start, int end) { + final int startIndex = getIndex(start), endIndex = getIndex(end); + if (startIndex <= endIndex) { + return sum[endIndex] - (startIndex == 0 ? 0: sum[startIndex - 1]); + } + return codeSum - sum[startIndex - 1] + sum[endIndex]; + } + + private int[] getFullSumArray(int length) { + final int[] array = new int[length]; + for (int index = 0 ; index < length ; index++) { + array[index] = codeSum; + } + return array; + } + } +} From 9e85ccc6d56584a861d98b518a134e38c8a442f8 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 19 Dec 2021 19:33:15 +0100 Subject: [PATCH 364/947] solves design an oredred stream --- README.md | 2 +- src/DesignAnOrderedStream.java | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/DesignAnOrderedStream.java diff --git a/README.md b/README.md index 151a896..e5290e9 100644 --- a/README.md +++ b/README.md @@ -409,7 +409,7 @@ | 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) | | | +| 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) | | | | 1668 | [Maximum Repeating Substring](https://leetcode.com/problems/maximum-repeating-substring) | | | | 1672 | [Richest Customer Wealth](https://leetcode.com/problems/richest-customer-wealth) | | | diff --git a/src/DesignAnOrderedStream.java b/src/DesignAnOrderedStream.java new file mode 100644 index 0000000..b01fa25 --- /dev/null +++ b/src/DesignAnOrderedStream.java @@ -0,0 +1,26 @@ +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class DesignAnOrderedStream { + class OrderedStream { + private final String[] array; + private int pointer = 1; + + public OrderedStream(int n) { + this.array = new String[n + 1]; + } + + public List insert(int key, String value) { + array[key] = value; + if (pointer == key) { + final List list = new ArrayList<>(); + while (pointer < array.length && array[pointer] != null) { + list.add(array[pointer++]); + } + return list; + } + return Collections.emptyList(); + } + } +} From e6daec3414e30e06d2e7624f84d7d232ea3a1554 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 19 Dec 2021 20:07:48 +0100 Subject: [PATCH 365/947] solves check if two strings are equivaent --- README.md | 2 +- src/CheckIfTwoStringArraysAreEquivalent.java | 21 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 src/CheckIfTwoStringArraysAreEquivalent.java diff --git a/README.md b/README.md index e5290e9..9eac572 100644 --- a/README.md +++ b/README.md @@ -410,7 +410,7 @@ | 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) | | | +| 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) | | | | 1672 | [Richest Customer Wealth](https://leetcode.com/problems/richest-customer-wealth) | | | | 1678 | [Goal Parser Interpretation](https://leetcode.com/problems/goal-parser-interpretation) | | | diff --git a/src/CheckIfTwoStringArraysAreEquivalent.java b/src/CheckIfTwoStringArraysAreEquivalent.java new file mode 100644 index 0000000..1226451 --- /dev/null +++ b/src/CheckIfTwoStringArraysAreEquivalent.java @@ -0,0 +1,21 @@ +public class CheckIfTwoStringArraysAreEquivalent { + public boolean arrayStringsAreEqual(String[] word1, String[] word2) { + for (int w1 = 0, w2 = 0, i = 0, j = 0 ; w1 < word1.length && w2 < word2.length ; ) { + if (word1[w1].charAt(i) != word2[w2].charAt(j)) return false; + if (i == word1[w1].length() - 1) { + w1++; + i = 0; + } else { + i++; + } + if (j == word2[w2].length() - 1) { + w2++; + j = 0; + } else { + j++; + } + if (w1 == word1.length && w2 == word2.length) return true; + } + return false; + } +} From 431d9dedc0e5c5e168590ca831371b306f73015c Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 19 Dec 2021 20:32:20 +0100 Subject: [PATCH 366/947] solves maximum repeating substring --- README.md | 2 +- src/MaximumRepeatingSubString.java | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/MaximumRepeatingSubString.java diff --git a/README.md b/README.md index 9eac572..84edf46 100644 --- a/README.md +++ b/README.md @@ -411,7 +411,7 @@ | 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) | | | +| 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) | | | | 1678 | [Goal Parser Interpretation](https://leetcode.com/problems/goal-parser-interpretation) | | | | 1684 | [Count the Number of Consistent Strings](https://leetcode.com/problems/count-the-number-of-consistent-strings) | | | diff --git a/src/MaximumRepeatingSubString.java b/src/MaximumRepeatingSubString.java new file mode 100644 index 0000000..71a7592 --- /dev/null +++ b/src/MaximumRepeatingSubString.java @@ -0,0 +1,24 @@ +public class MaximumRepeatingSubString { + public int maxRepeating(String sequence, String word) { + int result = 0, index = 0; + while (index < sequence.length()) { + int matchIndex = sequence.indexOf(word, index); + if (matchIndex == -1) break; + int k = 0; + for (int i = matchIndex + word.length() ; i < sequence.length() ; i += word.length(), k++) { + if (!areEqual(sequence, word, i)) break; + } + result = Math.max(result, 1 + k); + index = matchIndex + 1; + } + return result; + } + + private boolean areEqual(String text, String pattern, int startIndex) { + if (pattern.length() > text.length() - startIndex) return false; + for (int i = startIndex ; i < text.length() && i - startIndex < pattern.length() ; i++) { + if (text.charAt(i) != pattern.charAt(i - startIndex)) return false; + } + return true; + } +} From 52b74b8a9e1f94e139b21ab2fb09aa671a76c47c Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 19 Dec 2021 20:35:41 +0100 Subject: [PATCH 367/947] solves richest customer wealth --- README.md | 2 +- src/RichestCustomerWealth.java | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/RichestCustomerWealth.java diff --git a/README.md b/README.md index 84edf46..c0b324f 100644 --- a/README.md +++ b/README.md @@ -412,7 +412,7 @@ | 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) | | | +| 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) | | | | 1684 | [Count the Number of Consistent Strings](https://leetcode.com/problems/count-the-number-of-consistent-strings) | | | | 1688 | [Count of Matches in Tournament](https://leetcode.com/problems/count-of-matches-in-tournament) | | | diff --git a/src/RichestCustomerWealth.java b/src/RichestCustomerWealth.java new file mode 100644 index 0000000..dacf5c5 --- /dev/null +++ b/src/RichestCustomerWealth.java @@ -0,0 +1,11 @@ +import java.util.Arrays; + +public class RichestCustomerWealth { + public int maximumWealth(int[][] accounts) { + int maxWealth = 0; + for (int[] customer : accounts) { + maxWealth = Math.max(maxWealth, Arrays.stream(customer).sum()); + } + return maxWealth; + } +} From 3ca422552a44f4cb744be812ec2bfc2fd29f6923 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 19 Dec 2021 20:39:47 +0100 Subject: [PATCH 368/947] solves goal parser implemetation --- README.md | 2 +- src/GoalParserInterpretation.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/GoalParserInterpretation.java diff --git a/README.md b/README.md index c0b324f..fce5926 100644 --- a/README.md +++ b/README.md @@ -413,7 +413,7 @@ | 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) | | | +| 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) | | | | 1688 | [Count of Matches in Tournament](https://leetcode.com/problems/count-of-matches-in-tournament) | | | | 1694 | [Reformat Phone Number](https://leetcode.com/problems/reformat-phone-number) | | | diff --git a/src/GoalParserInterpretation.java b/src/GoalParserInterpretation.java new file mode 100644 index 0000000..6797bbb --- /dev/null +++ b/src/GoalParserInterpretation.java @@ -0,0 +1,18 @@ +public class GoalParserInterpretation { + public String interpret(String command) { + final StringBuilder result = new StringBuilder(); + for (int index = 0 ; index < command.length() ; ) { + if (command.charAt(index) == 'G') { + result.append('G'); + index++; + } else if (command.charAt(index + 1) == ')') { + result.append('o'); + index += 2; + } else { + result.append("al"); + index += 4; + } + } + return result.toString(); + } +} From 16c2825c581bd68989f7337367021153bf184017 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 19 Dec 2021 20:44:51 +0100 Subject: [PATCH 369/947] solves count the number of consistent strings --- README.md | 2 +- src/CountTheNumberOfConsistentStrings.java | 35 ++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/CountTheNumberOfConsistentStrings.java diff --git a/README.md b/README.md index fce5926..c70636d 100644 --- a/README.md +++ b/README.md @@ -414,7 +414,7 @@ | 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) | | | +| 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) | | | | 1694 | [Reformat Phone Number](https://leetcode.com/problems/reformat-phone-number) | | | | 1700 | [Number of Students Unable to Eat Lunch](https://leetcode.com/problems/number-of-students-unable-to-eat-lunch) | | | diff --git a/src/CountTheNumberOfConsistentStrings.java b/src/CountTheNumberOfConsistentStrings.java new file mode 100644 index 0000000..d29f7ef --- /dev/null +++ b/src/CountTheNumberOfConsistentStrings.java @@ -0,0 +1,35 @@ +// T: O(allowed + words * word) +// S: O(allowed) + +import java.util.HashSet; +import java.util.Set; + +public class CountTheNumberOfConsistentStrings { + public int countConsistentStrings(String allowed, String[] words) { + final Set allowedCharacters = getCharacters(allowed); + int consistentStrings = 0; + for (String word :words) { + if (allCharsPresentIn(word, allowedCharacters)) { + consistentStrings++; + } + } + return consistentStrings; + } + + private Set getCharacters(String string) { + final Set set = new HashSet<>(); + for (int index = 0 ; index < string.length() ; index++) { + set.add(string.charAt(index)); + } + return set; + } + + private boolean allCharsPresentIn(String string, Set allowedChars) { + for (int index = 0 ; index < string.length() ; index++) { + if (!allowedChars.contains(string.charAt(index))) { + return false; + } + } + return true; + } +} From fc3e12c30b82a3876a48e664ecdaa2ace8b2c23b Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 19 Dec 2021 20:48:44 +0100 Subject: [PATCH 370/947] solves count number of matches in tournament --- README.md | 2 +- src/CountOfMatchesInTournament.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 src/CountOfMatchesInTournament.java diff --git a/README.md b/README.md index c70636d..8a813af 100644 --- a/README.md +++ b/README.md @@ -415,7 +415,7 @@ | 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) | | | +| 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) | | | | 1700 | [Number of Students Unable to Eat Lunch](https://leetcode.com/problems/number-of-students-unable-to-eat-lunch) | | | | 1704 | [Determine if String Halves Are Alike](https://leetcode.com/problems/determine-if-string-halves-are-alike) | | | diff --git a/src/CountOfMatchesInTournament.java b/src/CountOfMatchesInTournament.java new file mode 100644 index 0000000..9c2ce71 --- /dev/null +++ b/src/CountOfMatchesInTournament.java @@ -0,0 +1,10 @@ +// https://leetcode.com/problems/count-of-matches-in-tournament +// T: O(log N) +// S: O(log N) + +public class CountOfMatchesInTournament { + public int numberOfMatches(int n) { + if (n == 1) return 0; + return n / 2 + numberOfMatches(n - n / 2); + } +} From 74670a55796b2ec98ae9d1bee2d7e07bbb66e39a Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 19 Dec 2021 21:00:56 +0100 Subject: [PATCH 371/947] solves reformat phone number --- README.md | 2 +- src/ReformatPhoneNumber.java | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/ReformatPhoneNumber.java diff --git a/README.md b/README.md index 8a813af..0f75c2a 100644 --- a/README.md +++ b/README.md @@ -416,7 +416,7 @@ | 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) | | | +| 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) | | | | 1704 | [Determine if String Halves Are Alike](https://leetcode.com/problems/determine-if-string-halves-are-alike) | | | | 1708 | 🔒 [Largest Subarray Length K](https://leetcode.com/problems/largest-subarray-length-k/) | | | diff --git a/src/ReformatPhoneNumber.java b/src/ReformatPhoneNumber.java new file mode 100644 index 0000000..62c6067 --- /dev/null +++ b/src/ReformatPhoneNumber.java @@ -0,0 +1,30 @@ +import java.util.LinkedList; +import java.util.Queue; + +public class ReformatPhoneNumber { + public String reformatNumber(String number) { + final Queue digits = getDigits(number); + final StringBuilder result = new StringBuilder(); + int count = 3; + while (!digits.isEmpty()) { + if (digits.size() == 4 && count % 3 == 0) { + result.append(count == 3 ? "" : '-').append(digits.poll()).append(digits.poll()) + .append('-').append(digits.poll()).append(digits.poll()); + break; + } + result.append(count == 0 ? '-' : "").append(digits.poll()); + count = (count + 1) % 3; + } + return result.toString(); + } + + private Queue getDigits(String number) { + final Queue digits = new LinkedList<>(); + for (int index = 0 ; index < number.length() ; index++) { + if (Character.isDigit(number.charAt(index))) { + digits.add(number.charAt(index)); + } + } + return digits; + } +} From bb7925f71928d00e9cc98ec82e04964437bad019 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 19 Dec 2021 21:11:56 +0100 Subject: [PATCH 372/947] solves number of students unable to eat lunch --- README.md | 2 +- src/NumberOfStudentsUnableToEatLunch.java | 28 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/NumberOfStudentsUnableToEatLunch.java diff --git a/README.md b/README.md index 0f75c2a..2476b99 100644 --- a/README.md +++ b/README.md @@ -417,7 +417,7 @@ | 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) | | | +| 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) | | | | 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/) | | | diff --git a/src/NumberOfStudentsUnableToEatLunch.java b/src/NumberOfStudentsUnableToEatLunch.java new file mode 100644 index 0000000..675f3dd --- /dev/null +++ b/src/NumberOfStudentsUnableToEatLunch.java @@ -0,0 +1,28 @@ +import java.util.LinkedList; +import java.util.Queue; + +public class NumberOfStudentsUnableToEatLunch { + public int countStudents(int[] students, int[] sandwiches) { + final Queue studentQueue = queueFrom(students); + int replacementStudents = 0, stack = 0; + while (!studentQueue.isEmpty() && replacementStudents < studentQueue.size()) { + if (studentQueue.peek() == sandwiches[stack]) { + stack++; + studentQueue.poll(); + replacementStudents = 0; + } else { + studentQueue.add(studentQueue.poll()); + replacementStudents++; + } + } + return studentQueue.size(); + } + + private Queue queueFrom(int[] array) { + final Queue queue = new LinkedList<>(); + for (int element : array) { + queue.add(element); + } + return queue; + } +} From ecfdcae12654c2524b143099798e245ebf14561f Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 20 Dec 2021 17:48:17 +0100 Subject: [PATCH 373/947] solves determine if string halves are alike --- README.md | 2 +- src/DetermineIfStringHalvesAreAlike.java | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 src/DetermineIfStringHalvesAreAlike.java diff --git a/README.md b/README.md index 2476b99..d45266c 100644 --- a/README.md +++ b/README.md @@ -418,7 +418,7 @@ | 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) | | | +| 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/) | | | | 1716 | [Calculate Money in Leetcode Bank](https://leetcode.com/problems/calculate-money-in-leetcode-bank) | | | diff --git a/src/DetermineIfStringHalvesAreAlike.java b/src/DetermineIfStringHalvesAreAlike.java new file mode 100644 index 0000000..9e7f75f --- /dev/null +++ b/src/DetermineIfStringHalvesAreAlike.java @@ -0,0 +1,23 @@ +import java.util.Set; + +public class DetermineIfStringHalvesAreAlike { + private static final Set VOWELS = Set.of('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'); + + public boolean halvesAreAlike(String s) { + return numberOfVowels(s, 0, s.length() / 2) == numberOfVowels(s, s.length() / 2); + } + + private int numberOfVowels(String s, int startIndex) { + return numberOfVowels(s, startIndex, s.length()); + } + + private int numberOfVowels(String s, int startIndex, int endIndex) { + int count = 0; + for (int index = startIndex ; index < endIndex ; index++) { + if (VOWELS.contains(s.charAt(index))) { + count++; + } + } + return count; + } +} From d12afc986e1efc5f3f31be6f02eca7e85bf769da Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 20 Dec 2021 18:20:15 +0100 Subject: [PATCH 374/947] solves maximum units on a truck --- README.md | 2 +- src/MaximumUnitsOnATruck.java | 43 +++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 src/MaximumUnitsOnATruck.java diff --git a/README.md b/README.md index d45266c..abf96f8 100644 --- a/README.md +++ b/README.md @@ -420,7 +420,7 @@ | 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/) | | | +| 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) | | | | 1720 | [Decode XORed Array](https://leetcode.com/problems/decode-xored-array) | | | | 1725 | [Number Of Rectangles That Can Form The Largest Square](https://leetcode.com/problems/number-of-rectangles-that-can-form-the-largest-square) | | | diff --git a/src/MaximumUnitsOnATruck.java b/src/MaximumUnitsOnATruck.java new file mode 100644 index 0000000..b53dd78 --- /dev/null +++ b/src/MaximumUnitsOnATruck.java @@ -0,0 +1,43 @@ +import java.util.ArrayList; +import java.util.List; + +public class MaximumUnitsOnATruck { + public int maximumUnits(int[][] boxTypes, int truckSize) { + final List boxes = getBoxTypesFrom(boxTypes); + boxes.sort(BoxType::compareTo); + int units = 0; + for (BoxType box : boxes) { + if (box.number <= truckSize) { + units += box.units * box.number; + truckSize -= box.number; + } else { + units += box.units * truckSize; + break; + } + } + return units; + } + + private List getBoxTypesFrom(int[][] boxes) { + final List boxTypes = new ArrayList<>(); + for (int[] box : boxes) { + boxTypes.add(new BoxType(box[0], box[1])); + } + return boxTypes; + } + + private static final class BoxType implements Comparable { + private final int number; + private final int units; + + private BoxType(int number, int units) { + this.number = number; + this.units = units; + } + + @Override + public int compareTo(BoxType o) { + return Integer.compare(o.units, this.units); + } + } +} From 0d05e3e47ff870859a3c28b3bfea79305ab9560b Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 21 Dec 2021 14:12:18 +0100 Subject: [PATCH 375/947] solves calculate money in leetcode bank --- README.md | 2 +- src/CalculateMoneyInLeetCodeBank.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/CalculateMoneyInLeetCodeBank.java diff --git a/README.md b/README.md index abf96f8..4dd78c0 100644 --- a/README.md +++ b/README.md @@ -421,7 +421,7 @@ | 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) | | | +| 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) | | | | 1725 | [Number Of Rectangles That Can Form The Largest Square](https://leetcode.com/problems/number-of-rectangles-that-can-form-the-largest-square) | | | | 1732 | [Find the Highest Altitude](https://leetcode.com/problems/find-the-highest-altitude) | | | diff --git a/src/CalculateMoneyInLeetCodeBank.java b/src/CalculateMoneyInLeetCodeBank.java new file mode 100644 index 0000000..a75bd41 --- /dev/null +++ b/src/CalculateMoneyInLeetCodeBank.java @@ -0,0 +1,19 @@ +public class CalculateMoneyInLeetCodeBank { + private static final int SUM_7 = 28; + + public int totalMoney (int n) { + final int r = ceil((double) n / 7); + return r * SUM_7 + + 7 * summation(r - 1) + - (summation(6 + r) - summation(n % 7 == 0 ? 6 + r : r - 1 + n % 7)); + } + + private int ceil(double d) { + return (int) Math.ceil(d); + } + + private int summation(int x) { + if (x <= 0) return 0; + return (x * (x + 1)) / 2; + } +} From 6f666d88c339f25551fd4131f589ca703865a752 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 21 Dec 2021 14:19:23 +0100 Subject: [PATCH 376/947] solves decoded xored array --- README.md | 2 +- src/DecodeXORedArray.java | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 src/DecodeXORedArray.java diff --git a/README.md b/README.md index 4dd78c0..6d40d0b 100644 --- a/README.md +++ b/README.md @@ -422,7 +422,7 @@ | 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) | | | +| 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) | | | | 1732 | [Find the Highest Altitude](https://leetcode.com/problems/find-the-highest-altitude) | | | | 1736 | [Latest Time by Replacing Hidden Digits](https://leetcode.com/problems/latest-time-by-replacing-hidden-digits) | | | diff --git a/src/DecodeXORedArray.java b/src/DecodeXORedArray.java new file mode 100644 index 0000000..d287e28 --- /dev/null +++ b/src/DecodeXORedArray.java @@ -0,0 +1,12 @@ +public class DecodeXORedArray { + public int[] decode(int[] encoded, int first) { + final int[] result = new int[encoded.length + 1]; + result[0] = first; + int next = first, i = 1; + for (int element : encoded) { + next = element ^ next; + result[i++] = next; + } + return result; + } +} From 1624ec5fc6ea863aced23f3d76e09bc9bee6d464 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 21 Dec 2021 14:23:43 +0100 Subject: [PATCH 377/947] solves number of rectangles that can form largest square --- README.md | 2 +- ...erOfRectanglesThatCanFormTheLargestSquare.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/NumberOfRectanglesThatCanFormTheLargestSquare.java diff --git a/README.md b/README.md index 6d40d0b..993d5c4 100644 --- a/README.md +++ b/README.md @@ -423,7 +423,7 @@ | 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) | | | +| 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) | | | | 1736 | [Latest Time by Replacing Hidden Digits](https://leetcode.com/problems/latest-time-by-replacing-hidden-digits) | | | | 1742 | [Maximum Number of Balls in a Box](https://leetcode.com/problems/maximum-number-of-balls-in-a-box) | | | diff --git a/src/NumberOfRectanglesThatCanFormTheLargestSquare.java b/src/NumberOfRectanglesThatCanFormTheLargestSquare.java new file mode 100644 index 0000000..04b1694 --- /dev/null +++ b/src/NumberOfRectanglesThatCanFormTheLargestSquare.java @@ -0,0 +1,15 @@ +public class NumberOfRectanglesThatCanFormTheLargestSquare { + public int countGoodRectangles(int[][] rectangles) { + int maxLength = 0, frequency = 0, length; + for (int[] rectangle : rectangles) { + length = Math.min(rectangle[0], rectangle[1]); + if (length > maxLength) { + maxLength = length; + frequency = 1; + } else if (length == maxLength) { + frequency++; + } + } + return frequency; + } +} From 660bbe0577598cf2ecb8edc42a2920c72383df73 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 21 Dec 2021 14:27:43 +0100 Subject: [PATCH 378/947] solves find teh highest altitude --- README.md | 2 +- src/FindTheHighestAltitude.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/FindTheHighestAltitude.java diff --git a/README.md b/README.md index 993d5c4..bd6cd6b 100644 --- a/README.md +++ b/README.md @@ -424,7 +424,7 @@ | 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) | | | +| 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) | | | | 1742 | [Maximum Number of Balls in a Box](https://leetcode.com/problems/maximum-number-of-balls-in-a-box) | | | | 1748 | [Sum of Unique Elements](https://leetcode.com/problems/sum-of-unique-elements) | | | diff --git a/src/FindTheHighestAltitude.java b/src/FindTheHighestAltitude.java new file mode 100644 index 0000000..542969b --- /dev/null +++ b/src/FindTheHighestAltitude.java @@ -0,0 +1,14 @@ +// https://leetcode.com/problems/find-the-highest-altitude +// T: O(N) +// S: O(1) + +public class FindTheHighestAltitude { + public int largestAltitude(int[] gains) { + int highestAltitude = 0, current = 0; + for (int gain : gains) { + current+= gain; + highestAltitude = Math.max(highestAltitude, current); + } + return highestAltitude; + } +} From fbc9cc2b48d7623b022145ba0263413e610815aa Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 21 Dec 2021 15:17:12 +0100 Subject: [PATCH 379/947] solves latest time by replacing hidden digits --- README.md | 2 +- src/LatestTimeByReplacingHiddenDigits.java | 28 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/LatestTimeByReplacingHiddenDigits.java diff --git a/README.md b/README.md index bd6cd6b..65374aa 100644 --- a/README.md +++ b/README.md @@ -425,7 +425,7 @@ | 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) | | | +| 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) | | | | 1748 | [Sum of Unique Elements](https://leetcode.com/problems/sum-of-unique-elements) | | | | 1752 | [Check if Array Is Sorted and Rotated](https://leetcode.com/problems/check-if-array-is-sorted-and-rotated) | | | diff --git a/src/LatestTimeByReplacingHiddenDigits.java b/src/LatestTimeByReplacingHiddenDigits.java new file mode 100644 index 0000000..a93b8e1 --- /dev/null +++ b/src/LatestTimeByReplacingHiddenDigits.java @@ -0,0 +1,28 @@ +public class LatestTimeByReplacingHiddenDigits { + public String maximumTime(String time) { + String[] parts = time.split(":"); + String hour = parts[0], minutes = parts[1]; + return new StringBuilder(maxHours(hour)).append(':').append(maxMinutes(minutes)).toString(); + } + + private String maxHours(String string) { + if (string.charAt(0) == '?') { + if (string.charAt(1) == '?') return "23"; + if (string.charAt(1) > '3') return "1" + string.charAt(1); + return "2" + string.charAt(1); + } else if (string.charAt(1) == '?') { + return string.charAt(0) + (string.charAt(0) == '2' ? "3" : "9"); + } + return string; + } + + private String maxMinutes(String string) { + if (string.charAt(0) == '?') { + if (string.charAt(1) == '?') return "59"; + return "5" + string.charAt(1); + } else if (string.charAt(1) == '?') { + return string.charAt(0) + "9"; + } + return string; + } +} From 7ae61669227f0976a644bb75ae11024fbb864826 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 21 Dec 2021 15:28:41 +0100 Subject: [PATCH 380/947] solves maximum number of balls in a box --- README.md | 2 +- src/MaximumNumberOfBallsInABox.java | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/MaximumNumberOfBallsInABox.java diff --git a/README.md b/README.md index 65374aa..e64ad17 100644 --- a/README.md +++ b/README.md @@ -426,7 +426,7 @@ | 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) | | | +| 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) | | | | 1752 | [Check if Array Is Sorted and Rotated](https://leetcode.com/problems/check-if-array-is-sorted-and-rotated) | | | | 1758 | [Minimum Changes To Make Alternating Binary String](https://leetcode.com/problems/minimum-changes-to-make-alternating-binary-string) | | | diff --git a/src/MaximumNumberOfBallsInABox.java b/src/MaximumNumberOfBallsInABox.java new file mode 100644 index 0000000..abb1bd3 --- /dev/null +++ b/src/MaximumNumberOfBallsInABox.java @@ -0,0 +1,22 @@ +import java.util.HashMap; +import java.util.Map; + +public class MaximumNumberOfBallsInABox { + public int countBalls(int lowLimit, int highLimit) { + final Map boxes = new HashMap<>(); + for (int ball = lowLimit ; ball <= highLimit ; ball++) { + int boxNumber = sumOfDigits(ball); + boxes.put(boxNumber, boxes.getOrDefault(boxNumber, 0) + 1); + } + return boxes.values().stream().max(Integer::compareTo).get(); + } + + private int sumOfDigits(int n) { + int sum = 0; + while (n > 0) { + sum += n % 10; + n /= 10; + } + return sum; + } +} From 92f7dfb2bdf45090fbd0fbfea473a8c3b8c259cc Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 21 Dec 2021 15:38:36 +0100 Subject: [PATCH 381/947] solves sum of unique elements --- README.md | 2 +- src/SumOfUniqueElements.java | 37 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/SumOfUniqueElements.java diff --git a/README.md b/README.md index e64ad17..a0fb0d3 100644 --- a/README.md +++ b/README.md @@ -427,7 +427,7 @@ | 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) | | | +| 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) | | | | 1758 | [Minimum Changes To Make Alternating Binary String](https://leetcode.com/problems/minimum-changes-to-make-alternating-binary-string) | | | | 1763 | [Longest Nice Substring](https://leetcode.com/problems/longest-nice-substring) | | | diff --git a/src/SumOfUniqueElements.java b/src/SumOfUniqueElements.java new file mode 100644 index 0000000..b1e7fe3 --- /dev/null +++ b/src/SumOfUniqueElements.java @@ -0,0 +1,37 @@ +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public class SumOfUniqueElements { + public int sumOfUnique(int[] nums) { + final Set uniqueElements = uniqueElements(nums); + return sum(uniqueElements); + } + + private Set uniqueElements(int[] array) { + final Map frequencies = getFrequencies(array); + final Set set = new HashSet<>(); + for (Map.Entry entry : frequencies.entrySet()) { + if (entry.getValue() == 1) set.add(entry.getKey()); + } + return set; + } + + private Map getFrequencies(int[] array) { + final Map frequencies = new HashMap<>(); + for (int element : array) { + frequencies.put(element, frequencies.getOrDefault(element, 0) + 1); + } + return frequencies; + } + + private int sum(Collection collection) { + int sum = 0; + for (int element : collection) { + sum += element; + } + return sum; + } +} From 04d5d696af2f3b31599be73d2bdf9c67710ff01a Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 21 Dec 2021 15:51:48 +0100 Subject: [PATCH 382/947] solves check if array is sorted and rotated --- README.md | 8 ++++---- src/CheckIfArrayIsSortedAndRotated.java | 9 +++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 src/CheckIfArrayIsSortedAndRotated.java diff --git a/README.md b/README.md index a0fb0d3..a25fb95 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-328/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-328/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-352/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-352/2081-1abc9c.svg) ![problems-solved-python](https://img.shields.io/badge/Python-186/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) @@ -427,8 +427,8 @@ | 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) | | | +| 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) | | | | 1763 | [Longest Nice Substring](https://leetcode.com/problems/longest-nice-substring) | | | | 1768 | [Merge Strings Alternately](https://leetcode.com/problems/merge-strings-alternately) | | | diff --git a/src/CheckIfArrayIsSortedAndRotated.java b/src/CheckIfArrayIsSortedAndRotated.java new file mode 100644 index 0000000..dee8f41 --- /dev/null +++ b/src/CheckIfArrayIsSortedAndRotated.java @@ -0,0 +1,9 @@ +public class CheckIfArrayIsSortedAndRotated { + public boolean check(int[] array) { + int slope = 0; + for (int index = 0 ; index < array.length - 1 ; index++) { + if (array[index] > array[index + 1]) slope++; + } + return slope == 0 || (slope == 1 && array[array.length - 1] <= array[0]); + } +} From 1bc45e78bb63692a7f64a5e0b67ae1a70d5d598c Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 21 Dec 2021 15:58:41 +0100 Subject: [PATCH 383/947] solves minimum changes to make a binary string --- README.md | 2 +- ...imumChangesToMakeAlternatingBinaryString.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/MinimumChangesToMakeAlternatingBinaryString.java diff --git a/README.md b/README.md index a25fb95..fc71385 100644 --- a/README.md +++ b/README.md @@ -429,7 +429,7 @@ | 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) | | | +| 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) | | | | 1768 | [Merge Strings Alternately](https://leetcode.com/problems/merge-strings-alternately) | | | | 1773 | [Count Items Matching a Rule](https://leetcode.com/problems/count-items-matching-a-rule) | | | diff --git a/src/MinimumChangesToMakeAlternatingBinaryString.java b/src/MinimumChangesToMakeAlternatingBinaryString.java new file mode 100644 index 0000000..0f87666 --- /dev/null +++ b/src/MinimumChangesToMakeAlternatingBinaryString.java @@ -0,0 +1,16 @@ +public class MinimumChangesToMakeAlternatingBinaryString { + public int minOperations(String s) { + return Math.min( + operationsToChangeIntoAlternatingString(s, '1'), + operationsToChangeIntoAlternatingString(s, '0') + ); + } + + private int operationsToChangeIntoAlternatingString(String s, char start) { + int changes = 0, current = start - '0'; + for (int index = 0 ; index < s.length() ; index++, current ^= 1) { + if (s.charAt(index) != current + '0') changes++; + } + return changes; + } +} From ca71a8af6b89998b3dbe5ee5d2dd594a5fce4363 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 21 Dec 2021 16:39:59 +0100 Subject: [PATCH 384/947] solves longest nice substring --- README.md | 2 +- src/LongestNiceSubstring.java | 40 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/LongestNiceSubstring.java diff --git a/README.md b/README.md index fc71385..378fd69 100644 --- a/README.md +++ b/README.md @@ -430,7 +430,7 @@ | 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) | | | +| 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) | | | | 1773 | [Count Items Matching a Rule](https://leetcode.com/problems/count-items-matching-a-rule) | | | | 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) | | | diff --git a/src/LongestNiceSubstring.java b/src/LongestNiceSubstring.java new file mode 100644 index 0000000..bc124dd --- /dev/null +++ b/src/LongestNiceSubstring.java @@ -0,0 +1,40 @@ +import java.util.HashSet; +import java.util.Set; + +public class LongestNiceSubstring { + public String longestNiceSubstring(String s) { + String longestNiceSubString = ""; + Set alphabets = new HashSet<>(); + for (int i = 0 ; i < s.length() ; i++) { + for (int j = i ; j < s.length() ; j++) { + alphabets.add(s.charAt(j)); + if (containsBotLowerAndUpperCase(alphabets) && j - i + 1 > longestNiceSubString.length()) { + longestNiceSubString = s.substring(i, j + 1); + } + } + alphabets.clear(); + } + return longestNiceSubString; + } + + private boolean containsBotLowerAndUpperCase(Set alphabets) { + for (char alphabet : alphabets) { + if (!alphabets.contains(inverse(alphabet))) { + return false; + } + } + return true; + } + + private char inverse(char c) { + return Character.isLowerCase(c) ? Character.toUpperCase(c) : Character.toLowerCase(c); + } + + private Set getCharacters(String s, int start, int end) { + final Set set = new HashSet<>(); + for (int index = start ; index <= end ; index++) { + set.add(s.charAt(index)); + } + return set; + } +} From 823a7a1dfe2f076876aa4cbaec349a75529e1f4d Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 21 Dec 2021 16:45:56 +0100 Subject: [PATCH 385/947] solves merge strings alternately --- README.md | 2 +- src/MergeStringsAlternately.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/MergeStringsAlternately.java diff --git a/README.md b/README.md index 378fd69..824c4c5 100644 --- a/README.md +++ b/README.md @@ -431,7 +431,7 @@ | 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) | | | +| 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) | | | | 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) | | | | 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) | | | diff --git a/src/MergeStringsAlternately.java b/src/MergeStringsAlternately.java new file mode 100644 index 0000000..c421137 --- /dev/null +++ b/src/MergeStringsAlternately.java @@ -0,0 +1,17 @@ +public class MergeStringsAlternately { + public String mergeAlternately(String word1, String word2) { + final StringBuilder result = new StringBuilder(); + final String[] words = {word1, word2}; + int i = 0, maxLen = Math.max(word1.length(), word2.length()); + for (int[] indexes = {0, 0} ; indexes[0] < maxLen || indexes[1] < maxLen ; i ^= 1) { + result.append(get(words[i], indexes[i])); + indexes[i]++; + } + return result.toString(); + } + + private String get(String s, int index) { + if (index < s.length()) return s.charAt(index) + ""; + return ""; + } +} From 9b576d60bf2045ea7b1bb20cceb19594b564967c Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 21 Dec 2021 16:51:14 +0100 Subject: [PATCH 386/947] solves count items matching a rule --- README.md | 2 +- src/CountItemsMatchingARule.java | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/CountItemsMatchingARule.java diff --git a/README.md b/README.md index 824c4c5..3ca4fe7 100644 --- a/README.md +++ b/README.md @@ -432,7 +432,7 @@ | 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) | | | +| 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) | | | | 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) | | | | 1790 | [Check if One String Swap Can Make Strings Equal](https://leetcode.com/problems/check-if-one-string-swap-can-make-strings-equal) | | | diff --git a/src/CountItemsMatchingARule.java b/src/CountItemsMatchingARule.java new file mode 100644 index 0000000..741ad54 --- /dev/null +++ b/src/CountItemsMatchingARule.java @@ -0,0 +1,24 @@ +import java.util.List; + +public class CountItemsMatchingARule { + public int countMatches(List> items, String ruleKey, String ruleValue) { + return countMatches(items, getRuleIndex(ruleKey), ruleValue); + } + + private int countMatches(List> items, int ruleIndex, String ruleValue) { + int matches = 0; + for (List item : items) { + if (item.get(ruleIndex).equals(ruleValue)) matches++; + } + return matches; + } + + private int getRuleIndex(String key) { + return switch (key) { + case "type" -> 0; + case "color" -> 1; + case "name" -> 2; + default -> -1; + }; + } +} From adcb007e2bcec2d8ab6d38d965ae880502582187 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 21 Dec 2021 16:56:15 +0100 Subject: [PATCH 387/947] solves find nearest point that has same x ort y coordinate --- README.md | 2 +- ...restPointThatHasTheSameXOrYCoordinate.java | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/FindNearestPointThatHasTheSameXOrYCoordinate.java diff --git a/README.md b/README.md index 3ca4fe7..959f274 100644 --- a/README.md +++ b/README.md @@ -433,7 +433,7 @@ | 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) | | | +| 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) | | | | 1790 | [Check if One String Swap Can Make Strings Equal](https://leetcode.com/problems/check-if-one-string-swap-can-make-strings-equal) | | | | 1791 | [Find Center of Star Graph](https://leetcode.com/problems/find-center-of-star-graph) | | | diff --git a/src/FindNearestPointThatHasTheSameXOrYCoordinate.java b/src/FindNearestPointThatHasTheSameXOrYCoordinate.java new file mode 100644 index 0000000..77ee645 --- /dev/null +++ b/src/FindNearestPointThatHasTheSameXOrYCoordinate.java @@ -0,0 +1,20 @@ +public class FindNearestPointThatHasTheSameXOrYCoordinate { + public int nearestValidPoint(int x, int y, int[][] points) { + int minDistance = Integer.MAX_VALUE, minIndex = -1; + for (int index = 0 ; index < points.length ; index++) { + int[] point = points[index]; + if (point[0] == x || point[1] == y) { + int distance = manhattanDistance(x, y, point); + if (distance < minDistance) { + minDistance = distance; + minIndex = index; + } + } + } + return minIndex; + } + + private int manhattanDistance(int x, int y, int[] point) { + return Math.abs(x - point[0]) + Math.abs(y - point[1]); + } +} From 3728f09bd8ef84c8f01ebbd7de070983c32ada96 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 21 Dec 2021 17:02:48 +0100 Subject: [PATCH 388/947] solves check if binary string has at most one segment of ones --- README.md | 2 +- ...ckIfBinaryStringHasAtMostOneSegmentOfOnes.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/CheckIfBinaryStringHasAtMostOneSegmentOfOnes.java diff --git a/README.md b/README.md index 959f274..7c10177 100644 --- a/README.md +++ b/README.md @@ -434,7 +434,7 @@ | 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) | | | +| 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) | | | | 1791 | [Find Center of Star Graph](https://leetcode.com/problems/find-center-of-star-graph) | | | | 1796 | [Second Largest Digit in a String](https://leetcode.com/problems/second-largest-digit-in-a-string) | | | diff --git a/src/CheckIfBinaryStringHasAtMostOneSegmentOfOnes.java b/src/CheckIfBinaryStringHasAtMostOneSegmentOfOnes.java new file mode 100644 index 0000000..d8a60b6 --- /dev/null +++ b/src/CheckIfBinaryStringHasAtMostOneSegmentOfOnes.java @@ -0,0 +1,15 @@ +public class CheckIfBinaryStringHasAtMostOneSegmentOfOnes { + public boolean checkOnesSegment(String s) { + int segments = 0; + boolean isInSegment = false; + for (int index = 0 ; index < s.length() ; index++) { + if (!isInSegment && s.charAt(index) == '1') { + isInSegment = true; + segments++; + } else if (isInSegment && s.charAt(index) == '0') { + isInSegment = false; + } + } + return segments <= 1; + } +} From 522c2b1cd263fe16bbec80e4b790a9219338eed5 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 21 Dec 2021 18:15:54 +0100 Subject: [PATCH 389/947] a --- ...eckIfOneStringSwapCanMakeStringsEqual.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/CheckIfOneStringSwapCanMakeStringsEqual.java diff --git a/src/CheckIfOneStringSwapCanMakeStringsEqual.java b/src/CheckIfOneStringSwapCanMakeStringsEqual.java new file mode 100644 index 0000000..d0f1892 --- /dev/null +++ b/src/CheckIfOneStringSwapCanMakeStringsEqual.java @@ -0,0 +1,19 @@ +import java.util.LinkedList; +import java.util.Queue; + +public class CheckIfOneStringSwapCanMakeStringsEqual { + public boolean areAlmostEqual(String s1, String s2) { + if (s1.length() != s2.length()) return false; + final Queue differencesIndex = new LinkedList<>(); + for (int i = 0 ; i < s1.length() ; i++) { + if (s1.charAt(i) != s2.charAt(i)) { + differencesIndex.add(i); + } + } + return differencesIndex.size() == 0 || (differencesIndex.size() == 2 && areSameChars(s1, s2, differencesIndex)); + } + + private boolean areSameChars(String s1, String s2, Queue differenceIndexes) { + + } +} From d3b45600fee7efe96a62f8c99313256a8d1867bf Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 22 Dec 2021 15:02:35 +0100 Subject: [PATCH 390/947] solves check if one string swap can make strings equal --- README.md | 2 +- src/CheckIfOneStringSwapCanMakeStringsEqual.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7c10177..662e7b1 100644 --- a/README.md +++ b/README.md @@ -435,7 +435,7 @@ | 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) | | | +| 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) | | | | 1796 | [Second Largest Digit in a String](https://leetcode.com/problems/second-largest-digit-in-a-string) | | | | 1800 | [Maximum Ascending Subarray Sum](https://leetcode.com/problems/maximum-ascending-subarray-sum) | | | diff --git a/src/CheckIfOneStringSwapCanMakeStringsEqual.java b/src/CheckIfOneStringSwapCanMakeStringsEqual.java index d0f1892..9fc984e 100644 --- a/src/CheckIfOneStringSwapCanMakeStringsEqual.java +++ b/src/CheckIfOneStringSwapCanMakeStringsEqual.java @@ -14,6 +14,7 @@ public boolean areAlmostEqual(String s1, String s2) { } private boolean areSameChars(String s1, String s2, Queue differenceIndexes) { - + final int i = differenceIndexes.poll() , j = differenceIndexes.poll(); + return s1.charAt(i) == s2.charAt(j) && s1.charAt(j) == s2.charAt(i); } } From ddf2d37ff4430db505071bfe636f4d3d2acbc9bc Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 22 Dec 2021 15:07:37 +0100 Subject: [PATCH 391/947] solves find center of star graph --- README.md | 2 +- src/FindCenterOfStarGraph.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 src/FindCenterOfStarGraph.java diff --git a/README.md b/README.md index 662e7b1..e85e510 100644 --- a/README.md +++ b/README.md @@ -436,7 +436,7 @@ | 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) | | | +| 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) | | | | 1800 | [Maximum Ascending Subarray Sum](https://leetcode.com/problems/maximum-ascending-subarray-sum) | | | | 1805 | [Number of Different Integers in a String](https://leetcode.com/problems/number-of-different-integers-in-a-string) | | | diff --git a/src/FindCenterOfStarGraph.java b/src/FindCenterOfStarGraph.java new file mode 100644 index 0000000..2b5ff50 --- /dev/null +++ b/src/FindCenterOfStarGraph.java @@ -0,0 +1,10 @@ +public class FindCenterOfStarGraph { + public int findCenter(int[][] edges) { + return commonVertex(edges[0], edges[1]); + } + + private int commonVertex(int[] e1, int[] e2) { + if (e1[0] == e2[0] || e1[0] == e2[1]) return e1[0]; + return e1[1]; + } +} From a83b32c84a0ee8264f65e860f61288c8ad1403a4 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 22 Dec 2021 15:12:22 +0100 Subject: [PATCH 392/947] solves second largest digit in a string --- README.md | 2 +- src/SecondLargestDigitInAString.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/SecondLargestDigitInAString.java diff --git a/README.md b/README.md index e85e510..2f6b85d 100644 --- a/README.md +++ b/README.md @@ -437,7 +437,7 @@ | 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) | | | +| 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) | | | | 1805 | [Number of Different Integers in a String](https://leetcode.com/problems/number-of-different-integers-in-a-string) | | | | 1812 | [Determine Color of a Chessboard Square](https://leetcode.com/problems/determine-color-of-a-chessboard-square) | | | diff --git a/src/SecondLargestDigitInAString.java b/src/SecondLargestDigitInAString.java new file mode 100644 index 0000000..6b61a2c --- /dev/null +++ b/src/SecondLargestDigitInAString.java @@ -0,0 +1,18 @@ +public class SecondLargestDigitInAString { + public int secondHighest(String s) { + int largestDigit = -1, secondLargestDigit = -1; + for (int index = 0 ; index < s.length() ; index++) { + if (Character.isDigit(s.charAt(index))) { + int digit = s.charAt(index) - '0'; + if (digit > largestDigit) { + int temp = largestDigit; + largestDigit = digit; + secondLargestDigit = temp; + } else if (digit < largestDigit && digit > secondLargestDigit) { + secondLargestDigit = digit; + } + } + } + return secondLargestDigit; + } +} From e8e2e1180a291d7defd0a07b1996e3eea5132969 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 22 Dec 2021 15:16:05 +0100 Subject: [PATCH 393/947] solves maximum ascending sub array sum --- README.md | 2 +- src/MaximumAscendingSubArraySum.java | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 src/MaximumAscendingSubArraySum.java diff --git a/README.md b/README.md index 2f6b85d..536bf5c 100644 --- a/README.md +++ b/README.md @@ -438,7 +438,7 @@ | 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) | | | +| 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) | | | | 1812 | [Determine Color of a Chessboard Square](https://leetcode.com/problems/determine-color-of-a-chessboard-square) | | | | 1816 | [Truncate Sentence](https://leetcode.com/problems/truncate-sentence) | | | diff --git a/src/MaximumAscendingSubArraySum.java b/src/MaximumAscendingSubArraySum.java new file mode 100644 index 0000000..faf908f --- /dev/null +++ b/src/MaximumAscendingSubArraySum.java @@ -0,0 +1,12 @@ +public class MaximumAscendingSubArraySum { + public int maxAscendingSum(int[] nums) { + int maxSum = nums[0]; + for (int index = 1, current = nums[0] ; index < nums.length ; index++) { + if (nums[index] > nums[index - 1]) { + current += nums[index]; + } else current = nums[index]; + maxSum = Math.max(maxSum, current); + } + return maxSum; + } +} From 59679ca901f9e8c7ee9089ad106b2764404728e6 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 22 Dec 2021 15:31:05 +0100 Subject: [PATCH 394/947] solves number of different integers in string --- README.md | 2 +- src/NumberOfDifferentIntegersInString.java | 27 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/NumberOfDifferentIntegersInString.java diff --git a/README.md b/README.md index 536bf5c..0555b21 100644 --- a/README.md +++ b/README.md @@ -439,7 +439,7 @@ | 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) | | | +| 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) | | | | 1816 | [Truncate Sentence](https://leetcode.com/problems/truncate-sentence) | | | | 1822 | [Sign of the Product of an Array](https://leetcode.com/problems/sign-of-the-product-of-an-array) | | | diff --git a/src/NumberOfDifferentIntegersInString.java b/src/NumberOfDifferentIntegersInString.java new file mode 100644 index 0000000..62da2c1 --- /dev/null +++ b/src/NumberOfDifferentIntegersInString.java @@ -0,0 +1,27 @@ +import java.util.HashSet; +import java.util.Set; + +public class NumberOfDifferentIntegersInString { + public int numDifferentIntegers(String word) { + final Set uniqueIntegers = integersInString(word); + return uniqueIntegers.size(); + } + + private Set integersInString(String s) { + final Set integers = new HashSet<>(); + boolean inNumber = false; + StringBuilder current = new StringBuilder(); + for (int index = 0 ; index < s.length() ; index++) { + if (Character.isDigit(s.charAt(index))) { + if (!inNumber) inNumber = true; + current.append(s.charAt(index) == '0' && current.length() == 0 ? "" : s.charAt(index)); + if (index == s.length() - 1) integers.add(current.toString()); + } else if (inNumber) { + inNumber = false; + integers.add(current.toString()); + current = new StringBuilder(); + } + } + return integers; + } +} From 9bc28dd169b74fda7f318d278acc98191b75cb1a Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 22 Dec 2021 15:35:22 +0100 Subject: [PATCH 395/947] solves determine color f chessboard --- README.md | 2 +- src/DetermineColorOfChessboardSquare.java | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 src/DetermineColorOfChessboardSquare.java diff --git a/README.md b/README.md index 0555b21..f17681a 100644 --- a/README.md +++ b/README.md @@ -440,7 +440,7 @@ | 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) | | | +| 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) | | | | 1822 | [Sign of the Product of an Array](https://leetcode.com/problems/sign-of-the-product-of-an-array) | | | | 1826 | [Faulty Sensor](https://leetcode.com/problems/faulty-sensor) | | | diff --git a/src/DetermineColorOfChessboardSquare.java b/src/DetermineColorOfChessboardSquare.java new file mode 100644 index 0000000..e6b6735 --- /dev/null +++ b/src/DetermineColorOfChessboardSquare.java @@ -0,0 +1,5 @@ +public class DetermineColorOfChessboardSquare { + public boolean squareIsWhite(String coordinates) { + return ((coordinates.charAt(0) - 'a') + (coordinates.charAt(1) - '1')) % 2 == 1; + } +} From 6c4124b16080b1fc4b40754bf0f0aec87f585a0d Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 22 Dec 2021 15:44:10 +0100 Subject: [PATCH 396/947] solves truncate sentences --- README.md | 2 +- src/TruncateSentences.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/TruncateSentences.java diff --git a/README.md b/README.md index f17681a..eaf68ac 100644 --- a/README.md +++ b/README.md @@ -441,7 +441,7 @@ | 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) | | | +| 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) | | | | 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) | | | diff --git a/src/TruncateSentences.java b/src/TruncateSentences.java new file mode 100644 index 0000000..1929cac --- /dev/null +++ b/src/TruncateSentences.java @@ -0,0 +1,14 @@ +public class TruncateSentences { + public String truncateSentence(String s, int k) { + final StringBuilder result = new StringBuilder(); + for (int index = 0, words = 0 ; index < s.length() && words < k ; index++) { + if (s.charAt(index) != ' ') { + result.append(s.charAt(index)); + } else { + words++; + result.append(words < k ? ' ' : ""); + } + } + return result.toString(); + } +} From 86bf3e09656ae46073225d5378d7140546f8a259 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 22 Dec 2021 15:46:51 +0100 Subject: [PATCH 397/947] solves sign of the product of an array --- README.md | 2 +- src/SignOfTheProductOfAnArray.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/SignOfTheProductOfAnArray.java diff --git a/README.md b/README.md index eaf68ac..f88de9c 100644 --- a/README.md +++ b/README.md @@ -442,7 +442,7 @@ | 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) | | | +| 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) | | | | 1832 | [Check if the Sentence Is Pangram](https://leetcode.com/problems/check-if-the-sentence-is-pangram) | | | diff --git a/src/SignOfTheProductOfAnArray.java b/src/SignOfTheProductOfAnArray.java new file mode 100644 index 0000000..cc03744 --- /dev/null +++ b/src/SignOfTheProductOfAnArray.java @@ -0,0 +1,14 @@ +public class SignOfTheProductOfAnArray { + public int arraySign(int[] nums) { + int sign = 1; + for (int element : nums) { + sign *= signum(element); + } + return sign; + } + + private int signum(int x) { + if (x == 0) return 0; + return x > 0 ? 1 : -1; + } +} From ba6e544b7f19d83e20983851dfc71f9ca264387c Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 22 Dec 2021 15:47:26 +0100 Subject: [PATCH 398/947] solves sign of the product of an array --- src/SignOfTheProductOfAnArray.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/SignOfTheProductOfAnArray.java b/src/SignOfTheProductOfAnArray.java index cc03744..5702861 100644 --- a/src/SignOfTheProductOfAnArray.java +++ b/src/SignOfTheProductOfAnArray.java @@ -1,3 +1,7 @@ +// https://leetcode.com/problems/sign-of-the-product-of-an-array +// T: O(N) +// S: O(1) + public class SignOfTheProductOfAnArray { public int arraySign(int[] nums) { int sign = 1; From b40f3ba6397ac49214bf4caa52394e07d50b98a2 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 22 Dec 2021 15:48:00 +0100 Subject: [PATCH 399/947] solves sign of the product of an array --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f88de9c..e392a3c 100644 --- a/README.md +++ b/README.md @@ -443,7 +443,7 @@ | 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) | | | +| 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) | | | | 1832 | [Check if the Sentence Is Pangram](https://leetcode.com/problems/check-if-the-sentence-is-pangram) | | | | 1837 | [Sum of Digits in Base K](https://leetcode.com/problems/sum-of-digits-in-base-k) | | | From e15033322dbf621acc751cec3b44deea2405d781 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 22 Dec 2021 15:53:07 +0100 Subject: [PATCH 400/947] solves minimum operations to make the array increasing --- README.md | 2 +- src/MinimumOperationsToMakeTheArrayIncreasing.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/MinimumOperationsToMakeTheArrayIncreasing.java diff --git a/README.md b/README.md index e392a3c..eb32af4 100644 --- a/README.md +++ b/README.md @@ -444,7 +444,7 @@ | 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) | | | +| 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) | | | | 1837 | [Sum of Digits in Base K](https://leetcode.com/problems/sum-of-digits-in-base-k) | | | | 1844 | [Replace All Digits with Characters](https://leetcode.com/problems/replace-all-digits-with-characters) | | | diff --git a/src/MinimumOperationsToMakeTheArrayIncreasing.java b/src/MinimumOperationsToMakeTheArrayIncreasing.java new file mode 100644 index 0000000..6ead1a6 --- /dev/null +++ b/src/MinimumOperationsToMakeTheArrayIncreasing.java @@ -0,0 +1,14 @@ +// https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing +// T: O(N) +// S: O(1) + +public class MinimumOperationsToMakeTheArrayIncreasing { + public int minOperations(int[] nums) { + int operations = 0; + for (int index = 1, current = nums[0] ; index < nums.length ; index++) { + operations += Math.max(0, current - nums[index] + 1); + current = Math.max(current + 1, nums[index]); + } + return operations; + } +} From 57fbe4390b841521ed2614586924844e55dd9bdf Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 22 Dec 2021 15:56:24 +0100 Subject: [PATCH 401/947] solves check if sentence is a pangram --- README.md | 2 +- src/CheckIfSentenceIsPangram.java | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 src/CheckIfSentenceIsPangram.java diff --git a/README.md b/README.md index eb32af4..91113c3 100644 --- a/README.md +++ b/README.md @@ -445,7 +445,7 @@ | 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) | | | +| 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) | | | | 1844 | [Replace All Digits with Characters](https://leetcode.com/problems/replace-all-digits-with-characters) | | | | 1848 | [Minimum Distance to the Target Element](https://leetcode.com/problems/minimum-distance-to-the-target-element) | | | diff --git a/src/CheckIfSentenceIsPangram.java b/src/CheckIfSentenceIsPangram.java new file mode 100644 index 0000000..bddc470 --- /dev/null +++ b/src/CheckIfSentenceIsPangram.java @@ -0,0 +1,21 @@ +// https://leetcode.com/problems/check-if-the-sentence-is-pangram +// T: O(|s|) +// S: O(1) + +import java.util.HashSet; +import java.util.Set; + +public class CheckIfSentenceIsPangram { + public boolean checkIfPangram(String sentence) { + final Set letters = getLetters(sentence); + return letters.size() == 26; + } + + private Set getLetters(String s) { + final Set letters = new HashSet<>(); + for (int index = 0 ; index < s.length() ; index++) { + letters.add(s.charAt(index)); + } + return letters; + } +} From 514bfc1822def22341e852f0c1061a155de61ab6 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 22 Dec 2021 22:33:56 +0100 Subject: [PATCH 402/947] solves sum of digits in base k --- README.md | 2 +- src/SumOfDigitsInBaseK.java | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 src/SumOfDigitsInBaseK.java diff --git a/README.md b/README.md index 91113c3..3d59e0b 100644 --- a/README.md +++ b/README.md @@ -446,7 +446,7 @@ | 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) | | | +| 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) | | | | 1848 | [Minimum Distance to the Target Element](https://leetcode.com/problems/minimum-distance-to-the-target-element) | | | | 1854 | [Maximum Population Year](https://leetcode.com/problems/maximum-population-year) | | | diff --git a/src/SumOfDigitsInBaseK.java b/src/SumOfDigitsInBaseK.java new file mode 100644 index 0000000..eefa9d0 --- /dev/null +++ b/src/SumOfDigitsInBaseK.java @@ -0,0 +1,23 @@ +public class SumOfDigitsInBaseK { + public int sumBase(int n, int k) { + return sumOfDigits(toBaseK(n, k)); + } + + private int sumOfDigits(StringBuilder number) { + int sum = 0; + for (int index = 0 ; index < number.length() ; index++) { + sum += number.charAt(index) - '0'; + } + return sum; + } + + private StringBuilder toBaseK(int n, int k) { + if (n == 0) return new StringBuilder("0"); + final StringBuilder result = new StringBuilder(); + while (n > 0) { + result.append(n % k); + n /= k; + } + return result.reverse(); + } +} From 12285b178cb2fbf37bcc670d021cd1d75faa0619 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 22 Dec 2021 22:44:22 +0100 Subject: [PATCH 403/947] solvesreplace all digitswith characters --- README.md | 2 +- src/ReplaceAllDigitsWithCharacters.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/ReplaceAllDigitsWithCharacters.java diff --git a/README.md b/README.md index 3d59e0b..417c6a8 100644 --- a/README.md +++ b/README.md @@ -447,7 +447,7 @@ | 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) | | | +| 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) | | | | 1854 | [Maximum Population Year](https://leetcode.com/problems/maximum-population-year) | | | | 1859 | [Sorting the Sentence](https://leetcode.com/problems/sorting-the-sentence) | | | diff --git a/src/ReplaceAllDigitsWithCharacters.java b/src/ReplaceAllDigitsWithCharacters.java new file mode 100644 index 0000000..f62239b --- /dev/null +++ b/src/ReplaceAllDigitsWithCharacters.java @@ -0,0 +1,16 @@ +public class ReplaceAllDigitsWithCharacters { + public String replaceDigits(String s) { + final StringBuilder result = new StringBuilder(); + for (int i = 1 ; i < s.length() ; i += 2) { + result.append(s.charAt(i - 1)).append(shift(s.charAt(i - 1), s.charAt(i) - '0')); + } + if (s.length() % 2 == 1) { + result.append(s.charAt(s.length() - 1)); + } + return result.toString(); + } + + private char shift(char c, int shiftAmount) { + return (char) (c + shiftAmount); + } +} From b1a51438df569ac4c673c064754db7a189dadf27 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 22 Dec 2021 23:07:44 +0100 Subject: [PATCH 404/947] solves minimum distance to the target element --- README.md | 2 +- src/MinimumDistanceToTheTargetElement.java | 34 ++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/MinimumDistanceToTheTargetElement.java diff --git a/README.md b/README.md index 417c6a8..24a3292 100644 --- a/README.md +++ b/README.md @@ -448,7 +448,7 @@ | 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) | | | +| 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) | | | | 1859 | [Sorting the Sentence](https://leetcode.com/problems/sorting-the-sentence) | | | | 1863 | [Sum of All Subset XOR Totals](https://leetcode.com/problems/sum-of-all-subset-xor-totals) | | | diff --git a/src/MinimumDistanceToTheTargetElement.java b/src/MinimumDistanceToTheTargetElement.java new file mode 100644 index 0000000..7d58d16 --- /dev/null +++ b/src/MinimumDistanceToTheTargetElement.java @@ -0,0 +1,34 @@ +import java.util.ArrayList; +import java.util.List; + +public class MinimumDistanceToTheTargetElement { + public int getMinDistance(int[] nums, int target, int start) { + final List indexes = getIndexes(nums, target); + final int position = search(indexes, start); + if (position >= indexes.size()) return start - indexes.get(position - 1); + if (indexes.get(position) == start) return 0; + if (position == 0) return indexes.get(position) - start; + return Math.min(indexes.get(position) - start, start - indexes.get(position - 1)); + } + + private List getIndexes(int[] array, int target){ + final List indexes = new ArrayList<>(); + for (int index = 0 ; index < array.length ; index++) { + if (array[index] == target) { + indexes.add(index); + } + } + return indexes; + } + + private int search(List array, int x) { + int left = 0, right = array.size() - 1, middle; + while (left <= right) { + middle = left + (right - left) / 2; + if (array.get(middle) == x) return middle; + else if (array.get(middle) > x) right = middle - 1; + else left = middle + 1; + } + return left; + } +} From 0088d0284a0048d536e16b78b6849773f2b73490 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 22 Dec 2021 23:14:30 +0100 Subject: [PATCH 405/947] solves maximum population year --- README.md | 2 +- src/MaximumPopulationYear.java | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/MaximumPopulationYear.java diff --git a/README.md b/README.md index 24a3292..ee788d0 100644 --- a/README.md +++ b/README.md @@ -449,7 +449,7 @@ | 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) | | | +| 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) | | | | 1863 | [Sum of All Subset XOR Totals](https://leetcode.com/problems/sum-of-all-subset-xor-totals) | | | | 1869 | [Longer Contiguous Segments of Ones than Zeros](https://leetcode.com/problems/longer-contiguous-segments-of-ones-than-zeros) | | | diff --git a/src/MaximumPopulationYear.java b/src/MaximumPopulationYear.java new file mode 100644 index 0000000..68e7623 --- /dev/null +++ b/src/MaximumPopulationYear.java @@ -0,0 +1,22 @@ +public class MaximumPopulationYear { + public int maximumPopulation(int[][] logs) { + final int[] population = new int[101]; + for (int[] log : logs) { + population[log[0] - 1950]++; + population[log[1] - 1950]--; + } + return maxIndexOfRunningSum(population) + 1950; + } + + private int maxIndexOfRunningSum(int[] array) { + int maxIndex = 0; + for (int index = 1, current = array[0], maxVal = current ; index < array.length ; index++) { + current += array[index]; + if (current > maxVal) { + maxVal = current; + maxIndex = index; + } + } + return maxIndex; + } +} From b528a876b5df86adca025af3476882d446f092b2 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 22 Dec 2021 23:33:28 +0100 Subject: [PATCH 406/947] solves sorting the sentence --- README.md | 2 +- src/MaximumPopulationYear.java | 4 ++++ src/SortingTheSentence.java | 43 ++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 src/SortingTheSentence.java diff --git a/README.md b/README.md index ee788d0..36793e9 100644 --- a/README.md +++ b/README.md @@ -450,7 +450,7 @@ | 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) | | | +| 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) | | | | 1869 | [Longer Contiguous Segments of Ones than Zeros](https://leetcode.com/problems/longer-contiguous-segments-of-ones-than-zeros) | | | | 1876 | [Substrings of Size Three with Distinct Characters](https://leetcode.com/problems/substrings-of-size-three-with-distinct-characters) | | | diff --git a/src/MaximumPopulationYear.java b/src/MaximumPopulationYear.java index 68e7623..977d1b0 100644 --- a/src/MaximumPopulationYear.java +++ b/src/MaximumPopulationYear.java @@ -1,3 +1,7 @@ +// https://leetcode.com/problems/maximum-population-year +// T: O(N) +// S: O(1) + public class MaximumPopulationYear { public int maximumPopulation(int[][] logs) { final int[] population = new int[101]; diff --git a/src/SortingTheSentence.java b/src/SortingTheSentence.java new file mode 100644 index 0000000..672e715 --- /dev/null +++ b/src/SortingTheSentence.java @@ -0,0 +1,43 @@ +import java.util.ArrayList; +import java.util.List; + +public class SortingTheSentence { + public String sortSentence(String s) { + final List words = getWords(s); + words.sort(Word::compareTo); + final StringBuilder result = new StringBuilder(); + for (Word word : words) { + result.append(word.val).append(' '); + } + return result.deleteCharAt(result.length() - 1).toString(); + } + + private List getWords(String s) { + StringBuilder word = new StringBuilder(); + final List words = new ArrayList<>(); + for (int index = 0 ; index < s.length() ; index++) { + if (Character.isDigit(s.charAt(index))){ + words.add(new Word(word.toString(), s.charAt(index) - '0')); + word = new StringBuilder(); + } else if (s.charAt(index) != ' '){ + word.append(s.charAt(index)); + } + } + return words; + } + + private static final class Word implements Comparable { + private final String val; + private final int position; + + private Word(String val, int position) { + this.val = val; + this.position = position; + } + + @Override + public int compareTo(Word o) { + return Integer.compare(this.position, o.position); + } + } +} From 004e733abcd40b997b9ada4716d4201022c5b8ca Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 23 Dec 2021 00:04:55 +0100 Subject: [PATCH 407/947] solves sum of all subset xor sums --- README.md | 2 +- src/SumOfAllSubsetXORTotals.java | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/SumOfAllSubsetXORTotals.java diff --git a/README.md b/README.md index 36793e9..86e01af 100644 --- a/README.md +++ b/README.md @@ -451,7 +451,7 @@ | 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) | | | +| 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) | | | | 1876 | [Substrings of Size Three with Distinct Characters](https://leetcode.com/problems/substrings-of-size-three-with-distinct-characters) | | | | 1880 | [Check if Word Equals Summation of Two Words](https://leetcode.com/problems/check-if-word-equals-summation-of-two-words) | | | diff --git a/src/SumOfAllSubsetXORTotals.java b/src/SumOfAllSubsetXORTotals.java new file mode 100644 index 0000000..2043d75 --- /dev/null +++ b/src/SumOfAllSubsetXORTotals.java @@ -0,0 +1,13 @@ +// https://leetcode.com/problems/sum-of-all-subset-xor-totals +// T: O(N) +// S: O(1) + +public class SumOfAllSubsetXORTotals { + public int subsetXORSum(int[] nums) { + int or = 0; + for (int element : nums) { + or |= element; + } + return or * (1 << nums.length - 1); + } +} From 7be03ee33d428229d7c48905af502a84dc2b0b44 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 23 Dec 2021 00:09:23 +0100 Subject: [PATCH 408/947] solveslonger contiguous segment of ones than zeros --- README.md | 2 +- ...ongerContiguousSegmentOfOnesThanZeros.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/LongerContiguousSegmentOfOnesThanZeros.java diff --git a/README.md b/README.md index 86e01af..3540840 100644 --- a/README.md +++ b/README.md @@ -452,7 +452,7 @@ | 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) | | | +| 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) | | | | 1880 | [Check if Word Equals Summation of Two Words](https://leetcode.com/problems/check-if-word-equals-summation-of-two-words) | | | | 1886 | [Determine Whether Matrix Can Be Obtained By Rotation](https://leetcode.com/problems/determine-whether-matrix-can-be-obtained-by-rotation) | | | diff --git a/src/LongerContiguousSegmentOfOnesThanZeros.java b/src/LongerContiguousSegmentOfOnesThanZeros.java new file mode 100644 index 0000000..6feaec4 --- /dev/null +++ b/src/LongerContiguousSegmentOfOnesThanZeros.java @@ -0,0 +1,19 @@ +// https://leetcode.com/problems/longer-contiguous-segments-of-ones-than-zeros +// T: O(N) +// S: O(1) + +public class LongerContiguousSegmentOfOnesThanZeros { + public boolean checkZeroOnes(String s) { + return lengthContiguousSegment(s, '1') > lengthContiguousSegment(s, '0'); + } + + private int lengthContiguousSegment(String s, char c) { + int maxLen = 0; + for (int i = 0, current = 0 ; i < s.length() ; i++) { + if (s.charAt(i) == c) current++; + else current = 0; + maxLen = Math.max(maxLen, current); + } + return maxLen; + } +} From cf0b4cda14d01b955e2007bed6de85efa8f7a88e Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 23 Dec 2021 00:20:01 +0100 Subject: [PATCH 409/947] solves substrings with distinct characters --- README.md | 2 +- ...ingsOfSizeThreeWithDistinctCharacters.java | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/SubstringsOfSizeThreeWithDistinctCharacters.java diff --git a/README.md b/README.md index 3540840..dfc182a 100644 --- a/README.md +++ b/README.md @@ -453,7 +453,7 @@ | 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) | | | +| 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) | | | | 1886 | [Determine Whether Matrix Can Be Obtained By Rotation](https://leetcode.com/problems/determine-whether-matrix-can-be-obtained-by-rotation) | | | | 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) | | | diff --git a/src/SubstringsOfSizeThreeWithDistinctCharacters.java b/src/SubstringsOfSizeThreeWithDistinctCharacters.java new file mode 100644 index 0000000..30e2da5 --- /dev/null +++ b/src/SubstringsOfSizeThreeWithDistinctCharacters.java @@ -0,0 +1,34 @@ +// https://leetcode.com/problems/substrings-of-size-three-with-distinct-characters +// T: O(N) +// S: O(1) + +import java.util.HashMap; +import java.util.Map; + +public class SubstringsOfSizeThreeWithDistinctCharacters { + public int countGoodSubstrings(String s) { + if (s.length() < 3) return 0; + final Map frequency = getFrequency(s, 3); + int goodSubStrings = 0; + if (frequency.size() == 3) goodSubStrings++; + for (int index = 3 ; index < s.length() ; index++) { + remove(frequency, s.charAt(index - 3)); + frequency.put(s.charAt(index), frequency.getOrDefault(s.charAt(index), 0) + 1); + if (frequency.size() == 3) goodSubStrings++; + } + return goodSubStrings; + } + + private Map getFrequency(String s, int upto) { + final Map frequencies = new HashMap<>(); + for (int i = 0 ; i < upto ; i++) { + frequencies.put(s.charAt(i), frequencies.getOrDefault(s.charAt(i), 0) + 1); + } + return frequencies; + } + + private void remove(Map frequencies, char c) { + if (frequencies.get(c) == 1) frequencies.remove(c); + else frequencies.put(c, frequencies.get(c) - 1); + } +} From 6f077ec362cb0d0dcd26b580230f34cbe22e4b02 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 23 Dec 2021 00:25:16 +0100 Subject: [PATCH 410/947] solvescheck if words equal summation of two words --- README.md | 2 +- src/CheckIfWordEqualsSummationOfTwoWords.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/CheckIfWordEqualsSummationOfTwoWords.java diff --git a/README.md b/README.md index dfc182a..c27eaf2 100644 --- a/README.md +++ b/README.md @@ -454,7 +454,7 @@ | 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) | | | +| 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) | | | | 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) | | | | 1897 | [Redistribute Characters to Make All Strings Equal](https://leetcode.com/problems/redistribute-characters-to-make-all-strings-equal) | | | diff --git a/src/CheckIfWordEqualsSummationOfTwoWords.java b/src/CheckIfWordEqualsSummationOfTwoWords.java new file mode 100644 index 0000000..bd381f2 --- /dev/null +++ b/src/CheckIfWordEqualsSummationOfTwoWords.java @@ -0,0 +1,18 @@ +// https://leetcode.com/problems/check-if-word-equals-summation-of-two-words +// T: O(|f1| + |f2| + |f3|) +// S: O(1) + +public class CheckIfWordEqualsSummationOfTwoWords { + public boolean isSumEqual(String firstWord, String secondWord, String targetWord) { + return toNumber(firstWord) + toNumber(secondWord) == toNumber(targetWord); + } + + private int toNumber(String s) { + int sum = 0; + for (int i = 0 ; i < s.length() ; i++) { + sum *= 10; + sum += s.charAt(i) - 'a'; + } + return sum; + } +} From bd786e7b540f0529389e4d0d7e95515780ce106a Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 23 Dec 2021 17:56:00 +0100 Subject: [PATCH 411/947] solves git add. --- README.md | 4 ++-- ...mineWhetherMatrixCanBeObtainedByRotation.java | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 src/DetermineWhetherMatrixCanBeObtainedByRotation.java diff --git a/README.md b/README.md index c27eaf2..dbd39ca 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-352/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-352/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-378/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-378/2081-1abc9c.svg) ![problems-solved-python](https://img.shields.io/badge/Python-186/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/DetermineWhetherMatrixCanBeObtainedByRotation.java b/src/DetermineWhetherMatrixCanBeObtainedByRotation.java new file mode 100644 index 0000000..0805d09 --- /dev/null +++ b/src/DetermineWhetherMatrixCanBeObtainedByRotation.java @@ -0,0 +1,16 @@ +public class DetermineWhetherMatrixCanBeObtainedByRotation { + public boolean findRotation(int[][] mat, int[][] target) { + boolean[] c = new boolean[4]; + int n = mat.length; + for(int i = 0 ; i < n ; i++) { + for(int j = 0 ; j < n ; j++) { + if (mat[i][j] != target[i][j]) c[0]=false; + if (mat[i][j] != target[n-j-1][i]) c[1]=false; + if (mat[i][j] != target[n-i-1][n-j-1]) c[2]=false; + if (mat[i][j] != target[j][n-i-1]) c[3]=false; + } + } + + return c[0] || c[1] || c[2] || c[3]; + } +} From a483237bbdcf4158c936121b236b81467d09bea1 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 23 Dec 2021 17:56:22 +0100 Subject: [PATCH 412/947] solves determine whether matrix can be obtained by rotation --- README.md | 2 +- src/DetermineWhetherMatrixCanBeObtainedByRotation.java | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index dbd39ca..98f1bf3 100644 --- a/README.md +++ b/README.md @@ -455,7 +455,7 @@ | 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) | | | +| 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) | | | | 1897 | [Redistribute Characters to Make All Strings Equal](https://leetcode.com/problems/redistribute-characters-to-make-all-strings-equal) | | | | 1903 | [Largest Odd Number in String](https://leetcode.com/problems/largest-odd-number-in-string) | | | diff --git a/src/DetermineWhetherMatrixCanBeObtainedByRotation.java b/src/DetermineWhetherMatrixCanBeObtainedByRotation.java index 0805d09..4844d88 100644 --- a/src/DetermineWhetherMatrixCanBeObtainedByRotation.java +++ b/src/DetermineWhetherMatrixCanBeObtainedByRotation.java @@ -1,6 +1,6 @@ public class DetermineWhetherMatrixCanBeObtainedByRotation { public boolean findRotation(int[][] mat, int[][] target) { - boolean[] c = new boolean[4]; + boolean[] c = getTrueArray(4); int n = mat.length; for(int i = 0 ; i < n ; i++) { for(int j = 0 ; j < n ; j++) { @@ -13,4 +13,12 @@ public boolean findRotation(int[][] mat, int[][] target) { return c[0] || c[1] || c[2] || c[3]; } + + private boolean[] getTrueArray(int size) { + boolean[] array = new boolean[size]; + for (int i = 0 ; i < size ; i++) { + array[i] = true; + } + return array; + } } From c25ffb1d9397be485ce176e9995398856b3a076c Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 23 Dec 2021 18:17:20 +0100 Subject: [PATCH 413/947] solves check if all the integers in a range are covered --- README.md | 2 +- ...eckIfAllTheIntegersInARangeAreCovered.java | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/CheckIfAllTheIntegersInARangeAreCovered.java diff --git a/README.md b/README.md index 98f1bf3..5fc0ce7 100644 --- a/README.md +++ b/README.md @@ -456,7 +456,7 @@ | 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) | | | +| 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) | | | | 1903 | [Largest Odd Number in String](https://leetcode.com/problems/largest-odd-number-in-string) | | | | 1909 | [Remove One Element to Make the Array Strictly Increasing](https://leetcode.com/problems/remove-one-element-to-make-the-array-strictly-increasing) | | | diff --git a/src/CheckIfAllTheIntegersInARangeAreCovered.java b/src/CheckIfAllTheIntegersInARangeAreCovered.java new file mode 100644 index 0000000..91669e3 --- /dev/null +++ b/src/CheckIfAllTheIntegersInARangeAreCovered.java @@ -0,0 +1,27 @@ +// https://leetcode.com/problems/check-if-all-the-integers-in-a-range-are-covered +// T:O(|ranges| + |right - left|) +// S: O(1) + +public class CheckIfAllTheIntegersInARangeAreCovered { + public boolean isCovered(int[][] ranges, int left, int right) { + final int[] covered = new int[51]; + for (int[] range : ranges) { + covered[range[0] - 1]++; + covered[range[1]]--; + } + final int[] isCovered = runningSum(covered); + for (int i = left ; i <= right ; i++) { + if(isCovered[i - 1] <= 0) return false; + } + return true; + } + + private static int[] runningSum(int[] array) { + final int[] sum = new int[array.length]; + sum[0] = array[0]; + for (int i = 1 ; i < array.length ; i++) { + sum[i] = sum[i - 1] + array[i]; + } + return sum; + } +} From 174ecf4220798b2cc568a6c55701b7b96ff20fb5 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 23 Dec 2021 18:23:03 +0100 Subject: [PATCH 414/947] solves redistribute characters to make all strings equal --- README.md | 2 +- ...ributeCharactersToMakeAllStringsEqual.java | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/RedistributeCharactersToMakeAllStringsEqual.java diff --git a/README.md b/README.md index 5fc0ce7..b6c138c 100644 --- a/README.md +++ b/README.md @@ -457,7 +457,7 @@ | 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) | | | +| 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) | | | | 1909 | [Remove One Element to Make the Array Strictly Increasing](https://leetcode.com/problems/remove-one-element-to-make-the-array-strictly-increasing) | | | | 1913 | [Maximum Product Difference Between Two Pairs](https://leetcode.com/problems/maximum-product-difference-between-two-pairs) | | | diff --git a/src/RedistributeCharactersToMakeAllStringsEqual.java b/src/RedistributeCharactersToMakeAllStringsEqual.java new file mode 100644 index 0000000..be79b02 --- /dev/null +++ b/src/RedistributeCharactersToMakeAllStringsEqual.java @@ -0,0 +1,27 @@ +// https://leetcode.com/problems/redistribute-characters-to-make-all-strings-equal +// T: O(|words| * |word|) +// S: O(1) + +import java.util.HashMap; +import java.util.Map; + +public class RedistributeCharactersToMakeAllStringsEqual { + public boolean makeEqual(String[] words) { + if (words.length == 1) return true; + final Map frequencies = getCharacterFrequencies(words); + for (int frequency : frequencies.values()) { + if (frequency % words.length != 0) return false; + } + return true; + } + + private Map getCharacterFrequencies(String[] words) { + final Map frequencies = new HashMap<>(); + for (String word : words) { + for (int i = 0 ; i < word.length() ; i++) { + frequencies.put(word.charAt(i), frequencies.getOrDefault(word.charAt(i), 0) + 1); + } + } + return frequencies; + } +} From 77f055abe1a8af11289b62c44f562481517749d4 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 23 Dec 2021 18:27:45 +0100 Subject: [PATCH 415/947] solves largest odd number in a string --- README.md | 2 +- src/LargestOddNumberInString.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/LargestOddNumberInString.java diff --git a/README.md b/README.md index b6c138c..6e6d16a 100644 --- a/README.md +++ b/README.md @@ -458,7 +458,7 @@ | 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) | | | +| 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) | | | | 1913 | [Maximum Product Difference Between Two Pairs](https://leetcode.com/problems/maximum-product-difference-between-two-pairs) | | | | 1920 | [Build Array from Permutation](https://leetcode.com/problems/build-array-from-permutation) | | | diff --git a/src/LargestOddNumberInString.java b/src/LargestOddNumberInString.java new file mode 100644 index 0000000..daab62c --- /dev/null +++ b/src/LargestOddNumberInString.java @@ -0,0 +1,18 @@ +// https://leetcode.com/problems/largest-odd-number-in-string +// T: O(|num|) +// S: O(num) + +public class LargestOddNumberInString { + public String largestOddNumber(String num) { + for (int i = num.length() - 1 ; i >= 0 ; i--) { + if (isOddDigit(num.charAt(i))) { + return num.substring(0, i + 1); + } + } + return ""; + } + + private boolean isOddDigit(char digit) { + return (digit - '0') % 2 == 1; + } +} From 32195d980126667c9041cc36caa0e82ae2e1c6e8 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 23 Dec 2021 18:59:51 +0100 Subject: [PATCH 416/947] solves remove one element to make the array strictly increasing --- README.md | 2 +- ...ementToMakeTheArrayStrictlyIncreasing.java | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/RemoveOneElementToMakeTheArrayStrictlyIncreasing.java diff --git a/README.md b/README.md index 6e6d16a..f88896c 100644 --- a/README.md +++ b/README.md @@ -459,7 +459,7 @@ | 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) | | | +| 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) | | | | 1920 | [Build Array from Permutation](https://leetcode.com/problems/build-array-from-permutation) | | | | 1925 | [Count Square Sum Triples](https://leetcode.com/problems/count-square-sum-triples) | | | diff --git a/src/RemoveOneElementToMakeTheArrayStrictlyIncreasing.java b/src/RemoveOneElementToMakeTheArrayStrictlyIncreasing.java new file mode 100644 index 0000000..167bc01 --- /dev/null +++ b/src/RemoveOneElementToMakeTheArrayStrictlyIncreasing.java @@ -0,0 +1,27 @@ +public class RemoveOneElementToMakeTheArrayStrictlyIncreasing { + public boolean canBeIncreasing(int[] array) { + if (array[0] >= array[1]) { + if (array.length == 2) return true; + return array[2] > array[1] && isStrictlyIncreasing(array, 3); + } + boolean firstAnomaly = true; + for (int index = 2 ; index < array.length ; index++) { + if (array[index] <= array[index - 1]) { + if (!firstAnomaly) return false; + firstAnomaly = false; + if (index == array.length - 1) return true; + if (array[index + 1] > array[index - 1]) continue; + if (array[index + 1] > array[index] && array[index] > array[index - 2]) continue; + return false; + } + } + return true; + } + + private boolean isStrictlyIncreasing(int[] array, int start) { + for (int i = start ; i < array.length ; i++) { + if (array[i] <= array[i - 1]) return false; + } + return true; + } +} From 29786c9f25c8b388b0407da1d182e2b1b5d52e98 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 23 Dec 2021 19:15:44 +0100 Subject: [PATCH 417/947] solves maximum product difference between two pairs --- README.md | 2 +- ...ximumProductDifferenceBetweenTwoPairs.java | 49 +++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 src/MaximumProductDifferenceBetweenTwoPairs.java diff --git a/README.md b/README.md index f88896c..b4837be 100644 --- a/README.md +++ b/README.md @@ -460,7 +460,7 @@ | 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) | | | +| 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) | | | | 1925 | [Count Square Sum Triples](https://leetcode.com/problems/count-square-sum-triples) | | | | 1929 | [Concatenation of Array](https://leetcode.com/problems/concatenation-of-array) | | | diff --git a/src/MaximumProductDifferenceBetweenTwoPairs.java b/src/MaximumProductDifferenceBetweenTwoPairs.java new file mode 100644 index 0000000..1637159 --- /dev/null +++ b/src/MaximumProductDifferenceBetweenTwoPairs.java @@ -0,0 +1,49 @@ +// https://leetcode.com/problems/maximum-product-difference-between-two-pairs +// T: O(N) +// S: O(1) + +public class MaximumProductDifferenceBetweenTwoPairs { + public int maxProductDifference(int[] nums) { + Pair largest = getLargestAndSecondLargest(nums); + Pair smallest = getSmallestAndSecondSmallest(nums); + return largest.a * largest.b - smallest.a * smallest.b; + } + + private Pair getLargestAndSecondLargest(int[] array) { + int largest = Integer.MIN_VALUE, secondLargest = Integer.MIN_VALUE; + for (int element : array) { + if (element > largest) { + int temp = largest; + largest = element; + secondLargest = temp; + } else if (element > secondLargest) { + secondLargest= element; + } + } + return new Pair(largest, secondLargest); + } + + private Pair getSmallestAndSecondSmallest(int[] array) { + int smallest = Integer.MAX_VALUE, secondSmallest = Integer.MAX_VALUE; + for (int element : array) { + if (element < smallest) { + int temp = smallest; + smallest = element; + secondSmallest = temp; + } else if (element < secondSmallest) { + secondSmallest = element; + } + } + return new Pair(smallest, secondSmallest); + } + + private static final class Pair { + private final int a; + private final int b; + + private Pair(int a, int b) { + this.a = a; + this.b = b; + } + } +} From 48e2cc4d5f3cdbc60e5e92b041ce26a9ea14173b Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 23 Dec 2021 19:18:42 +0100 Subject: [PATCH 418/947] solves build array from permutation --- README.md | 2 +- src/BuildArrayFromPermutation.java | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/BuildArrayFromPermutation.java diff --git a/README.md b/README.md index b4837be..79fb57b 100644 --- a/README.md +++ b/README.md @@ -461,7 +461,7 @@ | 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) | | | +| 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) | | | | 1929 | [Concatenation of Array](https://leetcode.com/problems/concatenation-of-array) | | | | 1933 | 🔒 [Check If String Is Decomposable Into Value EqualSubstrings](https://leetcode.com/problems/check-if-string-is-decomposable-into-value-equal-substring) | | | diff --git a/src/BuildArrayFromPermutation.java b/src/BuildArrayFromPermutation.java new file mode 100644 index 0000000..5787cd8 --- /dev/null +++ b/src/BuildArrayFromPermutation.java @@ -0,0 +1,13 @@ +// https://leetcode.com/problems/build-array-from-permutation +// T: O(N) +// S: O(N) + +public class BuildArrayFromPermutation { + public int[] buildArray(int[] nums) { + final int[] result = new int[nums.length]; + for (int i = 0 ; i < nums.length ; i++) { + result[i] = nums[nums[i]]; + } + return result; + } +} From 05150bd938ed00515b030d6ac8a599e5b194346e Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 23 Dec 2021 19:32:46 +0100 Subject: [PATCH 419/947] solves count square sum triplets --- README.md | 2 +- src/CountSquareSumTriplets.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/CountSquareSumTriplets.java diff --git a/README.md b/README.md index 79fb57b..40e1daf 100644 --- a/README.md +++ b/README.md @@ -462,7 +462,7 @@ | 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) | | | +| 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) | | | | 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) | | | diff --git a/src/CountSquareSumTriplets.java b/src/CountSquareSumTriplets.java new file mode 100644 index 0000000..055079f --- /dev/null +++ b/src/CountSquareSumTriplets.java @@ -0,0 +1,16 @@ +// https://leetcode.com/problems/count-square-sum-triples +// T: O(n ^ 2) +// S: O(1) + +public class CountSquareSumTriplets { + public int countTriples(int n) { + int triplets = 0; + for (int i = 1 ; i <= n - 2 ; i++) { + for (int j = i + 1 ; j <= n - 1 ; j++) { + int sqrt = (int) Math.sqrt(i * i + j * j); + if (sqrt <= n && sqrt * sqrt == i * i + j * j) triplets++; + } + } + return 2 * triplets; + } +} From ee92b83415b64f38bb8ce6ce3f883a85b03ae7a8 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 23 Dec 2021 19:35:42 +0100 Subject: [PATCH 420/947] solves concatenation of array --- README.md | 2 +- src/ConcatenationOfArray.java | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 src/ConcatenationOfArray.java diff --git a/README.md b/README.md index 40e1daf..cf74da7 100644 --- a/README.md +++ b/README.md @@ -463,7 +463,7 @@ | 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) | | | +| 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) | | | | 1941 | [Check if All Characters Have Equal Number of Occurrences](https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences) | | | diff --git a/src/ConcatenationOfArray.java b/src/ConcatenationOfArray.java new file mode 100644 index 0000000..b5df06d --- /dev/null +++ b/src/ConcatenationOfArray.java @@ -0,0 +1,12 @@ +// https://leetcode.com/problems/concatenation-of-array +// T: O(N) +// S: O(N) + +public class ConcatenationOfArray { + public int[] getConcatenation(int[] nums) { + final int[] result = new int[nums.length * 2]; + for (int i = 0 ; i < nums.length ; i++) result[i] = nums[i]; + for (int i = nums.length ; i < result.length ; i++) result[i] = nums[i - nums.length]; + return result; + } +} From e9efa51e9bd379c2b45bdc4b06a23f2a425a528f Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 23 Dec 2021 19:44:15 +0100 Subject: [PATCH 421/947] solves maximum number of words you can type --- README.md | 2 +- src/MaximumNumberOfWordsYouCanType.java | 31 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/MaximumNumberOfWordsYouCanType.java diff --git a/README.md b/README.md index cf74da7..3b68a41 100644 --- a/README.md +++ b/README.md @@ -465,7 +465,7 @@ | 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) | | | +| 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) | | | | 1945 | [Sum of Digits of String After Convert](https://leetcode.com/problems/sum-of-digits-of-string-after-convert) | | | | 1952 | [Three Divisors](https://leetcode.com/problems/three-divisors) | | | diff --git a/src/MaximumNumberOfWordsYouCanType.java b/src/MaximumNumberOfWordsYouCanType.java new file mode 100644 index 0000000..5beef69 --- /dev/null +++ b/src/MaximumNumberOfWordsYouCanType.java @@ -0,0 +1,31 @@ +// https://leetcode.com/problems/maximum-number-of-words-you-can-type +// T: O(|brokenLetters| + |text|) +// S: O(1) + +import java.util.HashSet; +import java.util.Set; + +public class MaximumNumberOfWordsYouCanType { + public int canBeTypedWords(String text, String brokenLetters) { + final Set brokenCharacters = getCharacters(brokenLetters); + int words = 0; + boolean canType = true; + for (int i = 0 ; i < text.length() ; i++) { + if (text.charAt(i) == ' ') { + if (canType) words++; + canType = true; + } else if (brokenCharacters.contains(text.charAt(i))) { + canType = false; + } + } + return words + (canType ? 1 : 0); + } + + private Set getCharacters(String s) { + final Set set = new HashSet<>(); + for (int i = 0 ; i < s.length() ; i++) { + set.add(s.charAt(i)); + } + return set; + } +} From f852c6f66719a066a250e61ff28e5c913ea49fc0 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 23 Dec 2021 19:54:07 +0100 Subject: [PATCH 422/947] solves check if all chars have same frequency --- README.md | 2 +- ...haractersHaveEqualNumberOfOccurrences.java | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/CheckIfAllCharactersHaveEqualNumberOfOccurrences.java diff --git a/README.md b/README.md index 3b68a41..a90cae1 100644 --- a/README.md +++ b/README.md @@ -466,7 +466,7 @@ | 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) | | | +| 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) | | | | 1952 | [Three Divisors](https://leetcode.com/problems/three-divisors) | | | | 1957 | [Delete Characters to Make Fancy String](https://leetcode.com/problems/delete-characters-to-make-fancy-string) | | | diff --git a/src/CheckIfAllCharactersHaveEqualNumberOfOccurrences.java b/src/CheckIfAllCharactersHaveEqualNumberOfOccurrences.java new file mode 100644 index 0000000..b89942a --- /dev/null +++ b/src/CheckIfAllCharactersHaveEqualNumberOfOccurrences.java @@ -0,0 +1,25 @@ +// https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences +// T: O(|s|) +// S: O(1) + +import java.util.HashMap; +import java.util.Map; + +public class CheckIfAllCharactersHaveEqualNumberOfOccurrences { + public boolean areOccurrencesEqual(String s) { + final Map charFrequencies = getCharacterFrequencies(s); + int commonFrequency = charFrequencies.get(s.charAt(0)); + for (int frequency : charFrequencies.values()) { + if (frequency != commonFrequency) return false; + } + return true; + } + + private Map getCharacterFrequencies(String s) { + final Map characterFrequencies = new HashMap<>(); + for (int i = 0 ; i < s.length() ; i++) { + characterFrequencies.put(s.charAt(i), characterFrequencies.getOrDefault(s.charAt(i), 0) + 1); + } + return characterFrequencies; + } +} From a74cda19f85c6aed992f61a73a623a85ee152111 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 23 Dec 2021 19:54:18 +0100 Subject: [PATCH 423/947] solves check if all chars have same frequency --- src/CheckIfAllCharactersHaveEqualNumberOfOccurrences.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CheckIfAllCharactersHaveEqualNumberOfOccurrences.java b/src/CheckIfAllCharactersHaveEqualNumberOfOccurrences.java index b89942a..ab3e523 100644 --- a/src/CheckIfAllCharactersHaveEqualNumberOfOccurrences.java +++ b/src/CheckIfAllCharactersHaveEqualNumberOfOccurrences.java @@ -16,7 +16,7 @@ public boolean areOccurrencesEqual(String s) { } private Map getCharacterFrequencies(String s) { - final Map characterFrequencies = new HashMap<>(); + final Map characterFrequencies = new HashMap<>(26); for (int i = 0 ; i < s.length() ; i++) { characterFrequencies.put(s.charAt(i), characterFrequencies.getOrDefault(s.charAt(i), 0) + 1); } From 2996881d6fcfa76f30628c7ca1f9596c50df8d64 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 23 Dec 2021 20:03:10 +0100 Subject: [PATCH 424/947] solves sum of digits of string after convert --- README.md | 2 +- src/SumOfDigitsOfStringAfterConvert.java | 39 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/SumOfDigitsOfStringAfterConvert.java diff --git a/README.md b/README.md index a90cae1..1bedf8a 100644 --- a/README.md +++ b/README.md @@ -467,7 +467,7 @@ | 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) | | | +| 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) | | | | 1957 | [Delete Characters to Make Fancy String](https://leetcode.com/problems/delete-characters-to-make-fancy-string) | | | | 1961 | [Check If String Is a Prefix of Array](https://leetcode.com/problems/check-if-string-is-a-prefix-of-array) | | | diff --git a/src/SumOfDigitsOfStringAfterConvert.java b/src/SumOfDigitsOfStringAfterConvert.java new file mode 100644 index 0000000..62b55a4 --- /dev/null +++ b/src/SumOfDigitsOfStringAfterConvert.java @@ -0,0 +1,39 @@ +// https://leetcode.com/problems/sum-of-digits-of-string-after-convert +// T: O(|s|* k) +// S: O(|s|) + +public class SumOfDigitsOfStringAfterConvert { + public int getLucky(String s, int k) { + final String convertedString = convert(s); + int num = sumOfDigits(convertedString); + for (int i = 0 ; i < k - 1 ; i++) { + num = sumOfDigits(num); + } + return num; + } + + private String convert(String s) { + final StringBuilder result = new StringBuilder(); + for (int i = 0 ; i < s.length() ; i++) { + result.append(s.charAt(i) - 'a' + 1); + } + return result.toString(); + } + + private int sumOfDigits(int number) { + int sum = 0; + while (number > 0) { + sum += number % 10; + number /= 10; + } + return sum; + } + + private int sumOfDigits(String number) { + int sum = 0; + for (int i = 0 ; i < number.length() ; i++) { + sum += number.charAt(i) - '0'; + } + return sum; + } +} From 2deb87d712e931a5fa652abe50862f9623972da2 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 23 Dec 2021 20:15:08 +0100 Subject: [PATCH 425/947] solves three diivisors --- README.md | 2 +- src/ThreeDivisors.java | 49 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 src/ThreeDivisors.java diff --git a/README.md b/README.md index 1bedf8a..31c1331 100644 --- a/README.md +++ b/README.md @@ -468,7 +468,7 @@ | 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) | | | +| 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) | | | | 1961 | [Check If String Is a Prefix of Array](https://leetcode.com/problems/check-if-string-is-a-prefix-of-array) | | | | 1967 | [Number of Strings That Appear as Substrings in Word](https://leetcode.com/problems/number-of-strings-that-appear-as-substrings-in-word) | | | diff --git a/src/ThreeDivisors.java b/src/ThreeDivisors.java new file mode 100644 index 0000000..1a66a91 --- /dev/null +++ b/src/ThreeDivisors.java @@ -0,0 +1,49 @@ +// https://leetcode.com/problems/three-divisors +// T: O(1) +// S: O(1) + +public class ThreeDivisors { + private static final PrimeSieve PRIME_SIEVE = PrimeSieve.ofSize(101); + + public boolean isThree(int n) { + return isPerfectSquare(n); + } + + private boolean isPerfectSquare(int x) { + int sqrt = (int) Math.sqrt(x); + return sqrt * sqrt == x && PRIME_SIEVE.isPrime(sqrt); + } + + private static class PrimeSieve { + final byte[] sieve; + + private static PrimeSieve ofSize(int size) { + return new PrimeSieve(size); + } + + PrimeSieve(int size) { + this.sieve = new byte[size + 1]; + initializeSieve(); + } + + public boolean isPrime(int number) { + return sieve[number] == 0; + } + + private void initializeSieve() { + sieve[0] = 1; + sieve[1] = 1; + for (int i = 2 ; i < sieve.length ; i++) { + if (sieve[i] == 0) { + markFactors(i); + } + } + } + + private void markFactors(int prime) { + for (int i = prime * prime ; i < sieve.length ; i += prime) { + sieve[i] = 1; + } + } + } +} From 1834f65b5c43febfe6b50032b08952e0bfc50ca3 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 23 Dec 2021 20:21:47 +0100 Subject: [PATCH 426/947] solves delete chars to make fancy string --- src/DeleteCharactersToMakeFancyString.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/DeleteCharactersToMakeFancyString.java diff --git a/src/DeleteCharactersToMakeFancyString.java b/src/DeleteCharactersToMakeFancyString.java new file mode 100644 index 0000000..c725859 --- /dev/null +++ b/src/DeleteCharactersToMakeFancyString.java @@ -0,0 +1,19 @@ +// https://leetcode.com/problems/delete-characters-to-make-fancy-string +// T: O(|s|) +// S: O(|s|) + +public class DeleteCharactersToMakeFancyString { + public String makeFancyString(String s) { + char current = s.charAt(0); + final StringBuilder result = new StringBuilder().append(current); + for (int i = 1, count = 1 ; i < s.length() ; i++) { + if (s.charAt(i) == current) count++; + else { + count = 1; + current = s.charAt(i); + } + if (count < 3) result.append(current); + } + return result.toString(); + } +} From 780d460354b6cf182c2c6013c64d4e64b1f0c721 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 23 Dec 2021 20:29:34 +0100 Subject: [PATCH 427/947] solves check if string is prefix of array --- README.md | 2 +- src/CheckIfStringIsAPrefixOfArray.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/CheckIfStringIsAPrefixOfArray.java diff --git a/README.md b/README.md index 31c1331..f267347 100644 --- a/README.md +++ b/README.md @@ -469,7 +469,7 @@ | 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) | | | +| 1957 | [Delete Characters to Make Fancy String](https://leetcode.com/problems/delete-characters-to-make-fancy-string) | [![Java](assets/java.png)](src/CheckIfStringIsAPrefixOfArray.java) | | | 1961 | [Check If String Is a Prefix of Array](https://leetcode.com/problems/check-if-string-is-a-prefix-of-array) | | | | 1967 | [Number of Strings That Appear as Substrings in Word](https://leetcode.com/problems/number-of-strings-that-appear-as-substrings-in-word) | | | | 1971 | [Find if Path Exists in Graph](https://leetcode.com/problems/find-if-path-exists-in-graph) | | | diff --git a/src/CheckIfStringIsAPrefixOfArray.java b/src/CheckIfStringIsAPrefixOfArray.java new file mode 100644 index 0000000..6047b6c --- /dev/null +++ b/src/CheckIfStringIsAPrefixOfArray.java @@ -0,0 +1,18 @@ +// https://leetcode.com/problems/check-if-string-is-a-prefix-of-array +// T : O(|s|) +// S : O(1) + +public class CheckIfStringIsAPrefixOfArray { + public boolean isPrefixString(String s, String[] words) { + int w = 0, j = 0; + for (int i = 0 ; i < s.length() && w < words.length ; i++) { + if (s.charAt(i) != words[w].charAt(j)) return false; + if (j == words[w].length() - 1) { + if (w == words.length - 1 && i + 1 < s.length()) return false; + w++; + j = 0; + } else j++; + } + return j == 0; + } +} From a45ece03782f5a4a1df681d037a9d9aaefbe067e Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 23 Dec 2021 20:32:32 +0100 Subject: [PATCH 428/947] solves number of strings that appear as substrings in word --- README.md | 2 +- src/NumberOfStringsThatAppearAsSubstringsInWord.java | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/NumberOfStringsThatAppearAsSubstringsInWord.java diff --git a/README.md b/README.md index f267347..8f5ce42 100644 --- a/README.md +++ b/README.md @@ -470,7 +470,7 @@ | 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/CheckIfStringIsAPrefixOfArray.java) | | -| 1961 | [Check If String Is a Prefix of Array](https://leetcode.com/problems/check-if-string-is-a-prefix-of-array) | | | +| 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/NumberOfStringsThatAppearAsSubstringsInWord.java) | | | 1967 | [Number of Strings That Appear as Substrings in Word](https://leetcode.com/problems/number-of-strings-that-appear-as-substrings-in-word) | | | | 1971 | [Find if Path Exists in Graph](https://leetcode.com/problems/find-if-path-exists-in-graph) | | | | 1974 | [Minimum Time to Type Word Using Special Typewriter](https://leetcode.com/problems/minimum-time-to-type-word-using-special-typewriter) | | | diff --git a/src/NumberOfStringsThatAppearAsSubstringsInWord.java b/src/NumberOfStringsThatAppearAsSubstringsInWord.java new file mode 100644 index 0000000..93ff8e2 --- /dev/null +++ b/src/NumberOfStringsThatAppearAsSubstringsInWord.java @@ -0,0 +1,11 @@ +public class NumberOfStringsThatAppearAsSubstringsInWord { + public int numOfStrings(String[] patterns, String word) { + int substrings = 0; + for (String pattern : patterns) { + if (word.contains(pattern)) { + substrings++; + } + } + return substrings; + } +} From 79a2adb49d01c1826c690004224551e98b984868 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 23 Dec 2021 20:55:39 +0100 Subject: [PATCH 429/947] solves find path if exists in graph --- README.md | 8 ++-- src/FindIfPathExistsInGraph.java | 63 ++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 src/FindIfPathExistsInGraph.java diff --git a/README.md b/README.md index 8f5ce42..a91bd88 100644 --- a/README.md +++ b/README.md @@ -469,10 +469,10 @@ | 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/CheckIfStringIsAPrefixOfArray.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/NumberOfStringsThatAppearAsSubstringsInWord.java) | | -| 1967 | [Number of Strings That Appear as Substrings in Word](https://leetcode.com/problems/number-of-strings-that-appear-as-substrings-in-word) | | | -| 1971 | [Find if Path Exists in Graph](https://leetcode.com/problems/find-if-path-exists-in-graph) | | | +| 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) | | | | 1979 | [Find Greatest Common Divisor of Array](https://leetcode.com/problems/find-greatest-common-divisor-of-array) | | | | 1984 | [Minimum Difference Between Highest and Lowest of K Scores](https://leetcode.com/problems/minimum-difference-between-highest-and-lowest-of-k-scores) | | | diff --git a/src/FindIfPathExistsInGraph.java b/src/FindIfPathExistsInGraph.java new file mode 100644 index 0000000..f84fbf8 --- /dev/null +++ b/src/FindIfPathExistsInGraph.java @@ -0,0 +1,63 @@ +// https://leetcode.com/problems/find-if-path-exists-in-graph +// T: O(V + E) +// S: O(V + E) + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public class FindIfPathExistsInGraph { + public boolean validPath(int n, int[][] edges, int start, int end) { + UnDirectedGraph graph = UnDirectedGraph.from(n, edges); + return graph.pathFrom(start, end); + } + + private static final class UnDirectedGraph { + private final Map vertices = new HashMap<>(); + + public static UnDirectedGraph from(int vertices, int[][] edges) { + UnDirectedGraph graph = new UnDirectedGraph(vertices); + for (int[] edge : edges) { + graph.vertices.get(edge[0]).addEdge(edge[1]); + graph.vertices.get(edge[1]).addEdge(edge[0]); + } + return graph; + } + + private UnDirectedGraph(int vertices) { + for (int i = 0 ; i < vertices ; i++) { + this.vertices.put(i, new Vertex(i)); + } + } + + public boolean pathFrom(int start, int end) { + return pathTo(vertices.get(start), end, new HashSet<>()); + } + + private boolean pathTo(Vertex from, int to, Set visited) { + if (visited.contains(from.value)) return false; + if (from.value == to) return true; + visited.add(from.value); + for (int edge : from.edges) { + if (pathTo(vertices.get(edge), to, visited)) { + return true; + } + } + return false; + } + + private static final class Vertex { + private final int value; + private final Set edges = new HashSet<>(); + + Vertex(int value) { + this.value = value; + } + + public void addEdge(int to) { + edges.add(to); + } + } + } +} From 2c7223171bbddfc6241cef4370a1389e1db567b7 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 23 Dec 2021 21:03:06 +0100 Subject: [PATCH 430/947] solves minimum time to type word using special typewriter --- README.md | 2 +- ...mTimeToTypeWordUsingSpecialTypewriter.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/MinimumTimeToTypeWordUsingSpecialTypewriter.java diff --git a/README.md b/README.md index a91bd88..23f0fea 100644 --- a/README.md +++ b/README.md @@ -473,7 +473,7 @@ | 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) | | | +| 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) | | | | 1984 | [Minimum Difference Between Highest and Lowest of K Scores](https://leetcode.com/problems/minimum-difference-between-highest-and-lowest-of-k-scores) | | | | 1991 | [Find the Middle Index in Array](https://leetcode.com/problems/find-the-middle-index-in-array) | | | diff --git a/src/MinimumTimeToTypeWordUsingSpecialTypewriter.java b/src/MinimumTimeToTypeWordUsingSpecialTypewriter.java new file mode 100644 index 0000000..734e5fd --- /dev/null +++ b/src/MinimumTimeToTypeWordUsingSpecialTypewriter.java @@ -0,0 +1,19 @@ +// https://leetcode.com/problems/minimum-time-to-type-word-using-special-typewriter +// T: O(|word|) +// S: O(1) + +public class MinimumTimeToTypeWordUsingSpecialTypewriter { + public int minTimeToType(String word) { + return movingTime(word) + word.length(); + } + + private int movingTime(String s) { + int movingTime = 0, distance; + for (int i = 1 ; i < s.length() ; i++) { + distance = Math.abs(s.charAt(i) - s.charAt(i - 1)); + movingTime += Math.min(distance, 26 - distance); + } + distance = Math.abs(s.charAt(0) - 'a'); + return movingTime + Math.min(distance, 26 - distance); + } +} From d372e5e9f238fb1728c545f10df660ea52f475b8 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 23 Dec 2021 21:06:20 +0100 Subject: [PATCH 431/947] solves find greatest common divisor of array --- README.md | 2 +- src/FindGreatestCommonDivisorOfArray.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/FindGreatestCommonDivisorOfArray.java diff --git a/README.md b/README.md index 23f0fea..c0b9b88 100644 --- a/README.md +++ b/README.md @@ -474,7 +474,7 @@ | 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) | | | +| 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) | | | | 1991 | [Find the Middle Index in Array](https://leetcode.com/problems/find-the-middle-index-in-array) | | | | 1995 | [Count Special Quadruplets](https://leetcode.com/problems/count-special-quadruplets) | | | diff --git a/src/FindGreatestCommonDivisorOfArray.java b/src/FindGreatestCommonDivisorOfArray.java new file mode 100644 index 0000000..bdc59dd --- /dev/null +++ b/src/FindGreatestCommonDivisorOfArray.java @@ -0,0 +1,18 @@ +// https://leetcode.com/problems/find-greatest-common-divisor-of-array +// T: O(N) +// S: O(1) + +import java.util.Arrays; + +public class FindGreatestCommonDivisorOfArray { + public int findGCD(int[] nums) { + return gcd( + Arrays.stream(nums).max().getAsInt(), + Arrays.stream(nums).min().getAsInt() + ); + } + + private int gcd(int a, int b) { + return b == 0 ? a : gcd(b, a % b); + } +} From 1be16694829893573c5070ae60505e85e946afd9 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 23 Dec 2021 21:11:25 +0100 Subject: [PATCH 432/947] solves minimum difference betweeb highest and lowest of k scores --- README.md | 2 +- ...fferenceBetweenHighestAndLowestOfKScores.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/MinimumDifferenceBetweenHighestAndLowestOfKScores.java diff --git a/README.md b/README.md index c0b9b88..091c739 100644 --- a/README.md +++ b/README.md @@ -475,7 +475,7 @@ | 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) | | | +| 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) | | | | 1995 | [Count Special Quadruplets](https://leetcode.com/problems/count-special-quadruplets) | | | | 2000 | [Reverse Prefix of Word](https://leetcode.com/problems/reverse-prefix-of-word) | | | diff --git a/src/MinimumDifferenceBetweenHighestAndLowestOfKScores.java b/src/MinimumDifferenceBetweenHighestAndLowestOfKScores.java new file mode 100644 index 0000000..b645ace --- /dev/null +++ b/src/MinimumDifferenceBetweenHighestAndLowestOfKScores.java @@ -0,0 +1,16 @@ +// https://leetcode.com/problems/minimum-difference-between-highest-and-lowest-of-k-scores +// T: O(Nlog(N)) +// S: O(1) + +import java.util.Arrays; + +public class MinimumDifferenceBetweenHighestAndLowestOfKScores { + public int minimumDifference(int[] nums, int k) { + Arrays.sort(nums); + int minDifference = Integer.MAX_VALUE; + for (int i = 0 ; i < nums.length - k + 1 ; i++) { + minDifference = Math.min(minDifference, nums[i + k - 1] - nums[i]); + } + return minDifference; + } +} From b2967d49139b3bf61ff0857622d4041d192b07c6 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 23 Dec 2021 21:17:04 +0100 Subject: [PATCH 433/947] solves find the middle index in array --- README.md | 2 +- src/FindTheMiddleIndexInArray.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/FindTheMiddleIndexInArray.java diff --git a/README.md b/README.md index 091c739..9cdd17a 100644 --- a/README.md +++ b/README.md @@ -476,7 +476,7 @@ | 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) | | | +| 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) | | | | 2000 | [Reverse Prefix of Word](https://leetcode.com/problems/reverse-prefix-of-word) | | | | 2006 | [Count Number of Pairs With Absolute Difference K](https://leetcode.com/problems/count-number-of-pairs-with-absolute-difference-k) | | | diff --git a/src/FindTheMiddleIndexInArray.java b/src/FindTheMiddleIndexInArray.java new file mode 100644 index 0000000..a881510 --- /dev/null +++ b/src/FindTheMiddleIndexInArray.java @@ -0,0 +1,18 @@ +// https://leetcode.com/problems/find-the-middle-index-in-array +// T: O(N) +// S: O(1) + +import java.util.Arrays; + +public class FindTheMiddleIndexInArray { + public int findMiddleIndex(int[] nums) { + int leftSum = 0, rightSum = Arrays.stream(nums).sum() - nums[0]; + if (leftSum == rightSum) return 0; + for (int index = 1 ; index < nums.length ; index++) { + rightSum -= nums[index]; + leftSum += nums[index - 1]; + if (leftSum == rightSum) return index; + } + return -1; + } +} From 162b200e8724b1a644193c71c767141066b9040a Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 23 Dec 2021 21:34:18 +0100 Subject: [PATCH 434/947] solves count special quadruplets --- README.md | 2 +- src/CountSpecialQuadruplets.java | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/CountSpecialQuadruplets.java diff --git a/README.md b/README.md index 9cdd17a..213b995 100644 --- a/README.md +++ b/README.md @@ -477,7 +477,7 @@ | 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) | | | +| 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) | | | | 2006 | [Count Number of Pairs With Absolute Difference K](https://leetcode.com/problems/count-number-of-pairs-with-absolute-difference-k) | | | | 2011 | [Final Value of Variable After Performing Operations](https://leetcode.com/problems/final-value-of-variable-after-performing-operations) | | | diff --git a/src/CountSpecialQuadruplets.java b/src/CountSpecialQuadruplets.java new file mode 100644 index 0000000..870bcc7 --- /dev/null +++ b/src/CountSpecialQuadruplets.java @@ -0,0 +1,27 @@ +// https://leetcode.com/problems/count-special-quadruplets +// T: O(N^2) +// S: O(N^2) + +import java.util.HashMap; +import java.util.Map; + +public class CountSpecialQuadruplets { + public int countQuadruplets(int[] nums) { + final Map differenceFreq = new HashMap<>(); + differenceFreq.put(nums[nums.length -1] - nums[nums.length - 2], 1); + int quadruplets = 0; + + for (int b = nums.length - 3 ; b > 0 ; b--) { + for (int a = b - 1 ; a >= 0 ; a--) { + quadruplets += differenceFreq.getOrDefault(nums[a] + nums[b], 0); + } + + for (int x = b + 1 ; x < nums.length ; x++) { + int difference = nums[x] - nums[b]; + differenceFreq.put(difference, differenceFreq.getOrDefault(difference, 0) + 1); + } + } + + return quadruplets; + } +} From eef0fc5963a720d5988883f883fc3e0a29c2c5e9 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 23 Dec 2021 21:34:42 +0100 Subject: [PATCH 435/947] updates stats --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 213b995..e51ca60 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-378/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-378/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-400/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-400/2081-1abc9c.svg) ![problems-solved-python](https://img.shields.io/badge/Python-186/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) From 19214f8347d17277fa15dba22f24d2d5276a92b6 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 23 Dec 2021 22:39:16 +0100 Subject: [PATCH 436/947] solves reverse prefix of word --- README.md | 2 +- src/ReversePrefixOfWord.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/ReversePrefixOfWord.java diff --git a/README.md b/README.md index e51ca60..dee032c 100644 --- a/README.md +++ b/README.md @@ -478,7 +478,7 @@ | 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) | | | +| 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) | | | | 2011 | [Final Value of Variable After Performing Operations](https://leetcode.com/problems/final-value-of-variable-after-performing-operations) | | | | 2016 | [Maximum Difference Between Increasing Elements](https://leetcode.com/problems/maximum-difference-between-increasing-elements) | | | diff --git a/src/ReversePrefixOfWord.java b/src/ReversePrefixOfWord.java new file mode 100644 index 0000000..1ea3564 --- /dev/null +++ b/src/ReversePrefixOfWord.java @@ -0,0 +1,19 @@ +// https://leetcode.com/problems/reverse-prefix-of-word +// T: O(|word|) +// S: O(|word|) + +public class ReversePrefixOfWord { + public String reversePrefix(String word, char ch) { + final StringBuilder result = new StringBuilder(); + boolean encounteredChar = false; + for (int i = 0 ; i < word.length() ; i++) { + if (!encounteredChar && word.charAt(i) == ch) { + result.append(word.charAt(i)).reverse(); + encounteredChar = true; + } else { + result.append(word.charAt(i)); + } + } + return result.toString(); + } +} From a51d6cd009ec3a2d15863d0405273e2b24d0dd87 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 23 Dec 2021 22:43:18 +0100 Subject: [PATCH 437/947] solves count number of pairs with absolut difference k --- README.md | 2 +- ...tNumberOfPairsWithAbsoluteDifferenceK.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/CountNumberOfPairsWithAbsoluteDifferenceK.java diff --git a/README.md b/README.md index dee032c..670119d 100644 --- a/README.md +++ b/README.md @@ -479,7 +479,7 @@ | 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) | | | +| 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) | | | | 2016 | [Maximum Difference Between Increasing Elements](https://leetcode.com/problems/maximum-difference-between-increasing-elements) | | | | 2022 | [Convert 1D Array Into 2D Array](https://leetcode.com/problems/convert-1d-array-into-2d-array) | | | diff --git a/src/CountNumberOfPairsWithAbsoluteDifferenceK.java b/src/CountNumberOfPairsWithAbsoluteDifferenceK.java new file mode 100644 index 0000000..52b6ede --- /dev/null +++ b/src/CountNumberOfPairsWithAbsoluteDifferenceK.java @@ -0,0 +1,19 @@ +// https://leetcode.com/problems/count-number-of-pairs-with-absolute-difference-k +// T: O(N) +// S: O(N) + +import java.util.HashMap; +import java.util.Map; + +public class CountNumberOfPairsWithAbsoluteDifferenceK { + public int countKDifference(int[] nums, int k) { + final Map frequency = new HashMap<>(); + int pairs = 0; + for (int element : nums) { + pairs += frequency.getOrDefault(element - k, 0); + pairs += frequency.getOrDefault(element + k, 0); + frequency.put(element, frequency.getOrDefault(element, 0) + 1); + } + return pairs; + } +} From 73459305f2742e23bac0e8430d6739a97486d303 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 23 Dec 2021 22:47:37 +0100 Subject: [PATCH 438/947] solves final value of variable after performing operations --- README.md | 2 +- ...ueOfVariableAfterPerformingOperations.java | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 src/FinalValueOfVariableAfterPerformingOperations.java diff --git a/README.md b/README.md index 670119d..a06794e 100644 --- a/README.md +++ b/README.md @@ -480,7 +480,7 @@ | 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) | | | +| 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) | | | | 2022 | [Convert 1D Array Into 2D Array](https://leetcode.com/problems/convert-1d-array-into-2d-array) | | | | 2027 | [Minimum Moves to Convert String](https://leetcode.com/problems/minimum-moves-to-convert-string) | | | diff --git a/src/FinalValueOfVariableAfterPerformingOperations.java b/src/FinalValueOfVariableAfterPerformingOperations.java new file mode 100644 index 0000000..4e763b2 --- /dev/null +++ b/src/FinalValueOfVariableAfterPerformingOperations.java @@ -0,0 +1,21 @@ +// https://leetcode.com/problems/final-value-of-variable-after-performing-operations +// T: O(|operations|) +// S: O(1) + +public class FinalValueOfVariableAfterPerformingOperations { + public int finalValueAfterOperations(String[] operations) { + int x = 0; + for (String operation : operations) { + x = apply(x, operation); + } + return x; + } + + private int apply(int x, String operation) { + return switch (operation) { + case "++X", "X++" -> x + 1; + case "--X", "X--" -> x - 1; + default -> x; + }; + } +} From bab6edb06938dfa8dc9a3e171eea8621aef6d711 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 23 Dec 2021 22:52:30 +0100 Subject: [PATCH 439/947] solves maximum difference between increasing elements --- README.md | 2 +- ...ximumDifferenceBetweenIncreasingElements.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/MaximumDifferenceBetweenIncreasingElements.java diff --git a/README.md b/README.md index a06794e..e45ed39 100644 --- a/README.md +++ b/README.md @@ -481,7 +481,7 @@ | 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) | | | +| 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) | | | | 2027 | [Minimum Moves to Convert String](https://leetcode.com/problems/minimum-moves-to-convert-string) | | | | 2032 | [Two Out of Three](https://leetcode.com/problems/two-out-of-three) | | | diff --git a/src/MaximumDifferenceBetweenIncreasingElements.java b/src/MaximumDifferenceBetweenIncreasingElements.java new file mode 100644 index 0000000..1453ca4 --- /dev/null +++ b/src/MaximumDifferenceBetweenIncreasingElements.java @@ -0,0 +1,16 @@ +// https://leetcode.com/problems/maximum-difference-between-increasing-elements +// T: O(N) +// S: O(1) + +public class MaximumDifferenceBetweenIncreasingElements { + public int maximumDifference(int[] nums) { + int maxDifference = -1; + for (int index = nums.length - 2, currentMax = nums[nums.length - 1] ; index >= 0 ; index--) { + if (currentMax > nums[index]) { + maxDifference = Math.max(maxDifference, currentMax - nums[index]); + } + currentMax = Math.max(currentMax, nums[index]); + } + return maxDifference; + } +} From 471fd13dcd30ccce55f5c5a430f0babe518ef129 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 24 Dec 2021 01:47:28 +0100 Subject: [PATCH 440/947] solves convert 1d array to 2d array --- README.md | 2 +- src/Convert1DArrayInto2DArray.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/Convert1DArrayInto2DArray.java diff --git a/README.md b/README.md index e45ed39..8fee494 100644 --- a/README.md +++ b/README.md @@ -482,7 +482,7 @@ | 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) | | | +| 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) | | | | 2032 | [Two Out of Three](https://leetcode.com/problems/two-out-of-three) | | | | 2037 | [Minimum Number of Moves to Seat Everyone](https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone) | | | diff --git a/src/Convert1DArrayInto2DArray.java b/src/Convert1DArrayInto2DArray.java new file mode 100644 index 0000000..5930be3 --- /dev/null +++ b/src/Convert1DArrayInto2DArray.java @@ -0,0 +1,16 @@ +// https://leetcode.com/problems/convert-1d-array-into-2d-array +// T: O(n * m) +// S: O(n * m) + +public class Convert1DArrayInto2DArray { + public int[][] construct2DArray(int[] original, int m, int n) { + if (m * n != original.length) return new int[0][]; + final int[][] result = new int[m][n]; + for (int i = 0 ; i < m ; i++) { + for (int j = 0 ; j < n ; j++) { + result[i][j] = original[n * i + j]; + } + } + return result; + } +} From 2594a6302e781eefc2e839e201d0d586dc82ea39 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 24 Dec 2021 14:57:23 +0100 Subject: [PATCH 441/947] solves minimum movies to convert string --- README.md | 2 +- src/MinimumMovesToConvertString.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/MinimumMovesToConvertString.java diff --git a/README.md b/README.md index 8fee494..8910d26 100644 --- a/README.md +++ b/README.md @@ -483,7 +483,7 @@ | 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) | | | +| 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) | | | | 2037 | [Minimum Number of Moves to Seat Everyone](https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone) | | | | 2042 | [Check if Numbers Are Ascending in a Sentence](https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence) | | | diff --git a/src/MinimumMovesToConvertString.java b/src/MinimumMovesToConvertString.java new file mode 100644 index 0000000..c5e751e --- /dev/null +++ b/src/MinimumMovesToConvertString.java @@ -0,0 +1,16 @@ +// https://leetcode.com/problems/minimum-moves-to-convert-string +// T: O(|s|) +// S: O(1) + +public class MinimumMovesToConvertString { + public int minimumMoves(String s) { + int conversions = 0; + for (int i = 0 ; i < s.length() ; i++) { + if (s.charAt(i) == 'X') { + conversions++; + i += 2; + } + } + return conversions; + } +} From 4ed6fc52d26002e834b79d84d87791ddd2405661 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 24 Dec 2021 15:05:00 +0100 Subject: [PATCH 442/947] solves twoout of three --- README.md | 2 +- src/TwoOutOfThree.java | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/TwoOutOfThree.java diff --git a/README.md b/README.md index 8910d26..7989d20 100644 --- a/README.md +++ b/README.md @@ -484,7 +484,7 @@ | 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) | | | +| 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) | | | | 2042 | [Check if Numbers Are Ascending in a Sentence](https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence) | | | | 2047 | [Number of Valid Words in a Sentence](https://leetcode.com/problems/number-of-valid-words-in-a-sentence) | | | diff --git a/src/TwoOutOfThree.java b/src/TwoOutOfThree.java new file mode 100644 index 0000000..c512a07 --- /dev/null +++ b/src/TwoOutOfThree.java @@ -0,0 +1,35 @@ +// https://leetcode.com/problems/two-out-of-three +// T: O(|nums1| + |nums2| + |nums3|) +// S: O(|nums1| + |nums2| + |nums3|) + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class TwoOutOfThree { + public List twoOutOfThree(int[] nums1, int[] nums2, int[] nums3) { + final Set set1 = getElements(nums1); + final Set set2 = getElements(nums2); + final Set set3 = getElements(nums3); + final Set resultElements = new HashSet<>(); + for (int element : set1) { + if (set2.contains(element) || set3.contains(element)) { + resultElements.add(element); + } + } + for (int element : set2) { + if (set3.contains(element)) resultElements.add(element); + } +// return resultElements.stream().toList(); // cant be used because LeetCode is still on a previous version of Java + return new ArrayList<>(resultElements); + } + + private Set getElements(int[] array) { + final Set set = new HashSet<>(); + for (int element : array) { + set.add(element); + } + return set; + } +} From 921543616713a49b83ea13c6cd70bccf8bb8199c Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 24 Dec 2021 15:14:42 +0100 Subject: [PATCH 443/947] solves minimum number of moves to seat everyone --- README.md | 2 +- src/MinimumNumberOfMovesToSeatEveryone.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/MinimumNumberOfMovesToSeatEveryone.java diff --git a/README.md b/README.md index 7989d20..b2252cf 100644 --- a/README.md +++ b/README.md @@ -485,7 +485,7 @@ | 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) | | | +| 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) | | | | 2047 | [Number of Valid Words in a Sentence](https://leetcode.com/problems/number-of-valid-words-in-a-sentence) | | | | 2053 | [Kth Distinct String in an Array](https://leetcode.com/problems/kth-distinct-string-in-an-array) | | | diff --git a/src/MinimumNumberOfMovesToSeatEveryone.java b/src/MinimumNumberOfMovesToSeatEveryone.java new file mode 100644 index 0000000..e547ffb --- /dev/null +++ b/src/MinimumNumberOfMovesToSeatEveryone.java @@ -0,0 +1,17 @@ +// https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone +// T: O(n log(n)) +// S: O(1) + +import java.util.Arrays; + +public class MinimumNumberOfMovesToSeatEveryone { + public int minMovesToSeat(int[] seats, int[] students) { + Arrays.sort(seats); + Arrays.sort(students); + int minMoves = 0; + for (int i = 0 ; i < students.length ; i++) { + minMoves += Math.abs(seats[i] - students[i]); + } + return minMoves; + } +} From 829c711964e55733cc53dbe6ddc80c1407d6ac94 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 24 Dec 2021 15:45:54 +0100 Subject: [PATCH 444/947] solves check if numbers are in ascending order in a sentence --- README.md | 2 +- ...CheckIfNumbersAreAscendingInASentence.java | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/CheckIfNumbersAreAscendingInASentence.java diff --git a/README.md b/README.md index b2252cf..a4d54d2 100644 --- a/README.md +++ b/README.md @@ -486,7 +486,7 @@ | 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) | | | +| 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) | | | | 2053 | [Kth Distinct String in an Array](https://leetcode.com/problems/kth-distinct-string-in-an-array) | | | | 2057 | [Smallest Index With Equal Value](https://leetcode.com/problems/smallest-index-with-equal-value) | | | diff --git a/src/CheckIfNumbersAreAscendingInASentence.java b/src/CheckIfNumbersAreAscendingInASentence.java new file mode 100644 index 0000000..e1177c5 --- /dev/null +++ b/src/CheckIfNumbersAreAscendingInASentence.java @@ -0,0 +1,40 @@ +// https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence +// T: O(|s|) +// S: O(|s|) + +import java.util.LinkedList; +import java.util.Queue; + +public class CheckIfNumbersAreAscendingInASentence { + public boolean areNumbersAscending(String s) { + StringBuilder word = new StringBuilder(); + final Queue numbers = new LinkedList<>(); + for (int i = 0 ; i < s.length() ; i++) { + if (s.charAt(i) == ' ') { + if (isNumber(word)) { + if (!numbers.isEmpty() && lessThanEqual(word.toString(), numbers.peek())) { + return false; + } + numbers.poll(); + numbers.add(word.toString()); + } + word = new StringBuilder(); + } else word.append(s.charAt(i)); + } + return !isNumber(word) || numbers.isEmpty() || !lessThanEqual(word.toString(), numbers.peek()); + } + + private boolean isNumber(StringBuilder s) { + return Character.isDigit(s.charAt(0)); + } + + private boolean lessThanEqual(String s, String o) { + if (s.length() < o.length()) return true; + if (s.length() > o.length()) return false; + for (int i = 0 ; i < s.length() ; i++) { + if (s.charAt(i) < o.charAt(i)) return true; + if (s.charAt(i) > o.charAt(i)) return false; + } + return true; + } +} From d5291f8b48301a6523b6b46b9d427154af5590e5 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 24 Dec 2021 16:18:32 +0100 Subject: [PATCH 445/947] solves number of valid words in a sentence --- README.md | 2 +- src/NumberOfValidWordsInASentence.java | 50 ++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 src/NumberOfValidWordsInASentence.java diff --git a/README.md b/README.md index a4d54d2..23aa277 100644 --- a/README.md +++ b/README.md @@ -487,7 +487,7 @@ | 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) | | | +| 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) | | | | 2057 | [Smallest Index With Equal Value](https://leetcode.com/problems/smallest-index-with-equal-value) | | | | 2062 | [Count Vowel Substrings of a String](https://leetcode.com/problems/count-vowel-substrings-of-a-string) | | | diff --git a/src/NumberOfValidWordsInASentence.java b/src/NumberOfValidWordsInASentence.java new file mode 100644 index 0000000..c3f1195 --- /dev/null +++ b/src/NumberOfValidWordsInASentence.java @@ -0,0 +1,50 @@ +// https://leetcode.com/problems/number-of-valid-words-in-a-sentence +// T: O(|sentence|) +// S: O(|sentence|) + +import java.util.Set; + +public class NumberOfValidWordsInASentence { + private static final Set PUNCTUATIONS = Set.of('!', '.', ','); + + public int countValidWords(String sentence) { + StringBuilder word = new StringBuilder(); + int validWords= 0; + for (int i = 0 ; i < sentence.length() ; i++) { + if (sentence.charAt(i) == ' ') { + validWords += isValidWord(word) ? 1 : 0; + word = new StringBuilder(); + } else word.append(sentence.charAt(i)); + } + return validWords + (isValidWord(word) ? 1 : 0); + } + + private boolean isValidWord(StringBuilder s) { + if (s.length() == 0) return false; + for (int i = 0, hyphens = 0 ; i < s.length() ; i++) { + if (isDigit(s.charAt(i))) return false; + else if (isHyphen(s.charAt(i))) { + if (hyphens > 0) return false; + hyphens++; + if (i == 0 || i == s.length() - 1 || !isAlphabet(s.charAt(i + 1))) return false; + } else if (isPunctuationMark(s.charAt(i)) && i < s.length() - 1) return false; + } + return true; + } + + private boolean isDigit(char c) { + return Character.isDigit(c); + } + + private boolean isHyphen(char c) { + return c == '-'; + } + + private boolean isAlphabet(char c) { + return Character.isAlphabetic(c); + } + + private boolean isPunctuationMark(char c) { + return PUNCTUATIONS.contains(c); + } +} From cef38578d8b6736cf8446a82995def05befe50c2 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 24 Dec 2021 16:27:29 +0100 Subject: [PATCH 446/947] solves kth distinct string in array --- README.md | 2 +- src/KthDistinctStringInAnArray.java | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/KthDistinctStringInAnArray.java diff --git a/README.md b/README.md index 23aa277..b3ebd0d 100644 --- a/README.md +++ b/README.md @@ -488,7 +488,7 @@ | 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) | | | +| 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) | | | | 2062 | [Count Vowel Substrings of a String](https://leetcode.com/problems/count-vowel-substrings-of-a-string) | | | | 2068 | [Check Whether Two Strings are Almost Equivalent](https://leetcode.com/problems/check-whether-two-strings-are-almost-equivalent) | | | diff --git a/src/KthDistinctStringInAnArray.java b/src/KthDistinctStringInAnArray.java new file mode 100644 index 0000000..e3cab6d --- /dev/null +++ b/src/KthDistinctStringInAnArray.java @@ -0,0 +1,27 @@ +// https://leetcode.com/problems/kth-distinct-string-in-an-array +// T: O(|arr|) +// S: O(|arr|) + +import java.util.HashMap; +import java.util.Map; + +public class KthDistinctStringInAnArray { + public String kthDistinct(String[] arr, int k) { + final Map frequencies = getFrequency(arr); + for (String s : arr) { + if (frequencies.get(s) == 1) { + k--; + } + if (k == 0) return s; + } + return ""; + } + + private Map getFrequency(String[] array) { + final Map frequencies = new HashMap<>(); + for (String s : array) { + frequencies.put(s, frequencies.getOrDefault(s, 0) + 1); + } + return frequencies; + } +} From 1c389c580877e1ed9a3edcc2a64951bf6a13d648 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 24 Dec 2021 22:27:00 +0100 Subject: [PATCH 447/947] solves smallest index with equal value --- README.md | 2 +- src/SmallestIndexWithEqualValue.java | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 src/SmallestIndexWithEqualValue.java diff --git a/README.md b/README.md index b3ebd0d..6d31435 100644 --- a/README.md +++ b/README.md @@ -489,7 +489,7 @@ | 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) | | | +| 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) | | | | 2068 | [Check Whether Two Strings are Almost Equivalent](https://leetcode.com/problems/check-whether-two-strings-are-almost-equivalent) | | | | 2073 | [Time Needed to Buy Tickets](https://leetcode.com/problems/time-needed-to-buy-tickets) | | | diff --git a/src/SmallestIndexWithEqualValue.java b/src/SmallestIndexWithEqualValue.java new file mode 100644 index 0000000..a9689a6 --- /dev/null +++ b/src/SmallestIndexWithEqualValue.java @@ -0,0 +1,12 @@ +// https://leetcode.com/problems/smallest-index-with-equal-value +// T: O(N) +// S: O(1) + +public class SmallestIndexWithEqualValue { + public int smallestEqual(int[] nums) { + for (int i = 0 ; i < nums.length ; i++) { + if (i % 10 == nums[i]) return i; + } + return -1; + } +} From e202c8200a135512c850e12878736d5acf7e3967 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 24 Dec 2021 23:23:39 +0100 Subject: [PATCH 448/947] solves count vowel substrings of a string --- README.md | 2 +- src/CountVowelSubstringsOfAString.java | 51 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 src/CountVowelSubstringsOfAString.java diff --git a/README.md b/README.md index 6d31435..df9e0e7 100644 --- a/README.md +++ b/README.md @@ -490,7 +490,7 @@ | 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) | | | +| 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) | | | | 2073 | [Time Needed to Buy Tickets](https://leetcode.com/problems/time-needed-to-buy-tickets) | | | | 2078 | [Two Furthest Houses With Different Colors](https://leetcode.com/problems/two-furthest-houses-with-different-colors) | | | diff --git a/src/CountVowelSubstringsOfAString.java b/src/CountVowelSubstringsOfAString.java new file mode 100644 index 0000000..f8599e2 --- /dev/null +++ b/src/CountVowelSubstringsOfAString.java @@ -0,0 +1,51 @@ +// https://leetcode.com/problems/count-vowel-substrings-of-a-string +// T: O(|word|) +// S: O(|word|) + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +public class CountVowelSubstringsOfAString { + private static final Set VOWELS = Set.of('a', 'e', 'i', 'o','u'); + + public static int countVowelSubstrings(String word) { + int vowelSubstrings = 0; + final Map vowels = new HashMap<>(); + for (int j = 0 ; j < word.length() ; j++) { + if (isVowel(word.charAt(j))) { + addToMap(vowels, word.charAt(j)); + for (int i = j + 1, k = j ; i < word.length() ; i++) { + if (isVowel(word.charAt(i))) { + addToMap(vowels, word.charAt(i)); + for ( ; k < i && vowels.size() == 5 ; k++) { + removeFromMap(vowels, word.charAt(k)); + } + vowelSubstrings += k - j; + if (i == word.length() - 1) { + j = i; + } + } else { + j = i; + vowels.clear(); + break; + } + } + } + } + return vowelSubstrings; + } + + private static boolean isVowel(char c) { + return VOWELS.contains(c); + } + + private static void addToMap(Map frequencies, char c) { + frequencies.put(c, frequencies.getOrDefault(c, 0) + 1); + } + + private static void removeFromMap(Map frequencies, char c) { + if (frequencies.getOrDefault(c, 0) == 1) frequencies.remove(c); + else frequencies.put(c, frequencies.get(c) - 1); + } +} From cc08eab6aedccbe2bac60f10e6f841dfe0bad40b Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 24 Dec 2021 23:37:09 +0100 Subject: [PATCH 449/947] solvescheck whether two strings are almost equivalent --- README.md | 2 +- ...kWhetherTwoStringsAreAlmostEquivalent.java | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/CheckWhetherTwoStringsAreAlmostEquivalent.java diff --git a/README.md b/README.md index df9e0e7..c95baa7 100644 --- a/README.md +++ b/README.md @@ -491,7 +491,7 @@ | 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) | | | +| 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) | | | | 2078 | [Two Furthest Houses With Different Colors](https://leetcode.com/problems/two-furthest-houses-with-different-colors) | | | | 2085 | [Count Common Words With One Occurrence](https://leetcode.com/problems/count-common-words-with-one-occurrence) | | | diff --git a/src/CheckWhetherTwoStringsAreAlmostEquivalent.java b/src/CheckWhetherTwoStringsAreAlmostEquivalent.java new file mode 100644 index 0000000..c537e8f --- /dev/null +++ b/src/CheckWhetherTwoStringsAreAlmostEquivalent.java @@ -0,0 +1,28 @@ +// https://leetcode.com/problems/check-whether-two-strings-are-almost-equivalent +// T: O(|word1| + |word2|) +// S: O(1) + +import java.util.HashMap; +import java.util.Map; + +public class CheckWhetherTwoStringsAreAlmostEquivalent { + public boolean checkAlmostEquivalent(String word1, String word2) { + final Map word1Frequencies = getFrequencies(word1); + final Map word2Frequencies = getFrequencies(word2); + for (char c = 'a' ; c <= 'z' ; c++) { + if (Math.abs(word1Frequencies.getOrDefault(c, 0) - word2Frequencies.getOrDefault(c, 0)) + > 3) { + return false; + } + } + return true; + } + + private Map getFrequencies(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 11dbb09f5ecb61693b6b754e5491e268823eb0a8 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 24 Dec 2021 23:44:50 +0100 Subject: [PATCH 450/947] solves time needed to buy tickets --- README.md | 2 +- src/TimeNeededToBuyTickets.java | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 src/TimeNeededToBuyTickets.java diff --git a/README.md b/README.md index c95baa7..f5298c6 100644 --- a/README.md +++ b/README.md @@ -492,7 +492,7 @@ | 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) | | | +| 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) | | | | 2085 | [Count Common Words With One Occurrence](https://leetcode.com/problems/count-common-words-with-one-occurrence) | | | | 2089 | [Find Target Indices After Sorting Array](https://leetcode.com/problems/find-target-indices-after-sorting-array) | | | diff --git a/src/TimeNeededToBuyTickets.java b/src/TimeNeededToBuyTickets.java new file mode 100644 index 0000000..7ea3a8b --- /dev/null +++ b/src/TimeNeededToBuyTickets.java @@ -0,0 +1,12 @@ +// https://leetcode.com/problems/time-needed-to-buy-tickets +// T: O(|tickets|) +// S: O(1) + +public class TimeNeededToBuyTickets { + public int timeRequiredToBuy(int[] tickets, int k) { + int time = 0; + for (int i = 0 ; i < k ; i++) time += Math.min(tickets[i], tickets[k]); + for (int i = k + 1 ; i < tickets.length ; i++) time += Math.min(tickets[i], tickets[k] - 1); + return time + tickets[k]; + } +} From fc6211fa25ddc33728c4c89268d8daaad4edd737 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 25 Dec 2021 02:01:29 +0100 Subject: [PATCH 451/947] solves two furthest houses with different color --- README.md | 2 +- src/TwoFurthestHousesWithDifferentColors.java | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/TwoFurthestHousesWithDifferentColors.java diff --git a/README.md b/README.md index f5298c6..4fdaad6 100644 --- a/README.md +++ b/README.md @@ -493,7 +493,7 @@ | 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) | | | +| 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) | | | | 2089 | [Find Target Indices After Sorting Array](https://leetcode.com/problems/find-target-indices-after-sorting-array) | | | | 2094 | [Finding 3-Digit Even Numbers](https://leetcode.com/problems/finding-3-digit-even-numbers) | | | diff --git a/src/TwoFurthestHousesWithDifferentColors.java b/src/TwoFurthestHousesWithDifferentColors.java new file mode 100644 index 0000000..e0e0084 --- /dev/null +++ b/src/TwoFurthestHousesWithDifferentColors.java @@ -0,0 +1,9 @@ +public class TwoFurthestHousesWithDifferentColors { + public int maxDistance(int[] colors) { + int i = colors.length - 1; + for ( ; i >= 0 && colors[i] == colors[0] ; i--); + int distance = i; + for (i = 0 ; i < colors.length && colors[i] == colors[colors.length - 1] ; i++); + return Math.max(distance, colors.length - 1 - i); + } +} From d896a220f46fcecac3302d7cf6be6dafaa864cd3 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 25 Dec 2021 02:10:12 +0100 Subject: [PATCH 452/947] solves count common words with only one occurrence --- README.md | 4 ++-- src/CountCommonWordsWithOneOccurrence.java | 28 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 src/CountCommonWordsWithOneOccurrence.java diff --git a/README.md b/README.md index 4fdaad6..7762be2 100644 --- a/README.md +++ b/README.md @@ -493,8 +493,8 @@ | 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) | | | +| 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) | | | | 2094 | [Finding 3-Digit Even Numbers](https://leetcode.com/problems/finding-3-digit-even-numbers) | | | | 2099 | [Find Subsequence of Length K With the Largest Sum](https://leetcode.com/problems/find-subsequence-of-length-k-with-the-largest-sum) | | | diff --git a/src/CountCommonWordsWithOneOccurrence.java b/src/CountCommonWordsWithOneOccurrence.java new file mode 100644 index 0000000..1e9bf77 --- /dev/null +++ b/src/CountCommonWordsWithOneOccurrence.java @@ -0,0 +1,28 @@ +// https://leetcode.com/problems/count-common-words-with-one-occurrence +// T: O(|words1| + |words2|) +// S: O(|words1| + |words2|) + +import java.util.HashMap; +import java.util.Map; + +public class CountCommonWordsWithOneOccurrence { + public int countWords(String[] words1, String[] words2) { + final Map words1Frequency = getFrequencies(words1); + final Map words2Frequency = getFrequencies(words2); + int words = 0; + for (Map.Entry entry: words1Frequency.entrySet()) { + if (entry.getValue() == 1 && words2Frequency.getOrDefault(entry.getKey(), 0) == 1) { + words++; + } + } + return words; + } + + private Map getFrequencies(String[] array) { + final Map frequencies = new HashMap<>(); + for (String s : array) { + frequencies.put(s, frequencies.getOrDefault(s, 0) + 1); + } + return frequencies; + } +} From 0a5201f092e3d042861dc081bc9bcba2d9d9c86f Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 25 Dec 2021 13:02:12 +0100 Subject: [PATCH 453/947] solves find target indices after sorting array --- README.md | 2 +- src/FindTargetIndicesAfterSortingArray.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/FindTargetIndicesAfterSortingArray.java diff --git a/README.md b/README.md index 7762be2..2ee55cf 100644 --- a/README.md +++ b/README.md @@ -495,7 +495,7 @@ | 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) | | | +| 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) | | | | 2099 | [Find Subsequence of Length K With the Largest Sum](https://leetcode.com/problems/find-subsequence-of-length-k-with-the-largest-sum) | | | | 2103 | [Rings and Rods](https://leetcode.com/problems/rings-and-rods) | | | diff --git a/src/FindTargetIndicesAfterSortingArray.java b/src/FindTargetIndicesAfterSortingArray.java new file mode 100644 index 0000000..c6d1e8a --- /dev/null +++ b/src/FindTargetIndicesAfterSortingArray.java @@ -0,0 +1,16 @@ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class FindTargetIndicesAfterSortingArray { + public List targetIndices(int[] nums, int target) { + Arrays.sort(nums); + final List indices = new ArrayList<>(); + for (int i = 0 ; i < nums.length ; i++) { + if (nums[i] == target) { + indices.add(i); + } + } + return indices; + } +} From 4d21dca69492a3259f7cfef5b3d7c77bc8b7c9f7 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 25 Dec 2021 13:08:21 +0100 Subject: [PATCH 454/947] solves find target indices after sorting --- src/FindTargetIndicesAfterSortingArray.java | 35 ++++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/src/FindTargetIndicesAfterSortingArray.java b/src/FindTargetIndicesAfterSortingArray.java index c6d1e8a..7132914 100644 --- a/src/FindTargetIndicesAfterSortingArray.java +++ b/src/FindTargetIndicesAfterSortingArray.java @@ -1,16 +1,35 @@ +// https://leetcode.com/problems/find-target-indices-after-sorting-array +// T: O(|nums|) +// S: O(|nums|) + import java.util.ArrayList; -import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class FindTargetIndicesAfterSortingArray { public List targetIndices(int[] nums, int target) { - Arrays.sort(nums); - final List indices = new ArrayList<>(); - for (int i = 0 ; i < nums.length ; i++) { - if (nums[i] == target) { - indices.add(i); - } + final Map frequency = getFrequency(nums); + int index = 0; + for (int i = 0 ; i < target ; i++) { + index += frequency.getOrDefault(i, 0); + } + return indices(index, frequency.getOrDefault(target, 0)); + } + + private Map getFrequency(int[] array) { + final Map result = new HashMap<>(); + for (int element : array) { + result.put(element, result.getOrDefault(element, 0) + 1); + } + return result; + } + + private List indices(int start, int length) { + final List result = new ArrayList<>(length); + for (int i = 0 ; i < length ; i++) { + result.add(start++); } - return indices; + return result; } } From a35ec77fdfb28d72df63ce908ce0ec4c2f3e5c5a Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 25 Dec 2021 13:20:19 +0100 Subject: [PATCH 455/947] soles finding3digit evennumbers --- README.md | 2 +- src/Finding3DigitEvenNumbers.java | 57 +++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/Finding3DigitEvenNumbers.java diff --git a/README.md b/README.md index 2ee55cf..fcccaed 100644 --- a/README.md +++ b/README.md @@ -496,6 +496,6 @@ | 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) | | | +| 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) | | | | 2103 | [Rings and Rods](https://leetcode.com/problems/rings-and-rods) | | | diff --git a/src/Finding3DigitEvenNumbers.java b/src/Finding3DigitEvenNumbers.java new file mode 100644 index 0000000..6bc09ef --- /dev/null +++ b/src/Finding3DigitEvenNumbers.java @@ -0,0 +1,57 @@ +// https://leetcode.com/problems/finding-3-digit-even-numbers +// T: O(N) +// S: O(N) + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class Finding3DigitEvenNumbers { + public int[] findEvenNumbers(int[] digits) { + final Map frequencies = getFrequency(digits); + final List numbers = new ArrayList<>(); + for (int number = 100 ; number <= 999 ; number += 2) { + if (canBeFormed(number, frequencies)) { + numbers.add(number); + } + } + return toArray(numbers); + } + + private boolean canBeFormed(int number, Map digits) { + final Map numberDigits = getFrequency(number); + for (Map.Entry entry : numberDigits.entrySet()) { + if (digits.getOrDefault(entry.getKey(), 0) < entry.getValue()) { + return false; + } + } + return true; + } + + private int[] toArray(List list) { + final int[] array = new int[list.size()]; + for (int i = 0 ; i < list.size() ; i++) { + array[i] = list.get(i); + } + return array; + } + + private Map getFrequency(int[] array) { + final Map frequency = new HashMap<>(); + for (int element : array) { + frequency.put(element, frequency.getOrDefault(element, 0) + 1); + } + return frequency; + } + + private Map getFrequency(int number) { + final Map frequency = new HashMap<>(); + while (number > 0) { + int digit = number % 10; + frequency.put(digit, frequency.getOrDefault(digit, 0) + 1); + number /= 10; + } + return frequency; + } +} From d31e2cea50ac7345e6cfc661ef5fc6a0335a474e Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 25 Dec 2021 14:55:22 +0100 Subject: [PATCH 456/947] solves find subsequence of length k with the largest sum --- README.md | 2 +- ...SubsequenceOfLengthKWithTheLargestSum.java | 51 +++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 src/FindSubsequenceOfLengthKWithTheLargestSum.java diff --git a/README.md b/README.md index fcccaed..afeaf1e 100644 --- a/README.md +++ b/README.md @@ -497,5 +497,5 @@ | 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) | | | +| 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) | | | diff --git a/src/FindSubsequenceOfLengthKWithTheLargestSum.java b/src/FindSubsequenceOfLengthKWithTheLargestSum.java new file mode 100644 index 0000000..386c787 --- /dev/null +++ b/src/FindSubsequenceOfLengthKWithTheLargestSum.java @@ -0,0 +1,51 @@ +// https://leetcode.com/problems/find-subsequence-of-length-k-with-the-largest-sum +// T: O(nloogn + klogk) +// S: o(n) + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; + +public class FindSubsequenceOfLengthKWithTheLargestSum { + public int[] maxSubsequence(int[] nums, int k) { + Listnumbers = toNumbersList(nums); + numbers.sort(Comparator.comparingInt(a -> a.value)); + List topK = getLastK(numbers, k); + topK.sort(Comparator.comparing(a -> a.index)); + return toArray(topK); + } + + private List toNumbersList(int[] array) { + final List numbers = new ArrayList<>(array.length); + for (int index = 0 ; index < array.length ; index++) { + numbers.add(new Number(array[index], index)); + } + return numbers; + } + + private List getLastK(List numbers, int k) { + final List result = new ArrayList<>(); + for (int i = 0 ; i < k ; i++) { + result.add(numbers.get(numbers.size() - 1 - i)); + } + return result; + } + + private int[] toArray(List numbers) { + final int[] array = new int[numbers.size()]; + for (int i = 0 ; i < array.length ; i++) { + array[i] = numbers.get(i).value; + } + return array; + } + + private static final class Number { + private final int value; + private final int index; + + private Number(int value, int index) { + this.value = value; + this.index = index; + } + } +} From 72ca04112a078c86ddec20c96be036ef650f3819 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 25 Dec 2021 15:01:16 +0100 Subject: [PATCH 457/947] solves rings and rods --- README.md | 2 +- src/RingsAndRods.java | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/RingsAndRods.java diff --git a/README.md b/README.md index afeaf1e..ef31130 100644 --- a/README.md +++ b/README.md @@ -498,4 +498,4 @@ | 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) | | | +| 2103 | [Rings and Rods](https://leetcode.com/problems/rings-and-rods) | [![Java](assets/java.png)](src/RingsAndRods.java) | | diff --git a/src/RingsAndRods.java b/src/RingsAndRods.java new file mode 100644 index 0000000..49f45fa --- /dev/null +++ b/src/RingsAndRods.java @@ -0,0 +1,32 @@ +// https://leetcode.com/problems/rings-and-rods +// T: O(|rings|) +// S: O(1) + +public class RingsAndRods { + public int countPoints(String rings) { + final boolean[][] rods = new boolean[10][3]; + for (int i = 0 ; i < rings.length() ; i += 2) { + rods[rings.charAt(i + 1) - '0'][toColorIndex(rings.charAt(i))] = true; + } + int points = 0; + for (boolean[] rod : rods) { + if (containsAllColors(rod)) { + points++; + } + } + return points; + } + + private int toColorIndex(char color) { + return switch (color) { + case 'R' -> 0; + case 'G' -> 1; + case 'B' -> 2; + default -> -1; + }; + } + + private boolean containsAllColors(boolean[] rod) { + return rod[0] && rod[1] && rod[2]; + } +} From b1b348c9ac559a3c299467a38a9d792e61bef0fc Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 25 Dec 2021 15:04:46 +0100 Subject: [PATCH 458/947] solvesfind first palindrome string in array --- README.md | 1 + src/FindFirstPalindromicStringInArray.java | 23 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 src/FindFirstPalindromicStringInArray.java diff --git a/README.md b/README.md index ef31130..3f38a59 100644 --- a/README.md +++ b/README.md @@ -499,3 +499,4 @@ | 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) | | diff --git a/src/FindFirstPalindromicStringInArray.java b/src/FindFirstPalindromicStringInArray.java new file mode 100644 index 0000000..1060b82 --- /dev/null +++ b/src/FindFirstPalindromicStringInArray.java @@ -0,0 +1,23 @@ +// https://leetcode.com/problems/find-first-palindromic-string-in-the-array +// T: O(|words| * len(words[i])) +// S: O(1) + +public class FindFirstPalindromicStringInArray { + public String firstPalindrome(String[] words) { + for (String word : words) { + if (isPalindrome(word)) { + return word; + } + } + return ""; + } + + private boolean isPalindrome(String s) { + for (int i = 0; i < s.length() / 2 ; i++) { + if (s.charAt(i) != s.charAt(s.length() - 1 - i)) { + return false; + } + } + return true; + } +} From e68c2b7fa4c7e9f04d62b4c6c244d44ff3d5027c Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 25 Dec 2021 15:06:01 +0100 Subject: [PATCH 459/947] updates stats --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3f38a59..d6a19a9 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-400/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-400/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-422/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-422/2081-1abc9c.svg) ![problems-solved-python](https://img.shields.io/badge/Python-186/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) From 226d1e28d10f68bf9e1856c5c9ab08d9746a747d Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 25 Dec 2021 15:22:19 +0100 Subject: [PATCH 460/947] solves add two numbers --- README.md | 1 + src/AddTwoNumbers.java | 44 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 src/AddTwoNumbers.java diff --git a/README.md b/README.md index d6a19a9..79854e5 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ | # | 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) | | | 7 | [Reverse Integer](https://leetcode.com/problems/reverse-integer/) | [![Java](assets/java.png)](src/ReverseInteger.java) [![Python](assets/python.png)](python/reverse_integer.py) | [![java-yt](assets/java-yt.png)](https://youtu.be/7bOhyl5lWjI) [![python-yt](assets/python-yt.png)](https://youtu.be/lmLG30TLcSg) | | 9 | [PalindromeNumber](https://leetcode.com/problems/palindrome-number/) | [![Java](assets/java.png)](src/PalindromeNumber.java) [![Python](assets/python.png)](python/palindrome_number.py) | | | 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) | diff --git a/src/AddTwoNumbers.java b/src/AddTwoNumbers.java new file mode 100644 index 0000000..0e44c1b --- /dev/null +++ b/src/AddTwoNumbers.java @@ -0,0 +1,44 @@ +// https://leetcode.com/problems/add-two-numbers +// T: O(max(|l1|, |l2|)) +// S: O(max(|l1|, |l2|)) + +public class AddTwoNumbers { + public ListNode addTwoNumbers(ListNode l1, ListNode l2) { + ListNode result = new ListNode(); + ListNode current = result; + int carry = 0; + + while (l1 != null || l2 != null) { + current.next = new ListNode(); + current = current.next; + int sum = get(l1) + get(l2) + carry; + current.val = sum % 10; + carry = sum / 10; + l1 = next(l1); + l2 = next(l2); + } + if (carry > 0) { + current.next = new ListNode(carry); + } + + return result.next; + } + + private ListNode next(ListNode node) { + if (node == null) return null; + return node.next; + } + + private int get(ListNode node) { + if (node == null) return 0; + return node.val; + } + + public static class ListNode { + int val; + ListNode next; + ListNode() {} + ListNode(int val) { this.val = val; } + ListNode(int val, ListNode next) { this.val = val; this.next = next; } + } +} From 5eb3f90f3c175b7fd8ddb29c9535339a82e5a71f Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 25 Dec 2021 15:36:34 +0100 Subject: [PATCH 461/947] solves longestsubstring with repeating characters --- README.md | 1 + ...stSubstringWithoutRepeatingCharacters.java | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 src/LongestSubstringWithoutRepeatingCharacters.java diff --git a/README.md b/README.md index 79854e5..29de247 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ |:----:|-----------------------------------------------------------------------------------------------------------------------------------------------------------|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:---------------------------------------------------------------------------------------------------------------------------------:| | 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) | | +| 3 | [Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters) | [![Java](assets/java.png)](src/LongestSubstringWithoutRepeatingCharacters.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) | [![java-yt](assets/java-yt.png)](https://youtu.be/7bOhyl5lWjI) [![python-yt](assets/python-yt.png)](https://youtu.be/lmLG30TLcSg) | | 9 | [PalindromeNumber](https://leetcode.com/problems/palindrome-number/) | [![Java](assets/java.png)](src/PalindromeNumber.java) [![Python](assets/python.png)](python/palindrome_number.py) | | | 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) | diff --git a/src/LongestSubstringWithoutRepeatingCharacters.java b/src/LongestSubstringWithoutRepeatingCharacters.java new file mode 100644 index 0000000..e70f68b --- /dev/null +++ b/src/LongestSubstringWithoutRepeatingCharacters.java @@ -0,0 +1,23 @@ +// https://leetcode.com/problems/longest-substring-without-repeating-characters +// T: O(|s|) +// S: O(1) + +import java.util.HashSet; +import java.util.Set; + +public class LongestSubstringWithoutRepeatingCharacters { + public int lengthOfLongestSubstring(String s) { + final Set letters = new HashSet<>(); + int maxLength = 1; + for (int i = 0, j = 0 ; i < s.length() ; i++) { + if (letters.contains(s.charAt(i))) { + while (letters.contains(s.charAt(i))) { + letters.remove(s.charAt(j++)); + } + } + letters.add(s.charAt(i)); + maxLength = Math.max(maxLength, i - j + 1); + } + return maxLength; + } +} From c547bf268543eb57b2e90e98dc0d6e8817396f77 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 25 Dec 2021 16:51:49 +0100 Subject: [PATCH 462/947] solves longest common subsequence --- README.md | 1 + src/LongestCommonSubsequence.java | 39 +++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 src/LongestCommonSubsequence.java diff --git a/README.md b/README.md index 29de247..d0de7f4 100644 --- a/README.md +++ b/README.md @@ -306,6 +306,7 @@ | 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) | | | diff --git a/src/LongestCommonSubsequence.java b/src/LongestCommonSubsequence.java new file mode 100644 index 0000000..1091a53 --- /dev/null +++ b/src/LongestCommonSubsequence.java @@ -0,0 +1,39 @@ +public class LongestCommonSubsequence { + public int longestCommonSubsequence(String text1, String text2) { + final int[][] memory = new int[2][text2.length()]; + final int rows = text1.length(), columns = text2.length(); + + // first row, first column + memory[0][0] = text1.charAt(0) == text2.charAt(0) ? 1 : 0; + + // first row + for (int column = 1 ; column < columns ; column++) { + memory[0][column] = text2.charAt(column) == text1.charAt(0) ? 1 : memory[0][column - 1]; + } + + int i = 1; + // rest of table + for (int row = 1 ; row < rows ; row++, i ^= 1) { + for (int column = 0 ; column < text2.length() ; column++) { + if (column == 0) { + memory[i][column] = text1.charAt(row) == text2.charAt(0) ? 1 : memory[i ^ 1][column]; + } else { + memory[i][column] = max( + memory[i][column - 1], + memory[i ^ 1][column], + text1.charAt(row) == text2.charAt(column) ? 1 + memory[i ^ 1][column - 1] : 0 + ); + } + } + } + return memory[i ^ 1][columns - 1]; + } + + private int max(int... values) { + int result = 0; + for (int value : values) { + result = Math.max(result, value); + } + return result; + } +} From 2456384daa3118a16ed42fe98d58a25b73b24d6f Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 25 Dec 2021 16:52:08 +0100 Subject: [PATCH 463/947] solves longest common subsequence --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d0de7f4..2e49f05 100644 --- a/README.md +++ b/README.md @@ -306,7 +306,7 @@ | 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) | | +| 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) | | | From e8663329c6ae6c26487df27c2e7c00d9a9b79484 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 25 Dec 2021 23:17:09 +0100 Subject: [PATCH 464/947] solves maximum length of repeated subarray --- README.md | 1 + src/MaximumLengthOfRepeatedSubArray.java | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/MaximumLengthOfRepeatedSubArray.java diff --git a/README.md b/README.md index 2e49f05..362e74d 100644 --- a/README.md +++ b/README.md @@ -200,6 +200,7 @@ | 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) | | diff --git a/src/MaximumLengthOfRepeatedSubArray.java b/src/MaximumLengthOfRepeatedSubArray.java new file mode 100644 index 0000000..ffc00c5 --- /dev/null +++ b/src/MaximumLengthOfRepeatedSubArray.java @@ -0,0 +1,21 @@ +// longest common subarray / longest common substring length +// https://leetcode.com/problems/maximum-length-of-repeated-subarray +// T: O(|nums1| * |nums2|) +// S: O(min(|nums1|, |nums2|)) + +public class MaximumLengthOfRepeatedSubArray { + public int findLength(int[] nums1, int[] nums2) { + final int rows = nums1.length + 1, columns = nums2.length + 1; + final int[][] memory = new int[2][columns]; + int maxValue = 0; + + for (int row = 1, i = 1 ; row < rows ; row++, i ^= 1) { + for (int column = 1 ; column < columns ; column++) { + memory[i][column] = nums1[row - 1] == nums2[column - 1] ? 1 + memory[i ^ 1][column - 1] : 0; + maxValue = Math.max(maxValue, memory[i][column]); + } + } + + return maxValue; + } +} From 678ed88d457c9d5a9d240156206af50fb65c89b9 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 25 Dec 2021 23:38:26 +0100 Subject: [PATCH 465/947] solves longest palindromic substring --- src/LongestPalindromicSubstring.java | 35 ++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/LongestPalindromicSubstring.java diff --git a/src/LongestPalindromicSubstring.java b/src/LongestPalindromicSubstring.java new file mode 100644 index 0000000..9b92e19 --- /dev/null +++ b/src/LongestPalindromicSubstring.java @@ -0,0 +1,35 @@ +// https://leetcode.com/problems/longest-palindromic-substring + +public class LongestPalindromicSubstring { + public static void main(String[] args) { + System.out.println(isPalindrome("caba", 1, 4)); + } + + public static String longestPalindrome(String s) { + final String s2 = new StringBuilder(s).reverse().toString(); + final int rows = s.length() + 1, columns = s2.length() + 1; + final int[][] dp = new int[2][columns]; + int maxLength = 0, startIndex = -1; + + for (int row = 1, i = 1 ; row < rows ; row++, i ^= 1) { + for (int column = 1 ; column < columns ; column++) { + dp[i][column] = s.charAt(row - 1) == s2.charAt(column - 1) ? dp[i ^ 1][column - 1] + 1 : 0; + if (dp[i][column] > maxLength && isPalindrome(s, row - dp[i][column], row)) { + maxLength = dp[i][column]; + startIndex = row - maxLength; + } + } + } + + return s.substring(startIndex, startIndex + maxLength); + } + + private static boolean isPalindrome(String s, int start, int end) { + for (int i = start ; i < start + (end - start) / 2 ; i++) { + if (s.charAt(i) != s.charAt(end - i - 1 + start)) { + return false; + } + } + return true; + } +} From c8a256f3f4fd5959e33ed53dd1a2aec6ba63a1c3 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 26 Dec 2021 11:47:30 +0100 Subject: [PATCH 466/947] solves longest palindromic substring --- README.md | 1 + src/LongestPalindromicSubstring.java | 44 ++++++++++++---------------- 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 362e74d..66532b3 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ | 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) | | | 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) | | | 7 | [Reverse Integer](https://leetcode.com/problems/reverse-integer/) | [![Java](assets/java.png)](src/ReverseInteger.java) [![Python](assets/python.png)](python/reverse_integer.py) | [![java-yt](assets/java-yt.png)](https://youtu.be/7bOhyl5lWjI) [![python-yt](assets/python-yt.png)](https://youtu.be/lmLG30TLcSg) | | 9 | [PalindromeNumber](https://leetcode.com/problems/palindrome-number/) | [![Java](assets/java.png)](src/PalindromeNumber.java) [![Python](assets/python.png)](python/palindrome_number.py) | | | 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) | diff --git a/src/LongestPalindromicSubstring.java b/src/LongestPalindromicSubstring.java index 9b92e19..661021d 100644 --- a/src/LongestPalindromicSubstring.java +++ b/src/LongestPalindromicSubstring.java @@ -1,35 +1,29 @@ // https://leetcode.com/problems/longest-palindromic-substring +// T: O(n^2) +// S: O(1) public class LongestPalindromicSubstring { - public static void main(String[] args) { - System.out.println(isPalindrome("caba", 1, 4)); - } - - public static String longestPalindrome(String s) { - final String s2 = new StringBuilder(s).reverse().toString(); - final int rows = s.length() + 1, columns = s2.length() + 1; - final int[][] dp = new int[2][columns]; - int maxLength = 0, startIndex = -1; - - for (int row = 1, i = 1 ; row < rows ; row++, i ^= 1) { - for (int column = 1 ; column < columns ; column++) { - dp[i][column] = s.charAt(row - 1) == s2.charAt(column - 1) ? dp[i ^ 1][column - 1] + 1 : 0; - if (dp[i][column] > maxLength && isPalindrome(s, row - dp[i][column], row)) { - maxLength = dp[i][column]; - startIndex = row - maxLength; - } + public String longestPalindrome(String s) { + if (s.length() < 2) return s; + int maxLen = 0, startIndex = -1; + for (int i = 0, len ; i < s.length() - 1 ; i++) { + len = palindromeLengthFromCenter(s, i, i); + if (s.charAt(i) == s.charAt(i + 1)) { + len = Math.max(len, palindromeLengthFromCenter(s, i, i + 1)); + } + if (len > maxLen) { + maxLen = len; + startIndex = i - (maxLen - 1) / 2; } } - - return s.substring(startIndex, startIndex + maxLength); + return s.substring(startIndex, startIndex + maxLen); } - private static boolean isPalindrome(String s, int start, int end) { - for (int i = start ; i < start + (end - start) / 2 ; i++) { - if (s.charAt(i) != s.charAt(end - i - 1 + start)) { - return false; - } + private int palindromeLengthFromCenter(String s, int left, int right) { + while (left - 1 >= 0 && right + 1 < s.length() && s.charAt(left - 1) == s.charAt(right + 1)) { + left--; + right++; } - return true; + return right - left + 1; } } From b22ccb4b3d49e6c087742d6daf35674943f1a7d6 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 26 Dec 2021 12:03:17 +0100 Subject: [PATCH 467/947] solves zigzag conversion --- README.md | 1 + src/ZigZagConversion.java | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/ZigZagConversion.java diff --git a/README.md b/README.md index 66532b3..efd7a40 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ | 2 | [Add Two Numbers](https://leetcode.com/problems/add-two-numbers) | [![Java](assets/java.png)](src/AddTwoNumbers.java) | | | 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) | [![java-yt](assets/java-yt.png)](https://youtu.be/7bOhyl5lWjI) [![python-yt](assets/python-yt.png)](https://youtu.be/lmLG30TLcSg) | | 9 | [PalindromeNumber](https://leetcode.com/problems/palindrome-number/) | [![Java](assets/java.png)](src/PalindromeNumber.java) [![Python](assets/python.png)](python/palindrome_number.py) | | | 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) | diff --git a/src/ZigZagConversion.java b/src/ZigZagConversion.java new file mode 100644 index 0000000..e70cd2b --- /dev/null +++ b/src/ZigZagConversion.java @@ -0,0 +1,31 @@ +// https://leetcode.com/problems/zigzag-conversion +// T: O(|s|) +// S: O(|s|) + +public class ZigZagConversion { + public static String convert(String s, int numRows) { + if (numRows == 1) return s; + final StringBuilder result = new StringBuilder(); + final int jumpSize = (numRows - 1) * 2; + + // first row + for (int i = 0 ; i < s.length() ; i += jumpSize) { + result.append(s.charAt(i)); + } + + for (int row = 1 ; row < numRows - 1 ; row++) { + int[] jumps = {jumpSize - 2 * row, 2 * row}; + for (int i = row, k = 0 ; i < s.length() ; k ^= 1) { + result.append(s.charAt(i)); + i += jumps[k]; + } + } + + // last row + for (int i = numRows - 1 ; i < s.length() ; i += jumpSize) { + result.append(s.charAt(i)); + } + + return result.toString(); + } +} From 4edda66068b13bd18422c59e5cc03f60e88c6a84 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 26 Dec 2021 12:15:41 +0100 Subject: [PATCH 468/947] solves 8: string to atoi --- README.md | 1 + src/StringToIntegerAtoi.java | 45 ++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 src/StringToIntegerAtoi.java diff --git a/README.md b/README.md index efd7a40..dcd5259 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ | 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) | [![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 | [PalindromeNumber](https://leetcode.com/problems/palindrome-number/) | [![Java](assets/java.png)](src/PalindromeNumber.java) [![Python](assets/python.png)](python/palindrome_number.py) | | | 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) | | diff --git a/src/StringToIntegerAtoi.java b/src/StringToIntegerAtoi.java new file mode 100644 index 0000000..bd8d8f5 --- /dev/null +++ b/src/StringToIntegerAtoi.java @@ -0,0 +1,45 @@ +// https://leetcode.com/problems/string-to-integer-atoi +// T:O(|input|) +// S:O(1) + +public class StringToIntegerAtoi { + public int myAtoi(String input) { + int sign = 1; + int result = 0; + int index = 0; + int n = input.length(); + + // Discard all spaces from the beginning of the input string. + while (index < n && input.charAt(index) == ' ') { + index++; + } + + // sign = +1, if it's positive number, otherwise sign = -1. + if (index < n && input.charAt(index) == '+') { + index++; + } else if (index < n && input.charAt(index) == '-') { + sign = -1; + index++; + } + + // Traverse next digits of input and stop if it is not a digit + while (index < n && Character.isDigit(input.charAt(index))) { + int digit = input.charAt(index) - '0'; + + // Check overflow and underflow conditions. + if ((result > Integer.MAX_VALUE / 10) || + (result == Integer.MAX_VALUE / 10 && digit > Integer.MAX_VALUE % 10)) { + // If integer overflowed return 2^31-1, otherwise if underflowed return -2^31. + return sign == 1 ? Integer.MAX_VALUE : Integer.MIN_VALUE; + } + + // Append current digit to the result. + result = 10 * result + digit; + index++; + } + + // We have formed a valid number without any overflow/underflow. + // Return it after multiplying it with its sign. + return sign * result; + } +} From 5e3804e9cdbe0f07f77430142939fa52e0559ca4 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 26 Dec 2021 12:40:32 +0100 Subject: [PATCH 469/947] solves container with most water --- README.md | 1 + src/ContainerWitMostWater.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 src/ContainerWitMostWater.java diff --git a/README.md b/README.md index dcd5259..a4a3a66 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ | 7 | [Reverse Integer](https://leetcode.com/problems/reverse-integer/) | [![Java](assets/java.png)](src/ReverseInteger.java) [![Python](assets/python.png)](python/reverse_integer.py) | [![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 | [PalindromeNumber](https://leetcode.com/problems/palindrome-number/) | [![Java](assets/java.png)](src/PalindromeNumber.java) [![Python](assets/python.png)](python/palindrome_number.py) | | +| 11 | [Container With Most Water](https://leetcode.com/problems/container-with-most-water) | [![Java](assets/java.png)](src/ContainerWitMostWater.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) | | | 20 | [ValidParentheses](https://leetcode.com/problems/valid-parentheses/) | [![Java](assets/java.png)](src/ValidParentheses.java) [![Python](assets/python.png)](python/valid_parentheses.py) | | diff --git a/src/ContainerWitMostWater.java b/src/ContainerWitMostWater.java new file mode 100644 index 0000000..d2d1a3a --- /dev/null +++ b/src/ContainerWitMostWater.java @@ -0,0 +1,15 @@ +// https://leetcode.com/problems/container-with-most-water +// T: O(n) +// S: O(1) + +public class ContainerWitMostWater { + public static int maxArea(int[] height) { + int water = 0; + for (int i = 0, j = height.length - 1; i < j; ) { + water = Math.max(water, Math.min(height[i], height[j]) * (j - i)); + if (height[i] > height[j]) j--; + else i++; + } + return water; + } +} From 5faaca7ad487c6163c8aed69153879db231f4836 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 26 Dec 2021 13:07:58 +0100 Subject: [PATCH 470/947] solves integer to roman --- README.md | 1 + src/IntegerToRoman.java | 62 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 src/IntegerToRoman.java diff --git a/README.md b/README.md index a4a3a66..ee4d394 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ | 8 | [String to Integer (atoi)](https://leetcode.com/problems/string-to-integer-atoi) | [![Java](assets/java.png)](src/StringToIntegerAtoi.java) | | | 9 | [PalindromeNumber](https://leetcode.com/problems/palindrome-number/) | [![Java](assets/java.png)](src/PalindromeNumber.java) [![Python](assets/python.png)](python/palindrome_number.py) | | | 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) | | | 20 | [ValidParentheses](https://leetcode.com/problems/valid-parentheses/) | [![Java](assets/java.png)](src/ValidParentheses.java) [![Python](assets/python.png)](python/valid_parentheses.py) | | diff --git a/src/IntegerToRoman.java b/src/IntegerToRoman.java new file mode 100644 index 0000000..8668211 --- /dev/null +++ b/src/IntegerToRoman.java @@ -0,0 +1,62 @@ +// https://leetcode.com/problems/integer-to-roman +// 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") + ); + + 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; + } + return result.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 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); + default -> ""; + }; + } + + private String thousandsPlaceToRoman(int digit) { + return "M".repeat(digit); + } +} From 4ac058ada599e541402a0dfa0af0680962c911ff Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 26 Dec 2021 14:35:38 +0100 Subject: [PATCH 471/947] solves 3 sum --- README.md | 1 + src/ThreeSum.java | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/ThreeSum.java diff --git a/README.md b/README.md index ee4d394..7b6d28e 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ | 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) | | | 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) | | | 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) | | diff --git a/src/ThreeSum.java b/src/ThreeSum.java new file mode 100644 index 0000000..46ac050 --- /dev/null +++ b/src/ThreeSum.java @@ -0,0 +1,25 @@ +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 ThreeSum { + public List> threeSum(int[] nums) { + if (nums.length < 3) return Collections.emptyList(); + final Set> triplets = new HashSet<>(); + Arrays.sort(nums); + + for (int i = 0; i < nums.length - 2; i++) { + for (int j = i + 1, k = nums.length - 1 ; j < k ; ) { + int sum = nums[i] + nums[j] + nums[k]; + if (sum == 0) triplets.add(List.of(nums[i], nums[j++], nums[k--])); + else if (sum > 0) k--; + else j++; + } + } + + return new ArrayList<>(triplets); + } +} From 3700b4e7ba91cc610156ebdbb000fc56fff49793 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 26 Dec 2021 21:40:52 +0100 Subject: [PATCH 472/947] solves 3 sum closest --- README.md | 1 + src/ThreeSumClosest.java | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/ThreeSumClosest.java diff --git a/README.md b/README.md index 7b6d28e..b52830f 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ | 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) | | | 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) | | | 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) | | diff --git a/src/ThreeSumClosest.java b/src/ThreeSumClosest.java new file mode 100644 index 0000000..67fcea4 --- /dev/null +++ b/src/ThreeSumClosest.java @@ -0,0 +1,28 @@ +// https://leetcode.com/problems/3sum-closest +// T: O(n^2) +// S: O(1) + +import java.util.Arrays; + +public class ThreeSumClosest { + public static void main(String[] args) { + System.out.println(threeSumClosest(new int[] {0, 2, 1, -3}, 1)); + } + + public static int threeSumClosest(int[] nums, int target) { + Arrays.sort(nums); + int closestSum = nums[0] + nums[1] + nums[2]; + for (int i = 0 ; i < nums.length - 2 ; i++) { + for (int j = i + 1, k = nums.length - 1 ; j < k ; ) { + int sum = nums[i] + nums[j] + nums[k]; + if (sum == target) return sum; + if (Math.abs(sum - target) < Math.abs(closestSum - target)) { + closestSum = sum; + } + else if (sum > target) k--; + else j++; + } + } + return closestSum; + } +} From 560d583762a7c252ce4d2f6879a883c87da20655 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 26 Dec 2021 21:51:41 +0100 Subject: [PATCH 473/947] solves letter combinations of phone numbers --- README.md | 1 + src/LetterCombinationsOfAPhoneNumber.java | 35 +++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/LetterCombinationsOfAPhoneNumber.java diff --git a/README.md b/README.md index b52830f..b4807e5 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ | 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) | | | 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) | | | 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) | | diff --git a/src/LetterCombinationsOfAPhoneNumber.java b/src/LetterCombinationsOfAPhoneNumber.java new file mode 100644 index 0000000..31bfd39 --- /dev/null +++ b/src/LetterCombinationsOfAPhoneNumber.java @@ -0,0 +1,35 @@ +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Set; + +public class LetterCombinationsOfAPhoneNumber { + private static final Map> NUMBER_TO_CHARS = Map.ofEntries( + Map.entry('2', Set.of('a', 'b', 'c')), + Map.entry('3', Set.of('d', 'e', 'f')), + Map.entry('4', Set.of('g', 'h', 'i')), + Map.entry('5', Set.of('j', 'k', 'l')), + Map.entry('6', Set.of('m', 'n', 'o')), + Map.entry('7', Set.of('p', 'q', 'r', 's')), + Map.entry('8', Set.of('t', 'u', 'v')), + Map.entry('9', Set.of('w', 'x', 'y', 'z')) + ); + + public List letterCombinations(String digits) { + if (digits.isEmpty()) return Collections.emptyList(); + final List result = new ArrayList<>(); + addLetterCombinationsToResult(digits, 0, "", result); + return result; + } + + private void addLetterCombinationsToResult(String s, int i, String current, List result) { + if (i == s.length()) { + result.add(current); + return; + } + for (char character : NUMBER_TO_CHARS.get(s.charAt(i))) { + addLetterCombinationsToResult(s, i + 1, current + character, result); + } + } +} From 35c853b89b48bcccafb25f8259a1bb6dd5c3f7f6 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 26 Dec 2021 22:01:37 +0100 Subject: [PATCH 474/947] solves 4 sum --- README.md | 1 + src/FourSum.java | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/FourSum.java diff --git a/README.md b/README.md index b4807e5..6668b44 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ | 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) | | | 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) | | | 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) | | diff --git a/src/FourSum.java b/src/FourSum.java new file mode 100644 index 0000000..b17a273 --- /dev/null +++ b/src/FourSum.java @@ -0,0 +1,25 @@ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class FourSum { + public List> fourSum(int[] nums, int target) { + Arrays.sort(nums); + final Set> quadruplets = new HashSet<>(); + + for (int a = 0 ; a < nums.length - 3 ; a++) { + for (int b = a + 1 ; b < nums.length - 2 ; b++) { + for (int c = b + 1, d = nums.length - 1 ; c < d ; ) { + int sum = nums[a] + nums[b] + nums[c] + nums[d]; + if (sum == target) quadruplets.add(List.of(nums[a], nums[b], nums[c++], nums[d--])); + else if (sum < target) c++; + else d--; + } + } + } + + return new ArrayList<>(quadruplets); + } +} From 2fe8532c6518e5475840327bca1be317e833171f Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 26 Dec 2021 22:07:50 +0100 Subject: [PATCH 475/947] solves remove nth node from end of linked list --- README.md | 1 + src/RemoveNthNodeFromEndOfList.java | 32 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/RemoveNthNodeFromEndOfList.java diff --git a/README.md b/README.md index 6668b44..e7324a1 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ | 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) | | | 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) | | diff --git a/src/RemoveNthNodeFromEndOfList.java b/src/RemoveNthNodeFromEndOfList.java new file mode 100644 index 0000000..3c9d440 --- /dev/null +++ b/src/RemoveNthNodeFromEndOfList.java @@ -0,0 +1,32 @@ + +public class RemoveNthNodeFromEndOfList { + public static class ListNode { + int val; + ListNode next; + ListNode() {} + ListNode(int val) { this.val = val; } + ListNode(int val, ListNode next) { this.val = val; this.next = next; } + } + + public ListNode removeNthFromEnd(ListNode head, int n) { + final int length = length(head); + final int removalIndex = length - n; + if (removalIndex == 0) return head.next; + ListNode current = head; + for (int i = 0 ; i < removalIndex - 1 ; i++) { + current = current.next; + } + current.next = current.next.next; + return head; + } + + private int length(ListNode head) { + int count = 0; + ListNode current = head; + while (current != null) { + count++; + current = current.next; + } + return count; + } +} From dbad318c2a271aee435e28037a183254f4e3dc32 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 26 Dec 2021 22:20:58 +0100 Subject: [PATCH 476/947] solves git add . --- src/GenerateParentheses.java | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/GenerateParentheses.java diff --git a/src/GenerateParentheses.java b/src/GenerateParentheses.java new file mode 100644 index 0000000..3417e29 --- /dev/null +++ b/src/GenerateParentheses.java @@ -0,0 +1,40 @@ +// https://leetcode.com/problems/generate-parentheses +// T: O(Catalan-number(n)) or O(4^n/sqrt(n)) +// S: O(Catalan-number(n)) or O(4^n/sqrt(n)) + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class GenerateParentheses { + private static final Map> VALID_PARENTHESES = new HashMap<>(); + + static { + VALID_PARENTHESES.put(0, List.of("")); + VALID_PARENTHESES.put(1, List.of("()")); + for (int i = 2 ; i <= 8 ; i++) { + addValidParentheses(i); + } + } + + private static void addValidParentheses(int i) { + final List result = new ArrayList<>(); + addValidParentheses(i, result); + VALID_PARENTHESES.put(i, result); + } + + private static void addValidParentheses(int i, List result) { + for (int k = 0 ; k < i ; k++) { + for (String s1 : VALID_PARENTHESES.get(i - k - 1)) { + for (String s2 : VALID_PARENTHESES.get(k)) { + result.add("(" + s1 + ")" + s2); + } + } + } + } + + public List generateParenthesis(int n) { + return VALID_PARENTHESES.get(n); + } +} From 75e62405b3a986f743cac5e9461c55102bf1f331 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 26 Dec 2021 22:21:21 +0100 Subject: [PATCH 477/947] solves generate parantheses --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e7324a1..044b5fc 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ | 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) | | | 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) | | | 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) | | From 4b446ebb19d565392dc29fa0ded10333804c24a8 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 26 Dec 2021 22:50:39 +0100 Subject: [PATCH 478/947] solves swap nodes in pairs --- README.md | 1 + src/SwapNodesInPairs.java | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 src/SwapNodesInPairs.java diff --git a/README.md b/README.md index 044b5fc..939e75f 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ | 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) | | | 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/SwapNodesInPairs.java b/src/SwapNodesInPairs.java new file mode 100644 index 0000000..99ce5d7 --- /dev/null +++ b/src/SwapNodesInPairs.java @@ -0,0 +1,29 @@ +// https://leetcode.com/problems/swap-nodes-in-pairs +// T: O(n) +// S: O(1) + +public class SwapNodesInPairs { + private static class ListNode { + int val; + ListNode next; + + ListNode(int val, ListNode next) { + this.val = val; + this.next = next; + } + } + + public ListNode swapPairs(ListNode head) { + if (head == null || head.next == null) return head; + ListNode newHead = head.next, a = head, b = head.next.next, temp; + head.next.next = head; + while (a != null) { + a.next = (b == null || b.next == null ? b : b.next); + temp = (b == null || b.next == null ? null : b.next.next); + if (b != null && b.next != null) b.next.next = b; + a = b; + b = temp; + } + return newHead; + } +} From 542c263fc14a4d0e52af9290d7f7034c2f68d983 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 26 Dec 2021 23:01:14 +0100 Subject: [PATCH 479/947] solves divide two integers --- README.md | 1 + src/DivideTwoIntegers.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 src/DivideTwoIntegers.java diff --git a/README.md b/README.md index 939e75f..f85261b 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ | 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) | | | 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) | | | 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) | | | 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) | | | 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) | | diff --git a/src/DivideTwoIntegers.java b/src/DivideTwoIntegers.java new file mode 100644 index 0000000..ce2be9f --- /dev/null +++ b/src/DivideTwoIntegers.java @@ -0,0 +1,16 @@ +// https://leetcode.com/problems/divide-two-integers +// T: O(A / B) +// S: O(1) + +public class DivideTwoIntegers { + public int divide(int A, int B) { + if (A == 1 << 31 && B == -1) return (1 << 31) - 1; + int a = Math.abs(A), b = Math.abs(B), res = 0, x = 0; + while (a - b >= 0) { + for (x = 0; a - (b << x << 1) >= 0; x++); + res += 1 << x; + a -= b << x; + } + return (A > 0) == (B > 0) ? res : -res; + } +} From d5a84e9179a4c3427890313a933fe1950fbcdabc Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 26 Dec 2021 23:51:14 +0100 Subject: [PATCH 480/947] solves nextpermutation --- README.md | 1 + src/NextPermutation.java | 42 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 src/NextPermutation.java diff --git a/README.md b/README.md index f85261b..8b6b1b9 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,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) | | +| 31 | [Next Permutation](https://leetcode.com/problems/next-permutation) | [![Java](assets/java.png)](src/NextPermutation.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) | | | 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) | | | 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) | | diff --git a/src/NextPermutation.java b/src/NextPermutation.java new file mode 100644 index 0000000..2b85462 --- /dev/null +++ b/src/NextPermutation.java @@ -0,0 +1,42 @@ +// https://leetcode.com/problems/next-permutation +// T: O(|nums|) +// S: O(1) + +public class NextPermutation { + public void nextPermutation(int[] nums) { + for (int i = nums.length - 2 ; i >= 0 ; i--) { + if (nums[i] < nums[i + 1]) { + int index = indexOfNextLargest(nums, i + 1, nums[i]); + swap(nums, i, index); + reverse(nums, i + 1, nums.length); + return; + } + } + reverse(nums); + } + + private void swap(int[] array, int i, int j) { + int temp = array[i]; + array[i] = array[j]; + array[j] = temp; + } + + private int indexOfNextLargest(int[] array, int start, int x) { + for (int i = start ; i < array.length ; i++) { + if (array[i] <= x) { + return i - 1; + } + } + return array.length - 1; + } + + private void reverse(int[] array) { + reverse(array, 0, array.length); + } + + private void reverse(int[] array, int start, int end) { + for (int i = start ; i < start + (end - start) / 2 ; i++) { + swap(array, i, end - i + start - 1); + } + } +} From 5d65e228ff594e056676fc59cb3a1926388d899b Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Wed, 5 Jan 2022 13:15:35 +0100 Subject: [PATCH 481/947] solves search in rotated sorted array --- README.md | 1 + src/SearchInRotatedSortedArray.java | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/SearchInRotatedSortedArray.java diff --git a/README.md b/README.md index 8b6b1b9..9bac5ae 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ | 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) | | | 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) | | | 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) | | | 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) | | diff --git a/src/SearchInRotatedSortedArray.java b/src/SearchInRotatedSortedArray.java new file mode 100644 index 0000000..f689436 --- /dev/null +++ b/src/SearchInRotatedSortedArray.java @@ -0,0 +1,28 @@ +// https://leetcode.com/problems/search-in-rotated-sorted-array +// T: O(logN) +// SL 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; + } + return -1; + } + + private int minElementIndex(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; + } + return left; + } +} From 7462b517c7f2692115811e57cead06145eb93c5d Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Wed, 5 Jan 2022 13:22:46 +0100 Subject: [PATCH 482/947] solves find first and last position of element in sorted array --- README.md | 1 + ...AndLastPositionOfElementInSortedArray.java | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 src/FindFirstAndLastPositionOfElementInSortedArray.java diff --git a/README.md b/README.md index 9bac5ae..fef5bf1 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ | 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) | | +| 33 | [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) | | | 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) | | | 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) | | diff --git a/src/FindFirstAndLastPositionOfElementInSortedArray.java b/src/FindFirstAndLastPositionOfElementInSortedArray.java new file mode 100644 index 0000000..f2fc5e7 --- /dev/null +++ b/src/FindFirstAndLastPositionOfElementInSortedArray.java @@ -0,0 +1,38 @@ +// https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array +// T: O(logN) +// S: O(1) + +public class FindFirstAndLastPositionOfElementInSortedArray { + public int[] searchRange(int[] nums, int target) { + return new int[] { + leftMostIndex(nums, target), + rightMostIndex(nums, target) + }; + } + + private int leftMostIndex(int[] array, int target) { + int left = 0, right = array.length - 1, middle; + while (left <= right) { + middle = left + (right - left) / 2; + if (array[middle] == target) { + if (middle - 1 >= 0 && array[middle - 1] == target) right = middle - 1; + else return middle; + } else if (array[middle] > target) right = middle - 1; + else left = middle + 1; + } + return -1; + } + + private int rightMostIndex(int[] array, int target) { + int left = 0, right = array.length - 1, middle; + while (left <= right) { + middle = left + (right - left) / 2; + if (array[middle] == target) { + if (middle + 1 < array.length && array[middle + 1] == target) left = middle + 1; + else return middle; + } else if (array[middle] > target) right = middle - 1; + else left = middle + 1; + } + return -1; + } +} From 313ccfac07f147016558d9f0832b1897272d1eec Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Wed, 5 Jan 2022 13:57:14 +0100 Subject: [PATCH 483/947] solves valid sudoku --- README.md | 7 +++-- src/ValidSudoku.java | 72 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 src/ValidSudoku.java diff --git a/README.md b/README.md index fef5bf1..91ed6fb 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-422/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-422/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-442/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-442/2081-1abc9c.svg) ![problems-solved-python](https://img.shields.io/badge/Python-186/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) @@ -38,8 +38,9 @@ | 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) | | -| 33 | [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) | | +| 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) | | | 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) | | | 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) | | | 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) | | diff --git a/src/ValidSudoku.java b/src/ValidSudoku.java new file mode 100644 index 0000000..977b5de --- /dev/null +++ b/src/ValidSudoku.java @@ -0,0 +1,72 @@ +// https://leetcode.com/problems/valid-sudoku +// T: O(1) +// S: O(1) + +import java.util.HashSet; +import java.util.Set; + +public class ValidSudoku { + private static final int SUDOKU_SIZE = 9; + + public boolean isValidSudoku(char[][] board) { + if (repetitionInRows(board)) return false; + if (repetitionInColumns(board)) return false; + return !repetitionInBlocks(board); + } + + private boolean repetitionInRows(char[][] board) { + for (char[] row : board) { + if (repetitionInRow(row)) return true; + } + return false; + } + + private boolean repetitionInRow(char[] row) { + final Set digits = new HashSet<>(); + for (char character : row) { + if (Character.isDigit(character)) { + if (digits.contains(character)) return true; + digits.add(character); + } + } + return false; + } + + private boolean repetitionInColumns(char[][] board) { + final Set digits = new HashSet<>(); + for (int column = 0 ; column < SUDOKU_SIZE ; column++) { + digits.clear(); + for (int row = 0 ; row < SUDOKU_SIZE ; row++) { + char c = board[row][column]; + if (Character.isDigit(c)) { + if (digits.contains(c)) return true; + digits.add(c); + } + } + } + return false; + } + + private boolean repetitionInBlocks(char[][] board) { + for (int i = 0 ; i < SUDOKU_SIZE / 3 ; i++) { + for (int j = 0 ; j < SUDOKU_SIZE / 3 ; j++) { + if (repetitionInBlock(board, i, j)) return true; + } + } + return false; + } + + private boolean repetitionInBlock(final char[][] board, final int i, final int j) { + final Set digits = new HashSet<>(); + for (int row = 3 * i ; row < 3 * i + 3 ; row++) { + for (int column = 3 * j ; column < 3 * j + 3 ; column++) { + char c = board[row][column]; + if (Character.isDigit(c)) { + if (digits.contains(c)) return true; + digits.add(c); + } + } + } + return false; + } +} From 79fb2d493a786ca8d75228f4f3a0656090cac8b6 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Wed, 5 Jan 2022 14:12:40 +0100 Subject: [PATCH 484/947] solves combination sum --- README.md | 1 + src/CombinationSum.java | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/CombinationSum.java diff --git a/README.md b/README.md index 91ed6fb..7d4ff29 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ | 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) | | | 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) | | | 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) | | | 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) | | | 66 | [Plus One](https://leetcode.com/problems/plus-one) | [![Java](assets/java.png)](src/PlusOne.java) [![Python](assets/python.png)](python/plus_one.py) | | diff --git a/src/CombinationSum.java b/src/CombinationSum.java new file mode 100644 index 0000000..10ca632 --- /dev/null +++ b/src/CombinationSum.java @@ -0,0 +1,31 @@ +// 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 + +import java.util.ArrayList; +import java.util.List; + +public class CombinationSum { + private final List> result = new ArrayList<>(); + private int[] candidates; + private int target; + + public List> combinationSum(int[] candidates, int target) { + this.candidates = candidates; + this.target = target; + combinationSum(new ArrayList<>(), 0, 0); + return result; + } + + public void combinationSum(List current, int sum, int index) { + if (sum == target) { + result.add(current); + return; + } else if (sum > target) return; + for (int i = index ; i < candidates.length ; i++) { + List newCandidate = new ArrayList<>(current); + newCandidate.add(candidates[i]); + combinationSum(newCandidate, sum + candidates[i], i); + } + } +} From ccf18abe9812b0593351bad1bb61c79296af4e2a Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Wed, 5 Jan 2022 16:55:51 +0100 Subject: [PATCH 485/947] solves combination sum ii --- README.md | 1 + src/CombinationSumII.java | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 src/CombinationSumII.java diff --git a/README.md b/README.md index 7d4ff29..59b7c88 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ | 36 | [Valid Sudoku](https://leetcode.com/problems/valid-sudoku) | [![Java](assets/java.png)](src/ValidSudoku.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) | | | 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) | | | 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) | | | 66 | [Plus One](https://leetcode.com/problems/plus-one) | [![Java](assets/java.png)](src/PlusOne.java) [![Python](assets/python.png)](python/plus_one.py) | | diff --git a/src/CombinationSumII.java b/src/CombinationSumII.java new file mode 100644 index 0000000..c6cda11 --- /dev/null +++ b/src/CombinationSumII.java @@ -0,0 +1,39 @@ +// https://leetcode.com/problems/combination-sum-ii +// T: O(2^N) +// S: O(N) + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +public class CombinationSumII { + public List> combinationSum2(int[] candidates, int target) { + List> results = new ArrayList<>(); + LinkedList comb = new LinkedList<>(); + Arrays.sort(candidates); + backtrack(candidates, comb, target, 0, results); + return results; + } + + private void backtrack(int[] candidates, LinkedList comb, + int remain, int curr, + List> results) { + if (remain == 0) { + results.add(new ArrayList(comb)); + return; + } + + for (int nextCurr = curr; nextCurr < candidates.length; ++nextCurr) { + if (nextCurr > curr && candidates[nextCurr] == candidates[nextCurr - 1]) + continue; + + int pick = candidates[nextCurr]; + if (remain - pick < 0) break; + + comb.addLast(pick); + backtrack(candidates, comb, remain - pick, nextCurr + 1, results); + comb.removeLast(); + } + } +} From bb2a15e1cdd3d0ddc74bea02473646755dabc77e Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Wed, 5 Jan 2022 17:43:56 +0100 Subject: [PATCH 486/947] solves multiply strings --- README.md | 1 + src/MultiplyStrings.java | 49 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 src/MultiplyStrings.java diff --git a/README.md b/README.md index 59b7c88..447001b 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,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) | | +| 43 | [Multiply Strings](https://leetcode.com/problems/multiply-strings) | [![Java](assets/java.png)](src/MultiplyStrings.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) | | | 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) | | | 66 | [Plus One](https://leetcode.com/problems/plus-one) | [![Java](assets/java.png)](src/PlusOne.java) [![Python](assets/python.png)](python/plus_one.py) | | diff --git a/src/MultiplyStrings.java b/src/MultiplyStrings.java new file mode 100644 index 0000000..03cd382 --- /dev/null +++ b/src/MultiplyStrings.java @@ -0,0 +1,49 @@ +// https://leetcode.com/problems/multiply-strings +// T: O(|num1| * |num2|) +// S: O(|num1| + |num2|) + +public class MultiplyStrings { + private static final String ZERO = "0"; + private static final String ONE = "1"; + + public String multiply(String num1, String num2) { + if (ZERO.equals(num1) || ZERO.equals(num2)) return ZERO; + if (ONE.equals(num1)) return num2; + if (ONE.equals(num2)) return num1; + + StringBuilder result = new StringBuilder(ZERO); + for (int i = num2.length() - 1 ; i >= 0 ; i--) { + result = add(result, multiply(num1, num2.charAt(i) - '0', num2.length() - i - 1)); + } + return result.toString(); + } + + private StringBuilder multiply(String number, int digit, int factor) { + final StringBuilder result = new StringBuilder(); + int carry = 0; + for (int i = number.length() - 1 ; i >= 0 ; i--) { + int val = (number.charAt(i) - '0') * digit + carry; + result.append(val % 10); + carry = val / 10; + } + if (carry > 0) result.append(carry); + return result.reverse().append(ZERO.repeat(factor)); + } + + private StringBuilder add(StringBuilder a, StringBuilder b) { + final StringBuilder result = new StringBuilder(); + int carry = 0; + for (int i = a.length() - 1, j = b.length() - 1 ; i >= 0 || j >= 0 ; i--, j--) { + int val = getDigit(a, i) + getDigit(b, j) + carry; + result.append(val % 10); + carry = val / 10; + } + if (carry > 0) result.append(carry); + return result.reverse(); + } + + private int getDigit(StringBuilder string, int index) { + if (index < 0) return 0; + return string.charAt(index) - '0'; + } +} From 5995bda11b0979f00729090f41ce82649f28aecc Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 6 Jan 2022 00:32:42 +0100 Subject: [PATCH 487/947] solves jump game ii --- README.md | 1 + src/JumpGameII.java | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 src/JumpGameII.java diff --git a/README.md b/README.md index 447001b..130c654 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ | 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) | | | 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) | | | 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) | | | 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) | | | 66 | [Plus One](https://leetcode.com/problems/plus-one) | [![Java](assets/java.png)](src/PlusOne.java) [![Python](assets/python.png)](python/plus_one.py) | | diff --git a/src/JumpGameII.java b/src/JumpGameII.java new file mode 100644 index 0000000..0fefd43 --- /dev/null +++ b/src/JumpGameII.java @@ -0,0 +1,24 @@ +// https://leetcode.com/problems/jump-game-ii +// T: O(n) +// S: O(1) + +public class JumpGameII { + public int jump(int[] nums) { + if (nums.length == 1) return 0; + + int jumps = 0; + for (int current = 0 ; current < nums.length ; jumps++) { + int maxJumpIndex = current, maxJump = nums[current]; + for (int i = current ; i < current + nums[current] + 1 && i < nums.length ; i++) { + if (i == nums.length - 1) return jumps + 1; + int potential = i - current + nums[i]; + if (potential > maxJump) { + maxJump = potential; + maxJumpIndex = i; + } else if (potential == maxJump) maxJumpIndex = i; + } + current = maxJumpIndex; + } + return jumps; + } +} From 5ec246b1709831c52851fec6cfca0ad34b90d12e Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 6 Jan 2022 00:55:20 +0100 Subject: [PATCH 488/947] solves jump game --- README.md | 1 + src/JumpGame.java | 13 +++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 src/JumpGame.java diff --git a/README.md b/README.md index 130c654..38f8ec1 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ | 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) | | | 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) | | +| 55 | [Jump Game](https://leetcode.com/problems/jump-game) | [![Java](assets/java.png)](src/JumpGame.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) | | | 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) | | diff --git a/src/JumpGame.java b/src/JumpGame.java new file mode 100644 index 0000000..cd2824a --- /dev/null +++ b/src/JumpGame.java @@ -0,0 +1,13 @@ +// https://leetcode.com/problems/jump-game +// T: O(N) +// S: O(1) + +public class JumpGame { + public boolean canJump(int[] nums) { + int last = nums.length - 1; + for (int i = nums.length - 2 ; i >= 0 ; i--) { + if (i + nums[i] >= last) last = i; + } + return last == 0; + } +} From 1376e12a7254731f58daff359a2eca10afbbb818 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 6 Jan 2022 12:02:13 +0100 Subject: [PATCH 489/947] solves permutations --- README.md | 1 + src/Permutations.java | 76 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 src/Permutations.java diff --git a/README.md b/README.md index 38f8ec1..8f1d858 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ | 40 | [Combination Sum II](https://leetcode.com/problems/combination-sum-ii) | [![Java](assets/java.png)](src/CombinationSumII.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) | | | 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) | | | 55 | [Jump Game](https://leetcode.com/problems/jump-game) | [![Java](assets/java.png)](src/JumpGame.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) | | diff --git a/src/Permutations.java b/src/Permutations.java new file mode 100644 index 0000000..b6d23d6 --- /dev/null +++ b/src/Permutations.java @@ -0,0 +1,76 @@ +// https://leetcode.com/problems/permutations +// T: O(n * n!) +// S: O(n * n!) + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class Permutations { + private static final Map>> PERMUTATION_MASKS = new HashMap<>(); + + static { + PERMUTATION_MASKS.put(1, List.of(List.of(0))); + PERMUTATION_MASKS.put(2, List.of( + List.of(0, 1), + List.of(1, 0) + )); + PERMUTATION_MASKS.put(3, List.of( + List.of(0, 1, 2), + List.of(0, 2, 1), + List.of(1, 0, 2), + List.of(1, 2, 0), + List.of(2, 0, 1), + List.of(2, 1, 0) + )); + + for (int i = 4 ; i <= 6 ; i++) { + PERMUTATION_MASKS.put(i, getPermutationMask(i)); + } + } + + private static List> getPermutationMask(int size) { + final List> result = new ArrayList<>(); + final List> previousPermutations = PERMUTATION_MASKS.get(size - 1); + for (List mask : previousPermutations) { + for (int insertionPosition = 0 ; insertionPosition < size ; insertionPosition++) { + result.add(newPermutation(mask, insertionPosition)); + } + } + return result; + } + + private static List newPermutation(List mask, int index) { + final List result = new ArrayList<>(); + for (int i = 0 ; i < index ; i++) result.add(mask.get(i)); + result.add(mask.size()); + for (int i = index ; i < mask.size() ; i++) result.add(mask.get(i)); + return result; + } + + public List> permute(int[] nums) { + final List> results = new ArrayList<>(); + final List> permutationMasks = PERMUTATION_MASKS.get(nums.length); + for (List mask : permutationMasks) { + results.add(permute(nums, mask)); + } + return results; + } + + private List permute(int[] array, List mask) { + final int[] result = new int[array.length]; + for (int i = 0 ; i < array.length ; i++) { + result[mask.get(i)] = array[i]; + } + return toList(result); + } + + private List toList(int[] array) { + final List result = new ArrayList<>(array.length); + for (int element : array) { + result.add(element); + } + return result; + } +} From 12861a46136baeac7c9567a71299f2a650edc3ce Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 6 Jan 2022 13:44:52 +0100 Subject: [PATCH 490/947] solves permutations ii --- README.md | 1 + src/PermutationsII.java | 42 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 src/PermutationsII.java diff --git a/README.md b/README.md index 8f1d858..2ad8a22 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ | 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) | | | 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) | | | 55 | [Jump Game](https://leetcode.com/problems/jump-game) | [![Java](assets/java.png)](src/JumpGame.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) | | diff --git a/src/PermutationsII.java b/src/PermutationsII.java new file mode 100644 index 0000000..36eb08c --- /dev/null +++ b/src/PermutationsII.java @@ -0,0 +1,42 @@ +// https://leetcode.com/problems/permutations-ii +// T: O(n * n!) +// S: O(n * n!) + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +public class PermutationsII { + public List> permuteUnique(int[] nums) { + final Map frequencies = getFrequencies(nums); + final List> result = new ArrayList<>(); + permuteUnique(nums, result, frequencies, new LinkedList<>()); + return result; + } + + private void permuteUnique(int[] array, List> result, Map frequencies, LinkedList current) { + if (current.size() == array.length) { + result.add(new ArrayList<>(current)); + return; + } + for (Map.Entry entry : frequencies.entrySet()) { + if (entry.getValue() > 0) { + entry.setValue(entry.getValue() - 1); + current.add(entry.getKey()); + permuteUnique(array, result, frequencies, current); + current.removeLast(); + entry.setValue(entry.getValue() + 1); + } + } + } + + private Map getFrequencies(int[] array) { + final Map frequencies = new HashMap<>(); + for (int element : array) { + frequencies.put(element, frequencies.getOrDefault(element, 0) + 1); + } + return frequencies; + } +} From b099583518ccaf75fa765298153e62a316b0009c Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 6 Jan 2022 17:20:55 +0100 Subject: [PATCH 491/947] solves rotate image --- README.md | 1 + src/RotateImage.java | 53 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 src/RotateImage.java diff --git a/README.md b/README.md index 2ad8a22..40691b0 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ | 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) | | | 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) | | | 55 | [Jump Game](https://leetcode.com/problems/jump-game) | [![Java](assets/java.png)](src/JumpGame.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) | | diff --git a/src/RotateImage.java b/src/RotateImage.java new file mode 100644 index 0000000..c56b02d --- /dev/null +++ b/src/RotateImage.java @@ -0,0 +1,53 @@ +// https://leetcode.com/problems/rotate-image +// T: O(n ^ 2) +// S: O(1) + +public class RotateImage { + private static final class Point { + private final int row; + private final int column; + + private Point(int row, int column) { + this.row = row; + this.column = column; + } + } + + public void rotate(int[][] matrix) { + final int frames = (matrix.length + 1) / 2; + for (int frame = 0 ; frame < frames ; frame++) { + rotate90Degrees(matrix, frame); + } + } + + private void rotate90Degrees(int[][] matrix, int frame) { + for (int i = 0 ; i < matrix.length - 2 * frame - 1 ; i++) { + Point p1 = getCoordinates(frame, 0, matrix.length, i); + int temp1 = get(matrix, p1), temp2; + for (int k = 0 ; k < 4 ; k++) { + Point p2 = getCoordinates(frame, (k + 1) % 4, matrix.length, i); + temp2 = get(matrix, p2); + set(matrix, p2, temp1); + temp1 = temp2; + } + } + } + + private int get(int[][] matrix, Point point) { + return matrix[point.row][point.column]; + } + + private void set(int[][] matrix, Point point, int value) { + matrix[point.row][point.column] = value; + } + + private Point getCoordinates(int frame, int k, int size, int shift) { + return switch (k) { + case 0 -> new Point(frame, frame + shift); + case 1 -> new Point(frame + shift, size - 1 - frame); + case 2 -> new Point(size - 1 - frame, size - 1 - frame - shift); + case 3 -> new Point(size - 1 - frame - shift, frame); + default -> null; + }; + } +} From 9f2af59d761e5bba94128f5d41e3c398363903bb Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 6 Jan 2022 17:35:50 +0100 Subject: [PATCH 492/947] solves group anagrams --- README.md | 1 + src/GroupAnagrams.java | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 src/GroupAnagrams.java diff --git a/README.md b/README.md index 40691b0..351858c 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ | 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) | | | 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) | | | 55 | [Jump Game](https://leetcode.com/problems/jump-game) | [![Java](assets/java.png)](src/JumpGame.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) | | diff --git a/src/GroupAnagrams.java b/src/GroupAnagrams.java new file mode 100644 index 0000000..3d0e000 --- /dev/null +++ b/src/GroupAnagrams.java @@ -0,0 +1,33 @@ +// https://leetcode.com/problems/group-anagrams +// T: O(|words| * |words[i]|) +// S: O(|words| * |words[i]|) + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class GroupAnagrams { + public List> groupAnagrams(String[] words) { + final Map> anagrams = new HashMap<>(); + for (String word : words) { + final String signature = getSignature(word); + if (anagrams.containsKey(signature)) { + anagrams.get(signature).add(word); + } else { + List list = new ArrayList<>(); + list.add(word); + anagrams.put(signature, list); + } + } + return new ArrayList<>(anagrams.values()); + } + + private String getSignature(String string) { + final char[] array = new char[26]; + for (int i = 0 ; i < string.length() ; i++) { + array[string.charAt(i) - 'a']++; + } + return String.valueOf(array); + } +} From bef9cf076adeb84eb8752b26a8820ea2c328a5a5 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 6 Jan 2022 18:01:11 +0100 Subject: [PATCH 493/947] solves pow(x, n ) --- README.md | 1 + src/Powxn.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 src/Powxn.java diff --git a/README.md b/README.md index 351858c..24a6132 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ | 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) | | | 55 | [Jump Game](https://leetcode.com/problems/jump-game) | [![Java](assets/java.png)](src/JumpGame.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) | | diff --git a/src/Powxn.java b/src/Powxn.java new file mode 100644 index 0000000..5f3f4fb --- /dev/null +++ b/src/Powxn.java @@ -0,0 +1,17 @@ +// https://leetcode.com/problems/powx-n +// T: O(log(n)) +// S: O(1) + +public class Powxn { + public double myPow(double x, int n) { + if (n >= 0) return power(x, n); + return 1 / power(x, -n); + } + + private double power(double x, int n) { + if (n == 0) return 1; + if (n == 1) return x; + double half = power(x, n / 2); + return half * half * (n % 2 == 0 ? 1 : x); + } +} From eec57c12bf58a90f87258b4190f70c73893ec377 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 6 Jan 2022 18:22:04 +0100 Subject: [PATCH 494/947] solves spiral matrix --- README.md | 1 + src/SpiralMatrix.java | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/SpiralMatrix.java diff --git a/README.md b/README.md index 24a6132..b00cbcd 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,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) | | | 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) | | | 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) | | | 66 | [Plus One](https://leetcode.com/problems/plus-one) | [![Java](assets/java.png)](src/PlusOne.java) [![Python](assets/python.png)](python/plus_one.py) | | diff --git a/src/SpiralMatrix.java b/src/SpiralMatrix.java new file mode 100644 index 0000000..92a243d --- /dev/null +++ b/src/SpiralMatrix.java @@ -0,0 +1,32 @@ +import java.util.ArrayList; +import java.util.List; + +public class SpiralMatrix { + public List spiralOrder(int[][] matrix) { + final List result = new ArrayList<>(); + 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++) { + result.add(matrix[row][column]); + } + top++; + if (i == elements) break; + for (int row = top, column = right - 1 ; row < bottom ; row++, i++) { + result.add(matrix[row][column]); + } + right--; + if (i == elements) break; + for (int row = bottom - 1, column = right - 1 ; column >= left ; column--, i++) { + result.add(matrix[row][column]); + } + bottom--; + if (i == elements) break; + for (int row = bottom - 1, column = left ; row >= top ; row--, i++) { + result.add(matrix[row][column]); + } + left++; + if (i == elements) break; + } + return result; + } +} From d51ba19ae30baad66c8c70b3ca949c88a59bc39f Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 6 Jan 2022 18:36:17 +0100 Subject: [PATCH 495/947] solves merge intervals --- README.md | 1 + src/MergeIntervals.java | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/MergeIntervals.java diff --git a/README.md b/README.md index b00cbcd..b1095fd 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ | 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) | | | 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) | | | 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) | | diff --git a/src/MergeIntervals.java b/src/MergeIntervals.java new file mode 100644 index 0000000..732cb5b --- /dev/null +++ b/src/MergeIntervals.java @@ -0,0 +1,35 @@ +// https://leetcode.com/problems/merge-intervals/submissions +// T: O(n log(n)) +// S: O(n) + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; + +public class MergeIntervals { + public int[][] merge(int[][] intervals) { + Arrays.sort(intervals, Comparator.comparingInt(interval -> interval[0])); + final List mergedIntervals = new ArrayList<>(); + int start = intervals[0][0], stop = intervals[0][1]; + for (int i = 1 ; i < intervals.length ; i++) { + if (intervals[i][0] <= stop) stop = Math.max(stop, intervals[i][1]); + else { + mergedIntervals.add(new int[] {start, stop}); + start = intervals[i][0]; + stop = intervals[i][1]; + } + } + mergedIntervals.add(new int[] {start, stop}); + return toArray(mergedIntervals); + } + + private int[][] toArray(List list) { + int[][] result = new int[list.size()][2]; + int i = 0; + for (int[] interval : list) { + result[i++] = interval; + } + return result; + } +} From 9d65c7920fc74dc42ac6f82649ca837fcb594b68 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 7 Jan 2022 15:30:25 +0100 Subject: [PATCH 496/947] solves insert inrterval --- README.md | 1 + src/InsertInterval.java | 54 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 src/InsertInterval.java diff --git a/README.md b/README.md index b1095fd..2d51e44 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ | 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) | | | 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) | | diff --git a/src/InsertInterval.java b/src/InsertInterval.java new file mode 100644 index 0000000..774275a --- /dev/null +++ b/src/InsertInterval.java @@ -0,0 +1,54 @@ +// https://leetcode.com/problems/insert-interval/submissions +// T: O(n) +// S: O(n) + +public class InsertInterval { + public int[][] insert(int[][] intervals, int[] newInterval) { + if (intervals.length == 0) return new int[][] {newInterval}; + final int startIndex = search(intervals, newInterval[0]); + final int endIndex = search(intervals, newInterval[1]); + final int newStart = startIndex >= intervals.length + ? newInterval[0] + : Math.min(intervals[startIndex][0], newInterval[0]); + final int newEnd = endIndex >= intervals.length + ? newInterval[1] + : newInterval[1] >= intervals[endIndex][0] ? intervals[endIndex][1] : newInterval[1]; + final boolean hasMerged = hasMerged(intervals, newInterval, startIndex, endIndex); + final int intervalMergedEnd = endIndex >= intervals.length + ? intervals.length - 1 + : newInterval[1] >= intervals[endIndex][0] ? endIndex : endIndex - 1; + final int intervalMergedStart = startIndex; + final int elements = intervals.length - (hasMerged ? intervalMergedEnd - intervalMergedStart : -1); + final int[][] result = new int[elements][2]; + int i = 0; + for ( ; i < intervalMergedStart ; i++) result[i] = intervals[i]; + result[i++] = new int[] {newStart, newEnd}; + if (hasMerged) { + for (i = intervalMergedEnd + 1 ; i < intervals.length ; i++) { + result[i - (intervalMergedEnd - intervalMergedStart)] = intervals[i]; + } + } else { + for ( ; i < intervals.length ; i++) { + result[i] = intervals[i - 1]; + } + } + return result; + } + + private boolean hasMerged(int[][] intervals, int[] interval, int start, int end) { + if (start >= intervals.length) return false; + return interval[0] <= intervals[start][1] || + (end < intervals.length && interval[1] >= intervals[end][0]); + } + + private int search(int[][] array, int x) { + int left = 0, right = array.length - 1, middle; + while (left <= right) { + middle = left + (right - left) / 2; + if (array[middle][1] == x) return middle; + else if (array[middle][1] > x) right = middle - 1; + else left = middle + 1; + } + return left; + } +} From 001977ed169e501b1a1408205eae3640b6741cd1 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 10 Jan 2022 14:07:36 +0100 Subject: [PATCH 497/947] solves spiral matrix ii --- README.md | 1 + src/SpiralMatrixII.java | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 src/SpiralMatrixII.java diff --git a/README.md b/README.md index 2d51e44..2d03fa1 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ | 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) | | | 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) | | diff --git a/src/SpiralMatrixII.java b/src/SpiralMatrixII.java new file mode 100644 index 0000000..0ec7c88 --- /dev/null +++ b/src/SpiralMatrixII.java @@ -0,0 +1,34 @@ +// https://leetcode.com/problems/spiral-matrix-ii +// T: O(n^2) +// S: O(n^2) + +public class SpiralMatrixII { + public int[][] generateMatrix(int n) { + final int[][] matrix = new int[n][n]; + final int rows = matrix.length, columns = matrix[0].length, elements = rows * columns; + + for (int i = 0, top = 0, bottom = rows, left = 0, right = columns, k = 1 ; ; ) { + for (int row = top, column = left ; column < right ; column++, i++) { + matrix[row][column] = k++; + } + top++; + if (i == elements) break; + for (int row = top, column = right - 1 ; row < bottom ; row++, i++) { + matrix[row][column] = k++; + } + right--; + if (i == elements) break; + for (int row = bottom - 1, column = right - 1 ; column >= left ; column--, i++) { + matrix[row][column] = k++; + } + bottom--; + if (i == elements) break; + for (int row = bottom - 1, column = left ; row >= top ; row--, i++) { + matrix[row][column] = k++; + } + left++; + if (i == elements) break; + } + return matrix; + } +} From 3c06bdaec10df9a146bce8958041277607346c09 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 10 Jan 2022 14:22:43 +0100 Subject: [PATCH 498/947] solves rotate list --- README.md | 1 + src/RotateList.java | 52 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 src/RotateList.java diff --git a/README.md b/README.md index 2d03fa1..e535790 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,7 @@ | 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) | | | 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) | | diff --git a/src/RotateList.java b/src/RotateList.java new file mode 100644 index 0000000..49a5d37 --- /dev/null +++ b/src/RotateList.java @@ -0,0 +1,52 @@ +// https://leetcode.com/problems/rotate-list +// T: O(N) +// S: O(1) + +public class RotateList { + public static class ListNode { + int val; + ListNode next; + ListNode() {} + ListNode(int val) { this.val = val; } + ListNode(int val, ListNode next) { this.val = val; this.next = next; } + } + + public ListNode rotateRight(ListNode head, int k) { + final int length = getLength(head); + if (length == 0) return head; + final int rotations = k % length; + if (rotations == 0) return head; + final ListNode last = getLastNode(head); + final ListNode cutoffNode = getCutoffNode(head, rotations, length); + final ListNode newHead = cutoffNode.next; + last.next = head; + cutoffNode.next = null; + return newHead; + } + + private int getLength(ListNode head) { + int length = 0; + ListNode current = head; + while (current != null) { + current = current.next; + length++; + } + return length; + } + + private ListNode getLastNode(ListNode head) { + ListNode current = head; + while (current.next != null) { + current = current.next; + } + return current; + } + + private ListNode getCutoffNode(ListNode head, int rotations, int length) { + ListNode current = head; + for (int i = 0 ; i < length - rotations - 1 ; i++) { + current = current.next; + } + return current; + } +} From 425279a5877d181f32e4059513dfd0e526150fd1 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 10 Jan 2022 15:17:55 +0100 Subject: [PATCH 499/947] solves unique paths --- README.md | 1 + src/UniquePaths.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 src/UniquePaths.java diff --git a/README.md b/README.md index e535790..823af72 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ | 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) | | | 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) | | diff --git a/src/UniquePaths.java b/src/UniquePaths.java new file mode 100644 index 0000000..c7ac26b --- /dev/null +++ b/src/UniquePaths.java @@ -0,0 +1,15 @@ +// https://leetcode.com/problems/unique-paths +// T: O(min(m, n)) +// S: O(1) + +public class UniquePaths { + public int uniquePaths(int m, int n) { + final int M = Math.max(m, n) - 1, N = Math.min(m, n) - 1; + long result = 1; + for (int i = M + 1, j = 1 ; i <= M + N ; i++, j++) { + result *= i; + result /= j; + } + return (int) result; + } +} From 39506445833bacc253c219d429fb958680bf87d4 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 10 Jan 2022 19:46:46 +0100 Subject: [PATCH 500/947] solves unique paths ii --- README.md | 1 + src/UniquePathII.java | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/UniquePathII.java diff --git a/README.md b/README.md index 823af72..f0dd8e9 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,7 @@ | 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) | | | 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) | | diff --git a/src/UniquePathII.java b/src/UniquePathII.java new file mode 100644 index 0000000..d86a9bb --- /dev/null +++ b/src/UniquePathII.java @@ -0,0 +1,35 @@ +// https://leetcode.com/problems/unique-paths-ii +// T: O(m * n) +// S: O(n) + +public class UniquePathII { + public int uniquePathsWithObstacles(int[][] obstacleGrid) { + final int rows = obstacleGrid.length, columns = obstacleGrid[0].length; + if (obstacleGrid[rows - 1][columns - 1] == 1) return 0; + final int[][] memory = getMemoryTable(obstacleGrid); + + int i = 0; + for (int row = rows - 2 ; row >= 0; row--, i ^= 1) { + memory[i][columns - 1] = memory[i ^ 1][columns - 1] & (obstacleGrid[row][columns - 1] ^ 1); + for (int column = columns - 2 ; column >= 0 ; column--) { + if (obstacleGrid[row][column] == 1) { + memory[i][column] = 0; + } else { + memory[i][column] = memory[i ^ 1][column] + memory[i][column + 1]; + } + } + } + + return memory[i ^ 1][0]; + } + + private int[][] getMemoryTable(int[][] obstacles) { + final int rows = obstacles.length, columns = obstacles[0].length; + final int[][] memory = new int[2][columns]; + memory[1][columns - 1] = 1; + for (int column = columns - 2 ; column >= 0 ; column--) { + memory[1][column] = memory[1][column + 1] & (obstacles[rows - 1][column] ^ 1); + } + return memory; + } +} From 3d9040f6dc3fb3996df4c4842eb13a2780f5ac0e Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 10 Jan 2022 19:53:37 +0100 Subject: [PATCH 501/947] solves minimum path sum --- README.md | 5 +++-- src/MinimumPathSum.java | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 src/MinimumPathSum.java diff --git a/README.md b/README.md index f0dd8e9..6646b36 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-442/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-442/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-460/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-460/2081-1abc9c.svg) ![problems-solved-python](https://img.shields.io/badge/Python-186/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) @@ -61,6 +61,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) | | | 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) | | diff --git a/src/MinimumPathSum.java b/src/MinimumPathSum.java new file mode 100644 index 0000000..a1a4130 --- /dev/null +++ b/src/MinimumPathSum.java @@ -0,0 +1,27 @@ +// https://leetcode.com/problems/minimum-path-sum +// T: O(m * n) +// S: O(1) + +public class MinimumPathSum { + public int minPathSum(int[][] grid) { + final int rows = grid.length, columns = grid[0].length; + + // last row + for (int column = columns - 2 ; column >= 0 ; column--) { + grid[rows - 1][column] += grid[rows - 1][column + 1]; + } + + // last column + for (int row = rows - 2 ; row >= 0 ; row--) { + grid[row][columns - 1] += grid[row + 1][columns - 1]; + } + + for (int row = rows - 2 ; row >= 0 ; row--) { + for (int column = columns - 2 ; column >= 0 ; column--) { + grid[row][column] += Math.min(grid[row + 1][column], grid[row][column + 1]); + } + } + + return grid[0][0]; + } +} From df815e8486d19fd10e832afc99930f16356ba75c Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 14 Jan 2022 12:30:34 +0100 Subject: [PATCH 502/947] solves set matrix zeroes --- README.md | 1 + src/SetMatrixZeroes.java | 46 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 src/SetMatrixZeroes.java diff --git a/README.md b/README.md index 6646b36..879e3fd 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,7 @@ | 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) | | +| 73 | [Set Matrix Zeroes](https://leetcode.com/problems/set-matrix-zeroes) | [![Java](assets/java.png)](src/SetMatrixZeroes.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) | | | 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) | | | 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) | | diff --git a/src/SetMatrixZeroes.java b/src/SetMatrixZeroes.java new file mode 100644 index 0000000..fd1cb92 --- /dev/null +++ b/src/SetMatrixZeroes.java @@ -0,0 +1,46 @@ +// https://leetcode.com/problems/set-matrix-zeroes/ +// T: O(m * n) +// S: O(1) + +public class SetMatrixZeroes { + public void setZeroes(int[][] matrix) { + final int rows = matrix.length, columns = matrix[0].length; + boolean firstColumnIsZero = false; + + for (int row = 0 ; row < rows ; row++) { + if (matrix[row][0] == 0) firstColumnIsZero = true; + for (int column = 1 ; column < columns ; column++) { + if (matrix[row][column] == 0) { + matrix[row][0] = 0; + matrix[0][column] = 0; + } + } + } + + for (int column = columns - 1 ; column >= 1 ; column--) { + if (matrix[0][column] == 0) { + markColumn0(matrix, column); + } + } + + for (int row = rows - 1 ; row >= 0 ; row--) { + if (matrix[row][0] == 0) { + markRow0(matrix, row); + } + } + + if (firstColumnIsZero) markColumn0(matrix, 0); + } + + private void markRow0(int[][] matrix, int row) { + for (int column = 0 ; column < matrix[0].length ; column++) { + matrix[row][column] = 0; + } + } + + private void markColumn0(int[][] matrix, int column) { + for (int row = 0 ; row < matrix.length ; row++) { + matrix[row][column] = 0; + } + } +} From 99d65bc866000920b4ab76111a9c400bd62b33e3 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 16 Jan 2022 22:51:45 +0100 Subject: [PATCH 503/947] solves simplify path --- README.md | 1 + src/SimplifyPath.java | 55 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 src/SimplifyPath.java diff --git a/README.md b/README.md index 879e3fd..2b14193 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,7 @@ | 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) | | | 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) | | | 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) | | diff --git a/src/SimplifyPath.java b/src/SimplifyPath.java new file mode 100644 index 0000000..1c9f21f --- /dev/null +++ b/src/SimplifyPath.java @@ -0,0 +1,55 @@ +// https://leetcode.com/problems/simplify-path +// T: O(|path|) +// S: O(|path|) + +import java.util.LinkedList; + +public class SimplifyPath { + private static final char SLASH = '/'; + private static final String ROOT = "/"; + private static final String GO_ONE_LEVEL_UP = ".."; + private static final String STAY_WHERE_YOU_ARE = "."; + + public String simplifyPath(String path) { + final LinkedList fragments = new LinkedList<>(); + StringBuilder current = new StringBuilder(); + for (int i = 0 ; i < path.length() ; i++) { + if (path.charAt(i) == SLASH) { + if (!isEmpty(current)) { + addToFragments(current, fragments); + current = new StringBuilder(); + } + } else current.append(path.charAt(i)); + } + if (!isEmpty(current)) addToFragments(current, fragments); + return toPath(fragments); + } + + private String toPath(LinkedList fragments) { + if (fragments.isEmpty()) return ROOT; + StringBuilder result = new StringBuilder(); + for (StringBuilder fragment : fragments) { + result.append(SLASH).append(fragment); + } + return result.toString(); + } + + private void removeLast(LinkedList fragments) { + if (!fragments.isEmpty()) { + fragments.removeLast(); + } + } + + private void addToFragments(StringBuilder current, LinkedList fragments) { + String currentString = current.toString(); + if (GO_ONE_LEVEL_UP.equals(currentString)) { + removeLast(fragments); + } else if (!STAY_WHERE_YOU_ARE.equals(currentString)) { + fragments.add(current); + } + } + + private boolean isEmpty(StringBuilder stringBuilder) { + return stringBuilder.length() == 0; + } +} From a715532dfe4393ee5ccbc11325ba31f46e30b5a4 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 16 Jan 2022 22:55:53 +0100 Subject: [PATCH 504/947] solves search a 2d matrix --- README.md | 1 + src/SearchA2DMatrix.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 src/SearchA2DMatrix.java diff --git a/README.md b/README.md index 2b14193..7b25786 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,7 @@ | 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) | | | 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) | | | 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) | | | 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) | | diff --git a/src/SearchA2DMatrix.java b/src/SearchA2DMatrix.java new file mode 100644 index 0000000..91ecaa1 --- /dev/null +++ b/src/SearchA2DMatrix.java @@ -0,0 +1,17 @@ +// https://leetcode.com/problems/search-a-2d-matrix +// T: O(log(m*n)) +// S: O(1) + +public class SearchA2DMatrix { + public boolean searchMatrix(int[][] matrix, int target) { + final int rows = matrix.length, columns = matrix[0].length; + int left = 0, right = rows * columns - 1, middle; + while (left <= right) { + middle = left + (right - left) / 2; + if (matrix[middle / columns][middle % columns] == target) return true; + else if (matrix[middle / columns][middle % columns] > target) right = middle - 1; + else left = middle + 1; + } + return false; + } +} From e5d6c58688cd5cb8d20ac051dfb20fa6751f04b6 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 16 Jan 2022 23:05:07 +0100 Subject: [PATCH 505/947] solves sort colors --- README.md | 1 + src/SortColors.java | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/SortColors.java diff --git a/README.md b/README.md index 7b25786..e724c78 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,7 @@ | 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) | | | 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) | | | 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) | | | 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) | | diff --git a/src/SortColors.java b/src/SortColors.java new file mode 100644 index 0000000..90ea3f0 --- /dev/null +++ b/src/SortColors.java @@ -0,0 +1,21 @@ +// https://leetcode.com/problems/sort-colors +// T: O(n) single pass solution +// S: O(1) + +public class SortColors { + public void sortColors(int[] nums) { + int zerosIndex = 0; + int onesIndex = 0; + + for (int i = 0 ; i < nums.length ; i++) { + int temp = nums[i]; + nums[i] = 2; + if (temp == 0) { + nums[onesIndex++] = 1; + nums[zerosIndex++] = 0; + } else if (temp == 1) { + nums[onesIndex++] = 1; + } + } + } +} From 0719b165ce4e273f4a742b0f362d30c4ea68d7d1 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 16 Jan 2022 23:17:40 +0100 Subject: [PATCH 506/947] solves combinations --- README.md | 1 + src/Combinations.java | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/Combinations.java diff --git a/README.md b/README.md index e724c78..dcbab49 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,7 @@ | 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) | | | 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) | | | 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) | | | 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) | | diff --git a/src/Combinations.java b/src/Combinations.java new file mode 100644 index 0000000..d2e9f6a --- /dev/null +++ b/src/Combinations.java @@ -0,0 +1,31 @@ +// https://leetcode.com/problems/combinations +// T: O(k * 2^n) +// S: O(k) + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +public class Combinations { + public List> combine(int n, int k) { + final List> result = new ArrayList<>(); + createCombinations(n, k, result); + return result; + } + + private void createCombinations(int n, int k, List> result) { + addCombinations(n, 1, k, result, new LinkedList<>()); + } + + private void addCombinations(int n, int current, int length, List> result, LinkedList combination) { + if (combination.size() == length) { + result.add(new ArrayList<>(combination)); + return; + } + if (current > n) return; + combination.add(current); + addCombinations(n, current + 1, length, result, combination); + combination.removeLast(); + addCombinations(n, current + 1, length, result, combination); + } +} From cc0aa8eeadf3c5acee0786d580b8ff5c8920e713 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 17 Jan 2022 14:00:34 +0100 Subject: [PATCH 507/947] solves subsets --- README.md | 1 + src/Subsets.java | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/Subsets.java diff --git a/README.md b/README.md index dcbab49..fc616b3 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,7 @@ | 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) | | | 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) | | | 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) | | | 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) | | diff --git a/src/Subsets.java b/src/Subsets.java new file mode 100644 index 0000000..5465ca6 --- /dev/null +++ b/src/Subsets.java @@ -0,0 +1,27 @@ +// https://leetcode.com/problems/subsets +// T: O(n * 2^n) +// S: O(n) + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +public class Subsets { + public List> subsets(int[] nums) { + final List> result = new ArrayList<>(); + addSubsets(nums, 0, result, new LinkedList<>()); + return result; + } + + private void addSubsets(int[] array, int index, List> result, LinkedList current) { + if (index == array.length) { + result.add(new ArrayList<>(current)); + return; + } + + current.add(array[index]); + addSubsets(array, index + 1, result, current); + current.removeLast(); + addSubsets(array, index + 1, result, current); + } +} From 27f3ba2e4a17e2daa913e6d0dfb2ab9162176b33 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 17 Jan 2022 18:03:52 +0100 Subject: [PATCH 508/947] solves word search --- README.md | 1 + src/WordSearch.java | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/WordSearch.java diff --git a/README.md b/README.md index fc616b3..7c9cdb5 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,7 @@ | 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) | | | 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) | | | 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) | | | 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) | | diff --git a/src/WordSearch.java b/src/WordSearch.java new file mode 100644 index 0000000..8833249 --- /dev/null +++ b/src/WordSearch.java @@ -0,0 +1,35 @@ +// https://leetcode.com/problems/word-search +// T: O(4^{m * n}) +// S: O(m * n) + +public class WordSearch { + + public boolean exist(char[][] board, String word) { + final int rows = board.length, columns = board[0].length; + + for (int row = 0; row < rows ; row++) { + for (int column = 0; column < columns ; column++) { + if (exist(board, row, column, word, 0)) { + return true; + } + } + } + + return false; + } + + private boolean exist(char[][] board, int row, int column, String word, int i) { + if (i == word.length()) return true; + if (row < 0 || column < 0 || row == board.length || column == board[row].length) return false; + if (board[row][column] != word.charAt(i)) return false; + + board[row][column] ^= 256; + boolean exist = exist(board, row, column+1, word, i + 1) + || exist(board, row, column - 1, word, i + 1) + || exist(board, row + 1, column, word, i + 1) + || exist(board, row - 1, column, word, i + 1); + + board[row][column] ^= 256; + return exist; + } +} From 98095f73ec11b53a57b86969d04c0918e018b067 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 17 Jan 2022 20:54:51 +0100 Subject: [PATCH 509/947] solves remove duplicates fromsorted array ii --- README.md | 1 + src/RemoveDuplicatesFromSortedArrayII.java | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 src/RemoveDuplicatesFromSortedArrayII.java diff --git a/README.md b/README.md index 7c9cdb5..5442617 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,7 @@ | 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) | | | 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) | | | 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) | | | 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) | | diff --git a/src/RemoveDuplicatesFromSortedArrayII.java b/src/RemoveDuplicatesFromSortedArrayII.java new file mode 100644 index 0000000..57d3528 --- /dev/null +++ b/src/RemoveDuplicatesFromSortedArrayII.java @@ -0,0 +1,20 @@ +// https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii +// T: O(N) +// S: O(1) + +public class RemoveDuplicatesFromSortedArrayII { + public int removeDuplicates(int[] nums) { + int insertionIndex = 1; + for (int i = 1, count = 1 ; i < nums.length ; i++) { + if (nums[i] == nums[insertionIndex - 1]) { + if (count == 2) continue; + nums[insertionIndex++] = nums[i]; + count++; + } else { + nums[insertionIndex++] = nums[i]; + count = 1; + } + } + return insertionIndex; + } +} From 0f5017bb4ce958cbfd4f084e784329bc09d43b9d Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 17 Jan 2022 21:51:58 +0100 Subject: [PATCH 510/947] solves search in rotated sorted array II --- README.md | 1 + src/SearchInRotatedSortedArrayII.java | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 src/SearchInRotatedSortedArrayII.java diff --git a/README.md b/README.md index 5442617..b08a15a 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,7 @@ | 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) | | | 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) | | | 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) | | | 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) | | diff --git a/src/SearchInRotatedSortedArrayII.java b/src/SearchInRotatedSortedArrayII.java new file mode 100644 index 0000000..6291ce0 --- /dev/null +++ b/src/SearchInRotatedSortedArrayII.java @@ -0,0 +1,12 @@ +// https://leetcode.com/problems/search-in-rotated-sorted-array-ii +// T: O(N) +// S: O(1) + +public class SearchInRotatedSortedArrayII { + public boolean search(int[] nums, int target) { + for (int element : nums) { + if (element == target) return true; + } + return false; + } +} From 9fd0ab5924566925f84564e336e96adacc971d55 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 17 Jan 2022 22:11:54 +0100 Subject: [PATCH 511/947] solves remove duplicate from sorted list II --- README.md | 1 + src/RemoveDuplicatesFromSortedListII.java | 31 +++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/RemoveDuplicatesFromSortedListII.java diff --git a/README.md b/README.md index b08a15a..ecfe2a2 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,7 @@ | 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) | | | 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) | | | 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) | | diff --git a/src/RemoveDuplicatesFromSortedListII.java b/src/RemoveDuplicatesFromSortedListII.java new file mode 100644 index 0000000..fa54ecf --- /dev/null +++ b/src/RemoveDuplicatesFromSortedListII.java @@ -0,0 +1,31 @@ +// https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii +// T: O(N) +// S: O(1) + +public class RemoveDuplicatesFromSortedListII { + private static class ListNode { + int val; + ListNode next; + } + + public ListNode deleteDuplicates(ListNode head) { + if (head == null) return null; + ListNode tempHead = new ListNode(); + tempHead.next = head; + int val; + for (ListNode current = head, previous = tempHead ; current != null && current.next != null ; ) { + if (current.val == current.next.val) { + val = current.val; + while (current.next != null && current.next.val == val) { + current = current.next; + } + current = current.next; + previous.next = current; + } else { + previous = current; + current = current.next; + } + } + return tempHead.next; + } +} From 89f8d9df79c8ed058d1654db535c9b849a948d3d Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 17 Jan 2022 22:42:00 +0100 Subject: [PATCH 512/947] solves partition list --- README.md | 1 + src/PartitionList.java | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 src/PartitionList.java diff --git a/README.md b/README.md index ecfe2a2..6914dcd 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,7 @@ | 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) | | | 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) | | | 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) | | | 100 | [Same Tree](https://leetcode.com/problems/same-tree) | [![Java](assets/java.png)](src/SameTree.java) [![Python](assets/python.png)](python/same_tree.py) | | diff --git a/src/PartitionList.java b/src/PartitionList.java new file mode 100644 index 0000000..e55ce03 --- /dev/null +++ b/src/PartitionList.java @@ -0,0 +1,29 @@ +// https://leetcode.com/problems/partition-list +// T: O(N) +// S: O(1) + +public class PartitionList { + public static class ListNode { + int val; + ListNode next; + ListNode() {} + } + + public ListNode partition(ListNode head, int x) { + ListNode beforeHead = new ListNode(), beforeTemp = beforeHead; + ListNode afterHead = new ListNode(), afterTemp = afterHead; + while (head != null) { + if (head.val < x) { + beforeTemp.next = head; + beforeTemp = beforeTemp.next; + } else { + afterTemp.next = head; + afterTemp = afterTemp.next; + } + head = head.next; + } + afterTemp.next = null; + beforeTemp.next = afterHead.next; + return beforeHead.next; + } +} From 1ff825249e78311c445fcaeeb2a60abb61b4b7d0 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 17 Jan 2022 22:55:17 +0100 Subject: [PATCH 513/947] solves gray code --- README.md | 1 + src/GrayCode.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 src/GrayCode.java diff --git a/README.md b/README.md index 6914dcd..0710b58 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,7 @@ | 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) | | | 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) | | | 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) | | | 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) | | diff --git a/src/GrayCode.java b/src/GrayCode.java new file mode 100644 index 0000000..40525cd --- /dev/null +++ b/src/GrayCode.java @@ -0,0 +1,19 @@ +// https://leetcode.com/problems/gray-code +// T: O(2 ^ n) +// S: O(2 ^ n) + +import java.util.ArrayList; +import java.util.List; + +public class GrayCode { + public List grayCode(int n) { + final List result = new ArrayList<>(1 << n); + result.add(0); + for (int i = 0, factor = 1 ; i < n ; i++, factor *= 2) { + for (int j = factor - 1 ; j >= 0 ; j--) { + result.add(result.get(j) + factor); + } + } + return result; + } +} From 2d1358816efd0a9cf4378a2a3bf40327c67cacdd Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 17 Jan 2022 23:24:24 +0100 Subject: [PATCH 514/947] a --- src/SubsetsII.java | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/SubsetsII.java diff --git a/src/SubsetsII.java b/src/SubsetsII.java new file mode 100644 index 0000000..3ef56f7 --- /dev/null +++ b/src/SubsetsII.java @@ -0,0 +1,39 @@ +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +public class SubsetsII { + public List> subsetsWithDup(int[] nums) { + final Map frequencies = getElementFrequencies(nums); + final List> result = new ArrayList<>(); + computeSubSets(frequencies, result, new LinkedList<>(), 0, nums.length); + return result; + } + + private void computeSubSets(Map frequencies, List> result, LinkedList current, int depth, int maxDepth) { + if (depth == maxDepth) { + result.add(new ArrayList<>(current)); + return; + } + for (Map.Entry entry : frequencies.entrySet()) { + if (entry.getValue() > 0) { + entry.setValue(entry.getValue() - 1); + computeSubSets(frequencies, result, current, depth + 1, maxDepth); + current.add(entry.getKey()); + computeSubSets(frequencies, result, current, depth + 1, maxDepth); + current.removeLast(); + entry.setValue(entry.getValue() + 1); + } + } + } + + private Map getElementFrequencies(int[] array) { + final Map frequencies = new HashMap<>(); + for (int element : array) { + frequencies.put(element, frequencies.getOrDefault(element, 0) + 1); + } + return frequencies; + } +} From 8b2fe4a6af90b4187f2619ec584097c13087f804 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Tue, 25 Jan 2022 11:23:56 +0100 Subject: [PATCH 515/947] solves subsets II --- README.md | 1 + src/SubsetsII.java | 40 ++++++++++++++-------------------------- 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 0710b58..6924362 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,7 @@ | 86 | [Partition List](https://leetcode.com/problems/partition-list) | [![Java](assets/java.png)](src/PartitionList.java) | | | 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) | | | 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) | | | 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) | | diff --git a/src/SubsetsII.java b/src/SubsetsII.java index 3ef56f7..2522c5a 100644 --- a/src/SubsetsII.java +++ b/src/SubsetsII.java @@ -1,39 +1,27 @@ +// https://leetcode.com/problems/subsets-ii +// T: O(2^n) +// S: O(n * 2^n) + import java.util.ArrayList; -import java.util.HashMap; +import java.util.Arrays; import java.util.LinkedList; import java.util.List; -import java.util.Map; public class SubsetsII { public List> subsetsWithDup(int[] nums) { - final Map frequencies = getElementFrequencies(nums); + Arrays.sort(nums); final List> result = new ArrayList<>(); - computeSubSets(frequencies, result, new LinkedList<>(), 0, nums.length); + helper(result, new LinkedList<>(), nums, 0); return result; } - private void computeSubSets(Map frequencies, List> result, LinkedList current, int depth, int maxDepth) { - if (depth == maxDepth) { - result.add(new ArrayList<>(current)); - return; - } - for (Map.Entry entry : frequencies.entrySet()) { - if (entry.getValue() > 0) { - entry.setValue(entry.getValue() - 1); - computeSubSets(frequencies, result, current, depth + 1, maxDepth); - current.add(entry.getKey()); - computeSubSets(frequencies, result, current, depth + 1, maxDepth); - current.removeLast(); - entry.setValue(entry.getValue() + 1); - } - } - } - - private Map getElementFrequencies(int[] array) { - final Map frequencies = new HashMap<>(); - for (int element : array) { - frequencies.put(element, frequencies.getOrDefault(element, 0) + 1); + public void helper(List> result, LinkedList current, int[] numbers, int index) { + result.add(new ArrayList<>(current)); + for(int i = index ; i < numbers.length ; i++) { + if(i > index && numbers[i] == numbers[i-1]) continue; + current.add(numbers[i]); + helper(result, current, numbers, i + 1); + current.removeLast(); } - return frequencies; } } From 2698d6db2102908d3ee1363487d17143f8e9a5c8 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Tue, 25 Jan 2022 11:46:14 +0100 Subject: [PATCH 516/947] solves decode ways --- README.md | 1 + src/DecodeWays.java | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/DecodeWays.java diff --git a/README.md b/README.md index 6924362..9854481 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,7 @@ | 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) | | | 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) | | | 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) | | diff --git a/src/DecodeWays.java b/src/DecodeWays.java new file mode 100644 index 0000000..a7bb841 --- /dev/null +++ b/src/DecodeWays.java @@ -0,0 +1,27 @@ +// https://leetcode.com/problems/decode-ways +// T: O(n) +// S: O(1) + +public class DecodeWays { + private static final char ZERO = '0'; + + public int numDecodings(String s) { + int previous = 1, current, temp; + current = s.charAt(s.length() - 1) > ZERO ? 1 : 0; + for (int i = s.length() - 2 ; i >= 0 ; i--) { + if (s.charAt(i) == ZERO) { + previous = current; + current = 0; + } else { + temp = current; + current += isValidAlphabet(s.charAt(i), s.charAt(i + 1)) ? previous : 0; + previous = temp; + } + } + return current; + } + + private boolean isValidAlphabet(char a, char b) { + return (a - ZERO) * 10 + (b - ZERO) <= 26; + } +} From 7fa5ba1b2184a4188c45bbd6e2b1b2b0fd5683fe Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Tue, 25 Jan 2022 12:20:03 +0100 Subject: [PATCH 517/947] a --- src/ReverseLinkedListII.java | 46 ++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/ReverseLinkedListII.java diff --git a/src/ReverseLinkedListII.java b/src/ReverseLinkedListII.java new file mode 100644 index 0000000..dcf8773 --- /dev/null +++ b/src/ReverseLinkedListII.java @@ -0,0 +1,46 @@ +public class ReverseLinkedListII { + private static class ListNode { + int val; + ListNode next; + ListNode(int val) { this.val = val; } + } + + public ListNode reverseBetween(ListNode head, int leftVal, int rightVal) { + if (leftVal == rightVal) return head; + + ListNode sentinelHead = new ListNode(-1000); + sentinelHead.next = head; + ListNode beforeLeft = getNodeBefore(sentinelHead, leftVal); + System.out.println(beforeLeft.val); + ListNode left = beforeLeft.next; +// ListNode afterRight = getNodeAfter(sentinelHead, rightVal); + ListNode a = beforeLeft.next, b = a.next, c = b.next; + + while (c != null && b.val != rightVal) { + a.next = null; + b.next = a; + a = b; + b = c; + c = c.next; + } + a.next = null; + b.next = a; + beforeLeft.next = b; + left.next = c; + return sentinelHead.next; + } + + private ListNode getNodeBefore(ListNode head, int value) { + while (head != null && head.next != null && head.next.val != value) { + head = head.next; + } + return head; + } + + private ListNode getNodeAfter(ListNode head, int value) { + while (head != null && head.val != value) { + head = head.next; + } + return head.next; + } +} From 2e8e39993ff94c81252c9f52793e83d9807b8081 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Tue, 25 Jan 2022 12:27:53 +0100 Subject: [PATCH 518/947] a --- src/ReverseLinkedListII.java | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/ReverseLinkedListII.java b/src/ReverseLinkedListII.java index dcf8773..5a79d16 100644 --- a/src/ReverseLinkedListII.java +++ b/src/ReverseLinkedListII.java @@ -3,9 +3,27 @@ private static class ListNode { int val; ListNode next; ListNode(int val) { this.val = val; } + + @Override + public String toString() { + if (next == null) return "ListNode{val=" + val + ", next=null}"; + return "ListNode{" + + "val=" + val + + ", next=" + next + + '}'; + } + } + + public static void main(String[] args) { + ListNode head = new ListNode(1); + head.next = new ListNode(2); + head.next.next = new ListNode(3); + head.next.next.next = new ListNode(4); + head.next.next.next.next = new ListNode(5); + System.out.println(reverseBetween(head, 2, 4)); } - public ListNode reverseBetween(ListNode head, int leftVal, int rightVal) { + public static ListNode reverseBetween(ListNode head, int leftVal, int rightVal) { if (leftVal == rightVal) return head; ListNode sentinelHead = new ListNode(-1000); @@ -13,7 +31,6 @@ public ListNode reverseBetween(ListNode head, int leftVal, int rightVal) { ListNode beforeLeft = getNodeBefore(sentinelHead, leftVal); System.out.println(beforeLeft.val); ListNode left = beforeLeft.next; -// ListNode afterRight = getNodeAfter(sentinelHead, rightVal); ListNode a = beforeLeft.next, b = a.next, c = b.next; while (c != null && b.val != rightVal) { @@ -23,24 +40,16 @@ public ListNode reverseBetween(ListNode head, int leftVal, int rightVal) { b = c; c = c.next; } - a.next = null; b.next = a; beforeLeft.next = b; left.next = c; return sentinelHead.next; } - private ListNode getNodeBefore(ListNode head, int value) { + private static ListNode getNodeBefore(ListNode head, int value) { while (head != null && head.next != null && head.next.val != value) { head = head.next; } return head; } - - private ListNode getNodeAfter(ListNode head, int value) { - while (head != null && head.val != value) { - head = head.next; - } - return head.next; - } } From f4d2ba11e310f81de89f91f52ee0b8e4e4b2b37c Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 4 Feb 2022 12:20:30 +0530 Subject: [PATCH 519/947] solves reverse linked list ii --- README.md | 3 +- src/ReverseLinkedListII.java | 60 ++++++++++++++++++------------------ 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 9854481..fb4b812 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ ## 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) | +| 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) | | | 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) | | @@ -82,6 +82,7 @@ | 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 Lined](https://leetcode.com/problems/decode-ways) | [![Java](assets/java.png)](src/DecodeWays.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) | | | 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) | | diff --git a/src/ReverseLinkedListII.java b/src/ReverseLinkedListII.java index 5a79d16..3e94a1f 100644 --- a/src/ReverseLinkedListII.java +++ b/src/ReverseLinkedListII.java @@ -14,42 +14,42 @@ public String toString() { } } - public static void main(String[] args) { - ListNode head = new ListNode(1); - head.next = new ListNode(2); - head.next.next = new ListNode(3); - head.next.next.next = new ListNode(4); - head.next.next.next.next = new ListNode(5); - System.out.println(reverseBetween(head, 2, 4)); - } + public ListNode reverseBetween(ListNode head, int m, int n) { + if (head == null || m == n) { + return head; + } - public static ListNode reverseBetween(ListNode head, int leftVal, int rightVal) { - if (leftVal == rightVal) return head; + // Move the two pointers until they reach the proper starting point + // in the list. + ListNode cur = head, prev = null; + while (m > 1) { + prev = cur; + cur = cur.next; + m--; + n--; + } - ListNode sentinelHead = new ListNode(-1000); - sentinelHead.next = head; - ListNode beforeLeft = getNodeBefore(sentinelHead, leftVal); - System.out.println(beforeLeft.val); - ListNode left = beforeLeft.next; - ListNode a = beforeLeft.next, b = a.next, c = b.next; + // The two pointers that will fix the final connections. + ListNode con = prev, tail = cur; - while (c != null && b.val != rightVal) { - a.next = null; - b.next = a; - a = b; - b = c; - c = c.next; + // Iteratively reverse the nodes until n becomes 0. + ListNode third = null; + while (n > 0) { + third = cur.next; + cur.next = prev; + prev = cur; + cur = third; + n--; } - b.next = a; - beforeLeft.next = b; - left.next = c; - return sentinelHead.next; - } - private static ListNode getNodeBefore(ListNode head, int value) { - while (head != null && head.next != null && head.next.val != value) { - head = head.next; + // Adjust the final connections + if (con != null) { + con.next = prev; + } else { + head = prev; } + + tail.next = cur; return head; } } From e5cc8f4f5d920a66fdd59299484ae9ae159ae6f9 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 4 Feb 2022 12:22:59 +0530 Subject: [PATCH 520/947] solves reverse linked list ii --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fb4b812..9ae8747 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ ## 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) | +| 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) | | | 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) | | @@ -82,7 +82,7 @@ | 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 Lined](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) | | | 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) | | | 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) | | From 7debb75de4fcbe71781b9491c37ae3fd6d81e232 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 4 Feb 2022 12:57:29 +0530 Subject: [PATCH 521/947] solves rotting oranges --- README.md | 1 + src/RottingOranges.java | 90 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 src/RottingOranges.java diff --git a/README.md b/README.md index 9ae8747..6a865c9 100644 --- a/README.md +++ b/README.md @@ -320,6 +320,7 @@ | 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) | | diff --git a/src/RottingOranges.java b/src/RottingOranges.java new file mode 100644 index 0000000..adcff21 --- /dev/null +++ b/src/RottingOranges.java @@ -0,0 +1,90 @@ +import java.util.HashSet; +import java.util.LinkedList; +import java.util.Objects; +import java.util.Queue; +import java.util.Set; + +public class RottingOranges { + private static final int EMPTY_CELL = 0; + private static final int FRESH_ORANGE = 1; + private static final int ROTTEN_ORANGE = 2; + + private static final class Orange { + private final int row; + private final int column; + private final int minutes; + + private Orange(int row, int column, int minutes) { + this.row = row; + this.column = column; + this.minutes = minutes; + } + + @Override + public boolean equals(Object obj) { + if (obj == this) return true; + if (obj == null || obj.getClass() != this.getClass()) return false; + var that = (Orange) obj; + return this.row == that.row && this.column == that.column; + } + + @Override + public int hashCode() { + return Objects.hash(row, column); + } + } + + public static int orangesRotting(int[][] grid) { + final Queue oranges = allRottingOranges(grid); + final Set visited = new HashSet<>(); + int result = 0; + while (!oranges.isEmpty()) { + Orange orange = oranges.poll(); + if (!isValidPosition(orange, grid) || visited.contains(orange) || isEmptyCell(grid, orange)) { + continue; + } + visited.add(orange); + grid[orange.row][orange.column] = ROTTEN_ORANGE; + oranges.add(new Orange(orange.row - 1, orange.column, orange.minutes + 1)); + oranges.add(new Orange(orange.row, orange.column + 1, orange.minutes + 1)); + oranges.add(new Orange(orange.row + 1, orange.column, orange.minutes + 1)); + oranges.add(new Orange(orange.row, orange.column - 1, orange.minutes + 1)); + result = Math.max(result, orange.minutes); + } + if (allAreRotten(grid)) return result; + return -1; + } + + private static boolean allAreRotten(int[][] grid) { + for (int[] row : grid) { + for (int orange : row) { + if (orange == FRESH_ORANGE) return false; + } + } + return true; + } + + private static Queue allRottingOranges(int[][] grid) { + final Queue rottenOranges = new LinkedList<>(); + for (int row = 0 ; row < grid.length ; row++) { + for (int column = 0 ; column < grid[0].length ; column++) { + if (grid[row][column] == ROTTEN_ORANGE) { + rottenOranges.add(new Orange(row, column, 0)); + } + } + } + return rottenOranges; + } + + private static boolean isValidPosition(Orange orange, int[][] grid) { + return orange.row >= 0 && orange.row < grid.length && orange.column >= 0 && orange.column < grid[0].length; + } + + private static boolean isRotten(int[][] grid, Orange orange) { + return grid[orange.row][orange.column] == ROTTEN_ORANGE; + } + + private static boolean isEmptyCell(int[][] grid, Orange orange) { + return grid[orange.row][orange.column] == EMPTY_CELL; + } +} From f0aff7d6b9dd22b5eb67e8fc9b77cbd3d8d11d84 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 14 Apr 2022 14:26:50 +0200 Subject: [PATCH 522/947] updates readme --- README.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/README.md b/README.md index 6a865c9..790afa7 100644 --- a/README.md +++ b/README.md @@ -83,24 +83,55 @@ | 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) | | | | 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) | | | +| 96 | [Unique Binary Search Trees](https://leetcode.com/problems/unique-binary-search-trees) | | | +| 97 | [Interleaving String](https://leetcode.com/problems/interleaving-string) | | | +| 98 | [Validate Binary Search Tree](https://leetcode.com/problems/validate-binary-search-tree) | | | +| 99 | [Recover Binary Search Tree](https://leetcode.com/problems/recover-binary-search-tree) | | | | 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) | | | +| 103 | [Binary Tree Zigzag Level Order Traversal](https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal) | | | | 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) | | | +| 106 | [Construct Binary Tree from Inorder and Postorder Traversal](https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal) | | | | 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) | | | | 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) | | | +| 114 | [Flatten Binary Tree to Linked List](https://leetcode.com/problems/flatten-binary-tree-to-linked-list) | | | +| 116 | [Populating Next Right Pointers in Each Node](https://leetcode.com/problems/populating-next-right-pointers-in-each-node) | | | +| 117 | [Populating Next Right Pointers in Each Node II](https://leetcode.com/problems/populating-next-right-pointers-in-each-node-ii) | | | | 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) | | | | 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) | | | +| 129 | [Sum Root to Leaf Numbers](https://leetcode.com/problems/sum-root-to-leaf-numbers) | | | +| 130 | [Surrounded Regions](https://leetcode.com/problems/surrounded-regions) | | | +| 131 | [Palindrome Partitioning](https://leetcode.com/problems/palindrome-partitioning) | | | +| 133 | [Clone Graph](https://leetcode.com/problems/clone-graph) | | | +| 134 | [Gas Station](https://leetcode.com/problems/gas-station) | | | | 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) | | | +| 138 | [Copy List with Random Pointer](https://leetcode.com/problems/copy-list-with-random-pointer) | | | +| 139 | [Word Break](https://leetcode.com/problems/word-break) | | | | 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) | | | +| 143 | [Reorder List](https://leetcode.com/problems/reorder-list) | | | | 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) | | | +| 147 | [Insertion Sort List](https://leetcode.com/problems/insertion-sort-list) | | | +| 148 | [Sort List](https://leetcode.com/problems/sort-list) | | | +| 150 | [Evaluate Reverse Polish Notation](https://leetcode.com/problems/evaluate-reverse-polish-notation) | | | | 155 | [Min Stack](https://leetcode.com/problems/min-stack) | [![Java](assets/java.png)](src/MinStack.java) [![Python](assets/python.png)](python/min_stack.py) | | | 157 | [Read N Characters Given Read4](https://leetcode.com/problems/read-n-characters-given-read4) | | | | 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) | | From 3d36e45b83aac5d5466307603dade860e676122f Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 14 Apr 2022 15:40:41 +0200 Subject: [PATCH 523/947] updates readme --- README.md | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 83 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 790afa7..651b164 100644 --- a/README.md +++ b/README.md @@ -132,55 +132,136 @@ | 147 | [Insertion Sort List](https://leetcode.com/problems/insertion-sort-list) | | | | 148 | [Sort List](https://leetcode.com/problems/sort-list) | | | | 150 | [Evaluate Reverse Polish Notation](https://leetcode.com/problems/evaluate-reverse-polish-notation) | | | +| 151 | [Reverse Words in a String](https://leetcode.com/problems/reverse-words-in-a-string) | | | +| 152 | [Maximum Product Subarray](https://leetcode.com/problems/maximum-product-subarray) | | | +| 153 | [Find Minimum in Rotated Sorted Array](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array) | | | | 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) | | | +| 165 | [Compare Version Numbers](https://leetcode.com/problems/compare-version-numbers) | | | +| 166 | [Fraction to Recurring Decimal](https://leetcode.com/problems/fraction-to-recurring-decimal) | | | | 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) | | | +| 179 | [Largest Number](https://leetcode.com/problems/largest-number) | | | +| 187 | [Repeated DNA Sequences](https://leetcode.com/problems/repeated-dna-sequences) | | | | 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) | | | +| 200 | [Number of Islands](https://leetcode.com/problems/number-of-islands) | | | +| 201 | [Bitwise AND of Numbers Range](https://leetcode.com/problems/bitwise-and-of-numbers-range) | | | | 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 Lists](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) | | | +| 208 | [Implement Trie (Prefix Tree)](https://leetcode.com/problems/implement-trie-prefix-tree) | | | +| 209 | [Minimum Size Subarray Sum](https://leetcode.com/problems/minimum-size-subarray-sum) | | | +| 210 | [Course Schedule II](https://leetcode.com/problems/course-schedule-ii) | | | +| 211 | [Design Add and Search Words Data Structure](https://leetcode.com/problems/design-add-and-search-words-data-structure) | | | +| 213 | [House Robber II](https://leetcode.com/problems/house-robber-ii) | | | +| 215 | [Kth Largest Element in an Array](https://leetcode.com/problems/kth-largest-element-in-an-array) | | | +| 216 | [Combination Sum III](https://leetcode.com/problems/combination-sum-iii) | | | | 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate) | [![Java](assets/java.png)](src/ContainsDuplicate.java) [![Python](assets/python.png)](python/contains_duplicate.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) | | | +| 221 | [Maximal Square](https://leetcode.com/problems/maximal-square) | | | +| 222 | [Count Complete Tree Nodes](https://leetcode.com/problems/count-complete-tree-nodes) | | | +| 223 | [Rectangle Area](https://leetcode.com/problems/rectangle-area) | | | | 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) | | -| 226 | [Summary Ranges](https://leetcode.com/problems/summary-ranges/) | [![Java](assets/java.png)](src/SummaryRanges.java) [![Python](assets/python.png)](python/summary_ranges.py) | | +| 228 | [Basic Calculator II](https://leetcode.com/problems/basic-calculator-ii) | | | +| 229 | [Majority Element II](https://leetcode.com/problems/majority-element-ii) | | | +| 230 | [Kth Smallest Element in a BST](https://leetcode.com/problems/kth-smallest-element-in-a-bst) | | | | 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) | | | | 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) | | | +| 240 | [Search a 2D Matrix II](https://leetcode.com/problems/search-a-2d-matrix-ii) | | | +| 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) | | | +| 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) | | | | 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) | | | +| 275 | [H-Index II](https://leetcode.com/problems/h-index-ii) | | | | 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) | | | +| 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) | | | +| 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) | | | +| 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) | | -| 326 | [Counting Bits](https://leetcode.com/problems/counting-bits/) | [![Java](assets/java.png)](src/CountingBits.java) [![Python](assets/python.png)](python/counting_bits.py) | | +| 328 | [Odd Even Linked List](https://leetcode.com/problems/odd-even-linked-list) | [![Java](assets/java.png)](src/PowerOfThree.java) [![Python](assets/python.png)](python/power_of_three.py) | | +| 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) | | | | 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) | | | 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) | | From 4aa0df47db3c651645a691587c913bc9fe6d1f1f Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 14 Apr 2022 17:28:07 +0200 Subject: [PATCH 524/947] solves restores ip addresses in java --- README.md | 2 +- src/RestoreIPAddresses.java | 57 +++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/RestoreIPAddresses.java diff --git a/README.md b/README.md index 651b164..2ecc405 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ | 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) | | | +| 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) | | | | 96 | [Unique Binary Search Trees](https://leetcode.com/problems/unique-binary-search-trees) | | | diff --git a/src/RestoreIPAddresses.java b/src/RestoreIPAddresses.java new file mode 100644 index 0000000..5ad1ef1 --- /dev/null +++ b/src/RestoreIPAddresses.java @@ -0,0 +1,57 @@ +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +public class RestoreIPAddresses { + public List restoreIpAddresses(final String s) { + final List result = new ArrayList<>(); + restoreIpAddresses(s, result, new LinkedList<>(), 0); + return result; + } + + private void restoreIpAddresses(final String s, final List result, LinkedList numbers, int index) { + if (numbers.size() == 4 && index == s.length()) { + result.add(ipAddressFrom(numbers)); + return; + } + if (numbers.size() >= 4 || index == s.length()) { + return; + } + for (int i = index + 1 ; i <= s.length() ; i++) { + if (isValidIpAddressInteger(s, index, i)) { + numbers.add(toNumber(s, index, i)); + restoreIpAddresses(s, result, numbers, i); + numbers.removeLast(); + } else { + break; + } + } + } + + private String ipAddressFrom(LinkedList numbers) { + StringBuilder result = new StringBuilder(); + for (int number : numbers) { + result.append(number).append('.'); + } + result.deleteCharAt(result.length() - 1); + return result.toString(); + } + + private boolean isValidIpAddressInteger(String s, int start, int end) { + if (hasLeadingZeros(s, start, end)) return false; + return toNumber(s, start, end) < 256; + } + + private boolean hasLeadingZeros(String s, int start, int end) { + return end - start > 1 && s.charAt(start) == '0'; + } + + private int toNumber(String s, int start, int end) { + int val = 0; + for (int index = start ; index < end ; index++) { + val *= 10; + val += s.charAt(index) - '0'; + } + return val; + } +} From 85cfd5443fba3dac4bd30514b8610359fd38b8b8 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 20 Apr 2022 19:41:13 +0200 Subject: [PATCH 525/947] a --- CONTRIBUTING.md | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 577d22d..23b1fe5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -30,19 +30,19 @@ To add a logo in the [README](README.md) table simply add a link with an embedde For the icon link refer to the table below to obtain the link for a specific programming language: -| Programming Language | Icon | Icon Link| -|:--------------------:|:----:|:----:| -| Java | ![Java](assets/java.png) | assets/java.png | -| Python | ![Python](assets/python.png) | assets/python.png | -| C | ![C](https://img.icons8.com/color/35/000000/c-programming.png) | https://img.icons8.com/color/35/000000/c-programming.png | -| C++ | ![C++](https://img.icons8.com/color/35/000000/c-plus-plus-logo.png) | https://img.icons8.com/color/35/000000/c-plus-plus-logo.png | -| C# | ![C#](https://img.icons8.com/color/35/000000/c-sharp-logo.png) | https://img.icons8.com/color/35/000000/c-sharp-logo.png | -| JavaScript | ![JavaScript](https://img.icons8.com/color/40/000000/javascript.png) | https://img.icons8.com/color/40/000000/javascript.png | -| TypeScript | ![TypeScript](https://img.icons8.com/color/40/000000/typescript.png) | https://img.icons8.com/color/40/000000/typescript.png | -| Ruby | ![Ruby](https://img.icons8.com/office/35/000000/ruby-programming-language.png) | https://img.icons8.com/office/35/000000/ruby-programming-language.png | -| Scala | ![Scala](https://img.icons8.com/dusk/35/000000/scala.png) | https://img.icons8.com/office/35/000000/ruby-programming-language.png | -| PHP | ![PHP](https://img.icons8.com/officel/40/000000/php-logo.png) | https://img.icons8.com/officel/40/000000/php-logo.png | -| Swift | ![Swift](https://img.icons8.com/fluent/40/000000/swift.png) | https://img.icons8.com/fluent/40/000000/swift.png | +| Programming Language | Icon | Icon Link | +|:--------------------:|:------------------------------------------------------------------------------:|:---------------------------------------------------------------------:| +| Java | ![Java](assets/java.png) | assets/java.png | +| Python | ![Python](assets/python.png) | assets/python.png | +| C | ![C](https://img.icons8.com/color/35/000000/c-programming.png) | https://img.icons8.com/color/35/000000/c-programming.png | +| C++ | ![C++](https://img.icons8.com/color/35/000000/c-plus-plus-logo.png) | https://img.icons8.com/color/35/000000/c-plus-plus-logo.png | +| C# | ![C#](https://img.icons8.com/color/35/000000/c-sharp-logo.png) | https://img.icons8.com/color/35/000000/c-sharp-logo.png | +| JavaScript | ![JavaScript](https://img.icons8.com/color/40/000000/javascript.png) | https://img.icons8.com/color/40/000000/javascript.png | +| TypeScript | ![TypeScript](https://img.icons8.com/color/40/000000/typescript.png) | https://img.icons8.com/color/40/000000/typescript.png | +| Ruby | ![Ruby](https://img.icons8.com/office/35/000000/ruby-programming-language.png) | https://img.icons8.com/office/35/000000/ruby-programming-language.png | +| Scala | ![Scala](https://img.icons8.com/dusk/35/000000/scala.png) | https://img.icons8.com/office/35/000000/ruby-programming-language.png | +| PHP | ![PHP](https://img.icons8.com/officel/40/000000/php-logo.png) | https://img.icons8.com/officel/40/000000/php-logo.png | +| Swift | ![Swift](https://img.icons8.com/fluent/40/000000/swift.png) | https://img.icons8.com/fluent/40/000000/swift.png | From 273836702cac3c253a58c9057666801525975dde Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 21 Apr 2022 09:53:30 +0200 Subject: [PATCH 526/947] solves unique binary search trees ii --- README.md | 4 +- src/TreePrinter.java | 140 +++++++++++++++++++++++++++++ src/UniqueBinarySearchTreesII.java | 69 ++++++++++++++ 3 files changed, 211 insertions(+), 2 deletions(-) create mode 100644 src/TreePrinter.java create mode 100644 src/UniqueBinarySearchTreesII.java diff --git a/README.md b/README.md index 2ecc405..1fc83ab 100644 --- a/README.md +++ b/README.md @@ -84,8 +84,8 @@ | 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) | | | +| 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) | | | | 97 | [Interleaving String](https://leetcode.com/problems/interleaving-string) | | | | 98 | [Validate Binary Search Tree](https://leetcode.com/problems/validate-binary-search-tree) | | | diff --git a/src/TreePrinter.java b/src/TreePrinter.java new file mode 100644 index 0000000..aa7087c --- /dev/null +++ b/src/TreePrinter.java @@ -0,0 +1,140 @@ +import java.util.ArrayList; +import java.util.List; + + +/** + * Binary tree printer + * + * @author saiteja + */ +public class TreePrinter +{ + /** Node that can be printed */ + public interface PrintableNode + { + /** Get left child */ + PrintableNode getLeft(); + + + /** Get right child */ + PrintableNode getRight(); + + + /** Get text to be printed */ + String getText(); + } + + + /** + * Print a tree + * + * @param root + * tree root node + */ + public static void print(PrintableNode root) + { + List> lines = new ArrayList>(); + + List level = new ArrayList(); + List next = new ArrayList(); + + level.add(root); + int nn = 1; + + int widest = 0; + + while (nn != 0) { + List line = new ArrayList(); + + nn = 0; + + for (PrintableNode n : level) { + if (n == null) { + line.add(null); + + next.add(null); + next.add(null); + } else { + String aa = n.getText(); + line.add(aa); + if (aa.length() > widest) widest = aa.length(); + + next.add(n.getLeft()); + next.add(n.getRight()); + + if (n.getLeft() != null) nn++; + if (n.getRight() != null) nn++; + } + } + + if (widest % 2 == 1) widest++; + + lines.add(line); + + List tmp = level; + level = next; + next = tmp; + next.clear(); + } + + int perpiece = lines.get(lines.size() - 1).size() * (widest + 4); + for (int i = 0; i < lines.size(); i++) { + List line = lines.get(i); + int hpw = (int) Math.floor(perpiece / 2f) - 1; + + if (i > 0) { + for (int j = 0; j < line.size(); j++) { + + // split node + char c = ' '; + if (j % 2 == 1) { + if (line.get(j - 1) != null) { + c = (line.get(j) != null) ? '┴' : '┘'; + } else { + if (j < line.size() && line.get(j) != null) c = '└'; + } + } + System.out.print(c); + + // lines and spaces + if (line.get(j) == null) { + for (int k = 0; k < perpiece - 1; k++) { + System.out.print(" "); + } + } else { + + for (int k = 0; k < hpw; k++) { + System.out.print(j % 2 == 0 ? " " : "─"); + } + System.out.print(j % 2 == 0 ? "┌" : "┐"); + for (int k = 0; k < hpw; k++) { + System.out.print(j % 2 == 0 ? "─" : " "); + } + } + } + System.out.println(); + } + + // print line of numbers + for (int j = 0; j < line.size(); j++) { + + String f = line.get(j); + if (f == null) f = ""; + int gap1 = (int) Math.ceil(perpiece / 2f - f.length() / 2f); + int gap2 = (int) Math.floor(perpiece / 2f - f.length() / 2f); + + // a number + for (int k = 0; k < gap1; k++) { + System.out.print(" "); + } + System.out.print(f); + for (int k = 0; k < gap2; k++) { + System.out.print(" "); + } + } + System.out.println(); + + perpiece /= 2; + } + } +} \ No newline at end of file diff --git a/src/UniqueBinarySearchTreesII.java b/src/UniqueBinarySearchTreesII.java new file mode 100644 index 0000000..cb93978 --- /dev/null +++ b/src/UniqueBinarySearchTreesII.java @@ -0,0 +1,69 @@ +import java.util.ArrayList; +import java.util.List; + +public class UniqueBinarySearchTreesII { + private static class TreeNode implements TreePrinter.PrintableNode { + int val; + TreeNode left; + TreeNode right; + + TreeNode(int val) { + this.val = val; + } + + TreeNode(int val, TreeNode left, TreeNode right) { + this.val = val; + this.left = left; + this.right = right; + } + + @Override + public TreePrinter.PrintableNode getLeft() { + return left; + } + + @Override + public TreePrinter.PrintableNode getRight() { + return right; + } + + @Override + public String getText() { + return val + ""; + } + } + + public static List generateTrees(int n) { + List[] result = new List[n + 1]; + result[0] = new ArrayList(); + if (n == 0) { + return result[0]; + } + + result[0].add(null); + for (int len = 1; len <= n; len++) { + result[len] = new ArrayList(); + for (int j = 0; j < len; j++) { + for (TreeNode nodeL : result[j]) { + for (TreeNode nodeR : result[len - j - 1]) { + TreeNode node = new TreeNode(j + 1); + node.left = nodeL; + node.right = clone(nodeR, j + 1); + result[len].add(node); + } + } + } + } + return result[n]; + } + + private static TreeNode clone(TreeNode n, int offset) { + if (n == null) { + return null; + } + TreeNode node = new TreeNode(n.val + offset); + node.left = clone(n.left, offset); + node.right = clone(n.right, offset); + return node; + } +} From 6ff1aa99be54a88b10defb779dc44d639efbfed6 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 21 Apr 2022 14:04:31 +0200 Subject: [PATCH 527/947] solves unique binary search trees --- README.md | 6 +++--- src/UniqueBinarySearchTrees.java | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 src/UniqueBinarySearchTrees.java diff --git a/README.md b/README.md index 1fc83ab..3d86630 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-460/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-460/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-479/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-479/2081-1abc9c.svg) ![problems-solved-python](https://img.shields.io/badge/Python-186/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) @@ -86,7 +86,7 @@ | 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) | | | +| 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) | | | | 98 | [Validate Binary Search Tree](https://leetcode.com/problems/validate-binary-search-tree) | | | | 99 | [Recover Binary Search Tree](https://leetcode.com/problems/recover-binary-search-tree) | | | diff --git a/src/UniqueBinarySearchTrees.java b/src/UniqueBinarySearchTrees.java new file mode 100644 index 0000000..78c5c23 --- /dev/null +++ b/src/UniqueBinarySearchTrees.java @@ -0,0 +1,17 @@ +// T: O(n) +// S: O(1) + +public class UniqueBinarySearchTrees { + public int numTrees(int n) { + return catalanNumber(n); + } + + private int catalanNumber(int n) { + long result = 1; + for (int i = 2 ; i <= n ; i++) { + result *= (4L * i - 2); + result /= i + 1; + } + return (int) result; + } +} From f01fd8ee142a31d85c4dbc4b484675b156329f7b Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 1 May 2022 15:21:56 +0200 Subject: [PATCH 528/947] solves trapping rainwater in java --- README.md | 1 + src/InterleavingString.java | 15 +++++++++++++++ src/TrappingRainwater.java | 17 +++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 src/InterleavingString.java create mode 100644 src/TrappingRainwater.java diff --git a/README.md b/README.md index 3d86630..b01167a 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,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) | | +| 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) | | diff --git a/src/InterleavingString.java b/src/InterleavingString.java new file mode 100644 index 0000000..a7efd81 --- /dev/null +++ b/src/InterleavingString.java @@ -0,0 +1,15 @@ +public class InterleavingString { + public static void main(String[] args) { + System.out.println(isInterleave("aabcc", "dbbca", "aadbbcbcac")); + } + + public static boolean isInterleave(String s1, String s2, String s3) { + if (s1.length() + s2.length() != s3.length()) return false; + for (int i = 0, j = 0, t = 0 ; i <= s1.length() && j <= s2.length() && t < s3.length() ; t++) { + if (i < s1.length() && s3.charAt(t) == s1.charAt(i)) i++; + else if (j < s2.length() && s3.charAt(t) == s2.charAt(j)) j++; + else return false; + } + return true; + } +} diff --git a/src/TrappingRainwater.java b/src/TrappingRainwater.java new file mode 100644 index 0000000..dcf19e7 --- /dev/null +++ b/src/TrappingRainwater.java @@ -0,0 +1,17 @@ +public class TrappingRainwater { + public static int trap(int[] height) { + int result = 0; + for (int left = 0, right = height.length - 1, leftMax = 0, rightMax = 0 ; left < right ; ) { + if (height[left] < height[right]) { + if (leftMax < height[left]) leftMax = height[left]; + else result += leftMax - height[left]; + left++; + } else { + if (rightMax < height[right]) rightMax = height[right]; + else result += rightMax - height[right]; + right--; + } + } + return result; + } +} From 269d5731e33782d5ec61496e22b7c0c2eed5e295 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 1 May 2022 15:25:15 +0200 Subject: [PATCH 529/947] solves trapping rainwater in java --- src/TrappingRainwater.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/TrappingRainwater.java b/src/TrappingRainwater.java index dcf19e7..f06fc83 100644 --- a/src/TrappingRainwater.java +++ b/src/TrappingRainwater.java @@ -1,3 +1,6 @@ +// T: O(n) +// S: O(1) + public class TrappingRainwater { public static int trap(int[] height) { int result = 0; From 8baca0cbf3e69dfd3b79db2a22acf5c862f9c97e Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 1 May 2022 18:12:08 +0200 Subject: [PATCH 530/947] fixes typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b01167a..9aaf752 100644 --- a/README.md +++ b/README.md @@ -165,7 +165,7 @@ | 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 Lists](https://leetcode.com/problems/reverse-linked-list) | [![Java](assets/java.png)](src/ReverseLinkedList.java) [![Python](assets/python.png)](python/reverse_linked_list.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) | | | | 208 | [Implement Trie (Prefix Tree)](https://leetcode.com/problems/implement-trie-prefix-tree) | | | | 209 | [Minimum Size Subarray Sum](https://leetcode.com/problems/minimum-size-subarray-sum) | | | From 6a731d61250e82f159a4226ff60cb389c0d964c5 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 1 May 2022 18:12:23 +0200 Subject: [PATCH 531/947] fixes typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9aaf752..edd6d4b 100644 --- a/README.md +++ b/README.md @@ -165,7 +165,7 @@ | 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) | | +| 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) | | | | 208 | [Implement Trie (Prefix Tree)](https://leetcode.com/problems/implement-trie-prefix-tree) | | | | 209 | [Minimum Size Subarray Sum](https://leetcode.com/problems/minimum-size-subarray-sum) | | | From fec43813f49186982ba3c0e04dd47aaa8f1f6a85 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 1 May 2022 18:49:49 +0200 Subject: [PATCH 532/947] updates reverse linked list ii in java --- src/ReverseLinkedListII.java | 73 ++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 41 deletions(-) diff --git a/src/ReverseLinkedListII.java b/src/ReverseLinkedListII.java index 3e94a1f..08e5c7a 100644 --- a/src/ReverseLinkedListII.java +++ b/src/ReverseLinkedListII.java @@ -1,55 +1,46 @@ +// T: O(n) +// S: O(1) + public class ReverseLinkedListII { - private static class ListNode { + public static class ListNode { int val; ListNode next; + ListNode() {} ListNode(int val) { this.val = val; } - - @Override - public String toString() { - if (next == null) return "ListNode{val=" + val + ", next=null}"; - return "ListNode{" + - "val=" + val + - ", next=" + next + - '}'; - } + ListNode(int val, ListNode next) { this.val = val; this.next = next; } } - public ListNode reverseBetween(ListNode head, int m, int n) { - if (head == null || m == n) { - return head; - } + public ListNode reverseBetween(ListNode head, int left, int right) { + if (left == right) return head; - // Move the two pointers until they reach the proper starting point - // in the list. - ListNode cur = head, prev = null; - while (m > 1) { - prev = cur; - cur = cur.next; - m--; - n--; + ListNode start = new ListNode(); + start.next = head; + + ListNode temp = start; + int i = 1; + for ( ; i < left ; i++) { + temp = temp.next; } - // The two pointers that will fix the final connections. - ListNode con = prev, tail = cur; + ListNode a = temp.next, b = temp.next.next, c = temp.next.next.next; + a.next = null; - // Iteratively reverse the nodes until n becomes 0. - ListNode third = null; - while (n > 0) { - third = cur.next; - cur.next = prev; - prev = cur; - cur = third; - n--; + for ( ; i < right && c != null; i++) { + b.next = a; + a = b; + b = c; + c = c.next; } - - // Adjust the final connections - if (con != null) { - con.next = prev; - } else { - head = prev; + if (i < right) { + b.next = a; + if (left != 1) { + temp.next = b; + return start.next; + } + return b; } - - tail.next = cur; - return head; + temp.next.next = b; + temp.next = a; + return start.next; } } From 7e8f781db5e0568aa34e8f0e1551cc26242f8a0a Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 1 May 2022 19:12:21 +0200 Subject: [PATCH 533/947] solves flatten multilevel doubly linked list --- README.md | 1 + src/FlattenAMultiLevelDoublyLinkedList.java | 49 +++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 src/FlattenAMultiLevelDoublyLinkedList.java diff --git a/README.md b/README.md index edd6d4b..a42c847 100644 --- a/README.md +++ b/README.md @@ -286,6 +286,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) | | | +| 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) | | diff --git a/src/FlattenAMultiLevelDoublyLinkedList.java b/src/FlattenAMultiLevelDoublyLinkedList.java new file mode 100644 index 0000000..ef0bea8 --- /dev/null +++ b/src/FlattenAMultiLevelDoublyLinkedList.java @@ -0,0 +1,49 @@ +// T: O(n) +// S: O(n) + +public class FlattenAMultiLevelDoublyLinkedList { + private static final class Node { + public int val; + public Node prev; + public Node next; + public Node child; + } + + public Node flatten(Node head) { + for (Node temp = head ; temp != null ; temp = temp.next) { + if (temp.child != null) { + Node lastNodeOfFlattenedChildren = flattenLinkedList(temp.child); + lastNodeOfFlattenedChildren.next = temp.next; + if (temp.next != null) { + temp.next.prev = lastNodeOfFlattenedChildren; + } + temp.next = temp.child; + temp.child.prev = temp; + temp.child = null; + } + } + return head; + } + + private Node flattenLinkedList(Node head) { + Node temp = head; + for (; temp.next != null ; temp = temp.next) { + if (temp.child != null) { + Node lastNodeOfFlattenedChildren = flattenLinkedList(temp.child); + lastNodeOfFlattenedChildren.next = temp.next; + temp.next.prev = lastNodeOfFlattenedChildren; + temp.next = temp.child; + temp.child.prev = temp; + temp.child = null; + } + } + if (temp.child != null) { + Node lastNodeOfFlattenedChildren = flattenLinkedList(temp.child); + temp.next = temp.child; + temp.child.prev = temp; + temp.child = null; + return lastNodeOfFlattenedChildren; + } + return temp; + } +} From 34cdbd0912a5315a5fe807f4ee13ac2327549539 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 2 May 2022 17:37:13 +0200 Subject: [PATCH 534/947] a --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a42c847..133b48f 100644 --- a/README.md +++ b/README.md @@ -261,15 +261,25 @@ | 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) | [![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) | | | | 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) | | From c451a765dd8f3bb909154489d922995c5f435611 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 2 May 2022 17:38:25 +0200 Subject: [PATCH 535/947] updates total solved problems --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 133b48f..6511f04 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-479/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-479/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-482/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-482/2081-1abc9c.svg) ![problems-solved-python](https://img.shields.io/badge/Python-186/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) From fb52881c6d8f44d62a2f36cb6922a6eec338b41c Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 2 May 2022 19:25:16 +0200 Subject: [PATCH 536/947] updates linked list cycle --- src/LinkedListCycle.java | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/LinkedListCycle.java b/src/LinkedListCycle.java index bf4265c..1b61206 100644 --- a/src/LinkedListCycle.java +++ b/src/LinkedListCycle.java @@ -1,26 +1,25 @@ -import java.util.HashSet; -import java.util.Set; +// T: O(n) +// S: O(1) public class LinkedListCycle { - static class ListNode { + private static class ListNode { int val; ListNode next; ListNode(int x) { - val = x; - next = null; + val = x; + next = null; } } public boolean hasCycle(ListNode head) { - Set nodes = new HashSet<>(); - while (head != null) { - if (nodes.contains(head)) { - return true; - } else { - nodes.add(head); - } - head = head.next; + if (head == null) return false; + + for (ListNode slow = head, fast = head.next; fast != null && fast.next != null ; ) { + if (slow == fast) return true; + slow = slow.next; + fast = fast.next.next; } + return false; } } From b3065b451d2e829ad505a5beb427d5686872993d Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 5 May 2022 14:17:30 +0200 Subject: [PATCH 537/947] solves lru cache --- README.md | 2 +- src/LRUCache.java | 84 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 src/LRUCache.java diff --git a/README.md b/README.md index 6511f04..3b90547 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ | 143 | [Reorder List](https://leetcode.com/problems/reorder-list) | | | | 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) | | | +| 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) | | | | 148 | [Sort List](https://leetcode.com/problems/sort-list) | | | | 150 | [Evaluate Reverse Polish Notation](https://leetcode.com/problems/evaluate-reverse-polish-notation) | | | diff --git a/src/LRUCache.java b/src/LRUCache.java new file mode 100644 index 0000000..f0862e2 --- /dev/null +++ b/src/LRUCache.java @@ -0,0 +1,84 @@ +// T: O(n) +// S: O(n) + +import java.util.HashMap; +import java.util.Map; + +public class LRUCache { + private static class Node { + int key; + int value; + Node next; + Node previous; + + Node() { } + Node(int key, int value) { + this.key = key; + this.value = value; + } + } + + private final int capacity; + private final Map cache = new HashMap<>(); + 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) { + return -1; + } + moveToHead(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.size() > capacity){ + Node tail = popTail(); + this.cache.remove(tail.key); + } + } else { + node.value = value; + moveToHead(node); + } + } + + private Node popTail(){ + Node res = tail.previous; + this.removeNode(res); + return res; + } + + private void addNode(Node node) { + node.previous = head; + node.next = head.next; + head.next.previous = node; + head.next = node; + } + + private void removeNode(Node node){ + Node pre = node.previous; + Node post = node.next; + pre.next = post; + post.previous = pre; + } + + private void moveToHead(Node node){ + this.removeNode(node); + this.addNode(node); + } +} From e1dd58feb7da943372e87cc87c2ae47356fe6918 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 5 May 2022 18:48:12 +0200 Subject: [PATCH 538/947] updates valid parantheses --- src/ValidParentheses.java | 59 ++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 35 deletions(-) diff --git a/src/ValidParentheses.java b/src/ValidParentheses.java index 5d95593..ea31056 100644 --- a/src/ValidParentheses.java +++ b/src/ValidParentheses.java @@ -1,48 +1,37 @@ // https://leetcode.com/problems/valid-parentheses/ +// T: O(n) +// S: O(n) -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; import java.util.Set; import java.util.Stack; public class ValidParentheses { - private static final Set openBrackets = new HashSet<>(); - private static final Map inverse = new HashMap<>(); - - static { - openBrackets.add('('); - openBrackets.add('{'); - openBrackets.add('['); - - inverse.put(')', '('); - inverse.put('}', '{'); - inverse.put(']', '['); - } - - public boolean isValid(String string) { - Stack brackets = new Stack<>(); - for(int index = 0 ; index < string.length() ; index++) { - char character = string.charAt(index); - if (isOpenBracket(character)) { - brackets.push(character); - } else { - if (!brackets.isEmpty() && brackets.peek() == inverse(character)) { - brackets.pop(); - } else { - return false; - } - } + private static final Set CLOSING_BRACES = Set.of(')', ']', '}'); + + public boolean isValid(String s) { + final Stack stack = new Stack<>(); + char bracket; + for (int i = 0 ; i < s.length() ; i++) { + bracket = s.charAt(i); + if (isClosingBracket(bracket)) { + if (!stack.isEmpty() && areOpposites(stack.peek(), bracket)) { + stack.pop(); + } else return false; + } else stack.push(bracket); } - - return brackets.isEmpty(); + return stack.isEmpty(); } - private char inverse(char bracket) { - return inverse.get(bracket); + private boolean isClosingBracket(char c) { + return CLOSING_BRACES.contains(c); } - private boolean isOpenBracket(char bracket) { - return openBrackets.contains(bracket); + private boolean areOpposites(char left, char right) { + return switch(left) { + case '(' -> right == ')'; + case '[' -> right == ']'; + case '{' -> right == '}'; + default -> false; + }; } } From 3982b6d2078545fe2dd88b9264738743559d2eb7 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 5 May 2022 19:11:04 +0200 Subject: [PATCH 539/947] solves minimum removals to make valid parentheses inj java --- README.md | 1 + src/MinimumRemoveToMakeValidParentheses.java | 44 ++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 src/MinimumRemoveToMakeValidParentheses.java diff --git a/README.md b/README.md index 3b90547..427fbb5 100644 --- a/README.md +++ b/README.md @@ -504,6 +504,7 @@ | 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) | | | 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) | | diff --git a/src/MinimumRemoveToMakeValidParentheses.java b/src/MinimumRemoveToMakeValidParentheses.java new file mode 100644 index 0000000..f7a5e96 --- /dev/null +++ b/src/MinimumRemoveToMakeValidParentheses.java @@ -0,0 +1,44 @@ +// https://leetcode.com/problems/minimum-remove-to-make-valid-parentheses +// T: O(n) +// S: O(n) + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.Stack; + +public class MinimumRemoveToMakeValidParentheses { + private static final record OpeningBrace(int index) { } + + public String minRemoveToMakeValid(String s) { + final Stack stack = new Stack<>(); + final List extraClosingBraceIndices = new ArrayList<>(); + char c; + for (int i = 0 ; i < s.length() ; i++) { + c = s.charAt(i); + if (c == ')') { + if (!stack.isEmpty()) { + stack.pop(); + } else extraClosingBraceIndices.add(i); + } else if (c == '(') stack.push(new OpeningBrace(i)); + } + final Set errorIndices = compileErrorIndicesFrom(extraClosingBraceIndices, stack); + StringBuilder result = new StringBuilder(); + for (int i = 0; i < s.length() ; i++) { + if (!errorIndices.contains(i)) { + result.append(s.charAt(i)); + } + } + return result.toString(); + } + + private Set compileErrorIndicesFrom(List wrongClosingBraces, Stack openingBraces) { + Set result = new HashSet<>(); + while (!openingBraces.isEmpty()) { + result.add(openingBraces.pop().index); + } + result.addAll(wrongClosingBraces); + return result; + } +} From ea4643aa4de35b35a4e15361b6370d8bb7f10bb7 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 5 May 2022 19:45:56 +0200 Subject: [PATCH 540/947] solves kth largest element in array in java --- README.md | 2 +- src/KthLargestElementInAnArray.java | 34 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/KthLargestElementInAnArray.java diff --git a/README.md b/README.md index 427fbb5..363a73d 100644 --- a/README.md +++ b/README.md @@ -172,7 +172,7 @@ | 210 | [Course Schedule II](https://leetcode.com/problems/course-schedule-ii) | | | | 211 | [Design Add and Search Words Data Structure](https://leetcode.com/problems/design-add-and-search-words-data-structure) | | | | 213 | [House Robber II](https://leetcode.com/problems/house-robber-ii) | | | -| 215 | [Kth Largest Element in an Array](https://leetcode.com/problems/kth-largest-element-in-an-array) | | | +| 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) | | | | 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate) | [![Java](assets/java.png)](src/ContainsDuplicate.java) [![Python](assets/python.png)](python/contains_duplicate.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) | | diff --git a/src/KthLargestElementInAnArray.java b/src/KthLargestElementInAnArray.java new file mode 100644 index 0000000..02ac421 --- /dev/null +++ b/src/KthLargestElementInAnArray.java @@ -0,0 +1,34 @@ +// https://leetcode.com/problems/kth-largest-element-in-an-array +// T: O(n) +// S: O(1) + +public class KthLargestElementInAnArray { + public int findKthLargest(int[] nums, int k) { + int partitionIndex = nums.length - k; + for (int left = 0, right = nums.length - 1, j ; left < right ; ) { + j = partition(nums, left, right); + if (j == partitionIndex) return nums[partitionIndex]; + else if (j < partitionIndex) left = j + 1; + else right = j - 1; + } + return nums[partitionIndex]; + } + + private int partition(int[] array, int left, int right) { + int pivot = array[right], i = left - 1; + for (int j = left ; j < right ; j++) { + if (array[j] < pivot) { + i++; + swap(array, i, j); + } + } + swap(array, i + 1, right); + return i + 1; + } + + private void swap(int[] array, int i, int j) { + int temp = array[i]; + array[i] = array[j]; + array[j] = temp; + } +} From 75171a3f246c8e9c87b98d41e309f622189e4e6f Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sat, 7 May 2022 12:33:57 +0200 Subject: [PATCH 541/947] solves binary tree level order traversal in java --- README.md | 2 +- src/BinaryTreeLevelOrderTraversal.java | 38 ++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/BinaryTreeLevelOrderTraversal.java diff --git a/README.md b/README.md index 363a73d..dab9a8f 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ | 99 | [Recover Binary Search Tree](https://leetcode.com/problems/recover-binary-search-tree) | | | | 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) | | | +| 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) | | | | 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) | | | diff --git a/src/BinaryTreeLevelOrderTraversal.java b/src/BinaryTreeLevelOrderTraversal.java new file mode 100644 index 0000000..a6c07f6 --- /dev/null +++ b/src/BinaryTreeLevelOrderTraversal.java @@ -0,0 +1,38 @@ +// https://leetcode.com/problems/binary-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 BinaryTreeLevelOrderTraversal { + public List> levelOrder(TreeNode root) { + if (root == null) { + return List.of(); + } + + final Queue queue = new LinkedList<>(); + queue.add(root); + queue.add(null); + final List> result = new ArrayList<>(); + List level = new ArrayList<>(); + + while (!queue.isEmpty()) { + TreeNode current = queue.poll(); + if (current == null) { + result.add(level); + if (!queue.isEmpty()) { + queue.add(null); + level = new ArrayList<>(); + } + } else { + level.add(current.val); + if (current.left != null) queue.add(current.left); + if (current.right != null) queue.add(current.right); + } + } + return result; + } +} From 121971ba884e52e22cc125e3aec916bb1cf7f31d Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 7 May 2022 21:30:54 +0200 Subject: [PATCH 542/947] shifts tree node to personal class --- src/HelloWorld.java | 5 +++++ src/MinimumDistanceBetweenBSTNodes.java | 13 ------------- src/TreeNode.java | 12 ++++++++++++ 3 files changed, 17 insertions(+), 13 deletions(-) create mode 100644 src/HelloWorld.java create mode 100644 src/TreeNode.java diff --git a/src/HelloWorld.java b/src/HelloWorld.java new file mode 100644 index 0000000..74f62ba --- /dev/null +++ b/src/HelloWorld.java @@ -0,0 +1,5 @@ +public class HelloWorld { + public static void main(String[] args) { + System.out.println("Hello world"); + } +} diff --git a/src/MinimumDistanceBetweenBSTNodes.java b/src/MinimumDistanceBetweenBSTNodes.java index ce8fe6c..654c796 100644 --- a/src/MinimumDistanceBetweenBSTNodes.java +++ b/src/MinimumDistanceBetweenBSTNodes.java @@ -1,16 +1,3 @@ -class TreeNode { - int val; - TreeNode left; - TreeNode right; - TreeNode() {} - TreeNode(int val) { this.val = val; } - TreeNode(int val, TreeNode left, TreeNode right) { - this.val = val; - this.left = left; - this.right = right; - } -} - public class MinimumDistanceBetweenBSTNodes { long result = Integer.MAX_VALUE; diff --git a/src/TreeNode.java b/src/TreeNode.java new file mode 100644 index 0000000..4389491 --- /dev/null +++ b/src/TreeNode.java @@ -0,0 +1,12 @@ +public class TreeNode { + int val; + TreeNode left; + TreeNode right; + TreeNode() {} + TreeNode(int val) { this.val = val; } + TreeNode(int val, TreeNode left, TreeNode right) { + this.val = val; + this.left = left; + this.right = right; + } +} From 97c338576fcd22cbed337b5327c4f3022af676d3 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 7 May 2022 21:41:19 +0200 Subject: [PATCH 543/947] solves right side view in java --- README.md | 2 +- src/BinaryTreeRightSideView.java | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/BinaryTreeRightSideView.java diff --git a/README.md b/README.md index dab9a8f..60aeccf 100644 --- a/README.md +++ b/README.md @@ -158,7 +158,7 @@ | 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) | | | +| 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) | | | | 201 | [Bitwise AND of Numbers Range](https://leetcode.com/problems/bitwise-and-of-numbers-range) | | | | 202 | [Happy Number](https://leetcode.com/problems/happy-number) | [![Java](assets/java.png)](src/HappyNumber.java) [![Python](assets/python.png)](python/happy_number.py) | | diff --git a/src/BinaryTreeRightSideView.java b/src/BinaryTreeRightSideView.java new file mode 100644 index 0000000..eee78cd --- /dev/null +++ b/src/BinaryTreeRightSideView.java @@ -0,0 +1,22 @@ +// https://leetcode.com/problems/binary-tree-right-side-view +// T: O(n) +// S: O(log(n)) + +import java.util.ArrayList; +import java.util.List; + +public class BinaryTreeRightSideView { + public List rightSideView(TreeNode root) { + final List result = new ArrayList<>(); + rightSideView(root, result, 0); + return result; + } + + private void rightSideView(TreeNode root, final List result, int level) { + if (root == null) return; + if (level == result.size()) result.add(root.val); + + rightSideView(root.right, result, level + 1); + rightSideView(root.left, result, level + 1); + } +} From b1e0d04ff1aea0bfcc59150227584b67ed334d41 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 8 May 2022 11:27:09 +0200 Subject: [PATCH 544/947] solves complete tree nodes in java --- README.md | 2 +- src/CountCompleteTreeNodes.java | 19 +++++++++++++++++++ src/TreeNode.java | 17 ++++++++++++++++- src/TreePrinter.java | 11 +++-------- 4 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 src/CountCompleteTreeNodes.java diff --git a/README.md b/README.md index 60aeccf..8993391 100644 --- a/README.md +++ b/README.md @@ -178,7 +178,7 @@ | 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) | | | | 221 | [Maximal Square](https://leetcode.com/problems/maximal-square) | | | -| 222 | [Count Complete Tree Nodes](https://leetcode.com/problems/count-complete-tree-nodes) | | | +| 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) | | | | 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) | | diff --git a/src/CountCompleteTreeNodes.java b/src/CountCompleteTreeNodes.java new file mode 100644 index 0000000..b0611fb --- /dev/null +++ b/src/CountCompleteTreeNodes.java @@ -0,0 +1,19 @@ +// https://leetcode.com/problems/count-complete-tree-nodes +// T: O(log(n) ^ 2) +// S: O(log(n)) + +public class CountCompleteTreeNodes { + private static int depth(TreeNode root) { + if (root == null) return 0; + return 1 + depth(root.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)); + } +} diff --git a/src/TreeNode.java b/src/TreeNode.java index 4389491..0d2d037 100644 --- a/src/TreeNode.java +++ b/src/TreeNode.java @@ -1,4 +1,4 @@ -public class TreeNode { +public class TreeNode implements TreePrinter.PrintableNode { int val; TreeNode left; TreeNode right; @@ -9,4 +9,19 @@ public class TreeNode { this.left = left; this.right = right; } + + @Override + public TreePrinter.PrintableNode getLeft() { + return this.left; + } + + @Override + public TreePrinter.PrintableNode getRight() { + return this.right; + } + + @Override + public String getText() { + return this.val + ""; + } } diff --git a/src/TreePrinter.java b/src/TreePrinter.java index aa7087c..6a4ded1 100644 --- a/src/TreePrinter.java +++ b/src/TreePrinter.java @@ -7,19 +7,15 @@ * * @author saiteja */ -public class TreePrinter -{ +public class TreePrinter { /** Node that can be printed */ - public interface PrintableNode - { + public interface PrintableNode { /** Get left child */ PrintableNode getLeft(); - /** Get right child */ PrintableNode getRight(); - /** Get text to be printed */ String getText(); } @@ -31,8 +27,7 @@ public interface PrintableNode * @param root * tree root node */ - public static void print(PrintableNode root) - { + public static void print(PrintableNode root) { List> lines = new ArrayList>(); List level = new ArrayList(); From 97f179c62e912c14794d6ac5b59b9fb460836363 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 8 May 2022 11:41:14 +0200 Subject: [PATCH 545/947] solves validate bst in java --- README.md | 2 +- src/ValidateBinarySearchTree.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/ValidateBinarySearchTree.java diff --git a/README.md b/README.md index 8993391..1867bef 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,7 @@ | 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) | | | -| 98 | [Validate Binary Search Tree](https://leetcode.com/problems/validate-binary-search-tree) | | | +| 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) | | | | 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) | | diff --git a/src/ValidateBinarySearchTree.java b/src/ValidateBinarySearchTree.java new file mode 100644 index 0000000..8aa408a --- /dev/null +++ b/src/ValidateBinarySearchTree.java @@ -0,0 +1,17 @@ +// https://leetcode.com/problems/validate-binary-search-tree +// T: O(n) +// S: O(log(n)) + +public class ValidateBinarySearchTree { + public boolean isValidBST(TreeNode root) { + return isValidBST(root, Long.MIN_VALUE, Long.MAX_VALUE); + } + + private boolean isValidBST(TreeNode root, long minLeftVal, long maxRightVal) { + if (root == null) return true; + return minLeftVal < root.val + && root.val < maxRightVal + && isValidBST(root.left, minLeftVal, root.val) + && isValidBST(root.right, root.val, maxRightVal); + } +} From 06be5bd926308860fa4c7f6eb6ff01a99459b024 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 8 May 2022 12:05:38 +0200 Subject: [PATCH 546/947] solves number of islands in java --- README.md | 2 +- src/NumberOfIslands.java | 52 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/NumberOfIslands.java diff --git a/README.md b/README.md index 1867bef..1985a44 100644 --- a/README.md +++ b/README.md @@ -159,7 +159,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) | | | +| 200 | [Number of Islands](https://leetcode.com/problems/number-of-islands) | [![Java](assets/java.png)](src/NumberOfIslands.java) | | | 201 | [Bitwise AND of Numbers Range](https://leetcode.com/problems/bitwise-and-of-numbers-range) | | | | 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) | | diff --git a/src/NumberOfIslands.java b/src/NumberOfIslands.java new file mode 100644 index 0000000..e820177 --- /dev/null +++ b/src/NumberOfIslands.java @@ -0,0 +1,52 @@ +// https://leetcode.com/problems/number-of-islands +// T: O(m * n) +// T: O(m * n) + +public class NumberOfIslands { + private static final char VISITED = '0'; + private static final char ISLAND = '1'; + + public int numIslands(char[][] grid) { + final int rows = grid.length, columns = grid[0].length; + int islands = 0; + + for (int row = 0 ; row < rows ; row++) { + for (int column = 0 ; column < columns ; column++) { + if (isIsland(grid[row][column])) { + islands++; + markIslandAsSeen(grid, row, column); + } + } + } + + return islands; + } + + private boolean isIsland(char c) { + return c == ISLAND; + } + + private void markIslandAsSeen(char[][] grid, int row, int column) { + if (!isValidPosition(grid, row, column) || !isIsland(grid[row][column])) return; + markVisited(grid, row, column); + markIslandAsSeen(grid, row - 1, column); + markIslandAsSeen(grid, row, column + 1); + markIslandAsSeen(grid, row + 1, column); + markIslandAsSeen(grid, row, column - 1); + } + + private boolean isValidPosition(char[][] grid, int row, int column) { + return row >= 0 + && row < grid.length + && column >= 0 + && column < grid[0].length; + } + + private boolean alreadyVisited(char c) { + return c == VISITED; + } + + private void markVisited(char[][] grid, int row, int column) { + grid[row][column] = VISITED; + } +} From 31797d1d63a668c93d4d0689b6d3456e8718f2f8 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 8 May 2022 12:28:49 +0200 Subject: [PATCH 547/947] updates rotting oranges --- src/RottingOranges.java | 125 +++++++++++++++++++++------------------- 1 file changed, 66 insertions(+), 59 deletions(-) diff --git a/src/RottingOranges.java b/src/RottingOranges.java index adcff21..4b3b10d 100644 --- a/src/RottingOranges.java +++ b/src/RottingOranges.java @@ -1,90 +1,97 @@ -import java.util.HashSet; import java.util.LinkedList; -import java.util.Objects; import java.util.Queue; -import java.util.Set; public class RottingOranges { - private static final int EMPTY_CELL = 0; + private record RottenOrange(int row, int column, int time) {} + private static final int FRESH_ORANGE = 1; private static final int ROTTEN_ORANGE = 2; - private static final class Orange { - private final int row; - private final int column; - private final int minutes; - - private Orange(int row, int column, int minutes) { - this.row = row; - this.column = column; - this.minutes = minutes; - } + public int orangesRotting(int[][] grid) { + final Queue queue = new LinkedList<>(); + addAllRottenOrangesToQueue(grid, queue); + int elapsedTime = 0; - @Override - public boolean equals(Object obj) { - if (obj == this) return true; - if (obj == null || obj.getClass() != this.getClass()) return false; - var that = (Orange) obj; - return this.row == that.row && this.column == that.column; + while (!queue.isEmpty()) { + RottenOrange orange = queue.poll(); + addAdjacentOrangesInQueue(orange, queue, grid); + elapsedTime = Math.max(elapsedTime, orange.time); } - @Override - public int hashCode() { - return Objects.hash(row, column); - } + if (containsFreshOranges(grid)) return -1; + return elapsedTime; } - public static int orangesRotting(int[][] grid) { - final Queue oranges = allRottingOranges(grid); - final Set visited = new HashSet<>(); - int result = 0; - while (!oranges.isEmpty()) { - Orange orange = oranges.poll(); - if (!isValidPosition(orange, grid) || visited.contains(orange) || isEmptyCell(grid, orange)) { - continue; + private void addAllRottenOrangesToQueue(int[][] grid, final Queue queue) { + for (int row = 0 ; row < grid.length ; row++) { + for (int column = 0 ; column < grid[0].length ; column++) { + if (isRottenOrange(grid[row][column])) { + queue.add(new RottenOrange(row, column, 0)); + } } - visited.add(orange); - grid[orange.row][orange.column] = ROTTEN_ORANGE; - oranges.add(new Orange(orange.row - 1, orange.column, orange.minutes + 1)); - oranges.add(new Orange(orange.row, orange.column + 1, orange.minutes + 1)); - oranges.add(new Orange(orange.row + 1, orange.column, orange.minutes + 1)); - oranges.add(new Orange(orange.row, orange.column - 1, orange.minutes + 1)); - result = Math.max(result, orange.minutes); } - if (allAreRotten(grid)) return result; - return -1; } - private static boolean allAreRotten(int[][] grid) { + private boolean isRottenOrange(int orange) { + return orange == ROTTEN_ORANGE; + } + + private boolean isFreshOrange(int orange) { + return orange == FRESH_ORANGE; + } + + private boolean containsFreshOranges(int[][] grid) { for (int[] row : grid) { for (int orange : row) { - if (orange == FRESH_ORANGE) return false; + if (isFreshOrange(orange)) return true; } } - return true; + return false; } - private static Queue allRottingOranges(int[][] grid) { - final Queue rottenOranges = new LinkedList<>(); - for (int row = 0 ; row < grid.length ; row++) { - for (int column = 0 ; column < grid[0].length ; column++) { - if (grid[row][column] == ROTTEN_ORANGE) { - rottenOranges.add(new Orange(row, column, 0)); - } - } + private void addAdjacentOrangesInQueue(RottenOrange orange, Queue queue, int[][] grid) { + addOrangeOnTop(orange, queue, grid); + addOrangeOnRight(orange, queue, grid); + addOrangeOnBottom(orange, queue, grid); + addOrangeOnLeft(orange, queue, grid); + } + + private void addOrangeOnTop(RottenOrange orange, Queue queue, int[][] grid) { + if (isValidPosition(grid, orange.row - 1, orange.column) && isFreshOrange(grid[orange.row - 1][orange.column])) { + markRotten(grid, orange.row - 1, orange.column); + queue.add(new RottenOrange(orange.row - 1, orange.column, orange.time + 1)); + } + } + + private void addOrangeOnRight(RottenOrange orange, Queue queue, int[][] grid) { + if (isValidPosition(grid, orange.row, orange.column + 1) && isFreshOrange(grid[orange.row][orange.column + 1])) { + markRotten(grid, orange.row, orange.column + 1); + queue.add(new RottenOrange(orange.row, orange.column + 1, orange.time + 1)); + } + } + + private void addOrangeOnBottom(RottenOrange orange, Queue queue, int[][] grid) { + if (isValidPosition(grid, orange.row + 1, orange.column) && isFreshOrange(grid[orange.row + 1][orange.column])) { + markRotten(grid, orange.row + 1, orange.column); + queue.add(new RottenOrange(orange.row + 1, orange.column, orange.time + 1)); } - return rottenOranges; } - private static boolean isValidPosition(Orange orange, int[][] grid) { - return orange.row >= 0 && orange.row < grid.length && orange.column >= 0 && orange.column < grid[0].length; + private void addOrangeOnLeft(RottenOrange orange, Queue queue, int[][] grid) { + if (isValidPosition(grid, orange.row, orange.column - 1) && isFreshOrange(grid[orange.row][orange.column - 1])) { + markRotten(grid, orange.row, orange.column - 1); + queue.add(new RottenOrange(orange.row, orange.column - 1, orange.time + 1)); + } } - private static boolean isRotten(int[][] grid, Orange orange) { - return grid[orange.row][orange.column] == ROTTEN_ORANGE; + private boolean isValidPosition(int[][] grid, int row, int column) { + return row >= 0 + && row < grid.length + && column >= 0 + && column < grid[0].length; } - private static boolean isEmptyCell(int[][] grid, Orange orange) { - return grid[orange.row][orange.column] == EMPTY_CELL; + private void markRotten(int[][] grid, int row, int column) { + grid[row][column] = ROTTEN_ORANGE; } } From f61606e9721b736378e189c13d6a08036c466419 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 8 May 2022 12:28:53 +0200 Subject: [PATCH 548/947] updates rotting oranges --- src/RottingOranges.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/RottingOranges.java b/src/RottingOranges.java index 4b3b10d..015528e 100644 --- a/src/RottingOranges.java +++ b/src/RottingOranges.java @@ -1,3 +1,7 @@ +// https://leetcode.com/problems/rotting-oranges +// T: O(m * n) +// S: O(m * n) + import java.util.LinkedList; import java.util.Queue; From fda12cb4a5e9876e40c4e7485a6dbd8944caf494 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 8 May 2022 12:43:13 +0200 Subject: [PATCH 549/947] updates stats --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1985a44..73d9c9b 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-482/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-482/2081-1abc9c.svg) -![problems-solved-python](https://img.shields.io/badge/Python-186/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-490/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-490/2081-1abc9c.svg) +![problems-solved-python](https://img.shields.io/badge/Python-185/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) From 544844a0e6a7833223230003ea06e2d36cbdd388 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 8 May 2022 14:24:18 +0200 Subject: [PATCH 550/947] solves time needed to infrom all employees in java --- README.md | 1 + src/TimeNeededToInformAllEmployees.java | 57 +++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 src/TimeNeededToInformAllEmployees.java diff --git a/README.md b/README.md index 73d9c9b..4f19df3 100644 --- a/README.md +++ b/README.md @@ -531,6 +531,7 @@ | 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) | | diff --git a/src/TimeNeededToInformAllEmployees.java b/src/TimeNeededToInformAllEmployees.java new file mode 100644 index 0000000..9aec965 --- /dev/null +++ b/src/TimeNeededToInformAllEmployees.java @@ -0,0 +1,57 @@ +// https://leetcode.com/problems/time-needed-to-inform-all-employees +// T: O(n) +// S: O(n) + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class TimeNeededToInformAllEmployees { + private static final class TreeNode { + int val; + List subordinates = new ArrayList<>(); + + TreeNode(int val) { + this.val = val; + } + + private boolean hasSubordinates() { + return subordinates.size() > 0; + } + + private void addSubordinate(TreeNode subordinate) { + this.subordinates.add(subordinate); + } + } + + public int numOfMinutes(int n, int headID, int[] manager, int[] informTime) { + TreeNode company = createEmployeeGraph(headID, manager); + return timeNeededForInformationDispersal(company, informTime); + } + + private int timeNeededForInformationDispersal(TreeNode root, int[] informTime) { + if (root == null || !root.hasSubordinates()) return 0; + int timeTaken = 0; + for (TreeNode subordinate : root.subordinates) { + timeTaken = Math.max(timeTaken, timeNeededForInformationDispersal(subordinate, informTime)); + } + return timeTaken + informTime[root.val]; + } + + private TreeNode createEmployeeGraph(int headIndex, int[] managers) { + final TreeNode root = new TreeNode(headIndex); + final Map employees = new HashMap<>(); + employees.put(headIndex, root); + for (int i = 0 ; i < managers.length ; i++) { + int managerId = managers[i]; + if (managerId == -1) continue; + TreeNode manager = employees.getOrDefault(managerId, new TreeNode(managerId)); + TreeNode subordinate = employees.getOrDefault(i, new TreeNode(i)); + manager.addSubordinate(subordinate); + if (!employees.containsKey(managerId)) employees.put(managerId, manager); + if (!employees.containsKey(i)) employees.put(i, subordinate); + } + return root; + } +} From eec695bad5d018c06b0fa764ce43dff911d04508 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 8 May 2022 14:54:38 +0200 Subject: [PATCH 551/947] solves course schedule in java --- README.md | 2 +- src/CourseSchedule.java | 62 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 src/CourseSchedule.java diff --git a/README.md b/README.md index 4f19df3..939d0bf 100644 --- a/README.md +++ b/README.md @@ -166,7 +166,7 @@ | 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) | | | +| 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) | | | | 209 | [Minimum Size Subarray Sum](https://leetcode.com/problems/minimum-size-subarray-sum) | | | | 210 | [Course Schedule II](https://leetcode.com/problems/course-schedule-ii) | | | diff --git a/src/CourseSchedule.java b/src/CourseSchedule.java new file mode 100644 index 0000000..b73812e --- /dev/null +++ b/src/CourseSchedule.java @@ -0,0 +1,62 @@ +// https://leetcode.com/problems/course-schedule +// T: O(|pre-requisites| + numCourses) +// S: O(numCourses) + +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 CourseSchedule { + public boolean canFinish(int numCourses, int[][] prerequisites) { + final Map> dependencyGraph = getDependencyGraph(prerequisites); + return !containsLoop(dependencyGraph, numCourses); + } + + private boolean containsLoop(Map> graph, int numCourses) { + Set computed = new HashSet<>(); + for (int i = 0 ; i < numCourses ; i++) { + if (graph.containsKey(i)) { + if (computed.contains(i)) continue; + if (containsLoop(graph, i, computed)) { + return true; + } + } + } + return false; + } + + private boolean containsLoop(Map> graph, int vertex, Set computed) { + return containsLoop(graph, vertex, computed, new HashSet<>()); + } + + private boolean containsLoop(Map> graph, int vertex, Set computed, Set visited) { + if (visited.contains(vertex)) return true; + if (computed.contains(vertex)) return false; + visited.add(vertex); + computed.add(vertex); + if (graph.containsKey(vertex)) { + List dependsOn = graph.get(vertex); + for (int dependency : dependsOn) { + if (containsLoop(graph, dependency, computed, visited)) { + return true; + } + } + } + visited.remove(vertex); + return false; + } + + private Map> getDependencyGraph(int[][] prerequisites) { + final Map> dependencyGraph = new HashMap<>(); + for (int[] prerequisite : prerequisites) { + if (!dependencyGraph.containsKey(prerequisite[0])) { + dependencyGraph.put(prerequisite[0], new ArrayList<>()); + } + dependencyGraph.get(prerequisite[0]).add(prerequisite[1]); + } + return dependencyGraph; + } +} From 761ec3d1ed297d1944660ca3255bb2a3e192d068 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Sun, 8 May 2022 16:02:13 +0200 Subject: [PATCH 552/947] solves course schedule in java --- src/CourseSchedule.java | 62 ++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/src/CourseSchedule.java b/src/CourseSchedule.java index b73812e..45047e2 100644 --- a/src/CourseSchedule.java +++ b/src/CourseSchedule.java @@ -4,52 +4,56 @@ import java.util.ArrayList; import java.util.HashMap; -import java.util.HashSet; +import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.Set; +import java.util.Queue; public class CourseSchedule { public boolean canFinish(int numCourses, int[][] prerequisites) { - final Map> dependencyGraph = getDependencyGraph(prerequisites); - return !containsLoop(dependencyGraph, numCourses); - } + final int[] inDegree = getInDegreeValues(prerequisites, numCourses); + final Queue queue = queueWithInDegree0Vertices(inDegree); + final Map> graph = getDependencyGraph(prerequisites); - private boolean containsLoop(Map> graph, int numCourses) { - Set computed = new HashSet<>(); - for (int i = 0 ; i < numCourses ; i++) { - if (graph.containsKey(i)) { - if (computed.contains(i)) continue; - if (containsLoop(graph, i, computed)) { - return true; + while (!queue.isEmpty()) { + int vertex = queue.poll(); + if (graph.containsKey(vertex)) { + for (int adjacent : graph.get(vertex)) { + inDegree[adjacent]--; + if (inDegree[adjacent] == 0) queue.add(adjacent); } } } - return false; + + return allAreZero(inDegree); } - private boolean containsLoop(Map> graph, int vertex, Set computed) { - return containsLoop(graph, vertex, computed, new HashSet<>()); + private boolean allAreZero(int[] array) { + for (int element : array) { + if (element != 0) return false; + } + return true; } - private boolean containsLoop(Map> graph, int vertex, Set computed, Set visited) { - if (visited.contains(vertex)) return true; - if (computed.contains(vertex)) return false; - visited.add(vertex); - computed.add(vertex); - if (graph.containsKey(vertex)) { - List dependsOn = graph.get(vertex); - for (int dependency : dependsOn) { - if (containsLoop(graph, dependency, computed, visited)) { - return true; - } + private Queue queueWithInDegree0Vertices(int[] inDegrees) { + final Queue queue = new LinkedList<>(); + for (int i = 0; i < inDegrees.length; i++) { + if (inDegrees[i] == 0) { + queue.add(i); } } - visited.remove(vertex); - return false; + return queue; + } + + private static int[] getInDegreeValues(int[][] preRequisites, int numCourses) { + int[] result = new int[numCourses]; + for (int[] preRequisite: preRequisites) { + result[preRequisite[1]]++; + } + return result; } - private Map> getDependencyGraph(int[][] prerequisites) { + private static Map> getDependencyGraph(int[][] prerequisites) { final Map> dependencyGraph = new HashMap<>(); for (int[] prerequisite : prerequisites) { if (!dependencyGraph.containsKey(prerequisite[0])) { From 2d6c5dac3d92cf62523c38b5d4fc7a15001e4bb7 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 9 May 2022 18:25:24 +0200 Subject: [PATCH 553/947] solves network delay time in java --- README.md | 1 + src/NetworkDelayTime.java | 65 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 src/NetworkDelayTime.java diff --git a/README.md b/README.md index 939d0bf..97257b0 100644 --- a/README.md +++ b/README.md @@ -379,6 +379,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) | | +| 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) | | diff --git a/src/NetworkDelayTime.java b/src/NetworkDelayTime.java new file mode 100644 index 0000000..157ae1f --- /dev/null +++ b/src/NetworkDelayTime.java @@ -0,0 +1,65 @@ +// https://leetcode.com/problems/network-delay-time +// Single source shortest path algorithm (Dijkstra's Algorithm) +// T: O(E log(N) for dijkstra + N for searching max val) +// S: O(E + N) + +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 NetworkDelayTime { + private record Node(int value, long time) { } + + public int networkDelayTime(int[][] times, int n, int k) { + final Map> graph = createDirectedGraphFrom(times); + final long[] minTimeTaken = getMinTimeTakenArray(n, k); + final Queue queue = new PriorityQueue(Comparator.comparing(Node::time)); + queue.add(new Node(k, 0)); + + while (!queue.isEmpty()) { + Node node = queue.poll(); + if (!graph.containsKey(node.value)) continue; + Map vertexNode = graph.get(node.value); + for (int adjacent : vertexNode.keySet()) { + if (minTimeTaken[node.value - 1] + vertexNode.get(adjacent) < minTimeTaken[adjacent - 1]) { + minTimeTaken[adjacent - 1] = minTimeTaken[node.value - 1] + vertexNode.get(adjacent); + queue.add(new Node(adjacent, minTimeTaken[adjacent - 1])); + } + } + } + + return allAreReached(minTimeTaken) ? (int) Arrays.stream(minTimeTaken).max().getAsLong() : -1; + } + + private Map> createDirectedGraphFrom(int[][] times) { + final Map> graph = new HashMap<>(); + for (int[] time : times) { + int start = time[0]; + int destination = time[1]; + int delay = time[2]; + + graph.putIfAbsent(start, new HashMap<>()); + graph.get(start).put(destination, delay); + } + return graph; + } + + private long[] getMinTimeTakenArray(int length, int start) { + long[] array = new long[length]; + for (int i = 0 ; i < length ; i++) { + array[i] = Integer.MAX_VALUE; + } + array[start - 1] = 0; + return array; + } + + private boolean allAreReached(long[] array) { + for (long val : array) { + if (val == Integer.MAX_VALUE) return false; + } + return true; + } +} From cf12b63d163884fc0a073b280644930fc37aa3e5 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 9 May 2022 18:36:36 +0200 Subject: [PATCH 554/947] adds comments in min cost climbing stairs --- src/MinCostClimbingStairs.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/MinCostClimbingStairs.java b/src/MinCostClimbingStairs.java index c68c397..b1f6137 100644 --- a/src/MinCostClimbingStairs.java +++ b/src/MinCostClimbingStairs.java @@ -1,3 +1,7 @@ +// https://leetcode.com/problems/min-cost-climbing-stairs +// T: O(n) +// S: O(1) + public class MinCostClimbingStairs { public int minCostClimbingStairs(int[] cost) { int currentCost = cost[1], previousCost = cost[0], temp; From fc7f5c03c088493c4948125763b70263d265b7a1 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 9 May 2022 19:46:02 +0200 Subject: [PATCH 555/947] a --- src/KnightProbabilityInChessboard.java | 147 +++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 src/KnightProbabilityInChessboard.java diff --git a/src/KnightProbabilityInChessboard.java b/src/KnightProbabilityInChessboard.java new file mode 100644 index 0000000..7f6ce95 --- /dev/null +++ b/src/KnightProbabilityInChessboard.java @@ -0,0 +1,147 @@ +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class KnightProbabilityInChessboard { + static class Position { + private final int n; + private int row; + private int column; + + Position(int row, int column, int n) { + this.n = n; + this.row = row; + this.column = column; + + } + + private void normalize() { + row = normalize(row); + column = normalize(column); + if (row > column) { + int temp = row; + row = column; + column = temp; + } + } + + private int normalize(int index) { + if (index >= (n + 1) / 2) { + return n - index; + } + return index; + } + + private Position apply(Movement movement) { + return switch (movement) { + case TOP_LEFT -> new Position(row - 2, column - 1, n); + case TOP_RIGHT -> new Position(row - 2, column + 1, n); + case RIGHT_TOP -> new Position(row - 1, column + 2, n); + case RIGHT_BOTTOM -> new Position(row + 1, column + 2, n); + case BOTTOM_RIGHT -> new Position(row + 2, column + 1, n); + case BOTTOM_LEFT -> new Position(row + 2, column - 1, n); + case LEFT_BOTTOM -> new Position(row + 1, column - 2, n); + case LEFT_TOP -> new Position(row - 1, column - 2, n); + }; + } + + private boolean isValid() { + return row >= 0 + && row < n + && column >= 0 + && column < n; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + Position other = (Position) o; + if (row != other.row) return false; + return column == other.column; + } + + @Override + public int hashCode() { + return 31 * row + column; + } + } + + private record State(int n, int k, Position position) { } + + private enum Movement { + TOP_LEFT, + TOP_RIGHT, + RIGHT_TOP, + RIGHT_BOTTOM, + BOTTOM_RIGHT, + BOTTOM_LEFT, + LEFT_TOP, + LEFT_BOTTOM + } + + private final Map> allowedMovements = new HashMap<>(); + private final Map results = new HashMap<>(); + + public double knightProbability(int n, int k, int row, int column) { + computeValidMovements(n); + return getKnightProbability(n, k, new Position(row, column, n)); + } + + private double getKnightProbability(int n, int k, Position position) { + if (!position.isValid()) return 0; + if (k == 0) return 1; + + position.normalize(); + State state = new State(n, k, position); + if (results.containsKey(state)) return results.get(state); + + if (k == 1) { + double answer = ((double) validMoves(position)) / 8; + results.put(state, answer); + return answer; + } + + int sumOfProbabilities = 0; + for (Movement movement : allowedMovements.get(position)) { + Position newPosition = position.apply(movement); + sumOfProbabilities += getKnightProbability(n, k - 1, newPosition); + } + double answer = ((double) sumOfProbabilities) / 8; + results.put(state, answer); + return answer; + } + + private void computeValidMovements(int n) { + for (int row = 0 ; row < (n + 1) / 2 ; row++) { + for (int column = row ; column < (n + 1) / 2 ; column++) { + Position position = new Position(row, column, n); + allowedMovements.put(position, knightMovementsAt(position)); + } + } + } + + private List knightMovementsAt(Position position) { + final List movements = new ArrayList<>(); + if (isValidIndices(position.row - 2, position.column - 1, position.n)) movements.add(Movement.TOP_LEFT); + if (isValidIndices(position.row - 2, position.column + 1, position.n)) movements.add(Movement.TOP_RIGHT); + if (isValidIndices(position.row - 1, position.column + 2, position.n)) movements.add(Movement.RIGHT_TOP); + if (isValidIndices(position.row + 1, position.column + 2, position.n)) movements.add(Movement.RIGHT_BOTTOM); + if (isValidIndices(position.row + 2, position.column + 1, position.n)) movements.add(Movement.BOTTOM_RIGHT); + if (isValidIndices(position.row + 2, position.column - 1, position.n)) movements.add(Movement.BOTTOM_LEFT); + if (isValidIndices(position.row + 1, position.column - 2, position.n)) movements.add(Movement.LEFT_BOTTOM); + if (isValidIndices(position.row - 1, position.column - 2, position.n)) movements.add(Movement.LEFT_TOP); + return movements; + } + + private boolean isValidIndices(int row, int column, int n) { + return row >= 0 + && row < n + && column >= 0 + && column < n; + } + + private int validMoves(Position position) { + return allowedMovements.get(position).size(); + } +} From cb8276494354cdc06fe1a600c1a31283610fef3e Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 9 May 2022 19:49:43 +0200 Subject: [PATCH 556/947] a --- src/KnightProbabilityInChessboard.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/KnightProbabilityInChessboard.java b/src/KnightProbabilityInChessboard.java index 7f6ce95..2bccc29 100644 --- a/src/KnightProbabilityInChessboard.java +++ b/src/KnightProbabilityInChessboard.java @@ -65,6 +65,14 @@ public boolean equals(Object o) { public int hashCode() { return 31 * row + column; } + + @Override + public String toString() { + return "Position{" + + "row=" + row + + ", column=" + column + + '}'; + } } private record State(int n, int k, Position position) { } @@ -85,6 +93,7 @@ private enum Movement { public double knightProbability(int n, int k, int row, int column) { computeValidMovements(n); + System.out.println(allowedMovements); return getKnightProbability(n, k, new Position(row, column, n)); } From 8fea23e1cdc66408cb0ccb56b31985b54c17bdc7 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Tue, 10 May 2022 10:01:36 +0200 Subject: [PATCH 557/947] solves knight probability in java --- README.md | 1 + src/KnightProbabilityInChessboard.java | 58 +++++++++++++------------- 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 97257b0..cc8ae93 100644 --- a/README.md +++ b/README.md @@ -362,6 +362,7 @@ | 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) | | diff --git a/src/KnightProbabilityInChessboard.java b/src/KnightProbabilityInChessboard.java index 2bccc29..927fc8c 100644 --- a/src/KnightProbabilityInChessboard.java +++ b/src/KnightProbabilityInChessboard.java @@ -1,3 +1,7 @@ +// https://leetcode.com/problems/knight-probability-in-chessboard +// T: O(n^2 * k) +// S: O(n^2) + import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -13,7 +17,6 @@ static class Position { this.n = n; this.row = row; this.column = column; - } private void normalize() { @@ -28,7 +31,7 @@ private void normalize() { private int normalize(int index) { if (index >= (n + 1) / 2) { - return n - index; + return n - index - 1; } return index; } @@ -46,13 +49,6 @@ private Position apply(Movement movement) { }; } - private boolean isValid() { - return row >= 0 - && row < n - && column >= 0 - && column < n; - } - @Override public boolean equals(Object o) { if (this == o) return true; @@ -65,14 +61,6 @@ public boolean equals(Object o) { public int hashCode() { return 31 * row + column; } - - @Override - public String toString() { - return "Position{" + - "row=" + row + - ", column=" + column + - '}'; - } } private record State(int n, int k, Position position) { } @@ -88,17 +76,16 @@ private enum Movement { LEFT_BOTTOM } - private final Map> allowedMovements = new HashMap<>(); - private final Map results = new HashMap<>(); + private static final Map> allowedMovements = new HashMap<>(); + private static final Map results = new HashMap<>(); + private static int[][] validMoves; - public double knightProbability(int n, int k, int row, int column) { + public static double knightProbability(int n, int k, int row, int column) { computeValidMovements(n); - System.out.println(allowedMovements); return getKnightProbability(n, k, new Position(row, column, n)); } - private double getKnightProbability(int n, int k, Position position) { - if (!position.isValid()) return 0; + private static double getKnightProbability(int n, int k, Position position) { if (k == 0) return 1; position.normalize(); @@ -111,26 +98,37 @@ private double getKnightProbability(int n, int k, Position position) { return answer; } - int sumOfProbabilities = 0; + double sumOfProbabilities = 0; for (Movement movement : allowedMovements.get(position)) { Position newPosition = position.apply(movement); sumOfProbabilities += getKnightProbability(n, k - 1, newPosition); } - double answer = ((double) sumOfProbabilities) / 8; + double answer = sumOfProbabilities / 8; results.put(state, answer); return answer; } - private void computeValidMovements(int n) { + private static void computeValidMovements(int n) { for (int row = 0 ; row < (n + 1) / 2 ; row++) { for (int column = row ; column < (n + 1) / 2 ; column++) { Position position = new Position(row, column, n); allowedMovements.put(position, knightMovementsAt(position)); } } + fillValidMovesTable(n); + } + + private static void fillValidMovesTable(int n) { + final int length = (n + 1) / 2; + validMoves = new int[length][length]; + for (int row = 0 ; row < length ; row++) { + for (int column = row ; column < length ; column++) { + validMoves[row][column] = allowedMovements.get(new Position(row, column, n)).size(); + } + } } - private List knightMovementsAt(Position position) { + private static List knightMovementsAt(Position position) { final List movements = new ArrayList<>(); if (isValidIndices(position.row - 2, position.column - 1, position.n)) movements.add(Movement.TOP_LEFT); if (isValidIndices(position.row - 2, position.column + 1, position.n)) movements.add(Movement.TOP_RIGHT); @@ -143,14 +141,14 @@ private List knightMovementsAt(Position position) { return movements; } - private boolean isValidIndices(int row, int column, int n) { + private static boolean isValidIndices(int row, int column, int n) { return row >= 0 && row < n && column >= 0 && column < n; } - private int validMoves(Position position) { - return allowedMovements.get(position).size(); + private static int validMoves(Position position) { + return validMoves[position.row][position.column]; } } From aa6caf7cb5cdb15dcd00cfdf0628f1b9079280fe Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Tue, 10 May 2022 10:41:56 +0200 Subject: [PATCH 558/947] solves sudoku solver in java --- README.md | 1 + src/SudokuSolver.java | 140 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 141 insertions(+) create mode 100644 src/SudokuSolver.java diff --git a/README.md b/README.md index cc8ae93..dad7ed7 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ | 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) | | diff --git a/src/SudokuSolver.java b/src/SudokuSolver.java new file mode 100644 index 0000000..c8b48be --- /dev/null +++ b/src/SudokuSolver.java @@ -0,0 +1,140 @@ +// https://leetcode.com/problems/sudoku-solver +// T: O(n^2 * k) but n = 9 and k = 9 so just O(1) +// S: O(n^2) but n = 9 so just O(1) + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public class SudokuSolver { + private record Position(int row, int column) { + private static final Position start = new Position(0, 0); + + private boolean isValid() { + return row >= 0 + && row < 9 + && column >= 0 + && column < 9; + } + + private Position next() { + if (column == 8) return new Position(row + 1, 0); + return new Position(row, column + 1); + } + } + + private static final Map> rows = new HashMap<>(); + private static final Map> columns = new HashMap<>(); + private static final Map> subGrids = new HashMap<>(); + + public static void solveSudoku(char[][] board) { + computeDigitsInRows(board); + computeDigitsInColumns(board); + computeDigitsInSubGrids(board); + solveSudoku(board, Position.start); + } + + private static boolean solveSudoku(char[][] board, Position position) { + if (!position.isValid()) return true; + if (isAlreadyFilled(board, position)) return solveSudoku(board, position.next()); + + for (int i = 1 ; i <= 9 ; i++) { + if (isInRow(i, position) || isInColumn(i, position) || isInSubGrid(i, position)) continue; + insertInGrid(i, position, board); + boolean solved = solveSudoku(board, position.next()); + if (solved) return true; + removeFromGrid(i, position, board); + } + return false; + } + + private static boolean isAlreadyFilled(char[][] board, Position position) { + return board[position.row][position.column] != '.'; + } + + private static boolean isInRow(int digit, Position position) { + return rows.get(position.row).contains(digit); + } + + private static boolean isInColumn(int digit, Position position) { + return columns.get(position.column).contains(digit); + } + + private static boolean isInSubGrid(int digit, Position position) { + return subGrids.get(getSubGridId(position)).contains(digit); + } + + private static void insertInGrid(int digit, Position position, char[][] board) { + rows.get(position.row).add(digit); + columns.get(position.column).add(digit); + subGrids.get(getSubGridId(position)).add(digit); + board[position.row][position.column] = toChar(digit); + } + + private static void removeFromGrid(int digit, Position position, char[][] board) { + rows.get(position.row).remove(digit); + columns.get(position.column).remove(digit); + subGrids.get(getSubGridId(position)).remove(digit); + board[position.row][position.column] = '.'; + } + + private static void computeDigitsInRows(char[][] board) { + for (int row = 0 ; row < 9 ; row++) { + final Set digits = new HashSet<>(); + for (char element : board[row]) { + if (Character.isDigit(element)) { + digits.add(toInt(element)); + } + } + rows.put(row, digits); + } + } + + private static void computeDigitsInColumns(char[][] board) { + for (int column = 0 ; column < 9 ; column++) { + final Set digits = new HashSet<>(); + for (int row = 0 ; row < 9 ; row++) { + if (Character.isDigit(board[row][column])) { + digits.add(toInt(board[row][column])); + } + } + columns.put(column, digits); + } + } + + private static void computeDigitsInSubGrids(char[][] board) { + for (int i = 0 ; i < 3 ; i++) { + for (int j = 0 ; j < 3 ; j++) { + final int subGridId = getSubGridId(i, j); + final Set digits = new HashSet<>(); + for (int row = 3 * i ; row < 3 * i + 3 ; row++) { + for (int column = 3 * j ; column < 3 * j + 3 ; column++) { + if (Character.isDigit(board[row][column])) { + digits.add(toInt(board[row][column])); + } + } + } + subGrids.put(subGridId, digits); + } + } + } + + private static int toInt(char c) { + return c - '0'; + } + + private static char toChar(int digit) { + return (char) ('0' + digit); + } + + private static int getSubGridId(int i, int j) { + return 10 * i + j; + } + + private static int getSubGridId(Position position) { + int i = position.row / 3; + int j = position.column / 3; + return getSubGridId(i, j); + } +} From 2e8da12de0521a014d1673a0ec0671d58cfc5a90 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 10 May 2022 21:45:41 +0200 Subject: [PATCH 559/947] solves throne inheritance in java --- README.md | 1 + src/ThroneInheritance.java | 63 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 src/ThroneInheritance.java diff --git a/README.md b/README.md index dad7ed7..dd2244e 100644 --- a/README.md +++ b/README.md @@ -583,6 +583,7 @@ | 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) | | diff --git a/src/ThroneInheritance.java b/src/ThroneInheritance.java new file mode 100644 index 0000000..f8ab812 --- /dev/null +++ b/src/ThroneInheritance.java @@ -0,0 +1,63 @@ +// https://leetcode.com/problems/throne-inheritance +// N = people in royal family +// birth() T: O(1) +// death() T: O(1) +// getInheritanceOrder T: O(N) +// S: O(N) + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class ThroneInheritance { + private static final class Person { + private final String name; + private boolean isAlive = true; + private final List children = new ArrayList<>(); + + Person(String name) { + this.name = name; + } + + void markDead() { + this.isAlive = false; + } + + void addChild(Person child) { + this.children.add(child); + } + } + + private final Map royalFamily = new HashMap<>(); + private final Person king; + + public ThroneInheritance(String kingName) { + king = new Person(kingName); + royalFamily.put(kingName, king); + } + + public void birth(String parentName, String childName) { + Person child = new Person(childName); + royalFamily.put(childName, child); + royalFamily.get(parentName).addChild(child); + } + + public void death(String name) { + royalFamily.get(name).markDead(); + } + + public List getInheritanceOrder() { + final List names = new ArrayList<>(); + getInheritanceOrder(king, names); + return names; + } + + public void getInheritanceOrder(Person person, List names) { + if (person == null) return; + if (person.isAlive) names.add(person.name); + for (Person child : person.children) { + getInheritanceOrder(child, names); + } + } +} From d773f196889982405e50819d17dca7565ef0d0ca Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 12 May 2022 14:54:58 +0200 Subject: [PATCH 560/947] adds time/space data --- src/ContainsDuplicate.java | 4 ++++ src/TwoSum.java | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/ContainsDuplicate.java b/src/ContainsDuplicate.java index 9a1571e..fe925c7 100644 --- a/src/ContainsDuplicate.java +++ b/src/ContainsDuplicate.java @@ -1,3 +1,7 @@ +// https://leetcode.com/problems/contains-duplicate +// T: O(N) +// S: O(N) + import java.util.HashSet; import java.util.Set; diff --git a/src/TwoSum.java b/src/TwoSum.java index ef5470e..f072b69 100644 --- a/src/TwoSum.java +++ b/src/TwoSum.java @@ -1,4 +1,6 @@ // https://leetcode.com/problems/two-sum/ +// T: O(N) +// S: O(N) import java.util.Arrays; import java.util.HashMap; From 922de2a374903e59ab45e6ae6ee965cbccde9d1c Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 12 May 2022 16:42:59 +0200 Subject: [PATCH 561/947] adds time and space complexity for #121 --- src/BestTimeToBuyAndSellStock.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/BestTimeToBuyAndSellStock.java b/src/BestTimeToBuyAndSellStock.java index e25419b..1e84d42 100644 --- a/src/BestTimeToBuyAndSellStock.java +++ b/src/BestTimeToBuyAndSellStock.java @@ -1,3 +1,7 @@ +// https://leetcode.com/problems/best-time-to-buy-and-sell-stock +// T: O(n) +// S: O(1) + public class BestTimeToBuyAndSellStock { public int maxProfit(int[] prices) { if (prices.length == 0) { From ec89a8a9b6da0a62709780b9bff1be8d24ed2eff Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 12 May 2022 16:51:04 +0200 Subject: [PATCH 562/947] adds time and space complexity for #242 --- src/ValidAnagram.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/ValidAnagram.java b/src/ValidAnagram.java index a2c93ad..cf4aab5 100644 --- a/src/ValidAnagram.java +++ b/src/ValidAnagram.java @@ -1,3 +1,8 @@ +// https://leetcode.com/problems/valid-anagram +// T: O(|s| + |t|) +// S: O(1) + + import java.util.HashMap; import java.util.Map; From bf241b0b6b793b7839c2537486a9b224e0a7d527 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 19 May 2022 14:36:49 +0200 Subject: [PATCH 563/947] adds details in leetcode#204 --- src/CountPrimes.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/CountPrimes.java b/src/CountPrimes.java index 90fbbbf..f9cbbf0 100644 --- a/src/CountPrimes.java +++ b/src/CountPrimes.java @@ -1,3 +1,7 @@ +// https://leetcode.com/problems/count-primes +// T: O(n log(log(n))) +// S: O(n) + public class CountPrimes { public static int countPrimes(int number) { From b1246c4725080acb7e65549fab5da9e1dd526df0 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 23 May 2022 19:56:29 +0200 Subject: [PATCH 564/947] solves interleaving strings in java --- README.md | 4 +++- src/InterleavingString.java | 39 +++++++++++++++++++++++++++---------- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index dd2244e..c56676a 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,7 @@ | 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) | | | +| 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) | | | | 100 | [Same Tree](https://leetcode.com/problems/same-tree) | [![Java](assets/java.png)](src/SameTree.java) [![Python](assets/python.png)](python/same_tree.py) | | @@ -281,6 +281,8 @@ | 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) | | diff --git a/src/InterleavingString.java b/src/InterleavingString.java index a7efd81..4955ba7 100644 --- a/src/InterleavingString.java +++ b/src/InterleavingString.java @@ -1,15 +1,34 @@ -public class InterleavingString { - public static void main(String[] args) { - System.out.println(isInterleave("aabcc", "dbbca", "aadbbcbcac")); - } +// https://leetcode.com/problems/interleaving-string +// T: O(n * m) +// S: O(min(m, n)) - public static boolean isInterleave(String s1, String s2, String s3) { +public class InterleavingString { + public boolean isInterleave(String s1, String s2, String s3) { if (s1.length() + s2.length() != s3.length()) return false; - for (int i = 0, j = 0, t = 0 ; i <= s1.length() && j <= s2.length() && t < s3.length() ; t++) { - if (i < s1.length() && s3.charAt(t) == s1.charAt(i)) i++; - else if (j < s2.length() && s3.charAt(t) == s2.charAt(j)) j++; - else return false; + if (s1.length() < s2.length()) { + String temp = s1; + s1 = s2; + s2 = temp; } - return true; + + final int rows = s1.length() + 1, columns = s2.length() + 1; + final boolean[] dp = new boolean[columns]; + + for (int row = 0 ; row < rows ; row++) { + for (int column = 0 ; column < columns ; column++) { + if (row == 0 && column == 0) { + dp[column] = true; + } else if (row == 0) { + dp[column] = dp[column - 1] && s2.charAt(column - 1) == s3.charAt(row + column - 1); + } else if (column == 0) { + dp[column] = dp[column] && s1.charAt(row - 1) == s3.charAt(row + column - 1); + } else { + dp[column] = (s1.charAt(row - 1) == s3.charAt(row + column - 1) && dp[column]) + || (s2.charAt(column - 1) == s3.charAt(row + column - 1) && dp[column - 1]); + } + } + } + + return dp[columns - 1]; } } From 6e514503095ade9c026f9dfdbbe64eba8f790a07 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 23 May 2022 20:09:44 +0200 Subject: [PATCH 565/947] removes TreeNode dependency --- src/BalancedBinaryTree.java | 5 --- src/BinaryTreeLevelOrderTraversalII.java | 5 --- src/BinaryTreePaths.java | 16 +-------- src/ConvertSortedArrayToBinarySearchTree.java | 15 -------- src/FindModeInBinarySearchTree.java | 13 ------- src/InvertBinaryTree.java | 5 --- ...owestCommonAncestorOfBinarySearchTree.java | 5 --- src/MaximumDepthOfBinaryTree.java | 6 ---- src/MinimumDepthOfBinaryTree.java | 5 --- src/PathSum.java | 5 --- src/SameTree.java | 5 --- src/SymmetricTree.java | 5 --- src/UniqueBinarySearchTreesII.java | 35 ++----------------- 13 files changed, 3 insertions(+), 122 deletions(-) diff --git a/src/BalancedBinaryTree.java b/src/BalancedBinaryTree.java index 6497146..3d1929f 100644 --- a/src/BalancedBinaryTree.java +++ b/src/BalancedBinaryTree.java @@ -1,9 +1,4 @@ public class BalancedBinaryTree { - private static class TreeNode { - int val; - TreeNode left; - TreeNode right; - } public static boolean isBalanced(TreeNode root) { return height(root) != -1; diff --git a/src/BinaryTreeLevelOrderTraversalII.java b/src/BinaryTreeLevelOrderTraversalII.java index 3ba166b..e87a467 100644 --- a/src/BinaryTreeLevelOrderTraversalII.java +++ b/src/BinaryTreeLevelOrderTraversalII.java @@ -5,11 +5,6 @@ import java.util.Queue; public class BinaryTreeLevelOrderTraversalII { - private static class TreeNode { - int val; - TreeNode left; - TreeNode right; - } private static class Pair { TreeNode tree; diff --git a/src/BinaryTreePaths.java b/src/BinaryTreePaths.java index 72cc649..3a9225f 100644 --- a/src/BinaryTreePaths.java +++ b/src/BinaryTreePaths.java @@ -2,24 +2,10 @@ import java.util.List; public class BinaryTreePaths { - public static void main(String[] args) { - String[] array = {"hello", "1", "2"}; - List list = new ArrayList<>(); - list.add("1"); - list.add("2"); - list.add("3"); - System.out.println(String.join("->", list)); - } - - private static class TreeNode { - int val; - TreeNode left; - TreeNode right; - } public static List binaryTreePaths(TreeNode root) { List result = new ArrayList<>(); - binaryTreePaths(root, new ArrayList(), result); + binaryTreePaths(root, new ArrayList<>(), result); return result; } diff --git a/src/ConvertSortedArrayToBinarySearchTree.java b/src/ConvertSortedArrayToBinarySearchTree.java index db17b39..2d1aa2d 100644 --- a/src/ConvertSortedArrayToBinarySearchTree.java +++ b/src/ConvertSortedArrayToBinarySearchTree.java @@ -1,19 +1,4 @@ public class ConvertSortedArrayToBinarySearchTree { - private static class TreeNode { - int val; - TreeNode left; - TreeNode right; - - TreeNode(int val) { - this.val = val; - } - - TreeNode(int val, TreeNode left, TreeNode right) { - this.val = val; - this.left = left; - this.right = right; - } - } public static TreeNode sortedArrayToBST(int[] array) { return sortedArrayToBST(array, 0, array.length); diff --git a/src/FindModeInBinarySearchTree.java b/src/FindModeInBinarySearchTree.java index 8e91197..7982ef2 100644 --- a/src/FindModeInBinarySearchTree.java +++ b/src/FindModeInBinarySearchTree.java @@ -3,19 +3,6 @@ import java.util.List; public class FindModeInBinarySearchTree { - static class TreeNode { - int val; - TreeNode left; - TreeNode right; - TreeNode() {} - TreeNode(int val) { this.val = val; } - TreeNode(int val, TreeNode left, TreeNode right) { - this.val = val; - this.left = left; - this.right = right; - } - } - private static TreeNode previous; private static int count = 1; private static int mode = 0; diff --git a/src/InvertBinaryTree.java b/src/InvertBinaryTree.java index 5fb9e80..667c246 100644 --- a/src/InvertBinaryTree.java +++ b/src/InvertBinaryTree.java @@ -1,9 +1,4 @@ public class InvertBinaryTree { - private static class TreeNode { - int val; - TreeNode left; - TreeNode right; - } public static TreeNode invertTree(TreeNode root) { if (root == null) { diff --git a/src/LowestCommonAncestorOfBinarySearchTree.java b/src/LowestCommonAncestorOfBinarySearchTree.java index 9b54a35..4b488d6 100644 --- a/src/LowestCommonAncestorOfBinarySearchTree.java +++ b/src/LowestCommonAncestorOfBinarySearchTree.java @@ -2,11 +2,6 @@ import java.util.List; public class LowestCommonAncestorOfBinarySearchTree { - private static class TreeNode { - int val; - TreeNode left; - TreeNode right; - } public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { List pathToP = pathTo(root, p); diff --git a/src/MaximumDepthOfBinaryTree.java b/src/MaximumDepthOfBinaryTree.java index 4a716f8..050eb47 100644 --- a/src/MaximumDepthOfBinaryTree.java +++ b/src/MaximumDepthOfBinaryTree.java @@ -1,10 +1,4 @@ public class MaximumDepthOfBinaryTree { - private static class TreeNode { - int val; - TreeNode left; - TreeNode right; - } - public int maxDepth(TreeNode root) { if (root == null) { return 0; diff --git a/src/MinimumDepthOfBinaryTree.java b/src/MinimumDepthOfBinaryTree.java index fc2b722..5f83724 100644 --- a/src/MinimumDepthOfBinaryTree.java +++ b/src/MinimumDepthOfBinaryTree.java @@ -1,9 +1,4 @@ public class MinimumDepthOfBinaryTree { - private static class TreeNode { - int val; - TreeNode left; - TreeNode right; - } public static int minDepth(TreeNode root) { if (root == null) { diff --git a/src/PathSum.java b/src/PathSum.java index 8bf006a..94e9ed4 100644 --- a/src/PathSum.java +++ b/src/PathSum.java @@ -1,9 +1,4 @@ public class PathSum { - private static class TreeNode { - int val; - TreeNode left; - TreeNode right; - } public static boolean hasPathSum(TreeNode root, int sum) { return root != null && hasPathSum(root, sum, root.val); diff --git a/src/SameTree.java b/src/SameTree.java index 9dc840f..4f8fda6 100644 --- a/src/SameTree.java +++ b/src/SameTree.java @@ -1,9 +1,4 @@ public class SameTree { - private static class TreeNode { - int val; - TreeNode left; - TreeNode right; - } public boolean isSameTree(TreeNode p, TreeNode q) { if (p == null && q == null) { diff --git a/src/SymmetricTree.java b/src/SymmetricTree.java index 16940ab..cf6a86c 100644 --- a/src/SymmetricTree.java +++ b/src/SymmetricTree.java @@ -1,9 +1,4 @@ public class SymmetricTree { - private static class TreeNode { - int val; - TreeNode left; - TreeNode right; - } public boolean isSymmetric(TreeNode root) { return root == null || isSymmetric(root.left, root.right); diff --git a/src/UniqueBinarySearchTreesII.java b/src/UniqueBinarySearchTreesII.java index cb93978..9958e8d 100644 --- a/src/UniqueBinarySearchTreesII.java +++ b/src/UniqueBinarySearchTreesII.java @@ -2,47 +2,16 @@ import java.util.List; public class UniqueBinarySearchTreesII { - private static class TreeNode implements TreePrinter.PrintableNode { - int val; - TreeNode left; - TreeNode right; - - TreeNode(int val) { - this.val = val; - } - - TreeNode(int val, TreeNode left, TreeNode right) { - this.val = val; - this.left = left; - this.right = right; - } - - @Override - public TreePrinter.PrintableNode getLeft() { - return left; - } - - @Override - public TreePrinter.PrintableNode getRight() { - return right; - } - - @Override - public String getText() { - return val + ""; - } - } - public static List generateTrees(int n) { List[] result = new List[n + 1]; - result[0] = new ArrayList(); + result[0] = new ArrayList<>(); if (n == 0) { return result[0]; } result[0].add(null); for (int len = 1; len <= n; len++) { - result[len] = new ArrayList(); + result[len] = new ArrayList<>(); for (int j = 0; j < len; j++) { for (TreeNode nodeL : result[j]) { for (TreeNode nodeR : result[len - j - 1]) { From 3d90a93a292db8b8f9b90b3576b238a5682c1000 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Wed, 25 May 2022 17:56:35 +0200 Subject: [PATCH 566/947] solves trie #208 in java --- README.md | 2 +- src/HelloWorld.java | 8 +++++- src/Trie.java | 59 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 src/Trie.java diff --git a/README.md b/README.md index c56676a..b16dc76 100644 --- a/README.md +++ b/README.md @@ -168,7 +168,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) | | | +| 208 | [Implement Trie (Prefix Tree)](https://leetcode.com/problems/implement-trie-prefix-tree) | [![Java](assets/java.png)](src/Trie.java) | | | 209 | [Minimum Size Subarray Sum](https://leetcode.com/problems/minimum-size-subarray-sum) | | | | 210 | [Course Schedule II](https://leetcode.com/problems/course-schedule-ii) | | | | 211 | [Design Add and Search Words Data Structure](https://leetcode.com/problems/design-add-and-search-words-data-structure) | | | diff --git a/src/HelloWorld.java b/src/HelloWorld.java index 74f62ba..c1ee344 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -1,5 +1,11 @@ public class HelloWorld { public static void main(String[] args) { - System.out.println("Hello world"); + Trie trie = new Trie(); + trie.insert("apple"); +// System.out.println(trie.search("apple")); +// System.out.println(trie.search("app")); + System.out.println(trie.startsWith("app")); // true + trie.insert("app"); +// System.out.println(trie.search("app")); } } diff --git a/src/Trie.java b/src/Trie.java new file mode 100644 index 0000000..7e847eb --- /dev/null +++ b/src/Trie.java @@ -0,0 +1,59 @@ +// https://leetcode.com/problems/implement-trie-prefix-tree +// insertion +// T: O(n) +// S: O(n) +// search +// T: O(n) +// S: O(n) +// starts with +// T: O(n) +// S: O(n) + +public class Trie { + private final Trie[] alphabet = new Trie[26]; + private boolean isWordEnd = false; + + public Trie() { } + + public void insert(String word) { + insert(word, 0); + } + + private void insert(String word, int index) { + if (index == word.length()) { + this.isWordEnd = true; + return; + } + int charIndex = toIndex(word.charAt(index)); + if (alphabet[charIndex] == null) { + alphabet[charIndex] = new Trie(); + } + alphabet[charIndex].insert(word, index + 1); + } + + public boolean search(String word) { + return search(word, 0); + } + + public boolean search(String word, int index) { + if (index == word.length()) return isWordEnd; + int charIndex = toIndex(word.charAt(index)); + if (alphabet[charIndex] == null) return false; + return alphabet[charIndex].search(word, index + 1); + } + + public boolean startsWith(String prefix) { + return startsWith(prefix, 0); + } + + public boolean startsWith(String prefix, int index) { + if (index == prefix.length()) return true; + int charIndex = toIndex(prefix.charAt(index)); + if (alphabet[charIndex] == null) return false; + return alphabet[charIndex].startsWith(prefix, index + 1); + } + + private int toIndex(char c) { + return c - 'a'; + } +} From 1b2d6499dd19458029e3aaba48cbfb22aa671ffc Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sun, 29 May 2022 15:38:50 +0200 Subject: [PATCH 567/947] solves leetcode #99 recover bst in java --- README.md | 2 +- src/RecoverBinarySearchTree.java | 33 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/RecoverBinarySearchTree.java diff --git a/README.md b/README.md index b16dc76..d3187c1 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ | 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) | | | +| 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) | | diff --git a/src/RecoverBinarySearchTree.java b/src/RecoverBinarySearchTree.java new file mode 100644 index 0000000..922858d --- /dev/null +++ b/src/RecoverBinarySearchTree.java @@ -0,0 +1,33 @@ +// https://leetcode.com/problems/recover-binary-search-tree +// T: O(n) +// S: O(log(n)) + +public class RecoverBinarySearchTree { + TreeNode first, second, previous = new TreeNode(Integer.MIN_VALUE); + + public void recoverTree(TreeNode root) { + inorder(root); + swapValues(first, second); + } + + private void inorder(TreeNode root) { + if (root == null) return; + inorder(root.left); + + if (first == null && root.val < previous.val) { + first = previous; + } + if (first != null && root.val < previous.val) { + second = root; + } + previous = root; + + inorder(root.right); + } + + private void swapValues(TreeNode a, TreeNode b) { + int temp = a.val; + a.val = b.val; + b.val = temp; + } +} From b1863cf872409dae1664ebf733966095a2096346 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sun, 29 May 2022 15:53:07 +0200 Subject: [PATCH 568/947] solves #103 in java --- README.md | 2 +- src/BinaryTreeZigzagLevelOrderTraversal.java | 50 ++++++++++++++++++++ src/HelloWorld.java | 13 +++-- 3 files changed, 57 insertions(+), 8 deletions(-) create mode 100644 src/BinaryTreeZigzagLevelOrderTraversal.java diff --git a/README.md b/README.md index d3187c1..2f52823 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ | 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) | | | +| 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) | | | | 106 | [Construct Binary Tree from Inorder and Postorder Traversal](https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal) | | | diff --git a/src/BinaryTreeZigzagLevelOrderTraversal.java b/src/BinaryTreeZigzagLevelOrderTraversal.java new file mode 100644 index 0000000..6e919ee --- /dev/null +++ b/src/BinaryTreeZigzagLevelOrderTraversal.java @@ -0,0 +1,50 @@ +// https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal +// T: O(n) +// S: O(n) + +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; + +public class BinaryTreeZigzagLevelOrderTraversal { + public List> zigzagLevelOrder(TreeNode root) { + if (root == null) return Collections.EMPTY_LIST; + + final List> result = new ArrayList<>(); + final Queue queue = new LinkedList<>(); + queue.add(root); + queue.add(null); + + List level = new ArrayList<>(); + + while (!queue.isEmpty()) { + final TreeNode current = queue.poll(); + if (current == null) { + result.add(level); + level = new LinkedList<>(); + if (!queue.isEmpty()) { + queue.add(null); + } + continue; + } + level.add(current.val); + addChildrenInQueue(queue, current); + } + + zigZagOrder(result); + return result; + } + + private void zigZagOrder(List> levels) { + for (int i = 1 ; i < levels.size() ; i += 2) { + Collections.reverse(levels.get(i)); + } + } + + private void addChildrenInQueue(Queue queue, TreeNode root) { + if (root.left != null) queue.add(root.left); + if (root.right != null) queue.add(root.right); + } +} diff --git a/src/HelloWorld.java b/src/HelloWorld.java index c1ee344..ba8fab9 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -1,11 +1,10 @@ +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + public class HelloWorld { public static void main(String[] args) { - Trie trie = new Trie(); - trie.insert("apple"); -// System.out.println(trie.search("apple")); -// System.out.println(trie.search("app")); - System.out.println(trie.startsWith("app")); // true - trie.insert("app"); -// System.out.println(trie.search("app")); + List list = new ArrayList<>(); + Collections.reverse(list); } } From fb1370262de7c8b58a19f16ae369f60f1e3b7acb Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sun, 29 May 2022 16:23:28 +0200 Subject: [PATCH 569/947] solves #105 in java --- README.md | 2 +- ...ryTreeFromPreorderAndInorderTraversal.java | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/ConstructBinaryTreeFromPreorderAndInorderTraversal.java diff --git a/README.md b/README.md index 2f52823..d540e10 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ | 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) | | | +| 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) | | | | 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) | | diff --git a/src/ConstructBinaryTreeFromPreorderAndInorderTraversal.java b/src/ConstructBinaryTreeFromPreorderAndInorderTraversal.java new file mode 100644 index 0000000..d99f6be --- /dev/null +++ b/src/ConstructBinaryTreeFromPreorderAndInorderTraversal.java @@ -0,0 +1,34 @@ +// https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal +// T: O(n) +// S: O(n) + +import java.util.HashMap; +import java.util.Map; + +public class ConstructBinaryTreeFromPreorderAndInorderTraversal { + int preOrderIndex = 0; + Map inOrderIndices; + + public TreeNode buildTree(int[] preorder, int[] inorder) { + inOrderIndices = buildValueToIndexMap(inorder); + return buildTree(preorder, inorder, 0, preorder.length); + } + + private TreeNode buildTree(int[] preOrder, int[] inOrder, int start, int end) { + if (start >= end) return null; + + int inOrderIndex = inOrderIndices.get(preOrder[preOrderIndex]); + final TreeNode root = new TreeNode(preOrder[preOrderIndex++]); + root.left = buildTree(preOrder, inOrder, start, inOrderIndex); + root.right = buildTree(preOrder, inOrder, inOrderIndex + 1, end); + return root; + } + + private Map buildValueToIndexMap(int[] array) { + final Map result = new HashMap<>(); + for (int index = 0 ; index < array.length ; index++) { + result.put(array[index], index); + } + return result; + } +} From 252c2963d4ccc6fdd9e78e1372a14cffeaca3c33 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sun, 29 May 2022 17:51:02 +0200 Subject: [PATCH 570/947] solves #106 in java --- README.md | 2 +- ...yTreeFromInorderAndPostorderTraversal.java | 34 +++++++++++++++++++ ...ryTreeFromPreorderAndInorderTraversal.java | 2 +- src/HelloWorld.java | 17 ++++++++-- 4 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 src/ConstructBinaryTreeFromInorderAndPostorderTraversal.java diff --git a/README.md b/README.md index d540e10..3e048ea 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,7 @@ | 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) | | | +| 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) | | | diff --git a/src/ConstructBinaryTreeFromInorderAndPostorderTraversal.java b/src/ConstructBinaryTreeFromInorderAndPostorderTraversal.java new file mode 100644 index 0000000..7ccaa9f --- /dev/null +++ b/src/ConstructBinaryTreeFromInorderAndPostorderTraversal.java @@ -0,0 +1,34 @@ +// https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal +// T: O(n) +// S: O(n) + +import java.util.HashMap; +import java.util.Map; + +public class ConstructBinaryTreeFromInorderAndPostorderTraversal { + Map inOrderIndices; + int[] postOrder; + + public TreeNode buildTree(int[] inorder, int[] postorder) { + inOrderIndices = getIndicesMap(inorder); + this.postOrder = postorder; + return buildTreePostIn(0, inorder.length - 1, 0, postorder.length - 1); + } + + private TreeNode buildTreePostIn(int is, int ie, int ps, int pe){ + if (ps > pe || is > ie) return null; + final TreeNode root = new TreeNode(postOrder[pe]); + int ri = inOrderIndices.get(postOrder[pe]); + root.left = buildTreePostIn(is, ri-1, ps, ps+ri-is-1); + root.right = buildTreePostIn(ri+1, ie, ps+ri-is, pe-1); + return root; + } + + private Map getIndicesMap(int[] array) { + final Map result = new HashMap<>(array.length); + for (int index = 0 ; index < array.length ; index++) { + result.put(array[index], index); + } + return result; + } +} diff --git a/src/ConstructBinaryTreeFromPreorderAndInorderTraversal.java b/src/ConstructBinaryTreeFromPreorderAndInorderTraversal.java index d99f6be..739cd2a 100644 --- a/src/ConstructBinaryTreeFromPreorderAndInorderTraversal.java +++ b/src/ConstructBinaryTreeFromPreorderAndInorderTraversal.java @@ -15,7 +15,7 @@ public TreeNode buildTree(int[] preorder, int[] inorder) { } private TreeNode buildTree(int[] preOrder, int[] inOrder, int start, int end) { - if (start >= end) return null; + if (start == end) return null; int inOrderIndex = inOrderIndices.get(preOrder[preOrderIndex]); final TreeNode root = new TreeNode(preOrder[preOrderIndex++]); diff --git a/src/HelloWorld.java b/src/HelloWorld.java index ba8fab9..7d4225b 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -4,7 +4,20 @@ public class HelloWorld { public static void main(String[] args) { - List list = new ArrayList<>(); - Collections.reverse(list); +// ConstructBinaryTreeFromInorderAndPostorderTraversal c = new ConstructBinaryTreeFromInorderAndPostorderTraversal(); +// TreeNode treeNode = c.buildTree(new int[] {9, 3, 15, 20, 7}, new int[] {9, 15, 7, 20, 3}); +// TreePrinter.print(treeNode); +// +// c = new ConstructBinaryTreeFromInorderAndPostorderTraversal(); +// treeNode = c.buildTree(new int[] {2, 1}, new int[] {2, 1}); +// TreePrinter.print(treeNode); +// +// c = new ConstructBinaryTreeFromInorderAndPostorderTraversal(); +// treeNode = c.buildTree(new int[] {-1}, new int[] {-1}); +// TreePrinter.print(treeNode); + + ConstructBinaryTreeFromInorderAndPostorderTraversal c = new ConstructBinaryTreeFromInorderAndPostorderTraversal(); + TreeNode treeNode = c.buildTree(new int[] {1, 2, 3, 4}, new int[] {2, 1, 3, 4}); + TreePrinter.print(treeNode); } } From a2ddf9e1b52aedaad57648a23840e96df23c7d2c Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 30 May 2022 15:43:12 +0200 Subject: [PATCH 571/947] solves #106 in java --- ...BinaryTreeFromInorderAndPostorderTraversal.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/ConstructBinaryTreeFromInorderAndPostorderTraversal.java b/src/ConstructBinaryTreeFromInorderAndPostorderTraversal.java index 7ccaa9f..e43d546 100644 --- a/src/ConstructBinaryTreeFromInorderAndPostorderTraversal.java +++ b/src/ConstructBinaryTreeFromInorderAndPostorderTraversal.java @@ -10,17 +10,17 @@ public class ConstructBinaryTreeFromInorderAndPostorderTraversal { int[] postOrder; public TreeNode buildTree(int[] inorder, int[] postorder) { - inOrderIndices = getIndicesMap(inorder); + this.inOrderIndices = getIndicesMap(inorder); this.postOrder = postorder; return buildTreePostIn(0, inorder.length - 1, 0, postorder.length - 1); } - private TreeNode buildTreePostIn(int is, int ie, int ps, int pe){ - if (ps > pe || is > ie) return null; - final TreeNode root = new TreeNode(postOrder[pe]); - int ri = inOrderIndices.get(postOrder[pe]); - root.left = buildTreePostIn(is, ri-1, ps, ps+ri-is-1); - root.right = buildTreePostIn(ri+1, ie, ps+ri-is, pe-1); + private TreeNode buildTreePostIn(int inOrderStart, int inOrderEnd, int postOrderStart, int postOrderEnd) { + if (postOrderStart > postOrderEnd || inOrderStart > inOrderEnd) return null; + final TreeNode root = new TreeNode(postOrder[postOrderEnd]); + int ri = inOrderIndices.get(postOrder[postOrderEnd]); + root.left = buildTreePostIn(inOrderStart, ri - 1, postOrderStart, postOrderStart + ri - inOrderStart - 1); + root.right = buildTreePostIn(ri + 1, inOrderEnd, postOrderStart + ri - inOrderStart, postOrderEnd - 1); return root; } From 20382be7c95e771cbf3cb46dfd01bcaad8371894 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 30 May 2022 16:03:38 +0200 Subject: [PATCH 572/947] solves #109 in java --- README.md | 2 +- src/AddTwoNumbers.java | 8 ----- ...vertBinaryNumberInLinkedListToInteger.java | 9 ----- src/ConvertSortedListToBinarySearchTree.java | 36 +++++++++++++++++++ src/DeleteANodeInLinkedList.java | 4 --- src/IntersectionOf2LinkedLists.java | 8 ----- src/LinkedListCycle.java | 9 ----- src/ListNode.java | 15 ++++++++ src/Merge2SortedLists.java | 10 +----- src/MiddleOfTheLinkedList.java | 8 ----- src/PalindromeLinkedList.java | 4 --- src/PartitionList.java | 5 --- src/RemoveDuplicatesFromSortedList.java | 16 --------- src/RemoveDuplicatesFromSortedListII.java | 4 --- src/RemoveLinkedListElements.java | 9 ----- src/RemoveNthNodeFromEndOfList.java | 8 ----- src/ReverseLinkedList.java | 7 ++-- src/ReverseLinkedListII.java | 7 ---- src/RotateList.java | 7 ---- src/SwapNodesInPairs.java | 9 ----- 20 files changed, 56 insertions(+), 129 deletions(-) create mode 100644 src/ConvertSortedListToBinarySearchTree.java create mode 100644 src/ListNode.java diff --git a/README.md b/README.md index 3e048ea..e586c70 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ | 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) | | | +| 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) | | diff --git a/src/AddTwoNumbers.java b/src/AddTwoNumbers.java index 0e44c1b..d2d7661 100644 --- a/src/AddTwoNumbers.java +++ b/src/AddTwoNumbers.java @@ -33,12 +33,4 @@ private int get(ListNode node) { if (node == null) return 0; return node.val; } - - public static class ListNode { - int val; - ListNode next; - ListNode() {} - ListNode(int val) { this.val = val; } - ListNode(int val, ListNode next) { this.val = val; this.next = next; } - } } diff --git a/src/ConvertBinaryNumberInLinkedListToInteger.java b/src/ConvertBinaryNumberInLinkedListToInteger.java index 17a6f31..d3cc201 100644 --- a/src/ConvertBinaryNumberInLinkedListToInteger.java +++ b/src/ConvertBinaryNumberInLinkedListToInteger.java @@ -8,13 +8,4 @@ public int getDecimalValue(ListNode head) { } return value; } - - - private static class ListNode { - int val; - ListNode next; - ListNode() {}; - ListNode(int val) { this.val = val; } - ListNode(int val, ListNode next) { this.val = val; this.next = next; } - } } diff --git a/src/ConvertSortedListToBinarySearchTree.java b/src/ConvertSortedListToBinarySearchTree.java new file mode 100644 index 0000000..d485735 --- /dev/null +++ b/src/ConvertSortedListToBinarySearchTree.java @@ -0,0 +1,36 @@ +// https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree +// T: O(n) +// S: O(n) + +import java.util.ArrayList; +import java.util.List; + +public class ConvertSortedListToBinarySearchTree { + public TreeNode sortedListToBST(ListNode head) { + final List list = toList(head); + return listToBST(list); + } + + private TreeNode listToBST(List list) { + return listToBST(list, 0, list.size()); + } + + private TreeNode listToBST(List list, int start, int end) { + if (start == end) return null; + + final int middle = start + (end - start) / 2; + final TreeNode root = new TreeNode(list.get(middle)); + root.left = listToBST(list, start, middle); + root.right = listToBST(list, middle + 1, end); + return root; + } + + private List toList(ListNode head) { + final List result = new ArrayList<>(); + while (head != null) { + result.add(head.val); + head = head.next; + } + return result; + } +} diff --git a/src/DeleteANodeInLinkedList.java b/src/DeleteANodeInLinkedList.java index 349aa89..24a02ec 100644 --- a/src/DeleteANodeInLinkedList.java +++ b/src/DeleteANodeInLinkedList.java @@ -1,8 +1,4 @@ public class DeleteANodeInLinkedList { - private static class ListNode { - int val; - ListNode next; - } public static void deleteNode(ListNode node) { ListNode current = node; diff --git a/src/IntersectionOf2LinkedLists.java b/src/IntersectionOf2LinkedLists.java index 27b6759..6fcf322 100644 --- a/src/IntersectionOf2LinkedLists.java +++ b/src/IntersectionOf2LinkedLists.java @@ -2,14 +2,6 @@ import java.util.Set; public class IntersectionOf2LinkedLists { - public static class ListNode { - int val; - ListNode next; - ListNode(int x) { - val = x; - next = null; - } - } public ListNode getIntersectionNode(ListNode headA, ListNode headB) { Set aNodes = new HashSet<>(); diff --git a/src/LinkedListCycle.java b/src/LinkedListCycle.java index 1b61206..3c2adae 100644 --- a/src/LinkedListCycle.java +++ b/src/LinkedListCycle.java @@ -2,15 +2,6 @@ // S: O(1) public class LinkedListCycle { - private static class ListNode { - int val; - ListNode next; - ListNode(int x) { - val = x; - next = null; - } - } - public boolean hasCycle(ListNode head) { if (head == null) return false; diff --git a/src/ListNode.java b/src/ListNode.java new file mode 100644 index 0000000..df94d59 --- /dev/null +++ b/src/ListNode.java @@ -0,0 +1,15 @@ +public class ListNode { + int val; + ListNode next; + + ListNode() { } + + ListNode(int val) { + this.val = val; + } + + ListNode(int val, ListNode next) { + this.val = val; + this.next = next; + } +} diff --git a/src/Merge2SortedLists.java b/src/Merge2SortedLists.java index 2c47ced..577a5ac 100644 --- a/src/Merge2SortedLists.java +++ b/src/Merge2SortedLists.java @@ -1,4 +1,4 @@ -// https://leetcode.com/problems/merge-two-sorted-lists/ +// https://leetcode.com/problems/merge-two-sorted-lists public class Merge2SortedLists { public ListNode mergeTwoLists(ListNode l1, ListNode l2) { @@ -19,12 +19,4 @@ public ListNode mergeTwoLists(ListNode l1, ListNode l2) { previous.next = l1 == null ? l2 : l1; return result.next; } - - public static class ListNode { - int val; - ListNode next; - ListNode() {} - ListNode(int val) { this.val = val; } - ListNode(int val, ListNode next) { this.val = val; this.next = next; } - } } diff --git a/src/MiddleOfTheLinkedList.java b/src/MiddleOfTheLinkedList.java index 888368c..afc6b30 100644 --- a/src/MiddleOfTheLinkedList.java +++ b/src/MiddleOfTheLinkedList.java @@ -1,12 +1,4 @@ public class MiddleOfTheLinkedList { - public static class ListNode { - int val; - ListNode next; - ListNode() {} - ListNode(int val) { this.val = val; } - ListNode(int val, ListNode next) { this.val = val; this.next = next; } - } - public ListNode middleNode(ListNode head) { ListNode slow = head, fast = head; while (fast != null && fast.next != null) { diff --git a/src/PalindromeLinkedList.java b/src/PalindromeLinkedList.java index 9fd1978..3abba8b 100644 --- a/src/PalindromeLinkedList.java +++ b/src/PalindromeLinkedList.java @@ -2,10 +2,6 @@ import java.util.List; public class PalindromeLinkedList { - private static class ListNode { - int val; - ListNode next; - } public static boolean isPalindrome(ListNode head) { List list = listFrom(head); diff --git a/src/PartitionList.java b/src/PartitionList.java index e55ce03..04b718d 100644 --- a/src/PartitionList.java +++ b/src/PartitionList.java @@ -3,11 +3,6 @@ // S: O(1) public class PartitionList { - public static class ListNode { - int val; - ListNode next; - ListNode() {} - } public ListNode partition(ListNode head, int x) { ListNode beforeHead = new ListNode(), beforeTemp = beforeHead; diff --git a/src/RemoveDuplicatesFromSortedList.java b/src/RemoveDuplicatesFromSortedList.java index f12c0c9..fde4aed 100644 --- a/src/RemoveDuplicatesFromSortedList.java +++ b/src/RemoveDuplicatesFromSortedList.java @@ -1,20 +1,4 @@ public class RemoveDuplicatesFromSortedList { - public static class ListNode { - int val; - ListNode next; - - ListNode() { - } - - ListNode(int val) { - this.val = val; - } - - ListNode(int val, ListNode next) { - this.val = val; - this.next = next; - } - } public ListNode deleteDuplicates(ListNode head) { ListNode current = head; diff --git a/src/RemoveDuplicatesFromSortedListII.java b/src/RemoveDuplicatesFromSortedListII.java index fa54ecf..0b09be2 100644 --- a/src/RemoveDuplicatesFromSortedListII.java +++ b/src/RemoveDuplicatesFromSortedListII.java @@ -3,10 +3,6 @@ // S: O(1) public class RemoveDuplicatesFromSortedListII { - private static class ListNode { - int val; - ListNode next; - } public ListNode deleteDuplicates(ListNode head) { if (head == null) return null; diff --git a/src/RemoveLinkedListElements.java b/src/RemoveLinkedListElements.java index f74adb1..e7651f9 100644 --- a/src/RemoveLinkedListElements.java +++ b/src/RemoveLinkedListElements.java @@ -1,13 +1,4 @@ public class RemoveLinkedListElements { - private static class ListNode { - int val; - ListNode next; - - ListNode(int val, ListNode next) { - this.val = val; - this.next = next; - } - } public static ListNode removeElements(ListNode head, int target) { ListNode result = new ListNode(-1, head), current = result; diff --git a/src/RemoveNthNodeFromEndOfList.java b/src/RemoveNthNodeFromEndOfList.java index 3c9d440..ba96f05 100644 --- a/src/RemoveNthNodeFromEndOfList.java +++ b/src/RemoveNthNodeFromEndOfList.java @@ -1,12 +1,4 @@ - public class RemoveNthNodeFromEndOfList { - public static class ListNode { - int val; - ListNode next; - ListNode() {} - ListNode(int val) { this.val = val; } - ListNode(int val, ListNode next) { this.val = val; this.next = next; } - } public ListNode removeNthFromEnd(ListNode head, int n) { final int length = length(head); diff --git a/src/ReverseLinkedList.java b/src/ReverseLinkedList.java index b73820c..8039cda 100644 --- a/src/ReverseLinkedList.java +++ b/src/ReverseLinkedList.java @@ -1,8 +1,7 @@ +// T: O(n) +// S: O(1) + public class ReverseLinkedList { - private static class ListNode { - int val; - ListNode next; - } public static ListNode reverseList(ListNode head) { if (head == null || head.next == null) { diff --git a/src/ReverseLinkedListII.java b/src/ReverseLinkedListII.java index 08e5c7a..bb0711d 100644 --- a/src/ReverseLinkedListII.java +++ b/src/ReverseLinkedListII.java @@ -2,13 +2,6 @@ // S: O(1) public class ReverseLinkedListII { - public static class ListNode { - int val; - ListNode next; - ListNode() {} - ListNode(int val) { this.val = val; } - ListNode(int val, ListNode next) { this.val = val; this.next = next; } - } public ListNode reverseBetween(ListNode head, int left, int right) { if (left == right) return head; diff --git a/src/RotateList.java b/src/RotateList.java index 49a5d37..52fef21 100644 --- a/src/RotateList.java +++ b/src/RotateList.java @@ -3,13 +3,6 @@ // S: O(1) public class RotateList { - public static class ListNode { - int val; - ListNode next; - ListNode() {} - ListNode(int val) { this.val = val; } - ListNode(int val, ListNode next) { this.val = val; this.next = next; } - } public ListNode rotateRight(ListNode head, int k) { final int length = getLength(head); diff --git a/src/SwapNodesInPairs.java b/src/SwapNodesInPairs.java index 99ce5d7..7154694 100644 --- a/src/SwapNodesInPairs.java +++ b/src/SwapNodesInPairs.java @@ -3,15 +3,6 @@ // S: O(1) public class SwapNodesInPairs { - private static class ListNode { - int val; - ListNode next; - - ListNode(int val, ListNode next) { - this.val = val; - this.next = next; - } - } public ListNode swapPairs(ListNode head) { if (head == null || head.next == null) return head; From 0efcf46bc61326a538b86f7a568c030d38053318 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 30 May 2022 16:22:15 +0200 Subject: [PATCH 573/947] solves #113 in java --- README.md | 2 +- src/PathSumII.java | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 src/PathSumII.java diff --git a/README.md b/README.md index e586c70..4f4252e 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,7 @@ | 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) | | | +| 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) | | | | 116 | [Populating Next Right Pointers in Each Node](https://leetcode.com/problems/populating-next-right-pointers-in-each-node) | | | | 117 | [Populating Next Right Pointers in Each Node II](https://leetcode.com/problems/populating-next-right-pointers-in-each-node-ii) | | | diff --git a/src/PathSumII.java b/src/PathSumII.java new file mode 100644 index 0000000..cb6b805 --- /dev/null +++ b/src/PathSumII.java @@ -0,0 +1,43 @@ +// https://leetcode.com/problems/path-sum-ii +// T: O(n * log(n)) +// S: O(n * log(n)) + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +public class PathSumII { + public List> pathSum(TreeNode root, int targetSum) { + final List> result = new ArrayList<>(); + if (root == null) return result; + pathSum(root, targetSum, result); + return result; + } + + private void pathSum(TreeNode root, int targetSum, final List> result) { + pathSum(root, targetSum, result, 0, new LinkedList<>()); + } + + private void pathSum(TreeNode root, int targetSum, final List> result, int sum, LinkedList path) { + path.addLast(root.val); + sum += root.val; + + if (isLeafNode(root)) { + if (sum == targetSum) result.add(new ArrayList<>(path)); + return; + } + + if (root.left != null) { + pathSum(root.left, targetSum, result, sum, path); + path.removeLast(); + } + if (root.right != null) { + pathSum(root.right, targetSum, result, sum, path); + path.removeLast(); + } + } + + private boolean isLeafNode(TreeNode root) { + return root.left == null && root.right == null; + } +} From d3078479c1cadf54554e9594a2caf72b6ead75fd Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 30 May 2022 16:42:24 +0200 Subject: [PATCH 574/947] solves #114 in java --- README.md | 2 +- src/FlattenBinaryTreeToLinkedList.java | 26 ++++++++++++++++++++++ src/HelloWorld.java | 30 +++++++++++--------------- src/TreeNode.java | 13 ++++++++++- 4 files changed, 51 insertions(+), 20 deletions(-) create mode 100644 src/FlattenBinaryTreeToLinkedList.java diff --git a/README.md b/README.md index 4f4252e..01d0f5e 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,7 @@ | 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) | | | +| 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) | | | | 117 | [Populating Next Right Pointers in Each Node II](https://leetcode.com/problems/populating-next-right-pointers-in-each-node-ii) | | | | 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) | | diff --git a/src/FlattenBinaryTreeToLinkedList.java b/src/FlattenBinaryTreeToLinkedList.java new file mode 100644 index 0000000..6e2643f --- /dev/null +++ b/src/FlattenBinaryTreeToLinkedList.java @@ -0,0 +1,26 @@ +// https://leetcode.com/problems/flatten-binary-tree-to-linked-list +// T: O(n) +// S: O(log(n)) + +public class FlattenBinaryTreeToLinkedList { + public static void flatten(TreeNode root) { + flattenAndGetLastNode(root); + } + + private static TreeNode flattenAndGetLastNode(TreeNode root) { + if (root == null) return null; + + TreeNode leftLast = flattenAndGetLastNode(root.left); + TreeNode rightLast = flattenAndGetLastNode(root.right); + + if (root.left != null) { + leftLast.right = root.right; + root.right = root.left; + root.left = null; + } + + return rightLast != null + ? rightLast + : (leftLast == null ? root : leftLast); + } +} diff --git a/src/HelloWorld.java b/src/HelloWorld.java index 7d4225b..9739549 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -1,23 +1,17 @@ -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - public class HelloWorld { public static void main(String[] args) { -// ConstructBinaryTreeFromInorderAndPostorderTraversal c = new ConstructBinaryTreeFromInorderAndPostorderTraversal(); -// TreeNode treeNode = c.buildTree(new int[] {9, 3, 15, 20, 7}, new int[] {9, 15, 7, 20, 3}); -// TreePrinter.print(treeNode); -// -// c = new ConstructBinaryTreeFromInorderAndPostorderTraversal(); -// treeNode = c.buildTree(new int[] {2, 1}, new int[] {2, 1}); -// TreePrinter.print(treeNode); -// -// c = new ConstructBinaryTreeFromInorderAndPostorderTraversal(); -// treeNode = c.buildTree(new int[] {-1}, new int[] {-1}); -// TreePrinter.print(treeNode); + TreeNode root = new TreeNode(1); + root.left = new TreeNode(2); + root.right = new TreeNode(5); + root.left.left = new TreeNode(3); + root.left.right = new TreeNode(4); + root.right.right = new TreeNode(6); + + TreePrinter.print(root); + + FlattenBinaryTreeToLinkedList.flatten(root); + + TreePrinter.print(root); - ConstructBinaryTreeFromInorderAndPostorderTraversal c = new ConstructBinaryTreeFromInorderAndPostorderTraversal(); - TreeNode treeNode = c.buildTree(new int[] {1, 2, 3, 4}, new int[] {2, 1, 3, 4}); - TreePrinter.print(treeNode); } } diff --git a/src/TreeNode.java b/src/TreeNode.java index 0d2d037..8f1a19d 100644 --- a/src/TreeNode.java +++ b/src/TreeNode.java @@ -3,13 +3,24 @@ public class TreeNode implements TreePrinter.PrintableNode { TreeNode left; TreeNode right; TreeNode() {} - TreeNode(int val) { this.val = val; } + + TreeNode(int val) { + this.val = val; + } + TreeNode(int val, TreeNode left, TreeNode right) { this.val = val; this.left = left; this.right = right; } + @Override + public String toString() { + return "TreeNode{" + + "val=" + val + + '}'; + } + @Override public TreePrinter.PrintableNode getLeft() { return this.left; From 937959938ff254baf362e4e26d8c94dfe34a54a4 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 30 May 2022 17:09:08 +0200 Subject: [PATCH 575/947] solves #114 in java --- README.md | 2 +- src/HelloWorld.java | 16 ++--- src/MaximumDepthOfNAryTree.java | 24 +++---- src/NArayTreePreOrderTraversal.java | 16 +++++ src/NAryTreePostorderTraversal.java | 16 +++++ ...PopulatingNextRightPointersInEachNode.java | 63 +++++++++++++++++++ 6 files changed, 116 insertions(+), 21 deletions(-) create mode 100644 src/PopulatingNextRightPointersInEachNode.java diff --git a/README.md b/README.md index 01d0f5e..527dfbc 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ | 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) | | | +| 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) | | | | 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) | | diff --git a/src/HelloWorld.java b/src/HelloWorld.java index 9739549..961f7e0 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -1,17 +1,17 @@ public class HelloWorld { public static void main(String[] args) { - TreeNode root = new TreeNode(1); - root.left = new TreeNode(2); - root.right = new TreeNode(5); - root.left.left = new TreeNode(3); - root.left.right = new TreeNode(4); - root.right.right = new TreeNode(6); + PopulatingNextRightPointersInEachNode.Node root = new PopulatingNextRightPointersInEachNode.Node(1); + root.left = new PopulatingNextRightPointersInEachNode.Node(2); + root.right = new PopulatingNextRightPointersInEachNode.Node(3); + root.left.left = new PopulatingNextRightPointersInEachNode.Node(4); + root.left.right = new PopulatingNextRightPointersInEachNode.Node(5); + root.right.left = new PopulatingNextRightPointersInEachNode.Node(6); + root.right.right = new PopulatingNextRightPointersInEachNode.Node(7); TreePrinter.print(root); - FlattenBinaryTreeToLinkedList.flatten(root); + root = PopulatingNextRightPointersInEachNode.connect(root); TreePrinter.print(root); - } } diff --git a/src/MaximumDepthOfNAryTree.java b/src/MaximumDepthOfNAryTree.java index 227c76d..e553a24 100644 --- a/src/MaximumDepthOfNAryTree.java +++ b/src/MaximumDepthOfNAryTree.java @@ -1,22 +1,22 @@ import java.util.List; -class Node { - public int val; - public List children; +public class MaximumDepthOfNAryTree { + private static class Node { + public int val; + public List children; - public Node() {} + public Node() {} - public Node(int _val) { - val = _val; - } + public Node(int _val) { + val = _val; + } - public Node(int _val, List _children) { - val = _val; - children = _children; + public Node(int _val, List _children) { + val = _val; + children = _children; + } } -}; -public class MaximumDepthOfNAryTree { public int maxDepth(Node root) { if (root == null) return 0; int maxDepth = 0; diff --git a/src/NArayTreePreOrderTraversal.java b/src/NArayTreePreOrderTraversal.java index c689bd7..12d54a4 100644 --- a/src/NArayTreePreOrderTraversal.java +++ b/src/NArayTreePreOrderTraversal.java @@ -2,6 +2,22 @@ import java.util.List; public class NArayTreePreOrderTraversal { + private 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; + } + } + List result = new ArrayList<>(); public List preorder(Node root) { diff --git a/src/NAryTreePostorderTraversal.java b/src/NAryTreePostorderTraversal.java index 66f3ae0..a33c4ee 100644 --- a/src/NAryTreePostorderTraversal.java +++ b/src/NAryTreePostorderTraversal.java @@ -2,6 +2,22 @@ import java.util.List; public class NAryTreePostorderTraversal { + private 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; + } + } + List result = new ArrayList<>(); public List postorder(Node root) { diff --git a/src/PopulatingNextRightPointersInEachNode.java b/src/PopulatingNextRightPointersInEachNode.java new file mode 100644 index 0000000..6b11112 --- /dev/null +++ b/src/PopulatingNextRightPointersInEachNode.java @@ -0,0 +1,63 @@ +// https://leetcode.com/problems/populating-next-right-pointers-in-each-node +// T: O(n) +// S: O(n) + +import java.util.LinkedList; +import java.util.Queue; + +public class PopulatingNextRightPointersInEachNode { + public static Node connect(Node root) { + if (root == null) return null; + + final Queue queue = new LinkedList<>(); + queue.add(root); + queue.add(null); + Node previous = null; + + while (!queue.isEmpty()) { + final Node current = queue.poll(); + if (current == null) { + previous = null; + if (!queue.isEmpty()) queue.add(null); + continue; + } + + if (previous != null) previous.next = current; + previous = current; + addChildrenToQueue(queue, current); + } + + return root; + } + + private static void addChildrenToQueue(Queue queue, Node root) { + if (root.left != null) queue.add(root.left); + if (root.right != null) queue.add(root.right); + } + + public static class Node implements TreePrinter.PrintableNode { + public int val; + public Node left; + public Node right; + public Node next; + + public Node(int val) { + this.val = val; + } + + @Override + public TreePrinter.PrintableNode getLeft() { + return left; + } + + @Override + public TreePrinter.PrintableNode getRight() { + return right; + } + + @Override + public String getText() { + return val + ""; + } + } +} From 59a4e2d0d5870f7acebc7aaf0d71639670f1321c Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 30 May 2022 17:12:59 +0200 Subject: [PATCH 576/947] solves #117 in java --- README.md | 2 +- src/HelloWorld.java | 13 ---- ...PopulatingNextRightPointersInEachNode.java | 2 +- ...pulatingNextRightPointersInEachNodeII.java | 63 +++++++++++++++++++ 4 files changed, 65 insertions(+), 15 deletions(-) create mode 100644 src/PopulatingNextRightPointersInEachNodeII.java diff --git a/README.md b/README.md index 527dfbc..1f4cf03 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,7 @@ | 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) | | | +| 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) | | | diff --git a/src/HelloWorld.java b/src/HelloWorld.java index 961f7e0..6fcd2f3 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -1,17 +1,4 @@ public class HelloWorld { public static void main(String[] args) { - PopulatingNextRightPointersInEachNode.Node root = new PopulatingNextRightPointersInEachNode.Node(1); - root.left = new PopulatingNextRightPointersInEachNode.Node(2); - root.right = new PopulatingNextRightPointersInEachNode.Node(3); - root.left.left = new PopulatingNextRightPointersInEachNode.Node(4); - root.left.right = new PopulatingNextRightPointersInEachNode.Node(5); - root.right.left = new PopulatingNextRightPointersInEachNode.Node(6); - root.right.right = new PopulatingNextRightPointersInEachNode.Node(7); - - TreePrinter.print(root); - - root = PopulatingNextRightPointersInEachNode.connect(root); - - TreePrinter.print(root); } } diff --git a/src/PopulatingNextRightPointersInEachNode.java b/src/PopulatingNextRightPointersInEachNode.java index 6b11112..0a4e0d1 100644 --- a/src/PopulatingNextRightPointersInEachNode.java +++ b/src/PopulatingNextRightPointersInEachNode.java @@ -35,7 +35,7 @@ private static void addChildrenToQueue(Queue queue, Node root) { if (root.right != null) queue.add(root.right); } - public static class Node implements TreePrinter.PrintableNode { + private static class Node implements TreePrinter.PrintableNode { public int val; public Node left; public Node right; diff --git a/src/PopulatingNextRightPointersInEachNodeII.java b/src/PopulatingNextRightPointersInEachNodeII.java new file mode 100644 index 0000000..0767b08 --- /dev/null +++ b/src/PopulatingNextRightPointersInEachNodeII.java @@ -0,0 +1,63 @@ +// https://leetcode.com/problems/populating-next-right-pointers-in-each-node-ii +// T: O(n) +// S: O(n) + +import java.util.LinkedList; +import java.util.Queue; + +public class PopulatingNextRightPointersInEachNodeII { + public static Node connect(Node root) { + if (root == null) return null; + + final Queue queue = new LinkedList<>(); + queue.add(root); + queue.add(null); + Node previous = null; + + while (!queue.isEmpty()) { + final Node current = queue.poll(); + if (current == null) { + previous = null; + if (!queue.isEmpty()) queue.add(null); + continue; + } + + if (previous != null) previous.next = current; + previous = current; + addChildrenToQueue(queue, current); + } + + return root; + } + + private static void addChildrenToQueue(Queue queue, Node root) { + if (root.left != null) queue.add(root.left); + if (root.right != null) queue.add(root.right); + } + + private static class Node implements TreePrinter.PrintableNode { + public int val; + public Node left; + public Node right; + public Node next; + + public Node(int val) { + this.val = val; + } + + @Override + public TreePrinter.PrintableNode getLeft() { + return left; + } + + @Override + public TreePrinter.PrintableNode getRight() { + return right; + } + + @Override + public String getText() { + return val + ""; + } + } +} From 2ea90cd363d7b3fe70f3ae08b80f4f09ad4284be Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 30 May 2022 17:29:13 +0200 Subject: [PATCH 577/947] solves #120 in java --- README.md | 2 +- src/Triangle.java | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/Triangle.java diff --git a/README.md b/README.md index 1f4cf03..21381af 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ | 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) | | | +| 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) | | diff --git a/src/Triangle.java b/src/Triangle.java new file mode 100644 index 0000000..7a1192d --- /dev/null +++ b/src/Triangle.java @@ -0,0 +1,35 @@ +// https://leetcode.com/problems/triangle +// T: O(n) where n elements in triangle +// S: O(1) + +import java.util.List; + +public class Triangle { + public int minimumTotal(List> triangle) { + final int rows = triangle.size(); + List previousRow = triangle.get(0); + + for (int row = 1 ; row < rows ; row++) { + final List currentRow = triangle.get(row); + for (int column = 0 ; column < row + 1 ; column++) { + if (column == 0) currentRow.set(column, currentRow.get(column) + previousRow.get(0)); + else if (column == row) currentRow.set(column, currentRow.get(column) + previousRow.get(row - 1)); + else currentRow.set( + column, + currentRow.get(column) + Math.min(previousRow.get(column - 1), previousRow.get(column)) + ); + } + previousRow = currentRow; + } + + return minOfLastRow(triangle); + } + + private int minOfLastRow(List> triangle) { + return min(triangle.get(triangle.size() - 1)); + } + + private int min(List array) { + return array.stream().min(Integer::compareTo).get(); + } +} From 0f70dc8a48f51f22f652792f834aa3dd770da5a4 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 30 May 2022 17:56:02 +0200 Subject: [PATCH 578/947] solves #128 in java --- README.md | 2 +- src/LongestConsecutiveSequence.java | 64 +++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 src/LongestConsecutiveSequence.java diff --git a/README.md b/README.md index 21381af..ddf9383 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ | 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) | | | +| 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) | | | | 130 | [Surrounded Regions](https://leetcode.com/problems/surrounded-regions) | | | | 131 | [Palindrome Partitioning](https://leetcode.com/problems/palindrome-partitioning) | | | diff --git a/src/LongestConsecutiveSequence.java b/src/LongestConsecutiveSequence.java new file mode 100644 index 0000000..1becd51 --- /dev/null +++ b/src/LongestConsecutiveSequence.java @@ -0,0 +1,64 @@ +// https://leetcode.com/problems/longest-consecutive-sequence +// T: O(n) +// S: O(n) + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public class LongestConsecutiveSequence { + private static class Node { + Node next; + Node previous; + } + + public int longestConsecutive(int[] nums) { + final Map nodes = createDisjointSets(nums); + return longestConsecutiveSequenceLength(nodes); + } + + private Map createDisjointSets(int[] array) { + final Map result = new HashMap<>(); + for (int element : array) { + if (result.containsKey(element)) continue; + + Node current = new Node(); + + if (result.containsKey(element - 1)) { + Node left = result.get(element - 1); + left.next = current; + current.previous = left; + } + + if (result.containsKey(element + 1)) { + Node right = result.get(element + 1); + current.next = right; + right.previous = current; + } + + result.put(element, current); + } + + return result; + } + + private int longestConsecutiveSequenceLength(Map nodes) { + final Set processedNodes = new HashSet<>(); + int maxLength = 0; + + for (Node node : nodes.values()) { + int length = getLength(node, processedNodes); + maxLength = Math.max(maxLength, length); + } + + return maxLength; + } + + private int getLength(Node node, Set processedNodes) { + if (node == null) return 0; + if (processedNodes.contains(node)) return 0; + processedNodes.add(node); + return 1 + getLength(node.previous, processedNodes) + getLength(node.next, processedNodes); + } +} From 3aae7746f3fe1e03cd036446d9f8419a2f682f4b Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 30 May 2022 18:25:15 +0200 Subject: [PATCH 579/947] solves #129 in java --- README.md | 6 +-- src/LongestConsecutiveSequence.java | 61 +++++++---------------------- src/SumRootToLeafNumbers.java | 20 ++++++++++ 3 files changed, 38 insertions(+), 49 deletions(-) create mode 100644 src/SumRootToLeafNumbers.java diff --git a/README.md b/README.md index ddf9383..05faff3 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-490/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-490/2081-1abc9c.svg) +![problems-solved](https://img.shields.io/badge/Problems%20Solved-509/2081-1f425f.svg) +![problems-solved-java](https://img.shields.io/badge/Java-509/2081-1abc9c.svg) ![problems-solved-python](https://img.shields.io/badge/Python-185/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) @@ -116,7 +116,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) | | | 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) | | | +| 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) | | | | 131 | [Palindrome Partitioning](https://leetcode.com/problems/palindrome-partitioning) | | | | 133 | [Clone Graph](https://leetcode.com/problems/clone-graph) | | | diff --git a/src/LongestConsecutiveSequence.java b/src/LongestConsecutiveSequence.java index 1becd51..228903f 100644 --- a/src/LongestConsecutiveSequence.java +++ b/src/LongestConsecutiveSequence.java @@ -2,63 +2,32 @@ // T: O(n) // S: O(n) -import java.util.HashMap; import java.util.HashSet; -import java.util.Map; import java.util.Set; public class LongestConsecutiveSequence { - private static class Node { - Node next; - Node previous; - } - public int longestConsecutive(int[] nums) { - final Map nodes = createDisjointSets(nums); - return longestConsecutiveSequenceLength(nodes); - } - - private Map createDisjointSets(int[] array) { - final Map result = new HashMap<>(); - for (int element : array) { - if (result.containsKey(element)) continue; - - Node current = new Node(); - - if (result.containsKey(element - 1)) { - Node left = result.get(element - 1); - left.next = current; - current.previous = left; - } - - if (result.containsKey(element + 1)) { - Node right = result.get(element + 1); - current.next = right; - right.previous = current; - } - - result.put(element, current); - } - - return result; - } - - private int longestConsecutiveSequenceLength(Map nodes) { - final Set processedNodes = new HashSet<>(); + final Set numbers = setFrom(nums); int maxLength = 0; - for (Node node : nodes.values()) { - int length = getLength(node, processedNodes); - maxLength = Math.max(maxLength, length); + for (int number : numbers) { + if (!numbers.contains(number - 1)) { + int length = 1; + for (int i = number + 1 ; numbers.contains(i) ; i++) { + length++; + } + maxLength = Math.max(maxLength, length); + } } return maxLength; } - private int getLength(Node node, Set processedNodes) { - if (node == null) return 0; - if (processedNodes.contains(node)) return 0; - processedNodes.add(node); - return 1 + getLength(node.previous, processedNodes) + getLength(node.next, processedNodes); + private Set setFrom(int[] array) { + final Set set = new HashSet<>(); + for (int element : array) { + set.add(element); + } + return set; } } diff --git a/src/SumRootToLeafNumbers.java b/src/SumRootToLeafNumbers.java new file mode 100644 index 0000000..769cd45 --- /dev/null +++ b/src/SumRootToLeafNumbers.java @@ -0,0 +1,20 @@ +// https://leetcode.com/problems/sum-root-to-leaf-numbers +// T: O(n) +// S: O(log(n)) + +public class SumRootToLeafNumbers { + public int sumNumbers(TreeNode root) { + return sumNumbers(root, 0); + } + + private int sumNumbers(TreeNode root, int currentSum) { + if (root == null) return 0; + if (isLeafNode(root)) return 10 * currentSum + root.val; + return sumNumbers(root.left, 10 * currentSum + root.val) + + sumNumbers(root.right, 10 * currentSum + root.val); + } + + private boolean isLeafNode(TreeNode root) { + return root.left == null && root.right == null; + } +} From 54487739681e3ab4f9fc48c6b08a65afe757bc07 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 31 May 2022 16:16:09 +0200 Subject: [PATCH 580/947] solves #130 in java --- README.md | 2 +- src/SurroundedRegions.java | 92 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 src/SurroundedRegions.java diff --git a/README.md b/README.md index 05faff3..8e4d697 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,7 @@ | 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) | | | +| 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) | | | | 133 | [Clone Graph](https://leetcode.com/problems/clone-graph) | | | | 134 | [Gas Station](https://leetcode.com/problems/gas-station) | | | diff --git a/src/SurroundedRegions.java b/src/SurroundedRegions.java new file mode 100644 index 0000000..9442e5e --- /dev/null +++ b/src/SurroundedRegions.java @@ -0,0 +1,92 @@ +// https://leetcode.com/problems/surrounded-regions +// T: O(m * n) +// S: O(m * n) + +import java.util.HashSet; +import java.util.Set; + +public class SurroundedRegions { + private record Position(int row, int column) { + @Override + public boolean equals(Object o) { + if (this == o) return true; + Position position = (Position) o; + if (row != position.row) return false; + return column == position.column; + } + + @Override + public int hashCode() { + return 31 * row + column; + } + + public Position top() { + return new Position(row - 1, column); + } + + public Position right() { + return new Position(row, column + 1); + } + + public Position bottom() { + return new Position(row + 1, column); + } + + public Position left() { + return new Position(row, column - 1); + } + } + + public void solve(char[][] board) { + final Set visited = new HashSet<>(); + final Set current = new HashSet<>(); + final int rows = board.length, columns = board[0].length; + + for (int row = 1 ; row < rows - 1 ; row++) { + for (int column = 1 ; column < columns - 1 ; column++) { + if (board[row][column] == 'O') { + final boolean isBorderRegion = markRegion(board, new Position(row, column), visited, current); + if (!isBorderRegion) { + captureRegion(board, current); + } + current.clear(); + } + } + } + } + + private boolean markRegion(char[][] board, Position position, Set visited, Set region) { + if (isInvalidPosition(board, position) || visited.contains(position) || isX(board, position)) return false; + visited.add(position); + region.add(position); + boolean top = markRegion(board, position.top(), visited, region); + boolean right = markRegion(board, position.right(), visited, region); + boolean bottom = markRegion(board, position.bottom(), visited, region); + boolean left = markRegion(board, position.left(), visited, region); + return top || right || bottom || left || isBorderPosition(board, position); + } + + private boolean isX(char[][] board, Position position) { + return board[position.row][position.column] == 'X'; + } + + private boolean isBorderPosition(char[][] board, Position position) { + return position.row == 0 + || position.row == board.length - 1 + || position.column == 0 + || position.column == board[0].length - 1; + } + + private boolean isInvalidPosition(char[][] board, Position position) { + return position.row < 0 + || position.row >= board.length + || position.column < 0 + || position.column >= board[0].length; + } + + private void captureRegion(char[][] board, Set positions) { + for (Position position : positions) { + board[position.row][position.column] = 'X'; + } + } +} From bc09a990e4079fbfaea88c57d5a65822d1f77158 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Tue, 31 May 2022 17:59:29 +0200 Subject: [PATCH 581/947] solves #131 in jav --- README.md | 2 +- src/HelloWorld.java | 1 + src/PalindromePartitioning.java | 79 +++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 src/PalindromePartitioning.java diff --git a/README.md b/README.md index 8e4d697..0b48f45 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,7 @@ | 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) | | | +| 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) | | | | 134 | [Gas Station](https://leetcode.com/problems/gas-station) | | | | 136 | [Single Number](https://leetcode.com/problems/single-number) | [![Java](assets/java.png)](src/SingleNumber.java) [![Python](assets/python.png)](python/single_number.py) | | diff --git a/src/HelloWorld.java b/src/HelloWorld.java index 6fcd2f3..38aaee2 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -1,4 +1,5 @@ public class HelloWorld { public static void main(String[] args) { + System.out.println(PalindromePartitioning.partition("abbab")); } } diff --git a/src/PalindromePartitioning.java b/src/PalindromePartitioning.java new file mode 100644 index 0000000..80986fe --- /dev/null +++ b/src/PalindromePartitioning.java @@ -0,0 +1,79 @@ +// https://leetcode.com/problems/palindrome-partitioning +// T: O(n * 2^n) +// S: O(n * 2^n) + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +public class PalindromePartitioning { + private record Range(int start, int end) { } + + public static List> partition(String s) { + final List> palindromicPartitions = new ArrayList<>(); + addValidPartitionsToResult(s, palindromicPartitions); + return palindromicPartitions; + } + + private static void addValidPartitionsToResult(String s, List> result) { + if (isPalindrome(s)) result.add(List.of(s)); + for (int i = 1 ; i < s.length() ; i++) { + LinkedList segments = new LinkedList<>(); + segments.add(new Range(0, i)); + segments.add(new Range(i, s.length())); + addValidPartitionsToResult(s, result, segments); + } + } + + private static void addValidPartitionsToResult(String s, List> result, LinkedList segments) { + if (!isPalindrome(s, getSecondLast(segments))) return; + final Range lastSegment = lastSegment(segments); + if (isPalindrome(s, lastSegment)) { + result.add(getPartitions(s, segments)); + } + if (lastSegment.start + 1 < s.length()) { + segments.pollLast(); + } + for (int i = lastSegment.start + 1 ; i < s.length() ; i++) { + segments.addLast(new Range(lastSegment.start, i)); + segments.addLast(new Range(i, lastSegment.end)); + addValidPartitionsToResult(s, result, segments); + segments.pollLast(); + segments.pollLast(); + } + if (lastSegment.start + 1 < s.length()) { + segments.add(lastSegment); + } + } + + private static List getPartitions(String s, List segments) { + final List result = new LinkedList<>(); + for (Range range : segments) { + result.add(s.substring(range.start, range.end)); + } + return result; + } + + private static Range getSecondLast(List segments) { + return segments.get(segments.size() - 2); + } + + private static Range lastSegment(List segments) { + return segments.get(segments.size() - 1); + } + + public static boolean isPalindrome(String s) { + return isPalindrome(s, 0, s.length()); + } + + private static boolean isPalindrome(String s, Range range) { + return isPalindrome(s, range.start, range.end); + } + + public static boolean isPalindrome(String s, int start, int end) { + for (int i = start ; i < start + (end - start) / 2 ; i++) { + if (s.charAt(i) != s.charAt(end - i + start - 1)) return false; + } + return true; + } +} From c5b384c39fb110dbb94207aec82be88ef24389c8 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Wed, 1 Jun 2022 15:14:44 +0200 Subject: [PATCH 582/947] updates #131 in jav --- src/HelloWorld.java | 9 +++- src/PalindromePartitioning.java | 79 +++++++-------------------------- 2 files changed, 23 insertions(+), 65 deletions(-) diff --git a/src/HelloWorld.java b/src/HelloWorld.java index 38aaee2..1d611eb 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -1,5 +1,12 @@ +import java.util.Map; + +import static java.util.Map.entry; + public class HelloWorld { public static void main(String[] args) { - System.out.println(PalindromePartitioning.partition("abbab")); + Map map = Map.of( + "hello", null, + "", null + ); } } diff --git a/src/PalindromePartitioning.java b/src/PalindromePartitioning.java index 80986fe..ed20a1d 100644 --- a/src/PalindromePartitioning.java +++ b/src/PalindromePartitioning.java @@ -1,79 +1,30 @@ // https://leetcode.com/problems/palindrome-partitioning // T: O(n * 2^n) -// S: O(n * 2^n) +// S: O(n) for recursion call stack import java.util.ArrayList; import java.util.LinkedList; import java.util.List; public class PalindromePartitioning { - private record Range(int start, int end) { } - - public static List> partition(String s) { - final List> palindromicPartitions = new ArrayList<>(); - addValidPartitionsToResult(s, palindromicPartitions); - return palindromicPartitions; - } - - private static void addValidPartitionsToResult(String s, List> result) { - if (isPalindrome(s)) result.add(List.of(s)); - for (int i = 1 ; i < s.length() ; i++) { - LinkedList segments = new LinkedList<>(); - segments.add(new Range(0, i)); - segments.add(new Range(i, s.length())); - addValidPartitionsToResult(s, result, segments); - } - } - - private static void addValidPartitionsToResult(String s, List> result, LinkedList segments) { - if (!isPalindrome(s, getSecondLast(segments))) return; - final Range lastSegment = lastSegment(segments); - if (isPalindrome(s, lastSegment)) { - result.add(getPartitions(s, segments)); - } - if (lastSegment.start + 1 < s.length()) { - segments.pollLast(); - } - for (int i = lastSegment.start + 1 ; i < s.length() ; i++) { - segments.addLast(new Range(lastSegment.start, i)); - segments.addLast(new Range(i, lastSegment.end)); - addValidPartitionsToResult(s, result, segments); - segments.pollLast(); - segments.pollLast(); - } - if (lastSegment.start + 1 < s.length()) { - segments.add(lastSegment); - } - } - - private static List getPartitions(String s, List segments) { - final List result = new LinkedList<>(); - for (Range range : segments) { - result.add(s.substring(range.start, range.end)); - } + public List> partition(String s) { + final int length = s.length(); + final boolean[][] dp = new boolean[length][length]; + final List> result = new ArrayList<>(); + addValidPartitions(s, 0, dp, result, new LinkedList<>()); return result; } - private static Range getSecondLast(List segments) { - return segments.get(segments.size() - 2); - } - - private static Range lastSegment(List segments) { - return segments.get(segments.size() - 1); - } - - public static boolean isPalindrome(String s) { - return isPalindrome(s, 0, s.length()); - } - - private static boolean isPalindrome(String s, Range range) { - return isPalindrome(s, range.start, range.end); - } + private void addValidPartitions(String s, int start, boolean[][] dp, List> result, LinkedList current) { + if (start == s.length()) result.add(new ArrayList<>(current)); - public static boolean isPalindrome(String s, int start, int end) { - for (int i = start ; i < start + (end - start) / 2 ; i++) { - if (s.charAt(i) != s.charAt(end - i + start - 1)) return false; + for (int end = start ; end < s.length() ; end++) { + if (s.charAt(start) == s.charAt(end) && (end - start <= 2 || dp[start + 1][end - 1])) { + dp[start][end] = true; + current.addLast(s.substring(start, end + 1)); + addValidPartitions(s, end + 1, dp, result, current); + current.pollLast(); + } } - return true; } } From 01ab000d404267db392dc97bc38bf36ba048aed2 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Wed, 1 Jun 2022 15:35:43 +0200 Subject: [PATCH 583/947] solves #133 in java --- README.md | 2 +- src/CloneGraph.java | 59 +++++++++++++++++++++++++++++++++++++++++++++ src/HelloWorld.java | 8 ------ 3 files changed, 60 insertions(+), 9 deletions(-) create mode 100644 src/CloneGraph.java diff --git a/README.md b/README.md index 0b48f45..5b062d8 100644 --- a/README.md +++ b/README.md @@ -119,7 +119,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) | | | +| 133 | [Clone Graph](https://leetcode.com/problems/clone-graph) | [![Java](assets/java.png)](src/CloneGraph.java) | | | 134 | [Gas Station](https://leetcode.com/problems/gas-station) | | | | 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) | | | diff --git a/src/CloneGraph.java b/src/CloneGraph.java new file mode 100644 index 0000000..ff96466 --- /dev/null +++ b/src/CloneGraph.java @@ -0,0 +1,59 @@ +// https://leetcode.com/problems/clone-graph +// 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 CloneGraph { + private static final class Node { + public int val; + public List neighbors; + + public Node() { + val = 0; + neighbors = new ArrayList<>(); + } + + public Node(int val) { + this.val = val; + neighbors = new ArrayList<>(); + } + + public Node(int val, ArrayList neighbors) { + this.val = val; + this.neighbors = neighbors; + } + } + + public Node cloneGraph(Node node) { + if (node == null) return null; + final Map graph = new HashMap<>(); + cloneGraph(node, new HashSet<>(), graph); + return graph.get(node.val); + } + + private void cloneGraph(Node node, Set visited, Map newGraph) { + if (node == null) return; + if (visited.contains(node.val)) return; + visited.add(node.val); + + Node current = getNode(newGraph, node.val); + for (Node adjacent : node.neighbors) { + Node newNeighbour = getNode(newGraph, adjacent.val); + current.neighbors.add(newNeighbour); + cloneGraph(adjacent, visited, newGraph); + } + } + + private Node getNode(Map graph, int value) { + if (graph.containsKey(value)) return graph.get(value); + Node node = new Node(value); + graph.put(value, node); + return node; + } +} diff --git a/src/HelloWorld.java b/src/HelloWorld.java index 1d611eb..6fcd2f3 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -1,12 +1,4 @@ -import java.util.Map; - -import static java.util.Map.entry; - public class HelloWorld { public static void main(String[] args) { - Map map = Map.of( - "hello", null, - "", null - ); } } From 9cae15eff4a453945070cfc03fc7379758dc4256 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 4 Jun 2022 19:42:54 +0200 Subject: [PATCH 584/947] updates tree printer class --- src/TreePrinter.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/TreePrinter.java b/src/TreePrinter.java index 6a4ded1..9586652 100644 --- a/src/TreePrinter.java +++ b/src/TreePrinter.java @@ -28,10 +28,10 @@ public interface PrintableNode { * tree root node */ public static void print(PrintableNode root) { - List> lines = new ArrayList>(); + List> lines = new ArrayList<>(); - List level = new ArrayList(); - List next = new ArrayList(); + List level = new ArrayList<>(); + List next = new ArrayList<>(); level.add(root); int nn = 1; @@ -86,7 +86,7 @@ public static void print(PrintableNode root) { if (line.get(j - 1) != null) { c = (line.get(j) != null) ? '┴' : '┘'; } else { - if (j < line.size() && line.get(j) != null) c = '└'; + if (line.get(j) != null) c = '└'; } } System.out.print(c); @@ -111,9 +111,8 @@ public static void print(PrintableNode root) { } // print line of numbers - for (int j = 0; j < line.size(); j++) { + for (String f : line) { - String f = line.get(j); if (f == null) f = ""; int gap1 = (int) Math.ceil(perpiece / 2f - f.length() / 2f); int gap2 = (int) Math.floor(perpiece / 2f - f.length() / 2f); @@ -132,4 +131,4 @@ public static void print(PrintableNode root) { perpiece /= 2; } } -} \ No newline at end of file +} From c68fd0d7028617791ca565bae6bd7bfdc6f24445 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Wed, 15 Jun 2022 16:00:03 +0200 Subject: [PATCH 585/947] solves gas station --- README.md | 2 +- src/GasStation.java | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/GasStation.java diff --git a/README.md b/README.md index 5b062d8..5763811 100644 --- a/README.md +++ b/README.md @@ -120,7 +120,7 @@ | 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) | | -| 134 | [Gas Station](https://leetcode.com/problems/gas-station) | | | +| 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) | | | | 138 | [Copy List with Random Pointer](https://leetcode.com/problems/copy-list-with-random-pointer) | | | diff --git a/src/GasStation.java b/src/GasStation.java new file mode 100644 index 0000000..29384b2 --- /dev/null +++ b/src/GasStation.java @@ -0,0 +1,27 @@ +// https://leetcode.com/problems/gas-station +// T: O(n) +// S: O(1) + +public class GasStation { + public int canCompleteCircuit(int[] gas, int[] cost) { + if (sum(gas) < sum(cost)) return -1; + + int startIndex = 0; + for (int i = 0, total = 0 ; i < gas.length ; i++) { + total += gas[i] - cost[i]; + if (total < 0) { + total = 0; + startIndex = i + 1; + } + } + return startIndex; + } + + private int sum(int[] array) { + int sum = 0; + for (int element : array) { + sum += element; + } + return sum; + } +} From 934e943ca90ccf488e966d91f556f87230e4d335 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Wed, 15 Jun 2022 18:03:15 +0200 Subject: [PATCH 586/947] solves single number ii in java --- README.md | 2 +- src/SingleNumberII.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/SingleNumberII.java diff --git a/README.md b/README.md index 5763811..518dcae 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,7 @@ | 133 | [Clone Graph](https://leetcode.com/problems/clone-graph) | [![Java](assets/java.png)](src/CloneGraph.java) | | | 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) | | | +| 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) | | | | 139 | [Word Break](https://leetcode.com/problems/word-break) | | | | 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) | | diff --git a/src/SingleNumberII.java b/src/SingleNumberII.java new file mode 100644 index 0000000..d28288e --- /dev/null +++ b/src/SingleNumberII.java @@ -0,0 +1,17 @@ +// https://leetcode.com/problems/single-number-ii +// T: O(n) +// S: O(1) + +public class SingleNumberII { + public int singleNumber(int[] nums) { + int x1 = 0, x2 = 0, mask = 0; + for (int element : nums) { + x2 ^= (x1 & element); + x1 ^= element; + mask = ~(x1 & x2); + x1 &= mask; + x2 &= mask; + } + return x1; + } +} From aea4f807018d9cb9df92a3f68a003a4b1cd4ce39 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Wed, 15 Jun 2022 18:19:40 +0200 Subject: [PATCH 587/947] solves copy list with random pointer --- README.md | 2 +- src/CopyListWithRandomPointer.java | 47 ++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 src/CopyListWithRandomPointer.java diff --git a/README.md b/README.md index 518dcae..e1e8c8f 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,7 @@ | 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) | | | +| 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) | | | | 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) | | | diff --git a/src/CopyListWithRandomPointer.java b/src/CopyListWithRandomPointer.java new file mode 100644 index 0000000..3c97e95 --- /dev/null +++ b/src/CopyListWithRandomPointer.java @@ -0,0 +1,47 @@ +// https://leetcode.com/problems/copy-list-with-random-pointer +// T: O(N) +// S: O(N) + +import java.util.HashMap; +import java.util.Map; + +public class CopyListWithRandomPointer { + private static final class Node { + int val; + Node next; + Node random; + + public Node(int val) { + this.val = val; + this.next = null; + this.random = null; + } + } + + private static final Map nodes = new HashMap<>(); + + public Node copyRandomList(Node head) { + if (head == null) return null; + + 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); + } + } + + return getNode(head); + } + + private Node getNode(Node node) { + if (nodes.containsKey(node)) { + return nodes.get(node); + } + Node copyNode = new Node(node.val); + nodes.put(node, copyNode); + return copyNode; + } +} From c09ffe3f8e2bee1fdd399e2c5afc40860adacfbf Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 17 Jun 2022 11:58:30 +0200 Subject: [PATCH 588/947] solves word break with trie --- src/WordBreak.java | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/WordBreak.java diff --git a/src/WordBreak.java b/src/WordBreak.java new file mode 100644 index 0000000..02b4111 --- /dev/null +++ b/src/WordBreak.java @@ -0,0 +1,58 @@ +import java.util.List; + +public class WordBreak { + private static final class Trie { + private static final int LETTERS_IN_ENGLISH_ALPHABET = 26; + + Trie[] letters = new Trie[LETTERS_IN_ENGLISH_ALPHABET]; + boolean isWord = false; + + public void insert(String word) { + insert(word, 0, this); + } + + private void insert(String s, int index, Trie root) { + if (index >= s.length()) { + root.isWord = true; + return; + } + if (root.letters[s.charAt(index) - 'a'] == null) { + root.letters[s.charAt(index) - 'a'] = new Trie(); + } + insert(s, index + 1, root.letters[s.charAt(index) - 'a']); + } + + public boolean exists(String word) { + return exists(word, 0, this); + } + + private boolean exists(String s, int index, Trie root) { + if (index >= s.length()) { + return root.isWord; + } + if (root.letters[s.charAt(index) - 'a'] == null) return false; + return exists(s, index + 1, root.letters[s.charAt(index) - 'a']); + } + } + + + public boolean wordBreak(String s, List wordDict) { + final Trie trie = new Trie(); + for (String string : wordDict) { + trie.insert(string); + } + return wordBreak(s, trie); + } + + private boolean wordBreak(String s, Trie root) { + if (s.isEmpty()) return true; + + for (int i = 0 ; i < s.length() ; i++) { + if (root.exists(s.substring(0, i + 1)) && wordBreak(s.substring(i + 1), root)) { + return true; + } + } + + return false; + } +} From 93310ddccac40642a42f2eab4871bdb62d8a7ec8 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 17 Jun 2022 12:00:23 +0200 Subject: [PATCH 589/947] solves word break in java --- README.md | 2 +- src/WordBreak.java | 66 ++++++++++++---------------------------------- 2 files changed, 18 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index e1e8c8f..964672f 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,7 @@ | 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) | | | +| 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) | | | | 143 | [Reorder List](https://leetcode.com/problems/reorder-list) | | | diff --git a/src/WordBreak.java b/src/WordBreak.java index 02b4111..a48b315 100644 --- a/src/WordBreak.java +++ b/src/WordBreak.java @@ -1,58 +1,26 @@ +// https://leetcode.com/problems/word-break +// T: O(s^3 + w) +// S: O(s + w) + +import java.util.HashSet; import java.util.List; +import java.util.Set; public class WordBreak { - private static final class Trie { - private static final int LETTERS_IN_ENGLISH_ALPHABET = 26; - - Trie[] letters = new Trie[LETTERS_IN_ENGLISH_ALPHABET]; - boolean isWord = false; - - public void insert(String word) { - insert(word, 0, this); - } - - private void insert(String s, int index, Trie root) { - if (index >= s.length()) { - root.isWord = true; - return; - } - if (root.letters[s.charAt(index) - 'a'] == null) { - root.letters[s.charAt(index) - 'a'] = new Trie(); - } - insert(s, index + 1, root.letters[s.charAt(index) - 'a']); - } - - public boolean exists(String word) { - return exists(word, 0, this); - } - - private boolean exists(String s, int index, Trie root) { - if (index >= s.length()) { - return root.isWord; - } - if (root.letters[s.charAt(index) - 'a'] == null) return false; - return exists(s, index + 1, root.letters[s.charAt(index) - 'a']); - } - } - - public boolean wordBreak(String s, List wordDict) { - final Trie trie = new Trie(); - for (String string : wordDict) { - trie.insert(string); - } - return wordBreak(s, trie); - } - - private boolean wordBreak(String s, Trie root) { - if (s.isEmpty()) return true; - - for (int i = 0 ; i < s.length() ; i++) { - if (root.exists(s.substring(0, i + 1)) && wordBreak(s.substring(i + 1), root)) { - return true; + final Set words = new HashSet<>(wordDict); + final boolean[] dp = new boolean[s.length() + 1]; + dp[0] = true; + + for (int i = 1 ; i <= s.length() ; i++) { + for (int j = 0 ; j < i ; j++) { + if (dp[j] && words.contains(s.substring(j, i))) { + dp[i] = true; + break; + } } } - return false; + return dp[dp.length - 1]; } } From 0def0e3a9d1593c70615e8fe9bf26e7746050b50 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 17 Jun 2022 12:17:23 +0200 Subject: [PATCH 590/947] solves linkedlist cycle ii in java --- README.md | 2 +- src/LinkedListCycleII.java | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/LinkedListCycleII.java diff --git a/README.md b/README.md index 964672f..65e4a7d 100644 --- a/README.md +++ b/README.md @@ -126,7 +126,7 @@ | 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) | | | +| 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) | | | | 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) | | diff --git a/src/LinkedListCycleII.java b/src/LinkedListCycleII.java new file mode 100644 index 0000000..cd27d62 --- /dev/null +++ b/src/LinkedListCycleII.java @@ -0,0 +1,24 @@ +// https://leetcode.com/problems/linked-list-cycle-ii +// T: O(n) +// S: O(1) + +public class LinkedListCycleII { + public ListNode detectCycle(ListNode head) { + if (head == null) return null; + + ListNode slow = head, fast = head, entry = head; + while (fast.next != null && fast.next.next != null) { + slow = slow.next; + fast = fast.next.next; + + if (slow == fast) { + while (entry != slow) { + entry = entry.next; + slow = slow.next; + } + return entry; + } + } + return null; + } +} From 5c47593555d91262914e763e0f97fd0d56542c40 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 17 Jun 2022 13:41:03 +0200 Subject: [PATCH 591/947] solves reorder list in java --- README.md | 2 +- src/ReorderList.java | 47 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 src/ReorderList.java diff --git a/README.md b/README.md index 65e4a7d..02cc1a0 100644 --- a/README.md +++ b/README.md @@ -127,7 +127,7 @@ | 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) | | | +| 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) | | diff --git a/src/ReorderList.java b/src/ReorderList.java new file mode 100644 index 0000000..23f8d9f --- /dev/null +++ b/src/ReorderList.java @@ -0,0 +1,47 @@ +// https://leetcode.com/problems/reorder-list +// T: O(N) +// S: O(1) + +public class ReorderList { + public void reorderList(ListNode head) { + if (head == null || head.next == null) return; + + ListNode middle = getMiddleOfLinkedList(head); + ListNode preMiddle = reverseLinkedList(middle); + interleaveNodes(head, preMiddle); + } + + private ListNode getMiddleOfLinkedList(ListNode head) { + ListNode p1 = head; + ListNode p2 = head; + while(p2.next!=null&&p2.next.next!=null){ + p1 = p1.next; + p2 = p2.next.next; + } + return p1; + } + + private ListNode reverseLinkedList(ListNode head) { + ListNode preCurrent = head.next; + while(preCurrent.next != null){ + ListNode current = preCurrent.next; + preCurrent.next = current.next; + current.next = head.next; + head.next = current; + } + return head; + } + + // 1->2->3->6->5->4 to 1->6->2->5->3->4 + private void interleaveNodes(ListNode head, ListNode preMiddle) { + ListNode p1 = head; + ListNode p2 = preMiddle.next; + while(p1 != preMiddle){ + preMiddle.next = p2.next; + p2.next = p1.next; + p1.next = p2; + p1 = p2.next; + p2 = preMiddle.next; + } + } +} From 9eb22c94b16d905c94a1dc8b80625da909fc02a5 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 17 Jun 2022 14:03:12 +0200 Subject: [PATCH 592/947] solves insertion sort list in java --- README.md | 2 +- src/InsertionSortList.java | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/InsertionSortList.java diff --git a/README.md b/README.md index 02cc1a0..92c54a8 100644 --- a/README.md +++ b/README.md @@ -131,7 +131,7 @@ | 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) | | | +| 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) | | | | 150 | [Evaluate Reverse Polish Notation](https://leetcode.com/problems/evaluate-reverse-polish-notation) | | | | 151 | [Reverse Words in a String](https://leetcode.com/problems/reverse-words-in-a-string) | | | diff --git a/src/InsertionSortList.java b/src/InsertionSortList.java new file mode 100644 index 0000000..6b41236 --- /dev/null +++ b/src/InsertionSortList.java @@ -0,0 +1,29 @@ +// https://leetcode.com/problems/insertion-sort-list +// T: O(n^2) +// S: O(1) + +public class InsertionSortList { + public ListNode insertionSortList(ListNode head) { + if (head == null || head.next == null) return head; + + ListNode newHead = new ListNode(0); + ListNode pre = newHead; + ListNode next; + + for (ListNode cur = head ; cur != null ; ) { + next = cur.next; + + while (pre.next != null && pre.next.val < cur.val) { + pre = pre.next; + } + + //insert between pre and pre.next + cur.next = pre.next; + pre.next = cur; + pre = newHead; + cur = next; + } + + return newHead.next; + } +} From 091e3357623a7e550554457ddeb783dc58de2de9 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 17 Jun 2022 14:40:20 +0200 Subject: [PATCH 593/947] solves sort list in java --- README.md | 2 +- src/SortList.java | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/SortList.java diff --git a/README.md b/README.md index 92c54a8..71b1487 100644 --- a/README.md +++ b/README.md @@ -132,7 +132,7 @@ | 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) | | | +| 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) | | | | 151 | [Reverse Words in a String](https://leetcode.com/problems/reverse-words-in-a-string) | | | | 152 | [Maximum Product Subarray](https://leetcode.com/problems/maximum-product-subarray) | | | diff --git a/src/SortList.java b/src/SortList.java new file mode 100644 index 0000000..9c838e3 --- /dev/null +++ b/src/SortList.java @@ -0,0 +1,41 @@ +// https://leetcode.com/problems/sort-list +// T: O(N log(N)) +// S: O(log(N)) + +public class SortList { + public ListNode sortList(ListNode head) { + if (head == null || head.next == null) return head; + ListNode mid = getMid(head); + ListNode left = sortList(head); + ListNode right = sortList(mid); + return merge(left, right); + } + + ListNode merge(ListNode list1, ListNode list2) { + ListNode dummyHead = new ListNode(); + ListNode tail = dummyHead; + while (list1 != null && list2 != null) { + if (list1.val < list2.val) { + tail.next = list1; + list1 = list1.next; + } else { + tail.next = list2; + list2 = list2.next; + } + tail = tail.next; + } + tail.next = (list1 != null ? list1 : list2); + return dummyHead.next; + } + + ListNode getMid(ListNode head) { + ListNode midPrev = null; + while (head != null && head.next != null) { + midPrev = (midPrev == null ? head : midPrev.next); + head = head.next.next; + } + ListNode mid = midPrev.next; + midPrev.next = null; + return mid; + } +} From 8b4fdc8adbba0a356de0b447687eb4cb52061679 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 17 Jun 2022 15:03:23 +0200 Subject: [PATCH 594/947] solves reverse polish notation in java --- README.md | 2 +- src/EvaluateReversePolishNotation.java | 48 ++++++++++++++++++++++++++ src/HelloWorld.java | 3 ++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 src/EvaluateReversePolishNotation.java diff --git a/README.md b/README.md index 71b1487..734842c 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,7 @@ | 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) | | | +| 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) | | | | 152 | [Maximum Product Subarray](https://leetcode.com/problems/maximum-product-subarray) | | | | 153 | [Find Minimum in Rotated Sorted Array](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array) | | | diff --git a/src/EvaluateReversePolishNotation.java b/src/EvaluateReversePolishNotation.java new file mode 100644 index 0000000..8562731 --- /dev/null +++ b/src/EvaluateReversePolishNotation.java @@ -0,0 +1,48 @@ +// https://leetcode.com/problems/evaluate-reverse-polish-notation +// T: O(N) +// S: O(N) + +import java.util.Set; +import java.util.Stack; + +public class EvaluateReversePolishNotation { + private static final String ADDITION = "+"; + private static final String SUBTRACTION = "-"; + private static final String MULTIPLICATION = "*"; + private static final String DIVISION = "/"; + + private static final Set OPERATORS = Set.of( + ADDITION, + SUBTRACTION, + MULTIPLICATION, + DIVISION + ); + + public static int evalRPN(String[] tokens) { + Stack stack = new Stack<>(); + for (String token : tokens) { + if (isOperator(token)) { + int number1 = stack.pop(); + int number2 = stack.pop(); + stack.push(apply(number2, number1, token)); + } else { + stack.push(Integer.parseInt(token)); + } + } + return stack.pop(); + } + + private static boolean isOperator(String token) { + return OPERATORS.contains(token); + } + + private static int apply(int a, int b, String operator) { + return switch (operator) { + case ADDITION -> a + b; + case SUBTRACTION -> a - b; + case MULTIPLICATION -> a * b; + case DIVISION -> a / b; + default -> 0; + }; + } +} diff --git a/src/HelloWorld.java b/src/HelloWorld.java index 6fcd2f3..c3c64b8 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -1,4 +1,7 @@ public class HelloWorld { public static void main(String[] args) { + System.out.println(Integer.parseInt("2")); + System.out.println(Integer.parseInt("-11")); + System.out.println(EvaluateReversePolishNotation.evalRPN(new String[] {"2", "-11", "-"})); } } From ddf875809ae323d783c6ac341efb73e2dbf75bf3 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 17 Jun 2022 16:11:46 +0200 Subject: [PATCH 595/947] solves reverse words in a string --- README.md | 2 +- src/HelloWorld.java | 4 +--- src/ReverseWordsInAString.java | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 src/ReverseWordsInAString.java diff --git a/README.md b/README.md index 734842c..6e169b2 100644 --- a/README.md +++ b/README.md @@ -134,7 +134,7 @@ | 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) | | | +| 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) | | | | 153 | [Find Minimum in Rotated Sorted Array](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array) | | | | 155 | [Min Stack](https://leetcode.com/problems/min-stack) | [![Java](assets/java.png)](src/MinStack.java) [![Python](assets/python.png)](python/min_stack.py) | | diff --git a/src/HelloWorld.java b/src/HelloWorld.java index c3c64b8..474c54e 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -1,7 +1,5 @@ public class HelloWorld { public static void main(String[] args) { - System.out.println(Integer.parseInt("2")); - System.out.println(Integer.parseInt("-11")); - System.out.println(EvaluateReversePolishNotation.evalRPN(new String[] {"2", "-11", "-"})); + System.out.println(ReverseWordsInAString.reverseWords(" hello world ")); } } diff --git a/src/ReverseWordsInAString.java b/src/ReverseWordsInAString.java new file mode 100644 index 0000000..e30488c --- /dev/null +++ b/src/ReverseWordsInAString.java @@ -0,0 +1,19 @@ +// https://leetcode.com/problems/reverse-words-in-a-string +// T: O(s) +// S: O(s) + +public class ReverseWordsInAString { + private static final char SPACE = ' '; + + public static String reverseWords(String s) { + final String[] words = s.split(" "); + final StringBuilder result = new StringBuilder(); + for (int i = words.length - 1 ; i >= 0 ; i--) { + String word = words[i]; + if (word.isEmpty()) continue; + result.append(word).append(SPACE); + } + result.deleteCharAt(result.length() - 1); + return result.toString(); + } +} From 3acdff108683eb94b1c19eb10be5408cf00dd72c Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 17 Jun 2022 17:34:06 +0200 Subject: [PATCH 596/947] solves maximum product sub array in java --- README.md | 2 +- src/HelloWorld.java | 4 +++- src/MaximumProductSubarray.java | 25 +++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 src/MaximumProductSubarray.java diff --git a/README.md b/README.md index 6e169b2..331594b 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,7 @@ | 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) | | | +| 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) | | | | 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) | | | diff --git a/src/HelloWorld.java b/src/HelloWorld.java index 474c54e..bb829de 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -1,5 +1,7 @@ public class HelloWorld { public static void main(String[] args) { - System.out.println(ReverseWordsInAString.reverseWords(" hello world ")); + System.out.println( + MaximumProductSubarray.maxProduct(new int[] {-4, -3, -2}) + ); } } diff --git a/src/MaximumProductSubarray.java b/src/MaximumProductSubarray.java new file mode 100644 index 0000000..2eb334d --- /dev/null +++ b/src/MaximumProductSubarray.java @@ -0,0 +1,25 @@ +// https://leetcode.com/problems/maximum-product-subarray +// T: O(N) +// S: O(1) + +public class MaximumProductSubarray { + public static int maxProduct(int[] nums) { + int max = nums[0], min = nums[0], maxSoFar = max, temp; + for (int i = 1 ; i < nums.length ; i++) { + int number = nums[i]; + temp = max(max * number, min * number, number); + min = min(max * number, min * number, number); + max = temp; + maxSoFar = Math.max(maxSoFar, max); + } + return maxSoFar; + } + + private static int max(int a, int b, int c) { + return Math.max(a, Math.max(b, c)); + } + + private static int min(int a, int b, int c) { + return Math.min(a, Math.min(b, c)); + } +} From d2a16253f79ff73d1695462a2ceaa3933d101a48 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 22 Jun 2022 09:05:19 +0200 Subject: [PATCH 597/947] solves find min in rotated array --- README.md | 2 +- src/FindMinimumInRotatedSortedArray.java | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 src/FindMinimumInRotatedSortedArray.java diff --git a/README.md b/README.md index 331594b..e7abeb1 100644 --- a/README.md +++ b/README.md @@ -136,7 +136,7 @@ | 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) | | | +| 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) | | | diff --git a/src/FindMinimumInRotatedSortedArray.java b/src/FindMinimumInRotatedSortedArray.java new file mode 100644 index 0000000..7965aea --- /dev/null +++ b/src/FindMinimumInRotatedSortedArray.java @@ -0,0 +1,23 @@ +// https://leetcode.com/problems/find-minimum-in-rotated-sorted-array +// T: O(log(N)) +// 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; + } + + private boolean isRotated(int[] array) { + return array[0] > array[array.length - 1]; + } +} From 0d5fdb00a9dee77d62c98d1dec0c7ac44fca9ef9 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 22 Jun 2022 09:24:25 +0200 Subject: [PATCH 598/947] solves find peak element in java --- README.md | 2 +- src/FindPeakElement.java | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/FindPeakElement.java diff --git a/README.md b/README.md index e7abeb1..6798d16 100644 --- a/README.md +++ b/README.md @@ -143,7 +143,7 @@ | 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) | | | +| 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) | | | | 166 | [Fraction to Recurring Decimal](https://leetcode.com/problems/fraction-to-recurring-decimal) | | | | 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) | | diff --git a/src/FindPeakElement.java b/src/FindPeakElement.java new file mode 100644 index 0000000..57e2505 --- /dev/null +++ b/src/FindPeakElement.java @@ -0,0 +1,27 @@ +// https://leetcode.com/problems/find-peak-element +// T: O(log(N)) +// S: O(1) + +public class FindPeakElement { + public static int findPeakElement(int[] array) { + for (int left = 0, right = array.length - 1, middle ; left <= right ; ) { + middle = left + (right - left) / 2; + + if (isPeakElement(array, middle)) return middle; + + if (isOnIncreasingSlope(array, middle)) 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); + } +} From eea12629fc40d9bd239e9dc5cdd59e3416b25139 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 22 Jun 2022 09:39:32 +0200 Subject: [PATCH 599/947] solves compare version number --- README.md | 2 +- src/CompareVersionNumbers.java | 37 ++++++++++++++++++++++++++++++++++ src/HelloWorld.java | 4 +--- 3 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 src/CompareVersionNumbers.java diff --git a/README.md b/README.md index 6798d16..c2ab8a3 100644 --- a/README.md +++ b/README.md @@ -144,7 +144,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) | | -| 165 | [Compare Version Numbers](https://leetcode.com/problems/compare-version-numbers) | | | +| 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) | | | | 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) | | diff --git a/src/CompareVersionNumbers.java b/src/CompareVersionNumbers.java new file mode 100644 index 0000000..52ddbb5 --- /dev/null +++ b/src/CompareVersionNumbers.java @@ -0,0 +1,37 @@ +// https://leetcode.com/problems/compare-version-numbers +// T: O(|v1| + |v2|) +// S: O(v1 + v2) + +import java.util.ArrayList; +import java.util.List; + +public class CompareVersionNumbers { + public static int compareVersion(String version1, String version2) { + final List revisions1 = getRevisions(version1); + final List revisions2 = getRevisions(version2); + return compareVersion(revisions1, revisions2); + } + + public static int compareVersion(List version1, List version2) { + int length = Math.max(version1.size(), version2.size()); + for (int i = 0 ; i < length ; i++){ + if (get(version1, i) < get(version2, i)) return -1; + else if (get(version1, i) > get(version2, i)) return 1; + } + return 0; + } + + private static int get(List list, int index) { + if (index >= list.size()) return 0; + return list.get(index); + } + + private static List getRevisions(String version) { + final String[] revisions = version.split("\\."); + final List result = new ArrayList<>(); + for (String revision : revisions) { + result.add(Integer.parseInt(revision)); + } + return result; + } +} diff --git a/src/HelloWorld.java b/src/HelloWorld.java index bb829de..137cbbc 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -1,7 +1,5 @@ public class HelloWorld { public static void main(String[] args) { - System.out.println( - MaximumProductSubarray.maxProduct(new int[] {-4, -3, -2}) - ); + System.out.println(CompareVersionNumbers.compareVersion("0.1", "1.1")); } } From 45792d40e2b82ea2c372583267d85641f6e8b056 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 22 Jun 2022 09:55:49 +0200 Subject: [PATCH 600/947] solves fraction to decimal in leetcode --- README.md | 2 +- src/FractionToRecurringDecimal.java | 48 +++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 src/FractionToRecurringDecimal.java diff --git a/README.md b/README.md index c2ab8a3..0319722 100644 --- a/README.md +++ b/README.md @@ -145,7 +145,7 @@ | 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) | | | +| 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) | | diff --git a/src/FractionToRecurringDecimal.java b/src/FractionToRecurringDecimal.java new file mode 100644 index 0000000..ed861cb --- /dev/null +++ b/src/FractionToRecurringDecimal.java @@ -0,0 +1,48 @@ +// https://leetcode.com/problems/fraction-to-recurring-decimal +// T: O(log(n / d)) but not sure, could use some mathematician's help +// S: O(log(n / d)) + +import java.util.HashMap; +import java.util.Map; + +public class FractionToRecurringDecimal { + private static final String ZERO = "0"; + + public String fractionToDecimal(long numerator, long denominator) { + if (numerator == 0) return ZERO; + + StringBuilder result = new StringBuilder(); + result.append(isNegative(numerator, denominator) ? "-" : ""); + + numerator = Math.abs(numerator); + denominator = Math.abs(denominator); + + // integral part + result.append(numerator / denominator); + numerator %= denominator; + if (numerator == 0) return result.toString(); + + // fractional part + result.append("."); + Map map = new HashMap<>(); + map.put(numerator, result.length()); + + while (numerator != 0) { + numerator *= 10; + result.append(numerator / denominator); + numerator %= denominator; + if (map.containsKey(numerator)) { + int index = map.get(numerator); + result.insert(index, "("); + result.append(")"); + break; + } else map.put(numerator, result.length()); + } + + return result.toString(); + } + + private boolean isNegative(long numerator, long denominator) { + return (numerator > 0) ^ (denominator > 0); + } +} From 592c598cf17c797352c85edf8ab9e8e9ec5b417a Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 22 Jun 2022 10:10:07 +0200 Subject: [PATCH 601/947] solves bst iterator in java --- README.md | 2 +- src/BinarySearchTreeIterator.java | 34 +++++++++++++++++++++++++++++++ src/HelloWorld.java | 13 +++++++++++- 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 src/BinarySearchTreeIterator.java diff --git a/README.md b/README.md index 0319722..58abfa0 100644 --- a/README.md +++ b/README.md @@ -152,7 +152,7 @@ | 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) | | | +| 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) | | | | 187 | [Repeated DNA Sequences](https://leetcode.com/problems/repeated-dna-sequences) | | | | 189 | [Rotate Array](https://leetcode.com/problems/rotate-array) | [![Java](assets/java.png)](src/RotateArray.java) [![Python](assets/python.png)](python/rotate_array.py) | | diff --git a/src/BinarySearchTreeIterator.java b/src/BinarySearchTreeIterator.java new file mode 100644 index 0000000..69258cd --- /dev/null +++ b/src/BinarySearchTreeIterator.java @@ -0,0 +1,34 @@ +// https://leetcode.com/problems/binary-search-tree-iterator +// T: O(N) +// T(next): O(1) +// T(hasNext): O(1) +// S: O(log(N)) + +import java.util.Stack; + +public class BinarySearchTreeIterator { + + public static final class BSTIterator { + private final Stack stack = new Stack<>(); + + public BSTIterator(TreeNode root) { + addLeftNodesPathToStack(root); + } + + public int next() { + final TreeNode node = stack.pop(); + addLeftNodesPathToStack(node.right); + return node.val; + } + + public boolean hasNext() { + return !stack.isEmpty(); + } + + private void addLeftNodesPathToStack(TreeNode root) { + if (root == null) return; + stack.push(root); + addLeftNodesPathToStack(root.left); + } + } +} diff --git a/src/HelloWorld.java b/src/HelloWorld.java index 137cbbc..27a1f84 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -1,5 +1,16 @@ public class HelloWorld { public static void main(String[] args) { - System.out.println(CompareVersionNumbers.compareVersion("0.1", "1.1")); + TreeNode root = new TreeNode(7); + root.left = new TreeNode(3); + root.right = new TreeNode(15); + root.right.left = new TreeNode(9); + root.right.right = new TreeNode(20); + + TreePrinter.print(root); + + BinarySearchTreeIterator.BSTIterator iterator = new BinarySearchTreeIterator.BSTIterator(root); + while (iterator.hasNext()) { + System.out.println(iterator.next()); + } } } From 72f2d170ac252f3eac7467e927cece590441a091 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 22 Jun 2022 12:01:25 +0200 Subject: [PATCH 602/947] solves large number and repeated dna sequences in java --- README.md | 4 ++-- src/HelloWorld.java | 39 +++++++++++++++++++++++--------- src/LargestNumber.java | 38 +++++++++++++++++++++++++++++++ src/RepeatedDNASequences.java | 42 +++++++++++++++++++++++++++++++++++ src/TreeNode.java | 10 +++++++++ 5 files changed, 121 insertions(+), 12 deletions(-) create mode 100644 src/LargestNumber.java create mode 100644 src/RepeatedDNASequences.java diff --git a/README.md b/README.md index 58abfa0..b906289 100644 --- a/README.md +++ b/README.md @@ -153,8 +153,8 @@ | 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) | | | -| 187 | [Repeated DNA Sequences](https://leetcode.com/problems/repeated-dna-sequences) | | | +| 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) | | diff --git a/src/HelloWorld.java b/src/HelloWorld.java index 27a1f84..6987410 100644 --- a/src/HelloWorld.java +++ b/src/HelloWorld.java @@ -1,16 +1,35 @@ public class HelloWorld { public static void main(String[] args) { - TreeNode root = new TreeNode(7); - root.left = new TreeNode(3); - root.right = new TreeNode(15); - root.right.left = new TreeNode(9); - root.right.right = new TreeNode(20); + System.out.println( + LargestNumber.largestNumber(new int[] {1, 2, 3}) + ); - TreePrinter.print(root); + System.out.println( + LargestNumber.largestNumber(new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9}) + ); - BinarySearchTreeIterator.BSTIterator iterator = new BinarySearchTreeIterator.BSTIterator(root); - while (iterator.hasNext()) { - System.out.println(iterator.next()); - } + 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}) + ); + + System.out.println( + LargestNumber.largestNumber(new int[] {432, 43243}) + ); } } diff --git a/src/LargestNumber.java b/src/LargestNumber.java new file mode 100644 index 0000000..39debbb --- /dev/null +++ b/src/LargestNumber.java @@ -0,0 +1,38 @@ +// https://leetcode.com/problems/largest-number +// T: O(Nlog(N)) +// S: O(N) + +import java.util.ArrayList; +import java.util.List; + +public class LargestNumber { + private static final String ZERO = "0"; + + public static String largestNumber(int[] nums) { + final List numbers = convertToStrings(nums); + numbers.sort((s1, s2) -> { + final String order1 = s1 + s2; + final String order2 = s2 + s1; + return order2.compareTo(order1); + }); + + if (numbers.get(0).equals(ZERO)) return ZERO; + return combineStrings(numbers); + } + + private static String combineStrings(List numbers) { + final StringBuilder result = new StringBuilder(); + for (String string : numbers) { + result.append(string); + } + return result.toString(); + } + + private static List convertToStrings(int[] array) { + final List numbers = new ArrayList<>(); + for (int number : array) { + numbers.add(String.valueOf(number)); + } + return numbers; + } +} diff --git a/src/RepeatedDNASequences.java b/src/RepeatedDNASequences.java new file mode 100644 index 0000000..05d55f6 --- /dev/null +++ b/src/RepeatedDNASequences.java @@ -0,0 +1,42 @@ +// https://leetcode.com/problems/repeated-dna-sequences +// T: O(N) +// S: O(N) + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +public class RepeatedDNASequences { + private static final Map NUCLEOTIDES_TO_INT = Map.ofEntries( + Map.entry('A', 0), + Map.entry('C', 1), + Map.entry('G', 2), + Map.entry('T', 3) + ); + + public List findRepeatedDnaSequences(String s) { + final List dnaSequences = new ArrayList<>(); + final Set encodings = new HashSet<>(); + final Set repeatedEncodings = new HashSet<>(); + + for (int i = 0 ; i < s.length() - 9 ; i++) { + final int encoding = getSequenceEncoding(s, i); + if (!encodings.add(encoding) && repeatedEncodings.add(encoding)) { + dnaSequences.add(s.substring(i, i + 10)); + } + } + + return dnaSequences; + } + + private int getSequenceEncoding(String s, int index) { + int encoding = 0; + for (int i = index ; i < index + 10 ; i++) { + encoding <<= 2; + encoding |= NUCLEOTIDES_TO_INT.get(s.charAt(i)); + } + return encoding; + } +} diff --git a/src/TreeNode.java b/src/TreeNode.java index 8f1a19d..d8a3798 100644 --- a/src/TreeNode.java +++ b/src/TreeNode.java @@ -4,6 +4,16 @@ public class TreeNode implements TreePrinter.PrintableNode { TreeNode right; TreeNode() {} + public static final TreeNode EXAMPLE_1; + + static { + EXAMPLE_1 = new TreeNode(7); + EXAMPLE_1.left = new TreeNode(3); + EXAMPLE_1.right = new TreeNode(15); + EXAMPLE_1.right.left = new TreeNode(9); + EXAMPLE_1.right.right = new TreeNode(20); + } + TreeNode(int val) { this.val = val; } From 093ed78ea736f853611a098a22d824a9b033a27d Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 22 Jun 2022 14:10:52 +0200 Subject: [PATCH 603/947] solves bitwise and ofnumbers range --- README.md | 2 +- src/BitwiseANDOfNumbersRange.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/BitwiseANDOfNumbersRange.java diff --git a/README.md b/README.md index b906289..6debbdd 100644 --- a/README.md +++ b/README.md @@ -161,7 +161,7 @@ | 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) | | -| 201 | [Bitwise AND of Numbers Range](https://leetcode.com/problems/bitwise-and-of-numbers-range) | | | +| 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) | | diff --git a/src/BitwiseANDOfNumbersRange.java b/src/BitwiseANDOfNumbersRange.java new file mode 100644 index 0000000..3dfef1b --- /dev/null +++ b/src/BitwiseANDOfNumbersRange.java @@ -0,0 +1,16 @@ +// https://leetcode.com/problems/bitwise-and-of-numbers-range +// T: O(log(left)) +// S: O(1) + +public class BitwiseANDOfNumbersRange { + public int rangeBitwiseAnd(int left, int right) { + int moveFactor = 0; + while(left != right){ + left >>= 1; + right >>= 1; + moveFactor++; + } + + return left << moveFactor; + } +} From 0371e704c168543e0afe11b2341952f013e1b207 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 22 Jun 2022 14:20:08 +0200 Subject: [PATCH 604/947] solves min size subarray sum in java --- README.md | 2 +- src/MinimumSizeSubarraySum.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/MinimumSizeSubarraySum.java diff --git a/README.md b/README.md index 6debbdd..100bebc 100644 --- a/README.md +++ b/README.md @@ -169,7 +169,7 @@ | 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) | | -| 209 | [Minimum Size Subarray Sum](https://leetcode.com/problems/minimum-size-subarray-sum) | | | +| 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) | | | | 211 | [Design Add and Search Words Data Structure](https://leetcode.com/problems/design-add-and-search-words-data-structure) | | | | 213 | [House Robber II](https://leetcode.com/problems/house-robber-ii) | | | diff --git a/src/MinimumSizeSubarraySum.java b/src/MinimumSizeSubarraySum.java new file mode 100644 index 0000000..8a79679 --- /dev/null +++ b/src/MinimumSizeSubarraySum.java @@ -0,0 +1,17 @@ +// https://leetcode.com/problems/minimum-size-subarray-sum +// T: O(N) +// S: O(1) + +public class MinimumSizeSubarraySum { + public int minSubArrayLen(int target, int[] array) { + int minSize = Integer.MAX_VALUE; + for (int left = 0, right = 0, sum = 0 ; right < array.length ; right++) { + sum += array[right]; + while (sum >= target) { + minSize = Math.min(minSize, right - left + 1); + sum -= array[left++]; + } + } + return minSize == Integer.MAX_VALUE ? 0 : minSize; + } +} From af921bd7aa3d526dc4a0c34c6f5e637c9c6274e6 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 22 Jun 2022 14:56:32 +0200 Subject: [PATCH 605/947] solves course schedule ii --- README.md | 2 +- src/CourseScheduleII.java | 101 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 src/CourseScheduleII.java diff --git a/README.md b/README.md index 100bebc..c029c96 100644 --- a/README.md +++ b/README.md @@ -170,7 +170,7 @@ | 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) | | | 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) | | | +| 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) | | | | 213 | [House Robber II](https://leetcode.com/problems/house-robber-ii) | | | | 215 | [Kth Largest Element in an Array](https://leetcode.com/problems/kth-largest-element-in-an-array) | [![Java](assets/java.png)](src/KthLargestElementInAnArray.java) | | diff --git a/src/CourseScheduleII.java b/src/CourseScheduleII.java new file mode 100644 index 0000000..2a76d56 --- /dev/null +++ b/src/CourseScheduleII.java @@ -0,0 +1,101 @@ +// https://leetcode.com/problems/course-schedule-ii +// T: O(V + E) --> O(numCourses + |preReq|) +// S: O(V + E) --> O(numCourses + |preReq|) + +import java.util.ArrayList; +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 CourseScheduleII { + private static final class Vertex { + private final int data; + private final Set edges = new HashSet<>(); + private int outDegree = 0; + + Vertex(int data) { + this.data = data; + } + + private void addEdge(Edge edge) { + edges.add(edge); + if (edge.from == this) outDegree++; + } + + private void removeEdge(Edge edge) { + edges.remove(edge); + if (edge.from == this) outDegree--; + } + + private boolean hasDependency() { + return outDegree > 0; + } + } + + private record Edge(Vertex from, Vertex to) { } + + public int[] findOrder(int numCourses, int[][] prerequisites) { + final Map graph = createGraphWithNVertices(numCourses); + mapPrerequisitesInGraph(graph, prerequisites); + List topologicalOrder = topologicalSort(graph); + return topologicalOrder.size() == numCourses ? toArray(topologicalOrder) : new int[] { }; + } + + private List topologicalSort(Map graph) { + final Queue queue = zeroDependencyVertices(graph); + final List order = new ArrayList<>(); + + while (!queue.isEmpty()) { + Vertex vertex = queue.poll(); + order.add(vertex.data); + for (Edge edge : vertex.edges) { + edge.from.removeEdge(edge); + if (!edge.from.hasDependency()) { + queue.add(edge.from); + } + } + } + + return order; + } + + private Queue zeroDependencyVertices(Map graph) { + final Queue queue = new LinkedList<>(); + for (Vertex vertex : graph.values()) { + if (!vertex.hasDependency()) { + queue.add(vertex); + } + } + return queue; + } + + private void mapPrerequisitesInGraph(Map graph, int[][] prerequisites) { + for (int[] preRequisite : prerequisites) { + Vertex from = graph.get(preRequisite[0]); + Vertex to = graph.get(preRequisite[1]); + Edge edge = new Edge(from, to); + from.addEdge(edge); + to.addEdge(edge); + } + } + + private Map createGraphWithNVertices(int n) { + final Map graph = new HashMap<>(); + for (int i = 0 ; i < n ; i++) { + graph.put(i, new Vertex(i)); + } + return graph; + } + + private 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; + } +} From 32a62a12d8e0e99b550dfb7237d9ba45df64bec8 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 22 Jun 2022 15:27:19 +0200 Subject: [PATCH 606/947] solves design and add search words data structure --- README.md | 2 +- src/DesignAddAndSearchWordsDataStructure.java | 81 +++++++++++++++++++ 2 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 src/DesignAddAndSearchWordsDataStructure.java diff --git a/README.md b/README.md index c029c96..8f3cc45 100644 --- a/README.md +++ b/README.md @@ -171,7 +171,7 @@ | 208 | [Implement Trie (Prefix Tree)](https://leetcode.com/problems/implement-trie-prefix-tree) | [![Java](assets/java.png)](src/Trie.java) | | | 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) | | | +| 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) | | | 213 | [House Robber II](https://leetcode.com/problems/house-robber-ii) | | | | 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) | | | diff --git a/src/DesignAddAndSearchWordsDataStructure.java b/src/DesignAddAndSearchWordsDataStructure.java new file mode 100644 index 0000000..8c35fc4 --- /dev/null +++ b/src/DesignAddAndSearchWordsDataStructure.java @@ -0,0 +1,81 @@ +// https://leetcode.com/problems/design-add-and-search-words-data-structure +// S: O(sum |word|_i) +/* + trie.add(String word) + T: O(word) + + trie.contains(String word) + T: O(26^3 * word) = O(k * word) = O(word) + */ +/* + word_dict.addWord(String word) + T: O(word) + + word_dict.search(String word) + T: O(word) + */ + +import java.util.HashSet; +import java.util.Set; + +public class DesignAddAndSearchWordsDataStructure { + private static final class WordDictionary { + + private final Trie trie = new Trie(); + private final Set words = new HashSet<>(); + + public void addWord(String word) { + words.add(word); + trie.add(word); + } + + public boolean search(String word) { + if (!containsDots(word)) return words.contains(word); + return trie.contains(word); + } + + private boolean containsDots(String word) { + for (int i = 0 ; i < word.length() ; i++) { + if (word.charAt(i) == '.') return true; + } + return false; + } + } + + private static final class Trie { + final Trie[] children = new Trie[26]; + boolean isWord = false; + + public void add(String s) { + add(s, 0); + } + + private void add(String s, int index) { + if (index == s.length()) { + isWord = true; + return; + } + char c = s.charAt(index); + if (children[c - 'a'] == null) children[c - 'a'] = new Trie(); + children[c - 'a'].add(s, index + 1); + } + + public boolean contains(String s) { + return contains(s, 0); + } + + private boolean contains(String s, int index) { + if (index == s.length()) return isWord; + char character = s.charAt(index); + if (character != '.') { + return children[character - 'a'] != null && children[character - 'a'].contains(s, index + 1); + } + for (Trie child : children) { + if (child != null && child.contains(s, index + 1)) { + return true; + } + } + return false; + } + } +} From c1734a1c48ffaad7d2dfc87bdf9cae493fd5bc45 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 22 Jun 2022 16:19:36 +0200 Subject: [PATCH 607/947] solves house robber ii --- README.md | 2 +- src/HouseRobberII.java | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/HouseRobberII.java diff --git a/README.md b/README.md index 8f3cc45..dbc015d 100644 --- a/README.md +++ b/README.md @@ -172,7 +172,7 @@ | 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) | | -| 213 | [House Robber II](https://leetcode.com/problems/house-robber-ii) | | | +| 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) | | | | 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate) | [![Java](assets/java.png)](src/ContainsDuplicate.java) [![Python](assets/python.png)](python/contains_duplicate.py) | | diff --git a/src/HouseRobberII.java b/src/HouseRobberII.java new file mode 100644 index 0000000..d00072a --- /dev/null +++ b/src/HouseRobberII.java @@ -0,0 +1,25 @@ +// https://leetcode.com/problems/house-robber-ii +// T: O(N) +// S: O(1) + +public class HouseRobberII { + public int rob(int[] array) { + if (array.length == 1) return array[0]; + if (array.length == 2) return Math.max(array[0], array[1]); + + return Math.max( + rob(array, 0, array.length - 2), + rob(array, 1, array.length - 1) + ); + } + + public int rob(int[] array, int start, int end) { + int a = array[start], b = Math.max(array[start], array[start + 1]), c = Math.max(a, b); + for (int i = start + 2 ; i <= end ; i++) { + c = Math.max(array[i] + a, b); + a = b; + b = c; + } + return c; + } +} From 74f637d5d514f6dc8a899e7bb571e3efa68a83ee Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Wed, 22 Jun 2022 16:45:11 +0200 Subject: [PATCH 608/947] solves combination iii in java --- README.md | 2 +- src/CombinationSumIII.java | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/CombinationSumIII.java diff --git a/README.md b/README.md index dbc015d..04701df 100644 --- a/README.md +++ b/README.md @@ -174,7 +174,7 @@ | 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) | | | 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) | | | +| 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) | | | 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) | | | diff --git a/src/CombinationSumIII.java b/src/CombinationSumIII.java new file mode 100644 index 0000000..5854615 --- /dev/null +++ b/src/CombinationSumIII.java @@ -0,0 +1,37 @@ +// https://leetcode.com/problems/combination-sum-iii +// T: O(9^k) +// S: O(k) + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +public class CombinationSumIII { + private final List> result = new ArrayList<>(); + private int sum; + + public List> combinationSum3(int k, int n) { + sum = n; + combinationSum(1, Math.min(sum / 2, 9), 0, k - 1, new LinkedList<>()); + return result; + } + + private void combinationSum(int start, int end, int currentSum, int k, LinkedList current) { + if (k == 0) { + if (currentSum < sum && sum - currentSum >= start && sum - currentSum <= 9) { + current.add(sum - currentSum); + result.add(new ArrayList<>(current)); + current.pollLast(); + } + return; + } + + for (int i = start ; i <= end ; i++) { + current.add(i); + currentSum += i; + combinationSum(i + 1, Math.min((sum - currentSum) / 2, 9), currentSum, k - 1, current); + currentSum -= i; + current.pollLast(); + } + } +} From 206d3819eafe83cf903a1203b9db0af75b94a8f7 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 23 Jun 2022 09:24:13 +0200 Subject: [PATCH 609/947] solves contains duplicate iii in java --- src/ContainsDuplicateIII.java | 51 +++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/ContainsDuplicateIII.java diff --git a/src/ContainsDuplicateIII.java b/src/ContainsDuplicateIII.java new file mode 100644 index 0000000..b2d5be7 --- /dev/null +++ b/src/ContainsDuplicateIII.java @@ -0,0 +1,51 @@ +import java.util.TreeMap; + +public class ContainsDuplicateIII { + + public boolean containsNearbyAlmostDuplicate(int[] array, int k, int t) { + // no memory + if (k == 0) return false; + + final TreeMap elements = new TreeMap<>(); + for (int i = 0 ; i < array.length ; i++) { + long lowerBound = (long) array[i] - t; + long upperBound = (long) array[i] + t; + long lowerClosest = getClosestOrHigher(elements, lowerBound); + if (inRange(lowerClosest, lowerBound, upperBound)) return true; + long upperClosest = getClosestOrLower(elements, upperBound); + if (inRange(upperClosest, lowerBound, upperBound)) return true; + if (i >= k) { + removeFromMap(elements, array[i - k]); + } + addToMap(elements, array[i]); + } + + return false; + } + + private void removeFromMap(TreeMap elements, long val) { + if (elements.get(val) == 1) { + elements.remove(val); + } else { + elements.put(val, elements.get(val) - 1); + } + } + + private void addToMap(TreeMap elements, long val) { + elements.put(val, elements.getOrDefault(val, 0) + 1); + } + + private long getClosestOrHigher(TreeMap elements, long val) { + Long lowerClosest = elements.ceilingKey(val); + return lowerClosest == null ? Long.MAX_VALUE : lowerClosest; + } + + private long getClosestOrLower(TreeMap elements, long val) { + Long upperClosest = elements.floorKey(val); + return upperClosest == null ? Long.MIN_VALUE : upperClosest; + } + + private boolean inRange(long val, long low, long high) { + return low <= val && val <= high; + } +} From 88cdd6b5950963fa1766404e8706759eb255e376 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 23 Jun 2022 09:27:14 +0200 Subject: [PATCH 610/947] solves contains duplicate iii in java --- README.md | 2 +- src/ContainsDuplicateIII.java | 65 +++++++++++++---------------------- 2 files changed, 25 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 04701df..53e5368 100644 --- a/README.md +++ b/README.md @@ -177,7 +177,7 @@ | 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) | | | 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) | | | +| 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) | | | | 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) | | | diff --git a/src/ContainsDuplicateIII.java b/src/ContainsDuplicateIII.java index b2d5be7..1acbb60 100644 --- a/src/ContainsDuplicateIII.java +++ b/src/ContainsDuplicateIII.java @@ -1,51 +1,34 @@ -import java.util.TreeMap; +// https://leetcode.com/problems/contains-duplicate-iii +// T: O(N) +// S: O(N) + +import java.util.HashMap; +import java.util.Map; public class ContainsDuplicateIII { - public boolean containsNearbyAlmostDuplicate(int[] array, int k, int t) { - // no memory + private long getID(long i, long w) { + return i < 0 ? (i + 1) / w - 1 : i / w; + } + + public boolean containsNearbyAlmostDuplicate(int[] nums, int k, int t) { if (k == 0) return false; - final TreeMap elements = new TreeMap<>(); - for (int i = 0 ; i < array.length ; i++) { - long lowerBound = (long) array[i] - t; - long upperBound = (long) array[i] + t; - long lowerClosest = getClosestOrHigher(elements, lowerBound); - if (inRange(lowerClosest, lowerBound, upperBound)) return true; - long upperClosest = getClosestOrLower(elements, upperBound); - if (inRange(upperClosest, lowerBound, upperBound)) return true; - if (i >= k) { - removeFromMap(elements, array[i - k]); - } - addToMap(elements, array[i]); + final Map buckets = new HashMap<>(); + final long w = (long) t + 1; + + for (int i = 0; i < nums.length; ++i) { + long m = getID(nums[i], w); + if (buckets.containsKey(m)) + return true; + if (buckets.containsKey(m - 1) && Math.abs(nums[i] - buckets.get(m - 1)) < w) + return true; + if (buckets.containsKey(m + 1) && Math.abs(nums[i] - buckets.get(m + 1)) < w) + return true; + buckets.put(m, (long)nums[i]); + if (i >= k) buckets.remove(getID(nums[i - k], w)); } return false; } - - private void removeFromMap(TreeMap elements, long val) { - if (elements.get(val) == 1) { - elements.remove(val); - } else { - elements.put(val, elements.get(val) - 1); - } - } - - private void addToMap(TreeMap elements, long val) { - elements.put(val, elements.getOrDefault(val, 0) + 1); - } - - private long getClosestOrHigher(TreeMap elements, long val) { - Long lowerClosest = elements.ceilingKey(val); - return lowerClosest == null ? Long.MAX_VALUE : lowerClosest; - } - - private long getClosestOrLower(TreeMap elements, long val) { - Long upperClosest = elements.floorKey(val); - return upperClosest == null ? Long.MIN_VALUE : upperClosest; - } - - private boolean inRange(long val, long low, long high) { - return low <= val && val <= high; - } } From db3a9de2935cee5dddc5257f037a9a7418b76945 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 23 Jun 2022 09:52:09 +0200 Subject: [PATCH 611/947] solves contains duplicate iii in java --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 53e5368..41cf0e4 100644 --- a/README.md +++ b/README.md @@ -177,7 +177,7 @@ | 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) | | | 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) | | +| 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) | | | | 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) | | | From 4c7b5300651060234ad37815f6c526d424346c4f Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 23 Jun 2022 10:04:22 +0200 Subject: [PATCH 612/947] solves maximal square in java --- src/MaximalSquare.java | 64 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/MaximalSquare.java diff --git a/src/MaximalSquare.java b/src/MaximalSquare.java new file mode 100644 index 0000000..a9d82c2 --- /dev/null +++ b/src/MaximalSquare.java @@ -0,0 +1,64 @@ +// https://leetcode.com/problems/maximal-square +// T: O(m * n) +// S: O(m * n) + +public class MaximalSquare { + public int maximalSquare(char[][] matrix) { + final int rows = matrix.length, columns = matrix[0].length; + final int[][] dp = new int[rows][columns]; + + assignFirstRowInDPMatrix(dp, matrix); + assignFirstColumnInDPMatrix(dp, matrix); + + int maxSideLen = contains1(dp) ? 1 : 0; + + for (int row = 1 ; row < rows ; row++) { + for (int column = 1 ; column < columns ; column++) { + if (isOne(matrix[row][column])) { + dp[row][column] = min(dp[row - 1][column], dp[row][column - 1], dp[row - 1][column - 1]) + 1; + } else dp[row][column] = 0; + maxSideLen = Math.max(maxSideLen, dp[row][column]); + } + } + + return maxSideLen * maxSideLen; + } + + private boolean contains1(int[][] dp) { + return contains1InFirstRow(dp) || contains1InFirstColumn(dp); + } + + private boolean contains1InFirstRow(int[][] dp) { + for (int element : dp[0]) { + if (element == 1) return true; + } + return false; + } + + private boolean contains1InFirstColumn(int[][] dp) { + for (int[] row : dp) { + if (row[0] == 1) return true; + } + return false; + } + + private boolean isOne(char character) { + return character == '1'; + } + + private int min(int a, int b, int c) { + return Math.min(a, Math.min(b, c)); + } + + private void assignFirstRowInDPMatrix(int[][] dp, char[][] matrix) { + for (int column = 0 ; column < matrix[0].length ; column++) { + dp[0][column] = matrix[0][column] - '0'; + } + } + + private void assignFirstColumnInDPMatrix(int[][] dp, char[][] matrix) { + for (int row = 0 ; row < matrix.length ; row++) { + dp[row][0] = matrix[row][0] - '0'; + } + } +} From 0e26fc4daabf37c994a8bfda6744a6ac3321c279 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 23 Jun 2022 10:12:42 +0200 Subject: [PATCH 613/947] solves maximal square in java --- README.md | 2 +- src/MaximalSquare.java | 64 +++++++++++------------------------------- 2 files changed, 17 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index 41cf0e4..a9ac624 100644 --- a/README.md +++ b/README.md @@ -178,7 +178,7 @@ | 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate) | [![Java](assets/java.png)](src/ContainsDuplicate.java) [![Python](assets/python.png)](python/contains_duplicate.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) | | | +| 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) | | | | 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) | | diff --git a/src/MaximalSquare.java b/src/MaximalSquare.java index a9d82c2..df44fe3 100644 --- a/src/MaximalSquare.java +++ b/src/MaximalSquare.java @@ -1,64 +1,32 @@ // https://leetcode.com/problems/maximal-square // T: O(m * n) -// S: O(m * n) +// S: O(n) public class MaximalSquare { public int maximalSquare(char[][] matrix) { - final int rows = matrix.length, columns = matrix[0].length; - final int[][] dp = new int[rows][columns]; - - assignFirstRowInDPMatrix(dp, matrix); - assignFirstColumnInDPMatrix(dp, matrix); - - int maxSideLen = contains1(dp) ? 1 : 0; - - for (int row = 1 ; row < rows ; row++) { - for (int column = 1 ; column < columns ; column++) { - if (isOne(matrix[row][column])) { - dp[row][column] = min(dp[row - 1][column], dp[row][column - 1], dp[row - 1][column - 1]) + 1; - } else dp[row][column] = 0; - maxSideLen = Math.max(maxSideLen, dp[row][column]); + final int columns = matrix[0].length; + final int[] dp = new int[columns + 1]; + int maxSideLength = 0, prev = 0, temp; + + for (char[] row : matrix) { + for (int column = 0; column < columns; column++) { + temp = dp[column + 1]; + if (isOne(row[column])) { + dp[column + 1] = min(dp[column + 1], dp[column], prev) + 1; + } else dp[column + 1] = 0; + maxSideLength = Math.max(maxSideLength, dp[column + 1]); + prev = temp; } } - return maxSideLen * maxSideLen; - } - - private boolean contains1(int[][] dp) { - return contains1InFirstRow(dp) || contains1InFirstColumn(dp); - } - - private boolean contains1InFirstRow(int[][] dp) { - for (int element : dp[0]) { - if (element == 1) return true; - } - return false; - } - - private boolean contains1InFirstColumn(int[][] dp) { - for (int[] row : dp) { - if (row[0] == 1) return true; - } - return false; - } - - private boolean isOne(char character) { - return character == '1'; + return maxSideLength * maxSideLength; } private int min(int a, int b, int c) { return Math.min(a, Math.min(b, c)); } - private void assignFirstRowInDPMatrix(int[][] dp, char[][] matrix) { - for (int column = 0 ; column < matrix[0].length ; column++) { - dp[0][column] = matrix[0][column] - '0'; - } - } - - private void assignFirstColumnInDPMatrix(int[][] dp, char[][] matrix) { - for (int row = 0 ; row < matrix.length ; row++) { - dp[row][0] = matrix[row][0] - '0'; - } + private boolean isOne(char c) { + return c == '1'; } } From 52a3060fefe10859d02dab44c64afca7fe274124 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 23 Jun 2022 11:32:32 +0200 Subject: [PATCH 614/947] solves rectangle area in java --- README.md | 2 +- src/RectangleArea.java | 49 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 src/RectangleArea.java diff --git a/README.md b/README.md index a9ac624..ab2c61e 100644 --- a/README.md +++ b/README.md @@ -180,7 +180,7 @@ | 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) | | | +| 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) | | | 228 | [Basic Calculator II](https://leetcode.com/problems/basic-calculator-ii) | | | diff --git a/src/RectangleArea.java b/src/RectangleArea.java new file mode 100644 index 0000000..d9fb13a --- /dev/null +++ b/src/RectangleArea.java @@ -0,0 +1,49 @@ +// https://leetcode.com/problems/rectangle-area +// T: O(1) +// S: O(1) + +public class RectangleArea { + private record Point(int x, int y) {} + + private static class Rectangle { + public final int xl; + public final int xr; + public final int yb; + public final int yt; + public final int area; + + Rectangle(Point lowerLeft, Point upperRight) { + xl = lowerLeft.x; + xr = upperRight.x; + yb = lowerLeft.y; + yt = upperRight.y; + area = (upperRight.x - lowerLeft.x) * (upperRight.y - lowerLeft.y); + } + + public static Rectangle from(int x1, int y1, int x2, int y2) { + final Point a1 = new Point(x1, y1); + final Point a2 = new Point(x2, y2); + return new Rectangle(a1, a2); + } + + public Rectangle intersection(Rectangle other) { + final int intersectionXl = Math.max(xl, other.xl); + final int intersectionXr = Math.max(intersectionXl, Math.min(xr, other.xr)); + final int intersectionYb = Math.max(yb, other.yb); + final int intersectionYt = Math.max(intersectionYb, Math.min(yt, other.yt)); + + if (intersectionXl > intersectionXr || intersectionYb > intersectionYt) { + return null; + } + + return Rectangle.from(intersectionXl, intersectionYb, intersectionXr, intersectionYt); + } + } + + public static int computeArea(int ax1, int ay1, int ax2, int ay2, int bx1, int by1, int bx2, int by2) { + final Rectangle rectangle1 = Rectangle.from(ax1, ay1, ax2, ay2); + final Rectangle rectangle2 = Rectangle.from(bx1, by1, bx2, by2); + final Rectangle intersection = rectangle1.intersection(rectangle2); + return rectangle1.area + rectangle2.area - (intersection == null ? 0 : intersection.area); + } +} From af9661e32ec563f265f49dec937bebdf8ab6b70d Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Thu, 23 Jun 2022 12:00:19 +0200 Subject: [PATCH 615/947] solves basic calcuator ii in java --- README.md | 2 +- src/BasicCalculatorII.java | 88 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 src/BasicCalculatorII.java diff --git a/README.md b/README.md index ab2c61e..bcf3efd 100644 --- a/README.md +++ b/README.md @@ -183,7 +183,7 @@ | 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) | | -| 228 | [Basic Calculator II](https://leetcode.com/problems/basic-calculator-ii) | | | +| 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) | | | | 230 | [Kth Smallest Element in a BST](https://leetcode.com/problems/kth-smallest-element-in-a-bst) | | | | 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) | | diff --git a/src/BasicCalculatorII.java b/src/BasicCalculatorII.java new file mode 100644 index 0000000..2751f13 --- /dev/null +++ b/src/BasicCalculatorII.java @@ -0,0 +1,88 @@ +// https://leetcode.com/problems/basic-calculator-ii +// extremely innovative approach, using a grammar to evaluate expressions +// T: O(N) +// S: O(1) + +import java.util.Set; + +public class BasicCalculatorII { + private static final char ADDITION = '+'; + private static final char SUBTRACTION = '-'; + private static final char MULTIPLICATION = '*'; + private static final char DIVISION = '/'; + private static final char SPACE = ' '; + + private static final Set ADDITIVE_OPERATORS = Set.of(ADDITION, SUBTRACTION); + private static final Set MULTIPLICATIVE_OPERATORS = Set.of(MULTIPLICATION, DIVISION); + + private String expression; + private int index; + + public int calculate(String s) { + this.expression = s; + this.index = 0; + return addition(); + } + + private int addition() { + int sum = multiplication(); + while (index < expression.length() && isAdditiveOperator(expression.charAt(index))) { + char operator = expression.charAt(index++); + sum = applyOperator(sum, multiplication(), operator); + } + return sum; + } + + private int multiplication() { + int result = toNumber(); + while (index < expression.length() && isMultiplicativeOperator(expression.charAt(index))) { + char operator = expression.charAt(index++); + result = applyOperator(result, toNumber(), operator); + } + return result; + } + + private int toNumber() { + int number = 0; + while (index < expression.length() && isDigitOrSpace(expression.charAt(index))) { + if (isSpace(expression.charAt(index))) { + index++; + continue; + } + number *= 10; + number += toDigit(expression.charAt(index)); + index++; + } + return number; + } + + private int toDigit(char digit) { + return digit - '0'; + } + + private boolean isDigitOrSpace(char c) { + return Character.isDigit(c) || isSpace(c); + } + + private boolean isSpace(char c) { + return c == SPACE; + } + + private int applyOperator(int a, int b, char operator) { + return switch (operator) { + case ADDITION -> a + b; + case SUBTRACTION -> a - b; + case MULTIPLICATION -> a * b; + case DIVISION -> a / b; + default -> throw new IllegalStateException("Unexpected value: " + operator); + }; + } + + private boolean isAdditiveOperator(char operator) { + return ADDITIVE_OPERATORS.contains(operator); + } + + private boolean isMultiplicativeOperator(char operator) { + return MULTIPLICATIVE_OPERATORS.contains(operator); + } +} From ea80d1e10140a77bfd0a863552a36c6d3b567d46 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 24 Jun 2022 09:09:21 +0200 Subject: [PATCH 616/947] solves majority element in java --- src/MajorityElement.java | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/src/MajorityElement.java b/src/MajorityElement.java index ee47435..ee63039 100644 --- a/src/MajorityElement.java +++ b/src/MajorityElement.java @@ -1,24 +1,20 @@ -import java.util.HashMap; -import java.util.Map; +// https://leetcode.com/problems/majority-element +// T: O(N) +// S: O(1) public class MajorityElement { - public int majorityElement(int[] array) { - Map frequencies = getFrequencies(array); - int maxFrequency = frequencies.values().stream().max(Integer::compareTo).get(); - for (Map.Entry entry : frequencies.entrySet()) { - if (entry.getValue() == maxFrequency) { - return entry.getKey(); - } - } + public int majorityElement(int[] nums) { + int candidate = nums[0], frequency = 0; - return -1; - } + for (int element : nums) { + frequency += element == candidate ? 1 : -1; - private static Map getFrequencies(int[] array) { - Map result = new HashMap<>(); - for (int element : array) { - result.put(element, result.getOrDefault(element, 0) + 1); + if (frequency == 0) { + candidate = element; + frequency = 1; + } } - return result; + + return candidate; } } From 50318bd2f5d9b2bf1e8a1c29cc32df7e84c1d459 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 24 Jun 2022 09:26:58 +0200 Subject: [PATCH 617/947] solves majority element ii in java --- README.md | 2 +- src/MajorityElementII.java | 42 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 src/MajorityElementII.java diff --git a/README.md b/README.md index bcf3efd..9063b1c 100644 --- a/README.md +++ b/README.md @@ -184,7 +184,7 @@ | 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) | | | +| 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) | | | | 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) | | diff --git a/src/MajorityElementII.java b/src/MajorityElementII.java new file mode 100644 index 0000000..26664fb --- /dev/null +++ b/src/MajorityElementII.java @@ -0,0 +1,42 @@ +// https://leetcode.com/problems/majority-element-ii +// T: O(N) +// S: O(1) + +import java.util.ArrayList; +import java.util.List; + +public class MajorityElementII { + public List majorityElement(int[] nums) { + int candidate1 = 0, candidate2 = 0, frequency1 = 0, frequency2 = 0; + for (int element : nums) { + if (element == candidate1) frequency1++; + else if (element == candidate2) frequency2++; + else if (frequency1 == 0) { + candidate1 = element; + frequency1 = 1; + } else if (frequency2 == 0) { + candidate2 = element; + frequency2 = 1; + } else { + frequency1--; + frequency2--; + } + } + return confirmCandidates(nums, candidate1, candidate2); + } + + private List confirmCandidates(int[] array, int candidate1, int candidate2) { + final List result = new ArrayList<>(); + if (frequency(array, candidate1) > array.length / 3) result.add(candidate1); + if (candidate2 != candidate1 && frequency(array, candidate2) > array.length / 3) result.add(candidate2); + return result; + } + + private int frequency(int[] array, int val) { + int count = 0; + for (int element : array) { + if (element == val) count++; + } + return count; + } +} From 2bd9edd5f3f7c1ecb1461a759aa3ba9c21095f41 Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Fri, 24 Jun 2022 09:27:53 +0200 Subject: [PATCH 618/947] updates stats --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9063b1c..48690a2 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LeetCode Algorithms -![problems-solved](https://img.shields.io/badge/Problems%20Solved-509/2081-1f425f.svg) -![problems-solved-java](https://img.shields.io/badge/Java-509/2081-1abc9c.svg) +![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) [![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 43ebf2352dfabae76f4e514a7826d1d6ca585d6c Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 27 Jun 2022 16:01:07 +0200 Subject: [PATCH 619/947] solves kth largest element in bst --- README.md | 2 +- src/KthSmallestElementInABST.java | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/KthSmallestElementInABST.java diff --git a/README.md b/README.md index 48690a2..75a803e 100644 --- a/README.md +++ b/README.md @@ -185,7 +185,7 @@ | 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) | | | +| 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) | | diff --git a/src/KthSmallestElementInABST.java b/src/KthSmallestElementInABST.java new file mode 100644 index 0000000..616f928 --- /dev/null +++ b/src/KthSmallestElementInABST.java @@ -0,0 +1,27 @@ +// https://leetcode.com/problems/kth-smallest-element-in-a-bst +// T: O(k + log(N)) +// S: O(log(N)) + +import java.util.Stack; + +public class KthSmallestElementInABST { + public int kthSmallest(TreeNode root, int k) { + final Stack stack = new Stack<>(); + addLeftPathToStack(root, stack); + + for (int count = 0 ; !stack.isEmpty() ; ) { + final TreeNode current = stack.pop(); + count++; + if (count == k) return current.val; + addLeftPathToStack(current.right, stack); + } + + return -1; + } + + private void addLeftPathToStack(TreeNode root, Stack stack) { + if (root == null) return; + stack.push(root); + addLeftPathToStack(root.left, stack); + } +} From e3dd2de9443111c3092ced5c554ace2685e8c812 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 27 Jun 2022 16:20:12 +0200 Subject: [PATCH 620/947] solves lowest common ancestor of binary tree --- README.md | 2 +- src/LowestCommonAncestorOfBinaryTree.java | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/LowestCommonAncestorOfBinaryTree.java diff --git a/README.md b/README.md index 75a803e..e2c9fc1 100644 --- a/README.md +++ b/README.md @@ -190,7 +190,7 @@ | 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) | | | +| 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) | | | | 240 | [Search a 2D Matrix II](https://leetcode.com/problems/search-a-2d-matrix-ii) | | | diff --git a/src/LowestCommonAncestorOfBinaryTree.java b/src/LowestCommonAncestorOfBinaryTree.java new file mode 100644 index 0000000..3bfd075 --- /dev/null +++ b/src/LowestCommonAncestorOfBinaryTree.java @@ -0,0 +1,13 @@ +// https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree +// T: O(N) +// S: O(log(N)) + +public class LowestCommonAncestorOfBinaryTree { + public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { + if (root == null || root == p || root == q) return root; + TreeNode left = lowestCommonAncestor(root.left, p, q); + TreeNode right = lowestCommonAncestor(root.right, p, q); + if (left != null && right != null) return root; + return left == null ? right : left; + } +} From 180ce562d80e1c0dab0111410e8e549c7a7eefc5 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 27 Jun 2022 17:01:03 +0200 Subject: [PATCH 621/947] solves product of array except itself in java --- src/ProductOfArrayExceptItself.java | 37 +++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/ProductOfArrayExceptItself.java diff --git a/src/ProductOfArrayExceptItself.java b/src/ProductOfArrayExceptItself.java new file mode 100644 index 0000000..6c001d2 --- /dev/null +++ b/src/ProductOfArrayExceptItself.java @@ -0,0 +1,37 @@ +// https://leetcode.com/problems/product-of-array-except-self +// T: O(N) +// S: O(1) + +public class ProductOfArrayExceptItself { + + private record ProductDetails(int nonZeroProduct, int numberOfZeros) { } + + public int[] productExceptSelf(int[] nums) { + final ProductDetails productDetails = getProductDetails(nums); + if (productDetails.numberOfZeros > 1) return new int[nums.length]; + if (productDetails.numberOfZeros == 1) return productSumOnlyWhenZero(nums, productDetails.nonZeroProduct); + final int[] result = new int[nums.length]; + for (int i = 0 ; i < result.length ; i++) { + result[i] = productDetails.nonZeroProduct / nums[i]; + } + return result; + } + + private int[] productSumOnlyWhenZero(int[] array, int product) { + final int[] result = new int[array.length]; + for (int i = 0 ; i < array.length ; i++) { + if (array[i] == 0) result[i] = product; + } + return result; + } + + private ProductDetails getProductDetails(int[] array) { + int numberOfZeros = 0; + int nonZeroProduct = 1; + for (int element : array) { + if (element == 0) numberOfZeros++; + else nonZeroProduct *= element; + } + return new ProductDetails(nonZeroProduct, numberOfZeros); + } +} From 9ca4b0abd833b0e5a01bb25ac44dcb1d747d8eb1 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 27 Jun 2022 17:07:43 +0200 Subject: [PATCH 622/947] solves product of array except itself in java --- README.md | 2 +- src/ProductOfArrayExceptItself.java | 31 ++++++++++------------------- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index e2c9fc1..3037c8d 100644 --- a/README.md +++ b/README.md @@ -192,7 +192,7 @@ | 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) | | | +| 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) | | | | 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) | | diff --git a/src/ProductOfArrayExceptItself.java b/src/ProductOfArrayExceptItself.java index 6c001d2..6baadff 100644 --- a/src/ProductOfArrayExceptItself.java +++ b/src/ProductOfArrayExceptItself.java @@ -4,34 +4,25 @@ public class ProductOfArrayExceptItself { - private record ProductDetails(int nonZeroProduct, int numberOfZeros) { } - public int[] productExceptSelf(int[] nums) { - final ProductDetails productDetails = getProductDetails(nums); - if (productDetails.numberOfZeros > 1) return new int[nums.length]; - if (productDetails.numberOfZeros == 1) return productSumOnlyWhenZero(nums, productDetails.nonZeroProduct); final int[] result = new int[nums.length]; - for (int i = 0 ; i < result.length ; i++) { - result[i] = productDetails.nonZeroProduct / nums[i]; - } + multipleWithLeftPrefix(nums, result); + multiplyWithRightPostfix(nums, result); return result; } - private int[] productSumOnlyWhenZero(int[] array, int product) { - final int[] result = new int[array.length]; - for (int i = 0 ; i < array.length ; i++) { - if (array[i] == 0) result[i] = product; + private void multipleWithLeftPrefix(int[] numbers, int[] result) { + result[0] = 1; + for(int i = 1 ; i < numbers.length ; i++) { + result[i] = result[i - 1] * numbers[i - 1]; } - return result; } - private ProductDetails getProductDetails(int[] array) { - int numberOfZeros = 0; - int nonZeroProduct = 1; - for (int element : array) { - if (element == 0) numberOfZeros++; - else nonZeroProduct *= element; + private void multiplyWithRightPostfix(int[] numbers, int[] result) { + int right = 1; + for(int i = result.length - 1 ; i >= 0 ; i--) { + result[i] *= right; + right *= numbers[i]; } - return new ProductDetails(nonZeroProduct, numberOfZeros); } } From 5d901e4f6677f19f3f9d33cfd25d31a4c4cf793b Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 27 Jun 2022 17:28:30 +0200 Subject: [PATCH 623/947] solves search in 2d matrix ii in java --- README.md | 2 +- src/SearchA2DMatrixII.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/SearchA2DMatrixII.java diff --git a/README.md b/README.md index 3037c8d..5f18da6 100644 --- a/README.md +++ b/README.md @@ -193,7 +193,7 @@ | 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) | | | +| 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) | | | diff --git a/src/SearchA2DMatrixII.java b/src/SearchA2DMatrixII.java new file mode 100644 index 0000000..787e00e --- /dev/null +++ b/src/SearchA2DMatrixII.java @@ -0,0 +1,15 @@ +// https://leetcode.com/problems/search-a-2d-matrix-ii +// T: O(m + n) +// S: O(1) + +public class SearchA2DMatrixII { + public boolean searchMatrix(int[][] matrix, int target) { + final int rows = matrix.length, columns = matrix[0].length; + for (int column = columns - 1, row = 0 ; row < rows && column >= 0 ; ) { + if (matrix[row][column] == target) return true; + else if (matrix[row][column] < target) row++; + else column--; + } + return false; + } +} From 3e3c7c9949dd7d9eea2713c40cff88e464e7adf2 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 27 Jun 2022 17:37:24 +0200 Subject: [PATCH 624/947] solves single number iii --- src/SingleNumberIII.java | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/SingleNumberIII.java diff --git a/src/SingleNumberIII.java b/src/SingleNumberIII.java new file mode 100644 index 0000000..6a261b5 --- /dev/null +++ b/src/SingleNumberIII.java @@ -0,0 +1,34 @@ +// https://leetcode.com/problems/single-number-iii +// T: O(N) +// S: O(1) + +public class SingleNumberIII { + public int[] singleNumber(int[] nums) { + // get xor of 2 unique numbers a ^ b + int diff = getXor(nums); + + diff = getLastSetBit(diff); + + final int[] result = {0, 0}; + for (int element : nums) { + // different set bit + if ((element & diff) == 0) { + result[0] ^= element; + } else result[1] ^= element; + } + + return result; + } + + private int getXor(int[] array) { + int diff = 0; + for (int element : array) { + diff ^= element; + } + return diff; + } + + private int getLastSetBit(int x) { + return x & -x; + } +} From 8b64156511eff0a86f33513495b9563b636920bd Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Mon, 27 Jun 2022 17:37:37 +0200 Subject: [PATCH 625/947] solves single number iii --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5f18da6..990c6f8 100644 --- a/README.md +++ b/README.md @@ -212,7 +212,7 @@ | 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) | | | +| 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) | | | From 5451945ae9c0c3ea03bbb0d77a5f5cce1e907510 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Wed, 29 Jun 2022 14:22:30 +0200 Subject: [PATCH 626/947] solves ugly numbr ii in java --- README.md | 2 +- src/UglyNumberII.java | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/UglyNumberII.java diff --git a/README.md b/README.md index 990c6f8..3c3001a 100644 --- a/README.md +++ b/README.md @@ -215,7 +215,7 @@ | 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) | | | +| 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) | | diff --git a/src/UglyNumberII.java b/src/UglyNumberII.java new file mode 100644 index 0000000..11f5c1f --- /dev/null +++ b/src/UglyNumberII.java @@ -0,0 +1,27 @@ +// https://leetcode.com/problems/ugly-number-ii +// T: O(N) +// S: O(N) + +public class UglyNumberII { + public int nthUglyNumber(int n) { + final int[] dp = new int[n]; + dp[0] = 1; + int index2, index3, index5; + index2 = index3 = index5 = 0; + int factor2 = 2, factor3 = 3, factor5 = 5; + + for(int i = 1 ; i < n ; i++) { + final int uglyNumber = min(factor2, factor3, factor5); + dp[i] = uglyNumber; + if(factor2 == uglyNumber) factor2 = 2 * dp[++index2]; + if(factor3 == uglyNumber) factor3 = 3 * dp[++index3]; + if(factor5 == uglyNumber) factor5 = 5 * dp[++index5]; + } + + return dp[n-1]; + } + + private int min(int a, int b, int c) { + return Math.min(a, Math.min(b, c)); + } +} From e08ff859d56acb695cf29cb3c5d334deb8402533 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Wed, 29 Jun 2022 14:25:18 +0200 Subject: [PATCH 627/947] adds time and space complexity for ugly number in java --- src/UglyNumber.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/UglyNumber.java b/src/UglyNumber.java index 92cd96f..d6ef212 100644 --- a/src/UglyNumber.java +++ b/src/UglyNumber.java @@ -1,3 +1,7 @@ +// https://leetcode.com/problems/ugly-number +// T: O(log(N)) +// S: O(1) + public class UglyNumber { public static boolean isUgly(int number) { if (number <= 0) { From 0a9e70fb469fbeda4c33ce2ca13fd61613339e49 Mon Sep 17 00:00:00 2001 From: Harshdeep Singh Date: Sun, 3 Jul 2022 05:04:56 +0530 Subject: [PATCH 628/947] Solved Reverse Integer In JavaScript --- README.md | 7 ++++--- assets/javascript.png | Bin 0 -> 674 bytes javascript/ReverseInteger.js | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 assets/javascript.png create mode 100644 javascript/ReverseInteger.js diff --git a/README.md b/README.md index 3c3001a..53aa6cd 100644 --- a/README.md +++ b/README.md @@ -9,14 +9,15 @@ 🔒 = 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) | | | 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) | [![java-yt](assets/java-yt.png)](https://youtu.be/7bOhyl5lWjI) [![python-yt](assets/python-yt.png)](https://youtu.be/lmLG30TLcSg) | +| 7 | [Reverse Integer](https://leetcode.com/problems/reverse-integer/) | [![Java](assets/java.png)](src/ReverseInteger.java) [![Python](assets/python.png)](python/reverse_integer.py) [![JavaScript](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 | [PalindromeNumber](https://leetcode.com/problems/palindrome-number/) | [![Java](assets/java.png)](src/PalindromeNumber.java) [![Python](assets/python.png)](python/palindrome_number.py) | | | 11 | [Container With Most Water](https://leetcode.com/problems/container-with-most-water) | [![Java](assets/java.png)](src/ContainerWitMostWater.java) | | @@ -149,7 +150,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) | | | | 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/assets/javascript.png b/assets/javascript.png new file mode 100644 index 0000000000000000000000000000000000000000..70978bce0bd7594dc997dffe1bc792767f92de0e GIT binary patch literal 674 zcmV;T0$u%yP);a#4$Dk%R;iJ#bOO>=9Um%6wg zT+W&Qx%YR!x%Y6-odF9Ai~pj`iqeNnwg`Y)9PN`a6(aFq2_}mrm@JlHvRH!2VhJY8 zv=_`wRZ!CVwiEVP`eWbxtfdWp6WE4=P&k>HgqD zp&%cIN1$St!qXqQZ+BV<>i59aM&l9t z!V~*Z6Str*0Cgu6W!n^0`xIS0aQ_)RaqDrL4V(^m_a4f(E4I`rny(qh{~R^?;Y5Gj zN+0sCZTuCoa)}Z!-`1^BB7Mj}2a;_!>cuW4Tf{;5$kG&nx^DY?DtI7TyP`y6(`4V1>!(q7f0G_%PUO$w$gqkYI z%Zc32>xUcd(A%#V@xj7EVPiR_U(jqVw*LA^mT50&VPO%2UqXJ+TrpNKy#N3J07*qo IM6N<$g7L06DF6Tf literal 0 HcmV?d00001 diff --git a/javascript/ReverseInteger.js b/javascript/ReverseInteger.js new file mode 100644 index 0000000..6841af2 --- /dev/null +++ b/javascript/ReverseInteger.js @@ -0,0 +1,16 @@ +// https://leetcode.com/problems/reverse-integer/ + +var reverse = function (x) { + let result = 0; + const isNegative = x <= 0; + let absNumber = Math.abs(x); + while (absNumber !== 0) { + let remainder = absNumber % 10; + absNumber = Math.floor(absNumber / 10); + result = result * 10 + remainder; + if (result > 2147483647) { + return 0; + } + } + return isNegative ? -result : result; +}; From d6d1d12d21eb026ad0c32d4492da4fdd00e558fe Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 14 Jul 2022 09:27:34 +0200 Subject: [PATCH 629/947] updates reverse integer in js --- javascript/ReverseInteger.js | 12 +++++++++--- src/UglyNumberIII.java | 28 ++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 src/UglyNumberIII.java diff --git a/javascript/ReverseInteger.js b/javascript/ReverseInteger.js index 6841af2..8851b80 100644 --- a/javascript/ReverseInteger.js +++ b/javascript/ReverseInteger.js @@ -1,16 +1,22 @@ -// https://leetcode.com/problems/reverse-integer/ +// https://leetcode.com/problems/reverse-integer +// T: O(log(n)) +// S: O(1) -var reverse = function (x) { +const INTEGER_MAX_VAL = 2147483647; + +const reverse = x => { let result = 0; const isNegative = x <= 0; let absNumber = Math.abs(x); + while (absNumber !== 0) { let remainder = absNumber % 10; absNumber = Math.floor(absNumber / 10); result = result * 10 + remainder; - if (result > 2147483647) { + if (result > INTEGER_MAX_VAL) { return 0; } } + return isNegative ? -result : result; }; diff --git a/src/UglyNumberIII.java b/src/UglyNumberIII.java new file mode 100644 index 0000000..535d80e --- /dev/null +++ b/src/UglyNumberIII.java @@ -0,0 +1,28 @@ +import java.util.Arrays; + +public class UglyNumberIII { + public static int nthUglyNumber(int n, int a, int b, int c) { + final int[] dp = new int[n + 1]; + dp[0] = 1; + int factorA = a, factorB = b, factorC = c; + int indexA = 0, indexB = 0, indexC = 0; + + for (int i = 1 ; i < dp.length ; i++) { + final int uglyNumber = min(factorA, factorB, factorC); + dp[i] = uglyNumber; + if (uglyNumber == factorA) factorA = a * dp[++indexA]; + if (uglyNumber == factorB) factorB = b * dp[++indexB]; + if (uglyNumber == factorC) factorC = c * dp[++indexC]; + } + System.out.println(Arrays.toString(dp)); + return dp[dp.length - 1]; + } + + private static int min(int a, int b, int c) { + return Math.min(a, Math.min(b, c)); + } + + public static void main(String[] args) { + System.out.println(nthUglyNumber(100, 2, 3, 5)); + } +} From cad617cb73af5335e1056c7a581802bf9727bccc Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 14 Jul 2022 09:28:36 +0200 Subject: [PATCH 630/947] updates stats --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 53aa6cd..f855b03 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ ![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-js](https://img.shields.io/badge/JavaScript-1/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) From 2d03b9574d4bd98c176da6f81bc557037d189cbe Mon Sep 17 00:00:00 2001 From: Harshdeep Singh Date: Thu, 14 Jul 2022 16:02:51 +0530 Subject: [PATCH 631/947] Solved Leetcode 26 Problem In JavaScript --- README.md | 1356 ++++++++--------- javascript/RemoveDuplicatesFromSortedArray.js | 14 + 2 files changed, 692 insertions(+), 678 deletions(-) create mode 100644 javascript/RemoveDuplicatesFromSortedArray.js diff --git a/README.md b/README.md index f855b03..cdfafea 100644 --- a/README.md +++ b/README.md @@ -11,681 +11,681 @@ ## 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) | | -| 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) [![JavaScript](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 | [PalindromeNumber](https://leetcode.com/problems/palindrome-number/) | [![Java](assets/java.png)](src/PalindromeNumber.java) [![Python](assets/python.png)](python/palindrome_number.py) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | | -| 275 | [H-Index II](https://leetcode.com/problems/h-index-ii) | | | -| 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) | | | -| 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) | | | -| 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) | | | -| 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) | | -| 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) | | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | | -| 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) | | -| 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) | | +| # | 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) | | +| 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) [![JavaScript](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 | [PalindromeNumber](https://leetcode.com/problems/palindrome-number/) | [![Java](assets/java.png)](src/PalindromeNumber.java) [![Python](assets/python.png)](python/palindrome_number.py) | | +| 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) [![JavaScript](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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | | +| 275 | [H-Index II](https://leetcode.com/problems/h-index-ii) | | | +| 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) | | | +| 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) | | | +| 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) | | | +| 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) | | +| 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) | | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | | +| 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) | | +| 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) | | diff --git a/javascript/RemoveDuplicatesFromSortedArray.js b/javascript/RemoveDuplicatesFromSortedArray.js new file mode 100644 index 0000000..27f75b1 --- /dev/null +++ b/javascript/RemoveDuplicatesFromSortedArray.js @@ -0,0 +1,14 @@ +// https://leetcode.com/problems/remove-duplicates-from-sorted-array/ +// T: O(N) +// S: O(1) + +const removeDuplicates = (nums) => { + let index = 0; + for (let i = 1; i < nums.length; i++) { + if (nums[index] < nums[i]) { + nums[index + 1] = nums[i]; + index++; + } + } + return index + 1; +}; From 63ce90566103a7d2b5a67b0395058b6703ebfed3 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 14 Jul 2022 13:59:09 +0200 Subject: [PATCH 632/947] solves ugly number iii --- javascript/ReverseInteger.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/javascript/ReverseInteger.js b/javascript/ReverseInteger.js index 8851b80..386febc 100644 --- a/javascript/ReverseInteger.js +++ b/javascript/ReverseInteger.js @@ -20,3 +20,5 @@ const reverse = x => { return isNegative ? -result : result; }; + +console.log(reverse(120)) From 5eed621725b4142973bf885364965f2968c2947f Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 14 Jul 2022 13:59:30 +0200 Subject: [PATCH 633/947] solves ugly number iii --- README.md | 1 + src/UglyNumberII.java | 11 ++++--- src/UglyNumberIII.java | 67 ++++++++++++++++++++++++++++++------------ 3 files changed, 55 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index cdfafea..91de405 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ ## Problems +<<<<<<< HEAD | # | 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) | diff --git a/src/UglyNumberII.java b/src/UglyNumberII.java index 11f5c1f..c4c5dd1 100644 --- a/src/UglyNumberII.java +++ b/src/UglyNumberII.java @@ -6,19 +6,18 @@ public class UglyNumberII { public int nthUglyNumber(int n) { final int[] dp = new int[n]; dp[0] = 1; - int index2, index3, index5; - index2 = index3 = index5 = 0; int factor2 = 2, factor3 = 3, factor5 = 5; + int index2 = 0, index3 = 0, index5 = 0; for(int i = 1 ; i < n ; i++) { final int uglyNumber = min(factor2, factor3, factor5); dp[i] = uglyNumber; - if(factor2 == uglyNumber) factor2 = 2 * dp[++index2]; - if(factor3 == uglyNumber) factor3 = 3 * dp[++index3]; - if(factor5 == uglyNumber) factor5 = 5 * dp[++index5]; + if (uglyNumber == factor2) factor2 = 2 * dp[++index2]; + if (uglyNumber == factor3) factor3 = 3 * dp[++index3]; + if (uglyNumber == factor5) factor5 = 5 * dp[++index5]; } - return dp[n-1]; + return dp[dp.length - 1]; } private int min(int a, int b, int c) { diff --git a/src/UglyNumberIII.java b/src/UglyNumberIII.java index 535d80e..dbea550 100644 --- a/src/UglyNumberIII.java +++ b/src/UglyNumberIII.java @@ -1,28 +1,59 @@ -import java.util.Arrays; +// https://leetcode.com/problems/ugly-number-iii +// T: O(log(MAX_VAL)) MAX_VAL = Integer.MAX_VAL here +// S: O(1) public class UglyNumberIII { - public static int nthUglyNumber(int n, int a, int b, int c) { - final int[] dp = new int[n + 1]; - dp[0] = 1; - int factorA = a, factorB = b, factorC = c; - int indexA = 0, indexB = 0, indexC = 0; + private long a; + private long b; + private long c; + private long lcm_a_b; + private long lcm_a_c; + private long lcm_b_c; + private long lcm_a_b_c; - for (int i = 1 ; i < dp.length ; i++) { - final int uglyNumber = min(factorA, factorB, factorC); - dp[i] = uglyNumber; - if (uglyNumber == factorA) factorA = a * dp[++indexA]; - if (uglyNumber == factorB) factorB = b * dp[++indexB]; - if (uglyNumber == factorC) factorC = c * dp[++indexC]; + public int nthUglyNumber(int n, int a, int b, int c) { + setValues(a, b, c); + int left = 1, right = Integer.MAX_VALUE, middle; + long factors; + while (left <= right) { + middle = left + (right - left) / 2; + factors = numberOfFactors(middle); + if (factors >= n) right = middle - 1; + else left = middle + 1; } - System.out.println(Arrays.toString(dp)); - return dp[dp.length - 1]; + return left; } - private static int min(int a, int b, int c) { - return Math.min(a, Math.min(b, c)); + private void setValues(long a, long b, long c) { + this.a = a; + this.b = b; + this.c = c; + this.lcm_a_b = lcm(a, b); + this.lcm_a_c = lcm(a, c); + this.lcm_b_c = lcm(b, c); + this.lcm_a_b_c = lcm(lcm_a_b, c); } - public static void main(String[] args) { - System.out.println(nthUglyNumber(100, 2, 3, 5)); + /* + * @param n number + * @return will tell how many factors are there of a, b and c between 1 and n + * e.g. if n=10 and a=2 b=3 so there are 7 factors {2, 3, 4, 6, 8, 9, 10} + */ + private long numberOfFactors(int n) { + return n / a + + n / b + + n / c + - n / lcm_a_b + - n / lcm_a_c + - n / lcm_b_c + + n / lcm_a_b_c; + } + + private long gcd(long a, long b) { + return b == 0 ? a : gcd(b, a % b); + } + + private long lcm(long a, long b) { + return (a * b) / gcd(a, b); } } From e5ee855831a0aac49652efffeb952c75c7504dea Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 14 Jul 2022 14:03:17 +0200 Subject: [PATCH 634/947] solves ugly number iii in java --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 91de405..f34efc9 100644 --- a/README.md +++ b/README.md @@ -504,6 +504,7 @@ | 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) | | From 8d8d5002a4e0964ce7d7eab4794d4de177ac91fa Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 14 Jul 2022 14:03:45 +0200 Subject: [PATCH 635/947] solves ugly number iii in java --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index f34efc9..af4a60f 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,6 @@ ## Problems -<<<<<<< HEAD | # | 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) | From 10cb0f3e84912534a9f3b0cf5d1961d5e07645e1 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 14 Jul 2022 14:05:32 +0200 Subject: [PATCH 636/947] solves ugly number iii in java --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index af4a60f..b95eaaa 100644 --- a/README.md +++ b/README.md @@ -503,7 +503,7 @@ | 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) | | +| 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) | | From ccdfef5a1b53c4c65af195fc35618fa6e003713f Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 14 Jul 2022 14:30:07 +0200 Subject: [PATCH 637/947] solves h index in java --- README.md | 2 +- src/HIndex.java | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/HIndex.java diff --git a/README.md b/README.md index b95eaaa..b026bb8 100644 --- a/README.md +++ b/README.md @@ -223,7 +223,7 @@ | 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) | | | +| 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) | | | | 276 | 🔒 [Paint Fence](https://leetcode.com/problems/paint-fence) | | | | 277 | 🔒 [Find The Celebrity](https://leetcode.com/problems/find-the-celebrity) | | | diff --git a/src/HIndex.java b/src/HIndex.java new file mode 100644 index 0000000..9c4d750 --- /dev/null +++ b/src/HIndex.java @@ -0,0 +1,34 @@ +// https://leetcode.com/problems/h-index +// T: O(N) +// S: O(N) + +import java.util.HashMap; +import java.util.Map; + +public class HIndex { + public int hIndex(int[] citations) { + final Map citationFrequencies = getFrequencies(citations); + final int maxCitation = max(citations); + for (int hIndex = maxCitation, papers = 0 ; hIndex >= 0 ; hIndex--) { + papers += citationFrequencies.getOrDefault(hIndex, 0); + if (papers >= hIndex) return hIndex; + } + return 0; + } + + private int max(int[] array) { + int result = 0; + for (int element : array) { + result = Math.max(result, element); + } + return result; + } + + private Map getFrequencies(int[] array) { + final Map frequencies = new HashMap<>(); + for (int element : array) { + frequencies.put(element, frequencies.getOrDefault(element, 0) + 1); + } + return frequencies; + } +} From 7376ddd29ab72dd879fbe3453b4df606b49fc27f Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 14 Jul 2022 18:28:15 +0200 Subject: [PATCH 638/947] solves h index ii --- README.md | 2 +- src/HIndexII.java | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/HIndexII.java diff --git a/README.md b/README.md index b026bb8..b117eff 100644 --- a/README.md +++ b/README.md @@ -224,7 +224,7 @@ | 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) | | | +| 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) | | diff --git a/src/HIndexII.java b/src/HIndexII.java new file mode 100644 index 0000000..4a30b0d --- /dev/null +++ b/src/HIndexII.java @@ -0,0 +1,20 @@ +// https://leetcode.com/problems/h-index-ii +// T: O(log(N)) +// S: O(1) + +public class HIndexII { + public static void main(String[] args) { + System.out.println(hIndex(new int[] {0, 5, 5, 5, 5})); + } + + public static int hIndex(int[] citations) { + int left = 0, right = citations.length - 1, middle; + while (left <= right) { + middle = left + (right - left) / 2; + if (citations[middle] == citations.length - middle) return citations[middle]; + else if (citations[middle] > citations.length - middle) right = middle - 1; + else left = middle + 1; + } + return citations.length - left; + } +} From 52ea603335da26b52bc6ee1cc14a6cd54ba8da1b Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 14 Jul 2022 18:56:56 +0200 Subject: [PATCH 639/947] solves perfect squares in java --- src/PerfectSquares.java | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/PerfectSquares.java diff --git a/src/PerfectSquares.java b/src/PerfectSquares.java new file mode 100644 index 0000000..8e99cff --- /dev/null +++ b/src/PerfectSquares.java @@ -0,0 +1,32 @@ +// https://leetcode.com/problems/perfect-squares +// T: O(N * k) k = size of perfect squares array which is constant +// S: O(N + k) + +public class PerfectSquares { + private static final int[] PERFECT_SQUARES = { + 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484, 529, 576, + 625, 676, 729, 784, 841, 900, 961, 1024, 1089, 1156, 1225, 1296, 1369, 1444, 1521, 1600, 1681, 1764, 1849, + 1936, 2025, 2116, 2209, 2304, 2401, 2500, 2601, 2704, 2809, 2916, 3025, 3136, 3249, 3364, 3481, 3600, 3721, + 3844, 3969, 4096, 4225, 4356, 4489, 4624, 4761, 4900, 5041, 5184, 5329, 5476, 5625, 5776, 5929, 6084, 6241, + 6400, 6561, 6724, 6889, 7056, 7225, 7396, 7569, 7744, 7921, 8100, 8281, 8464, 8649, 8836, 9025, 9216, 9409, + 9604, 9801, 10000, 10_201 + }; + + public int numSquares(int n) { + final int[] dp = new int[n + 1]; + dp[0] = dp[1] = 1; + for (int i = 2 ; i < dp.length ; i++) { + dp[i] = numSquares(i, dp); + } + return dp[dp.length - 1]; + } + + private int numSquares(int n, int[] dp) { + int result = Integer.MAX_VALUE, square; + for (int i = 0 ; PERFECT_SQUARES[i] <= n ; i++) { + square = PERFECT_SQUARES[i]; + result = Math.min(result, dp[square] + dp[n - square]); + } + return result; + } +} From d07c6e23c373e699e649084964416836432c9d63 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Thu, 14 Jul 2022 19:07:19 +0200 Subject: [PATCH 640/947] solves perfect squares --- README.md | 2 +- src/PerfectSquares.java | 48 +++++++++++++++++++++++++---------------- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index b117eff..defb91a 100644 --- a/README.md +++ b/README.md @@ -228,7 +228,7 @@ | 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) | | | +| 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) | | diff --git a/src/PerfectSquares.java b/src/PerfectSquares.java index 8e99cff..bdbd698 100644 --- a/src/PerfectSquares.java +++ b/src/PerfectSquares.java @@ -1,32 +1,44 @@ // https://leetcode.com/problems/perfect-squares -// T: O(N * k) k = size of perfect squares array which is constant -// S: O(N + k) +// T: O(k + sqrt(n)) k = size of perfect squares set which is constant +// S: O(k) + +import java.util.Set; public class PerfectSquares { - private static final int[] PERFECT_SQUARES = { + private static final Set PERFECT_SQUARES = Set.of( 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484, 529, 576, 625, 676, 729, 784, 841, 900, 961, 1024, 1089, 1156, 1225, 1296, 1369, 1444, 1521, 1600, 1681, 1764, 1849, 1936, 2025, 2116, 2209, 2304, 2401, 2500, 2601, 2704, 2809, 2916, 3025, 3136, 3249, 3364, 3481, 3600, 3721, 3844, 3969, 4096, 4225, 4356, 4489, 4624, 4761, 4900, 5041, 5184, 5329, 5476, 5625, 5776, 5929, 6084, 6241, 6400, 6561, 6724, 6889, 7056, 7225, 7396, 7569, 7744, 7921, 8100, 8281, 8464, 8649, 8836, 9025, 9216, 9409, - 9604, 9801, 10000, 10_201 - }; + 9604, 9801, 10_000, 10_201 + ); - public int numSquares(int n) { - final int[] dp = new int[n + 1]; - dp[0] = dp[1] = 1; - for (int i = 2 ; i < dp.length ; i++) { - dp[i] = numSquares(i, dp); - } - return dp[dp.length - 1]; + private boolean isSquare(int n) { + return PERFECT_SQUARES.contains(n); } - private int numSquares(int n, int[] dp) { - int result = Integer.MAX_VALUE, square; - for (int i = 0 ; PERFECT_SQUARES[i] <= n ; i++) { - square = PERFECT_SQUARES[i]; - result = Math.min(result, dp[square] + dp[n - square]); + // Based on Lagrange's Four Square theorem, there + // are only 4 possible results: 1, 2, 3, 4. + int numSquares(int n) { + // If n is a perfect square, return 1. + if (isSquare(n)) return 1; + + // The result is 4 if and only if n can be written in the + // form of 4^k*(8*m + 7). Please refer to + // Legendre's three-square theorem. + while (n % 4 == 0) { + n >>= 2; } - return result; + if (n % 8 == 7) return 4; + + // Check whether 2 is the result. if number can be composed as a^2 + b^2 + for(int i = 1; i * i <= n; i++) { + if (isSquare(n - i * i)) { + return 2; + } + } + + return 3; } } From 5cd2b5c7a90514464cb8220679e6a6f2359e03ab Mon Sep 17 00:00:00 2001 From: Moiz Date: Fri, 15 Jul 2022 22:12:06 +0530 Subject: [PATCH 641/947] hello --- python/120.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 python/120.py diff --git a/python/120.py b/python/120.py new file mode 100644 index 0000000..e69de29 From 0f42f746d51525e994b43013c353ec9b871498ea Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 15 Jul 2022 19:28:27 +0200 Subject: [PATCH 642/947] removes unnused file --- python/120.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 python/120.py diff --git a/python/120.py b/python/120.py deleted file mode 100644 index e69de29..0000000 From 4636f2d92660e858a459823b49ce8a38560d34fa Mon Sep 17 00:00:00 2001 From: anishLearnsToCode Date: Mon, 18 Jul 2022 10:25:22 +0200 Subject: [PATCH 643/947] updates contributing file --- CONTRIBUTING.md | 34 +--------------------------------- programming-language-logos.md | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 33 deletions(-) create mode 100644 programming-language-logos.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 23b1fe5..fa9f31c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -18,36 +18,4 @@ and then create a pull request with the added solution and updated readme. 2. Say you solve some problem called __cars-and-trucks__ in using your favorite programming language, say Python then simple add a new file called `cars-and-trucks.py` in the `python` directory. -3. In the [README](README.md) file, add a Python logo along with an empty link. -4. Updating the link for the solution will be done by the Project maintainers - (aka. [anishLearnsToCode](https://github.com/anishLearnsToCode)) - -## Programming Language Logos -To add a logo in the [README](README.md) table simply add a link with an embedded picture as -```markdown -[![Python](icon-link)](this link will be filled by the author if the pull request is accepted) -``` - -For the icon link refer to the table below to obtain the link for a specific programming language: - -| Programming Language | Icon | Icon Link | -|:--------------------:|:------------------------------------------------------------------------------:|:---------------------------------------------------------------------:| -| Java | ![Java](assets/java.png) | assets/java.png | -| Python | ![Python](assets/python.png) | assets/python.png | -| C | ![C](https://img.icons8.com/color/35/000000/c-programming.png) | https://img.icons8.com/color/35/000000/c-programming.png | -| C++ | ![C++](https://img.icons8.com/color/35/000000/c-plus-plus-logo.png) | https://img.icons8.com/color/35/000000/c-plus-plus-logo.png | -| C# | ![C#](https://img.icons8.com/color/35/000000/c-sharp-logo.png) | https://img.icons8.com/color/35/000000/c-sharp-logo.png | -| JavaScript | ![JavaScript](https://img.icons8.com/color/40/000000/javascript.png) | https://img.icons8.com/color/40/000000/javascript.png | -| TypeScript | ![TypeScript](https://img.icons8.com/color/40/000000/typescript.png) | https://img.icons8.com/color/40/000000/typescript.png | -| Ruby | ![Ruby](https://img.icons8.com/office/35/000000/ruby-programming-language.png) | https://img.icons8.com/office/35/000000/ruby-programming-language.png | -| Scala | ![Scala](https://img.icons8.com/dusk/35/000000/scala.png) | https://img.icons8.com/office/35/000000/ruby-programming-language.png | -| PHP | ![PHP](https://img.icons8.com/officel/40/000000/php-logo.png) | https://img.icons8.com/officel/40/000000/php-logo.png | -| Swift | ![Swift](https://img.icons8.com/fluent/40/000000/swift.png) | https://img.icons8.com/fluent/40/000000/swift.png | - - - - - - - - +3. In the [README](README.md) file, do not make any modification. The README file will be modified by __@anishLearnsToCode__. diff --git a/programming-language-logos.md b/programming-language-logos.md new file mode 100644 index 0000000..29996e9 --- /dev/null +++ b/programming-language-logos.md @@ -0,0 +1,21 @@ +## Programming Language Logos +To add a logo in the [README](README.md) table simply add a link with an embedded picture as +```markdown +[![Python](icon-link)](this link will be filled by the author if the pull request is accepted) +``` + +For the icon link refer to the table below to obtain the link for a specific programming language: + +| Programming Language | Icon | Icon Link | +|:--------------------:|:------------------------------------------------------------------------------:|:---------------------------------------------------------------------:| +| Java | ![Java](assets/java.png) | assets/java.png | +| Python | ![Python](assets/python.png) | assets/python.png | +| C | ![C](https://img.icons8.com/color/35/000000/c-programming.png) | https://img.icons8.com/color/35/000000/c-programming.png | +| C++ | ![C++](https://img.icons8.com/color/35/000000/c-plus-plus-logo.png) | https://img.icons8.com/color/35/000000/c-plus-plus-logo.png | +| C# | ![C#](https://img.icons8.com/color/35/000000/c-sharp-logo.png) | https://img.icons8.com/color/35/000000/c-sharp-logo.png | +| JavaScript | ![JavaScript](https://img.icons8.com/color/40/000000/javascript.png) | https://img.icons8.com/color/40/000000/javascript.png | +| TypeScript | ![TypeScript](https://img.icons8.com/color/40/000000/typescript.png) | https://img.icons8.com/color/40/000000/typescript.png | +| Ruby | ![Ruby](https://img.icons8.com/office/35/000000/ruby-programming-language.png) | https://img.icons8.com/office/35/000000/ruby-programming-language.png | +| Scala | ![Scala](https://img.icons8.com/dusk/35/000000/scala.png) | https://img.icons8.com/office/35/000000/ruby-programming-language.png | +| PHP | ![PHP](https://img.icons8.com/officel/40/000000/php-logo.png) | https://img.icons8.com/officel/40/000000/php-logo.png | +| Swift | ![Swift](https://img.icons8.com/fluent/40/000000/swift.png) | https://img.icons8.com/fluent/40/000000/swift.png | From 90c4e103ba4cebe0f7d0172217bc95001b573241 Mon Sep 17 00:00:00 2001 From: Harshdeep Singh Date: Mon, 15 Aug 2022 18:36:48 +0530 Subject: [PATCH 644/947] Solved Add Two Numbers in JavaScript --- javascript/AddTwoNumbers.js | 39 +++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 javascript/AddTwoNumbers.js diff --git a/javascript/AddTwoNumbers.js b/javascript/AddTwoNumbers.js new file mode 100644 index 0000000..2068a40 --- /dev/null +++ b/javascript/AddTwoNumbers.js @@ -0,0 +1,39 @@ +// https://leetcode.com/problems/add-two-numbers/ +// T: O(max(|l1|, |l2|)) +// S: O(max(|l1|, |l2|)) + +const addTwoNumbers = (l1, l2) => { + let p1 = l1; + let p2 = l2; + let carry = 0; + let result_node = new ListNode(-1); + let pointer = result_node; + while (p1 || p2 || carry !== 0) { + let sum = 0; + if (p1 !== null && p2 !== null) { + sum = p1.val + p2.val; + p1 = p1.next; + p2 = p2.next; + } else if (p1 !== null) { + sum = p1.val; + p1 = p1.next; + } else if (p2 !== null) { + sum = p2.val; + p2 = p2.next; + } + + if (carry !== 0) { + sum = sum + carry; + carry = 0; + } + + if (sum > 9) { + carry = Math.floor(sum / 10); + sum = sum % 10; + } + + pointer.next = new ListNode(sum); + pointer = pointer.next; + } + return result_node.next; +}; From f1b5ab08bfa4e7b18445b881ca8c976379bde0d4 Mon Sep 17 00:00:00 2001 From: Harshdeep Singh Date: Wed, 17 Aug 2022 18:11:32 +0530 Subject: [PATCH 645/947] Solved Palindrome Number In JavaScript --- javascript/PalindromeNumber.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 javascript/PalindromeNumber.js diff --git a/javascript/PalindromeNumber.js b/javascript/PalindromeNumber.js new file mode 100644 index 0000000..feaae8e --- /dev/null +++ b/javascript/PalindromeNumber.js @@ -0,0 +1,16 @@ +const isPalindrome = (x) => { + if (x < 0 || (x % 10 === 0 && x !== 0)) { + return false; + } + let result = x; + let sum = 0; + while (x !== 0) { + let remainder = x % 10; + sum = sum * 10 + remainder; + x = Math.floor(x / 10); + } + if (sum === result) { + return true; + } + return false; +}; From e74ee36c40f0d1af8eeabfc7c944bfe4a7a8796a Mon Sep 17 00:00:00 2001 From: Harshdeep Singh <94737463+JunDevHarsh@users.noreply.github.com> Date: Wed, 17 Aug 2022 20:00:16 +0530 Subject: [PATCH 646/947] Update PalindromeNumber.js - Added link to the problem - Added T.C. as well as S.C. --- javascript/PalindromeNumber.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/javascript/PalindromeNumber.js b/javascript/PalindromeNumber.js index feaae8e..1670dd3 100644 --- a/javascript/PalindromeNumber.js +++ b/javascript/PalindromeNumber.js @@ -1,3 +1,7 @@ +// https://leetcode.com/problems/palindrome-number +// T: O(log(n)) +// S: O(1) + const isPalindrome = (x) => { if (x < 0 || (x % 10 === 0 && x !== 0)) { return false; From a962192be5bb53ed5518c7d6cf0bf9e765e7edb9 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 19 Aug 2022 18:20:21 +0200 Subject: [PATCH 647/947] fixes table in readme.md file --- README.md | 1360 ++++++++++++++++++++++++++--------------------------- 1 file changed, 679 insertions(+), 681 deletions(-) diff --git a/README.md b/README.md index defb91a..e90402c 100644 --- a/README.md +++ b/README.md @@ -3,690 +3,688 @@ ![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-js](https://img.shields.io/badge/JavaScript-1/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) 🔒 = 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) | | -| 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) [![JavaScript](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 | [PalindromeNumber](https://leetcode.com/problems/palindrome-number/) | [![Java](assets/java.png)](src/PalindromeNumber.java) [![Python](assets/python.png)](python/palindrome_number.py) | | -| 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) [![JavaScript](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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | | -| 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) | | | -| 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) | | -| 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) | | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | -| 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) | | | -| 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) | | -| 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) | | +| # | 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) | | +| 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 | [PalindromeNumber](https://leetcode.com/problems/palindrome-number/) | [![Java](assets/java.png)](src/PalindromeNumber.java) [![Python](assets/python.png)](python/palindrome_number.py) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | | +| 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) | | | +| 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) | | +| 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) | | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | +| 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) | | | +| 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) | | +| 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) | | From 223c69c2e59e3e91aecde6c65b2724c31325d1fd Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Fri, 19 Aug 2022 18:23:15 +0200 Subject: [PATCH 648/947] adds add two numbers javascript solution in readme.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e90402c..57aaffa 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ | # | 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) | | +| 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) | | From 3b40487cbd275e31e51ea2b7ba5289afd382e635 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sun, 21 Aug 2022 14:04:47 +0200 Subject: [PATCH 649/947] updates readme.md file --- README.md | 1 + javascript/ReverseInteger.js | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 57aaffa..6a12182 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ ![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-javascript](https://img.shields.io/badge/Python-3/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/javascript/ReverseInteger.js b/javascript/ReverseInteger.js index 386febc..8851b80 100644 --- a/javascript/ReverseInteger.js +++ b/javascript/ReverseInteger.js @@ -20,5 +20,3 @@ const reverse = x => { return isNegative ? -result : result; }; - -console.log(reverse(120)) From 63953c16cff57836a6b24011ee3e6845710a4b69 Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sun, 21 Aug 2022 14:13:20 +0200 Subject: [PATCH 650/947] adds link to palindrome number solution in js in readme file --- README.md | 4 ++-- javascript/PalindromeNumber.js | 8 +++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 6a12182..b0aee61 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ![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-javascript](https://img.shields.io/badge/Python-3/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) @@ -19,7 +19,7 @@ | 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 | [PalindromeNumber](https://leetcode.com/problems/palindrome-number/) | [![Java](assets/java.png)](src/PalindromeNumber.java) [![Python](assets/python.png)](python/palindrome_number.py) | | +| 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) | diff --git a/javascript/PalindromeNumber.js b/javascript/PalindromeNumber.js index 1670dd3..1779c43 100644 --- a/javascript/PalindromeNumber.js +++ b/javascript/PalindromeNumber.js @@ -2,7 +2,7 @@ // T: O(log(n)) // S: O(1) -const isPalindrome = (x) => { +const isPalindrome = x => { if (x < 0 || (x % 10 === 0 && x !== 0)) { return false; } @@ -13,8 +13,6 @@ const isPalindrome = (x) => { sum = sum * 10 + remainder; x = Math.floor(x / 10); } - if (sum === result) { - return true; - } - return false; + + return sum === result; }; From dcf52244b5cda67bae47585408547236071274ff Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 11 Feb 2023 13:45:25 +0100 Subject: [PATCH 651/947] solve speeking iterator #284 in java --- README.md | 2 +- src/PeekingIterator.java | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/PeekingIterator.java diff --git a/README.md b/README.md index b0aee61..63bdb99 100644 --- a/README.md +++ b/README.md @@ -231,7 +231,7 @@ | 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) | | | +| 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) | | | diff --git a/src/PeekingIterator.java b/src/PeekingIterator.java new file mode 100644 index 0000000..8709886 --- /dev/null +++ b/src/PeekingIterator.java @@ -0,0 +1,37 @@ +// https://leetcode.com/problems/peeking-iterator +// T: O(N) +// S: O(N) + +import java.util.Iterator; + +public class PeekingIterator implements Iterator { + final private Iterator iterator; + int next; + boolean hasNext; + + public PeekingIterator(Iterator iterator) { + this.iterator = iterator; + hasNext = iterator.hasNext(); + next = iterator.hasNext() ? iterator.next() : 0; + } + + // Returns the next element in the iteration without advancing the iterator. + public Integer peek() { + return next; + } + + // hasNext() and next() should behave the same as in the Iterator interface. + // Override them if needed. + @Override + public Integer next() { + int result = next; + hasNext = iterator.hasNext(); + next = iterator.hasNext() ? iterator.next() : 0; + return result; + } + + @Override + public boolean hasNext() { + return hasNext; + } +} \ No newline at end of file From 8d9e45c55adfa0cc35a8bd22a8a22616436a224b Mon Sep 17 00:00:00 2001 From: Anish Sachdeva Date: Sat, 11 Feb 2023 14:21:36 +0100 Subject: [PATCH 652/947] solves find the duplicate element #287 in java --- README.md | 2 +- src/FindTheDuplicateNumber.java | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/FindTheDuplicateNumber.java diff --git a/README.md b/README.md index 63bdb99..1a83c86 100644 --- a/README.md +++ b/README.md @@ -234,7 +234,7 @@ | 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) | | | +| 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) | | diff --git a/src/FindTheDuplicateNumber.java b/src/FindTheDuplicateNumber.java new file mode 100644 index 0000000..c86f050 --- /dev/null +++ b/src/FindTheDuplicateNumber.java @@ -0,0 +1,26 @@ +// https://leetcode.com/problems/find-the-duplicate-number +// T: O(N) +// S: O(1) + +public class FindTheDuplicateNumber { + public static int findDuplicate(int[] nums) { + int tortoise = nums[0]; + int hare = nums[0]; + + do { + tortoise = nums[tortoise]; + hare = nums[nums[hare]]; + } while (tortoise != hare); + + // Find the "entrance" to the cycle. + tortoise = nums[0]; + + while (tortoise != hare) { + tortoise = nums[tortoise]; + hare = nums[hare]; + } + + return hare; + } +} + From 2df36e1686f03b6795569d278e23fc34be159c5d Mon Sep 17 00:00:00 2001 From: sumanth_botlagunta <86908741+sumanth-botlagunta@users.noreply.github.com> Date: Mon, 20 Mar 2023 13:10:21 +0530 Subject: [PATCH 653/947] Design Browser History (#1472, java, py) + Add and Search Words Data Structure (#211, py) * 1472. Design Browser History * problem 211: Design Add and Search Words Data Structure --- ...ign_add_and_search_words_data_structure.py | 36 +++++++++++++++++++ python/design_browser_history.py | 18 ++++++++++ src/DesignBrowserHistory.java | 26 ++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 python/design_add_and_search_words_data_structure.py create mode 100644 python/design_browser_history.py create mode 100644 src/DesignBrowserHistory.java diff --git a/python/design_add_and_search_words_data_structure.py b/python/design_add_and_search_words_data_structure.py new file mode 100644 index 0000000..23326bf --- /dev/null +++ b/python/design_add_and_search_words_data_structure.py @@ -0,0 +1,36 @@ +class Trienode: + def __init__(self): + self.children = {} + self.word = False + +class WordDictionary: + + def __init__(self): + self.root = Trienode() + + + def addWord(self, word: str) -> None: + ptr = self.root + for ch in word: + if ch not in ptr.children: + ptr.children[ch] = Trienode() + ptr = ptr.children[ch] + ptr.word = True + + + def search(self, word: str) -> bool: + def dfs(j, root): + curr = root + for i in range(j, len(word)): + ch = word[i] + if ch == ".": + for child in curr.children.values(): + if dfs(i+1, child): + return True + return False + else: + if ch not in curr.children: + return False + curr = curr.children[ch] + return curr.word + return dfs(0, self.root) diff --git a/python/design_browser_history.py b/python/design_browser_history.py new file mode 100644 index 0000000..918683a --- /dev/null +++ b/python/design_browser_history.py @@ -0,0 +1,18 @@ +class BrowserHistory: + + def __init__(self, homepage: str): + self.history = [homepage] + self.ptr = 0 + + def visit(self, url: str) -> None: + self.ptr += 1 + self.history = self.history[:self.ptr] + self.history.append(url) + + def back(self, steps: int) -> str: + self.ptr = max(0, self.ptr - steps) + return self.history[self.ptr] + + def forward(self, steps: int) -> str: + self.ptr = min(len(self.history) - 1, self.ptr + steps) + return self.history[self.ptr] diff --git a/src/DesignBrowserHistory.java b/src/DesignBrowserHistory.java new file mode 100644 index 0000000..ded6e65 --- /dev/null +++ b/src/DesignBrowserHistory.java @@ -0,0 +1,26 @@ +class BrowserHistory { + private List history; + private int ptr; + + public BrowserHistory(String homepage) { + this.history = new ArrayList<>(); + this.history.add(homepage); + this.ptr = 0; + } + + public void visit(String url) { + this.ptr++; + this.history = this.history.subList(0, this.ptr); + this.history.add(url); + } + + public String back(int steps) { + this.ptr = Math.max(0, this.ptr - steps); + return this.history.get(this.ptr); + } + + public String forward(int steps) { + this.ptr = Math.min(this.history.size() - 1, this.ptr + steps); + return this.history.get(this.ptr); + } +} From 482e8c254e318597ec4ff84d4e36c6cf656c311d Mon Sep 17 00:00:00 2001 From: sumanth_botlagunta <86908741+sumanth-botlagunta@users.noreply.github.com> Date: Fri, 24 Mar 2023 20:29:31 +0530 Subject: [PATCH 654/947] solves problems in python * 1472. Design Browser History * problem 211: Design Add and Search Words Data Structure * added new lines at end of files * 208: implement Trie (Prefix Tree) * 2348: Number of Zero-Filled Subarrays * 218: The Skyline Problem * 2492: Minimum Score of a Path Between Two Cities * added Links + Time & Space Complexity * 1319: Number of Operations to Make Network Connected * 200: Number of Islands --- ...imum_score_of_a_path_between_two_cities.py | 34 +++++++++++++++++ ...of_operations_to_make_network_connected.py | 35 +++++++++++++++++ python/number_of_islands.py | 24 ++++++++++++ python/number_of_zero_filled_subarrays.py | 19 ++++++++++ python/the_skyline_problem.py | 29 ++++++++++++++ python/trie.py | 38 +++++++++++++++++++ 6 files changed, 179 insertions(+) create mode 100644 python/minimum_score_of_a_path_between_two_cities.py create mode 100644 python/no_of_operations_to_make_network_connected.py create mode 100644 python/number_of_islands.py create mode 100644 python/number_of_zero_filled_subarrays.py create mode 100644 python/the_skyline_problem.py create mode 100644 python/trie.py diff --git a/python/minimum_score_of_a_path_between_two_cities.py b/python/minimum_score_of_a_path_between_two_cities.py new file mode 100644 index 0000000..37cfc10 --- /dev/null +++ b/python/minimum_score_of_a_path_between_two_cities.py @@ -0,0 +1,34 @@ +# https://leetcode.com/problems/minimum-score-of-a-path-between-two-cities/ +# T: O(N + M) where N is the number of nodes and M is the number of edges +# S: O(N + M) where N is the number of nodes and M is the number of edges + +from collections import deque + +class Solution: + def __init__(self): + self.min_dist = 1e14 + + def minScore(self, n: int, roads) -> int: + graph = {} + vis = [False]*n + for x, y, d in roads: + if x in graph: + graph[x].append((y, d)) + else: + graph[x] = [(y, d)] + if y in graph: + graph[y].append((x, d)) + else: + graph[y] = [(x, d)] + + visited = set() + queue = deque([1]) + + while queue: + node = queue.popleft() + for adj, score in graph[node]: + if adj not in visited: + queue.append(adj) + visited.add(adj) + self.min_dist = min(self.min_dist, score) + return self.min_dist diff --git a/python/no_of_operations_to_make_network_connected.py b/python/no_of_operations_to_make_network_connected.py new file mode 100644 index 0000000..f5cec37 --- /dev/null +++ b/python/no_of_operations_to_make_network_connected.py @@ -0,0 +1,35 @@ +# https://leetcode.com/problems/number-of-operations-to-make-network-connected/description/ +# T: O(M) where M is the number of connections +# S: O(N) where N is the number of nodes + +class Solution: + def makeConnected(self, n, connections) -> int: + if len(connections) < n-1: + return -1 + if n == 1: + return 0 + graph = {} + for a, b in connections: + if a in graph: + graph[a].append(b) + else: + graph[a] = [b] + + if b in graph: + graph[b].append(a) + else: + graph[b] = [a] + + visited = [0] * n + + def dfs(node): + if visited[node]: + return 0 + visited[node] = 1 + if node in graph: + for num in graph[node]: + dfs(num) + return 1 + + + return sum(dfs(node) for node in range(n)) - 1 diff --git a/python/number_of_islands.py b/python/number_of_islands.py new file mode 100644 index 0000000..76d2814 --- /dev/null +++ b/python/number_of_islands.py @@ -0,0 +1,24 @@ +# https://leetcode.com/problems/number-of-islands/description/ +# T: O(MN) where M is the number of rows and N is the number of columns. +# S: O(MN) where M is the number of rows and N is the number of columns. + +def numIslands(self, grid): + if not grid: + return 0 + + count = 0 + for i in range(len(grid)): + for j in range(len(grid[0])): + if grid[i][j] == '1': + self.dfs(grid, i, j) + count += 1 + return count + +def dfs(self, grid, i, j): + if i<0 or j<0 or i>=len(grid) or j>=len(grid[0]) or grid[i][j] != '1': + return + grid[i][j] = '#' + self.dfs(grid, i+1, j) + self.dfs(grid, i-1, j) + self.dfs(grid, i, j+1) + self.dfs(grid, i, j-1) diff --git a/python/number_of_zero_filled_subarrays.py b/python/number_of_zero_filled_subarrays.py new file mode 100644 index 0000000..1438c11 --- /dev/null +++ b/python/number_of_zero_filled_subarrays.py @@ -0,0 +1,19 @@ +# https://leetcode.com/problems/number-of-zero-filled-subarrays/ +# T: O(N) where N is the length of nums +# S: O(1) + +class Solution: + def zeroFilledSubarray(self, nums) -> int: + count = 0 + i = 0 + while i < len(nums): + if nums[i] == 0: + j = i + while j < len(nums) and nums[j] == 0: + j += 1 + count += (j - i) * (j - i + 1) // 2 + i = j + else: + i = i+1 + + return count diff --git a/python/the_skyline_problem.py b/python/the_skyline_problem.py new file mode 100644 index 0000000..91e2aad --- /dev/null +++ b/python/the_skyline_problem.py @@ -0,0 +1,29 @@ +# https://leetcode.com/problems/the-skyline-problem/ +# T: O(NlogN) where N is the number of buildings +# S: O(N) where N is the number of buildings + +import bisect + +class Solution: + def getSkyline(self, buildings): + h = [] + for b in buildings: + h.append((b[0], -b[2])) + h.append((b[1], b[2])) + + h.sort() + prev = cur = 0 + m = [0] + res = [] + + for i in h: + if i[1] < 0: + bisect.insort(m, -i[1]) + else: + m.remove(i[1]) + cur = max(m) + if cur != prev: + res.append([i[0], cur]) + prev = cur + + return res diff --git a/python/trie.py b/python/trie.py new file mode 100644 index 0000000..ef9b4ed --- /dev/null +++ b/python/trie.py @@ -0,0 +1,38 @@ +# https://leetcode.com/problems/implement-trie-prefix-tree/ +# T: O(N) where N is the length of the word +# S: O(MN) where M is the number of words, N is the maximum length of the word + +class TrieNode: + def __init__(self): + self.children = {} + self.is_word = False + +class Trie: + + def __init__(self): + self.root = TrieNode() + + def insert(self, word: str) -> None: + node = self.root + for char in word: + if char not in node.children: + node.children[char] = TrieNode() + node = node.children[char] + node.is_word = True + + def search(self, word: str) -> bool: + node = self.root + for char in word: + if char not in node.children: + return False + node = node.children[char] + return node.is_word + + + def startsWith(self, prefix: str) -> bool: + node = self.root + for char in prefix: + if char not in node.children: + return False + node = node.children[char] + return True From 2da60f3ecd38cc577c97696130af8654290c8394 Mon Sep 17 00:00:00 2001 From: sumanth_botlagunta <86908741+sumanth-botlagunta@users.noreply.github.com> Date: Mon, 27 Mar 2023 12:28:18 +0530 Subject: [PATCH 655/947] solves Longest Cycle in Graph (#2360) in python --- python/longest_cycle_in_graph.py | 28 +++++++++++++++++++ ...tes_to_make_all_paths_lead_to_city_zero.py | 26 +++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 python/longest_cycle_in_graph.py create mode 100644 python/reorder_routes_to_make_all_paths_lead_to_city_zero.py diff --git a/python/longest_cycle_in_graph.py b/python/longest_cycle_in_graph.py new file mode 100644 index 0000000..07af343 --- /dev/null +++ b/python/longest_cycle_in_graph.py @@ -0,0 +1,28 @@ +# https://leetcode.com/problems/longest-cycle-in-a-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 __init__(self): + self.answer = -1 + + def dfs(self, node, edges, dist, visit): + visit[node] = True + neighbor = edges[node] + + if neighbor != -1 and not visit[neighbor]: + dist[neighbor] = dist[node] + 1 + self.dfs(neighbor, edges, dist, visit) + elif neighbor != -1 and neighbor in dist: + self.answer = max(self.answer, dist[node] - dist[neighbor] + 1) + + def longestCycle(self, edges): + n = len(edges) + visit = [False] * n + + for i in range(n): + if not visit[i]: + dist = {i: 1} + self.dfs(i, edges, dist, visit) + + return self.answer diff --git a/python/reorder_routes_to_make_all_paths_lead_to_city_zero.py b/python/reorder_routes_to_make_all_paths_lead_to_city_zero.py new file mode 100644 index 0000000..1c89b52 --- /dev/null +++ b/python/reorder_routes_to_make_all_paths_lead_to_city_zero.py @@ -0,0 +1,26 @@ +# https://leetcode.com/problems/reorder-routes-to-make-all-paths-lead-to-the-city-zero/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 __init__(self): + self.reorders = 0 + + def minReorder(self, n, connections): + edges = {(u, v) for u, v in connections} + graph = {i:[] for i in range(n)} + for u, v in connections: + graph[u].append(v) + graph[v].append(u) + visit = set() + visit.add(0) + def dfs(graph, edges, visit, city): + for node in graph[city]: + if node in visit: + continue + if (node, city) not in edges: + self.reorders+=1 + visit.add(node) + dfs(graph, edges, visit, node) + dfs(graph, edges, visit, 0) + return self.reorders From cdd20ee54b27ffb53fad87c232cdfbedc1dc0037 Mon Sep 17 00:00:00 2001 From: sumanth_botlagunta <86908741+sumanth-botlagunta@users.noreply.github.com> Date: Mon, 27 Mar 2023 12:30:49 +0530 Subject: [PATCH 656/947] solves Count Unreachable Pairs of Nodes in an Undirected Graph (#2316) in python (#12) --- ...e_pair_of_node_in_an_undirectable_graph.py | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 python/count_unreachable_pair_of_node_in_an_undirectable_graph.py diff --git a/python/count_unreachable_pair_of_node_in_an_undirectable_graph.py b/python/count_unreachable_pair_of_node_in_an_undirectable_graph.py new file mode 100644 index 0000000..22fde48 --- /dev/null +++ b/python/count_unreachable_pair_of_node_in_an_undirectable_graph.py @@ -0,0 +1,49 @@ +# https://leetcode.com/problems/count-unreachable-pairs-of-nodes-in-an-undirected-graph/description/ +# T: O(N + E) where N is the number of nodes and E is the number of edges +# S: O(N + E) where N is the number of nodes and E is the number of edges + +from collections import defaultdict +class Solution: + def __init__(self): + self.graph = defaultdict(list) + self.visited = set() + self.n = 0 + + def add_edge(self, u, v): + self.graph[u].append(v) + self.graph[v].append(u) + + def dfs(self, v, component): + self.visited.add(v) + component.append(v) + for neighbor in self.graph[v]: + if neighbor not in self.visited: + self.dfs(neighbor, component) + + def find_components(self): + components = [] + for v in range(self.n): + if v not in self.visited: + component = [] + self.dfs(v, component) + components.append(component) + + return components + + def countPairs(self, n, edges): + for u, v in edges: + self.add_edge(u, v) + self.n = n + component_lengths = [] + components = self.find_components() + for component in components: + component_lengths.append(len(component)) + print(components, component_lengths) + + k = sum(component_lengths) + sol = 0 + for l in component_lengths: + sol+=((k-l)*l) + sol = sol//2 + + return sol From cb54e2a4a66f8c5a40f6b112810cb7e972e1a961 Mon Sep 17 00:00:00 2001 From: sumanth_botlagunta <86908741+sumanth-botlagunta@users.noreply.github.com> Date: Mon, 27 Mar 2023 12:39:02 +0530 Subject: [PATCH 657/947] solves Reorder Routes to Make All Paths Lead to the City Zero (#1466) in python (#11) From a159d1b0362a0ae7e5b7f4274fce11ed3fbfd45c Mon Sep 17 00:00:00 2001 From: sumanth_botlagunta <86908741+sumanth-botlagunta@users.noreply.github.com> Date: Tue, 28 Mar 2023 16:34:56 +0530 Subject: [PATCH 658/947] solves minimum cost for tickets (#983) in python --- python/minimum_cost_for_tickets.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 python/minimum_cost_for_tickets.py diff --git a/python/minimum_cost_for_tickets.py b/python/minimum_cost_for_tickets.py new file mode 100644 index 0000000..8a88372 --- /dev/null +++ b/python/minimum_cost_for_tickets.py @@ -0,0 +1,26 @@ +# https://leetcode.com/problems/minimum-cost-for-tickets/description/ +# T: O(N) where N is the last day of travel +# S: O(N) where N is the last day of travel + +class Solution: + def mincostTickets(self, days, costs): + # Create a list of size days[-1] + 1 and initialize it with 0's + dp = [0] * (days[-1] + 1) + + # Create a set of travel days + travel_days = set(days) + + # Iterate over the range of 1 to len(dp) with a step of 1 + for i in range(1, len(dp)): + # If the current day is not in the set of travel days + if i not in travel_days: + # Set its cost to the cost of traveling on the previous day + dp[i] = dp[i - 1] + else: + # Calculate the minimum cost for traveling on that day + dp[i] = min(dp[max(0, i - 1)] + costs[0], + dp[max(0, i - 7)] + costs[1], + dp[max(0, i - 30)] + costs[2]) + + # Return the last element of this list which will be the minimum cost of travel for all days + return dp[-1] From 557eea91b894845616cfe25009a289fdcea1ee68 Mon Sep 17 00:00:00 2001 From: sumanth_botlagunta <86908741+sumanth-botlagunta@users.noreply.github.com> Date: Tue, 28 Mar 2023 16:36:52 +0530 Subject: [PATCH 659/947] solves Minimum Path Sum (#64) in python --- python/minimum_path_sum.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 python/minimum_path_sum.py diff --git a/python/minimum_path_sum.py b/python/minimum_path_sum.py new file mode 100644 index 0000000..af71159 --- /dev/null +++ b/python/minimum_path_sum.py @@ -0,0 +1,19 @@ +# https://leetcode.com/problems/minimum-path-sum/ +# T: O(m*n) where n is the number of rows and m is the number of columns +# S: O(1) + +class Solution: + def minPathSum(self, grid): + rows, columns = len(grid), len(grid[0]) + + for column in range(columns - 2, -1, -1): + grid[rows - 1][column] += grid[rows - 1][column + 1] + + for row in range(rows - 2, -1, -1): + grid[row][columns - 1] += grid[row + 1][columns - 1] + + for row in range(rows - 2, -1, -1): + for column in range(columns - 2, -1, -1): + grid[row][column] += min(grid[row + 1][column], grid[row][column + 1]) + + return grid[0][0] From 1842d273259705a5626e379a1b1a7fb54de010eb Mon Sep 17 00:00:00 2001 From: sumanth_botlagunta <86908741+sumanth-botlagunta@users.noreply.github.com> Date: Thu, 30 Mar 2023 12:37:20 +0530 Subject: [PATCH 660/947] solves reducing dishes (#1402) in python --- python/reducing_dishes.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 python/reducing_dishes.py diff --git a/python/reducing_dishes.py b/python/reducing_dishes.py new file mode 100644 index 0000000..bafc396 --- /dev/null +++ b/python/reducing_dishes.py @@ -0,0 +1,17 @@ +# https://leetcode.com/problems/reducing-dishes/ +# T: O(nlogn) where n is the length of satisfaction +# S: O(1) + +class Solution: + def maxSatisfaction(self, satisfaction: List[int]) -> int: + satisfaction.sort(reverse = True) + n = len(satisfaction) + presum , res = 0, 0 + + for i in range(n): + presum += satisfaction[i] + if presum < 0: + break + res = res + presum + + return res From 6b07fe9c279d8468cf016e7a89d61bbee9f8878a Mon Sep 17 00:00:00 2001 From: sumanth_botlagunta <86908741+sumanth-botlagunta@users.noreply.github.com> Date: Thu, 30 Mar 2023 20:02:48 +0530 Subject: [PATCH 661/947] solves scramble strings (#87) in python --- python/scramble_strings.py | 46 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 python/scramble_strings.py diff --git a/python/scramble_strings.py b/python/scramble_strings.py new file mode 100644 index 0000000..35046e5 --- /dev/null +++ b/python/scramble_strings.py @@ -0,0 +1,46 @@ +# https://leetcode.com/problems/scramble-string/description/ +# T: O(n^4) where n is the number of characters in the string +# S: O(n^3) where n is the number of characters in the string + +from collections import defaultdict + +class Solution: + def isScramble(self, s1: str, s2: str) -> bool: + cache = dict() + return self.helper(s1, s2, cache) + + def helper(self, s1: str, s2: str, cache: dict) -> bool: + key = (s1,s2) + key_r = (s2,s1) + if key in cache: + return cache[key] + if key_r in cache: + return cache[key_r] + # If not cached + n = len(s1) + # Base case + if sorted(s1) != sorted(s2): + cache[key] = False + return False + if n <= 3: + cache[key] = True + return True + # split sting for comparision + count_s1 = defaultdict(int) + count_s2 = defaultdict(int) + count_s2_r = defaultdict(int) + + for i in range(1, n): + count_s1[s1[i-1]] += 1 + count_s2[s2[i-1]] += 1 + count_s2_r[s2[-i]] += 1 + + if count_s1 == count_s2: + cache[key] = self.helper(s1[0:i], s2[0:i], cache) and self.helper(s1[i:n], s2[i:n], cache) + if cache[key]: + return True + if count_s1 == count_s2_r: + cache[key] = self.helper(s1[0:i], s2[n-i:n], cache) and self.helper(s1[i:n], s2[0:n-i], cache) + if cache[key]: + return True + return False From 3b461ddfe7ae9d1ac0f619095b0279fea35c10b5 Mon Sep 17 00:00:00 2001 From: sumanth_botlagunta <86908741+sumanth-botlagunta@users.noreply.github.com> Date: Mon, 3 Apr 2023 12:50:57 +0530 Subject: [PATCH 662/947] solves Successful Pairs of Spells and Potions (#2300) --- python/successfull_pairs_of_spells_and_potions.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 python/successfull_pairs_of_spells_and_potions.py diff --git a/python/successfull_pairs_of_spells_and_potions.py b/python/successfull_pairs_of_spells_and_potions.py new file mode 100644 index 0000000..fd5ad16 --- /dev/null +++ b/python/successfull_pairs_of_spells_and_potions.py @@ -0,0 +1,8 @@ +# https://leetcode.com/problems/successful-pairs-of-spells-and-potions/editorial/ +# T: O((n + m)logm) where n is the number of spells and m is the number of potions +# S: O(m) where m is the number of potions + +class Solution: + def successfulPairs(self, spells: List[int], potions: List[int], success: int) -> List[int]: + potions.sort() + return [len(potions) - bisect_left(potions, (success + x - 1) // x) for x in spells] From 1e6f3ee4b6a6c13a270f44de58973925936b7945 Mon Sep 17 00:00:00 2001 From: sumanth_botlagunta <86908741+sumanth-botlagunta@users.noreply.github.com> Date: Mon, 3 Apr 2023 12:52:24 +0530 Subject: [PATCH 663/947] solves Number of Ways of Cutting a Pizza (#1444) in python --- python/number_of_ways_of_cutting_pizza.py | 24 +++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 python/number_of_ways_of_cutting_pizza.py diff --git a/python/number_of_ways_of_cutting_pizza.py b/python/number_of_ways_of_cutting_pizza.py new file mode 100644 index 0000000..d4fe288 --- /dev/null +++ b/python/number_of_ways_of_cutting_pizza.py @@ -0,0 +1,24 @@ +# https://leetcode.com/problems/number-of-ways-of-cutting-a-pizza/ +# T: O(k*r*c*(m+n)) where k is the number of cuts, r and c are the number of rows and columns in the pizza, and m and n are the number of rows and columns in the preSum array. +# S: O(k*r*c) where k is the number of cuts, and r and c are the number of rows and columns in the pizza. + +class Solution: + def ways(self, pizza: List[str], K: int) -> int: + m, n, MOD = len(pizza), len(pizza[0]), 10 ** 9 + 7 + preSum = [[0] * (n + 1) for _ in range(m + 1)] + for r in range(m - 1, -1, -1): + for c in range(n - 1, -1, -1): + preSum[r][c] = preSum[r][c + 1] + preSum[r + 1][c] - preSum[r + 1][c + 1] + (pizza[r][c] == 'A') + @lru_cache(None) + def dp(k, r, c): + if preSum[r][c] == 0: return 0 + if k == 0: return 1 + ans = 0 + for nr in range(r + 1, m): + if preSum[r][c] - preSum[nr][c] > 0: + ans = (ans + dp(k - 1, nr, c)) % MOD + for nc in range(c + 1, n): + if preSum[r][c] - preSum[r][nc] > 0: + ans = (ans + dp(k - 1, r, nc)) % MOD + return ans + return dp(K - 1, 0, 0) From d7b47d3e39f4ff3015f7d0ccb5b1dd623d2e1628 Mon Sep 17 00:00:00 2001 From: sumanth_botlagunta <86908741+sumanth-botlagunta@users.noreply.github.com> Date: Wed, 5 Apr 2023 02:15:01 +0530 Subject: [PATCH 664/947] solves boats to save people (#881) in python --- python/boats_to_save_people.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 python/boats_to_save_people.py diff --git a/python/boats_to_save_people.py b/python/boats_to_save_people.py new file mode 100644 index 0000000..5d795e8 --- /dev/null +++ b/python/boats_to_save_people.py @@ -0,0 +1,14 @@ +# https://leetcode.com/problems/boats-to-save-people/description/ +# T: O(nlogn) where n is the length of people +# S: O(logn) for sorting + +class Solution: + def numRescueBoats(self, people: List[int], limit: int) -> int: + people.sort() + left, right, ans = 0, len(people) - 1, 0 + while left <= right: + ans += 1 + if people[left] + people[right] <= limit: + left+=1 + right-=1 + return ans From 98d18de1ce4b33c0880b464bb85c48c2b5dcb4c7 Mon Sep 17 00:00:00 2001 From: sumanth_botlagunta <86908741+sumanth-botlagunta@users.noreply.github.com> Date: Thu, 6 Apr 2023 15:54:35 +0530 Subject: [PATCH 665/947] solves Number of closed islands (#1254) in python --- python/number_of_closed_islands.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 python/number_of_closed_islands.py diff --git a/python/number_of_closed_islands.py b/python/number_of_closed_islands.py new file mode 100644 index 0000000..88944ab --- /dev/null +++ b/python/number_of_closed_islands.py @@ -0,0 +1,30 @@ +# https://leetcode.com/problems/number-of-closed-islands/description/ +# T: O(m*n) +# S: O(m*n) + +class Solution: + def closedIsland(self, grid: List[List[int]]) -> int: + m = len(grid) + n = len(grid[0]) + visit = [[False] * n for _ in range(m)] + count = 0 + + def dfs(x: int, y: int, m: int, n: int, grid: List[List[int]], visit: List[List[bool]]) -> bool: + if x < 0 or x >= m or y < 0 or y >= n: + # (x, y) is a boundary cell. + return False + if grid[x][y] == 1 or visit[x][y]: + # (x, y) is not a valid cell to visit. + return True + visit[x][y] = True + isClosed = True + for dx, dy in [(0, 1), (1, 0), (0, -1), (-1, 0)]: + isClosed &= dfs(x + dx, y + dy, m, n, grid, visit) + return isClosed + + for i in range(m): + for j in range(n): + if grid[i][j] == 0 and not visit[i][j] and dfs(i, j, m, n, grid, visit): + count += 1 + + return count From f607b2ad4ca9146e207300528000497724495186 Mon Sep 17 00:00:00 2001 From: sumanth_botlagunta <86908741+sumanth-botlagunta@users.noreply.github.com> Date: Thu, 6 Apr 2023 15:55:52 +0530 Subject: [PATCH 666/947] solves minimise maximum of the array (#2439) in python --- python/minimize_maximum_of_array.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 python/minimize_maximum_of_array.py diff --git a/python/minimize_maximum_of_array.py b/python/minimize_maximum_of_array.py new file mode 100644 index 0000000..d9e0c27 --- /dev/null +++ b/python/minimize_maximum_of_array.py @@ -0,0 +1,12 @@ +# https://leetcode.com/problems/minimize-maximum-of-array/description/ +# T:O(n) where n is the number of elements in the array +# S:O(1) + +class Solution: + def minimizeArrayValue(self, nums: List[int]) -> int: + minimumValue = 0 + prefixSum = 0 + for i, num in enumerate(nums): + prefixSum += num + minimumValue = max(minimumValue,((prefixSum+i)//(i+1))) + return minimumValue From f9079e5208980b921d5b5472f3bf2a877186a166 Mon Sep 17 00:00:00 2001 From: sumanth_botlagunta <86908741+sumanth-botlagunta@users.noreply.github.com> Date: Fri, 7 Apr 2023 18:30:36 +0530 Subject: [PATCH 667/947] solves number of enclaves (#1020) in python --- python/number_of_enclaves.py | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 python/number_of_enclaves.py diff --git a/python/number_of_enclaves.py b/python/number_of_enclaves.py new file mode 100644 index 0000000..73f6248 --- /dev/null +++ b/python/number_of_enclaves.py @@ -0,0 +1,42 @@ +# https://leetcode.com/problems/number-of-enclaves/description/ +# T: O(m*n) +# S: O(m*n) + +from typing import List + +class Solution: + def dfs(self, x: int, y: int, m: int, n: int, grid: List[List[int]], visit: List[List[bool]]): + if x < 0 or x >= m or y < 0 or y >= n or visit[x][y] or grid[x][y] == 0: + return + visit[x][y] = True + self.dfs(x+1, y, m, n, grid, visit) + self.dfs(x-1, y, m, n, grid, visit) + self.dfs(x, y+1, m, n, grid, visit) + self.dfs(x, y-1, m, n, grid, visit) + + def numEnclaves(self, grid: List[List[int]]) -> int: + m, n = len(grid), len(grid[0]) + visit = [[False for _ in range(n)] for _ in range(m)] + + # Traverse the first and last columns. + for i in range(m): + if grid[i][0] == 1 and not visit[i][0]: + self.dfs(i, 0, m, n, grid, visit) + if grid[i][n-1] == 1 and not visit[i][n-1]: + self.dfs(i, n-1, m, n, grid, visit) + + # Traverse the first and last rows. + for j in range(n): + if grid[0][j] == 1 and not visit[0][j]: + self.dfs(0, j, m, n, grid, visit) + if grid[m-1][j] == 1 and not visit[m-1][j]: + self.dfs(m-1, j, m, n, grid, visit) + + # Count the number of unvisited land cells. + count = 0 + for i in range(m): + for j in range(n): + if grid[i][j] == 1 and not visit[i][j]: + count += 1 + + return count 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 668/947] 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 669/947] 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 670/947] 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 671/947] 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 672/947] 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 673/947] 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 674/947] 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 675/947] 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 676/947] 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 677/947] 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 678/947] 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 679/947] 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 680/947] 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 681/947] 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 682/947] 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 683/947] 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 684/947] 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 685/947] 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 686/947] 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 687/947] 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 688/947] 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 689/947] 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 690/947] 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 691/947] 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 692/947] 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 693/947] 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 694/947] 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 695/947] 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 696/947] 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 697/947] 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 698/947] 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 699/947] 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 700/947] 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 701/947] 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 702/947] 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 703/947] 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 704/947] 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 705/947] 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 706/947] 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 707/947] 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 708/947] 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 709/947] 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 710/947] 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 711/947] 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 712/947] 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 713/947] 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 714/947] 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 715/947] 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 716/947] 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 717/947] 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 718/947] 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 719/947] 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 720/947] 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 721/947] 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 722/947] 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 723/947] 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 724/947] 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 725/947] 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 726/947] 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 727/947] 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 728/947] 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 729/947] 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 730/947] 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 731/947] 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 732/947] 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 733/947] 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 734/947] 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 735/947] 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 736/947] 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 737/947] 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 738/947] 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 739/947] 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 740/947] 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 741/947] 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 742/947] 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 743/947] 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 744/947] 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 745/947] 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 746/947] 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 747/947] 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 748/947] 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 749/947] 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 750/947] 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 751/947] 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 752/947] 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 753/947] 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 754/947] 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 755/947] 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 756/947] 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 757/947] 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 758/947] 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 759/947] 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 760/947] 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 761/947] 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 762/947] 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 763/947] 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 764/947] 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 765/947] 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 766/947] 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 767/947] 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 768/947] 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 769/947] 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 770/947] 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 771/947] 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 772/947] 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 773/947] 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 774/947] 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 775/947] 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 776/947] 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 777/947] 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 778/947] 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 779/947] 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 780/947] 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 781/947] 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 782/947] 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 783/947] 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 784/947] 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 785/947] 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 786/947] 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 787/947] 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 788/947] 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 789/947] 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 790/947] 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 791/947] 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 792/947] 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 793/947] 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 794/947] 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 795/947] 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 796/947] 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 797/947] 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 798/947] 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 799/947] 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 800/947] 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 801/947] 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 802/947] 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 803/947] 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 804/947] 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 805/947] 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 806/947] 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 807/947] 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 808/947] 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 809/947] 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 810/947] 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 811/947] 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 812/947] 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 813/947] 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 814/947] 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 815/947] 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 816/947] 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 817/947] 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 818/947] 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 819/947] 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 820/947] 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 821/947] 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 822/947] 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 823/947] 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 824/947] 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 825/947] 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 826/947] 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 827/947] 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 828/947] 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 829/947] 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 830/947] 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 831/947] 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 832/947] 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 833/947] 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 834/947] 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 835/947] 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 836/947] 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 837/947] 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 838/947] 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 839/947] 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 840/947] 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 841/947] 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 842/947] 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 843/947] 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 844/947] 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 845/947] 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 846/947] 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 847/947] 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 848/947] 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 849/947] 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 850/947] 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 851/947] 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 852/947] 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 853/947] 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 854/947] 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 855/947] 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 856/947] 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 857/947] 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 858/947] 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 859/947] 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 860/947] 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 861/947] 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 862/947] 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 863/947] 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 864/947] 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 865/947] 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 866/947] 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 867/947] 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 868/947] 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 869/947] 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 870/947] 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 871/947] 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 872/947] 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 873/947] 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 874/947] 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 875/947] 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 876/947] 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 877/947] 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 878/947] 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 879/947] 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 880/947] 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 881/947] 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 882/947] 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 883/947] 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 884/947] 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 885/947] 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 886/947] 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 887/947] 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 888/947] 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 889/947] 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 890/947] 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 891/947] 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 892/947] 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 893/947] 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 894/947] 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 895/947] 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 896/947] 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 897/947] 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 898/947] 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 899/947] 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 900/947] 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 901/947] 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 902/947] 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 903/947] 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 904/947] 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 905/947] 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 906/947] 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 907/947] 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 908/947] 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 909/947] 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 910/947] 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 911/947] 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 912/947] 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 913/947] 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 914/947] 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 915/947] 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 916/947] 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 917/947] 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 918/947] 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 919/947] 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 920/947] 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 921/947] 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 922/947] 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 923/947] 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 924/947] 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 925/947] 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 926/947] 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 927/947] 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 928/947] 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 929/947] 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 930/947] 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 931/947] 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 932/947] 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 933/947] 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 934/947] 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 935/947] 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 936/947] 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 937/947] 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 938/947] 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 939/947] 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 940/947] 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 941/947] 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 942/947] 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 943/947] 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 944/947] 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 945/947] 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 946/947] 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 947/947] 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; } -} + }