Manafall Daily Quest

Stock Span Calculator

Function Name: calculateStockSpan

Description

Write a function that calculates the span of stock’s price for all days. The span of the stock's price today is defined as the maximum number of consecutive days (starting from today and going backwards) for which the price of the stock was less than or equal to today's price.

For example, if the list of stock prices was [100, 80, 60, 70, 60, 75, 85], then the function should return the spans as [1, 1, 1, 2, 1, 4, 6].

Requirements

  • The function should take an array of integers representing the stock prices as an argument.
  • It should return an array of integers where the ith integer represents the span of the stock price on day i.
  • The stock price list provided as input will have at least one price and at most 10,000 prices.
  • Each price will be at least 1 and no more than 100,000.

Examples

For the array [100, 80, 60, 70, 60, 75, 85], the output should be [1, 1, 1, 2, 1, 4, 6].If the input is [30, 35, 40, 38, 35], the result should be [1, 2, 3, 1, 1].For a single-price array like [50], the output would simply be [1].

Links

https://en.wikipedia.org/wiki/Technical_analysis

Symmetric Tree Check

Wed Jan 01 2025

Write a function that takes the root node of a binary tree as its parameter and returns a boolean indicating whether the tree is symmetric around its center. A binary tree is considered symmetric if it can be divided into two halves that are mirror images of each other.The function should handle trees with any number of nodes, and nodes may have the value of any integer.A tree with zero nodes (empty tree) should be considered symmetric.

Prev Quest