FastPrepEnglish to Morse Code
Problems/English to Morse Code

English to Morse Code

Oscar Health logoOscar Health● EasyFULLTIMEPHONE SCREEN

Updated Dec 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported from a first backend interview round at Oscar Health in November 2026. It was the first of two coding tasks: turn English text into Morse code. The report names the task only. It gives no code table, no format and no examples.

So the details are ours. We use the standard international code for the 26 letters, treat uppercase and lowercase the same, put one space between letters and a slash with a space on each side between words, and limit the text to 1000 characters. All three examples are ours.

Our version is about 70% the same as the reported question.

Given a string text made of English words separated by single spaces, return text written in Morse code.

Write each letter with its code from the table below. Each code is made of the characters . (dot) and - (dash). Uppercase and lowercase letters use the same code, so A and a are both .-.

  • Inside a word, separate the codes of consecutive letters with one space.
  • Between two words, write a space, a slash and a space: " / ".

The result does not start or end with a space.

International Morse code for the 26 letters
LetterCodeLetterCode
a.-n-.
b-...o---
c-.-.p.--.
d-..q--.-
e.r.-.
f..-.s...
g--.t-
h....u..-
i..v...-
j.---w.--
k-.-x-..-
l.-..y-.--
m--z--..

Function

toMorse(text: String) → String

Examples

Example 1

text = "SOS"return = "... --- ..."

S is ... and O is ---. The three letters form one word, so their codes are separated by single spaces: "... --- ...".

Example 2

text = "Hello World"return = ".... . .-.. .-.. --- / .-- --- .-. .-.. -.."

Hello becomes .... . .-.. .-.. --- and World becomes .-- --- .-. .-.. -... The two words are joined with " / ". Uppercase H and W use the same codes as h and w.

Example 3

text = "I am"return = ".. / .- --"

I is a word of one letter, ... am becomes .- --. Joining the two words gives ".. / .- --".

Constraints

  • 1 <= text.length <= 1000
  • text consists of English letters (a to z and A to Z) and spaces.
  • text does not start or end with a space, and no two spaces are next to each other.

More Oscar Health interview questions

  • All English Decodings of Morse CodePHONE SCREEN · Seen Dec 2026
  • Longest Name Chain in a Directed Acyclic GraphPHONE SCREEN · Seen Sep 2026
  • Members Lacking Provider Network AccessONSITE INTERVIEW · Seen Apr 2026

Similar questions at other companies

  • Transaction Fee Calculator — Parts 1–2: Basic Fee Calculation and Conditional Fee RulesStripe · PHONE SCREENStripe interview questions
  • Run-Length Encoding and DecodingAirbnb · PHONE SCREENAirbnb interview questions
  • Straight-Line Word SearchReddit · PHONE SCREENReddit interview questions
  • Search and Format ContactsAdyen · PHONE SCREENAdyen interview questions
  • Subtract Two Large Number StringsStackAdapt · PHONE SCREENStackAdapt interview questions
  • Valid ParenthesesByteDance · PHONE SCREENByteDance interview questions
  • Detect a Straight FlushTemu · PHONE SCREENTemu interview questions
  • Check if a String Is a PalindromeCisco · PHONE SCREENCisco interview questions
  • Halfway Course in a Single TrackCrunchyroll · PHONE SCREENCrunchyroll interview questions
  • Longest Common PrefixKotak Mahindra Bank · PHONE SCREEN · ONSITE INTERVIEWKotak Mahindra Bank interview questions
See Oscar Health hiring insights
Saved
class Solution {
    public String toMorse(String text) {
      // Write your code here.
    }

}
Checking account…