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 October 31, 2025 17:23
The Two Sneaky Numbers of Digitville

Question

Approach

I scan the array once while keeping a set of numbers I have already seen. Whenever I encounter a number that is already in the set, it must be one of the sneaky repeated numbers, so I add it to the result list. Since there are exactly two repeats, I stop once I found both.

Implementation

class Solution:
 def getSneakyNumbers(self, nums: List[int]) -> List[int]:
@Ifihan
Ifihan / main.md
Created October 30, 2025 22:25
Minimum Number of Increments on Subarrays to Form a Target Array

Question

Approach

My approach is to track how many times the array increases. I start by setting the number of operations to the first element since that’s how many increments are needed to reach it from zero. Then, as I move through the array, I only add the positive differences between consecutive elements—because whenever a value increases compared to the previous one, that increase represents new operations needed. This gives the minimum number of operations efficiently in one pass.

Implementation

class Solution:
 def minNumberOperations(self, target: List[int]) -> int:
@Ifihan
Ifihan / main.md
Created October 29, 2025 22:00
Smallest Number With All Set Bits

Question

Approach

I realized that a number whose binary representation contains only set bits is of the form ( 2^k - 1 ) (like 1, 3, 7, 15, 31, …). So I can find the smallest such number that is greater than or equal to n. I start from 1 and keep generating numbers of this form until I find one ≥ n, then return it.

Implementation

@Ifihan
Ifihan / main.md
Created October 28, 2025 20:44
Make Array Elements Equal to Zero

Question

Approach

I start by identifying all indices where nums[i] == 0 — these are the possible starting positions. For each such index, I simulate the described process twice: once moving left and once moving right. During the simulation, I maintain a copy of the array so I can decrement values and reverse direction as required. If I exit the bounds of the array and all elements are 0, that starting position and direction count as a valid selection. I sum up all valid cases and return that count.

Implementation

class Solution:
    def countValidSelections(self, nums: List[int]) -> int:
@Ifihan
Ifihan / main.md
Created October 27, 2025 21:13
Number of Laser Beams in a Bank

Question

Approach

I scan the rows and count the number of security devices ('1') in each row. I only care about rows that contain at least one device. For every pair of consecutive non-empty rows (i.e., rows with devices and no device-containing rows between them) each device in the earlier row forms a beam with every device in the later row, so I add prev_count * curr_count to the answer and then update prev_count = curr_count. This gives the total beams in a single pass.

Implementation

class Solution:
 def numberOfBeams(self, bank: List[str]) -> int:
@Ifihan
Ifihan / main.md
Created October 26, 2025 22:52
Simple Bank System

Question

Approach

I store the balances in a zero-indexed Python list but treat account numbers as 1-indexed. For every operation I first check that the account indices are within [1, n]. For withdraw and transfer I additionally check that the source account has enough balance. All updates are done in-place, and each operation runs in constant time.

Implementation

class Bank:
@Ifihan
Ifihan / main.md
Created October 25, 2025 05:23
Calculate Money in Leetcode Bank

Question

Approach

I observe that Hercy saves money in weekly cycles. Each week starts on Monday with an increasing base amount. The first week starts with 1, the second week starts with 2, and so on. For each full week, the total is the sum of 7 consecutive numbers starting from that base. So, for w full weeks, I can compute the sum using the arithmetic series formula. For the remaining r days (less than a week), I add the first r terms of the next week's sequence.

Implementation

class Solution:
 def totalMoney(self, n: int) -> int:
@Ifihan
Ifihan / main.md
Created October 24, 2025 21:39
Next Greater Numerically Balanced Number

Question

Approach

I simply search upward from n+1 until I find a number that is numerically balanced. For each candidate number I count its digits; if any '0' appears I reject it immediately (because 0 would have to appear zero times) and otherwise I check that for every digit d present, its frequency equals d.

Implementation

class Solution:
 def nextBeautifulNumber(self, n: int) -> int:
@Ifihan
Ifihan / main.md
Created October 23, 2025 21:33
Check If Digits Are Equal in String After Operations I

Question

Approach

To solve this, I repeatedly reduced the string by replacing it with the sequence formed by taking the sum of each pair of adjacent digits modulo 10. I continued this process until only two digits remained. Then, I simply checked if those final two digits were equal—returning True if they were and False otherwise.

Implementation

class Solution:
 def hasSameDigits(self, s: str) -> bool:
@Ifihan
Ifihan / main.md
Created October 22, 2025 21:37
Maximum Frequency of an Element After Performing Operations II