Solved

scoresSpecial  challenge

Posted on 2016-08-30
13
68 Views
Last Modified: 2016-09-09
Hi,

i am working one below challenge
http://codingbat.com/prob/p140485

i was not clear on below description


Given two arrays, A and B, of non-negative int scores. A "special" score is one which is a multiple of 10, such as 40 or 90. Return the sum of largest special score in A and the largest special score in B. To practice decomposition, write a separate helper method which finds the largest special score in an array. Write your helper method after your scoresSpecial() method in the JavaBat text area.


how below results are 40 each? please advise
scoresSpecial([12, 10, 4], [2, 20, 30]) → 40
scoresSpecial([20, 10, 4], [2, 20, 10]) → 40
scoresSpecial([12, 11, 4], [2, 20, 31]) → 20
0
Comment
Question by:gudii9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
  • +1
13 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 41777567
>Return the sum of largest special score in A and the largest special score in B
+
>write a separate helper method which finds the largest special score in an array

actually, the answer is fully given there, apart from actually giving out the code itself.
0
 
LVL 16

Expert Comment

by:krakatoa
ID: 41778419
Good luck to you in your mysterious and futile mission.
0
 
LVL 7

Author Comment

by:gudii9
ID: 41790640
public int scoresSpecial(int[] a, int[] b) {
  int result1=0;
  int result2=0;
  int initialA=0;
  int intitiaB=0;
  for(int i=0;i<a.length;i++){
    if(a[i]%10==0){
      result1=result1+a[i];
    }
    
  }
  for(int j=0;j<b.length;j++){
    if(b[j]%10==0){
      result2=result1+b[j];
    }
  }
  return (result1+result2);
}

Open in new window


something like above?
xpected      Run            
scoresSpecial([12, 10, 4], [2, 20, 30]) → 40      50      X      
scoresSpecial([20, 10, 4], [2, 20, 10]) → 40      70      X      
scoresSpecial([12, 11, 4], [2, 20, 31]) → 20      20      OK      
scoresSpecial([1, 20, 2, 50], [3, 4, 5]) → 50      70      X      
scoresSpecial([3, 4, 5], [1, 50, 2, 20]) → 50      20      X      
scoresSpecial([10, 4, 20, 30], [20]) → 50      140      X      
scoresSpecial([10, 4, 20, 30], [20]) → 50      140      X      
scoresSpecial([10, 4, 20, 30], [3, 20, 99]) → 50      140      X      
scoresSpecial([10, 4, 20, 30], [30, 20, 99]) → 60      140      X      
scoresSpecial([], [2]) → 0      0      OK      
scoresSpecial([], [20]) → 20      20      OK      
scoresSpecial([14, 10, 4], [4, 20, 30]) → 40      50      X      
other tests
X

how to get biggest 10 multiple from array a and also array b to add them up and return?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Author Comment

by:gudii9
ID: 41790649
public int scoresSpecial(int[] a, int[] b) {
  int result1=0;
  int result2=0;
  int initialA=0;
  int initialB=0;
  for(int i=0;i<a.length;i++){
    if(a[i]%10==0&&initialA<a[i]){
     
      initialA=a[i];
       result1=initialA;
    }
    
  }
  for(int j=0;j<b.length;j++){
    if(b[j]%10==0&&initialB<b[j]){
      
      initialB=b[j];
      result2=initialB;
    }
  }
  return (result1+result2);
}

Open in new window

something like above. Above passes all tests.
Any improvements or alternate approaches?
0
 
LVL 7

Author Comment

by:gudii9
ID: 41790660
public int scoresSpecial(int[] a, int[] b) {

  return (scoresUtil(a)+scoresUtil(b));
}

  public int scoresUtil(int[] x){
  int result1=0;
  int result2=0;
  int initialA=0;
  int initialB=0;
  for(int i=0;i<x.length;i++){
    if(x[i]%10==0&&initialA<x[i]){
     
      initialA=x[i];
       result1=initialA;
    }
   
  }

 return result1;
}

Open in new window

more refactored to helper method as above.
0
 
LVL 27

Assisted Solution

by:rrz
rrz earned 250 total points
ID: 41790706
That is good. I think you are improving.  You could clean it up to make it more readable.  
public int scoresSpecial(int[] a, int[] b) {
  return (scoresUtil(a) + scoresUtil(b));
}
public int scoresUtil(int[] x){
  int largest = 0;
  for(int i = 0; i < x.length; i++){
    if(x[i]%10 == 0 && largest < x[i]){
      largest = x[i];
    }
  }
 return largest;
}

Open in new window

0
 
LVL 16

Expert Comment

by:krakatoa
ID: 41790794
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 41790810
I think the code is ok and complete, at least I see nothing missing
0
 
LVL 16

Expert Comment

by:krakatoa
ID: 41790865
Very funny - you deleted my code for being "complete" (full was the term used). So what's the difference now?
0
 
LVL 27

Expert Comment

by:rrz
ID: 41791352
@krakatoa,
So what's the difference now?
The difference is that I was just rewriting gudii9 code that he posted at  
https://www.experts-exchange.com/questions/28966729/scoresSpecial-challenge.html#a41790660
0
 
LVL 16

Expert Comment

by:krakatoa
ID: 41791383
The point is both your code and mine passed all the tests, and you made no more attempt to get him to iron out his mistakes and recode it than I did - so imho, the situation is still not kosher.
0
 
LVL 7

Author Comment

by:gudii9
ID: 41791417
You could clean it up to make it more readable.  

i like naming largest and your code is more refined.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question