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 December 21, 2025 22:50
Delete Columns to Make Sorted II

Question

Approach

I process the strings column by column from left to right. I keep track of which adjacent string pairs are already confirmed to be in correct lexicographic order.

For each column:

  • I check all unconfirmed adjacent pairs.
  • If any pair violates lexicographic order (strs[i][c] > strs[i+1][c]), I must delete this column.
@Ifihan
Ifihan / main.md
Last active December 21, 2025 23:01
Delete Columns to Make Sorted

Question

Approach

I iterate column by column. For each column, I compare characters from top to bottom. If I find any row where the character is smaller than the one above it, the column is not lexicographically sorted, so I count it as a deletion and move to the next column.

Implementation

class Solution:
 def minDeletionSize(self, strs: List[str]) -> int:
@Ifihan
Ifihan / main.md
Created December 19, 2025 22:46
Find All People With Secret
@Ifihan
Ifihan / main.md
Created December 18, 2025 22:58
Best Time to Buy and Sell Stock using Strategy

Question

Approach

I first compute the original profit as a baseline. Since I’m allowed at most one modification, I reframe the problem as: what is the maximum additional gain I can get by replacing any length-k subarray with a fixed pattern — first k/2 days contribute 0, last k/2 days contribute +prices[i]. For every possible window of length k, I compute the delta profit: (new contribution of the window) − (original contribution of the window). To do this efficiently, I use prefix sums:

  • one prefix sum for the original profit contributions strategy[i] * prices[i]
@Ifihan
Ifihan / main.md
Created December 17, 2025 22:59
Best Time to Buy and Sell Stock V
@Ifihan
Ifihan / main.md
Created December 16, 2025 17:48
Maximum Profit from Trading Stocks with Discounts
@Ifihan
Ifihan / main.md
Created December 15, 2025 21:57
Number of Smooth Descent Periods of a Stock

Question

Approach

I scan the array once while tracking the length of the current smooth descent streak. If prices[i] == prices[i-1] - 1, the streak continues and I increment its length; otherwise, I reset the streak length to 1. At each index, I add the current streak length to the answer because every prefix of the current streak forms a valid smooth descent period ending at that day. This way, all single-day and multi-day valid periods are counted in one pass.

Implementation

class Solution:
 def getDescentPeriods(self, prices: List[int]) -> int:
@Ifihan
Ifihan / main.md
Created December 14, 2025 22:30
Number of Ways to Divide a Long Corridor
@Ifihan
Ifihan / main.md
Created December 13, 2025 22:32
Coupon Code Validator

Question

Approach

I iterate through all coupons and keep only those that satisfy all validity rules: the coupon must be active, its business line must be one of the allowed categories, and its code must be non-empty and contain only alphanumeric characters or underscores. While filtering, I group valid coupon codes by their business line. Finally, I output the result by traversing the business lines in the required fixed order and appending the codes in lexicographical order within each category.

Implementation

class Solution:
    def validateCoupons(self, code: List[str], businessLine: List[str], isActive: List[bool]) -> List[str]:
@Ifihan
Ifihan / main.md
Created December 12, 2025 22:57
Count Mentions Per User

Question

Approach

I simulate events in increasing timestamp order and, for events sharing a timestamp, I process all OFFLINE events before MESSAGE events (because status changes are applied before messages at the same time). I keep an offline_until time for each user (the time they become online again); a user is online at time T iff T >= offline_until[user]. On an OFFLINE event at time t for user id I set offline_until[id] = t + 60. On a MESSAGE event at time t I parse the mentions string token-by-token:

  • ALL increments every user's count (offline or online).
  • HERE increments the count for every user currently online at time t.
  • idX increments user X (count each occurrence; duplicates count separately).