PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/TikTok

Find and count target-sum subarrays

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of contiguous subarray-sum problems, algorithmic techniques for linear-time and constant-extra-space solutions, and the ability to reason about correctness and edge cases such as zeros, negative numbers, and large inputs.

  • Medium
  • TikTok
  • Coding & Algorithms
  • Machine Learning Engineer

Find and count target-sum subarrays

Company: TikTok

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

Given an integer array nums and an integer target, implement: ( 1) a function that returns true if any non-empty contiguous subarray sums to target; ( 2) a function that returns the number of contiguous subarrays whose sum equals target; ( 3) assuming all numbers in nums are non-negative, design an O(n) time, O( 1) extra-space method to find one such subarray (return its start and end indices) and explain how to adapt it to count all such subarrays. For ( 1) and ( 2) also aim for O(n) time. Discuss trade-offs, edge cases (e.g., zeros, negative numbers, large inputs), and prove correctness.

Quick Answer: This question evaluates understanding of contiguous subarray-sum problems, algorithmic techniques for linear-time and constant-extra-space solutions, and the ability to reason about correctness and edge cases such as zeros, negative numbers, and large inputs.

Related Interview Questions

  • Parse a nested list from a string - TikTok (medium)
  • Implement stacks, streaming median, and upward path sum - TikTok (easy)
  • Maximize sum with no adjacent elements - TikTok (medium)
  • Implement stack variants and path-sum check - TikTok (medium)
  • Find the longest palindromic substring - TikTok (easy)
TikTok logo
TikTok
Jul 31, 2025, 12:00 AM
Machine Learning Engineer
Technical Screen
Coding & Algorithms
3
0

Given an integer array nums and an integer target, implement: (

  1. a function that returns true if any non-empty contiguous subarray sums to target; (
  2. a function that returns the number of contiguous subarrays whose sum equals target; (
  3. assuming all numbers in nums are non-negative, design an O(n) time, O(
  4. extra-space method to find one such subarray (return its start and end indices) and explain how to adapt it to count all such subarrays. For (
  5. and (
  6. also aim for O(n) time. Discuss trade-offs, edge cases (e.g., zeros, negative numbers, large inputs), and prove correctness.

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More TikTok•More Machine Learning Engineer•TikTok Machine Learning Engineer•TikTok Coding & Algorithms•Machine Learning Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.