Leetcode 1859. Sorting the Sentence || Biweekly Contest 52 problem 1 || Code + Explanation + Example
Vložit
- čas přidán 14. 05. 2021
- 1859. Sorting the Sentence
Difficulty:Easy
A sentence is a list of words that are separated by a single space with no leading or trailing spaces. Each word consists of lowercase and uppercase English letters.
A sentence can be shuffled by appending the 1-indexed word position to each word then rearranging the words in the sentence.
For example, the sentence "This is a sentence" can be shuffled as "sentence4 a3 is2 This1" or "is2 sentence4 This1 a3".
Given a shuffled sentence s containing no more than 9 words, reconstruct and return the original sentence.
Example 1:
Input: s = "is2 sentence4 This1 a3"
Output: "This is a sentence"
Explanation: Sort the words in s to their original positions "This1 is2 a3 sentence4", then remove the numbers.
Example 2:
Input: s = "Myself2 Me1 I4 and3"
Output: "Me Myself and I"
Explanation: Sort the words in s to their original positions "Me1 Myself2 and3 I4", then remove the numbers.
osm explanation of the question keep it up...
Thank you so much .. i was stuck in this problem from past 2 hrs but you made it so easy!
clear cut 6min solution
love it! Thanks!
Thanks for the explanation, I understood all of it.
best explanation of this ques and easily understandable
You have earned a huge respect from me.
Crystal clear explanation. Keep up with this work Didi.
Thank u so much. U cleared my doubt.
That is a smart solution
🙂Thanks
awesome explanation.
crystal clear explanation
ky baat h ye hoti h approach
m pagal ho gya leetcode p decsion dekhke itne khtrnak syntax likhe hue h
koi map use krra h koi set
really nice
very good explanation...
best explanation.
Thanks a lot...
thank you so much mam
Tq so much 💖💓
really amazing
very nice !
Will u be uploading the others questions also...
thank u
nice explaination maam but maam instead of substracting with 48 we can substract it by 49 in order to to get 0th index otherwise 0th index will remain empty in vector
Job ke liye best of luck mam
why we need to specify size of vector...it's automatic take it..
why did we declare the vector size 10 for 9 elements, please?
Because index are from 0 in a vector
awesome explanation.