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

 

tmhscs@gmail.com monroe > hasPerfectSquare
prev  |  next  |  chance

Mr. Monroe is obsessed with perfect squares! Every 3 weeks, he tests his AP CS class over a new topic and heavily scrutinizes if it is possible to choose a combination of grades such that the sum of the grades chosen is a positive perfect square. For example, among grades [1,76,45], 76 + 45 = 121, which is a perfect square. Rather than using a calculator to brute force this process, Mr. Monroe wants you to create a method that returns whether or not a positive perfect square can be made by the sum of the grades. (No loops needed.)


hasPerfectSquare(0, [0, 76, 45], 0) → true
hasPerfectSquare(0, [15, 20, 45, 91, 98], 0) → false
hasPerfectSquare(0, [64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64], 0) → true

...Save, Compile, Run (ctrl-enter)

public boolean hasPerfectSquare(int start, int[] grades, int sum) { }

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: 425 Post-solution available

Copyright Nick Parlante 2017 - privacy