Posts

StringBuilder VI

Image
Another problem that leads to TLE if using standard string (remember that string concatenation is very costly since there are multiple objects being created), but if you switch to StringBuilder, which allows you to make changes to its elements (it isn't immutable), you can achieve a very quick result. Using it and at the very end convert it to regular String. Code is down below, cheers, ACC. Maximum Bitwise XOR After Rearrangement - LeetCode You are given two binary strings  s  and  t ​​​​​​​, each of length  n . You may  rearrange  the characters of  t  in any order, but  s   must remain unchanged . Return a  binary string  of length  n  representing the  maximum  integer value obtainable by taking the bitwise  XOR  of  s  and rearranged  t .   Example 1: Input:   s = "101", t = "011" Output:   "110" Explanation: One optimal rearrangement of  t  is  "01...

Follow the instructions

Image
Some LC problems require only that you follow the instructions. In fact, the description of the problem is literally the algorithm. I think problems like this one should be downgraded to easy level, there isn't anything to really optimize here. In addition, the constraints are very small, limited. In any case, the solution is down below, cheers, ACC. Find the Score Difference in a Game - LeetCode You are given an integer array  nums , where  nums[i]  represents the points scored in the  i th  game. There are  exactly  two players. Initially, the first player is  active  and the second player is  inactive . The following rules apply  sequentially  for each game  i : If  nums[i]  is odd, the active and inactive players swap roles. In every 6th game (that is, game indices  5, 11, 17, ... ), the active and inactive players swap roles. The active player plays the  i th  game and gains  nums[i] ...