I went the editorial way!

I first recorded the last occurrence of each character in the string. Then, I iterated through the string while maintaining a window that represents the current partition. For each character, I updated the right boundary of the window to the farthest last occurrence seen so far. Once I reached the end of this window, it meant that all characters in the window were unique to it—so I closed the partition, recorded its size, and started a new one.
class Solution:
def partitionLabels(self, s: str) -> List[int]:
I started by finding the dominant element in the entire array using the Boyer-Moore majority vote algorithm, since we’re told there's exactly one dominant element. Once I had the dominant element, I went through the array while keeping a count of how many times the dominant appeared in the prefix up to the current index.
For each index i, I checked if the dominant element was dominant in both the prefix nums[:i+1] and the suffix nums[i+1:]. The first index where both parts have the dominant element is the minimum valid split index, so I returned that. If no valid split exists, I returned -1.
To solve this problem, I first flattened the grid into a single list and sorted it. Then I checked whether all differences between elements and the first element are divisible by x—if not, it's impossible to make the grid uni-value and I return -1. If not, I used the median of the list as the target value (since it minimizes the total number of absolute differences), and computed the total number of operations needed by summing up abs(value - median) // x for each value.
class Solution:
def minOperations(self, grid: List[List[int]], x: int) -> int:
To solve this, I grouped the rectangles by sorting them based on their x or y coordinates. Then, I scanned through the sorted list to find points where I could split them into three non-overlapping groups—each with at least one rectangle and no rectangle spanning across the cut. I checked both horizontal and vertical directions, and if either allowed such a split, I returned True
; if not, I returned False
.
That didn't pass all the cases which is weird and didn't find why it was like that. So I checked the editiorial and saw my mistaskes.
To solve the problem, I sorted all the meeting intervals by their start day and merged any overlapping ones to avoid double-counting days. After merging, I calculated the total number of unique meeting days by summing the length of each merged interval. Finally, I subtracted the total meeting days from the given number of days to get the count of days when the employee is available but has no meetings.
class Solution:
def countDays(self, days: int, meetings: List[List[int]]) -> int:
To solve the problem, I used Dijkstra’s algorithm to find the shortest path from node 0 to node n - 1. While doing that, I kept track of the number of ways to reach each node using a ways
array. I initialized the distance to node 0 as 0 and the number of ways to reach it as 1. As I traversed the graph using a min-heap, I updated the shortest distance to each node. If I found a shorter path, I reset the ways count; if I found an equally short path, I added to the existing count. Finally, I returned the number of ways to reach the destination node in the shortest time, modulo (10^9 + 7).
class Solution:
def countPaths(self, n: int, roads: List[List[int]]) -> int:
I perform BFS on each unvisited node to gather all nodes in a connected component. I then count the number of nodes and edges in that component. A complete component of size k
must have exactly k*(k-1)/2 edges.
class Solution:
def countCompleteComponents(self, n: int, edges: List[List[int]]) -> int: