@@ -29,3 +29,93 @@ def minDominoRotations(self, tops: List[int], bottoms: List[int]) -> int:
29
29
if count >= len (tops ):
30
30
return min ([len (tops ) - tops .count (value ), len (bottoms ) - bottoms .count (value )])
31
31
return - 1
32
+
33
+
34
+
35
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
36
+
37
+
38
+ class Solution :
39
+ def minDominoRotations (self , tops : List [int ], bottoms : List [int ]) - > int :
40
+
41
+ top_freq = dict (Counter (tops ))
42
+ bottom_freq = dict (Counter (bottoms ))
43
+
44
+ most_frequent_top = [[k ,v ] for k ,v in top_freq .items ()]
45
+ most_frequent_top .sort (key = lambda x : x [1 ], reverse = True )
46
+
47
+ most_frequent_bottom = [[k ,v ] for k ,v in bottom_freq .items ()]
48
+ most_frequent_bottom .sort (key = lambda x : x [1 ], reverse = True )
49
+
50
+ n = len (tops )
51
+ most_frequent_top = most_frequent_top [0 ]
52
+ most_frequent_bottom = most_frequent_bottom [0 ]
53
+
54
+ print (top_freq )
55
+ print (bottom_freq )
56
+ print ('-----------' )
57
+
58
+ print ('most top val' )
59
+ most_frequent_top_number = most_frequent_top [0 ]
60
+ most_frequent_bottom_number = most_frequent_bottom [0 ]
61
+
62
+ print (f'most_frequent top number: { most_frequent_top_number } ' )
63
+ print (f'most_frequent bottom number: { most_frequent_bottom_number } ' )
64
+
65
+ most_frequent_top_number_count = most_frequent_top [1 ]
66
+ most_frequent_bottom_number_count = most_frequent_bottom [1 ]
67
+
68
+
69
+
70
+
71
+
72
+ res1 = res2 = 0
73
+
74
+ m = list (zip (tops ,bottoms ))
75
+ #make all tops same
76
+
77
+ newtops = []
78
+ for t ,b in m :
79
+ if t != most_frequent_top_number :
80
+ if bottom_freq [most_frequent_bottom_number ]> 0 :
81
+ bottom_freq [most_frequent_bottom_number ]-= 1
82
+ newtops .append (b )
83
+ res1 += 1
84
+ else :
85
+ newtops .append (t )
86
+
87
+ print (f'newtops: { newtops } ' )
88
+ expected_tops = [ most_frequent_top_number for x in tops ]
89
+ print (f'expected tops: { expected_tops } ' )
90
+ print ('---------------' )
91
+ print ('---------------' )
92
+ print ('---------------' )
93
+
94
+
95
+
96
+ newbottoms = []
97
+ for t ,b in m :
98
+ if b != most_frequent_bottom_number :
99
+ if top_freq [most_frequent_top_number ]> 0 :
100
+ top_freq [most_frequent_top_number ]-= 1
101
+ newbottoms .append (t )
102
+ res2 += 1
103
+ else :
104
+ newbottoms .append (b )
105
+
106
+
107
+ expected_bottoms = [most_frequent_bottom_number for x in tops ]
108
+ print (f'newtops: { newtops } ' )
109
+ print (f'newbottoms: { newbottoms } ' )
110
+ print (f'expected: { expected_bottoms } ' )
111
+
112
+ print (res1 ,res2 )
113
+
114
+ if newtops != expected_tops and newbottoms != expected_bottoms :
115
+ print ('cant make newtops or newbottoms as expected' )
116
+ return - 1
117
+
118
+
119
+ print (min (res1 ,res2 ))
120
+ return min (res1 ,res2 )
121
+
0 commit comments