Given a target and an array, count how many elements are greater than the target and how many are less than it. If there are more greater elements, return greater; if there are more smaller elements, return smaller; if they're equal, return tie.
Given an initial state, a season, and a day, return the moon state for that specific date. The moon's cycle is 8 days with 8 possible states, and the initial state given is the state on the first day of the year. Season/day represent the month and day.
Question 3: Given an n×m matrix and a list of commands, e.g. ["reverseRow r", "swap r1, r2", "rotate"].
"reverseRow r": given row index r (int), reverse the numbers in that row.
"swap r1, r2": given row indices r1, r2, swap them.
"rotate": rotate the matrix 90 degrees clockwise.
Return the matrix after applying all the commands.
Question 4: Given a list where each number represents an index, return the running length of the longest consecutive sequence seen so far. For example, [2, 3, 0, 4] returns [1, 2, 2, 3]. Starting with "2", the length is 1; adding 3 makes it "2, 3", length 2; adding 0 doesn't connect, so it's still 2; then adding 4 makes "2, 3, 4", length 3.
Too long, I couldn't finish it in time... I'm toast.
Summary (Oct 2025 – Jan 2026)
Question 4: Given a list of integers and a target number, return the number of pairs whose combination (concatenation) equals the given number.
e.g. numbers = [1, 212, 12, 12], target = 1212
pair 1: numbers[0], numbers[1] => 1, 212 => 1212
pair 2: numbers[2], numbers[3] => 12, 12 => 1212
pair 3: numbers[3], numbers[2] => 12, 12 => 1212
ANS: This should use the two-sum approach — a hash map, O(n).
Question 3: Matrix problem.
Given a matrix whose elements are the symbols +, -, or digits 0-9, you can only move strictly top-to-bottom and left-to-right. The following patterns are invalid:
Two consecutive symbols: 0 ++ 1, 3 +- 4
Two consecutive digits: 1 2 + 3, 5 - 6 3
Find the maximum result among all valid expressions.
My third question was actually a matrix, but it can be simplified to this: given a string containing only digits and +/-, identify all valid expressions and find the maximum value among them. Example: 2+3-1, the max value should be 5 (the other possible values are 2, 3, 1, 4). It can also be invalid — e.g. 2 - + 4 is not a valid expression. Of course, every single digit on its own is a valid expression.
ANS: Should be solved with DP, storing the max value up to the current position. Note that the answer isn't just dp[n-1][m-1] — you need to return the max over all possible positions (because dp[n-1][m-1] only covers the path all the way to the end, e.g. 2+3-1, but the actual answer is 2+3). If matrix[i][j] is a digit, you need to check whether the cell above and to the left has a '+' or '-'. If not, it's just itself. If it does, you check whether the cells above/left of THAT have digits. Those are all the possibilities. In the top-left 2x2 area, dp[i][j] is just itself (the digit).
def max_expr_value(grid):
NEG = float("-inf")
n, m = len(grid), len(grid[0])
D = [[NEG] * m for _ in range(n)] # end with digit (complete expr)
P = [[NEG] * m for _ in range(n)] # pending '+'
M = [[NEG] * m for _ in range(n)] # pending '-'
ans = NEG
for i in range(n):
for j in range(m):
bestD = bestP = bestM = NEG
if i > 0:
bestD = max(bestD, D[i-1][j])
bestP = max(bestP, P[i-1][j])
bestM = max(bestM, M[i-1][j])
if j > 0:
bestD = max(bestD, D[i][j-1])
bestP = max(bestP, P[i][j-1])
bestM = max(bestM, M[i][j-1])
cell = grid[i][j]
if cell.isdigit():
d = int(cell)
# digit can always start a new expression
D[i][j] = d
if bestP != NEG:
D[i][j] = max(D[i][j], bestP + d)
if bestM != NEG:
D[i][j] = max(D[i][j], bestM - d)
ans = max(ans, D[i][j])
elif cell == '+':
if bestD != NEG:
P[i][j] = bestD
elif cell == '-':
if bestD != NEG:
M[i][j] = bestD
return None if ans == NEG else ans
Question 2: Array problem with multiple processing steps.
Step 1: Find the first non-zero number x from the left.
Step 2: Starting from that position, iterate forward through the array. If a value is not less than x, subtract x from it. If you hit a value less than x, jump to step 3. If you reach the last element, stop and return ans.
Step 3: Add x to ans.
Step 4: If all numbers are 0, return ans; otherwise go back to step 1.
Example: nums = [3, 5, 5, 1], ans = 0
Step one: x = 3, nums[1] = nums[2] = 5 - 3 = 2, nums[3] = 1 < 3, ans = ans + x = 3, nums = [0, 2, 2, 1]
Step two: x = 2, nums[1] = nums[2] = 2 - 2 = 0, nums[3] = 1 < 2, ans = 3 + 2 = 5, nums = [0, 0, 0, 1]
Step three: x = 1, nums[3] = 0, ans = 5 + 1 = 6, nums = [0, 0, 0, 0]
The array is all zeros, so return ans = 6.
I wrote it with a while loop and kept getting a timeout — I think either the return value or one of the steps was wrong.
ANS: Not sure if this can be done in O(n).
Text Justification, a bit more complex than the LeetCode version. It's a 2D list, where each sub-list has to start a new line, and each string can contain several words. If adding the next string would exceed the width, you need to start a new line. For example, ["cat is cute", "i love puppy"], ["something else"] — if adding "cat is cute" would exceed the width, you'd need to push "cute" down to the next line, making it "cat is", "cute i", "love puppy" like that. The spacing goes at the front/back rather than in the middle of a word. I passed all 10 of the visible test cases, but failed 4 of the hidden ones.
Question 1: String problem — count symmetric triplets.
Given a string, count +1 for every contiguous triplet of characters that's symmetric (i.e. the first and third characters match), and return the total count. Note it's case-insensitive.
E.g.: axA returns 1, cxcbdb returns 2.
ANS: First normalize all characters to uppercase or lowercase. If the string length is less than 3, return 0 directly. Loop through the string, check whether position i and i+2 match, increment the count if they do, and return the total count once you're done.
Given an array and a replacement rate, where the array only contains 'A' and 'P', e.g. ['A', 'A', 'A', 'P', 'P', 'P']. Change the array according to the following rules, and return how many rounds it takes to reach the final state:
If the number of trailing 'P's is greater than or equal to the replacement rate, remove that many trailing 'P's (equal to the replacement rate).
Otherwise, if there's still an 'A' in the array, change the last 'A' to a 'P'.
Otherwise, the final state has been reached.
3
['A', 'A', 'P']
['A', 'P', 'P']
['P', 'P', 'P']
[]
ANS: The stopping conditions are: no more 'A's, or fewer 'P's than the replacement rate. Can this be done with math? Otherwise just brute-force it.
Question 3: memory allocation and removal. Given a 1D array (memory) and a 2D array (queries). Each query either allocates memory, or erases memory by id.
ANS: This one has a lot of code — just write it out directly.
Question 4: Given an array and an integer (distance), find the two closest values in the array whose distance is not less than the given distance. I think this might be a LeetCode original problem, but I don't remember which one.
ANS: Should be sort, then sliding window / two pointer. Left and right both start from the left. Expand the window by moving right forward; shrink the window while making sure the distance between left and right stays no less than the given distance. Return the final answer. O(n log n).
Question 2: Split an array (A) into two groups (B and C). For each element a, if the count of elements greater than a in B is higher than the count of elements greater than a in C, put a into B; otherwise put it into C. If it's a tie, put it into whichever of B/C is shorter; if that's also a tie, put it into B. (An optimal solution isn't required.)
[1, 2, 3, 4, 5]
=>
[1, 3, 5]
[2, 4]
ANS: Sort first, then distribute elements into B and C accordingly.
Discussion
Loading comments…