Posts

Showing posts from June, 2024

Standard Priority Queue VI

Image
For this problem you use a priority queue to keep track of the indexes to remove later on. Also, the size of the priority queue matters here, need to be minimum otherwise it runs into memory limit exceeded. Keep in mind that the string concatenation also leads to TLE, so need to use a StringBuilder and only convert to string at the return step. Code is down below, cheers, ACC. Lexicographically Minimum String After Removing Stars - LeetCode 3170. Lexicographically Minimum String After Removing Stars Medium 100 6 Add to List Share You are given a string  s . It may contain any number of  '*'  characters. Your task is to remove all  '*'  characters. While there is a  '*' , do the following operation: Delete the leftmost  '*'  and the  smallest  non- '*'  character to its  left . If there are several smallest characters, you can delete any of them. Return the  lexicographically smallest  resulting string after remov...

The power and simplicity of IComparer IV

Image
IComparer is particularly interesting when dealing with multi-dimensional arrays. In this case, sorting a set of intervals can be tricky if done using standard merge sort or quick sort algorithms. IComparer makes the task super simple (sure behind the scenes it is using qSort, but the sorting function is very simplified in this case with IComparer). The merge of the intervals afterwards becomes a linear pass, and so is the calculation of the days without meetings. Code is down below, cheers, ACC. Count Days Without Meetings - LeetCode 3169. Count Days Without Meetings Medium 41 1 Add to List Share You are given a positive integer  days  representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array  meetings  of size  n  where,  meetings[i] = [start_i, end_i]  represents the starting and ending days of meeting  i  (inclusive). Return the count of days when the employee is...