breadthFirst and contiguousSum in scala