2341. Maximum Number of Pairs in Array
- Store the nums value as the key, the frequency of each num as value
1 | # O(n) time | O(n) space |
2342. Max Sum of a Pair With Equal Sum of Digits
- Store the sum of each digit in each num as the key, and store the values of the corresponding nums as the value
- make the value sorted
1 | # O(n) time | O(n) space |
2343. Query Kth Smallest Trimmed Number
- Trim the string based on the trim
- store the index and result into arr
- sort arr
- get the kth smallest trimmed number
1 | # O(nm) time | O(n) space |
2344. Minimum Deletions to Make Array Divisible
- use math.gcd to get the greatest common divisor of the list
- sort the numbers list
- travers numbers list and when the common divisor can divides the current number without a reminder, which means the current index is the number of deleted times
1 | # O(nlogn) time | O(1) space |
Note
The math.gcd() method returns the greatest common divisor of the two integers int1 and int2.
GCD is the largest common divisor that divides the numbers without a remainder.
GCD is also known as the highest common factor (HCF).
Tip: gcd(0,0) returns 0.
1 | math.gcd(int1, int2) |
[^1]: 2341. Maximum Number of Pairs in Array
[^2]: 2342. Max Sum of a Pair With Equal Sum of Digits
[^3]: 2343. Query Kth Smallest Trimmed Number
[^4]: 2344. Minimum Deletions to Make Array Divisible
[^5]: Python math.gcd() Method