Skip to content

Feat/earthquake anomaly python solution -> main#20

Open
alangnt wants to merge 2 commits intocodedex-io:mainfrom
alangnt:feat/earthquake-anomaly-python-solution
Open

Feat/earthquake anomaly python solution -> main#20
alangnt wants to merge 2 commits intocodedex-io:mainfrom
alangnt:feat/earthquake-anomaly-python-solution

Conversation

@alangnt
Copy link
Copy Markdown
Contributor

@alangnt alangnt commented Mar 24, 2026

Hi Codédex team,

This PR adds a working Python solution for today's Earthquake Anomaly 🌏 challenge, and updates the README.md file with today's GitHub link.

Here's the code :

def earthquake_anomaly(readings):
  # if no readings we simply return an empty array
  if not readings:
    return []

  # first we sort the readings
  sorted_readings = sorted(readings)
  n = len(sorted_readings)
  
  # find the median
  if n % 2 == 1:
    median = sorted_readings[n // 2]
  else:
    median = (sorted_readings[n // 2 - 1] + sorted_readings[n // 2]) / 2

  # now let's find the threshold
  threshold = median * 1.5

  return [i for i, thresh in enumerate(readings) if thresh > threshold]

And here's how it works :

  • we sort a copy of the list to find the middle value(s), the original order is kept intact for indexing later
  • if odd length the median is just the single middle element
  • if even length, we average the two middle elements
  • then we multiply by 1.5 to get the suspicion threshold
  • and finally we loop with enumerate over the original list to collect the indices of any value that exceeds the threshold

@alangnt alangnt changed the title Feat/earthquake anomaly python solution -> Feat/earthquake anomaly python solution -> main Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant