StockSpan

Run Settings
LanguageC#
Language Version
Run Command
using System; using System.Collections.Generic; using System.Linq; class MainClass { static void Main() { int[] price = { 10, 4, 5, 90, 120, 80 }; int n = price.Length; int[] S = new int[n]; CalculateStockSpan(price, S); foreach(var item in S) { Console.WriteLine(item.ToString() + " " ); } } public static void CalculateStockSpan(int[] price, int[] span){ span[0] = 1; for(int i = 1; i< price.Length; i++) { span[i] = 1; int currVal = price[i]; int j = i; while(j > 0 && currVal > price[j-1] ) { span[i]++; j--; } } } }
Editor Settings
Theme
Key bindings
Full width
Lines