Hi,
I am working on below challenge
http://codingbat.com/prob/p199484
Psedo code description of approach :
1. create new array of given array size
2. loop given array in for loop
3. check each element value not greater than 10
4. if yes multiply by 10
5 if no give same value from given array to new array
I wrote my code as below
public int[] tenRun(int[] nums) {
int len =nums.length;
int[] arr=new int[len];
for(int i=0;i<len;i++){
if(nums[i]<10){
arr[i]=nums[i]*10;
}
else{
arr[i]=nums[i];
}
}
return arr;
}
I am not passing all tests
Expected Run
tenRun([2, 10, 3, 4, 20, 5]) → [2, 10, 10, 10, 20, 20] [20, 10, 30, 40, 20, 50] X
tenRun([10, 1, 20, 2]) → [10, 10, 20, 20] [10, 10, 20, 20] OK
tenRun([10, 1, 9, 20]) → [10, 10, 10, 20] [10, 10, 90, 20] X
tenRun([1, 2, 50, 1]) → [1, 2, 50, 50] [10, 20, 50, 10] X
tenRun([1, 20, 50, 1]) → [1, 20, 50, 50] [10, 20, 50, 10] X
tenRun([10, 10]) → [10, 10] [10, 10] OK
tenRun([10, 2]) → [10, 10] [10, 20] X
tenRun([0, 2]) → [0, 0] [0, 20] X
tenRun([1, 2]) → [1, 2] [10, 20] X
tenRun([1]) → [1] [10] X
tenRun([]) → [] [] OK
other tests
X
How to improve my design, approach, code? please advise
Our community of experts have been thoroughly vetted for their expertise and industry experience.