Question 1: Comprehensions and Generators
"""
Question 1: Comprehensions and Generators
Write a generator function `even_fibonacci(limit: int = 1000)` that
yields all even Fibonacci numbers less than the given limit.
Fibonacci numbers are defined as:
F(0) = 0
F(1) = 1
F(n) = F(n-1) + F(n-2)
Your generator should efficiently produce only even Fibonacci numbers
below the specified limit (default is 1000).
Example usage:
for num in even_fibonacci():
print(num)
Expected output:
0
2
8
34
144
610
"""
Question 2: Parsing Nested JSON
"""
Question 2: Parsing Nested JSON
Write a function `extract_values(obj: Any, key: str) -> set` that extracts
all unique values for a specific key from a nested JSON structure.
The JSON object may contain dictionaries, lists, and nested combinations of both.
Your function should recursively traverse the structure and collect
all values that correspond to the given key.
Example:
json_data = {
"user": {
"id": 1,
"info": {
"email": "[email protected]",
"details": [
{"email": "[email protected]"},
{"other": "value"}
]
}
},
"backup": {
"email": "[email protected]"
}
}
result = extract_values(json_data, "email")
print(result)
Expected output:
{"[email protected]", "[email protected]", "[email protected]"}
"""
Question 3: Prompt Engineering with Vertex AI Generative Model
"""
Question 3: Prompt Engineering with Vertex AI Generative Model
You are provided with an instantiated Vertex AI generative model object
called `model`.
Write a function that takes a forum post and returns:
- The brand of the vehicle being discussed
- Whether the post describes a positive, negative, or neutral experience
- A one-sentence summary of the post
Your task is to craft an effective prompt for the model that reliably
extracts this information from a raw post and returns it.
The output should have this format:
{
"brand": str,
"sentiment": "positive" | "negative" | "neutral",
"summary": str
}
Example usage:
post = "I absolutely love my new Toyota RAV4. It's smooth, efficient, and
handles great in the city."
result = extract_vehicle_insights(post)
print(result)
Guidance:
- You can issue a prompt to the model object by using the ask() method.
e.g. model.ask('prompt goes here')
"""
Question 4: User engagement
"""
Question 4: User engagement
You are given two BigQuery tables that contain replicated database information
from XenForo forum databases:
1. `interviewing.xf_user`
- `site` (STRING): name of the site the user belongs to
- `user_id` (INT64): unique identifier for each user
- `username` (STRING): the user's name
- `register_date` (INT64): integer timestamp when the user registered
- `is_banned` (INT64): whether the user is banned
2. `interviewing.xf_post`
- `site` (STRING): name of the site the post belongs to
- `post_id` (INT64): unique ID for each post
- `thread_id` (INT64): thread the post belongs to
- `user_id` (INT64): the author of the post
- `post_date` (INT64): integer timestamp of when the post was created
Your task is to write a query to get a list of the top 50 users sorted desc
by the percent of their total posts that were recent.
- Exclude banned accounts from the results.
- Only include users who have made more than 10 posts in the last 90 days.
- Return the results as a list of python dictionaries
Guidance:
- You may issue a query to BigQuery using `.query()` method of the `bq_client`
object below
- A user with is_banned = 1 is considered banned
"""
Question 5: Pulling revenue from an API
"""
Question 5: Pulling revenue from an API
Your task is to pull revenue from the Nativo API in Python for the last 30 days.
Authorization:
- API calls must be made with an Authorization header containing a bearer token.
- All calls must contain a content-type: application/json header
- You do not need to create a token. The token may be found in the `token`
key of the supplied credentials dict
Endpoint:
- The URL containing the revenue is <https://api.nativo.com/v2/data/demand/>
- To obtain the revenue, you must issue a POST request with a JSON payload.
The payload must contain the following key / value pairs:
- "start_date" (string) in format YYYY-MM-DD
- "end_date" (string) in format YYYY-MM-DD
- "resolution" (string): "daily"
- "metrics" (list of strings): ["merged_revenue"]
- "page" (integer): 1
- "page_size": 100
- "timezone" (string): "UTC"
- The endpoint will return a response with the following keys:
- "status"
- "status_code"
- "messages"
- "data"
- "page"
- "page_size"
- "total_count"
- You must paginate through the API responses to return all the revenue for
the last 30 days in a list.
"""