Saicharan67 / Interview-Coding-Questions

11 stars 10 forks source link

Create Form minimum number from given sequence #21

Closed hyderr closed 2 years ago

hyderr commented 2 years ago

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.

Examples:

Input: D Output: 21 Input: I Output: 12 Input: DD Output: 321 Input: II Output: 123 Input: DIDI Output: 21435 Input: IIDDD Output: 126543 Input: DDIDDIID Output: 321654798