FastPrepRemove Repeated Letters in First-occurrence Order
Problems/Remove Repeated Letters in First-occurrence Order

Remove Repeated Letters in First-occurrence Order

AMD logoAMD● EasyINTERNONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report supplies MALAYALAM → MALY and a no-dictionary follow-up. The uppercase alphabet, empty case, bounds and callable interface are authored for practice; approximate source match 95%.

Keep only the first occurrence of every letter in s, preserving the original order. Return the resulting string.

For example, MALAYALAM becomes MALY. Do not sort the letters or choose a different subsequence. As a follow-up, solve this without a dictionary or hash map.

Function

removeDuplicateLetters(s: String) → String

Examples

Example 1

s = "MALAYALAM"return = "MALY"

The first M, A, L and Y occur at indices 0, 1, 2 and 4. Every later character has already appeared.

Example 2

s = "BANANA"return = "BAN"

Keep B at index 0, A at index 1 and N at index 2; skip the remaining repeats.

Constraints

  • 0 <= s.length <= 2000.
  • s contains only uppercase English letters A through Z.

More AMD problems

  • Insert After a Linked-List NodeONSITE INTERVIEW · Seen Oct 2026
  • LRU CacheONSITE INTERVIEW · Seen Oct 2026
  • Lowest Common Ancestor of a Binary TreePHONE SCREEN · Seen Oct 2026
All AMD interview questionsSee AMD hiring insights
Saved
public String removeDuplicateLetters(String s) {
    // Write your code here.
}
Checking account…