Add and Search Word - Data structure design | LeetCode 211 | C++, Java, Python

preview_player
Показать описание


**** Best Books For Data Structures & Algorithms for Interviews:**********
*****************************************************************************

August LeetCoding Challenge | Problem 5 | Add and Search Word - Data structure design | 5 August,
Facebook Coding Interview question,
google coding interview question,
leetcode,
Add and Search Word - Data structure design,
Add and Search Word - Data structure design c++,
Add and Search Word - Data structure design Java,
Add and Search Word - Data structure design python,
Add and Search Word - Data structure design solution,
211. Add and Search Word - Data structure design,

#CodingInterview #LeetCode #AugustCodingChallenge #Google #Amazon #trie
Рекомендации по теме
Комментарии
Автор

Thank you so much for these awesome videos and very clear explanations! You are teaching me many new things, thank you for your effort!

sheldon
Автор

Thanks as always. I did something similar, but I was having time issues. I copied a Trie I wrote for Word Search II. I accessed it modularly which hurt my time a little (didn't directly manipulate or read the Trie structure). I also recursed on all the characters which was another performance hit. I got a TLE on a test with 10, 000 addWord's and 16, 500 search's I cached the search results and that got me through it.

crankyinmv
Автор

I initially implemented using a list and matching via regex but I kept failing the final stress testing test. the time complexity of the trie is much better than applying filters and regex matches to the entire wordDict. Thank you!

xabaki
Автор

I got ArrayIndexOutOfBounds error, since the character in the word is a dot: '.', and c - 'a' is -51, it's not in the range of [0, 25], how to deal with this?

glaiveEdits
Автор

I implemented the addWord recursively, it gave TLE. I don’t why it showed Tle though both recursive and iterative versions have the same TC.

samiles
Автор

It was a great tutorial sir . Can we replace . with a to z character and process only when curr->child[element] is not null.

for(char x='a';x<='z';x++){

if(!curr->child[x-'a'])
continue;

string other=word.substr(0, d)+x+word.substr(d+1);

if(search(other))
return true;
}
But i dont understand why is it failing for testcase 6

vamsimudaliar
Автор

One doubt - In case the control moves to recursion, we simply return True if the letters are found. Why don't we check endswith condition here before returning true?

atharvapatil
Автор

In line number 31 you have already handled if the child is null. So, in line 34 it will never be null.

rajapanda
Автор

can you also write code in java and python also from scratch and have descriptions on the seek based on timestamps, so that it's easy to skip some parts of the video.
That'd be very useful.
Thanks.

abhilashvadnala
Автор

sir please help me with this, I'm trying leetcode 463 in recursive by taking your idea but my code has some logical errors it seems, Don't know why it was always returning zero.please fix it for me sir! below is mycode:

class Solution:
def islandPerimeter(self, grid: List[List[int]]) -> int:
def isSafe(grid, i, j):
return (i>=0 and i<len(grid)) and (j>=0 and j<len(grid[0])) and (grid[i][j]==1)
peri = 0
def dfsRec(grid, visited, i, j, peri):
visited[i][j]=True
dirs = [(1, 0), (-1, 0), (0, 1), (0, -1)]
tot_safe = 4
for k in dirs:
if isSafe(grid, i+k[0], j+k[1]):
tot_safe-=1
peri+=tot_safe
for dir in dirs:
if isSafe(grid, i+dir[0], j+dir[1]):
if visited[i][j]==False:
dfsRec(grid, visited, i+dir[0], j+dir[1], peri)


visited = [[False for i in range(len(grid))] for j in range(len(grid[0]))]
for i in range(len(grid)):
for j in range(len(grid[0])):
if visited[i][j]==False:
dfsRec(grid, visited, i, j, peri)
return peri

ayyappahemanth
Автор

Add links to those trie videos in description that would be helpful! Still the links are below

ayyappahemanth
Автор

then there are people who doesn't want to learn any new programming language apart from the one they are comfortable with..

praveen
welcome to shbcf.ru