LeetCode #523: Continuos Subarray Sum
Blog iconCoder OP
Nov 6
Intution :We need a subarray say from i to j such that sum of all elements is divisible by k.sum_j means prefix sum from 0 to jsum_i means prefix sum from 0 to i => (sum_j - sum_i) % k = 0 => sum_j % k - sum % k = 0 => sum_j % k = sum_i % k <Relation derived !!!> Thus for some prefix_sum(0,j) , we need to check if there exist some prefix_sum(0,i) such that both are equal.If yes then return true.Otherwise check for some other jLets do a dry run on first example:Given, nums : 23 2 4 6 7 , ...

Coder OP

Written by
Coder OP
Subscribe

2025 Paragraph Technologies Inc

PopularTrendingPrivacyTermsHome
Search...Ctrl+K

Coder OP

Subscribe