Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.
Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.
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
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
Title | # Comments | Views | Activity |
---|---|---|---|
pagenation logic how it is working in my code | 1 | 54 | |
AutoIncrement column based of FK | 11 | 55 | |
ejb message driven bean mdb creation steps | 2 | 22 | |
Using jdbcTemplate.batchUpdate to improve INSERT performance | 6 | 22 |
Join the community of 500,000 technology professionals and ask your questions.