-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Create 1498-number-of-subsequences-that-satisfy-the-given-sum-conditi… #2604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…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)); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Waiting for an update...
There was a problem hiding this comment.
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?
…on.js updating time complexity.
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/