Given a 2D matrix of character... | CareerCup
1) Create a hash table with character as a key and value representing the coordinates of the character present in the matrix.2) if The search string is "rat",then search for the first character in the hash map and find its coordinates.
3) After this search for the second character in the hash table and find its coordinates and find the relationship("r") between the coordinates of the first char and the second char,whether it lies in the left straight or right straight or diagonal.
3) After this see for the third char and check for the relationship of its coordinate with the coordinate of its last char and if it matches with the "r" ,then continue else return false.
4) Continue this process till the end of the string .
Time complexity :
1) In creating hash table : O(m*n)
2) search for string occurence : O (l) : l is the string length
Read full article from Given a 2D matrix of character... | CareerCup
No comments:
Post a Comment