Skip to content

Instantly share code, notes, and snippets.

View steph-crown's full-sized avatar
💻
Open to work

Stephen Emmanuel steph-crown

💻
Open to work
View GitHub Profile
@steph-crown
steph-crown / me.md
Created January 17, 2026 15:11
3047. Find the Largest Area of Square Inside Two Rectangles

Question

How I Solved It?

This was a classic Geometry problem. All I needed to do was in three steps:

  • Initialize a maxArea value
  • Compare every rectangle with one another (a nested loop)
  • For each rectangle pair, Check if they intersect (the minimum of the rights minus the maximum of the lefts > 0)
  • If intersects, find the largest possible square (square of the smaller side of the intersection boundary)
  • Update maxArea with the maximum of this value in previous step and maxArea
@steph-crown
steph-crown / me.md
Last active January 15, 2026 08:26
2943. Maximize Area of Square Hole in Grid

Question

How I Solved It

  • After some thinking, it became clear that my focus shouldn't be on the grid, but on those bars hBars and vBars that can be removed from the grid
  • I needed to find the maximum number of consecutive bars that can be removed from hBars, such that the same number can be removed from vBars.
  • It doesn't mater the position of the bars in the grid. As long as they're consecutive and the same number of horizontal and vertical bars is removed, you'll definitely form a square
  • So I got started. I created a reusable function maxConsecutives that finds the max number of consecutive bars in a bars array, ensuring we can't remove the bars at the edges cos they'll be useless to our goal of finding bordered squares
  • Then I called this function with hBars and vBars, picked the minimum of both return values, added by 1 and squared.
  • I added by 1 because whe
@steph-crown
steph-crown / me.md
Created January 8, 2026 07:59
1458. Max Dot Product of Two Subsequences

Question

This question is a confirmation that I need to take a separate, dedicated short course on dynamic programming.

With help from solutions on YouTube though, I was able to get this:

function maxDotProduct(nums1: number[], nums2: number[]): number {
    const m = nums1.length;
 const n = nums2.length;
@steph-crown
steph-crown / me.md
Created January 7, 2026 08:29
1339. Maximum Product of Splitted Binary Tree

Question

The Hint helped me with this one.

Screenshot 2026-01-07 at 9 25 55 AM

How I Solved It?

  • I calculated the sum for each node, and using what was stated in the hint, for each node, I multiplied its sum with the sum of the complement of the node. Then I found the maximum of all such products.
  • The dilemma was now how to get the totals of each node in an array. So I created a sumInOrder function to that, within the root function so it could update the totals array in the main function.
@steph-crown
steph-crown / me.md
Created January 6, 2026 12:27
1161. Maximum Level Sum of a Binary Tree

Question

This problem was more about understanding the binary tree data structure than it was about thinking of some algorithm to use. I used TypeScript for this one.

How I Solved It

  • The idea was simple. Initialize a maxSum to -Infinity
  • Then, find the sum, levelSum for each levels and update maxSum to this levelSum if levelSum is greater
  • Finally return maxSum
  • The only thing I had to think of was how to traverse the tree in a way that gave me all the nodes at a level in a single loop cycle so I could add them.
  • I used breath-first search (BFS) to accomplish this
@steph-crown
steph-crown / me.md
Created January 5, 2026 09:58
1975. Maximum Matrix Sum

Question

This is one of those problems where the question is C. Ronaldo (or L. Messi, depending on your cup of tea), and the solution is ... J. Lingard.

I knew this was a greedy problem and I just needed to find a pattern to be able to make a valid assumption about the array without having to do individual checks between adjacent elements. It took me a while, but a comment from consistentNotMotivated lit all the lightbulbs in my head. See comment below:

Screenshot 2026-01-05 at 10 45 19 AM

How I Solved It

Well, it's clear from the comment referenced above. In more straightforward terms,

@steph-crown
steph-crown / main.md
Created January 4, 2026 16:09
1390. Four Divisors

Question

I admit, I checked the hint before getting started, and I saw the hint that You only need to loop to the square root of a number to find its divisors. To be fair, I think I would have figured that out myself after observing the patterns (winks twice).

How I Solved It

  • After confirming the square root theory, the solution became so obvious and I wondered if there's was a hidden twist that could have made this question MEDIUM level rather than EASY.
  • Anyways, I solved by looping throughn the array, and for each number, I start from 1 up to the its square root to find the divisors.
  • Then if the divisor count is more than 4, I add them to the sum
  • Finally, I return the sum
  • And it worked, wow. So no hidden twists. Boring.
@steph-crown
steph-crown / me.md
Created January 3, 2026 10:09
217. Contains Duplicate

Problem

Did You Know :)?

  • This was my easiest of the year so far.

How I Solved It

  • It was immediately clear what I needed to do
  • Loop through, store the count in a hashmap, and once any count crossed 1, return true, else return false at the end of the loop
  • Then I remembered I had seen something similar before, the day before. See here. And I remembered that there was an even sleeker way to do this with a hashset since we don't care about the counts and we just want to know the item that occurs more than once.
  • With a hashset, i just need to check if the item already exists before, then return true
@steph-crown
steph-crown / me.md
Created January 3, 2026 09:31
1411. Number of Ways to Paint N × 3 Grid

Problem

This was one of those problems that you need to take your time to understand and find a pattern

How I Solved It

  • I started by trying to find the number of possible combinations for each row. I quickly calculated the first row as having 12 possible combinations, that is 3 uniques in first cell, multiplied by 2 uniques in second cell and 2 uniques in third cell. Second and third cells have 2 uniques each because they mustn't take the color directly to their left. This means there are 2 left for each
  • After figuring this out, finding a general pattern for subsequent rows proved more difficult than I envisaged, due to the dependence of each cell on both the pattern in the row above it and the selected color in the cell to its left
  • After about 30 minutes of coming close to figuring something out, I conceded and checked YouTube to see if I could find an explanation. Luckily I found
@steph-crown
steph-crown / me.md
Created January 2, 2026 22:12
961. N-Repeated Element in Size 2N Array

Problem

How I Solved It

  • This was very straightforward. It was immediately obvious that I needed to just find the number that occurs most in the list. I just had to use a hashmap to store counts and get the largest
  • I observed even further that I didn't need to wait to count everything in the list. As I add the counts to the map, once I encountered a number with count of n/2, that's our guy.
  • Then something even more interesting clicked. The question says there are 2 * n numbers and one number occurs n times. This means there is only space for n more numbers. But then it says there are n + 1 unique numbers. This means that, beyond the number that occurs n times, there are n more numbers in the list. It follows therefore that, these other n numbers occur exactly one time each. Therefore if we can find a number occuring more than once, that's our guy.
  • I didn't need to