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 6, 2025 18:19
Build Array from Permutation

Question

Approach

I used a simple list comprehension to construct the result array in a clean and efficient way.

Implementation

class Solution:
 def buildArray(self, nums: List[int]) -> List[int]:
@Ifihan
Ifihan / main.md
Created May 5, 2025 19:01
Domino and Tromino Tiling

Question

Approach

I used dynamic programming to build a solution bottom-up. I defined dp[i] as the number of ways to tile a 2×i board. The recurrence relation came from understanding that I can add a vertical domino (dp[i-1]), a pair of horizontal dominoes or trominoes (dp[i-2]), and more complex tromino arrangements that require tracking prior gaps using a separate variable (dp[i-3] and beyond). I initialized the base cases for n = 1, 2, 3, and iteratively built up the solution to n. To avoid overflow, I applied modulo 10^9 + 7 at every step.

Implementation

class Solution:
    def numTilings(self, n: int) -> int:
@Ifihan
Ifihan / main.md
Created May 4, 2025 22:37
Number of Equivalent Domino Pairs

Question

Approach

To solve this, I realized that each domino can be uniquely represented by its sorted tuple form — for example, [2,1] becomes (1,2). This ensures that both [1,2] and [2,1] are considered equal. I then used a dictionary to count how many times each normalized domino appears. For each count greater than 1, I computed the number of unique pairs using the combination formula count * (count - 1) // 2, and summed these up to get the final answer.

Implementation

class Solution:
@Ifihan
Ifihan / main.md
Created May 3, 2025 13:27
Minimum Domino Rotations For Equal Row

Question

Approach

When approaching this problem, I realized that only the first domino's top and bottom values could potentially be the unified value across the entire row. So I focused on checking if all dominoes can be rotated such that either tops or bottoms becomes full of just tops[0] or bottoms[0]. For each candidate, I counted how many rotations are needed to achieve this — both by rotating tops to match the candidate or bottoms to match the candidate. If either configuration works, I returned the minimum number of rotations. If not, I returned -1.

Implementation

class Solution:
    def minDominoRotations(self, tops: List[int], bottoms: List[int]) -> int:
@Ifihan
Ifihan / app.py
Last active May 3, 2025 11:22
Build a Gemini-Powered YouTube Summarizer
import os
from flask import Flask, render_template, request, jsonify
from google import genai
from google.genai import types
app = Flask(__name__)
PROJECT_ID = "build-with-vertex-ai"
@Ifihan
Ifihan / main.md
Last active May 2, 2025 18:05
Push Dominoes

Question

Approach

When solving this, I imagined the dominoes as experiencing "forces" from left and right. Each domino receives a force from the closest 'R' to its left or 'L' to its right. The closer the source, the stronger the force. I assigned a large positive value when a domino was pushed to the right ('R') and a large negative value when pushed to the left ('L'). Then I scanned the string twice:

  • Left to Right: I assigned decreasing positive forces after each 'R' and reset after 'L'.
  • Right to Left: I assigned decreasing negative forces after each 'L' and reset after 'R'.

Finally, I added the forces at each position:

@Ifihan
Ifihan / main.md
Created May 1, 2025 21:37
Maximum Number of Tasks You Can Assign
@Ifihan
Ifihan / main.md
Created April 30, 2025 21:14
Find Numbers with Even Number of Digits

Question

Approach

To solve this, I just iterated through the nums array and for each number, I counted the number of digits using either len(str(num)) or logarithmic math. If the number of digits was even, I incremented a counter.

Implementation

class Solution:
 def findNumbers(self, nums: List[int]) -> int:
@Ifihan
Ifihan / main.md
Created April 29, 2025 17:07
Count Subarrays Where Max Element Appears at Least K Times

Question

Approach

I iterated through the array with a right pointer and maintained a left pointer to denote the start of the current window. As I moved the right pointer, I tracked how many times the current max value appeared in the window.

Each time the count of the max value reached at least k, I knew that all subarrays ending at this right and starting from any index ≤ left would be valid. So I added (left + 1) to the result.

If the count of the max fell below k, I shrank the window from the left until the condition was satisfied again.

@Ifihan
Ifihan / main.md
Created April 28, 2025 21:36
Count Subarrays With Score Less Than K