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 June 28, 2023 17:48
Remove Duplicates from Sorted List

Remove Duplicates from Sorted List

Question on Leetcode - Easy

Approach

(high level summary)

The approach taken was to use two pointer method: one that takes account of the current value and the other to take the value ahead. Then I traversed through the linkedlist.

First, I use a while loop to iterate over each node in the linked list. It will continue until the current variable reaches the end of the list (i.e., None). Inside this while loop, another variable, temp is initialized with the next node after the current node (curr). This temp variable is used to check for duplicate values.

@Ifihan
Ifihan / main.md
Created June 29, 2023 20:54
Middle of the Linked List

Middle of the Linked List

Question on Leetcode - Easy

Approach

The approach I took was to use two pointers. One moved the normal speed, while the other went twice as fast as the first pointer.

When the faster pointer reaches the end, it returns the value (node) of the value at that time.

Code

@Ifihan
Ifihan / main.md
Created June 30, 2023 22:13
Squares of a Sorted Array

Squares of a Sorted Array

Question on Leetcode - Easy

Approach

The approach to this question looks straighforward and simple at first. I'm returning the list pf squared arrays using sorted(). Should solve better tomorrow.

Code

class Solution:
 def sortedSquares(self, nums: List[int]) -> List[int]:
@Ifihan
Ifihan / main.md
Created July 3, 2023 21:02
Find Common Characters

Find Common Characters

Question on Leetcode - Easy

Approach

My approach to this question was use a set to break down each string into a set and store their occurence to a hashmap. Then, I compare the values of each character to the length of the array.

For example, if a appears three times in the array and the length of the array is four, a is not going to be included in the result printed.

Any edge cases thought of? Nope. Not yet.

@Ifihan
Ifihan / main.md
Created July 6, 2023 15:40
Count the Number of Vowel Strings in Range

Count the Number of Vowel Strings in Range

Question on Leetcode - Easy

Approach

The question states there are two integers that serve as boundaries for the array (left and right). Taking that into condideration, we are to only search for vowels in that boundary.

What qualifies a word to be a vowel string? It starts with a vowel character and ends with a vowel character. And the vowels in the English dictionary are: a, e, i, o, and u.

To go about this, I defined a res that would serve as a counter. Then run a for loop over the array with the range being the boundaries left and right. Then I check if the current word first letter and last letter starts with any vowel. If it does, add to counter res and if it does not, pass.

@Ifihan
Ifihan / main.md
Last active July 6, 2023 16:32
Kth Distinct String in an Array

Kth Distinct String in an Array

Question on Leetcode - Easy

Approach

The appraoch used is to creates two sets, distincts and seen. The distincts set will store the unique elements of the input array arr, and the seen set will store the elements that have already been seen.

We then iterate through the input array arr. For each element num, the code checks if num is in the seen set. If it is, then the code removes num from the distincts set. Otherwise, the code adds num to both the distincts and seen sets.

After the loop has finished, the code checks if the length of the distincts set is less than the input k. If it is, then the code returns the empty string. Otherwise, the code returns the k-th element of the distincts set.

@Ifihan
Ifihan / main.md
Created July 7, 2023 12:46
Number of Students Unable to Eat Lunch

Number of Students Unable to Eat Lunch

Question on Leetcode - Easy

Approach

My first approach was to traverse through the student array and compare with the sandwiches array. If they're the same, pop the student. If it is not, remove and add to the end of the array. Continue like that until there are no matches left and then return with the length. I was left with an error, hmm. It was inacurrate. The sandwicheswere not accounted for.

Then the second approach was using a while loop and popping the students and sandwiches if they were the same. If they are not, I searched for the student in the sandwiches array and pop and return the length. It worked but I got Time Limit Exceeded.

My final approach was to use a hashmap to store 0's and 1's. I first count the number of students with each preference using a dictionary. Then, I iterate over the sandwiches, checking if there are any students remaining with the same prefer

@Ifihan
Ifihan / README.md
Created October 20, 2023 13:20
Zaycode Gists

Hey there

My name is Ifihan

@Ifihan
Ifihan / main.md
Last active January 1, 2025 22:46
Maximum Score After Splitting a String

Question

Approach

I first thought of using recursion, but it's not that deep, hehe.

Then I thought of using a two pointer approach. Here's how it goes: I first initialize two variables - one for the left and to calculate the number of 0s in the left substring as I'd traverse and the second pointer is implicit as it's the complement of the left substring.

Then, I precompute the total number of 1s, then traverse the string. In this step, I'd update the count of 0s in the left substring as I traverse from left to right. Then on the right substring, substract the counts of 1s that have been met so far from the toal numbers of 1s to get the remaining 1s.

@Ifihan
Ifihan / main.md
Created January 2, 2025 15:17
Count Vowel Strings in Ranges

Question

Approaches

Approach 1

My first approach was to map out the vowel list [a, e, i, o, u]. Then I have a res variable to store the results.

Then to check for each range in the queries list, I then extracted the ranges into li and r1 and a count variable to keep track of eligible vowels. Then I iterate with l1 and r1. For each index, I get the corresponding word words[i]. Then I do a check to know if the word starts with a vowel by comparing the first and last words against my vowel_list. Then I increase the count variable if they're satisfied. After this, I append the the count to rhe res variable. When all the queries have now been processed, return the res variable.