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
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
Find Triplet Sum
00:00
5 left

Find Triplet Sum

MediumPython

Problem

Calsoft's platform services may need to identify three compatible values whose combined score matches a requested target. Given an integer array and a target integer, find three distinct elements whose values sum to the target.

Return the original indices of any valid triplet as a list of three integers. The indices may be returned in any order. If no such triplet exists, return an empty list. An element cannot be reused, although duplicate values at different indices may be selected.

Formal Specification

Implement find_triplet(nums, target):

  • Input: nums, a list of integers, and target, an integer.
  • Output: A list containing three distinct indices whose values sum to target, or [] if no solution exists.

Constraints

  • 3 <= len(nums) <= 10^4
  • -10^9 <= nums[i], target <= 10^9
  • Indices in a returned triplet must be distinct
  • Return any valid triplet when multiple solutions exist
  • Duplicate values are allowed

Function Signature

def find_triplet(nums, target):
Interviewer

Your question is Find Triplet Sum. 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.