You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/** * Two pointer algorithm * O(2*n) * See: * http://codeforces.com/contest/676/problem/C * http://codeforces.com/contest/580/problem/B * * @paramn maximum right bound * @paramf given an interval returns if it is acceptable * f must be monotonic i.e. for all super-interval j of i, f(j) implies f(i) * * @return List of all intervals in [0, n) at which f is acceptable*/defvalidIntervals(n: Int)(f: (Int, Int) =>Boolean):Iterator[(Int, Int)] = {
valit=newIterator[Option[(Int, Int)]] {
varl, r=0overridedefhasNext= r < n
overridedefnext() = {
if(f(l, r)) {
r +=1Some((l, r -1))
} else {
if(l < r) l +=1else r +=1None
}
}
}
it.flatten
}
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: