Second Largest Digit in a String
A easy-tier problem at 52% community acceptance, tagged with Hash Table, String. Reported in interviews at Softwire and 0 others.
Second Largest Digit in a String is an easy problem that only 52% of candidates clear on the first submission. It shows up in Softwire assessments and tests whether you can scan a string, extract digits, and track two values without off-by-one errors. The problem looks trivial until you hit edge cases: what if there's only one unique digit, or none at all? What if duplicates exist? Most candidates rush through and miss the return condition. If this hits your live OA and you blank on the logic, StealthCoder solves it invisibly in seconds.
Companies that ask "Second Largest Digit in a String"
Second Largest Digit in a String is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by a senior engineer who knows the OA is theater. This is the script.
Get StealthCoderThe trick is simple: iterate once through the string, collect all digit characters, remove duplicates, sort them, and return the second largest. But the gotcha is the return condition. If there aren't at least two distinct digits, you return -1. The naive approach fails when candidates don't convert the string to a set first, or they try to track the largest and second largest in a single pass and mess up the logic. Hash Table (set) is the safe move here. String iteration is straightforward. Many candidates over-engineer it or forget to handle the edge case of fewer than two unique digits. When you're burning clock time in a live assessment, it's the kind of problem where a single line of oversight tanks you. StealthCoder hedge: if you second-guess yourself on the return condition, it's there.
Pattern tags
You know the problem.
Make sure you actually pass it.
Second Largest Digit in a String recycles across companies for a reason. It's easy-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by a senior engineer who knows the OA is theater. This is the script. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Second Largest Digit in a String interview FAQ
Is Second Largest Digit really that easy?+
Technically yes, but acceptance rate is 52%, not 90%. Edge cases trip people up: single unique digit, no digits, or duplicate digits. The return condition for invalid cases is where candidates stumble. It looks trivial until you defend it in a live setting.
Should I use a set or just sort the string digits?+
Set first. Convert string digits to a set to remove duplicates, then sort. Sorting a string digit-by-digit is slower and error-prone. The hash table approach is cleaner and guaranteed to handle duplicates correctly.
What's the return value if there's no second largest digit?+
Return -1. This happens when there's fewer than two distinct digits in the entire string. Check this condition before indexing. It's the edge case that catches unprepared candidates.
Do I need to validate that characters are actual digits?+
Yes, but it depends on the problem statement. Most versions require you to skip non-digit characters silently. Check the input examples. A safe approach: iterate the string, filter for digits (using isdigit() or similar), then proceed.
Is this problem still asked by Softwire and others?+
Softwire has confirmed this problem in reports. At easy difficulty with moderate acceptance, it's a pre-screen filter rather than a deep interview round question. Expect it as a warm-up or gating problem.
Want the actual problem statement? View "Second Largest Digit in a String" on LeetCode →