All Posts

Leetcode 2807: Insert Greatest Common Divisors in Linked List

You are given the head of a linked list, where each node contains an integer. For each pair of adjacent nodes, insert a new node with a value equal to the greatest common divisor (GCD) of the two nodes. Return the modified linked list after performing this operation.

Leetcode 2947: Count Beautiful Substrings I

You are given a string s and a positive integer k. A string is beautiful if it satisfies the conditions that the number of vowels equals the number of consonants, and the product of the number of vowels and consonants is divisible by k. Return the number of non-empty beautiful substrings in the string.

Leetcode 3044: Most Frequent Prime

You are given a matrix of integers, where each cell contains a digit from 1 to 9. Starting from any cell in the matrix, you can move in one of eight possible directions (east, south-east, south, south-west, west, north-west, north, and north-east) and create numbers by appending the digits along the path. For each valid path, numbers greater than 10 are generated. The task is to find the most frequent prime number greater than 10 among all the numbers generated by traversing the matrix. If there are multiple such prime numbers, return the largest one. If no prime number exists, return -1.