Facebook practice puzzle
Anonymous User
978
Sep 13, 2021
Sep 13, 2021

Is there any Leetcode problem similar to this facebook Practice Puzzle.
image

Here is my Solution:
For some reason I am unable to pass 2 cases and the Facebook Tool does not provide any insights into those test cases


long long getSecondsRequired(long long N, int F, vector<long long> P) {
  // Write your code here
  if(P.size() == 0 || F == 0)
    return 0;
  int groupSize = 1;
  sort(P.begin(),P.end());
  if(P.size() == 1)
  {
    return N - P[0];
  }
  long long ans = 0;
  int currPos = P[0];
  for(int i = 1;i < P.size();i++)
  {
    ans += P[i] - currPos - 1;
    currPos = P[i];
    groupSize++;
    
  }
  
  
  ans += N - P[P.size()-1] + groupSize - 1;

  return ans;
}
Comments (2)