Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Second Largest String

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Second Largest String. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

How would you write a program to find the second largest string? Treat strings as distinct by their casefold() values and compare them lexicographically without regard to case; preserve the first spelling encountered for the returned value. Implement second_largest_string(strings), which accepts a list of strings and returns the second-largest distinct string, or None when fewer than two case-insensitive values exist.

Constraints

  • 1 <= len(strings) <= 10^4
  • Each element is a non-empty Python string
  • Comparison is lexicographic on each string's casefolded value
  • Case-insensitive duplicates count as one distinct value
  • Return None when fewer than two distinct casefolded values exist

Function Signature

def second_largest_string(strings):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output