10. April 2021
Math Coding Problems - Interview Problems

Some common math coding exercises used as interview programming questions
isPrime
An algorigthm to compute a Prime Number which is greater than 1 and only divisbile by one and itself. For example Prime numbers are 1,2,3,5,7,11,13,17..
Problem: Given a number n the function must determine if n is prime and return true/false.
1boolean isPrime(int n) {
2 for (int x=2; x*x <=n; x++) {
3 if (n % x == 0) {
4 return false;
5 }
6 }
7 return true;
8}
Time Complexity: Analyzing this code fragment has a time complexity of o(n/2)
