Skip to content

Commit

Permalink
Relative sort
Browse files Browse the repository at this point in the history
  • Loading branch information
BravesDevs committed Jun 11, 2024
1 parent bbf933f commit bf0cebd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lc_daily/py/heightChecker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Solution:
def heightChecker(self, heights: List[int]) -> int:
relativeSortArray
19 changes: 19 additions & 0 deletions lc_daily/py/relativeSortArray.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from collections import Counter


class Solution:
def relativeSortArray(self, arr1, arr2):
freq = Counter(arr1)
arr1.sort()
res = []
for i in arr2:
res.extend([i]*freq[i])
for i in arr1:
if i not in arr2:
res.append(i)
return res


sln = Solution()
print(sln.relativeSortArray([2, 3, 1, 3, 2, 4, 6, 7, 9, 2, 19], [
2, 1, 4, 3, 9, 6]))

0 comments on commit bf0cebd

Please sign in to comment.