-
Manacher’s Algorithm for Longest Palindromic Substring
Manacher’s Algorithm for Longest Palindromic Substring Longest Palindromic Substring has a straight-forward description [1]: Given a string s, return the longest palindromic substring in s. The goal of this article is to understand how to solve it using the tricky Manacher’s algorithm. A naive method iterates all the element and then expands from the center…
-
Algorithms | Cheat Sheet
1 Sort use case Merge sort Quick sort Heap sort Heap structure In many computer science applications, we only need to access the largest or smallest element in the dataset. A priority queue is an abstract data type, while a Heap is a data structure. Therefore, a Heap is not a Priority Queue, but a…
-
[LeetCode] Graphs
Types of graphs: Terminologies: 1 Disjoint Set 1.1 Overview of Disjoint Set Q: Given the vertices and edges between them, how could we quickly check whether two vertices are connected? The disjoint set is a data structure(others might refer to it as an algorithm), also known as union-find data structure. The primary use of disjoint…
-
[LeetCode 875] Koko Eating Bananas
When I first came across this problem, I was stuck. I could not write the solution in 20 minutus. I wondered whether it should be solved by dynamic programming, or whether it should be done by 2D state variable. Or it should be done by greedy algorithm? When I checked out the solution, I found…
-
[LeetCode] The Process of Solving Lonely Pixel I(531) and Lonely Pixel II(533)
Lonely Pixel I(531) Description Given an m x n picture consisting of black ‘B’ and white ‘W’ pixels, return the number of black lonely pixels.A black lonely pixel is a character ‘B’ that located at a specific position where the same row and same column don’t have any other black pixels. Example 1: Example 2:…