I've switched over to Python as my preferred language for interviewing/leetcoding. The reasons are, well, obvious and easily found all over the internet.
- Always at least consider the brute-force solution initially.
- Try not to get hung up trying to solve a problem, look up the solution if needed and comprehend it thoroughly.
- Simply use a dictionary, store indices of past items.
- Many ways to verify palindromes. One way is to reverse entire input, check for equality.
divmod(a, b) -> (a // b, a % b)
- Initialize pointers at both ends of input. Keep track of maximum while iterating. Move the pointer that has less effect on the maximum value.
- Use a list as a stack. Remember to ensure the stack is empty at the end.
- Use a dummy node to keep track of the result's head node.
- Trivial with
split.
- For recursive solutions, local function definitions are useful and allow not passing arguments around.
- For the iterative solution, a helper variable for the current node helps to imitate the function callstack behavior.
- You can use either some item from input as initial min/max value, or
float("inf") - Visualize the graph. The ideal time may be to sell at current time after having bought at minimum. Keep track of max profit and min price.
- Not much to say, just be mindful of the steps.
- Extremely simple with dictionary, though keep the sorting solution in mind.