Find first non-repeating character index
Problem Description
You will be presented with two distinct coding tasks.
Task 1: First Unique Character
Given a string s consisting of lowercase ASCII letters, return the 0-based index of the first character that appears exactly once in the string. If no such character exists, return -1.
Input:
s: A string (lowercase ASCII letters).
Output:
- An integer representing the 0-based index of the first unique character, or
-1if none exists.
Examples:
s = "leetcode"→0(character'l')s = "loveleetcode"→2(character'v')s = "aabb"→-1
Task 2: Highest Average Score
You are provided with a list of student score records. Each record is a pair containing a student_id (string) and a score (integer). A student's student_id may appear multiple times, indicating multiple scores for that student.
Your task is to compute the average score for each student (the mean of all their recorded scores) and then return the maximum average score found among all students. The output should be the highest average value.
Input:
- A list of pairs
[(student_id, score), ...].
Output:
- The highest average score (as a floating-point value or an exact rational).
Example:
Input: [("a", 80), ("b", 90), ("a", 100)]
- Average for 'a' = (80 + 100) / 2 = 90
- Average for 'b' = 90
Output:
90
Clarifications to Discuss:
- How should rounding be handled if an average is not an integer?
- Should ties for the highest average return just the value, or also the corresponding student ID(s)?
AI interview prep
Core dilemma
Efficiently processing sequential data to extract specific statistical properties (first unique character, maximum average) while optimizing for time and space complexity, particularly when dealing with frequency counts and aggregations over potentially large datasets.
3 tradeoffs and 2 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Find first non-repeating character index
Problem Description
You will be presented with two distinct coding tasks.
Task 1: First Unique Character
Given a string s consisting of lowercase ASCII letters, return the 0-based index of the first character that appears exactly once in the string. If no such character exists, return -1.
Input:
s: A string (lowercase ASCII letters).
Output:
- An integer representing the 0-based index of the first unique character, or
-1if none exists.
Examples:
s = "leetcode"→0(character'l')s = "loveleetcode"→2(character'v')s = "aabb"→-1
Task 2: Highest Average Score
You are provided with a list of student score records. Each record is a pair containing a student_id (string) and a score (integer). A student's student_id may appear multiple times, indicating multiple scores for that student.
Your task is to compute the average score for each student (the mean of all their recorded scores) and then return the maximum average score found among all students. The output should be the highest average value.
Input:
- A list of pairs
[(student_id, score), ...].
Output:
- The highest average score (as a floating-point value or an exact rational).
Example:
Input: [("a", 80), ("b", 90), ("a", 100)]
- Average for 'a' = (80 + 100) / 2 = 90
- Average for 'b' = 90
Output:
90
Clarifications to Discuss:
- How should rounding be handled if an average is not an integer?
- Should ties for the highest average return just the value, or also the corresponding student ID(s)?