Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
Why windowSum is a float?

ornella

Mar 2, 2022

Why windowSum is a float?

1

0

Comments
Comments
Design Gurus
Design Gurus4 years ago

It is because of the following statement:

result[i] = sum / K;

As the division can result in a floating number.

The other option is to keep the 'sum' as an integer and type-cast it to double before the division.

On this page