Skip to content

Diary

DevGod

#Leetcode 904, the rules of picking unique types of fruit to place into two baskets can be reworded as find the largest sliding window in the given array containing only two unique elements. For example, [1,1,2,2,1,1,2] valid, [1,2,3] would be invalid, #JS #LeetCode

Read More
8/2/2025

DevGod

#Leetcode 118, building a pascal triangle with bottom-up DP matrix array. Actually, super easy revisiting this problem with the animated pascal triangle gif they give you in the problem details #JS #DynamicProgramming

Read More
7/30/2025

DevGod

#Leetcode 2044, just used a #backtracking #recursive function to do subsets, but only keeping track of the ored result of the subsets. Greedily use a reduce function to find the max or of everything in the given array #JS #InterviewPrep #CompSci

Read More
7/26/2025

DevGod

#Leetcode 2210, finding hills and valleys by just checking for sign changes in a messy way. The greedy trick is not giving a hoot about sign changes from positive to zero, neg to zero, or zero to zero changes to avoid overcounting #JS #Arrays

Read More
7/25/2025

DevGod

#Leetcode 3487, make the nums unique values with a set, filter out all elements below zero, reduce to find the sum, if sum is zero, meaning all nums could have been removed, an all negative array, return the max single element of nums, else return sum #JS

Read More
7/24/2025

DevGod

#Leetcode 1717, Greedily checking for the high scored ‘ab’ or ‘ba’ pairs using current counts of a & b chars as I iterate through the string. In the event I reach the end of a given string, or chars != a or b, I add the smaller score of lower scored ‘a or b’ pairs #JS #Greedy

Read More
7/21/2025

DevGod

#Leetcode 1695, a sliding window x a JavaScript Set to keep track of unique elements x a running score of numbers inside the sliding window x an answer variable holding the largest seen sum value, this was an easy medium in a while #SlidingWindow #HashSet #Sums #JS

Read More
7/20/2025

DevGod

#Leetcode 1957, just a regular expression to find groups of 3 or more consecutive chars, then a #JS replace to convert the 3 or more group with just two of the same char. Still working on yesterday’s hard problem, but at least today’s is very easy.

Read More
7/19/2025

DevGod

#Leetcode 1233, this year I used a Trie like datastructure to insert words only if they dont encounter a previous prefix of a folder path. Greedily sort the folder paths Lexi graphically & by length. This means shorter folder paths are more likely to be parent folder paths

To insert first. Last year I actually did a more optimal solution without the custom Trie data structure by just using sorting & #JS ‘s builtin startsWith() method. The takeaway is Trie #DSA is funny for string inserting in a tree like way & prefixs, but also use more mem time

Read More
7/17/2025

DevGod

#Leetcode 3202, 2d DP to find nums%k as our current value, and then 0 to k as potential past values that could be paired. For example, we could have 1,2,1,2, or 1,3,1,3, or 1,1,1,1 ect. Using this DP matrix lets us check lengths of all previous potential alternating paths #JS

Read More
7/15/2025

DevGod

#Leetcode 3201, the main paths to form array subsequences are all odds, all evens, odd even odd, or even, odd, even… I use #DP to find the max length of alternating parity subsequences. At the end, I just return the max of the alternating paths, or the odd even counts. #JS

Other notes, odd+odd=even, even+even=even, so subseqs of the same parity are possible odd+even = odd, even+odd=even, so we can also have subseqs of alternating parity. So our odd/even counts, & DP finding the largest path of alternating is covered

Read More
7/14/2025

DevGod

#Leetcode 1290, finally an easy problem after the two hard daily problems in a row. Just traverse the linkedList whilst using arithmetic shift left << and OR ing the head value to the end. Return the ans #JS #Bitwise #ComputerScience

Read More
7/12/2025

DevGod

#Leetcode 1751, using Lodash’s sortedLastIndex to binary search for the next attenable event. The first start time after the previous event’s end time. Then using bottom up #DP to keep track of the max sum. Since only previous and current rows needed, I saved some memory as well

Bottom up DP with just two arrays to keep track of previous best sums Binary search to find next attenable events Sorting by start and end times to perform said binary search Excallidraw to make sense of everything

Read More
7/7/2025

DevGod

#Leetcode 1353 For array of [start,end] time pairs for events, we use a minHeap to keep track of the events, sorted by start time. Using a day counter, we enqueue valid events into another minPQ, sorted by end times. Whenever we can pop from the end minPQ, we add to the score #JS

Code ended up pretty messy, so I made a excallidrawing, also messy, to try and explain my double heap / PQ thought process, Enjoy

Read More
7/5/2025

DevGod

#Leetcode 1865, because nums1 array is only 1k elements at most, we can use nums 2 as a freqency map. Count method can then be a 1k element loop at worst. Add method can just reduce the previous freqs, and increment the new freqs from adding val to nums2. #JS #Hashmap #Design

Read More
7/4/2025

DevGod

#Leetcode 1394, #JS #Lodash

_.countBy() to generate the freq map

_.toPairs() to go from Object to array of pairs

.filter() to filter only where key = freq

.sort() to sort in descending order

?. to prevent undefined error

?? to return -1 if no lucky num, else return the lucky num

Read More
7/3/2025

DevGod

#Leetcode 3330. To find the number of intended words Alice wanted, we can just sliding window through our string, finding consecutive letter pairs and adding 1 to our answer. Alice AT MOST ONCE dupe types for some amout of chars. +1 at the end to include the orginal word #JS

Read More
6/29/2025

DevGod

#Leetcode 594, already this solved in JS so I decided to brush my rusty Java21 skills. Couldn’t remember the Java _.countBy lodashJS eqivlent, so I just went with a binary search aproach instead. While loop to find the last element, then returning max range #Java #programminglife

Read More
6/28/2025

DevGod

#Leetcode 1498, Used lodash’s builtin binary searching method sortedLastIndex -1 to get the rightmost max number of the array, after sorting the array. Then I use this 2**R-L exponential to get number of subseqs. Used abunch of bigInts to handle large numbers. #JS #WebDev

Read More
6/27/2025

DevGod

#Leetcode 2099, easy daily problem, just using a min priority queue, since if we go over the k elements limit, we want to dequeue the smallest element. This leaves us with K largest elements at the end. We then just have to sort and map back to the number using the indexs. #JS

Read More
6/26/2025

DevGod

#Leetcode 2311, very messy solution but still works well. Main idea is to build a subseq respecting the 32 bit limit of JS bitwise. We build left to right, then if we run into an invalid subseq we greedily remove ones until it works, while keeping track of count + leading zeros

Read More
6/24/2025

DevGod

#Leetcode 2200, an easy daily problem solve using a set() to avoid duplicates, as well as just some min and maxs to prevent the algorithm from going out of bounds. At the end we just convert the hashset back to an array. #Javascript #JS #NodeJS

Read More
6/22/2025

DevGod

#Leetcode 2081, I choked on this daily so needed to see the editorial. Thought I would get away with using an OEIS template for finding the palindrome number seq, but just time limited myself on this hard problem. Also whomever wrote the leetcode editorial cheated lmao O(1)

Read More
6/21/2025

DevGod

#Leetcode 2138, very easy #Daily problem by just Lodash’s builtin chunk function, then editing the last group to have the fill char, then returning the mapped with all char arrays in chunk converted into substrings #Js #Lodash #Coding

Read More
6/20/2025

DevGod

#Leetcode 2294, sorting the given array to do a #Greedy trick without storing noncontinuous subseqs, just ans++ every time we get a diff >= K. We are counting how many ‘cuts’ we can make in our sorted array, returning cuts+1. #JS #Sorting #Javascript

Read More
6/18/2025

DevGod

#Leetcode 3443, at first struggled cause I thought it was max final ending dist, instead of the max dist at any point by changing K dirs. Used a freq map to keep track of dists, then use 2*k because by cancelling out pairs like ‘NS / EW’, I can add 2 to my dist #JS #Hashmap

Read More
6/18/2025

DevGod

#Leetcode 2966, Greedily sorting then using lodash chunk function for splitting the array into a matrix of subarrays of length 3. If I find a chunk breaking the rules of a distance greater then K, I return an empty array instead. Else I returned the chunked version of the array

Read More
6/16/2025

DevGod

#Leetcode 1432, a sequel to yesterday’s problem. The big catch is we can NOT have any leading zeros in our converted Max & Min. Finding Max is the same, change first non 9 digit to 9s. Min is trickier, as we forloop to ensure we dont convert the string to value with leading zeros

Read More
6/13/2025

DevGod

#Leetcode 2566, pretty easy problem, just converting the numbers to strings, then max is the first non 9 most significant digit (MSD) replaced all with 9. The min is converting the first MSD to 0 with replace all. Returning the max and min converted back to JS Number #javascript

Read More
6/12/2025

DevGod

Leetcode 2616 was super tricky until I finally saw that there was only one greedy way to sort & find the differences of everything to solve the minified maximum pairs rule. I needed was binary search to find the min max of P pairs. Zero pairs = return 0 max :)

Read More
6/11/2025

DevGod

Leetcode 2929 Distribute Candies Among Children II. A rare daily solve in PY instead of JS, just for the ease of the builtin comb function. Broke my brain for a while before remembering Inclusion Exclusion Jutsu. Enjoy my messy chicken scratch code.

Read More
5/30/2025

DevGod

#Leetcode 909 Snakes and Ladders. Messy spotToCord function to convert a board spot to cords for checking if snake or ladder. Breadth First Search to search for a path to the N^2 while keeping track of the dice rolls needed to get there. Returning either -1 or dice rolls

Read More
5/29/2025

DevGod

Leetcode 2359. Solved today’s daily using a DFS function to fill my memo matrix with node distances from the root node. I ran this DFS for each given input nodes. Return -1 if no path connection, else return minimal max distance found using memo matrix

Read More
5/28/2025