FastPrepReverse and Format a Sentence
Problems/Reverse and Format a Sentence

Reverse and Format a Sentence

JP Morgan Chase logoJP Morgan Chase● EasyINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a JP Morgan Chase intern online assessment. The author reports returning a sentence with the words reversed, an uppercase first letter and a final full stop. We chose the spacing, optional punctuation in the input, what to do with empty input, the limits and the test data. Our version is about 95% the same as the report.

Return a new sentence with its words in reverse order. Uppercase the first letter of the result and end it with one period.

For this exercise, a word is a nonempty run of English letters. Ignore an optional period at the end of the input, remove outer spaces, and put one space between output words. Keep all other letter case unchanged. If there are no words, return ".".

Function

reverseSentence(sentence: String) → String

Examples

Example 1

sentence = "hello world"return = "World hello."

Reverse hello and world, uppercase the new first letter and append one period.

Example 2

sentence = "  I   like Java.  "return = "Java like I."

Remove the original final period and extra spaces, reverse the three words and keep the other letter case.

Constraints

  • For this exercise, assume 0 <= sentence.length <= 10000.
  • The input contains English letters A-Z and a-z, ordinary spaces, and at most one period.
  • If present, the period is the last non-space character.

More JP Morgan Chase Online Assessment questions

  • Find Total CostOA · Seen Oct 2026
  • Minimum Meeting RoomsOA · Seen Oct 2026
  • Count Dropped RequestsOA · Seen Oct 2026
  • Maximize Minimum Deployment DifficultyOA · Seen Oct 2026
  • Task SchedulingOA · Seen Oct 2026
  • Substring RemovalOA · Seen Oct 2026
  • Maximum Game Board ScoreOA · Seen Sep 2026
  • Minimum Digit Changes Between String HalvesOA · Seen Sep 2026
  • Same Substring Within BudgetOA · Seen Sep 2026
  • Invert Ad Visibility BitsOA · Seen Aug 2026

Similar questions at other companies

  • Count User Mentions in Chat MessagesRamp · OARamp interview questions
  • First Non-Repeating CharacterAmazon · OA · ONSITE INTERVIEW
  • Maximum Ones After K OperationsGoldman Sachs · OAGoldman Sachs interview questions
  • Total Each Letter's Count in an Encoded StringIBM · OAIBM interview questions
  • Find Words That Can Be Formed by CharactersTabaPay · OA
  • Blood Type Inheritance: Possible Parent GenotypesAbridge · OAAbridge interview questions
  • Count Palindrome Addition ChoicesThe D.E. Shaw Group · OAThe D.E. Shaw Group interview questions
  • Count Palindrome Addition ChoicesHudson River Trading · OAHudson River Trading interview questions
  • Count Phrases Formed by Anagram ReplacementWells Fargo · OAWells Fargo interview questions
  • Count Substrings With Identical CharactersVirtu Financial · OAVirtu Financial interview questions

Interview reports that mention this question

  • JPMorgan Tech Intern Interviews: 43 Experiences (Part 1 of 5)

JP Morgan Chase interview experiences

  • JPMorgan Quant Stats Superdays: 3 Experiences (Part 3 of 3)
  • JPMorgan Quant Modeling Superdays: 7 Experiences (Part 2 of 3)
  • JPMorgan Quant Intern Superday: 19 Experiences (Part 1 of 3)
  • JP Morgan Chase Data and AI Intern Superday: 11 Experiences
  • JPMorgan Code for Good India 2024: 6 Experiences (Part 5 of 5)
All JP Morgan Chase interview questionsSee JP Morgan Chase hiring insights
Saved
class Solution {
    public String reverseSentence(String sentence) {
        // Write your code here.
    }
}
Checking account…