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 February 12, 2025 19:09
Max Sum of a Pair With Equal Sum of Digits

Question

Approach

I start by defining a helper function digit_sum that calculates the sum of digits for a given number. Then, I create a dictionary sum_map to store the largest number encountered for each digit sum. I then iterate through the list nums, compute the digit sum for each number, and check if that digit sum already exists in sum_map. If it does, I update max_sum with the sum of the current number and the stored maximum number for that digit sum. I also update sum_map to ensure it always holds the largest value for each digit sum.

Finally, I return max_sum, which holds the largest sum found. If no valid pair is found, I return -1.

Implementation

@Ifihan
Ifihan / main.md
Created February 13, 2025 22:07
Minimum Operations to Exceed Threshold Value II
@Ifihan
Ifihan / main.md
Created February 14, 2025 22:16
Product of the Last K Numbers

Question

Approach

Prefix sum came back to kick me in the leg. I was co confused so I went to the editorial

Uploading image.png…

@Ifihan
Ifihan / main.md
Created February 15, 2025 22:06
Find the Punishment Number of an Integer

Question

Approach

Hm, I think I'm getting weak or backtracking is difficult. Well, editorial came to save me

image
@Ifihan
Ifihan / main.md
Created February 16, 2025 06:16
Construct the Lexicographically Largest Valid Sequence
@Ifihan
Ifihan / main.md
Created February 17, 2025 20:55
Letter Tile Possibilities
@Ifihan
Ifihan / main.md
Created February 18, 2025 22:18
Construct Smallest Number From DI String
@Ifihan
Ifihan / main.md
Created February 19, 2025 20:45
The k-th Lexicographical String of All Happy Strings of Length n
@Ifihan
Ifihan / main.md
Created February 20, 2025 22:16
Find Unique Binary String

Question

Approach

Still not had time to properly learn backtracking so ... editorial!

image
@Ifihan
Ifihan / main.md
Created February 21, 2025 22:26
Find Elements in a Contaminated Binary Tree