Add Strings || Leetcode 415 || Variant Question Big Tech Actually Asks

preview_player
Показать описание
Discover the actual variant Meta asks on Leetcode problem 415: Add Strings.

Timestamps:
00:00 Leetcode Explanation
10:53 Leetcode Coding
12:49 Variant Explanation (Add Decimal Strings)
23:46 Variant Coding (Add Decimal Strings)

Follow us on social media:

GitHub:

More Context:
FAANG, mid-sized companies, and startups are asking more LeetCode-style puzzle questions every day, making it harder to stand out as the competition grows. With an increasing number of new graduates entering the software market and tech companies laying off developers while overworking those who remain, it’s a tough landscape. Take Meta, for example: they expect 2-3 months of intense study time, only to likely ghost you afterward. But this doesn’t mean we should be unprepared.

While LeetCode is a valuable learning resource, many developers focus too much on rote memorization. Others find themselves stuck in a vicious cycle, where they don’t study as efficiently as they could because they’re juggling multiple responsibilities. They have full-time jobs, personal commitments, or other obligations that limit the time they can dedicate to solving problems. It’s a grind. Unfortunately, most companies introduce their own twists or "variants" of common problems (e.g., 6-sum instead of 2-sum), which throw candidates off. Rephrasings of problems and follow-up questions are also common, so recognizing these variations and curveballs is crucial.

For those who don’t have the time to revisit LeetCode problems multiple times to solidify concepts, this channel covers the most frequently asked variants, rephrasings, and follow-ups. If you've seen these before, you’ll have a significant edge over your competitors. Remember, time pressure — especially at Meta — is intense, so speed is essential. Even with thorough preparation, interviewers may be unpredictable, but knowing the variants beforehand can drastically increase your chances of success.

Take LeetCode 415, Add Strings, which is one of Meta’s most frequently asked questions (top 30 as of writing). Meta sometimes sticks to the original problem. Variants - however - do exist, and with thousands of interviewers, it's hard to predict them all. We cover a key variant: what if the number strings have decimals?

We also walk through variants in mock interviews. Using the exact platform (CoderPad) that Meta uses, you’ll get familiar with the UI, settings, and overall experience. This is a 1-on-1 simulation of how Meta conducts and facilitates their interviews, so the goal is to avoid wasting time on the tool itself. Once again, time limits at Meta are a huge factor, so speed is critical.

That said, even with perfect preparation, interviewers might not always be in a good mood or may judge unfairly. The interview process has its power dynamics, but with insider knowledge, you’ll have done as much as you can on your end to secure a Strong Hire decision.
Рекомендации по теме
Комментарии
Автор

OOPS made a mistake. Didn't mean to have my voice in double-time at 22:07. Um, maybe it's a feature? Sounds funny though.

CodingWithMinmer
Автор

I was asked this variant and completely bombed the question. So many edge cases

conquest-In
Автор

Thanks so much Minmer! One small point for the python solution for the variant: if we make the carry a self integer variable, like self.carry = 0, then we can avoid the awkward passing it around as a list-enclosed value!

crinzo_
Автор

My friend received a another variant of this problem instead of add it was multiply 2 strings and the follow up was how to handle decimals and the other follow up was how do you handle negatives (this was for the phone screen)

sathishkumar-bgtb
Автор

Hey Minmer, thanks for the great video (as always). Lot of code and very neatly written.

2 questions:

a) For the variant that you covered in this video, is there a variant in linked list form as well i.e. decimals represented in linked list form and you need to add them

b) Is LC#43 (Multiply strings) also considered as a variant. I have found that one to be more tricky always.

himanshuaggarwal
Автор

In the python code on your github, were are we carrying over the solution to the integer? i.e -> 0.99 + 0.12?

myskilltoonice
Автор

Hey Minmer, great vid as always. Have my onsite coming up in a couple of weeks. Have you noticed in the community any questions Meta has been asking a lot recently?

xavierelon
Автор

why do we need to check the size of the decimals? Shouldn't our helper already handle strings of unequal size? and why not set the decimals as "0" if the decimal is empty?

VadayKapeed
Автор

Here is a similar solution to add linked list -
string addStrings(string num1, string num2) {

int carry = 0;
int n1 = num1.size()-1;
int n2 = num2.size()-1;
string total = "";
while(n1>=0 || n2>=0 || carry) {
int p1Val = n1 >=0? num1[n1] - '0' : 0 ;
int p2Val = n2>=0? num2[n2] - '0' : 0 ;
int sum = p1Val + p2Val + carry;
carry = sum / 10;
int digit = sum % 10;
total += digit + '0';
n1--;
n2--;
}
std::reverse(total.begin(), total.end());
return total;
}

codewiz
Автор

Hi Minmer, thanks for the variant, but I guess there is a bug with returning carry from your helper function.

I made an inner data object(Pair of String, Integer might be used as well) to return it and propagate to the main caller function.


public static String addStrings(String num1, String num2) {
String[] nums1 = num1.split("\\.");
String[] nums2 = num2.split("\\.");

String decimals1 = nums1.length > 1 ? nums1[1] : "";
String decimals2 = nums2.length > 1 ? nums2[1] : "";
boolean hasDecimal = !decimals1.isEmpty() || !decimals2.isEmpty();

while(decimals1.length() != decimals2.length()) {
if(decimals1.length() > decimals2.length()){
decimals2 = decimals2 + "0";
} else {
decimals1 = decimals1 + "0";
}
}

Integer carry = 0;
StringBuilder sb = new StringBuilder();
DataWithCarry dataDecimal = helper(decimals1, decimals2, carry);
sb.append(dataDecimal.sum);
if(hasDecimal) {
sb.append(".");
}
DataWithCarry dataOther = helper(nums1[0], nums2[0], dataDecimal.carry);
sb.append(dataOther.sum);
if (dataOther.carry > 0) {
sb.append((char) (dataOther.carry + '0'));
}
return sb.reverse().toString();
}

public static DataWithCarry helper(String num1, String num2, Integer carry) {
StringBuilder sb = new StringBuilder();
int n1 = num1.length() - 1;
int n2 = num2.length() - 1;
while (n1 >= 0 || n2 >= 0) {
int sum = 0;
if (n1 >= 0) {
sum += num1.charAt(n1) - '0';
n1--;
}
if (n2 >= 0) {
sum += num2.charAt(n2) - '0';
n2--;
}
sum += carry;
sb.append((char) (sum % 10 + '0'));
carry = sum / 10;
}
return new DataWithCarry(sb.toString(), carry); // return the sum of string and carry
}

private static class DataWithCarry{
String sum;
int carry;

public DataWithCarry(String sum, int carry) {
this.sum = sum;
this.carry = carry;
}
}

EminINALdarkrwe
join shbcf.ru