- See Code
O(nk)
class Solution:
def numberOfLines(self, widths: List[int], S: str) -> List[int]:
res = [0]
for c in S:
num = widths[ord(c) - 97]
if res[-1] + num > 100:
res.append(num)
else:
res[-1] += num
return [len(res), res[-1]]