Count Primes
Function Name: countPrimes
Description
Write a function that takes a positive integer n and returns the number of prime numbers less than n.
The function should implement an efficient algorithm for counting primes (e.g., Sieve of Eratosthenes).
Do not use any built-in functions for detecting prime numbers.
Optimize the function to handle large numbers as inputs.
Requirements
- The function countPrimes should take a single integer parameter.
- Must not use any external libraries or packages.
- The result should be returned as an integer representing the count of prime numbers less than the input value.
- The input integer is non-negative.
- The code should be written with scalability in mind, efficiently handling large values of n.
Examples
If the function is called with the value 10, i.e., countPrimes(10), it should return 4 since there are four prime numbers (2, 3, 5, 7) less than 10.Calling the function with the value 0 or 1, i.e., countPrimes(0) or countPrimes(1), should return 0 since there are no prime numbers less than 0 or 1.
Links
Array Pair Sum Divisibility
Fri Nov 29 2024
In this challenge, you are given an array of integers and a positive integer 'k'. Your task is to write a function that checks whether it is possible to divide the array into pairs such that the sum of each pair is divisible by 'k'.The function should return a boolean value: true if such a division is possible, or false if it is not. Each element of the array can only be used in one pair.
Validate Subsequence
Sun Dec 01 2024
Write a function that takes in two non-empty arrays of integers. The function should determine whether the second array is a subsequence of the first one.A subsequence of an array is a set of numbers that aren't necessarily adjacent in the array but are in the same order as they appear in the array. For instance, [1, 3, 4] forms a subsequence of [1, 2, 3, 4], and so does [2, 4]. A single number in an array and the array itself are both valid subsequences of the array.You may assume that there will be no duplicate numbers in each array.