Skip to content

Commit

Permalink
Merge pull request nirmalnishant645#16 from nirmalnishant645/problem
Browse files Browse the repository at this point in the history
Check for unsorted elements in the array
  • Loading branch information
anantkaushik authored Jan 29, 2020
2 parents dc402ef + d9b4b6f commit 7d85439
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions 1051-Height-Checker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'''
Students are asked to stand in non-decreasing order of heights for an annual photo.
Return the minimum number of students that must move in order for all students to be standing in non-decreasing order of height.
Example 1:
Input: heights = [1,1,4,2,1,3]
Output: 3
Constraints:
1 <= heights.length <= 100
1 <= heights[i] <= 100
'''
class Solution:
def heightChecker(self, heights: List[int]) -> int:
arr = sorted(heights)
res = 0
for i in range(len(heights)):
if heights[i] != arr[i]:
res += 1
return res

0 comments on commit 7d85439

Please sign in to comment.