Cross Bridge in minimum time in codefights

This is veryintersting and I just worte down some testcases and
found algorithm.
someday I will write detail of this problem.


my code is here
 int c, l;
 int Bridge(int[] t) {
  l=t.length;
  Arrays.sort(t);
  
  while(l>3) {
   c+= Math.min( 2*t[1],  t[l - 2] + t[0]) + t[l-1] + t[0];
   l-=2;   
  }
  return c+= l<3?t[l-1]:t[1] + t[0]+t[2];
 }

https://codefights.com/challenge/K4HYozLrbRoLHkt8P

Comments

Popular posts from this blog

Project euler 169 found clue

Floyd-Warshall's algorithm