Ad
  • Custom User Avatar

    Of course you don't NEED to iterate through. It's a really quick solution to a really quick problem, that's why it's good. The Intstream solution takes 1.3s if the input is 1 billion, but since the tests were way smaller, that ain't a problem. If coding a real project, then of course everyone should think twice if their solution is really the most efficient or not. Here it's not necessary.