Back down to 394, thanks mostly to richierich :point:
EDIT: new record: 392! verified for all permutations.
int h(char[]g){
int n=99,i=-2,p=n,q=-p,r=p,s=q,v,w,y[]=new int[5*n];
for(;i<13;y[n+g[++i]]++)y[" A23456789TJQK".indexOf(g[i+=2])]++;
for(;n-->0;y[198+y[n]]=n)if(y[n]>0)if((p=n)<2)s=14;else{r=p=p<n?p:n;s=q=q>n?q:n;}
for(w=q-p<5|s-r<5?7:0;++n<99;y[297+y[99+n]]=n,y[396+y[n]]++)w&=y[n]/2-1;
for(v=y[302]>>5;new int[]{s-r<5?w&v:0,w&v,y[202],y[399]&p,v,w,y[201],p-1,p,1}[99-n]<1;n--)p=y[398];
return n;
}