Question: can you help me fix my code so it passes alll the tests its failing import java.util.HashSet; / / Sum of Strings [ 3 0
can you help me fix my code so it passes alll the tests its failing
import java.util.HashSet;
Sum of Strings
DO NOT add additional fields
DO NOT add additional methods
public class Task
DO NOT change this field
private HashSet strings;
DO NOT change this method
public void setStringsHashSet stringSet
strings stringSet;
DO NOT change the signature for this method
This method does not need to be recursive
public boolean stringSum
forString string : strings
ifisConstructablestring string
return true;
return false;
This method MUST be recursive
You can change the name and parameters of this method
private boolean isConstructableString aim, String initial
return isConstructableHelperaim new HashSet initial;
private boolean isConstructableHelperString aim, HashSet visited, String initial
if aimisEmpty return true;
if visitedcontainsaim return false;
visited.addaim;
for String string : strings
if string.equalsinitial && aim.startsWithstring
String remaining aim.substringstringlength;
if isConstructableHelperremaining visited, initial
return true;
visited.removeaim; Backtrack
return false;
public class Task
DO NOT change this field
private int map;
DO NOT change this method
public void setMapint grid
map grid;
DO NOT change the signature for this method
This method does not need to be recursive
public int digint battery
int maxGold ;
for int col ; col maplength; col
maxGold Math.maxmaxGold maximumGoldFrom col, battery, new booleanmaplengthmaplength;
return maxGold;
private int maximumGoldFromint y int x int battery, boolean visited
if battery y y map.length x x maplength visitedyx
return ;
visitedyx true; Mark cell as visited
int gold mapyx;
Explore all directions
int maxGold ;
maxGold Math.maxmaxGold gold maximumGoldFromy x battery visited; Left
maxGold Math.maxmaxGold gold maximumGoldFromy x battery visited; Right
maxGold Math.maxmaxGold gold maximumGoldFromy x battery visited; Down
visitedyx false; Backtrack
return maxGold;
@Test
public void StringSumHelper
Task t new Task;
HashSet strings new HashSet;
strings.add;
strings.addSEAN;
tsetStringsstrings;
boolean output tstringSum;
assertEqualsfalse output;
@Test
public void DigTest
Task t new Task;
int map new int
new int
new int
new int
new int
new int
;
tsetMapmap;
assertEquals tdig;
@Test
public void DigTest
Task t new Task;
int map
new int
new int
new int
;
tsetMapmap;
assertEquals tdig;
public void DigTest
Task t new Task;
int map
new int
new int
new int
;
tsetMapmap;
assertEquals tdig;
@Test
public void DigTest
Task t new Task;
int map
new int
new int
new int
;
tsetMapmap;
assertEquals tdig;
all these are failing DigTest org.opentestjAssertionFailedError: Expected : Actual : DigTest org.opentestjAssertionFailedError: Expected : Actual : DigTest org.opentestjAssertionFailedError: Expected : Actual : DigTest org.opentestjAssertionFailedError: Expected : Actual : StringSumHelper org.opentestjAssertionFailedError: Expected :false Actual :true
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
