Forked from jakehawken/AlmostIncreasingSequence.swift
Last active
January 9, 2019 17:53
-
-
Save jakebromberg/96a95ed1cf476e63de4315494cf4dd07 to your computer and use it in GitHub Desktop.
For the "almostIncreasingSequence" problem on CodeFights:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Solves the problem in linear time and constant space