Skip to content

Latest commit

 

History

History
24 lines (19 loc) · 1.11 KB

jeremymanning.md

File metadata and controls

24 lines (19 loc) · 1.11 KB

Initial thoughts (stream-of-consciousness)

  • I think we can do the following:
    • Convert each number in nums to a string
    • Then replace the characters: ''.join([str(mapping[int(i)]) for i in str(n)])
    • After converting each number in nums, sort the values by the given array

Refining the problem, round 2 thoughts

  • We could also solve this as a 1-liner:
    • return [m[0] for m in sorted(zip(nums, [int(''.join([str(mapping[int(i)]) for i in str(n)])) for n in nums]), key=lambda x: x[1])]

Attempted solution(s)

class Solution:
    def sortJumbled(self, mapping: List[int], nums: List[int]) -> List[int]:
        return [m[0] for m in sorted(zip(nums, [int(''.join([str(mapping[int(i)]) for i in str(n)])) for n in nums]), key=lambda x: x[1])]
  • Given test cases pass
  • I can't think of any critical edge cases; submitting...

Screenshot 2024-07-23 at 11 36 22 PM

Solved!