Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Start free
Two Sum Interval Merge Substrings and Anagrams
00:00
5 left

Two Sum Interval Merge Substrings and Anagrams

HardPython

Problem

As part of a Luxoft engineering assessment, implement four independent algorithms in one function. Return the required result for each task: find a pair summing to a target, merge overlapping intervals, find the longest substring without repeated characters, and determine whether two strings are anagrams.

Formal Specification

Implement solve_all(nums, target, intervals, s, t). Return a dictionary with these keys:

  1. two_sum: the zero-based indices of the unique pair in nums whose values sum to target, or [] if no pair exists.
  2. merge_intervals: all overlapping intervals merged and sorted by start time.
  3. longest_substring: the length of the longest substring of s containing no repeated characters.
  4. valid_anagram: true if s and t contain the same characters with the same frequencies, otherwise false.

Intervals are represented as two-element lists [start, end]. Treat strings as case-sensitive and compare every character, including spaces and punctuation.

Constraints

  • 2 <= len(nums) <= 10^5
  • -10^9 <= nums[i], target <= 10^9
  • 0 <= len(intervals) <= 10^5
  • Each interval has exactly two integers and start <= end
  • 0 <= len(s), len(t) <= 10^5
  • At most one valid two-sum pair exists
  • String comparison is case-sensitive and includes spaces and punctuation

Function Signature

def solve_all(nums, target, intervals, s, t):
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements are in the Question tab.

Sign up free to run or submit. Log in
Code
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 2
Run your code to see test output here.