Skip to main content
5 of 10
added 85 characters in body
Unmitigated
  • 2.8k
  • 1
  • 5
  • 14

Java, 257 246 210 200 195 bytes

a->{Integer r=9,i=512,j,e,s,k,x,y,z;for(;i-->0;j=r.bitCount(i),r=e!=0|r<j?r:j)for(j=s=e=0;j<3;s=s<1?x:s,e|=x-s|y-s,j++)for(k=x=y=0;k<9;x+=k/3==j?z:0,y+=k++%3==j?z:0)z=(i&1<<k)>0?7:a[k];return r;}

Saved 11 bytes thanks to ceilingcat.

Saved 46 bytes thanks to Olivier Grégoire.

Saved 5 bytes thanks to Donat.

Takes a flat array as input. This method tries all 512 (29) possibilities by using the binary representations of the integers from 0 to 511. On each iteration, it sets the values at all indexes where i has a set bit to 7. Then, it checks if the current array is valid, in which case the answer is updated.

Try it online!

Unmitigated
  • 2.8k
  • 1
  • 5
  • 14