Posts

Showing posts from 2025

Miller-Rabin Primality Test and Caching IV

Image
It is interesting to ask the time complexity of a LC solution to ChatGPT, especially if it involves a complex algorithm like Miller-Rabin Primality Testing. This one is a good example: Complete Prime Number - LeetCode You are given an integer  num . A number  num  is called a  Complete Prime Number  if every  prefix  and every  suffix  of  num  is  prime . Return  true  if  num  is a Complete Prime Number, otherwise return  false . Note : A  prefix  of a number is formed by the  first   k  digits of the number. A  suffix  of a number is formed by the  last   k  digits of the number. A  prime  number is a natural number greater than 1 with only two factors, 1 and itself. Single-digit numbers are considered Complete Prime Numbers only if they are  prime .   Example 1: Input:   num = 23 Output:   true Explanation: ​​​​​​​ Prefi...

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...