Big O
)}

Problem

This function returns the number of times a number appears in the array.

def count_occurrences(arr, num): count = 0 for i in range(len(arr)): if arr[i] == num: count += 1 return count

Solution

The number of loops is determined by the size of the array NN. The instructions inside the loop are constant-time. It follows that the time complexity is O(N)O(N).


This workbook was created by Jad and Rayan Slim. Feel free to explore some of their courses:
The Complete Java Development Bootcamp
The Complete Spring Boot Development Bootcamp – Become a Java Web Developer

Feedback Summary
0.0
0 students
5

0%
4

0%
3

0%
2

0%
1

0%
Written Reviews
There are no written reviews yet.