InterviewBit Academy is now Scaler!
Learn Tech Skills from Scratch @ Scaler EDGE

Find Permutation

Given a positive integer n and a string s consisting only of letters D or I, you have to find any permutation of first n positive integer that satisfy the given input string.

D means the next number is smaller, while I means the next number is greater.


  • Length of given string s will always equal to n - 1
  • Your solution should run in linear time and space.

Example :

Input 1:

n = 3

s = ID

Return: [1, 3, 2]

NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Find Permutation on Interview Code Editor
Sign Up
to access hints and editorial solutions for Find Permutation
Asked In:


Click here to start solving coding interview questions