HackerRank: A Very Big Sum

Question: [get the question here]

screen-shot-2017-03-03-at-2-41-16-pm

Solution:

First things to consider:

  •  the resulting data structure must be able to accommodate [0, 5*10^10] at most which is approximately [0, 2^34]
  • the range of a 32-bit integer is [-2^31, (2^31)-1]
  • conclusively, an ‘int’ data type will not accommodate the extreme cases

Note:

Integer = 32-bits

Long int = 32-bits

Long long int = 64-bits

screen-shot-2017-03-03-at-4-25-04-pm

Time complexity of this solution: O(n)

Space complexity of this solution: O(n)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s