Pure math related problems are rarely asked during an interview. That is because an interview is usually testing an interviewee’s problem solving skills. Most math problems are based on some theorems, and those theorems are hard to infer in a short time. Therefore, it is hard to show problem solving skills by resolving a pure math problem. In this article, we will focus on introducing some common used theorems to inspire sparks.

Original thought are inspired by labuladong

Bit Operation:

Most often used bit operations are or, and, xor. There are many tricky and interesting skills. Here we will only focus on two of them.

  • n &(n - 1) : This operation can remove the last bit of 1 in n.
  • xor operation : a ^ a = 0 a ^ 0 = a

The prove will not be shown here, but you can use examples to infer theorems.

Factorial Calculation:

Factorial problems usually are not resolved by actual factorial calculation because factorial calculation’s time complexity is very big. We often need to find patterns to get result without a complete factorial computation .

Problems:

Bit Operation:

1332. Number of 1 Bits

142. O(1) Check Power of 2

82. Single Number

Factorial Calculation:

(LeetCode) 172 Factorial Trailing Zeroes

(Leetcode)793 Preimage Size of Factorial Zeroes Function

1324 Count Primes

1275 Super Pow

196 Missing Number

1112 Set Mismatch

(LeetCode) 382 Linked List Random Node