You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
4
+
5
+
D means the next number is smaller, while I means the next number is greater.
6
+
7
+
Notes
8
+
Length of given string s will always equal to n - 1
9
+
Your solution should run in linear time and space.
10
+
11
+
Input 1:
12
+
13
+
n = 3
14
+
s = ID
15
+
Return: [1, 3, 2]
16
+
17
+
Solution Complexity : O(N) time and O(1) space
18
+
Refer this URL for lexicographically smaller permutation solution:
19
+
https://leetcode.com/articles/find-permutation/
20
+
*/
21
+
22
+
vector<int> Solution::findPerm(const string A, int B) {
0 commit comments