Manafall Daily Quest

Array Quadruplet

Function Name: findQuadruplet

Description

Write a function called 'findQuadruplet' that finds a quadruplet of numbers in a given array that sum up to a given target sum. A quadruplet is a group of four numbers that are part of the array. The function should return an array of these four numbers in any order. If there is no such quadruplet present in the array, the function should return an empty array.

Requirements

  • The function should take an array of integers and a target sum as its arguments.
  • Do not use any built-in functions that solve the problem directly.
  • Optimize for time complexity as much as possible.
  • The function should return the first quadruplet that it encounters which meets the requirement.
  • If there's no such quadruplet, return an empty array.
  • The quadruplet should be returned in an array, regardless of their order in the original array.

Examples

findQuadruplet([2, 7, 4, 0, 9, 5, 1, 3], 20) -> returns [2, 4, 7, 7]findQuadruplet([1, 2, 3, 4, 5, 6, 7, 8], 30) -> returns []findQuadruplet([1, 2, 3, 4, 5, -5, 12, -1], 10) -> returns [2, 3, 5, -5]

Robot Room Cleaner

Wed Oct 23 2024

Imagine a robot sitting on the upper left corner of a grid with rows and columns. The grid is filled with dirt (represented by a '1'), and clean tiles are represented by a '0'. The robot can move up, down, left, or right, and it can clean the tile it's on. The function 'cleanRoom' should simulate the cleaning process. It takes a 2D array representing the room's condition, a start position for the robot, and returns the number of tiles cleaned by the robot. It cleans each dirty tile only once, regardless of the path taken.

Prev Quest

Fibonacci Finder

Fri Oct 25 2024

Write a function named `fibonacci_at_index` that takes one integer parameter, `n`,and returns the nth number in the Fibonacci sequence, where the sequence starts with 0 (zero based indexing).The Fibonacci sequence is defined by the following recurrence relation:F(0) = 0, F(1) = 1,F(n) = F(n - 1) + F(n - 2)for n > 1. Your solution should be efficient enough to handle values of `n` up to 30 withoutsignificant performance degradation. Avoid recursion that can lead to a stack overflow, or inefficientcomputations that lead to long processing times.

Next Quest