Didn't have strength for this so editorial

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
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:
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.
class FindSumPairs:
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.
class Solution:
def findLucky(self, arr: List[int]) -> int:
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.