LeetCode Solution | 1859: Sorting the Sentence

LeetCode | 31 May, 2021

Problem Description:


We have to rearrange a given sentence ‘s’. Words of this sentence are separated by spaces. Each word contains a number at the end which indicates the position where the word should be placed to arrange the sentence.


Constraints:


  • 2 <= s.length <= 200
  • s consists of lowercase and uppercase English letters, spaces, and digits from 1 to 9.
  • The number of words in s is between 1 and 9.
  • The words in s are separated by a single space.
  • s contains no leading or trailing spaces.


Ideological Analysis:


We have to check the last element of every word. Then we’ll sort them according to the number given at the end of the word and remove the last element of each word.


Click here for Source Code.

Tanjina Rahman, 31 May, 2021


Share this article on →