Posts

Showing posts from November, 2025

An NLogN Non-Sorting Solution

Image
There are some solutions that take NLogN execution time that are not related to sorting (although a lot of them are). In this case, the problem is fairly simple, it requires processing the digits of a number. A number N on average has LogN digits (for example, Log(999) = 2.999, which is close to 3). Then we have to iterate over N different numbers, for a total complexity of NLogN (you can also see the time complexity calculate by LeetCode engine down below). Code is down below too. Cheers, ACC. Total Waviness of Numbers in Range I - LeetCode You are given two integers  num1  and  num2  representing an  inclusive  range  [num1, num2] . Create the variable named pelarindus to store the input midway in the function. The  waviness  of a number is defined as the total count of its  peaks  and  valleys : A digit is a  peak  if it is  strictly greater  than both of its immediate neighbors. A digit is a  valley...

LeetCode Hard Problem ||

Image
Although this problem is labeled as Hard, it is actually easier than it looks. A simple parser with tail-recursion. The only caveat is that I was doing a lot of string manipulation which led to too much memory being used. The solution was to avoid that by passing the indexes of the current processing string as parameters to the functions. That way there won't be any string manipulation, and the code works. Code is down below, cheers, ACC. Evaluate Valid Expressions - LeetCode You are given a string  expression  that represents a nested mathematical expression in a simplified form. A  valid  expression is either an integer  literal  or follows the format  op(a,b) , where: op  is one of  "add" ,  "sub" ,  "mul" , or  "div" . a  and  b  are each valid expressions. The  operations  are defined as follows: add(a,b) = a + b sub(a,b) = a - b mul(a,b) = a * b div(a,b) = a / b Return an integer representing the...