ServiceNow | Senior Software Engineer | Round 2 | SSE Interview Experience
Question Details
code for prime number with out using any count variable i forgot the square root and took time to optimise the code, later got the hit from interviwer and optimised it. further...
Full Details
code for prime number with out using any count variable
i forgot the square root and took time to optimise the code, later got the hit from interviwer and optimised it.
further optimized code is requested then again elemenated 0 & 1 & -ve numbers
futher optimised code is requested again got hit w.r.t even numbers and furhter optimized elemenating even numbers
static boolean primNumber(int num) {
\t\tint i = 2;
\t\tif (num <= 1) {
\t\t\treturn false;
\t\t} else {
\t\t\twhile (i%2 !=0 || i <= Math.sqrt(num)) {
\t\t\t\tif ( num % i == 0) {
\t\t\t\t\treturn false;
\t\t\t\t}
\t\t\t\ti++;
\t\t\t}
\t\t\treturn true;
\t\t}
\t}
About This Question
This is a reported interview question from a square/block interview for a swe role (senior level) during the onsite round reported in 2024.
It covers the following topics: Math .