Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakebromberg/96a95ed1cf476e63de4315494cf4dd07 to your computer and use it in GitHub Desktop.
Save jakebromberg/96a95ed1cf476e63de4315494cf4dd07 to your computer and use it in GitHub Desktop.
For the "almostIncreasingSequence" problem on CodeFights:
extension Sequence where Element: Comparable {
func isAlmostIncreasingSequence() -> Bool {
var foundMisplacedElement = false
for (a, b) in zip(self, self.dropFirst()) where a >= b {
guard !foundMisplacedElement else { return false }
foundMisplacedElement = true
}
return true
}
}
@jakebromberg
Copy link
Author

jakebromberg commented Jan 9, 2019

Solves the problem in linear time and constant space

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment