Used the editorial

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.
To solve the problem, I iterate through the array and identify all indices j
where the element is equal to the given key
. For each such index, I compute the range of valid indices i
that are within a distance k
of j
(i.e., |i - j| <= k
). I add each of these i
values into a set to avoid duplicates. After processing all matching indices, I convert the set to a sorted list and return it as the final result.
I start by counting all '0's since they don't affect the value and can always be included. Then, traverse from the right (least significant bit) and greedily include '1's only if their addition keeps the total binary value within k. This didn't pass all the test cases so I checked the editorial and saw the issue
class Solution:
def longestSubsequence(self, s: str, k: int) -> int: