about | help | code help+videos | done | prefs |
hills
Given an integer n, return an array containing the pattern: 0, 0,1,0 , 0,1,2,1,0 , 0,1,2,3,2,1,0. The pattern continues until the number at the peak is n. Hint (only if it's helpful for you!): 1+3+5+7+...+(2n+1) = (n+1)^2. For example: 1+3+5= (2+1)^2 = 9 hills(2) → [0, 0, 1, 0, 0, 1, 2, 1, 0] hills(1) → [0, 0, 1, 0] hills(0) → [0] ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 250
Copyright Nick Parlante 2017 - privacy