How to solve the battleship interview question

  Рет қаралды 44,177

Devpost

Devpost

Күн бұрын

Пікірлер
@edvinkeskin8558
@edvinkeskin8558 Жыл бұрын
Some versions of the game doesn't permit two ships being side by side in which case using a boolean matrix followed by checking all four sides would be suffice to state hit or sink so it's worth asking the interviewer about this
@yissssss
@yissssss 2 жыл бұрын
I think a better approach is to just store the ship objects with appropriate coordinates then remove the coordinates as they are hit. Once the coordinates are gone, the ship is sunk.
@walterloso
@walterloso 8 жыл бұрын
I loved this. Could we please have more of this? More whiteboard solutions that are focused more on approaches to answer different technical questions.
@SamujjalMajumder
@SamujjalMajumder 5 жыл бұрын
Use a Map of Ship vs Integer Counter(for cells), reduce counter with everyhit and nullify corresponding cell value. If Counter == 0, its a SINK!
@madhumithabaskar9832
@madhumithabaskar9832 4 жыл бұрын
Please can you provide the program for this question?
@Cookiekeks
@Cookiekeks 4 жыл бұрын
Thank you so much! Im programming a battleship game currently and i struggelt but now i understand it more. Great Video!
@sunitgautam7547
@sunitgautam7547 6 жыл бұрын
Can somebody suggest more such content? Working out a solution to problem on a whiteboard and improving on it along the way.
@shawniscoolerthanyou
@shawniscoolerthanyou 7 жыл бұрын
I feel OOP would be pretty useful here.
@ancientelevator9
@ancientelevator9 4 жыл бұрын
Right? I immediately started thinking of a player and ship class along with their properties and methods.
@xinli2169
@xinli2169 Жыл бұрын
great video, i indeed encountered this problem during an interview
@IanDouglas
@IanDouglas 7 жыл бұрын
Instead of searching the entire matrix to detect a sunk condition, you know that S2 can only be in positions left/right or up/down from the coordinate that you just hit. Wouldn't it be easier to store each ship in a smaller structure like ships = { 'player1': { 's1': {'x1,y1': false, 'x2,y2': true}, 's2': [{'x1,y1': true, 'x2,y2': true, 'x3,y3': false} etc} ... where the true/false values indicate if that piece of the ship is hit and if you hit s2, look it up in that other structure to detect how many other pieces were hit to mark is as sunk? I would think the complexity of maintaining that separate structure far easier than searching a 10x10 grid to find, at most, 5 other parts of the 6-piece boat, from 100 locations.
@zxcv9875
@zxcv9875 7 жыл бұрын
if you're assuming there is no repeats of firing, couldn't you also have a variable something like playerName.s2 which would hold the coordinates of ship 2 in an array and do somethingl ike if ((x,y) in playerName.s2) s2Life--; and if it's 0, you say sunk. Do the same for s1-s3 and for player1-2.
@leopalaciosgarcia6391
@leopalaciosgarcia6391 6 жыл бұрын
What if for a size-4 ship you first hit the 3rd position, then the 4th, if you check the positions left/right and up/down of the 4th you will be missing that positions 1 and 2 are still unhit. But sure, as he mentions, there are more elegant and efficient solutions.
@samuelmiller
@samuelmiller 3 жыл бұрын
This was awesome
@T25de
@T25de 2 жыл бұрын
each game will have about two players... its a two player game... schitzo lol
@kengerfil
@kengerfil 3 жыл бұрын
3:30 - 3:47 The left guy pisses me off by the way he is acting, bruh
@nonconsensualopinion
@nonconsensualopinion 2 жыл бұрын
Might want to try some yoga or meditation. You seem high strung.
@thegreattheone
@thegreattheone 8 жыл бұрын
sound's too damn low guys
How to: Work at Google - Example Coding/Engineering Interview
24:02
Life at Google
Рет қаралды 7 МЛН
Amazon Coding Interview Question - Recursive Staircase Problem
20:01
Quando A Diferença De Altura É Muito Grande 😲😂
00:12
Mari Maria
Рет қаралды 45 МЛН
Mom Hack for Cooking Solo with a Little One! 🍳👶
00:15
5-Minute Crafts HOUSE
Рет қаралды 23 МЛН
5 Problem Solving Tips for Cracking Coding Interview Questions
19:12
System Design Interview - Top K Problem (Heavy Hitters)
36:18
System Design Interview
Рет қаралды 379 М.
Google Coding Interview With A Competitive Programmer
54:17
Clément Mihailescu
Рет қаралды 2,5 МЛН
NETFLIX System design | software architecture for netflix
51:26
Tech Dummies Narendra L
Рет қаралды 439 М.
How to prepare for Technical Interviews
7:50
mayuko
Рет қаралды 347 М.
WHATSAPP System Design: Chat Messaging Systems for Interviews
25:15
Gaurav Sen
Рет қаралды 1,9 МЛН
Quando A Diferença De Altura É Muito Grande 😲😂
00:12
Mari Maria
Рет қаралды 45 МЛН