My Stats
EXP gained
200
Level
2 (Genius)
Community stats
Discussions
0
0
Know more
4
Total problems solved
3
Easy
1
Moderate
0
Hard
0
Ninja

Current streak:

0 days

Longest streak:

1 day

Less

More

Discussions
sum of two array
Interview problems

first think about  all possible cases

vector<int> reverse(vector<int> v){ int s=0; int e=v.size()-1; while(s<e){  swap(v[s++],v[e--]); } return v; } vector<int> findArraySum(vector<int>&a, int n, vector<int>&b, int m) { int i= n-1; int j= m-1; vector<int>ans; int carry=0; while(i>=0 && j>=0){  int val1=a[i];  int val2=b[j];  int sum= val1+val2+carry;

carry= sum/10;  sum= sum%10;  ans.push_back(sum);  i--;  j--; } while(i>=0){  int sum= a[i] + carry;  carry= sum/10;  sum= sum%10;  ans.push_back(sum);  i--;

} while(j>=0){  int sum= b[j]+ carry;  carry= sum/10;  sum= sum%10;  ans.push_back(sum);  j--; } while(carry!=0){  int sum=carry;  carry= sum/10;  sum= sum%10;  ans.push_back(sum); } return reverse(ans);

}

VIVEK SINGH
Published On 13-Sep-2023
51 views
0 replies