GOOGLE - BATTLESHIPS IN A BOARD (LeetCode)
Battleships in a Board LeetCode coding solution. One of Google's most commonly asked interview questions according to LeetCode.
Coding Interviews Battleships in a Board (LeetCode) question and explanation.
This question is a commonly asked by the following companies: Google.
Link to problem: https://leetcode.com/problems/battleships-in-a-board/description/
Intuition behind solution:
- Solution #1: Traverse the matrix looking for 'X's. Once you find an X, increment your count and call a recursive function to "sink" the entire battleships by constantly visiting its 4 neighboring cells (up, down, left, and right). This will prevent you from counting the same battleship multiple times. Once you have traversed the entire matrix, simply return your count.
- Solution #2: Traverse the matrix using the same logic as the first solution however, only count the first 'X' you find in any battleship. This can be done by realizing how we are traversing the matrix (top to bottom and left to right) and understanding that battleships strictly exist horizontally or vertically. Therefore we ensure only counting the first 'X' of any battleship by checking the cell above us and the cell to the left of us to see if either of them are 'X's. Once we finish traversing the matrix we return our count again.
SOCIAL
----------------------------------------------------------------------------------------------------------------
Support me on Patreon: https://www.patreon.com/KevinNaughtonJr
Follow me on Twitter: https://twitter.com/KevinNaughtonJr
Follow me on Instagram: https://www.instagram.com/programeme
Follow me on GitHub: https://github.com/kdn251
MUSIC
----------------------------------------------------------------------------------------------------------------
Evil Morty Remix by Young Russell - https://soundcloud.com/yungrussell/evil-morty-remix
Видео GOOGLE - BATTLESHIPS IN A BOARD (LeetCode) канала Kevin Naughton Jr.
Coding Interviews Battleships in a Board (LeetCode) question and explanation.
This question is a commonly asked by the following companies: Google.
Link to problem: https://leetcode.com/problems/battleships-in-a-board/description/
Intuition behind solution:
- Solution #1: Traverse the matrix looking for 'X's. Once you find an X, increment your count and call a recursive function to "sink" the entire battleships by constantly visiting its 4 neighboring cells (up, down, left, and right). This will prevent you from counting the same battleship multiple times. Once you have traversed the entire matrix, simply return your count.
- Solution #2: Traverse the matrix using the same logic as the first solution however, only count the first 'X' you find in any battleship. This can be done by realizing how we are traversing the matrix (top to bottom and left to right) and understanding that battleships strictly exist horizontally or vertically. Therefore we ensure only counting the first 'X' of any battleship by checking the cell above us and the cell to the left of us to see if either of them are 'X's. Once we finish traversing the matrix we return our count again.
SOCIAL
----------------------------------------------------------------------------------------------------------------
Support me on Patreon: https://www.patreon.com/KevinNaughtonJr
Follow me on Twitter: https://twitter.com/KevinNaughtonJr
Follow me on Instagram: https://www.instagram.com/programeme
Follow me on GitHub: https://github.com/kdn251
MUSIC
----------------------------------------------------------------------------------------------------------------
Evil Morty Remix by Young Russell - https://soundcloud.com/yungrussell/evil-morty-remix
Видео GOOGLE - BATTLESHIPS IN A BOARD (LeetCode) канала Kevin Naughton Jr.
Показать
Комментарии отсутствуют
Информация о видео
Другие видео канала
GOOGLE - BOATS TO SAVE PEOPLE (LeetCode)The Hardest Easy GameMy Regrets as a Computer Science StudentI failed all my tech interviews until I did these 5 thingsCreating a Winning Content Plan for Your Blog (The Battleship Method)AMAZON CODING INTERVIEW QUESTION - REORGANIZE STRINGGOOGLE - LICENSE KEY FORMATTING (LeetCode)How We Solved the Worst Minigame in Zelda's HistoryTop K Frequent Elements - Bucket Sort - Leetcode 347 - PythonHow I would learn to code (if I could start over)Course Schedule - Graph Adjacency List - Leetcode 207GOOGLE PHONE INTERVIEW QUESTION - LARGEST VALUES FROM LABELS[CC] How to Design Twitter - System Design EP1GOOGLE CODING INTERVIEW QUESTION - BINARY TREE LONGEST CONSECUTIVE SEQUENCEDecode String | FAANG Coding Question | StackFACEBOOK - WALLS AND GATES (LeetCode)GOOGLE CODING INTERVIEW QUESTION - LETTER COMBINATIONS OF A PHONE NUMBER (LeetCode)How to Code Battleship in Python - Single Player Game