File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

algorithm in java

 
Deepak Lal
Ranch Hand
Posts: 561
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Problem Statement :: In Java ,Given an array of ints, is it possible to choose a group of some of the ints, such that the group sums to the given target, with this additional constraint: if there are numbers in the array that are adjacent and the identical value, they must either all be chosen, or none of them chosen. For example, with the array {1, 2, 2, 2, 5, 2}, either all three 2's in the middle must be chosen or not, all as a group. (one loop can be used to find the extent of the identical values).



I have done some initial Analysis and the partial code is at http://ideone.com/Lik4l/Code
please provide me with the code fix.
output is showing wrongly as,
======================
Add similar number --> 8
modified Array is 2
modified Array is 8
modified Array is 4
The flag is -->true
======================
Expected Modified Array should be {2,8,0,8}
could you help me to solve this.


 
Deepak Lal
Ranch Hand
Posts: 561
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,
Could you help me with this problem???

Regards
Deepak Lal
 
Campbell Ritchie
Sheriff
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't need code for such a problem. You need to write out with a pencil and paper exactly how you intend to solve it.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic