CHALLENGE : Find the longest word in a sentence. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

CHALLENGE : Find the longest word in a sentence.

For example - INPUT :- I am a programmer OUTPUT :- programmer Any language is welcome...

6th Oct 2017, 1:47 PM
Aman Ansari
Aman Ansari - avatar
24 Answers
+ 11
JavaScript: alert(prompt("").split(" ").reduce(function(a, b) { return b.length < a.length ? a : b; }, ""));
6th Oct 2017, 4:34 PM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 9
What happenz if input is "Hello world"?
6th Oct 2017, 1:50 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 5
Question: If several words are the same length, which one must be returned? All of them? First one? 🤔
6th Oct 2017, 9:19 PM
noobcøder
noobcøder - avatar
6th Oct 2017, 2:04 PM
Kartikey Sahu
Kartikey Sahu - avatar
7th Oct 2017, 5:58 AM
noobcøder
noobcøder - avatar
+ 3
Yes
6th Oct 2017, 1:49 PM
Aman Ansari
Aman Ansari - avatar
7th Oct 2017, 6:11 AM
Ferhat Sevim
Ferhat Sevim - avatar
+ 2
Words are any sequences of any characters right?
6th Oct 2017, 1:48 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 2
my practice on python https://code.sololearn.com/ciwnB5loDoBo/#py tested with: "am i a programmer? subvocalize" output: subvocalize
6th Oct 2017, 9:12 PM
ysraelcon
ysraelcon - avatar
6th Oct 2017, 11:46 PM
---
--- - avatar
7th Oct 2017, 8:21 AM
Hiroki Masuda
Hiroki Masuda - avatar
+ 1
Find all longest words with filter , ; [ ] : " ' https://code.sololearn.com/WRv4AZ9A7EQQ/?ref=app
6th Oct 2017, 2:21 PM
Calviղ
Calviղ - avatar
+ 1
I returned a list of all the words of the longest length (so if input is "Hello World" it would return ["Hello", "World"]. So, here's my try: https://code.sololearn.com/cX381CeM75hr/?ref=app
6th Oct 2017, 10:46 PM
blackcat1111
blackcat1111 - avatar
7th Oct 2017, 6:56 PM
m_sudhu
m_sudhu - avatar
9th Oct 2017, 9:41 PM
Luis Lopes
Luis Lopes - avatar
0
I think both words should be outputted then... Or what do u think..??
6th Oct 2017, 1:55 PM
Aman Ansari
Aman Ansari - avatar
0
@venkat can you please tell me how to limit the input for an integer type in python
6th Oct 2017, 1:59 PM
Dewansh Raj
0
Perl: print [(sort{length($b)<=>length($a)} split(/\s/,'The longest word will print'))]->[0]; Output: longest
6th Oct 2017, 3:10 PM
Mauricio Lairet
Mauricio Lairet - avatar
0
https://code.sololearn.com/cqqHHWI9Kh8o/?ref=app prints longest words in a sentence
6th Oct 2017, 4:06 PM
Dark0d3
Dark0d3 - avatar