You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Backtracking/find_original_words.py
+14-7Lines changed: 14 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,15 @@
1
1
'''
2
-
Find Original Words
2
+
Word Break
3
3
4
-
Given a dictionary of words and a string made up of those words (no spaces), return the original sentence in a list. If there is more than one possible reconstruction, return any of them.
4
+
Given a dictionary of words and a string made up of those words (no spaces), return the original sentence in a list.
5
+
If there is more than one possible reconstruction, return solution with less words.
5
6
If there is no possible reconstruction, then return null.
6
7
7
8
Input: sentence = 'thequickbrownfox', words = ['quick', 'brown', 'the', 'fox']
Copy file name to clipboardExpand all lines: Trees/find_second_largest_node_bst.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -6,8 +6,8 @@
6
6
=========================================
7
7
There are 4 possible cases (see the details in the code).
8
8
Only 1 branch is searched to the end (leaf), not the whole tree.
9
-
Time Complexity: O(LogN) , this is if the tree is balanced (balanced bst), but the worst case will be if all elements are in the one (the right) branch O(N)
10
-
Space Complexity: O(LogN) , -||- but this is because of the recursion stack (LogN elements will be in the recursion stack till the leaf is reached)
9
+
Time Complexity: O(N) , this is the worst case when all elements are in one (the right) branch O(N), O(LogN) if the tree is balanced (balanced bst)
10
+
Space Complexity: O(N) , because of the recursion stack (but this is the tree is one branch), O(LogN) if the tree is balanced.
0 commit comments