Skip to content

Conversation

@aadil42
Copy link
Contributor

@aadil42 aadil42 commented Jun 20, 2023

Solved number-of-subsequences-that-satisfy-the-given-sum-condition in JS.

File(s) Added: 1498-number-of-subsequences-that-satisfy-the-given-sum-condition.js
Language(s) Used: JavaScript
Submission URL: https://leetcode.com/problems/number-of-subsequences-that-satisfy-the-given-sum-condition/submissions/947074363/

…on.js

Solved number-of-subsequences-that-satisfy-the-given-sum-condition in JS.
}

// we are subtracting 1 from right because we would have gone over the subsequance by 1 // think about it.
total += (BigInt(2)**BigInt(right - 1 - left));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BigInt will increase Time complexity

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get how BigInt will increase the time complexity. I'm using BigInt because the value was overflowing. However, I realized that the time complexity should be n*log(n) because of the sorting. I updated that time complexity.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Numbers is a primitive data type that operates in binary and Time O(1). BigInt is a string, that gets converted to Number at Time(N).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so the Time complexity should be nlog(n) * (the time it takes to convert BigInt to a number which is O(n) if it's converted from the string). so it should be nlog(n)*k where k is equal to the time it takes to convert a BitInt to a Number right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aakhtar3, any update on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waiting for an update...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aakhtar3, Is the reasoning correct for this one? Waiting for an update.

Ok, so the Time complexity should be n_log(n) * (the time it takes to convert BigInt to a number which is O(n) if it's converted from the string). so it should be n_log(n)*k where k is equal to the time it takes to convert a BitInt to a Number right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants