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 / README.md
Created October 20, 2023 13:20
Zaycode Gists

Hey there

My name is Ifihan

@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 / 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 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
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 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 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 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 21, 2023 10:45
Is Subsequence

Is Subsequence

Question on Leetcode - Easy

Approach

The approach taken was to use a pointer intialized at 0, for the sequence s string. This pointer servers as a counter which the increases for every positive match against the main string. Afterwards, I traversed through the main string t and returned the a boolean of if the pointer value was the same as the length of the sequence s.

Code

class Solution:
@Ifihan
Ifihan / main.md
Created May 29, 2023 22:11
Merge Two Sorted Lists

21. Merge Two Sorted Lists

Question: Leetcode - Easy

Approach

The approach to use two pointers: The first one was a dummy ListNode() and the second is a tail. Then I traverse throught the list by appending the smaller values of either lists in the tail pointer.

Once the end of the list is gotten to, I then append the remaining nodes to the linked list.