Adding Big Numbers Time : Space : 12345678910111213141516171819202122232425262728293031#include <string>std::string add(const std::string& a, const std::string& b) { std::string ca = a, cb = b; std::reverse(std::begin(ca), std::end(ca)); std::reverse(std::begin(cb), std::end(cb)); std::string res = ""; int carry = 0, i = 0; while(i < ca.length() and i < cb.length()) { int now = carry + ca[i] - '0' + cb[i] - '0'; res.push_back(now % 10 + '0'); carry = now / 10; i += 1; } while(i < ca.length()) { int now = carry + ca[i] - '0'; res.push_back(now % 10 + '0'); carry = now / 10; i += 1; } while(i < cb.length()) { int now = carry + cb[i] - '0'; res.push_back(now % 10 + '0'); carry = now / 10; i += 1; } if(carry) res.push_back(carry + '0'); std::reverse(std::begin(res), std::end(res)); return res;}