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 March 4, 2026 18:50
Merge Sorted Array

Question

Approach

I am trying to modify the element nums1 after n so we create a loop that runs for n times . The elements in nums1 are modified are the mth element because nums1 lenght is m+n so we do not waste any iterations. After the elements are replaced they are sorted.

Complexity

  • Time complexity: O((N+M)Log(N+M))

  • Space complexity: O(1)

@Ephraimiyanda
Ephraimiyanda / main.md
Created February 28, 2026 22:39
Search in Rotated Sorted Array II

Question

Approach

I loop through the array to check if a number is equal to the target

Complexity

  • Time complexity:O(1)

  • Space complexity:O(N)

@Ephraimiyanda
Ephraimiyanda / main.md
Created February 16, 2026 15:37
Number of 1 Bits

Question

Approach

  1. The number is converted to binary then split into an array.
  2. The array is the filtered to only the hold the 1's .
  3. The length of the array is returned

Complexity

  • Time complexity:
@Ephraimiyanda
Ephraimiyanda / main.md
Created February 16, 2026 15:11
Largest Number

Question

Approach

we are comparing the concactenation of numbers not their addition. so the numbers are turned to strings and are sorted based on their concactenation in descending order and are then joined an returned.

Complexity

  • Time complexity:O(N log N)

  • Space complexity:O(N)

@Ephraimiyanda
Ephraimiyanda / main.md
Created February 16, 2026 13:24
Find the Difference

Question

Approach

i loop through an alphabetically sorted t. if a letter in t is an extra as compared to alphabetically sorted s i return the alphabet.

Complexity

  • Time complexity: O(Nlogn)

  • Space complexity:O(N)

@Ephraimiyanda
Ephraimiyanda / main.md
Created February 12, 2026 20:38
Contains Duplicate

Question

Approach

As i loop through the numbers i check if a number exists onthemap.if it does i return true if it doesnt i and add the number to the map and continue. if there are no duplicates false is returned.

Complexity

  • Time complexity:O(N)

  • Space complexity:O(N)

@Ephraimiyanda
Ephraimiyanda / main.md
Created February 10, 2026 20:18
First Unique Character in a String

Question

Approach

A double loop is created to go through the string turned array picking each letter and then checking the other letters if they match which the current letter using the isUnique boolean value. if isUnique is true we return the index i of the string . if its not found -1 is returned.

Complexity

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

Code

@Ephraimiyanda
Ephraimiyanda / main.md
Created February 9, 2026 23:59
Top K Frequent Elements

Question

Approach

  1. A loop is run to go through each number.
  2. A map is used to check if the number is seen for the first time , if it has not been then the loop skips to the next number.
  3. if a number is seen for the first time a second inner loop is run to check which other number in the array is the same as the current number.
  4. the map is turned into an array of arrays and the k number frequent elements which are the i[0] values are returned.

Complexity

  • Time complexity:O(N^2)
@Ephraimiyanda
Ephraimiyanda / main.md
Created February 8, 2026 12:27
House Robber

Question

Approach

to get the max profit i check if robbing a house is better than skipping while folllowing the adjacent house rule

Complexity

  • Time complexity:O(N)

  • Space complexity:O(1)

Code

@Ephraimiyanda
Ephraimiyanda / main.md
Created February 8, 2026 10:35
Counting Bits

Question

Approach

  1. Create a loop which runsfor n+1 times.
  2. Inside the loop i find the binary representation for the index value.
  3. I then move to find the amount of 1 in the binary representation and add it to the ans array

Complexity

  • Time complexity:O(NLogN)

  • Space complexity:O(N)