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
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& nums) {