Error
|
|
---|---|
@Ibrahim Nash | 6420 |
@blackshadows | 6376 |
@mb1973 | 5578 |
@Quandray | 5231 |
@akhayrutdinov | 5111 |
@saiujwal13083 | 4510 |
@sanjay05 | 3762 |
@kirtidee18 | 3673 |
@marius_valentin_dragoi | 3522 |
@sushant_a | 3459 |
@verma_ji | 3412 |
Complete Leaderboard | |
|
|
@codersgroup18 | 714 |
@Manikanta punnam | 587 |
@sriramgoparaju99 | 532 |
@praveenbgp6 | 525 |
@yashkaril4 | 517 |
@prankursharma31 | 489 |
@rdakka | 467 |
@sonamnigam1999 | 441 |
@sonamkumari63928 | 427 |
@purohitmn02 | 427 |
@shubhamstudent5 | 419 |
Complete Leaderboard |
Given a pattern containing only I's and D's. I for increasing and D for decreasing.
Devise an algorithm to print the minimum number following that pattern.
Digits from 1-9 and digits can't repeat.
Example 1:
Input: D Output: 21 Explanation: D is meant for decreasing, So we choose the minimum number among 21,31,54,87,etc.
Example 2:
Input: IIDDD Output: 126543 Explanation: Above example is self- explanatory, 1 < 2 < 6 > 5 > 4 > 3 I - I - D - D - D
Your Task:
You don't need to read input or print anything. Your task is to complete the function printMinNumberForPattern() which takes the string S and returns a string containing the minimum number following the valid pattern.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 ≤ Length of String ≤ 8
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Yes