Over a million developers have joined DZone.

Thursday Code Puzzler: Sentence Spacer

DZone 's Guide to

Thursday Code Puzzler: Sentence Spacer

· Java Zone ·
Free Resource

t's Thursday, so it's time for another code puzzler. The idea is simple: solve the coding problem as efficiently as you can, in any language or framework that you find suitable.

Note: Even though there really is nothing stopping you from finding a solution to this on the internet, try to keep honest, and come up with your own answer.  It's all about the participation!

Build up A Sentence From A Word Without Spaces 

Create a method that will take a string parameter with no spaces, and adds spaces in appropriate places to create a sentence. You can assume a dictionary of words is provided. 

Example input could be 'dzonepublishcodepuzzlerseverythursday' which would produce 'dzone publish code puzzlers every thursday'.

Keep in mind that, although you can take a simple approach, it would be cool if: 

  • Your solution realises that multiples (i.e. trailing 's') would probably not be in the dictionary 
  • Logic could be added to determine if the generated sentence makes sense or not.

Catch up on all our previous puzzlers here


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}