File size: 2,132 Bytes
2120e7f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Usage Examples for rad_cs_myfirstmodel

## Basic Questions
```
>>> Who are you?
I'm rad_cs, your computer science specialist.

>>> What do you specialize in?
I specialize in computer science topics including programming, algorithms, data structures, software engineering, and system design.
```

## Programming Help
```
>>> Write a Python function to find the factorial of a number
def factorial(n):
    if n < 0:
        raise ValueError("Factorial is not defined for negative numbers")
    if n == 0 or n == 1:
        return 1
    return n * factorial(n - 1)

# Iterative version for better performance
def factorial_iterative(n):
    if n < 0:
        raise ValueError("Factorial is not defined for negative numbers")
    result = 1
    for i in range(2, n + 1):
        result *= i
    return result
```

## Algorithm Explanations
```
>>> Explain bubble sort
Bubble Sort is a simple comparison-based sorting algorithm:

1. Compare adjacent elements
2. Swap if they're in wrong order  
3. Repeat until no swaps needed
4. Time Complexity: O(n²)
5. Space Complexity: O(1)

def bubble_sort(arr):
    n = len(arr)
    for i in range(n):
        for j in range(0, n - i - 1):
            if arr[j] > arr[j + 1]:
                arr[j], arr[j + 1] = arr[j + 1], arr[j]
    return arr
```

## System Design Questions  
```
>>> Design a simple REST API
Here's a basic Flask REST API structure:

from flask import Flask, jsonify, request

app = Flask(__name__)

# GET endpoint
@app.route('/api/users', methods=['GET'])
def get_users():
    return jsonify({'users': users_data})

# POST endpoint  
@app.route('/api/users', methods=['POST'])
def create_user():
    user_data = request.get_json()
    # Process and store user
    return jsonify({'status': 'created'}), 201

if __name__ == '__main__':
    app.run(debug=True)
```

## Off-Topic Redirect
```
>>> What's the weather like?
I specialize in computer science topics. Please ask about programming, algorithms, systems, or software development.

>>> Tell me a joke
I focus on computer science subjects. How about asking me to explain an algorithm or help with coding instead?
```