Guest User

Untitled

a guest
Oct 24th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. public static int maxSizeAlterSlice(int[] a){
  2. int max_size_so_far = -1;
  3. int cur_max_size = -1;
  4. if(a.length == 1)
  5. return 1;
  6. int startInd = 0;
  7. int endInd = 0;
  8. int i=1;
  9. int compareInd=0;
  10. while(i<a.length){
  11. if((a[compareInd]>=0 && a[i]<=0)||(a[compareInd]<=0 && a[i]>=0)){
  12. compareInd=i;
  13. endInd++;
  14. i++;
  15. }else{
  16. cur_max_size = endInd-startInd+1;
  17. if(max_size_so_far<cur_max_size){
  18. max_size_so_far = cur_max_size;
  19. }
  20. startInd = i;
  21. compareInd=startInd;
  22. endInd=startInd;
  23. i=startInd+1;
  24. }
  25. }
  26. return max_size_so_far;
  27. }
Add Comment
Please, Sign In to add comment