We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
This is truly an exercise in clarifying requirements and a bit of computer science trivia. Great for competitive coders, questionable for interview prep. Not impossible that someone will interview with this problem but very rarely would this be an appropriate measure of problem solving and job fit.
Go ahead and try it to familiarize with the problem but if you get stuck, just start reading instead. You'll learn more than by thinking in circles.
I also really appreciate the amount of thoughtful responses here instead of mindlessly posting solutions!!! Way to go HackerRank community!!!
ths one is all over the place. It mixes metaphors; goes back and forth between stating the problem and instructing how to implement solution. Are talkng stacks of plates? Why is it telling me to create arrays?
You know, problems are supposed to be difficult to solve. Not difficult to understand what meant to say the AI that wrote it.
First understand what are factors, e.g., 4 and 6 are factors of 24.
Secondly, understand that prime numbers only have 2 factors : 1 and itself. And 24 has 1,2,3,4,6,8,12,24 as factors. Hence it's not a prime number.
Thirdly, understand that to identify whether a number is a prime number from a programming stand point, we need to loop from 1 to 24 to see how many factors we are getting. This way is called brute force, but it takes a very long time.
If we take a closer look, we notice a pattern, 2 * 12 is 24, 3 * 8 is 24, 4 * 6 is 24, and vice versa, 6 * 4 is 24, 8 * 3 is 24, 12 * 2 is 24. And square root of 24 is between these two sets of factors. 1, 2, 3, 4, 4.8989, 6, 8, 12, 24
So instead of looping all the way to 24, we can just loop up to square root of 24
This is truly an exercise in clarifying requirements and a bit of computer science trivia. Great for competitive coders, questionable for interview prep. Not impossible that someone will interview with this problem but very rarely would this be an appropriate measure of problem solving and job fit.
Go ahead and try it to familiarize with the problem but if you get stuck, just start reading instead. You'll learn more than by thinking in circles.
I also really appreciate the amount of thoughtful responses here instead of mindlessly posting solutions!!! Way to go HackerRank community!!!
ths one is all over the place. It mixes metaphors; goes back and forth between stating the problem and instructing how to implement solution. Are talkng stacks of plates? Why is it telling me to create arrays?
You know, problems are supposed to be difficult to solve. Not difficult to understand what meant to say the AI that wrote it.
Typescript
Java Solution:-
This is silly.