Skip to content

Commit 87b8aaf

Browse files
committed
fallback implementation using itertools & Approach 2
1 parent df17fac commit 87b8aaf

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

Techgig/CodeGladiators/OptimalReordering.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,37 @@ def optimal_reorder(g_rev,oppo,N):
124124
print (merged[i][1],merged[i+1][1])
125125
max_wins += 1
126126
return max_wins
127-
127+
128+
def optimal_reorder2(A,B):
129+
arrA = A.copy()
130+
C = [None] * len(B)
131+
for i in range(len(B)):
132+
k = i + 1
133+
all_ele = []
134+
while (k < len(arrA)):
135+
if arrA[k] > B[i]:
136+
all_ele.append(arrA[k])
137+
k += 1
138+
if all_ele:
139+
e = min(all_ele)
140+
else:
141+
e = min(arrA)
142+
C[i] = e
143+
arrA.remove(e)
144+
return C
145+
146+
import itertools
147+
def optimal_reorder3(A,B):
148+
possible_arrs = set(itertools.permutations(A,len(A)))
149+
maxwins = 0
150+
for arr in possible_arrs:
151+
wins = 0
152+
for x in range(len(A)):
153+
if arr[x] > B[x]:
154+
wins += 1
155+
if maxwins < wins:
156+
maxwins = wins
157+
return maxwins
128158

129159
if __name__ == '__main__':
130160
T = int(input())

0 commit comments

Comments
 (0)