Solve string and hashmap interview tasks
Problem 1: First Non-Repeating Character
Given a string s, identify and return the first character that appears exactly once within the string. If no such character exists, return an empty string or a special marker like null.
Input
s: A string.
Output
- The first non-repeating character, or an empty marker if none exists.
Constraints
- The length of
swill be between 1 and 10^5 characters, inclusive (1 <= len(s) <= 10^5). sis assumed to contain ASCII letters unless specified otherwise.
Problem 2: Best Average Score
You are provided with a list of score records. Each record is a pair containing a name (string) and a score (integer).
Your task is to calculate the average score for each unique person and then return the highest average score found among all individuals.
Assumptions
- A person's name may appear multiple times in the records; their average score is the mean of all their recorded scores.
- You can assume that each person will have at least one score record.
Deliverable
- Specify how you handle rounding for average scores (e.g., return a floating-point number, or an exact rational/decimal representation).
Input
records: A list of(name, score)tuples.
Output
- The maximum average score across all names.
Constraints
- The length of
recordswill be between 1 and 10^5 entries, inclusive (1 <= len(records) <= 10^5). - Scores can be negative or positive integers. State any assumptions if you restrict the score range.
AI interview prep
Core dilemma
Optimizing for both time and space complexity when processing sequential data (string characters) and aggregated data (scores), while correctly handling edge cases, data types, and potential precision issues.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Solve string and hashmap interview tasks
Problem 1: First Non-Repeating Character
Given a string s, identify and return the first character that appears exactly once within the string. If no such character exists, return an empty string or a special marker like null.
Input
s: A string.
Output
- The first non-repeating character, or an empty marker if none exists.
Constraints
- The length of
swill be between 1 and 10^5 characters, inclusive (1 <= len(s) <= 10^5). sis assumed to contain ASCII letters unless specified otherwise.
Problem 2: Best Average Score
You are provided with a list of score records. Each record is a pair containing a name (string) and a score (integer).
Your task is to calculate the average score for each unique person and then return the highest average score found among all individuals.
Assumptions
- A person's name may appear multiple times in the records; their average score is the mean of all their recorded scores.
- You can assume that each person will have at least one score record.
Deliverable
- Specify how you handle rounding for average scores (e.g., return a floating-point number, or an exact rational/decimal representation).
Input
records: A list of(name, score)tuples.
Output
- The maximum average score across all names.
Constraints
- The length of
recordswill be between 1 and 10^5 entries, inclusive (1 <= len(records) <= 10^5). - Scores can be negative or positive integers. State any assumptions if you restrict the score range.