java - codility challenge, test case OK , Evaluation report Wrong Answer -


the aluminium 2014 gives me wrong answer [3 , 9 , -6 , 7 ,-3 , 9 , -6 , -10] got 25 expected 28

but when repeated challenge same code , make case test gives me correct answer

your test case [3, 9, -6, 7, -3, 9, -6, -10] : no runtime errors (returned value: 28)

what wrong ???

the challenge :-

a non-empty zero-indexed array consisting of n integers given. pair of integers (p, q), such 0 ≤ p ≤ q < n, called slice of array a. sum of slice (p, q) total of a[p] + a[p+1] + ... + a[q]. maximum sum maximum sum of slice of a. example, consider array such that: a[0] = 3 a[1] = 2 a[2] = -6 a[3] = 3 a[4] = 1 example (0, 1) slice of has sum a[0] + a[1] = 5. maximum sum of a. can perform single swap operation in array a. operation takes 2 indices , j, such 0 ≤ ≤ j < n, , exchanges values of a[i] , a[j]. goal find maximum sum can achieve after performing single swap. example, after swapping elements 2 , 4, following array a: a[0] = 3 a[1] = 2 a[2] = 1 a[3] = 3 a[4] = -6 after that, (0, 3) slice of has sum a[0] + a[1] + a[2] + a[3] = 9. maximum sum of after single swap. write function: class solution { public int solution(int[] a); } that, given non-empty zero-indexed array of n integers, returns maximum sum of slice of after single swap operation. example, given: a[0] = 3 a[1] = 2 a[2] = -6 a[3] = 3 a[4] = 1 function should return 9, explained above.

and code :-

import java.math.*;  class solution {     public int solution(int[] a) {         if(a.length == 1)              return a[0];         else if (a.length==2)             return a[0]+a[1];          else{             int finalmaxsum = a[0];              (int l=0 ; l<a.length ; l++){                 (int k = l+1 ; k<a.length ; k++ ){                      int [] newa = a;                     int temp = newa[l];                     newa [l] = newa[k];                     newa[k]=temp;                      int maxsum = newa[0];                     int current_max = newa[0];                     for(int = 1; < newa.length; i++)                     {                         current_max = math.max(a[i], current_max + newa[i]);                          maxsum = math.max(maxsum, current_max);                     }                      finalmaxsum = math.max(finalmaxsum , maxsum);                  }             }              return finalmaxsum;         }     } } 

i don't know what's wrong ??

it bug in website , reply support team

the evaluation system run program not on test case presented you, on mirrored test case b = [-10, -6, 9, -3, 7, -6, 9, 3]. on test case b program indeed returned 22, when should have returned 28.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -