Lunatic Server Solutions Interview Question for Developer Program Engineers
- 0of 0 votes
Answerson last interview lunatic server solution asked 3 questions. one of them was very easy. the problem states that...
- PriyaDarad June 06, 2012 in United States
Given a stream of text, your task is to create a formatted paragraph out of it. The paragraph should be left justified and each line of text in the formatted paragraph should not exceed a given length. Each line should contain maximum possible characters.
In addition to the input text, a set of words with their possible hyphen positions will also be given. The hyphenation makes it possible sometimes to add incomplete words at the end of line, if the completed words overflow the line length limit. To indicate that this particular word is incomplete, a hyphen (-) is added at the end of such broken words. Remaining part of this word is placed at the beginning of the next line. The specified line length limit must be observed including the trailing hyphen character if any.
The input text will contain alphabets, digits, punctuation marks and spaces. The only white space character used is a blank space, which is used to separate words. Each line in a formatted paragraph begins with a non-blank character. Even if the input text has words separated by many spaces, your output should separate them by only single space or a line break.
Notes:
The list of hyphenated words will not include any punctuation marks that may occur in the text to be formatted. You may assume that the punctuation marks will occur only at the end of each word (alpha-numeric characters). That is there will not be words like They'll or Sita's anywhere in the input.
The word length will never exceed the line length limit.
The input text can always be formatted using the given constraints.
No word, hyphenated or otherwise will exceed a length of 20 characters.
Input specification:
First line has an integer n denoting the number of hyphenated words.
Next n lines give each of the hyphenated word with possible hyphen break positions in the word by a hyphen itself. For example, "hyphenate" is given as "hy-phen-ate" and "formatting" is given as "for-mat-ting".
Next line will be an integer denoting the maximum number of characters per line in the formatted paragraph, i.e., the line length limit.
Last line contains the text to be formatted into a paragraph. The entire text will be terminated by a new line. The length of text will not exceed 256 characters.
Output specification:
The output should be a sequence of characters, which begin each line of the formatted paragraph followed by a single new line character. Thus, there will be those many non-white space characters as there are lines in the formatted paragraph.
Sample Input and Output:
Input:
4
con-cept
pro-gram-ming
ob-vi-ous
im-pos-si-ble
25
Most people find the concept of programming obvious, but the doing impossible.
Output:
Mcos
Note : Candidate can not get characters of indices, which are multiple of 24.
you have to make program in java with proper coding and follow the problem statement.| Report Duplicate | Flag | PURGE
Lunatic Server Solutions Developer Program Engineer Java
Interview Type: Written Test