Advertisement
Andrey0125

Untitled

Mar 21st, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. bool almostIncreasingSequence(std::vector<int> sequence)
  2. {
  3. int count = 0;
  4. int problemIndex = 0;
  5. for(int i = 0; i < sequence.size() - 1; i++)
  6. {
  7. if(sequence[i] >= sequence[i + 1])
  8. {
  9. count++;
  10. problemIndex = i;
  11. }
  12. }
  13. if(count > 1)
  14. return false;
  15. return checkIncreasing(sequence, problemIndex) ||
  16. checkIncreasing(sequence, problemIndex + 1);
  17. }
  18.  
  19. bool checkIncreasing(vector<int> seq, int index)
  20. {
  21. if(index - 1 < seq.size() && index + 1 < seq.size())
  22. {
  23. if(seq[index - 1] >= seq[index + 1])
  24. {
  25. return false;
  26. }
  27. }
  28. for(int i = 0; i < seq.size() - 1; i++)
  29. {
  30. if(i == index || i + 1 == index)
  31. continue;
  32. else if(seq[i] >= seq[i + 1])
  33. return false;
  34. }
  35. return true;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement