Skip to content

Instantly share code, notes, and snippets.

View Ifihan's full-sized avatar
🔧
Work in Progress

Ifihanagbara Olusheye Ifihan

🔧
Work in Progress
View GitHub Profile
@Ifihan
Ifihan / main.md
Created July 12, 2025 22:01
Meeting Rooms III
@Ifihan
Ifihan / main.md
Created July 12, 2025 21:58
The Earliest and Latest Rounds Where Players Compete
@Ifihan
Ifihan / main.md
Created July 10, 2025 23:02
Reschedule Meetings for Maximum Free Time II

Question

Approach

To solve this, I first calculated the duration of each meeting. My goal was to find the maximum continuous free time that can exist after rescheduling at most one meeting to a different valid time slot.

I iterated over each meeting and considered removing it from its original slot. Then, I tried inserting it into any valid gap between the remaining meetings, including at the very beginning or end of the event window. For each valid rescheduling, I recomputed the free time gaps and tracked the maximum possible value across all such reschedules.

This approach failed (557/695) so I went to the editiorial

@Ifihan
Ifihan / main.md
Created July 10, 2025 22:55
Reschedule Meetings for Maximum Free Time I
@Ifihan
Ifihan / main.md
Created July 8, 2025 22:30
Maximum Number of Events That Can Be Attended II
@Ifihan
Ifihan / main.md
Created July 7, 2025 22:39
Maximum Number of Events That Can Be Attended

Question

Approach

I first sort all the events by their starting day. This allows me to process the events in chronological order. I then simulate each day, and for every day, I keep track of all events that can still be attended using a min-heap (priority queue) to store their end days. Each day, I:

  1. Add all events starting on that day to the heap.
  2. Remove from the heap all events whose end day has passed.
  3. If there’s at least one valid event left in the heap, I attend the one with the earliest end day and move to the next day.
@Ifihan
Ifihan / main.md
Created July 6, 2025 22:06
Finding Pairs With a Certain Sum

Question

Approach

I store nums1 as-is since it’s small (up to 1000 elements) and won’t change. For nums2, which can be large, I keep a frequency map (Counter) to quickly compute the number of pairs that sum to a given total. Every time I perform an add operation, I update both nums2 and its frequency map in constant time. During a count query, I iterate through nums1 and for each value, I check how many times its complement to tot exists in nums2 using the frequency map.

Implementation

class FindSumPairs:
@Ifihan
Ifihan / main.md
Last active July 5, 2025 22:28
Find Lucky Integer in an Array

Question

Approach

I first count how many times each number appears in the array. I use a frequency map (like Python's Counter) to make this easier. Then, I go through each number and check if its frequency is equal to the number itself. If it is, I consider it a "lucky" number. While doing this, I keep track of the largest such lucky number I find. If I don't find any number that satisfies the condition, I return -1; otherwise, I return the largest lucky number found.

Implementation

class Solution:
 def findLucky(self, arr: List[int]) -> int:
@Ifihan
Ifihan / main.md
Created July 4, 2025 21:00
Find the K-th Character in String Game II
@Ifihan
Ifihan / main.md
Created July 3, 2025 18:09
Find the K-th Character in String Game I

Question

Approach

I start with the initial string word = "a". In each operation, I take the current string and generate a new string by replacing each character with its next character in the English alphabet—where 'z' wraps around to 'a'.

Once the length of the string reaches or exceeds k, I return the k-th character (1-indexed) from the resulting string.

Implementation