In the first brute force approach of the Second problem, wouldn't the TC be O(n^3) instead of O(n^2)? Because rechecking for the diff would be O(n) too, not O(1). Because, after removing 2 elements from nums1, we would need to check the validity of the difference throughout the arrays (modified nums1 and nums2), as the diff could be inconsistent for some cases of removing 2 elements from nums1. Nice Explanation BTW!
since you have sorted it taking diff would be O(1) only because, suppose consider 1st array of size 5 and 2nd array of size 3 now ,if you remove 1st and 3rd element of 1st array you could directly take diff nums2[0] - nums1[1] 2nd element and keep on checking min of diff throught O(n^2) iterations
Firstly I thought the same generating all pair in o(n2) then for checking the diff in o(n) make it o(n3) But no need to generate pair as element are sorted check for single element only and number of same diff should be greater than or equal to num2.size then in similar fashion check for each element make it o(n2) And he further optimize it in o(3n) by taking element first second and 3rd only
yes, exactly class Solution { private: int solve(vector& nums1, vector& nums2){ int n=nums1.size(); int m=nums2.size(); int i=0; int j=0; while(nums1[j]==-1){ j++; } int ans=nums2[i]-nums1[j]; j++; i++; while(i
@@bhuvanak4157 int minimumAddedInteger(vector& nums1, vector& nums2) { int n = nums1.size(); int m = nums2.size(); sort(nums1.begin(),nums2.end()); sort(nums2.begin(),nums2.end()); int j=0; int ans = 1e9; int index = 0; int i = index; while(index
@@bhuvanak4157 class Solution { private: int solve(vector& nums1, vector& nums2){ int n=nums1.size(); int m=nums2.size(); int i=0; int j=0; while(nums1[j]==-1){ j++; } int ans=nums2[i]-nums1[j]; j++; i++; while(i
because of you i can easily and consistently upsolving the contest love your consistency
In the first brute force approach of the Second problem, wouldn't the TC be O(n^3) instead of O(n^2)? Because rechecking for the diff would be O(n) too, not O(1). Because, after removing 2 elements from nums1, we would need to check the validity of the difference throughout the arrays (modified nums1 and nums2), as the diff could be inconsistent for some cases of removing 2 elements from nums1. Nice Explanation BTW!
exactly
since you have sorted it taking diff would be O(1) only because, suppose consider 1st array of size 5 and 2nd array of size 3 now ,if you remove 1st and 3rd element of 1st array you could directly take diff nums2[0] - nums1[1] 2nd element and keep on checking min of diff throught O(n^2) iterations
Firstly I thought the same generating all pair in o(n2) then for checking the diff in o(n) make it o(n3)
But no need to generate pair as element are sorted check for single element only and number of same diff should be greater than or equal to num2.size then in similar fashion check for each element make it o(n2)
And he further optimize it in o(3n) by taking element first second and 3rd only
@@pranavreddy-do9ck no bro, we would have to go through it all only
yes, exactly
class Solution {
private:
int solve(vector& nums1, vector& nums2){
int n=nums1.size();
int m=nums2.size();
int i=0;
int j=0;
while(nums1[j]==-1){
j++;
}
int ans=nums2[i]-nums1[j];
j++;
i++;
while(i
Problem3 of today's Contest - ua-cam.com/video/eA1xIDUqIDc/v-deo.html
.
Do make sure to join Discord for doubts, discussion & active problem Solving ❤
very good explanation
well explained!
👍👍
I solved 2nd using O (n ^ 3) brute force of brute force approach 😂 and It worked too 😂
could you please share the code
@@bhuvanak4157 int minimumAddedInteger(vector& nums1, vector& nums2) {
int n = nums1.size();
int m = nums2.size();
sort(nums1.begin(),nums2.end());
sort(nums2.begin(),nums2.end());
int j=0;
int ans = 1e9;
int index = 0;
int i = index;
while(index
Me too😅
@@bhuvanak4157
class Solution {
private:
int solve(vector& nums1, vector& nums2){
int n=nums1.size();
int m=nums2.size();
int i=0;
int j=0;
while(nums1[j]==-1){
j++;
}
int ans=nums2[i]-nums1[j];
j++;
i++;
while(i
very well
:)
my 2nd part approach was just similar and even after so many bound and checks i got run time error🥲