Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
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
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
Build my plan
Binary Tree and String Reverse
00:00
5 left

Binary Tree and String Reverse

EasyPython

Problem

A Citigroup transaction-monitoring component must locate a transaction amount in a sorted list and reverse a related reference string for downstream formatting. Implement both operations in one function.

Given a sorted list of integers amounts, an integer target, and a string reference, return a two-element list containing the index of target in amounts, or -1 if it is absent, followed by reference reversed character by character.

Use binary search for the lookup. If duplicate target values exist, returning any matching index is valid. Reverse the string without calling a built-in reverse helper.

Formal Specification

  • Input: amounts, a non-decreasing list of integers; target, an integer; and reference, a string.
  • Output: [index, reversed_reference], where index is a valid matching position or -1, and reversed_reference is the input string in reverse order.
  • The input string may contain spaces, punctuation, and mixed-case characters. Preserve every character exactly, changing only its position.

Constraints

  • 0 <= len(amounts) <= 100,000
  • -10^9 <= amounts[i], target <= 10^9
  • amounts is sorted in non-decreasing order
  • 0 <= len(reference) <= 100,000

Function Signature

def search_and_reverse(amounts, target, reference):
Interviewer

Your question is Binary Tree and String Reverse. 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.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.