Skip to content

Instantly share code, notes, and snippets.

View DevYoma's full-sized avatar
🎯
Focusing

Ogheneyoma DevYoma

🎯
Focusing
  • Lagos, Nigeria
View GitHub Profile
@DevYoma
DevYoma / main.md
Last active September 27, 2025 23:38
[1859]Sorting the Sentence

Question

Thought Process/Learnings

So, we split s

  • Create the sortedWords array(mutable, so the values can be re-assigned), let sortedWords = new Array(splitText.length), the initial data in this array is the undefined data type.
  • loop through the array splitText then do the following:
  • get the last character of each word, which is the number
  • convert it to number as it is a string, then make it zero based (as we're using it for array purposes)
  • get the word without the number,
  • we then reassign the values in the sortedWords array using the indexInSortedArray like this, sortedWords[indexInSortedArray] and asssigning it to cleanWord
@DevYoma
DevYoma / main.md
Created September 26, 2025 15:13
[1832]Check if a Sentence is a Panagram

Question

Thought Process/Learning(s)

A panagram is a sentence or phrase that uses every letter of the alphabet at least once So, I initially used a Map Data structure, but I then changed it to a set, since we're not counting any frequency, we're just checking if each alphabet occurs at least more than one time

  • Created a set, letterSet
  • Looped through the sentence and check if the character at the current index is in the set(NB: set contain unique data)
  • if character isn't in Set, use letterSet.add(character)
@DevYoma
DevYoma / main.md
Created September 16, 2025 22:58
[104]Maximum Depth of Binary Tree

Question

Thought Process/Learnings

My first Binary Tree & Breadth First Search question. (still a bit foggy in my mind) Created a queue array and used a while loop to always loop through it while the length of the queue array is greater than zero I then got the size of the queueLevel Size which is just the current number of items in the queue array. Then using a for loop to iterate through the queueLevelSize and then checking if the current element being removed from the Queues(First in, First out FIFO) Left or right element value is not null. if it is not null, it means that current node is a parent element to at least one child element, so push those element(s) into the queue using the push() method. Then return depth afterwards

@DevYoma
DevYoma / main.md
Created September 15, 2025 21:56
[1773]Count Items Matching a Rule

Question

Thought Process/Learnings

function countMatches(items: string[][], ruleKey: string, ruleValue: string): number {
  let outputResult: number = 0;
  let ruleIndex: number; 
@DevYoma
DevYoma / main.md
Created September 14, 2025 22:06
[2185]Counting Words With a Given Prefix

Question

Thought Process/Learnings

Simple and straight forward. Initialized a counter, looped through the words array, stored each prefix word using the slice then check if is equal to the pref, increase the count if it is.

function prefixCount(words: string[], pref: string): number {
 let count: number = 0;
@DevYoma
DevYoma / main.md
Last active September 14, 2025 02:09
[17]Letter Combinations of a Phone Number

Question

Thought Process/Learnings

Along the line, I got to learn that this problem required the Backtracking recursion approach, which I did not use.

So, I created an object phoneDialObject with the numbers 2-9 as the keys and their letters as values. I created the 2d letterArrays to hold the result(string eg "abc", "bcd") of the digits index in the phoneDialObject. I stored it in stringLetters, eg "abc" "def" I then looped through the stringLetters and pushed each character into the digitLetters array. Now that I think of it, you can use a split() to achieve the same task. I then pushed each digitalLetters[] into the 2d letterArrays: so I had something like this [['a','b', 'c'], ['d', 'e', 'f']]

@DevYoma
DevYoma / main.md
Created September 11, 2025 21:18
[3516]Find Closet Person

Question

Thought Process/Learning

Decided to do a Math question today.

  • Didn't want to bother with signs that's why I used the absolute() abs() function
  • applied the conditions and returned what was asked to return for each condition.
function findClosest(x: number, y: number, z: number): number {
 const target = z;
@DevYoma
DevYoma / main.md
Created September 10, 2025 21:45
[349] Intersection of Two Arrays

Question

Thought Process/Learning

  • So, I converted the first array nums1 to a set(No duplicates)
  • I then created a resultSet to store the unique elements that are in both arrays.
  • Loop through the nums2, then check if the firstNumSet has the current element being iterated over, i.e nums2[i], if it is, add it to the resultSet
  • then use the Array.from to convert the resultSet to an array.
@DevYoma
DevYoma / main.md
Created September 9, 2025 22:45
[709]To Lower Case

Question

Thoughts/Learnings

This question made me read up more on ASCII.

  • To convert a character to its equivalent ASCII code, you use the charCodeAt() instance method. Instance because it is an instance of the String Class.
  • To convert from ASCII code to its equivalent string, you use the fromCharCode() static method. Static because it belongs to the Class method itselt.
  • Strings in JS/TS are immutable (once created, they cannot be changed, hence the result array declaration to push into after they've been iterated by)
  • result.join("") to get the strings from the result array

Funny how you can just use result.toLowerCase() and you'll solve this question. ☠️, but i don't think that's how we're being asked to solve the question.

@DevYoma
DevYoma / main.md
Created September 8, 2025 22:23
Check Balanced String

Question

Thought Process/Learnings

I just looped through the num array, converted it to the number type. I then checked if the current index divided by 2 is equals zero, if it is, I then added the convertedNum to the evenSum, and added the convertedNum to oddSum if the index divided by 2 was not zero. I then returned oddSum === evenSum

function isBalanced(num: string): boolean {
let oddSum: number = 0;