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
Created January 16, 2026 15:02
Valid Parentheses

Question

Approach

  1. check if the length of the string is greater than 1. if its not we return false.
  2. Make the string an array and loop through it.
  3. Create a stack and store opening brackets inside.
  4. Check if the next closing bracket is equal to the last element in stack. if it is i return true else i return false.

Complexity

  • Time complexity: O(N)
@Ephraimiyanda
Ephraimiyanda / main.md
Created January 15, 2026 20:38
Pow(x, n)

Approach

I used the double multiplication (**) method for typescript

Complexity

  • Time complexity:O(1)

  • Space complexity:O(1)

Code

@Ephraimiyanda
Ephraimiyanda / main.md
Created January 15, 2026 16:03
Container With Most Water

Question

Approach

To get the area between poles i created two pointers for the pair of poles that moves inward while calculating the areas between the poles also while limiting the height to be used for calculating the area to the shorter pole.

Complexity

  • Time complexity: O(N)

  • Space complexity: O(1)

Code

@Ephraimiyanda
Ephraimiyanda / main.md
Created January 14, 2026 00:27
Single Number

Question

Approach

I looped through the numbersand checked in pairs if they were duplicates.

Complexity

  • Time complexity: O(N log N)

  • Space complexity: O(N)

Code

@Ephraimiyanda
Ephraimiyanda / main.md
Last active January 13, 2026 16:05
Find the Index of the First Occurrence in a String

Question

Approach

I looped through the string and sliced it by the length of the needle.if the word formed is the same as the needle then i return the index of the first letter of the word from the haystack.

Complexity

  • Time complexity: O(M∗N)

  • Space complexity: O(1)

Code

@Ephraimiyanda
Ephraimiyanda / main.md
Created January 11, 2026 06:47
Longest Common Prefix

Approach

1.I first get the smallest word in the array of words. 2.A tracker to keep track of the length of the prefix is set. 3.A loop to go through the array and a loop to check whether each word starts with the prefix is created. if any of the words do not contain the prefix the prefix is reduced till all the words contaiin the longest prefix.

Complexity

  • Time complexity: O(S)

  • Space complexity: O(1)

@Ephraimiyanda
Ephraimiyanda / main.md
Created January 9, 2026 23:55
Length of Last Word

Question

Approach

I turnedthe string into an array and filtered for words with characters greater than 0 to remove spaces and then retrieved the length of the last word.

Complexity

  • Time complexity: O(N)

  • Space complexity: O(N)

Code

@Ephraimiyanda
Ephraimiyanda / main.md
Created January 8, 2026 23:49
Search in Rotated Sorted Array

Approach

i looped through thr array checking to see which number was the target and return the index and if the target did not exist among the numbers i return -1.

Complexity

  • Time complexity: O(N) The time complexity for the question is supposed to be solved using O(log n). So this will need a revisit to be solved properly

  • Space complexity: O(1)

Code

@Ephraimiyanda
Ephraimiyanda / main.md
Created January 8, 2026 02:05
Remove Element

Approach

i loop through the numbers and assign a pointer for the next location of a val. if there is no val i overwrite the non val element and return the length on the non value elements.

Complexity

  • Time complexity: O(N)

  • Space complexity: O(1)

Code

@Ephraimiyanda
Ephraimiyanda / main.md
Created January 6, 2026 22:22
Reverse Integer

Approach

setting the limit for the integer was a priority before turning the number into an array to be able to reverse it.Afterwards logic to check if the original integer was a negative or positive integer so that the reversed will be negative or positive.

Complexity

  • Time complexity: O(N)

  • Space complexity: O(N)

Code