Skip to main content
All Questions

Find the minimum removals from either end that sum to exactly x.

Unlock detailed company stats for this questionUpgrade

Given an array readings and an integer x, remove elements from either end of the array so that the removed values sum to exactly x, using the minimum number of removals.

Examples:

  • readings = [1,1,4,2,3], x = 5 -> 2 (remove 3, then 2)
  • readings = [3,2,20,1,1,3], x = 10 -> 1

Constraints: 1 <= readings.length <= 10^5, 1 <= readings[i] <= 10^4, 1 <= x <= 10^9.

Expect follow-ups like

  • What are the time and space complexity of your solution?

Format · DSA problem-solving round.

Community answers

No answers contributed by the community yet.

Related courses

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.

Course

System Design Interviews

Learn how to answer the latest system design questions across product, infrastructure, and AI domains. Features in-depth video examples, written breakdowns, and helpful reference patterns. Watch senior engineers and managers answer these questions in mock interview videos.