Problem Statement
You have a sentence written entirely in a single row. You would like to split it into several rows by replacing some of the spaces with "new row" indicators. Your goal is to minimize the width of the longest row in the resulting text ("new row" indicators do not count towards the width of a row). You may replace at most K spaces.
You will be given a
Definition
- Class:
- SentenceSplitting
- Method:
- split
- Parameters:
- String, int
- Returns:
- int
- Method signature:
- int split(String sentence, int K)
- (be sure your method is public)
Constraints
- sentence will contain between 1 and 50 characters, inclusive.
- sentence will consist of only letters ('a'-'z', 'A'-'Z') and spaces (' ').
- Each space character in sentence will be between two letters.
- K will be between 1 and 50, inclusive.
Examples
"This is a test sentence"
1
Returns: 13
You should split the sentence between the words "a" and "test".
"This is another test sentence"
2
Returns: 12
You should split the sentence between the words "is" and "another", and between the words "test" and "sentence".
"TheOnlyWord"
37
Returns: 11
"One veeeeeeeeeeeeeeeeeeery long word"
2
Returns: 22
"HUIUueVIk uDCCrzrNJOje Vw mIkGzM Dla eSYbaLpuIhaC"
4
Returns: 12
"a P m Zgfd rkv"
1
Returns: 8
"Ha K"
4
Returns: 2
"u cZ Mc iR"
5
Returns: 2
"VCAz ww M mJ d"
5
Returns: 4
"wg AIwP Q M eMKTN aU lK"
1
Returns: 11
"amD uD b xb kpiOLDK ZyiuGJ ChaCPSp"
1
Returns: 19
"NAusRW KcZXo b UVnhfZ KG C chLuZWX esC AaKWDU saay"
5
Returns: 10
"pt GPNmCGg q PxzhuOhmGf yXLTsrCCBejG A FmR Xp Fyv"
3
Returns: 12
"TbH SOEN SQb zJeIJKf LQ PH HS d"
5
Returns: 7
"PZl S Cn xGxARLXwY qTx eKK fA hS"
5
Returns: 9
"wQbzaJR uGkv DsrPaKF mz dWaRLb aW S"
4
Returns: 9
"raIbW OX vhcK TXcjNTv WEgCXiw YAY ABrOWDEPh"
2
Returns: 15
"Nf v OXipD uFQEol c Bw K BmAtILV"
4
Returns: 7
"JaPFu B sfV Q EV xSOqD"
2
Returns: 8
"U wzls qVLox H ZLYyl"
5
Returns: 5
"rZ Yky B Ttu VzuV NR OQ r"
2
Returns: 8
"ZmX dB qt JRRjwtT QDdQe ocuAc tUUOGW jtCLs ECN A"
4
Returns: 11
"Wdp EO yU Ctqll KX"
3
Returns: 5
"j QS Ihg Ja z crtRS jyWsdSf o AHtR"
5
Returns: 7
"uPqd Z tz j m K DITjLI m JSNM g mmSN H Jm fn"
4
Returns: 11
"Y kS dkHjB wZf I tzC wFg s E lzFkELzSby"
8
Returns: 10
"R Aj RHystOo O JAIO G r k ncMsT iYzFNqdbG D r"
7
Returns: 9
"R Cc G cvDhP cAWh rDM WPjl UI F fD pseqowhkOgJX"
9
Returns: 12
"j laYpx FK Bu Raw KbJ XIZ giQP r cuW Fl yGsOpuiLDU"
6
Returns: 10
"S ApXDo UBfoqD CEaL V WZ c q Va M p cQisMy s"
5
Returns: 8
"I n SGk BbI sY JnR nrGYyQYhOolS oA Wl V FF z y"
5
Returns: 12
"WHKUA KTh ipI u C OoWYUg u tjP r"
7
Returns: 6
"e DbWD Z t l r S VCl yqotsU o lz VVRTmwE A voUf"
7
Returns: 7
"lOnc eA Xcv X M l Pmr xNep S c Jg"
10
Returns: 4
"gX Zmy M Z BGPEwWmha fUdU p JNq A ZhU fby m"
6
Returns: 9
"Eu dacUK Ota Gt OPgQPkrbBQISM p omTSLxC o Ls gq"
7
Returns: 13
"aB CAdX fKYhI vtzz d i ORqce F nwo A IW"
8
Returns: 5
"xQ T zE v I L o qJ mlpKF p cWHU c UGg P nzXM"
10
Returns: 5
"ntpis ht VrEW KDzx Pifn k hRw E DJZJU e k dq Xj"
2
Returns: 17
"S UnqMxG Fw iD n KDf y OYKuHkE rAl J Pp xE"
1
Returns: 21
"O YoEyIr uQO R uq I R kgnY C y oL TwvomftUcRs"
3
Returns: 12
"xS lioz MI CFB kObZ A Es dy lMduCsi IAUN Ku"
2
Returns: 15
"lQv x P B IIfr Kn BoX c XNEpX tANIqmc bR"
4
Returns: 10
"ZcN v XgqgSiF MW PlBj oVmG x kA B xdJ g IG"
10
Returns: 7
"baVm Kam q EfE o d n Ac F nh I InW jqE aRd c dC"
3
Returns: 12
"G xJ lRmI w tMZN q F mH B eG GF xs be Hg"
13
Returns: 4
"WkW VfM rl ha U p W R l z M Dkv Q g s V"
5
Returns: 7
"N BM uX HB a L Zh Xl r u TQ Ak Z v"
5
Returns: 6
"z dd g J P Y a bx z y V CVK JK uU A B a W"
4
Returns: 9
"A o Xcw Ln YfJE r n Z e Ot p RC s lBi r B"
7
Returns: 6
"lr p w x w n kM Ww No iH x Sl w A HM hV"
8
Returns: 5
"HzH iD rWL rS eHs q E p Jk Dx b p zDdC sh lL Qm O"
11
Returns: 5
"e b E g rn cQ f Ru t L q G w R Vm"
3
Returns: 8
"q ti nf I l FO Pi Nsm M X DMLU u H d ayAr dL G S k"
1
Returns: 25
"iw F lM tP A w c c wK n WrS v oz"
9
Returns: 4
"z E j f arK KF WsO Z hl K C U QD S dY aH"
11
Returns: 4
"nSvL f wes aC oe t JV J sS MJ q zt df"
13
Returns: 4
"Z j J m Cg bt T p K I ZQ ww QP S I"
13
Returns: 3
"Q ph iM d buM rC N W k n KA Qm Ui BU zQ"
8
Returns: 5
"N Dqs q M im WcA HT q eVu Dec oc FvY Ks W La S xZ"
9
Returns: 6
"TZ B rj oY ds fWC CZ bH kn Uq h"
11
Returns: 3
"sjk YhS Zv mz C mVqIPhM C vFd x Y wB O X CH T a"
13
Returns: 7
"n x c gU GU i v I V v hEh qu jGG I BfgG DBW Qgkz"
7
Returns: 7
"lf d L Nve F OnP nGN e eaz e G zE v vrCu a PD x t"
13
Returns: 4
"A"
1
Returns: 1
"a"
50
Returns: 1
"Z"
1
Returns: 1
"z"
50
Returns: 1
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
1
Returns: 49
"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
50
Returns: 49
"A AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AA"
1
Returns: 46
"A A A A A A A A A A A A A A A A A A A A A A A A A"
1
Returns: 25
"A A A A A A A A A A A A A A A A A A A A A A A A A"
2
Returns: 17
"A A A A ARA A A A A A A A A ARA A A A A A ARR A A"
8
Returns: 5
"Each tournament round is an elimination round"
3
Returns: 15
"One veeeeeeeeeeeeeeeeeeery long word"
2
Returns: 22
"a b c d ee t t f s w r t tt z w w r w t t w q ez e"
20
Returns: 3
"a a a a a a a a a a a a a a a a a a a a a a a a"
1
Returns: 23
"aaaa nnnn eeeee nnnnn ooo"
2
Returns: 9
"Each tournament round is an elimination round"
3
Returns: 15
"a a a a a a a a a a a a a a a a a a a a a a a a"
22
Returns: 3
"a b c d e f g h i j k l m n o p q r s t u v w x y"
48
Returns: 1
"a a a a a a a a a a a a a a a a a aaaa"
6
Returns: 5
"This is a test sentence"
10
Returns: 8
"a a a a a a a a a a a a a a a a a a a a a a a a a"
50
Returns: 1
"One veeeeeeeery long wordinu jebo ti pas mater"
6
Returns: 11
"a a a a a a a a a a a a a a a a a a a a a a a a aa"
50
Returns: 2
"a b c d e f g h i j k l m n o p q r s t u v w x y"
50
Returns: 1
"a A a A a A a A a A a A a A a A a A a A a A a A"
39
Returns: 1
"aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa"
50
Returns: 2
"I dont know you and you suck"
12
Returns: 4
"a b c d e f g h i j k l m n o p q r s t u v x y w"
24
Returns: 1
"a ab abc abcd"
10
Returns: 4
"a b c d e f g h i j k lm n o p q r s t u v w x y z"
12
Returns: 4
"ab cd ef gh ij kl mn po qr st uw xyz"
3
Returns: 9
"a a a a a a a a a a a a a a a a a a a a a a a a a"
10
Returns: 5
"a b c d e f g h i j k l m n o p q r s t u v w x yz"
4
Returns: 10
"Ta s d f g t h j u k i gt e e w d e r e r cc e c"
12
Returns: 3
"a a a a a a a a a a a a a a a a a a a a a a"
4
Returns: 9
"a a a a a a a a a a a a a a a a a a a a a a a a"
24
Returns: 1
"a a a a a a a a a a a a a a a a a a a a a"
4
Returns: 9
"a a a a a a a a a a a a a a a a a a a a a a a a a"
30
Returns: 1
"a a a a a b b b b b c c c c c d d d d d e e e e ef"
50
Returns: 2
"a b c d e a b c d e a b c d e a b c d e a b c d e"
24
Returns: 1
"a a a a a a a a a a a a a a a a a a a a a a a a a"
4
Returns: 9
"aaa a a aaa"
1
Returns: 5
"This is the f g h j k l ty op qw as fdsfds h"
15
Returns: 6
"aaaaaaa aa aaa aaaaaa"
1
Returns: 10
"x x x x x x x x x x x x x x x x x x x x x x x x x"
50
Returns: 1
"a a a a a a a a a a a a a a a a a a a a a a a a a"
25
Returns: 1
"AB CD"
10
Returns: 2
"test sentence a a test sentence"
1
Returns: 15
"This challege but think if u can i dont believe i"
5
Returns: 9