This is a verified interview question from Microsoft. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Python Data Science: Top Employee Across Branches - Microsoft Online Assessment Data Science Role IIT BHU" covers key patterns like Arrays.
"**Mode**: On-Campus **Exam Pattern**: 1 DSA + 1 Python Data Science - 60mins **OA Date**: 2026-10-15 DSA: https://www.codinzhub.com/question/dsa-minimum-operations-to-equalize-prices-microsoft-online-assessment-iit-bhu # Top Employee Across Branches > **Language:** Python 3 · **Library:** pandas · **Function:** `topEmp(df)` ## Problem Statement Given data of employee sales across different sales branches as a pandas dataframe, find the employee who has the highest total sales across all branches. ### Notes - There may be multiple sales by an employee for the same branch. They should be summed up. - If sales are missing for a particular branch for an employee, assumed sales are `0`. - If no such employee exists, return an empty dataframe with a header. - There is at most 1 employee with the highest sales across branches. ## Input The dataframe consists of three columns: | Column | Description | |---------------|-------------------------------------| | `emp_id` | Employee ID | | `branch_code` | Unique identifier for each branch | | `sales` | Sales amounts | ## Example Consider the following dataframe: | emp_id | branch_code | sales | |:------:|:-----------:|:-----:| | 1 | b01 | 100 | | 1 | b01 | 200 | | 1 | b02 | 50 | | 2 | b01 | 150 | | 2 | b02 | 10 | | 2 | b02 | 20 | The dataframe after performing the steps is: | emp_id | |:------:| | 1 | ## Function Description Complete the function `topEmp` in the editor below. `topEmp` has the following parameter(s): - `df`: a pandas dataframe ### Returns - `pandas dataframe`: the results of processing ## Constraints - 1 ≤ number of rows in `df` ≤ 1000 ## Input Format For Custom Testing A CSV file that describes the dataframe. ## Sample Case 0 ### Sample Input For Custom Testing ```csv emp_id,branch_code,sales 1,b01,113 1,b01,126 1,b02,108 2,b01,178 ``` ### Sample Output ``` emp_id 1 ``` ### Explanation Employee 1 has total sales of 239 in branch b01 and 108 in b02 whereas employee 2 has sales of 178 and no sales in branch b02. ## Sample Case 1 ### Sample Input For Custom Testing ```csv emp_id,branch_code,sales 1,b01,193 1,b02,151 1,b02,195 2,b01,114 2,b01,122 2,b01,128 2,b02,103 2,b02,142 ``` ### Sample Output ``` emp_id ``` ### Explanation Employee 1 has total sales of 193 in b01 and 346 in b02. Employee 2 has total sales ... > The rest of this explanation was cut off in the original screenshot. ## Starter Code ```python #!/usr/bin/python3 # Complete the 'topEmp' function below. # # The function is expected to return a pandas dataframe. # def topEmp(df): # Write your code here ```"
Join thousands of developers practicing for Microsoft.