PLEASE CODE IN PYTHON  Problem Description: In order to ensure peace and prosperity for future generations, the United Nations is creating the world’s largest candy. The ingredients must be taken in railway cars from the top of a mountain and poured into Lake Geneva. The railway system goes steeply from the mountaintop down to the lake, with a T-shaped branch in the middle as shown below. Right now, each of the N ingredients is in its own railway car. Each railway car is assigned a positive integer from 1 to N. The ingredients must be poured into the lake in the order 1, 2, 3, . . . , N but the railway cars are lined up in some random order. The difficulty is that, because of the especially heavy gravity today, you can only move cars downhill to the lake, or sideways on the branch line. Is it still possible to pour the ingredients into the lake in the order 1, 2, 3, . . . , N ? For example, if the cars were in the order 2, 3, 1, 4, we can slide these into the lake in order as described below:  • Slide car 4 out to the branch • Slide car 1 into the lake • Slide car 3 out to the branch • Slide car 2 into the lake • Slide car 3 from the branch into the lake • Slide car 4 from the branch into the lake Input Specification The first line will contain the number T (1 ≤ T ≤ 10) which is the number of different tests that will be run. Each test has the form of an integer N (1 ≤ N ≤ 100 000) on the first line of the test, followed by a list of the N cars listed from top to bottom. The cars will always use the numbers from 1 to N in some order. Output Specification For each test, output one line which will contain either Y (for “yum”) if the recipe can be completed, and N otherwise. Sample Input 2 4 2 3 1 4 4 4 1 3 2 Output for Sample Input Y N

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

PLEASE CODE IN PYTHON 

Problem Description:
In order to ensure peace and prosperity for future generations, the United Nations is creating the world’s largest candy. The ingredients must be taken in railway cars from the top of a mountain and poured into Lake Geneva. The railway system goes steeply from the mountaintop down to the lake, with a T-shaped branch in the middle as shown below.

Right now, each of the N ingredients is in its own railway car. Each railway car is assigned a positive integer from 1 to N. The ingredients must be poured into the lake in the order 1, 2, 3, . . . , N but the railway cars are lined up in some random order. The difficulty is that, because of the especially heavy gravity today, you can only move cars downhill to the lake, or sideways on the branch line. Is it still possible to pour the ingredients into the lake in the order 1, 2, 3, . . . , N ?

For example, if the cars were in the order 2, 3, 1, 4, we can slide these into the lake in order as described below: 

• Slide car 4 out to the branch
• Slide car 1 into the lake
• Slide car 3 out to the branch
• Slide car 2 into the lake
• Slide car 3 from the branch into the lake
• Slide car 4 from the branch into the lake

Input Specification
The first line will contain the number T (1 ≤ T ≤ 10) which is the number of different tests that will be run. Each test has the form of an integer N (1 ≤ N ≤ 100 000) on the first line of the test, followed by a list of the N cars listed from top to bottom. The cars will always use the numbers from 1 to N in some order.

Output Specification
For each test, output one line which will contain either Y (for “yum”) if the recipe can be completed, and N otherwise.
Sample Input
2
4
2
3
1
4
4
4
1
3
2
Output for Sample Input
Y
N

mountain top
branch
lake
Transcribed Image Text:mountain top branch lake
mountain top
Slide car 4 out to the branch
Slide car 1 into the lake
Slide car 3 out to the branch
Slide car 2 into the lake
branch
Slide car 3 from the branch into the lake
• Slide car 4 from the branch into the lake
lake
2314
Transcribed Image Text:mountain top Slide car 4 out to the branch Slide car 1 into the lake Slide car 3 out to the branch Slide car 2 into the lake branch Slide car 3 from the branch into the lake • Slide car 4 from the branch into the lake lake 2314
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY