Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Solve Two Sum and Longest Substring

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

Your question is Solve Two Sum and Longest Substring. 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

A Samsung Exynos mobile diagnostics utility receives numeric event data and a compact identifier string. Implement one function that performs two independent analyses: find the indices of two array values that sum to a target, and compute the length of the longest substring containing no repeated characters.

Formal Specification

Implement solve_mobile_arrays(nums, target, s).

  1. For the integer array nums, return the indices of the two distinct elements whose values sum to target. Return the indices in ascending order. Each valid input contains exactly one pair.
  2. For the string s, return the length of its longest substring with all unique characters.
  3. Return a dictionary with keys two_sum and longest_substring, where two_sum maps to the index pair and longest_substring maps to the integer length.

Characters are compared exactly as supplied, including case and whitespace.

Constraints

  • 2 <= len(nums) <= 10^5
  • 0 <= len(s) <= 10^5
  • -10^9 <= nums[i], target <= 10^9
  • nums contains exactly one valid two-sum pair
  • s may contain any standard Unicode characters

Function Signature

def solve_mobile_arrays(nums, target, s):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output