LC 3850 - Count Sequences to K

To check whether it can become an integer k, we track prime-exponent vectors instead of doing fraction arithmetic. In this problem we only care about primes {2,3,5} since the number is 1 to 6. If k contains any other prime factor, it is impossible, return 0. Then we do the search backwards, process nums from right to left, and at each position, do unchanged, multiple or divide. When we finish all indices we add the total count by one if the remaining target is 1. ...

February 22, 2026 · 3 min

LC 3849 - Maximum Bitwise XOR After Rearrangement

We record the position for ones and zeros, then count the number of ones in t, the goal is to match the 1’s in t to some positions in s. The stategy is to (1) mathc the zeros from MSB, and (2) match the zeros from LSB, since matching zeros would increase the value, so we want to do this from MSB, and for mathcing ones we decreas the value so we want to do this from LSB. ...

February 22, 2026 · 2 min

LC 3848 - Check Digitorial Permutation

We pre-calculate the factorial for 1 to 10 first, then iterate thorught the string and add all the factorial up. Now we sum then up, and chekc if this sum can be formed by the original numers digits. Code class Solution { public: bool isDigitorialPermutation(int n) { vector<int> fac(10, 1); for(int i = 1 ; i < 10 ; ++i) fac[i] = fac[i-1] * i; string s = to_string(n); int cnt = s.size(); int sum = 0; for(int i = 0 ; i < cnt ; ++i) { sum += fac[s[i] - '0']; } string s2 = to_string(sum); if(s2.size() != s.size()) return false; unordered_map<char, int> charCnt; for(const auto& c: s) ++charCnt[c]; for(const auto& c: s2) { if(charCnt[c] == 0) return false; --charCnt[c]; } return true; } };

February 22, 2026 · 1 min

LC 3847 - Find the Score Difference in a Game

Check if the current number is odd, and the idx is mod 5 by 6, then update score1 and score2 Code class Solution { public: int scoreDifference(vector<int>& nums) { int score1 = 0; int score2 = 0; bool active1 = true; int n = nums.size(); for(int i = 0 ; i < n ; ++i) { if((nums[i] % 2 == 1) ^ (i % 6 == 5)) active1 = !active1; if(active1) score1 += nums[i]; else score2 += nums[i]; } return score1 - score2; } };

February 22, 2026 · 1 min