From the course: Get Ready for Your Coding Interview
Unlock the full course today
Join today to access over 23,100 courses taught by industry experts.
Visual solution to sample question #2
From the course: Get Ready for Your Coding Interview
Visual solution to sample question #2
- [Instructor] How would I solve this problem of comparing two numbers in strings without converting them to numbers first? Here's what I would do. I would first compare the lengths of the two strings. If the first string has a larger length than the second one, then the first string has a number that's larger than the second one as well. What if they have the same length? Then I'm going to compare them character by character or digit by digit. We're going to start by comparing the first character. In Python, you can use a simple comparison operator for this. For instance, two less than two returns false, because they're equal to each other. But this doesn't necessarily work with strings with different lengths. For example, 10 less than three returns true, even though 10 is larger than three. The reason for this is because of what Python does with a simple comparison operator. It compares the two strings in the…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.