Manafall Daily Quest

Prime Factorization

Function Name: primeFactors

Description

Write a function that computes the prime factors of a given number, n.

A prime factor is a factor that is a prime number, and prime factorization is the determination of the set of prime numbers which multiply together to give the original integer.

The function should return an array of integers that represents the prime factors of the given number in ascending order.

Requirements

  • The function 'primeFactors' should take an integer 'n' as its only parameter.
  • The input number 'n' will be a positive integer greater than 1.
  • If the number is prime, return the number itself within an array.
  • The function should return an empty array if the input is less than or equal to 1.
  • Do not use any third-party libraries or built-in prime number functions.
  • Optimize the function for readability and efficiency.

Examples

Example 1: primeFactors(6) should return [2, 3].Example 2: primeFactors(28) should return [2, 2, 7].Example 3: primeFactors(29) should return [29].Example 4: primeFactors(1) should return [].

Links

https://en.wikipedia.org/wiki/Prime_numberhttps://en.wikipedia.org/wiki/Prime_factorhttps://www.mathsisfun.com/prime-factorization.html

Magic Index Finder

Thu Aug 22 2024

In a given sorted array of distinct integers, write a function named 'findMagicIndex' that finds and returns a 'magic index' if one exists. A 'magic index' in an array A is defined as an index i such that A[i] equals i. If no such index exists, the function should return -1. Assume the array is sorted in ascending order and there are no duplicate elements.

Prev Quest

Circular Queue Implementation

Sat Aug 24 2024

Create a CircularQueue class that represents a circular queue for integers with a fixed size.It should support enqueue (add an item), dequeue (remove and return an item), and isEmpty methods.Additionally, the CircularQueue class should have a method to return the current size of the queue.

Next Quest