Posts

Showing posts from 2025

StringBuilder V

Image
One more problem which is simple but leads to TLE if you use String instead of StringBuilder. The entire code below was initially written with String and I got several time-limit exceeded errors. Switching most of the implementation to StringBuilder solved the problem. Code is down below, cheers, ACC. Reverse Words With Same Vowel Count - LeetCode You are given a string  s  consisting of lowercase English words, each separated by a single space. Determine how many vowels appear in the  first  word. Then, reverse each following word that has the  same vowel count . Leave all remaining words unchanged. Return the resulting string. Vowels are  'a' ,  'e' ,  'i' ,  'o' , and  'u' .   Example 1: Input:   s = "cat and mice" Output:   "cat dna mice" Explanation: ​​​​​​​ The first word  "cat"  has 1 vowel. "and"  has 1 vowel, so it is reversed to form  "dna" . "mice"  has 2 vowels, so it remains...

Miller-Rabin Primality Test and Caching V

Image
Once concern about Miller-Rabin Primality Test is that it is a probability one. That's true. It can check for primality is O(Log(N)) which is the best that one can get, but probabilistically. The probability of a false positive, however, is (1/4)^k, where k is the number of witnesses in your code. In my implementations I use k=100. Which makes the probability of a false positive equal to 1/(2^200). Now when I ask ChatGPT 5.1 for "what is like to have such a probability", one of its answers is: A chance of 1/(2^200) is equivalent to picking one special atom in Earth at random and hitting the wrong atom by mistake, ten thousand times in a row . Hence you're good. Example in this problem. Code is down below, cheers, ACC. Largest Prime from Consecutive Prime Sum - LeetCode ou are given an integer  n . Return the  largest  prime number  less than or equal to  n  that can be expressed as the  sum  of one or more  consecutive prime numbers  sta...