All Posts
Leetcode 816: Ambiguous Coordinates
You are given a string s representing coordinates that have been encoded by removing commas, decimal points, and spaces. Your task is to restore the coordinates to their original form by considering all possible valid ways the digits could be split into two parts: a left part representing the x-coordinate and a right part representing the y-coordinate. Both parts may optionally contain a decimal point. The final coordinates must follow specific rules: no leading zeros are allowed, and the decimal point must be placed correctly. Return a list of all possible valid coordinates, formatted as ‘(x, y)’, where x and y represent the respective coordinates.
Leetcode 817: Linked List Components
You are given the head of a linked list containing unique integer values, and an array nums which is a subset of the linked list values. A connected component is defined as a sequence of consecutive values in the linked list that all appear in nums. Your task is to return the number of such connected components.
Leetcode 820: Short Encoding of Words
Given an array of words, you are to return the length of the shortest reference string that can encode these words. The reference string consists of the words concatenated with a ‘#’ character at the end, and indices are used to encode the words by identifying their position in the reference string. Each word is encoded by the substring in the reference string that starts at its position and ends at the next ‘#’.
Leetcode 822: Card Flipping Game
You are given two arrays, fronts and backs, representing the numbers on the front and back of each card. Each card is initially placed with the front number facing up. You may flip any number of cards. An integer is considered ‘good’ if it appears on the back of some card and is not visible on the front of any card after flipping. Your task is to return the minimum possible ‘good’ integer after flipping the cards. If there is no such ‘good’ integer, return 0.
Leetcode 823: Binary Trees With Factors
Given an array of unique integers, where each integer is greater than 1, we can create a binary tree using these integers. The value of each non-leaf node must be the product of the values of its children. The goal is to return the number of distinct binary trees that can be constructed. Since the result may be large, return the answer modulo 10^9 + 7.
Leetcode 825: Friends Of Appropriate Ages
You are given an integer array ages
, where each element represents the age of a person on a social media platform. A person will not send a friend request to another person if any of the following conditions are true:
- The recipient’s age is less than or equal to half of the sender’s age plus 7.
- The recipient’s age is greater than the sender’s age.
- The recipient’s age is greater than 100 and the sender’s age is less than 100.
Otherwise, the sender can send a friend request. Return the total number of friend requests made between people.