PracHub
QuestionsLearningGuidesInterview Prep
|Home/Coding & Algorithms/Upstart

Count Words in Lexicographic Order

Last updated: Jul 28, 2026

Quick Overview

Count repeated lowercase words and return the distinct words with their frequencies in lexicographic order. Preserve the input while analyzing large collections, many duplicates, time and space costs, streaming limits, locale-aware ordering, and frequency-based extensions.

  • medium
  • Upstart
  • Coding & Algorithms
  • Software Engineer

Count Words in Lexicographic Order

Company: Upstart

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Take-home Project

# Count Words in Lexicographic Order Implement `word_counts(words)` for a list of lowercase words. Return a list of `(word, count)` pairs sorted in ascending lexicographic order by word. ## Constraints - `0 <= len(words) <= 200000` - Every word contains one to fifty lowercase English letters. - The input list may contain many duplicates and must not be mutated. ## Example `["pear", "apple", "pear", "banana", "apple"]` returns `[("apple", 2), ("banana", 1), ("pear", 2)]`. ## Clarifications Comparison is case-sensitive, but inputs are already lowercase. State the time and space complexity in terms of the number of words and distinct words. ## Hints Separate frequency aggregation from ordering the distinct keys. ## Extensions - Stream input too large to fit in memory. - Sort under locale-aware collation. - Return the most frequent words with lexicographic tie-breaking.

Quick Answer: Count repeated lowercase words and return the distinct words with their frequencies in lexicographic order. Preserve the input while analyzing large collections, many duplicates, time and space costs, streaming limits, locale-aware ordering, and frequency-based extensions.

Related Interview Questions

  • Sum Multiples of Three, Five, or Seven - Upstart (medium)
  • Find the Minimum Absolute Difference - Upstart (medium)
  • Add Dramatic Punctuation to Text - Upstart (medium)
  • Interleave Three Equal-Length Strings - Upstart (easy)
|Home/Coding & Algorithms/Upstart

Count Words in Lexicographic Order

Upstart logo
Upstart
Jul 27, 2026, 12:00 AM
mediumSoftware EngineerTake-home ProjectCoding & Algorithms
0
0

Count Words in Lexicographic Order

Implement word_counts(words) for a list of lowercase words. Return a list of (word, count) pairs sorted in ascending lexicographic order by word.

Constraints

  • 0 <= len(words) <= 200000
  • Every word contains one to fifty lowercase English letters.
  • The input list may contain many duplicates and must not be mutated.

Example

["pear", "apple", "pear", "banana", "apple"] returns [("apple", 2), ("banana", 1), ("pear", 2)].

Clarifications

Comparison is case-sensitive, but inputs are already lowercase. State the time and space complexity in terms of the number of words and distinct words.

Hints

Separate frequency aggregation from ordering the distinct keys.

Extensions

  • Stream input too large to fit in memory.
  • Sort under locale-aware collation.
  • Return the most frequent words with lexicographic tie-breaking.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Upstart•More Software Engineer•Upstart Software Engineer•Upstart Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

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

Product

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

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding 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.