Skip to content

Latest commit

 

History

History
34 lines (25 loc) · 656 Bytes

File metadata and controls

34 lines (25 loc) · 656 Bytes

Divide and print

  • it was a basic problem.
  • only implementation matters in this one.
  • below is mine.
implementation
string isFlexible(int n, vector<int> arr) {
  int i = 1;
  while (i < n and arr[i - 1] < arr[i])
    i++;
  int stop_one = i;

  while (i < n and arr[i - 1] == arr[i])
    i++;
  int stop_two = i;

  if (stop_one == stop_two)
    return "NO";
  if (stop_two == n)
    return "YES";

  while (i < n and arr[i - 1] > arr[i])
    i++;

  return (i == n ? "YES" : "NO");
}