By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,045 Members | 1,743 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,045 IT Pros & Developers. It's quick & easy.

How to print largest even number in given string?

aveeva
P: 27
String: NodeJs is one of the best technology

NodeJs 6

is 2

one 3

of 2

the 3

best 4

technology 10

From above, how to print technology which largest even number.

How to print the largest even number?
1 Week Ago #1
Share this Question
Share on Google+
1 Reply


dev7060
P: 77
One algo could be:

- Store each word in an array and do condition checks. A word can be stored by pushing characters into an array until a space is found.

- Declare a var max and arr_max (an array) in the beginning (outside of loop body and everything) and set its size equal to the length of the first word and copy the word to arr_max intially. Then on each iteration, condition checks can be used like if the length is even and max < length, assign the value of new length to max and save the current word to arr_max.

- After the loop body, output max and arr_max.
1 Week Ago #2

Post your reply

Sign in to post your reply or Sign up for a free account.