gabby's Profile

gabby's avatar

gabby

@gabby1090
Herald IV 280 XP
Member since September 2026
🔥 9
Day streak
9
Days checked in
1
Huddle
❓ What did you accomplish? | ✅ Work on at least one LeetCode problem per day
💬 class Solution:
def minEatingSpeed(self, piles: list[int], h: int) -> int:
left = 1
right = max(piles)
9
2
❓ What did you accomplish? | ✅ Work on at least one LeetCode problem per day
💬 class Solution:
def searchRange(self, nums: list[int], target: int) -> list[int]:
first = -1
left = 0
right = len(nums) - 1

# Record each match and keep searching left for an earlier one.
while left <= right:
mid = left + (right - left) // 2
if nums[mid] < target:
left = mid + 1
elif nums[mid] > target:
right = mid - 1
else:
first = mid
right = mid - 1
8
3
❓ What did you accomplish? | ✅
💬 Streak protected by freeze
7
❓ What did you accomplish? | ✅ Work on at least one LeetCode problem per day
💬 class Solution:
def search(self, nums: list[int], target: int) -> int:
"""Find target in O(log n) time using O(1) extra space."""
left = 0
right = len(nums) - 1

# Any possible match is inside the inclusive range [left, right].
while left <= right:
mid = (left + right) // 2
value = nums[mid]

if value == target:
return mid
if value < target:
left = mid + 1
else:
right = mid - 1

return -1
7
1
❓ What did you accomplish? | ✅ Work on at least one LeetCode problem per day
💬 class Solution:
def subarraysDivByK(self, nums: list[int], k: int) -> int:
"""Count nonempty contiguous subarrays whose sum is divisible by k.

nums may contain negative numbers and zeros; k is positive.
Time: O(n + k). Extra space: O(k).
"""
# Equal prefix remainders mean their difference is divisible by k.
seen = [0] * k
seen[0] = 1 # The empty prefix has remainder zero.
remainder = 0
count = 0

for num in nums:
# Python's modulo with positive k also handles negative sums.
remainder = (remainder + num) % k
count += seen[remainder]
# Record this prefix after counting to exclude empty subarrays.
seen[remainder] += 1

return count
6
1
❓ What did you accomplish? | ✅ Work on at least one LeetCode problem per day
💬 class Solution:
def findMaxLength(self, nums: list[int]) -> int:
first_seen = {0: -1}
balance = 0
best = 0
get = first_seen.get
for i, num in enumerate(nums):
balance += 1 if num else -1
earlier = get(balance)

if earlier is None:
first_seen[balance] = i
else:
length = i - earlier
if length > best:
best = length
return best
5
1
❓ What did you accomplish? | ✅ Work on at least one LeetCode problem per day
💬 class Solution:
def pivotIndex(self, nums: list[int]) -> int:
"""Return the leftmost index with equal sums on either side, or -1.

The pivot itself is excluded from both sums.
At either end of the array, the empty side has a sum of zero.
"""
# loop nums for O(n) while keep track for left_sum
left_sum = 0
right_sum = sum(nums)
for i in range(len(nums)):
right_sum -= nums[i]
if left_sum == right_sum:
return i
else:
left_sum += nums[i]

return -1
4
3
❓ What did you accomplish? | ✅ Work on at least one LeetCode problem per day
💬 class NumArray:
def __init__(self, nums: list[int]):
"""Initialize your data structure here."""
self.nums = nums
self.prefix = [0] * (len(self.nums) + 1)
for i in range(0, len(nums)):
self.prefix[i + 1] = self.nums[i] + self.prefix[i]

def sumRange(self, left: int, right: int) -> int:
"""Return the sum of nums[left] through nums[right], inclusive."""
return self.prefix[right + 1] - self.prefix[left]
3
2
❓ What did you accomplish? | ✅ Work on at least one LeetCode problem per day
💬 class Solution:
def maxArea(self, height: list[int]) -> int:
if not height:
return 0
# area = (right - left) * min ( height[right], height[left])
left = 0
right = len(height) - 1
max_area = 0
while left < right:
area = (right - left) * min(height[right], height[left])
if area > max_area:
max_area = area
# move shorter inward
if height[left] > height[right]:
right = right - 1
else:
left = left + 1
return max_area
2
7
❓ What did you accomplish? | ✅ Work on at least one LeetCode problem per day
💬 class Solution:
def removeDuplicates(self, nums: list[int]) -> int:
if not nums:
return 0
read_pnt = write_pnt = 0
for read_pnt in range(0, len(nums)):
if nums[read_pnt] > nums[write_pnt]:
write_pnt += 1
nums[write_pnt] = nums[read_pnt]
return write_pnt + 1
1
5
Sign up free Log in