FastPrepNumbers with Exactly Three Divisors
Problems/Numbers with Exactly Three Divisors

Numbers with Exactly Three Divisors

Adobe logoAdobe● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The interviewer asked: "array, for each element find if it is almost prime(has exactly 3 divisors) n 1e5." The candidate used an observation about the square root and primes.

The report does not say what to return or how large the values are. Here, you return one true or false per element in the same order, and every value is a positive integer up to 10^9.

The judged task matches the report at about 90%.

Call a positive integer almost prime if it has exactly three positive divisors. For example, 9 is almost prime because its divisors are 1, 3, and 9.

You are given an integer array nums. Return a boolean array answer of the same length, where answer[i] is true if nums[i] is almost prime and false otherwise.

Function

almostPrimes(nums: int[]) → boolean[]

Examples

Example 1

nums = [4,6,9,25,1]return = [true,false,true,true,false]

4 has divisors 1, 2, 4, 9 has 1, 3, 9, and 25 has 1, 5, 25, so they are almost prime. 6 has four divisors and 1 has only one.

Example 2

nums = [8,16,49]return = [false,false,true]

8 has divisors 1, 2, 4, 8 and 16 has 1, 2, 4, 8, 16, so neither has exactly three. 49 has 1, 7, 49.

Example 3

nums = [961,1000000000]return = [true,false]

961 = 31 * 31, and 31 is prime, so the divisors are 1, 31, 961. 1000000000 has many divisors, such as 2, 5, and 10.

Constraints

  • 1 <= nums.length <= 10^5
  • 1 <= nums[i] <= 10^9

More Adobe problems

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
All Adobe interview questionsSee Adobe hiring insights
Saved
public boolean[] almostPrimes(int[] nums) {
    // Write your code here.
}
Checking account…