id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

prevPerm


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)

public int[] prevPerm(int[] perm) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 200

Copyright Nick Parlante 2017 - privacy