Given a list of elements, a surpasser of an element is an element on its right hand side that is larger than it. The surpasser count of an element is the number of its surpassers. Return the maximum surpasser count of a list.
- List of elements may occupy max memory size;
- The set of elements are any a poset (orderable);
msc of G,E,N,E,R,A,T,I,N,G is 6
msc of 10,3,4,5,2 is 2
msc←{⌈/+/¨⍵<⊖,\⊖⍵}
msc←{1>⍴⍵:0⋄H←(1↑⍵)⋄(+/{H<⍵}¨(1↓⍵))⌈∇(1↓⍵)}
msc[]=0;msc(h:t)=sum[1|y<-t,y>h]`max`msc t
msc[]=0;msc(h:t)=max(sum[1|x<-t,h<x])$msc t
msc l=maximum[sum[1|x<-t,x>h]|h:t<-tails l]
msc=maximum.ap(zipWith((length.).filter.(<)))tails
msc(x)=maximum(count(>(x[i]),x[i:end]) for i=1:length(x))
msc=lambda l: max([sorted(l[i:])[::-1].index(e) for i,e in enumerate(l)])
msc=lambda l:max([len([x for x in l[e:] if x>l[e]]) for e in range(len(l))])
msc l=maximum(map length(groupBy(==)[x|x<-[0..length l-1],y<-drop x l,y>l!!x]))
func msc<T:Comparable>(_ l:[T]){l.enumerated().map{i,e in l.dropFirst(i).filter{e<$0}.count}.max()!}
Either by ignorance or by Swift type system, in order to work with Array of Arrays we need to teach Swift how we want to compare those arrays.
extension Array: Comparable where Element: Comparable {
public static func < (lhs: [Element], rhs: [Element]) -> Bool {
return lhs.count < rhs.count
}
}