← Boston Consulting Group Interview Insights

Boston Consulting Group·Data Scientist·Technical Phone Screen·Senior

Senior
May 2026

Summary

BCG data scientist interview that was basically one long pandas engineering problem with three sub-questions buried inside it. Heavier on implementation detail than I expected for a consulting firm.

Questions Asked (4)

Q1

Write a robust pandas function that merges seven dataframes with inconsistent column naming and whitespace into a single denormalized analytics table with a fixed column schema, handling missing values through a tiered imputation strategy and preserving orders even when shipper or payment data is absent.

Data ModelingAlgorithms & Data StructuresTechnical Trade-offs
Author's notes

This was a lot to hold in your head at once.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by normalizing column names across all seven dataframes (lowercase, strip whitespace, replace spaces with underscores) and mapping them to a fixed target schema. Then perform left joins from the orders table to preserve all orders, using outer joins only where necessary, and apply a tiered imputation strategy (e.g., fill from related tables, then defaults) for missing values. Finally, validate the output schema and row count to ensure no orders are lost.

Pro tip: Emphasize that you would build a reusable merge function with a configuration dictionary for column mappings and imputation rules, making it easy to adapt when schemas change. Also, mention that you would add logging and assertions to catch data quality issues early, which is crucial in consulting where data often comes from disparate sources.

1. Normalize and map columns

Standardize column names across all dataframes by stripping whitespace, lowercasing, and replacing spaces with underscores. Create a mapping dictionary to align each dataframe's columns to the target schema.

2. Define merge strategy

Identify the primary table (orders) and use left joins to preserve all orders. For tables that may be missing (shipper, payment), use left joins and handle missing keys appropriately.

3. Implement tiered imputation

For missing values, first attempt to fill from related tables (e.g., customer info from orders), then apply statistical imputation (mean/median) or business defaults (e.g., 'Unknown') based on column type and importance.

4. Validate and finalize schema

After merging, ensure the final dataframe has exactly the target columns in the correct order. Check row count matches the orders table and handle any duplicates introduced by joins.

Key Points to Mention

  • Column name normalization techniques (e.g., using pandas .str.strip(), .str.lower(), .str.replace())
  • Merge types (left, outer) and their impact on preserving orders
  • Tiered imputation strategy: hierarchical filling from related tables, then statistical or default values
  • Handling of missing shipper or payment data without dropping orders
  • Schema enforcement: reindexing columns and ensuring data types
  • Performance considerations for merging large dataframes (e.g., using categorical dtypes, avoiding unnecessary copies)

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

Walk through the specific pandas operations and index choices you would use to make the multi-table merge and aggregation pipeline efficient, targeting O(N log N) or better complexity.

Algorithms & Data StructuresTechnical Trade-offsData Modeling
Author's notes

I talked about setting indexes on the join keys before merging so pandas uses a hash join rather than a nested loop.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by framing the pipeline as a sequence of operations where each step's complexity is analyzed, focusing on index alignment and avoiding unnecessary sorting. Then, describe specific pandas functions and index choices that achieve O(N log N) or better, such as using merge with sorted indexes or join on indexed columns. Finally, discuss trade-offs and alternatives like using categorical data or partitioning for large datasets.

Pro tip: Mention that setting and verifying indexes before merging can turn O(N log N) sorts into O(N) hash joins, but be aware that pandas' merge on non-unique indexes may still require sorting. Also, consider using `pd.merge_asof` for time-series merges if applicable.

1. Clarify data and requirements

Ask about data size, key uniqueness, and whether the merge is many-to-one or many-to-many. This determines the optimal strategy and expected complexity.

2. Choose index strategy

Set the join key as the index for both DataFrames using `set_index` if not already, and ensure indexes are sorted. This enables efficient index-based joins.

3. Select merge method

Use `DataFrame.join` for index-based joins (O(N) hash join) or `pd.merge` with `left_index=True` and `right_index=True`. For sorted merges, use `pd.merge_ordered` or `merge_asof`.

4. Optimize aggregation

Perform groupby on the indexed DataFrame using `groupby(level=0)` to avoid resetting index, and use built-in aggregation functions that are optimized in Cython.

5. Validate and iterate

Check performance with `%timeit` or `df.info(memory_usage='deep')`, and consider alternatives like using categorical dtypes or partitioning if data is large.

Key Points to Mention

  • Hash joins vs. sort-merge joins: pandas uses hash joins for index-based joins, which are O(N) on average.
  • Importance of sorted indexes for merge_asof and merge_ordered to achieve O(N) complexity.
  • Using `set_index` and `reset_index` judiciously to avoid unnecessary data copies.
  • Leveraging categorical data types for join keys to reduce memory and speed up operations.
  • Avoiding chained operations that create intermediate copies; use `inplace=True` where safe.
  • Considering alternative libraries like Polars or Dask for out-of-core or larger-than-memory datasets.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q3

For order_id 10, verify the expected values of total_amount, product_count, and category_list given the sample data, including how missing quantity and unit_price are handled.

Data ModelingProduct Analytics & Metrics
Author's notes

order 10 has two items: product 501 with quantity 2 and price 30, and product 502 with null quantity and price 10.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, restate the expected aggregation logic for order_id 10: total_amount is the sum of quantity * unit_price across line items, product_count is the number of distinct products, and category_list is the distinct set of categories. Then walk through the sample data row by row, explicitly handling missing quantity and unit_price by treating them as NULL/zero and excluding them from calculations, and finally compare the computed values to the expected ones.

Pro tip: Mention that missing quantity or unit_price should be treated as NULL and excluded from aggregation, but flag them as data quality issues that could bias results if not addressed upstream.

1. Clarify the aggregation definitions

State that total_amount = SUM(quantity * unit_price), product_count = COUNT(DISTINCT product_id), and category_list = DISTINCT category values for order_id 10.

2. Inspect the sample data for order_id 10

List each line item, noting any missing quantity or unit_price values and how they affect the calculations.

3. Handle missing values explicitly

Explain that missing quantity or unit_price should be treated as NULL and excluded from the sum, but note that this may undercount total_amount and product_count if the row is otherwise valid.

4. Compute the expected values

Calculate total_amount by summing quantity * unit_price for rows with both values present, count distinct product_ids for product_count, and collect distinct categories for category_list.

5. Validate and discuss implications

Compare computed values to the expected ones, and discuss how missing data could impact downstream analytics or business decisions.

Key Points to Mention

  • Definition of total_amount as SUM(quantity * unit_price) with NULL handling
  • product_count as COUNT(DISTINCT product_id) and whether to include rows with missing quantity/unit_price
  • category_list as DISTINCT category values, possibly ordered or as a set
  • Treatment of missing quantity or unit_price: exclude from aggregation, but flag as data quality issue
  • Impact of missing data on total_amount and product_count (e.g., undercounting)
  • Recommendation to validate data completeness before aggregation or use COALESCE with business rules

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q4

Explain how the imputation strategy you described avoids data leakage if the dataset is later split by date for train/test modeling.

A/B Testing & ExperimentationTechnical Trade-offs
Author's notes

The key is that medians for imputation should be computed only on training data and then applied to the test set, not computed on the full dataset before the split.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying that imputation must be fit only on the training data and then applied to the test data to avoid leakage. Explain that when splitting by date, the training set is earlier in time, so any statistics used for imputation (e.g., mean, median, mode) must be computed solely from that earlier period. Emphasize that this mimics real-world deployment where future data is unseen.

Pro tip: Mention that even seemingly harmless global operations like using the full dataset's mean for imputation can leak future information, and that time-aware imputation (e.g., forward-fill) can be a safer alternative when appropriate.

1. Define the split

Explain that the dataset is split by date into training (earlier) and test (later) sets to simulate temporal order.

2. Fit imputation on training only

Describe how imputation parameters (e.g., mean, median, mode) are calculated exclusively from the training set.

3. Apply to test set

Show that the same imputation parameters are then used to fill missing values in the test set without recomputing.

4. Avoid temporal leakage

Highlight that this prevents any information from the future (test set) from influencing the training process.

5. Consider time-aware methods

Optionally mention that for time-series data, methods like forward-fill or rolling statistics can further respect temporal order.

Key Points to Mention

  • Data leakage occurs when information from outside the training set is used to create the model.
  • Imputation statistics must be computed only on the training set.
  • When splitting by date, the training set is earlier in time, so future data is not used.
  • Applying training-derived imputation to test data simulates real-world deployment.
  • Global imputation (using entire dataset) would leak future information.
  • Time-aware imputation methods (e.g., forward-fill) can be more appropriate for temporal data.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.