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
Get started
Merge Strings Alternately
00:00
5 left

Merge Strings Alternately

EasyPython

Problem

Infineon Technologies test utilities receive two diagnostic strings that must be merged character by character. Given strings first and second, create a merged string by taking one character from first, then one from second, repeating until both strings are exhausted. When one string ends, append the remaining characters from the other string in their original order.

Then build a hash map for the merged string. Each distinct character must map to a list of its zero-based positions in the merged string, ordered from left to right.

Return both the merged string and the character-position hash map.

Formal Specification

  • Input: two strings, first and second, containing printable ASCII characters.
  • Output: a two-element result where the first element is the merged string and the second element is a dictionary mapping each character to a list of integer positions.
  • Dictionary keys must include every distinct character in the merged string.

Constraints

  • 0 <= len(first), len(second) <= 10^5
  • len(first) + len(second) <= 2 * 10^5
  • Characters are printable ASCII characters
  • Position lists must be zero-based and ordered

Function Signature

def merge_and_index(first, second):
Interviewer

Your question is Merge Strings Alternately. Start with the requirements in the Question tab.

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.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.