Cinema Seat Allocation
Function Name: maximizeAttendees
Description
Imagine there is a small cinema with a single row of seats, numbered from 1 to 50. Due to social distancing guidelines, every group attending must leave at least two empty seats between other groups. Your task is to write a function that determines the maximum number of attendees the cinema can accommodate given a list of reserved seats.
Your function should return the maximum number of additional attendees that can be accommodated without violating the distancing guidelines. Note that groups can have an arbitrary number of members, but the number of groups is not provided.
Requirements
- The function must accept one parameter: an array of integers, where each integer represents a reserved seat number.
- Assume that each reserved seat is occupied by exactly one person.
- The function should consider distancing guidelines that require at least two empty seats between groups.
- If a seat or sequence of seats could belong to multiple groups, allocate them in a way that maximizes the attendees.
- Both ends of the row (seat 1 and seat 50) can be occupied without extra spaces since there's no adjacent seat beyond the ends.
- Return the total number of possible additional attendees the cinema can accommodate.
Examples
If the reserved seats are [2, 5, 8, 11], the function maximizeAttendees([2, 5, 8, 11]) should return 9.The seating could be arranged as follows: 1, (3, 4), (6, 7), 9, 10, (12, 13, 14), 15-50.
Links
Prime Factorization
Thu Sep 05 2024
Write a function that takes a positive integer as an argument and returns its prime factorization in the form of an array. Prime factorization means breaking down a composite number into its prime factors. The function needs to return the prime factors sorted in ascending order.For example, the prime factorization of 18 is [2, 3, 3], as it can be expressed as 2 * 3 * 3.A prime number has exactly two distinct natural number divisors: 1 and itself. Your task is to efficiently compute the prime factors for any given positive integer.
Array Pair Sum
Sat Sep 07 2024
Write a function that finds and returns a pair of numbers from a given array of integers that adds up to a given sum. If there are multiple pairs that match the given sum, the function should return the first pair found. If no such pair exists, return an indication that no such pair has been found, such as null or an empty list.