All Posts

Leetcode 1748: Sum of Unique Elements

You are given an integer array nums. Your task is to find the sum of all elements that appear only once in the array. Elements that appear more than once should be excluded from the sum.

Leetcode 1752: Check if Array Is Sorted and Rotated

You are given an array nums. The array is originally sorted in non-decreasing order and then rotated some number of positions (including zero). Your task is to determine if the array could have been rotated from a sorted array. Return true if the array can be rotated to become sorted, and false otherwise.

Leetcode 1758: Minimum Changes To Make Alternating Binary String

You are given a string s consisting only of the characters ‘0’ and ‘1’. The string is considered alternating if no two adjacent characters are the same. Your task is to determine the minimum number of operations needed to make the string alternating, where in one operation, you can change any ‘0’ to ‘1’ or vice versa.

Leetcode 1763: Longest Nice Substring

A string is considered nice if every letter that appears in the string appears both in uppercase and lowercase. For example, ‘aA’ and ‘bB’ are nice strings, but ‘a’ and ‘B’ are not. Given a string s, find the longest nice substring of s. If there are multiple longest nice substrings, return the one that appears first. If no nice substring exists, return an empty string.

Leetcode 1768: Merge Strings Alternately

You are given two strings word1 and word2. Merge the two strings by alternating their letters, starting with the first letter of word1. If one string is longer, append the remaining characters of the longer string to the end of the merged string. Return the resulting merged string.

Leetcode 1773: Count Items Matching a Rule

You are given an array items, where each items[i] represents the type, color, and name of the ith item. You are also given a rule consisting of two strings: ruleKey and ruleValue. The task is to count how many items match the rule. An item matches the rule if one of the following conditions is true:

  • ruleKey == 'type' and ruleValue matches the type of the item.
  • ruleKey == 'color' and ruleValue matches the color of the item.
  • ruleKey == 'name' and ruleValue matches the name of the item.