- mathematical analysis
- Pattern recognition
I have noticed I approach problems in a brute force manner. However, from solutions I have encoutered, I have learnt that I should try and find a pattern and see how that can be used to optimize my code.
- Rise, fall, valleys and peak patterns of numbers
- When there are sequential numbers that are scattered and you ned to find minimum actions to take a sorting algorithm will most likely be the clue.
- The Modulo (%) operator x + (y - (x % y)) will return the next highest multiple of y from x It can also be used to wrap around an array preventing the need of an IF statement idx % N will wrap around an array
- For any number K, the sum of 2 values (A & B) is evenly divisible by K if the sum of the remainders of A/K + B/K is K That is if (A%K) + (B%K) == K
- Try not to confuse SUB-SET, SUB-SEQUENCE, SUB-ARRAY / SUB-STRING
- For sequential lists 1 <= a[i] <= n -- should not be confused with from 1 <= a[i] <= 10^x