Snippets Collections
class Solution
{
    public static boolean check(int n,int counter)
    {
        if(counter<=n){
            if(n%counter==0)
                return false;
		    // calculate next position of input number
		    n=n-n/counter;
		    counter++;
		    // make recursive call with updated counter 
		    // and position return check(n, counter);
		    return check(n, counter);
        }    
       	else
       		return true;
    }
    
    // n: Input n
    // Return True if the given number is a lucky number else return False
    public static boolean isLucky(int n)
    {
        return check(n,2);
    }
}
star

Sun Feb 06 2022 23:08:00 GMT+0000 (Coordinated Universal Time) https://practice.geeksforgeeks.org/problems/lucky-numbers2911/1/?track=DSASP-Recursion&batchId=190

#java #gfg #geeksforgeeks #recursion #luckynumbers

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension