Sort by

recency

|

258 Discussions

|

  • + 0 comments
    int div = 1;
        int ans = 1;
            if(l==b){
                return ans;
            }else {              
                for(int i= 1 ; i<=l;i++ ){
                     if((l%i==0) && (b%i==0)){
                         div = i;                     
                     }
                }
               ans = (l*b)/(div*div);
            }
             return ans;
    
  • + 0 comments

    Can Someone Find the Error in my Function

    int restaurant(int l, int b) { if(0 == b % l ) { return b/l; } else { float frac = (float)b / (float)l ; int i = 1; while( (frac != (int)(frac)) ) { frac +=(float)b / (float)l; i++; } return (int)(i)*(int)(frac); } }

  • + 0 comments
    python3
    
    def divisor(n):
        div = []
        for i in range(1,n+1):
            if i == 1 or i == n:
                div.append(i)
            else:
                if n % i == 0:
                    div.append(i)
        
        return div
        
    def restaurant(l,b):
        # Write your code here
        divl = divisor(l)
        divb = divisor(b)
        common = []
        for i in divl:
            if i in divb:
                common.append(i)
                
        maximum = max(common)
        total = int((l/maximum)*(b/maximum))
        return total    
        
            
    
  • + 0 comments

    My code in Java 15:

    public static int restaurant(int l, int b) {
        // Write your code here
            int oriSize = l * b;
            int pS = gcd(l, b); // possibleBiggestSide
            
            return (l / pS) * (b / pS);
    
        }
        
        private static int gcd(int a, int b){
            
            if(a < b){
                int temp = a;
                a = b;
                b = temp;
            }
            if(b == 0) return a;
            return gcd(b, a % b);
            
        }
    
  • + 1 comment

    Easy one in C++, just using the GCD:

    int restaurant(int l, int b) 
    {
        int size = __gcd(l, b);
        
        return (l/size) * (b/size);
    }