top of page

### Looking to master object-oriented and system design for tech interviews or career growth?

• Improve your system design and machine coding skills.

• Study with our helpful resources.

**We're in beta mode and would love to hear your feedback.

Search

# Sorted Permutation Rank InterviewBit Solution

Problem: Sorted Permutation Rank

Problem Description:

Given a string, find the rank of the string amongst its permutations sorted lexicographically. Assume that no characters are repeated.

Example :

```Input : 'acb'
Output : 2

The order permutations with letters 'a', 'c', and 'b' :
abc
acb
bac
bca
cab
cba ```

## Approach

Refer the problem Sorted Permutation Rank with Repeats. The approach & solution to the problem is exactly the same, except that we are not considering the frequency of character because, in this problem, characters are unique without repeat.

## Time & Space Complexity

`Time Complexity: O(N^2)`

- For every index we are traversing the string, to find the number of character lesser than the current one.

`Space Complexity: O(1)`

- Apart from the space taken by our input array, we have taken the constant amount of space, independent of the size of the string.

Code in C++

Tags:

bottom of page