iiitv / iiitv/algos

Longest Subarray with Sum K [Java]

Open
#885 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
1.1k
Forks
487
PR merge metrics
No merged PRs in 30d

Description

To Implement the algorithm to find the length of the longest subarray with sum equal to a given value k.
The array may contain both positive and negative numbers.

Problem Statement
Given an array of integers and a number k, return the length of the longest subarray whose sum equals k.

Examples

Input: N = 3, k = 5, array[] = {2, 3, 5}
Output: 2
Explanation: The longest subarray with sum 5 is {2, 3}. Its length is 2.

Input: N = 3, k = 1, array[] = {-1, 1, 1}
Output: 3
Explanation: The longest subarray with sum 1 is {-1, 1, 1}. Its length is 3.

@raj-j-shah can you please assign this issue to me under Hacktoberfest 2025

Contributor guide

Open the contributing guide

Research direction

No file, test, or entry point is named in the issue, so first locate the Java algorithm implementations and their test conventions. Implement longest-subarray length for arrays containing positive and negative values, then verify the two supplied examples and equivalent project tests if available.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
data
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.