Recursion Comments

Comments

  • i have tried to compile this on my dev C++ and it works ..

  • Why r.binarySearch?

  • Dear admin,

    When clicking on the Raw I/O option under Input I see "8":

    Input

    8 <<<<No Square
    25
    81
    225
    841
    1024
    7056
    36
    144

    Correct Output
    5
    9
    15
    29
    32
    84
    6
    12

    cont...
  • @David, the first number in raw input states how many cases there will be, it's not one of the actual cases.

  • Awesome site this is!

  • how do i know what is desired number? Should I make anarray from 0 to a, than start at midle checking if that number to power 2is a?

  • @armands, you don't actually need an array, but that's the right idea (see the hint).

  • Hi guys, i have written this code https://ideone.com/eFWUiZ its kind of bad, i know it , i suck at recursion but it was a bit logical for me i really don't know where i'm missing up

  • See if you can keep it organized. If you don't have the right number, see if it's larger or smaller and call your recursive method accordingly. You don't want to have two methods calling each other since that's just confusing. Look over the provided code for binary search and see how to adjust it for the "square root search" problem.

    cont...
  • WOOOHOOO! Man I'm pleased with my implementation of binary search.

    However, you see how I got the range for iMid and iMax?

    I made a crude estimation there... that the square root of any number could certainly be within the range = a/2

    cont...
  • After solving the question here, you can click on the "Featured Answers" link (next to the hint button) to see a possible solution. The idea is to use the same technique as binary search, but in search of the square root (i.e. the number that multiplied by itself equals the original number).

  • Working answer. Refer after trying it out

    public static int computeRoot(int mid,int a){
        if(mid==1){
        return 0;
        }
        if(mid*mid == a ){
    
    cont...
  • Getting a stack overflow error but am not sure what is wrong.

    //your code here
        int c=0;
        if(a==0){
            System.out.println(a + " -> "+b);
    
        }
        else{
            doStuff(a,b);
            System.out.println(a + " -> "+b);
            doStuff(c,b);
        }
    
  • I don't know if this is how you thought for us to do it but this works for me.

    //your code here
    int notUsed = 0;
    for (int i = 1; i <= 3; i++){
    if(i != a && i != b){
    notUsed = i;
    }
    }
    System.out.println(a + "->" + notUsed + " " + a + "->" + b + " " + notUsed + "->" + b);

  • @Kevin: you never break the loop.
    Hint: never reduces a, so it will never reach 0 to break the loop

  • Hi my script is correct (as i was able to test the correct output using another browser)

    however im not clear on whats the submition rule for learneroo. Using javascript, does learneroo accept
    console.log(Start + "->" + End)?

    cont...
  • @Ed, just use print() to print in Javascript. I'm going to add more help info soon.

  • Although I know the process of solution to the problem, I can't figure out how to transform into program. Could anyone give me some hint of how to program it?

  • You can view the beginning of a solution here. The comments there can help guide you to a full solution.

  • Thanks, I have finished the challenge with your hint.

  •     public static void doStuff(int a){
        solve(1, 3, a);
        System.out.println();
    }
    
    static void solve(int a, int b, int elements){
    
    cont...
  • Any answers or help for this one? I find the backtracking code suggestion pretty vague... Thanks!

  • See if the new hint help.

  • Thanks! Much clearer.
    Greg

  • static boolean groupSum(int index, int[] nums, int sum) {
    //base case: check if reached sum
    if(index==nums.length-1){
    if(sum==0)return true;

    cont...
Contact Us
Sign in or email us at [email protected]