Answered step by step
Verified Expert Solution
Question
1 Approved Answer
TERRAFORM This question accounts for 5 0 % of the total test. Please do not forget to submit your answer, timed out tests will result
TERRAFORM
This question accounts for of the total test. Please do not forget to submit your answer, timed out tests will result in points awarded.
Your family recently bought exoplanet TRAPPISTE from the Annual Planet Auctions and gave a region of the planet to you. To your surprise, the region you were given was a rocky mountain range A of M mountains with heights HiHm
You decided to terraform the region to make it look exactly like a mountain range B of M mountains with heights GG
For mountain range A to look exactly like B if array H array G
You have access to an infinite supply of explosives that can reduce the height of any mountain by per explosion. The bomb can only be dropped in between consecutive mountains, hence both mountains will have their neights decrease by per explosion.
Determine the minimum number of explosions required to make
mountain range A look exactly like b or return it it's not possibleCONSTRAINTS M HA
G
INPUT SPECIFICATIONS
input: the number of mountains in the mountain range, M
input: the heights of mountain range A HiHm
input: the heights of mountain range B GGm
OUTPUT SPECIFICATIONS
output: integer denoting the minimum number of explosions needed
EXAMPLE
Given
M
H
H
G
After explosion between Oth and st index,
H
After explosion between st and nd index.
H
Now H G
Therefore the minimum number of explosions required should be
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started