Skip to content

Commit a65fdf6

Browse files
we are so back
new way of writting code . desc in the code before solution and naming with the problem type first i.e easy, mid, hard.-problem number , problem name. And me trying python from now on
1 parent 2971e78 commit a65fdf6

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# you are given an array of strings names, and an array heights that consists of distinct positive integers. Both arrays are of length n.
2+
3+
# For each index i, names[i] and heights[i] denote the name and height of the ith person.
4+
5+
# Return names sorted in descending order by the people's heights.
6+
7+
8+
9+
# Example 1:
10+
11+
# Input: names = ["Mary","John","Emma"], heights = [180,165,170]
12+
# Output: ["Mary","Emma","John"]
13+
# Explanation: Mary is the tallest, followed by Emma and John.
14+
15+
# Example 2:
16+
17+
# Input: names = ["Alice","Bob","Bob"], heights = [155,185,150]
18+
# Output: ["Bob","Alice","Bob"]
19+
# Explanation: The first Bob is the tallest, followed by Alice and the second Bob.
20+
21+
22+
class Solution(object):
23+
def sortPeople(self, names, heights):
24+
"""
25+
:type names: List[str]
26+
:type heights: List[int]
27+
:rtype: List[str]
28+
"""
29+
returnVar = []
30+
indexes = []
31+
for i in range(len(heights)):
32+
if not returnVar:
33+
returnVar.append(names[i])
34+
indexes.append(i)
35+
else:
36+
added = False
37+
for j in range(len(returnVar)):
38+
if heights[i] > heights[indexes[j]]:
39+
returnVar.insert(j, names[i])
40+
indexes.insert(j, i)
41+
added = True
42+
break
43+
if not added:
44+
returnVar.append(names[i])
45+
indexes.append(i)
46+
return returnVar

0 commit comments

Comments
 (0)