[InterviewBit] Find Permutation

Find Permutation

  • Time :
  • Space :
1
2
3
4
5
6
7
8
9
10
11
vector<int> Solution::findPerm(const string A, int B) {
vector<int> res{1};
int l = 1, r = 1;
for(int i = 0; i < A.length(); i++) {
if(A[i] == 'I') res.push_back(++r);
else res.push_back(--l);
}
for(int i = 0; i < res.size(); i++) res[i] += (1 - l);
return res;
}

Author: Song Hayoung
Link: https://songhayoung.github.io/2022/10/14/PS/interviewbit/find-permutation/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.