Skip to content

Instantly share code, notes, and snippets.

View Ephraimiyanda's full-sized avatar

Ephraim Iyanda Ephraimiyanda

View GitHub Profile
@Ephraimiyanda
Ephraimiyanda / main.md
Last active January 26, 2026 01:06
Mun Stack

Approach

  1. minStack always stores the current minimum.
  2. push to minStack only if it’s a new minimum.
  3. pop from minStack only if ive removed the minimum.

Complexity

  • Time complexity:O(1)

  • Space complexity:O(N)

@Ephraimiyanda
Ephraimiyanda / main.md
Created January 24, 2026 22:48
Sort Colors

Question

Intuition

immediately i saw the question my head went to a buble sort

Approach

  1. An intertwined loop is created and in that loop the number and its previous number is checked and are swapped based on their size.
  2. the algorithm keeps swapping the numbers till they are eventually all sorted in ascending or descending order.

Complexity

  • Time complexity: O(N^2)
@Ephraimiyanda
Ephraimiyanda / main.md
Created January 24, 2026 22:18
Search Insert Position

Approach

  1. I check if the number is the target. if it is i return the index of the number.
  2. if nums[i] is bigger than the target that means the target didnt exist in the previous number for its index to be returned so i return the index of the previos number of where the target would have been.
  3. if the target is larger than all the numbers i return the length of the arrar because that would be its index.

Complexity

  • Time complexity:O(N)

  • Space complexity:O(1)

@Ephraimiyanda
Ephraimiyanda / main.md
Created January 23, 2026 23:22
Find First and Last Position of Element in Sorted Array

Question

Approach

  1. the numbers are looped through to check for numbers that are the target.
  2. the index of the numbers are then added to an array.
  3. since we are looking for the range , the minimum and max value of the indexes are returned

Complexity

  • Time complexity:O(N)
@Ephraimiyanda
Ephraimiyanda / main.md
Created January 23, 2026 14:17
Majority Element

Approach

  1. Create a unique array without repeating numbers to avoid.
  2. Loop thruogh the unique array and filter the orignal array using numbers in unique array.
  3. if the the number of a particular number that was filtered is greater than n/2 it returns the unique number.

Complexity

  • Time complexity: O(N^2)

  • Space complexity: O(N)

@Ephraimiyanda
Ephraimiyanda / main.md
Created January 21, 2026 00:05
Merge Intervals

Approach

  1. Pointers are assigned to track the start and end values of the interval groups.
  2. if there is not more than 1 interval group i return the interval array.
  3. The values in the interval groups are sorted based on the their size so i can check accurately if adjacent values of the interval groups overlap.
  4. A loop is created to check if the interval values overlap.if they do ,they are merged and added to the array to be returned. then i move forward and check if the new merged interval overlaps again, if it doesnt i add it to the array to be returned like that.

Complexity

  • Time complexity:O(Nlogn)

  • Space complexity: O(N)

Question

Approach

  1. I created a map to store number combinations that sum up to 0.
  2. loop through the numbers but i stop early since im adding 3 numbers and dont want to go out of bounds.
  3. pointers are assigned to track the numbers being addded.
  4. if a set of numbers that are equal to 0, do not exist in tha mapthe numbers are added to the result array.

Complexity

  • Time complexity:O(N^2)
@Ephraimiyanda
Ephraimiyanda / main.md
Created January 19, 2026 00:27
Best Time to Buy and Sell Stock II

Approach

  1. A loop is created to check if a price is larger than it previous .
  2. The profit between the prices is calculated and added to the maxProfit.

Complexity

  • Time complexity:O(N)

  • Space complexity:O(1)

Code

@Ephraimiyanda
Ephraimiyanda / main.md
Created January 18, 2026 23:38
Reverse Words in a String

Question

Approach

  1. The string us turned into an array.
  2. All the spaces in the array are removed in a loop.
  3. The words are the added into an array from the last to the first so that its in a reversed order.
  4. I use the join operator to add words together with single spaces

Complexity

  • Time complexity: O(N)
@Ephraimiyanda
Ephraimiyanda / main.md
Created January 17, 2026 23:09
Valid Palindrome

Approach

  1. If the string is empty or has length 0 return true.
  2. I created a loop to convert all characters to lowercase and check non-alphanumeric characters.
  3. Added passed characters to an array.
  4. I turned the arry into a string and checed if it was a palindrome

Complexity

  • Time complexity:O(N)

  • Space complexity:O(N)