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

@Ephraimiyanda
Ephraimiyanda / main.md
Created February 6, 2026 00:54
Majority Element II

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 size of the duplicate numbers are tracked and if size > n / 3 then i add the number to the results array.

Complexity

  • Time complexity: O(N^2)

  • Space complexity: O(N)

@Ephraimiyanda
Ephraimiyanda / main.md
Last active February 4, 2026 23:45
Rotate Array

Question

Approach

I created a copy of the array to be able to track the rotation of the array by k numbers.

I first thought of this

function rotate(nums: number[], k: number): void {
@Ephraimiyanda
Ephraimiyanda / main.md
Created February 3, 2026 22:11
Contains Duplicate II

Approach

  1. using a hashmap i check if a number exists in the map, if it doesnt then i store the index of the number in the map.
  2. if the number exists in the map the next time the number is seen in the array the absolute difference between the index of the previously stored number and its current duplicate is checked.
  3. if the difference is less than or equal to k i return true

Complexity

  • Time complexity:O(N)

  • Space complexity:O(N)

@Ephraimiyanda
Ephraimiyanda / main.md
Created February 2, 2026 22:17
Two Sum II - Input Array Is Sorted

Question

Approach

  1. An indexes array is created to store the index integers.
  2. A double loop is created to check which numbers when added are equal to the target.
  3. if the sum of the numbersisequal to the target, "1" is added to their indexes which is then pushed to the indexes array.

Complexity

  • Time complexity: O(N^2)
@Ephraimiyanda
Ephraimiyanda / main.md
Last active February 1, 2026 23:42
Isomorphic Strings

Question

Approach

I create two maps to check if the order of characters are preserved. t is used as pattern for s and s also a pattern for t. if the two patterns d not match then we return false

Complexity

  • Time complexity: O(N)

  • Space complexity: O(N)