All Posts

Leetcode 1733: Minimum Number of People to Teach

In a social network consisting of multiple users and their friendships, users can communicate with each other only if they share a common language. You are given a list of languages each user knows and a list of friendships between users. Your task is to teach a single language to some users such that all the users in each friendship can communicate. The goal is to minimize the number of users you need to teach the new language.

Leetcode 1737: Change Minimum Characters to Satisfy One of Three Conditions

You are given two strings, a and b, consisting of lowercase letters. In one operation, you can change any character in either string to any lowercase letter. Your goal is to perform the minimum number of operations to satisfy one of the following three conditions:

  1. Every character in string a is strictly less than every character in string b alphabetically.
  2. Every character in string b is strictly less than every character in string a alphabetically.
  3. Both a and b consist of only one distinct character.

Return the minimum number of operations needed to achieve one of these conditions.

Leetcode 1742: Maximum Number of Balls in a Box

You are working in a ball factory with n balls numbered from lowLimit to highLimit (inclusive). You have an infinite number of boxes numbered from 1 to infinity. Your task is to place each ball into the box where the box number equals the sum of the digits of the ball’s number. For example, a ball numbered 321 will go into box 6 (since 3 + 2 + 1 = 6), and a ball numbered 10 will go into box 1 (since 1 + 0 = 1). The goal is to find the box with the most balls and return the number of balls in that box.

Leetcode 1743: Restore the Array From Adjacent Pairs

You are given an integer array nums with unique elements, but you have forgotten it. However, you do remember every pair of adjacent elements in nums. You are given a 2D integer array adjacentPairs where each adjacentPairs[i] = [ui, vi] indicates that the elements ui and vi are adjacent in nums. Your task is to reconstruct the original array nums using these adjacent pairs. There could be multiple valid solutions, so return any one of them.

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