Menu

PWC 397: Reflection
📰

PWC 397: Reflection

DEV Community: perl·Bob Lied·16 days ago
#4nuoPGXG
#devtoperl#devto#dev#decimal#binary
Reading 0:00
15s threshold

October ends with a plaintive little offering from the weekly challenge . It asks us to consider the negative and liminal space just beyond the surface -- to search for what is missing; to create an order that is mysteriously irrational yet trivially banal; to contemplate what it is we yearn for. Listen to Wishing You Were Here .

Task 1: Absent Smallest Positive

The task

You are given an array of integers. Write a script to return the smallest absent positive integer such that it is strictly greater than the average of all elements in the given array.

Example 1

Input: @arr = (1, 2, 4, 5, 6)

Output: 7

Average: (1 + 2 + 4 + 5 + 6) / 5 = 3.6

We need the smallest positive integer absent from nums that is strictly greater than 3.6. The positive integers greater than 3.6 are 4, 5, 6, ...

The smallest missing one is 7.

Example 2

Input: @arr = (-5, -2, -1, 3)

Output: 1

The average is -1.25. There is a gap in the array between -1 and 3.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.