1

NumPy: Counting a Subarray

Unsolved
Data Wrangling
Search

Difficulty: 2 | Problem written by bilaldadanlar

Educational Resource: https://cs231n.github.io/python-numpy-tutorial/


Problem reported in interviews at

Amazon
Apple
Facebook
Google
Netflix

Write a function that counts how many times the second array pattern (pattern) exists in the first array (arr) and returns the number of occurrences.

Bonus points if you do not use a for loop or list comprehension.

Sample Input:
<class 'list'>
arr: [0 1 1 1 2 2 2 1 1 3 3 3]
pattern: [1 1]

Expected Output:
<class 'int'>
3

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Quia consequuntur dolorum ad aperiam labore.

Voluptatem eligendi qui non nam? Deleniti corporis ipsum officiis laborum dignissimos exercitationem quas laudantium culpa eum, nihil mollitia ab itaque doloremque temporibus ut magnam.

Non quisquam rem, dolorum voluptate culpa, quia beatae dolorum nobis facilis sed praesentium iure quasi quam, est fugiat aspernatur sapiente aut provident maiores porro consequatur aperiam, iusto magnam quis saepe accusamus. Eos ipsum quod molestiae illo itaque architecto eaque quibusdam asperiores. Natus harum at rem sit dolorem sapiente ea labore, maxime ipsa deleniti dignissimos obcaecati.

This is a premium feature.
To access this and other such features, click on upgrade below.

Ready.

Input Test Case

Please enter only one test case at a time
numpy has been already imported as np (import numpy as np)