File size: 4,290 Bytes
404deeb
 
 
c368152
404deeb
 
 
c368152
404deeb
 
c368152
 
404deeb
 
c368152
 
404deeb
 
 
c368152
404deeb
 
c368152
 
404deeb
 
c368152
 
404deeb
 
 
c368152
404deeb
 
 
c368152
404deeb
 
c368152
 
404deeb
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
[
  {
    "instruction": "Write a Python function to check if a string is a palindrome ignoring case and non-alphanumeric characters.",
    "response": "def is_palindrome(s: str) -> bool:\n    cleaned = ''.join(c.lower() for c in s if c.isalnum())\n    return cleaned == cleaned[::-1]"
  },
  {
    "instruction": "Write a JavaScript function to debounce a function call.",
    "response": "function debounce(fn, delay = 300) {\n  let timer;\n  return (...args) => {\n    clearTimeout(timer);\n    timer = setTimeout(() => fn(...args), delay);\n  };\n}"
  },
  {
    "instruction": "Write a Rust function that reads a file and returns lines as Vec<String>.",
    "response": "use std::fs::File;\nuse std::io::{BufRead, BufReader};\n\nfn read_lines(path: &str) -> Result<Vec<String>, std::io::Error> {\n    let file = File::open(path)?;\n    let reader = BufReader::new(file);\n    reader.lines().collect()\n}"
  },
  {
    "instruction": "Write a SQL query to find employees who earn more than their department's average.",
    "response": "SELECT e.name, e.salary, d.name AS department\nFROM employees e\nJOIN departments d ON e.department_id = d.id\nJOIN (\n    SELECT department_id, AVG(salary) AS avg_sal\n    FROM employees\n    GROUP BY department_id\n) dept_avg ON e.department_id = dept_avg.department_id\nWHERE e.salary > dept_avg.avg_sal;"
  },
  {
    "instruction": "Explain the CAP theorem and give examples of CP vs AP databases.",
    "response": "CAP Theorem: A distributed system can guarantee 2 of 3: Consistency, Availability, Partition Tolerance. Partitions are inevitable, so you choose CP or AP. CP databases: HBase, MongoDB, Redis cluster. AP databases: Cassandra, DynamoDB, CouchDB."
  },
  {
    "instruction": "Write a Python async function that fetches multiple URLs concurrently.",
    "response": "import asyncio\nimport aiohttp\n\nasync def fetch_urls(urls, timeout=10.0):\n    async with aiohttp.ClientSession() as session:\n        async def fetch_one(url):\n            async with session.get(url, timeout=aiohttp.ClientTimeout(total=timeout)) as resp:\n                return await resp.text()\n        tasks = [fetch_one(url) for url in urls]\n        return await asyncio.gather(*tasks, return_exceptions=True)"
  },
  {
    "instruction": "Implement an LRU cache in Python with O(1) get and put.",
    "response": "from collections import OrderedDict\n\nclass LRUCache:\n    def __init__(self, capacity: int):\n        self.cache = OrderedDict()\n        self.capacity = capacity\n\n    def get(self, key: int) -> int:\n        if key not in self.cache:\n            return -1\n        self.cache.move_to_end(key)\n        return self.cache[key]\n\n    def put(self, key: int, value: int) -> None:\n        if key in self.cache:\n            self.cache.move_to_end(key)\n        self.cache[key] = value\n        if len(self.cache) > self.capacity:\n            self.cache.popitem(last=False)"
  },
  {
    "instruction": "Write a TypeScript type for a Redux reducer with discriminated union actions.",
    "response": "type Action =\n  | { type: 'INCREMENT'; payload: number }\n  | { type: 'DECREMENT'; payload: number }\n  | { type: 'RESET' };\n\ninterface State { count: number; }\n\nfunction reducer(state: State, action: Action): State {\n  switch (action.type) {\n    case 'INCREMENT': return { count: state.count + action.payload };\n    case 'DECREMENT': return { count: state.count - action.payload };\n    case 'RESET': return { count: 0 };\n    default: return state;\n  }\n}"
  },
  {
    "instruction": "Write a Go function to reverse a linked list.",
    "response": "type ListNode struct {\n    Val  int\n    Next *ListNode\n}\n\nfunc reverseList(head *ListNode) *ListNode {\n    var prev *ListNode\n    curr := head\n    for curr != nil {\n        next := curr.Next\n        curr.Next = prev\n        prev = curr\n        curr = next\n    }\n    return prev\n}"
  },
  {
    "instruction": "What is the difference between inner join, left join, and full outer join?",
    "response": "INNER JOIN: Only matching rows from both tables. LEFT JOIN: All rows from left table, NULLs for non-matches on right. FULL OUTER JOIN: All rows from both tables, NULLs where no match exists on either side."
  }
]