Guest User

Untitled

a guest
Oct 18th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. function solution(board)
  2. {
  3. var arr = [];
  4. let index = 0;
  5. let max = 0;
  6. for(let value of board){
  7. value.forEach((v,i)=>{
  8. if(v === 1){
  9. arr[i] = (arr[i])? arr[i]+1: 1;
  10. }
  11. })
  12. }
  13. arr.forEach((v)=>{
  14. if(max < v){
  15. max = v;
  16. }
  17. })
  18. arr.sort((a,b)=>a-b);
  19. for(let i = max; i > 0; i--){
  20. for(let value of arr){
  21. if(value >= i){
  22. index++;
  23. }
  24. }
  25. if(i === index){
  26. return i*i;
  27. }
  28. index = 0;
  29. }
  30. }
Add Comment
Please, Sign In to add comment