Your question is Factorial and String-Length Sorting. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Walmart Global Tech services may need to calculate a numeric value and organize product labels for display. Implement one function that computes the factorial of a non-negative integer and sorts an array of strings by increasing string length.
Implement factorial_and_sort(n, words):
n!, where n! = 1 * 2 * ... * n and 0! = 1.factorial and sorted_words.Example 1
Input: n = 5, words = ["milk", "egg", "water", "tea"]
Output: {"factorial": 120, "sorted_words": ["egg", "tea", "milk", "water"]}
5! is 120. The strings are ordered by lengths 3, 3, 4, and 5, with egg remaining before tea because they have equal length.
Example 2
Input: n = 0, words = ["apple", "kiwi", "pear"]
Output: {"factorial": 1, "sorted_words": ["kiwi", "pear", "apple"]}
0! is 1, and the two four-letter strings retain their original order.
def factorial_and_sort(n, words):