From 215f789e3b29004bfac3a3d41f4ea558f55cbf0e Mon Sep 17 00:00:00 2001 From: Jacklin Sibiyal <128830717+jacklinsibiyal@users.noreply.github.com> Date: Thu, 10 Oct 2024 10:38:23 +0530 Subject: [PATCH 1/6] Create contains_duplicate.py --- contains_duplicate.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 contains_duplicate.py diff --git a/contains_duplicate.py b/contains_duplicate.py new file mode 100644 index 0000000..eb20748 --- /dev/null +++ b/contains_duplicate.py @@ -0,0 +1,9 @@ +class Solution: + def containsDuplicate(self, nums: List[int]) -> bool: + seen = set() + for num in nums: + if num in seen: + return True + else: + seen.add(num) + return False \ No newline at end of file From c1e75932876985c6e25aa7125065cc733b272ecd Mon Sep 17 00:00:00 2001 From: Jacklin Sibiyal <128830717+jacklinsibiyal@users.noreply.github.com> Date: Thu, 10 Oct 2024 11:29:12 +0530 Subject: [PATCH 2/6] 2 more --- plusone.py | 9 +++++++++ twosum.py | 8 ++++++++ 2 files changed, 17 insertions(+) create mode 100644 plusone.py create mode 100644 twosum.py diff --git a/plusone.py b/plusone.py new file mode 100644 index 0000000..1e9e835 --- /dev/null +++ b/plusone.py @@ -0,0 +1,9 @@ +class Solution: + def plusOne(self, digits: List[int]) -> List[int]: + n = len(digits) + for i in range(n - 1, -1, -1): + if digits[i] < 9: + digits[i] += 1 + return digits + digits[i] = 0 + return [1] + digits \ No newline at end of file diff --git a/twosum.py b/twosum.py new file mode 100644 index 0000000..9e4ee6f --- /dev/null +++ b/twosum.py @@ -0,0 +1,8 @@ +class Solution: + def twoSum(self, nums: List[int], target: int) -> List[int]: + h = {} + for i, n in enumerate(nums): + c = target - n + if c in h: + return [h[c], i] + h[n] = i From 5b096a844f0ceba2e0e8b3370c71096f786f6abf Mon Sep 17 00:00:00 2001 From: Jacklin Sibiyal <128830717+jacklinsibiyal@users.noreply.github.com> Date: Thu, 10 Oct 2024 15:52:23 +0530 Subject: [PATCH 3/6] Create validanagram.py --- validanagram.py | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 validanagram.py diff --git a/validanagram.py b/validanagram.py new file mode 100644 index 0000000..3c5c6dd --- /dev/null +++ b/validanagram.py @@ -0,0 +1,5 @@ +class Solution: + def isAnagram(self, s: str, t: str) -> bool: + if len(s) != len(t): + return False + return Counter(s) == Counter(t) \ No newline at end of file From cdb5b2d4a37d4b3a1340b52f699f2545ef6ef8b9 Mon Sep 17 00:00:00 2001 From: Jacklin Sibiyal <128830717+jacklinsibiyal@users.noreply.github.com> Date: Sat, 12 Oct 2024 23:12:37 +0530 Subject: [PATCH 4/6] challenge --- groupanagram.py | 9 +++++++++ topk.py | 15 +++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 groupanagram.py create mode 100644 topk.py diff --git a/groupanagram.py b/groupanagram.py new file mode 100644 index 0000000..b487bcc --- /dev/null +++ b/groupanagram.py @@ -0,0 +1,9 @@ +class Solution: + def groupAnagrams(self, strs: List[str]) -> List[List[str]]: + anagramGroups = defaultdict(list) + + for word in strs: + sortedWord = ''.join(sorted(word)) + anagramGroups[sortedWord].append(word) + + return list(anagramGroups.values()) \ No newline at end of file diff --git a/topk.py b/topk.py new file mode 100644 index 0000000..e8a4a60 --- /dev/null +++ b/topk.py @@ -0,0 +1,15 @@ +class Solution: + def topKFrequent(self, nums: List[int], k: int) -> List[int]: + + frequency = Counter(nums) + buckets = [[] for _ in range(len(nums) + 1)] + + for num, freq in frequency.items(): + buckets[freq].append(num) + + result = [] + for i in range(len(buckets) - 1, 0, -1): + if buckets[i]: + result.extend(buckets[i]) + if len(result) >= k: + return result[:k] From 7cbfd4e2d4d13715d158d0ac7fae5e0b7f32b9f8 Mon Sep 17 00:00:00 2001 From: Jacklin Sibiyal <128830717+jacklinsibiyal@users.noreply.github.com> Date: Fri, 18 Oct 2024 11:19:37 +0530 Subject: [PATCH 5/6] Create product_exceptself.py --- product_exceptself.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 product_exceptself.py diff --git a/product_exceptself.py b/product_exceptself.py new file mode 100644 index 0000000..89df424 --- /dev/null +++ b/product_exceptself.py @@ -0,0 +1,14 @@ +class Solution: + def productExceptSelf(self, nums: List[int]) -> List[int]: + n = len(nums) + answer = [1] * n + prefix = 1 + for i in range(n): + answer[i] = prefix + prefix *= nums[i] + suffix = 1 + for i in range(n - 1, -1, -1): + answer[i] *= suffix + suffix *= nums[i] + + return answer \ No newline at end of file From 947dff8e5c0a1d754336f56697b7f19a35933622 Mon Sep 17 00:00:00 2001 From: Jacklin Sibiyal <128830717+jacklinsibiyal@users.noreply.github.com> Date: Fri, 18 Oct 2024 11:22:54 +0530 Subject: [PATCH 6/6] Till Day 5 --- contains_duplicate.py => Jacklin/contains_duplicate.py | 0 groupanagram.py => Jacklin/groupanagram.py | 0 plusone.py => Jacklin/plusone.py | 0 product_exceptself.py => Jacklin/product_exceptself.py | 0 topk.py => Jacklin/topk.py | 0 twosum.py => Jacklin/twosum.py | 0 validanagram.py => Jacklin/validanagram.py | 0 7 files changed, 0 insertions(+), 0 deletions(-) rename contains_duplicate.py => Jacklin/contains_duplicate.py (100%) rename groupanagram.py => Jacklin/groupanagram.py (100%) rename plusone.py => Jacklin/plusone.py (100%) rename product_exceptself.py => Jacklin/product_exceptself.py (100%) rename topk.py => Jacklin/topk.py (100%) rename twosum.py => Jacklin/twosum.py (100%) rename validanagram.py => Jacklin/validanagram.py (100%) diff --git a/contains_duplicate.py b/Jacklin/contains_duplicate.py similarity index 100% rename from contains_duplicate.py rename to Jacklin/contains_duplicate.py diff --git a/groupanagram.py b/Jacklin/groupanagram.py similarity index 100% rename from groupanagram.py rename to Jacklin/groupanagram.py diff --git a/plusone.py b/Jacklin/plusone.py similarity index 100% rename from plusone.py rename to Jacklin/plusone.py diff --git a/product_exceptself.py b/Jacklin/product_exceptself.py similarity index 100% rename from product_exceptself.py rename to Jacklin/product_exceptself.py diff --git a/topk.py b/Jacklin/topk.py similarity index 100% rename from topk.py rename to Jacklin/topk.py diff --git a/twosum.py b/Jacklin/twosum.py similarity index 100% rename from twosum.py rename to Jacklin/twosum.py diff --git a/validanagram.py b/Jacklin/validanagram.py similarity index 100% rename from validanagram.py rename to Jacklin/validanagram.py