Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8649565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:35:35+00:00 2026-06-12T13:35:35+00:00

I just gave a coding interview on codility I was asked the to implement

  • 0

I just gave a coding interview on codility

I was asked the to implement the following, but i was not able to finish it in 20 minutes, now I am here to get ideas form this community

Write a function public int whole_cubes_count ( int A,int B ) where it should return whole cubes within the range

For example if A=8 and B=65, all the possible cubes in the range are 2^3 =8 , 3^3 =27 and 4^3=64, so the function should return count 3

I was not able to figure out how to identify a number as whole cube. How do I solve this problem?

A and B can have range from [-20000 to 20000]

This is what I tried

import java.util.Scanner;
class Solution1 {
  public int whole_cubes_count ( int A,int B ) {
      int count =0;

    while(A<=B)
    {
        double v = Math.pow(A, 1 / 3); // << What goes here?
        System.out.println(v);
        if (v<=B)
            {
            count=count+1;
            }
        A =A +1;
    }
    return count ;
  }

  public static void main(String[] args) 
  {
    System.out.println("Enter 1st Number");
    Scanner scan = new Scanner(System.in);
    int s1 = scan.nextInt();
    System.out.println("Enter 2nd Number");
    //Scanner scan = new Scanner(System.in);
    int s2 = scan.nextInt();
    Solution1 n = new Solution1();
     System.out.println(n.whole_cubes_count (s1,s2));
  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:35:37+00:00Added an answer on June 12, 2026 at 1:35 pm

    Down and dirty, that’s what I say.

    If you only have 20 minutes, then they shouldn’t expect super-optimized code. So don’t even try. Play to the constraints of the system which say only +20,000 to -20,000 as the range. You know the cube values have to be within 27, since 27 * 27 * 27 = 19683.

    public int whole_cubes_count(int a, int b) {
        int count = 0;
        int cube;
        for (int x = -27; x <= 27; x++) {
            cube = x * x * x;
            if ((cube >= a) && (cube <= b))
                count++;
        }
        return count;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just starting with The Well-Grounded Rubyist, and they gave the following example: print
Im not getting the data correctly. this just gave me nothing!? function getUser() {
I'm learning about POSIX threads right now, but I guess this is just a
I just gave an answer to a quite simple question by using an extension
Just checking my JS and I have an error, but I cannot see where.
Pretty straight forward question, I've just forgotten the correct coding to do it. I
I just gave a database diagram for a DB I created to our head
My teacher just gave me an assignment in c++ and I am trying to
Google App Engine just gave me an error I don't understand. Given a module
I'm just curious if I'm doing this right. I'm coding a private section of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.