![]() ![]() One line has 3 extra spaces and all other lines have 0 extra spaces. For example, consider the following two arrangement of same set of words:ġ) There are 3 lines. The idea behind this cost function is to balance the spaces among lines. Please note that the total cost function is not sum of extra spaces, but sum of cubes (or square is also used) of extra spaces. So optimal value of total cost is 0 + 2*2*2 + 3*3*3 = 35 The total extra spaces in line 1, line 2 and line 3 are 0, 2 and 3 respectively. "Geeks for Geeks presents word wrap problem"įollowing is the optimized arrangement of words in 3 lines The problem is to minimize the following total cost.Ĭost of a line = (Number of extra spaces in the line)^3įor example, consider the following string and line width M = 15 The extra spaces includes spaces put at the end of every line except the last one. In other words, not have few lines with lots of extra spaces and some lines with small amount of extra spaces. The word processors like MS Word do task of placing line breaks. Assume that the length of each word is smaller than the line width. Put line breaks in the given sequence such that the lines are printed neatly. Given a sequence of words, and a limit on the number of characters that can be put in one line (line width). Rearrange array in alternating positive & negative items with O(1) extra space | Set 1.Rearrange positive and negative numbers in O(n) time and O(1) extra space.Rearrange array such that arr >= arr if i is even and arr ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |