@StefanPochmann
Thanks for this explanation!
Jianghan Li
@lee215
Posts made by lee215

RE: Python Solution using Counter

RE: Python Solution using Counter
@StefanPochmann
Thanks for this counter example.
I also found some like "meem","oggo", "goog" in python2.
Couldn't find counter example in Python3. 
RE: My Python Solution
@srinivas.varadharajanlive.com
A number with n digits reduces to maximum 81n, I'll say complexity of O(logN).
In fact, a big number (like n>4) will reduce really fast.
But some small number may take a while. 
RE: Python Solution using Counter
@pierrr
thanks for your reply.
"elements with equal counts are ordered arbitrarily." That is right.
Though I think it keeps an order for equal case.
"aaabbbcc" for example, if we get "ab" for first round, which means 'a' goes before 'b', then we may get "ac" or "ab" for second round. 
Python Solution using Counter
def reorganizeString(self, S): c = collections.Counter(S) if max(c.values()) <= (len(S) + 1) / 2: res = "" while c: out = c.most_common(2) if len(out): res += out[0][0] c[out[0][0]] = 1 if len(out) > 1: res += out[1][0] c[out[1][0]] = 1 c += collections.Counter() return res return ""

Python Easy and Concise Solution
def maxChunksToSorted(self, arr): res, c1, c2 = 0, collections.Counter(), collections.Counter() for a, b in zip(arr, sorted(arr)): c1[a] += 1 c2[b] += 1 res += c1 == c2 return res

Python Easy and Concise Solution
def isToeplitzMatrix(self, m): for i in range(len(m)  1): for j in range(len(m[0])  1): if m[i][j] != m[i + 1][j + 1]: return False return True
Make it 1 line:
def isToeplitzMatrix(self, m): return all(m[i][j] == m[i+1][j+1] for i in range(len(m)1) for j in range(len(m[0])1))

Python Easy Understood Solution
def maxChunksToSorted(self, arr): curMax = 1 res = 0 for i, v in enumerate(arr): curMax = max(curMax, v) if curMax == i: res += 1 return res
Make it in 1 line by reduce:
return reduce(lambda (curMax, res), (i, v): (max(curMax, v), res + (max(curMax, v) == i)), enumerate(arr), (1, 0))[1]
Another 1 linear solution, O(N^2) and N<=10
def maxChunksToSorted(self, arr): return sum(max(arr[:i + 1]) == i for i in range(len(arr)))

RE: Easy and Concise Solution with Explanation [C++/Java/Python]
@ManuelP
I don't like to useeval
orre
. But your solution is really interesting.
Upvoted :)