Given a pattern containing only (I)s and (D)s. (I) stands for increasing and (D) for decreasing. Devise an algorithm to print the minimum number following that pattern. Digits are from 1-9 and digits can not repeat
All Answers
total answers (1)
total answers (1)
The pattern & number to be generated
Hence, maximum string length possible is 8, since we can construct only with different digits (1-9)
"II" → 123
"DD" → 321
The problem can be used with help of stack. The concept is to create stack with consecutive number same as depth of a local contiguous sequence of 'D'.
Prerequisite:
C++ Implementation
Output
Example with explanation:
need an explanation for this answer? contact us directly to get an explanation for this answer