Count unsorted columns
Problem to count the unsorted columns in given three string.
Example-1:
Input : s1 = "hello" s2 = "world" s3 = "crazy" Output : 3 Explain : unsorted columns are: h l o w r d c a y The three unsorted columns are (h,w,c),(l,r,a) and (o,d,y).
Example-2:
Input : s1 = "live" s2 = "like" s3 = "love" Output : 3 Explain : unsorted columns are: v k v The only one unsorted column is (v,k,v).
Solution
s1 = "hello" s2 = "world" s3 = "crazy" k = 0 for i in range(len(s1)): a = s1[i] + s2[i] + s3[i] b = s1[i] + s2[i] + s3[i] c = sorted(b) d = "".join(c) if(a!=d): k += 1 print(k)
Output
3