PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

Practice a Bytedance coding interview problem focused on find the best word for a query suffix. The prompt emphasizes edge cases, clean implementation, and verifiable test behavior without revealing the solution.

  • hard
  • Bytedance
  • Coding & Algorithms
  • Software Engineer

Find the Best Word for a Query Suffix

Company: Bytedance

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Technical Screen

Given dictionary words and query strings, return for each query the dictionary word with the longest common suffix. Ties go to the shortest word, then lexicographically smallest. Implement: ```python def best_suffix_matches(words: list[str], queries: list[str]) -> list[str]: pass ```

Quick Answer: Practice a Bytedance coding interview problem focused on find the best word for a query suffix. The prompt emphasizes edge cases, clean implementation, and verifiable test behavior without revealing the solution.

For each query, return the word with longest common suffix, then shortest length, then lexicographically smallest.

Examples

Input: {"words":["time","me","bell"],"queries":["mime"]}

Expected Output: ["time"]

Explanation: Tie suffix length, shorter wins.

Input: {"words":["abc","xbc","zz"],"queries":["qbc"]}

Expected Output: ["abc"]

Explanation: Tie length and size, lexicographic.

Input: {"words":["a","b"],"queries":["x"]}

Expected Output: ["a"]

Explanation: No suffix tie.

Input: {"words":[],"queries":["x"]}

Expected Output: [""]

Explanation: No words.

Input: {"words":["running","jogging","king"],"queries":["sing"]}

Expected Output: ["king"]

Explanation: Longest suffix ing.

Input: {"words":["hello"],"queries":["hello"]}

Expected Output: ["hello"]

Explanation: Exact.

Input: {"words":["car","bar","far"],"queries":["star","zz"]}

Expected Output: ["bar","bar"]

Explanation: First by lexicographic when tied.

Input: {"words":["abcd","bcd","cd"],"queries":["xxcd"]}

Expected Output: ["cd"]

Explanation: Shortest among equal suffix.

Last updated: Jul 4, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,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
  • 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.

Related Coding Questions

  • Elements Occurring More Than n/3 Times in a Sorted Array - Bytedance (medium)
  • Least Frequently Used (LFU) Cache - Bytedance (hard)
  • Course Schedule Feasibility - Bytedance (hard)
  • Reverse a Singly Linked List - Bytedance (medium)
  • Reverse Nodes in Groups of K - Bytedance (medium)