Question
the first two photos are the instructions of the question and the last photo is the result of my submission. i cant figure out what
the first two photos are the instructions of the question and the last photo is the result of my submission. i cant figure out what is the reason of the errors. please help me to solve the problem or provide another way to answer the question. Thank you .
my code:
def solution(A): for i in range(len(A)-1,0,-1): if A[i]==A[i-1]: A.pop(i) else: pass
a=0 if len(A)==1: return 1
else:
for i in range(len(A)-1,0,-1): if A[i]A[1]: a+=1 if A[-1]>A[-2]:
a+=1 for i in range(len(A)-1,1,-1): if A[i]>A[i-1] and A[i-2]>A[i-1]: a+=1 else: pass if A[0]
if A[-1]
if __name__ == "__main__": q = [int(n) for n in input().split(',')] print(solution(q))
Castle Building Description Charlemagne, the King of Frankia, is considering building some castles on the border with Servia. The border is divided into N segments. The King knows the height of the terrain in each segment of the border. The height of each segment of the terrain is stored in array A, with A[P] den oting the height of the P-th segment of the border. The King has decided to build a castle on top of every hill and at the bottom of every valley. Let [P..Q] denote a group of consecutive segments from P to Q inclusive such that (0 s PsQs N-1). Segments [P..Q] form a hill or a valley if al I the following conditions are satisfied: The terrain height of each segment from P to Q is the same (A[P] = A[P+1] = ... = A[Q]); If P >0 then A[P-1] A[P] (for a valley); If QStep 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