`{"id":"fabd20d5-ae1e-4bff-9033-18c4d258def3","name":"Smallest Number Following Pattern","description":"<p>1. You are given a pattern of upto 8 length containing characters 'i' and 'd'. 2. 'd' stands for decreasing and 'i' stands for increasing 3. You have to print the smallest number, using the digits 1 to 9 only without repetition, such that the digit decreases following a d and increases follwing an i. e.g. d -&gt; 21 i -&gt; 12 ddd -&gt; 4321 iii -&gt; 1234 dddiddd -&gt; 43218765 iiddd -&gt; 126543</p>","inputFormat":"<p>Input is managed for you</p>","outputFormat":"<p>Smallest sequence of digits (from 1 to 9) without duplicacy and following the pattern</p>","constraints":"<p>0 &lt; str.length &lt;= 8 str contains only 'd' and 'i'</p>","sampleCode":{"cpp":{"code":"#include<iostream>\n#include <string>\n#include <stack>\nusing namespace std;\n\n\n\nint main(){\n string str;\n cin >> str;\n \n // write your code here\n \n \n \n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main{\r\n \r\n\r\npublic static void main(String[] args) throws Exception {\r\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n String str = br.readLine();\r\n\r\n // code\r\n }\r\n}"},"python":{"code":"def main():\n inp = str(input())\n \n\n # write your code here\n \n \n \nmain()"}},"points":10,"difficulty":"easy","sampleInput":"ddddiiii","sampleOutput":"543216789","questionVideo":"https://www.youtube.com/embed/4_0l-QydwzI","hints":[],"associated":[{"id":"205e149d-d7ab-47ea-90ff-6f98dbbc2c59","name":"which data strcuture is used in the problem? (Q- which data strcuture is used in the problem)","slug":"which-data-strcuture-is-used-in-the-problem-q-which-data-strcuture-is-used-in-the-problem","type":4},{"id":"4cfb33d6-9d18-40c8-b650-b3d77056d387","name":"what is the time complexity for solving the problem?(Q- Smallest Number)","slug":"what-is-the-time-complexity-for-solving-the-problem-q-smallest-number","type":4},{"id":"81e2084e-0913-4d9b-a01b-a97800fa7009","name":"for the sequence \"iiiii\" the problem is equivalent tp(Q- Smallest Number)","slug":"for-the-sequence-iiiii-the-problem-is-equivalent-tp-q-smallest-number","type":4},{"id":"c832fcf1-db2f-46a1-99ad-e2f225293c40","name":"for the sequence \"ddddd\" the problem is equivalent to (Q- Smallest Number)","slug":"for-the-sequence-ddddd-the-problem-is-equivalent-to-q-smallest-number","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"9847c2b3-e3ad-4b1c-97d1-00206b1be68d","name":"Stacks And Queues For Beginners","slug":"stacks-and-queues-for-beginners","type":0},{"id":"0bd1d07b-476a-4129-aa13-ac40caca93d5","name":"Smallest Number Following Pattern","slug":"smallest-number-following-pattern","type":1}],"next":{"id":"901d73f0-dfca-4f01-b248-a322e2741d17","name":"Smallest Number following pattern","type":3,"slug":"smallest-number-following-pattern"},"prev":{"id":"7314ed81-e880-45a8-aac0-e7ea30943722","name":"Merge Overlapping Interval","type":3,"slug":"merge-overlapping-interval"}}}`

# Smallest Number Following Pattern

<p>1. You are given a pattern of upto 8 length containing characters 'i' and 'd'. 2. 'd' stands for decreasing and 'i' stands for increasing 3. You have to print the smallest number, using the digits 1 to 9 only without repetition, such that the digit decreases following a d and increases follwing an i. e.g. d -&gt; 21 i -&gt; 12 ddd -&gt; 4321 iii -&gt; 1234 dddiddd -&gt; 43218765 iiddd -&gt; 126543</p>

`{"id":"fabd20d5-ae1e-4bff-9033-18c4d258def3","name":"Smallest Number Following Pattern","description":"<p>1. You are given a pattern of upto 8 length containing characters 'i' and 'd'. 2. 'd' stands for decreasing and 'i' stands for increasing 3. You have to print the smallest number, using the digits 1 to 9 only without repetition, such that the digit decreases following a d and increases follwing an i. e.g. d -&gt; 21 i -&gt; 12 ddd -&gt; 4321 iii -&gt; 1234 dddiddd -&gt; 43218765 iiddd -&gt; 126543</p>","inputFormat":"<p>Input is managed for you</p>","outputFormat":"<p>Smallest sequence of digits (from 1 to 9) without duplicacy and following the pattern</p>","constraints":"<p>0 &lt; str.length &lt;= 8 str contains only 'd' and 'i'</p>","sampleCode":{"cpp":{"code":"#include<iostream>\n#include <string>\n#include <stack>\nusing namespace std;\n\n\n\nint main(){\n string str;\n cin >> str;\n \n // write your code here\n \n \n \n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main{\r\n \r\n\r\npublic static void main(String[] args) throws Exception {\r\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n String str = br.readLine();\r\n\r\n // code\r\n }\r\n}"},"python":{"code":"def main():\n inp = str(input())\n \n\n # write your code here\n \n \n \nmain()"}},"points":10,"difficulty":"easy","sampleInput":"ddddiiii","sampleOutput":"543216789","questionVideo":"https://www.youtube.com/embed/4_0l-QydwzI","hints":[],"associated":[{"id":"205e149d-d7ab-47ea-90ff-6f98dbbc2c59","name":"which data strcuture is used in the problem? (Q- which data strcuture is used in the problem)","slug":"which-data-strcuture-is-used-in-the-problem-q-which-data-strcuture-is-used-in-the-problem","type":4},{"id":"4cfb33d6-9d18-40c8-b650-b3d77056d387","name":"what is the time complexity for solving the problem?(Q- Smallest Number)","slug":"what-is-the-time-complexity-for-solving-the-problem-q-smallest-number","type":4},{"id":"81e2084e-0913-4d9b-a01b-a97800fa7009","name":"for the sequence \"iiiii\" the problem is equivalent tp(Q- Smallest Number)","slug":"for-the-sequence-iiiii-the-problem-is-equivalent-tp-q-smallest-number","type":4},{"id":"c832fcf1-db2f-46a1-99ad-e2f225293c40","name":"for the sequence \"ddddd\" the problem is equivalent to (Q- Smallest Number)","slug":"for-the-sequence-ddddd-the-problem-is-equivalent-to-q-smallest-number","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"9847c2b3-e3ad-4b1c-97d1-00206b1be68d","name":"Stacks And Queues For Beginners","slug":"stacks-and-queues-for-beginners","type":0},{"id":"0bd1d07b-476a-4129-aa13-ac40caca93d5","name":"Smallest Number Following Pattern","slug":"smallest-number-following-pattern","type":1}],"next":{"id":"901d73f0-dfca-4f01-b248-a322e2741d17","name":"Smallest Number following pattern","type":3,"slug":"smallest-number-following-pattern"},"prev":{"id":"7314ed81-e880-45a8-aac0-e7ea30943722","name":"Merge Overlapping Interval","type":3,"slug":"merge-overlapping-interval"}}}`

Editor

# Smallest Number Following Pattern

easy

1. You are given a pattern of upto 8 length containing characters 'i' and 'd'. 2. 'd' stands for decreasing and 'i' stands for increasing 3. You have to print the smallest number, using the digits 1 to 9 only without repetition, such that the digit decreases following a d and increases follwing an i. e.g. d -> 21 i -> 12 ddd -> 4321 iii -> 1234 dddiddd -> 43218765 iiddd -> 126543

## Constraints

0 < str.length <= 8 str contains only 'd' and 'i'

## Format

### Input

Input is managed for you

### Output

Smallest sequence of digits (from 1 to 9) without duplicacy and following the pattern

## Example

Sample Input

`.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}ddddiiii`

### Sample Output

`.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}543216789`

Question Video

Discussions

Show Discussion

Related Resources