Count the number of largest groups

















I give you an integer n. Find the sum of the digits of each integer from 1 to n in base 10 (add the digits of each digit), then place the digits and their equivalents in the same group.

Ask you to count the number of numbers in each group and return the number of groups with the largest parallel number of numbers.

Example:
Enter: n = 13
Output: 4
Explanation: there are 9 groups in total, summing 1 through 13 numerically: [1,10], [2,11], [3,12], [4,13], [5], [6], [7], [8], [9]. In all, four groups are tied for the most numbers.








Step 1: Use Map data structure in JavaScript to count the sum of each digit.

Step 2: Find the largest digit sum.

Step 3: Find the number of digits with the largest sum.

Time complexity O(n), space complexity O(n).










Construct K palindrome strings

















You are given a string s and an integer k. Construct k non-empty palindrome strings from all the characters in the S string.

Return True if you can construct k palindrome strings from all the characters in S, False otherwise.

Example:
Enter: s = ‘annabelle’, k = 2
Output: true,
Explanation: Two palindrome strings can be constructed from all the characters in S.
Some possible constructs include: ‘Anna’ + ‘elble’, ‘anbna’ + ‘elle’, ‘Anellena’ + ‘b’








A string that is a palindrome string has two states:

  • If the string length is even, ensure that the number of characters is even

  • If the length of the string is odd, ensure that only one character is odd

So, we also need to use Map data structure to count the number of characters.

Given the number of individual characters, the number of substrings that the string can be split into depends on the number of odd characters and cannot exceed the length of the string itself. (Single character as a substring of a loop)

Time complexity O(n), space complexity O(n).










Whether the circle and rectangle overlap

















You are given a circle represented by (RADIUS, x_Center, y_center) and a rectangle parallel to the axes (x1, y1, x2, y2), where (x1, y1) is the lower left corner of the rectangle and (x2, y2) is the upper right corner.

Return True if the circle and rectangle overlap, False otherwise.

In other words, you detect the presence of a point (xi, yi) that is on both the circle and the rectangle (both include the case of a point falling on a boundary).
Example:
Input: RADIUS = 1, x_center = 0, y_center = 0, x1 = 1, y1 = -1, x2 = 3, y2 = 1
Output: true,
Explanation: circles and rectangles have a common point (1,0)








The intersection of a circle and a rectangle can occur in the following two situations:

  • The circles intersect around the rectangle

  • The circle intersects four arcs in the rectangle

Time complexity O(1), space complexity O(1).










Chefs are most fond of cooking in order and

















A chef collected the satisfaction degree of his N dishes, and the chef cooked each dish in 1 unit of time.

The “liking time” coefficient of a dish is defined as the time spent cooking the dish and each previous dish multiplied by the degree of satisfaction of the dish, namely time[I]*satisfaction[I].

Return the maximum amount of “love time” for all dishes.

You can arrange the dishes in any order, or you can choose not to make certain dishes to get a greater sum.

Example:
Satisfaction = [-1,-8,0,5,-9]
Output: 14
Explanation: When the second and last course are removed, the maximum favorite time coefficient sum is (-1*1 + 0*2 + 5*3 = 14). Each dish takes about 1 unit to complete.








This problem is relatively simple, using greedy strategy, so need to sort first, and then in the process of statistical screening of the maximum sum can be.

Time complexity O(nlogn), space complexity O(1).










Highlights from the past






  • LeetCode Tour for front End Engineers – Night Meow 22

  • Front End Engineer’s LeetCode Tour – Night Meow 21

  • Front End Engineer’s LeetCode Tour – Night Meow 20

  • JavaScript AC solutions to problems on LeetCode