Some of my favorite problems on LeetCode.

LeetCode is an excellent website for practicing programming skills and preparing tech interviews. In this post, I will share with you 10 interesting problems from LeetCode about array or string algorithms. Most of them are concise in description but not intuitive for one to come up with the best solution at once. Meanwhile, the ideas and techniques used in these problems are applicable to many other similar ones.

Given two sorted integer arrays A and B, find the k pairs of (A[i], B[j]) with the smallest sums, where 0≤i<|A|, 0≤j<|B|.

Apparently, the possible…

Computer programmers are obsessed with determinism. We’d think of the world as a state machine, whose next state solely depends on its current state and the action we take. Such a world is enjoyably predictable and everything could be perfectly planned to our advantage. Yet life is not that easy. We are surrounded by a huge amount of uncertainty, from variations of stock prices to the occurrence of a global pandemic.

Such reality calls for the *Markov decision process* (MDP), a simple but powerful model to help us describe sequential decision making in a stochastic environment. Formally, an MDP consists…

Software Engineer, Bookworm