• Courses
  • Tutorials
  • DSA
  • Data Science
  • Web Tech
January 11, 2024 |2.1K Views

PROBLEM OF THE DAY : 10/01/2024 | Longest subarray with sum divisible by K

Description
Discussion

Welcome to the daily solving of our PROBLEM OF THE DAY with Yash Dwivedi We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Array but also build up problem-solving skills.

In this problem, we are given an array arr containing N integers and a positive integer K, find the length of the longest sub array with sum of the elements divisible by the given value K.

Example :

Input:
N = 6, K = 3
arr[] = {2, 7, 6, 1, 4, 5}
Output: 
4

Explanation:
The subarray is {7, 6, 1, 4} with sum 18, which is divisible by 3.

Give the problem a try before going through the video. All the best!!!
Problem Link: https://www.geeksforgeeks.org/problems/longest-subarray-with-sum-divisible-by-k1259/1