FastPrepRemove Duplicate Characters
Problems/Remove Duplicate Characters

Remove Duplicate Characters

NatWest Group logoNatWest Group● EasyOA
QuestionFunctionExamples

Problem statement

You are given a string s. Remove duplicate characters while preserving the order of their first occurrence, and return the resulting string.

Function

removeDuplicateCharacters(s: String) → String

Examples

Example 1

s = "banana"return = "ban"

The first occurrences are b, a, and n. Later repeated characters are skipped.

The source shared the rule but did not include this exact sample. FastPrep added this small example so the behavior can be checked directly.

More NatWest Group problems

  • Sum Elements at Even IndicesOA · Seen Jul 2026
See NatWest Group hiring insights
Saved
public String removeDuplicateCharacters(String s) {
  // write your code here
}
Checking account…