Enable contrast version

# Tutor profile: Shan M.

Inactive
Shan M.
Data Scientist at Media iQ Digital
Tutor Satisfaction Guarantee

## Questions

### Subject:Python Programming

TutorMe
Question:

The stock span problem is a financial problem where we have a series of n daily price quotes for a stock and we need to calculate span of stock’s price for all n days. The span Si of the stock’s price on a given day i is defined as the maximum number of consecutive days just before the given day, for which the price of the stock on the current day is less than or equal to its price on the given day.

Inactive
Shan M.

def calculateSpan(price, n, S): # Span value of first day is always 1 S = 1 # Calculate span value of remaining days by linearly # checking previous days for i in range(1, n, 1): S[i] = 1 # Initialize span value # Traverse left while the next element on left is # smaller than price[i] j = i - 1 while (j>=0) and (price[i] >= price[j]) : S[i] += 1 j -= 1 def printArray(arr, n): for i in range(n): print(arr[i], end = " ") # Driver program to test above function price = [10, 4, 5, 90, 120, 80] n = len(price) S = [None] * n # Fill the span values in list S[] calculateSpan(price, n, S) # print the calculated span values printArray(S, n)

### Subject:Java Programming

TutorMe
Question:

The stock span problem is a financial problem where we have a series of n daily price quotes for a stock and we need to calculate span of stock’s price for all n days. The span Si of the stock’s price on a given day i is defined as the maximum number of consecutive days just before the given day, for which the price of the stock on the current day is less than or equal to its price on the given day.

Inactive
Shan M.

import java.util.Arrays; class GFG { // method to calculate stock span values static void calculateSpan(int price[], int n, int S[]) { // Span value of first day is always 1 S = 1; // Calculate span value of remaining days by linearly checking // previous days for (int i = 1; i < n; i++) { S[i] = 1; // Initialize span value // Traverse left while the next element on left is smaller // than price[i] for (int j = i-1; (j>=0)&&(price[i]>=price[j]); j--) S[i]++; } } { System.out.print(Arrays.toString(arr)); } // Driver program to test above functions public static void main(String[] args) { int price[] = {10, 4, 5, 90, 120, 80}; int n = price.length; int S[]= new int[n]; // Fill the span values in array S[] calculateSpan(price, n, S); // print the calculated span values printArray(S); } }

### Subject:C Programming

TutorMe
Question:

The stock span problem is a financial problem where we have a series of n daily price quotes for a stock and we need to calculate span of stock’s price for all n days. The span Si of the stock’s price on a given day i is defined as the maximum number of consecutive days just before the given day, for which the price of the stock on the current day is less than or equal to its price on the given day.

Inactive
Shan M.

void calculateSpan(int price[], int n, int S[]) { // Span value of first day is always 1 S = 1; // Calculate span value of remaining days by linearly checking // previous days for (int i = 1; i < n; i++) { S[i] = 1; // Initialize span value // Traverse left while the next element on left is smaller // than price[i] for (int j = i-1; (j>=0)&&(price[i]>=price[j]); j--) S[i]++; } } void printArray(int arr[], int n) { for (int i = 0; i < n; i++) printf("%d ", arr[i]); } // Driver program to test above function int main() { int price[] = {10, 4, 5, 90, 120, 80}; int n = sizeof(price)/sizeof(price); int S[n]; // Fill the span values in array S[] calculateSpan(price, n, S); // print the calculated span values printArray(S, n); return 0; }

## Contact tutor

Send a message explaining your
needs and Shan will reply soon.
Contact Shan