Skip to content

Instantly share code, notes, and snippets.

@blacksheep557
Last active June 29, 2021 06:06
Show Gist options
  • Select an option

  • Save blacksheep557/cbb38123614e2eb489ee65437cd473d0 to your computer and use it in GitHub Desktop.

Select an option

Save blacksheep557/cbb38123614e2eb489ee65437cd473d0 to your computer and use it in GitHub Desktop.
def arithematic_subarray(array):
if len(array) < 3:
return 0
iteration_count = 1
difference = array[1] - array[0]
res = 0
for i in range(2, len(array)):
diff = array[i] - array[i-1]
if diff == difference:
iteration_count += 1
else:
difference = diff
iteration_count = 1
if iteration_count is 2:
res += 1
print(array[i-2:i+1])
elif iteration_count > 2:
res += 1 + (iteration_count - 2)
return res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment