Manafall Daily Quest

Stock Spanner

Function Name: calculateSpan

Description

Write a function to calculate the span of stock’s price on a given list of days. The span of the stock’s price today is defined as the maximum number of consecutive days (starting from today and going backward) for which the price of the stock was less than or equal to today's price.

The function should take an array of integers representing the stock prices and return an array of integers representing the span of each stock price.

Requirements

  • Your function should take an array of integers as its parameter.
  • The function should return an array of integers with the same length as the input array.
  • Each element in the returned array should be the span of the corresponding stock price in the input array.
  • You may not use libraries or built-in functions that directly solve this problem.
  • Optimize the function to handle a large list of stock prices efficiently.

Examples

If the input array is [100, 80, 60, 70, 60, 75, 85], then your function should return [1, 1, 1, 2, 1, 4, 6].Here's how the output is calculated:- For stock price 100 (day 1), the span is 1 because no earlier stock prices are available.- For stock price 80 (day 2), the span is 1 because 100 (day 1) is greater than 80.- For stock price 60 (day 3), the span is also 1 for the same reason as day 2.- For stock price 70 (day 4), the span is 2 because the stock price was lower for one day before day 4 (60 on day 3).- For stock price 75 (day 6), the span is 4 because the price was lower for days 3, 4, and 5.

Tic Tac Toe Validator

Sun Sep 29 2024

Write a function to validate a Tic Tac Toe game state. The game is played on a 3x3 grid. The function should determine if the given game state is a possible state that could be reached within the rules of Tic Tac Toe. The board is presented as a single array with 9 elements, representing rows from top to bottom, where 'X', 'O', or an empty string '' are the possible values for each cell.The function should return true if the board configuration is valid, and false otherwise. A valid Tic Tac Toe board has either 'X' or 'O' as the winner, or the game is ongoing or is a draw, but it cannot contain both 'X' and 'O' as winners. Additionally, the number of 'X's must be equal to or one more than the number of 'O's.

Prev Quest

Sum Of Two Linked Lists

Tue Oct 01 2024

Write a function 'sumOfLinkedLists' that takes two arguments representing the heads of two non-empty linked lists, each of which contains non-negative integers. The digits are stored in reverse order, with each of their nodes containing a single digit. Add the two numbers and return the sum as a linked list in the same reversed format.The function should create a new linked list that represents the sum of the numbers, with nodes containing single digits and the linked list still reversed.You can assume the two linked lists do not contain any leading zeros, except for the number 0 itself.

Next Quest