All Posts

Leetcode 3042: Count Prefix and Suffix Pairs I

You are given a 0-indexed string array words. You need to determine the number of index pairs (i, j) such that i < j and the string at index i is both a prefix and a suffix of the string at index j. The function isPrefixAndSuffix(str1, str2) returns true if str1 is both a prefix and a suffix of str2, and false otherwise.

Leetcode 3046: Split the Array

You are given an integer array ’nums’ of even length. Your task is to determine whether it is possible to divide the array into two subarrays, ’nums1’ and ’nums2’, such that both subarrays have distinct elements and the same length. Each subarray must contain half of the total elements from the original array.

Leetcode 3099: Harshad Number

An integer is called a Harshad number if it is divisible by the sum of its digits. You are given an integer x. Your task is to return the sum of the digits of x if x is a Harshad number. Otherwise, return -1.

Leetcode 3110: Score of a String

You are given a string s. The score of a string is defined as the sum of the absolute difference between the ASCII values of adjacent characters. Return the score of the string s.

Leetcode 3120: Count the Number of Special Characters I

You are given a string word. A letter is considered special if it appears both in its lowercase and uppercase form in the string. Return the number of special letters in word.

Leetcode 3127: Make a Square with the Same Color

You are given a 3x3 matrix consisting of characters ‘B’ (black) and ‘W’ (white). Your task is to determine if it is possible to change the color of at most one cell to form a 2x2 square where all cells are of the same color. Return true if it is possible, otherwise return false.