FastPrepEncrypt Letters by First-Occurrence Substitution
Problems/Encrypt Letters by First-Occurrence Substitution

Encrypt Letters by First-Occurrence Substitution

Palantir logoPalantir● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The reported first-occurrence substitution encryption matches at about 85%, including case-insensitive mapping identities with case preserved. Its dash-pair direction and ignore-nonletters wording are ambiguous. Plaintext-first ranking, omission of nonletters, encryption of every repeated occurrence and finite ASCII bounds are explicitly chosen practice interpretations.

For this exercise, encrypt the letters of text with a first-occurrence substitution. The first different letter you encounter maps to a, the next new letter to b, and so on. Treat uppercase and lowercase versions as the same letter when assigning a mapping.

Encrypt every letter occurrence with its assigned alphabet rank and preserve that occurrence's case. For example, a letter assigned rank zero becomes a when lowercase and A when uppercase.

In this exercise, remove nonletters from the output and do not assign them a mapping. Return an empty string when the input contains no letters.

Function

encryptSubstitution(text: String) → String

Examples

Example 1

text = "bkmw"return = "abcd"

The letter order b, k, m, w becomes a, b, c, d under the first-occurrence mapping.

Example 2

text = "B!bK-k4M"return = "AaBbC"

The same letter identity has one rank in either case; punctuation and digits are omitted.

Constraints

  • For this exercise, assume 0 <= text.length <= 500.
  • Input consists of printable ASCII characters with codes 32 through 126. Only A through Z and a through z are letters.

More Palantir interview questions

  • Balanced Session ManagerPHONE SCREEN · Seen Nov 2026
  • Query Words Within K PositionsPHONE SCREEN · Seen Nov 2026
  • Employees With Shared InterestsPHONE SCREEN · Seen Jul 2025
  • Merge a 2048 RowPHONE SCREEN · Seen Jan 2025
  • Encrypt Text by Columnar TranspositionPHONE SCREEN · Seen Aug 2022
  • Basic Item DiscountsOA · Seen Nov 2026
  • Optimize Discount Selection Under a Point BudgetOA · Seen Nov 2026
  • Stacked Item and Category DiscountsOA · Seen Nov 2026
  • Map and Accumulate Learning QueriesONSITE INTERVIEW · Seen Oct 2026
  • Relational Learning QueriesONSITE INTERVIEW · Seen Apr 2025

Similar questions at other companies

  • Dasher Pay with Store Waits and Peak HoursDoorDash · PHONE SCREENDoorDash interview questions
  • Invoice / Payment ReconciliationStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions
  • Classify Password StrengthHackerRank · OA · PHONE SCREEN · ONSITE INTERVIEWHackerRank interview questions
  • Route Pattern MatcherGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
  • Fuzzy Word Lookup With One Misspelled LetterMeta · PHONE SCREENMeta interview questions
  • Most Frequent Call Path From Function Trace LogsRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
  • Group Timestamps into Consecutive-Day IntervalsDuolingo · PHONE SCREENDuolingo interview questions
  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • Longest Substring Without Repeating CharactersAngel One · PHONE SCREEN

Palantir interview experiences

  • Palantir SWE New Grad - Gotham
  • Palantir FDSE Experienced-Hire Interviews: 5 Experiences
  • Palantir FDSE New Grad OA Questions: 6 Experiences (Part 2 of 2)
  • Palantir FDSE New Grad Interviews: 5 Experiences (Part 1 of 2)
  • Palantir FDSE Intern OA and Interviews: 3 Experiences
  • Palantir FDSE Karat and Learning: 7 Experiences (Part 2 of 2)
All Palantir interview questionsSee Palantir hiring insights
Saved
class Solution {
    public String encryptSubstitution(String text) {
        // Write your code here.
        return "";
    }
}
Checking account…