Question: language is java There are two sequences of stack operations converting the word TROT to TORT: [ i i ii O OOO i oii ooi

 language is java There are two sequences of stack operations converting

the word TROT to TORT: [ i i ii O OOO i

language is java

There are two sequences of stack operations converting the word TROT to TORT: [ i i ii O OOO i oii ooi o ] where i and o stands for in / push and out / pop operation respectively. In this problem, you are given two words and you are asked to find out all sequences of stack operations converting the first word to the second word. Input The input consists of two lines, the first of which is the source word and the second is the target word. Output your program should print a sorted list of valid i/o sequences. The list is delimited by [ ] and the sequences are sorted in lexicographical order. Within each sequence, i 's' and o 's are separated by a single space and each sequence is terminated by a new line. There should be a newline character printed after the closing square bracket delimiter. Process Given an input word, a valid i/o sequence implies that every character of the word is pushed and popped exactly once, and no attempt is ever made to pop an empty stack. For example, if the word FOO is input, then the sequence: . iioio o is valid and produces OFF ii o is not valid (too short), iioooi is not valid (illegal pop from an empty stack) A valid sequence results in a permutation of the letters in the input word. For example, given the input word FOO, both sequences i io ioo and i iiooo give the word OOF. Example 1 Input: madam adamm Output: [ i ii iooooo iiiiooooi o iioioioio o iioioioio ] Example 3 Input: long short Output: [ ] Example 4 Input: eric rice Output: [ iioioioo ] There are two sequences of stack operations converting the word TROT to TORT: [ i i ii O OOO i oii ooi o ] where i and o stands for in / push and out / pop operation respectively. In this problem, you are given two words and you are asked to find out all sequences of stack operations converting the first word to the second word. Input The input consists of two lines, the first of which is the source word and the second is the target word. Output your program should print a sorted list of valid i/o sequences. The list is delimited by [ ] and the sequences are sorted in lexicographical order. Within each sequence, i 's' and o 's are separated by a single space and each sequence is terminated by a new line. There should be a newline character printed after the closing square bracket delimiter. Process Given an input word, a valid i/o sequence implies that every character of the word is pushed and popped exactly once, and no attempt is ever made to pop an empty stack. For example, if the word FOO is input, then the sequence: . iioio o is valid and produces OFF ii o is not valid (too short), iioooi is not valid (illegal pop from an empty stack) A valid sequence results in a permutation of the letters in the input word. For example, given the input word FOO, both sequences i io ioo and i iiooo give the word OOF. Example 1 Input: madam adamm Output: [ i ii iooooo iiiiooooi o iioioioio o iioioioio ] Example 3 Input: long short Output: [ ] Example 4 Input: eric rice Output: [ iioioioo ]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!