Find the characters common to two strings
Coding problemEasy-MediumAsked in: Capgemini, Infosys
Given two strings a and b, return a string of the characters that appear in both. List each such character once, in the order it first appears in a.
Ignore spaces. Upper and lower case are different characters. If no character is shared, return an empty string.
Examples
Example 1
Input: a = "hello", b = "world"
Output: "lo"
Example 2
Input: a = "Apple", b = "apple"
Output: "ple"
A and a are different characters.
Example 3
Input: a = "abc", b = "xyz"
Output: ""
Constraints
- The length of a and of b is between 0 and 100,000
- Both hold printable ASCII characters only
Run checks the 3 examples. Submit also runs the hidden tests: edge cases, large inputs and a time limit.
Run your code to see the results here. Ctrl or Cmd + Enter runs; add Shift to submit.