Skip to content

Commit f65e1c5

Browse files
author
Partho Biswas
committed
Move_Element_To_End
1 parent 0ac5b28 commit f65e1c5

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,7 @@ BFS, DFS, Dijkstra, Floyd–Warshall, Bellman-Ford, Kruskal, Prim's, Minimum Spa
750750
|09| [Calendar_Matching](algoexpert.io/questions/Calendar_Matching.md) | [Python](algoexpert.io/python/Calendar_Matching.py) |
751751
|10| [Spiral_Traverse](algoexpert.io/questions/Spiral_Traverse.md) | [Python](algoexpert.io/python/Spiral_Traverse.py) |
752752
|11| [Monotonic_Array](algoexpert.io/questions/Monotonic_Array.md) | [Python](algoexpert.io/python/Monotonic_Array.py) |
753+
|12| [Move_Element_To_End](algoexpert.io/questions/Move_Element_To_End.md) | [Python](algoexpert.io/python/Move_Element_To_End.py) |
753754

754755
</p>
755756
</details>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
def moveElementToEnd(array, toMove):
2+
left, right = 0, len(array) - 1
3+
while left < right:
4+
if array[right] == toMove:
5+
right -= 1
6+
if array[left] != toMove:
7+
left += 1
8+
if array[left] == toMove and array[right] != toMove:
9+
array[left], array[right] = array[right], array[left]
10+
return array

algoexpert.io/python/Multi_String_Search.py

-12
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
1-
21
# Solution 02
32
# O(b^2 + ns) time | O(b^2 + n) space
43
def multiStringSearch(bigString, smallStrings):
54
modifiedSuffixTrie = ModifiedSuffixTrie(bigString)
65
return [modifiedSuffixTrie.conntains(string) for string in smallStrings]
76

8-
97
class ModifiedSuffixTrie:
108
def __init__(self, string):
119
self.root = {}
1210
self.populateModifiedSuffixTrieFrom(string)
1311

14-
1512
def populateModifiedSuffixTrieFrom(self, string):
1613
for i in range(len(string)):
1714
self.insertSubstringStartinngAt(i, string)
1815

19-
2016
def insertSubstringStartinngAt(self, idx, string):
2117
node = self.root
2218
for j in range(idx, len(string)):
@@ -25,7 +21,6 @@ def insertSubstringStartinngAt(self, idx, string):
2521
node[letter] = {}
2622
node = node[letter]
2723

28-
2924
def conntains(self, string):
3025
node = self.root
3126
for letter in string:
@@ -35,10 +30,6 @@ def conntains(self, string):
3530
return True
3631

3732

38-
39-
40-
41-
4233
# Solution 03
4334
# O(bs + ns) time | O(ns) space
4435
def multiStringSearch(bigString, smallStrings):
@@ -50,7 +41,6 @@ def multiStringSearch(bigString, smallStrings):
5041
findSmallStringsIn(bigString, i, trie, containedString)
5142
return [string in containedString for string in smallStrings]
5243

53-
5444
def findSmallStringsIn(string, startIdx, trie, containedStringns):
5545
currentNode = trie.root
5646
for i in range(startIdx, len(string)):
@@ -61,13 +51,11 @@ def findSmallStringsIn(string, startIdx, trie, containedStringns):
6151
if trie.endSymbol in currentNode:
6252
containedStringns[currentNode[trie.endSymbol]] = True
6353

64-
6554
class Trie:
6655
def __init__(self):
6756
self.root = {}
6857
self.endSymbol = '*'
6958

70-
7159
def insert(self, string):
7260
current = self.root
7361
for i in range(len(string)):

0 commit comments

Comments
 (0)