Bloomberg Interview Question

Generate the first n prime numbers and time complexity.

Interview Answers

Anonymous

Jun 16, 2016

private static void generatePrime(int n) { for(int i = 2; i < n; i++) { boolean status = true; for(int j = 2; j <= Math.sqrt(i); j++) { if(i%j == 0) { status = false; } } if(status) System.out.print(i+", "); } }

Anonymous

Jun 16, 2016

time complexity is nlogn

Anonymous

Jun 30, 2015

Generate tuples whose sum is 10 and time complexity.