I’d started to get bored of leetcode. I could not bring myself to solve another leetcode problem. After all, it did not serve any higher purpose. I wanted something else to occupy my mind — that is when I came across Jeff Erickson’s book on Algorithms : https://jeffe.cs.illinois.edu/teaching/algorithms/#book
It absolutely blew my mind! This book is clearer and better written than any other algorithm book out there! So friends and algorithm enthusiasts — let’s solve the exercises!
I will be starting a new series of posts on the book — I’m open to discussions and working together while solving the exercises! Let me know!
If you notice the problem closely — what you need is a sorted list of the array everytime. What better data structure to use than a heap?
public int connectSticks(int[] sticks) {
PriorityQueue<Integer> pq = new PriorityQueue<>()…
A string S
of lowercase English letters is given. We want to partition this string into as many parts as possible so that each letter appears in at most one part, and return a list of integers representing the size of these parts.
Input s = “ababcbacadefegdehijhklij”;
Output = [9…