Manafall Daily Quest

Validate Subsequence

Function Name: isValidSubsequence

Description

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.

Requirements

  • The function must take two parameters: an array of integers (the main array) and another array of integers (the sequence).
  • The function should return a boolean indicating whether the second array is a subsequence of the first array.
  • The function should not mutate the input arrays.
  • Aim to optimize the function for time complexity.
  • Do not use built-in functions that perform the operation directly.

Examples

Given mainArray = [5, 1, 22, 25, 6, -1, 8, 10] and sequence = [1, 6, -1, 10], the function should return true.Given mainArray = [5, 1, 22, 25, 6, -1, 8, 10] and sequence = [0, 3, 14], the function should return false.

Links

https://en.wikipedia.org/wiki/Subsequencehttps://www.geeksforgeeks.org/subsequence-of-an-array/

Count Primes

Sat Nov 30 2024

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.

Prev Quest

Balanced Brackets

Mon Dec 02 2024

Write a function that takes a string containing bracket characters ('(', ')', '{', '}', '[' and ']') and checks whether the string contains a balanced set of brackets.A string has balanced brackets if each type of bracket is properly closed and nested within the string.The function should return a boolean indicating whether the input string is balanced.

Next Quest