Ad
  • Custom User Avatar
  • Custom User Avatar

    Your code has a bug.
    Let say g=3, m=3, n=4
    Result: [0, 3] // Should be[0,0]

    Let say g=5, m=5, n=6
    Resutl: [0,6] // Should be [0,0]

    Your function will getting problem when g=m and n > m + 1 (or more)
    Your problem code is here:

    if (candidates[1] - candidates[0] == (long long)g) {
    return candidates;

    For the first iteration
    candidate[1] will fill with first prime number
    but candidate[0] is 0.
    So, when first prime - 0 == g (your code wrong here)
    // you should start compare candidate[0] and candidate[1] after these two values are filled

  • Custom User Avatar

    The description it too simple until made me confuse. Is the function requires remove all the duplicate values and return that array/list or need to count how many values are distinct and return that number. If just need to tell the number of distict values why made this function to return a pointer.