PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches

Quick Overview

This question evaluates proficiency in string manipulation and frequency counting, including correct handling of tie-breaking by earliest first occurrence and awareness of character-set distinctions.

  • easy
  • SoFi
  • Coding & Algorithms
  • Software Engineer

Find maximum-occurring character in a string

Company: SoFi

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Take-home Project

## Problem Given a non-empty string `s`, return the character that occurs the most times in `s`. ### Tie-breaking If multiple characters have the same maximum frequency, return the one whose **first occurrence index in `s` is smallest**. ### Input - A string `s` (characters are case-sensitive). ### Output - A single character: the maximum-occurring character under the tie-break rule. ### Constraints - `1 <= len(s) <= 2 * 10^5` - `s` may contain any printable ASCII characters (treat each distinct character separately). ### Example - Input: `"abcaac"` - Frequencies: `a=3, c=2, b=1` → Output: `a`

Quick Answer: This question evaluates proficiency in string manipulation and frequency counting, including correct handling of tie-breaking by earliest first occurrence and awareness of character-set distinctions.

Given a non-empty string `s`, return the character that appears the most times in `s`. If multiple characters have the same maximum frequency, return the one whose first occurrence index in `s` is smallest. Treat all characters as distinct, including uppercase vs lowercase letters, digits, spaces, and punctuation.

Constraints

  • 1 <= len(s) <= 2 * 10^5
  • Characters are case-sensitive.
  • Each printable ASCII character should be treated as a distinct character.

Examples

Input: ("abcaac",)

Expected Output: "a"

Explanation: Frequencies are: a=3, c=2, b=1, so the answer is 'a'.

Input: ("abcd",)

Expected Output: "a"

Explanation: All characters appear once, so the tie is broken by earliest first occurrence. 'a' appears first.

Input: ("aAaA",)

Expected Output: "a"

Explanation: The string is case-sensitive: 'a'=2 and 'A'=2. Since 'a' appears first at index 0, return 'a'.

Input: ("x",)

Expected Output: "x"

Explanation: Single-character edge case: the only character is the answer.

Input: ("112233!!",)

Expected Output: "1"

Explanation: Characters '1', '2', '3', and '!' each appear twice. '1' has the smallest first occurrence index.

Input: ("abbbbaaa",)

Expected Output: "a"

Explanation: 'a' appears 4 times and 'b' appears 4 times. Since 'a' first appears at index 0 and 'b' at index 1, return 'a'.

Hints

  1. Use a hash map (dictionary) to count how many times each character appears.
  2. To handle ties correctly, also store the first index where each character appears.
Last updated: May 10, 2026

Loading coding console...

PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Find Smallest Common Row Value - SoFi (easy)
  • Format words into wrapped/justified lines - SoFi (medium)
  • Find the second most frequent tag - SoFi (medium)
  • Implement a multithreaded task executor with semaphores - SoFi (medium)
  • Implement chance of a personal best - SoFi (hard)