DavidM
BAN USER
Comments (3)
Reputation 0
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
Recursive python solution
Output isn't exactly as asked, but an extra condition can be added to remove initial arrow
def getAllPaths(root):
if not root:
return [""]
all_paths = [ "->" + str(root.value) + path for path in getAllPaths(root.left)]
all_paths.extend([ "->" + str(root.value) + path for path in getAllPaths(root.right)])
return list(set(all_paths))
Comment hidden because of low score. Click to expand.
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
python solution running in O(n^2) time
works something like this:
1. create a hash for each string in the dictionary array storing total occurrances of each char
2. loop over string and take similar hash of cumulative string so far
3. compare cumalative hash to each hash of dictionary
4. If cumulative hash equals some dict hash, append that word to output. Reset cumulative string to empty.
5. ???
6. result
- DavidM November 15, 2016