about | help | code help+videos | done | prefs |
Find the next lexicographically smaller permutation of the input. For example, the next smaller permutation of “4312” is “4231”. Below are steps to find the previous permutation: Find largest index i such that str[i – 1] > str[i]. Find largest index j such that j >= i and str[j] < str[i – 1]. Swap str[j] and str[i – 1]. Reverse the sub-array starting at str[i]. prevPerm([4, 3, 1, 2]) → [4, 2, 3, 1] prevPerm([1, 3, 2]) → [1, 2, 3] prevPerm([2, 1, 3]) → [1, 3, 2] ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 200
Copyright Nick Parlante 2017 - privacy