Chances are that you never used prime numbers in your day-to-day job. Same applies to Fibonacci sequences, factorial, etc. Like it or not, a lot of companies out there will use these on their coding questions. Of course you can ask questions, it is totally acceptable that you don’t remember math concepts from high school. However, knowing these will save you precious minutes and will make you fell much more confident. Here are the ones to watch out for:
Modulo (remainder operator)
This is an extremely simple concept but you often see people struggling with it. The module operator is used to find the reminder after the division of two integers. Say you want to work out the integer division of 17 divided by 5. The result is 3, the reminder is 2 (17-15). Simple concept but it is used in a LOT in coding interviews.
You will most likely need to use the modulo operator in the following exercises:
Sum Multiples of Three and Five
Package Rice Bags
Package Rice Bags (part 2)
A prime number can only be divided by itself and one. Nine is not a prime number as it can be divided by three. Seven is a prime as it cannot be divided by any other integer other than seven itself and one. Prime numbers have all sorts of applications in software engineering, most notably in Cryptography. But let’s get into that now… it is heavily used in whiteboard interview questions, and you can practice it here:
Largest Prime Factor
The first two elements of the Fibonacci sequence are zero and one. Each subsequent element (called Fibonacci number) is the sum of the two previous elements. Here are the ten first Fibonacci numbers.
This code kata is an absolute classic. A particular call out for the recursive version.
Even Fibonacci Sum
The factorial of a given number is the product of all positive integers that are equal or less than that number. For instance, the factorial of five is:
Again, this coding interview question may come in two flavors (recursive and non-recursive). Try both here:
Palindrome is an entity that reads the same backwards as forwards. It applies to strings, lists, arrays, etc. Examples of palindromes are “ABBA”, “Step on no pets” or [10,3,5,3,10].
Longest Palindrome in Word
Greatest Common Divisor
The Greatest Common Divisor of two positive integers is the largest integer that divides both without a remainder. The Greatest Common Divisor of 10 and 25 is 5.
Watch out for the recursive recursive versions of this classic programming question:
Greatest Common Divisor