Tap here to switch tabs
Problem
Submissions

Problem: Longest Subarray Divisible by K, Up to One Negation I

Try to solve the Longest Subarray Divisible by K with At Most One Negation I problem.

Statement

You are given an integer array nums and an integer k.

You may choose at most 11 element in a contiguous subarray and negate its value.

Return the maximum length of a subarray whose sum is divisible by k after applying at most 11 negation. If no such subarray exists, return 00.

Note: A subarray is a contiguous non-empty sequence of elements within an array.

Constraints:

  • 1≤1 \leq nums.length ≤1000\leq 1000

  • −105≤-10^5 \leq nums[i] ≤105\leq 10^5

  • 1≤1 \leq k ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Longest Subarray Divisible by K, Up to One Negation I

Try to solve the Longest Subarray Divisible by K with At Most One Negation I problem.

Statement

You are given an integer array nums and an integer k.

You may choose at most 11 element in a contiguous subarray and negate its value.

Return the maximum length of a subarray whose sum is divisible by k after applying at most 11 negation. If no such subarray exists, return 00.

Note: A subarray is a contiguous non-empty sequence of elements within an array.

Constraints:

  • 1≤1 \leq nums.length ≤1000\leq 1000

  • −105≤-10^5 \leq nums[i] ≤105\leq 10^5

  • 1≤1 \leq k ≤105\leq 10^5