Skip to content

Instantly share code, notes, and snippets.

View Jonniie's full-sized avatar
🏋️‍♂️
horning my tools

John Areola Jonniie

🏋️‍♂️
horning my tools
View GitHub Profile
@Jonniie
Jonniie / main.md
Created January 14, 2026 20:41
896. Monotonic Array

Leetcode #896

Approach

My approach was to figure out using the first two unique numbers if the array is increasing or decreasing, if its increasing, that means new numbers must not be less than the last number and if its a decreasing array, then subsequent numbers must not be greater than the previous number. Based on this conditions, we are able to do an early false return for non-monotonic arrays, and if all checks, we return a true

Complexities

Space complexity: O(1)
Time Complexity: O(N)
@Jonniie
Jonniie / main.md
Created January 5, 2026 23:47
1975. Maximum Matrix Sum
@Jonniie
Jonniie / main.md
Created January 4, 2026 17:31
1390. Four Divisors

Leetcode #1390

Approach

The approach was to find the factors of each num in the nums array, did this by iterating from 1 to sqrt(num), then used a set to store the factors (to avoid repetition in the case of perfect squares), then we check for the number with factors size of 4, and add the sum of all the 4 factors to the res value.

class Solution {
public:
    int sumFourDivisors(vector<int>& nums) {
        int res = 0;
@Jonniie
Jonniie / main.md
Created January 2, 2026 19:32
961. N-Repeated Element in Size 2N Array

Leetcode #961

Approach

Iterate through the nums array, and using an hashmap, we count the frequency of each number, as soon as we encounter a number with frequency more than 1, we return that number and exit the loop , as that's the non-unique number

class Solution {
public:
 int repeatedNTimes(vector&amp; nums) {
@Jonniie
Jonniie / main.md
Last active January 1, 2026 16:28
Plus One

Leetcode #66

Approach

my intuitive approach was basically to join all the digits together, convert to a number, (using BigInt) to handle big numbers, split the resulting string into characters and map over the array of characters to convert the individual characters to number.

More optimal approach was to do the addition manually, start iteration from the end of the digits array, check if the current digit is less than 9, if yes, add one to the digit and return the entire digits array, if the number is 9, we want to change it to 0 and continue the iteration, till we get a number that is less than 9, to bear the carry. And at the end of the iteration, if we've not exited the function, meaning all digits were 9, we insert a 1 at the beginning of our new digits array, which has just digit zero.

# approach i
var plusOne = function(digits) {
@Jonniie
Jonniie / main.md
Last active October 16, 2025 22:04
Smallest Missing Non-negative Integer After Operations

Leetcode #2598

Approach

Didn't realize at first that each elements in the nums array has to be unique after performing an operation. My first step was to build a mod array to store the least non-negative number that can be formed from each nums element. Then sorted the mod array, if first element in the sorted array isn't 0, then 0 is our smallest mex.

For cases of repeting numbers in our mod array, we build a frequency map, with the frequencies being "0-indexed", then I modifed the mod array elements using their freq. count, (adding value * freq to the mod element).

Then a second sort, to keep the elements in the mod array in increasing order, to make iteration easy.

@Jonniie
Jonniie / main.md
Created October 15, 2025 23:27
Adjacent Increasing Subarrays Detection II

Leetcode #3350

Approach

I assembled every individual increasing set of elements into an array, arr, if all elements in the nums array are increasing, then size of arr will be 1, then we can return the result of the floor division of the length by 2, to give the maximum number of elements in each adjacent increasing group.

For an array with > 1 increasing groups, we iterate over the set of arrays, first we check for the possible adjacent grouping we can get from the current increasing group (max(res, len/2);), then we compare the adjacent increasing groups as well, picking the min of them, to ensure we have the maximum equal number of elemnts from each group.

For each computation, we keep the max value, which at the end gives the maximum possible valaue of elements that satisfy the adjacent incresing group rule.

@Jonniie
Jonniie / main.md
Created October 14, 2025 23:37
Adjacent Increasing Subarrays Detection I

Leetcode #3349

Approach

First step was to first group all increasing elements into their own array, then iterate through the groups, to see if a single group could form adjacent subarrays with increasing elemnts (len / k >= 2), if not, we check with the adjacent group (len >= k && nxt_len >= k) and if neither of these exist across the group arrays, return false

var hasIncreasingSubarrays = function(nums, k) {
    let arr = []
@Jonniie
Jonniie / main.md
Last active October 13, 2025 19:54
Find Resultant Array After Removing Anagrams

Leetcode #2273

Approach

First step was to sort each word in the words array, and store that in a new array. Then loop through the sorted words array, adding the original word to the result array, then comparing adjacent elements, for elements with same set of characters (anagrams), till we get where the words no longer repeat, meaning we've reached a unique word, and then continue the loop until the end of the words array

class Solution {
public:
@Jonniie
Jonniie / main.md
Created February 1, 2025 23:10
Leetcode Day 1

Question

Approach

My approach was to loop through the nums arr and check the equality of the parities of adjacent elements, so it checks if elements at i and i+1 are either both even or both odd

Implementation

class Solution {
public:
 bool isArraySpecial(vector&amp; nums) {