Facebook Practice Puzzle
Anonymous User
3039

image

Here is my C++ code:

#include <bits/stdc++.h>
using namespace std;
// Write any include statements here

long long getMinCodeEntryTime(int N, int M, vector<int> C) {
  // Write your code here
  int ans = 0;
  int curr = 1;
  for(auto c : C)
  {
    int lower = c;
    lower = min(c,curr);
    int higher = (lower == c)?curr:c;
    ans += min(abs(higher-lower),N - higher+lower );
    curr = c;
  }
  
  return ans;
}

I cant seem to figure out whats wrong in this. I can only pass 15/30 cases. It seemed very simple but as of now I cannot find where I am wrong. Please help

Comments (20)