Problem · String

Remove Duplicate Characters

Learn this problem
EasyNatWest GroupOA

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

drafts saved locally
public String removeDuplicateCharacters(String s) {
  // write your code here
}
s"banana"
expected"ban"
checking account