A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.
public int bigDiff(int[] nums) {
int large=0;
int small=0;
for(int n:nums){
large= Math.max(large, n);
//large=n;
}
for(int n:nums){
small= Math.min(large, n);
// small=n;
}
return (large-small);
}
Expected Run
bigDiff([10, 3, 5, 6]) → 7 4 X
bigDiff([7, 2, 10, 9]) → 8 1 X
bigDiff([2, 10, 7, 2]) → 8 8 OK
bigDiff([2, 10]) → 8 0 X
bigDiff([10, 2]) → 8 8 OK
bigDiff([10, 0]) → 10 10 OK
bigDiff([2, 3]) → 1 0 X
bigDiff([2, 2]) → 0 0 OK
bigDiff([2]) → 0 0 OK
bigDiff([5, 1, 6, 1, 9, 9]) → 8 0 X
bigDiff([7, 6, 8, 5]) → 3 3 OK
bigDiff([7, 7, 6, 8, 5, 5, 6]) → 3 2 X
other tests
X
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
I know that; I'm trying to get him closer to the solution, without giving it to him.
public int bigDiff(int[] nums) {
int large=0;
int small=0;
for(int n:nums){
large= Math.max(large, n);
//large=n;
}
for(int n:nums){
small= Math.min(small, n);
// small=n;
}
return (large-small);
}
Expected Run
bigDiff([10, 3, 5, 6]) → 7 10 X
bigDiff([7, 2, 10, 9]) → 8 10 X
bigDiff([2, 10, 7, 2]) → 8 10 X
bigDiff([2, 10]) → 8 10 X
bigDiff([10, 2]) → 8 10 X
bigDiff([10, 0]) → 10 10 OK
bigDiff([2, 3]) → 1 3 X
bigDiff([2, 2]) → 0 2 X
bigDiff([2]) → 0 2 X
bigDiff([5, 1, 6, 1, 9, 9]) → 8 9 X
bigDiff([7, 6, 8, 5]) → 3 8 X
bigDiff([7, 7, 6, 8, 5, 5, 6]) → 3 8 X
other tests
X
public int bigDiff(int[] nums) {
int large=0;
int small=0;
int largest=0;
int smallest=0;
int result=0;
int len=nums.length;
for(int i=0;i<len-1;i++){
large= Math.max(nums[i], nums[i+1]);
//large=n;
// if(large>largest){
//result=l
}
for(int i=0;i<len-1;i++){
small= Math.min(nums[i], nums[i+1]);
// small=n;
}
return (large-small);
}
Expected Run
bigDiff([10, 3, 5, 6]) → 7 1 X
bigDiff([7, 2, 10, 9]) → 8 1 X
bigDiff([2, 10, 7, 2]) → 8 5 X
bigDiff([2, 10]) → 8 8 OK
bigDiff([10, 2]) → 8 8 OK
bigDiff([10, 0]) → 10 10 OK
bigDiff([2, 3]) → 1 1 OK
bigDiff([2, 2]) → 0 0 OK
bigDiff([2]) → 0 0 OK
bigDiff([5, 1, 6, 1, 9, 9]) → 8 0 X
bigDiff([7, 6, 8, 5]) → 3 3 OK
bigDiff([7, 7, 6, 8, 5, 5, 6]) → 3 1 X
other tests
X
If you are experiencing a similar issue, please ask a related question
Join the community of 500,000 technology professionals and ask your questions.