Subarray Sum Equals K (LeetCode Day 22 Question) | Programming Tutorials

preview_player
Показать описание


Number of subarrays having sum exactly equal to k.

Given an array of integers and an integer k. We have to write a code to find the total number of continuous subarrays whose sum equals to k.


For example:

Example 1:

Input : {1, 1, 1} , k = 2
Output : 2


Example 2:

Input: {-1, -1, 1} , k = 0
Output: 1


Example 3:

Input : {1}, k = 0
Output: 0


Example 4:

Input: {10, 2, -2, -30, 10} , k = -20
Output : 3

This problem is the day 22 challenge of LeetCode 30 day challenge.

Рекомендации по теме
Комментарии
Автор

The best part of ur explanation is both brut force & optimised which makes us understand better.

surajgrandhi
Автор

How could we able to think this 2nd type of approach by our own??

rifatp
Автор

And the second approach is lit. how do you get those ideas bro.

surajgrandhi
join shbcf.ru