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 May 16, 2025 13:43
Longest Unequal Adjacent Groups Subsequence II

Question

Approach

I modeled the problem as a directed graph, where each valid pair (i, j) (with i < j) creates an edge if:

  • groups[i] != groups[j],
  • words[i] and words[j] have equal length,
  • and their Hamming distance is 1.
@Ifihan
Ifihan / main.md
Created May 15, 2025 22:55
Longest Unequal Adjacent Groups Subsequence I

Question

Approach

I started by always selecting the first word. Then, I iterated through the list, and for each word, I checked if its group differs from the group of the last selected word. If so, I added it to the result.

Implementation

class Solution:
 def getLongestSubsequence(self, words: List[str], groups: List[int]) -&gt; List[str]:
@Ifihan
Ifihan / main.md
Created May 14, 2025 19:05
Total Characters in String After Transformations II
@Ifihan
Ifihan / main.md
Created May 13, 2025 18:44
Total Characters in String After Transformations I

Question

Approach

I approached this problem by tracking how many letters of each type exist instead of the full string. Each transformation updates the counts: every z adds two a, and all others move forward in the alphabet. After repeating this process t times, the sum of all counts gives the final length.

Implementation

class Solution:
 def lengthAfterTransformations(self, s: str, t: int) -&gt; int:
@Ifihan
Ifihan / main.md
Created May 12, 2025 19:10
Finding 3-Digit Even Numbers

Question

Approach

I iterated through all 3-digit numbers from 100 to 999, ensuring they are even (i.e., last digit is even). For each candidate, I checked if it could be formed using the available digits considering their counts. I used Counter to handle duplicates correctly, ensuring I only used digits as many times as they appear. I stored valid numbers in a set to avoid duplicates and finally returned them sorted.

Implementation

class Solution:
    def findEvenNumbers(self, digits: List[int]) -> List[int]:
@Ifihan
Ifihan / main.md
Created May 11, 2025 22:50
Three Consecutive Odds

Question

Approach

I iterate through the array while maintaining a counter that tracks consecutive odd numbers. Each time I encounter an odd number, I increment the counter. If the counter reaches 3, I immediately return True. If I encounter an even number, I reset the counter to 0.

Implementation

class Solution:
 def threeConsecutiveOdds(self, arr: List[int]) -&gt; bool:
@Ifihan
Ifihan / main.md
Created May 10, 2025 22:29
Minimum Equal Sum of Two Arrays After Replacing Zeros

Question

Approach

I first calculate the current sum and count of zeroes in both arrays. Since we must replace 0's with positive integers ≥ 1, I consider the minimum possible increment for each zero. I then try to equalize the sums by appropriately choosing values for the zeros. If it’s impossible due to a mismatch in fixed parts, I return -1.

Implementation

class Solution:
    def minSum(self, nums1: List[int], nums2: List[int]) -> int:
@Ifihan
Ifihan / main.md
Created May 9, 2025 18:23
Count Number of Balanced Permutations
@Ifihan
Ifihan / main.md
Created May 8, 2025 22:44
Find Minimum Time to Reach Last Room II

Question

Approach

I tried my method today but didn't pass all my testcases so I used the editorial

image
@Ifihan
Ifihan / main.md
Created May 7, 2025 22:33
Find Minimum Time to Reach Last Room I

Question

Approach

I used the editorial because my solution (using priority queue (min-heap)) kept on failing some test cases.

image