id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

zbaharav@kehillah.org 54-practice-array > hills
prev  |  next  |  chance

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)

public int[] hills(int n){ }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 250

Copyright Nick Parlante 2017 - privacy