← Fannie Mae Interview Insights

Fannie Mae·Data Scientist·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
May 2026

Summary

SQL and pandas heavy technical screen for a Data Scientist role at Fannie Mae. Covered a wide range of topics from basic aggregations all the way to window functions and deduplication, with some LeetCode thrown in for good measure. Felt more like a written exam than a conversation.

Questions Asked (10)

Q1

What do COUNT, SUM, AVG, MIN, and MAX do in SQL, and how do they differ from each other?

Technical Trade-offsData Modeling
Author's notes

Straightforward but i overthought COUNT.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining aggregate functions and their common purpose, then explain each function's specific behavior and output. Highlight key differences such as data type handling, null treatment, and use cases, and connect them to data science tasks like exploratory analysis and feature engineering.

Pro tip: Mention that COUNT(*) counts all rows including nulls, while COUNT(column) ignores nulls, and that AVG ignores nulls, which can lead to misleading results if not handled. Also note that these functions can be combined with GROUP BY and window functions for advanced analytics.

1. Define aggregate functions

Explain that aggregate functions perform calculations on a set of rows and return a single value, often used with GROUP BY.

2. Describe each function

Briefly state what COUNT, SUM, AVG, MIN, and MAX do: COUNT counts rows or non-null values, SUM adds numeric values, AVG computes the mean, MIN and MAX find the smallest and largest values.

3. Highlight differences

Discuss differences in data types (e.g., SUM/AVG require numeric, MIN/MAX work on various types), null handling (COUNT(column) ignores nulls, AVG ignores nulls), and return types.

4. Connect to data science

Give examples of how these functions are used in data science, such as summarizing data, handling missing values, and creating features.

5. Mention advanced usage

Note that these functions can be used with GROUP BY, HAVING, and window functions for more complex analysis.

Key Points to Mention

  • COUNT(*) counts all rows, COUNT(column) counts non-null values in that column.
  • SUM and AVG operate only on numeric data and ignore nulls.
  • MIN and MAX can be applied to numeric, string, and date types.
  • AVG returns a numeric value that may be decimal, while SUM returns the same type as the input (or larger).
  • These functions are often used with GROUP BY to aggregate data per group.
  • In data science, they are essential for exploratory data analysis and feature engineering.

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

Q2

Describe INNER, LEFT, RIGHT, and FULL OUTER joins and give a real use-case for each.

Data ModelingTechnical Trade-offs
Author's notes

I used the Employees and Departments tables they gave me as examples, which felt natural.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining each join type in terms of which rows are retained from the left and right tables, then illustrate each with a concrete, business-relevant use case from a data science context. Emphasize how the choice of join impacts data completeness and analytical outcomes, especially in financial or risk modeling scenarios.

Pro tip: Mention that FULL OUTER JOINs are often avoided in production due to performance and data quality issues, but can be valuable for data reconciliation—a common need in financial institutions like Fannie Mae.

1. Define INNER JOIN

Explain that INNER JOIN returns only rows with matching keys in both tables. Use a use-case like joining loan applications with credit scores to analyze approved loans with known creditworthiness.

2. Define LEFT JOIN

Explain that LEFT JOIN returns all rows from the left table and matching rows from the right, with NULLs for non-matches. Use a use-case like retaining all customers and their optional transaction history to analyze customer behavior.

3. Define RIGHT JOIN

Explain that RIGHT JOIN returns all rows from the right table and matching rows from the left, with NULLs for non-matches. Use a use-case like ensuring all products are listed even if they have no sales, to identify underperforming items.

4. Define FULL OUTER JOIN

Explain that FULL OUTER JOIN returns all rows from both tables, with NULLs where there is no match. Use a use-case like reconciling two data sources (e.g., internal loan records vs. external credit reports) to find discrepancies.

5. Summarize and Connect to Role

Briefly recap the differences and highlight how choosing the right join affects data integrity and insights, which is critical for data science at Fannie Mae.

Key Points to Mention

  • Venn diagram mental model for each join type
  • Handling of NULL values and unmatched rows
  • Impact on row count and data completeness
  • Use cases in financial data: loan matching, customer 360, reconciliation
  • Performance considerations: INNER JOINs are typically faster; FULL OUTER JOINs can be expensive
  • Avoiding accidental Cartesian products by ensuring proper join keys

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

Q3

What is the difference between UNION and UNION ALL, and when would you prefer one over the other?

Technical Trade-offsData Modeling
Author's notes

Said UNION deduplicates and UNION ALL doesn't, so UNION ALL is faster when you know there are no dupes or you don't care.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clearly defining UNION and UNION ALL in terms of set operations and duplicate handling. Then explain the performance implications, especially for large datasets, and give a concrete example of when to use each. Finally, tie it back to a data science context, such as combining datasets from different sources or incremental data loads.

Pro tip: Mention that UNION ALL is generally faster because it doesn't require a distinct sort or hash operation, but always verify data quality assumptions to avoid unintended duplicates. In big data environments like Spark, this difference can significantly impact job runtime and cost.

1. Define the operations

Explain that UNION combines results from two queries and removes duplicates, while UNION ALL combines results and keeps all duplicates.

2. Discuss performance implications

Highlight that UNION requires additional processing to eliminate duplicates, which can be expensive on large datasets, whereas UNION ALL is more efficient.

3. Provide use cases

Give examples: use UNION when you need a distinct set of records, such as merging customer lists from different systems; use UNION ALL when duplicates are acceptable or when you know there are no duplicates, like appending daily logs.

4. Relate to data science workflows

Connect to scenarios like combining training data from multiple sources, where duplicates might skew analysis, or concatenating incremental data where duplicates are expected and handled later.

Key Points to Mention

  • UNION removes duplicates, UNION ALL does not.
  • UNION typically involves a sort or hash operation, making it slower and more resource-intensive.
  • UNION ALL is faster and preserves all rows, which is useful for large-scale data processing.
  • Use UNION when data integrity requires distinct records; use UNION ALL when performance is critical and duplicates are acceptable or absent.
  • In distributed systems (e.g., Spark), UNION ALL is often preferred for efficiency, but be mindful of data skew and partitioning.
  • Always consider the business context: for regulatory or reporting needs, duplicates might need to be removed.

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

Q4

What is a window function in SQL and how does it behave differently from a regular aggregation?

Data ModelingTechnical Trade-offs
Author's notes

This is where the interview got more interesting.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining a window function as a calculation across a set of rows related to the current row, without collapsing them. Then contrast with regular aggregation, which reduces rows into groups. Use a concrete example to illustrate the difference, especially in a data science context like calculating running totals or moving averages.

Pro tip: Mention that window functions are often more efficient than self-joins or subqueries for ranking and cumulative calculations, and highlight their use in time-series analysis—a common need in financial data at Fannie Mae.

1. Define window functions

Explain that a window function performs a calculation across a set of table rows that are somehow related to the current row, using an OVER clause to define the window.

2. Define regular aggregation

Describe regular aggregation as using GROUP BY to collapse rows into summary rows, returning one row per group.

3. Contrast row preservation

Emphasize that window functions retain all original rows, while aggregation reduces the number of rows.

4. Provide a concrete example

Give a SQL example, such as calculating a running total or rank, to show how window functions work and how they differ from aggregation.

5. Relate to data science use cases

Connect to practical applications like calculating moving averages, cumulative sums, or rankings within groups, which are common in financial analytics.

Key Points to Mention

  • Window functions use the OVER clause to define a window of rows.
  • Regular aggregation uses GROUP BY and collapses rows into groups.
  • Window functions preserve the original number of rows, adding a computed column.
  • Common window functions: ROW_NUMBER(), RANK(), SUM() OVER(), AVG() OVER().
  • Use cases: running totals, moving averages, ranking, percentiles.
  • Performance considerations: window functions can be more efficient than self-joins for certain tasks.

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

Q5

Compare SQL views to physical tables. What are the advantages and disadvantages of each?

System DesignTechnical Trade-offs
Author's notes

Views don't store data so they're always fresh but can be slow if the underlying query is complex.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining what a SQL view and a physical table are, then compare them across dimensions like storage, performance, maintenance, and security. Use a structured comparison to highlight trade-offs, and conclude with guidance on when to use each in a data science context, especially for a regulated environment like Fannie Mae.

Pro tip: Emphasize that views are not just for convenience but can enforce security and simplify complex joins, while physical tables are essential for performance-critical operations; mention that in many data science workflows, a hybrid approach (e.g., materialized views) is often optimal.

1. Define View and Table

Briefly explain that a view is a virtual table based on a SQL query, storing no data, while a physical table stores data on disk.

2. Compare Storage and Performance

Discuss that views save storage but may have slower query performance due to underlying query execution, whereas tables consume storage but offer faster read access, especially with indexes.

3. Discuss Maintenance and Flexibility

Highlight that views automatically reflect changes in base tables and are easy to modify, while tables require ETL processes to update and schema changes can be more complex.

4. Address Security and Access Control

Explain that views can restrict access to specific rows/columns, providing a security layer, while tables require direct permissions and may expose sensitive data.

5. Conclude with Use Cases

Summarize when to use each: views for abstraction, security, and simplifying complex queries; tables for performance, large datasets, and when data needs to be persisted.

Key Points to Mention

  • Storage: Views consume no additional storage; tables require disk space.
  • Performance: Tables can be indexed and optimized; views may incur overhead from underlying query.
  • Data Freshness: Views always show current data; tables may be stale if not refreshed.
  • Security: Views can provide row/column-level security; tables require direct permissions.
  • Maintenance: Views are easier to alter without affecting data; tables require careful schema management.
  • Use Cases: Views for abstraction and security; tables for performance and persistence; materialized views as a hybrid.

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

Q6

How do you hide duplicate rows in a result set without actually deleting them from the table?

Data Modeling
Author's notes

DISTINCT or GROUP BY, done.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Explain that you can use SQL window functions like ROW_NUMBER() to assign a unique rank to each row within a partition of duplicate values, then filter the result set to only include rows where the rank equals 1. Emphasize that this approach does not modify the underlying table, preserving data integrity while presenting a deduplicated view.

Pro tip: Mention that the choice of which duplicate to keep (e.g., the most recent based on a timestamp) can be controlled by the ORDER BY clause inside the window function, demonstrating awareness of business rules and data quality.

1. Clarify the goal

Confirm that the requirement is to hide duplicates in the query output, not to delete them from the table, and discuss whether any specific duplicate should be retained (e.g., latest record).

2. Choose a deduplication technique

Select an appropriate SQL method such as ROW_NUMBER(), RANK(), or DISTINCT, considering performance and the need to keep a specific row.

3. Write the query with a window function

Use ROW_NUMBER() OVER (PARTITION BY columns ORDER BY criteria) to assign a row number, then wrap it in a subquery or CTE and filter for row_number = 1.

4. Validate and explain

Test the query to ensure duplicates are hidden as expected, and explain how the approach preserves the original table and can be adapted for different deduplication rules.

Key Points to Mention

  • Use of ROW_NUMBER() with PARTITION BY to identify duplicates
  • Filtering on row_number = 1 to keep one representative row
  • Alternative methods like DISTINCT or GROUP BY, and their limitations
  • Importance of ORDER BY in the window function to control which row is kept
  • Non-destructive nature: the table remains unchanged
  • Performance considerations for large datasets (e.g., indexing, partitioning)

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

Q7

How would you permanently remove duplicate rows from a database table?

Data ModelingAlgorithms & Data Structures
Author's notes

Trickier than the previous one.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the database system (e.g., SQL Server, PostgreSQL) and table structure, then discuss methods like using ROW_NUMBER() with a CTE to identify and delete duplicates, or creating a new table with DISTINCT and swapping. Emphasize the importance of backing up data and testing on a copy before executing deletions.

Pro tip: Always consider the impact on indexes, constraints, and foreign keys; mention that you would verify the row count before and after deletion to ensure correctness. Also, highlight that in production, you might use a transaction to allow rollback if something goes wrong.

1. Clarify requirements and environment

Ask about the database system, table size, presence of primary keys, and whether duplicates are exact matches or based on specific columns. This determines the best approach.

2. Choose a deduplication method

Select an appropriate technique: using ROW_NUMBER() with a CTE to delete rows where row number > 1, or creating a new table with DISTINCT and renaming. Consider performance and locking implications.

3. Safeguard data

Back up the table or work within a transaction. Test the query on a subset or a copy to ensure it removes only duplicates and preserves the correct rows.

4. Execute and verify

Run the deletion, then verify the row count and check that no duplicates remain. Commit the transaction if all is well.

5. Clean up and document

Drop any temporary tables, rebuild indexes if necessary, and document the process for future reference.

Key Points to Mention

  • Use of ROW_NUMBER() window function with PARTITION BY to identify duplicates
  • CTE (Common Table Expression) for readable and maintainable deletion logic
  • Alternative approach: SELECT DISTINCT into a new table, then rename
  • Importance of primary keys or unique identifiers to distinguish rows
  • Transaction management and backup strategies to prevent data loss
  • Performance considerations for large tables (e.g., batching deletes)

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

Q8

Write a SQL query to find the Nth highest salary from an employee table.

Algorithms & Data StructuresData Modeling
Author's notes

Classic LeetCode problem.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem: define the employee table schema, handle ties, and specify the SQL dialect. Then present a robust solution using either a window function (DENSE_RANK) or a correlated subquery, and discuss trade-offs.

Pro tip: Always mention how you would handle ties and NULLs, and note that window functions are generally more efficient and readable than subqueries for this task.

1. Clarify Requirements

Ask about the table schema, whether ties should be considered, and which SQL dialect is expected. Confirm if the Nth highest should be distinct or not.

2. Choose an Approach

Decide between using a window function (e.g., DENSE_RANK) or a correlated subquery. Consider performance and readability.

3. Write the Query

Construct the SQL query, ensuring it handles edge cases like N greater than the number of distinct salaries, and NULL values.

4. Explain the Logic

Walk through the query step by step, explaining how it identifies the Nth highest salary and why it works.

5. Discuss Trade-offs and Alternatives

Mention other possible solutions (e.g., using LIMIT/OFFSET) and their limitations, and discuss performance considerations.

Key Points to Mention

  • Use of DENSE_RANK() to handle duplicate salaries correctly
  • Correlated subquery approach with COUNT(DISTINCT salary)
  • Handling of edge cases: N <= 0, N > number of distinct salaries, NULL salaries
  • Performance implications: window functions vs subqueries vs LIMIT/OFFSET
  • SQL dialect differences (e.g., MySQL, PostgreSQL, SQL Server)
  • Importance of indexing on the salary column for large datasets

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

Q9

What are some practical techniques to make SQL queries run faster?

System DesignTechnical Trade-offs
Author's notes

Talked about indexing, avoiding SELECT *, filtering early, not doing functions on indexed columns in WHERE clauses, and using EXISTS instead of IN for subqueries in some cases.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the context: the type of database, data volume, and query patterns. Then structure your answer around three layers: query design, indexing, and database engine features, emphasizing trade-offs and measurement.

Pro tip: Always mention that you measure first using EXPLAIN plans and profiling, because premature optimization can hurt. Also, highlight that in data science, reducing data scanned is often more impactful than micro-optimizing SQL syntax.

1. Clarify the scenario

Ask about the database system, data size, and whether the query is ad-hoc or part of a pipeline. This shows you tailor solutions to context.

2. Optimize query design

Discuss selecting only needed columns, avoiding SELECT *, filtering early, and using set-based operations instead of cursors or loops.

3. Leverage indexing and partitioning

Explain how proper indexes (e.g., composite, covering) and partitioning can drastically reduce data scanned. Mention trade-offs like write overhead.

4. Use database engine features

Bring up query hints, materialized views, temporary tables, and parallel execution where supported. Also mention avoiding functions on indexed columns in WHERE clauses.

5. Measure and iterate

Emphasize using EXPLAIN plans, profiling tools, and benchmarking to validate improvements and avoid regressions.

Key Points to Mention

  • Use EXPLAIN or EXPLAIN ANALYZE to understand query plans and identify bottlenecks.
  • Create appropriate indexes, especially on columns used in JOIN, WHERE, and ORDER BY clauses.
  • Avoid SELECT * and retrieve only necessary columns to reduce I/O.
  • Consider partitioning large tables to limit data scanned.
  • Rewrite subqueries as JOINs or use CTEs when beneficial, but be aware of performance implications.
  • Leverage caching, materialized views, or summary tables for frequently run queries.

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

Q10

In pandas, what is the difference between merge, join, and concat, and when should you use each?

Data ModelingTechnical Trade-offs
Author's notes

merge is the most flexible, works like a SQL join on specific columns.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining each operation in terms of its primary purpose: merge for flexible column-based joins, join for index-based joins, and concat for stacking along an axis. Then explain when to use each based on the structure of your data and the desired output, emphasizing that merge is the most versatile for SQL-like operations.

Pro tip: Mention that join is essentially a convenience wrapper around merge that defaults to index-based joining, and that concat can handle both row and column binding but does not align on keys—this shows deep understanding and helps avoid common pitfalls.

1. Define merge

Explain that merge combines DataFrames based on common columns or indices, similar to SQL joins, and supports various join types (inner, outer, left, right).

2. Define join

Describe join as a method that combines DataFrames based on their indices by default, with an optional 'on' parameter for column-based joins, and is a convenient shortcut for index-based merging.

3. Define concat

Explain that concat stacks DataFrames along a particular axis (rows or columns) without aligning on keys, useful for appending or adding columns when indices are already aligned.

4. Compare use cases

Highlight when to use each: merge for complex column-based joins, join for quick index-based joins, and concat for simple stacking or appending operations.

5. Summarize with a practical example

Provide a brief example scenario (e.g., combining customer and transaction data) to illustrate the choice between these functions.

Key Points to Mention

  • merge is the most flexible and SQL-like, allowing joins on multiple columns and different join types.
  • join is a method that defaults to index-based joining and is essentially a wrapper around merge.
  • concat is for stacking DataFrames along an axis and does not perform key-based alignment.
  • Use merge when you need to combine data based on common columns or complex conditions.
  • Use join when your DataFrames have meaningful indices and you want a quick index-based join.
  • Use concat when you need to append rows or add columns without key matching, such as combining monthly data.

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