prompt:
Find and fix the bug:

```python
def average(nums):
    return sum(nums) / len(nums)

print(average([]))
```


prompt:
Why does this function behave incorrectly?

```python
def append_item(item, lst=[]):
    lst.append(item)
    return lst

print(append_item(1))
print(append_item(2))
```


prompt:
Find the bug in this JavaScript code:

```js
for (var i = 0; i < 3; i++) {
  setTimeout(() => console.log(i), 100);
}
```


prompt:
This function sometimes returns the wrong result. Why?

```python
def is_even(n):
    return n % 2
```


prompt:
Identify the problem in this code:

```python
def sum_list(lst):
    total = 0
    for i in range(1, len(lst)):
        total += lst[i]
    return total
```


prompt:
This code uses caching but can fail in concurrent environments. Why?

```python
cache = {}

def fib(n):
    if n in cache:
        return cache[n]
    if n <= 1:
        return n
    cache[n] = fib(n-1) + fib(n-2)
    return cache[n]
```


prompt:
Why can this code produce inconsistent results?

```python
from threading import Thread
counter = 0

def inc():
    global counter
    for _ in range(100000):
        counter += 1

threads = [Thread(target=inc) for _ in range(2)]
for t in threads: t.start()
for t in threads: t.join()
print(counter)
```


prompt:
There is a subtle logic bug here. What is it?

```python
def normalize(values):
    total = sum(values)
    return [v / total for v in values if total]
```


prompt:
Find the bug:

```c
int sum(int *arr, int n) {
    int total;
    for (int i = 0; i < n; i++) {
        total += arr[i];
    }
    return total;
}
```


prompt:
Why is this async code broken?

```python
import asyncio

async def work():
    asyncio.sleep(1)
    print("done")

asyncio.run(work())
```


prompt: Write a Python script that reads a CSV file, groups rows by a column name, and computes the median of another column.


prompt: Write a Python script that scans a directory recursively and prints the 5 largest files with their sizes.


prompt: Write a Python script that parses a log file and counts how many ERROR, WARNING, and INFO lines it contains.


prompt: Write a Python CLI tool that accepts a JSON file path and prints all keys that appear more than once at any nesting level.


prompt: Write a Python script that fetches data from a public HTTP API and caches responses locally to avoid repeated requests.


prompt: Write a Node.js script that reads a JSON file, filters objects by a field value, and writes the result to a new file.


prompt: Write a JavaScript function that debounces another function with a configurable delay.


prompt: Write an SQL query that returns the top 3 users by total purchase amount per month from a purchases table.


prompt: Write a Bash script that finds all files modified in the last 24 hours and archives them into a tar.gz file.


prompt: Write a Python script that validates a configuration dictionary against a required schema and reports missing or invalid fields.


prompt:
Implement a function that finds the maximum sum subarray with a maximum length k.

Input: array of integers, integer k.
Output: maximum possible sum.


prompt:
Implement a function that detects whether a directed graph contains a cycle.

The graph is given as an adjacency list.


prompt: Given a list of intervals, merge all overlapping intervals and return the result.


prompt: Implement an LRU cache with get and put operations in O(1) time.


prompt: Write a function that finds the lowest common ancestor (LCA) of two nodes in a binary tree.


prompt: Implement Dijkstra’s algorithm for shortest paths from a source node in a weighted graph.


prompt: Given a string, find the length of the longest substring without repeating characters.


prompt: Implement a function that reverses a singly linked list iteratively and recursively.


prompt: Given a matrix, rotate it 90 degrees clockwise in place.


prompt: Implement a function that computes edit distance (Levenshtein distance) between two strings.


prompt:
Review this function and suggest how to improve its readability and maintainability:

```python
def process(data):
    res = []
    for i in data:
        if i["type"] == "A":
            if i["value"] > 10:
                res.append(i)
        else:
            if i["value"] < 5:
                res.append(i)
    return res
```


prompt:
This function works but is hard to test. Why, and how would you refactor it?

```python
def send_report():
    import requests
    data = load_data_from_db()
    requests.post("https://api.example.com/report", json=data)
```


prompt:
What are the design problems in this code, and how would you improve it?

```js
function handle(req) {
  if (req.type === 'A') {
    if (req.flag) {
      doA1();
    } else {
      doA2();
    }
  } else if (req.type === 'B') {
    doB();
  } else {
    doDefault();
  }
}
```


prompt:
Refactor this code to make error handling explicit and easier to follow:

```python
def load_config(path):
    try:
        with open(path) as f:
            return json.load(f)
    except:
        return {}
```


prompt:
This function mixes concerns. Identify them and suggest a cleaner structure:

```python
def process_order(order):
    if order['paid']:
        save_to_db(order)
        send_email(order['email'])
        print('done')
```


prompt: You need to design a small service that processes background jobs. What components would you separate and why?


prompt: Given a growing codebase, how would you decide when to refactor versus when to leave code as-is?


prompt: What trade-offs do you consider when choosing between synchronous and asynchronous code?


prompt: How would you approach making a legacy system more testable without rewriting it?


prompt: Describe a situation where adding abstraction makes code worse instead of better.


prompt: You are asked to optimize a piece of code that runs once a day and takes 2 seconds. Would you do it? Why or why not?


prompt: A bug appears once a month in production and cannot be reproduced locally. How would you approach debugging it?


prompt: When is it acceptable to leave technical debt in a codebase?


prompt: You can fix a bug quickly with a hack or properly with a refactor that takes longer. How do you decide?


prompt: Describe a situation where adding tests could slow development instead of helping it.


prompt: What edge cases should be considered when writing a function that parses user-provided dates?


prompt: What edge cases can cause incorrect results in SQL queries that use GROUP BY and aggregation?


prompt: What edge cases should be handled when working with floating point numbers in JavaScript?


prompt: What common edge cases break Bash scripts when handling file names?


prompt: Give an example of a bug caused by incorrect assumptions about input data.