LeetCode: Contains Duplicate IIProblem: https://leetcode.com/problems/contains-duplicate-ii/ Code: class Solution: def containsNearbyDuplicate(self, nums: List[int], k: int) -> bool: # window = k seen_in_window = set() for i in range(len(nums)): ...Jan 9, 2026·2 min read
LeetCode: Missing NumberProblem: https://leetcode.com/problems/missing-number/ Code: class Solution: def missingNumber(self, nums: List[int]) -> int: n = len(nums) actual_sum = sum(nums) expected_sum = (n * (n + 1))//2 # including the missing num...Dec 21, 2025·3 min read
LeetCode: Second Largest Digit in a StringProblem: https://leetcode.com/problems/second-largest-digit-in-a-string/ Code: class Solution: def secondHighest(self, s: str) -> int: dgts = set() for ch in s: if ch.isdigit(): dgts.add(int(ch)) ...Dec 21, 2025·2 min read
LeetCode: Merge Sorted ArrayProblem: https://leetcode.com/problems/merge-sorted-array/description/ Code: class Solution: def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None: """ Do not return anything, modify nums1 in-place instead. ...Dec 21, 2025·3 min read
LeetCode: Rotate Array by OneProblem: https://www.geeksforgeeks.org/problems/cyclically-rotate-an-array-by-one2614/1 Code: class Solution: def rotate(self, arr): arr.insert(0, arr[-1]) del arr[-1] return arr # Below solution creates a new list, calle...Dec 17, 2025·2 min read
LeetCode: Check If String Is a Prefix of ArrayProblem: https://leetcode.com/problems/check-if-string-is-a-prefix-of-array/description/ Code: class Solution: def isPrefixString(self, s: str, words: List[str]) -> bool: index=0 for word in words: if not s.startswith(...Dec 16, 2025·2 min read
LeetCode: Find Sqrt(x)Problem: https://leetcode.com/problems/sqrtx/description/ Code: class Solution: def mySqrt(self, x: int) -> int: if x <= 1: return x low, high = 1, x // 2 while low <= high: mid = (low + high) // 2...Dec 16, 2025·2 min read