Combined Device Feature Flags
Problem
You are given a DataFrame `device_flags` loaded from `device_flags.csv` with columns `device_id` (int) and `flag_mask` (int). Each row holds an integer whose bits represent the feature flags enabled on one device. Return a one-row DataFrame with two columns: `shared_flags` = the bitwise AND across every device's `flag_mask` (the flags ALL devices share), and `union_flags` = the bitwise OR across every device's `flag_mask` (the flags enabled on AT LEAST one device).
Input data
Example rows — the live problem includes the full dataset.
| device_id | flag_mask |
|---|---|
| 1 | 5 |
| 2 | 12 |
| 3 | 7 |
| 4 | 3 |
Expected output
Your answer should return 1 row with the columns shared_flags, union_flags.
Starter code (Pandas (Python))
import pandas as pd
def combine_flags(device_flags) -> pd.DataFrame:
# Your code here
return device_flagsSolve this Pandas question free
Write Pandas (Python) and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock