internship. They have separate tests ig for TAs.
can u share pdf of final test results also ?
Does anybody have the pdf of final round results ?? Also apart from interview opportunity , are there any prizes as well for the top rankers ??
Its fault of coding ninjas. They should not give a problem for which an online solution is available. I also could not able to do this problem but at least it’s ok to fail without cheating
import java.util.*;
class Main{
public static void main (String[] args) {
Scanner sc= new Scanner(System.in);
int n=sc.nextInt();
int a[]=new int[n];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
int k=sc.nextInt();
minimum(a,k);
}
public static void minimum(int []a,int k){
//finding sub array whose multiplication will make it largest subarray
int sum=0,max=a[0],end_index=0;
for(int i=0;i<a.length;i++){
sum+=a[i]*k;
max=Math.max(sum,max);
if(sum<0){
sum=0;
}
else{
end_index=i;
sum=sum;
}
//sum= sum<0 ? 0:sum;
}
//copying that sub array to original array
for(int i=end_index;max>0;i--){
a[i]=a[i]*k;
max-=a[i];
}
//now again finding largest sub array sum
sum=0;max=a[0];end_index=0;
for(int i=0;i<a.length;i++){
sum+=a[i];
max=Math.max(sum,max);
sum= sum<0 ? 0:sum;
}
//System.out.println(Arrays.toString(a));
System.out.println(max);
}
}