Skip to content

Instantly share code, notes, and snippets.

View semijacks's full-sized avatar

Semilore Idowu semijacks

View GitHub Profile
@semijacks
semijacks / merge_triplets_to_form_target_triplet.py
Created March 29, 2026 21:37
1899. Merge Triplets to Form Target Triplet
class Solution:
def mergeTriplets(self, triplets: List[List[int]], target: List[int]) -> bool:
mask = 0
for t in triplets:
if all(t[i] <= target[i] for i in range(3)):
for i in range(3):
if t[i] == target[i]:
mask |= (1 << i)
@semijacks
semijacks / hand_of_straights.py
Created March 28, 2026 22:44
846. Hand of Straights
class Solution:
def isNStraightHand(self, hand: List[int], groupSize: int) -> bool:
if len(hand) % groupSize:
return False
count = {}
for n in hand:
count[n] = 1 + count.get(n, 0)
minHeap = list(count.keys())
@semijacks
semijacks / gas_station.py
Created March 27, 2026 22:03
134. Gas Station
class Solution:
def canCompleteCircuit(self, gas: List[int], cost: List[int]) -> int:
if sum(gas) < sum(cost):
return -1
total_tank = 0
start_index = 0
for i in range(len(gas)):
total_tank += gas[i] - cost[i]
@semijacks
semijacks / jump_game_II.py
Created March 26, 2026 22:47
45. Jump Game II
class Solution:
def jump(self, nums: List[int]) -> int:
jumps = 0
current_jump_end = 0
farthest_reach = 0
for i in range(len(nums) - 1):
farthest_reach = max(farthest_reach, nums[i] + i)
if i == current_jump_end:
@semijacks
semijacks / jump_game.py
Created March 25, 2026 22:51
55. Jump Game
class Solution:
def canJump(self, nums: List[int]) -> bool:
goal = len(nums) - 1
for i in range(len(nums) - 1, -1, -1):
if nums[i] + i >= goal:
goal = i
return True if goal == 0 else False
@semijacks
semijacks / maximum_subarray.py
Created March 24, 2026 21:59
53. Maximum Subarray
class Solution:
def maxSubArray(self, nums: List[int]) -> int:
max_sum, curr_sum = nums[0], nums[0]
for num in nums[1:]:
curr_sum = max(num, curr_sum + num)
max_sum = max(max_sum, curr_sum)
return max_sum
@semijacks
semijacks / minimum_interval_to_include_each_query.py
Created March 23, 2026 22:48
1851. Minimum Interval to Include Each Query
class Solution:
def minInterval(self, intervals: List[List[int]], queries: List[int]) -> List[int]:
intervals.sort()
sorted_queries = sorted([(q, i) for i, q in enumerate(queries)])
minHeap = []
res = [0] * len(queries)
i = 0
for q, original_idx in sorted_queries:
@semijacks
semijacks / meeting_rooms.py
Created March 22, 2026 21:19
253. Meeting Rooms II
"""
Definition of Interval:
class Interval(object):
def __init__(self, start, end):
self.start = start
self.end = end
"""
class Solution:
def minMeetingRooms(self, intervals: List[Interval]) -> int:
@semijacks
semijacks / meeting_rooms.py
Created March 21, 2026 21:01
252. Meeting Rooms
"""
Definition of Interval:
class Interval(object):
def __init__(self, start, end):
self.start = start
self.end = end
"""
class Solution:
def canAttendMeetings(self, intervals: List[Interval]) -> bool:
@semijacks
semijacks / non_overlapping_intervals.py
Created March 20, 2026 22:36
435. Non-overlapping Intervals
class Solution:
def eraseOverlapIntervals(self, intervals: List[List[int]]) -> int:
res = 0
intervals.sort(key = lambda interval: interval[0])
prev = intervals[0]
for start, end in intervals[1:]:
if start < prev[1]:
res += 1
prev[1] = min(prev[1], end)