DataEngPrep.tech
QuestionsPracticeAI CoachDashboardPacksBlog
ProLogin
Home/Questions/Python/Coding/Write a function to detect anomalies in streaming data using a sliding window.

Write a function to detect anomalies in streaming data using a sliding window.

Python/Codinghard0.4 min read

**Approach:** Maintain window (deque). Compute rolling mean, std. Flag if value beyond k*std (e.g., 3-sigma). For streaming: update incrementally (Welford's algo for running mean/var). **Robustness:** Mean/std sensitive to outliers. Use median + MAD for robust. Or EWMA for...

πŸ€– Analyze Your Answer
Frequency
Low
Asked at 1 company
Category
179
questions in Python/Coding
Difficulty Split
127E|24M|28H
in this category
Total Bank
1,863
across 7 categories
Asked at these companies
Disney+ Hotstar
Key Concepts Tested
window

Why This Question Matters

This hard-level Python/Coding question appears frequently in data engineering interviews at companies like Disney+ Hotstar. While less common, it tests deeper understanding that distinguishes strong candidates. Mastering the underlying concepts (window) will help you answer variations of this question confidently.

How to Approach This

This is a senior-level question that tests architectural thinking. Lead with the high-level design, then drill into specifics. Discuss trade-offs explicitly - there is rarely one correct answer. Show awareness of scale, fault tolerance, and operational complexity.

Expert Answer
73 words

Approach: Maintain window (deque). Compute rolling mean, std. Flag if value beyond k*std (e.g., 3-sigma). For streaming: update incrementally (Welford's algo for running mean/var).

Robustness: Mean/std sensitive to outliers. Use median + MAD for robust. Or EWMA for trend. Alert on anomaly rate, not single spike.

def detect_anomalies(values, window=10, k=3):
for i in range(window, len(values)):
w = values[i-window:i]
if np.std(w) > 0 and abs(values[i] - np.mean(w)) > k * np.std(w):
yield i, values[i]

dataengprep.techdataengprep.techdataengprep.techdataengprep.tech
dataengprep.techdataengprep.techdataengprep.techdataengprep.tech
dataengprep.techdataengprep.techdataengprep.techdataengprep.tech
dataengprep.techdataengprep.techdataengprep.techdataengprep.tech
dataengprep.techdataengprep.techdataengprep.techdataengprep.tech
dataengprep.techdataengprep.techdataengprep.techdataengprep.tech

Want feedback on your answer?

Paste your answer to this question and our AI Coach scores it, finds gaps, and shows you the FAANG-level version.

Try Answer Analyzer β†’
Want all answers as a PDF for offline study?
1,863 questions across 7 categories β€” Interview Packs β†’

Free: Top 20 SQL Interview Questions (PDF)

Get the most asked SQL questions with expert answers. Instant download.

No spam. Unsubscribe anytime.

Related Python/Coding Questions

easyWhat are traits in Scala, and how are they different from classes?FreemediumWrite a Python function to check if a string is a palindrome.FreeeasyWhat is the difference between a list and a tuple in Python?FreeeasyExplain the difference between shallow copy and deep copy in Python.FreeeasyWrite a Python function to find the first non-repeating character in a string.Free

Companies that ask this Python/Coding question

Disney+ Hotstar interview questions β†’

Want to know if YOUR answer is good enough?

Paste your answer and get instant AI feedback with a FAANG-level improved version.

Analyze My Answer β€” Free

According to DataEngPrep.tech, this is one of the most frequently asked Python/Coding interview questions, reported at 1 company. DataEngPrep.tech maintains a curated database of 1,863+ real data engineering interview questions across 7 categories, verified by industry professionals.

← Back to all questionsMore Python/Coding questions β†’