Mathworks EDG New Grad | OA 2020 | Ideal Numbers In a Range

image
image

My Solution
#include <bits/stdc++.h>

using namespace std;

string ltrim(const string &);
string rtrim(const string &);


/*
 * Complete the 'getIdealNums' function below.
 *
 * The function is expected to return a LONG_INTEGER.
 * The function accepts following parameters:
 *  1. LONG_INTEGER low
 *  2. LONG_INTEGER high
 */

long getIdealNums(long low, long high) {
    long ans=0;
    for(long i=1;i<=high;i*=3)
    {
        for(long j=i;j<=high;j*=5)
        {
            if (j>=low)
            ans++;
        }
    }
    return ans;
}
Comments (10)