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 1, 2026 16:14
Plus one

Question

Approach

i converted the array to an integer and added 1 to it ,but then while trying to do i discovered typescripts number can not support more than 17 numbers and it looses its precison. so i used BigInt which lets me keep large numbers ensuring numerical precision is preserved for large values and converted the integer back to an array

Complexity

  • Time complexity: O(N)

Code

@Ephraimiyanda
Ephraimiyanda / main.md
Created January 4, 2026 00:03
Remove Duplicates from Sorted Array

Approach

I looped through the array to be able to modify the numbers in place

Complexity

  • Time complexity: O(N)
  • Space complexity: O(1)

Code

function removeDuplicates(nums: number[]): number {
@Ephraimiyanda
Ephraimiyanda / main.md
Created January 4, 2026 23:27
Median of Two Sorted Arrays

Question

Approach

I checked if the length of the array was an even or odd number. This allows me to anticipate whether the median will be a single digit or the average of the two middle numbers.

Complexity

  • Time complexity: O(Nlog(N)). The overall run time complexity should be O(log (m+n)) as stated in the question .i will have to come back for a proper solution .
@Ephraimiyanda
Ephraimiyanda / main.md
Created January 6, 2026 00:33
Palindrome Number

Approach

If the number is negative we know the reverse of the number will not be the same so i return false. if the number is a positive integer ,i convert it to an array and compare it with its reverse.

Complexity

  • Time complexity: O(N)

  • Space complexity: O(N)

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

@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 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 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 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
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