PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This prompt evaluates algorithmic problem-solving skills focused on combinatorial search and backtracking, including handling duplicate values, index distinctness, and enforcing character-uniqueness constraints across concatenated subsets.

  • hard
  • Meta
  • Coding & Algorithms
  • Software Engineer

Solve Two Backtracking Array Problems

Company: Meta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Technical Screen

You will solve two independent coding problems. For each problem, first discuss edge cases, then implement a correct solution, and finally explain how you would optimize it. ### Problem 1: Find Three Cards Summing to 15 You are given a list of integer card values. Return the indices of any three distinct cards whose values sum to exactly `15`. If no such three cards exist, return an empty result. Requirements: - Each card may be used at most once. - The input may contain duplicate values. - The returned indices must be distinct. - Discuss a brute-force approach and an optimized approach. Example: ```text cards = [2, 7, 4, 8, 6, 1] ``` A valid answer is indices for values `7 + 6 + 2 = 15`. ### Problem 2: Maximize Unique Characters from a Word List You are given a list of lowercase words. Choose any subset of the words and concatenate them in any order. The final concatenated string must contain no repeated characters. Return the maximum possible length of such a concatenation. Requirements: - A word that contains duplicate characters internally cannot be used. - Each word may be chosen at most once. - Return only the maximum length, not the actual subset. - Discuss a straightforward backtracking solution and at least one optimization. Example: ```text words = ["ab", "cd", "aef", "gh"] ``` One valid choice is `"cd" + "aef" + "gh"`, which has length `7` and all unique characters.

Quick Answer: This prompt evaluates algorithmic problem-solving skills focused on combinatorial search and backtracking, including handling duplicate values, index distinctness, and enforcing character-uniqueness constraints across concatenated subsets.

Part 1: Find Three Cards Summing to 15

Given a list of integer card values, return the indices of three distinct cards whose values add up to exactly `15`. If multiple valid triples exist, return the lexicographically smallest triple of indices in increasing order. If no such triple exists, return an empty list. A brute-force approach checks every triple of indices in `O(n^3)`. A better solution should improve on that.

Constraints

  • `0 <= len(cards) <= 2000`
  • `-10^9 <= cards[i] <= 10^9`
  • Indices in the answer must be distinct
  • Duplicate card values may appear

Examples

Input: ([2, 7, 4, 8, 6, 1],)

Expected Output: [0, 1, 4]

Explanation: Values at indices 0, 1, and 4 are 2, 7, and 6, which sum to 15.

Input: ([5, 5, 5, 5],)

Expected Output: [0, 1, 2]

Explanation: There are multiple valid triples, so return the lexicographically smallest one.

Input: ([20, -5, 0, 5, 10],)

Expected Output: [0, 1, 2]

Explanation: 20 + (-5) + 0 = 15.

Input: ([1, 2, 3, 4],)

Expected Output: []

Explanation: No three values sum to 15.

Input: ([15],)

Expected Output: []

Explanation: Edge case: fewer than three cards.

Hints

  1. Try fixing the first two indices and asking what third value is needed to reach 15.
  2. To make the answer deterministic, scan `i` and `j` from left to right and choose the earliest valid `k > j`.

Part 2: Maximize Unique Characters from a Word List

You are given a list of lowercase words. Choose any subset of the words and concatenate them in any order so that the final string contains no repeated characters. Return the maximum possible length of such a concatenation. A word that contains duplicate characters internally cannot be used at all. A straightforward solution uses backtracking over subsets. An optimized solution can represent each word as a bitmask and prune impossible branches.

Constraints

  • `0 <= len(words) <= 16`
  • `1 <= len(words[i]) <= 26`
  • `words[i]` contains only lowercase English letters

Examples

Input: (['ab', 'cd', 'aef', 'gh'],)

Expected Output: 7

Explanation: One best choice is 'cd' + 'aef' + 'gh', which has length 7 and all unique characters.

Input: ([],)

Expected Output: 0

Explanation: Edge case: choosing nothing gives length 0.

Input: (['aa', 'bc', 'def'],)

Expected Output: 5

Explanation: The word 'aa' is invalid because it repeats a character internally, so the best is 'bc' + 'def'.

Input: (['ab', 'bc', 'cd'],)

Expected Output: 4

Explanation: You cannot use 'ab' and 'bc' together, but 'ab' + 'cd' is valid and has length 4.

Input: (['abcdefghijklmnopqrstuvwxyz', 'ab', 'cd'],)

Expected Output: 26

Explanation: The single 26-letter word already uses every lowercase letter exactly once.

Hints

  1. First discard any word that already contains a repeated character inside itself.
  2. Represent each valid word as a 26-bit mask so overlap checks become very fast.
Last updated: Jun 13, 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
  • 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

  • Compute Exclusive Execution Times - Meta (medium)
  • Solve Tree Columns And Maze Variants - Meta (medium)
  • Solve Tree Diameter and Palindromic Counts - Meta (medium)
  • Simulate Monster Team Battles - Meta (hard)
  • Solve a Key-Door Corridor Maze - Meta (medium)