Posts

Showing posts from November, 2025

Binary Search to Find Next Greater Element III

Image
The solution to this problem boils down to finding the next greater element to N in a sorted list. Binary Search is the best mechanism here. Steps: 1/ For each element, create a sorted list of its indexes. Store in a hash table for quick access 2/ Create a helper function to find the reverse of a number (in LogN) 3/ Create a helper function to do the Binary Search and find the next greater index Code is down below, cheers, ACC. Minimum Absolute Distance Between Mirror Pairs - LeetCode ou are given an integer array  nums . A  mirror pair  is a pair of indices  (i, j)  such that: 0 <= i < j < nums.length , and reverse(nums[i]) == nums[j] , where  reverse(x)  denotes the integer formed by reversing the digits of  x . Leading zeros are omitted after reversing, for example  reverse(120) = 21 . Return the  minimum  absolute distance between the indices of any mirror pair. The absolute distance between indices  i  and...

Trie-Trie-Trie!!! - Part 5

Image
 An interesting problem that can be solved with Tries (there are other solutions too). You can create a simple trie and add all the digits to it. Then the idea is to have a Search function that given the original string and the current index, searches for any match in the trie starting at that index, and if there is a match, returns the jump offset. Complexity becomes the length of the string times the depth of the trie, which is a constant, hence the final time complexity is linear. Code is down below, cheers, ACC. Convert Number Words to Digits - LeetCode You are given a string  s  consisting of lowercase English letters.  s  may contain  valid concatenated  English words representing the digits 0 to 9, without spaces. Your task is to  extract  each valid number word  in order  and convert it to its corresponding digit, producing a string of digits. Parse  s  from left to right. At each position: If a valid number word s...