Without noticing, I skipped updating the weekly contest blog for three weeks. Recently I was busy with graduation and onboarding. During the graduation trip in the middle, I even rarely skipped both a weekly contest and a biweekly contest.
This week counts as my first week after joining Amazon, and my global rank surprisingly reached 74. Thinking carefully, the last time I entered the top 100 in a weekly contest was Contest 243, roughly a month and a half ago.
The last two problems this week were both hard, so they really separated people.
Because my China-site rating had reached 2460, I was worried about losing rating, so recently I have basically been playing on the US site. The US-site account is a 2330 “alt account”, so it is basically hard to lose points.
1929. Concatenation of Array
A warm-up problem. Straightforward. Python can even solve it in one line with return nums + nums.
1 2 3 4 5 6 7 8 9 10 11
classSolution { public: vector<int> getConcatenation(vector<int>& nums){ constint n = nums.size(); vector<int> ans(2 * n); for (int i = 0; i < n; ++i) { ans[i] = ans[i+n] = nums[i]; } return ans; } };
Time complexity: O(n), space complexity: O(n).
1930. Unique Length-3 Palindromic Subsequences
Because the palindrome length is short, only 3, there are at most 26*26 different palindromes. The palindrome can be represented by the middle character and the characters on both sides.
Because it is a subsequence, use cntLeft and cntRight to maintain whether the characters on the two sides meet the requirement.
The number of rows changed from 3 to 1-5, but the idea is unchanged: still ternary bit_mask + DP.
Use a ternary bit_mask to represent the color state of each column, and derive the number of arrangements for the new column from the number of arrangements of the previous column.