Skip to content
CampusEduX

Longest Subarray with Sum K

Mediumjavapythonccppjavascript

Given an integer array and a target K, find the length of the longest contiguous subarray whose sum is exactly K.

Input Format

The first line contains two integers N and K. The second line contains N space-separated integers.

Output Format

Print the length of the longest such subarray, or 0 if none exists.

Related Problems

  • Zero Sum Subarray
    Medium · java, python, c, cpp, javascript
    Solve Problem
  • Longest Consecutive Sequence
    Medium · java, python, c, cpp, javascript
    Solve Problem
  • Group Anagrams
    Medium · java, python, c, cpp, javascript
    Solve Problem

Input (stdin)

Output

Run your code to see output here...