Skip to content

Instantly share code, notes, and snippets.

View Ifihan's full-sized avatar
🔧
Work in Progress

Ifihanagbara Olusheye Ifihan

🔧
Work in Progress
View GitHub Profile
@Ifihan
Ifihan / main.md
Created July 26, 2025 22:33
Maximize Subarrays After Removing One Conflicting Pair
@Ifihan
Ifihan / main.md
Created July 25, 2025 15:53
Maximum Unique Subarray Sum After Deletion

Question

Approach

I used a sliding window technique to maintain a subarray where all the elements are unique. I kept a set called seen to quickly check for duplicates and removed elements from the left of the window if a duplicate was encountered. For each unique window, I maintained the sum and updated the maximum sum encountered so far.

It didn't work and I checked the editorial, and it was a one-liner???

@Ifihan
Ifihan / main.md
Created July 24, 2025 22:35
Minimum Score After Removals on a Tree
@Ifihan
Ifihan / main.md
Created July 23, 2025 23:08
Maximum Score From Removing Substrings

Question

Approach

I decided to always prioritize removing the more valuable pattern first—either "ab" or "ba"—depending on which of x or y is greater. I wrote a helper function remove_pattern that simulates the removal of the given pattern using a stack. It loops through each character and checks whether the top of the stack and the current character form the desired pattern. If they do, I remove the top and add the pattern’s value to the score. I run this function twice: once for the higher-value pattern and again for the other on the updated string.

Implementation

class Solution:
    def maximumGain(self, s: str, x: int, y: int) -> int:
@Ifihan
Ifihan / main.md
Created July 22, 2025 19:50
Maximum Erasure Value

Question

Approach

I used a sliding window technique with a set to keep track of the unique elements in the current window using two pointers: left and right. As I moved right through the array, I kept adding elements to a running sum and to the set. If I encountered a duplicate element (i.e., one already in the set), I slid the left pointer forward and removed elements from the set and subtracted their values from the sum until the duplicate was removed. At each step, I updated the maximum sum I could get.

Implementation

class Solution:
    def maximumUniqueSubarray(self, nums: List[int]) -> int:
@Ifihan
Ifihan / main.md
Created July 21, 2025 21:59
Delete Characters to Make Fancy String

Question

Approach

I iterated through the string character by character while building a new result string. I kept track of the last two characters in the result. If the current character is the same as the last two added characters, I skipped it because adding it would create three consecutive identical characters, which violates the "fancy" condition. Otherwise, I added the character to the result.

Implementation

class Solution:
 def makeFancyString(self, s: str) -> str:
@Ifihan
Ifihan / main.md
Created July 20, 2025 20:35
Delete Duplicate Folders in System
@Ifihan
Ifihan / main.md
Created July 19, 2025 21:48
Remove Sub-Folders from the Filesystem

Question

Approach

I first sorted the list of folders in lexicographical order. This way, all potential parent folders come before their subfolders. Then, I iterated through the sorted list and maintained a result list. For each folder, I checked whether it starts with the last added folder in the result list followed by a /. If it does, that means it's a subfolder and should be skipped. Else, I added it to the result.

Implementation

class Solution:
 def removeSubfolders(self, folder: List[str]) -> List[str]:
@Ifihan
Ifihan / main.md
Last active July 19, 2025 21:18
Minimum Difference in Sums After Removal of Elements
@Ifihan
Ifihan / main.md
Created July 17, 2025 20:44
Find the Maximum Length of Valid Subsequence II