Given a large list of positive integers, count the number of k-subsequences. A k-subarray of an array is defined as follows: It is a subarray, i.e. made of contiguous elements in the array The sum of the subarray elements, s, is evenly divisible by _k, _i.e.: sum mod k = 0. Given an array of integers, determine the number of k-subarrays it contains.  For example, k = 5 and the array nums = [5, 10, 11, 9, 5].  The  10 k-subarrays are: {5}, {5, 10}, {5, 10, 11, 9}, {5, 10, 11, 9, 5}, {10}, {10, 11, 9}, {10, 11, 9, 5}, {11, 9}, {11

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Given a large list of positive integers, count the number of k-subsequences.

A k-subarray of an array is defined as follows:

  • It is a subarray, i.e. made of contiguous elements in the array
  • The sum of the subarray elements, s, is evenly divisible by _k, _i.e.: sum mod k = 0.

Given an array of integers, determine the number of k-subarrays it contains.  For example, k = 5 and the array nums = [5, 10, 11, 9, 5].  The  10 k-subarrays are: {5}, {5, 10}, {5, 10, 11, 9}, {5, 10, 11, 9, 5}, {10}, {10, 11, 9}, {10, 11, 9, 5}, {11, 9}, {11, 9, 5}, {5}.

**Function Description **

Complete the function kSub in the editor below. The function must return a long integer that represents the number of k-subarrays in the array.

kSub has the following parameter(s):

    k:  the integer divisor of a k-subarray

    nums[nums[0],...nums[n-1]]:  an array of integers

Constraints

  • 1 ≤ n ≤ 3 × 105
  • 1 ≤ k ≤ 100
  • 1 ≤ nums[i] ≤ 104

Input Format For Custom Testing

Input from stdin will be processed as follows and passed to the function.

The first line contains an integer, _k, _the number the sum of the subarray must be divisible by.

The next line contains an integer, n, that denotes the number of elements in nums.

Each line i of the n subsequent lines (where 0 ≤ i < n) contains an integer that describes nums[i].

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Random variables
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education