Wrong input sample given in Weekly Contest 54 Q1?


  • 0
    A

    The test sample below is not correct:
    [-1,1,1,1,2,1]
    since nums[i] will be an integer between 0 and 49,999
    which results in my code getting RE?
    class Solution {
    public:
    int findShortestSubArray(vector<int>& nums) {
    int n = nums.size();
    int a[50001];
    memset(a, 0, sizeof(a));
    for(int i = 0; i < n; i++)
    a[nums[i]]++;
    int max = 0;
    for(int i = 0; i < n; i++)
    if(max < a[i])
    max = a[i];
    int ans = n;
    for(int i = 0; i < n; i++)
    if(max == a[i])
    {
    int left,right;
    for(int j = 0; j < n;j++)
    if(nums[j] == i)
    {
    left =j;
    break;
    }
    for(int j = n-1; j >= 0; j--)
    if(nums[j] == i)
    {
    right =j;
    break;
    }
    if(ans>right-left+1)
    ans = right-left+1;
    }
    return ans;
    }
    };


  • 0
    H

    @alpc113 said in Wrong input sample given in Weekly Contest 54 Q1?:

    since nums[i] will be an integer between 0 and 49,999
    which results in my code getting RE?

    why this round not have announcement in contest? i don't know why this round will be rated-.-


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.