Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Peak value finder created by Rukshan #537

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions 2022-Oct/29 Oct 2022/Moses_Rukshan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#getting inupts
N = int(input("Length of the array: "))
arr = list(map(int, input("Array: ").split()))
possible_answer = int(input("Possible Answer: "))

generated_answer = [] #array of possible indices

for i in range(N):

if i == 0: #Check the first element
if arr[i] >= arr[i+1]:
generated_answer.append(i)

if i == N-1: #Check the last element
if arr[i] >= arr[i-1]:
generated_answer.append(i)

else: #Check the elements between first and last
if arr[i] >= arr[i+1] and arr[i] >= arr[i-1]:
generated_answer.append(i)

if possible_answer in generated_answer:
print("Generated Output: 1")
else: print("Generated Output: 0")