LeetCode: 60. Permutation Sequence(Golang & Java)

Опубликовано: 17 Январь 2025
на канале: Nandeshwar Sah
19
1

Problem: Permutation sequence
Difficulty Level: Hard
Algorithm: analyse pattern, 1. prepare numbers array 1, 2, 3, prepare factorial 1 1 2 6 array, reduce k by 1, then run loop i=1 to n(3 here), calculated idx = k / fact[n-i] , extract idx value from numbers, then update numbers removed idx value, update k -= idx * fact[n-i]
Programming Language: golang & Java