Do you need to remember what the counts were? Can the count be tested as each word is processed and the smallest value saved at that time?
Otherwise the logic looks reasonable. The Third step...
Type: Posts; User: Norm
Do you need to remember what the counts were? Can the count be tested as each word is processed and the smallest value saved at that time?
Otherwise the logic looks reasonable. The Third step...
Design the program before trying to write code for it.
Explain what steps need to be taken to solve the problem.
First step would be to have a loop that looks at each word one at a time
Then what?...
Ok, work out the logic for that.
Compare two words, save the smallest. Look at next word and compare its length against the smallest so far, save the smallest. Continue until at end of list of...
What does the code do now?
How do you want to change what it does?
What is the desired output?
The contents of the res array is initially null. This statement concatenates the new words to its current contents:
res[pos] += nWord; // adds new word to end of existing value
...