Data Interview Qs - Subarray sums

InterviewQs

Subarray sums

Forward this email to a friend or colleague and challenge them to solve it.

Hi, 

Suppose you're given an array of integers, and a number x. Find the smallest subarray with a sum greater than the given value. Given the array, the array's length n, and the number x your function should return:

  • The length of the smallest subarray that has a sum greater than x
  • The actual subarray that has a sum greater than x

For example:

    

# Given the following

array = [5,6,2,3,8]

x = 12

# Your output should be:

array length: 2

array: [8,6]

#note that [8, 5] would also be an acceptable answer, as it contains a length of 2 as well

If the output is not possible, then you can return the length of the array + 1 (indicating that an additional element would be needed to satisfy the requirements).



 

You’ve accumulated 182 questions since joining our email list. Create a premium account to access detailed solutions to each problem (including this one) + our new Case studies.


Was this email forwarded to you? You can join our list here to receive questions

How did you like today's question?

15411 Boischatel, Montreal, QC, H9H1Y7, Canada
Don't want to get these emails anymore? We'll forgive you if you unsubscribe

Older messages

Picking a survey group

Monday, August 30, 2021

InterviewQs Picking a survey group Forward this email to a friend or colleague and challenge them to solve it. Hi, You work for a large hardware company (one that manufactures watches, computers, and

Replacing bad data with Pandas

Friday, August 27, 2021

InterviewQs Replacing bad data with Pandas Forward this email to a friend or colleague and challenge them to solve it. Hi, Suppose you are given a dataframe, df, that contains various negative values.

Coin toss patterns (state transition diagrams)

Wednesday, August 25, 2021

InterviewQs Coin toss patterns (state transition diagrams) Forward this email to a friend or colleague and challenge them to solve it. Hi, A fair coin is tossed repeatedly and independently. Find the

Smallest missing number in array

Monday, August 23, 2021

InterviewQs Smallest missing number in array Forward this email to a friend or colleague and challenge them to solve it. Hi, Write a function that outputs the smallest missing number in a sorted array

Item inventory

Friday, August 20, 2021

InterviewQs Item inventory Forward this email to a friend or colleague and challenge them to solve it. Hi, You are given 2 tables, the first one is named current_inventory, and contains has the current

You Might Also Like

Scale AI’s $1B fundraise illustrates data’s growing importance

Tuesday, May 21, 2024

Scale AI has raised a $1B Series F, doubling its valuation to $13.8B View this email online in your browser By Rebecca Bellan Tuesday, May 21, 2024 Welcome to TechCrunch AM! This morning, we've got

Esbuild v0.21.3; ESLint v9.3.0; Node v22.2.0; Promise.withResolvers(); duplicate named capturing...

Tuesday, May 21, 2024

We have 11 links for you - Stay up-to-date on JavaScript and tools Tired of handling a tech stack with REST, SQL, Webpack and 1000 other technologies? uix.unyt.org Sponsor With its radically holistic

LW 134 - How To Win In The Shopify App Store in 2024

Tuesday, May 21, 2024

How To Win In The Shopify App Store in 2024 Shopify Development news and articles Issue 134 - 05/21/2024 Read Online Liquid Weekly All Things Shopify Development How To Win In The Shopify App Store in

⚙️ New research: AI guardrails aren't good enough

Tuesday, May 21, 2024

Plus: Google unveils new AI safety plans ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌

No such thing as a modular monolith?

Tuesday, May 21, 2024

Ending soon: early bird discounts for my architecting for fast, sustainable flow workshop You are receiving this email because you subscribed to the microservices.io mailing list. Helping organizations

Webinar: Stop Mac Hacks in Their Tracks

Tuesday, May 21, 2024

Security Blind Spots of Service Accounts Join us for a live webinar May 23, 2024 | 11:30 AM EST | 1 hour 0 min Hi there, Old rumors of Macs being magically more secure than Windows still exist today.

Windows 11 to Deprecate NTLM, Add AI-Powered App Controls and Security Defenses

Tuesday, May 21, 2024

THN Daily Updates Newsletter cover Webinar - Navigating the SMB Threat Landscape: Key Insights from Huntress' Threat Report Analyzing the Post-Qakbot Era and Emerging Threats with Cybersecurity

Microsoft's AI-centric Copilot+ PCs

Tuesday, May 21, 2024

The Morning After It's Tuesday, May 21, 2024. Microsoft couldn't wait until its Build conference today. It just revealed a bunch of new hardware and plans for Windows. Copilot+ PCs were the big

Post from Syncfusion Blogs on 05/21/2024

Tuesday, May 21, 2024

New blogs from Syncfusion Perform CRUD Operations in Blazor Pivot Table with SQL Database using Entity Framework By Sastha Prathap Explore syncing Syncfusion Blazor Pivot Table with SQL using Entity

Edge 397: Multi-Plan Selection in Autonomous Agents

Tuesday, May 21, 2024

Agents that can generate and evaluate multiple plans simultaneously. ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏