Ebay Interview Question
SDE1sCountry: United States
Interview Type: In-Person
We dont need a HashMap to keep track of each ship's health
Instead of using x as a placeholder, use a number representing the health of the ship. Every time ship is attacked, decrease this number.
Once the number is -ve of zero, the ship sunk.
Represent the coordinates as a 2-dimensional array, where the value is 0 if the coordinate is empty and x if it's occupied by ship x. Also use a HashMap to keep track of each ship's health. Update both as we fire at each coordinate.
- Sunny June 28, 2013